@usebillow/sdk 0.8.0 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { H as HostedDomainResponse } from './index.d-CKQAhQfJ.js';
1
+ import { H as HostedDomainResponse } from './index.d-DSEYhV2c.js';
2
2
 
3
3
  /**
4
4
  * Public SDK types for prepaid credits. Re-exported by ../types.ts.
@@ -67,9 +67,33 @@ interface CreateCreditGrantInput {
67
67
  }
68
68
  /** A Credit Account's status: `frozen` takes no new reservations; `closed` (erased) takes nothing. */
69
69
  type CreditAccountStatus = "active" | "frozen" | "closed";
70
+ /** What current Included Credit Windows include, and where it stands. */
71
+ interface IncludedCredits {
72
+ /** What the windows include. */
73
+ granted: string;
74
+ /** Consumed from their credits, net of reversals. */
75
+ used: string;
76
+ held: string;
77
+ /** Unheld and spendable, credits recorded but not issued yet included. */
78
+ remaining: string;
79
+ }
80
+ /** One subscription's current Included Credit Window, in a customer's balance. */
81
+ interface IncludedPeriod extends IncludedCredits {
82
+ subscriptionId: string;
83
+ /** The window (ISO 8601), half-open: its credits expire at `end`. */
84
+ start: string;
85
+ end: string;
86
+ /** The billing period it belongs to (a trial's is the trial). */
87
+ periodStart: string;
88
+ periodEnd: string;
89
+ /** The next window's start within the paid period (a monthly refill), or null. */
90
+ nextRefillAt: string | null;
91
+ }
70
92
  /**
71
93
  * A customer's credit balance, true at `asOf`. A balance never grants spending authority - only a
72
- * reservation does. A customer with no credit account yet reads as zeros, `active`, `exhausted`.
94
+ * reservation does. A customer with no credit account yet reads as their subscriptions' recorded
95
+ * included credits alone (zeros without any), `active`, `exhausted` when nothing is spendable.
96
+ * Included credits count from the instant their window is current, before Billow issues them.
73
97
  */
74
98
  interface CreditBalance {
75
99
  /** The customer's external id. */
@@ -79,7 +103,10 @@ interface CreditBalance {
79
103
  spendable: string;
80
104
  /** Credits held by open reservations. */
81
105
  held: string;
82
- /** Credits consumed since `periodStart`, net of reversals. */
106
+ /**
107
+ * Credits consumed since `periodStart`, net of their reversals: a reversal counts against the
108
+ * period of the consumption it reverses, so this is never negative.
109
+ */
83
110
  consumedThisPeriod: string;
84
111
  /** The current included period's start, else the first instant of the current UTC month. */
85
112
  periodStart: string;
@@ -99,22 +126,23 @@ interface CreditBalance {
99
126
  /** Spendable on a category not listed: the grants that pay for every category. */
100
127
  otherCategories: string;
101
128
  };
102
- /** The active included grants (a subscription's period allowance); null when there are none. */
103
- currentPeriod: {
104
- granted: string;
105
- /** Consumed from them, net of reversals. */
106
- used: string;
107
- held: string;
108
- /** Unheld and spendable. */
109
- remaining: string;
129
+ /**
130
+ * The current Included Credit Windows together - the billing period, or the current month under
131
+ * a monthly allocation - across the customer's subscriptions; null when none is current (between
132
+ * a period's end and the payment that grants the next).
133
+ */
134
+ currentPeriod: (IncludedCredits & {
135
+ /** The earliest current window's start. */
110
136
  start: string;
111
- /** When they expire (the period end); null if one never does. */
112
- end: string | null;
113
- } | null;
137
+ /** The earliest current window's end: when the first of these credits stop. */
138
+ end: string;
139
+ }) | null;
140
+ /** Each subscription's current window, soonest end first (empty when none is current). */
141
+ includedPeriods: IncludedPeriod[];
114
142
  thresholds: {
115
143
  lowPercent: number;
116
144
  criticalPercent: number;
117
- /** What the percentages apply to: the current period's credits, else the last top-up's. */
145
+ /** What the percentages apply to: the current windows' credits, else the last top-up's. */
118
146
  reference: string | null;
119
147
  level: CreditThresholdLevel;
120
148
  };
@@ -144,6 +172,8 @@ interface CreditLedgerEntry {
144
172
  callerReason: string | null;
145
173
  /** The metadata of the resource it belongs to: its reservation, reversal or top-up, else its grant. */
146
174
  metadata: Record<string, string> | null;
175
+ /** On an included grant's transaction: the subscription whose window issued the grant. */
176
+ subscriptionId: string | null;
147
177
  createdAt: string;
148
178
  }
149
179
  /** What `credits.usage.get` totals each row by. */
@@ -326,6 +356,69 @@ interface CreateCreditIncludedRuleInput {
326
356
  type UpdateCreditIncludedRuleInput = Partial<Omit<CreateCreditIncludedRuleInput, "priceId">> & {
327
357
  archived?: boolean;
328
358
  };
359
+ /**
360
+ * Where an Included Credit Window stands: `scheduled` (a later window, not started), `pending`
361
+ * (current, waiting to be issued - Billow issues it within seconds), `blocked` (current, but its
362
+ * last issue attempt could not go through - see `blockedCause` - and Billow retries it with
363
+ * backoff), `issued`, `suspended` (held by a pause), `lapsed` (over without being issued: a period
364
+ * paid after it ended, or one that passed while paused), `ended` (ended early, with `endCause`),
365
+ * or `account_closed` (the customer was erased, so it never issues).
366
+ */
367
+ type CreditWindowState = "scheduled" | "pending" | "blocked" | "issued" | "suspended" | "lapsed" | "ended" | "account_closed";
368
+ /**
369
+ * An Included Credit Window: what one window of a period Billow granted a subscription includes -
370
+ * the whole billing period, one month of it under a monthly rule, or a trial - and how far its
371
+ * credits have been issued.
372
+ */
373
+ interface CreditIncludedWindow {
374
+ id: string;
375
+ subscriptionId: string;
376
+ /** The customer's external id. */
377
+ customerId: string;
378
+ /** The window (ISO 8601), half-open: its credits expire at `end`. */
379
+ start: string;
380
+ end: string;
381
+ /** The billing period it belongs to (a trial's is the trial). */
382
+ periodStart: string;
383
+ periodEnd: string;
384
+ /** The next window's start within the period (a monthly refill), or null for its last window. */
385
+ nextRefillAt: string | null;
386
+ /** How the rule allocated the period when it was granted. */
387
+ allocation: CreditAllocationInterval;
388
+ /** The categories its credits may pay for; null = every category. */
389
+ eligibility: string[] | null;
390
+ /** Microcredits the window includes. */
391
+ entitled: string;
392
+ /** Microcredits issued to the customer for it so far. */
393
+ issued: string;
394
+ state: CreditWindowState;
395
+ /**
396
+ * For a `blocked` window: `capacity` (its credits would take the customer's balance past the
397
+ * largest total Billow holds) or `error` (an unexpected fault); null otherwise.
398
+ */
399
+ blockedCause: "capacity" | "error" | null;
400
+ /** For a `pending` or `blocked` window: since when it has been due. */
401
+ dueSince: string | null;
402
+ endedAt: string | null;
403
+ endCause: "canceled" | "charged_back" | null;
404
+ createdAt: string;
405
+ }
406
+ /**
407
+ * Whose Included Credit Windows to list: one or more subscriptions, or a customer (by external id)
408
+ * - exactly one of the two.
409
+ */
410
+ type CreditIncludedWindowListParams = ({
411
+ subscription: string | string[];
412
+ customer?: never;
413
+ } | {
414
+ customer: string;
415
+ subscription?: never;
416
+ }) & {
417
+ /** Only each subscription's latest window that has started (what the subscription shows now). */
418
+ current?: boolean;
419
+ limit?: number;
420
+ cursor?: string;
421
+ };
329
422
  /**
330
423
  * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
331
424
  * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
@@ -427,4 +520,4 @@ interface HostedDomainDisabledData extends HostedDomainEventBase {
427
520
  reason: Extract<HostedDomainStatusReason, "dns_lost" | "reassigned" | "entitlement_lapsed" | "suspended">;
428
521
  }
429
522
 
430
- export type { CreditTopUpStatus as A, CreditTransactionType as B, CreditGrantKind as C, CreditUsageGroupBy as D, HostedDomainEventBase as E, HostedDomainStatus as F, HostedDomainStatusReason as G, HostedDomainActivatedData as H, UpdateCreditPackInput as U, CreditThresholdLevel as a, HostedDomainDnsFailingData as b, HostedDomainReassignmentPendingData as c, HostedDomainDisabledData as d, CreditGrant as e, CreditTopUp as f, CreateCreditGrantInput as g, CreditGrantRequestResult as h, CreditPacks as i, CreateCreditPackInput as j, CreditPack as k, CreateCreditIncludedRuleInput as l, CreditIncludedRule as m, UpdateCreditIncludedRuleInput as n, CreateCreditTopUpInput as o, CreditTopUpRequestResult as p, CreditTopUpListParams as q, CreditBalance as r, CreditLedgerEntry as s, CreditUsageParams as t, CreditUsage as u, CreditAccountStatus as v, CreditAllocationInterval as w, CreditMoney as x, CreditPackBreakdown as y, CreditPackListItem as z };
523
+ export type { CreditPackBreakdown as A, CreditPackListItem as B, CreditGrantKind as C, CreditTopUpStatus as D, CreditTransactionType as E, CreditUsageGroupBy as F, CreditWindowState as G, HostedDomainActivatedData as H, HostedDomainEventBase as I, HostedDomainStatus as J, HostedDomainStatusReason as K, IncludedCredits as L, IncludedPeriod as M, UpdateCreditPackInput as U, CreditThresholdLevel as a, HostedDomainDnsFailingData as b, HostedDomainReassignmentPendingData as c, HostedDomainDisabledData as d, CreditGrant as e, CreditTopUp as f, CreditIncludedWindow as g, CreateCreditGrantInput as h, CreditGrantRequestResult as i, CreditPacks as j, CreateCreditPackInput as k, CreditPack as l, CreateCreditIncludedRuleInput as m, CreditIncludedRule as n, UpdateCreditIncludedRuleInput as o, CreditIncludedWindowListParams as p, CreateCreditTopUpInput as q, CreditTopUpRequestResult as r, CreditTopUpListParams as s, CreditBalance as t, CreditLedgerEntry as u, CreditUsageParams as v, CreditUsage as w, CreditAccountStatus as x, CreditAllocationInterval as y, CreditMoney as z };
@@ -1,4 +1,4 @@
1
- import { H as HostedDomainResponse } from './index.d-CKQAhQfJ.cjs';
1
+ import { H as HostedDomainResponse } from './index.d-DSEYhV2c.cjs';
2
2
 
3
3
  /**
4
4
  * Public SDK types for prepaid credits. Re-exported by ../types.ts.
@@ -67,9 +67,33 @@ interface CreateCreditGrantInput {
67
67
  }
68
68
  /** A Credit Account's status: `frozen` takes no new reservations; `closed` (erased) takes nothing. */
69
69
  type CreditAccountStatus = "active" | "frozen" | "closed";
70
+ /** What current Included Credit Windows include, and where it stands. */
71
+ interface IncludedCredits {
72
+ /** What the windows include. */
73
+ granted: string;
74
+ /** Consumed from their credits, net of reversals. */
75
+ used: string;
76
+ held: string;
77
+ /** Unheld and spendable, credits recorded but not issued yet included. */
78
+ remaining: string;
79
+ }
80
+ /** One subscription's current Included Credit Window, in a customer's balance. */
81
+ interface IncludedPeriod extends IncludedCredits {
82
+ subscriptionId: string;
83
+ /** The window (ISO 8601), half-open: its credits expire at `end`. */
84
+ start: string;
85
+ end: string;
86
+ /** The billing period it belongs to (a trial's is the trial). */
87
+ periodStart: string;
88
+ periodEnd: string;
89
+ /** The next window's start within the paid period (a monthly refill), or null. */
90
+ nextRefillAt: string | null;
91
+ }
70
92
  /**
71
93
  * A customer's credit balance, true at `asOf`. A balance never grants spending authority - only a
72
- * reservation does. A customer with no credit account yet reads as zeros, `active`, `exhausted`.
94
+ * reservation does. A customer with no credit account yet reads as their subscriptions' recorded
95
+ * included credits alone (zeros without any), `active`, `exhausted` when nothing is spendable.
96
+ * Included credits count from the instant their window is current, before Billow issues them.
73
97
  */
74
98
  interface CreditBalance {
75
99
  /** The customer's external id. */
@@ -79,7 +103,10 @@ interface CreditBalance {
79
103
  spendable: string;
80
104
  /** Credits held by open reservations. */
81
105
  held: string;
82
- /** Credits consumed since `periodStart`, net of reversals. */
106
+ /**
107
+ * Credits consumed since `periodStart`, net of their reversals: a reversal counts against the
108
+ * period of the consumption it reverses, so this is never negative.
109
+ */
83
110
  consumedThisPeriod: string;
84
111
  /** The current included period's start, else the first instant of the current UTC month. */
85
112
  periodStart: string;
@@ -99,22 +126,23 @@ interface CreditBalance {
99
126
  /** Spendable on a category not listed: the grants that pay for every category. */
100
127
  otherCategories: string;
101
128
  };
102
- /** The active included grants (a subscription's period allowance); null when there are none. */
103
- currentPeriod: {
104
- granted: string;
105
- /** Consumed from them, net of reversals. */
106
- used: string;
107
- held: string;
108
- /** Unheld and spendable. */
109
- remaining: string;
129
+ /**
130
+ * The current Included Credit Windows together - the billing period, or the current month under
131
+ * a monthly allocation - across the customer's subscriptions; null when none is current (between
132
+ * a period's end and the payment that grants the next).
133
+ */
134
+ currentPeriod: (IncludedCredits & {
135
+ /** The earliest current window's start. */
110
136
  start: string;
111
- /** When they expire (the period end); null if one never does. */
112
- end: string | null;
113
- } | null;
137
+ /** The earliest current window's end: when the first of these credits stop. */
138
+ end: string;
139
+ }) | null;
140
+ /** Each subscription's current window, soonest end first (empty when none is current). */
141
+ includedPeriods: IncludedPeriod[];
114
142
  thresholds: {
115
143
  lowPercent: number;
116
144
  criticalPercent: number;
117
- /** What the percentages apply to: the current period's credits, else the last top-up's. */
145
+ /** What the percentages apply to: the current windows' credits, else the last top-up's. */
118
146
  reference: string | null;
119
147
  level: CreditThresholdLevel;
120
148
  };
@@ -144,6 +172,8 @@ interface CreditLedgerEntry {
144
172
  callerReason: string | null;
145
173
  /** The metadata of the resource it belongs to: its reservation, reversal or top-up, else its grant. */
146
174
  metadata: Record<string, string> | null;
175
+ /** On an included grant's transaction: the subscription whose window issued the grant. */
176
+ subscriptionId: string | null;
147
177
  createdAt: string;
148
178
  }
149
179
  /** What `credits.usage.get` totals each row by. */
@@ -326,6 +356,69 @@ interface CreateCreditIncludedRuleInput {
326
356
  type UpdateCreditIncludedRuleInput = Partial<Omit<CreateCreditIncludedRuleInput, "priceId">> & {
327
357
  archived?: boolean;
328
358
  };
359
+ /**
360
+ * Where an Included Credit Window stands: `scheduled` (a later window, not started), `pending`
361
+ * (current, waiting to be issued - Billow issues it within seconds), `blocked` (current, but its
362
+ * last issue attempt could not go through - see `blockedCause` - and Billow retries it with
363
+ * backoff), `issued`, `suspended` (held by a pause), `lapsed` (over without being issued: a period
364
+ * paid after it ended, or one that passed while paused), `ended` (ended early, with `endCause`),
365
+ * or `account_closed` (the customer was erased, so it never issues).
366
+ */
367
+ type CreditWindowState = "scheduled" | "pending" | "blocked" | "issued" | "suspended" | "lapsed" | "ended" | "account_closed";
368
+ /**
369
+ * An Included Credit Window: what one window of a period Billow granted a subscription includes -
370
+ * the whole billing period, one month of it under a monthly rule, or a trial - and how far its
371
+ * credits have been issued.
372
+ */
373
+ interface CreditIncludedWindow {
374
+ id: string;
375
+ subscriptionId: string;
376
+ /** The customer's external id. */
377
+ customerId: string;
378
+ /** The window (ISO 8601), half-open: its credits expire at `end`. */
379
+ start: string;
380
+ end: string;
381
+ /** The billing period it belongs to (a trial's is the trial). */
382
+ periodStart: string;
383
+ periodEnd: string;
384
+ /** The next window's start within the period (a monthly refill), or null for its last window. */
385
+ nextRefillAt: string | null;
386
+ /** How the rule allocated the period when it was granted. */
387
+ allocation: CreditAllocationInterval;
388
+ /** The categories its credits may pay for; null = every category. */
389
+ eligibility: string[] | null;
390
+ /** Microcredits the window includes. */
391
+ entitled: string;
392
+ /** Microcredits issued to the customer for it so far. */
393
+ issued: string;
394
+ state: CreditWindowState;
395
+ /**
396
+ * For a `blocked` window: `capacity` (its credits would take the customer's balance past the
397
+ * largest total Billow holds) or `error` (an unexpected fault); null otherwise.
398
+ */
399
+ blockedCause: "capacity" | "error" | null;
400
+ /** For a `pending` or `blocked` window: since when it has been due. */
401
+ dueSince: string | null;
402
+ endedAt: string | null;
403
+ endCause: "canceled" | "charged_back" | null;
404
+ createdAt: string;
405
+ }
406
+ /**
407
+ * Whose Included Credit Windows to list: one or more subscriptions, or a customer (by external id)
408
+ * - exactly one of the two.
409
+ */
410
+ type CreditIncludedWindowListParams = ({
411
+ subscription: string | string[];
412
+ customer?: never;
413
+ } | {
414
+ customer: string;
415
+ subscription?: never;
416
+ }) & {
417
+ /** Only each subscription's latest window that has started (what the subscription shows now). */
418
+ current?: boolean;
419
+ limit?: number;
420
+ cursor?: string;
421
+ };
329
422
  /**
330
423
  * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
331
424
  * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
@@ -427,4 +520,4 @@ interface HostedDomainDisabledData extends HostedDomainEventBase {
427
520
  reason: Extract<HostedDomainStatusReason, "dns_lost" | "reassigned" | "entitlement_lapsed" | "suspended">;
428
521
  }
429
522
 
430
- export type { CreditTopUpStatus as A, CreditTransactionType as B, CreditGrantKind as C, CreditUsageGroupBy as D, HostedDomainEventBase as E, HostedDomainStatus as F, HostedDomainStatusReason as G, HostedDomainActivatedData as H, UpdateCreditPackInput as U, CreditThresholdLevel as a, HostedDomainDnsFailingData as b, HostedDomainReassignmentPendingData as c, HostedDomainDisabledData as d, CreditGrant as e, CreditTopUp as f, CreateCreditGrantInput as g, CreditGrantRequestResult as h, CreditPacks as i, CreateCreditPackInput as j, CreditPack as k, CreateCreditIncludedRuleInput as l, CreditIncludedRule as m, UpdateCreditIncludedRuleInput as n, CreateCreditTopUpInput as o, CreditTopUpRequestResult as p, CreditTopUpListParams as q, CreditBalance as r, CreditLedgerEntry as s, CreditUsageParams as t, CreditUsage as u, CreditAccountStatus as v, CreditAllocationInterval as w, CreditMoney as x, CreditPackBreakdown as y, CreditPackListItem as z };
523
+ export type { CreditPackBreakdown as A, CreditPackListItem as B, CreditGrantKind as C, CreditTopUpStatus as D, CreditTransactionType as E, CreditUsageGroupBy as F, CreditWindowState as G, HostedDomainActivatedData as H, HostedDomainEventBase as I, HostedDomainStatus as J, HostedDomainStatusReason as K, IncludedCredits as L, IncludedPeriod as M, UpdateCreditPackInput as U, CreditThresholdLevel as a, HostedDomainDnsFailingData as b, HostedDomainReassignmentPendingData as c, HostedDomainDisabledData as d, CreditGrant as e, CreditTopUp as f, CreditIncludedWindow as g, CreateCreditGrantInput as h, CreditGrantRequestResult as i, CreditPacks as j, CreateCreditPackInput as k, CreditPack as l, CreateCreditIncludedRuleInput as m, CreditIncludedRule as n, UpdateCreditIncludedRuleInput as o, CreditIncludedWindowListParams as p, CreateCreditTopUpInput as q, CreditTopUpRequestResult as r, CreditTopUpListParams as s, CreditBalance as t, CreditLedgerEntry as u, CreditUsageParams as v, CreditUsage as w, CreditAccountStatus as x, CreditAllocationInterval as y, CreditMoney as z };
package/dist/index.cjs CHANGED
@@ -576,6 +576,31 @@ function createCreditsResource(ctx) {
576
576
  options
577
577
  )
578
578
  },
579
+ includedWindows: {
580
+ /**
581
+ * The Included Credit Windows of one or more subscriptions (`subscription`, an id or a list
582
+ * of up to 100), or of a customer (`customer`, by external id) - newest first: what each
583
+ * period Billow granted includes (the whole period, each month of it under a monthly rule,
584
+ * or a trial), how far it was issued, and its `state`. With `current: true`, only each
585
+ * subscription's latest window that has started - what it stands at now. Auto-paginating by
586
+ * cursor: `await` the first page, `for await (…)` every window, or `.listAll()` to collect
587
+ * them.
588
+ */
589
+ list: (params, options) => {
590
+ const { subscription, ...rest } = params;
591
+ const subscriptions = Array.isArray(subscription) ? subscription.join(",") : subscription;
592
+ return makeCursorListPromise(
593
+ (p) => apiRequest(
594
+ ctx,
595
+ "GET",
596
+ `/v1/credits/included-windows${toQuery({ ...p, subscription: subscriptions })}`,
597
+ void 0,
598
+ options
599
+ ),
600
+ rest
601
+ );
602
+ }
603
+ },
579
604
  topUps: {
580
605
  /**
581
606
  * Buy a Credit Pack for a customer: answers the top-up with `checkoutUrl`, the hosted
@@ -1323,7 +1348,18 @@ function createSubscriptionsResource(ctx) {
1323
1348
  "POST",
1324
1349
  `/v1/subscriptions/${encodeURIComponent(id)}/resume-cancellation`
1325
1350
  ),
1351
+ /**
1352
+ * Pause an active or trialing subscription: no renewals and no access until it is resumed.
1353
+ * Refused while one of its invoices is still being collected.
1354
+ */
1326
1355
  pause: (id) => apiRequest(ctx, "POST", `/v1/subscriptions/${encodeURIComponent(id)}/pause`),
1356
+ /**
1357
+ * Resume a paused subscription. Paused time is never billed: resumed before its paid period
1358
+ * ends, it carries on and renews at `currentPeriodEnd`; resumed after, a fresh full period
1359
+ * starts now and is charged at once like a renewal, with the ended period's usage (a decline
1360
+ * returns it `past_due`). Usage recorded while paused is never billed. A paused trial resumes
1361
+ * `trialing`. Duplicate calls are safe.
1362
+ */
1327
1363
  resume: (id) => apiRequest(ctx, "POST", `/v1/subscriptions/${encodeURIComponent(id)}/resume`),
1328
1364
  /** Apply a coupon to an existing subscription. */
1329
1365
  applyCoupon: (id, code) => apiRequest(