From 3aa9210724a224a7d1bf25172ae8064e39466c27 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 19 Sep 2025 11:39:48 +0300 Subject: [PATCH 1/3] chore(clerk-js,types): Rename commerce files to billing --- .changeset/all-papers-call.md | 2 ++ packages/clerk-js/src/core/clerk.ts | 2 +- .../core/modules/{commerce => billing}/index.ts | 2 +- .../CommerceBilling.ts => billing/namespace.ts} | 0 .../payment-source-methods.ts | 0 .../{CommerceCheckout.ts => BillingCheckout.ts} | 2 +- .../{CommercePayer.ts => BillingPayer.ts} | 0 .../{CommercePayment.ts => BillingPayment.ts} | 0 ...rcePaymentSource.ts => BillingPaymentSource.ts} | 0 .../resources/{CommercePlan.ts => BillingPlan.ts} | 2 +- .../{CommerceStatement.ts => BillingStatement.ts} | 0 ...merceSubscription.ts => BillingSubscription.ts} | 0 .../resources/{CommerceFeature.ts => Feature.ts} | 0 .../clerk-js/src/core/resources/Organization.ts | 2 +- packages/clerk-js/src/core/resources/User.ts | 2 +- packages/clerk-js/src/core/resources/internal.ts | 14 +++++++------- .../clerk-js/src/utils/{commerce.ts => billing.ts} | 6 +----- packages/clerk-js/src/utils/index.ts | 2 +- ...erceHook.tsx => createBillingPaginatedHook.tsx} | 11 ++++------- .../shared/src/react/hooks/usePaymentAttempts.tsx | 4 ++-- .../shared/src/react/hooks/usePaymentMethods.tsx | 4 ++-- packages/shared/src/react/hooks/usePlans.tsx | 4 ++-- packages/shared/src/react/hooks/useStatements.tsx | 4 ++-- packages/types/src/{commerce.ts => billing.ts} | 0 24 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 .changeset/all-papers-call.md rename packages/clerk-js/src/core/modules/{commerce => billing}/index.ts (54%) rename packages/clerk-js/src/core/modules/{commerce/CommerceBilling.ts => billing/namespace.ts} (100%) rename packages/clerk-js/src/core/modules/{commerce => billing}/payment-source-methods.ts (100%) rename packages/clerk-js/src/core/resources/{CommerceCheckout.ts => BillingCheckout.ts} (98%) rename packages/clerk-js/src/core/resources/{CommercePayer.ts => BillingPayer.ts} (100%) rename packages/clerk-js/src/core/resources/{CommercePayment.ts => BillingPayment.ts} (100%) rename packages/clerk-js/src/core/resources/{CommercePaymentSource.ts => BillingPaymentSource.ts} (100%) rename packages/clerk-js/src/core/resources/{CommercePlan.ts => BillingPlan.ts} (96%) rename packages/clerk-js/src/core/resources/{CommerceStatement.ts => BillingStatement.ts} (100%) rename packages/clerk-js/src/core/resources/{CommerceSubscription.ts => BillingSubscription.ts} (100%) rename packages/clerk-js/src/core/resources/{CommerceFeature.ts => Feature.ts} (100%) rename packages/clerk-js/src/utils/{commerce.ts => billing.ts} (87%) rename packages/shared/src/react/hooks/{createCommerceHook.tsx => createBillingPaginatedHook.tsx} (88%) rename packages/types/src/{commerce.ts => billing.ts} (100%) diff --git a/.changeset/all-papers-call.md b/.changeset/all-papers-call.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/all-papers-call.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index 1b3c5c9f613..e65248a4c8c 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -148,7 +148,7 @@ import { createFapiClient } from './fapiClient'; import { createClientFromJwt } from './jwt-client'; import { APIKeys } from './modules/apiKeys'; import { createCheckoutInstance } from './modules/checkout/instance'; -import { Billing } from './modules/commerce'; +import { Billing } from './modules/billing'; import { BaseResource, Client, diff --git a/packages/clerk-js/src/core/modules/commerce/index.ts b/packages/clerk-js/src/core/modules/billing/index.ts similarity index 54% rename from packages/clerk-js/src/core/modules/commerce/index.ts rename to packages/clerk-js/src/core/modules/billing/index.ts index 0a2889868cc..2154d420158 100644 --- a/packages/clerk-js/src/core/modules/commerce/index.ts +++ b/packages/clerk-js/src/core/modules/billing/index.ts @@ -1,2 +1,2 @@ -export * from './CommerceBilling'; +export * from './namespace'; export * from './payment-source-methods'; diff --git a/packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts b/packages/clerk-js/src/core/modules/billing/namespace.ts similarity index 100% rename from packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts rename to packages/clerk-js/src/core/modules/billing/namespace.ts diff --git a/packages/clerk-js/src/core/modules/commerce/payment-source-methods.ts b/packages/clerk-js/src/core/modules/billing/payment-source-methods.ts similarity index 100% rename from packages/clerk-js/src/core/modules/commerce/payment-source-methods.ts rename to packages/clerk-js/src/core/modules/billing/payment-source-methods.ts diff --git a/packages/clerk-js/src/core/resources/CommerceCheckout.ts b/packages/clerk-js/src/core/resources/BillingCheckout.ts similarity index 98% rename from packages/clerk-js/src/core/resources/CommerceCheckout.ts rename to packages/clerk-js/src/core/resources/BillingCheckout.ts index 03d026a6021..4e3225b3d37 100644 --- a/packages/clerk-js/src/core/resources/CommerceCheckout.ts +++ b/packages/clerk-js/src/core/resources/BillingCheckout.ts @@ -11,7 +11,7 @@ import type { import { unixEpochToDate } from '@/utils/date'; import { billingTotalsFromJSON } from '../../utils'; -import { BillingPayer } from './CommercePayer'; +import { BillingPayer } from './BillingPayer'; import { BaseResource, BillingPaymentSource, BillingPlan, isClerkAPIResponseError } from './internal'; export class BillingCheckout extends BaseResource implements BillingCheckoutResource { diff --git a/packages/clerk-js/src/core/resources/CommercePayer.ts b/packages/clerk-js/src/core/resources/BillingPayer.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommercePayer.ts rename to packages/clerk-js/src/core/resources/BillingPayer.ts diff --git a/packages/clerk-js/src/core/resources/CommercePayment.ts b/packages/clerk-js/src/core/resources/BillingPayment.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommercePayment.ts rename to packages/clerk-js/src/core/resources/BillingPayment.ts diff --git a/packages/clerk-js/src/core/resources/CommercePaymentSource.ts b/packages/clerk-js/src/core/resources/BillingPaymentSource.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommercePaymentSource.ts rename to packages/clerk-js/src/core/resources/BillingPaymentSource.ts diff --git a/packages/clerk-js/src/core/resources/CommercePlan.ts b/packages/clerk-js/src/core/resources/BillingPlan.ts similarity index 96% rename from packages/clerk-js/src/core/resources/CommercePlan.ts rename to packages/clerk-js/src/core/resources/BillingPlan.ts index c54f644b4ee..dfd5f96da9d 100644 --- a/packages/clerk-js/src/core/resources/CommercePlan.ts +++ b/packages/clerk-js/src/core/resources/BillingPlan.ts @@ -1,6 +1,6 @@ import type { BillingMoneyAmount, BillingPayerResourceType, BillingPlanJSON, BillingPlanResource } from '@clerk/types'; -import { billingMoneyAmountFromJSON } from '@/utils/commerce'; +import { billingMoneyAmountFromJSON } from '@/utils/billing'; import { BaseResource, Feature } from './internal'; diff --git a/packages/clerk-js/src/core/resources/CommerceStatement.ts b/packages/clerk-js/src/core/resources/BillingStatement.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommerceStatement.ts rename to packages/clerk-js/src/core/resources/BillingStatement.ts diff --git a/packages/clerk-js/src/core/resources/CommerceSubscription.ts b/packages/clerk-js/src/core/resources/BillingSubscription.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommerceSubscription.ts rename to packages/clerk-js/src/core/resources/BillingSubscription.ts diff --git a/packages/clerk-js/src/core/resources/CommerceFeature.ts b/packages/clerk-js/src/core/resources/Feature.ts similarity index 100% rename from packages/clerk-js/src/core/resources/CommerceFeature.ts rename to packages/clerk-js/src/core/resources/Feature.ts diff --git a/packages/clerk-js/src/core/resources/Organization.ts b/packages/clerk-js/src/core/resources/Organization.ts index 7ac4d76355f..91f7373c4f5 100644 --- a/packages/clerk-js/src/core/resources/Organization.ts +++ b/packages/clerk-js/src/core/resources/Organization.ts @@ -28,7 +28,7 @@ import type { import { convertPageToOffsetSearchParams } from '../../utils/convertPageToOffsetSearchParams'; import { unixEpochToDate } from '../../utils/date'; -import { addPaymentSource, getPaymentSources, initializePaymentSource } from '../modules/commerce'; +import { addPaymentSource, getPaymentSources, initializePaymentSource } from '../modules/billing'; import { BaseResource, OrganizationInvitation, OrganizationMembership } from './internal'; import { OrganizationDomain } from './OrganizationDomain'; import { OrganizationMembershipRequest } from './OrganizationMembershipRequest'; diff --git a/packages/clerk-js/src/core/resources/User.ts b/packages/clerk-js/src/core/resources/User.ts index d7b920b51ec..04789175adc 100644 --- a/packages/clerk-js/src/core/resources/User.ts +++ b/packages/clerk-js/src/core/resources/User.ts @@ -36,7 +36,7 @@ import { unixEpochToDate } from '../../utils/date'; import { normalizeUnsafeMetadata } from '../../utils/resourceParams'; import { getFullName } from '../../utils/user'; import { eventBus, events } from '../events'; -import { addPaymentSource, getPaymentSources, initializePaymentSource } from '../modules/commerce'; +import { addPaymentSource, getPaymentSources, initializePaymentSource } from '../modules/billing'; import { BackupCode } from './BackupCode'; import { BaseResource, diff --git a/packages/clerk-js/src/core/resources/internal.ts b/packages/clerk-js/src/core/resources/internal.ts index d668bae4768..46dff0ad5be 100644 --- a/packages/clerk-js/src/core/resources/internal.ts +++ b/packages/clerk-js/src/core/resources/internal.ts @@ -4,13 +4,13 @@ export * from './UserSettings'; export * from './CommerceSettings'; export * from './AuthConfig'; export * from './Client'; -export * from './CommerceCheckout'; -export * from './CommerceFeature'; -export * from './CommerceStatement'; -export * from './CommercePayment'; -export * from './CommercePaymentSource'; -export * from './CommercePlan'; -export * from './CommerceSubscription'; +export * from './BillingCheckout'; +export * from './Feature'; +export * from './BillingStatement'; +export * from './BillingPayment'; +export * from './BillingPaymentSource'; +export * from './BillingPlan'; +export * from './BillingSubscription'; export * from './DeletedObject'; export * from './DisplayConfig'; export * from './EmailAddress'; diff --git a/packages/clerk-js/src/utils/commerce.ts b/packages/clerk-js/src/utils/billing.ts similarity index 87% rename from packages/clerk-js/src/utils/commerce.ts rename to packages/clerk-js/src/utils/billing.ts index 83a99444f64..496dd10520b 100644 --- a/packages/clerk-js/src/utils/commerce.ts +++ b/packages/clerk-js/src/utils/billing.ts @@ -16,10 +16,6 @@ export const billingMoneyAmountFromJSON = (data: BillingMoneyAmountJSON): Billin }; }; -const hasPastDue = (data: unknown): data is { past_due: BillingMoneyAmountJSON } => { - return typeof data === 'object' && data !== null && 'past_due' in data; -}; - export const billingTotalsFromJSON = ( data: T, ): T extends { total_due_now: BillingMoneyAmountJSON } ? BillingCheckoutTotals : BillingStatementTotals => { @@ -35,7 +31,7 @@ export const billingTotalsFromJSON = = { +type BillingHookConfig = { hookName: string; resourceType: string; useFetcher: ( @@ -38,17 +38,17 @@ type CommerceHookConfig({ +export function createBillingPaginatedHook({ hookName, resourceType, useFetcher, options, -}: CommerceHookConfig) { +}: BillingHookConfig) { type HookParams = PaginatedHookConfig & { for?: ForPayerType; }; - return function useCommerceHook( + return function useBillingHook( params?: T, ): PaginatedResources { const { for: _for, ...paginationParams } = params || ({} as Partial); @@ -110,6 +110,3 @@ export function createCommercePaginatedHook({ +export const usePaymentAttempts = createBillingPaginatedHook({ hookName: 'usePaymentAttempts', resourceType: 'billing-payment-attempts', useFetcher: () => { diff --git a/packages/shared/src/react/hooks/usePaymentMethods.tsx b/packages/shared/src/react/hooks/usePaymentMethods.tsx index 94310e1d114..8537f32caa9 100644 --- a/packages/shared/src/react/hooks/usePaymentMethods.tsx +++ b/packages/shared/src/react/hooks/usePaymentMethods.tsx @@ -1,12 +1,12 @@ import type { BillingPaymentSourceResource, GetPaymentSourcesParams } from '@clerk/types'; import { useOrganizationContext, useUserContext } from '../contexts'; -import { createCommercePaginatedHook } from './createCommerceHook'; +import { createBillingPaginatedHook } from './createBillingPaginatedHook'; /** * @internal */ -export const usePaymentMethods = createCommercePaginatedHook({ +export const usePaymentMethods = createBillingPaginatedHook({ hookName: 'usePaymentMethods', resourceType: 'commerce-payment-methods', useFetcher: resource => { diff --git a/packages/shared/src/react/hooks/usePlans.tsx b/packages/shared/src/react/hooks/usePlans.tsx index 3ae4bfe7c56..77a45213908 100644 --- a/packages/shared/src/react/hooks/usePlans.tsx +++ b/packages/shared/src/react/hooks/usePlans.tsx @@ -1,12 +1,12 @@ import type { BillingPlanResource, GetPlansParams } from '@clerk/types'; import { useClerkInstanceContext } from '../contexts'; -import { createBillingPaginatedHook as createCommercePaginatedHook } from './createCommerceHook'; +import { createBillingPaginatedHook } from './createBillingPaginatedHook'; /** * @internal */ -export const usePlans = createCommercePaginatedHook({ +export const usePlans = createBillingPaginatedHook({ hookName: 'usePlans', resourceType: 'billing-plans', useFetcher: _for => { diff --git a/packages/shared/src/react/hooks/useStatements.tsx b/packages/shared/src/react/hooks/useStatements.tsx index 12cfd079938..78817ffebc1 100644 --- a/packages/shared/src/react/hooks/useStatements.tsx +++ b/packages/shared/src/react/hooks/useStatements.tsx @@ -1,12 +1,12 @@ import type { BillingStatementResource, GetStatementsParams } from '@clerk/types'; import { useClerkInstanceContext } from '../contexts'; -import { createBillingPaginatedHook as createCommercePaginatedHook } from './createCommerceHook'; +import { createBillingPaginatedHook } from './createBillingPaginatedHook'; /** * @internal */ -export const useStatements = createCommercePaginatedHook({ +export const useStatements = createBillingPaginatedHook({ hookName: 'useStatements', resourceType: 'billing-statements', useFetcher: () => { diff --git a/packages/types/src/commerce.ts b/packages/types/src/billing.ts similarity index 100% rename from packages/types/src/commerce.ts rename to packages/types/src/billing.ts From 9aa2f3cfb1ce74437cb558adea9bb2fc6326ff44 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 19 Sep 2025 11:45:38 +0300 Subject: [PATCH 2/3] patch import paths --- packages/types/src/clerk.ts | 4 ++-- packages/types/src/index.ts | 2 +- packages/types/src/json.ts | 2 +- packages/types/src/organization.ts | 2 +- packages/types/src/user.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index e012f303fc4..8730bea7d3f 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -20,7 +20,6 @@ import type { UserVerificationTheme, WaitlistTheme, } from './appearance'; -import type { ClientResource } from './client'; import type { BillingCheckoutResource, BillingNamespace, @@ -28,7 +27,8 @@ import type { BillingSubscriptionPlanPeriod, ConfirmCheckoutParams, ForPayerType, -} from './commerce'; +} from './billing'; +import type { ClientResource } from './client'; import type { CustomMenuItem } from './customMenuItems'; import type { CustomPage } from './customPages'; import type { InstanceType } from './instance'; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 1530db283ca..b0f51eec6fc 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -6,9 +6,9 @@ export * from './attributes'; export * from './authConfig'; export * from './authObject'; export * from './backupCode'; +export * from './billing'; export * from './clerk'; export * from './client'; -export * from './commerce'; export * from './commerceSettings'; export * from './customMenuItems'; export * from './customPages'; diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index 22ec1c15abe..9ab16c1540c 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -11,7 +11,7 @@ import type { BillingStatementStatus, BillingSubscriptionPlanPeriod, BillingSubscriptionStatus, -} from './commerce'; +} from './billing'; import type { CommerceSettingsJSON } from './commerceSettings'; import type { DisplayConfigJSON } from './displayConfig'; import type { EnterpriseProtocol, EnterpriseProvider } from './enterpriseAccount'; diff --git a/packages/types/src/organization.ts b/packages/types/src/organization.ts index 2ec09c37056..a3acfe36d39 100644 --- a/packages/types/src/organization.ts +++ b/packages/types/src/organization.ts @@ -1,4 +1,4 @@ -import type { BillingPaymentSourceMethods } from './commerce'; +import type { BillingPaymentSourceMethods } from './billing'; import type { OrganizationDomainResource, OrganizationEnrollmentMode } from './organizationDomain'; import type { OrganizationInvitationResource, OrganizationInvitationStatus } from './organizationInvitation'; import type { OrganizationCustomRoleKey, OrganizationMembershipResource } from './organizationMembership'; diff --git a/packages/types/src/user.ts b/packages/types/src/user.ts index 8e8c696b6ca..6b0a5ee7d8e 100644 --- a/packages/types/src/user.ts +++ b/packages/types/src/user.ts @@ -1,5 +1,5 @@ import type { BackupCodeResource } from './backupCode'; -import type { BillingPaymentSourceMethods } from './commerce'; +import type { BillingPaymentSourceMethods } from './billing'; import type { DeletedObjectResource } from './deletedObject'; import type { EmailAddressResource } from './emailAddress'; import type { EnterpriseAccountResource } from './enterpriseAccount'; From 6c5e6a42775857eae8fd5d8195c2201f5325659c Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 19 Sep 2025 12:25:54 +0300 Subject: [PATCH 3/3] fix lint --- packages/clerk-js/src/core/clerk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index e65248a4c8c..05c3c245514 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -147,8 +147,8 @@ import type { FapiClient, FapiRequestCallback } from './fapiClient'; import { createFapiClient } from './fapiClient'; import { createClientFromJwt } from './jwt-client'; import { APIKeys } from './modules/apiKeys'; -import { createCheckoutInstance } from './modules/checkout/instance'; import { Billing } from './modules/billing'; +import { createCheckoutInstance } from './modules/checkout/instance'; import { BaseResource, Client,