@zonastery/bursar 1.0.0 → 1.0.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/README.md +108 -64
- package/dist/billing/auto-recharge-port.js.map +1 -1
- package/dist/billing/auto-recharge-service.js.map +1 -1
- package/dist/billing/billing-service.js.map +1 -1
- package/dist/billing/billing-store.d.ts +2 -2
- package/dist/billing/billing-store.d.ts.map +1 -1
- package/dist/billing/billing-store.js.map +1 -1
- package/dist/billing/contracts.js.map +1 -1
- package/dist/billing/event-handlers.d.ts.map +1 -1
- package/dist/billing/event-handlers.js +21 -4
- package/dist/billing/event-handlers.js.map +1 -1
- package/dist/billing/event-processor.d.ts +1 -0
- package/dist/billing/event-processor.d.ts.map +1 -1
- package/dist/billing/event-processor.js +35 -9
- package/dist/billing/event-processor.js.map +1 -1
- package/dist/billing/financial-event-handlers.js.map +1 -1
- package/dist/billing/index.d.ts +1 -0
- package/dist/billing/index.d.ts.map +1 -1
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/management.js.map +1 -1
- package/dist/billing/policy-window.js.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/auto-recharge.js +3 -1
- package/dist/billing/postgres/repositories/auto-recharge.js.map +1 -1
- package/dist/billing/postgres/repositories/customer.js.map +1 -1
- package/dist/billing/postgres/repositories/dispute.js.map +1 -1
- package/dist/billing/postgres/repositories/event.d.ts +2 -2
- package/dist/billing/postgres/repositories/event.d.ts.map +1 -1
- package/dist/billing/postgres/repositories/event.js +10 -12
- package/dist/billing/postgres/repositories/event.js.map +1 -1
- package/dist/billing/postgres/repositories/invoice.js.map +1 -1
- package/dist/billing/postgres/repositories/offer.js.map +1 -1
- package/dist/billing/postgres/repositories/payment.js.map +1 -1
- package/dist/billing/postgres/repositories/preferences.js.map +1 -1
- package/dist/billing/postgres/repositories/refund.js.map +1 -1
- package/dist/billing/postgres/repositories/subscription.js.map +1 -1
- package/dist/billing/postgres/repositories/topup.js.map +1 -1
- package/dist/billing/postgres/store.d.ts +7 -5
- package/dist/billing/postgres/store.d.ts.map +1 -1
- package/dist/billing/postgres/store.js +19 -4
- package/dist/billing/postgres/store.js.map +1 -1
- package/dist/billing/service-types.js.map +1 -1
- package/dist/billing/types/auto-recharge.js.map +1 -1
- package/dist/billing/types/catalog.js.map +1 -1
- package/dist/billing/types/common.js.map +1 -1
- package/dist/billing/types/documents.js.map +1 -1
- package/dist/billing/types/events.js.map +1 -1
- package/dist/billing/types/index.js.map +1 -1
- package/dist/billing/types/preferences.js.map +1 -1
- package/dist/billing/types/subscriptions.js.map +1 -1
- package/dist/breakdown.js.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/bursar.d.ts +7 -3
- package/dist/bursar.d.ts.map +1 -1
- package/dist/bursar.js +12 -4
- package/dist/bursar.js.map +1 -1
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -0
- package/dist/catalog.js.map +1 -1
- package/dist/commerce/errors.d.ts +3 -4
- package/dist/commerce/errors.d.ts.map +1 -1
- package/dist/commerce/errors.js +3 -5
- package/dist/commerce/errors.js.map +1 -1
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/plan-change.js.map +1 -1
- package/dist/commerce/provider-registry.js.map +1 -1
- package/dist/commerce/service.d.ts.map +1 -1
- package/dist/commerce/service.js +47 -12
- package/dist/commerce/service.js.map +1 -1
- package/dist/commerce/types.d.ts +8 -0
- package/dist/commerce/types.d.ts.map +1 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/config/parse-access.js.map +1 -1
- package/dist/config/parse-commerce.js.map +1 -1
- package/dist/config/parse-credits.js.map +1 -1
- package/dist/config/parse-plans.d.ts.map +1 -1
- package/dist/config/parse-plans.js +23 -7
- package/dist/config/parse-plans.js.map +1 -1
- package/dist/config/parse-pricing.js.map +1 -1
- package/dist/config/parse-utils.js.map +1 -1
- package/dist/config/types.d.ts +14 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/config.d.ts +7 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -1
- package/dist/config.js.map +1 -1
- package/dist/credits/events.js.map +1 -1
- package/dist/credits/lease-workflow.js.map +1 -1
- package/dist/credits/low-balance-monitor.js.map +1 -1
- package/dist/credits/postgres/repositories/analytics.d.ts +5 -1
- package/dist/credits/postgres/repositories/analytics.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/analytics.js +3 -1
- package/dist/credits/postgres/repositories/analytics.js.map +1 -1
- package/dist/credits/postgres/repositories/balance.js.map +1 -1
- package/dist/credits/postgres/repositories/bucket.js.map +1 -1
- package/dist/credits/postgres/repositories/deduction.d.ts +9 -0
- package/dist/credits/postgres/repositories/deduction.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/deduction.js +24 -0
- package/dist/credits/postgres/repositories/deduction.js.map +1 -1
- package/dist/credits/postgres/repositories/lease.js.map +1 -1
- package/dist/credits/postgres/repositories/plan.d.ts +6 -1
- package/dist/credits/postgres/repositories/plan.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/plan.js +15 -3
- package/dist/credits/postgres/repositories/plan.js.map +1 -1
- package/dist/credits/postgres/repositories/pricing.d.ts +3 -3
- package/dist/credits/postgres/repositories/pricing.d.ts.map +1 -1
- package/dist/credits/postgres/repositories/pricing.js +12 -6
- package/dist/credits/postgres/repositories/pricing.js.map +1 -1
- package/dist/credits/postgres/repositories/team.js.map +1 -1
- package/dist/credits/postgres/store.d.ts +12 -7
- package/dist/credits/postgres/store.d.ts.map +1 -1
- package/dist/credits/postgres/store.js +86 -13
- package/dist/credits/postgres/store.js.map +1 -1
- package/dist/credits/postgres/value-mappers.d.ts.map +1 -1
- package/dist/credits/postgres/value-mappers.js +6 -2
- package/dist/credits/postgres/value-mappers.js.map +1 -1
- package/dist/credits/pricing-runtime.d.ts +3 -2
- package/dist/credits/pricing-runtime.d.ts.map +1 -1
- package/dist/credits/pricing-runtime.js +4 -4
- package/dist/credits/pricing-runtime.js.map +1 -1
- package/dist/credits/queries.js.map +1 -1
- package/dist/credits/service-errors.js.map +1 -1
- package/dist/credits/service-types.js.map +1 -1
- package/dist/credits/service.d.ts +16 -3
- package/dist/credits/service.d.ts.map +1 -1
- package/dist/credits/service.js +51 -5
- package/dist/credits/service.js.map +1 -1
- package/dist/credits/store.d.ts +8 -3
- package/dist/credits/store.d.ts.map +1 -1
- package/dist/credits/store.js +4 -0
- package/dist/credits/store.js.map +1 -1
- package/dist/credits/types/account.d.ts +1 -1
- package/dist/credits/types/account.d.ts.map +1 -1
- package/dist/credits/types/account.js.map +1 -1
- package/dist/credits/types/admission.js.map +1 -1
- package/dist/credits/types/analytics.js.map +1 -1
- package/dist/credits/types/catalog.d.ts +3 -1
- package/dist/credits/types/catalog.d.ts.map +1 -1
- package/dist/credits/types/catalog.js.map +1 -1
- package/dist/credits/types/grants.js.map +1 -1
- package/dist/credits/types/index.js.map +1 -1
- package/dist/credits/types/ledger.d.ts +10 -0
- package/dist/credits/types/ledger.d.ts.map +1 -1
- package/dist/credits/types/ledger.js.map +1 -1
- package/dist/credits/types/quotas.js.map +1 -1
- package/dist/credits/types/teams.js.map +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +53 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +61 -5
- package/dist/errors.js.map +1 -1
- package/dist/expr/ast.js.map +1 -1
- package/dist/expr/evaluator.js.map +1 -1
- package/dist/expr/language.js.map +1 -1
- package/dist/expr/parser.js.map +1 -1
- package/dist/expr/tokenizer.js.map +1 -1
- package/dist/expr.js +2 -2
- package/dist/expr.js.map +1 -1
- package/dist/generated/pricing-config.schema.json +37 -9
- package/dist/generated/pricing-config.types.d.ts +14 -3
- package/dist/generated/pricing-config.types.d.ts.map +1 -1
- package/dist/generated/pricing-config.types.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/load-pricing-file.d.ts.map +1 -1
- package/dist/load-pricing-file.js +8 -4
- package/dist/load-pricing-file.js.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/providers/_shared.d.ts.map +1 -1
- package/dist/providers/_shared.js +41 -14
- package/dist/providers/_shared.js.map +1 -1
- package/dist/providers/dodo/client-contract.js.map +1 -1
- package/dist/providers/dodo/event-mapper.js.map +1 -1
- package/dist/providers/dodo/index.js.map +1 -1
- package/dist/providers/dodo/provider.js.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock/index.js.map +1 -1
- package/dist/providers/mock/provider.js.map +1 -1
- package/dist/providers/stripe/event-mapper.js.map +1 -1
- package/dist/providers/stripe/index.js.map +1 -1
- package/dist/providers/stripe/provider.js.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/retry.d.ts +26 -4
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +65 -23
- package/dist/retry.js.map +1 -1
- package/dist/shared/diagnostics.d.ts +7 -0
- package/dist/shared/diagnostics.d.ts.map +1 -0
- package/dist/shared/diagnostics.js +18 -0
- package/dist/shared/diagnostics.js.map +1 -0
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/postgres-client.d.ts +38 -5
- package/dist/shared/postgres-client.d.ts.map +1 -1
- package/dist/shared/postgres-client.js +261 -25
- package/dist/shared/postgres-client.js.map +1 -1
- package/dist/shared/postgres-errors.d.ts +11 -0
- package/dist/shared/postgres-errors.d.ts.map +1 -0
- package/dist/shared/postgres-errors.js +105 -0
- package/dist/shared/postgres-errors.js.map +1 -0
- package/dist/shared/postgres-types.js.map +1 -1
- package/dist/shared/postgres-validation.d.ts.map +1 -1
- package/dist/shared/postgres-validation.js +1 -1
- package/dist/shared/postgres-validation.js.map +1 -1
- package/dist/storage/adapters/clickhouse.d.ts.map +1 -1
- package/dist/storage/adapters/clickhouse.js +20 -2
- package/dist/storage/adapters/clickhouse.js.map +1 -1
- package/dist/storage/adapters/s3.js.map +1 -1
- package/dist/storage/outbox-worker.d.ts +2 -1
- package/dist/storage/outbox-worker.d.ts.map +1 -1
- package/dist/storage/outbox-worker.js +17 -3
- package/dist/storage/outbox-worker.js.map +1 -1
- package/dist/storage/ports.d.ts +1 -0
- package/dist/storage/ports.d.ts.map +1 -1
- package/dist/storage/ports.js.map +1 -1
- package/dist/storage/postgres-repository.d.ts.map +1 -1
- package/dist/storage/postgres-repository.js +11 -1
- package/dist/storage/postgres-repository.js.map +1 -1
- package/dist/storage/runtime.d.ts +11 -1
- package/dist/storage/runtime.d.ts.map +1 -1
- package/dist/storage/runtime.js +91 -35
- package/dist/storage/runtime.js.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
# Bursar for JavaScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@zonastery/bursar)
|
|
4
|
+
[](https://www.npmjs.com/package/@zonastery/bursar)
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img
|
|
8
|
+
src="https://raw.githubusercontent.com/zonastery/bursar/main/docs/static/img/logo.png"
|
|
9
|
+
alt="Bursar logo"
|
|
10
|
+
width="192"
|
|
11
|
+
height="192"
|
|
12
|
+
/>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
The TypeScript SDK for [Bursar](https://github.com/Zonastery/bursar) — a
|
|
16
|
+
behavioral mirror of the Python SDK. It meters usage, prices operations, and
|
|
17
|
+
manages balances against the shared canonical PostgreSQL schema and the same
|
|
18
|
+
versioned configuration document, with identical rounding. `@zonastery/bursar`
|
|
19
|
+
is ESM-only and requires Node.js 22 or newer.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
4
22
|
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
```bash
|
|
24
|
+
npm install @zonastery/bursar
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Optional peer dependencies: `pg` (PostgresStore), `stripe` and `dodopayments`
|
|
28
|
+
(provider billing), `js-yaml` (YAML config loading). No peer is required for
|
|
29
|
+
core credits.
|
|
30
|
+
|
|
31
|
+
## Database setup
|
|
32
|
+
|
|
33
|
+
Database installation belongs to the SQL baseline, not to the SDK. Apply it
|
|
34
|
+
with the Python migration CLI:
|
|
7
35
|
|
|
8
36
|
```bash
|
|
9
|
-
|
|
37
|
+
pip install bursar[postgres]
|
|
38
|
+
export DATABASE_URL=postgresql://...
|
|
39
|
+
bursar migrate
|
|
10
40
|
```
|
|
11
41
|
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
12
44
|
```ts
|
|
13
45
|
import { Bursar, PostgresStore } from "@zonastery/bursar";
|
|
14
46
|
|
|
15
|
-
const
|
|
16
|
-
|
|
47
|
+
const store = new PostgresStore(process.env.DATABASE_URL!, tenantId, {
|
|
48
|
+
connectionTimeoutMs: 10_000,
|
|
49
|
+
statementTimeoutMs: 30_000,
|
|
50
|
+
onPoolError: (error) => console.error("Bursar PostgreSQL pool error", error),
|
|
51
|
+
});
|
|
17
52
|
const bursar = new Bursar({ creditStore: store });
|
|
18
53
|
|
|
19
54
|
const grant = await bursar.credits.addCredits(userId, 500, {
|
|
@@ -34,83 +69,92 @@ while (page.nextCursor) {
|
|
|
34
69
|
}
|
|
35
70
|
```
|
|
36
71
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
72
|
+
`LedgerEntry`, `LedgerCursor`, and `LedgerPage` are the public history
|
|
73
|
+
contract; pagination is cursor-only. Publish one versioned configuration
|
|
74
|
+
document through the facade — billing and auto-recharge read the same active
|
|
75
|
+
document:
|
|
40
76
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
that active configuration; there is no separate billing configuration.
|
|
77
|
+
```ts
|
|
78
|
+
await bursar.catalog.publishAndActivate(config);
|
|
79
|
+
```
|
|
45
80
|
|
|
46
|
-
|
|
47
|
-
applications. Database installation is deliberately not a store or `Bursar`
|
|
48
|
-
method.
|
|
81
|
+
## Errors, deadlines, and retries
|
|
49
82
|
|
|
50
|
-
|
|
83
|
+
All Bursar-classified failures extend `BursarError` and carry stable `code`,
|
|
84
|
+
`category`, and `retryable` fields. Native `cause` chains retain the underlying
|
|
85
|
+
driver error without exposing it from
|
|
86
|
+
`bursarErrorPublicMessage()` or the serialized `toJSON()` shape. PostgreSQL
|
|
87
|
+
failures are classified primarily from SQLSTATE and network error codes, with
|
|
88
|
+
narrow fallbacks for the stable timeout messages emitted by `pg` itself.
|
|
51
89
|
|
|
52
|
-
`
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
`PostgresStore` and `PostgresBillingStore` use a 10-second connection deadline,
|
|
91
|
+
a 30-second server-side statement deadline, and a 30-second idle-transaction
|
|
92
|
+
deadline by default. All are configurable. An SDK-owned pool also installs an
|
|
93
|
+
idle-client error listener so a network partition cannot become an uncaught
|
|
94
|
+
EventEmitter error.
|
|
55
95
|
|
|
56
|
-
|
|
57
|
-
|
|
96
|
+
Use `retryBursarOperation()` only for reads or idempotent mutations. It uses
|
|
97
|
+
bounded exponential backoff with jitter, an elapsed-time budget, and optional
|
|
98
|
+
`AbortSignal` cancellation:
|
|
58
99
|
|
|
59
100
|
```ts
|
|
60
|
-
import {
|
|
61
|
-
|
|
62
|
-
const runtime = await createBursarRuntime({
|
|
63
|
-
postgres: process.env.DATABASE_URL!,
|
|
64
|
-
tenantId: process.env.BURSAR_TENANT_ID!,
|
|
65
|
-
});
|
|
66
|
-
await runtime.start();
|
|
101
|
+
import { isBursarError, retryBursarOperation } from "@zonastery/bursar";
|
|
67
102
|
|
|
68
|
-
|
|
103
|
+
try {
|
|
104
|
+
const balance = await retryBursarOperation(() => bursar.credits.getBalance(userId), {
|
|
105
|
+
maxAttempts: 3,
|
|
106
|
+
signal: request.signal,
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (isBursarError(error)) {
|
|
110
|
+
console.error("Bursar request failed", error.toJSON());
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
69
114
|
```
|
|
70
115
|
|
|
71
|
-
|
|
72
|
-
|
|
116
|
+
`StoreError.indeterminate` means a transport failure occurred when a mutation
|
|
117
|
+
may have reached PostgreSQL. Retry only with the same idempotency key. A plain
|
|
118
|
+
`StoreError` is deliberately non-retryable; custom stores should throw
|
|
119
|
+
`StoreUnavailableError` or `StoreTimeoutError` only for classified transient
|
|
120
|
+
failures.
|
|
121
|
+
|
|
122
|
+
## Optional S3 and ClickHouse storage
|
|
123
|
+
|
|
124
|
+
PostgreSQL remains authoritative. S3 and ClickHouse are optional delivery
|
|
125
|
+
targets, managed by `createBursarRuntime` from `@zonastery/bursar/node`:
|
|
73
126
|
|
|
74
127
|
```ts
|
|
75
|
-
import { createClient } from "@clickhouse/client";
|
|
76
128
|
import { createBursarRuntime } from "@zonastery/bursar/node";
|
|
77
129
|
|
|
78
|
-
const clickhouseClient = createClient({ url: process.env.CLICKHOUSE_URL! });
|
|
79
|
-
|
|
80
130
|
const runtime = await createBursarRuntime({
|
|
81
131
|
postgres: process.env.DATABASE_URL!,
|
|
82
132
|
tenantId: process.env.BURSAR_TENANT_ID!,
|
|
83
|
-
s3: {
|
|
84
|
-
bucket: process.env.BURSAR_S3_BUCKET!,
|
|
85
|
-
region: process.env.BURSAR_S3_REGION!,
|
|
86
|
-
endpoint: process.env.BURSAR_S3_ENDPOINT,
|
|
87
|
-
forcePathStyle: process.env.BURSAR_S3_FORCE_PATH_STYLE === "true",
|
|
88
|
-
credentials: {
|
|
89
|
-
accessKeyId: process.env.BURSAR_S3_ACCESS_KEY_ID!,
|
|
90
|
-
secretAccessKey: process.env.BURSAR_S3_SECRET_ACCESS_KEY!,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
clickhouse: {
|
|
94
|
-
client: clickhouseClient,
|
|
95
|
-
tenantId: process.env.BURSAR_TENANT_ID!,
|
|
96
|
-
// Optional; omit to keep the ClickHouse projection indefinitely.
|
|
97
|
-
retentionDays: 730,
|
|
98
|
-
},
|
|
99
133
|
});
|
|
100
|
-
|
|
101
134
|
await runtime.start();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
135
|
+
const bursar = runtime.bursar;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
With no S3/ClickHouse configuration the runtime creates no background worker
|
|
139
|
+
and analytics query PostgreSQL directly. See the
|
|
140
|
+
[storage guide](https://zonastery.github.io/bursar/docs/guides/storage-backends)
|
|
141
|
+
for the full S3 and ClickHouse setup.
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
cd javascript
|
|
147
|
+
bun ci # Bun 1.3.14; installs the committed bun.lock
|
|
148
|
+
bun run typecheck
|
|
149
|
+
bun run test # integration tests need Postgres (DATABASE_URL or testcontainer)
|
|
150
|
+
bun run lint
|
|
151
|
+
bun run build
|
|
105
152
|
```
|
|
106
153
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
154
|
+
Bun manages development dependencies and scripts; consumers of the published
|
|
155
|
+
package do not need it. See
|
|
156
|
+
[CONTRIBUTING.md](https://github.com/Zonastery/bursar/blob/main/CONTRIBUTING.md).
|
|
157
|
+
|
|
158
|
+
## License
|
|
112
159
|
|
|
113
|
-
|
|
114
|
-
Database retention maintenance remains independent: schedule
|
|
115
|
-
`bursar.maybe_run_storage_maintenance()` and partition maintenance with
|
|
116
|
-
`pg_cron` as described in the SQL README.
|
|
160
|
+
AGPL-3.0.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-recharge-port.js","sourceRoot":"","sources":["../../src/billing/auto-recharge-port.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"auto-recharge-port.js","sourceRoot":"","sources":["../../src/billing/auto-recharge-port.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingTopupResult,\n} from \"./types/index.js\";\n\n/** Narrow billing capability required by AutoRechargeService. */\nexport interface AutoRechargeBillingPort {\n getActiveBursarConfig(): Promise<Record<string, unknown> | null>;\n resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null>;\n resolveTopupByLookup(provider: string, lookupKey: string): Promise<BillingTopupResult | null>;\n getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null>;\n getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;\n upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void>;\n claimAutoRechargeAttempt(input: {\n userId: string;\n idempotencyKey: string;\n }): Promise<BillingAutoRechargeAttempt | null>;\n updateAutoRechargeAttempt(input: {\n id: string;\n state: string;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void>;\n /** Count attempts since an exact instant. */\n countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-recharge-service.js","sourceRoot":"","sources":["../../src/billing/auto-recharge-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AASlD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAiC/D,MAAM,OAAO,mBAAmB;IACD;IAA7B,YAA6B,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAEzD,KAAK,CAAC,MAAM,CAAC,QAAyB;QAC5C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;QACvD,IAAI,CAA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I,CAAC,OAAO,CAAC,yBAAyB,CAAC;gBAC3C,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,KAAK,EAAE,YAAY;gBACnB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,IAAI,IAAI;aACpD,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAC1C,CAAC;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YAC3C,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,KAAK,EAAE,QAAQ;YACf,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,IAAI,IAAI;YACnD,WAAW,EAAE,gBAAgB;SAC9B,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { loadConfigFromDict } from \"../config.js\";\nimport type { BillingAutoRechargeProfile, BillingAutoRechargeStatus } from \"./types/index.js\";\nimport type {\n PaymentMethodInfo,\n PaymentProvider,\n SavedPaymentChargeQuote,\n SavedPaymentChargeResult,\n} from \"../providers/types.js\";\nimport type { AutoRechargeBillingPort } from \"./auto-recharge-port.js\";\nimport { resolveAutoRechargeWindow } from \"./policy-window.js\";\n\nexport type AutoRechargeOutcome =\n | \"not_configured\"\n | \"disabled\"\n | \"above_threshold\"\n | \"already_processing\"\n | \"limit_reached\"\n | \"submitted\"\n | \"action_required\"\n | \"failed\";\n\nexport interface AutoRechargeProcessResult {\n outcome: AutoRechargeOutcome;\n charge?: SavedPaymentChargeResult | null;\n}\n\ninterface ResolvedAutoRechargePolicy {\n enabled: true;\n threshold: number;\n topupKey: string;\n topupId: string;\n quantity: number;\n maxChargesPerWindow: number;\n windowUnit: \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n windowCount: number;\n windowAnchor: \"calendar\" | \"plan_assignment\" | \"rolling\";\n windowTimezone: string;\n windowStart: string;\n windowEnd: string;\n productId: string;\n}\n\nexport class AutoRechargeService {\n constructor(private readonly billing: AutoRechargeBillingPort) {}\n\n private async policy(provider: PaymentProvider): Promise<ResolvedAutoRechargePolicy | null> {\n const raw = await this.billing.getActiveBursarConfig();\n if (!raw) return null;\n const config = loadConfigFromDict(raw);\n const auto = config.commerce.autoRecharge;\n if (!auto) return null;\n\n const topupKey = auto.eligibleTopups[0];\n const topup = config.commerce.offers[topupKey];\n if (!topup || topup.type !== \"topup\") return null;\n const reference = topup.providers[provider.provider];\n if (!reference) return null;\n\n const productId =\n reference.type === \"stripe_price\"\n ? reference.priceId\n : reference.type === \"dodo_product\"\n ? reference.productId\n : reference.externalId;\n const resolvedTopup =\n reference.type === \"stripe_price\"\n ? await this.billing.resolveTopup(provider.provider, null, productId)\n : reference.type === \"dodo_product\"\n ? await this.billing.resolveTopup(provider.provider, productId, null)\n : await this.billing.resolveTopupByLookup(provider.provider, productId);\n if (!resolvedTopup) return null;\n\n const period = resolveAutoRechargeWindow(auto.limits.window);\n return {\n enabled: true,\n threshold: Number(auto.balanceBelow.default),\n topupKey,\n topupId: resolvedTopup.topupId,\n quantity: auto.quantity.default,\n maxChargesPerWindow: auto.limits.maxPurchases,\n windowUnit: period.unit,\n windowCount: period.count,\n windowAnchor: period.anchor,\n windowTimezone: period.timezone,\n windowStart: period.start,\n windowEnd: period.end,\n productId,\n };\n }\n\n private async paymentMethod(\n userId: string,\n provider: PaymentProvider,\n ): Promise<{ customerId: string; method: PaymentMethodInfo } | null> {\n const customer = await this.billing.getCustomerByUserId(userId, provider.provider);\n if (!customer) return null;\n if (!provider.listPaymentMethods) {\n throw new Error(`provider_capability_not_supported:listPaymentMethods:${provider.provider}`);\n }\n const methods = await provider.listPaymentMethods(customer.providerCustomerId);\n const method =\n (await provider.getDefaultPaymentMethod?.(customer.providerCustomerId)) ??\n methods.find((candidate) => candidate.isDefault) ??\n (methods.length === 1 ? methods[0] : null);\n return method ? { customerId: customer.providerCustomerId, method } : null;\n }\n\n async quote(input: {\n userId: string;\n provider: PaymentProvider;\n }): Promise<SavedPaymentChargeQuote | null> {\n const policy = await this.policy(input.provider);\n if (!policy || !input.provider.previewSavedPaymentCharge) return null;\n const payment = await this.paymentMethod(input.userId, input.provider);\n if (!payment) return null;\n return input.provider.previewSavedPaymentCharge({\n customerId: payment.customerId,\n paymentMethodId: payment.method.id,\n productId: policy.productId,\n quantity: policy.quantity,\n metadata: {},\n idempotencyKey: \"auto-recharge-preview\",\n });\n }\n\n async getStatus(input: {\n userId: string;\n provider: PaymentProvider;\n }): Promise<BillingAutoRechargeStatus | null> {\n const policy = await this.policy(input.provider);\n if (!policy) return null;\n const profile = await this.billing.getAutoRechargeProfile(input.userId);\n const payment = profile?.enabled\n ? await this.paymentMethod(input.userId, input.provider)\n : null;\n const quote = await this.quote(input);\n return {\n enabled: Boolean(profile?.enabled),\n state: profile?.enabled ? profile.state : \"disabled\",\n thresholdCredits: policy.threshold,\n topupKey: policy.topupKey,\n quantity: policy.quantity,\n maxRecharges: policy.maxChargesPerWindow,\n windowStart: policy.windowStart,\n windowEnd: policy.windowEnd,\n rechargesInWindow: await this.billing.countAutoRechargeAttempts(\n input.userId,\n policy.windowStart,\n ),\n paymentMethodId: payment?.method.id ?? null,\n paymentMethodLast4: payment?.method.last4 ?? null,\n paymentMethodBrand: payment?.method.brand ?? null,\n suspendedReason: profile?.state === \"paused\" ? \"auto_recharge_paused\" : null,\n pendingAttemptId: null,\n quoteAmountMinor: quote?.amountMinor ?? null,\n quoteCurrency: quote?.currency ?? null,\n };\n }\n\n async enable(input: {\n userId: string;\n provider: PaymentProvider;\n balance: number;\n returnUrl?: string;\n consentReference?: string;\n }): Promise<BillingAutoRechargeStatus | null> {\n const policy = await this.policy(input.provider);\n if (!policy) throw new Error(\"auto_recharge_not_configured\");\n const payment = await this.paymentMethod(input.userId, input.provider);\n if (!payment) throw new Error(\"payment_method_required\");\n\n const profile: BillingAutoRechargeProfile = {\n userId: input.userId,\n enabled: true,\n state: \"active\",\n armed: true,\n provider: input.provider.provider,\n topupId: policy.topupId,\n quantity: policy.quantity,\n threshold: policy.threshold,\n maxChargesPerWindow: policy.maxChargesPerWindow,\n windowUnit: policy.windowUnit,\n windowCount: policy.windowCount,\n windowAnchor: policy.windowAnchor,\n windowTimezone: policy.windowTimezone,\n };\n await this.billing.upsertAutoRechargeProfile(profile);\n await this.processIfNeeded(input);\n return this.getStatus(input);\n }\n\n async disable(userId: string): Promise<void> {\n const profile = await this.billing.getAutoRechargeProfile(userId);\n if (!profile) return;\n await this.billing.upsertAutoRechargeProfile({\n ...profile,\n enabled: false,\n state: \"disabled\",\n armed: true,\n });\n }\n\n async retry(input: {\n userId: string;\n provider: PaymentProvider;\n balance: number;\n returnUrl?: string;\n }): Promise<AutoRechargeProcessResult> {\n const profile = await this.billing.getAutoRechargeProfile(input.userId);\n if (!profile?.enabled) throw new Error(\"auto_recharge_disabled\");\n await this.billing.upsertAutoRechargeProfile(\n {\n ...profile,\n state: \"active\",\n armed: true,\n },\n { resetCooldown: true },\n );\n return this.processIfNeeded(input);\n }\n\n async processIfNeeded(input: {\n userId: string;\n provider: PaymentProvider;\n balance: number;\n returnUrl?: string;\n }): Promise<AutoRechargeProcessResult> {\n const policy = await this.policy(input.provider);\n if (!policy) return { outcome: \"not_configured\" };\n const profile = await this.billing.getAutoRechargeProfile(input.userId);\n if (!profile?.enabled || profile.state !== \"active\") return { outcome: \"disabled\" };\n if (input.balance >= policy.threshold) {\n return { outcome: \"above_threshold\" };\n }\n\n const payment = await this.paymentMethod(input.userId, input.provider);\n if (!payment) return { outcome: \"failed\" };\n const attempt = await this.billing.claimAutoRechargeAttempt({\n userId: input.userId,\n idempotencyKey: `auto-recharge:${input.userId}:${randomUUID()}`,\n });\n if (!attempt) return { outcome: \"limit_reached\" };\n\n if (!input.provider.chargeSavedPaymentMethod) {\n throw new Error(\n `provider_capability_not_supported:chargeSavedPaymentMethod:${input.provider.provider}`,\n );\n }\n const charge = await input.provider.chargeSavedPaymentMethod({\n customerId: payment.customerId,\n paymentMethodId: payment.method.id,\n productId: policy.productId,\n quantity: policy.quantity,\n returnUrl: input.returnUrl,\n idempotencyKey: attempt.idempotencyKey,\n metadata: {\n auto_recharge_attempt_id: attempt.id,\n purpose: \"credit_topup\",\n userId: input.userId,\n },\n });\n if (charge.status === \"requires_customer_action\") {\n await this.billing.updateAutoRechargeAttempt({\n id: attempt.id,\n state: \"action_required\",\n providerAttemptId: charge.providerPaymentId ?? null,\n });\n return { outcome: \"action_required\", charge };\n }\n if (charge.status === \"succeeded\" || charge.status === \"processing\") {\n await this.billing.updateAutoRechargeAttempt({\n id: attempt.id,\n state: \"processing\",\n providerAttemptId: charge.providerPaymentId ?? null,\n });\n return { outcome: \"submitted\", charge };\n }\n\n await this.billing.updateAutoRechargeAttempt({\n id: attempt.id,\n state: \"failed\",\n providerAttemptId: charge.providerPaymentId ?? null,\n failureCode: \"payment_failed\",\n });\n return { outcome: \"failed\", charge };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-service.js","sourceRoot":"","sources":["../../src/billing/billing-service.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIpD;;;GAGG;AACH,MAAM,OAAO,cAAc;IAChB,YAAY,CAAsB;IAC1B,KAAK,CAAe;IACpB,UAAU,CAAoB;IAC9B,MAAM,CAAwB;IAE/C,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,YAAY,KAAmB,EAAE,OAA+B;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAA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B,YAAY,CAAC,WAAW,EACxB,SAAS,CACV,CAAC;QACF,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;IAChF,CAAC;IAED,mDAAmD;IACnD,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,KAAmB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["import type { BillingStore } from \"./billing-store.js\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingEvent,\n BillingEventResult,\n BillingOfferResult,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n BillingTopupResult,\n CheckoutIntent,\n} from \"./types/index.js\";\nimport { SUBSCRIPTION_STATUS } from \"./types/index.js\";\nimport { AutoRechargeService } from \"./auto-recharge-service.js\";\nimport { BillingEventProcessor } from \"./event-processor.js\";\nimport { BillingManagement } from \"./management.js\";\nimport type { BillingServiceOptions } from \"./service-types.js\";\nexport type { BillingProvisioningPort, BillingServiceOptions } from \"./service-types.js\";\n\n/**\n * Provider-agnostic billing lifecycle state machine.\n * Mirrors the Python billing service implementation.\n */\nexport class BillingService {\n readonly autoRecharge: AutoRechargeService;\n private readonly store: BillingStore;\n private readonly management: BillingManagement;\n private readonly events: BillingEventProcessor;\n\n get hasProvisioning(): boolean {\n return this.events.hasProvisioning;\n }\n\n constructor(store: BillingStore, options?: BillingServiceOptions) {\n this.store = store;\n this.management = new BillingManagement(store);\n this.events = new BillingEventProcessor(store, options);\n this.autoRecharge = new AutoRechargeService(this);\n }\n\n async createOrGetCheckoutIntent(\n input: Parameters<BillingStore[\"createOrGetCheckoutIntent\"]>[0],\n ): Promise<CheckoutIntent> {\n return this.management.createOrGetCheckoutIntent(input);\n }\n\n async updateCheckoutIntent(\n id: string,\n update: Parameters<BillingStore[\"updateCheckoutIntent\"]>[1],\n ): Promise<void> {\n await this.management.updateCheckoutIntent(id, update);\n }\n\n async getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null> {\n return this.management.getCheckoutIntent(id, subjectId);\n }\n\n async getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n return this.management.getActiveSubscription(userId);\n }\n\n async getUserPreferences(userId: string): Promise<BillingPreferences | null> {\n return this.management.getUserPreferences(userId);\n }\n\n async listBillingInvoices(userId: string) {\n return this.management.listBillingInvoices(userId);\n }\n\n async upsertBillingSubscription(state: BillingSubscriptionState): Promise<void> {\n await this.management.upsertBillingSubscription(state);\n }\n\n async createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange> {\n return this.management.createBillingSubscriptionChange(input);\n }\n\n async getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null> {\n return this.management.getOpenBillingSubscriptionChange(provider, providerSubscriptionId);\n }\n\n async updateBillingSubscriptionChange(\n id: string,\n update: Parameters<BillingStore[\"updateBillingSubscriptionChange\"]>[1],\n ): Promise<void> {\n await this.management.updateBillingSubscriptionChange(id, update);\n }\n\n async recordSubscriptionConflict(\n input: Parameters<BillingStore[\"recordSubscriptionConflict\"]>[0],\n ): Promise<void> {\n await this.management.recordSubscriptionConflict(input);\n }\n\n async updateUserPreferences(preferences: BillingPreferences): Promise<void> {\n await this.management.updateUserPreferences(preferences);\n }\n\n async getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null> {\n return this.management.getAutoRechargeProfile(userId);\n }\n\n async getActiveBursarConfig(): Promise<Record<string, unknown> | null> {\n return this.management.getActiveBursarConfig();\n }\n\n async listCancellableProviderSubscriptionIds(userId: string): Promise<string[]> {\n return this.management.listCancellableProviderSubscriptionIds(userId);\n }\n\n async listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]> {\n return this.management.listCancellableSubscriptions(userId);\n }\n\n async pseudonymizeFinancialSubject(userId: string): Promise<void> {\n await this.management.pseudonymizeFinancialSubject(userId);\n }\n\n async upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void> {\n await this.management.upsertAutoRechargeProfile(profile, options);\n }\n\n async claimAutoRechargeAttempt(input: {\n userId: string;\n idempotencyKey: string;\n }): Promise<BillingAutoRechargeAttempt | null> {\n return this.management.claimAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttempt(input: {\n id: string;\n state: string;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n }): Promise<void> {\n await this.management.updateAutoRechargeAttempt(input);\n }\n\n async updateAutoRechargeAttemptByProviderPayment(input: {\n provider: string;\n providerPaymentId: string;\n state: string;\n failureCode?: string | null;\n failureMessage?: string | null;\n }): Promise<void> {\n await this.management.updateAutoRechargeAttemptByProviderPayment(input);\n }\n\n async countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number> {\n return this.management.countAutoRechargeAttempts(userId, since);\n }\n\n async getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null> {\n return this.management.getCustomerByUserId(userId, provider);\n }\n\n async resolveOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null> {\n return this.management.resolveOffer(provider, productId, priceId);\n }\n\n async resolveOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null> {\n return this.management.resolveOfferByLookup(provider, lookupKey);\n }\n\n async resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null> {\n return this.management.resolveTopup(provider, productId, priceId);\n }\n\n async resolveTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null> {\n return this.management.resolveTopupByLookup(provider, lookupKey);\n }\n\n async upsertCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void> {\n await this.management.upsertCustomer(provider, providerCustomerId, userId, email);\n }\n\n async getUserSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n const subscription = await this.store.getUserSubscription(userId, [\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n SUBSCRIPTION_STATUS.CANCELED,\n SUBSCRIPTION_STATUS.PAST_DUE,\n SUBSCRIPTION_STATUS.INCOMPLETE,\n // EXPIRED excluded — expired subscriptions are not \"current\" for billing purposes.\n ]);\n return this.expireGraceIfNeeded(subscription);\n }\n\n async getBlockingSubscription(userId: string): Promise<BillingSubscriptionState | null> {\n const subscription = await this.store.getUserSubscription(userId, [\n SUBSCRIPTION_STATUS.ACTIVE,\n SUBSCRIPTION_STATUS.TRIALING,\n SUBSCRIPTION_STATUS.PAST_DUE,\n SUBSCRIPTION_STATUS.INCOMPLETE,\n ]);\n return this.expireGraceIfNeeded(subscription);\n }\n\n async expirePastDueGracePeriods(now = new Date()): Promise<number> {\n if (!this.events.hasProvisioning) return 0;\n const asOf = now.toISOString();\n const candidates = await this.store.listExpiredGraceSubscriptions(asOf);\n let expiredCount = 0;\n for (const candidate of candidates) {\n if (!candidate.subscriptionId || !candidate.graceEndsAt) continue;\n const current = await this.store.getBillingSubscription(\n candidate.provider,\n candidate.providerSubscriptionId,\n );\n if (\n current?.status !== \"past_due\" ||\n current.graceEndsAt !== candidate.graceEndsAt ||\n current.graceExpiredAt\n ) {\n continue;\n }\n await this.events.revokeIfCurrentSubscription(\n candidate.userId,\n candidate.providerSubscriptionId,\n );\n if (\n await this.store.markSubscriptionGraceExpired(\n candidate.subscriptionId,\n candidate.graceEndsAt,\n asOf,\n )\n ) {\n expiredCount += 1;\n }\n }\n return expiredCount;\n }\n\n private async expireGraceIfNeeded(\n subscription: BillingSubscriptionState | null,\n ): Promise<BillingSubscriptionState | null> {\n if (\n !subscription ||\n !this.events.hasProvisioning ||\n subscription.status !== \"past_due\" ||\n subscription.graceExpiredAt ||\n !subscription.graceEndsAt ||\n new Date(subscription.graceEndsAt).getTime() > Date.now() ||\n !subscription.subscriptionId\n ) {\n return subscription;\n }\n\n await this.events.revokeIfCurrentSubscription(\n subscription.userId,\n subscription.providerSubscriptionId,\n );\n const expiredAt = new Date().toISOString();\n const marked = await this.store.markSubscriptionGraceExpired(\n subscription.subscriptionId,\n subscription.graceEndsAt,\n expiredAt,\n );\n return marked ? { ...subscription, graceExpiredAt: expiredAt } : subscription;\n }\n\n /** Invalidate cached provider offer resolution. */\n invalidateOfferCache(): void {\n this.events.invalidateOfferCache();\n }\n\n async ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult> {\n return this.events.ingestBillingEvent(event);\n }\n}\n"]}
|
|
@@ -12,8 +12,8 @@ export declare abstract class BillingStore {
|
|
|
12
12
|
abstract getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;
|
|
13
13
|
abstract resolveBillingOffer(provider: string, productId?: string | null, priceId?: string | null): Promise<BillingOfferResult | null>;
|
|
14
14
|
abstract claimBillingEvent(provider: string, eventId: string, eventType: string, envelope?: Record<string, unknown>): Promise<BillingEventClaim>;
|
|
15
|
-
abstract completeBillingEvent(provider: string, eventId: string, claimToken: string): Promise<
|
|
16
|
-
abstract failBillingEvent(provider: string, eventId: string, claimToken: string, error?: string): Promise<
|
|
15
|
+
abstract completeBillingEvent(provider: string, eventId: string, claimToken: string): Promise<boolean>;
|
|
16
|
+
abstract failBillingEvent(provider: string, eventId: string, claimToken: string, error?: string): Promise<boolean>;
|
|
17
17
|
abstract upsertBillingCustomer(provider: string, providerCustomerId: string, userId: string, email?: string | null): Promise<void>;
|
|
18
18
|
abstract upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;
|
|
19
19
|
abstract getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null>;
|
|
@@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OAAgB,YAAY;CAkKjC"}
|
|
1
|
+
{"version":3,"file":"billing-store.js","sourceRoot":"","sources":["../../src/billing/billing-store.ts"],"names":[],"mappings":"AA6BA;;;;;GAKG;AACH,MAAM,OAAgB,YAAY;CAkKjC","sourcesContent":["import type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingEventClaim,\n BillingOfferResult,\n BillingPreferences,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n CheckoutIntent,\n BillingTopupResult,\n BillingInvoiceInfo,\n} from \"./types/index.js\";\nimport type {\n AutoRechargeAttemptClaim,\n AutoRechargeAttemptUpdate,\n AutoRechargeProviderPaymentUpdate,\n BillingCreditGrantCreate,\n BillingDisputeUpsert,\n BillingInvoiceUpsert,\n BillingPaymentUpsert,\n BillingRefundUpsert,\n BillingSubscriptionChangeUpdate,\n BillingSubscriptionConflictCreate,\n CheckoutIntentCreate,\n CheckoutIntentUpdate,\n} from \"./contracts.js\";\n\n/**\n * Abstract billing store — provider-agnostic persistence layer for\n * subscription lifecycle state.\n *\n * Mirrors Python bursar/billing/store.py.\n */\nexport abstract class BillingStore {\n abstract createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent>;\n\n abstract updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void>;\n\n abstract getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;\n\n abstract resolveBillingOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null>;\n\n abstract claimBillingEvent(\n provider: string,\n eventId: string,\n eventType: string,\n envelope?: Record<string, unknown>,\n ): Promise<BillingEventClaim>;\n\n abstract completeBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n ): Promise<boolean>;\n\n abstract failBillingEvent(\n provider: string,\n eventId: string,\n claimToken: string,\n error?: string,\n ): Promise<boolean>;\n\n abstract upsertBillingCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void>;\n\n abstract upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;\n\n abstract getBillingCustomer(provider: string, providerCustomerId: string): Promise<string | null>;\n\n abstract getBillingSubscription(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionState | null>;\n\n abstract createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange>;\n\n abstract getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null>;\n\n abstract listExpiredGraceSubscriptions(\n now: string,\n limit?: number,\n ): Promise<BillingSubscriptionState[]>;\n\n abstract markSubscriptionGraceExpired(\n subscriptionId: string,\n expectedGraceEndsAt: string,\n expiredAt?: string,\n ): Promise<boolean>;\n\n abstract updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void>;\n\n abstract getUserSubscription(\n userId: string,\n statuses?: string[],\n ): Promise<BillingSubscriptionState | null>;\n\n abstract resolveCreditTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null>;\n abstract resolveCreditTopupByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingTopupResult | null>;\n\n abstract resolveBillingOfferByLookup(\n provider: string,\n lookupKey: string,\n ): Promise<BillingOfferResult | null>;\n\n abstract computeTopupCredits(\n amountMinor: number,\n topupConfig: BillingTopupResult,\n ): Promise<number>;\n\n abstract upsertBillingPayment(options: BillingPaymentUpsert): Promise<string>;\n abstract createBillingCreditGrant(input: BillingCreditGrantCreate): Promise<string>;\n abstract grantBillingCredit(\n grantId: string,\n idempotencyKey: string,\n ): Promise<Record<string, unknown>>;\n abstract getBillingCreditGrantByPayment(paymentId: string): Promise<string | null>;\n abstract postBillingRefund(\n refundId: string,\n grantId: string,\n amountMinor: number,\n idempotencyKey: string,\n ): Promise<Record<string, unknown>>;\n\n abstract listBillingInvoices(userId: string): Promise<BillingInvoiceInfo[]>;\n\n abstract upsertBillingRefund(options: BillingRefundUpsert): Promise<string>;\n\n abstract upsertBillingInvoice(options: BillingInvoiceUpsert): Promise<void>;\n\n abstract upsertBillingDispute(options: BillingDisputeUpsert): Promise<void>;\n\n abstract getBillingPayment(\n provider: string,\n providerPaymentId: string,\n ): Promise<Record<string, unknown> | null>;\n\n abstract getActiveBursarConfig(): Promise<Record<string, unknown> | null>;\n\n abstract pseudonymizeFinancialSubject(userId: string): Promise<boolean>;\n\n abstract getUserSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;\n\n abstract recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;\n\n /** Select a current provider subscription as the subject's entitlement source. */\n abstract selectSubscriptionEntitlementSource(\n userId: string,\n provider: string,\n providerSubscriptionId?: string | null,\n ): Promise<boolean>;\n\n abstract getBillingPreferences(userId: string): Promise<BillingPreferences | null>;\n\n abstract upsertBillingPreferences(prefs: BillingPreferences): Promise<void>;\n abstract getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;\n abstract upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void>;\n abstract claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null>;\n abstract updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void>;\n abstract updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void>;\n abstract countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;\n\n abstract getBillingCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/billing/contracts.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/billing/contracts.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutoRechargeService } from \"./auto-recharge-service.js\";\nimport type {\n BillingAutoRechargeAttempt,\n BillingAutoRechargeProfile,\n BillingCustomerRecord,\n BillingDisputeInfo,\n BillingEvent,\n BillingEventResult,\n BillingInvoiceInfo,\n BillingOfferResult,\n BillingPaymentInfo,\n BillingPreferences,\n BillingRefundInfo,\n BillingSubscriptionChange,\n BillingSubscriptionChangeInput,\n BillingSubscriptionState,\n BillingTopupResult,\n CheckoutIntent,\n} from \"./types/index.js\";\n\nexport interface CheckoutIntentCreate {\n subjectId: string;\n provider: string;\n checkoutKind: \"subscription\" | \"credit_topup\";\n productKey: string;\n requestDigest: string;\n expiresAt: string;\n}\n\nexport interface CheckoutIntentUpdate {\n status?: \"open\" | \"completed\" | \"failed\" | \"expired\";\n providerSessionId?: string | null;\n checkoutUrl?: string | null;\n}\n\nexport interface BillingSubscriptionChangeUpdate {\n state?: BillingSubscriptionChange[\"state\"];\n providerOperationId?: string | null;\n errorMessage?: string | null;\n}\n\nexport interface BillingSubscriptionConflictCreate {\n userId?: string | null;\n provider: string;\n duplicateSubscriptionId: string;\n existingSubscriptionId?: string | null;\n eventId?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface BillingPaymentUpsert {\n provider: string;\n providerPaymentId: string;\n providerInvoiceId?: string | null;\n userId?: string | null;\n amountMinor?: number;\n taxMinor?: number | null;\n currency?: string | null;\n purpose?: string;\n status?: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n providerUpdatedAt?: string;\n metadata?: Record<string, unknown> | null;\n}\n\nexport interface BillingCreditGrantCreate {\n paymentId?: string | null;\n subscriptionId?: string | null;\n topupId?: string | null;\n configuredCredits: number;\n quantity?: number;\n billingEventId?: string | null;\n}\n\nexport interface BillingRefundUpsert {\n provider: string;\n providerRefundId: string;\n providerPaymentId?: string | null;\n userId?: string | null;\n amountMinor?: number;\n currency?: string | null;\n reason?: string | null;\n status?: \"pending\" | \"succeeded\" | \"failed\" | \"canceled\";\n providerUpdatedAt?: string;\n metadata?: Record<string, unknown> | null;\n}\n\nexport interface BillingInvoiceUpsert {\n provider: string;\n providerInvoiceId: string;\n providerSubscriptionId?: string | null;\n userId?: string | null;\n status?: string | null;\n amountPaidMinor?: number | null;\n amountDueMinor?: number | null;\n currency?: string | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n metadata?: Record<string, unknown> | null;\n providerUpdatedAt?: string;\n}\n\nexport interface BillingDisputeUpsert {\n provider: string;\n providerDisputeId: string;\n providerPaymentId?: string | null;\n userId?: string | null;\n status?: string;\n reason?: string | null;\n metadata?: Record<string, unknown> | null;\n providerUpdatedAt?: string;\n}\n\nexport interface AutoRechargeAttemptClaim {\n userId: string;\n idempotencyKey: string;\n}\n\nexport interface AutoRechargeAttemptUpdate {\n id: string;\n state: string;\n providerAttemptId?: string | null;\n failureCode?: string | null;\n failureMessage?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface AutoRechargeProviderPaymentUpdate {\n provider: string;\n providerPaymentId: string;\n state: string;\n failureCode?: string | null;\n failureMessage?: string | null;\n}\n\n/** Boundary used by payment providers to submit normalized lifecycle events. */\nexport interface BillingEventSink {\n ingestBillingEvent(event: BillingEvent): Promise<BillingEventResult>;\n}\n\n/** Application-facing billing capability exposed by Bursar. */\nexport interface BillingCapability extends BillingEventSink {\n readonly autoRecharge: AutoRechargeService;\n readonly hasProvisioning: boolean;\n createOrGetCheckoutIntent(input: CheckoutIntentCreate): Promise<CheckoutIntent>;\n updateCheckoutIntent(id: string, update: CheckoutIntentUpdate): Promise<void>;\n getCheckoutIntent(id: string, subjectId: string): Promise<CheckoutIntent | null>;\n getUserSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getActiveSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getBlockingSubscription(userId: string): Promise<BillingSubscriptionState | null>;\n getUserPreferences(userId: string): Promise<BillingPreferences | null>;\n getActiveBursarConfig(): Promise<Record<string, unknown> | null>;\n listCancellableProviderSubscriptionIds(userId: string): Promise<string[]>;\n listCancellableSubscriptions(userId: string): Promise<BillingSubscriptionState[]>;\n listBillingInvoices(userId: string): Promise<BillingInvoiceInfo[]>;\n createBillingSubscriptionChange(\n input: BillingSubscriptionChangeInput,\n ): Promise<BillingSubscriptionChange>;\n getOpenBillingSubscriptionChange(\n provider: string,\n providerSubscriptionId: string,\n ): Promise<BillingSubscriptionChange | null>;\n updateBillingSubscriptionChange(\n id: string,\n update: BillingSubscriptionChangeUpdate,\n ): Promise<void>;\n recordSubscriptionConflict(input: BillingSubscriptionConflictCreate): Promise<void>;\n upsertBillingSubscription(state: BillingSubscriptionState): Promise<void>;\n updateUserPreferences(preferences: BillingPreferences): Promise<void>;\n getAutoRechargeProfile(userId: string): Promise<BillingAutoRechargeProfile | null>;\n upsertAutoRechargeProfile(\n profile: BillingAutoRechargeProfile,\n options?: { resetCooldown?: boolean },\n ): Promise<void>;\n claimAutoRechargeAttempt(\n input: AutoRechargeAttemptClaim,\n ): Promise<BillingAutoRechargeAttempt | null>;\n updateAutoRechargeAttempt(input: AutoRechargeAttemptUpdate): Promise<void>;\n updateAutoRechargeAttemptByProviderPayment(\n input: AutoRechargeProviderPaymentUpdate,\n ): Promise<void>;\n countAutoRechargeAttempts(userId: string, since: string | Date): Promise<number>;\n expirePastDueGracePeriods(now?: Date): Promise<number>;\n invalidateOfferCache(): void;\n getCustomerByUserId(\n userId: string,\n provider?: string | null,\n ): Promise<BillingCustomerRecord | null>;\n resolveOffer(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingOfferResult | null>;\n resolveOfferByLookup(provider: string, lookupKey: string): Promise<BillingOfferResult | null>;\n resolveTopup(\n provider: string,\n productId?: string | null,\n priceId?: string | null,\n ): Promise<BillingTopupResult | null>;\n resolveTopupByLookup(provider: string, lookupKey: string): Promise<BillingTopupResult | null>;\n upsertCustomer(\n provider: string,\n providerCustomerId: string,\n userId: string,\n email?: string | null,\n ): Promise<void>;\n pseudonymizeFinancialSubject(userId: string): Promise<void>;\n}\n\n// Keep document-record types reachable from the contract module for store\n// implementers without forcing them to import the broad billing type barrel.\nexport type { BillingDisputeInfo, BillingInvoiceInfo, BillingPaymentInfo, BillingRefundInfo };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../../src/billing/event-handlers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAInB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAEV,qBAAqB,EAEtB,MAAM,oBAAoB,CAAC;AAY5B,qBAAa,oBAAoB;IAgB7B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAfxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiC;IAC9D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAU;IACtD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkD;IAC7E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuE;IAElG,IAAI,eAAe,IAAI,OAAO,CAE7B;gBAGkB,KAAK,EAAE,YAAY,EACpC,OAAO,CAAC,EAAE,qBAAqB;IAmEjC,UAAU,CACR,SAAS,EAAE,gBAAgB,GAC1B,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,SAAS;IAIrE,oBAAoB,I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,CAAC,SAAS,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuE;IAElG,IAAI,eAAe,IAAI,OAAO,CAE7B;gBAGkB,KAAK,EAAE,YAAY,EACpC,OAAO,CAAC,EAAE,qBAAqB;IAmEjC,UAAU,CACR,SAAS,EAAE,gBAAgB,GAC1B,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,SAAS;IAIrE,oBAAoB,IAAI,IAAI;IAItB,6BAA6B,CACjC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,GACzC,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;OAIG;YACW,aAAa;YAgDb,yBAAyB;YAYzB,qBAAqB;YAmBrB,qBAAqB;YAcrB,uBAAuB;YAwBvB,uBAAuB;IAUrC,OAAO,CAAC,sBAAsB;YAiEhB,mBAAmB;YA+CnB,yBAAyB;YA+FzB,yBAAyB;YA8BzB,2BAA2B;YA2B3B,yBAAyB;YAyBzB,6BAA6B;YA4C7B,2BAA2B;YAe3B,6BAA6B;YAe7B,0BAA0B;YAiC1B,yBAAyB;YAkBzB,wBAAwB;YAkBxB,yBAAyB;YAqBzB,kBAAkB;YAMlB,qBAAqB;YA4DrB,sBAAsB;YA4BtB,kBAAkB;IAShC;;;OAGG;IACG,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAOvE,gBAAgB;YA8ChB,qBAAqB;CASpC"}
|
|
@@ -559,15 +559,32 @@ export class BillingEventHandlers {
|
|
|
559
559
|
return;
|
|
560
560
|
}
|
|
561
561
|
this.logger.debug("[BillingService] provisionSubscription setting plan", { uid, plan });
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
562
|
+
let periodStart;
|
|
563
|
+
if (preserveAllowanceAnchor) {
|
|
564
|
+
const existingAnchor = this.provisioning.getUserPlan
|
|
565
|
+
? (await this.provisioning.getUserPlan(uid))?.planAssignedAt
|
|
566
|
+
: undefined;
|
|
567
|
+
if (existingAnchor) {
|
|
568
|
+
const anchor = new Date(existingAnchor);
|
|
569
|
+
// A provider's subscription period start may actually be its next
|
|
570
|
+
// renewal date. Never let a future anchor hide an already-active
|
|
571
|
+
// entitlement after a plan change.
|
|
572
|
+
if (!Number.isNaN(anchor.getTime()) && anchor.getTime() <= Date.now()) {
|
|
573
|
+
periodStart = anchor;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
periodStart = event.subscription?.periodStart;
|
|
579
|
+
}
|
|
565
580
|
const planAssignedAt = periodStart
|
|
566
581
|
? (() => {
|
|
567
582
|
const d = new Date(periodStart);
|
|
568
583
|
return Number.isNaN(d.getTime()) ? undefined : d;
|
|
569
584
|
})()
|
|
570
|
-
:
|
|
585
|
+
: preserveAllowanceAnchor
|
|
586
|
+
? new Date()
|
|
587
|
+
: undefined;
|
|
571
588
|
await this.provisioning.setUserPlan(uid, plan, planAssignedAt);
|
|
572
589
|
if (this.autoSelectEntitlementSource && event.provider) {
|
|
573
590
|
const selected = await this.store.selectSubscriptionEntitlementSource(uid, event.provider, event.subscription?.providerSubscriptionId);
|