Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/shy-chairs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Replace `"commerce"` with `"billing"` in error message when components cannot render because the feature is disabled.
49 changes: 35 additions & 14 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ declare global {
}
}

const CANNOT_RENDER_BILLING_DISABLED_ERROR_CODE = 'cannot_render_billing_disabled';
const CANNOT_RENDER_USER_MISSING_ERROR_CODE = 'cannot_render_user_missing';
const CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE = 'cannot_render_organizations_disabled';
const CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE = 'cannot_render_organization_missing';
const CANNOT_RENDER_SINGLE_SESSION_ENABLED_ERROR_CODE = 'cannot_render_single_session_enabled';
const defaultOptions: ClerkOptions = {
polling: true,
standardBrowser: true,
Expand Down Expand Up @@ -521,7 +526,7 @@ export class Clerk implements ClerkInterface {
if (sessionExistsAndSingleSessionModeEnabled(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotOpenSignInOrSignUp, {
code: 'cannot_render_single_session_enabled',
code: CANNOT_RENDER_SINGLE_SESSION_ENABLED_ERROR_CODE,
});
}
return;
Expand All @@ -541,6 +546,14 @@ export class Clerk implements ClerkInterface {

public __internal_openCheckout = (props?: __experimental_CheckoutProps): void => {
this.assertComponentsReady(this.#componentControls);
if (disabledBillingFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyCommerceComponent('Checkout'), {
code: CANNOT_RENDER_BILLING_DISABLED_ERROR_CODE,
});
}
return;
}
void this.#componentControls
.ensureMounted({ preloadHint: 'Checkout' })
.then(controls => controls.openDrawer('checkout', props || {}));
Expand All @@ -553,6 +566,14 @@ export class Clerk implements ClerkInterface {

public __internal_openSubscriptionDetails = (props?: __experimental_SubscriptionDetailsProps): void => {
this.assertComponentsReady(this.#componentControls);
if (disabledBillingFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyCommerceComponent('SubscriptionDetails'), {
code: CANNOT_RENDER_BILLING_DISABLED_ERROR_CODE,
});
}
return;
}
void this.#componentControls
.ensureMounted({ preloadHint: 'SubscriptionDetails' })
.then(controls => controls.openDrawer('subscriptionDetails', props || {}));
Expand All @@ -568,7 +589,7 @@ export class Clerk implements ClerkInterface {
if (noUserExists(this)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotOpenUserProfile, {
code: 'cannot_render_user_missing',
code: CANNOT_RENDER_USER_MISSING_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -604,7 +625,7 @@ export class Clerk implements ClerkInterface {
if (sessionExistsAndSingleSessionModeEnabled(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotOpenSignInOrSignUp, {
code: 'cannot_render_single_session_enabled',
code: CANNOT_RENDER_SINGLE_SESSION_ENABLED_ERROR_CODE,
});
}
return;
Expand All @@ -626,7 +647,7 @@ export class Clerk implements ClerkInterface {
if (noUserExists(this)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotOpenUserProfile, {
code: 'cannot_render_user_missing',
code: CANNOT_RENDER_USER_MISSING_ERROR_CODE,
});
}
return;
Expand All @@ -649,15 +670,15 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('OrganizationProfile'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
}
if (noOrganizationExists(this)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderComponentWhenOrgDoesNotExist, {
code: 'cannot_render_organization_missing',
code: CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE,
});
}
return;
Expand All @@ -679,7 +700,7 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('CreateOrganization'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -762,7 +783,7 @@ export class Clerk implements ClerkInterface {
if (noUserExists(this)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderComponentWhenUserDoesNotExist, {
code: 'cannot_render_user_missing',
code: CANNOT_RENDER_USER_MISSING_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -794,7 +815,7 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('OrganizationProfile'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
Expand All @@ -803,7 +824,7 @@ export class Clerk implements ClerkInterface {
if (noOrganizationExists(this) && userExists) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderComponentWhenOrgDoesNotExist, {
code: 'cannot_render_organization_missing',
code: CANNOT_RENDER_ORGANIZATION_MISSING_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -834,7 +855,7 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('CreateOrganization'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -865,7 +886,7 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('OrganizationSwitcher'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -904,7 +925,7 @@ export class Clerk implements ClerkInterface {
if (disabledOrganizationsFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyOrganizationComponent('OrganizationList'), {
code: 'cannot_render_organizations_disabled',
code: CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE,
});
}
return;
Expand Down Expand Up @@ -979,7 +1000,7 @@ export class Clerk implements ClerkInterface {
if (disabledBillingFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotRenderAnyCommerceComponent('PricingTable'), {
code: 'cannot_render_commerce_disabled',
code: CANNOT_RENDER_BILLING_DISABLED_ERROR_CODE,
});
}
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const createMessageForDisabledOrganizations = (
`The <${componentName}/> cannot be rendered when the feature is turned off. Visit 'dashboard.clerk.com' to enable the feature. Since the feature is turned off, this is no-op.`,
);
};
const createMessageForDisabledCommerce = (componentName: 'PricingTable' | 'Checkout') => {
const createMessageForDisabledCommerce = (componentName: 'PricingTable' | 'Checkout' | 'SubscriptionDetails') => {
return formatWarning(
`The <${componentName}/> component cannot be rendered when commerce is disabled. Visit 'https://dashboard.clerk.com/last-active?path=commerce/settings' to follow the necessary steps to enable commerce. Since commerce is disabled, this is no-op.`,
`The <${componentName}/> component cannot be rendered when billing is disabled. Visit 'https://dashboard.clerk.com/last-active?path=billing/settings' to follow the necessary steps to enable commerce. Since commerce is disabled, this is no-op.`,
);
};
const warnings = {
Expand Down