Skip to content

Commit 45e8298

Browse files
feat(clerk-js, shared, types, clerk-react): Mark commerce apis as stable (#5833)
Co-authored-by: panteliselef <panteliselef@outlook.com>
1 parent c15a412 commit 45e8298

105 files changed

Lines changed: 722 additions & 788 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/better-streets-sort.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/tanstack-react-start': minor
3+
'@clerk/chrome-extension': minor
4+
'@clerk/react-router': minor
5+
'@clerk/nextjs': minor
6+
'@clerk/clerk-react': minor
7+
'@clerk/clerk-expo': minor
8+
---
9+
10+
Export a new `<PricingTable />` component. This component renders plans for user or organizations and upon selection the end-user is prompted with a checkout form.

.changeset/social-tables-cover.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@clerk/tanstack-react-start': minor
3+
'@clerk/chrome-extension': minor
4+
'@clerk/react-router': minor
5+
'@clerk/clerk-js': minor
6+
'@clerk/nextjs': minor
7+
'@clerk/shared': minor
8+
'@clerk/clerk-react': minor
9+
'@clerk/types': minor
10+
'@clerk/clerk-expo': minor
11+
'@clerk/remix': minor
12+
---
13+
14+
Mark commerce apis as stable

.changeset/witty-doors-hear.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/clerk-react': minor
4+
'@clerk/types': minor
5+
---
6+
7+
Expose stable commerce stable apis under `Clerk.commerce`
8+
9+
## Render the pricing table component
10+
- `Clerk.mountPricingTable`
11+
- `Clerk.unmountPricingTable`
12+
13+
## Commerce namespace
14+
- `Clerk.commerce.initializePaymentSource()`
15+
- `Clerk.commerce.addPaymentSource()`
16+
- `Clerk.commerce.getPaymentSources()`
17+
- `Clerk.commerce.billing`
18+
- `Clerk.commerce.billing.getPlans()`
19+
- `Clerk.commerce.billing.getSubscriptions()`
20+
- `Clerk.commerce.billing.getInvoices()`
21+
- `Clerk.commerce.billing.startCheckout()`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<template>
2-
<experimental_PricingTable />
2+
<PricingTable />
33
</template>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
2-
import { experimental_PricingTable } from '@clerk/vue';
2+
import { PricingTable } from '@clerk/vue';
33
</script>
44

55
<template>
6-
<experimental_PricingTable />
6+
<PricingTable />
77
</template>

packages/clerk-js/sandbox/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void (async () => {
308308
});
309309
},
310310
'/pricing-table': () => {
311-
Clerk.__experimental_mountPricingTable(app, componentControls.pricingTable.getProps() ?? {});
311+
Clerk.mountPricingTable(app, componentControls.pricingTable.getProps() ?? {});
312312
},
313313
'/open-sign-in': () => {
314314
mountOpenSignInButton(app, componentControls.signIn.getProps() ?? {});

packages/clerk-js/src/core/clerk.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@ import {
1515
import { addClerkPrefix, isAbsoluteUrl, stripScheme } from '@clerk/shared/url';
1616
import { allSettled, handleValueOrFn, noop } from '@clerk/shared/utils';
1717
import type {
18-
__experimental_CheckoutProps,
19-
__experimental_CommerceNamespace,
20-
__experimental_PlanDetailsProps,
2118
__internal_ComponentNavigationContext,
2219
__internal_UserVerificationModalProps,
2320
AuthenticateWithCoinbaseWalletParams,
2421
AuthenticateWithGoogleOneTapParams,
2522
AuthenticateWithMetamaskParams,
2623
AuthenticateWithOKXWalletParams,
24+
CheckoutProps,
2725
Clerk as ClerkInterface,
2826
ClerkAPIError,
2927
ClerkAuthenticateWithWeb3Params,
3028
ClerkOptions,
3129
ClientJSONSnapshot,
3230
ClientResource,
31+
CommerceNamespace,
3332
CreateOrganizationParams,
3433
CreateOrganizationProps,
3534
CredentialReturn,
@@ -50,6 +49,7 @@ import type {
5049
OrganizationResource,
5150
OrganizationSwitcherProps,
5251
PendingSessionResource,
52+
PlanDetailsProps,
5353
PricingTableProps,
5454
PublicKeyCredentialCreationOptionsWithoutExtensions,
5555
PublicKeyCredentialRequestOptionsWithoutExtensions,
@@ -131,7 +131,7 @@ import { eventBus, events } from './events';
131131
import type { FapiClient, FapiRequestCallback } from './fapiClient';
132132
import { createFapiClient } from './fapiClient';
133133
import { createClientFromJwt } from './jwt-client';
134-
import { __experimental_Commerce } from './modules/commerce';
134+
import { Commerce } from './modules/commerce';
135135
import {
136136
BaseResource,
137137
Client,
@@ -187,7 +187,7 @@ export class Clerk implements ClerkInterface {
187187
version: __PKG_VERSION__,
188188
environment: process.env.NODE_ENV || 'production',
189189
};
190-
private static _commerce: __experimental_CommerceNamespace;
190+
private static _commerce: CommerceNamespace;
191191

192192
public client: ClientResource | undefined;
193193
public session: SignedInSessionResource | null | undefined;
@@ -316,9 +316,9 @@ export class Clerk implements ClerkInterface {
316316
return this.#options.standardBrowser || false;
317317
}
318318

319-
get __experimental_commerce(): __experimental_CommerceNamespace {
319+
get commerce(): CommerceNamespace {
320320
if (!Clerk._commerce) {
321-
Clerk._commerce = new __experimental_Commerce();
321+
Clerk._commerce = new Commerce();
322322
}
323323
return Clerk._commerce;
324324
}
@@ -546,7 +546,7 @@ export class Clerk implements ClerkInterface {
546546
void this.#componentControls.ensureMounted().then(controls => controls.closeModal('signIn'));
547547
};
548548

549-
public __internal_openCheckout = (props?: __experimental_CheckoutProps): void => {
549+
public __internal_openCheckout = (props?: CheckoutProps): void => {
550550
this.assertComponentsReady(this.#componentControls);
551551
if (disabledBillingFeature(this, this.environment)) {
552552
if (this.#instanceType === 'development') {
@@ -575,7 +575,7 @@ export class Clerk implements ClerkInterface {
575575
void this.#componentControls.ensureMounted().then(controls => controls.closeDrawer('checkout'));
576576
};
577577

578-
public __internal_openPlanDetails = (props?: __experimental_PlanDetailsProps): void => {
578+
public __internal_openPlanDetails = (props?: PlanDetailsProps): void => {
579579
this.assertComponentsReady(this.#componentControls);
580580
if (disabledBillingFeature(this, this.environment)) {
581581
if (this.#instanceType === 'development') {
@@ -1006,7 +1006,7 @@ export class Clerk implements ClerkInterface {
10061006
void this.#componentControls?.ensureMounted().then(controls => controls.unmountComponent({ node }));
10071007
};
10081008

1009-
public __experimental_mountPricingTable = (node: HTMLDivElement, props?: PricingTableProps): void => {
1009+
public mountPricingTable = (node: HTMLDivElement, props?: PricingTableProps): void => {
10101010
this.assertComponentsReady(this.#componentControls);
10111011
if (disabledBillingFeature(this, this.environment)) {
10121012
if (this.#instanceType === 'development') {
@@ -1028,7 +1028,7 @@ export class Clerk implements ClerkInterface {
10281028
this.telemetry?.record(eventPrebuiltComponentMounted('PricingTable', props));
10291029
};
10301030

1031-
public __experimental_unmountPricingTable = (node: HTMLDivElement): void => {
1031+
public unmountPricingTable = (node: HTMLDivElement): void => {
10321032
this.assertComponentsReady(this.#componentControls);
10331033
void this.#componentControls.ensureMounted().then(controls =>
10341034
controls.unmountComponent({

packages/clerk-js/src/core/modules/commerce/Commerce.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
import type {
2-
__experimental_AddPaymentSourceParams,
3-
__experimental_CommerceBillingNamespace,
4-
__experimental_CommerceInitializedPaymentSourceJSON,
5-
__experimental_CommerceNamespace,
6-
__experimental_CommercePaymentSourceJSON,
7-
__experimental_GetPaymentSourcesParams,
8-
__experimental_InitializePaymentSourceParams,
2+
AddPaymentSourceParams,
93
ClerkPaginatedResponse,
4+
CommerceBillingNamespace,
5+
CommerceInitializedPaymentSourceJSON,
6+
CommerceNamespace,
7+
CommercePaymentSourceJSON,
8+
GetPaymentSourcesParams,
9+
InitializePaymentSourceParams,
1010
} from '@clerk/types';
1111

1212
import { convertPageToOffsetSearchParams } from '../../../utils/convertPageToOffsetSearchParams';
13-
import {
14-
__experimental_CommerceInitializedPaymentSource,
15-
__experimental_CommercePaymentSource,
16-
BaseResource,
17-
} from '../../resources/internal';
18-
import { __experimental_CommerceBilling } from './CommerceBilling';
13+
import { BaseResource, CommerceInitializedPaymentSource, CommercePaymentSource } from '../../resources/internal';
14+
import { CommerceBilling } from './CommerceBilling';
1915

20-
export class __experimental_Commerce implements __experimental_CommerceNamespace {
21-
private static _billing: __experimental_CommerceBillingNamespace;
16+
export class Commerce implements CommerceNamespace {
17+
private static _billing: CommerceBillingNamespace;
2218

23-
get __experimental_billing(): __experimental_CommerceBillingNamespace {
24-
if (!__experimental_Commerce._billing) {
25-
__experimental_Commerce._billing = new __experimental_CommerceBilling();
19+
get billing(): CommerceBillingNamespace {
20+
if (!Commerce._billing) {
21+
Commerce._billing = new CommerceBilling();
2622
}
27-
return __experimental_Commerce._billing;
23+
return Commerce._billing;
2824
}
2925

30-
initializePaymentSource = async (params: __experimental_InitializePaymentSourceParams) => {
26+
initializePaymentSource = async (params: InitializePaymentSourceParams) => {
3127
const { orgId, ...rest } = params;
3228
const json = (
3329
await BaseResource._fetch({
@@ -37,11 +33,11 @@ export class __experimental_Commerce implements __experimental_CommerceNamespace
3733
method: 'POST',
3834
body: rest as any,
3935
})
40-
)?.response as unknown as __experimental_CommerceInitializedPaymentSourceJSON;
41-
return new __experimental_CommerceInitializedPaymentSource(json);
36+
)?.response as unknown as CommerceInitializedPaymentSourceJSON;
37+
return new CommerceInitializedPaymentSource(json);
4238
};
4339

44-
addPaymentSource = async (params: __experimental_AddPaymentSourceParams) => {
40+
addPaymentSource = async (params: AddPaymentSourceParams) => {
4541
const { orgId, ...rest } = params;
4642

4743
const json = (
@@ -50,11 +46,11 @@ export class __experimental_Commerce implements __experimental_CommerceNamespace
5046
method: 'POST',
5147
body: rest as any,
5248
})
53-
)?.response as unknown as __experimental_CommercePaymentSourceJSON;
54-
return new __experimental_CommercePaymentSource(json);
49+
)?.response as unknown as CommercePaymentSourceJSON;
50+
return new CommercePaymentSource(json);
5551
};
5652

57-
getPaymentSources = async (params: __experimental_GetPaymentSourcesParams) => {
53+
getPaymentSources = async (params: GetPaymentSourcesParams) => {
5854
const { orgId, ...rest } = params;
5955

6056
return await BaseResource._fetch({
@@ -63,10 +59,10 @@ export class __experimental_Commerce implements __experimental_CommerceNamespace
6359
search: convertPageToOffsetSearchParams(rest),
6460
}).then(res => {
6561
const { data: paymentSources, total_count } =
66-
res?.response as unknown as ClerkPaginatedResponse<__experimental_CommercePaymentSourceJSON>;
62+
res?.response as unknown as ClerkPaginatedResponse<CommercePaymentSourceJSON>;
6763
return {
6864
total_count,
69-
data: paymentSources.map(paymentSource => new __experimental_CommercePaymentSource(paymentSource)),
65+
data: paymentSources.map(paymentSource => new CommercePaymentSource(paymentSource)),
7066
};
7167
});
7268
};
Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import type {
2-
__experimental_CommerceBillingNamespace,
3-
__experimental_CommerceCheckoutJSON,
4-
__experimental_CommerceInvoiceJSON,
5-
__experimental_CommerceInvoiceResource,
6-
__experimental_CommercePlanResource,
7-
__experimental_CommerceProductJSON,
8-
__experimental_CommerceSubscriptionJSON,
9-
__experimental_CommerceSubscriptionResource,
10-
__experimental_CreateCheckoutParams,
11-
__experimental_GetInvoicesParams,
12-
__experimental_GetPlansParams,
13-
__experimental_GetSubscriptionsParams,
142
ClerkPaginatedResponse,
3+
CommerceBillingNamespace,
4+
CommerceCheckoutJSON,
5+
CommerceInvoiceJSON,
6+
CommerceInvoiceResource,
7+
CommercePlanResource,
8+
CommerceProductJSON,
9+
CommerceSubscriptionJSON,
10+
CommerceSubscriptionResource,
11+
CreateCheckoutParams,
12+
GetInvoicesParams,
13+
GetPlansParams,
14+
GetSubscriptionsParams,
1515
} from '@clerk/types';
1616

1717
import { convertPageToOffsetSearchParams } from '../../../utils/convertPageToOffsetSearchParams';
1818
import {
19-
__experimental_CommerceCheckout,
20-
__experimental_CommerceInvoice,
21-
__experimental_CommercePlan,
22-
__experimental_CommerceSubscription,
2319
BaseResource,
20+
CommerceCheckout,
21+
CommerceInvoice,
22+
CommercePlan,
23+
CommerceSubscription,
2424
} from '../../resources/internal';
2525

26-
export class __experimental_CommerceBilling implements __experimental_CommerceBillingNamespace {
27-
getPlans = async (params?: __experimental_GetPlansParams): Promise<__experimental_CommercePlanResource[]> => {
26+
export class CommerceBilling implements CommerceBillingNamespace {
27+
getPlans = async (params?: GetPlansParams): Promise<CommercePlanResource[]> => {
2828
const { data: products } = (await BaseResource._fetch({
2929
path: `/commerce/products`,
3030
method: 'GET',
3131
search: { payerType: params?.subscriberType || '' },
32-
})) as unknown as ClerkPaginatedResponse<__experimental_CommerceProductJSON>;
32+
})) as unknown as ClerkPaginatedResponse<CommerceProductJSON>;
3333

3434
const defaultProduct = products.find(product => product.is_default);
35-
return defaultProduct?.plans.map(plan => new __experimental_CommercePlan(plan)) || [];
35+
return defaultProduct?.plans.map(plan => new CommercePlan(plan)) || [];
3636
};
3737

3838
getSubscriptions = async (
39-
params: __experimental_GetSubscriptionsParams,
40-
): Promise<ClerkPaginatedResponse<__experimental_CommerceSubscriptionResource>> => {
39+
params: GetSubscriptionsParams,
40+
): Promise<ClerkPaginatedResponse<CommerceSubscriptionResource>> => {
4141
const { orgId, ...rest } = params;
4242

4343
return await BaseResource._fetch({
@@ -46,45 +46,42 @@ export class __experimental_CommerceBilling implements __experimental_CommerceBi
4646
search: convertPageToOffsetSearchParams(rest),
4747
}).then(res => {
4848
const { data: subscriptions, total_count } =
49-
res?.response as unknown as ClerkPaginatedResponse<__experimental_CommerceSubscriptionJSON>;
49+
res?.response as unknown as ClerkPaginatedResponse<CommerceSubscriptionJSON>;
5050

5151
return {
5252
total_count,
53-
data: subscriptions.map(subscription => new __experimental_CommerceSubscription(subscription)),
53+
data: subscriptions.map(subscription => new CommerceSubscription(subscription)),
5454
};
5555
});
5656
};
5757

58-
getInvoices = async (
59-
params: __experimental_GetInvoicesParams,
60-
): Promise<ClerkPaginatedResponse<__experimental_CommerceInvoiceResource>> => {
58+
getInvoices = async (params: GetInvoicesParams): Promise<ClerkPaginatedResponse<CommerceInvoiceResource>> => {
6159
const { orgId, ...rest } = params;
6260

6361
return await BaseResource._fetch({
6462
path: orgId ? `/organizations/${orgId}/commerce/invoices` : `/me/commerce/invoices`,
6563
method: 'GET',
6664
search: convertPageToOffsetSearchParams(rest),
6765
}).then(res => {
68-
const { data: invoices, total_count } =
69-
res?.response as unknown as ClerkPaginatedResponse<__experimental_CommerceInvoiceJSON>;
66+
const { data: invoices, total_count } = res?.response as unknown as ClerkPaginatedResponse<CommerceInvoiceJSON>;
7067

7168
return {
7269
total_count,
73-
data: invoices.map(invoice => new __experimental_CommerceInvoice(invoice)),
70+
data: invoices.map(invoice => new CommerceInvoice(invoice)),
7471
};
7572
});
7673
};
7774

78-
startCheckout = async (params: __experimental_CreateCheckoutParams) => {
75+
startCheckout = async (params: CreateCheckoutParams) => {
7976
const { orgId, ...rest } = params;
8077
const json = (
81-
await BaseResource._fetch<__experimental_CommerceCheckoutJSON>({
78+
await BaseResource._fetch<CommerceCheckoutJSON>({
8279
path: orgId ? `/organizations/${orgId}/commerce/checkouts` : `/me/commerce/checkouts`,
8380
method: 'POST',
8481
body: rest as any,
8582
})
86-
)?.response as unknown as __experimental_CommerceCheckoutJSON;
83+
)?.response as unknown as CommerceCheckoutJSON;
8784

88-
return new __experimental_CommerceCheckout(json, orgId);
85+
return new CommerceCheckout(json, orgId);
8986
};
9087
}

0 commit comments

Comments
 (0)