@usethrottle/subscriptions 1.5.0 → 2.0.0

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.
@@ -19,6 +19,11 @@ function normalizeSubscription(raw) {
19
19
  planReference: requiredString(raw?.planReference, "subscription.planReference"),
20
20
  planName: optionalString(raw?.planName),
21
21
  interval: raw?.interval ?? "monthly",
22
+ intervalUnit: optionalString(raw?.intervalUnit) ?? null,
23
+ intervalCount: raw?.intervalCount == null ? null : Number(raw.intervalCount),
24
+ totalPayments: raw?.totalPayments == null ? null : Number(raw.totalPayments),
25
+ paymentsMade: Number(raw?.paymentsMade ?? 0),
26
+ completedAt: optionalIsoDateString(raw?.completedAt),
22
27
  amount: Number(raw?.amount ?? 0),
23
28
  currency: optionalString(raw?.currency) ?? "USD",
24
29
  currentPeriodStart: requiredDateString(
@@ -113,6 +118,14 @@ function optionalDateString(value) {
113
118
  if (typeof value === "string" && value.length > 0) return value;
114
119
  return null;
115
120
  }
121
+ function optionalIsoDateString(value) {
122
+ if (value instanceof Date) return value.toISOString();
123
+ if (typeof value === "string" && value.length > 0) {
124
+ const d = new Date(value);
125
+ return Number.isNaN(d.getTime()) ? value : d.toISOString();
126
+ }
127
+ return null;
128
+ }
116
129
  function objectOrEmpty(value) {
117
130
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
118
131
  }
@@ -186,6 +199,9 @@ var SubscriptionsClient = class {
186
199
  planReference: input.planReference,
187
200
  planName: input.planName,
188
201
  interval: input.interval,
202
+ intervalUnit: input.intervalUnit,
203
+ intervalCount: input.intervalCount,
204
+ totalPayments: input.totalPayments,
189
205
  amount: input.amount,
190
206
  currency: input.currency,
191
207
  currentPeriodStart: toIso(input.currentPeriodStart),
@@ -202,6 +218,7 @@ var SubscriptionsClient = class {
202
218
  setQuery(query, "externalCustomerId", params.externalCustomerId);
203
219
  setQuery(query, "status", params.status);
204
220
  setQuery(query, "interval", params.interval);
221
+ setQuery(query, "installment", params.installment);
205
222
  setQuery(query, "q", params.q);
206
223
  setQuery(query, "cursor", params.cursor);
207
224
  setQuery(query, "limit", params.limit);
@@ -338,4 +355,4 @@ export {
338
355
  SubscriptionsClient,
339
356
  createSubscriptionsClient
340
357
  };
341
- //# sourceMappingURL=chunk-O7VSJ72M.js.map
358
+ //# sourceMappingURL=chunk-HKMHVVK7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/normalize.ts","../src/client.ts"],"sourcesContent":["import { ThrottleError } from '@usethrottle/errors';\n\n/**\n * Thrown on a non-2xx response from the Throttle Subscriptions API.\n *\n * Extends the shared {@link ThrottleError} so a single\n * `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every\n * Throttle SDK. `instanceof ThrottleSubscriptionsError` keeps working.\n */\nexport class ThrottleSubscriptionsError extends ThrottleError {\n constructor(args: { code: string; message: string; statusCode: number; details?: unknown }) {\n super(args);\n this.name = 'ThrottleSubscriptionsError';\n }\n}\n\nexport { ThrottleError, isThrottleError } from '@usethrottle/errors';\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),\n applicationId: optionalString(raw?.applicationId),\n customerId: requiredString(raw?.customerId, 'subscription.customerId'),\n status: (raw?.status ?? 'active') as SubscriptionStatus,\n planReference: requiredString(raw?.planReference, 'subscription.planReference'),\n planName: optionalString(raw?.planName),\n interval: (raw?.interval ?? 'monthly') as SubscriptionInterval,\n intervalUnit: (optionalString(raw?.intervalUnit) as Subscription['intervalUnit']) ?? null,\n intervalCount: raw?.intervalCount == null ? null : Number(raw.intervalCount),\n totalPayments: raw?.totalPayments == null ? null : Number(raw.totalPayments),\n paymentsMade: Number(raw?.paymentsMade ?? 0),\n completedAt: optionalIsoDateString(raw?.completedAt),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n currentPeriodStart: requiredDateString(\n raw?.currentPeriodStart,\n 'subscription.currentPeriodStart',\n ),\n currentPeriodEnd: requiredDateString(\n raw?.currentPeriodEnd,\n 'subscription.currentPeriodEnd',\n ),\n trialEnd: optionalDateString(raw?.trialEnd),\n cancelAtPeriodEnd: Boolean(raw?.cancelAtPeriodEnd ?? false),\n failureCount: Number(raw?.failureCount ?? 0),\n lastPaymentAt: optionalDateString(raw?.lastPaymentAt),\n pausedAt: optionalDateString(raw?.pausedAt),\n cancelledAt: optionalDateString(raw?.cancelledAt),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt) ?? 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),\n email: optionalString(raw?.email),\n firstName: optionalString(raw?.firstName),\n lastName: optionalString(raw?.lastName),\n phone: optionalString(raw?.phone),\n company: optionalString(raw?.company),\n metadata: objectOrEmpty(raw?.metadata),\n createdAt: optionalDateString(raw?.createdAt) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt) ?? 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),\n cardBrand: optionalString(raw?.cardBrand),\n cardLastFour: optionalString(raw?.cardLastFour),\n isDefault: Boolean(raw?.isDefault ?? false),\n isActive: Boolean(raw?.isActive ?? true),\n createdAt: optionalDateString(raw?.createdAt) ?? undefined,\n updatedAt: optionalDateString(raw?.updatedAt) ?? undefined,\n };\n}\n\nexport function normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.id;\n return {\n ...withoutUnderscoreKeys(raw),\n id: optionalString(raw?.id) ?? undefined,\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl) ?? undefined,\n embedToken: optionalString(raw?.embedToken) ?? undefined,\n expiresAt: optionalDateString(raw?.expiresAt) ?? 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 ?? 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\n/**\n * Like `optionalDateString`, but always reserializes to a full ISO string\n * (with milliseconds) rather than passing a raw string through unchanged.\n * `completedAt` is a fresh field with no legacy raw-string callers to stay\n * compatible with, so it normalizes cleanly instead of echoing whatever the\n * API sent.\n */\nfunction optionalIsoDateString(value: unknown): string | null {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string' && value.length > 0) {\n const d = new Date(value);\n return Number.isNaN(d.getTime()) ? value : d.toISOString();\n }\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\nfunction withoutUnderscoreKeys(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).filter(([key]) => !key.includes('_')),\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 SubscriptionInvoiceRefund,\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 intervalUnit: input.intervalUnit,\n intervalCount: input.intervalCount,\n totalPayments: input.totalPayments,\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 orderId: input.orderId,\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, 'installment', params.installment);\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(\n id: string,\n input: { atPeriodEnd?: boolean; refund?: 'none' | 'prorated' | 'last_cycle' } = {},\n ): Promise<Subscription> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/cancel`,\n { atPeriodEnd: input.atPeriodEnd ?? false, refund: input.refund ?? 'none' },\n );\n return normalizeSubscription(data);\n }\n\n /**\n * Refund one billing cycle.\n *\n * `intent` has no default: refunding money and ending the subscription are\n * separate decisions, and guessing either way is wrong often enough that the\n * API requires the caller to say which one they mean.\n */\n async refundInvoice(\n id: string,\n invoiceId: string,\n input: { intent: 'money_only' | 'refund_and_cancel'; amount?: number; reason?: string },\n ): Promise<SubscriptionInvoiceRefund> {\n return this.request<SubscriptionInvoiceRefund>(\n 'POST',\n `/api/v1/subscriptions/${encodeURIComponent(id)}/invoices/${encodeURIComponent(invoiceId)}/refund`,\n input,\n );\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 paymentMethodId: 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":";AAAA,SAAS,qBAAqB;AAgB9B,SAAS,iBAAAA,gBAAe,uBAAuB;AAPxC,IAAM,6BAAN,cAAyC,cAAc;AAAA,EAC5D,YAAY,MAAgF;AAC1F,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AACF;;;ACHO,SAAS,sBAAsB,KAAwB;AAC5D,SAAO;AAAA,IACL,IAAI,eAAe,KAAK,IAAI,iBAAiB;AAAA,IAC7C,aAAa,eAAe,KAAK,WAAW;AAAA,IAC5C,eAAe,eAAe,KAAK,aAAa;AAAA,IAChD,YAAY,eAAe,KAAK,YAAY,yBAAyB;AAAA,IACrE,QAAS,KAAK,UAAU;AAAA,IACxB,eAAe,eAAe,KAAK,eAAe,4BAA4B;AAAA,IAC9E,UAAU,eAAe,KAAK,QAAQ;AAAA,IACtC,UAAW,KAAK,YAAY;AAAA,IAC5B,cAAe,eAAe,KAAK,YAAY,KAAsC;AAAA,IACrF,eAAe,KAAK,iBAAiB,OAAO,OAAO,OAAO,IAAI,aAAa;AAAA,IAC3E,eAAe,KAAK,iBAAiB,OAAO,OAAO,OAAO,IAAI,aAAa;AAAA,IAC3E,cAAc,OAAO,KAAK,gBAAgB,CAAC;AAAA,IAC3C,aAAa,sBAAsB,KAAK,WAAW;AAAA,IACnD,QAAQ,OAAO,KAAK,UAAU,CAAC;AAAA,IAC/B,UAAU,eAAe,KAAK,QAAQ,KAAK;AAAA,IAC3C,oBAAoB;AAAA,MAClB,KAAK;AAAA,MACL;AAAA,IACF;AAAA,IACA,kBAAkB;AAAA,MAChB,KAAK;AAAA,MACL;AAAA,IACF;AAAA,IACA,UAAU,mBAAmB,KAAK,QAAQ;AAAA,IAC1C,mBAAmB,QAAQ,KAAK,qBAAqB,KAAK;AAAA,IAC1D,cAAc,OAAO,KAAK,gB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G,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":["ThrottleError"]}
@@ -1,8 +1,9 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { ThrottleError } from '@usethrottle/errors';
3
3
 
4
- type SubscriptionStatus = 'active' | 'paused' | 'cancelled' | 'past_due' | 'trialing';
5
- type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';
4
+ type SubscriptionStatus = 'active' | 'paused' | 'cancelled' | 'past_due' | 'trialing' | 'unpaid' | 'completed';
5
+ type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
6
+ type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
6
7
  type SubscriptionSort = 'asc' | 'desc';
7
8
  interface Subscription {
8
9
  id: string;
@@ -13,6 +14,15 @@ interface Subscription {
13
14
  planReference: string;
14
15
  planName?: string | null;
15
16
  interval: SubscriptionInterval;
17
+ /** The cadence as "every intervalCount intervalUnit". Named intervals carry their shorthand (monthly → month, 1). */
18
+ intervalUnit: SubscriptionIntervalUnit | null;
19
+ intervalCount: number | null;
20
+ /** Installment plans only: the fixed number of payments. null for an ongoing subscription. */
21
+ totalPayments: number | null;
22
+ /** Installment plans only: payments counted so far, charges and waived periods alike. */
23
+ paymentsMade: number;
24
+ /** When the final installment succeeded. Set only on `completed`. */
25
+ completedAt: string | null;
16
26
  amount: number;
17
27
  currency: string;
18
28
  currentPeriodStart: string;
@@ -85,6 +95,8 @@ interface ListSubscriptionsParams {
85
95
  sort?: SubscriptionSort;
86
96
  createdAfter?: string | Date;
87
97
  createdBefore?: string | Date;
98
+ /** true: only installment plans; false: only ongoing subscriptions. */
99
+ installment?: boolean;
88
100
  }
89
101
  interface CreateSubscriptionInput {
90
102
  applicationId?: string;
@@ -92,7 +104,12 @@ interface CreateSubscriptionInput {
92
104
  externalCustomerId?: string;
93
105
  planReference: string;
94
106
  planName?: string;
95
- interval: SubscriptionInterval;
107
+ interval?: SubscriptionInterval;
108
+ /** Any cadence from 1 hour to 1 year. Send with intervalCount instead of, or with, `interval`. */
109
+ intervalUnit?: SubscriptionIntervalUnit;
110
+ intervalCount?: number;
111
+ /** Makes this an installment plan of exactly this many payments (2–60). No trial; set once. */
112
+ totalPayments?: number;
96
113
  amount: number;
97
114
  currency?: string;
98
115
  currentPeriodStart: string | Date;
@@ -111,6 +128,8 @@ interface UpdateSubscriptionInput {
111
128
  planReference?: string;
112
129
  planName?: string;
113
130
  interval?: SubscriptionInterval;
131
+ intervalUnit?: SubscriptionIntervalUnit;
132
+ intervalCount?: number;
114
133
  amount?: number;
115
134
  metadata?: Record<string, unknown>;
116
135
  }
@@ -124,7 +143,10 @@ interface ChangePlanInput extends UpdateSubscriptionInput {
124
143
  }
125
144
  interface RecurringIntent {
126
145
  plan: string;
127
- interval: SubscriptionInterval;
146
+ interval?: SubscriptionInterval;
147
+ intervalUnit?: SubscriptionIntervalUnit;
148
+ intervalCount?: number;
149
+ totalPayments?: number;
128
150
  amount?: number;
129
151
  trialDays?: number;
130
152
  planName?: string;
@@ -333,4 +355,4 @@ declare class ThrottleSubscriptionsError extends ThrottleError {
333
355
  });
334
356
  }
335
357
 
336
- export { createSubscriptionsClient as A, 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 Subscription as S, type ThrottleEnvelope as T, type UpdateSubscriptionInput as U, type ChangePlanInput as a, type CheckoutCollectInput as b, type CheckoutCustomerInput as c, type CheckoutSession as d, type CreateCheckoutSessionInput as e, type CreateSubscriptionInput as f, type Customer as g, type CustomerPaymentMethod as h, type Pagination as i, type QueryState as j, type SubscriptionFetcher as k, type SubscriptionInterval as l, type SubscriptionInvoiceRefund as m, type SubscriptionProviderProps as n, type SubscriptionSort as o, type SubscriptionStatus as p, type SubscriptionStatusBadgeProps as q, type SubscriptionTaxAddress as r, SubscriptionsClient as s, type SubscriptionsClientContract as t, type SubscriptionsClientOptions as u, ThrottleSubscriptionsError as v, type TrialCountdownProps as w, type TrialEligibilityInput as x, type TrialEligibilityReason as y, type TrialEligibilityResult as z };
358
+ export { type TrialEligibilityResult as A, createSubscriptionsClient as B, 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 Subscription as S, type ThrottleEnvelope as T, type UpdateSubscriptionInput as U, type ChangePlanInput as a, type CheckoutCollectInput as b, type CheckoutCustomerInput as c, type CheckoutSession as d, type CreateCheckoutSessionInput as e, type CreateSubscriptionInput as f, type Customer as g, type CustomerPaymentMethod as h, type Pagination as i, type QueryState as j, type SubscriptionFetcher as k, type SubscriptionInterval as l, type SubscriptionIntervalUnit as m, type SubscriptionInvoiceRefund as n, type SubscriptionProviderProps as o, type SubscriptionSort as p, type SubscriptionStatus as q, type SubscriptionStatusBadgeProps as r, type SubscriptionTaxAddress as s, SubscriptionsClient as t, type SubscriptionsClientContract as u, type SubscriptionsClientOptions as v, ThrottleSubscriptionsError as w, type TrialCountdownProps as x, type TrialEligibilityInput as y, type TrialEligibilityReason as z };
@@ -1,8 +1,9 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { ThrottleError } from '@usethrottle/errors';
3
3
 
4
- type SubscriptionStatus = 'active' | 'paused' | 'cancelled' | 'past_due' | 'trialing';
5
- type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';
4
+ type SubscriptionStatus = 'active' | 'paused' | 'cancelled' | 'past_due' | 'trialing' | 'unpaid' | 'completed';
5
+ type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
6
+ type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
6
7
  type SubscriptionSort = 'asc' | 'desc';
7
8
  interface Subscription {
8
9
  id: string;
@@ -13,6 +14,15 @@ interface Subscription {
13
14
  planReference: string;
14
15
  planName?: string | null;
15
16
  interval: SubscriptionInterval;
17
+ /** The cadence as "every intervalCount intervalUnit". Named intervals carry their shorthand (monthly → month, 1). */
18
+ intervalUnit: SubscriptionIntervalUnit | null;
19
+ intervalCount: number | null;
20
+ /** Installment plans only: the fixed number of payments. null for an ongoing subscription. */
21
+ totalPayments: number | null;
22
+ /** Installment plans only: payments counted so far, charges and waived periods alike. */
23
+ paymentsMade: number;
24
+ /** When the final installment succeeded. Set only on `completed`. */
25
+ completedAt: string | null;
16
26
  amount: number;
17
27
  currency: string;
18
28
  currentPeriodStart: string;
@@ -85,6 +95,8 @@ interface ListSubscriptionsParams {
85
95
  sort?: SubscriptionSort;
86
96
  createdAfter?: string | Date;
87
97
  createdBefore?: string | Date;
98
+ /** true: only installment plans; false: only ongoing subscriptions. */
99
+ installment?: boolean;
88
100
  }
89
101
  interface CreateSubscriptionInput {
90
102
  applicationId?: string;
@@ -92,7 +104,12 @@ interface CreateSubscriptionInput {
92
104
  externalCustomerId?: string;
93
105
  planReference: string;
94
106
  planName?: string;
95
- interval: SubscriptionInterval;
107
+ interval?: SubscriptionInterval;
108
+ /** Any cadence from 1 hour to 1 year. Send with intervalCount instead of, or with, `interval`. */
109
+ intervalUnit?: SubscriptionIntervalUnit;
110
+ intervalCount?: number;
111
+ /** Makes this an installment plan of exactly this many payments (2–60). No trial; set once. */
112
+ totalPayments?: number;
96
113
  amount: number;
97
114
  currency?: string;
98
115
  currentPeriodStart: string | Date;
@@ -111,6 +128,8 @@ interface UpdateSubscriptionInput {
111
128
  planReference?: string;
112
129
  planName?: string;
113
130
  interval?: SubscriptionInterval;
131
+ intervalUnit?: SubscriptionIntervalUnit;
132
+ intervalCount?: number;
114
133
  amount?: number;
115
134
  metadata?: Record<string, unknown>;
116
135
  }
@@ -124,7 +143,10 @@ interface ChangePlanInput extends UpdateSubscriptionInput {
124
143
  }
125
144
  interface RecurringIntent {
126
145
  plan: string;
127
- interval: SubscriptionInterval;
146
+ interval?: SubscriptionInterval;
147
+ intervalUnit?: SubscriptionIntervalUnit;
148
+ intervalCount?: number;
149
+ totalPayments?: number;
128
150
  amount?: number;
129
151
  trialDays?: number;
130
152
  planName?: string;
@@ -333,4 +355,4 @@ declare class ThrottleSubscriptionsError extends ThrottleError {
333
355
  });
334
356
  }
335
357
 
336
- export { createSubscriptionsClient as A, 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 Subscription as S, type ThrottleEnvelope as T, type UpdateSubscriptionInput as U, type ChangePlanInput as a, type CheckoutCollectInput as b, type CheckoutCustomerInput as c, type CheckoutSession as d, type CreateCheckoutSessionInput as e, type CreateSubscriptionInput as f, type Customer as g, type CustomerPaymentMethod as h, type Pagination as i, type QueryState as j, type SubscriptionFetcher as k, type SubscriptionInterval as l, type SubscriptionInvoiceRefund as m, type SubscriptionProviderProps as n, type SubscriptionSort as o, type SubscriptionStatus as p, type SubscriptionStatusBadgeProps as q, type SubscriptionTaxAddress as r, SubscriptionsClient as s, type SubscriptionsClientContract as t, type SubscriptionsClientOptions as u, ThrottleSubscriptionsError as v, type TrialCountdownProps as w, type TrialEligibilityInput as x, type TrialEligibilityReason as y, type TrialEligibilityResult as z };
358
+ export { type TrialEligibilityResult as A, createSubscriptionsClient as B, 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 Subscription as S, type ThrottleEnvelope as T, type UpdateSubscriptionInput as U, type ChangePlanInput as a, type CheckoutCollectInput as b, type CheckoutCustomerInput as c, type CheckoutSession as d, type CreateCheckoutSessionInput as e, type CreateSubscriptionInput as f, type Customer as g, type CustomerPaymentMethod as h, type Pagination as i, type QueryState as j, type SubscriptionFetcher as k, type SubscriptionInterval as l, type SubscriptionIntervalUnit as m, type SubscriptionInvoiceRefund as n, type SubscriptionProviderProps as o, type SubscriptionSort as p, type SubscriptionStatus as q, type SubscriptionStatusBadgeProps as r, type SubscriptionTaxAddress as s, SubscriptionsClient as t, type SubscriptionsClientContract as u, type SubscriptionsClientOptions as v, ThrottleSubscriptionsError as w, type TrialCountdownProps as x, type TrialEligibilityInput as y, type TrialEligibilityReason as z };
package/dist/index.cjs CHANGED
@@ -28,12 +28,15 @@ __export(index_exports, {
28
28
  ThrottleError: () => import_errors2.ThrottleError,
29
29
  ThrottleSubscriptionsError: () => ThrottleSubscriptionsError,
30
30
  TrialCountdown: () => TrialCountdown,
31
+ cadenceLabel: () => cadenceLabel2,
32
+ cadenceNoun: () => cadenceNoun2,
31
33
  canCancelSubscription: () => canCancelSubscription,
32
34
  canPauseSubscription: () => canPauseSubscription,
33
35
  canResumeSubscription: () => canResumeSubscription,
34
36
  createSubscriptionFetcher: () => createSubscriptionFetcher,
35
37
  createSubscriptionsClient: () => createSubscriptionsClient,
36
38
  daysUntil: () => daysUntil,
39
+ installmentProgress: () => installmentProgress2,
37
40
  isSubscriptionPastDue: () => isSubscriptionPastDue,
38
41
  isSubscriptionTrialing: () => isSubscriptionTrialing,
39
42
  isTerminalSubscription: () => isTerminalSubscription,
@@ -76,6 +79,11 @@ function normalizeSubscription(raw) {
76
79
  planReference: requiredString(raw?.planReference, "subscription.planReference"),
77
80
  planName: optionalString(raw?.planName),
78
81
  interval: raw?.interval ?? "monthly",
82
+ intervalUnit: optionalString(raw?.intervalUnit) ?? null,
83
+ intervalCount: raw?.intervalCount == null ? null : Number(raw.intervalCount),
84
+ totalPayments: raw?.totalPayments == null ? null : Number(raw.totalPayments),
85
+ paymentsMade: Number(raw?.paymentsMade ?? 0),
86
+ completedAt: optionalIsoDateString(raw?.completedAt),
79
87
  amount: Number(raw?.amount ?? 0),
80
88
  currency: optionalString(raw?.currency) ?? "USD",
81
89
  currentPeriodStart: requiredDateString(
@@ -170,6 +178,14 @@ function optionalDateString(value) {
170
178
  if (typeof value === "string" && value.length > 0) return value;
171
179
  return null;
172
180
  }
181
+ function optionalIsoDateString(value) {
182
+ if (value instanceof Date) return value.toISOString();
183
+ if (typeof value === "string" && value.length > 0) {
184
+ const d = new Date(value);
185
+ return Number.isNaN(d.getTime()) ? value : d.toISOString();
186
+ }
187
+ return null;
188
+ }
173
189
  function objectOrEmpty(value) {
174
190
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
175
191
  }
@@ -243,6 +259,9 @@ var SubscriptionsClient = class {
243
259
  planReference: input.planReference,
244
260
  planName: input.planName,
245
261
  interval: input.interval,
262
+ intervalUnit: input.intervalUnit,
263
+ intervalCount: input.intervalCount,
264
+ totalPayments: input.totalPayments,
246
265
  amount: input.amount,
247
266
  currency: input.currency,
248
267
  currentPeriodStart: toIso(input.currentPeriodStart),
@@ -259,6 +278,7 @@ var SubscriptionsClient = class {
259
278
  setQuery(query, "externalCustomerId", params.externalCustomerId);
260
279
  setQuery(query, "status", params.status);
261
280
  setQuery(query, "interval", params.interval);
281
+ setQuery(query, "installment", params.installment);
262
282
  setQuery(query, "q", params.q);
263
283
  setQuery(query, "cursor", params.cursor);
264
284
  setQuery(query, "limit", params.limit);
@@ -616,9 +636,65 @@ function useStableValue(value) {
616
636
  return (0, import_react2.useMemo)(() => value, [key]);
617
637
  }
618
638
 
639
+ // ../core-cadence/src/cadence.ts
640
+ var INTERVAL_UNITS = ["hour", "day", "week", "month"];
641
+ var NAMED_INTERVALS = ["weekly", "biweekly", "monthly", "quarterly", "yearly"];
642
+ var INTERVAL_VALUES = [...NAMED_INTERVALS, "custom"];
643
+ var HOUR_MS = 36e5;
644
+ var DAY_MS = 24 * HOUR_MS;
645
+ var WEEK_MS = 7 * DAY_MS;
646
+ function isNamedInterval(value) {
647
+ return typeof value === "string" && NAMED_INTERVALS.includes(value);
648
+ }
649
+ function isIntervalUnit(value) {
650
+ return typeof value === "string" && INTERVAL_UNITS.includes(value);
651
+ }
652
+
653
+ // ../core-cadence/src/installments.ts
654
+ function installmentProgress(sub) {
655
+ if (sub.totalPayments == null) return null;
656
+ const paymentsMade = Math.min(sub.paymentsMade ?? 0, sub.totalPayments);
657
+ const remainingPayments = sub.totalPayments - paymentsMade;
658
+ return {
659
+ paymentsMade,
660
+ totalPayments: sub.totalPayments,
661
+ remainingPayments,
662
+ remainingCents: remainingPayments * sub.amount * (sub.quantity ?? 1)
663
+ };
664
+ }
665
+
666
+ // ../core-cadence/src/labels.ts
667
+ var NAMED_NOUN = {
668
+ weekly: "week",
669
+ biweekly: "2 weeks",
670
+ monthly: "month",
671
+ quarterly: "quarter",
672
+ yearly: "year"
673
+ };
674
+ var NAMED_LABEL = {
675
+ weekly: "Weekly",
676
+ biweekly: "Biweekly",
677
+ monthly: "Monthly",
678
+ quarterly: "Quarterly",
679
+ yearly: "Yearly"
680
+ };
681
+ function cadenceNoun(cadence) {
682
+ if (isNamedInterval(cadence.interval)) return NAMED_NOUN[cadence.interval];
683
+ if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) {
684
+ return cadence.intervalCount === 1 ? cadence.intervalUnit : `${cadence.intervalCount} ${cadence.intervalUnit}s`;
685
+ }
686
+ return cadence.interval;
687
+ }
688
+ function cadenceLabel(cadence) {
689
+ if (isNamedInterval(cadence.interval)) return NAMED_LABEL[cadence.interval];
690
+ if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) return `Every ${cadenceNoun(cadence)}`;
691
+ return cadence.interval;
692
+ }
693
+
619
694
  // src/helpers.ts
620
695
  function isTerminalSubscription(status) {
621
- return getStatus(status) === "cancelled";
696
+ const s = getStatus(status);
697
+ return s === "cancelled" || s === "completed";
622
698
  }
623
699
  function canPauseSubscription(status) {
624
700
  return getStatus(status) === "active";
@@ -627,7 +703,7 @@ function canResumeSubscription(status) {
627
703
  return getStatus(status) === "paused";
628
704
  }
629
705
  function canCancelSubscription(status) {
630
- return getStatus(status) !== "cancelled";
706
+ return !isTerminalSubscription(status);
631
707
  }
632
708
  function isSubscriptionPastDue(status) {
633
709
  return getStatus(status) === "past_due";
@@ -644,6 +720,15 @@ function daysUntil(date, now = /* @__PURE__ */ new Date()) {
644
720
  function getStatus(input) {
645
721
  return typeof input === "string" ? input : input.status;
646
722
  }
723
+ function cadenceNoun2(cadence) {
724
+ return cadenceNoun(cadence);
725
+ }
726
+ function cadenceLabel2(cadence) {
727
+ return cadenceLabel(cadence);
728
+ }
729
+ function installmentProgress2(sub) {
730
+ return installmentProgress(sub);
731
+ }
647
732
 
648
733
  // src/components.tsx
649
734
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -652,14 +737,18 @@ var STATUS_LABELS = {
652
737
  paused: "Paused",
653
738
  cancelled: "Cancelled",
654
739
  past_due: "Past due",
655
- trialing: "Trialing"
740
+ trialing: "Trialing",
741
+ unpaid: "Unpaid",
742
+ completed: "Paid in full"
656
743
  };
657
744
  var STATUS_STYLES = {
658
745
  active: { color: "#035c4f", background: "#dff8ef", borderColor: "#a8e8d2" },
659
746
  paused: { color: "#735c00", background: "#fff4ca", borderColor: "#f3d46b" },
660
747
  cancelled: { color: "#6c2632", background: "#ffe1e7", borderColor: "#f4a9b8" },
661
748
  past_due: { color: "#7a2d00", background: "#ffe8d6", borderColor: "#f5b47f" },
662
- trialing: { color: "#124c73", background: "#dff1ff", borderColor: "#9ed3fb" }
749
+ trialing: { color: "#124c73", background: "#dff1ff", borderColor: "#9ed3fb" },
750
+ unpaid: { color: "#7a2d00", background: "#ffe8d6", borderColor: "#f5b47f" },
751
+ completed: { color: "#035c4f", background: "#dff8ef", borderColor: "#a8e8d2" }
663
752
  };
664
753
  function SubscriptionStatusBadge({
665
754
  status,
@@ -761,12 +850,15 @@ function DunningBanner({
761
850
  ThrottleError,
762
851
  ThrottleSubscriptionsError,
763
852
  TrialCountdown,
853
+ cadenceLabel,
854
+ cadenceNoun,
764
855
  canCancelSubscription,
765
856
  canPauseSubscription,
766
857
  canResumeSubscription,
767
858
  createSubscriptionFetcher,
768
859
  createSubscriptionsClient,
769
860
  daysUntil,
861
+ installmentProgress,
770
862
  isSubscriptionPastDue,
771
863
  isSubscriptionTrialing,
772
864
  isTerminalSubscription,