Skip to content

chore(clerk-js,types): Replace payerType[] with forPayerType #6342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/proud-pianos-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/types': minor
---

[Billing Beta] Replace `payerType[]` with `forPayerType` typed as `'org' | 'user'`.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
"types/commerce-initialized-payment-source-resource.mdx",
"types/commerce-money-json.mdx",
"types/commerce-money.mdx",
"types/commerce-payer-type.mdx",
"types/commerce-payment-charge-type.mdx",
"types/commerce-payment-json.mdx",
"types/commerce-payment-resource.mdx",
Expand All @@ -51,7 +52,6 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
"types/commerce-statement-status.mdx",
"types/commerce-statement-totals-json.mdx",
"types/commerce-statement-totals.mdx",
"types/commerce-subscriber-type.mdx",
"types/commerce-subscription-json.mdx",
"types/commerce-subscription-plan-period.mdx",
"types/commerce-subscription-resource.mdx",
Expand Down
8 changes: 4 additions & 4 deletions packages/clerk-js/src/core/resources/CommercePlan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CommercePlanJSON, CommercePlanJSONSnapshot, CommercePlanResource } from '@clerk/types';
import type { CommercePayerType, CommercePlanJSON, CommercePlanJSONSnapshot, CommercePlanResource } from '@clerk/types';

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

Expand All @@ -17,7 +17,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
isDefault!: boolean;
isRecurring!: boolean;
hasBaseFee!: boolean;
payerType!: string[];
forPayerType!: CommercePayerType;
publiclyVisible!: boolean;
slug!: string;
avatarUrl!: string;
Expand Down Expand Up @@ -47,7 +47,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
this.isDefault = data.is_default;
this.isRecurring = data.is_recurring;
this.hasBaseFee = data.has_base_fee;
this.payerType = data.payer_type;
this.forPayerType = data.for_payer_type;
this.publiclyVisible = data.publicly_visible;
this.slug = data.slug;
this.avatarUrl = data.avatar_url;
Expand All @@ -73,7 +73,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
is_default: this.isDefault,
is_recurring: this.isRecurring,
has_base_fee: this.hasBaseFee,
payer_type: this.payerType,
for_payer_type: this.forPayerType,
publicly_visible: this.publiclyVisible,
slug: this.slug,
avatar_url: this.avatarUrl,
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const PlanDetailsInternal = ({
const hasFeatures = features.length > 0;

return (
<SubscriberTypeContext.Provider value={plan.payerType[0] as 'user' | 'org'}>
<SubscriberTypeContext.Provider value={plan.forPayerType}>
<Drawer.Header
sx={t =>
!hasFeatures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { CommercePayerType } from '@clerk/types';
import { createContext, useContext } from 'react';

const DEFAUlT = 'user';
export const SubscriberTypeContext = createContext<'user' | 'org' | undefined>(DEFAUlT);
export const SubscriberTypeContext = createContext<CommercePayerType | undefined>(DEFAUlT);

export const useSubscriberTypeContext = () => useContext(SubscriberTypeContext) || DEFAUlT;
export const useSubscriberTypeContext = (): CommercePayerType => useContext(SubscriberTypeContext) || DEFAUlT;

export const useSubscriberTypeLocalizationRoot = () => {
const subscriberType = useSubscriberTypeContext();
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import type {
CommerceBillingNamespace,
CommerceCheckoutResource,
CommercePayerType,
CommercePlanResource,
CommerceSubscriberType,
CommerceSubscriptionPlanPeriod,
ConfirmCheckoutParams,
} from './commerce';
Expand Down Expand Up @@ -1108,7 +1108,7 @@
*/
windowNavigate: (to: URL | string) => void;
},
) => Promise<unknown> | unknown;

Check warning on line 1111 in packages/types/src/clerk.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'unknown' overrides all other types in this union type

export type WithoutRouting<T> = Omit<T, 'path' | 'routing'>;

Expand Down Expand Up @@ -1806,7 +1806,7 @@
appearance?: CheckoutTheme;
planId?: string;
planPeriod?: CommerceSubscriptionPlanPeriod;
subscriberType?: CommerceSubscriberType;
subscriberType?: CommercePayerType;
onSubscriptionComplete?: () => void;
portalId?: string;
portalRoot?: PortalRoot;
Expand Down Expand Up @@ -1843,7 +1843,7 @@
* If `org` is provided, the subscription details will be displayed for the active organization.
* @default 'user'
*/
for?: CommerceSubscriberType;
for?: CommercePayerType;
appearance?: SubscriptionDetailsTheme;
onSubscriptionCancel?: () => void;
portalId?: string;
Expand Down
16 changes: 3 additions & 13 deletions packages/types/src/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface CommerceBillingNamespace {
* <ClerkProvider clerkJsVersion="x.x.x" />
* ```
*/
export type CommerceSubscriberType = 'org' | 'user';
export type CommercePayerType = 'org' | 'user';

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

/**
Expand Down Expand Up @@ -356,18 +356,8 @@ export interface CommercePlanResource extends ClerkResource {
*
* Each plan is exclusively created for either individual users or organizations,
* and cannot be used interchangeably.
*
* @type {['user'] | ['org']}
* @example
* ```ts
* // For a user plan
* payerType: ['user']
*
* // For an organization plan
* payerType: ['org']
* ```
*/
payerType: string[];
forPayerType: CommercePayerType;
/**
* @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.
Expand Down
19 changes: 2 additions & 17 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import type { APIKeysSettingsJSON } from './apiKeysSettings';
import type {
CommercePayerType,
CommercePaymentChargeType,
CommercePaymentSourceStatus,
CommercePaymentStatus,
Expand Down Expand Up @@ -643,23 +644,7 @@ export interface CommercePlanJSON extends ClerkResourceJSON {
is_default: boolean;
is_recurring: boolean;
has_base_fee: boolean;
/**
* Specifies the subscriber type this plan is designed for.
*
* Each plan is exclusively created for either individual users or organizations,
* and cannot be used interchangeably.
*
* @type {['user'] | ['org']}
* @example
* ```ts
* // For a user plan
* payer_type: ['user']
*
* // For an organization plan
* payer_type: ['org']
* ```
*/
payer_type: string[];
for_payer_type: CommercePayerType;
publicly_visible: boolean;
slug: string;
avatar_url: string;
Expand Down
Loading