@voltro/plugin-billing 0.85.0 → 0.87.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 +5987 -0
- package/README.md +435 -0
- package/THIRD-PARTY-NOTICES.md +864 -253
- package/dist/catalog.js +471 -0
- package/dist/checkoutStore.js +165 -0
- package/dist/closeStore.js +125 -0
- package/dist/custodyInventory.js +155 -0
- package/dist/customerStore.js +259 -0
- package/dist/dunning.js +209 -0
- package/dist/economy.d.ts +30 -0
- package/dist/economy.js +266 -0
- package/dist/entitlement.js +41 -0
- package/dist/eventDelivery.js +72 -0
- package/dist/flushClaim.js +20 -0
- package/dist/index.d.ts +669 -65
- package/dist/index.js +243 -2803
- package/dist/invoiceHistory.js +91 -0
- package/dist/invoiceHistoryJournal.js +476 -0
- package/dist/invoiceHistoryProgress.js +235 -0
- package/dist/invoiceHistoryWork.js +363 -0
- package/dist/invoiceSnapshot.js +66 -0
- package/dist/invoiceStore.js +133 -0
- package/dist/metering.js +74 -0
- package/dist/plans.js +24 -0
- package/dist/providerIdentity.js +24 -0
- package/dist/providers.js +338 -0
- package/dist/provision.js +153 -0
- package/dist/service.js +1116 -0
- package/dist/stores.js +260 -0
- package/dist/stripeClient.js +53 -0
- package/dist/stripeIdentity.js +56 -0
- package/dist/stripeInvoiceHistory.js +67 -0
- package/dist/stripeInvoiceSnapshot.js +86 -0
- package/dist/stripeProvider.js +479 -0
- package/dist/stripeRest.js +52 -0
- package/dist/stripeVerifiedEvent.js +29 -0
- package/dist/table.js +77 -0
- package/dist/types.d.ts +298 -27
- package/dist/usageEvents.js +65 -0
- package/dist/webhook.js +38 -0
- package/package.json +17 -7
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { diffMeter as e, diffPortal as t, diffPrice as n, diffProduct as r, diffTaxSettings as i, diffWebhook as a, sellingReadiness as o } from "./catalog.js";
|
|
2
|
+
import { redactStripeKeys as s, stripeRest as c } from "./stripeRest.js";
|
|
3
|
+
import { execFileSync as l } from "node:child_process";
|
|
4
|
+
import { chmodSync as u, existsSync as d, readFileSync as f, realpathSync as p, writeFileSync as m } from "node:fs";
|
|
5
|
+
import { dirname as h, resolve as g } from "node:path";
|
|
6
|
+
//#region src/provision.ts
|
|
7
|
+
var _ = (e) => e.filter((e) => e.applied !== !0 && (e.kind === "create" || e.kind === "update" || e.kind === "adopt" || e.kind === "drift")), v = async (s, c, l) => {
|
|
8
|
+
let u = c.environments[l.env], d = await s.get("/v1/tax/settings"), f = l.env === "live";
|
|
9
|
+
if (d.livemode !== f) throw Error(`the key reaches a ${d.livemode ? "LIVE" : "test"} account, not ${l.env}`);
|
|
10
|
+
let p = [], m = {}, h = async (e, t) => {
|
|
11
|
+
let n = "apply" in e ? e.apply : void 0;
|
|
12
|
+
if (l.apply && n !== void 0) {
|
|
13
|
+
let r = await s.post(n.path, n.params);
|
|
14
|
+
t?.(r), p.push({
|
|
15
|
+
...e,
|
|
16
|
+
applied: !0
|
|
17
|
+
});
|
|
18
|
+
} else p.push(e);
|
|
19
|
+
}, g = await s.list("/v1/billing/meters"), _ = /* @__PURE__ */ new Map();
|
|
20
|
+
for (let t of c.meters) {
|
|
21
|
+
let n = e(t, g);
|
|
22
|
+
_.set(t.eventName, n.id), await h(n.finding, (e) => {
|
|
23
|
+
_.set(t.eventName, e.id);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
let v = await s.list("/v1/products"), y = [];
|
|
27
|
+
for (let e of c.products) {
|
|
28
|
+
let t = r(e, v), n = {
|
|
29
|
+
inPortal: e.inPortal,
|
|
30
|
+
productId: t.id,
|
|
31
|
+
priceId: null
|
|
32
|
+
};
|
|
33
|
+
await h(t.finding, (e) => {
|
|
34
|
+
n.productId = e.id;
|
|
35
|
+
}), y.push(n);
|
|
36
|
+
}
|
|
37
|
+
for (let [e, t] of c.products.entries()) {
|
|
38
|
+
let r = y[e], i = t.price.meter;
|
|
39
|
+
if (t.price.usageType === "metered" && (i === void 0 || !_.has(i))) {
|
|
40
|
+
p.push({
|
|
41
|
+
kind: "manual",
|
|
42
|
+
object: `price ${t.price.lookupKey}`,
|
|
43
|
+
detail: `metered, but names no catalog meter (${i ?? "none"})`
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
let a = i === void 0 ? null : _.get(i) ?? null, o = r.productId ?? (l.apply ? null : `pending:${t.key}`), c = a ?? (l.apply || t.price.usageType !== "metered" ? a : `pending:${i}`), u = (await s.list("/v1/prices", { lookup_keys: [t.price.lookupKey] }))[0] ?? null, d = r.productId === null ? [] : await s.list("/v1/prices", { product: r.productId }), f = n(t.price, o, c, u, d, l.allowPriceChange);
|
|
48
|
+
r.priceId = f.id, await h(f.finding, (e) => {
|
|
49
|
+
r.priceId = e.id;
|
|
50
|
+
}), r.priceId !== null && (m[t.price.envName] = r.priceId);
|
|
51
|
+
}
|
|
52
|
+
await h(i(c.tax, d));
|
|
53
|
+
let b = y.filter((e) => e.inPortal), x = b.every((e) => e.productId !== null && e.priceId !== null) ? b.map((e) => ({
|
|
54
|
+
productId: e.productId,
|
|
55
|
+
priceId: e.priceId
|
|
56
|
+
})) : null, S = await s.list("/v1/billing_portal/configurations", { expand: ["data.features.subscription_update.products"] });
|
|
57
|
+
for (let e of t(c.portal, u, x, S)) await h(e);
|
|
58
|
+
let C = a(u, await s.list("/v1/webhook_endpoints"));
|
|
59
|
+
C.kind === "create" && l.apply && l.envOut === null ? p.push({
|
|
60
|
+
kind: "manual",
|
|
61
|
+
object: C.object,
|
|
62
|
+
detail: "not created: pass --env-out so its signing secret is captured (Stripe shows it once)"
|
|
63
|
+
}) : await h(C, (e) => {
|
|
64
|
+
typeof e.secret == "string" && (m.STRIPE_WEBHOOK_SECRET = e.secret);
|
|
65
|
+
});
|
|
66
|
+
let w = await s.get("/v1/account").catch(() => null), T = await s.list("/v1/tax_ids", { owner: { type: "account" } }).catch(() => null), E = await s.list("/v1/tax/registrations", { status: "active" }).catch(() => []);
|
|
67
|
+
return p.push(...o({
|
|
68
|
+
catalog: c,
|
|
69
|
+
env: u,
|
|
70
|
+
chargesEnabled: w === null ? null : w.charges_enabled === !0,
|
|
71
|
+
accountTaxIds: T === null ? null : T.length,
|
|
72
|
+
activeRegistrations: E.map((e) => e.country)
|
|
73
|
+
})), {
|
|
74
|
+
livemode: d.livemode,
|
|
75
|
+
findings: p,
|
|
76
|
+
envOut: m
|
|
77
|
+
};
|
|
78
|
+
}, y = (e, t) => {
|
|
79
|
+
let n = new Set(Object.keys(t)), r = e.split("\n").filter((e) => !n.has(e.split("=")[0] ?? ""));
|
|
80
|
+
for (; r.length > 0 && r[r.length - 1] === "";) r.pop();
|
|
81
|
+
return [
|
|
82
|
+
...r,
|
|
83
|
+
...Object.entries(t).map(([e, t]) => `${e}=${t}`),
|
|
84
|
+
""
|
|
85
|
+
].join("\n");
|
|
86
|
+
}, b = (e, t) => {
|
|
87
|
+
try {
|
|
88
|
+
return l("git", [...e], {
|
|
89
|
+
cwd: t,
|
|
90
|
+
stdio: "ignore"
|
|
91
|
+
}), !0;
|
|
92
|
+
} catch {
|
|
93
|
+
return !1;
|
|
94
|
+
}
|
|
95
|
+
}, x = (e, t = b, n = (e) => d(e) ? p(e) : e) => {
|
|
96
|
+
for (let r of /* @__PURE__ */ new Set([g(e), g(n(g(e)))])) {
|
|
97
|
+
let n = h(r);
|
|
98
|
+
if (t(["rev-parse", "--is-inside-work-tree"], n) && !t([
|
|
99
|
+
"check-ignore",
|
|
100
|
+
"-q",
|
|
101
|
+
r
|
|
102
|
+
], n)) return `${e} is inside a git work tree and not ignored — write it to a gitignored file or outside the repo`;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}, S = (e) => {
|
|
106
|
+
let t = (t) => {
|
|
107
|
+
let n = e.indexOf(t);
|
|
108
|
+
return n < 0 ? null : e[n + 1];
|
|
109
|
+
}, n = t("--env");
|
|
110
|
+
if (n !== "sandbox" && n !== "live") return "--env sandbox|live is required";
|
|
111
|
+
let r = t("--env-out");
|
|
112
|
+
if (r === void 0 || r?.startsWith("--")) return "--env-out needs a file path";
|
|
113
|
+
let i = {
|
|
114
|
+
env: n,
|
|
115
|
+
apply: e.includes("--apply"),
|
|
116
|
+
allowPriceChange: e.includes("--allow-price-change"),
|
|
117
|
+
confirmLive: e.includes("--confirm-live"),
|
|
118
|
+
strict: e.includes("--strict"),
|
|
119
|
+
envOut: r
|
|
120
|
+
};
|
|
121
|
+
return i.env === "live" && i.apply && !i.confirmLive ? "writing to LIVE needs --confirm-live (run without --apply first to see the plan)" : i;
|
|
122
|
+
}, C = (e, t, n) => {
|
|
123
|
+
let r = t.STRIPE_PROVISION_KEY?.trim() || (e === "sandbox" ? n?.trim() : void 0);
|
|
124
|
+
return r === void 0 || r.length === 0 ? { refusal: "set STRIPE_PROVISION_KEY (a sandbox run also reads STRIPE_SECRET_KEY from the dotenv file)" } : e === "live" && !/^(sk|rk)_live_/.test(r) ? { refusal: "--env live needs a live key (sk_live_/rk_live_)" } : e === "sandbox" && !/^(sk|rk)_test_/.test(r) ? { refusal: "--env sandbox needs a test key (sk_test_/rk_test_)" } : { key: r };
|
|
125
|
+
}, w = (e, t) => d(e) ? f(e, "utf8").split("\n").find((e) => e.startsWith(`${t}=`))?.slice(t.length + 1).trim() : void 0, T = async (e, t, n = {}) => {
|
|
126
|
+
let r = n.vars ?? process.env, i = (e) => (console.error(`stripe provision: ${e}`), 2), a = S(t);
|
|
127
|
+
if (typeof a == "string") return i(a);
|
|
128
|
+
if (a.envOut !== null) {
|
|
129
|
+
let e = x(a.envOut);
|
|
130
|
+
if (e !== null) return i(e);
|
|
131
|
+
}
|
|
132
|
+
let o = C(a.env, r, n.dotenv === void 0 ? void 0 : w(n.dotenv, "STRIPE_SECRET_KEY"));
|
|
133
|
+
if ("refusal" in o) return i(o.refusal);
|
|
134
|
+
let l;
|
|
135
|
+
try {
|
|
136
|
+
l = await v((n.rest ?? c)(o.key), e, a);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return console.error(`stripe provision: ${s(e instanceof Error ? e.message : String(e))}`), 1;
|
|
139
|
+
}
|
|
140
|
+
console.log(`Stripe ${a.env} (${l.livemode ? "LIVE" : "test mode"}) — ${a.apply ? "apply" : "check"}`);
|
|
141
|
+
for (let e of l.findings) {
|
|
142
|
+
let t = e.applied === !0 ? `${e.kind} ✓` : e.kind;
|
|
143
|
+
console.log(` ${t.padEnd(10)} ${e.object}${"detail" in e ? ` — ${e.detail}` : ""}`);
|
|
144
|
+
}
|
|
145
|
+
if (a.envOut !== null) {
|
|
146
|
+
let e = a.envOut;
|
|
147
|
+
m(e, y(d(e) ? f(e, "utf8") : "", l.envOut), { mode: 384 }), u(e, 384), console.log(` wrote ${Object.keys(l.envOut).sort().join(", ")} to ${e}`);
|
|
148
|
+
}
|
|
149
|
+
let p = _(l.findings), h = l.findings.filter((e) => e.kind === "manual");
|
|
150
|
+
return console.log(` ${p.length} open, ${h.length} manual`), p.length > 0 || a.strict && h.length > 0 ? 1 : 0;
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
export { x as envOutRefusal, y as mergeEnvFile, _ as openFindings, S as parseProvisionArgs, v as provisionStripeCatalog, C as resolveProvisionKey, T as runStripeProvision };
|