@@ -2,7 +2,7 @@ import { page } from '$app/stores';
2
2
import { derived , get , writable } from 'svelte/store' ;
3
3
import { sdk } from './sdk' ;
4
4
import { organization , type Organization } from './organization' ;
5
- import type { InvoiceList , AddressesList , Invoice , PaymentList , PlansInfo } from '$lib/sdk/billing' ;
5
+ import type { InvoiceList , AddressesList , Invoice , PaymentList , PlansMap } from '$lib/sdk/billing' ;
6
6
import { isCloud } from '$lib/system' ;
7
7
import { cachedStore } from '$lib/helpers/cache' ;
8
8
import { Query , type Models } from '@appwrite.io/console' ;
@@ -15,22 +15,23 @@ import { base } from '$app/paths';
15
15
import TooManyFreOrgs from '$lib/components/billing/alerts/tooManyFreeOrgs.svelte' ;
16
16
import { activeHeaderAlert , showPostReleaseModal } from '$routes/console/store' ;
17
17
import MarkedForDeletion from '$lib/components/billing/alerts/markedForDeletion.svelte' ;
18
+ import { BillingPlan } from '$lib/constants' ;
18
19
19
20
export type Tier = 'tier-0' | 'tier-1' | 'tier-2' ;
20
21
21
22
export const paymentMethods = derived ( page , ( $page ) => $page . data . paymentMethods as PaymentList ) ;
22
23
export const addressList = derived ( page , ( $page ) => $page . data . addressList as AddressesList ) ;
23
- export const plansInfo = derived ( page , ( $page ) => $page . data . plansInfo as PlansInfo ) ;
24
+ export const plansInfo = derived ( page , ( $page ) => $page . data . plansInfo as PlansMap ) ;
24
25
export const daysLeftInTrial = writable < number > ( 0 ) ;
25
26
export const readOnly = writable < boolean > ( false ) ;
26
27
27
28
export function tierToPlan ( tier : Tier ) {
28
29
switch ( tier ) {
29
- case 'tier-0' :
30
+ case BillingPlan . STARTER :
30
31
return tierFree ;
31
- case 'tier-1' :
32
+ case BillingPlan . PRO :
32
33
return tierPro ;
33
- case 'tier-2' :
34
+ case BillingPlan . SCALE :
34
35
return tierScale ;
35
36
default :
36
37
return tierFree ;
@@ -63,8 +64,8 @@ export function getServiceLimit(serviceId: PlanServices, tier: Tier = null): num
63
64
if ( ! isCloud ) return 0 ;
64
65
if ( ! serviceId ) return 0 ;
65
66
const info = get ( plansInfo ) ;
66
- if ( ! info ?. plans ) return 0 ;
67
- const plan = info . plans . find ( ( p ) => p . $id === ( tier ?? get ( organization ) ?. billingPlan ) ) ;
67
+ if ( ! info ) return 0 ;
68
+ const plan = info . get ( tier ?? get ( organization ) ?. billingPlan ) ;
68
69
return plan ?. [ serviceId ] ;
69
70
}
70
71
@@ -117,7 +118,7 @@ export const tierScale: TierData = {
117
118
export const showUsageRatesModal = writable < boolean > ( false ) ;
118
119
119
120
export function checkForUsageFees ( plan : Tier , id : PlanServices ) {
120
- if ( plan === 'tier-1' || plan === 'tier-2' ) {
121
+ if ( plan === BillingPlan . PRO || plan === BillingPlan . SCALE ) {
121
122
switch ( id ) {
122
123
case 'bandwidth' :
123
124
case 'storage' :
@@ -157,7 +158,7 @@ export function isServiceLimited(serviceId: PlanServices, plan: Tier, total: num
157
158
}
158
159
159
160
export function calculateTrialDay ( org : Organization ) {
160
- if ( org ?. billingPlan === 'tier-0' ) return false ;
161
+ if ( org ?. billingPlan === BillingPlan . STARTER ) return false ;
161
162
const endDate = new Date ( org ?. billingStartDate ) ;
162
163
const today = new Date ( ) ;
163
164
const days = diffDays ( today , endDate ) ;
@@ -190,7 +191,7 @@ export async function checkForUsageLimit(org: Organization) {
190
191
}
191
192
const { bandwidth, documents, executions, storage, users } = org ?. billingLimits ?? { } ;
192
193
const members = await sdk . forConsole . teams . listMemberships ( org . $id ) ;
193
- const plan = get ( plansInfo ) . plans . find ( ( plan ) => plan . $id === org . billingPlan ) ;
194
+ const plan = get ( plansInfo ) ?. get ( org . billingPlan ) ;
194
195
const membersOverflow =
195
196
members ?. total > plan . members ? members . total - ( plan . members || members . total ) : 0 ;
196
197
@@ -207,7 +208,7 @@ export async function checkForUsageLimit(org: Organization) {
207
208
}
208
209
209
210
export async function checkPaymentAuthorizationRequired ( org : Organization ) {
210
- if ( org . billingPlan === 'tier-0' ) return ;
211
+ if ( org . billingPlan === BillingPlan . STARTER ) return ;
211
212
212
213
const invoices = await sdk . forConsole . billing . listInvoices ( org . $id , [
213
214
Query . equal ( 'status' , 'requires_authentication' )
0 commit comments