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
2 changes: 2 additions & 0 deletions .changeset/all-papers-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { Billing } from './modules/billing';
import { createCheckoutInstance } from './modules/checkout/instance';
import { Billing } from './modules/commerce';
import {
BaseResource,
Client,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './CommerceBilling';
export * from './namespace';
export * from './payment-source-methods';
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends BillingStatementTotalsJSON | BillingCheckoutTotalsJSON>(
data: T,
): T extends { total_due_now: BillingMoneyAmountJSON } ? BillingCheckoutTotals : BillingStatementTotals => {
Expand All @@ -35,7 +31,7 @@ export const billingTotalsFromJSON = <T extends BillingStatementTotalsJSON | Bil
if ('credit' in data) {
totals.credit = billingMoneyAmountFromJSON(data.credit);
}
if (hasPastDue(data)) {
if ('past_due' in data) {
totals.pastDue = billingMoneyAmountFromJSON(data.past_due);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './beforeUnloadTracker';
export * from './appearance';
export * from './commerce';
export * from './billing';
export * from './completeSignUpFlow';
export * from './componentGuards';
export * from './dynamicParamParser';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
/**
* @internal
*/
type CommerceHookConfig<TResource extends ClerkResource, TParams extends PagesOrInfiniteOptions> = {
type BillingHookConfig<TResource extends ClerkResource, TParams extends PagesOrInfiniteOptions> = {
hookName: string;
resourceType: string;
useFetcher: (
Expand All @@ -38,17 +38,17 @@ type CommerceHookConfig<TResource extends ClerkResource, TParams extends PagesOr
*
* @internal
*/
export function createCommercePaginatedHook<TResource extends ClerkResource, TParams extends PagesOrInfiniteOptions>({
export function createBillingPaginatedHook<TResource extends ClerkResource, TParams extends PagesOrInfiniteOptions>({
hookName,
resourceType,
useFetcher,
options,
}: CommerceHookConfig<TResource, TParams>) {
}: BillingHookConfig<TResource, TParams>) {
type HookParams = PaginatedHookConfig<PagesOrInfiniteOptions> & {
for?: ForPayerType;
};

return function useCommerceHook<T extends HookParams>(
return function useBillingHook<T extends HookParams>(
params?: T,
): PaginatedResources<TResource, T extends { infinite: true } ? true : false> {
const { for: _for, ...paginationParams } = params || ({} as Partial<T>);
Expand Down Expand Up @@ -110,6 +110,3 @@ export function createCommercePaginatedHook<TResource extends ClerkResource, TPa
return result;
};
}

// Billing alias factory for paginated hooks
export const createBillingPaginatedHook = createCommercePaginatedHook;
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePaymentAttempts.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { BillingPaymentResource, GetPaymentAttemptsParams } from '@clerk/types';

import { useClerkInstanceContext } from '../contexts';
import { createBillingPaginatedHook as createCommercePaginatedHook } from './createCommerceHook';
import { createBillingPaginatedHook } from './createBillingPaginatedHook';

/**
* @internal
*/
export const usePaymentAttempts = createCommercePaginatedHook<BillingPaymentResource, GetPaymentAttemptsParams>({
export const usePaymentAttempts = createBillingPaginatedHook<BillingPaymentResource, GetPaymentAttemptsParams>({
hookName: 'usePaymentAttempts',
resourceType: 'billing-payment-attempts',
useFetcher: () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePaymentMethods.tsx
Original file line number Diff line number Diff line change
@@ -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<BillingPaymentSourceResource, GetPaymentSourcesParams>({
export const usePaymentMethods = createBillingPaginatedHook<BillingPaymentSourceResource, GetPaymentSourcesParams>({
hookName: 'usePaymentMethods',
resourceType: 'commerce-payment-methods',
useFetcher: resource => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePlans.tsx
Original file line number Diff line number Diff line change
@@ -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<BillingPlanResource, GetPlansParams>({
export const usePlans = createBillingPaginatedHook<BillingPlanResource, GetPlansParams>({
hookName: 'usePlans',
resourceType: 'billing-plans',
useFetcher: _for => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/useStatements.tsx
Original file line number Diff line number Diff line change
@@ -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<BillingStatementResource, GetStatementsParams>({
export const useStatements = createBillingPaginatedHook<BillingStatementResource, GetStatementsParams>({
hookName: 'useStatements',
resourceType: 'billing-statements',
useFetcher: () => {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import type {
UserVerificationTheme,
WaitlistTheme,
} from './appearance';
import type { ClientResource } from './client';
import type {
BillingCheckoutResource,
BillingNamespace,
BillingPlanResource,
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';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/organization.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Loading