diff --git a/src/lib/components/billing/couponInput.svelte b/src/lib/components/billing/couponInput.svelte index 586a08d68..2a3f0bff2 100644 --- a/src/lib/components/billing/couponInput.svelte +++ b/src/lib/components/billing/couponInput.svelte @@ -17,7 +17,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/validateCreditModal.svelte b/src/lib/components/billing/validateCreditModal.svelte index 44dd04d98..61a56dc96 100644 --- a/src/lib/components/billing/validateCreditModal.svelte +++ b/src/lib/components/billing/validateCreditModal.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/sdk/billing.ts b/src/lib/sdk/billing.ts index 1e62c9066..77daedf75 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -257,14 +257,6 @@ export class Billing { }); } - async getRoles(organizationId: string): Promise { - const path = `/organizations/${organizationId}/roles`; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json' - }); - } - async updatePlan( organizationId: string, billingPlan: string, @@ -328,98 +320,6 @@ export class Billing { }); } - async updateBudget( - organizationId: string, - budget: number, - alerts: number[] - ): Promise { - const path = `/organizations/${organizationId}/budget`; - const params = { - organizationId, - budget, - alerts - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async setOrganizationPaymentMethod( - organizationId: string, - paymentMethodId: string - ): Promise { - const path = `/organizations/${organizationId}/payment-method`; - const params = { - organizationId, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async setOrganizationPaymentMethodBackup( - organizationId: string, - paymentMethodId: string - ): Promise { - const path = `/organizations/${organizationId}/payment-method/backup`; - const params = { - organizationId, - paymentMethodId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'patch', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async removeOrganizationPaymentMethod(organizationId: string): Promise { - const path = `/organizations/${organizationId}/payment-method`; - const params = { - organizationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'DELETE', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async removeOrganizationPaymentMethodBackup(organizationId: string): Promise { - const path = `/organizations/${organizationId}/payment-method/backup`; - const params = { - organizationId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'DELETE', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async listInvoices(organizationId: string, queries: string[] = []): Promise { const path = `/organizations/${organizationId}/invoices`; const params = { @@ -517,54 +417,6 @@ export class Billing { ); } - async listUsage( - organizationId: string, - startDate: string = undefined, - endDate: string = undefined - ): Promise { - const path = `/organizations/${organizationId}/usage`; - const params = { - organizationId - }; - - if (startDate !== undefined) { - params['startDate'] = startDate; - } - if (endDate !== undefined) { - params['endDate'] = endDate; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async listAggregation( - organizationId: string, - queries: string[] = [] - ): Promise { - const path = `/organizations/${organizationId}/aggregations`; - 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 getAggregation( organizationId: string, aggregationId: string @@ -607,38 +459,6 @@ export class Billing { } } - async getCouponAccount(couponId: string): Promise { - const path = `/account/coupons/${couponId}`; - const params = { - couponId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - - async getCoupon(couponId: string): Promise { - const path = `/console/coupons/${couponId}`; - const params = { - couponId - }; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call( - 'GET', - uri, - { - 'content-type': 'application/json' - }, - params - ); - } - async setBillingAddress( organizationId: string, billingAddressId: string diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index b8c8071a1..612720a54 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -461,7 +461,7 @@ export async function checkForNewDevUpgradePro(org: Organization) { if (isDismissed) return; // check if coupon already applied try { - await sdk.forConsole.billing.getCouponAccount(NEW_DEV_PRO_UPGRADE_COUPON); + await sdk.forConsole.account.getCoupon(NEW_DEV_PRO_UPGRADE_COUPON); } catch (e) { return; } diff --git a/src/routes/(console)/apply-credit/+page.svelte b/src/routes/(console)/apply-credit/+page.svelte index 9de413c4b..8239ddada 100644 --- a/src/routes/(console)/apply-credit/+page.svelte +++ b/src/routes/(console)/apply-credit/+page.svelte @@ -199,7 +199,7 @@ async function addCoupon() { try { - const response = await sdk.forConsole.billing.getCoupon(coupon); + const response = await sdk.forConsole.console.getCoupon(coupon); couponData = response; coupon = null; addNotification({ diff --git a/src/routes/(console)/apply-credit/+page.ts b/src/routes/(console)/apply-credit/+page.ts index 8bde34c31..562754b0d 100644 --- a/src/routes/(console)/apply-credit/+page.ts +++ b/src/routes/(console)/apply-credit/+page.ts @@ -11,7 +11,7 @@ export const load = async ({ url }) => { let campaign: Campaign; const code = url.searchParams.get('code'); try { - couponData = await sdk.forConsole.billing.getCouponAccount(code); + couponData = await sdk.forConsole.account.getCoupon(code); if (couponData.campaign) { campaign = await sdk.forConsole.billing.getCampaign(couponData.campaign); } diff --git a/src/routes/(console)/create-organization/+page.svelte b/src/routes/(console)/create-organization/+page.svelte index b358184fc..7fcca7790 100644 --- a/src/routes/(console)/create-organization/+page.svelte +++ b/src/routes/(console)/create-organization/+page.svelte @@ -61,7 +61,7 @@ if ($page.url.searchParams.has('coupon')) { const coupon = $page.url.searchParams.get('coupon'); try { - const response = await sdk.forConsole.billing.getCouponAccount(coupon); + const response = await sdk.forConsole.account.getCoupon(coupon); couponData = response; } catch (e) { couponData = { diff --git a/src/routes/(console)/organization-[organization]/+layout.ts b/src/routes/(console)/organization-[organization]/+layout.ts index cd1968ea8..8cb526499 100644 --- a/src/routes/(console)/organization-[organization]/+layout.ts +++ b/src/routes/(console)/organization-[organization]/+layout.ts @@ -1,18 +1,17 @@ -import { Dependencies } from '$lib/constants'; +import ProjectsAtRisk from '$lib/components/billing/alerts/projectsAtRisk.svelte'; +import { defaultRoles, defaultScopes, Dependencies } from '$lib/constants'; +import type { Plan } from '$lib/sdk/billing'; import { failedInvoice } from '$lib/stores/billing'; -import { isCloud } from '$lib/system'; +import { headerAlert } from '$lib/stores/headerAlert'; +import type { Organization } from '$lib/stores/organization'; +import { preferences } from '$lib/stores/preferences'; import { sdk } from '$lib/stores/sdk'; +import { isCloud } from '$lib/system'; import { error } from '@sveltejs/kit'; +import { get } from 'svelte/store'; import type { LayoutLoad } from './$types'; import Breadcrumbs from './breadcrumbs.svelte'; import Header from './header.svelte'; -import { headerAlert } from '$lib/stores/headerAlert'; -import ProjectsAtRisk from '$lib/components/billing/alerts/projectsAtRisk.svelte'; -import { get } from 'svelte/store'; -import { preferences } from '$lib/stores/preferences'; -import type { Organization } from '$lib/stores/organization'; -import { defaultRoles, defaultScopes } from '$lib/constants'; -import type { Plan } from '$lib/sdk/billing'; export const load: LayoutLoad = async ({ params, depends }) => { depends(Dependencies.ORGANIZATION); @@ -24,7 +23,7 @@ export const load: LayoutLoad = async ({ params, depends }) => { try { if (isCloud) { - const res = await sdk.forConsole.billing.getRoles(params.organization); + const res = await sdk.forConsole.organizations.getScopes(params.organization); roles = res.roles; scopes = res.scopes; currentPlan = await sdk.forConsole.billing.getOrganizationPlan(params.organization); diff --git a/src/routes/(console)/organization-[organization]/billing/addCreditWizard.svelte b/src/routes/(console)/organization-[organization]/billing/addCreditWizard.svelte index 3f82d62bb..9ccb16017 100644 --- a/src/routes/(console)/organization-[organization]/billing/addCreditWizard.svelte +++ b/src/routes/(console)/organization-[organization]/billing/addCreditWizard.svelte @@ -18,7 +18,7 @@ async function create() { try { - await sdk.forConsole.billing.setOrganizationPaymentMethod( + await sdk.forConsole.organizations.setDefaultPaymentMethod( $organization.$id, $addCreditWizardStore.paymentMethodId ); diff --git a/src/routes/(console)/organization-[organization]/billing/budgetAlert.svelte b/src/routes/(console)/organization-[organization]/billing/budgetAlert.svelte index 948eeab9e..472eb36da 100644 --- a/src/routes/(console)/organization-[organization]/billing/budgetAlert.svelte +++ b/src/routes/(console)/organization-[organization]/billing/budgetAlert.svelte @@ -3,7 +3,6 @@ import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { Alert, CardGrid, Heading } from '$lib/components'; import { BillingPlan, Dependencies } from '$lib/constants'; - import { tierToPlan, upgradeURL } from '$lib/stores/billing'; import { Button, Form, FormList, InputSelectSearch } from '$lib/elements/forms'; import { Table, @@ -15,6 +14,7 @@ TableRow } from '$lib/elements/table'; import { symmetricDifference } from '$lib/helpers/array'; + import { tierToPlan, upgradeURL } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; import { currentPlan, organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; @@ -49,7 +49,7 @@ async function updateBudget() { try { - await sdk.forConsole.billing.updateBudget( + await sdk.forConsole.organizations.updateBudget( $organization.$id, $organization.billingBudget, alerts diff --git a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte index b9c9b5eb3..44fe18a13 100644 --- a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte +++ b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte @@ -6,7 +6,7 @@ import { Button, Form, FormList, InputNumber, InputSwitch } from '$lib/elements/forms'; import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing'; import { addNotification } from '$lib/stores/notifications'; - import { organization, currentPlan } from '$lib/stores/organization'; + import { currentPlan, organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { onMount } from 'svelte'; @@ -20,7 +20,7 @@ async function updateBudget() { try { - await sdk.forConsole.billing.updateBudget( + await sdk.forConsole.organizations.updateBudget( $organization.$id, budget, $organization.budgetAlerts diff --git a/src/routes/(console)/organization-[organization]/billing/deleteOrgPayment.svelte b/src/routes/(console)/organization-[organization]/billing/deleteOrgPayment.svelte index e1e9f3ee8..ebbbc060c 100644 --- a/src/routes/(console)/organization-[organization]/billing/deleteOrgPayment.svelte +++ b/src/routes/(console)/organization-[organization]/billing/deleteOrgPayment.svelte @@ -1,12 +1,12 @@