Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: hardcoded sdk methods with console sdk #1722

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/commandCenter/searchers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sdk } from '$lib/stores/sdk';
import type { Searcher } from '../commands';

export const orgSearcher = (async (query: string) => {
const { teams } = await sdk.forConsole.billing.listOrganization();
const { teams } = await sdk.forConsole.organizations.list();
return teams
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))
.map((organization) => {
Expand Down
26 changes: 13 additions & 13 deletions src/lib/components/backupRestoreBox.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import { type Payload } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { isCloud, isSelfHosted } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { BillingPlan, Dependencies } from '$lib/constants';
import type { BackupArchive, BackupRestoration } from '$lib/sdk/backups';
import { goto, invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { addNotification } from '$lib/stores/notifications';
import { base } from '$app/paths';
import { getProjectId } from '$lib/helpers/project';
import { page } from '$app/stores';
import { BillingPlan, Dependencies } from '$lib/constants';
import { toLocaleDate } from '$lib/helpers/date';
import { getProjectId } from '$lib/helpers/project';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { isCloud, isSelfHosted } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { type Payload } from '@appwrite.io/console';
import { onMount } from 'svelte';

const backupRestoreItems: {
archives: Map<string, BackupArchive>;
restorations: Map<string, BackupRestoration>;
archives: Map<string, Models.BackupArchive>;
restorations: Map<string, Models.BackupRestoration>;
} = {
archives: new Map(),
restorations: new Map()
Expand Down Expand Up @@ -112,7 +112,7 @@
if (which === 'restorations') lastDatabaseRestorationId = null;
}

function backupName(item: BackupArchive | BackupRestoration, key: string) {
function backupName(item: Models.BackupArchive | Models.BackupRestoration, key: string) {
const attribute = key === 'archives' ? '$createdAt' : 'startedAt';

return toLocaleDate(item[attribute]);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/billing/couponInput.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<script lang="ts">
import { Button, FormList, InputText } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher();

export let required = false;
export let coupon: string = '';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
};

async function addCoupon() {
try {
const response = await sdk.forConsole.billing.getCouponAccount(coupon);
const response = await sdk.forConsole.account.getCoupon(coupon);
couponData = response;
dispatch('validation', couponData);
coupon = null;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/billing/creditsApplied.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';

export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/billing/discountsApplied.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';

export let label: string;
export let value: number;
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/billing/estimatedTotal.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<script lang="ts">
import { FormList, InputChoice, InputNumber } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon, Estimation } from '$lib/sdk/billing';
import type { Estimation } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { AppwriteException } from '@appwrite.io/console';
import Card from '../card.svelte';
import DiscountsApplied from './discountsApplied.svelte';
import { addNotification } from '$lib/stores/notifications';

export let organizationId: string | undefined = undefined;
export let billingPlan: string;
export let collaborators: string[];
export let fixedCoupon = false;
export let couponData: Partial<Coupon>;
export let couponData: Partial<Models.Coupon>;

export let billingBudget: number;

Expand Down
18 changes: 9 additions & 9 deletions src/lib/components/billing/planExcess.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { Alert } from '$lib/components';
import { BillingPlan } from '$lib/constants';
import {
TableBody,
TableCell,
Expand All @@ -8,18 +11,15 @@
TableRow,
TableScroll
} from '$lib/elements/table';
import { Alert } from '$lib/components';
import { calculateExcess, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { toLocaleDate } from '$lib/helpers/date';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import { abbreviateNumber } from '$lib/helpers/numbers';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import { formatNum } from '$lib/helpers/string';
import { onMount } from 'svelte';
import type { Aggregation } from '$lib/sdk/billing';
import { calculateExcess, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { BillingPlan } from '$lib/constants';
import { tooltip } from '$lib/actions/tooltip';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';

export let tier: Tier;

Expand All @@ -31,7 +31,7 @@
executions?: number;
members?: number;
} = null;
let aggregation: Aggregation = null;
let aggregation: Models.AggregationTeam = null;
let showExcess = false;

onMount(async () => {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/billing/selectPaymentMethod.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import { Button, Helper, InputChoice, InputSelectSearch, InputText } from '$lib/elements/forms';
import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
import { capitalize } from '$lib/helpers/string';
import { sdk } from '$lib/stores/sdk';
import { hasStripePublicKey, isCloud } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { Alert, Card, CreditCardBrandImage } from '..';
import PaymentModal from './paymentModal.svelte';
import { capitalize } from '$lib/helpers/string';

export let methods: PaymentList;
export let methods: Models.PaymentMethodList;
export let value: string;
export let taxId = '';

Expand All @@ -27,9 +27,9 @@
error = input.validationMessage;
}

async function cardSaved(event: CustomEvent<PaymentMethodData>) {
async function cardSaved(event: CustomEvent<Models.PaymentMethod>) {
value = event.detail.$id;
methods = await sdk.forConsole.billing.listPaymentMethods();
methods = await sdk.forConsole.account.listPaymentMethods();
}

onMount(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/billing/validateCreditModal.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button, FormList, InputText } from '$lib/elements/forms';
import type { Coupon } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher();
export let show = false;
let error: string = null;
let coupon: string = '';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
};

async function addCoupon() {
try {
const response = await sdk.forConsole.billing.getCouponAccount(coupon);
const response = await sdk.forConsole.account.getCoupon(coupon);
couponData = response;
dispatch('validation', couponData);
coupon = null;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/creditCardInfo.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import type { PaymentMethodData } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';
import { Alert } from '.';
import CreditCardBrandImage from './creditCardBrandImage.svelte';

export let isBox = false;
export let paymentMethod: PaymentMethodData;
export let paymentMethod: Models.PaymentMethod;
</script>

<div class:box={isBox}>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/layout/unauthenticated.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import AppwriteLogoLight from '$lib/images/appwrite-logo-light.svg';
import LoginDark from '$lib/images/login/login-dark-mode.png';
import LoginLight from '$lib/images/login/login-light-mode.png';
import type { Coupon } from '$lib/sdk/billing';
import { app } from '$lib/stores/app';
import type { Campaign } from '$lib/stores/campaigns';
import { getCampaignImageUrl } from '$routes/(public)/card/helpers';
import type { Models } from '@appwrite.io/console';

export const imgLight = LoginLight;
export const imgDark = LoginDark;

export let campaign: Campaign = null;
export let coupon: Coupon = null;
export let coupon: Models.Coupon = null;

$: variation = ((coupon?.campaign ?? campaign) ? campaign?.template : 'default') as
| 'default'
Expand Down
Loading