Skip to content

Commit 10e1060

Browse files
authored
chore(clerk-js,types): Replace payerType[] with forPayerType (#6342)
1 parent 35da3e8 commit 10e1060

File tree

8 files changed

+23
-41
lines changed

8 files changed

+23
-41
lines changed

.changeset/proud-pianos-attack.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
[Billing Beta] Replace `payerType[]` with `forPayerType` typed as `'org' | 'user'`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
3232
"types/commerce-initialized-payment-source-resource.mdx",
3333
"types/commerce-money-json.mdx",
3434
"types/commerce-money.mdx",
35+
"types/commerce-payer-type.mdx",
3536
"types/commerce-payment-charge-type.mdx",
3637
"types/commerce-payment-json.mdx",
3738
"types/commerce-payment-resource.mdx",
@@ -51,7 +52,6 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
5152
"types/commerce-statement-status.mdx",
5253
"types/commerce-statement-totals-json.mdx",
5354
"types/commerce-statement-totals.mdx",
54-
"types/commerce-subscriber-type.mdx",
5555
"types/commerce-subscription-json.mdx",
5656
"types/commerce-subscription-plan-period.mdx",
5757
"types/commerce-subscription-resource.mdx",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CommercePlanJSON, CommercePlanJSONSnapshot, CommercePlanResource } from '@clerk/types';
1+
import type { CommercePayerType, CommercePlanJSON, CommercePlanJSONSnapshot, CommercePlanResource } from '@clerk/types';
22

33
import { BaseResource, CommerceFeature } from './internal';
44

@@ -17,7 +17,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
1717
isDefault!: boolean;
1818
isRecurring!: boolean;
1919
hasBaseFee!: boolean;
20-
payerType!: string[];
20+
forPayerType!: CommercePayerType;
2121
publiclyVisible!: boolean;
2222
slug!: string;
2323
avatarUrl!: string;
@@ -47,7 +47,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
4747
this.isDefault = data.is_default;
4848
this.isRecurring = data.is_recurring;
4949
this.hasBaseFee = data.has_base_fee;
50-
this.payerType = data.payer_type;
50+
this.forPayerType = data.for_payer_type;
5151
this.publiclyVisible = data.publicly_visible;
5252
this.slug = data.slug;
5353
this.avatarUrl = data.avatar_url;
@@ -73,7 +73,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
7373
is_default: this.isDefault,
7474
is_recurring: this.isRecurring,
7575
has_base_fee: this.hasBaseFee,
76-
payer_type: this.payerType,
76+
for_payer_type: this.forPayerType,
7777
publicly_visible: this.publiclyVisible,
7878
slug: this.slug,
7979
avatar_url: this.avatarUrl,

packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const PlanDetailsInternal = ({
5858
const hasFeatures = features.length > 0;
5959

6060
return (
61-
<SubscriberTypeContext.Provider value={plan.payerType[0] as 'user' | 'org'}>
61+
<SubscriberTypeContext.Provider value={plan.forPayerType}>
6262
<Drawer.Header
6363
sx={t =>
6464
!hasFeatures

packages/clerk-js/src/ui/contexts/components/SubscriberType.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { CommercePayerType } from '@clerk/types';
12
import { createContext, useContext } from 'react';
23

34
const DEFAUlT = 'user';
4-
export const SubscriberTypeContext = createContext<'user' | 'org' | undefined>(DEFAUlT);
5+
export const SubscriberTypeContext = createContext<CommercePayerType | undefined>(DEFAUlT);
56

6-
export const useSubscriberTypeContext = () => useContext(SubscriberTypeContext) || DEFAUlT;
7+
export const useSubscriberTypeContext = (): CommercePayerType => useContext(SubscriberTypeContext) || DEFAUlT;
78

89
export const useSubscriberTypeLocalizationRoot = () => {
910
const subscriberType = useSubscriberTypeContext();

packages/types/src/clerk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import type { ClientResource } from './client';
2323
import type {
2424
CommerceBillingNamespace,
2525
CommerceCheckoutResource,
26+
CommercePayerType,
2627
CommercePlanResource,
27-
CommerceSubscriberType,
2828
CommerceSubscriptionPlanPeriod,
2929
ConfirmCheckoutParams,
3030
} from './commerce';
@@ -1806,7 +1806,7 @@ export type __internal_CheckoutProps = {
18061806
appearance?: CheckoutTheme;
18071807
planId?: string;
18081808
planPeriod?: CommerceSubscriptionPlanPeriod;
1809-
subscriberType?: CommerceSubscriberType;
1809+
subscriberType?: CommercePayerType;
18101810
onSubscriptionComplete?: () => void;
18111811
portalId?: string;
18121812
portalRoot?: PortalRoot;
@@ -1843,7 +1843,7 @@ export type __internal_SubscriptionDetailsProps = {
18431843
* If `org` is provided, the subscription details will be displayed for the active organization.
18441844
* @default 'user'
18451845
*/
1846-
for?: CommerceSubscriberType;
1846+
for?: CommercePayerType;
18471847
appearance?: SubscriptionDetailsTheme;
18481848
onSubscriptionCancel?: () => void;
18491849
portalId?: string;

packages/types/src/commerce.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export interface CommerceBillingNamespace {
8585
* <ClerkProvider clerkJsVersion="x.x.x" />
8686
* ```
8787
*/
88-
export type CommerceSubscriberType = 'org' | 'user';
88+
export type CommercePayerType = 'org' | 'user';
8989

9090
/**
9191
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
@@ -214,7 +214,7 @@ export type GetPlansParams = ClerkPaginationParams<{
214214
* <ClerkProvider clerkJsVersion="x.x.x" />
215215
* ```
216216
*/
217-
for?: CommerceSubscriberType;
217+
for?: CommercePayerType;
218218
}>;
219219

220220
/**
@@ -356,18 +356,8 @@ export interface CommercePlanResource extends ClerkResource {
356356
*
357357
* Each plan is exclusively created for either individual users or organizations,
358358
* and cannot be used interchangeably.
359-
*
360-
* @type {['user'] | ['org']}
361-
* @example
362-
* ```ts
363-
* // For a user plan
364-
* payerType: ['user']
365-
*
366-
* // For an organization plan
367-
* payerType: ['org']
368-
* ```
369359
*/
370-
payerType: string[];
360+
forPayerType: CommercePayerType;
371361
/**
372362
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
373363
* It is advised to pin the SDK version and the clerk-js version to a specific version to avoid breaking changes.

packages/types/src/json.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import type { APIKeysSettingsJSON } from './apiKeysSettings';
66
import type {
7+
CommercePayerType,
78
CommercePaymentChargeType,
89
CommercePaymentSourceStatus,
910
CommercePaymentStatus,
@@ -643,23 +644,7 @@ export interface CommercePlanJSON extends ClerkResourceJSON {
643644
is_default: boolean;
644645
is_recurring: boolean;
645646
has_base_fee: boolean;
646-
/**
647-
* Specifies the subscriber type this plan is designed for.
648-
*
649-
* Each plan is exclusively created for either individual users or organizations,
650-
* and cannot be used interchangeably.
651-
*
652-
* @type {['user'] | ['org']}
653-
* @example
654-
* ```ts
655-
* // For a user plan
656-
* payer_type: ['user']
657-
*
658-
* // For an organization plan
659-
* payer_type: ['org']
660-
* ```
661-
*/
662-
payer_type: string[];
647+
for_payer_type: CommercePayerType;
663648
publicly_visible: boolean;
664649
slug: string;
665650
avatar_url: string;

0 commit comments

Comments
 (0)