@voltro/plugin-billing 0.90.0 → 0.91.1

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/dist/catalog.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Stripe as e } from "./stripeClient.js";
2
- import { STRIPE_WEBHOOK_EVENTS as t } from "./stripeProvider.js";
1
+ import { STRIPE_WEBHOOK_EVENTS as e } from "./stripeProvider.js";
2
+ import { STRIPE_API_VERSION as t } from "./stripeRest.js";
3
3
  // src/catalog.ts
4
- var n = e.API_VERSION, r = (e) => {
4
+ var n = (e) => {
5
5
  let t = e.retired ?? {}, n = {
6
6
  prices: new Set(e.products.map((e) => e.price.lookupKey)),
7
7
  products: new Set(e.products.map((e) => e.key)),
@@ -12,12 +12,12 @@ var n = e.API_VERSION, r = (e) => {
12
12
  "products",
13
13
  "meters"
14
14
  ].flatMap((e) => (t[e] ?? []).filter((t) => n[e].has(t)).map((t) => `${e.slice(0, -1)} ${t}`));
15
- }, i = [
15
+ }, r = [
16
16
  "Checkout → \"Limit customers to one subscription\" (with the customer portal login link enabled) — Stripe's own refusal of a second subscription",
17
17
  "Smart Retries + failed-payment emails (Billing → Revenue recovery)",
18
18
  "invoice branding and email settings",
19
19
  "a restricted key (rk_) for the app, separate from the provisioning key"
20
- ], a = (e) => typeof e.tax_code == "string" ? e.tax_code : e.tax_code?.id ?? null, o = (e) => ({
20
+ ], i = (e) => typeof e.tax_code == "string" ? e.tax_code : e.tax_code?.id ?? null, a = (e) => ({
21
21
  name: e.name,
22
22
  description: e.description,
23
23
  unit_label: e.unitLabel,
@@ -26,15 +26,15 @@ var n = e.API_VERSION, r = (e) => {
26
26
  ...e.metadata,
27
27
  voltro_key: e.key
28
28
  }
29
- }), s = (e, t) => {
29
+ }), o = (e, t) => {
30
30
  let n = [];
31
- t.active || n.push("active"), t.name !== e.name && n.push("name"), (t.description ?? "") !== e.description && n.push("description"), (t.unit_label ?? "") !== e.unitLabel && n.push("unit_label"), a(t) !== e.taxCode && n.push("tax_code");
31
+ t.active || n.push("active"), t.name !== e.name && n.push("name"), (t.description ?? "") !== e.description && n.push("description"), (t.unit_label ?? "") !== e.unitLabel && n.push("unit_label"), i(t) !== e.taxCode && n.push("tax_code");
32
32
  for (let [r, i] of Object.entries({
33
33
  ...e.metadata,
34
34
  voltro_key: e.key
35
35
  })) t.metadata[r] !== i && n.push(`metadata.${r}`);
36
36
  return n;
37
- }, c = (e, t) => {
37
+ }, s = (e, t) => {
38
38
  let n = `product ${e.key}`, r = t.filter((t) => t.metadata.voltro_key === e.key);
39
39
  if (r.length > 1) return {
40
40
  finding: {
@@ -46,7 +46,7 @@ var n = e.API_VERSION, r = (e) => {
46
46
  };
47
47
  let i = r[0];
48
48
  if (i !== void 0) {
49
- let t = s(e, i);
49
+ let t = o(e, i);
50
50
  return t.length === 0 ? {
51
51
  finding: {
52
52
  kind: "ok",
@@ -62,7 +62,7 @@ var n = e.API_VERSION, r = (e) => {
62
62
  method: "POST",
63
63
  path: `/v1/products/${i.id}`,
64
64
  params: {
65
- ...o(e),
65
+ ...a(e),
66
66
  active: !0
67
67
  }
68
68
  }
@@ -70,9 +70,9 @@ var n = e.API_VERSION, r = (e) => {
70
70
  id: i.id
71
71
  };
72
72
  }
73
- let a = t.filter((t) => t.active && t.metadata.voltro_key === void 0 && Object.keys(e.metadata).length > 0 && Object.entries(e.metadata).every(([e, n]) => t.metadata[e] === n));
74
- if (a.length === 1) {
75
- let t = a[0];
73
+ let s = t.filter((t) => t.active && t.metadata.voltro_key === void 0 && Object.keys(e.metadata).length > 0 && Object.entries(e.metadata).every(([e, n]) => t.metadata[e] === n));
74
+ if (s.length === 1) {
75
+ let t = s[0];
76
76
  return {
77
77
  finding: {
78
78
  kind: "adopt",
@@ -81,17 +81,17 @@ var n = e.API_VERSION, r = (e) => {
81
81
  apply: {
82
82
  method: "POST",
83
83
  path: `/v1/products/${t.id}`,
84
- params: o(e)
84
+ params: a(e)
85
85
  }
86
86
  },
87
87
  id: t.id
88
88
  };
89
89
  }
90
- return a.length > 1 ? {
90
+ return s.length > 1 ? {
91
91
  finding: {
92
92
  kind: "manual",
93
93
  object: n,
94
- detail: `${a.length} products could be this one — archive all but one`
94
+ detail: `${s.length} products could be this one — archive all but one`
95
95
  },
96
96
  id: null
97
97
  } : {
@@ -102,26 +102,26 @@ var n = e.API_VERSION, r = (e) => {
102
102
  apply: {
103
103
  method: "POST",
104
104
  path: "/v1/products",
105
- params: o(e)
105
+ params: a(e)
106
106
  }
107
107
  },
108
108
  id: null
109
109
  };
110
- }, l = (e) => e.upTo === "inf" ? null : e.upTo, u = /^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,12})?$/, d = (e, t) => e !== null && u.test(e) && u.test(t) && f(e) === f(t), f = (e) => {
110
+ }, c = (e) => e.upTo === "inf" ? null : e.upTo, l = /^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,12})?$/, u = (e, t) => e !== null && l.test(e) && l.test(t) && d(e) === d(t), d = (e) => {
111
111
  let [t = "0", n = ""] = e.split("."), r = n.replace(/0+$/, "");
112
112
  return r.length === 0 ? t : `${t}.${r}`;
113
- }, p = (e) => e.tiers.some((e) => e.unitAmount !== void 0 && e.unitAmountDecimal !== void 0 || e.unitAmountDecimal !== void 0 && !u.test(e.unitAmountDecimal)), m = (e, t) => {
113
+ }, f = (e) => e.tiers.some((e) => e.unitAmount !== void 0 && e.unitAmountDecimal !== void 0 || e.unitAmountDecimal !== void 0 && !l.test(e.unitAmountDecimal)), p = (e, t) => {
114
114
  let n = [];
115
115
  (t.billing_scheme ?? "per_unit") !== "tiered" && n.push("billing_scheme"), (t.tiers_mode ?? null) !== e.mode && n.push("tiers_mode");
116
116
  let r = t.tiers ?? [];
117
117
  return r.length === e.tiers.length ? (e.tiers.forEach((e, t) => {
118
118
  let i = r[t];
119
- i.up_to !== l(e) && n.push(`tiers[${t}].up_to`), e.unitAmount !== void 0 && i.unit_amount !== e.unitAmount && n.push(`tiers[${t}].unit_amount`), e.unitAmountDecimal !== void 0 && !d(i.unit_amount_decimal ?? (i.unit_amount === null ? null : String(i.unit_amount)), e.unitAmountDecimal) && n.push(`tiers[${t}].unit_amount_decimal`), e.flatAmount !== void 0 && i.flat_amount !== e.flatAmount && n.push(`tiers[${t}].flat_amount`);
119
+ i.up_to !== c(e) && n.push(`tiers[${t}].up_to`), e.unitAmount !== void 0 && i.unit_amount !== e.unitAmount && n.push(`tiers[${t}].unit_amount`), e.unitAmountDecimal !== void 0 && !u(i.unit_amount_decimal ?? (i.unit_amount === null ? null : String(i.unit_amount)), e.unitAmountDecimal) && n.push(`tiers[${t}].unit_amount_decimal`), e.flatAmount !== void 0 && i.flat_amount !== e.flatAmount && n.push(`tiers[${t}].flat_amount`);
120
120
  }), n) : (n.push("tiers"), n);
121
- }, h = (e) => e.tiers.length > 0 && e.tiers.at(-1).upTo === "inf" && e.tiers.every((e) => e.unitAmount !== void 0 || e.unitAmountDecimal !== void 0 || e.flatAmount !== void 0), g = (e, t, n, r) => {
121
+ }, m = (e) => e.tiers.length > 0 && e.tiers.at(-1).upTo === "inf" && e.tiers.every((e) => e.unitAmount !== void 0 || e.unitAmountDecimal !== void 0 || e.flatAmount !== void 0), h = (e, t, n, r) => {
122
122
  let i = [];
123
- return r.product !== t && i.push("product"), r.currency !== e.currency && i.push("currency"), e.tiers === void 0 ? (r.billing_scheme ?? "per_unit") !== "per_unit" && i.push("billing_scheme") : i.push(...m(e.tiers, r)), e.unitAmount !== void 0 && r.unit_amount !== e.unitAmount && i.push("unit_amount"), r.recurring?.interval !== e.interval && i.push("interval"), r.recurring?.usage_type !== e.usageType && i.push("usage_type"), e.usageType === "metered" && r.recurring?.meter !== n && i.push("meter"), r.tax_behavior !== e.taxBehavior && i.push("tax_behavior"), i;
124
- }, _ = (e) => ({
123
+ return r.product !== t && i.push("product"), r.currency !== e.currency && i.push("currency"), e.tiers === void 0 ? (r.billing_scheme ?? "per_unit") !== "per_unit" && i.push("billing_scheme") : i.push(...p(e.tiers, r)), e.unitAmount !== void 0 && r.unit_amount !== e.unitAmount && i.push("unit_amount"), r.recurring?.interval !== e.interval && i.push("interval"), r.recurring?.usage_type !== e.usageType && i.push("usage_type"), e.usageType === "metered" && r.recurring?.meter !== n && i.push("meter"), r.tax_behavior !== e.taxBehavior && i.push("tax_behavior"), i;
124
+ }, g = (e) => ({
125
125
  billing_scheme: "tiered",
126
126
  tiers_mode: e.mode,
127
127
  tiers: e.tiers.map((e) => ({
@@ -130,7 +130,7 @@ var n = e.API_VERSION, r = (e) => {
130
130
  ...e.unitAmountDecimal === void 0 ? {} : { unit_amount_decimal: e.unitAmountDecimal },
131
131
  ...e.flatAmount === void 0 ? {} : { flat_amount: e.flatAmount }
132
132
  }))
133
- }), v = (e, t, n, r, i) => ({
133
+ }), _ = (e, t, n, r, i) => ({
134
134
  product: t,
135
135
  currency: e.currency,
136
136
  ...i,
@@ -143,7 +143,7 @@ var n = e.API_VERSION, r = (e) => {
143
143
  lookup_key: e.lookupKey,
144
144
  ...r ? { transfer_lookup_key: !0 } : {},
145
145
  metadata: { voltro_key: e.lookupKey }
146
- }), y = (e, t, n, r, i, a) => {
146
+ }), v = (e, t, n, r, i, a) => {
147
147
  let o = `price ${e.lookupKey}`;
148
148
  if (t === null) return {
149
149
  finding: {
@@ -169,7 +169,7 @@ var n = e.API_VERSION, r = (e) => {
169
169
  },
170
170
  id: null
171
171
  };
172
- if (e.tiers !== void 0 && p(e.tiers)) return {
172
+ if (e.tiers !== void 0 && f(e.tiers)) return {
173
173
  finding: {
174
174
  kind: "manual",
175
175
  object: o,
@@ -177,9 +177,9 @@ var n = e.API_VERSION, r = (e) => {
177
177
  },
178
178
  id: null
179
179
  };
180
- let s = e.tiers === void 0 ? e.unitAmount === void 0 ? null : { unit_amount: e.unitAmount } : h(e.tiers) ? _(e.tiers) : null;
180
+ let s = e.tiers === void 0 ? e.unitAmount === void 0 ? null : { unit_amount: e.unitAmount } : m(e.tiers) ? g(e.tiers) : null;
181
181
  if (r !== null) {
182
- let i = g(e, t, n, r);
182
+ let i = h(e, t, n, r);
183
183
  if (i.length > 0) {
184
184
  let c = s ?? (e.tiers === void 0 && r.unit_amount !== null ? { unit_amount: r.unit_amount } : null);
185
185
  if (c === null) return {
@@ -193,7 +193,7 @@ var n = e.API_VERSION, r = (e) => {
193
193
  let l = {
194
194
  method: "POST",
195
195
  path: "/v1/prices",
196
- params: v(e, t, n, !0, c)
196
+ params: _(e, t, n, !0, c)
197
197
  };
198
198
  return a ? {
199
199
  finding: {
@@ -232,7 +232,7 @@ var n = e.API_VERSION, r = (e) => {
232
232
  id: r.id
233
233
  };
234
234
  }
235
- let c = i.filter((r) => r.active && r.lookup_key === null && g(e, t, n, r).length === 0)[0];
235
+ let c = i.filter((r) => r.active && r.lookup_key === null && h(e, t, n, r).length === 0)[0];
236
236
  return c === void 0 ? s === null ? {
237
237
  finding: {
238
238
  kind: "manual",
@@ -248,7 +248,7 @@ var n = e.API_VERSION, r = (e) => {
248
248
  apply: {
249
249
  method: "POST",
250
250
  path: "/v1/prices",
251
- params: v(e, t, n, !1, s)
251
+ params: _(e, t, n, !1, s)
252
252
  }
253
253
  },
254
254
  id: null
@@ -268,7 +268,7 @@ var n = e.API_VERSION, r = (e) => {
268
268
  },
269
269
  id: c.id
270
270
  };
271
- }, b = (e, t) => {
271
+ }, y = (e, t) => {
272
272
  let n = `meter ${e.eventName}`, r = t.find((t) => t.event_name === e.eventName);
273
273
  if (r === void 0) return {
274
274
  finding: {
@@ -331,7 +331,7 @@ var n = e.API_VERSION, r = (e) => {
331
331
  },
332
332
  id: r.id
333
333
  };
334
- }, x = (e, t) => {
334
+ }, b = (e, t) => {
335
335
  let n = `retired price ${e}`, r = t.filter((t) => t.active && t.lookup_key === e);
336
336
  return r.length === 0 ? {
337
337
  kind: "ok",
@@ -350,7 +350,7 @@ var n = e.API_VERSION, r = (e) => {
350
350
  params: { active: !1 }
351
351
  }
352
352
  };
353
- }, S = (e, t) => {
353
+ }, x = (e, t) => {
354
354
  let n = `retired product ${e}`, r = t.filter((t) => t.active && t.metadata.voltro_key === e);
355
355
  return r.length === 0 ? {
356
356
  kind: "ok",
@@ -369,7 +369,7 @@ var n = e.API_VERSION, r = (e) => {
369
369
  params: { active: !1 }
370
370
  }
371
371
  };
372
- }, C = (e, t) => {
372
+ }, S = (e, t) => {
373
373
  let n = `retired meter ${e}`, r = t.find((t) => t.event_name === e);
374
374
  return r === void 0 || r.status !== "active" ? {
375
375
  kind: "ok",
@@ -384,7 +384,7 @@ var n = e.API_VERSION, r = (e) => {
384
384
  params: {}
385
385
  }
386
386
  };
387
- }, w = (e, t) => {
387
+ }, C = (e, t) => {
388
388
  let n = "tax settings", r = t.head_office?.address ?? {}, i = [];
389
389
  for (let [t, n] of Object.entries(e.headOffice)) r[t] !== n && i.push(`head_office.${t}`);
390
390
  return t.defaults.tax_code !== e.defaultTaxCode && i.push("defaults.tax_code"), t.defaults.tax_behavior !== e.defaultTaxBehavior && i.push("defaults.tax_behavior"), i.length === 0 ? t.status === "active" ? {
@@ -410,7 +410,7 @@ var n = e.API_VERSION, r = (e) => {
410
410
  }
411
411
  }
412
412
  };
413
- }, T = (e, t) => ({
413
+ }, w = (e, t) => ({
414
414
  business_profile: {
415
415
  headline: e.headline,
416
416
  privacy_policy_url: e.privacyPolicyUrl,
@@ -436,7 +436,7 @@ var n = e.API_VERSION, r = (e) => {
436
436
  subscription_update: { enabled: !1 }
437
437
  },
438
438
  metadata: { voltro_key: e.key }
439
- }), E = (e) => JSON.stringify([...e ?? []].sort()), D = (e, t) => {
439
+ }), T = (e) => JSON.stringify([...e ?? []].sort()), E = (e, t) => {
440
440
  let n = [], r = t.features, i = e.features;
441
441
  t.default_return_url !== e.default_return_url && n.push("default_return_url");
442
442
  let a = e.business_profile;
@@ -447,9 +447,9 @@ var n = e.API_VERSION, r = (e) => {
447
447
  "payment_method_update",
448
448
  "subscription_cancel"
449
449
  ]) r[e]?.enabled !== !0 && n.push(`${e}.enabled`);
450
- return E(r.customer_update?.allowed_updates) !== E(i.customer_update.allowed_updates) && n.push("customer_update.allowed_updates"), r.subscription_cancel?.mode !== "at_period_end" && n.push("subscription_cancel.mode"), r.subscription_update?.enabled !== !1 && n.push("subscription_update.enabled"), n;
451
- }, O = (e, t, n) => {
452
- let r = "customer portal", i = T(e, t), a = n.find((t) => t.metadata.voltro_key === e.key) ?? n.find((t) => t.active && t.name === e.name);
450
+ return T(r.customer_update?.allowed_updates) !== T(i.customer_update.allowed_updates) && n.push("customer_update.allowed_updates"), r.subscription_cancel?.mode !== "at_period_end" && n.push("subscription_cancel.mode"), r.subscription_update?.enabled !== !1 && n.push("subscription_update.enabled"), n;
451
+ }, D = (e, t, n) => {
452
+ let r = "customer portal", i = w(e, t), a = n.find((t) => t.metadata.voltro_key === e.key) ?? n.find((t) => t.active && t.name === e.name);
453
453
  if (a === void 0) return [{
454
454
  kind: "create",
455
455
  object: r,
@@ -467,7 +467,7 @@ var n = e.API_VERSION, r = (e) => {
467
467
  object: r,
468
468
  detail: "another configuration is the default — make this one the default in the Dashboard"
469
469
  }] : []];
470
- let o = [], s = D(i, a), c = a.metadata.voltro_key !== e.key;
470
+ let o = [], s = E(i, a), c = a.metadata.voltro_key !== e.key;
471
471
  return s.length > 0 || c || !a.active ? o.push({
472
472
  kind: c ? "adopt" : "update",
473
473
  object: r,
@@ -488,18 +488,18 @@ var n = e.API_VERSION, r = (e) => {
488
488
  object: r,
489
489
  detail: "not the account default — portal sessions would use another configuration"
490
490
  }), o;
491
- }, k = (e, r) => {
492
- if (e.webhookUrl === null) return {
491
+ }, O = (n, r) => {
492
+ if (n.webhookUrl === null) return {
493
493
  kind: "ok",
494
494
  object: "webhook endpoint (none: stripe listen forwards locally)"
495
495
  };
496
- let i = `webhook endpoint ${e.webhookUrl}`, a = r.filter((t) => t.url === e.webhookUrl);
496
+ let i = `webhook endpoint ${n.webhookUrl}`, a = r.filter((e) => e.url === n.webhookUrl);
497
497
  if (a.length > 1) return {
498
498
  kind: "manual",
499
499
  object: i,
500
500
  detail: `${a.length} endpoints for this url — delete all but one`
501
501
  };
502
- let o = a[0], s = [...t].sort();
502
+ let o = a[0], s = [...e].sort();
503
503
  return o === void 0 ? {
504
504
  kind: "create",
505
505
  object: i,
@@ -508,13 +508,13 @@ var n = e.API_VERSION, r = (e) => {
508
508
  method: "POST",
509
509
  path: "/v1/webhook_endpoints",
510
510
  params: {
511
- url: e.webhookUrl,
511
+ url: n.webhookUrl,
512
512
  enabled_events: s,
513
- api_version: n,
513
+ api_version: t,
514
514
  description: "Voltro billing"
515
515
  }
516
516
  }
517
- } : o.api_version !== null && o.api_version !== n ? {
517
+ } : o.api_version !== null && o.api_version !== t ? {
518
518
  kind: "drift",
519
519
  object: i,
520
520
  detail: `api version ${o.api_version} — payloads would not match the SDK; recreate it (and rotate STRIPE_WEBHOOK_SECRET)`
@@ -534,7 +534,7 @@ var n = e.API_VERSION, r = (e) => {
534
534
  kind: "ok",
535
535
  object: i
536
536
  };
537
- }, A = (e) => {
537
+ }, k = (e) => {
538
538
  let t = [];
539
539
  for (let n of e.catalog.tax.registrationCountries) e.activeRegistrations.includes(n) || t.push({
540
540
  kind: "manual",
@@ -559,11 +559,11 @@ var n = e.API_VERSION, r = (e) => {
559
559
  object: "account tax id",
560
560
  detail: "not readable with this key — check Dashboard → Settings → Tax ids"
561
561
  });
562
- for (let n of e.catalog.dashboardReminders ?? i) t.push({
562
+ for (let n of e.catalog.dashboardReminders ?? r) t.push({
563
563
  kind: "manual",
564
564
  object: "dashboard",
565
565
  detail: `${n} — not checkable through the API`
566
566
  });
567
567
  return t;
568
568
  };
569
- export { n as STRIPE_API_VERSION, i as STRIPE_DASHBOARD_REMINDERS, b as diffMeter, O as diffPortal, y as diffPrice, c as diffProduct, C as diffRetiredMeter, x as diffRetiredPrice, S as diffRetiredProduct, w as diffTaxSettings, k as diffWebhook, T as portalParams, r as retiredConflicts, A as sellingReadiness };
569
+ export { t as STRIPE_API_VERSION, r as STRIPE_DASHBOARD_REMINDERS, y as diffMeter, D as diffPortal, v as diffPrice, s as diffProduct, S as diffRetiredMeter, b as diffRetiredPrice, x as diffRetiredProduct, C as diffTaxSettings, O as diffWebhook, w as portalParams, n as retiredConflicts, k as sellingReadiness };
package/dist/index.d.ts CHANGED
@@ -2641,7 +2641,10 @@ declare interface StoreHolder {
2641
2641
  }
2642
2642
 
2643
2643
  /** The API version every provisioning request and webhook endpoint uses — the
2644
- * one the SDK the plugin bills with pins. */
2644
+ * one the SDK the plugin bills with pins. Defined here, not in the catalog:
2645
+ * `stripeClient` imports this module, and the catalog imports `stripeClient`,
2646
+ * so a catalog-owned constant closed an import cycle that read the SDK before
2647
+ * it was initialised when the catalog was the first module loaded. */
2645
2648
  export declare const STRIPE_API_VERSION: string;
2646
2649
 
2647
2650
  /** The Dashboard steps no API can check, which every Stripe billing app needs. */