From 2efc7c25ea22bfb8b9b0aa14c8ada8b8f094f741 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 6 Aug 2025 12:26:13 +0300 Subject: [PATCH 1/2] feat(clerk-js, types): Update billing resources with trial properties --- .changeset/sour-lemons-talk.md | 6 ++++++ .../core/resources/CommerceSubscription.ts | 5 +++++ packages/types/src/commerce.ts | 19 +++++++++++++++++++ packages/types/src/json.ts | 2 ++ 4 files changed, 32 insertions(+) create mode 100644 .changeset/sour-lemons-talk.md 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 4c852f1d353..bc1d12334fc 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; } } @@ -74,6 +76,7 @@ export class CommerceSubscriptionItem extends BaseResource implements CommerceSu credit?: { amount: CommerceMoney; }; + isFreeTrial = false; constructor(data: CommerceSubscriptionItemJSON) { super(); @@ -103,6 +106,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 = data.is_free_trial; return this; } diff --git a/packages/types/src/commerce.ts b/packages/types/src/commerce.ts index 3ae559e3c23..113bca2836a 100644 --- a/packages/types/src/commerce.ts +++ b/packages/types/src/commerce.ts @@ -1106,6 +1106,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; } /** @@ -1215,6 +1224,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 11dd4760797..6fbe4107427 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -780,6 +780,7 @@ export interface CommerceSubscriptionItemJSON extends ClerkResourceJSON { period_end: number; canceled_at: number | null; past_due_at: number | null; + is_free_trial: boolean; } /** @@ -809,6 +810,7 @@ export interface CommerceSubscriptionJSON extends ClerkResourceJSON { updated_at: number | null; past_due_at: number | null; subscription_items: CommerceSubscriptionItemJSON[] | null; + eligible_for_free_trial?: boolean; } /** From d4aac9c11cae0741662033ff9c13c913961ba6f0 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Tue, 12 Aug 2025 14:04:31 +0300 Subject: [PATCH 2/2] update bundlewatch.config.json --- packages/clerk-js/bundlewatch.config.json | 2 +- packages/clerk-js/src/core/resources/CommerceSubscription.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/clerk-js/bundlewatch.config.json b/packages/clerk-js/bundlewatch.config.json index 55893738a3c..9b99c347109 100644 --- a/packages/clerk-js/bundlewatch.config.json +++ b/packages/clerk-js/bundlewatch.config.json @@ -3,7 +3,7 @@ { "path": "./dist/clerk.js", "maxSize": "621KB" }, { "path": "./dist/clerk.browser.js", "maxSize": "75KB" }, { "path": "./dist/clerk.legacy.browser.js", "maxSize": "117KB" }, - { "path": "./dist/clerk.headless*.js", "maxSize": "57KB" }, + { "path": "./dist/clerk.headless*.js", "maxSize": "57.02KB" }, { "path": "./dist/ui-common*.js", "maxSize": "113KB" }, { "path": "./dist/ui-common*.legacy.*.js", "maxSize": "118KB" }, { "path": "./dist/vendors*.js", "maxSize": "40.2KB" }, diff --git a/packages/clerk-js/src/core/resources/CommerceSubscription.ts b/packages/clerk-js/src/core/resources/CommerceSubscription.ts index bc1d12334fc..dd4a780fc8c 100644 --- a/packages/clerk-js/src/core/resources/CommerceSubscription.ts +++ b/packages/clerk-js/src/core/resources/CommerceSubscription.ts @@ -107,7 +107,7 @@ 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 = data.is_free_trial; + this.isFreeTrial = this.withDefault(data.is_free_trial, false); return this; }