Add comments

This commit is contained in:
Eric Bailey
2024-10-28 09:57:10 -05:00
parent ce76e81b84
commit 89978efda3
+33 -34
View File
@@ -92,21 +92,52 @@ export enum SubscriptionId {
export type Subscription = export type Subscription =
| { | {
/**
* Using this to discriminate the union
*/
platform: 'android' | 'ios' platform: 'android' | 'ios'
/**
* Bsky internal ID. We map RC products to this for use in the app
*/
id: SubscriptionId id: SubscriptionId
/**
* This is the full ID from whatever store this product was configured in
*/
storeId: string storeId: string
/**
* This is the key needed to fetch the product from the RC SDK. For
* Android, this is the first part of the `storeId` e.g. bsky_tier_0 with
* no `:monthly-annual` suffix
*/
lookupKey: string lookupKey: string
/**
* A value needed to check out. This is useless on native, but on web, this is the `price.id`
*/
checkoutId: string checkoutId: string
/**
* The internal ID that we can use to fetch the subscription. For
* Androi/iOS, we probably won't need this. On web, this is the Stripe
* "subscription item" ID e.g. `si_xxx`
*/
storeSubscriptionIdentifier: string | null
/**
* This is unused on native, on web we fill this in with fetched Stripe
* product data. The price should be in cents, and we localize and format
* this value on the client.
*/
price?: number
/**
* The rest of this is pretty generic
*/
interval: 'monthly' | 'annual' interval: 'monthly' | 'annual'
autoRenew: boolean autoRenew: boolean
storeSubscriptionIdentifier: string | null
provider: RevenueCatSubscription['store'] provider: RevenueCatSubscription['store']
status: RevenueCatSubscription['status'] | null status: RevenueCatSubscription['status'] | null
entitlements: RevenueCatSubscription['entitlements']['items'] entitlements: RevenueCatSubscription['entitlements']['items']
startedAt: RevenueCatSubscription['starts_at'] | null startedAt: RevenueCatSubscription['starts_at'] | null
periodStart: RevenueCatSubscription['current_period_starts_at'] | null periodStart: RevenueCatSubscription['current_period_starts_at'] | null
periodEnd: RevenueCatSubscription['current_period_ends_at'] | null periodEnd: RevenueCatSubscription['current_period_ends_at'] | null
price?: number
} }
| { | {
platform: 'web' platform: 'web'
@@ -126,11 +157,6 @@ export type Subscription =
price: number price: number
} }
export type Subscriptions = {
monthly: Subscription[]
annual: Subscription[]
}
export function getMainSubscriptionProducts( export function getMainSubscriptionProducts(
products: RevenueCatProduct[], products: RevenueCatProduct[],
subscriptions: RevenueCatSubscription[], subscriptions: RevenueCatSubscription[],
@@ -429,30 +455,3 @@ export function normalizeMainSubscriptionProduct({
} }
} }
} }
export function organizeSubscriptionsByMain(
subscriptions: Subscription[],
): Subscriptions {
const result: Subscriptions = {
monthly: [],
annual: [],
}
for (const subscription of subscriptions) {
const {interval} = subscription
result[interval].push(subscription)
}
result.monthly = result.monthly.sort((a, b) => {
const _a = parseInt(a.id.slice(0, 1))
const _b = parseInt(b.id.slice(0, 1))
return _a - _b
})
result.annual = result.annual.sort((a, b) => {
const _a = parseInt(a.id.slice(0, 1))
const _b = parseInt(b.id.slice(0, 1))
return _a - _b
})
return result
}