@usebillow/sdk 0.6.0 → 0.8.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.
@@ -218,13 +218,13 @@ interface CreateCreditPackInput {
218
218
  type UpdateCreditPackInput = Partial<CreateCreditPackInput> & {
219
219
  archived?: boolean;
220
220
  };
221
- /** A pack a customer can buy, with its derived price per credit and savings. */
221
+ /** A pack a customer can buy, with its derived price per credit, savings and breakdown. */
222
222
  interface CreditPackListItem {
223
223
  id: string;
224
224
  name: string;
225
225
  credits: string;
226
226
  bonusCredits: string;
227
- /** The catalog Price: what `pricePerCredit` and `savingsBps` are measured on. */
227
+ /** The catalog Price: what `pricePerCredit` is measured on. */
228
228
  price: CreditMoney;
229
229
  /**
230
230
  * The tax a top-up of the pack charges (the Price's treatment, else your project's default):
@@ -243,16 +243,89 @@ interface CreditPackListItem {
243
243
  */
244
244
  pricePerCredit: string;
245
245
  /**
246
- * Basis points cheaper per credit than the currency's base pack (its highest per-credit price),
247
- * rounded down; 0 for the base pack itself.
246
+ * Basis points cheaper per credit before tax than the currency's base pack (its highest pre-tax
247
+ * price per credit), rounded down; 0 for the base pack itself.
248
248
  */
249
249
  savingsBps: number;
250
+ /** Credits received, list value, discount and price paid, to show before payment. */
251
+ breakdown: CreditPackBreakdown;
252
+ }
253
+ /**
254
+ * What a pack gives and what it costs, ready to show before payment, so you never work out a
255
+ * discount yourself. Money is compared before tax, against the same base pack as `savingsBps`, so
256
+ * tax is never a discount: with the pack's `tax`, `listValue - discount + tax = pricePaid`.
257
+ */
258
+ interface CreditPackBreakdown {
259
+ /** Microcredits the buyer receives: `credits` plus `bonusCredits`. */
260
+ creditsReceived: string;
261
+ /**
262
+ * What `creditsReceived` would cost before tax at the base pack's rate (the highest pre-tax
263
+ * price per credit in the currency), rounded down to the minor unit: never below the pack's own
264
+ * pre-tax price, and equal to it for the base pack.
265
+ */
266
+ listValue: CreditMoney;
267
+ /** The money saved: `listValue` less the pack's pre-tax price. Never negative; 0 for the base. */
268
+ discount: CreditMoney;
269
+ /** What a top-up of the pack charges, tax included: the same as `total`. */
270
+ pricePaid: CreditMoney;
250
271
  }
251
272
  /** The packs a customer can buy in one currency, cheapest first. */
252
273
  interface CreditPacks {
253
274
  currency: string;
254
275
  data: CreditPackListItem[];
255
276
  }
277
+ /**
278
+ * How an Included Credit Rule allocates its credits: `billing_period` - the whole period is one
279
+ * window; `month` - each month of the period is its own window, refilled at its start and expiring
280
+ * at its end, with no rollover (only on a Price billed for longer than a month).
281
+ */
282
+ type CreditAllocationInterval = "billing_period" | "month";
283
+ /**
284
+ * An Included Credit Rule: the credits a subscription on a recurring base Price includes for each
285
+ * period Billow grants it. At most one live (not archived) rule per Price. A change takes effect
286
+ * from the next period granted, never on one already granted.
287
+ */
288
+ interface CreditIncludedRule {
289
+ id: string;
290
+ /** The recurring base Price it applies to; never changes. */
291
+ priceId: string;
292
+ /** Microcredits each window includes: per billing period, or per month under `month`. */
293
+ credits: string;
294
+ /** Whether `credits` and `trialCredits` are multiplied by the base item's quantity (per seat). */
295
+ perUnit: boolean;
296
+ /** Microcredits a trial includes, as one window; "0" for none. */
297
+ trialCredits: string;
298
+ allocationInterval: CreditAllocationInterval;
299
+ /** An archived rule includes nothing for periods granted after it was archived. */
300
+ archived: boolean;
301
+ createdAt: string;
302
+ updatedAt: string;
303
+ }
304
+ /**
305
+ * Configure an Included Credit Rule on a recurring base Price (`fixed_recurring` or `licensed`, of
306
+ * a product that is not an add-on).
307
+ */
308
+ interface CreateCreditIncludedRuleInput {
309
+ priceId: string;
310
+ /** Whole microcredits each window includes, as a decimal string; positive. */
311
+ credits: string;
312
+ /**
313
+ * Required: `true` multiplies the credits by the base item's quantity (per-seat credits on a
314
+ * `licensed` Price); `false` includes them once per subscription whatever the quantity.
315
+ */
316
+ perUnit: boolean;
317
+ /** Whole microcredits a trial includes, as a decimal string; omit for none. */
318
+ trialCredits?: string;
319
+ /** `billing_period` when omitted; `month` only on a Price billed for longer than a month. */
320
+ allocationInterval?: CreditAllocationInterval;
321
+ }
322
+ /**
323
+ * Edit an Included Credit Rule: any of its terms, or `archived` (`false` brings it back while its
324
+ * Price has no other live rule). Its Price never changes.
325
+ */
326
+ type UpdateCreditIncludedRuleInput = Partial<Omit<CreateCreditIncludedRuleInput, "priceId">> & {
327
+ archived?: boolean;
328
+ };
256
329
  /**
257
330
  * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
258
331
  * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
@@ -354,4 +427,4 @@ interface HostedDomainDisabledData extends HostedDomainEventBase {
354
427
  reason: Extract<HostedDomainStatusReason, "dns_lost" | "reassigned" | "entitlement_lapsed" | "suspended">;
355
428
  }
356
429
 
357
- export type { HostedDomainStatusReason as A, CreditGrantKind as C, 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, CreateCreditTopUpInput as l, CreditTopUpRequestResult as m, CreditTopUpListParams as n, CreditBalance as o, CreditLedgerEntry as p, CreditUsageParams as q, CreditUsage as r, CreditAccountStatus as s, CreditMoney as t, CreditPackListItem as u, CreditTopUpStatus as v, CreditTransactionType as w, CreditUsageGroupBy as x, HostedDomainEventBase as y, HostedDomainStatus as z };
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 };
@@ -218,13 +218,13 @@ interface CreateCreditPackInput {
218
218
  type UpdateCreditPackInput = Partial<CreateCreditPackInput> & {
219
219
  archived?: boolean;
220
220
  };
221
- /** A pack a customer can buy, with its derived price per credit and savings. */
221
+ /** A pack a customer can buy, with its derived price per credit, savings and breakdown. */
222
222
  interface CreditPackListItem {
223
223
  id: string;
224
224
  name: string;
225
225
  credits: string;
226
226
  bonusCredits: string;
227
- /** The catalog Price: what `pricePerCredit` and `savingsBps` are measured on. */
227
+ /** The catalog Price: what `pricePerCredit` is measured on. */
228
228
  price: CreditMoney;
229
229
  /**
230
230
  * The tax a top-up of the pack charges (the Price's treatment, else your project's default):
@@ -243,16 +243,89 @@ interface CreditPackListItem {
243
243
  */
244
244
  pricePerCredit: string;
245
245
  /**
246
- * Basis points cheaper per credit than the currency's base pack (its highest per-credit price),
247
- * rounded down; 0 for the base pack itself.
246
+ * Basis points cheaper per credit before tax than the currency's base pack (its highest pre-tax
247
+ * price per credit), rounded down; 0 for the base pack itself.
248
248
  */
249
249
  savingsBps: number;
250
+ /** Credits received, list value, discount and price paid, to show before payment. */
251
+ breakdown: CreditPackBreakdown;
252
+ }
253
+ /**
254
+ * What a pack gives and what it costs, ready to show before payment, so you never work out a
255
+ * discount yourself. Money is compared before tax, against the same base pack as `savingsBps`, so
256
+ * tax is never a discount: with the pack's `tax`, `listValue - discount + tax = pricePaid`.
257
+ */
258
+ interface CreditPackBreakdown {
259
+ /** Microcredits the buyer receives: `credits` plus `bonusCredits`. */
260
+ creditsReceived: string;
261
+ /**
262
+ * What `creditsReceived` would cost before tax at the base pack's rate (the highest pre-tax
263
+ * price per credit in the currency), rounded down to the minor unit: never below the pack's own
264
+ * pre-tax price, and equal to it for the base pack.
265
+ */
266
+ listValue: CreditMoney;
267
+ /** The money saved: `listValue` less the pack's pre-tax price. Never negative; 0 for the base. */
268
+ discount: CreditMoney;
269
+ /** What a top-up of the pack charges, tax included: the same as `total`. */
270
+ pricePaid: CreditMoney;
250
271
  }
251
272
  /** The packs a customer can buy in one currency, cheapest first. */
252
273
  interface CreditPacks {
253
274
  currency: string;
254
275
  data: CreditPackListItem[];
255
276
  }
277
+ /**
278
+ * How an Included Credit Rule allocates its credits: `billing_period` - the whole period is one
279
+ * window; `month` - each month of the period is its own window, refilled at its start and expiring
280
+ * at its end, with no rollover (only on a Price billed for longer than a month).
281
+ */
282
+ type CreditAllocationInterval = "billing_period" | "month";
283
+ /**
284
+ * An Included Credit Rule: the credits a subscription on a recurring base Price includes for each
285
+ * period Billow grants it. At most one live (not archived) rule per Price. A change takes effect
286
+ * from the next period granted, never on one already granted.
287
+ */
288
+ interface CreditIncludedRule {
289
+ id: string;
290
+ /** The recurring base Price it applies to; never changes. */
291
+ priceId: string;
292
+ /** Microcredits each window includes: per billing period, or per month under `month`. */
293
+ credits: string;
294
+ /** Whether `credits` and `trialCredits` are multiplied by the base item's quantity (per seat). */
295
+ perUnit: boolean;
296
+ /** Microcredits a trial includes, as one window; "0" for none. */
297
+ trialCredits: string;
298
+ allocationInterval: CreditAllocationInterval;
299
+ /** An archived rule includes nothing for periods granted after it was archived. */
300
+ archived: boolean;
301
+ createdAt: string;
302
+ updatedAt: string;
303
+ }
304
+ /**
305
+ * Configure an Included Credit Rule on a recurring base Price (`fixed_recurring` or `licensed`, of
306
+ * a product that is not an add-on).
307
+ */
308
+ interface CreateCreditIncludedRuleInput {
309
+ priceId: string;
310
+ /** Whole microcredits each window includes, as a decimal string; positive. */
311
+ credits: string;
312
+ /**
313
+ * Required: `true` multiplies the credits by the base item's quantity (per-seat credits on a
314
+ * `licensed` Price); `false` includes them once per subscription whatever the quantity.
315
+ */
316
+ perUnit: boolean;
317
+ /** Whole microcredits a trial includes, as a decimal string; omit for none. */
318
+ trialCredits?: string;
319
+ /** `billing_period` when omitted; `month` only on a Price billed for longer than a month. */
320
+ allocationInterval?: CreditAllocationInterval;
321
+ }
322
+ /**
323
+ * Edit an Included Credit Rule: any of its terms, or `archived` (`false` brings it back while its
324
+ * Price has no other live rule). Its Price never changes.
325
+ */
326
+ type UpdateCreditIncludedRuleInput = Partial<Omit<CreateCreditIncludedRuleInput, "priceId">> & {
327
+ archived?: boolean;
328
+ };
256
329
  /**
257
330
  * A top-up's state: `pending` until its payment settles; `succeeded` (credits granted) or
258
331
  * `failed` (a later payment on the same checkout still succeeds it); `unfulfilled` - paid after
@@ -354,4 +427,4 @@ interface HostedDomainDisabledData extends HostedDomainEventBase {
354
427
  reason: Extract<HostedDomainStatusReason, "dns_lost" | "reassigned" | "entitlement_lapsed" | "suspended">;
355
428
  }
356
429
 
357
- export type { HostedDomainStatusReason as A, CreditGrantKind as C, 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, CreateCreditTopUpInput as l, CreditTopUpRequestResult as m, CreditTopUpListParams as n, CreditBalance as o, CreditLedgerEntry as p, CreditUsageParams as q, CreditUsage as r, CreditAccountStatus as s, CreditMoney as t, CreditPackListItem as u, CreditTopUpStatus as v, CreditTransactionType as w, CreditUsageGroupBy as x, HostedDomainEventBase as y, HostedDomainStatus as z };
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 };
package/dist/index.cjs CHANGED
@@ -528,6 +528,54 @@ function createCreditsResource(ctx) {
528
528
  options
529
529
  )
530
530
  },
531
+ includedRules: {
532
+ /**
533
+ * Configure an Included Credit Rule on a recurring base Price: the credits a subscription on
534
+ * it includes for each period Billow grants it - per billing period, or per month of a Price
535
+ * billed for longer than a month - and for a trial. Configuration, so no idempotency key:
536
+ * a second live rule for the same Price throws `conflict` (409,
537
+ * `details.reason: "included_rule_exists"`, with the live rule's `ruleId`). Throws
538
+ * `validation_error` (422) with `details.reason: "not_a_base_price"` for a Price that is not
539
+ * a recurring base Price, or `"allocation_not_shorter_than_billing"` for a monthly
540
+ * allocation on a Price not billed for longer than a month.
541
+ */
542
+ create: (input, options) => apiRequest(ctx, "POST", "/v1/credits/included-rules", input, options),
543
+ /** A rule, archived or not. */
544
+ get: (ruleId, options) => apiRequest(
545
+ ctx,
546
+ "GET",
547
+ `/v1/credits/included-rules/${encodeURIComponent(ruleId)}`,
548
+ void 0,
549
+ options
550
+ ),
551
+ /**
552
+ * Every rule, archived ones included, newest first. Auto-paginating by cursor: `await` the
553
+ * first page, `for await (…)` every rule, or `.listAll()` to collect them.
554
+ */
555
+ list: (params = {}, options) => makeCursorListPromise(
556
+ (p) => apiRequest(
557
+ ctx,
558
+ "GET",
559
+ `/v1/credits/included-rules${toQuery(p)}`,
560
+ void 0,
561
+ options
562
+ ),
563
+ params
564
+ ),
565
+ /**
566
+ * Edit a rule's credits, per-seat choice, trial credits or allocation interval, or archive
567
+ * it (`archived: false` brings it back). It takes effect from the next period granted;
568
+ * periods already granted keep what they were granted. A rule left live is judged against
569
+ * its Price as it is now, with the same errors as `create`.
570
+ */
571
+ update: (ruleId, input, options) => apiRequest(
572
+ ctx,
573
+ "PATCH",
574
+ `/v1/credits/included-rules/${encodeURIComponent(ruleId)}`,
575
+ input,
576
+ options
577
+ )
578
+ },
531
579
  topUps: {
532
580
  /**
533
581
  * Buy a Credit Pack for a customer: answers the top-up with `checkoutUrl`, the hosted
@@ -708,6 +756,24 @@ function createCreditsResource(ctx) {
708
756
  void 0,
709
757
  options
710
758
  ),
759
+ /**
760
+ * Your project's reservations, oldest first, optionally of one `status`, one `customer` (by
761
+ * external id), or protected more than `protectedLongerThan` seconds ago - with
762
+ * `{ status: "protected", protectedLongerThan: page.protectedHoldMaxSeconds }`, the paid
763
+ * operations waiting past your maximum for a decision (commit or release each). Every page
764
+ * carries `protectedHoldMaxSeconds`. Auto-paginating by cursor: `await` the first page,
765
+ * `for await (…)` every reservation, or `.listAll()` to collect them.
766
+ */
767
+ list: (params = {}, options) => makeCursorListPromise(
768
+ (p) => apiRequest(
769
+ ctx,
770
+ "GET",
771
+ `/v1/credits/reservations${toQuery(p)}`,
772
+ void 0,
773
+ options
774
+ ),
775
+ params
776
+ ),
711
777
  /**
712
778
  * A customer's reservation (by external id) made with `operationKey` - how to find one whose
713
779
  * reply was lost. Throws `not_found` (404) when there is none.
@@ -1619,6 +1685,21 @@ var BillowPortal = class {
1619
1685
  session(options) {
1620
1686
  return apiRequest(this.#ctx, "GET", "/portal/session", void 0, options);
1621
1687
  }
1688
+ /**
1689
+ * The single-use entry exchange (ADR-0039): on a client built with a minted link's entry
1690
+ * token, trade it for the session token to use from now on. Succeeds once per link, and
1691
+ * afterwards only for the browser presenting that exchange's `sessionToken`; anything else is
1692
+ * a 401. For a hosted surface; an integrator's own surface may keep using the entry token.
1693
+ */
1694
+ exchange(input, options) {
1695
+ return apiRequest(
1696
+ this.#ctx,
1697
+ "POST",
1698
+ "/portal/session/exchange",
1699
+ input,
1700
+ options
1701
+ );
1702
+ }
1622
1703
  /** The self-serve home payload: identity + subscriptions + usage + saved cards. */
1623
1704
  me(options) {
1624
1705
  return apiRequest(this.#ctx, "GET", "/portal/me", void 0, options);
@@ -1635,6 +1716,14 @@ var BillowPortal = class {
1635
1716
  ),
1636
1717
  params
1637
1718
  ),
1719
+ /** One of the Customer's invoices, in the list's shape. */
1720
+ get: (id, options) => apiRequest(
1721
+ this.#ctx,
1722
+ "GET",
1723
+ `/portal/invoices/${encodeURIComponent(id)}`,
1724
+ void 0,
1725
+ options
1726
+ ),
1638
1727
  /** Open or resume checkout for this customer's outstanding invoice. */
1639
1728
  pay: (id, input = {}, options) => apiRequest(
1640
1729
  this.#ctx,