@usethrottle/subscriptions 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,7 @@ npm install @usethrottle/subscriptions @usethrottle/checkout-react
11
11
  - Subscription lifecycle reads and mutations: list, get, create, update, change plan, pause, resume, cancel.
12
12
  - Recurring checkout-session creation for subscribe flows.
13
13
  - Trial eligibility checks for trial-fraud protection.
14
+ - Customer payment-method reads for subscription confirmation and buyer portals.
14
15
  - Buyer-portal proxy helpers so browser code never sees an `sk_*` key.
15
16
  - Primitive UI components for status, trial countdowns, and past-due dunning.
16
17
 
@@ -81,6 +82,7 @@ export { handler as GET, handler as POST, handler as PATCH };
81
82
  ```
82
83
 
83
84
  The helper allowlists subscription, customer-by-external, trial eligibility, and checkout-session paths. It pins subscription list reads, customer lookups, direct subscription creates, and checkout-session creates to the authenticated buyer's `externalCustomerId`, and verifies ownership before forwarding subscription mutations.
85
+ Payment-method reads are pinned to the authenticated buyer's Throttle customer row.
84
86
 
85
87
  ## Server-side API client
86
88
 
@@ -94,6 +96,7 @@ const subscriptions = createSubscriptionsClient({
94
96
  });
95
97
 
96
98
  await subscriptions.cancel('sub_123', { atPeriodEnd: true });
99
+ await subscriptions.listCustomerPaymentMethods('cus_123');
97
100
  ```
98
101
 
99
102
  `create()` accepts either a Throttle `customerId` or your own `externalCustomerId`. When you pass `externalCustomerId`, the client resolves the Throttle customer row before calling the subscription create endpoint.
@@ -16,8 +16,8 @@ var ThrottleSubscriptionsError = class extends Error {
16
16
  function normalizeSubscription(raw) {
17
17
  return {
18
18
  id: requiredString(raw?.id, "subscription.id"),
19
- merchantId: optionalString(raw?.merchantId ?? raw?.merchant_id),
20
- storeId: optionalString(raw?.storeId ?? raw?.store_id),
19
+ workspaceId: optionalString(raw?.workspaceId ?? raw?.merchant_id),
20
+ applicationId: optionalString(raw?.applicationId ?? raw?.store_id),
21
21
  customerId: requiredString(raw?.customerId ?? raw?.customer_id, "subscription.customerId"),
22
22
  status: raw?.status ?? "active",
23
23
  planReference: requiredString(
@@ -61,6 +61,18 @@ function normalizeCustomer(raw) {
61
61
  updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? void 0
62
62
  };
63
63
  }
64
+ function normalizeCustomerPaymentMethod(raw) {
65
+ return {
66
+ id: requiredString(raw?.id, "paymentMethod.id"),
67
+ processor: optionalString(raw?.processor),
68
+ methodType: optionalString(raw?.methodType ?? raw?.method_type),
69
+ cardBrand: optionalString(raw?.cardBrand ?? raw?.card_brand),
70
+ cardLastFour: optionalString(raw?.cardLastFour ?? raw?.card_last_four),
71
+ isDefault: Boolean(raw?.isDefault ?? raw?.is_default ?? false),
72
+ createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? void 0,
73
+ updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? void 0
74
+ };
75
+ }
64
76
  function normalizeCheckoutSession(raw) {
65
77
  const sessionId = raw?.sessionId ?? raw?.session_id ?? raw?.id;
66
78
  return {
@@ -168,7 +180,7 @@ var SubscriptionsClient = class {
168
180
  async create(input) {
169
181
  const customerId = await this.resolveCustomerId(input.customerId, input.externalCustomerId);
170
182
  const data = await this.request("POST", "/api/v1/subscriptions", {
171
- storeId: input.storeId,
183
+ applicationId: input.applicationId,
172
184
  customerId,
173
185
  planReference: input.planReference,
174
186
  planName: input.planName,
@@ -264,6 +276,13 @@ var SubscriptionsClient = class {
264
276
  throw err;
265
277
  }
266
278
  }
279
+ async listCustomerPaymentMethods(customerId) {
280
+ const data = await this.request(
281
+ "GET",
282
+ `/api/v1/customers/${encodeURIComponent(customerId)}/payment-methods`
283
+ );
284
+ return (data ?? []).map(normalizeCustomerPaymentMethod);
285
+ }
267
286
  async resolveCustomerId(customerId, externalCustomerId) {
268
287
  if (customerId) return customerId;
269
288
  if (!externalCustomerId) {
@@ -301,4 +320,4 @@ export {
301
320
  SubscriptionsClient,
302
321
  createSubscriptionsClient
303
322
  };
304
- //# sourceMappingURL=chunk-CRI67SGE.js.map
323
+ //# sourceMappingURL=chunk-YNHK6SPQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/normalize.ts","../src/client.ts"],"sourcesContent":["export class ThrottleSubscriptionsError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n\n constructor(args: { code: string; message: string; statusCode: number; details?: unknown }) {\n super(args.message);\n this.name = 'ThrottleSubscriptionsError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n }\n}\n","import type {\n CheckoutSession,\n Customer,\n CustomerPaymentMethod,\n Pagination,\n Subscription,\n SubscriptionInterval,\n SubscriptionStatus,\n TrialEligibilityResult,\n} from './types';\n\nexport function normalizeSubscription(raw: any): Subscription {\n return {\n id: requiredString(raw?.id, 'subscription.id'),\n workspaceId: optionalString(raw?.workspaceId ?? raw?.merchant_id),\n applicationId: optionalString(raw?.applicationId ?? raw?.store_id),\n customerId: requiredString(raw?.customerId ?? raw?.customer_id, 'subscription.customerId'),\n status: (raw?.status ?? 'active') as SubscriptionStatus,\n planReference: requiredString(\n raw?.planReference ?? raw?.plan_reference,\n 'subscription.planReference',\n ),\n planName: optionalString(raw?.planName ?? raw?.plan_name),\n interval: (raw?.interval ?? 'monthly') as SubscriptionInterval,\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n currentPeriodStart: requiredDateString(\n raw?.currentPeriodStart ?? raw?.current_period_start,\n 'subscription.currentPeriodStart',\n ),\n currentPeriodEnd: requiredDateString(\n raw?.currentPeriodEnd ?? raw?.current_period_end,\n 'subscription.currentPeriodEnd',\n ),\n trialEnd: optionalDateString(raw?.trialEnd ?? raw?.trial_end),\n cancelAtPeriodEnd: Boolean(raw?.cancelAtPeriodEnd ?? raw?.cancel_at_period_end ?? false),\n failureCount: Number(raw?.failureCount ?? raw?.failure_count ?? 0),\n lastPaymentAt: optionalDateString(raw?.lastPaymentAt ?? raw?.last_payment_at),\n pausedAt: optionalDateString(raw?.pausedAt ?? raw?.paused_at),\n cancelledAt: optionalDateString(raw?.cancelledAt ?? raw?.cancelled_at),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCustomer(raw: any): Customer | null {\n if (!raw) return null;\n return {\n id: requiredString(raw?.id, 'customer.id'),\n externalId: optionalString(raw?.externalId ?? raw?.external_id),\n email: optionalString(raw?.email),\n firstName: optionalString(raw?.firstName ?? raw?.first_name),\n lastName: optionalString(raw?.lastName ?? raw?.last_name),\n phone: optionalString(raw?.phone),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCustomerPaymentMethod(raw: any): CustomerPaymentMethod {\n return {\n id: requiredString(raw?.id, 'paymentMethod.id'),\n processor: optionalString(raw?.processor),\n methodType: optionalString(raw?.methodType ?? raw?.method_type),\n cardBrand: optionalString(raw?.cardBrand ?? raw?.card_brand),\n cardLastFour: optionalString(raw?.cardLastFour ?? raw?.card_last_four),\n isDefault: Boolean(raw?.isDefault ?? raw?.is_default ?? false),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url),\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token),\n expiresAt: optionalDateString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nexport function normalizeTrialEligibility(raw: any): TrialEligibilityResult {\n return {\n eligible: Boolean(raw?.eligible),\n reason: raw?.reason,\n };\n}\n\nexport function normalizePagination(raw: any): Pagination | undefined {\n if (!raw) return undefined;\n return {\n cursor: raw.cursor ?? null,\n hasMore: Boolean(raw.hasMore ?? raw.has_more ?? false),\n };\n}\n\nexport function toIso(value: string | Date | undefined): string | undefined {\n if (value === undefined) return undefined;\n return value instanceof Date ? value.toISOString() : value;\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' ? value : null;\n}\n\nfunction requiredDateString(value: unknown, label: string): string {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalDateString(value: unknown): string | null {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n return null;\n}\n\nfunction objectOrEmpty(value: unknown): Record<string, unknown> {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {};\n}\n","import { ThrottleSubscriptionsError } from './errors';\nimport {\n normalizeCheckoutSession,\n normalizeCustomer,\n normalizeCustomerPaymentMethod,\n normalizePagination,\n normalizeSubscription,\n normalizeTrialEligibility,\n toIso,\n} from './normalize';\nimport type {\n ChangePlanInput,\n CheckoutSession,\n CreateCheckoutSessionInput,\n CreateSubscriptionInput,\n Customer,\n CustomerPaymentMethod,\n ListSubscriptionsParams,\n PaginatedSubscriptions,\n Subscription,\n SubscriptionsClientContract,\n SubscriptionsClientOptions,\n ThrottleEnvelope,\n TrialEligibilityInput,\n TrialEligibilityResult,\n UpdateSubscriptionInput,\n} from './types';\n\nexport class SubscriptionsClient implements SubscriptionsClientContract {\n private readonly apiKey?: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly fetcher?: SubscriptionsClientOptions['fetcher'];\n private readonly timeoutMs: number;\n\n constructor(opts: SubscriptionsClientOptions = {}) {\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('SubscriptionsClient: fetch is required');\n if (!opts.apiKey && !opts.fetcher) {\n throw new Error('SubscriptionsClient: apiKey or fetcher is required');\n }\n\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.fetcher = opts.fetcher;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const init: RequestInit = {\n method,\n headers: {\n 'content-type': 'application/json',\n ...(this.apiKey ? { 'x-api-key': this.apiKey } : {}),\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n };\n\n const res = this.fetcher\n ? await this.fetcher(path, init)\n : await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), init);\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleSubscriptionsError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async create(input: CreateSubscriptionInput): Promise<Subscription> {\n const customerId = await this.resolveCustomerId(input.customerId, input.externalCustomerId);\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions', {\n applicationId: input.applicationId,\n customerId,\n planReference: input.planReference,\n planName: input.planName,\n interval: input.interval,\n amount: input.amount,\n currency: input.currency,\n currentPeriodStart: toIso(input.currentPeriodStart),\n currentPeriodEnd: toIso(input.currentPeriodEnd),\n trialEnd: toIso(input.trialEnd),\n metadata: input.metadata ?? {},\n });\n return normalizeSubscription(data);\n }\n\n async list(params: ListSubscriptionsParams = {}): Promise<PaginatedSubscriptions> {\n const query = new URLSearchParams();\n setQuery(query, 'customerId', params.customerId);\n setQuery(query, 'externalCustomerId', params.externalCustomerId);\n setQuery(query, 'status', params.status);\n setQuery(query, 'interval', params.interval);\n setQuery(query, 'q', params.q);\n setQuery(query, 'cursor', params.cursor);\n setQuery(query, 'limit', params.limit);\n setQuery(query, 'sort', params.sort);\n setQuery(query, 'createdAfter', toIso(params.createdAfter));\n setQuery(query, 'createdBefore', toIso(params.createdBefore));\n\n const suffix = query.toString() ? `?${query}` : '';\n const envelope = await this.requestEnvelope<unknown[]>('GET', `/api/v1/subscriptions${suffix}`);\n return {\n data: (envelope.data ?? []).map(normalizeSubscription),\n pagination: normalizePagination(envelope.meta?.pagination),\n };\n }\n\n async get(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n );\n return normalizeSubscription(data);\n }\n\n async update(id: string, input: UpdateSubscriptionInput): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'PATCH',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n input,\n );\n return normalizeSubscription(data);\n }\n\n changePlan(input: ChangePlanInput): Promise<Subscription> {\n const { id, ...body } = input;\n return this.update(id, body);\n }\n\n async pause(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/pause`,\n );\n return normalizeSubscription(data);\n }\n\n async resume(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/resume`,\n );\n return normalizeSubscription(data);\n }\n\n async cancel(id: string, input: { atPeriodEnd?: boolean } = {}): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/cancel`,\n { atPeriodEnd: input.atPeriodEnd ?? false },\n );\n return normalizeSubscription(data);\n }\n\n async createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n async checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult> {\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions/eligibility-check', {\n payment_method_id: input.paymentMethodId,\n });\n return normalizeTrialEligibility(data);\n }\n\n async getCustomerByExternalId(externalId: string): Promise<Customer | null> {\n try {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/customers/by-external/${encodeURIComponent(externalId)}`,\n );\n return normalizeCustomer(data);\n } catch (err) {\n if (err instanceof ThrottleSubscriptionsError && err.statusCode === 404) return null;\n throw err;\n }\n }\n\n async listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/customers/${encodeURIComponent(customerId)}/payment-methods`,\n );\n return (data ?? []).map(normalizeCustomerPaymentMethod);\n }\n\n private async resolveCustomerId(\n customerId?: string,\n externalCustomerId?: string,\n ): Promise<string> {\n if (customerId) return customerId;\n if (!externalCustomerId) {\n throw new ThrottleSubscriptionsError({\n code: 'invalid_request',\n message: 'customerId or externalCustomerId is required',\n statusCode: 400,\n });\n }\n\n const customer = await this.getCustomerByExternalId(externalCustomerId);\n if (!customer) {\n throw new ThrottleSubscriptionsError({\n code: 'customer_not_found',\n message: 'Customer not found',\n statusCode: 404,\n });\n }\n return customer.id;\n }\n}\n\nexport function createSubscriptionsClient(opts: SubscriptionsClientOptions): SubscriptionsClient {\n return new SubscriptionsClient(opts);\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction setQuery(query: URLSearchParams, key: string, value: unknown): void {\n if (value === undefined || value === null || value === '') return;\n query.set(key, String(value));\n}\n"],"mappings":";AAAO,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAgF;AAC1F,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,aAAa,KAAK;AACvB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;;;ACDO,SAAS,sBAAsB,KAAwB;AAC5D,SAAO;AAAA,IACL,IAAI,eAAe,KAAK,IAAI,iBAAiB;AAAA,IAC7C,aAAa,eAAe,KAAK,eAAe,KAAK,WAAW;AAAA,IAChE,eAAe,eAAe,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IACjE,YAAY,eAAe,KAAK,cAAc,KAAK,aAAa,yBAAyB;AAAA,IACzF,QAAS,KAAK,UAAU;AAAA,IACxB,eAAe;AAAA,MACb,KAAK,iBAAiB,KAAK;AAAA,MAC3B;AAAA,IACF;AAAA,IACA,UAAU,eAAe,KAAK,YAAY,KAAK,SAAS;AAAA,IACxD,UAAW,KAAK,YAAY;AAAA,IAC5B,QAAQ,OAAO,KAAK,UAAU,CAAC;AAAA,IAC/B,UAAU,eAAe,KAAK,QAAQ,KAAK;AAAA,IAC3C,oBAAoB;AAAA,MAClB,KAAK,sBAAsB,KAAK;AAAA,MAChC;AAAA,IACF;AAAA,IACA,kBAAkB;AAAA,MAChB,KAAK,oBAAoB,KAAK;AAAA,MAC9B;AAAA,IACF;AAAA,IACA,UAAU,mBAAmB,KAAK,YAAY,KAAK,SAAS;AAAA,IAC5D,mBAAmB,Q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,CAAC,GAAG,IAAI,8BAA8B;AAAA,EACxD;AAAA,EAEA,MAAc,kBACZ,YACA,oBACiB;AACjB,QAAI,WAAY,QAAO;AACvB,QAAI,CAAC,oBAAoB;AACvB,YAAM,IAAI,2BAA2B;AAAA,QACnC,MAAM;AAAA,QACN,SAAS;AAAA,QACT,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AAEA,UAAM,WAAW,MAAM,KAAK,wBAAwB,kBAAkB;AACtE,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,2BAA2B;AAAA,QACnC,MAAM;AAAA,QACN,SAAS;AAAA,QACT,YAAY;AAAA,MACd,CAAC;AAAA,IACH;AACA,WAAO,SAAS;AAAA,EAClB;AACF;AAEO,SAAS,0BAA0B,MAAuD;AAC/F,SAAO,IAAI,oBAAoB,IAAI;AACrC;AAEA,SAAS,cAAc,SAAiB,MAAsB;AAC5D,MAAI,gBAAgB,KAAK,IAAI,EAAG,QAAO;AACvC,SAAO,GAAG,OAAO,GAAG,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI,EAAE;AAC9D;AAEA,SAAS,SAAS,OAAwB,KAAa,OAAsB;AAC3E,MAAI,UAAU,UAAa,UAAU,QAAQ,UAAU,GAAI;AAC3D,QAAM,IAAI,KAAK,OAAO,KAAK,CAAC;AAC9B;","names":[]}
@@ -5,8 +5,8 @@ type SubscriptionInterval = 'weekly' | 'monthly' | 'quarterly' | 'yearly';
5
5
  type SubscriptionSort = 'asc' | 'desc';
6
6
  interface Subscription {
7
7
  id: string;
8
- merchantId?: string | null;
9
- storeId?: string | null;
8
+ workspaceId?: string | null;
9
+ applicationId?: string | null;
10
10
  customerId: string;
11
11
  status: SubscriptionStatus;
12
12
  planReference: string;
@@ -37,6 +37,16 @@ interface Customer {
37
37
  createdAt?: string;
38
38
  updatedAt?: string;
39
39
  }
40
+ interface CustomerPaymentMethod {
41
+ id: string;
42
+ processor?: string | null;
43
+ methodType?: string | null;
44
+ cardBrand?: string | null;
45
+ cardLastFour?: string | null;
46
+ isDefault?: boolean;
47
+ createdAt?: string;
48
+ updatedAt?: string;
49
+ }
40
50
  interface Pagination {
41
51
  cursor: string | null;
42
52
  hasMore: boolean;
@@ -58,7 +68,7 @@ interface ListSubscriptionsParams {
58
68
  createdBefore?: string | Date;
59
69
  }
60
70
  interface CreateSubscriptionInput {
61
- storeId?: string;
71
+ applicationId?: string;
62
72
  customerId?: string;
63
73
  externalCustomerId?: string;
64
74
  planReference: string;
@@ -110,7 +120,7 @@ interface CheckoutCollectInput {
110
120
  billingAddress?: boolean;
111
121
  }
112
122
  interface CreateCheckoutSessionInput {
113
- storeId: string;
123
+ applicationId: string;
114
124
  cartId?: string;
115
125
  externalCartId?: string;
116
126
  customerEmail?: string;
@@ -228,6 +238,7 @@ interface SubscriptionsClientContract {
228
238
  createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
229
239
  checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult>;
230
240
  getCustomerByExternalId(externalId: string): Promise<Customer | null>;
241
+ listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]>;
231
242
  }
232
243
 
233
244
  declare class SubscriptionsClient implements SubscriptionsClientContract {
@@ -252,6 +263,7 @@ declare class SubscriptionsClient implements SubscriptionsClientContract {
252
263
  createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
253
264
  checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult>;
254
265
  getCustomerByExternalId(externalId: string): Promise<Customer | null>;
266
+ listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]>;
255
267
  private resolveCustomerId;
256
268
  }
257
269
  declare function createSubscriptionsClient(opts: SubscriptionsClientOptions): SubscriptionsClient;
@@ -268,4 +280,4 @@ declare class ThrottleSubscriptionsError extends Error {
268
280
  });
269
281
  }
270
282
 
271
- export { type CancelSubscriptionInput as C, type DunningBannerProps as D, type ListSubscriptionsParams as L, type MutationState as M, type PaginatedSubscriptions as P, type QueryOptions as Q, type RecurringIntent as R, type SubscriptionProviderProps as S, type TrialEligibilityResult as T, type UpdateSubscriptionInput as U, type SubscriptionsClientContract as a, type SubscriptionFetcher as b, type Subscription as c, type ChangePlanInput as d, type CheckoutSession as e, type CreateCheckoutSessionInput as f, type CreateSubscriptionInput as g, type Customer as h, type QueryState as i, type TrialEligibilityInput as j, type SubscriptionStatusBadgeProps as k, type TrialCountdownProps as l, type SubscriptionStatus as m, type CheckoutCollectInput as n, type CheckoutCustomerInput as o, type Pagination as p, type SubscriptionInterval as q, type SubscriptionSort as r, SubscriptionsClient as s, type SubscriptionsClientOptions as t, type ThrottleEnvelope as u, ThrottleSubscriptionsError as v, type TrialEligibilityReason as w, createSubscriptionsClient as x };
283
+ export { type CancelSubscriptionInput as C, type DunningBannerProps as D, type ListSubscriptionsParams as L, type MutationState as M, type PaginatedSubscriptions as P, type QueryOptions as Q, type RecurringIntent as R, type SubscriptionProviderProps as S, type TrialEligibilityResult as T, type UpdateSubscriptionInput as U, type SubscriptionsClientContract as a, type SubscriptionFetcher as b, type Subscription as c, type ChangePlanInput as d, type CheckoutSession as e, type CreateCheckoutSessionInput as f, type CreateSubscriptionInput as g, type Customer as h, type QueryState as i, type CustomerPaymentMethod as j, type TrialEligibilityInput as k, type SubscriptionStatusBadgeProps as l, type TrialCountdownProps as m, type SubscriptionStatus as n, type CheckoutCollectInput as o, type CheckoutCustomerInput as p, type Pagination as q, type SubscriptionInterval as r, type SubscriptionSort as s, SubscriptionsClient as t, type SubscriptionsClientOptions as u, type ThrottleEnvelope as v, ThrottleSubscriptionsError as w, type TrialEligibilityReason as x, createSubscriptionsClient as y };
@@ -5,8 +5,8 @@ type SubscriptionInterval = 'weekly' | 'monthly' | 'quarterly' | 'yearly';
5
5
  type SubscriptionSort = 'asc' | 'desc';
6
6
  interface Subscription {
7
7
  id: string;
8
- merchantId?: string | null;
9
- storeId?: string | null;
8
+ workspaceId?: string | null;
9
+ applicationId?: string | null;
10
10
  customerId: string;
11
11
  status: SubscriptionStatus;
12
12
  planReference: string;
@@ -37,6 +37,16 @@ interface Customer {
37
37
  createdAt?: string;
38
38
  updatedAt?: string;
39
39
  }
40
+ interface CustomerPaymentMethod {
41
+ id: string;
42
+ processor?: string | null;
43
+ methodType?: string | null;
44
+ cardBrand?: string | null;
45
+ cardLastFour?: string | null;
46
+ isDefault?: boolean;
47
+ createdAt?: string;
48
+ updatedAt?: string;
49
+ }
40
50
  interface Pagination {
41
51
  cursor: string | null;
42
52
  hasMore: boolean;
@@ -58,7 +68,7 @@ interface ListSubscriptionsParams {
58
68
  createdBefore?: string | Date;
59
69
  }
60
70
  interface CreateSubscriptionInput {
61
- storeId?: string;
71
+ applicationId?: string;
62
72
  customerId?: string;
63
73
  externalCustomerId?: string;
64
74
  planReference: string;
@@ -110,7 +120,7 @@ interface CheckoutCollectInput {
110
120
  billingAddress?: boolean;
111
121
  }
112
122
  interface CreateCheckoutSessionInput {
113
- storeId: string;
123
+ applicationId: string;
114
124
  cartId?: string;
115
125
  externalCartId?: string;
116
126
  customerEmail?: string;
@@ -228,6 +238,7 @@ interface SubscriptionsClientContract {
228
238
  createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
229
239
  checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult>;
230
240
  getCustomerByExternalId(externalId: string): Promise<Customer | null>;
241
+ listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]>;
231
242
  }
232
243
 
233
244
  declare class SubscriptionsClient implements SubscriptionsClientContract {
@@ -252,6 +263,7 @@ declare class SubscriptionsClient implements SubscriptionsClientContract {
252
263
  createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
253
264
  checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult>;
254
265
  getCustomerByExternalId(externalId: string): Promise<Customer | null>;
266
+ listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]>;
255
267
  private resolveCustomerId;
256
268
  }
257
269
  declare function createSubscriptionsClient(opts: SubscriptionsClientOptions): SubscriptionsClient;
@@ -268,4 +280,4 @@ declare class ThrottleSubscriptionsError extends Error {
268
280
  });
269
281
  }
270
282
 
271
- export { type CancelSubscriptionInput as C, type DunningBannerProps as D, type ListSubscriptionsParams as L, type MutationState as M, type PaginatedSubscriptions as P, type QueryOptions as Q, type RecurringIntent as R, type SubscriptionProviderProps as S, type TrialEligibilityResult as T, type UpdateSubscriptionInput as U, type SubscriptionsClientContract as a, type SubscriptionFetcher as b, type Subscription as c, type ChangePlanInput as d, type CheckoutSession as e, type CreateCheckoutSessionInput as f, type CreateSubscriptionInput as g, type Customer as h, type QueryState as i, type TrialEligibilityInput as j, type SubscriptionStatusBadgeProps as k, type TrialCountdownProps as l, type SubscriptionStatus as m, type CheckoutCollectInput as n, type CheckoutCustomerInput as o, type Pagination as p, type SubscriptionInterval as q, type SubscriptionSort as r, SubscriptionsClient as s, type SubscriptionsClientOptions as t, type ThrottleEnvelope as u, ThrottleSubscriptionsError as v, type TrialEligibilityReason as w, createSubscriptionsClient as x };
283
+ export { type CancelSubscriptionInput as C, type DunningBannerProps as D, type ListSubscriptionsParams as L, type MutationState as M, type PaginatedSubscriptions as P, type QueryOptions as Q, type RecurringIntent as R, type SubscriptionProviderProps as S, type TrialEligibilityResult as T, type UpdateSubscriptionInput as U, type SubscriptionsClientContract as a, type SubscriptionFetcher as b, type Subscription as c, type ChangePlanInput as d, type CheckoutSession as e, type CreateCheckoutSessionInput as f, type CreateSubscriptionInput as g, type Customer as h, type QueryState as i, type CustomerPaymentMethod as j, type TrialEligibilityInput as k, type SubscriptionStatusBadgeProps as l, type TrialCountdownProps as m, type SubscriptionStatus as n, type CheckoutCollectInput as o, type CheckoutCustomerInput as p, type Pagination as q, type SubscriptionInterval as r, type SubscriptionSort as s, SubscriptionsClient as t, type SubscriptionsClientOptions as u, type ThrottleEnvelope as v, ThrottleSubscriptionsError as w, type TrialEligibilityReason as x, createSubscriptionsClient as y };
package/dist/index.cjs CHANGED
@@ -41,6 +41,7 @@ __export(index_exports, {
41
41
  useCreateCheckoutSession: () => useCreateCheckoutSession,
42
42
  useCreateSubscription: () => useCreateSubscription,
43
43
  useCustomerByExternalId: () => useCustomerByExternalId,
44
+ useCustomerPaymentMethods: () => useCustomerPaymentMethods,
44
45
  usePauseSubscription: () => usePauseSubscription,
45
46
  useResumeSubscription: () => useResumeSubscription,
46
47
  useSubscription: () => useSubscription,
@@ -70,8 +71,8 @@ var ThrottleSubscriptionsError = class extends Error {
70
71
  function normalizeSubscription(raw) {
71
72
  return {
72
73
  id: requiredString(raw?.id, "subscription.id"),
73
- merchantId: optionalString(raw?.merchantId ?? raw?.merchant_id),
74
- storeId: optionalString(raw?.storeId ?? raw?.store_id),
74
+ workspaceId: optionalString(raw?.workspaceId ?? raw?.merchant_id),
75
+ applicationId: optionalString(raw?.applicationId ?? raw?.store_id),
75
76
  customerId: requiredString(raw?.customerId ?? raw?.customer_id, "subscription.customerId"),
76
77
  status: raw?.status ?? "active",
77
78
  planReference: requiredString(
@@ -115,6 +116,18 @@ function normalizeCustomer(raw) {
115
116
  updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? void 0
116
117
  };
117
118
  }
119
+ function normalizeCustomerPaymentMethod(raw) {
120
+ return {
121
+ id: requiredString(raw?.id, "paymentMethod.id"),
122
+ processor: optionalString(raw?.processor),
123
+ methodType: optionalString(raw?.methodType ?? raw?.method_type),
124
+ cardBrand: optionalString(raw?.cardBrand ?? raw?.card_brand),
125
+ cardLastFour: optionalString(raw?.cardLastFour ?? raw?.card_last_four),
126
+ isDefault: Boolean(raw?.isDefault ?? raw?.is_default ?? false),
127
+ createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? void 0,
128
+ updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? void 0
129
+ };
130
+ }
118
131
  function normalizeCheckoutSession(raw) {
119
132
  const sessionId = raw?.sessionId ?? raw?.session_id ?? raw?.id;
120
133
  return {
@@ -222,7 +235,7 @@ var SubscriptionsClient = class {
222
235
  async create(input) {
223
236
  const customerId = await this.resolveCustomerId(input.customerId, input.externalCustomerId);
224
237
  const data = await this.request("POST", "/api/v1/subscriptions", {
225
- storeId: input.storeId,
238
+ applicationId: input.applicationId,
226
239
  customerId,
227
240
  planReference: input.planReference,
228
241
  planName: input.planName,
@@ -318,6 +331,13 @@ var SubscriptionsClient = class {
318
331
  throw err;
319
332
  }
320
333
  }
334
+ async listCustomerPaymentMethods(customerId) {
335
+ const data = await this.request(
336
+ "GET",
337
+ `/api/v1/customers/${encodeURIComponent(customerId)}/payment-methods`
338
+ );
339
+ return (data ?? []).map(normalizeCustomerPaymentMethod);
340
+ }
321
341
  async resolveCustomerId(customerId, externalCustomerId) {
322
342
  if (customerId) return customerId;
323
343
  if (!externalCustomerId) {
@@ -440,6 +460,15 @@ function useCustomerByExternalId(externalId, options = {}) {
440
460
  { ...options, enabled: options.enabled ?? Boolean(externalId) }
441
461
  );
442
462
  }
463
+ function useCustomerPaymentMethods(customerId, options = {}) {
464
+ const client = useSubscriptionClient();
465
+ const cacheVersion = useSubscriptionCacheVersion();
466
+ return useAsyncQuery(
467
+ () => customerId ? client.listCustomerPaymentMethods(customerId) : Promise.resolve(null),
468
+ [client, customerId, cacheVersion],
469
+ { ...options, enabled: options.enabled ?? Boolean(customerId) }
470
+ );
471
+ }
443
472
  function useTrialEligibility() {
444
473
  const client = useSubscriptionClient();
445
474
  return useAsyncMutation((input) => client.checkTrialEligibility(input));
@@ -727,6 +756,7 @@ function DunningBanner({
727
756
  useCreateCheckoutSession,
728
757
  useCreateSubscription,
729
758
  useCustomerByExternalId,
759
+ useCustomerPaymentMethods,
730
760
  usePauseSubscription,
731
761
  useResumeSubscription,
732
762
  useSubscription,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/errors.ts","../src/normalize.ts","../src/client.ts","../src/provider.tsx","../src/hooks.ts","../src/helpers.ts","../src/components.tsx"],"sourcesContent":["export { SubscriptionsClient, createSubscriptionsClient } from './client';\nexport { ThrottleSubscriptionsError } from './errors';\nexport {\n SubscriptionProvider,\n SubscriptionProviderWithClient,\n createSubscriptionFetcher,\n useSubscriptionClient,\n useSubscriptionInvalidation,\n} from './provider';\nexport {\n useCancelSubscription,\n useChangePlan,\n useCreateCheckoutSession,\n useCreateSubscription,\n useCustomerByExternalId,\n usePauseSubscription,\n useResumeSubscription,\n useSubscription,\n useSubscriptions,\n useTrialEligibility,\n useUpdateSubscription,\n} from './hooks';\nexport { DunningBanner, SubscriptionStatusBadge, TrialCountdown } from './components';\nexport {\n canCancelSubscription,\n canPauseSubscription,\n canResumeSubscription,\n daysUntil,\n isSubscriptionPastDue,\n isSubscriptionTrialing,\n isTerminalSubscription,\n} from './helpers';\nexport type * from './types';\n","export class ThrottleSubscriptionsError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n\n constructor(args: { code: string; message: string; statusCode: number; details?: unknown }) {\n super(args.message);\n this.name = 'ThrottleSubscriptionsError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n }\n}\n","import type {\n CheckoutSession,\n Customer,\n Pagination,\n Subscription,\n SubscriptionInterval,\n SubscriptionStatus,\n TrialEligibilityResult,\n} from './types';\n\nexport function normalizeSubscription(raw: any): Subscription {\n return {\n id: requiredString(raw?.id, 'subscription.id'),\n merchantId: optionalString(raw?.merchantId ?? raw?.merchant_id),\n storeId: optionalString(raw?.storeId ?? raw?.store_id),\n customerId: requiredString(raw?.customerId ?? raw?.customer_id, 'subscription.customerId'),\n status: (raw?.status ?? 'active') as SubscriptionStatus,\n planReference: requiredString(\n raw?.planReference ?? raw?.plan_reference,\n 'subscription.planReference',\n ),\n planName: optionalString(raw?.planName ?? raw?.plan_name),\n interval: (raw?.interval ?? 'monthly') as SubscriptionInterval,\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n currentPeriodStart: requiredDateString(\n raw?.currentPeriodStart ?? raw?.current_period_start,\n 'subscription.currentPeriodStart',\n ),\n currentPeriodEnd: requiredDateString(\n raw?.currentPeriodEnd ?? raw?.current_period_end,\n 'subscription.currentPeriodEnd',\n ),\n trialEnd: optionalDateString(raw?.trialEnd ?? raw?.trial_end),\n cancelAtPeriodEnd: Boolean(raw?.cancelAtPeriodEnd ?? raw?.cancel_at_period_end ?? false),\n failureCount: Number(raw?.failureCount ?? raw?.failure_count ?? 0),\n lastPaymentAt: optionalDateString(raw?.lastPaymentAt ?? raw?.last_payment_at),\n pausedAt: optionalDateString(raw?.pausedAt ?? raw?.paused_at),\n cancelledAt: optionalDateString(raw?.cancelledAt ?? raw?.cancelled_at),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCustomer(raw: any): Customer | null {\n if (!raw) return null;\n return {\n id: requiredString(raw?.id, 'customer.id'),\n externalId: optionalString(raw?.externalId ?? raw?.external_id),\n email: optionalString(raw?.email),\n firstName: optionalString(raw?.firstName ?? raw?.first_name),\n lastName: optionalString(raw?.lastName ?? raw?.last_name),\n phone: optionalString(raw?.phone),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url),\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token),\n expiresAt: optionalDateString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nexport function normalizeTrialEligibility(raw: any): TrialEligibilityResult {\n return {\n eligible: Boolean(raw?.eligible),\n reason: raw?.reason,\n };\n}\n\nexport function normalizePagination(raw: any): Pagination | undefined {\n if (!raw) return undefined;\n return {\n cursor: raw.cursor ?? null,\n hasMore: Boolean(raw.hasMore ?? raw.has_more ?? false),\n };\n}\n\nexport function toIso(value: string | Date | undefined): string | undefined {\n if (value === undefined) return undefined;\n return value instanceof Date ? value.toISOString() : value;\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' ? value : null;\n}\n\nfunction requiredDateString(value: unknown, label: string): string {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalDateString(value: unknown): string | null {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n return null;\n}\n\nfunction objectOrEmpty(value: unknown): Record<string, unknown> {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {};\n}\n","import { ThrottleSubscriptionsError } from './errors';\nimport {\n normalizeCheckoutSession,\n normalizeCustomer,\n normalizePagination,\n normalizeSubscription,\n normalizeTrialEligibility,\n toIso,\n} from './normalize';\nimport type {\n ChangePlanInput,\n CheckoutSession,\n CreateCheckoutSessionInput,\n CreateSubscriptionInput,\n Customer,\n ListSubscriptionsParams,\n PaginatedSubscriptions,\n Subscription,\n SubscriptionsClientContract,\n SubscriptionsClientOptions,\n ThrottleEnvelope,\n TrialEligibilityInput,\n TrialEligibilityResult,\n UpdateSubscriptionInput,\n} from './types';\n\nexport class SubscriptionsClient implements SubscriptionsClientContract {\n private readonly apiKey?: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly fetcher?: SubscriptionsClientOptions['fetcher'];\n private readonly timeoutMs: number;\n\n constructor(opts: SubscriptionsClientOptions = {}) {\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('SubscriptionsClient: fetch is required');\n if (!opts.apiKey && !opts.fetcher) {\n throw new Error('SubscriptionsClient: apiKey or fetcher is required');\n }\n\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.fetcher = opts.fetcher;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const init: RequestInit = {\n method,\n headers: {\n 'content-type': 'application/json',\n ...(this.apiKey ? { 'x-api-key': this.apiKey } : {}),\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n };\n\n const res = this.fetcher\n ? await this.fetcher(path, init)\n : await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), init);\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleSubscriptionsError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async create(input: CreateSubscriptionInput): Promise<Subscription> {\n const customerId = await this.resolveCustomerId(input.customerId, input.externalCustomerId);\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions', {\n storeId: input.storeId,\n customerId,\n planReference: input.planReference,\n planName: input.planName,\n interval: input.interval,\n amount: input.amount,\n currency: input.currency,\n currentPeriodStart: toIso(input.currentPeriodStart),\n currentPeriodEnd: toIso(input.currentPeriodEnd),\n trialEnd: toIso(input.trialEnd),\n metadata: input.metadata ?? {},\n });\n return normalizeSubscription(data);\n }\n\n async list(params: ListSubscriptionsParams = {}): Promise<PaginatedSubscriptions> {\n const query = new URLSearchParams();\n setQuery(query, 'customerId', params.customerId);\n setQuery(query, 'externalCustomerId', params.externalCustomerId);\n setQuery(query, 'status', params.status);\n setQuery(query, 'interval', params.interval);\n setQuery(query, 'q', params.q);\n setQuery(query, 'cursor', params.cursor);\n setQuery(query, 'limit', params.limit);\n setQuery(query, 'sort', params.sort);\n setQuery(query, 'createdAfter', toIso(params.createdAfter));\n setQuery(query, 'createdBefore', toIso(params.createdBefore));\n\n const suffix = query.toString() ? `?${query}` : '';\n const envelope = await this.requestEnvelope<unknown[]>('GET', `/api/v1/subscriptions${suffix}`);\n return {\n data: (envelope.data ?? []).map(normalizeSubscription),\n pagination: normalizePagination(envelope.meta?.pagination),\n };\n }\n\n async get(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n );\n return normalizeSubscription(data);\n }\n\n async update(id: string, input: UpdateSubscriptionInput): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'PATCH',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n input,\n );\n return normalizeSubscription(data);\n }\n\n changePlan(input: ChangePlanInput): Promise<Subscription> {\n const { id, ...body } = input;\n return this.update(id, body);\n }\n\n async pause(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/pause`,\n );\n return normalizeSubscription(data);\n }\n\n async resume(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/resume`,\n );\n return normalizeSubscription(data);\n }\n\n async cancel(id: string, input: { atPeriodEnd?: boolean } = {}): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/cancel`,\n { atPeriodEnd: input.atPeriodEnd ?? false },\n );\n return normalizeSubscription(data);\n }\n\n async createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n async checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult> {\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions/eligibility-check', {\n payment_method_id: input.paymentMethodId,\n });\n return normalizeTrialEligibility(data);\n }\n\n async getCustomerByExternalId(externalId: string): Promise<Customer | null> {\n try {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/customers/by-external/${encodeURIComponent(externalId)}`,\n );\n return normalizeCustomer(data);\n } catch (err) {\n if (err instanceof ThrottleSubscriptionsError && err.statusCode === 404) return null;\n throw err;\n }\n }\n\n private async resolveCustomerId(\n customerId?: string,\n externalCustomerId?: string,\n ): Promise<string> {\n if (customerId) return customerId;\n if (!externalCustomerId) {\n throw new ThrottleSubscriptionsError({\n code: 'invalid_request',\n message: 'customerId or externalCustomerId is required',\n statusCode: 400,\n });\n }\n\n const customer = await this.getCustomerByExternalId(externalCustomerId);\n if (!customer) {\n throw new ThrottleSubscriptionsError({\n code: 'customer_not_found',\n message: 'Customer not found',\n statusCode: 404,\n });\n }\n return customer.id;\n }\n}\n\nexport function createSubscriptionsClient(opts: SubscriptionsClientOptions): SubscriptionsClient {\n return new SubscriptionsClient(opts);\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction setQuery(query: URLSearchParams, key: string, value: unknown): void {\n if (value === undefined || value === null || value === '') return;\n query.set(key, String(value));\n}\n","import { createContext, useCallback, useContext, useMemo, useReducer, type ReactNode } from 'react';\nimport { SubscriptionsClient } from './client';\nimport type {\n SubscriptionFetcher,\n SubscriptionProviderProps,\n SubscriptionsClientContract,\n} from './types';\n\ninterface SubscriptionContextValue {\n client: SubscriptionsClientContract;\n cacheVersion: number;\n invalidate: () => void;\n}\n\nconst SubscriptionContext = createContext<SubscriptionContextValue | null>(null);\n\nexport function SubscriptionProvider({\n children,\n client,\n fetcher,\n baseUrl,\n timeoutMs,\n}: SubscriptionProviderProps) {\n const [cacheVersion, invalidate] = useReducer((value: number) => value + 1, 0);\n const resolvedClient = useMemo(() => {\n if (client) return client;\n return new SubscriptionsClient({\n fetcher: fetcher ?? createSubscriptionFetcher('/api/throttle'),\n baseUrl,\n timeoutMs,\n });\n }, [baseUrl, client, fetcher, timeoutMs]);\n\n const value = useMemo(\n () => ({ client: resolvedClient, cacheVersion, invalidate }),\n [cacheVersion, resolvedClient],\n );\n\n return <SubscriptionContext.Provider value={value}>{children}</SubscriptionContext.Provider>;\n}\n\nexport function useSubscriptionClient(): SubscriptionsClientContract {\n return useSubscriptionContext().client;\n}\n\nexport function useSubscriptionInvalidation(): () => void {\n return useSubscriptionContext().invalidate;\n}\n\nexport function useSubscriptionCacheVersion(): number {\n return useSubscriptionContext().cacheVersion;\n}\n\nexport function createSubscriptionFetcher(basePath: string): SubscriptionFetcher {\n const cleanBase = basePath.replace(/\\/+$/, '');\n return (path, init) => {\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return fetch(`${cleanBase}${cleanPath}`, init);\n };\n}\n\nexport function useSubscriptionContext(): SubscriptionContextValue {\n const ctx = useContext(SubscriptionContext);\n if (!ctx) {\n throw new Error(\n '@usethrottle/subscriptions hooks must be used inside <SubscriptionProvider />',\n );\n }\n return ctx;\n}\n\nexport function SubscriptionProviderWithClient({\n children,\n client,\n}: {\n children: ReactNode;\n client: SubscriptionsClientContract;\n}) {\n const [cacheVersion, invalidate] = useReducer((value: number) => value + 1, 0);\n const value = useMemo(() => ({ client, cacheVersion, invalidate }), [cacheVersion, client]);\n return <SubscriptionContext.Provider value={value}>{children}</SubscriptionContext.Provider>;\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n useSubscriptionCacheVersion,\n useSubscriptionClient,\n useSubscriptionInvalidation,\n} from './provider';\nimport type {\n CancelSubscriptionInput,\n ChangePlanInput,\n CheckoutSession,\n CreateCheckoutSessionInput,\n CreateSubscriptionInput,\n Customer,\n ListSubscriptionsParams,\n MutationState,\n PaginatedSubscriptions,\n QueryOptions,\n QueryState,\n Subscription,\n TrialEligibilityInput,\n TrialEligibilityResult,\n UpdateSubscriptionInput,\n} from './types';\n\nexport function useSubscriptions(\n params: ListSubscriptionsParams = {},\n options: QueryOptions<PaginatedSubscriptions> = {},\n): QueryState<PaginatedSubscriptions> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n const stableParams = useStableValue(params);\n return useAsyncQuery(\n () => client.list(stableParams),\n [client, stableParams, cacheVersion],\n options,\n );\n}\n\nexport function useSubscription(\n id: string | null | undefined,\n options: QueryOptions<Subscription> = {},\n): QueryState<Subscription> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n return useAsyncQuery(\n () => (id ? client.get(id) : Promise.resolve(null)),\n [client, id, cacheVersion],\n { ...options, enabled: options.enabled ?? Boolean(id) },\n );\n}\n\nexport function useCustomerByExternalId(\n externalId: string | null | undefined,\n options: QueryOptions<Customer> = {},\n): QueryState<Customer> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n return useAsyncQuery(\n () => (externalId ? client.getCustomerByExternalId(externalId) : Promise.resolve(null)),\n [client, externalId, cacheVersion],\n { ...options, enabled: options.enabled ?? Boolean(externalId) },\n );\n}\n\nexport function useTrialEligibility(): MutationState<\n TrialEligibilityResult,\n TrialEligibilityInput\n> {\n const client = useSubscriptionClient();\n return useAsyncMutation((input) => client.checkTrialEligibility(input));\n}\n\nexport function useCreateSubscription(): MutationState<Subscription, CreateSubscriptionInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.create(input), invalidate);\n}\n\nexport function useUpdateSubscription(): MutationState<\n Subscription,\n { id: string; data: UpdateSubscriptionInput }\n> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation(({ id, data }) => client.update(id, data), invalidate);\n}\n\nexport function useChangePlan(): MutationState<Subscription, ChangePlanInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.changePlan(input), invalidate);\n}\n\nexport function useCancelSubscription(): MutationState<Subscription, CancelSubscriptionInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation(\n (input) => client.cancel(input.id, { atPeriodEnd: input.atPeriodEnd }),\n invalidate,\n );\n}\n\nexport function usePauseSubscription(): MutationState<Subscription, { id: string }> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.pause(input.id), invalidate);\n}\n\nexport function useResumeSubscription(): MutationState<Subscription, { id: string }> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.resume(input.id), invalidate);\n}\n\nexport function useCreateCheckoutSession(): MutationState<\n CheckoutSession,\n CreateCheckoutSessionInput\n> {\n const client = useSubscriptionClient();\n return useAsyncMutation((input) => client.createCheckoutSession(input));\n}\n\nfunction useAsyncQuery<T>(\n load: () => Promise<T | null>,\n deps: readonly unknown[],\n options: QueryOptions<T>,\n): QueryState<T> {\n const enabled = options.enabled ?? true;\n const [data, setData] = useState<T | null>(options.initialData ?? null);\n const [error, setError] = useState<unknown>(null);\n const [isLoading, setIsLoading] = useState(enabled && options.initialData === undefined);\n const [isFetching, setIsFetching] = useState(false);\n const loadRef = useRef(load);\n loadRef.current = load;\n\n const refetch = useCallback(async () => {\n if (!enabled) return data;\n setIsFetching(true);\n setError(null);\n try {\n const next = await loadRef.current();\n setData(next);\n return next;\n } catch (err) {\n setError(err);\n throw err;\n } finally {\n setIsFetching(false);\n setIsLoading(false);\n }\n }, [data, enabled]);\n\n useEffect(() => {\n if (!enabled) {\n setIsLoading(false);\n return;\n }\n let cancelled = false;\n setIsFetching(true);\n setError(null);\n load()\n .then((next) => {\n if (!cancelled) setData(next);\n })\n .catch((err) => {\n if (!cancelled) setError(err);\n })\n .finally(() => {\n if (!cancelled) {\n setIsLoading(false);\n setIsFetching(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [enabled, ...deps]);\n\n return { data, error, isLoading, isFetching, refetch };\n}\n\nfunction useAsyncMutation<TData, TVariables>(\n action: (variables: TVariables) => Promise<TData>,\n onSuccess?: () => void,\n): MutationState<TData, TVariables> {\n const [data, setData] = useState<TData | null>(null);\n const [error, setError] = useState<unknown>(null);\n const [isPending, setIsPending] = useState(false);\n\n const mutateAsync = useCallback(\n async (variables: TVariables) => {\n setIsPending(true);\n setError(null);\n try {\n const next = await action(variables);\n setData(next);\n onSuccess?.();\n return next;\n } catch (err) {\n setError(err);\n throw err;\n } finally {\n setIsPending(false);\n }\n },\n [action, onSuccess],\n );\n\n const mutate = useCallback(\n (variables: TVariables) => {\n void mutateAsync(variables).catch(() => undefined);\n },\n [mutateAsync],\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setIsPending(false);\n }, []);\n\n return { data, error, isPending, mutate, mutateAsync, reset };\n}\n\nfunction useStableValue<T>(value: T): T {\n const key = JSON.stringify(value);\n return useMemo(() => value, [key]);\n}\n","import type { Subscription, SubscriptionStatus } from './types';\n\nexport function isTerminalSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'cancelled';\n}\n\nexport function canPauseSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'active';\n}\n\nexport function canResumeSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'paused';\n}\n\nexport function canCancelSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) !== 'cancelled';\n}\n\nexport function isSubscriptionPastDue(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'past_due';\n}\n\nexport function isSubscriptionTrialing(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'trialing';\n}\n\nexport function daysUntil(date: string | Date, now = new Date()): number {\n const end = date instanceof Date ? date : new Date(date);\n const ms = end.getTime() - now.getTime();\n if (!Number.isFinite(ms)) return 0;\n return Math.max(0, Math.ceil(ms / 86_400_000));\n}\n\nfunction getStatus(input: SubscriptionStatus | Subscription): SubscriptionStatus {\n return typeof input === 'string' ? input : input.status;\n}\n","import type { CSSProperties } from 'react';\nimport { daysUntil } from './helpers';\nimport type {\n DunningBannerProps,\n SubscriptionStatus,\n SubscriptionStatusBadgeProps,\n TrialCountdownProps,\n} from './types';\n\nconst STATUS_LABELS: Record<SubscriptionStatus, string> = {\n active: 'Active',\n paused: 'Paused',\n cancelled: 'Cancelled',\n past_due: 'Past due',\n trialing: 'Trialing',\n};\n\nconst STATUS_STYLES: Record<SubscriptionStatus, CSSProperties> = {\n active: { color: '#035c4f', background: '#dff8ef', borderColor: '#a8e8d2' },\n paused: { color: '#735c00', background: '#fff4ca', borderColor: '#f3d46b' },\n cancelled: { color: '#6c2632', background: '#ffe1e7', borderColor: '#f4a9b8' },\n past_due: { color: '#7a2d00', background: '#ffe8d6', borderColor: '#f5b47f' },\n trialing: { color: '#124c73', background: '#dff1ff', borderColor: '#9ed3fb' },\n};\n\nexport function SubscriptionStatusBadge({\n status,\n className,\n style,\n labels,\n}: SubscriptionStatusBadgeProps) {\n return (\n <span\n className={className}\n style={{\n display: 'inline-flex',\n alignItems: 'center',\n border: '1px solid',\n borderRadius: 999,\n padding: '2px 8px',\n fontSize: 12,\n fontWeight: 700,\n lineHeight: 1.6,\n whiteSpace: 'nowrap',\n ...STATUS_STYLES[status],\n ...style,\n }}\n >\n {labels?.[status] ?? STATUS_LABELS[status]}\n </span>\n );\n}\n\nexport function TrialCountdown({\n endDate,\n now,\n className,\n style,\n expiredLabel = 'Trial ended',\n prefix = 'Trial ends in',\n}: TrialCountdownProps) {\n const days = daysUntil(endDate, now);\n const label = days <= 0 ? expiredLabel : `${prefix} ${days} ${days === 1 ? 'day' : 'days'}`;\n\n return (\n <span className={className} style={style}>\n {label}\n </span>\n );\n}\n\nexport function DunningBanner({\n subscription,\n onUpdateCard,\n title = 'Payment needs attention',\n message,\n actionLabel = 'Update card',\n className,\n style,\n}: DunningBannerProps) {\n if (subscription.status !== 'past_due') return null;\n const fallbackMessage =\n subscription.failureCount > 0\n ? `We could not renew this subscription after ${subscription.failureCount} failed payment attempt${\n subscription.failureCount === 1 ? '' : 's'\n }.`\n : 'We could not renew this subscription with the saved payment method.';\n\n return (\n <div\n role=\"status\"\n className={className}\n style={{\n border: '1px solid #f5b47f',\n borderRadius: 8,\n background: '#fff7ed',\n color: '#7a2d00',\n padding: 16,\n display: 'grid',\n gap: 10,\n ...style,\n }}\n >\n <strong>{title}</strong>\n <span>{message ?? fallbackMessage}</span>\n {onUpdateCard ? (\n <button\n type=\"button\"\n onClick={onUpdateCard}\n style={{\n width: 'fit-content',\n border: '1px solid #7a2d00',\n borderRadius: 6,\n background: '#7a2d00',\n color: '#fff',\n padding: '8px 12px',\n fontWeight: 700,\n cursor: 'pointer',\n }}\n >\n {actionLabel}\n </button>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAC3C;AAAA,EAC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AAM;AAEzF,SACE,6CAAC,UAAK,WAAsB,OACzB,iBACH;AAEJ;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA;AACF,GAAuB;AACrB,MAAI,aAAa,WAAW,WAAY,QAAO;AAC/C,QAAM,kBACJ,aAAa,eAAe,IACxB,8CAA8C,aAAa,YAAY,0BACrE,aAAa,iBAAiB,IAAI,KAAK,GACzC,MACA;AAEN,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL;AAAA,MACA,OAAO;AAAA,QACL,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,YAAY;AAAA,QACZ,OAAO;AAAA,QACP,SAAS;AAAA,QACT,SAAS;AAAA,QACT,KAAK;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MAEA;AAAA,qDAAC,YAAQ,iBAAM;AAAA,QACf,6CAAC,UAAM,qBAAW,iBAAgB;AAAA,QACjC,eACC;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,SAAS;AAAA,YACT,OAAO;AAAA,cACL,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,cAAc;AAAA,cACd,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,QAAQ;AAAA,YACV;AAAA,YAEC;AAAA;AAAA,QACH,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["value","import_react","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.tsx","../src/errors.ts","../src/normalize.ts","../src/client.ts","../src/provider.tsx","../src/hooks.ts","../src/helpers.ts","../src/components.tsx"],"sourcesContent":["export { SubscriptionsClient, createSubscriptionsClient } from './client';\nexport { ThrottleSubscriptionsError } from './errors';\nexport {\n SubscriptionProvider,\n SubscriptionProviderWithClient,\n createSubscriptionFetcher,\n useSubscriptionClient,\n useSubscriptionInvalidation,\n} from './provider';\nexport {\n useCancelSubscription,\n useChangePlan,\n useCreateCheckoutSession,\n useCreateSubscription,\n useCustomerByExternalId,\n useCustomerPaymentMethods,\n usePauseSubscription,\n useResumeSubscription,\n useSubscription,\n useSubscriptions,\n useTrialEligibility,\n useUpdateSubscription,\n} from './hooks';\nexport { DunningBanner, SubscriptionStatusBadge, TrialCountdown } from './components';\nexport {\n canCancelSubscription,\n canPauseSubscription,\n canResumeSubscription,\n daysUntil,\n isSubscriptionPastDue,\n isSubscriptionTrialing,\n isTerminalSubscription,\n} from './helpers';\nexport type * from './types';\n","export class ThrottleSubscriptionsError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n\n constructor(args: { code: string; message: string; statusCode: number; details?: unknown }) {\n super(args.message);\n this.name = 'ThrottleSubscriptionsError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n }\n}\n","import type {\n CheckoutSession,\n Customer,\n CustomerPaymentMethod,\n Pagination,\n Subscription,\n SubscriptionInterval,\n SubscriptionStatus,\n TrialEligibilityResult,\n} from './types';\n\nexport function normalizeSubscription(raw: any): Subscription {\n return {\n id: requiredString(raw?.id, 'subscription.id'),\n workspaceId: optionalString(raw?.workspaceId ?? raw?.merchant_id),\n applicationId: optionalString(raw?.applicationId ?? raw?.store_id),\n customerId: requiredString(raw?.customerId ?? raw?.customer_id, 'subscription.customerId'),\n status: (raw?.status ?? 'active') as SubscriptionStatus,\n planReference: requiredString(\n raw?.planReference ?? raw?.plan_reference,\n 'subscription.planReference',\n ),\n planName: optionalString(raw?.planName ?? raw?.plan_name),\n interval: (raw?.interval ?? 'monthly') as SubscriptionInterval,\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n currentPeriodStart: requiredDateString(\n raw?.currentPeriodStart ?? raw?.current_period_start,\n 'subscription.currentPeriodStart',\n ),\n currentPeriodEnd: requiredDateString(\n raw?.currentPeriodEnd ?? raw?.current_period_end,\n 'subscription.currentPeriodEnd',\n ),\n trialEnd: optionalDateString(raw?.trialEnd ?? raw?.trial_end),\n cancelAtPeriodEnd: Boolean(raw?.cancelAtPeriodEnd ?? raw?.cancel_at_period_end ?? false),\n failureCount: Number(raw?.failureCount ?? raw?.failure_count ?? 0),\n lastPaymentAt: optionalDateString(raw?.lastPaymentAt ?? raw?.last_payment_at),\n pausedAt: optionalDateString(raw?.pausedAt ?? raw?.paused_at),\n cancelledAt: optionalDateString(raw?.cancelledAt ?? raw?.cancelled_at),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCustomer(raw: any): Customer | null {\n if (!raw) return null;\n return {\n id: requiredString(raw?.id, 'customer.id'),\n externalId: optionalString(raw?.externalId ?? raw?.external_id),\n email: optionalString(raw?.email),\n firstName: optionalString(raw?.firstName ?? raw?.first_name),\n lastName: optionalString(raw?.lastName ?? raw?.last_name),\n phone: optionalString(raw?.phone),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCustomerPaymentMethod(raw: any): CustomerPaymentMethod {\n return {\n id: requiredString(raw?.id, 'paymentMethod.id'),\n processor: optionalString(raw?.processor),\n methodType: optionalString(raw?.methodType ?? raw?.method_type),\n cardBrand: optionalString(raw?.cardBrand ?? raw?.card_brand),\n cardLastFour: optionalString(raw?.cardLastFour ?? raw?.card_last_four),\n isDefault: Boolean(raw?.isDefault ?? raw?.is_default ?? false),\n createdAt: optionalDateString(raw?.createdAt ?? raw?.created_at) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt ?? raw?.updated_at) ?? undefined,\n };\n}\n\nexport function normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url),\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token),\n expiresAt: optionalDateString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nexport function normalizeTrialEligibility(raw: any): TrialEligibilityResult {\n return {\n eligible: Boolean(raw?.eligible),\n reason: raw?.reason,\n };\n}\n\nexport function normalizePagination(raw: any): Pagination | undefined {\n if (!raw) return undefined;\n return {\n cursor: raw.cursor ?? null,\n hasMore: Boolean(raw.hasMore ?? raw.has_more ?? false),\n };\n}\n\nexport function toIso(value: string | Date | undefined): string | undefined {\n if (value === undefined) return undefined;\n return value instanceof Date ? value.toISOString() : value;\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' ? value : null;\n}\n\nfunction requiredDateString(value: unknown, label: string): string {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalDateString(value: unknown): string | null {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) return value;\n return null;\n}\n\nfunction objectOrEmpty(value: unknown): Record<string, unknown> {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {};\n}\n","import { ThrottleSubscriptionsError } from './errors';\nimport {\n normalizeCheckoutSession,\n normalizeCustomer,\n normalizeCustomerPaymentMethod,\n normalizePagination,\n normalizeSubscription,\n normalizeTrialEligibility,\n toIso,\n} from './normalize';\nimport type {\n ChangePlanInput,\n CheckoutSession,\n CreateCheckoutSessionInput,\n CreateSubscriptionInput,\n Customer,\n CustomerPaymentMethod,\n ListSubscriptionsParams,\n PaginatedSubscriptions,\n Subscription,\n SubscriptionsClientContract,\n SubscriptionsClientOptions,\n ThrottleEnvelope,\n TrialEligibilityInput,\n TrialEligibilityResult,\n UpdateSubscriptionInput,\n} from './types';\n\nexport class SubscriptionsClient implements SubscriptionsClientContract {\n private readonly apiKey?: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly fetcher?: SubscriptionsClientOptions['fetcher'];\n private readonly timeoutMs: number;\n\n constructor(opts: SubscriptionsClientOptions = {}) {\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('SubscriptionsClient: fetch is required');\n if (!opts.apiKey && !opts.fetcher) {\n throw new Error('SubscriptionsClient: apiKey or fetcher is required');\n }\n\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.fetcher = opts.fetcher;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const init: RequestInit = {\n method,\n headers: {\n 'content-type': 'application/json',\n ...(this.apiKey ? { 'x-api-key': this.apiKey } : {}),\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n };\n\n const res = this.fetcher\n ? await this.fetcher(path, init)\n : await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), init);\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleSubscriptionsError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async create(input: CreateSubscriptionInput): Promise<Subscription> {\n const customerId = await this.resolveCustomerId(input.customerId, input.externalCustomerId);\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions', {\n applicationId: input.applicationId,\n customerId,\n planReference: input.planReference,\n planName: input.planName,\n interval: input.interval,\n amount: input.amount,\n currency: input.currency,\n currentPeriodStart: toIso(input.currentPeriodStart),\n currentPeriodEnd: toIso(input.currentPeriodEnd),\n trialEnd: toIso(input.trialEnd),\n metadata: input.metadata ?? {},\n });\n return normalizeSubscription(data);\n }\n\n async list(params: ListSubscriptionsParams = {}): Promise<PaginatedSubscriptions> {\n const query = new URLSearchParams();\n setQuery(query, 'customerId', params.customerId);\n setQuery(query, 'externalCustomerId', params.externalCustomerId);\n setQuery(query, 'status', params.status);\n setQuery(query, 'interval', params.interval);\n setQuery(query, 'q', params.q);\n setQuery(query, 'cursor', params.cursor);\n setQuery(query, 'limit', params.limit);\n setQuery(query, 'sort', params.sort);\n setQuery(query, 'createdAfter', toIso(params.createdAfter));\n setQuery(query, 'createdBefore', toIso(params.createdBefore));\n\n const suffix = query.toString() ? `?${query}` : '';\n const envelope = await this.requestEnvelope<unknown[]>('GET', `/api/v1/subscriptions${suffix}`);\n return {\n data: (envelope.data ?? []).map(normalizeSubscription),\n pagination: normalizePagination(envelope.meta?.pagination),\n };\n }\n\n async get(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n );\n return normalizeSubscription(data);\n }\n\n async update(id: string, input: UpdateSubscriptionInput): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'PATCH',\n `/api/v1/subscriptions/${encodeURIComponent(id)}`,\n input,\n );\n return normalizeSubscription(data);\n }\n\n changePlan(input: ChangePlanInput): Promise<Subscription> {\n const { id, ...body } = input;\n return this.update(id, body);\n }\n\n async pause(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/pause`,\n );\n return normalizeSubscription(data);\n }\n\n async resume(id: string): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/resume`,\n );\n return normalizeSubscription(data);\n }\n\n async cancel(id: string, input: { atPeriodEnd?: boolean } = {}): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/cancel`,\n { atPeriodEnd: input.atPeriodEnd ?? false },\n );\n return normalizeSubscription(data);\n }\n\n async createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n async checkTrialEligibility(input: TrialEligibilityInput): Promise<TrialEligibilityResult> {\n const data = await this.request<unknown>('POST', '/api/v1/subscriptions/eligibility-check', {\n payment_method_id: input.paymentMethodId,\n });\n return normalizeTrialEligibility(data);\n }\n\n async getCustomerByExternalId(externalId: string): Promise<Customer | null> {\n try {\n const data = await this.request<unknown>(\n 'GET',\n `/api/v1/customers/by-external/${encodeURIComponent(externalId)}`,\n );\n return normalizeCustomer(data);\n } catch (err) {\n if (err instanceof ThrottleSubscriptionsError && err.statusCode === 404) return null;\n throw err;\n }\n }\n\n async listCustomerPaymentMethods(customerId: string): Promise<CustomerPaymentMethod[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/customers/${encodeURIComponent(customerId)}/payment-methods`,\n );\n return (data ?? []).map(normalizeCustomerPaymentMethod);\n }\n\n private async resolveCustomerId(\n customerId?: string,\n externalCustomerId?: string,\n ): Promise<string> {\n if (customerId) return customerId;\n if (!externalCustomerId) {\n throw new ThrottleSubscriptionsError({\n code: 'invalid_request',\n message: 'customerId or externalCustomerId is required',\n statusCode: 400,\n });\n }\n\n const customer = await this.getCustomerByExternalId(externalCustomerId);\n if (!customer) {\n throw new ThrottleSubscriptionsError({\n code: 'customer_not_found',\n message: 'Customer not found',\n statusCode: 404,\n });\n }\n return customer.id;\n }\n}\n\nexport function createSubscriptionsClient(opts: SubscriptionsClientOptions): SubscriptionsClient {\n return new SubscriptionsClient(opts);\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction setQuery(query: URLSearchParams, key: string, value: unknown): void {\n if (value === undefined || value === null || value === '') return;\n query.set(key, String(value));\n}\n","import { createContext, useCallback, useContext, useMemo, useReducer, type ReactNode } from 'react';\nimport { SubscriptionsClient } from './client';\nimport type {\n SubscriptionFetcher,\n SubscriptionProviderProps,\n SubscriptionsClientContract,\n} from './types';\n\ninterface SubscriptionContextValue {\n client: SubscriptionsClientContract;\n cacheVersion: number;\n invalidate: () => void;\n}\n\nconst SubscriptionContext = createContext<SubscriptionContextValue | null>(null);\n\nexport function SubscriptionProvider({\n children,\n client,\n fetcher,\n baseUrl,\n timeoutMs,\n}: SubscriptionProviderProps) {\n const [cacheVersion, invalidate] = useReducer((value: number) => value + 1, 0);\n const resolvedClient = useMemo(() => {\n if (client) return client;\n return new SubscriptionsClient({\n fetcher: fetcher ?? createSubscriptionFetcher('/api/throttle'),\n baseUrl,\n timeoutMs,\n });\n }, [baseUrl, client, fetcher, timeoutMs]);\n\n const value = useMemo(\n () => ({ client: resolvedClient, cacheVersion, invalidate }),\n [cacheVersion, resolvedClient],\n );\n\n return <SubscriptionContext.Provider value={value}>{children}</SubscriptionContext.Provider>;\n}\n\nexport function useSubscriptionClient(): SubscriptionsClientContract {\n return useSubscriptionContext().client;\n}\n\nexport function useSubscriptionInvalidation(): () => void {\n return useSubscriptionContext().invalidate;\n}\n\nexport function useSubscriptionCacheVersion(): number {\n return useSubscriptionContext().cacheVersion;\n}\n\nexport function createSubscriptionFetcher(basePath: string): SubscriptionFetcher {\n const cleanBase = basePath.replace(/\\/+$/, '');\n return (path, init) => {\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return fetch(`${cleanBase}${cleanPath}`, init);\n };\n}\n\nexport function useSubscriptionContext(): SubscriptionContextValue {\n const ctx = useContext(SubscriptionContext);\n if (!ctx) {\n throw new Error(\n '@usethrottle/subscriptions hooks must be used inside <SubscriptionProvider />',\n );\n }\n return ctx;\n}\n\nexport function SubscriptionProviderWithClient({\n children,\n client,\n}: {\n children: ReactNode;\n client: SubscriptionsClientContract;\n}) {\n const [cacheVersion, invalidate] = useReducer((value: number) => value + 1, 0);\n const value = useMemo(() => ({ client, cacheVersion, invalidate }), [cacheVersion, client]);\n return <SubscriptionContext.Provider value={value}>{children}</SubscriptionContext.Provider>;\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n useSubscriptionCacheVersion,\n useSubscriptionClient,\n useSubscriptionInvalidation,\n} from './provider';\nimport type {\n CancelSubscriptionInput,\n ChangePlanInput,\n CheckoutSession,\n CreateCheckoutSessionInput,\n CreateSubscriptionInput,\n Customer,\n CustomerPaymentMethod,\n ListSubscriptionsParams,\n MutationState,\n PaginatedSubscriptions,\n QueryOptions,\n QueryState,\n Subscription,\n TrialEligibilityInput,\n TrialEligibilityResult,\n UpdateSubscriptionInput,\n} from './types';\n\nexport function useSubscriptions(\n params: ListSubscriptionsParams = {},\n options: QueryOptions<PaginatedSubscriptions> = {},\n): QueryState<PaginatedSubscriptions> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n const stableParams = useStableValue(params);\n return useAsyncQuery(\n () => client.list(stableParams),\n [client, stableParams, cacheVersion],\n options,\n );\n}\n\nexport function useSubscription(\n id: string | null | undefined,\n options: QueryOptions<Subscription> = {},\n): QueryState<Subscription> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n return useAsyncQuery(\n () => (id ? client.get(id) : Promise.resolve(null)),\n [client, id, cacheVersion],\n { ...options, enabled: options.enabled ?? Boolean(id) },\n );\n}\n\nexport function useCustomerByExternalId(\n externalId: string | null | undefined,\n options: QueryOptions<Customer> = {},\n): QueryState<Customer> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n return useAsyncQuery(\n () => (externalId ? client.getCustomerByExternalId(externalId) : Promise.resolve(null)),\n [client, externalId, cacheVersion],\n { ...options, enabled: options.enabled ?? Boolean(externalId) },\n );\n}\n\nexport function useCustomerPaymentMethods(\n customerId: string | null | undefined,\n options: QueryOptions<CustomerPaymentMethod[]> = {},\n): QueryState<CustomerPaymentMethod[]> {\n const client = useSubscriptionClient();\n const cacheVersion = useSubscriptionCacheVersion();\n return useAsyncQuery(\n () => (customerId ? client.listCustomerPaymentMethods(customerId) : Promise.resolve(null)),\n [client, customerId, cacheVersion],\n { ...options, enabled: options.enabled ?? Boolean(customerId) },\n );\n}\n\nexport function useTrialEligibility(): MutationState<\n TrialEligibilityResult,\n TrialEligibilityInput\n> {\n const client = useSubscriptionClient();\n return useAsyncMutation((input) => client.checkTrialEligibility(input));\n}\n\nexport function useCreateSubscription(): MutationState<Subscription, CreateSubscriptionInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.create(input), invalidate);\n}\n\nexport function useUpdateSubscription(): MutationState<\n Subscription,\n { id: string; data: UpdateSubscriptionInput }\n> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation(({ id, data }) => client.update(id, data), invalidate);\n}\n\nexport function useChangePlan(): MutationState<Subscription, ChangePlanInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.changePlan(input), invalidate);\n}\n\nexport function useCancelSubscription(): MutationState<Subscription, CancelSubscriptionInput> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation(\n (input) => client.cancel(input.id, { atPeriodEnd: input.atPeriodEnd }),\n invalidate,\n );\n}\n\nexport function usePauseSubscription(): MutationState<Subscription, { id: string }> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.pause(input.id), invalidate);\n}\n\nexport function useResumeSubscription(): MutationState<Subscription, { id: string }> {\n const client = useSubscriptionClient();\n const invalidate = useSubscriptionInvalidation();\n return useAsyncMutation((input) => client.resume(input.id), invalidate);\n}\n\nexport function useCreateCheckoutSession(): MutationState<\n CheckoutSession,\n CreateCheckoutSessionInput\n> {\n const client = useSubscriptionClient();\n return useAsyncMutation((input) => client.createCheckoutSession(input));\n}\n\nfunction useAsyncQuery<T>(\n load: () => Promise<T | null>,\n deps: readonly unknown[],\n options: QueryOptions<T>,\n): QueryState<T> {\n const enabled = options.enabled ?? true;\n const [data, setData] = useState<T | null>(options.initialData ?? null);\n const [error, setError] = useState<unknown>(null);\n const [isLoading, setIsLoading] = useState(enabled && options.initialData === undefined);\n const [isFetching, setIsFetching] = useState(false);\n const loadRef = useRef(load);\n loadRef.current = load;\n\n const refetch = useCallback(async () => {\n if (!enabled) return data;\n setIsFetching(true);\n setError(null);\n try {\n const next = await loadRef.current();\n setData(next);\n return next;\n } catch (err) {\n setError(err);\n throw err;\n } finally {\n setIsFetching(false);\n setIsLoading(false);\n }\n }, [data, enabled]);\n\n useEffect(() => {\n if (!enabled) {\n setIsLoading(false);\n return;\n }\n let cancelled = false;\n setIsFetching(true);\n setError(null);\n load()\n .then((next) => {\n if (!cancelled) setData(next);\n })\n .catch((err) => {\n if (!cancelled) setError(err);\n })\n .finally(() => {\n if (!cancelled) {\n setIsLoading(false);\n setIsFetching(false);\n }\n });\n\n return () => {\n cancelled = true;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [enabled, ...deps]);\n\n return { data, error, isLoading, isFetching, refetch };\n}\n\nfunction useAsyncMutation<TData, TVariables>(\n action: (variables: TVariables) => Promise<TData>,\n onSuccess?: () => void,\n): MutationState<TData, TVariables> {\n const [data, setData] = useState<TData | null>(null);\n const [error, setError] = useState<unknown>(null);\n const [isPending, setIsPending] = useState(false);\n\n const mutateAsync = useCallback(\n async (variables: TVariables) => {\n setIsPending(true);\n setError(null);\n try {\n const next = await action(variables);\n setData(next);\n onSuccess?.();\n return next;\n } catch (err) {\n setError(err);\n throw err;\n } finally {\n setIsPending(false);\n }\n },\n [action, onSuccess],\n );\n\n const mutate = useCallback(\n (variables: TVariables) => {\n void mutateAsync(variables).catch(() => undefined);\n },\n [mutateAsync],\n );\n\n const reset = useCallback(() => {\n setData(null);\n setError(null);\n setIsPending(false);\n }, []);\n\n return { data, error, isPending, mutate, mutateAsync, reset };\n}\n\nfunction useStableValue<T>(value: T): T {\n const key = JSON.stringify(value);\n return useMemo(() => value, [key]);\n}\n","import type { Subscription, SubscriptionStatus } from './types';\n\nexport function isTerminalSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'cancelled';\n}\n\nexport function canPauseSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'active';\n}\n\nexport function canResumeSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'paused';\n}\n\nexport function canCancelSubscription(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) !== 'cancelled';\n}\n\nexport function isSubscriptionPastDue(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'past_due';\n}\n\nexport function isSubscriptionTrialing(status: SubscriptionStatus | Subscription): boolean {\n return getStatus(status) === 'trialing';\n}\n\nexport function daysUntil(date: string | Date, now = new Date()): number {\n const end = date instanceof Date ? date : new Date(date);\n const ms = end.getTime() - now.getTime();\n if (!Number.isFinite(ms)) return 0;\n return Math.max(0, Math.ceil(ms / 86_400_000));\n}\n\nfunction getStatus(input: SubscriptionStatus | Subscription): SubscriptionStatus {\n return typeof input === 'string' ? input : input.status;\n}\n","import type { CSSProperties } from 'react';\nimport { daysUntil } from './helpers';\nimport type {\n DunningBannerProps,\n SubscriptionStatus,\n SubscriptionStatusBadgeProps,\n TrialCountdownProps,\n} from './types';\n\nconst STATUS_LABELS: Record<SubscriptionStatus, string> = {\n active: 'Active',\n paused: 'Paused',\n cancelled: 'Cancelled',\n past_due: 'Past due',\n trialing: 'Trialing',\n};\n\nconst STATUS_STYLES: Record<SubscriptionStatus, CSSProperties> = {\n active: { color: '#035c4f', background: '#dff8ef', borderColor: '#a8e8d2' },\n paused: { color: '#735c00', background: '#fff4ca', borderColor: '#f3d46b' },\n cancelled: { color: '#6c2632', background: '#ffe1e7', borderColor: '#f4a9b8' },\n past_due: { color: '#7a2d00', background: '#ffe8d6', borderColor: '#f5b47f' },\n trialing: { color: '#124c73', background: '#dff1ff', borderColor: '#9ed3fb' },\n};\n\nexport function SubscriptionStatusBadge({\n status,\n className,\n style,\n labels,\n}: SubscriptionStatusBadgeProps) {\n return (\n <span\n className={className}\n style={{\n display: 'inline-flex',\n alignItems: 'center',\n border: '1px solid',\n borderRadius: 999,\n padding: '2px 8px',\n fontSize: 12,\n fontWeight: 700,\n lineHeight: 1.6,\n whiteSpace: 'nowrap',\n ...STATUS_STYLES[status],\n ...style,\n }}\n >\n {labels?.[status] ?? STATUS_LABELS[status]}\n </span>\n );\n}\n\nexport function TrialCountdown({\n endDate,\n now,\n className,\n style,\n expiredLabel = 'Trial ended',\n prefix = 'Trial ends in',\n}: TrialCountdownProps) {\n const days = daysUntil(endDate, now);\n const label = days <= 0 ? expiredLabel : `${prefix} ${days} ${days === 1 ? 'day' : 'days'}`;\n\n return (\n <span className={className} style={style}>\n {label}\n </span>\n );\n}\n\nexport function DunningBanner({\n subscription,\n onUpdateCard,\n title = 'Payment needs attention',\n message,\n actionLabel = 'Update card',\n className,\n style,\n}: DunningBannerProps) {\n if (subscription.status !== 'past_due') return null;\n const fallbackMessage =\n subscription.failureCount > 0\n ? `We could not renew this subscription after ${subscription.failureCount} failed payment attempt${\n subscription.failureCount === 1 ? '' : 's'\n }.`\n : 'We could not renew this subscription with the saved payment method.';\n\n return (\n <div\n role=\"status\"\n className={className}\n style={{\n border: '1px solid #f5b47f',\n borderRadius: 8,\n background: '#fff7ed',\n color: '#7a2d00',\n padding: 16,\n display: 'grid',\n gap: 10,\n ...style,\n }}\n >\n <strong>{title}</strong>\n <span>{message ?? fallbackMessage}</span>\n {onUpdateCard ? (\n <button\n type=\"button\"\n onClick={onUpdateCard}\n style={{\n width: 'fit-content',\n border: '1px solid #7a2d00',\n borderRadius: 6,\n background: '#7a2d00',\n color: '#fff',\n padding: '8px 12px',\n fontWeight: 700,\n cursor: 'pointer',\n }}\n >\n {actionLabel}\n </button>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,6BAAN,cAAyC,MAAM;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAgF;AAC1F,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,aAAa,KAAK;AACvB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;;;ACDO,SAAS,sBAAsB,KAAwB;AAC5D,SAAO;AAAA,IACL,IAAI,eAAe,KAAK,IAAI,iBAAiB;AAAA,IAC7C,aAAa,eAAe,KAAK,eAAe,KAAK,WAAW;AAAA,IAChE,eAAe,eAAe,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IACjE,YAAY,eAAe,KAAK,cAAc,KAAK,aAAa,yBAAyB;AAAA,IACzF,QAAS,KAAK,UAAU;AAAA,IACxB,eAAe;AAAA,MACb,KAAK,iBAAiB,KAAK;AAAA,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O;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,QAAQ;AAAA,YACV;AAAA,YAEC;AAAA;AAAA,QACH,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["value","import_react","import_jsx_runtime"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SubscriptionProviderProps, a as SubscriptionsClientContract, b as SubscriptionFetcher, M as MutationState, c as Subscription, C as CancelSubscriptionInput, d as ChangePlanInput, e as CheckoutSession, f as CreateCheckoutSessionInput, g as CreateSubscriptionInput, Q as QueryOptions, h as Customer, i as QueryState, L as ListSubscriptionsParams, P as PaginatedSubscriptions, T as TrialEligibilityResult, j as TrialEligibilityInput, U as UpdateSubscriptionInput, D as DunningBannerProps, k as SubscriptionStatusBadgeProps, l as TrialCountdownProps, m as SubscriptionStatus } from './errors-DfWfeSji.cjs';
2
- export { n as CheckoutCollectInput, o as CheckoutCustomerInput, p as Pagination, R as RecurringIntent, q as SubscriptionInterval, r as SubscriptionSort, s as SubscriptionsClient, t as SubscriptionsClientOptions, u as ThrottleEnvelope, v as ThrottleSubscriptionsError, w as TrialEligibilityReason, x as createSubscriptionsClient } from './errors-DfWfeSji.cjs';
1
+ import { S as SubscriptionProviderProps, a as SubscriptionsClientContract, b as SubscriptionFetcher, M as MutationState, c as Subscription, C as CancelSubscriptionInput, d as ChangePlanInput, e as CheckoutSession, f as CreateCheckoutSessionInput, g as CreateSubscriptionInput, Q as QueryOptions, h as Customer, i as QueryState, j as CustomerPaymentMethod, L as ListSubscriptionsParams, P as PaginatedSubscriptions, T as TrialEligibilityResult, k as TrialEligibilityInput, U as UpdateSubscriptionInput, D as DunningBannerProps, l as SubscriptionStatusBadgeProps, m as TrialCountdownProps, n as SubscriptionStatus } from './errors-DPfsiLtM.cjs';
2
+ export { o as CheckoutCollectInput, p as CheckoutCustomerInput, q as Pagination, R as RecurringIntent, r as SubscriptionInterval, s as SubscriptionSort, t as SubscriptionsClient, u as SubscriptionsClientOptions, v as ThrottleEnvelope, w as ThrottleSubscriptionsError, x as TrialEligibilityReason, y as createSubscriptionsClient } from './errors-DPfsiLtM.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
 
@@ -15,6 +15,7 @@ declare function SubscriptionProviderWithClient({ children, client, }: {
15
15
  declare function useSubscriptions(params?: ListSubscriptionsParams, options?: QueryOptions<PaginatedSubscriptions>): QueryState<PaginatedSubscriptions>;
16
16
  declare function useSubscription(id: string | null | undefined, options?: QueryOptions<Subscription>): QueryState<Subscription>;
17
17
  declare function useCustomerByExternalId(externalId: string | null | undefined, options?: QueryOptions<Customer>): QueryState<Customer>;
18
+ declare function useCustomerPaymentMethods(customerId: string | null | undefined, options?: QueryOptions<CustomerPaymentMethod[]>): QueryState<CustomerPaymentMethod[]>;
18
19
  declare function useTrialEligibility(): MutationState<TrialEligibilityResult, TrialEligibilityInput>;
19
20
  declare function useCreateSubscription(): MutationState<Subscription, CreateSubscriptionInput>;
20
21
  declare function useUpdateSubscription(): MutationState<Subscription, {
@@ -43,4 +44,4 @@ declare function isSubscriptionPastDue(status: SubscriptionStatus | Subscription
43
44
  declare function isSubscriptionTrialing(status: SubscriptionStatus | Subscription): boolean;
44
45
  declare function daysUntil(date: string | Date, now?: Date): number;
45
46
 
46
- export { CancelSubscriptionInput, ChangePlanInput, CheckoutSession, CreateCheckoutSessionInput, CreateSubscriptionInput, Customer, DunningBanner, DunningBannerProps, ListSubscriptionsParams, MutationState, PaginatedSubscriptions, QueryOptions, QueryState, Subscription, SubscriptionFetcher, SubscriptionProvider, SubscriptionProviderProps, SubscriptionProviderWithClient, SubscriptionStatus, SubscriptionStatusBadge, SubscriptionStatusBadgeProps, SubscriptionsClientContract, TrialCountdown, TrialCountdownProps, TrialEligibilityInput, TrialEligibilityResult, UpdateSubscriptionInput, canCancelSubscription, canPauseSubscription, canResumeSubscription, createSubscriptionFetcher, daysUntil, isSubscriptionPastDue, isSubscriptionTrialing, isTerminalSubscription, useCancelSubscription, useChangePlan, useCreateCheckoutSession, useCreateSubscription, useCustomerByExternalId, usePauseSubscription, useResumeSubscription, useSubscription, useSubscriptionClient, useSubscriptionInvalidation, useSubscriptions, useTrialEligibility, useUpdateSubscription };
47
+ export { CancelSubscriptionInput, ChangePlanInput, CheckoutSession, CreateCheckoutSessionInput, CreateSubscriptionInput, Customer, CustomerPaymentMethod, DunningBanner, DunningBannerProps, ListSubscriptionsParams, MutationState, PaginatedSubscriptions, QueryOptions, QueryState, Subscription, SubscriptionFetcher, SubscriptionProvider, SubscriptionProviderProps, SubscriptionProviderWithClient, SubscriptionStatus, SubscriptionStatusBadge, SubscriptionStatusBadgeProps, SubscriptionsClientContract, TrialCountdown, TrialCountdownProps, TrialEligibilityInput, TrialEligibilityResult, UpdateSubscriptionInput, canCancelSubscription, canPauseSubscription, canResumeSubscription, createSubscriptionFetcher, daysUntil, isSubscriptionPastDue, isSubscriptionTrialing, isTerminalSubscription, useCancelSubscription, useChangePlan, useCreateCheckoutSession, useCreateSubscription, useCustomerByExternalId, useCustomerPaymentMethods, usePauseSubscription, useResumeSubscription, useSubscription, useSubscriptionClient, useSubscriptionInvalidation, useSubscriptions, useTrialEligibility, useUpdateSubscription };