Skip to content

Commit 1ad3b92

Browse files
authored
chore(backend): Rename commerce resources to billing resources (#6812)
1 parent a48de44 commit 1ad3b92

File tree

10 files changed

+124
-119
lines changed

10 files changed

+124
-119
lines changed

.changeset/tricky-moments-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': minor
3+
---
4+
5+
[Billing Beta] Rename types and classes that contain commerce to use billing instead.

.typedoc/__tests__/__snapshots__/file-structure.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
235235
"backend/allowlist-identifier.mdx",
236236
"backend/auth-object.mdx",
237237
"backend/authenticate-request-options.mdx",
238+
"backend/billing-payment-attempt-webhook-event-json.mdx",
239+
"backend/billing-plan-json.mdx",
240+
"backend/billing-plan.mdx",
241+
"backend/billing-subscription-item-json.mdx",
242+
"backend/billing-subscription-item-webhook-event-json.mdx",
243+
"backend/billing-subscription-item.mdx",
244+
"backend/billing-subscription-webhook-event-json.mdx",
245+
"backend/billing-subscription.mdx",
238246
"backend/client.mdx",
239-
"backend/commerce-payment-attempt-webhook-event-json.mdx",
240-
"backend/commerce-plan-json.mdx",
241-
"backend/commerce-plan.mdx",
242-
"backend/commerce-subscription-item-json.mdx",
243-
"backend/commerce-subscription-item-webhook-event-json.mdx",
244-
"backend/commerce-subscription-item.mdx",
245-
"backend/commerce-subscription-webhook-event-json.mdx",
246-
"backend/commerce-subscription.mdx",
247247
"backend/email-address.mdx",
248248
"backend/external-account.mdx",
249249
"backend/feature.mdx",

packages/backend/src/api/endpoints/BillingApi.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ClerkPaginationRequest } from '@clerk/types';
22

33
import { joinPaths } from '../../util/path';
4-
import type { CommercePlan } from '../resources/CommercePlan';
5-
import type { CommerceSubscription } from '../resources/CommerceSubscription';
6-
import type { CommerceSubscriptionItem } from '../resources/CommerceSubscriptionItem';
4+
import type { BillingPlan } from '../resources/CommercePlan';
5+
import type { BillingSubscription } from '../resources/CommerceSubscription';
6+
import type { BillingSubscriptionItem } from '../resources/CommerceSubscriptionItem';
77
import type { PaginatedResourceResponse } from '../resources/Deserializer';
88
import { AbstractAPI } from './AbstractApi';
99

@@ -36,7 +36,7 @@ export class BillingAPI extends AbstractAPI {
3636
* @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](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
3737
*/
3838
public async getPlanList(params?: GetOrganizationListParams) {
39-
return this.request<PaginatedResourceResponse<CommercePlan[]>>({
39+
return this.request<PaginatedResourceResponse<BillingPlan[]>>({
4040
method: 'GET',
4141
path: joinPaths(basePath, 'plans'),
4242
queryParams: params,
@@ -48,7 +48,7 @@ export class BillingAPI extends AbstractAPI {
4848
*/
4949
public async cancelSubscriptionItem(subscriptionItemId: string, params?: CancelSubscriptionItemParams) {
5050
this.requireId(subscriptionItemId);
51-
return this.request<CommerceSubscriptionItem>({
51+
return this.request<BillingSubscriptionItem>({
5252
method: 'DELETE',
5353
path: joinPaths(basePath, 'subscription_items', subscriptionItemId),
5454
queryParams: params,
@@ -63,7 +63,7 @@ export class BillingAPI extends AbstractAPI {
6363
params: ExtendSubscriptionItemFreeTrialParams,
6464
) {
6565
this.requireId(subscriptionItemId);
66-
return this.request<CommerceSubscriptionItem>({
66+
return this.request<BillingSubscriptionItem>({
6767
method: 'POST',
6868
path: joinPaths('/billing', 'subscription_items', subscriptionItemId, 'extend_free_trial'),
6969
bodyParams: params,
@@ -75,7 +75,7 @@ export class BillingAPI extends AbstractAPI {
7575
*/
7676
public async getOrganizationBillingSubscription(organizationId: string) {
7777
this.requireId(organizationId);
78-
return this.request<CommerceSubscription>({
78+
return this.request<BillingSubscription>({
7979
method: 'GET',
8080
path: joinPaths(organizationBasePath, organizationId, 'billing', 'subscription'),
8181
});
@@ -86,7 +86,7 @@ export class BillingAPI extends AbstractAPI {
8686
*/
8787
public async getUserBillingSubscription(userId: string) {
8888
this.requireId(userId);
89-
return this.request<CommerceSubscription>({
89+
return this.request<BillingSubscription>({
9090
method: 'GET',
9191
path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
9292
});

packages/backend/src/api/resources/CommercePlan.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { BillingMoneyAmount } from '@clerk/types';
22

33
import { Feature } from './Feature';
4-
import type { CommercePlanJSON } from './JSON';
4+
import type { BillingPlanJSON } from './JSON';
55

66
/**
7-
* The `CommercePlan` object is similar to the [`BillingPlanResource`](/docs/references/javascript/types/billing-plan-resource) object as it holds information about a plan, as well as methods for managing it. However, the `CommercePlan` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/commerce/get/commerce/plans) and is not directly accessible from the Frontend API.
7+
* The `BillingPlan` object is similar to the [`BillingPlanResource`](/docs/references/javascript/types/billing-plan-resource) object as it holds information about a plan, as well as methods for managing it. However, the `BillingPlan` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/commerce/get/commerce/plans) and is not directly accessible from the Frontend API.
88
*
99
* @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](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
1010
*/
11-
export class CommercePlan {
11+
export class BillingPlan {
1212
constructor(
1313
/**
1414
* The unique identifier for the plan.
@@ -68,16 +68,16 @@ export class CommercePlan {
6868
readonly features: Feature[],
6969
) {}
7070

71-
static fromJSON(data: CommercePlanJSON): CommercePlan {
72-
const formatAmountJSON = (fee: CommercePlanJSON['fee']) => {
71+
static fromJSON(data: BillingPlanJSON): BillingPlan {
72+
const formatAmountJSON = (fee: BillingPlanJSON['fee']) => {
7373
return {
7474
amount: fee.amount,
7575
amountFormatted: fee.amount_formatted,
7676
currency: fee.currency,
7777
currencySymbol: fee.currency_symbol,
7878
};
7979
};
80-
return new CommercePlan(
80+
return new BillingPlan(
8181
data.id,
8282
data.product_id,
8383
data.name,

packages/backend/src/api/resources/CommerceSubscription.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { type BillingMoneyAmount } from '@clerk/types';
1+
import type { BillingMoneyAmount } from '@clerk/types';
22

3-
import { CommerceSubscriptionItem } from './CommerceSubscriptionItem';
4-
import type { CommerceSubscriptionJSON } from './JSON';
3+
import { BillingSubscriptionItem } from './CommerceSubscriptionItem';
4+
import type { BillingSubscriptionJSON } from './JSON';
55

66
/**
7-
* The `CommerceSubscription` object is similar to the [`CommerceSubscriptionResource`](/docs/references/javascript/types/commerce-subscription-resource) object as it holds information about a subscription, as well as methods for managing it. However, the `CommerceSubscription` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/billing/get/organizations/%7Borganization_id%7D/billing/subscription) and is not directly accessible from the Frontend API.
7+
* The `BillingSubscription` object is similar to the [`BillingSubscriptionResource`](/docs/references/javascript/types/commerce-subscription-resource) object as it holds information about a subscription, as well as methods for managing it. However, the `BillingSubscription` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/billing/get/organizations/%7Borganization_id%7D/billing/subscription) and is not directly accessible from the Frontend API.
88
*
99
* @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](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
1010
*/
11-
export class CommerceSubscription {
11+
export class BillingSubscription {
1212
constructor(
1313
/**
14-
* The unique identifier for the commerce subscription.
14+
* The unique identifier for the billing subscription.
1515
*/
1616
readonly id: string,
1717
/**
1818
* The current status of the subscription.
1919
*/
20-
readonly status: CommerceSubscriptionJSON['status'],
20+
readonly status: BillingSubscriptionJSON['status'],
2121
/**
2222
* The ID of the payer for this subscription.
2323
*/
@@ -41,7 +41,7 @@ export class CommerceSubscription {
4141
/**
4242
* Array of subscription items in this subscription.
4343
*/
44-
readonly subscriptionItems: CommerceSubscriptionItem[],
44+
readonly subscriptionItems: BillingSubscriptionItem[],
4545
/**
4646
* Information about the next scheduled payment.
4747
*/
@@ -52,7 +52,7 @@ export class CommerceSubscription {
5252
readonly eligibleForFreeTrial: boolean,
5353
) {}
5454

55-
static fromJSON(data: CommerceSubscriptionJSON): CommerceSubscription {
55+
static fromJSON(data: BillingSubscriptionJSON): BillingSubscription {
5656
const nextPayment = data.next_payment
5757
? {
5858
date: data.next_payment.date,
@@ -65,15 +65,15 @@ export class CommerceSubscription {
6565
}
6666
: null;
6767

68-
return new CommerceSubscription(
68+
return new BillingSubscription(
6969
data.id,
7070
data.status,
7171
data.payer_id,
7272
data.created_at,
7373
data.updated_at,
7474
data.active_at ?? null,
7575
data.past_due_at ?? null,
76-
data.subscription_items.map(item => CommerceSubscriptionItem.fromJSON(item)),
76+
data.subscription_items.map(item => BillingSubscriptionItem.fromJSON(item)),
7777
nextPayment,
7878
data.eligible_for_free_trial ?? false,
7979
);

packages/backend/src/api/resources/CommerceSubscriptionItem.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { BillingMoneyAmount, BillingMoneyAmountJSON } from '@clerk/types';
22

3-
import { CommercePlan } from './CommercePlan';
4-
import type { CommerceSubscriptionItemJSON } from './JSON';
3+
import { BillingPlan } from './CommercePlan';
4+
import type { BillingSubscriptionItemJSON } from './JSON';
55

66
/**
7-
* The `CommerceSubscriptionItem` object is similar to the [`CommerceSubscriptionItemResource`](/docs/references/javascript/types/commerce-subscription-item-resource) object as it holds information about a subscription item, as well as methods for managing it. However, the `CommerceSubscriptionItem` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/commerce/get/commerce/subscription_items) and is not directly accessible from the Frontend API.
7+
* The `BillingSubscriptionItem` object is similar to the [`BillingSubscriptionItemResource`](/docs/references/javascript/types/commerce-subscription-item-resource) object as it holds information about a subscription item, as well as methods for managing it. However, the `BillingSubscriptionItem` object is different in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/commerce/get/commerce/subscription_items) and is not directly accessible from the Frontend API.
88
*
99
* @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](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
1010
*/
11-
export class CommerceSubscriptionItem {
11+
export class BillingSubscriptionItem {
1212
constructor(
1313
/**
1414
* The unique identifier for the subscription item.
@@ -17,7 +17,7 @@ export class CommerceSubscriptionItem {
1717
/**
1818
* The status of the subscription item.
1919
*/
20-
readonly status: CommerceSubscriptionItemJSON['status'],
20+
readonly status: BillingSubscriptionItemJSON['status'],
2121
/**
2222
* The plan period for the subscription item.
2323
*/
@@ -46,7 +46,7 @@ export class CommerceSubscriptionItem {
4646
/**
4747
* The plan associated with this subscription item.
4848
*/
49-
readonly plan: CommercePlan,
49+
readonly plan: BillingPlan,
5050
/**
5151
* The plan ID.
5252
*/
@@ -89,7 +89,7 @@ export class CommerceSubscriptionItem {
8989
readonly lifetimePaid?: BillingMoneyAmount | null,
9090
) {}
9191

92-
static fromJSON(data: CommerceSubscriptionItemJSON): CommerceSubscriptionItem {
92+
static fromJSON(data: BillingSubscriptionItemJSON): BillingSubscriptionItem {
9393
function formatAmountJSON(
9494
amount: BillingMoneyAmountJSON | null | undefined,
9595
): BillingMoneyAmount | null | undefined {
@@ -105,14 +105,14 @@ export class CommerceSubscriptionItem {
105105
};
106106
}
107107

108-
return new CommerceSubscriptionItem(
108+
return new BillingSubscriptionItem(
109109
data.id,
110110
data.status,
111111
data.plan_period,
112112
data.period_start,
113113
data.next_payment,
114114
formatAmountJSON(data.amount),
115-
CommercePlan.fromJSON(data.plan),
115+
BillingPlan.fromJSON(data.plan),
116116
data.plan_id,
117117
data.created_at,
118118
data.updated_at,

packages/backend/src/api/resources/Deserializer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import {
3737
User,
3838
} from '.';
3939
import { AccountlessApplication } from './AccountlessApplication';
40-
import { CommercePlan } from './CommercePlan';
41-
import { CommerceSubscription } from './CommerceSubscription';
42-
import { CommerceSubscriptionItem } from './CommerceSubscriptionItem';
40+
import { BillingPlan } from './CommercePlan';
41+
import { BillingSubscription } from './CommerceSubscription';
42+
import { BillingSubscriptionItem } from './CommerceSubscriptionItem';
4343
import { Feature } from './Feature';
4444
import type { PaginatedResponseJSON } from './JSON';
4545
import { ObjectType } from './JSON';
@@ -183,12 +183,12 @@ function jsonToObject(item: any): any {
183183
return User.fromJSON(item);
184184
case ObjectType.WaitlistEntry:
185185
return WaitlistEntry.fromJSON(item);
186-
case ObjectType.CommercePlan:
187-
return CommercePlan.fromJSON(item);
188-
case ObjectType.CommerceSubscription:
189-
return CommerceSubscription.fromJSON(item);
190-
case ObjectType.CommerceSubscriptionItem:
191-
return CommerceSubscriptionItem.fromJSON(item);
186+
case ObjectType.BillingPlan:
187+
return BillingPlan.fromJSON(item);
188+
case ObjectType.BillingSubscription:
189+
return BillingSubscription.fromJSON(item);
190+
case ObjectType.BillingSubscriptionItem:
191+
return BillingSubscriptionItem.fromJSON(item);
192192
case ObjectType.Feature:
193193
return Feature.fromJSON(item);
194194
default:

0 commit comments

Comments
 (0)