@venturekit-pro/billing 0.0.42 → 0.0.43

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.
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Metered allowances — the pure rules.
3
+ *
4
+ * A **meter** counts something a subject (a tenant, a customer) consumes and pays for:
5
+ * WhatsApp messages, SMS, AI tokens, API calls. Every period (a month, usually) the
6
+ * subject gets an **included** quantity — the plan's limit, or one negotiated for it — and
7
+ * on top of it **credits**: units bought in packs, granted, or topped up automatically.
8
+ *
9
+ * A unit consumed is paid, in this order, from:
10
+ *
11
+ * 1. what the period includes;
12
+ * 2. credits — the soonest to expire first;
13
+ * 3. **debt** — nothing left. By default only an *exempt* consumption gets here (a safety
14
+ * alert, a sign-in code: things a product must never refuse); with
15
+ * `overage: { allow: 'all' }` anyone may, up to `maxDebt` (pay as you go). Debt is
16
+ * never free: it is taken from the next credits that arrive, which is what an
17
+ * automatic top-up ({@link topUpFor}) exists to provide.
18
+ *
19
+ * What credits are worth in a period is a **replay** ({@link openingCredits}): every credit
20
+ * entry (a lot) in the period it was made, every earlier period's draws, in order — so a
21
+ * lot can expire (`expiresAfterPeriods`: 1 = the month it was bought in, 12 = a year, 0 =
22
+ * never), a void can take back what was already spent (that becomes debt), and an unused
23
+ * included quantity can be carried over to the next periods ({@link CarryOverPolicy}).
24
+ * Without expiry or carry-over the replay is the plain running total: credits bought, less
25
+ * credits spent.
26
+ *
27
+ * Everything here is arithmetic; `meter.ts` reads and writes the counters around it. Costs
28
+ * are whole units: a product that prices categories differently (a Meta *marketing* message
29
+ * worth five *utility* ones) passes the cost per consumption.
30
+ */
31
+ export type MeterPeriod = 'day' | 'week' | 'month' | 'year';
32
+ export interface PeriodOptions {
33
+ /** IANA zone the periods follow (`Africa/Casablanca`): a month starts at local midnight on the 1st. Default UTC. */
34
+ timeZone?: string;
35
+ }
36
+ /**
37
+ * The period an instant is counted in: `2026-10-04`, `2026-W40` (ISO week), `2026-10`,
38
+ * `2026` — in UTC, or in `timeZone`. Keys of one meter sort chronologically as strings.
39
+ */
40
+ export declare function periodKey(at: Date, period?: MeterPeriod, options?: PeriodOptions): string;
41
+ /** The key before every period: what a running total with no history is dated. */
42
+ export declare const BEFORE_ANY_PERIOD = "";
43
+ /**
44
+ * A period's ordinal: consecutive periods differ by one, so "the lot is good for 3 periods"
45
+ * is arithmetic. {@link BEFORE_ANY_PERIOD} is `-Infinity`.
46
+ */
47
+ export declare function periodIndex(key: string, period?: MeterPeriod): number;
48
+ /** The key of the period with ordinal `index` — {@link periodIndex}'s inverse. */
49
+ export declare function periodFromIndex(index: number, period?: MeterPeriod): string;
50
+ /** `key` moved by `n` periods (negative = earlier). */
51
+ export declare function shiftPeriod(key: string, n: number, period?: MeterPeriod): string;
52
+ /** A credit entry as the replay reads it. */
53
+ export interface CreditLot {
54
+ /** Signed: a purchase or a grant adds, a void takes back. */
55
+ units: number;
56
+ /** The period it was made in; {@link BEFORE_ANY_PERIOD} for a running total with no history. */
57
+ period: string;
58
+ /**
59
+ * How many periods it can be spent in, the one it was made in included: `1` = that period
60
+ * only, `12` = a year, `0` = never expires. `null` / absent = the meter's
61
+ * {@link CreditPolicy}. Ignored on a void.
62
+ */
63
+ expiresAfterPeriods?: number | null;
64
+ }
65
+ export interface CreditPolicy {
66
+ /** The default life of a lot, in periods (`1` = credits expire with the period they were bought in). Absent or `0` = they roll over until spent. */
67
+ expiresAfterPeriods?: number;
68
+ }
69
+ /**
70
+ * Unused included quantity carried over: what a period included and did not use becomes a
71
+ * lot of the next period — capped at `max`, good for `expiresAfterPeriods` periods (default
72
+ * 1: the next period only, so it never snowballs).
73
+ */
74
+ export interface CarryOverPolicy {
75
+ max?: number;
76
+ expiresAfterPeriods?: number;
77
+ }
78
+ /** One earlier period's counters, as the replay reads them. */
79
+ export interface PeriodUsage {
80
+ period: string;
81
+ included: number;
82
+ used: number;
83
+ fromCredits: number;
84
+ onDebt: number;
85
+ }
86
+ export interface OpeningCredits {
87
+ /** Credits usable in the period before its own draws, net of any debt carried in — negative when more is owed than there is. */
88
+ opening: number;
89
+ /** Of `opening`, the units that expire at the end of the period (spent first). */
90
+ expiring: number;
91
+ }
92
+ export interface ReplayInput {
93
+ period: string;
94
+ kind?: MeterPeriod;
95
+ lots: readonly CreditLot[];
96
+ history: readonly PeriodUsage[];
97
+ credits?: CreditPolicy;
98
+ carryOver?: CarryOverPolicy;
99
+ /**
100
+ * What a period nobody consumed in included — it has no counters, and its whole quantity
101
+ * is carried over. Only asked for the periods {@link carryOverSources} names; `0` when absent.
102
+ */
103
+ includedOf?: (period: string) => number;
104
+ }
105
+ /**
106
+ * The periods with no counters whose included quantity the replay needs ({@link ReplayInput}
107
+ * `includedOf`): with carry-over on, a period nobody consumed in still carries its whole
108
+ * quantity to the next ones.
109
+ */
110
+ export declare function carryOverSources(input: ReplayInput): string[];
111
+ /**
112
+ * What credits are worth in `period`: the replay of every lot and every earlier period's
113
+ * draws (`fromCredits + onDebt`), period by period. In each one, lots arrive (with the
114
+ * carry-over of the period before), the expired ones go, voids are taken back (the newest
115
+ * lots first; what they had already paid becomes debt), the debt carried in is paid, then
116
+ * the period's draws — every take from the lot that expires soonest.
117
+ */
118
+ export declare function openingCredits(input: ReplayInput): OpeningCredits;
119
+ /** A meter's state for one subject and one period. Every figure is whole units. */
120
+ export interface MeterBalance {
121
+ period: string;
122
+ /** What the period includes (0 = nothing: credits only). */
123
+ included: number;
124
+ /** Everything consumed this period, whichever bucket paid. */
125
+ used: number;
126
+ /** Of `used`: paid with credits. */
127
+ fromCredits: number;
128
+ /** Of `used`: consumed with nothing left — owed, and taken from the next credits. */
129
+ onDebt: number;
130
+ /** Credits usable this period before its own draws, net of debt carried in ({@link openingCredits}). */
131
+ opening: number;
132
+ /** Of `opening`, the units that expire at the end of the period. */
133
+ expiring: number;
134
+ /** Every credit ever added, net of voids — what an automatic top-up's key is built on. */
135
+ credits: number;
136
+ }
137
+ /** How one consumption was paid. */
138
+ export interface MeterSplit {
139
+ included: number;
140
+ credits: number;
141
+ debt: number;
142
+ }
143
+ export declare const NO_SPLIT: MeterSplit;
144
+ /** What is left of the period's included quantity. A limit lowered under what was used leaves nothing, not a debt. */
145
+ export declare function includedLeft(b: MeterBalance): number;
146
+ /** Credits still available. */
147
+ export declare function creditsLeft(b: MeterBalance): number;
148
+ /** Of the credits left, the ones that expire at the end of the period. */
149
+ export declare function expiringLeft(b: MeterBalance): number;
150
+ /** What is owed: units consumed with nothing left (or credits voided after they were spent) that no credit has covered yet. */
151
+ export declare function debtOf(b: MeterBalance): number;
152
+ /** Every unit the subject can still consume without debt. */
153
+ export declare function remainingOf(b: MeterBalance): number;
154
+ /** How a consumption of `cost` units would be paid: included first, then credits, the rest on debt. */
155
+ export declare function splitOf(b: MeterBalance, cost?: number): MeterSplit;
156
+ /** The balance once `split` was consumed. */
157
+ export declare function afterConsume(b: MeterBalance, split: MeterSplit): MeterBalance;
158
+ /** The balance once `split` was given back (a send the provider refused). Clamped at zero. */
159
+ export declare function afterRelease(b: MeterBalance, split: MeterSplit): MeterBalance;
160
+ /**
161
+ * Who may consume with nothing left. `exempt` (the default): only exempt consumptions,
162
+ * everyone else is refused. `all`: pay as you go — anyone, while what is owed stays within
163
+ * `maxDebt` (absent = no cap). Exempt consumptions are never refused either way.
164
+ */
165
+ export interface OveragePolicy {
166
+ allow?: 'exempt' | 'all';
167
+ maxDebt?: number;
168
+ }
169
+ export interface GateInput {
170
+ /** Units the consumption costs (default 1). */
171
+ cost?: number;
172
+ /** Never refused: lands on debt when nothing is left. */
173
+ exempt?: boolean;
174
+ /** Units already promised to work not consumed yet (messages queued): they are spoken for. */
175
+ reserved?: number;
176
+ overage?: OveragePolicy;
177
+ }
178
+ export interface GateDecision {
179
+ allowed: boolean;
180
+ /** Units available once `reserved` is set aside. */
181
+ available: number;
182
+ /** Why a refusal: nothing left, not enough for this cost, or the debt cap reached. */
183
+ reason?: 'exhausted' | 'insufficient' | 'debt_limit';
184
+ }
185
+ /**
186
+ * Whether a consumption may go ahead. An exempt one always may; any other needs `cost`
187
+ * units free once `reserved` is set aside — or, paying as it goes, room under `maxDebt` for
188
+ * what would be owed once the reserved units and this one are consumed.
189
+ */
190
+ export declare function gate(b: MeterBalance, input?: GateInput): GateDecision;
191
+ /** `included:80` (80 % of the period's quantity used), `exhausted@<credits>` (nothing left), `debt@<credits>` (a debt began). */
192
+ export type MeterAlertKind = 'threshold' | 'exhausted' | 'debt';
193
+ export interface MeterAlert {
194
+ key: string;
195
+ kind: MeterAlertKind;
196
+ /** The threshold's fraction, for `threshold`. */
197
+ threshold?: number;
198
+ }
199
+ /**
200
+ * The alerts a consumption crossed, minus those already sent (`claimed`): each threshold
201
+ * of the included quantity once per period; "nothing left" and "a debt began" once per
202
+ * period **and credit level** — so a subject that buys more and runs out again hears it again.
203
+ */
204
+ export declare function alertsCrossed(before: MeterBalance, after: MeterBalance, thresholds?: readonly number[], claimed?: readonly string[]): MeterAlert[];
205
+ export interface TopUpPolicy {
206
+ /** Units in one automatic pack. */
207
+ packSize: number;
208
+ /** Also top up — not only on debt — when fewer than this many units remain (auto-recharge). */
209
+ below?: number;
210
+ }
211
+ export interface TopUpRequest {
212
+ packs: number;
213
+ units: number;
214
+ /**
215
+ * Stable while the credits have not changed: every caller that sees the same shortfall
216
+ * asks with the same key, so the purchase side buys once however many consumptions
217
+ * notice it before the new credits arrive.
218
+ */
219
+ idempotencyKey: string;
220
+ }
221
+ /** The packs of `packSize` that cover `units` (at least one). */
222
+ export declare function packsFor(units: number, packSize: number): number;
223
+ /**
224
+ * The automatic pack a balance calls for, or `null`: enough packs to cover the debt (and,
225
+ * with `below`, to climb back above it). Pure — who pays, and how it is invoiced, is the
226
+ * caller's.
227
+ */
228
+ export declare function topUpFor(b: MeterBalance, policy: TopUpPolicy): TopUpRequest | null;
229
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/meters/rules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C,EAAE,WAAW,GAAG,cAAc,GAAG,YAAY,CAAC;CACtD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAE,SAAc,GAAG,YAAY,CAazE;AAID,iIAAiI;AACjI,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,WAAW,GAAG,MAAM,CAAC;AAEhE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,cAAc,CAAC;IACrB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,GAAE,SAAS,MAAM,EAAU,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,UAAU,EAAE,CAa7J;AAID,MAAM,WAAW,WAAW;IAC1B,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAOlF"}
@@ -0,0 +1,348 @@
1
+ /**
2
+ * Metered allowances — the pure rules.
3
+ *
4
+ * A **meter** counts something a subject (a tenant, a customer) consumes and pays for:
5
+ * WhatsApp messages, SMS, AI tokens, API calls. Every period (a month, usually) the
6
+ * subject gets an **included** quantity — the plan's limit, or one negotiated for it — and
7
+ * on top of it **credits**: units bought in packs, granted, or topped up automatically.
8
+ *
9
+ * A unit consumed is paid, in this order, from:
10
+ *
11
+ * 1. what the period includes;
12
+ * 2. credits — the soonest to expire first;
13
+ * 3. **debt** — nothing left. By default only an *exempt* consumption gets here (a safety
14
+ * alert, a sign-in code: things a product must never refuse); with
15
+ * `overage: { allow: 'all' }` anyone may, up to `maxDebt` (pay as you go). Debt is
16
+ * never free: it is taken from the next credits that arrive, which is what an
17
+ * automatic top-up ({@link topUpFor}) exists to provide.
18
+ *
19
+ * What credits are worth in a period is a **replay** ({@link openingCredits}): every credit
20
+ * entry (a lot) in the period it was made, every earlier period's draws, in order — so a
21
+ * lot can expire (`expiresAfterPeriods`: 1 = the month it was bought in, 12 = a year, 0 =
22
+ * never), a void can take back what was already spent (that becomes debt), and an unused
23
+ * included quantity can be carried over to the next periods ({@link CarryOverPolicy}).
24
+ * Without expiry or carry-over the replay is the plain running total: credits bought, less
25
+ * credits spent.
26
+ *
27
+ * Everything here is arithmetic; `meter.ts` reads and writes the counters around it. Costs
28
+ * are whole units: a product that prices categories differently (a Meta *marketing* message
29
+ * worth five *utility* ones) passes the cost per consumption.
30
+ */
31
+ const DAY_MS = 86_400_000;
32
+ const pad = (n, width = 2) => String(n).padStart(width, '0');
33
+ /** The calendar date of `at` in `timeZone` (UTC when absent). */
34
+ function localDate(at, timeZone) {
35
+ if (!timeZone || timeZone === 'UTC')
36
+ return { y: at.getUTCFullYear(), m: at.getUTCMonth() + 1, d: at.getUTCDate() };
37
+ const parts = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(at);
38
+ const part = (type) => Number(parts.find((p) => p.type === type)?.value);
39
+ return { y: part('year'), m: part('month'), d: part('day') };
40
+ }
41
+ function isoWeek(y, m, d) {
42
+ /* ISO 8601: the week with the year's first Thursday is week 1 */
43
+ const date = new Date(Date.UTC(y, m - 1, d));
44
+ const day = date.getUTCDay() || 7;
45
+ date.setUTCDate(date.getUTCDate() + 4 - day);
46
+ const yearStart = Date.UTC(date.getUTCFullYear(), 0, 1);
47
+ return { year: date.getUTCFullYear(), week: Math.ceil(((date.getTime() - yearStart) / DAY_MS + 1) / 7) };
48
+ }
49
+ /**
50
+ * The period an instant is counted in: `2026-10-04`, `2026-W40` (ISO week), `2026-10`,
51
+ * `2026` — in UTC, or in `timeZone`. Keys of one meter sort chronologically as strings.
52
+ */
53
+ export function periodKey(at, period = 'month', options = {}) {
54
+ const { y, m, d } = localDate(at, options.timeZone);
55
+ switch (period) {
56
+ case 'day':
57
+ return `${y}-${pad(m)}-${pad(d)}`;
58
+ case 'month':
59
+ return `${y}-${pad(m)}`;
60
+ case 'year':
61
+ return String(y);
62
+ case 'week': {
63
+ const w = isoWeek(y, m, d);
64
+ return `${w.year}-W${pad(w.week)}`;
65
+ }
66
+ }
67
+ }
68
+ /** The key before every period: what a running total with no history is dated. */
69
+ export const BEFORE_ANY_PERIOD = '';
70
+ /**
71
+ * A period's ordinal: consecutive periods differ by one, so "the lot is good for 3 periods"
72
+ * is arithmetic. {@link BEFORE_ANY_PERIOD} is `-Infinity`.
73
+ */
74
+ export function periodIndex(key, period = 'month') {
75
+ if (key === BEFORE_ANY_PERIOD)
76
+ return Number.NEGATIVE_INFINITY;
77
+ switch (period) {
78
+ case 'year':
79
+ return Number(key);
80
+ case 'month':
81
+ return Number(key.slice(0, 4)) * 12 + Number(key.slice(5, 7)) - 1;
82
+ case 'day':
83
+ return Date.UTC(Number(key.slice(0, 4)), Number(key.slice(5, 7)) - 1, Number(key.slice(8, 10))) / DAY_MS;
84
+ case 'week': {
85
+ /* the Monday of ISO week 1 is the Monday on or before 4 January */
86
+ const year = Number(key.slice(0, 4));
87
+ const jan4 = Date.UTC(year, 0, 4) / DAY_MS;
88
+ const jan4Day = new Date(jan4 * DAY_MS).getUTCDay() || 7;
89
+ const monday = jan4 - (jan4Day - 1) + (Number(key.slice(6)) - 1) * 7;
90
+ /* 1970-01-05 (epoch day 4) was a Monday */
91
+ return (monday - 4) / 7;
92
+ }
93
+ }
94
+ }
95
+ /** The key of the period with ordinal `index` — {@link periodIndex}'s inverse. */
96
+ export function periodFromIndex(index, period = 'month') {
97
+ switch (period) {
98
+ case 'year':
99
+ return String(index);
100
+ case 'month':
101
+ return `${Math.floor(index / 12)}-${pad((((index % 12) + 12) % 12) + 1)}`;
102
+ case 'day':
103
+ return new Date(index * DAY_MS).toISOString().slice(0, 10);
104
+ case 'week':
105
+ return periodKey(new Date((index * 7 + 4) * DAY_MS), 'week');
106
+ }
107
+ }
108
+ /** `key` moved by `n` periods (negative = earlier). */
109
+ export function shiftPeriod(key, n, period = 'month') {
110
+ return periodFromIndex(periodIndex(key, period) + n, period);
111
+ }
112
+ const whole = (n) => (Number.isFinite(n) && n > 0 ? Math.floor(n) : 0);
113
+ function indexed(input) {
114
+ const kind = input.kind ?? 'month';
115
+ const current = periodIndex(input.period, kind);
116
+ const rows = new Map();
117
+ for (const h of input.history) {
118
+ const i = periodIndex(h.period, kind);
119
+ if (i < current)
120
+ rows.set(i, h);
121
+ }
122
+ const at = new Map();
123
+ for (const lot of input.lots) {
124
+ const i = periodIndex(lot.period, kind);
125
+ if (i > current || !Number.isInteger(lot.units) || lot.units === 0)
126
+ continue;
127
+ at.set(i, [...(at.get(i) ?? []), lot]);
128
+ }
129
+ return { current, rows, at };
130
+ }
131
+ /** The periods whose unused quantity can still be carried into one the replay visits: up to `expiresAfterPeriods` before each, never before the subject's first known period. */
132
+ function carryIndexes(input, x) {
133
+ if (!input.carryOver)
134
+ return [];
135
+ const life = Math.max(1, whole(input.carryOver.expiresAfterPeriods ?? 1));
136
+ const known = [...x.rows.keys(), ...[...x.at.keys()].filter(Number.isFinite)];
137
+ const first = known.length > 0 ? Math.min(...known) : x.current;
138
+ const out = new Set();
139
+ for (const r of [x.current, ...x.rows.keys()]) {
140
+ for (let k = 1; k <= life; k++)
141
+ if (r - k >= first)
142
+ out.add(r - k);
143
+ }
144
+ return [...out].sort((a, b) => a - b);
145
+ }
146
+ /**
147
+ * The periods with no counters whose included quantity the replay needs ({@link ReplayInput}
148
+ * `includedOf`): with carry-over on, a period nobody consumed in still carries its whole
149
+ * quantity to the next ones.
150
+ */
151
+ export function carryOverSources(input) {
152
+ const x = indexed(input);
153
+ return carryIndexes(input, x)
154
+ .filter((i) => !x.rows.has(i))
155
+ .map((i) => periodFromIndex(i, input.kind ?? 'month'));
156
+ }
157
+ /**
158
+ * What credits are worth in `period`: the replay of every lot and every earlier period's
159
+ * draws (`fromCredits + onDebt`), period by period. In each one, lots arrive (with the
160
+ * carry-over of the period before), the expired ones go, voids are taken back (the newest
161
+ * lots first; what they had already paid becomes debt), the debt carried in is paid, then
162
+ * the period's draws — every take from the lot that expires soonest.
163
+ */
164
+ export function openingCredits(input) {
165
+ const kind = input.kind ?? 'month';
166
+ const x = indexed(input);
167
+ const { current, rows, at } = x;
168
+ const defaultLife = whole(input.credits?.expiresAfterPeriods ?? 0);
169
+ const sources = new Set(carryIndexes(input, x));
170
+ const steps = new Set([current, ...at.keys(), ...rows.keys(), ...[...sources].map((i) => i + 1)]);
171
+ let pool = [];
172
+ let debt = 0;
173
+ let seq = 0;
174
+ /* soonest to expire first; among equals, the oldest */
175
+ const take = (units) => {
176
+ let need = units;
177
+ pool.sort((a, b) => a.last - b.last || a.seq - b.seq);
178
+ for (const held of pool) {
179
+ if (need === 0)
180
+ break;
181
+ const n = Math.min(need, held.left);
182
+ held.left -= n;
183
+ need -= n;
184
+ }
185
+ pool = pool.filter((h) => h.left > 0);
186
+ return need;
187
+ };
188
+ for (const i of [...steps].sort((a, b) => a - b)) {
189
+ for (const lot of at.get(i) ?? []) {
190
+ if (lot.units <= 0)
191
+ continue;
192
+ const life = lot.expiresAfterPeriods === null || lot.expiresAfterPeriods === undefined ? defaultLife : whole(lot.expiresAfterPeriods);
193
+ /* a running total with no date cannot expire */
194
+ const last = life === 0 || i === Number.NEGATIVE_INFINITY ? Number.POSITIVE_INFINITY : i + life - 1;
195
+ pool.push({ left: lot.units, last, seq: seq++ });
196
+ }
197
+ const before = sources.has(i - 1) ? rows.get(i - 1) ?? { period: periodFromIndex(i - 1, kind), included: whole(input.includedOf?.(periodFromIndex(i - 1, kind)) ?? 0), used: 0, fromCredits: 0, onDebt: 0 } : null;
198
+ if (input.carryOver && before) {
199
+ const unused = Math.max(0, whole(before.included) - (before.used - before.fromCredits - before.onDebt));
200
+ const units = input.carryOver.max === undefined ? unused : Math.min(unused, whole(input.carryOver.max));
201
+ if (units > 0)
202
+ pool.push({ left: units, last: i + Math.max(1, whole(input.carryOver.expiresAfterPeriods ?? 1)) - 1, seq: seq++, carried: true });
203
+ }
204
+ pool = pool.filter((h) => h.last >= i && h.left > 0);
205
+ /* a void takes back the newest bought units first; what they had already paid is owed again */
206
+ for (const lot of at.get(i) ?? []) {
207
+ if (lot.units >= 0)
208
+ continue;
209
+ let need = -lot.units;
210
+ pool.sort((a, b) => b.seq - a.seq);
211
+ for (const held of pool) {
212
+ if (need === 0)
213
+ break;
214
+ if (held.carried)
215
+ continue;
216
+ const n = Math.min(need, held.left);
217
+ held.left -= n;
218
+ need -= n;
219
+ }
220
+ pool = pool.filter((h) => h.left > 0);
221
+ debt += need;
222
+ }
223
+ debt = take(debt);
224
+ const row = rows.get(i);
225
+ if (row)
226
+ debt += take(row.fromCredits + row.onDebt);
227
+ }
228
+ const total = pool.reduce((n, h) => n + h.left, 0);
229
+ const expiring = pool.filter((h) => h.last === current).reduce((n, h) => n + h.left, 0);
230
+ return { opening: total - debt, expiring };
231
+ }
232
+ export const NO_SPLIT = Object.freeze({ included: 0, credits: 0, debt: 0 });
233
+ const drawn = (b) => b.fromCredits + b.onDebt;
234
+ /** What is left of the period's included quantity. A limit lowered under what was used leaves nothing, not a debt. */
235
+ export function includedLeft(b) {
236
+ return Math.max(0, whole(b.included) - (b.used - b.fromCredits - b.onDebt));
237
+ }
238
+ /** Credits still available. */
239
+ export function creditsLeft(b) {
240
+ return Math.max(0, b.opening - drawn(b));
241
+ }
242
+ /** Of the credits left, the ones that expire at the end of the period. */
243
+ export function expiringLeft(b) {
244
+ return Math.min(creditsLeft(b), Math.max(0, b.expiring - drawn(b)));
245
+ }
246
+ /** What is owed: units consumed with nothing left (or credits voided after they were spent) that no credit has covered yet. */
247
+ export function debtOf(b) {
248
+ return Math.max(0, drawn(b) - b.opening);
249
+ }
250
+ /** Every unit the subject can still consume without debt. */
251
+ export function remainingOf(b) {
252
+ return includedLeft(b) + creditsLeft(b);
253
+ }
254
+ /** How a consumption of `cost` units would be paid: included first, then credits, the rest on debt. */
255
+ export function splitOf(b, cost = 1) {
256
+ const units = Math.max(1, whole(cost));
257
+ const included = Math.min(units, includedLeft(b));
258
+ const credits = Math.min(units - included, creditsLeft(b));
259
+ return { included, credits, debt: units - included - credits };
260
+ }
261
+ /** The balance once `split` was consumed. */
262
+ export function afterConsume(b, split) {
263
+ return {
264
+ ...b,
265
+ used: b.used + split.included + split.credits + split.debt,
266
+ fromCredits: b.fromCredits + split.credits,
267
+ onDebt: b.onDebt + split.debt,
268
+ };
269
+ }
270
+ /** The balance once `split` was given back (a send the provider refused). Clamped at zero. */
271
+ export function afterRelease(b, split) {
272
+ const total = split.included + split.credits + split.debt;
273
+ return {
274
+ ...b,
275
+ used: Math.max(0, b.used - total),
276
+ fromCredits: Math.max(0, b.fromCredits - split.credits),
277
+ onDebt: Math.max(0, b.onDebt - split.debt),
278
+ };
279
+ }
280
+ /**
281
+ * Whether a consumption may go ahead. An exempt one always may; any other needs `cost`
282
+ * units free once `reserved` is set aside — or, paying as it goes, room under `maxDebt` for
283
+ * what would be owed once the reserved units and this one are consumed.
284
+ */
285
+ export function gate(b, input = {}) {
286
+ const cost = Math.max(1, whole(input.cost ?? 1));
287
+ const reserved = whole(input.reserved ?? 0);
288
+ const remaining = remainingOf(b);
289
+ const available = Math.max(0, remaining - reserved);
290
+ if (input.exempt || available >= cost)
291
+ return { allowed: true, available };
292
+ if (input.overage?.allow === 'all') {
293
+ if (input.overage.maxDebt === undefined)
294
+ return { allowed: true, available };
295
+ const owed = debtOf(b) + Math.max(0, reserved + cost - remaining);
296
+ if (owed <= whole(input.overage.maxDebt))
297
+ return { allowed: true, available };
298
+ return { allowed: false, available, reason: 'debt_limit' };
299
+ }
300
+ return { allowed: false, available, reason: available === 0 ? 'exhausted' : 'insufficient' };
301
+ }
302
+ const usedOfIncluded = (b) => b.used - b.fromCredits - b.onDebt;
303
+ /**
304
+ * The alerts a consumption crossed, minus those already sent (`claimed`): each threshold
305
+ * of the included quantity once per period; "nothing left" and "a debt began" once per
306
+ * period **and credit level** — so a subject that buys more and runs out again hears it again.
307
+ */
308
+ export function alertsCrossed(before, after, thresholds = [0.8], claimed = []) {
309
+ const out = [];
310
+ const included = whole(after.included);
311
+ if (included > 0) {
312
+ for (const t of thresholds) {
313
+ if (!(t > 0 && t <= 1))
314
+ continue;
315
+ const mark = included * t;
316
+ if (usedOfIncluded(before) < mark && usedOfIncluded(after) >= mark)
317
+ out.push({ key: `included:${Math.round(t * 100)}`, kind: 'threshold', threshold: t });
318
+ }
319
+ }
320
+ if (remainingOf(before) > 0 && remainingOf(after) === 0)
321
+ out.push({ key: `exhausted@${after.credits}`, kind: 'exhausted' });
322
+ if (debtOf(before) === 0 && debtOf(after) > 0)
323
+ out.push({ key: `debt@${after.credits}`, kind: 'debt' });
324
+ return out.filter((a) => !claimed.includes(a.key));
325
+ }
326
+ /** The packs of `packSize` that cover `units` (at least one). */
327
+ export function packsFor(units, packSize) {
328
+ const size = whole(packSize);
329
+ if (size === 0)
330
+ throw new Error('packsFor: packSize must be a positive whole number');
331
+ return Math.max(1, Math.ceil(Math.max(0, units) / size));
332
+ }
333
+ /**
334
+ * The automatic pack a balance calls for, or `null`: enough packs to cover the debt (and,
335
+ * with `below`, to climb back above it). Pure — who pays, and how it is invoiced, is the
336
+ * caller's.
337
+ */
338
+ export function topUpFor(b, policy) {
339
+ if (whole(policy.packSize) === 0)
340
+ return null;
341
+ const short = policy.below !== undefined ? Math.max(0, whole(policy.below) - remainingOf(b)) : 0;
342
+ const need = debtOf(b) + short;
343
+ if (need === 0)
344
+ return null;
345
+ const packs = packsFor(need, policy.packSize);
346
+ return { packs, units: packs * whole(policy.packSize), idempotencyKey: `topup@${b.credits}` };
347
+ }
348
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/meters/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AASH,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,KAAK,GAAG,CAAC,EAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAE7E,iEAAiE;AACjE,SAAS,SAAS,CAAC,EAAQ,EAAE,QAAiB;IAC5C,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC;IACpH,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAClI,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACzF,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,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