@voltro/plugin-billing 0.89.1 → 0.90.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,9 +1,9 @@
1
1
  import { BillingError as e } from "./types.js";
2
2
  import { exactProviderIdentifier as t } from "./providerIdentity.js";
3
3
  import { Effect as n } from "effect";
4
- import { canonicalJson as r } from "@voltro/protocol";
5
- import { and as i, eq as a, gt as o } from "@voltro/database";
6
- import { createHash as s } from "node:crypto";
4
+ import { and as r, eq as i, gt as a } from "@voltro/database";
5
+ import { createHash as o } from "node:crypto";
6
+ import { canonicalJson as s } from "@voltro/protocol";
7
7
  // src/custodyInventory.ts
8
8
  var c = Object.freeze([
9
9
  "_voltro_billing_customer_accounts",
@@ -22,40 +22,74 @@ var c = Object.freeze([
22
22
  "_voltro_billing_usage_events",
23
23
  "_voltro_billing_checkout_operations",
24
24
  "_voltro_billing_close_operations",
25
- "_voltro_billing_dunning_notices"
26
- ]), l = (r, i) => n.tryPromise({
25
+ "_voltro_billing_dunning_notices",
26
+ "_voltro_billing_subscription_write_heads",
27
+ "_voltro_billing_subscription_writes",
28
+ "_voltro_billing_invoice_payment_heads"
29
+ ]), l = Object.freeze(["_voltro_billing_invoice_history_scan_accounts"]), u = (r, i) => n.tryPromise({
27
30
  try: async () => {
28
31
  let e = i.tenantId, n = i.pageSize ?? 200, a = i.maxRowsPerTable ?? 5e3;
29
- if (!t(e) || e.length > 191 || !e.isWellFormed() || !Number.isSafeInteger(n) || n < 1 || n > 500 || !Number.isSafeInteger(a) || a < 1 || a > 5e4) throw v("Inventory tenant and bounds must be valid.", !1);
30
- if (r.integrityQuery === void 0) throw v("Complete native integrity reads are required.", !1);
32
+ if (!t(e) || e.length > 191 || !e.isWellFormed() || !Number.isSafeInteger(n) || n < 1 || n > 500 || !Number.isSafeInteger(a) || a < 1 || a > 5e4) throw x("Inventory tenant and bounds must be valid.", !1);
33
+ if (r.integrityQuery === void 0) throw x("Complete native integrity reads are required.", !1);
31
34
  let o = {
32
35
  format: "voltro.billing-custody-inventory.v1",
33
36
  tenantId: e,
34
37
  tables: await r.transactional(async (t) => {
35
- if (t.integrityQuery === void 0) throw v("Transactional native integrity reads are required.", !1);
36
- let r = await u(t, e, n, a), i = await u(t, e, n, a);
37
- if (g(r) !== g(i)) throw v("Billing state changed during inventory. Quiesce writers and retry.", !0);
38
+ if (t.integrityQuery === void 0) throw x("Transactional native integrity reads are required.", !1);
39
+ let r = await p(t, c, f(e), n, a), i = await p(t, c, f(e), n, a);
40
+ if (y(r) !== y(i)) throw x("Billing state changed during inventory. Quiesce writers and retry.", !0);
38
41
  return i;
39
42
  })
40
43
  };
41
44
  return Object.freeze({
42
45
  ...o,
43
- digest: g(o),
46
+ digest: y(o),
44
47
  observedAt: /* @__PURE__ */ new Date(),
45
48
  purpose: "review-only"
46
49
  });
47
50
  },
48
- catch: (t) => t instanceof e ? t : v("The native billing inventory could not be completed.", !0)
49
- }), u = async (e, n, s, l) => {
50
- let u = e.integrityQuery;
51
- if (u === void 0) throw v("Complete native integrity reads are required.", !1);
52
- let y = [], b = 0;
53
- for (let x of c) {
54
- let c = [], S = /* @__PURE__ */ new Set(), C;
51
+ catch: (t) => t instanceof e ? t : x("The native billing inventory could not be completed.", !0)
52
+ }), d = (a, o) => n.tryPromise({
53
+ try: async () => {
54
+ let e = o.provider, n = o.providerAccountId, s = o.livemode, c = o.pageSize ?? 200, u = o.maxRowsPerTable ?? 5e3;
55
+ if (!t(e) || e.length > 64 || !e.isWellFormed() || !t(n) || n.length > 191 || !n.isWellFormed() || typeof s != "boolean" || !Number.isSafeInteger(c) || c < 1 || c > 500 || !Number.isSafeInteger(u) || u < 1 || u > 5e4) throw x("Inventory account and bounds must be valid.", !1);
56
+ if (a.integrityQuery === void 0) throw x("Complete native integrity reads are required.", !1);
57
+ let d = {
58
+ predicate: r(i("provider", e), i("providerAccountId", n), i("livemode", +!!s)),
59
+ owns: (t) => t.provider === e && t.providerAccountId === n && t.livemode === +!!s
60
+ }, f = {
61
+ format: "voltro.billing-account-custody-inventory.v1",
62
+ provider: e,
63
+ providerAccountId: n,
64
+ livemode: s,
65
+ tables: await a.transactional(async (e) => {
66
+ if (e.integrityQuery === void 0) throw x("Transactional native integrity reads are required.", !1);
67
+ let t = await p(e, l, d, c, u), n = await p(e, l, d, c, u);
68
+ if (y(t) !== y(n)) throw x("Billing state changed during inventory. Quiesce writers and retry.", !0);
69
+ return n;
70
+ })
71
+ };
72
+ return Object.freeze({
73
+ ...f,
74
+ digest: y(f),
75
+ observedAt: /* @__PURE__ */ new Date(),
76
+ purpose: "review-only"
77
+ });
78
+ },
79
+ catch: (t) => t instanceof e ? t : x("The native billing account inventory could not be completed.", !0)
80
+ }), f = (e) => ({
81
+ predicate: i("tenantId", e),
82
+ owns: (t) => t.tenantId === e
83
+ }), p = async (e, n, i, o, c) => {
84
+ let l = e.integrityQuery;
85
+ if (l === void 0) throw x("Complete native integrity reads are required.", !1);
86
+ let u = [], d = 0;
87
+ for (let f of n) {
88
+ let n = [], p = /* @__PURE__ */ new Set(), S;
55
89
  for (;;) {
56
- let g = Math.min(s, l - c.length + 1), y = {
57
- table: x,
58
- predicate: C === void 0 ? a("tenantId", n) : i(a("tenantId", n), o("id", C)),
90
+ let u = Math.min(o, c - n.length + 1), y = {
91
+ table: f,
92
+ predicate: S === void 0 ? i.predicate : r(i.predicate, a("id", S)),
59
93
  crossTenant: !0,
60
94
  includeDeleted: !0,
61
95
  includeExpired: !0,
@@ -63,92 +97,94 @@ var c = Object.freeze([
63
97
  column: "id",
64
98
  direction: "asc"
65
99
  }],
66
- take: g,
100
+ take: u,
67
101
  skip: void 0,
68
102
  projection: void 0
69
- }, w = await u.call(e, y);
70
- if (!Array.isArray(w) || w.length > g) throw v(`Invalid inventory page for ${x}.`, !1);
71
- for (let e of w) {
72
- let i = h(e);
73
- if (!m(i)) throw v(`Invalid inventory row for ${x}.`, !1);
74
- let a = i.id;
75
- if (!t(a) || i.tenantId !== n || S.has(a)) throw v(`Invalid inventory identity for ${x}.`, !1);
76
- if (c.length === l) throw v(`Inventory bound exceeded for ${x}; no partial inventory is returned.`, !1);
77
- S.add(a);
103
+ }, C = await l.call(e, y);
104
+ if (!Array.isArray(C) || C.length > u) throw x(`Invalid inventory page for ${f}.`, !1);
105
+ for (let e of C) {
106
+ let r = v(e);
107
+ if (!_(r)) throw x(`Invalid inventory row for ${f}.`, !1);
108
+ let a = r.id;
109
+ if (!t(a) || !i.owns(r) || p.has(a)) throw x(`Invalid inventory identity for ${f}.`, !1);
110
+ if (n.length === c) throw x(`Inventory bound exceeded for ${f}; no partial inventory is returned.`, !1);
111
+ p.add(a);
78
112
  let o = {};
79
- for (let e of d) {
80
- let n = i[e];
113
+ for (let e of m) {
114
+ let n = r[e];
81
115
  if (n != null) {
82
- if (!t(n)) throw v(`Invalid inventory reference for ${x}.`, !1);
116
+ if (!t(n)) throw x(`Invalid inventory reference for ${f}.`, !1);
83
117
  o[e] = n;
84
118
  }
85
119
  }
86
- let s = r(i), u = Buffer.byteLength(s, "utf8");
87
- if (b += u, u > f || b > p) throw v("Native billing inventory byte bound exceeded; no partial inventory is returned.", !1);
88
- c.push(Object.freeze({
120
+ let l = s(r), u = Buffer.byteLength(l, "utf8");
121
+ if (d += u, u > h || d > g) throw x("Native billing inventory byte bound exceeded; no partial inventory is returned.", !1);
122
+ n.push(Object.freeze({
89
123
  id: a,
90
- digest: _(s),
124
+ digest: b(l),
91
125
  references: Object.freeze(o)
92
- })), C = a;
126
+ })), S = a;
93
127
  }
94
- if (w.length < g) break;
128
+ if (C.length < u) break;
95
129
  }
96
- c.sort((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), y.push(Object.freeze({
97
- tableName: x,
98
- rowCount: c.length,
99
- digest: g(c),
100
- rows: Object.freeze(c)
130
+ n.sort((e, t) => e.id < t.id ? -1 : +(e.id > t.id)), u.push(Object.freeze({
131
+ tableName: f,
132
+ rowCount: n.length,
133
+ digest: y(n),
134
+ rows: Object.freeze(n)
101
135
  }));
102
136
  }
103
- return Object.freeze(y);
104
- }, d = [
137
+ return Object.freeze(u);
138
+ }, m = [
105
139
  "provider",
106
140
  "providerAccountId",
107
141
  "providerCustomerId",
108
142
  "providerSubscriptionId",
109
- "providerInvoiceId"
110
- ], f = 4194304, p = 67108864, m = (e) => typeof e == "object" && !!e && !Array.isArray(e), h = (e, t = /* @__PURE__ */ new Set(), n = 0) => {
111
- if (n > 64) throw v("Native inventory value exceeds supported depth.", !1);
143
+ "providerInvoiceId",
144
+ "afterCustodyId",
145
+ "cycleEndCustodyId"
146
+ ], h = 4194304, g = 67108864, _ = (e) => typeof e == "object" && !!e && !Array.isArray(e), v = (e, t = /* @__PURE__ */ new Set(), n = 0) => {
147
+ if (n > 64) throw x("Native inventory value exceeds supported depth.", !1);
112
148
  if (e === null || typeof e == "boolean") return e;
113
149
  if (typeof e == "string") {
114
- if (!e.isWellFormed()) throw v("Native inventory contains malformed text.", !1);
150
+ if (!e.isWellFormed()) throw x("Native inventory contains malformed text.", !1);
115
151
  return e;
116
152
  }
117
153
  if (typeof e == "number") {
118
- if (!Number.isFinite(e) || !Number.isSafeInteger(e) && Math.abs(e) > 2 ** 53 - 1 || Object.is(e, -0)) throw v("Native inventory numeric evidence cannot be encoded exactly.", !1);
154
+ if (!Number.isFinite(e) || !Number.isSafeInteger(e) && Math.abs(e) > 2 ** 53 - 1 || Object.is(e, -0)) throw x("Native inventory numeric evidence cannot be encoded exactly.", !1);
119
155
  return e;
120
156
  }
121
157
  if (e instanceof Date) {
122
- if (!Number.isFinite(e.getTime())) throw v("Native inventory contains an invalid date.", !1);
158
+ if (!Number.isFinite(e.getTime())) throw x("Native inventory contains an invalid date.", !1);
123
159
  return e.toISOString();
124
160
  }
125
- if (typeof e != "object" || t.has(e)) throw v("Native inventory contains a non-JSON value.", !1);
161
+ if (typeof e != "object" || t.has(e)) throw x("Native inventory contains a non-JSON value.", !1);
126
162
  let r = Object.getPrototypeOf(e);
127
- if (!Array.isArray(e) && r !== Object.prototype && r !== null) throw v("Native inventory value has an unsupported prototype.", !1);
128
- if (Object.getOwnPropertySymbols(e).length !== 0) throw v("Native inventory contains unsupported symbol fields.", !1);
163
+ if (!Array.isArray(e) && r !== Object.prototype && r !== null) throw x("Native inventory value has an unsupported prototype.", !1);
164
+ if (Object.getOwnPropertySymbols(e).length !== 0) throw x("Native inventory contains unsupported symbol fields.", !1);
129
165
  t.add(e);
130
166
  try {
131
167
  if (Array.isArray(e)) {
132
- if (Object.keys(e).length !== e.length || Object.getOwnPropertyNames(e).length !== e.length + 1) throw v("Native inventory contains a sparse or extended array.", !1);
168
+ if (Object.keys(e).length !== e.length || Object.getOwnPropertyNames(e).length !== e.length + 1) throw x("Native inventory contains a sparse or extended array.", !1);
133
169
  return Array.from({ length: e.length }, (r, i) => {
134
170
  let a = Object.getOwnPropertyDescriptor(e, String(i));
135
- if (a === void 0 || !("value" in a)) throw v("Native inventory contains a sparse or accessor array.", !1);
136
- return h(a.value, t, n + 1);
171
+ if (a === void 0 || !("value" in a)) throw x("Native inventory contains a sparse or accessor array.", !1);
172
+ return v(a.value, t, n + 1);
137
173
  });
138
174
  }
139
- if (Object.getOwnPropertyNames(e).length !== Object.keys(e).length) throw v("Native inventory contains non-enumerable fields.", !1);
175
+ if (Object.getOwnPropertyNames(e).length !== Object.keys(e).length) throw x("Native inventory contains non-enumerable fields.", !1);
140
176
  return Object.fromEntries(Object.keys(e).map((r) => {
141
- if (!r.isWellFormed()) throw v("Native inventory contains a malformed field.", !1);
177
+ if (!r.isWellFormed()) throw x("Native inventory contains a malformed field.", !1);
142
178
  let i = Object.getOwnPropertyDescriptor(e, r);
143
- if (i === void 0 || !("value" in i)) throw v("Native inventory contains an accessor field.", !1);
144
- return [r, h(i.value, t, n + 1)];
179
+ if (i === void 0 || !("value" in i)) throw x("Native inventory contains an accessor field.", !1);
180
+ return [r, v(i.value, t, n + 1)];
145
181
  }));
146
182
  } finally {
147
183
  t.delete(e);
148
184
  }
149
- }, g = (e) => _(r(e)), _ = (e) => s("sha256").update(e, "utf8").digest("hex"), v = (t, n) => new e({
185
+ }, y = (e) => b(s(e)), b = (e) => o("sha256").update(e, "utf8").digest("hex"), x = (t, n) => new e({
150
186
  source: "billingCustodyInventory",
151
187
  message: t,
152
188
  transient: n
153
189
  });
154
- export { c as BILLING_CUSTODY_INVENTORY_TABLES, l as inspectBillingCustody };
190
+ export { l as BILLING_ACCOUNT_CUSTODY_INVENTORY_TABLES, c as BILLING_CUSTODY_INVENTORY_TABLES, d as inspectBillingAccountCustody, u as inspectBillingCustody };
package/dist/dunning.js CHANGED
@@ -143,12 +143,20 @@ var l = "_voltro_billing_dunning_notices", u = o(l, {
143
143
  html: `<p>${a} Your subscription stays active until ${i}.</p>${n}`,
144
144
  text: `${a} Your subscription stays active until ${i}.\n\n${r}`
145
145
  };
146
- }, w = (e) => (t) => t.to === null ? n.void : e.send({
147
- to: t.to,
148
- subject: t.subject,
149
- html: t.html,
150
- text: t.text
151
- }).pipe(n.asVoid), T = (e, t, n) => `${e}\u0000${t}\u0000${n}`, E = () => {
146
+ }, w = (e, t = {}) => (r) => {
147
+ let i = r.to;
148
+ return i === null ? n.void : (t.compose === void 0 ? n.succeed({
149
+ subject: r.subject,
150
+ html: r.html,
151
+ text: r.text
152
+ }) : t.compose(r)).pipe(n.flatMap((n) => e.send({
153
+ to: i,
154
+ subject: n.subject,
155
+ html: n.html,
156
+ text: n.text,
157
+ ...t.tags === void 0 ? {} : { tags: t.tags }
158
+ })), n.asVoid);
159
+ }, T = (e, t, n) => `${e}\u0000${t}\u0000${n}`, E = () => {
152
160
  let e = /* @__PURE__ */ new Map();
153
161
  return {
154
162
  claim: (t, r, i, a) => n.sync(() => {
@@ -14,6 +14,7 @@ var f = 864e5, p = (t) => new e({
14
14
  let e = structuredClone(l);
15
15
  if (e.rejected) throw p("The provider event could not be normalized and requires reconciliation.");
16
16
  if (typeof e.id != "string" || !e.id || e.id.trim() !== e.id || e.createdAt !== null && (!(e.createdAt instanceof Date) || !Number.isFinite(e.createdAt.getTime()))) throw p("The verified provider delivery requires exact identity and time evidence.");
17
+ if (e.event === null && e.providerCustomerId === null) return "processed";
17
18
  let d = m.receipts?.store() ?? h;
18
19
  if (g === void 0) {
19
20
  let e = m.provider.fetchAccountIdentity?.bind(m.provider);
@@ -39,12 +40,20 @@ var f = 864e5, p = (t) => new e({
39
40
  if (!await d.renew(x.claim, Date.now())) throw p("The provider delivery claim changed before processing.");
40
41
  let t = e.event, n = e.providerCustomerId ?? (t !== null && "providerCustomerId" in t ? t.providerCustomerId : null);
41
42
  if (t !== null && "providerCustomerId" in t && e.providerCustomerId !== null && t.providerCustomerId !== e.providerCustomerId) throw p("The provider delivery has inconsistent customer identities.");
42
- let i = t?._tag === "invoicePaid" || t?._tag === "invoicePaymentFailed", a = n !== null && t?._tag !== "customerUnlinked" && !i, o = [];
43
- if (t !== null && (!a || t._tag !== "subscriptionUpserted" && t._tag !== "subscriptionCanceled" && t._tag !== "customerLinked") && o.push(await r.runPromise(m.service.applyEvent(t))), a) {
44
- let e = await r.runPromise(m.service.syncCustomer(n, t !== null && "tenantId" in t && typeof t.tenantId == "string" ? t.tenantId : void 0));
45
- o.push(...e.events);
43
+ let i = [];
44
+ if (t?._tag === "invoicePaymentsCorrected") i.push(...await r.runPromise(m.service.reconcilePaymentCorrection({
45
+ ...v,
46
+ providerCustomerId: t.providerCustomerId,
47
+ providerEventId: e.id
48
+ })));
49
+ else {
50
+ let e = t?._tag === "invoicePaid" || t?._tag === "invoicePaymentFailed", a = n !== null && t?._tag !== "customerUnlinked" && !e;
51
+ if (t !== null && (!a || t._tag !== "subscriptionUpserted" && t._tag !== "subscriptionCanceled" && t._tag !== "customerLinked") && i.push(await r.runPromise(m.service.applyEvent(t))), a) {
52
+ let e = await r.runPromise(m.service.syncCustomer(n, t !== null && "tenantId" in t && typeof t.tenantId == "string" ? t.tenantId : void 0));
53
+ i.push(...e.events);
54
+ }
46
55
  }
47
- for (let t of o) {
56
+ for (let t of i) {
48
57
  if (!await d.renew(x.claim, Date.now())) throw p("The provider delivery claim changed before callback dispatch.");
49
58
  let n = m.onEvent?.[t._tag];
50
59
  n !== void 0 && await r.runPromise(n(t, Object.freeze({
@@ -0,0 +1,94 @@
1
+ import { BillingError as e } from "./types.js";
2
+ import { Effect as t } from "effect";
3
+ // src/historicalUsage.ts
4
+ var n = /^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,12})?$/, r = (e, t) => e !== null && n.test(e) ? e : t !== null && Number.isSafeInteger(t) && t >= 0 ? String(t) : null, i = (e) => Number(e) === 0, a = (e, t, n) => {
5
+ if (!Number.isSafeInteger(t) || !Number.isSafeInteger(n) || t < 0 || n <= t) return null;
6
+ if (e.tiers === null) {
7
+ let i = r(null, e.unitAmountMinor);
8
+ return i === null ? null : [{
9
+ quantity: n - t,
10
+ unitAmountDecimal: i
11
+ }];
12
+ }
13
+ if (e.tiersMode !== "graduated") return null;
14
+ let i = [], a = 0;
15
+ for (let o of e.tiers) {
16
+ if (o.flatAmountMinor !== null && o.flatAmountMinor !== 0) return null;
17
+ let e = o.upTo ?? Infinity;
18
+ if (e <= a) return null;
19
+ let s = Math.min(n, e) - Math.max(t, a);
20
+ if (s > 0) {
21
+ let e = r(o.unitAmountDecimal, o.unitAmountMinor);
22
+ if (e === null) return null;
23
+ i.push({
24
+ quantity: s,
25
+ unitAmountDecimal: e
26
+ });
27
+ }
28
+ if (o.upTo === null) return i;
29
+ a = e;
30
+ }
31
+ return null;
32
+ }, o = (e, t, n) => {
33
+ let r = e.find((e) => e.id === t);
34
+ if (r === void 0) return null;
35
+ let i = null;
36
+ for (let t of e) t.productId === r.productId && t.currency === r.currency && t.usageType === r.usageType && t.interval === r.interval && (t.createdAt.getTime() >= n.getTime() || (i === null || t.createdAt.getTime() > i.createdAt.getTime() || t.createdAt.getTime() === i.createdAt.getTime() && t.id > i.id) && (i = t));
37
+ return i;
38
+ }, s = (t, n = !1) => new e({
39
+ source: "historicalUsage",
40
+ message: t,
41
+ transient: n
42
+ }), c = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,179}$/, l = (e) => (n) => t.gen(function* () {
43
+ let r = n.period.start.getTime(), l = n.period.end.getTime(), u = e.now().getTime();
44
+ if (n.tenantId.length === 0 || n.priceId.length === 0 || !c.test(n.idempotencyKey) || n.description.trim().length === 0 || n.description.length > 500 || !Number.isFinite(r) || !Number.isFinite(l) || r >= l || !Number.isSafeInteger(n.fromUnits) || !Number.isSafeInteger(n.toUnits) || n.fromUnits < 0 || n.toUnits <= n.fromUnits) return yield* t.fail(s("Historical usage requires a tenant, a price, a valid closed period, a positive unit interval and a stable key."));
45
+ if (l > u) return yield* t.fail(s("Historical usage belongs to a closed period; this period has not ended yet."));
46
+ let d = e.provider.fetchPriceVersions, f = e.provider.ensureInvoiceItem;
47
+ if (d === void 0 || f === void 0) return yield* t.fail(s(`Billing provider "${e.provider.name}" cannot invoice historical usage.`));
48
+ if (yield* e.sealed(n.tenantId)) return yield* t.fail(s("Usage arrived after final billing dispatch was sealed. Financial reconciliation is required."));
49
+ let p = o(yield* d(n.priceId), n.priceId, n.period.end);
50
+ if (p === null) return yield* t.fail(s("The provider holds no version of this price that was in force during the period."));
51
+ let m = a(p, n.fromUnits, n.toUnits);
52
+ if (m === null) return yield* t.fail(s("The period's price is not a flat or graduated per-unit price; its amount cannot be applied exactly."));
53
+ let h = m.map((e, t) => ({
54
+ segment: e,
55
+ index: t
56
+ })).filter(({ segment: e }) => !i(e.unitAmountDecimal));
57
+ if (h.length === 0) return {
58
+ priceId: p.id,
59
+ currency: p.currency,
60
+ lines: []
61
+ };
62
+ let g = yield* e.customerOf(n.tenantId);
63
+ if (g === null) return yield* t.fail(s("Historical usage requires a linked provider customer.", !0));
64
+ let _ = yield* e.liveSubscriptionOf(n.tenantId), v = [];
65
+ for (let { segment: e, index: t } of h) {
66
+ let r = yield* f({
67
+ providerCustomerId: g,
68
+ ..._ === null ? {} : { providerSubscriptionId: _ },
69
+ productId: p.productId,
70
+ currency: p.currency,
71
+ quantity: e.quantity,
72
+ unitAmountDecimal: e.unitAmountDecimal,
73
+ taxBehavior: p.taxBehavior,
74
+ period: {
75
+ start: n.period.start,
76
+ end: n.period.end
77
+ },
78
+ description: n.description,
79
+ idempotencyKey: `${n.idempotencyKey}:${String(t)}`,
80
+ notBefore: n.period.end
81
+ });
82
+ v.push({
83
+ providerInvoiceItemId: r.providerInvoiceItemId,
84
+ quantity: e.quantity,
85
+ unitAmountDecimal: e.unitAmountDecimal
86
+ });
87
+ }
88
+ return {
89
+ priceId: p.id,
90
+ currency: p.currency,
91
+ lines: v
92
+ };
93
+ });
94
+ export { a as historicalUsageSegments, l as makeHistoricalUsageInvoicer, o as priceVersionInForce };