From 3d85c759ecb7fbddd988a053e5195246cbe464c3 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 20 May 2025 00:42:56 +0200 Subject: [PATCH 1/2] Update console URL from pkg.pr.new to try-module.cloud and migrate billing API calls --- package.json | 2 +- pnpm-lock.yaml | 10 +- .../commandCenter/searchers/organizations.ts | 2 +- .../billing/alerts/paymentMandate.svelte | 3 +- src/lib/components/billing/couponInput.svelte | 2 +- .../billing/estimatedTotalBox.svelte | 13 +-- .../billing/planComparisonBox.svelte | 4 +- src/lib/components/billing/planExcess.svelte | 10 +- .../billing/validateCreditModal.svelte | 3 +- src/lib/constants.ts | 3 + src/lib/layout/unauthenticated.svelte | 10 +- src/lib/sdk/billing.ts | 8 +- src/lib/stores/billing.ts | 103 +++++++++--------- src/lib/stores/campaigns.ts | 2 +- src/lib/stores/organization.ts | 30 +---- src/lib/stores/sdk.ts | 4 +- src/lib/stores/stripe.ts | 12 +- src/routes/(console)/+layout.svelte | 2 +- src/routes/(console)/+layout.ts | 11 +- .../account/organizations/+page.svelte | 2 +- .../(console)/account/organizations/+page.ts | 2 +- .../(console)/account/payments/+page.ts | 4 +- .../account/payments/addressModal.svelte | 11 +- .../payments/deleteAddressModal.svelte | 2 +- .../payments/deletePaymentModal.svelte | 2 +- .../account/payments/editAddressModal.svelte | 2 +- .../account/payments/editPaymentModal.svelte | 32 +++--- .../(console)/apply-credit/+page.svelte | 70 ++++++------ src/routes/(console)/apply-credit/+page.ts | 12 +- .../create-organization/+page.svelte | 46 ++++---- .../(console)/create-organization/+page.ts | 14 +-- .../onboarding/create-project/+page.ts | 15 +-- .../organization-[organization]/+layout.ts | 8 +- .../billing/+page.svelte | 16 ++- .../billing/+page.ts | 10 +- .../billing/addCreditModal.svelte | 2 +- .../billing/addCreditWizard.svelte | 7 +- .../billing/availableCredit.svelte | 2 +- .../billing/billingAddress.svelte | 2 +- .../billing/budgetAlert.svelte | 2 +- .../billing/budgetCap.svelte | 2 +- .../billing/cancelDowngradeModal.svelte | 2 +- .../billing/deleteOrgPayment.svelte | 4 +- .../billing/paymentHistory.svelte | 9 +- .../billing/paymentMethods.svelte | 4 +- .../billing/planSummary.svelte | 2 +- .../billing/removeAddress.svelte | 2 +- .../billing/replaceAddress.svelte | 14 ++- .../billing/replaceCard.svelte | 6 +- .../billing/retryPaymentModal.svelte | 19 ++-- .../billing/store.ts | 5 +- .../billing/taxId.svelte | 2 +- .../billing/wizard/addCredit.svelte | 2 +- .../billing/wizard/paymentDetails.svelte | 2 +- .../change-plan/+page.svelte | 32 +++--- .../change-plan/+page.ts | 15 +-- .../domains/domain-[domain]/settings/+page.ts | 2 +- .../organization-[organization]/header.svelte | 2 +- .../invoices/[invoiceId]/download/+page.ts | 5 +- .../invoices/[invoiceId]/view/+page.ts | 5 +- .../settings/+page.ts | 2 +- .../settings/deleteOrganizationModal.svelte | 7 +- .../settings/invoicesTable.svelte | 6 +- .../usage/[[invoice]]/+page.svelte | 12 +- .../usage/[[invoice]]/+page.ts | 9 +- .../usage/[[invoice]]/totalMembers.svelte | 2 +- .../project-[region]-[project]/+layout.ts | 8 +- .../databases/+page.ts | 3 +- .../template-[template]/+page.svelte | 8 +- .../settings/usage/[[invoice]]/+page.ts | 10 +- .../sites/+page.svelte | 9 +- .../settings/updateMaxFileSize.svelte | 3 +- src/routes/(console)/store.ts | 3 +- src/routes/(public)/(guest)/login/+page.ts | 12 +- src/routes/(public)/(guest)/register/+page.ts | 12 +- .../(public)/template-[template]/+page.ts | 9 +- src/routes/+layout.svelte | 2 +- src/routes/+layout.ts | 2 +- 78 files changed, 378 insertions(+), 374 deletions(-) diff --git a/package.json b/package.json index 99a3e173f2..d1ae6b6ad6 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@ai-sdk/svelte": "^1.1.24", - "@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959", + "@appwrite.io/console": "https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7", "@appwrite.io/pink": "0.25.0", "@appwrite.io/pink-icons": "0.25.0", "@appwrite.io/pink-icons-svelte": "^2.0.0-RC.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ceb043ad3..2bb3573a2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^1.1.24 version: 1.1.24(svelte@5.25.3)(zod@3.24.3) '@appwrite.io/console': - specifier: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959 - version: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959 + specifier: https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7 + version: https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7 '@appwrite.io/pink': specifier: 0.25.0 version: 0.25.0 @@ -254,8 +254,8 @@ packages: '@analytics/type-utils@0.6.2': resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==} - '@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959': - resolution: {tarball: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959} + '@appwrite.io/console@https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7': + resolution: {tarball: https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7} version: 1.5.2 '@appwrite.io/pink-icons-svelte@2.0.0-RC.1': @@ -3615,7 +3615,7 @@ snapshots: '@analytics/type-utils@0.6.2': {} - '@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959': {} + '@appwrite.io/console@https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fconsole@e50c8d0b7': {} '@appwrite.io/pink-icons-svelte@2.0.0-RC.1(svelte@5.25.3)': dependencies: diff --git a/src/lib/commandCenter/searchers/organizations.ts b/src/lib/commandCenter/searchers/organizations.ts index 1d959e9921..2a333d6cd5 100644 --- a/src/lib/commandCenter/searchers/organizations.ts +++ b/src/lib/commandCenter/searchers/organizations.ts @@ -7,7 +7,7 @@ import { isCloud } from '$lib/system'; export const orgSearcher = (async (query: string) => { const { teams } = !isCloud ? await sdk.forConsole.teams.list() - : await sdk.forConsole.billing.listOrganization(); + : await sdk.forConsole.organizations.list(); return teams .filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase())) diff --git a/src/lib/components/billing/alerts/paymentMandate.svelte b/src/lib/components/billing/alerts/paymentMandate.svelte index b55f5d20bf..c38027920c 100644 --- a/src/lib/components/billing/alerts/paymentMandate.svelte +++ b/src/lib/components/billing/alerts/paymentMandate.svelte @@ -8,8 +8,7 @@ import { confirmSetup } from '$lib/stores/stripe'; async function verifyPaymentMethod() { - const method = await sdk.forConsole.billing.setupPaymentMandate( - $organization.$id, + const method = await sdk.forConsole.account.updatePaymentMethodMandateOptions( $paymentMissingMandate.$id ); await confirmSetup(method.clientSecret, method.$id); diff --git a/src/lib/components/billing/couponInput.svelte b/src/lib/components/billing/couponInput.svelte index 85e73411c0..60dcadfe0e 100644 --- a/src/lib/components/billing/couponInput.svelte +++ b/src/lib/components/billing/couponInput.svelte @@ -18,7 +18,7 @@ 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; diff --git a/src/lib/components/billing/estimatedTotalBox.svelte b/src/lib/components/billing/estimatedTotalBox.svelte index 112d506c19..5e66057ad7 100644 --- a/src/lib/components/billing/estimatedTotalBox.svelte +++ b/src/lib/components/billing/estimatedTotalBox.svelte @@ -2,15 +2,16 @@ import { InputChoice, InputNumber } from '$lib/elements/forms'; import { toLocaleDate } from '$lib/helpers/date'; import { formatCurrency } from '$lib/helpers/numbers'; - import type { Coupon, PlansMap } from '$lib/sdk/billing'; + import type { Coupon } from '$lib/sdk/billing'; import { type Tier } from '$lib/stores/billing'; import { Card, Divider, Layout, Typography } from '@appwrite.io/pink-svelte'; import { CreditsApplied } from '.'; + import type { Models } from '@appwrite.io/console'; export let billingPlan: Tier; export let collaborators: string[]; export let couponData: Partial; - export let plans: PlansMap; + export let plans: Map; export let billingBudget: number; export let fixedCoupon = false; // If true, the coupon cannot be removed export let isDowngrade = false; @@ -29,9 +30,7 @@ ? grossCost - couponData.credits : 0 : grossCost; - $: trialEndDate = new Date( - billingPayDate.getTime() + currentPlan.trialDays * 24 * 60 * 60 * 1000 - ); + $: trialEndDate = new Date(billingPayDate.getTime() + currentPlan.trial * 24 * 60 * 60 * 1000); @@ -54,7 +53,7 @@ Upcoming charge
- Due on {!currentPlan.trialDays + Due on {!currentPlan.trial ? toLocaleDate(billingPayDate.toString()) : toLocaleDate(trialEndDate.toString())}
{formatCurrency(estimatedTotal)} @@ -64,7 +63,7 @@ You'll pay {formatCurrency(estimatedTotal)} now, with your first billing cycle starting on {!currentPlan.trialDays + >{!currentPlan.trial ? toLocaleDate(billingPayDate.toString()) : toLocaleDate(trialEndDate.toString())}. {#if couponData?.status === 'active'}Once your credits run out, you'll be charged diff --git a/src/lib/components/billing/planComparisonBox.svelte b/src/lib/components/billing/planComparisonBox.svelte index 9d7443df43..c3e1e3dbf4 100644 --- a/src/lib/components/billing/planComparisonBox.svelte +++ b/src/lib/components/billing/planComparisonBox.svelte @@ -1,12 +1,12 @@ diff --git a/src/lib/components/billing/planExcess.svelte b/src/lib/components/billing/planExcess.svelte index 02793dc708..63dca3e889 100644 --- a/src/lib/components/billing/planExcess.svelte +++ b/src/lib/components/billing/planExcess.svelte @@ -1,18 +1,18 @@ diff --git a/src/routes/(console)/project-[region]-[project]/+layout.ts b/src/routes/(console)/project-[region]-[project]/+layout.ts index f90abed153..7317c0f9bd 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.ts +++ b/src/routes/(console)/project-[region]-[project]/+layout.ts @@ -6,16 +6,16 @@ import { preferences } from '$lib/stores/preferences'; import { failedInvoice } from '$lib/stores/billing'; import { isCloud } from '$lib/system'; import { defaultRoles, defaultScopes } from '$lib/constants'; -import type { Plan } from '$lib/sdk/billing'; import { get } from 'svelte/store'; import { headerAlert } from '$lib/stores/headerAlert'; import PaymentFailed from '$lib/components/billing/alerts/paymentFailed.svelte'; import { loadAvailableRegions } from '$routes/(console)/regions'; import type { Organization } from '$lib/stores/organization'; +import type { Models } from '@appwrite.io/console'; export const load: LayoutLoad = async ({ params, depends }) => { depends(Dependencies.PROJECT); - let currentPlan: Plan = null; + let currentPlan: Models.BillingPlan = null; try { const project = await sdk.forConsole.projects.get(params.project); @@ -34,8 +34,8 @@ export const load: LayoutLoad = async ({ params, depends }) => { let roles = isCloud ? [] : defaultRoles; let scopes = isCloud ? [] : defaultScopes; if (isCloud) { - currentPlan = await sdk.forConsole.billing.getOrganizationPlan(project.teamId); - const res = await sdk.forConsole.billing.getRoles(project.teamId); + currentPlan = await sdk.forConsole.organizations.getPlan(project.teamId); + const res = await sdk.forConsole.organizations.getScopes(project.teamId); roles = res.roles; scopes = res.scopes; if (scopes.includes('billing.read')) { diff --git a/src/routes/(console)/project-[region]-[project]/databases/+page.ts b/src/routes/(console)/project-[region]-[project]/databases/+page.ts index 6abcffdc5a..9c0ede9ade 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/+page.ts +++ b/src/routes/(console)/project-[region]-[project]/databases/+page.ts @@ -7,7 +7,6 @@ import type { PageLoad, RouteParams } from './$types'; import type { BackupPolicy } from '$lib/sdk/backups'; import { isSelfHosted } from '$lib/system'; import { isCloud } from '$lib/system'; -import type { Plan } from '$lib/sdk/billing'; export const load: PageLoad = async ({ url, route, depends, params, parent }) => { depends(Dependencies.DATABASES); @@ -45,7 +44,7 @@ async function fetchDatabasesAndBackups( offset: number, params: RouteParams, search?: string | undefined, - currentPlan?: Plan + currentPlan?: Models.BillingPlan ) { const backupsEnabled = currentPlan?.backupsEnabled ?? true; diff --git a/src/routes/(console)/project-[region]-[project]/functions/templates/template-[template]/+page.svelte b/src/routes/(console)/project-[region]-[project]/functions/templates/template-[template]/+page.svelte index 4f5ca68a10..9d4fe43593 100644 --- a/src/routes/(console)/project-[region]-[project]/functions/templates/template-[template]/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/functions/templates/template-[template]/+page.svelte @@ -24,9 +24,15 @@ import { page } from '$app/state'; import { capitalize } from '$lib/helpers/string'; import { IconExternalLink } from '@appwrite.io/pink-icons-svelte'; + import type { BillingPlan } from '$lib/constants'; $: buttonDisabled = - isCloud && isServiceLimited('functions', $organization?.billingPlan, $functionsList?.total); + isCloud && + isServiceLimited( + 'functions', + $organization?.billingPlan as BillingPlan, + $functionsList?.total + ); diff --git a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts index c432d29b86..5432891845 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts +++ b/src/routes/(console)/project-[region]-[project]/settings/usage/[[invoice]]/+page.ts @@ -1,7 +1,7 @@ -import type { Aggregation, Invoice } from '$lib/sdk/billing'; +import type { Aggregation } from '$lib/sdk/billing'; import { accumulateUsage } from '$lib/sdk/usage'; import { sdk } from '$lib/stores/sdk'; -import { Query } from '@appwrite.io/console'; +import { Query, type Models } from '@appwrite.io/console'; import type { PageLoad } from './$types'; export const load: PageLoad = async ({ params, parent }) => { @@ -10,11 +10,11 @@ export const load: PageLoad = async ({ params, parent }) => { let startDate: string = organization.billingCurrentInvoiceDate; let endDate: string = organization.billingNextInvoiceDate; - let currentInvoice: Invoice = undefined; + let currentInvoice: Models.Invoice = undefined; let currentAggregation: Aggregation = undefined; if (invoice) { - currentInvoice = await sdk.forConsole.billing.getInvoice(organization.$id, invoice); + currentInvoice = await sdk.forConsole.organizations.getInvoice(organization.$id, invoice); currentAggregation = await sdk.forConsole.billing.getAggregation( organization.$id, currentInvoice.aggregationId @@ -25,7 +25,7 @@ export const load: PageLoad = async ({ params, parent }) => { } const [invoices, usage] = await Promise.all([ - sdk.forConsole.billing.listInvoices(organization.$id, [Query.orderDesc('from')]), + sdk.forConsole.organizations.listInvoices(organization.$id, [Query.orderDesc('from')]), sdk.forProject(region, project).project.getUsage(startDate, endDate) ]); diff --git a/src/routes/(console)/project-[region]-[project]/sites/+page.svelte b/src/routes/(console)/project-[region]-[project]/sites/+page.svelte index 855274fa47..fd6f9e0017 100644 --- a/src/routes/(console)/project-[region]-[project]/sites/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/sites/+page.svelte @@ -24,7 +24,7 @@ import Table from './table.svelte'; import { onMount } from 'svelte'; import { invalidate } from '$app/navigation'; - import { Dependencies } from '$lib/constants'; + import { BillingPlan, Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; export let data; let show = false; @@ -37,8 +37,11 @@ }, keys: ['c'], disabled: - isServiceLimited('sites', $organization?.billingPlan, data.siteList?.total) || - !$canWriteSites, + isServiceLimited( + 'sites', + $organization?.billingPlan as BillingPlan, + data.siteList?.total + ) || !$canWriteSites, icon: IconPlus, group: 'sites' } diff --git a/src/routes/(console)/project-[region]-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte b/src/routes/(console)/project-[region]-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte index 62bbb8c4bd..ad9b426003 100644 --- a/src/routes/(console)/project-[region]-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte +++ b/src/routes/(console)/project-[region]-[project]/storage/bucket-[bucket]/settings/updateMaxFileSize.svelte @@ -9,11 +9,10 @@ import { organization } from '$lib/stores/organization'; import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system'; import { updateBucket } from './+page.svelte'; - import type { Plan } from '$lib/sdk/billing'; import type { Models } from '@appwrite.io/console'; export let bucket: Models.Bucket; - export let currentPlan: Plan | null; + export let currentPlan: Models.BillingPlan | null; const service = currentPlan ? currentPlan['fileSize'] : null; const { value, unit, baseValue, units } = createByteUnitPair(bucket.maximumFileSize, 1000); diff --git a/src/routes/(console)/store.ts b/src/routes/(console)/store.ts index 7735d4c298..146a8e00e1 100644 --- a/src/routes/(console)/store.ts +++ b/src/routes/(console)/store.ts @@ -1,6 +1,5 @@ import { page } from '$app/stores'; import type { HeaderAlert } from '$lib/stores/headerAlert'; -import type { Organization } from '$lib/stores/organization'; import type { Models } from '@appwrite.io/console'; import { derived, writable } from 'svelte/store'; @@ -16,4 +15,4 @@ export const protocol = derived(page, ($page) => ); export const activeHeaderAlert = writable(null); -export const orgMissingPaymentMethod = writable(null); +export const orgMissingPaymentMethod = writable>>(null); diff --git a/src/routes/(public)/(guest)/login/+page.ts b/src/routes/(public)/(guest)/login/+page.ts index 33d808b7e5..4a48303d13 100644 --- a/src/routes/(public)/(guest)/login/+page.ts +++ b/src/routes/(public)/(guest)/login/+page.ts @@ -1,17 +1,17 @@ import { base } from '$app/paths'; -import type { Campaign } from '$lib/stores/campaigns'; import { sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; import type { PageLoad } from './$types'; +import type { Models } from '@appwrite.io/console'; export const load: PageLoad = async ({ url }) => { if (url.searchParams.has('code')) { const code = url.searchParams.get('code'); - let campaign: Campaign; + let campaign: Models.Campaign; try { - const couponData = await sdk.forConsole.billing.getCoupon(code); + const couponData = await sdk.forConsole.console.getCoupon(code); if (couponData.campaign) { - campaign = await sdk.forConsole.billing.getCampaign(couponData.campaign); + campaign = await sdk.forConsole.console.getCampaign(couponData.campaign); return { couponData, campaign @@ -23,9 +23,9 @@ export const load: PageLoad = async ({ url }) => { } if (url.searchParams.has('campaign')) { const campaignId = url.searchParams.get('campaign'); - let campaign: Campaign; + let campaign: Models.Campaign; try { - campaign = await sdk.forConsole.billing.getCampaign(campaignId); + campaign = await sdk.forConsole.console.getCampaign(campaignId); return { campaign }; } catch (e) { redirect(303, `${base}/login`); diff --git a/src/routes/(public)/(guest)/register/+page.ts b/src/routes/(public)/(guest)/register/+page.ts index 1fa2e79de8..852e7d0c9f 100644 --- a/src/routes/(public)/(guest)/register/+page.ts +++ b/src/routes/(public)/(guest)/register/+page.ts @@ -1,17 +1,17 @@ import { base } from '$app/paths'; -import type { Campaign } from '$lib/stores/campaigns.js'; import { sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; import type { PageLoad } from './$types'; +import type { Models } from '@appwrite.io/console'; export const load: PageLoad = async ({ url }) => { if (url.searchParams.has('code')) { const code = url.searchParams.get('code'); - let campaign: Campaign; + let campaign: Models.Campaign; try { - const couponData = await sdk.forConsole.billing.getCoupon(code); + const couponData = await sdk.forConsole.console.getCoupon(code); if (couponData.campaign) { - campaign = await sdk.forConsole.billing.getCampaign(couponData.campaign); + campaign = await sdk.forConsole.console.getCampaign(couponData.campaign); return { couponData, campaign @@ -23,9 +23,9 @@ export const load: PageLoad = async ({ url }) => { } if (url.searchParams.has('campaign')) { const campaignId = url.searchParams.get('campaign'); - let campaign: Campaign; + let campaign: Models.Campaign; try { - campaign = await sdk.forConsole.billing.getCampaign(campaignId); + campaign = await sdk.forConsole.console.getCampaign(campaignId); return { campaign }; } catch (e) { redirect(303, `${base}/register`); diff --git a/src/routes/(public)/template-[template]/+page.ts b/src/routes/(public)/template-[template]/+page.ts index dad1d1a067..f706267f81 100644 --- a/src/routes/(public)/template-[template]/+page.ts +++ b/src/routes/(public)/template-[template]/+page.ts @@ -1,6 +1,5 @@ -import { BillingPlan } from '$lib/constants.js'; import { sdk } from '$lib/stores/sdk.js'; -import { ID, type Models } from '@appwrite.io/console'; +import { BillingPlan, ID, type Models } from '@appwrite.io/console'; import { isCloud } from '$lib/system.js'; import { error, redirect } from '@sveltejs/kit'; import type { OrganizationList } from '$lib/stores/organization.js'; @@ -34,16 +33,16 @@ export const load = async ({ parent, url, params }) => { let organizations: Models.TeamList> | OrganizationList | undefined; if (isCloud) { - organizations = account?.$id ? await sdk.forConsole.billing.listOrganization() : undefined; + organizations = account?.$id ? await sdk.forConsole.organizations.list() : undefined; } else { organizations = account?.$id ? await sdk.forConsole.teams.list() : undefined; } if (!organizations?.total && account?.$id) { - await sdk.forConsole.billing.createOrganization( + await sdk.forConsole.organizations.create( ID.unique(), 'Personal project', - BillingPlan.FREE, + BillingPlan.Tier0, null, null ); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index f5bed4b866..852a19037e 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -68,7 +68,7 @@ if (page.url.searchParams.has('code')) { const code = page.url.searchParams.get('code'); - const coupon = await sdk.forConsole.billing.getCoupon(code).catch(() => null); + const coupon = await sdk.forConsole.console.getCoupon(code).catch(() => null); if (coupon?.campaign) { const campaign = await sdk.forConsole.billing .getCampaign(coupon.campaign) diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 78d86d2e47..ebe0dfeff6 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -32,7 +32,7 @@ export const load: LayoutLoad = async ({ depends, url, route }) => { account: account, organizations: !isCloud ? await sdk.forConsole.teams.list() - : await sdk.forConsole.billing.listOrganization() + : await sdk.forConsole.organizations.list() }; } From fdd970a13d48531a7589b1b202f7f8a4ee379b4b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 20 May 2025 01:04:09 +0200 Subject: [PATCH 2/2] Remove Invoice type and related billing methods --- src/lib/sdk/billing.ts | 104 +----------------- .../billing/planSummary.svelte | 5 +- 2 files changed, 4 insertions(+), 105 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index f81d81fafc..c1a3ffa8b1 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -1,4 +1,3 @@ -import type { Tier } from '$lib/stores/billing'; import type { Campaign } from '$lib/stores/campaigns'; import type { Client, Models } from '@appwrite.io/console'; import type { PaymentMethod } from '@stripe/stripe-js'; @@ -30,42 +29,6 @@ export type PaymentList = { total: number; }; -export type Invoice = { - $id: string; - $createdAt: Date; - $updatedAt: Date; - permissions: string[]; - teamId: string; - aggregationId: string; - plan: Tier; - amount: number; - tax: number; - taxAmount: number; - vat: number; - vatAmount: number; - grossAmount: number; - creditsUsed: number; - currency: string; - from: string; - to: string; - status: string; - dueAt: string; - clientSecret: string; - usage: { - name: string; - value: number /* service over the limit*/; - amount: number /* price of service over the limit*/; - rate: number; - desc: string; - }[]; - lastError?: string; -}; - -export type InvoiceList = { - invoices: Invoice[]; - total: number; -}; - export type Estimation = { amount: number; grossAmount: number; @@ -89,7 +52,7 @@ export type EstimationDeleteOrganization = { credits: number; discount: number; items: EstimationItem[]; - unpaidInvoices: Invoice[]; + unpaidInvoices: Models.Invoice[]; }; export type Coupon = { @@ -657,41 +620,6 @@ export class Billing { ); } - async listInvoices(organizationId: string, queries: string[] = []): Promise { - const path = `/organizations/${organizationId}/invoices`; - const params = { - organizationId, - queries - }; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getInvoice(organizationId: string, invoiceId: string): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}`; - const params = { - organizationId, - invoiceId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async getInvoiceView( organizationId: string, invoiceId: string @@ -732,36 +660,6 @@ export class Billing { ); } - async updateInvoiceStatus(organizationId: string, invoiceId: string): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}/status`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('PATCH', uri, { - 'content-type': 'application/json' - }); - } - - async retryPayment( - organizationId: string, - invoiceId: string, - paymentMethodId: string - ): Promise { - const path = `/organizations/${organizationId}/invoices/${invoiceId}/payments`; - const params = { - organizationId, - invoiceId, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'post', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async listUsage( organizationId: string, startDate: string = undefined, diff --git a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte index 491a3b487d..a6b8914c12 100644 --- a/src/routes/(console)/organization-[organization]/billing/planSummary.svelte +++ b/src/routes/(console)/organization-[organization]/billing/planSummary.svelte @@ -5,7 +5,7 @@ import { toLocaleDate } from '$lib/helpers/date'; import { plansInfo, upgradeURL } from '$lib/stores/billing'; import { organization } from '$lib/stores/organization'; - import type { Aggregation, CreditList, Invoice, Plan } from '$lib/sdk/billing'; + import type { Aggregation, CreditList, Plan } from '$lib/sdk/billing'; import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers'; import { humanFileSize } from '$lib/helpers/sizeConvertion'; import { BillingPlan } from '$lib/constants'; @@ -21,10 +21,11 @@ } from '@appwrite.io/pink-svelte'; import { IconInfo, IconTag } from '@appwrite.io/pink-icons-svelte'; import CancelDowngradeModel from './cancelDowngradeModal.svelte'; + import type { Models } from '@appwrite.io/console'; export let currentPlan: Plan; export let creditList: CreditList; - export let currentInvoice: Invoice | undefined = undefined; + export let currentInvoice: Models.Invoice | undefined = undefined; export let currentAggregation: Aggregation | undefined = undefined; let showCancel: boolean = false;