@usebillow/sdk 0.8.0 → 0.10.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.
- package/CHANGELOG.md +22 -0
- package/dist/{billing-B-VyZCXV.d.cts → billing-8ug1Gw05.d.cts} +14 -10
- package/dist/{billing-CgjcWmvb.d.ts → billing-Bs10EcjR.d.ts} +14 -10
- package/dist/{billing-status-BZQN_gm7.d.cts → billing-status-DZkB0VPK.d.cts} +5 -5
- package/dist/{billing-status-BZQN_gm7.d.ts → billing-status-DZkB0VPK.d.ts} +5 -5
- package/dist/{chunk-CCG4F5FK.js → chunk-47J7FYM5.js} +2 -2
- package/dist/chunk-47J7FYM5.js.map +1 -0
- package/dist/{chunk-J6JIZGWB.js → chunk-XKN7ZRAR.js} +81 -22
- package/dist/chunk-XKN7ZRAR.js.map +1 -0
- package/dist/config.cjs +3 -3
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +10 -10
- package/dist/config.d.ts +10 -10
- package/dist/config.js +3 -3
- package/dist/config.js.map +1 -1
- package/dist/{hosted-domains-BbuyxnuH.d.cts → hosted-domains-Ci6jeNAe.d.cts} +124 -17
- package/dist/{hosted-domains-BP91tg9P.d.ts → hosted-domains-DSs5Iw9U.d.ts} +124 -17
- package/dist/index.cjs +79 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -55
- package/dist/index.d.ts +89 -55
- package/dist/index.js +2 -2
- package/dist/ingestion.cjs.map +1 -1
- package/dist/ingestion.d.cts +19 -19
- package/dist/ingestion.d.ts +19 -19
- package/dist/ingestion.js.map +1 -1
- package/dist/react.cjs +28 -5
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +7 -7
- package/dist/react.d.ts +7 -7
- package/dist/react.js +2 -2
- package/dist/react.js.map +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +12 -12
- package/dist/server.d.ts +12 -12
- package/dist/server.js.map +1 -1
- package/dist/status.cjs.map +1 -1
- package/dist/status.d.cts +1 -1
- package/dist/status.d.ts +1 -1
- package/dist/status.js +1 -1
- package/dist/webhooks.cjs.map +1 -1
- package/dist/webhooks.d.cts +27 -14
- package/dist/webhooks.d.ts +27 -14
- package/dist/webhooks.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-CCG4F5FK.js.map +0 -1
- package/dist/chunk-J6JIZGWB.js.map +0 -1
- package/dist/{index.d-CKQAhQfJ.d.ts → index.d-DSEYhV2c.d.cts} +2 -2
- package/dist/{index.d-CKQAhQfJ.d.cts → index.d-DSEYhV2c.d.ts} +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as HostedDomainResponse } from './index.d-
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/**
|
|
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
|
-
/**
|
|
112
|
-
end: string
|
|
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
|
|
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
|
};
|
|
@@ -127,7 +155,11 @@ type CreditTransactionType = "grant" | "hold" | "release" | "consume" | "expire"
|
|
|
127
155
|
interface CreditLedgerEntry {
|
|
128
156
|
id: string;
|
|
129
157
|
type: CreditTransactionType;
|
|
130
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Why Billow posted it, as a system code (`api_grant`, `grant_expired`, `subscription_period`,
|
|
160
|
+
* `subscription_upgrade`, `subscription_canceled`, `subscription_charged_back`, ...); never free
|
|
161
|
+
* text.
|
|
162
|
+
*/
|
|
131
163
|
reason: string | null;
|
|
132
164
|
/** How it moved the account's unheld credits (signed). */
|
|
133
165
|
availableDelta: string;
|
|
@@ -144,6 +176,8 @@ interface CreditLedgerEntry {
|
|
|
144
176
|
callerReason: string | null;
|
|
145
177
|
/** The metadata of the resource it belongs to: its reservation, reversal or top-up, else its grant. */
|
|
146
178
|
metadata: Record<string, string> | null;
|
|
179
|
+
/** On an included grant's transaction: the subscription whose window issued the grant. */
|
|
180
|
+
subscriptionId: string | null;
|
|
147
181
|
createdAt: string;
|
|
148
182
|
}
|
|
149
183
|
/** What `credits.usage.get` totals each row by. */
|
|
@@ -326,6 +360,79 @@ interface CreateCreditIncludedRuleInput {
|
|
|
326
360
|
type UpdateCreditIncludedRuleInput = Partial<Omit<CreateCreditIncludedRuleInput, "priceId">> & {
|
|
327
361
|
archived?: boolean;
|
|
328
362
|
};
|
|
363
|
+
/**
|
|
364
|
+
* Where an Included Credit Window stands: `scheduled` (a later window, not started), `pending`
|
|
365
|
+
* (current, waiting to be issued - Billow issues it within seconds), `blocked` (current, but its
|
|
366
|
+
* last issue attempt could not go through - see `blockedCause` - and Billow retries it with
|
|
367
|
+
* backoff), `issued`, `suspended` (held by a pause), `lapsed` (over without being issued: a period
|
|
368
|
+
* paid after it ended, or one that passed while paused), `ended` (ended early, with `endCause`),
|
|
369
|
+
* or `account_closed` (the customer was erased, so it never issues).
|
|
370
|
+
*/
|
|
371
|
+
type CreditWindowState = "scheduled" | "pending" | "blocked" | "issued" | "suspended" | "lapsed" | "ended" | "account_closed";
|
|
372
|
+
/**
|
|
373
|
+
* An Included Credit Window: what one window of a period Billow granted a subscription includes -
|
|
374
|
+
* the whole billing period, one month of it under a monthly rule, or a trial - and how far its
|
|
375
|
+
* credits have been issued.
|
|
376
|
+
*/
|
|
377
|
+
interface CreditIncludedWindow {
|
|
378
|
+
id: string;
|
|
379
|
+
subscriptionId: string;
|
|
380
|
+
/** The customer's external id. */
|
|
381
|
+
customerId: string;
|
|
382
|
+
/** The window (ISO 8601), half-open: its credits expire at `end`. */
|
|
383
|
+
start: string;
|
|
384
|
+
end: string;
|
|
385
|
+
/** The billing period it belongs to (a trial's is the trial). */
|
|
386
|
+
periodStart: string;
|
|
387
|
+
periodEnd: string;
|
|
388
|
+
/** The next window's start within the period (a monthly refill), or null for its last window. */
|
|
389
|
+
nextRefillAt: string | null;
|
|
390
|
+
/** How the rule allocated the period when it was granted. */
|
|
391
|
+
allocation: CreditAllocationInterval;
|
|
392
|
+
/** The categories its credits may pay for; null = every category. */
|
|
393
|
+
eligibility: string[] | null;
|
|
394
|
+
/** Microcredits the window includes. */
|
|
395
|
+
entitled: string;
|
|
396
|
+
/** Microcredits issued to the customer for it so far. */
|
|
397
|
+
issued: string;
|
|
398
|
+
state: CreditWindowState;
|
|
399
|
+
/**
|
|
400
|
+
* For a `blocked` window: `capacity` (its credits would take the customer's balance past the
|
|
401
|
+
* largest total Billow holds) or `error` (an unexpected fault); null otherwise.
|
|
402
|
+
*/
|
|
403
|
+
blockedCause: "capacity" | "error" | null;
|
|
404
|
+
/** For a `pending` or `blocked` window: since when it has been due. */
|
|
405
|
+
dueSince: string | null;
|
|
406
|
+
/** When an `ended` window ended early; null otherwise. */
|
|
407
|
+
endedAt: string | null;
|
|
408
|
+
/**
|
|
409
|
+
* Why an `ended` window ended early: `canceled` (the subscription was canceled immediately) or
|
|
410
|
+
* `charged_back` (the payment for its period was lost to a chargeback); null otherwise.
|
|
411
|
+
*/
|
|
412
|
+
endCause: "canceled" | "charged_back" | null;
|
|
413
|
+
/**
|
|
414
|
+
* When a plan upgrade inside the period last raised what the window includes (or added the
|
|
415
|
+
* window, to a period that had none); null for a window as its period was granted.
|
|
416
|
+
*/
|
|
417
|
+
raisedAt: string | null;
|
|
418
|
+
createdAt: string;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Whose Included Credit Windows to list: one or more subscriptions, or a customer (by external id)
|
|
422
|
+
* - exactly one of the two.
|
|
423
|
+
*/
|
|
424
|
+
type CreditIncludedWindowListParams = ({
|
|
425
|
+
subscription: string | string[];
|
|
426
|
+
customer?: never;
|
|
427
|
+
} | {
|
|
428
|
+
customer: string;
|
|
429
|
+
subscription?: never;
|
|
430
|
+
}) & {
|
|
431
|
+
/** Only each subscription's latest window that has started (what the subscription shows now). */
|
|
432
|
+
current?: boolean;
|
|
433
|
+
limit?: number;
|
|
434
|
+
cursor?: string;
|
|
435
|
+
};
|
|
329
436
|
/**
|
|
330
437
|
* A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
|
|
331
438
|
* `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
|
|
@@ -427,4 +534,4 @@ interface HostedDomainDisabledData extends HostedDomainEventBase {
|
|
|
427
534
|
reason: Extract<HostedDomainStatusReason, "dns_lost" | "reassigned" | "entitlement_lapsed" | "suspended">;
|
|
428
535
|
}
|
|
429
536
|
|
|
430
|
-
export type {
|
|
537
|
+
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
|
@@ -36,19 +36,26 @@ var BillowApiError = class extends Error {
|
|
|
36
36
|
code;
|
|
37
37
|
/** Structured error context from the server (e.g. per-field validation issues), when present. */
|
|
38
38
|
details;
|
|
39
|
-
/** billow's per-request id (`x-request-id`)
|
|
39
|
+
/** billow's per-request id (`x-request-id`) - quote it in a bug report to trace the server log. */
|
|
40
40
|
requestId;
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* How many seconds to wait before trying again, from the response's `Retry-After` header (sent
|
|
43
|
+
* with a `429 rate_limited`); undefined when the response did not say.
|
|
44
|
+
*/
|
|
45
|
+
retryAfterSeconds;
|
|
46
|
+
constructor(status, code, message, details, requestId, retryAfterSeconds) {
|
|
42
47
|
super(message);
|
|
43
48
|
this.name = "BillowApiError";
|
|
44
49
|
this.status = status;
|
|
45
50
|
this.code = code;
|
|
46
51
|
this.details = details;
|
|
47
52
|
this.requestId = requestId;
|
|
53
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
48
54
|
}
|
|
49
55
|
};
|
|
50
56
|
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
51
57
|
var DEFAULT_RETRY_BACKOFF_MS = 500;
|
|
58
|
+
var MAX_RETRY_AFTER_SECONDS = 3600;
|
|
52
59
|
function makeContext(bearer, opts) {
|
|
53
60
|
return {
|
|
54
61
|
fetch: opts.fetch ?? fetch,
|
|
@@ -67,7 +74,7 @@ function isRetryable(status, safeToRepeat2) {
|
|
|
67
74
|
function backoffMs(base, attempt, retryAfter) {
|
|
68
75
|
if (retryAfter) {
|
|
69
76
|
const secs = Number(retryAfter);
|
|
70
|
-
if (Number.isFinite(secs) && secs >= 0) return secs * 1e3;
|
|
77
|
+
if (Number.isFinite(secs) && secs >= 0) return Math.min(secs, MAX_RETRY_AFTER_SECONDS) * 1e3;
|
|
71
78
|
}
|
|
72
79
|
return base * 2 ** attempt;
|
|
73
80
|
}
|
|
@@ -189,9 +196,25 @@ function errorFrom(res, data) {
|
|
|
189
196
|
err.code ?? "error",
|
|
190
197
|
err.message ?? String(res.status),
|
|
191
198
|
err.details,
|
|
192
|
-
requestIdOf(res)
|
|
199
|
+
requestIdOf(res),
|
|
200
|
+
retryAfterOf(res)
|
|
193
201
|
);
|
|
194
202
|
}
|
|
203
|
+
var IMF_FIXDATE = /^[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
204
|
+
function retryAfterOf(res) {
|
|
205
|
+
const value = res.headers.get("retry-after")?.trim();
|
|
206
|
+
if (!value) return void 0;
|
|
207
|
+
let seconds;
|
|
208
|
+
if (/^\d+$/.test(value)) {
|
|
209
|
+
seconds = Number(value);
|
|
210
|
+
} else if (IMF_FIXDATE.test(value)) {
|
|
211
|
+
seconds = Math.ceil((Date.parse(value) - Date.now()) / 1e3);
|
|
212
|
+
} else {
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
if (!Number.isFinite(seconds)) return void 0;
|
|
216
|
+
return Math.min(Math.max(0, seconds), MAX_RETRY_AFTER_SECONDS);
|
|
217
|
+
}
|
|
195
218
|
async function apiRequestBinary(ctx, method, path2, options) {
|
|
196
219
|
const res = await sendWithResilience(
|
|
197
220
|
ctx,
|
|
@@ -576,6 +599,31 @@ function createCreditsResource(ctx) {
|
|
|
576
599
|
options
|
|
577
600
|
)
|
|
578
601
|
},
|
|
602
|
+
includedWindows: {
|
|
603
|
+
/**
|
|
604
|
+
* The Included Credit Windows of one or more subscriptions (`subscription`, an id or a list
|
|
605
|
+
* of up to 100), or of a customer (`customer`, by external id) - newest first: what each
|
|
606
|
+
* period Billow granted includes (the whole period, each month of it under a monthly rule,
|
|
607
|
+
* or a trial), how far it was issued, and its `state`. With `current: true`, only each
|
|
608
|
+
* subscription's latest window that has started - what it stands at now. Auto-paginating by
|
|
609
|
+
* cursor: `await` the first page, `for await (…)` every window, or `.listAll()` to collect
|
|
610
|
+
* them.
|
|
611
|
+
*/
|
|
612
|
+
list: (params, options) => {
|
|
613
|
+
const { subscription, ...rest } = params;
|
|
614
|
+
const subscriptions = Array.isArray(subscription) ? subscription.join(",") : subscription;
|
|
615
|
+
return makeCursorListPromise(
|
|
616
|
+
(p) => apiRequest(
|
|
617
|
+
ctx,
|
|
618
|
+
"GET",
|
|
619
|
+
`/v1/credits/included-windows${toQuery({ ...p, subscription: subscriptions })}`,
|
|
620
|
+
void 0,
|
|
621
|
+
options
|
|
622
|
+
),
|
|
623
|
+
rest
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
},
|
|
579
627
|
topUps: {
|
|
580
628
|
/**
|
|
581
629
|
* Buy a Credit Pack for a customer: answers the top-up with `checkoutUrl`, the hosted
|
|
@@ -1183,7 +1231,7 @@ function createSettingsResource(ctx) {
|
|
|
1183
1231
|
},
|
|
1184
1232
|
/**
|
|
1185
1233
|
* Usage settlement grace (hours): defers *collection* of a boundary-adjacent priced
|
|
1186
|
-
* calendar-meter renewal past the tz month boundary until late usage settles
|
|
1234
|
+
* calendar-meter renewal past the tz month boundary until late usage settles - the billed
|
|
1187
1235
|
* windows/amount are unchanged, only the invoice timing shifts. `0` disables it (the default);
|
|
1188
1236
|
* a no-op for any subscription without a priced calendar meter. Cap 72h.
|
|
1189
1237
|
*/
|
|
@@ -1310,7 +1358,7 @@ function createSubscriptionsResource(ctx) {
|
|
|
1310
1358
|
void 0,
|
|
1311
1359
|
options
|
|
1312
1360
|
),
|
|
1313
|
-
/** Cancel
|
|
1361
|
+
/** Cancel - immediately, or at period end with `{ atPeriodEnd: true }`. */
|
|
1314
1362
|
cancel: (id, opts) => apiRequest(
|
|
1315
1363
|
ctx,
|
|
1316
1364
|
"POST",
|
|
@@ -1323,7 +1371,18 @@ function createSubscriptionsResource(ctx) {
|
|
|
1323
1371
|
"POST",
|
|
1324
1372
|
`/v1/subscriptions/${encodeURIComponent(id)}/resume-cancellation`
|
|
1325
1373
|
),
|
|
1374
|
+
/**
|
|
1375
|
+
* Pause an active or trialing subscription: no renewals and no access until it is resumed.
|
|
1376
|
+
* Refused while one of its invoices is still being collected.
|
|
1377
|
+
*/
|
|
1326
1378
|
pause: (id) => apiRequest(ctx, "POST", `/v1/subscriptions/${encodeURIComponent(id)}/pause`),
|
|
1379
|
+
/**
|
|
1380
|
+
* Resume a paused subscription. Paused time is never billed: resumed before its paid period
|
|
1381
|
+
* ends, it carries on and renews at `currentPeriodEnd`; resumed after, a fresh full period
|
|
1382
|
+
* starts now and is charged at once like a renewal, with the ended period's usage (a decline
|
|
1383
|
+
* returns it `past_due`). Usage recorded while paused is never billed. A paused trial resumes
|
|
1384
|
+
* `trialing`. Duplicate calls are safe.
|
|
1385
|
+
*/
|
|
1327
1386
|
resume: (id) => apiRequest(ctx, "POST", `/v1/subscriptions/${encodeURIComponent(id)}/resume`),
|
|
1328
1387
|
/** Apply a coupon to an existing subscription. */
|
|
1329
1388
|
applyCoupon: (id, code) => apiRequest(
|
|
@@ -1332,7 +1391,7 @@ function createSubscriptionsResource(ctx) {
|
|
|
1332
1391
|
`/v1/subscriptions/${encodeURIComponent(id)}/coupon`,
|
|
1333
1392
|
{ code }
|
|
1334
1393
|
),
|
|
1335
|
-
/** Change plan
|
|
1394
|
+
/** Change plan - immediate prorated upgrade, or downgrade scheduled for period end. `productId` accepts the product's id or slug. */
|
|
1336
1395
|
changePlan: (id, productId) => apiRequest(ctx, "POST", `/v1/subscriptions/${encodeURIComponent(id)}/change-plan`, { productId }),
|
|
1337
1396
|
/** Clear a pending downgrade. Duplicate calls are safe. */
|
|
1338
1397
|
clearScheduledPlanChange: (id) => apiRequest(
|
|
@@ -1406,7 +1465,7 @@ function createWebhookEndpointsResource(ctx) {
|
|
|
1406
1465
|
),
|
|
1407
1466
|
/** Delete an endpoint and its delivery history. */
|
|
1408
1467
|
delete: (id) => apiRequest(ctx, "DELETE", `/v1/webhook-endpoints/${encodeURIComponent(id)}`),
|
|
1409
|
-
/** Rotate the signing secret
|
|
1468
|
+
/** Rotate the signing secret - the new plaintext is returned once. */
|
|
1410
1469
|
rotateSecret: (id) => apiRequest(
|
|
1411
1470
|
ctx,
|
|
1412
1471
|
"POST",
|
|
@@ -1445,7 +1504,7 @@ var Billow = class {
|
|
|
1445
1504
|
/** Custom domains for the hosted customer portal (live keys, behind a rollout flag). */
|
|
1446
1505
|
hostedDomains;
|
|
1447
1506
|
/**
|
|
1448
|
-
* Organization settings (Phase D3, F)
|
|
1507
|
+
* Organization settings (Phase D3, F) - the configurable dunning schedule, usage settlement grace,
|
|
1449
1508
|
* and the cross-currency reporting currency + FX-rate registry (ADR-0013).
|
|
1450
1509
|
*/
|
|
1451
1510
|
settings;
|
|
@@ -1473,7 +1532,7 @@ var Billow = class {
|
|
|
1473
1532
|
coupons = {
|
|
1474
1533
|
/** Define a coupon (a reusable discount template). */
|
|
1475
1534
|
create: (input) => this.#request("POST", "/v1/coupons", input),
|
|
1476
|
-
/** List coupons (secret key only
|
|
1535
|
+
/** List coupons (secret key only - enumerates live promo codes). Auto-paginating. */
|
|
1477
1536
|
list: (params = {}, options) => makeListPromise(
|
|
1478
1537
|
(p) => this.#request("GET", `/v1/coupons${toQuery(p)}`, void 0, options),
|
|
1479
1538
|
params
|
|
@@ -1481,13 +1540,13 @@ var Billow = class {
|
|
|
1481
1540
|
/** Deactivate a coupon (existing discounts keep running). */
|
|
1482
1541
|
deactivate: (id) => this.#request("POST", `/v1/coupons/${encodeURIComponent(id)}/deactivate`)
|
|
1483
1542
|
};
|
|
1484
|
-
/** Manage developer webhook endpoints
|
|
1543
|
+
/** Manage developer webhook endpoints - register, rotate secrets, inspect deliveries.
|
|
1485
1544
|
* (To VERIFY incoming deliveries, import `constructEvent` from `@usebillow/sdk/webhooks`.) */
|
|
1486
1545
|
features = {
|
|
1487
1546
|
/** Define a feature (a boolean access gate, or a metered feature with a meter). */
|
|
1488
1547
|
create: (input) => this.#request("POST", "/v1/features", input),
|
|
1489
1548
|
/**
|
|
1490
|
-
* Edit a feature in place: its `name`, and
|
|
1549
|
+
* Edit a feature in place: its `name`, and - for a metered feature - its `meter`
|
|
1491
1550
|
* aggregation. The server refuses a meter change once usage has been recorded (it
|
|
1492
1551
|
* would rewrite billed history), so set the meter right at create time or before you
|
|
1493
1552
|
* start tracking. Returns the updated feature.
|
|
@@ -1544,7 +1603,7 @@ var Billow = class {
|
|
|
1544
1603
|
* choose a credential set and `target` to probe one verify target (Paymob: a
|
|
1545
1604
|
* method); pass `sampleToken` (SANDBOX ONLY) to run a functional sub-test.
|
|
1546
1605
|
* This probe hits the provider's live API (mutates nothing here), so it takes a
|
|
1547
|
-
* per-call {@link CallOptions} for a timeout / cancellation
|
|
1606
|
+
* per-call {@link CallOptions} for a timeout / cancellation - `opts` is spread into
|
|
1548
1607
|
* the body, so `options` stays a separate trailing arg (never merged in).
|
|
1549
1608
|
*/
|
|
1550
1609
|
verify: (provider, opts, options) => this.#request(
|
|
@@ -1571,7 +1630,7 @@ var Billow = class {
|
|
|
1571
1630
|
)
|
|
1572
1631
|
}
|
|
1573
1632
|
};
|
|
1574
|
-
/** The merchant's business identity
|
|
1633
|
+
/** The merchant's business identity - the seller block on documents and email from-name. */
|
|
1575
1634
|
businessProfile = {
|
|
1576
1635
|
/** The stored profile, or null if one was never saved. */
|
|
1577
1636
|
get: (options) => this.#request(
|
|
@@ -1587,11 +1646,11 @@ var Billow = class {
|
|
|
1587
1646
|
};
|
|
1588
1647
|
/**
|
|
1589
1648
|
* Hosted customer surfaces (Phase G, ADR-0014). Mint a portal session for one of
|
|
1590
|
-
* your signed-in users and redirect them to the returned `url`
|
|
1649
|
+
* your signed-in users and redirect them to the returned `url` - the self-serve
|
|
1591
1650
|
* portal, or a `checkout` hand-off for `productId`. The Customer's own calls go
|
|
1592
1651
|
* through {@link BillowPortal}, constructed with the session token.
|
|
1593
1652
|
*/
|
|
1594
|
-
/** Identity of this key's tenant
|
|
1653
|
+
/** Identity of this key's tenant - org, environment, configured currencies. */
|
|
1595
1654
|
me(options) {
|
|
1596
1655
|
return this.#request("GET", "/v1/me", void 0, options);
|
|
1597
1656
|
}
|
|
@@ -1611,14 +1670,14 @@ var Billow = class {
|
|
|
1611
1670
|
// ── The headline verbs ──────────────────────────────────────────────
|
|
1612
1671
|
/**
|
|
1613
1672
|
* Gate access to a feature. `featureId` is the feature slug. Returns
|
|
1614
|
-
* `{ allowed, balance }`
|
|
1673
|
+
* `{ allowed, balance }` - `balance` is `null` for unlimited/boolean features.
|
|
1615
1674
|
*/
|
|
1616
1675
|
check(input, options) {
|
|
1617
1676
|
return this.#request("POST", "/v1/check", input, options);
|
|
1618
1677
|
}
|
|
1619
1678
|
/**
|
|
1620
1679
|
* Record usage of a metered feature (`value` defaults to 1; negative credits
|
|
1621
|
-
* back). Pass `idempotencyKey` to make a retried call a no-op
|
|
1680
|
+
* back). Pass `idempotencyKey` to make a retried call a no-op - which also makes the call
|
|
1622
1681
|
* safe to retry automatically when `maxRetries` is set.
|
|
1623
1682
|
*/
|
|
1624
1683
|
track(input, options) {
|
|
@@ -1655,7 +1714,7 @@ var BillowPublishable = class {
|
|
|
1655
1714
|
this.#ctx = makeContext(publishableKey, opts);
|
|
1656
1715
|
}
|
|
1657
1716
|
products = {
|
|
1658
|
-
/** The active catalog
|
|
1717
|
+
/** The active catalog - products and their prices, for a pricing table. */
|
|
1659
1718
|
list: (options) => apiRequest(
|
|
1660
1719
|
this.#ctx,
|
|
1661
1720
|
"GET",
|
|
@@ -1679,7 +1738,7 @@ var BillowPortal = class {
|
|
|
1679
1738
|
if (!sessionToken) throw new Error("billow: a portal session token is required");
|
|
1680
1739
|
this.#ctx = makeContext(sessionToken, opts);
|
|
1681
1740
|
}
|
|
1682
|
-
/** The portal shell: flow, return URL, merchant brand, and customer identity
|
|
1741
|
+
/** The portal shell: flow, return URL, merchant brand, and customer identity -
|
|
1683
1742
|
* the lightweight payload the hosting app frames every page with, and the
|
|
1684
1743
|
* validate-and-route check at login. */
|
|
1685
1744
|
session(options) {
|