diff --git a/.changeset/sour-lemons-talk.md b/.changeset/sour-lemons-talk.md new file mode 100644 index 00000000000..5bdb616dbdb --- /dev/null +++ b/.changeset/sour-lemons-talk.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': minor +'@clerk/types': minor +--- + +Update billing resources with trial properties. diff --git a/packages/clerk-js/src/core/resources/CommerceSubscription.ts b/packages/clerk-js/src/core/resources/CommerceSubscription.ts index 341b515f968..cef2d451dcd 100644 --- a/packages/clerk-js/src/core/resources/CommerceSubscription.ts +++ b/packages/clerk-js/src/core/resources/CommerceSubscription.ts @@ -27,6 +27,7 @@ export class CommerceSubscription extends BaseResource implements CommerceSubscr date: Date; } | null = null; subscriptionItems!: CommerceSubscriptionItemResource[]; + eligibleForFreeTrial?: boolean; constructor(data: CommerceSubscriptionJSON) { super(); @@ -51,6 +52,7 @@ export class CommerceSubscription extends BaseResource implements CommerceSubscr } : null; this.subscriptionItems = (data.subscription_items || []).map(item => new CommerceSubscriptionItem(item)); + this.eligibleForFreeTrial = data.eligible_for_free_trial; return this; } } @@ -71,6 +73,7 @@ export class CommerceSubscriptionItem extends BaseResource implements CommerceSu credit?: { amount: CommerceMoney; }; + isFreeTrial = false; constructor(data: CommerceSubscriptionItemJSON) { super(); @@ -97,6 +100,8 @@ export class CommerceSubscriptionItem extends BaseResource implements CommerceSu this.amount = data.amount ? commerceMoneyFromJSON(data.amount) : undefined; this.credit = data.credit && data.credit.amount ? { amount: commerceMoneyFromJSON(data.credit.amount) } : undefined; + + this.isFreeTrial = this.withDefault(data.is_free_trial, false); return this; } diff --git a/packages/types/src/commerce.ts b/packages/types/src/commerce.ts index 1b51dd1077c..d5b8e08bddc 100644 --- a/packages/types/src/commerce.ts +++ b/packages/types/src/commerce.ts @@ -1094,6 +1094,15 @@ export interface CommerceSubscriptionItemResource extends ClerkResource { * ``` */ cancel: (params: CancelSubscriptionParams) => Promise; + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. + * It is advised to pin the SDK version and the clerk-js version to a specific version to avoid breaking changes. + * @example + * ```tsx + * + * ``` + */ + isFreeTrial: boolean; } /** @@ -1203,6 +1212,16 @@ export interface CommerceSubscriptionResource extends ClerkResource { * ``` */ updatedAt: Date | null; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. + * It is advised to pin the SDK version and the clerk-js version to a specific version to avoid breaking changes. + * @example + * ```tsx + * + * ``` + */ + eligibleForFreeTrial?: boolean; } /** diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index f7b4fa685fd..93c289b549b 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -783,6 +783,7 @@ export interface CommerceSubscriptionItemJSON extends ClerkResourceJSON { period_end: number | null; canceled_at: number | null; past_due_at: number | null; + is_free_trial: boolean; } /** @@ -812,6 +813,7 @@ export interface CommerceSubscriptionJSON extends ClerkResourceJSON { updated_at: number | null; past_due_at: number | null; subscription_items: CommerceSubscriptionItemJSON[] | null; + eligible_for_free_trial?: boolean; } /**