@arnaudjnn/billing-tools 0.63.2 → 0.64.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/dist/allowance.d.ts +20 -0
- package/dist/allowance.d.ts.map +1 -1
- package/dist/allowance.js +30 -5
- package/dist/allowance.js.map +1 -1
- package/dist/auth.d.ts +48 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +53 -2
- package/dist/auth.js.map +1 -1
- package/dist/billing.d.ts +59 -3
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +73 -12
- package/dist/billing.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +162 -1
- package/dist/cli/commands.js.map +1 -1
- package/dist/create-billing.d.ts +1 -1
- package/dist/doctor.d.ts +6 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +66 -1
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/metering.js +2 -2
- package/dist/metering.js.map +1 -1
- package/dist/plan-model.d.ts +11 -1
- package/dist/plan-model.d.ts.map +1 -1
- package/dist/plan-model.js +3 -2
- package/dist/plan-model.js.map +1 -1
- package/dist/subscription.d.ts +51 -17
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js +153 -43
- package/dist/subscription.js.map +1 -1
- package/dist/tools/billing.d.ts +16 -1
- package/dist/tools/billing.d.ts.map +1 -1
- package/dist/tools/billing.js +7 -2
- package/dist/tools/billing.js.map +1 -1
- package/dist/tools/management.d.ts.map +1 -1
- package/dist/tools/management.js +92 -17
- package/dist/tools/management.js.map +1 -1
- package/dist/tools/profile.d.ts +4 -0
- package/dist/tools/profile.d.ts.map +1 -0
- package/dist/tools/profile.js +171 -0
- package/dist/tools/profile.js.map +1 -0
- package/dist/tools/register.d.ts +17 -1
- package/dist/tools/register.d.ts.map +1 -1
- package/dist/tools/register.js +28 -3
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/subscription.d.ts +14 -0
- package/dist/tools/subscription.d.ts.map +1 -0
- package/dist/tools/subscription.js +167 -0
- package/dist/tools/subscription.js.map +1 -0
- package/dist/topup.d.ts +83 -1
- package/dist/topup.d.ts.map +1 -1
- package/dist/topup.js +107 -2
- package/dist/topup.js.map +1 -1
- package/dist/types.d.ts +18 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { enforceAdmin } from "../auth.js";
|
|
3
|
+
import { stripeConfigured } from "../billing.js";
|
|
4
|
+
import { cancelPlan, changePlan, planActions, previewPlanChange, PlanChangeError, } from "../subscription.js";
|
|
5
|
+
import { normalizePlans } from "../plans.js";
|
|
6
|
+
// The subscription lifecycle, as tools.
|
|
7
|
+
//
|
|
8
|
+
// This is the gap the QA pass found: changing plan was reachable from the app's
|
|
9
|
+
// own UI and from nowhere else. An agent could read the plans, buy tokens and
|
|
10
|
+
// meter usage, but could not move between plans, cancel, or even ask what a move
|
|
11
|
+
// would cost — the one thing a customer most wants to know before committing.
|
|
12
|
+
//
|
|
13
|
+
// Everything routes through `changePlan`, so the tool has the same properties the
|
|
14
|
+
// UI does: one live subscription, prorated up, scheduled down, cancel as a move
|
|
15
|
+
// to the free plan.
|
|
16
|
+
function json(obj) {
|
|
17
|
+
return { content: [{ type: "text", text: JSON.stringify(obj, null, 2) }] };
|
|
18
|
+
}
|
|
19
|
+
function err(text) {
|
|
20
|
+
return { isError: true, content: [{ type: "text", text }] };
|
|
21
|
+
}
|
|
22
|
+
/** Map a PlanChangeError onto a tool error the caller can act on. */
|
|
23
|
+
function toolError(e) {
|
|
24
|
+
if (e instanceof PlanChangeError) {
|
|
25
|
+
// `detail` carries the candidate subscription ids for the ambiguous case and
|
|
26
|
+
// the basket problems for an invalid one — both actionable, so pass them on.
|
|
27
|
+
const detail = Array.isArray(e.detail) ? ` [${e.detail.map(String).join(", ")}]` : "";
|
|
28
|
+
return err(`${e.message} (${e.code})${detail}`);
|
|
29
|
+
}
|
|
30
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
31
|
+
}
|
|
32
|
+
export function registerSubscriptionTools(server, adapter, config, opts) {
|
|
33
|
+
const seatsSchema = z
|
|
34
|
+
.record(z.string(), z.number().int().min(0))
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Seats per seat type, e.g. {"standard": 3, "premium": 1}. Defaults to the plan minimum');
|
|
37
|
+
const rates = async (orgId) => (opts.taxRates ? await opts.taxRates(orgId) : undefined);
|
|
38
|
+
server.tool("preview_plan_change", `What moving to a plan would cost, WITHOUT making the change. Returns the prorated
|
|
39
|
+
amount due now (the unused part of the current plan credited against the new one),
|
|
40
|
+
the recurring total afterwards, and when it takes effect. Quote this before
|
|
41
|
+
change_plan — the numbers come from the same arithmetic, so they agree.`, {
|
|
42
|
+
plan: z.string().describe("Target plan key, from list_plans"),
|
|
43
|
+
interval: z.enum(["monthly", "yearly"]).optional(),
|
|
44
|
+
seats: seatsSchema,
|
|
45
|
+
timing: z
|
|
46
|
+
.enum(["auto", "now", "period_end"])
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("Default `auto`: upgrades apply now, downgrades at the period end"),
|
|
49
|
+
}, async ({ plan, interval, seats, timing }) => {
|
|
50
|
+
const auth = await enforceAdmin(adapter, "preview_plan_change");
|
|
51
|
+
if ("isError" in auth)
|
|
52
|
+
return auth;
|
|
53
|
+
if (!stripeConfigured())
|
|
54
|
+
return err("Billing is not configured (STRIPE_SECRET_KEY unset).");
|
|
55
|
+
try {
|
|
56
|
+
const p = await previewPlanChange(adapter, auth.orgId, {
|
|
57
|
+
plans: opts.plans,
|
|
58
|
+
to: { plan, interval, seats },
|
|
59
|
+
currency: config.currency,
|
|
60
|
+
timing,
|
|
61
|
+
taxRates: await rates(auth.orgId),
|
|
62
|
+
});
|
|
63
|
+
return json({
|
|
64
|
+
outcome: p.kind,
|
|
65
|
+
currency: p.currency,
|
|
66
|
+
due_now: p.dueNow,
|
|
67
|
+
credit_applied: p.credit,
|
|
68
|
+
recurring_total: p.nextTotal,
|
|
69
|
+
effective_at: p.effectiveAt,
|
|
70
|
+
lines: p.lines,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return toolError(e);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
server.tool("change_plan", `Move this workspace to another plan — up, down, or off. One entry point for all
|
|
78
|
+
three: an upgrade applies immediately and is prorated, a downgrade is scheduled for
|
|
79
|
+
the end of the paid period (no refund, nothing lost early), and moving to the free
|
|
80
|
+
plan cancels at the period end. Moving back to the current plan while a cancellation
|
|
81
|
+
is pending resumes it. Preview the cost first with preview_plan_change.`, {
|
|
82
|
+
plan: z.string().describe("Target plan key, from list_plans"),
|
|
83
|
+
interval: z.enum(["monthly", "yearly"]).optional(),
|
|
84
|
+
seats: seatsSchema,
|
|
85
|
+
timing: z
|
|
86
|
+
.enum(["auto", "now", "period_end"])
|
|
87
|
+
.optional()
|
|
88
|
+
.describe("Default `auto`: upgrades now, downgrades at the period end"),
|
|
89
|
+
proration: z
|
|
90
|
+
.enum(["next_invoice", "invoice_now", "none"])
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("Default `next_invoice`: the prorated difference lands on the next invoice"),
|
|
93
|
+
}, async ({ plan, interval, seats, timing, proration }) => {
|
|
94
|
+
const auth = await enforceAdmin(adapter, "change_plan");
|
|
95
|
+
if ("isError" in auth)
|
|
96
|
+
return auth;
|
|
97
|
+
if (!stripeConfigured())
|
|
98
|
+
return err("Billing is not configured (STRIPE_SECRET_KEY unset).");
|
|
99
|
+
try {
|
|
100
|
+
const r = await changePlan(adapter, auth.orgId, {
|
|
101
|
+
plans: opts.plans,
|
|
102
|
+
to: { plan, interval, seats },
|
|
103
|
+
config,
|
|
104
|
+
currency: config.currency,
|
|
105
|
+
timing,
|
|
106
|
+
proration,
|
|
107
|
+
returnUrl: opts.returnUrl,
|
|
108
|
+
taxRates: await rates(auth.orgId),
|
|
109
|
+
});
|
|
110
|
+
return json({
|
|
111
|
+
outcome: r.kind,
|
|
112
|
+
plan: r.plan,
|
|
113
|
+
status: r.status,
|
|
114
|
+
effective_at: r.effectiveAt,
|
|
115
|
+
subscription_id: r.subscriptionId,
|
|
116
|
+
// Only on the first-purchase path: there is nothing to change yet, so
|
|
117
|
+
// the caller has to send someone through Checkout.
|
|
118
|
+
...(r.kind === "checkout" ? { checkout_client_secret: r.clientSecret, checkout_session_id: r.sessionId } : {}),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return toolError(e);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
server.tool("cancel_plan", `Cancel the subscription at the end of the period already paid for. Nothing is
|
|
126
|
+
refunded and nothing is lost today — the workspace drops to the free plan when the
|
|
127
|
+
period ends. Reverse it before then with change_plan back to the current plan.`, {}, async () => {
|
|
128
|
+
const auth = await enforceAdmin(adapter, "cancel_plan");
|
|
129
|
+
if ("isError" in auth)
|
|
130
|
+
return auth;
|
|
131
|
+
if (!stripeConfigured())
|
|
132
|
+
return err("Billing is not configured (STRIPE_SECRET_KEY unset).");
|
|
133
|
+
try {
|
|
134
|
+
const r = await cancelPlan(adapter, auth.orgId, { plans: opts.plans, currency: config.currency });
|
|
135
|
+
return json({ outcome: r.kind, plan: r.plan, status: r.status, effective_at: r.effectiveAt });
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return toolError(e);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
server.tool("get_plan", `The workspace's current plan: what it is on, whether a change is already
|
|
142
|
+
scheduled, and which moves are available (the plan above, the plan below, whether it
|
|
143
|
+
can be cancelled) — the same set the billing screen offers.`, {}, async () => {
|
|
144
|
+
const auth = await enforceAdmin(adapter, "get_plan");
|
|
145
|
+
if ("isError" in auth)
|
|
146
|
+
return auth;
|
|
147
|
+
const sub = (await adapter.getSubscription?.(auth.orgId)) ?? null;
|
|
148
|
+
const md = (await adapter.getOrgMetadata?.(auth.orgId)) ?? {};
|
|
149
|
+
const current = sub?.plan ?? null;
|
|
150
|
+
const actions = planActions(opts.plans, current);
|
|
151
|
+
const named = (key) => key ? (normalizePlans(opts.plans).find((m) => m.key === key)?.key ?? key) : null;
|
|
152
|
+
return json({
|
|
153
|
+
plan: current,
|
|
154
|
+
status: sub?.status ?? null,
|
|
155
|
+
period_end: sub?.periodEnd ?? null,
|
|
156
|
+
pending_plan: md.pendingPlan ?? null,
|
|
157
|
+
pending_plan_at: md.pendingPlanAt ?? null,
|
|
158
|
+
actions: {
|
|
159
|
+
upgrade_to: named(actions.upgradeTo),
|
|
160
|
+
downgrade_to: named(actions.downgradeTo),
|
|
161
|
+
can_cancel: actions.canCancel,
|
|
162
|
+
cancel_to: named(actions.cancelTo),
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/tools/subscription.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAG/D,wCAAwC;AACxC,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,iFAAiF;AACjF,8EAA8E;AAC9E,EAAE;AACF,kFAAkF;AAClF,gFAAgF;AA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AAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,OAAO,IAAI,CAAC;YACV,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,IAAI;YAC3B,UAAU,EAAE,GAAG,EAAE,SAAS,IAAI,IAAI;YAClC,YAAY,EAAE,EAAE,CAAC,WAAW,IAAI,IAAI;YACpC,eAAe,EAAE,EAAE,CAAC,aAAa,IAAI,IAAI;YACzC,OAAO,EAAE;gBACP,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;gBACpC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;gBACxC,UAAU,EAAE,OAAO,CAAC,SAAS;gBAC7B,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;aACnC;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/topup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BillingAdapter } from "./types.js";
|
|
2
|
+
import { type PlanCatalog } from "./plan-model.js";
|
|
2
3
|
export interface TopUpRequest {
|
|
3
4
|
id: string;
|
|
4
5
|
memberId: string;
|
|
@@ -6,6 +7,8 @@ export interface TopUpRequest {
|
|
|
6
7
|
cycle: string;
|
|
7
8
|
status: "pending" | "approved" | "denied";
|
|
8
9
|
createdAt: string;
|
|
10
|
+
/** Set when an admin granted it outright rather than approving a request. */
|
|
11
|
+
grantedBy?: string;
|
|
9
12
|
}
|
|
10
13
|
/** A user requests extra tokens for the current cycle (owner must approve). */
|
|
11
14
|
export declare function requestTopUp(adapter: BillingAdapter, orgId: string, req: {
|
|
@@ -22,6 +25,80 @@ export declare function approveTopUp(adapter: BillingAdapter, orgId: string, req
|
|
|
22
25
|
ok: boolean;
|
|
23
26
|
reason?: "not_found";
|
|
24
27
|
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Grant extra allowance to a member DIRECTLY, with no request to approve.
|
|
30
|
+
*
|
|
31
|
+
* The request→approve flow assumed the member notices the wall and asks. An admin
|
|
32
|
+
* looking at a usage screen has already noticed, and had no way to act: every path
|
|
33
|
+
* into a grant needed a `TopUpRequest` that only the member could create. This is
|
|
34
|
+
* that missing half.
|
|
35
|
+
*
|
|
36
|
+
* The grant is also recorded as an already-approved request, so it appears in the
|
|
37
|
+
* same history as the ones that were asked for. A grant that existed only as a
|
|
38
|
+
* number in `topUpGrants` would leave an allowance nobody could explain.
|
|
39
|
+
*
|
|
40
|
+
* `id` makes it idempotent: a double-clicked button grants once.
|
|
41
|
+
*/
|
|
42
|
+
export declare function grantTopUp(adapter: BillingAdapter, orgId: string, input: {
|
|
43
|
+
memberId: string;
|
|
44
|
+
amount: number;
|
|
45
|
+
/** MUST be the key the meter measures with — see `grantExtraAllowance`. */
|
|
46
|
+
cycle: string;
|
|
47
|
+
/** Who granted it, for the history. */
|
|
48
|
+
grantedBy?: string;
|
|
49
|
+
id?: string;
|
|
50
|
+
createdAt?: string;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
ok: boolean;
|
|
53
|
+
total: number;
|
|
54
|
+
reason?: "invalid_amount" | "duplicate";
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* The same grant, with the cycle resolved the way the METER resolves it.
|
|
58
|
+
*
|
|
59
|
+
* This is the part a caller must not be trusted with. A grant is stored under a
|
|
60
|
+
* cycle key and `resolveAllowance` looks it up under the key that
|
|
61
|
+
* `cycleWindowFor(model, subscriptionPeriod)` produces — the SUBSCRIPTION period
|
|
62
|
+
* when there is one, the calendar month otherwise. A caller passing a plausible
|
|
63
|
+
* "2026-08" for an org whose period starts on the 12th writes a grant that is
|
|
64
|
+
* never read, and nothing anywhere reports an error: the admin sees "granted",
|
|
65
|
+
* the member stays blocked. So the resolution lives here, once, and both the tool
|
|
66
|
+
* and any UI go through it.
|
|
67
|
+
*
|
|
68
|
+
* Returns `not_capped` for a plan that caps nothing per seat (a pool, or a pure
|
|
69
|
+
* wallet). There a grant is not merely useless, it is unreadable: the meter only
|
|
70
|
+
* adds extra allowance on top of a seat PACK, so it would be silently ignored.
|
|
71
|
+
*/
|
|
72
|
+
export declare function grantExtraAllowance(adapter: BillingAdapter, input: {
|
|
73
|
+
orgId: string;
|
|
74
|
+
plans: PlanCatalog;
|
|
75
|
+
plan?: string | null;
|
|
76
|
+
memberId: string;
|
|
77
|
+
/**
|
|
78
|
+
* Extra as a PERCENTAGE of the member's own seat pack (25 = +25%).
|
|
79
|
+
*
|
|
80
|
+
* The natural unit for this decision: "a quarter more than their seat" means
|
|
81
|
+
* the same thing on a 1 000-token seat and a 5 000-token one, where a fixed
|
|
82
|
+
* +250 is a rounding error on one and a third of the other. The pack is
|
|
83
|
+
* resolved here from the member's seat type, so no caller has to know it.
|
|
84
|
+
*/
|
|
85
|
+
percent?: number;
|
|
86
|
+
/** An absolute number of tokens instead. Exactly one of the two. */
|
|
87
|
+
amount?: number;
|
|
88
|
+
grantedBy?: string;
|
|
89
|
+
id?: string;
|
|
90
|
+
now?: number;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
ok: boolean;
|
|
93
|
+
/** The member's grand total for the cycle, after this grant. */
|
|
94
|
+
total?: number;
|
|
95
|
+
/** What this call actually added, in tokens. */
|
|
96
|
+
granted?: number;
|
|
97
|
+
/** The pack the percentage was taken from. */
|
|
98
|
+
packSize?: number;
|
|
99
|
+
cycle?: string;
|
|
100
|
+
reason?: "invalid_amount" | "not_capped" | "duplicate";
|
|
101
|
+
}>;
|
|
25
102
|
export declare function denyTopUp(adapter: BillingAdapter, orgId: string, requestId: string): Promise<{
|
|
26
103
|
ok: boolean;
|
|
27
104
|
reason?: "not_found";
|
|
@@ -29,5 +106,10 @@ export declare function denyTopUp(adapter: BillingAdapter, orgId: string, reques
|
|
|
29
106
|
/** A member's approved extra allowance for a cycle. The consumer reads this and
|
|
30
107
|
* passes it into `meterUsage` as `extraAllowance` so the meter adds it to the
|
|
31
108
|
* seat pack. */
|
|
32
|
-
export declare function extraAllowance(adapter: BillingAdapter, orgId: string, memberId: string, cycle: string
|
|
109
|
+
export declare function extraAllowance(adapter: BillingAdapter, orgId: string, memberId: string, cycle: string,
|
|
110
|
+
/** Key this library used before the cycle came from the subscription period.
|
|
111
|
+
* Consulted only when the current key has no entry, so a grant approved under
|
|
112
|
+
* the old scheme still applies and one approved under both is not counted
|
|
113
|
+
* twice. Removable once no live org has a pre-migration grant. */
|
|
114
|
+
legacyCycle?: string): Promise<number>;
|
|
33
115
|
//# sourceMappingURL=topup.d.ts.map
|
package/dist/topup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topup.d.ts","sourceRoot":"","sources":["../src/topup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"topup.d.ts","sourceRoot":"","sources":["../src/topup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAe1F,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAmBD,+EAA+E;AAC/E,wBAAsB,YAAY,CAChC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;I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CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GACA,OAAO,CAAC;IACT,EAAE,EAAE,OAAO,CAAC;IACZ,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,gBAAgB,GAAG,YAAY,GAAG,WAAW,CAAC;CACxD,CAAC,CAmCD;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC,CAOhD;AAED;;iBAEiB;AACjB,wBAAsB,cAAc,CAClC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM;AACb;;;mEAGmE;AACnE,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
package/dist/topup.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { cycleWindowFor, packSizeOf, planModel } from "./plan-model.js";
|
|
2
|
+
import { getSeatType } from "./seats.js";
|
|
1
3
|
// Top-up requests, stored entirely in the org's metadata via the adapter (no new
|
|
2
4
|
// database): a user-seat over its cap requests extra tokens → an owner approves →
|
|
3
5
|
// a per-member EXTRA ALLOWANCE for the current cycle that the meter adds on top of
|
|
@@ -47,6 +49,96 @@ export async function approveTopUp(adapter, orgId, requestId) {
|
|
|
47
49
|
await writeJson(adapter, orgId, GRANTS_KEY, grants);
|
|
48
50
|
return { ok: true };
|
|
49
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Grant extra allowance to a member DIRECTLY, with no request to approve.
|
|
54
|
+
*
|
|
55
|
+
* The request→approve flow assumed the member notices the wall and asks. An admin
|
|
56
|
+
* looking at a usage screen has already noticed, and had no way to act: every path
|
|
57
|
+
* into a grant needed a `TopUpRequest` that only the member could create. This is
|
|
58
|
+
* that missing half.
|
|
59
|
+
*
|
|
60
|
+
* The grant is also recorded as an already-approved request, so it appears in the
|
|
61
|
+
* same history as the ones that were asked for. A grant that existed only as a
|
|
62
|
+
* number in `topUpGrants` would leave an allowance nobody could explain.
|
|
63
|
+
*
|
|
64
|
+
* `id` makes it idempotent: a double-clicked button grants once.
|
|
65
|
+
*/
|
|
66
|
+
export async function grantTopUp(adapter, orgId, input) {
|
|
67
|
+
if (!Number.isFinite(input.amount) || input.amount <= 0) {
|
|
68
|
+
return { ok: false, total: 0, reason: "invalid_amount" };
|
|
69
|
+
}
|
|
70
|
+
const list = await readJson(adapter, orgId, REQUESTS_KEY, []);
|
|
71
|
+
if (input.id && list.some((r) => r.id === input.id)) {
|
|
72
|
+
const grants = await readJson(adapter, orgId, GRANTS_KEY, {});
|
|
73
|
+
return { ok: true, total: grants[input.memberId]?.[input.cycle] ?? 0, reason: "duplicate" };
|
|
74
|
+
}
|
|
75
|
+
const grants = await readJson(adapter, orgId, GRANTS_KEY, {});
|
|
76
|
+
grants[input.memberId] = grants[input.memberId] ?? {};
|
|
77
|
+
const total = (grants[input.memberId][input.cycle] ?? 0) + input.amount;
|
|
78
|
+
grants[input.memberId][input.cycle] = total;
|
|
79
|
+
list.push({
|
|
80
|
+
id: input.id ?? `grant_${input.memberId}_${input.cycle}_${input.amount}`,
|
|
81
|
+
memberId: input.memberId,
|
|
82
|
+
amount: input.amount,
|
|
83
|
+
cycle: input.cycle,
|
|
84
|
+
status: "approved",
|
|
85
|
+
createdAt: input.createdAt ?? new Date().toISOString(),
|
|
86
|
+
...(input.grantedBy ? { grantedBy: input.grantedBy } : {}),
|
|
87
|
+
});
|
|
88
|
+
await writeJson(adapter, orgId, REQUESTS_KEY, list.slice(-MAX_STORED_REQUESTS));
|
|
89
|
+
await writeJson(adapter, orgId, GRANTS_KEY, grants);
|
|
90
|
+
return { ok: true, total };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The same grant, with the cycle resolved the way the METER resolves it.
|
|
94
|
+
*
|
|
95
|
+
* This is the part a caller must not be trusted with. A grant is stored under a
|
|
96
|
+
* cycle key and `resolveAllowance` looks it up under the key that
|
|
97
|
+
* `cycleWindowFor(model, subscriptionPeriod)` produces — the SUBSCRIPTION period
|
|
98
|
+
* when there is one, the calendar month otherwise. A caller passing a plausible
|
|
99
|
+
* "2026-08" for an org whose period starts on the 12th writes a grant that is
|
|
100
|
+
* never read, and nothing anywhere reports an error: the admin sees "granted",
|
|
101
|
+
* the member stays blocked. So the resolution lives here, once, and both the tool
|
|
102
|
+
* and any UI go through it.
|
|
103
|
+
*
|
|
104
|
+
* Returns `not_capped` for a plan that caps nothing per seat (a pool, or a pure
|
|
105
|
+
* wallet). There a grant is not merely useless, it is unreadable: the meter only
|
|
106
|
+
* adds extra allowance on top of a seat PACK, so it would be silently ignored.
|
|
107
|
+
*/
|
|
108
|
+
export async function grantExtraAllowance(adapter, input) {
|
|
109
|
+
const model = planModel(input.plans, input.plan ?? null);
|
|
110
|
+
if (!model || model.cap.kind !== "per_seat")
|
|
111
|
+
return { ok: false, reason: "not_capped" };
|
|
112
|
+
// A percentage is meaningless without the pack it is a percentage OF, and the
|
|
113
|
+
// pack depends on the member's seat type, so resolve the seat the same way the
|
|
114
|
+
// meter does rather than assuming the default seat.
|
|
115
|
+
const seatType = (await getSeatType(adapter, input.orgId, input.memberId)) || "standard";
|
|
116
|
+
const packSize = packSizeOf(model, seatType);
|
|
117
|
+
if (packSize == null)
|
|
118
|
+
return { ok: false, reason: "not_capped" };
|
|
119
|
+
const amount = input.amount ??
|
|
120
|
+
(input.percent != null ? Math.round((packSize * input.percent) / 100) : NaN);
|
|
121
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
122
|
+
return { ok: false, reason: "invalid_amount", packSize };
|
|
123
|
+
}
|
|
124
|
+
let period = null;
|
|
125
|
+
try {
|
|
126
|
+
const sub = await adapter.getSubscription?.(input.orgId);
|
|
127
|
+
period = sub ? { start: sub.periodStart ?? null, end: sub.periodEnd ?? null } : null;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
period = null;
|
|
131
|
+
}
|
|
132
|
+
const cycle = cycleWindowFor(model, period, input.now ?? Date.now());
|
|
133
|
+
const res = await grantTopUp(adapter, input.orgId, {
|
|
134
|
+
memberId: input.memberId,
|
|
135
|
+
amount,
|
|
136
|
+
cycle: cycle.key,
|
|
137
|
+
grantedBy: input.grantedBy,
|
|
138
|
+
id: input.id,
|
|
139
|
+
});
|
|
140
|
+
return { ...res, granted: amount, packSize, cycle: cycle.key };
|
|
141
|
+
}
|
|
50
142
|
export async function denyTopUp(adapter, orgId, requestId) {
|
|
51
143
|
const list = await readJson(adapter, orgId, REQUESTS_KEY, []);
|
|
52
144
|
const req = list.find((r) => r.id === requestId);
|
|
@@ -59,8 +151,21 @@ export async function denyTopUp(adapter, orgId, requestId) {
|
|
|
59
151
|
/** A member's approved extra allowance for a cycle. The consumer reads this and
|
|
60
152
|
* passes it into `meterUsage` as `extraAllowance` so the meter adds it to the
|
|
61
153
|
* seat pack. */
|
|
62
|
-
export async function extraAllowance(adapter, orgId, memberId, cycle
|
|
154
|
+
export async function extraAllowance(adapter, orgId, memberId, cycle,
|
|
155
|
+
/** Key this library used before the cycle came from the subscription period.
|
|
156
|
+
* Consulted only when the current key has no entry, so a grant approved under
|
|
157
|
+
* the old scheme still applies and one approved under both is not counted
|
|
158
|
+
* twice. Removable once no live org has a pre-migration grant. */
|
|
159
|
+
legacyCycle) {
|
|
63
160
|
const grants = await readJson(adapter, orgId, GRANTS_KEY, {});
|
|
64
|
-
|
|
161
|
+
const forMember = grants[memberId];
|
|
162
|
+
if (!forMember)
|
|
163
|
+
return 0;
|
|
164
|
+
const current = forMember[cycle];
|
|
165
|
+
if (current !== undefined)
|
|
166
|
+
return current;
|
|
167
|
+
if (legacyCycle && forMember[legacyCycle] !== undefined)
|
|
168
|
+
return forMember[legacyCycle];
|
|
169
|
+
return 0;
|
|
65
170
|
}
|
|
66
171
|
//# sourceMappingURL=topup.js.map
|
package/dist/topup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topup.js","sourceRoot":"","sources":["../src/topup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"topup.js","sourceRoot":"","sources":["../src/topup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,iFAAiF;AACjF,kFAAkF;AAClF,mFAAmF;AACnF,+EAA+E;AAC/E,kFAAkF;AAClF,mFAAmF;AACnF,6EAA6E;AAE7E,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,qCAAqC;AAC3E,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,0DAA0D;AAC5F,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAe/B,KAAK,UAAU,QAAQ,CAAI,OAAuB,EAAE,KAAa,EAAE,GAAW,EAAE,QAAW;IACzF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG;QAAE,OAAO,QAAQ,CAAC;IAC1B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GA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,QAAQ,CAAiB,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;IAC9E,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IACjD,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAChF,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;IACtB,MAAM,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC;AAED;;iBAEiB;AACjB,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAuB,EACvB,KAAa,EACb,QAAgB,EAChB,KAAa;AACb;;;mEAGmE;AACnE,WAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAS,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,OAAO,CAAC,CAAC;IACzB,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC1C,IAAI,WAAW,IAAI,SAAS,CAAC,WAAW,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC;IACvF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -109,8 +109,25 @@ export interface BillingConfig {
|
|
|
109
109
|
* Default: unset, i.e. Stripe's English.
|
|
110
110
|
*/
|
|
111
111
|
defaultLocale?: string;
|
|
112
|
+
/**
|
|
113
|
+
* How to tax the charges the library raises on its OWN initiative — today the
|
|
114
|
+
* auto-reload invoice, which no form precedes.
|
|
115
|
+
*
|
|
116
|
+
* A subscription is taxed by whoever builds its Checkout Session, which is the
|
|
117
|
+
* app. An auto-reload has no session and no address form: it fires from the
|
|
118
|
+
* meter, so the only way for it to carry the same VAT as everything else the
|
|
119
|
+
* account bills is for the deployment to say here how to work the rate out.
|
|
120
|
+
* Leave unset only on an account that charges no tax at all — `checkBillingSetup`
|
|
121
|
+
* warns when a taxed account is auto-reloading untaxed.
|
|
122
|
+
*/
|
|
123
|
+
tax?: {
|
|
124
|
+
/** Stripe TaxRate ids for this customer, e.g. from `taxRatesFor`. */
|
|
125
|
+
rates?: (stripeCustomerId: string) => Promise<string[]> | string[];
|
|
126
|
+
/** Use Stripe Tax instead. Ignored when `rates` returns any. */
|
|
127
|
+
automatic?: boolean;
|
|
128
|
+
};
|
|
112
129
|
}
|
|
113
|
-
export type ResolvedConfig = Required<BillingConfig>;
|
|
130
|
+
export type ResolvedConfig = Required<Omit<BillingConfig, "tax">> & Pick<BillingConfig, "tax">;
|
|
114
131
|
export declare function resolveConfig(c: BillingConfig): ResolvedConfig;
|
|
115
132
|
/** Build the `internalDomains` allowlist from the environment: an optional
|
|
116
133
|
* deployment root domain (whatever your host exposes — pass it if you want the
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC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IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CAAC"}
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,mBAAmB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,mBAAmB;AA0InB,MAAM,UAAU,aAAa,CAAC,CAAgB;IAC5C,OAAO;QACL,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,GAAG;QAC/B,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,KAAK;QAC7B,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,eAAe,EAAE,CAAC,CAAC,eAAe,IAAI,EAAE;QACxC,aAAa,EAAE,CAAC,CAAC,aAAa,IAAI,EAAE;QACpC,GAAG,EAAE,CAAC,CAAC,GAAG;KACX,CAAC;AACJ,CAAC;AAED;;;;;;mDAMmD;AACnD,MAAM,UAAU,sBAAsB,CACpC,UAA0B,EAC1B,MAAM,GAAG,sBAAsB;IAE/B,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SACvC,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;SAClC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnaudjnn/billing-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "The get-paid engine for Stripe + WorkOS apps, for humans and AI agents. Drop-in API-key auth, token/credit + subscription billing, auth.md agent registration, and MPP machine payments, as MCP tools, a REST API, and a CLI. Framework-agnostic, storage-pluggable.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Arnaud Jeannin",
|
|
@@ -78,7 +78,8 @@
|
|
|
78
78
|
"build": "tsc",
|
|
79
79
|
"typecheck": "tsc --noEmit",
|
|
80
80
|
"clean": "rm -rf dist",
|
|
81
|
-
"prepublishOnly": "npm run build"
|
|
81
|
+
"prepublishOnly": "npm run build",
|
|
82
|
+
"test": "npm run build && node --test \"test/*.test.mjs\""
|
|
82
83
|
},
|
|
83
84
|
"dependencies": {
|
|
84
85
|
"@stripe/react-stripe-js": "^6",
|