@owlmeans/server-payment 0.1.18 → 0.1.19
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 +1 -1
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-payment/SKILL.md +74 -6
- package/build/access/types.d.ts +8 -1
- package/build/access/types.d.ts.map +1 -1
- package/build/access.d.ts.map +1 -1
- package/build/access.js +8 -2
- package/build/access.js.map +1 -1
- package/build/catalogue/types.d.ts +3 -1
- package/build/catalogue/types.d.ts.map +1 -1
- package/build/catalogue.d.ts.map +1 -1
- package/build/catalogue.js +15 -10
- package/build/catalogue.js.map +1 -1
- package/build/commit/types.d.ts +17 -2
- package/build/commit/types.d.ts.map +1 -1
- package/build/commit.d.ts.map +1 -1
- package/build/commit.js +40 -5
- package/build/commit.js.map +1 -1
- package/build/consts.d.ts +17 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +19 -0
- package/build/consts.js.map +1 -1
- package/build/consumer/capture.d.ts.map +1 -1
- package/build/consumer/capture.js +2 -1
- package/build/consumer/capture.js.map +1 -1
- package/build/consumer/reconcile.d.ts.map +1 -1
- package/build/consumer/reconcile.js +2 -1
- package/build/consumer/reconcile.js.map +1 -1
- package/build/entitlement.d.ts.map +1 -1
- package/build/entitlement.js +7 -1
- package/build/entitlement.js.map +1 -1
- package/build/grant-fold/types.d.ts +41 -0
- package/build/grant-fold/types.d.ts.map +1 -0
- package/build/grant-fold/types.js +2 -0
- package/build/grant-fold/types.js.map +1 -0
- package/build/grant-fold.d.ts +4 -0
- package/build/grant-fold.d.ts.map +1 -0
- package/build/grant-fold.js +64 -0
- package/build/grant-fold.js.map +1 -0
- package/build/grants/types.d.ts +39 -0
- package/build/grants/types.d.ts.map +1 -0
- package/build/grants/types.js +2 -0
- package/build/grants/types.js.map +1 -0
- package/build/grants.d.ts +6 -0
- package/build/grants.d.ts.map +1 -0
- package/build/grants.js +141 -0
- package/build/grants.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/observer.d.ts +3 -0
- package/build/observer.d.ts.map +1 -1
- package/build/observer.js +6 -0
- package/build/observer.js.map +1 -1
- package/build/plugins/events.d.ts.map +1 -1
- package/build/plugins/events.js +5 -2
- package/build/plugins/events.js.map +1 -1
- package/build/plugins/session/types.d.ts +2 -0
- package/build/plugins/session/types.d.ts.map +1 -1
- package/build/plugins/session.d.ts.map +1 -1
- package/build/plugins/session.js +15 -2
- package/build/plugins/session.js.map +1 -1
- package/build/plugins/stripe.js +3 -3
- package/build/plugins/stripe.js.map +1 -1
- package/build/reconcile/types.d.ts +4 -2
- package/build/reconcile/types.d.ts.map +1 -1
- package/build/reconcile.d.ts.map +1 -1
- package/build/reconcile.js +3 -1
- package/build/reconcile.js.map +1 -1
- package/build/resource.d.ts +2 -1
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +10 -2
- package/build/resource.js.map +1 -1
- package/build/schemas.d.ts +2 -1
- package/build/schemas.d.ts.map +1 -1
- package/build/schemas.js +16 -2
- package/build/schemas.js.map +1 -1
- package/build/service.d.ts +3 -3
- package/build/service.d.ts.map +1 -1
- package/build/service.js +7 -5
- package/build/service.js.map +1 -1
- package/build/subscription/types.d.ts +12 -2
- package/build/subscription/types.d.ts.map +1 -1
- package/build/subscription.d.ts.map +1 -1
- package/build/subscription.js +14 -3
- package/build/subscription.js.map +1 -1
- package/build/types.d.ts +129 -0
- package/build/types.d.ts.map +1 -1
- package/build/usage/types.d.ts +25 -8
- package/build/usage/types.d.ts.map +1 -1
- package/build/usage.d.ts.map +1 -1
- package/build/usage.js +201 -46
- package/build/usage.js.map +1 -1
- package/build/utils/types.d.ts +5 -0
- package/build/utils/types.d.ts.map +1 -1
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +4 -2
- package/build/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/access/types.ts +8 -1
- package/src/access.ts +12 -3
- package/src/catalogue/types.ts +3 -1
- package/src/catalogue.ts +17 -13
- package/src/commit/types.ts +17 -2
- package/src/commit.ts +47 -6
- package/src/consts.ts +20 -0
- package/src/consumer/capture.ts +2 -1
- package/src/consumer/reconcile.ts +2 -1
- package/src/entitlement.ts +8 -1
- package/src/grant-fold/types.ts +42 -0
- package/src/grant-fold.ts +89 -0
- package/src/grants/types.ts +42 -0
- package/src/grants.ts +171 -0
- package/src/index.ts +4 -0
- package/src/observer.ts +8 -1
- package/src/plugins/events.ts +5 -2
- package/src/plugins/session/types.ts +2 -0
- package/src/plugins/session.ts +15 -2
- package/src/plugins/stripe.ts +3 -3
- package/src/reconcile/types.ts +4 -2
- package/src/reconcile.ts +3 -1
- package/src/resource.ts +20 -7
- package/src/schemas.ts +20 -5
- package/src/service.ts +9 -6
- package/src/subscription/types.ts +12 -2
- package/src/subscription.ts +15 -2
- package/src/types.ts +133 -0
- package/src/usage/types.ts +25 -8
- package/src/usage.ts +235 -48
- package/src/utils/types.ts +5 -0
- package/src/utils.ts +6 -2
- package/tests/checkout.spec.ts +62 -0
- package/tests/consumer-fixtures.ts +7 -0
- package/tests/consumer-ops.spec.ts +12 -1
- package/tests/consumer-rights.spec.ts +35 -1
- package/tests/events.spec.ts +10 -0
- package/tests/fake-stripe.ts +35 -12
- package/tests/grants.spec.ts +276 -0
- package/tests/internal-plan.spec.ts +112 -0
- package/tests/usage.integration.spec.ts +32 -0
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
178
178
|
your project's skill store (`.agents/skills/`):
|
|
179
179
|
|
|
180
180
|
```sh
|
|
181
|
-
npx @owlmeans/agent-skills@^0.1.
|
|
181
|
+
npx @owlmeans/agent-skills@^0.1.19
|
|
182
182
|
```
|
|
183
183
|
|
|
184
184
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 3,
|
|
3
3
|
"package": "@owlmeans/server-payment",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.19",
|
|
5
|
+
"generatedAt": "2026-11-01T22:22:22.313Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: server-payment
|
|
3
|
-
description: Public in-process Stripe gateway for OwlMeans backends — amount and quantity checkout, subscriptions, the checkout plugin seam (per-entity narrowing, admission, holds), protocol-bound webhook routes, product sync with per-currency prices, fulfillment observers, entitlement gates, and the EU consumer-rights service (country lock, purchases and withdrawal windows, spend consent, subscription start requests, the withdrawal and cancellation functions with automatic refunds and credit notes, durable-medium mails, reconcile). Use when wiring @owlmeans/server-payment or changing Stripe payment behavior.
|
|
3
|
+
description: Public in-process Stripe gateway for OwlMeans backends — amount and quantity checkout, subscriptions, the checkout plugin seam (per-entity narrowing, admission, holds), protocol-bound webhook routes, product sync with per-currency prices, fulfillment observers, entitlement gates, internal plan grants and revokes, entitlement grants (payment-grant units and capabilities beside the plan), and the EU consumer-rights service (country lock, purchases and withdrawal windows, spend consent, subscription start requests, the withdrawal and cancellation functions with automatic refunds and credit notes, durable-medium mails, reconcile). Use when wiring @owlmeans/server-payment or changing Stripe payment behavior.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
7
|
|
|
8
8
|
# @owlmeans/server-payment
|
|
9
9
|
|
|
10
|
-
**Install:** `bun add @owlmeans/server-payment@^0.1.
|
|
10
|
+
**Install:** `bun add @owlmeans/server-payment@^0.1.19`
|
|
11
11
|
|
|
12
12
|
Public MIT package. It embeds Stripe into an application backend and owns everything between
|
|
13
13
|
Stripe and an entity's entitlements: the subscription store, one-time fulfillments, the usage
|
|
@@ -86,7 +86,8 @@ paymentAccessOf(context).observer().onSubscription(async event => { /* keyed by
|
|
|
86
86
|
`.use(plugin)`) needs the initialized context.
|
|
87
87
|
- **`manage: false`** registers the same surface with no Stripe client: no bootstrap at init, and
|
|
88
88
|
`createLink`, `portalLink`, `resyncSubscription`, `resyncAll`, the webhook route, `withdraw` and
|
|
89
|
-
`cancel` throw `PaygateError('unmanaged')`. `grantInternalPlan`, the
|
|
89
|
+
`cancel` throw `PaygateError('unmanaged')`. `grantInternalPlan`, `revokeInternalPlan`, the
|
|
90
|
+
entitlement grants, the entitlement service,
|
|
90
91
|
`amountPolicy`, `planPrices` and the consumer-rights reads, `recordConsent`,
|
|
91
92
|
`recordStartRequest` and `assertConsent` work, because they are Mongo only.
|
|
92
93
|
- **Three keys of a deployment's Stripe state**, each a `PaymentGatewayOptions` field, each read
|
|
@@ -153,6 +154,7 @@ None declares an ObjectId reference: `entityId` is an organization key and every
|
|
|
153
154
|
| `payment-webhook` | managed webhook endpoint of an owner (`service` = the gateway's `owner`; `secret` is `secure: true`) | `{paygate, service, url}` unique |
|
|
154
155
|
| `payment-usage` | usage event — the ledger | `{entityId, limitKey, eventKey}` unique · `{entityId, limitKey, window}` · `{entityId, limitKey, ref}` sparse · `{entityId, createdAt:-1}` |
|
|
155
156
|
| `payment-usage-counter` | (entity, limit, window) projection | `{entityId, limitKey, window}` unique |
|
|
157
|
+
| `payment-grant` | entitlement grant beside the plan: `kind` (`units` / `capability`), `limitKey`, `capability`, `amount`, `used`, `startsAt`, `endsAt?`, `status` (`active` / `revoked`), `ref`, `note`, `revokedAt` | (§ Entitlement grants) |
|
|
156
158
|
| `payment-fingerprint` | synchronized product (`<productSku>`, with `prices[]`) or portal (`portal:<owner>`) | `{sku}` unique |
|
|
157
159
|
| `payment-billing-profile` | organization: the billing country fixed at the first purchase | `{entityId}` unique · `{paygate, customerId}` sparse |
|
|
158
160
|
| `payment-purchase` | purchase = contract + withdrawal window (a paid one-time checkout, a subscription's first invoice) | `{purchaseId}` unique · `{contractRef}` unique · `{entityId, deadline:-1}` · `{entityId, purchasedAt:-1}` · `{sessionId}` unique sparse · `{paygate, subscriptionId}` · `{invoiceId}` · `{invoiceNumber}` · `{paygate, paymentIntentId}` |
|
|
@@ -174,7 +176,10 @@ None declares an ObjectId reference: `entityId` is an organization key and every
|
|
|
174
176
|
## Checkout
|
|
175
177
|
|
|
176
178
|
- `Amount`: one inline `price_data` item for the synchronized product, quantity 1, its
|
|
177
|
-
`tax_behavior` the declared `PricingPolicy.tax.behavior
|
|
179
|
+
`tax_behavior` the declared `PricingPolicy.tax.behavior`. Promotion-code entry defaults off;
|
|
180
|
+
`declarePaymentPricing({ stripe: { amountPromotionCodes: true }, … })` enables it for amount
|
|
181
|
+
sessions in that deployment. Discounts reduce payment, never the selected `amountMinor` or its
|
|
182
|
+
original charge metadata. `Quantity`: the
|
|
178
183
|
reusable price under the plan lookup key, adjustable quantity. Subscription: `planSku` (else the
|
|
179
184
|
product's first recurring plan), quantity 1. One-time Sessions enable `invoice_creation`.
|
|
180
185
|
- `CreateLinkParams.locale` is a caller-validated Stripe locale (Session `locale`, the Customer's
|
|
@@ -239,6 +244,22 @@ None declares an ObjectId reference: `entityId` is an organization key and every
|
|
|
239
244
|
session kept the pinned address). The purchase's `termsAccepted` comes only from the completed
|
|
240
245
|
session's `consent.terms_of_service` — absent when nothing was collected.
|
|
241
246
|
|
|
247
|
+
### Amount promotion codes and free completions
|
|
248
|
+
|
|
249
|
+
- Coupons apply to the existing single grossed-up line, processing adjustment included; Stripe
|
|
250
|
+
computes tax after the discount. `amount_subtotal` remains the original pre-discount base;
|
|
251
|
+
`amount_total` records the discounted, tax-inclusive payment, including an explicit zero.
|
|
252
|
+
- A completed amount session with promotion codes enabled, a positive base subtotal fully covered
|
|
253
|
+
by `total_details.amount_discount`, zero tax and zero total fulfills for `no_payment_required`
|
|
254
|
+
as well as `paid`. Currency, subtotal and credit-value metadata checks still apply. Fulfillment
|
|
255
|
+
keeps the full selected credits and the existing session idempotency key; no PaymentIntent or
|
|
256
|
+
invoice is required for a free redemption. Purchase backfill uses the same completion predicate.
|
|
257
|
+
- A zero-total top-up keeps its purchase receipt and country lock but has no monetary withdrawal
|
|
258
|
+
deadline, spending-consent window or refundable amount. Discounted paid purchases use the actual
|
|
259
|
+
payment for proportional refunds. Keep the original invoice-line basis in credit notes: Stripe
|
|
260
|
+
applies the invoice discount itself, once. `DisputeEvent.paidMinor` is the actual charge total in
|
|
261
|
+
dispute currency, including tax; an absent value retains the consumer's legacy fallback.
|
|
262
|
+
|
|
242
263
|
### Customer locks (`declarePaymentPricing` → `stripe`)
|
|
243
264
|
|
|
244
265
|
Both are opt-in, backend-only, read per call from the Stripe pricing plugin config, and work with
|
|
@@ -358,8 +379,17 @@ registry: a plugin whose `alias` is registered already replaces it). All hooks a
|
|
|
358
379
|
`downgraded` · `cancel-scheduled` · `cancel-undone` · `renewed` (once per invoice) · `past-due` ·
|
|
359
380
|
`suspended` · `trial-ending`.
|
|
360
381
|
- A repeated delivery (`lastEventId`) is ignored; an older payload than the stored state is not
|
|
361
|
-
applied. `
|
|
362
|
-
|
|
382
|
+
applied. `resyncSubscription` / `resyncAll` re-read and apply as a webhook would.
|
|
383
|
+
- **Internal plans** (`paygate: INTERNAL_PAYGATE`, row `internal:<planSku>:<entityId>`; Mongo only,
|
|
384
|
+
so they work unmanaged): `gateway.grantInternalPlan(ctx, entityId, planSku, { force?, periodEnd? })`
|
|
385
|
+
upserts the row — the free plan, or any plan with `force: true` (else `ProductError`); `periodEnd`
|
|
386
|
+
is when it stops entitling (absent: never). A re-grant of a row that stopped entitling (revoked,
|
|
387
|
+
or past its period end) RE-ACTIVATES the same row: `createdAt` stays the first grant's (subscription
|
|
388
|
+
windows, credit frames and grandfathered promos keep their anchor), `restartedAt` is stamped, and
|
|
389
|
+
observers hear `created` again under a key carrying `restartedAt`; a restart whose observers
|
|
390
|
+
failed is told again by the next grant. `gateway.revokeInternalPlan(ctx, entityId, planSku)` ends it
|
|
391
|
+
now — `status: canceled`, `canceledAt` = now, `periodEnd` = `endedAt` = now (or the period end
|
|
392
|
+
already past) — observers hear `canceled`; idempotent, answers whether anything changed.
|
|
363
393
|
|
|
364
394
|
## The usage ledger
|
|
365
395
|
|
|
@@ -370,6 +400,36 @@ key is idempotent; `release` appends `release:<eventKey>` first. `reconcileCount
|
|
|
370
400
|
`reconcileOccupancy`, `reconcileOf(ctx).reconcileEntity` and `.reconcileAll` repair it (details: the `entitlements`
|
|
371
401
|
skill).
|
|
372
402
|
|
|
403
|
+
## Entitlement grants
|
|
404
|
+
|
|
405
|
+
`entitlementGrantsOf(ctx)` (also `paymentAccessOf(ctx).grants()`; resource `payment-grant`,
|
|
406
|
+
`RES_PAYMENT_GRANT`, registered with the other payment resources; Mongo only) gives ONE organization
|
|
407
|
+
units or a capability beside its plan:
|
|
408
|
+
|
|
409
|
+
- `grant(entityId, { kind, limitKey?, amount?, capability?, startsAt?, endsAt?, ref?, note? })` —
|
|
410
|
+
`units` needs a limit key some declared plan has (`LimitUnknown`) and a positive safe integer
|
|
411
|
+
`amount`; `capability` (required for `capability`, optional on `units` — the capability those
|
|
412
|
+
units need) is `scope:permission[>=n]`, never under the `limit` scope. `revoke(grantId,
|
|
413
|
+
{ entityId? })` (idempotent; `entityId` refuses another organization's), `get`, `list(entityId,
|
|
414
|
+
{ active?, at?, kind?, limitKey? })` (newest first), `inForce(entityId, at?)`.
|
|
415
|
+
- In force while `active` from `startsAt` until `endsAt` (exclusive); revoked or ended → ignored at
|
|
416
|
+
read time: its used units stay consumed, its unused ones are gone.
|
|
417
|
+
- **Units are consumed AFTER the plan's allowance**: `consumeLimit` takes from the plan counter while
|
|
418
|
+
it has room, else from the first units grant in force with room (earliest end first, then oldest),
|
|
419
|
+
the event written in the grant's window `grant:<grantId>` (`GRANT_WINDOW_PREFIX`,
|
|
420
|
+
`grantFoldHelper.windowOf`); `releaseLimit` gives a unit back to where it came from.
|
|
421
|
+
`reconcileCounters` (and `reconcileOf(ctx).reconcileEntity` / `.reconcileAll`) rebuilds each units
|
|
422
|
+
grant's `used` from its `grant:<id>` events; `reconcileOccupancy` holds what the grants say and brings the plan counter to the rest, so a unit
|
|
423
|
+
of a revoked grant falls back on the plan (over-limit → the application's grace).
|
|
424
|
+
- **Folded, never a new field**: `limitState`, the consume outcome and the entitlement view read
|
|
425
|
+
`limit + Σ amount`, `used + Σ used`, `remaining` (`grantFoldHelper.foldLimitView`); capability
|
|
426
|
+
grants (and a units grant's capability) are merged into the effective plan by
|
|
427
|
+
`resolveEffectivePlan` (`grantFoldHelper.withCapabilities`: the grant's row replaces a promo's or a
|
|
428
|
+
smaller one, a plan that already covers it is left alone).
|
|
429
|
+
- Every grant and revoke tells `onEntitlementGrant` (`EntitlementGrantEvent`: `grant`, `change`
|
|
430
|
+
`granted` / `revoked`, key `grant:<id>:<change>`) in the process that wrote it; a throw is logged
|
|
431
|
+
and never undoes the grant — an application that provisions on it also reconciles nightly.
|
|
432
|
+
|
|
373
433
|
## Entitlements and gates
|
|
374
434
|
|
|
375
435
|
- `paymentAccessOf(ctx).entitlements()` → `effectivePlan`, `entitlements` (the `EntitlementView`), `hasCapability`,
|
|
@@ -583,6 +643,7 @@ refund touches the purchase only when it is of the purchase's own (first) invoic
|
|
|
583
643
|
| `onConsent` | `ConsentEvent` (`kind`, `consentId`, `purchaseIds`, `planSku`) | `consent:<id>` | recorded; `reconcile` retries |
|
|
584
644
|
| `onWithdrawal` | `WithdrawalEvent` (`status`, `purchase: PurchaseRef`, `refund`, `units`, `subscriptionCanceled`) | `withdrawal:<id>` | recorded; `reconcile` retries |
|
|
585
645
|
| `onCancellation` | `CancellationEvent` (`matched`, `kind`, `status`, `effectiveAt`) | `cancellation:<id>` | recorded; `reconcile` retries |
|
|
646
|
+
| `onEntitlementGrant` | `EntitlementGrantEvent` (`grant`, `change`) | `grant:<id>:<granted\|revoked>` | logged; the grant stands |
|
|
586
647
|
|
|
587
648
|
Every callback must be idempotent by its key. A proportional claw-back of an ordinary top-up
|
|
588
649
|
refund uses `netAmountMinor * refundedTotalMinor / paidMinor`.
|
|
@@ -607,6 +668,13 @@ concurrent withdrawals.
|
|
|
607
668
|
|
|
608
669
|
## External docs
|
|
609
670
|
|
|
671
|
+
- https://docs.stripe.com/api/checkout/sessions/object — `amount_subtotal` precedes discounts and
|
|
672
|
+
tax; `amount_total` follows them; a free payment can omit a PaymentIntent.
|
|
673
|
+
- https://docs.stripe.com/payments/checkout/no-cost-orders — fulfill zero-cost orders on Checkout
|
|
674
|
+
completion, including orders discounted by 100%.
|
|
675
|
+
- https://docs.stripe.com/invoicing/dashboard/credit-notes#credit-balances-and-discounts — invoice
|
|
676
|
+
discounts apply proportionally to credit-note lines; retain the original line basis.
|
|
677
|
+
|
|
610
678
|
- https://docs.stripe.com/api/checkout/sessions/create — `customer`: "If the Customer already has a valid email set, the email will be prefilled and not editable in Checkout" (else Checkout saves the typed one); `customer_email` only prefills a NEW customer and cannot be combined with `customer`. Inline `price_data`; `consent_collection.terms_of_service` needs a terms URL in the Dashboard (else `invalid_request_error` on param `consent_collection[terms_of_service]`); `custom_text.{submit, after_submit, terms_of_service_acceptance}` ≤ 1200 characters each; `currency` forces a Price's currency option; `expires_at` 30 min – 24 h.
|
|
611
679
|
- https://docs.stripe.com/tax/customer-locations — minimal tax location: country alone except US (postal code), CA and IN (postal code or province); https://docs.stripe.com/tax/checkout/page — an existing customer with `customer_update.address: 'never'` is taxed on its saved address. Verified against test mode (2026-10): a pinned DE customer keeps its VAT when the card country is switched to US; a country-only US/CA customer is refused at session creation.
|
|
612
680
|
- https://docs.stripe.com/payments/checkout/localize-prices/manual-currency-prices — `currency_options` on a Price, one reusable Price for several currencies; manual options override Adaptive Pricing for that currency.
|
package/build/access/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type Stripe from 'stripe';
|
|
2
2
|
import type { PaymentService } from '@owlmeans/payment';
|
|
3
|
-
import type { BillingProfileResource, CompletionObserver, ConsumerConsentResource, ConsumerDeclarationResource, ConsumerEventResource, ConsumerMailPluginConfig, ConsumerRightsService, EntitlementService, FingerprintResource, GatewayService, PaygateCustomerResource, PaymentFulfillmentResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, PaymentUsageCounterResource, PaymentUsageResource, PaymentWebhookResource, PortalBrandingConfig, PurchaseResource, StripePluginConfig, StripePricingPluginConfig } from '../types.js';
|
|
3
|
+
import type { BillingProfileResource, CompletionObserver, ConsumerConsentResource, ConsumerDeclarationResource, ConsumerEventResource, ConsumerMailPluginConfig, ConsumerRightsService, EntitlementService, FingerprintResource, GatewayService, PaygateCustomerResource, PaymentFulfillmentResource, PaymentGrantResource, PaymentSubscriptionRecord, PaymentSubscriptionResource, PaymentUsageCounterResource, PaymentUsageResource, PaymentWebhookResource, PortalBrandingConfig, PurchaseResource, StripePluginConfig, StripePricingPluginConfig } from '../types.js';
|
|
4
|
+
import type { EntitlementGrantHelper } from '../grants/types.js';
|
|
4
5
|
/** What one context holds for payments: its services, its resources, its plugin configs and its Stripe client. */
|
|
5
6
|
export interface PaymentAccess {
|
|
6
7
|
payment: () => PaymentService;
|
|
@@ -16,6 +17,12 @@ export interface PaymentAccess {
|
|
|
16
17
|
usageEvents: () => PaymentUsageResource;
|
|
17
18
|
usageCounters: () => PaymentUsageCounterResource;
|
|
18
19
|
fingerprints: () => FingerprintResource;
|
|
20
|
+
/** The entitlement grant records (`payment-grant`). @throws when the resource is not registered */
|
|
21
|
+
grantRecords: () => PaymentGrantResource;
|
|
22
|
+
/** The entitlement grant records, or `null` in a context that registered none (no grants at all). */
|
|
23
|
+
grantRecordsOf: () => PaymentGrantResource | null;
|
|
24
|
+
/** The organization entitlement grants: give, revoke, list and read what is in force (`entitlementGrantsOf`). */
|
|
25
|
+
grants: () => EntitlementGrantHelper;
|
|
19
26
|
billingProfiles: () => BillingProfileResource;
|
|
20
27
|
purchases: () => PurchaseResource;
|
|
21
28
|
consumerConsents: () => ConsumerConsentResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/access/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EACV,sBAAsB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,2BAA2B,EAChG,qBAAqB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,mBAAmB,EAC/G,cAAc,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/access/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EACV,sBAAsB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,2BAA2B,EAChG,qBAAqB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,mBAAmB,EAC/G,cAAc,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,yBAAyB,EACpH,2BAA2B,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,sBAAsB,EACtG,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,yBAAyB,EACtF,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAEhE,kHAAkH;AAClH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,cAAc,CAAA;IAC7B,OAAO,EAAE,MAAM,cAAc,CAAA;IAC7B,gEAAgE;IAChE,SAAS,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IACtC,QAAQ,EAAE,MAAM,kBAAkB,CAAA;IAClC,YAAY,EAAE,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;IACnC,yEAAyE;IACzE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAA;CACxG"}
|
package/build/access.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAgBjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAgBjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAItD,eAAO,MAAM,iBAAiB,QAAS,UAAU,KAAG,aAmEnD,CAAA;AAED,yDAAyD;AACzD,eAAO,MAAM,eAAe,8EAAwC,CAAA"}
|
package/build/access.js
CHANGED
|
@@ -2,9 +2,11 @@ import Stripe from 'stripe';
|
|
|
2
2
|
import { PLUGINS } from '@owlmeans/config';
|
|
3
3
|
import { memoHelper } from '@owlmeans/context';
|
|
4
4
|
import { DEFAULT_ALIAS as PAYMENT_SERVICE, ENTITLING_STATUSES } from '@owlmeans/payment';
|
|
5
|
-
import { CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG, CONSUMER_RIGHTS_SERVICE, ENTITLEMENT_SERVICE, GATEWAY_SERVICE, PAYMENT_OBSERVER, RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_PURCHASE, RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK, STRIPE_PINNED_API_VERSION, STRIPE_PLUGIN_CONFIG, STRIPE_PORTAL_PLUGIN_CONFIG, STRIPE_PRICING_PLUGIN_CONFIG, } from './consts.js';
|
|
5
|
+
import { CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG, CONSUMER_RIGHTS_SERVICE, ENTITLEMENT_SERVICE, GATEWAY_SERVICE, PAYMENT_OBSERVER, RES_BILLING_PROFILE, RES_CONSUMER_CONSENT, RES_CONSUMER_DECLARATION, RES_CONSUMER_EVENT, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_GRANT, RES_PAYMENT_PURCHASE, RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK, STRIPE_PINNED_API_VERSION, STRIPE_PLUGIN_CONFIG, STRIPE_PORTAL_PLUGIN_CONFIG, STRIPE_PRICING_PLUGIN_CONFIG, } from './consts.js';
|
|
6
|
+
import { entitlementGrantsOf } from './grants.js';
|
|
6
7
|
export const makePaymentAccess = (ctx) => {
|
|
7
8
|
const hasService = (alias) => ctx.hasService?.(alias) === true;
|
|
9
|
+
const hasResource = (alias) => ctx.hasResource?.(alias) === true;
|
|
8
10
|
const plugins = () => ctx.getConfigResource(PLUGINS);
|
|
9
11
|
const payment = () => ctx.service(PAYMENT_SERVICE);
|
|
10
12
|
const gateway = () => ctx.service(GATEWAY_SERVICE);
|
|
@@ -18,6 +20,9 @@ export const makePaymentAccess = (ctx) => {
|
|
|
18
20
|
const usageEvents = () => ctx.resource(RES_PAYMENT_USAGE);
|
|
19
21
|
const usageCounters = () => ctx.resource(RES_PAYMENT_USAGE_COUNTER);
|
|
20
22
|
const fingerprints = () => ctx.resource(RES_PAYMENT_FINGERPRINT);
|
|
23
|
+
const grantRecords = () => ctx.resource(RES_PAYMENT_GRANT);
|
|
24
|
+
const grantRecordsOf = () => hasResource(RES_PAYMENT_GRANT) ? grantRecords() : null;
|
|
25
|
+
const grants = () => entitlementGrantsOf(ctx);
|
|
21
26
|
const billingProfiles = () => ctx.resource(RES_BILLING_PROFILE);
|
|
22
27
|
const purchases = () => ctx.resource(RES_PAYMENT_PURCHASE);
|
|
23
28
|
const consumerConsents = () => ctx.resource(RES_CONSUMER_CONSENT);
|
|
@@ -35,7 +40,8 @@ export const makePaymentAccess = (ctx) => {
|
|
|
35
40
|
}, { sort: [{ field: 'rank', order: 'desc' }, { field: 'createdAt', order: 'desc' }] });
|
|
36
41
|
return {
|
|
37
42
|
payment, gateway, gatewayOf, observer, entitlements, paygateCustomers, subscriptions, fulfillments,
|
|
38
|
-
paymentWebhooks, usageEvents, usageCounters, fingerprints,
|
|
43
|
+
paymentWebhooks, usageEvents, usageCounters, fingerprints, grantRecords, grantRecordsOf, grants, billingProfiles,
|
|
44
|
+
purchases, consumerConsents,
|
|
39
45
|
consumerDeclarations, consumerEvents, consumerRights, consumerRightsOf, stripeConfig, portalBrandingConfig,
|
|
40
46
|
consumerMailConfig, stripePricingConfig, stripeClient, activeSubscription,
|
|
41
47
|
};
|
package/build/access.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,kBAAkB,EAAuB,MAAM,mBAAmB,CAAA;AAE7G,OAAO,EACL,kCAAkC,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,eAAe,EACjG,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,kBAAkB,EACzG,oBA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,OAAO,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAqC,CAAA;IAExF,MAAM,YAAY,GAAG,KAAK,IAAqB,EAAE,CAC/C,IAAI,MAAM,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,yBAAkC,EAAE,CAAC,CAAA;IAE5F,MAAM,kBAAkB,GAAG,KAAK,EAC9B,QAAgB,EAAE,UAAkB,EACO,EAAE,CAAC,MAAM,aAAa,EAAE,CAAC,IAAI,CAAC;QACzE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,kBAAkB,CAAC;KACtD,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;IAEvF,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY;QAClG,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe;QAChH,SAAS,EAAE,gBAAgB;QAC3B,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB;QAC1G,kBAAkB,EAAE,mBAAmB,EAAE,YAAY,EAAE,kBAAkB;KAC1E,CAAA;AACH,CAAC,CAAA;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA"}
|
|
@@ -14,7 +14,9 @@ export interface CatalogueHelper {
|
|
|
14
14
|
* The plan an entity holds: its highest-ranked subscription in an entitling status (the catalogue
|
|
15
15
|
* rank, the stored one for a plan the catalogue no longer declares; the newest first on a tie),
|
|
16
16
|
* else the declared free plan. The plan answered carries the winning row's `overrides`
|
|
17
|
-
* (`overriddenPlan`)
|
|
17
|
+
* (`overriddenPlan`) and the capability grants in force (`withCapabilities`), so every reader —
|
|
18
|
+
* ceilings, the view, the gates — sees one answer. The grants in force ride along as `grants`
|
|
19
|
+
* (units grants are not folded into `plan.limits`: the usage ledger consumes them after the plan).
|
|
18
20
|
*
|
|
19
21
|
* @throws PlanRequired when there is neither.
|
|
20
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/catalogue/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE7E,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC1D,mCAAmC;IACnC,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnE,4CAA4C;IAC5C,YAAY,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IAC1C,qFAAqF;IACrF,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC7C
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/catalogue/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE7E,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC1D,mCAAmC;IACnC,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnE,4CAA4C;IAC5C,YAAY,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IAC1C,qFAAqF;IACrF,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC7C;;;;;;;;;OASG;IACH,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;IAC7E;;;OAGG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IACtF,uEAAuE;IACvE,aAAa,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC,CAAA;IACtF,yGAAyG;IACzG,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAA;CACpH"}
|
package/build/catalogue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAUjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAK3D,eAAO,MAAM,mBAAmB,QAAS,UAAU,KAAG,eAsHrD,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,WAAW,gFAA0C,CAAA"}
|
package/build/catalogue.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ENTITLING_STATUSES,
|
|
1
|
+
import { ENTITLING_STATUSES, PlanRequired, ProductError, promoHelper } from '@owlmeans/payment';
|
|
2
2
|
import { memoHelper } from '@owlmeans/context';
|
|
3
3
|
import { STRIPE_PAYGATE_ALIAS } from './consts.js';
|
|
4
4
|
import { paymentAccessOf } from './access.js';
|
|
5
5
|
import { planHelper } from './plan.js';
|
|
6
|
+
import { subscriptionHelper } from './subscription.js';
|
|
7
|
+
import { grantFoldHelper } from './grant-fold.js';
|
|
8
|
+
import { entitlementGrantsOf } from './grants.js';
|
|
6
9
|
import { log } from './log.js';
|
|
7
10
|
/** The plan skus already reported unknown — process-wide, so each is warned about once. */
|
|
8
11
|
const unknownPlans = new Set();
|
|
9
|
-
/** An internal grant with a period end stops entitling at that instant; a paygate row never does. */
|
|
10
|
-
const stillEntitles = (row, at) => row.paygate !== INTERNAL_PAYGATE || row.periodEnd == null || new Date(row.periodEnd).getTime() > at.getTime();
|
|
11
12
|
export const makeCatalogueHelper = (ctx) => {
|
|
12
13
|
const access = paymentAccessOf(ctx);
|
|
13
14
|
const findPlan = async (planSku) => {
|
|
@@ -41,7 +42,8 @@ export const makeCatalogueHelper = (ctx) => {
|
|
|
41
42
|
const fallback = await freePlanOf();
|
|
42
43
|
const { items } = await access.subscriptions().list({ entityId, status: [...ENTITLING_STATUSES] }, { size: 0 });
|
|
43
44
|
const candidates = [];
|
|
44
|
-
|
|
45
|
+
// An internal grant with a period end stops entitling at that instant; a paygate row never does.
|
|
46
|
+
for (const row of items.filter(item => subscriptionHelper.entitlesAt(item, at))) {
|
|
45
47
|
const plan = await findPlan(row.planSku);
|
|
46
48
|
if (plan == null) {
|
|
47
49
|
if (!unknownPlans.has(row.planSku)) {
|
|
@@ -55,13 +57,16 @@ export const makeCatalogueHelper = (ctx) => {
|
|
|
55
57
|
candidates.sort((a, b) => b.rank - a.rank
|
|
56
58
|
|| new Date(b.row.createdAt).getTime() - new Date(a.row.createdAt).getTime());
|
|
57
59
|
const best = candidates[0];
|
|
58
|
-
if (best
|
|
59
|
-
|
|
60
|
+
if (best == null && fallback == null) {
|
|
61
|
+
throw new PlanRequired(entityId);
|
|
60
62
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const grants = await entitlementGrantsOf(ctx).inForce(entityId, at);
|
|
64
|
+
const effective = (plan, subscription) => grants.length === 0
|
|
65
|
+
? { plan, subscription, fallback }
|
|
66
|
+
: { plan: grantFoldHelper.withCapabilities(plan, grants), subscription, fallback, grants };
|
|
67
|
+
return best != null
|
|
68
|
+
? effective(planHelper.overriddenPlan(best.plan, best.row), best.row)
|
|
69
|
+
: effective(fallback, null);
|
|
65
70
|
};
|
|
66
71
|
const entitlementsOf = async (entityId, productSkus) => {
|
|
67
72
|
const { plan, subscription } = await resolveEffectivePlan(entityId);
|
package/build/catalogue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../src/catalogue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AA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,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;QAEhD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC,CAAA;IAED,OAAO;QACL,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa;QACpG,gBAAgB;KACjB,CAAA;AACH,CAAC,CAAA;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA"}
|
package/build/commit/types.d.ts
CHANGED
|
@@ -14,9 +14,24 @@ export interface SubscriptionCommitHelper {
|
|
|
14
14
|
commitSubscription: (previous: PaymentSubscriptionRecord | null, next: PaymentSubscriptionRecord, opts?: CommitOptions) => Promise<CommitResult>;
|
|
15
15
|
/**
|
|
16
16
|
* Grant a plan without a paygate — the free plan every entity holds, or a complimentary one
|
|
17
|
-
* (`force`). One row per grant (`free:<entityId>` / `internal:<planSku>:<entityId>`), upserted
|
|
18
|
-
*
|
|
17
|
+
* (`force`). One row per grant (`free:<entityId>` / `internal:<planSku>:<entityId>`), upserted.
|
|
18
|
+
*
|
|
19
|
+
* Observers hear `created` when the row first entitles, and again (`previous: null`, the key
|
|
20
|
+
* suffixed with the row's new `restartedAt`) when a re-grant re-activates a row that had stopped
|
|
21
|
+
* entitling — revoked, or past its period end. A re-grant of an entitling row only moves its
|
|
22
|
+
* period end and tells nobody. `createdAt` is always the FIRST grant's: subscription-week windows,
|
|
23
|
+
* credit frames and grandfathered promos keep their anchor, so a revoke and a re-grant inside one
|
|
24
|
+
* window never open a second allowance in it.
|
|
19
25
|
*/
|
|
20
26
|
grantInternalPlan: (entityId: string, planSku: string, opts?: GrantInternalPlanOptions) => Promise<PaymentSubscriptionRecord>;
|
|
27
|
+
/**
|
|
28
|
+
* End an internal grant now: `status: canceled`, `periodEnd` / `endedAt` = now (a grant already
|
|
29
|
+
* past its period end keeps that instant), `canceledAt` = now. Observers hear `canceled` — the
|
|
30
|
+
* event a paygate cancellation delivers. Idempotent: no row, or a row ended already, changes
|
|
31
|
+
* nothing and tells nobody.
|
|
32
|
+
*
|
|
33
|
+
* @returns whether anything changed
|
|
34
|
+
*/
|
|
35
|
+
revokeInternalPlan: (entityId: string, planSku: string) => Promise<boolean>;
|
|
21
36
|
}
|
|
22
37
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commit/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,eAAe,EACjG,oBAAoB,EACrB,MAAM,aAAa,CAAA;AAEpB,gHAAgH;AAChH,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,UAAU,EAAE,CAAC,MAAM,EAAE,yBAAyB,EAAE,KAAK,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACzG;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAClB,QAAQ,EAAE,yBAAyB,GAAG,IAAI,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE,aAAa,KAC9F,OAAO,CAAC,YAAY,CAAC,CAAA;IAC1B
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commit/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,eAAe,EACjG,oBAAoB,EACrB,MAAM,aAAa,CAAA;AAEpB,gHAAgH;AAChH,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,UAAU,EAAE,CAAC,MAAM,EAAE,yBAAyB,EAAE,KAAK,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACzG;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAClB,QAAQ,EAAE,yBAAyB,GAAG,IAAI,EAAE,IAAI,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE,aAAa,KAC9F,OAAO,CAAC,YAAY,CAAC,CAAA;IAC1B;;;;;;;;;;OAUG;IACH,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAC7H;;;;;;;OAOG;IACH,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC5E"}
|
package/build/commit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAajE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAEjE,eAAO,MAAM,4BAA4B,QAAS,UAAU,KAAG,
|
|
1
|
+
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAajE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAEjE,eAAO,MAAM,4BAA4B,QAAS,UAAU,KAAG,wBA6K9D,CAAA;AAED,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,yFAAmD,CAAA"}
|
package/build/commit.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ENTITLING_STATUSES, INTERNAL_PAYGATE, ProductError, SubscriptionStatus, UnknownPlan } from '@owlmeans/payment';
|
|
2
2
|
import { memoHelper } from '@owlmeans/context';
|
|
3
3
|
import { log } from './log.js';
|
|
4
|
-
import { SUBSCRIPTION_LOG_EVENTS } from './consts.local.js';
|
|
4
|
+
import { ENDED, SUBSCRIPTION_LOG_EVENTS } from './consts.local.js';
|
|
5
5
|
import { paymentAccessOf } from './access.js';
|
|
6
6
|
import { paymentUtils } from './utils.js';
|
|
7
7
|
import { catalogueOf } from './catalogue.js';
|
|
@@ -9,6 +9,9 @@ import { planHelper } from './plan.js';
|
|
|
9
9
|
import { subscriptionHelper } from './subscription.js';
|
|
10
10
|
export const makeSubscriptionCommitHelper = (ctx) => {
|
|
11
11
|
const access = paymentAccessOf(ctx);
|
|
12
|
+
const timeOf = (value) => value == null ? null : new Date(value).getTime();
|
|
13
|
+
/** An internal grant's row: `free:<entityId>` for a free plan, `internal:<planSku>:<entityId>` otherwise. */
|
|
14
|
+
const internalIdOf = (entityId, planSku, plan) => plan?.free === true ? `free:${entityId}` : `internal:${planSku}:${entityId}`;
|
|
12
15
|
const snapshotOf = async (record, state) => {
|
|
13
16
|
const planSku = state?.planSku ?? record.planSku;
|
|
14
17
|
const declared = await catalogueOf(ctx).findPlan(planSku);
|
|
@@ -73,7 +76,8 @@ export const makeSubscriptionCommitHelper = (ctx) => {
|
|
|
73
76
|
await opts.beforePropagate?.(stored, change);
|
|
74
77
|
await access.observer().propagateSubscription({
|
|
75
78
|
change,
|
|
76
|
-
|
|
79
|
+
// `created` has nothing before it — a row that starts entitling again starts anew too.
|
|
80
|
+
previous: change !== 'created' && prior != null && previous != null ? await snapshotOf(previous, prior) : null,
|
|
77
81
|
current: await snapshotOf(stored),
|
|
78
82
|
active: ENTITLING_STATUSES.includes(stored.status),
|
|
79
83
|
eventKey: subscriptionHelper.subscriptionEventKey(stored, change, opts),
|
|
@@ -97,10 +101,17 @@ export const makeSubscriptionCommitHelper = (ctx) => {
|
|
|
97
101
|
throw new ProductError(`internal-grant:${planSku}`);
|
|
98
102
|
}
|
|
99
103
|
const product = await catalogueOf(ctx).findProduct(plan.productSku);
|
|
100
|
-
const externalId =
|
|
104
|
+
const externalId = internalIdOf(entityId, planSku, plan);
|
|
101
105
|
const previous = await access.subscriptions().byExternalId(externalId, INTERNAL_PAYGATE);
|
|
102
106
|
const now = new Date();
|
|
103
107
|
const { periodEnd: _periodEnd, endedAt: _endedAt, canceledAt: _canceledAt, ...kept } = previous ?? {};
|
|
108
|
+
// A row that stopped entitling (revoked, or past its period end) starts anew. So does one an
|
|
109
|
+
// earlier call re-activated while its observers failed: they never heard that restart, and the
|
|
110
|
+
// retry tells them under the same key.
|
|
111
|
+
const ended = previous != null && !subscriptionHelper.entitlesAt(previous, now);
|
|
112
|
+
const untold = previous?.restartedAt != null && !ended
|
|
113
|
+
&& timeOf(previous.propagated?.restartedAt) !== timeOf(previous.restartedAt);
|
|
114
|
+
const restartedAt = ended ? now : previous?.restartedAt;
|
|
104
115
|
const next = {
|
|
105
116
|
...kept,
|
|
106
117
|
entityId,
|
|
@@ -112,13 +123,37 @@ export const makeSubscriptionCommitHelper = (ctx) => {
|
|
|
112
123
|
status: SubscriptionStatus.Active,
|
|
113
124
|
rank: planHelper.planRank(plan),
|
|
114
125
|
...(opts.periodEnd != null ? { periodEnd: opts.periodEnd } : {}),
|
|
126
|
+
// The first grant's: subscription-week windows, credit frames and grandfathered promos keep
|
|
127
|
+
// their anchor through a revoke and a re-grant, so no window opens twice.
|
|
115
128
|
createdAt: previous?.createdAt ?? now,
|
|
129
|
+
...(restartedAt != null ? { restartedAt } : {}),
|
|
116
130
|
updatedAt: now,
|
|
117
131
|
};
|
|
118
|
-
const { record } = await commitSubscription(previous, next);
|
|
132
|
+
const { record } = await commitSubscription(previous, next, ended || untold ? { restart: true } : {});
|
|
119
133
|
return record ?? next;
|
|
120
134
|
};
|
|
121
|
-
|
|
135
|
+
const revokeInternalPlan = async (entityId, planSku) => {
|
|
136
|
+
const plan = await catalogueOf(ctx).findPlan(planSku);
|
|
137
|
+
const previous = await access.subscriptions().byExternalId(internalIdOf(entityId, planSku, plan), INTERNAL_PAYGATE);
|
|
138
|
+
if (previous == null || ENDED.includes(previous.status)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const now = new Date();
|
|
142
|
+
// A grant already past its period end ended then, not now.
|
|
143
|
+
const endedAt = previous.periodEnd != null && new Date(previous.periodEnd).getTime() < now.getTime()
|
|
144
|
+
? new Date(previous.periodEnd) : now;
|
|
145
|
+
const next = {
|
|
146
|
+
...previous,
|
|
147
|
+
status: SubscriptionStatus.Canceled,
|
|
148
|
+
periodEnd: endedAt,
|
|
149
|
+
canceledAt: now,
|
|
150
|
+
endedAt,
|
|
151
|
+
updatedAt: now,
|
|
152
|
+
};
|
|
153
|
+
const { change, updated } = await commitSubscription(previous, next);
|
|
154
|
+
return change != null || updated;
|
|
155
|
+
};
|
|
156
|
+
return { snapshotOf, commitSubscription, grantInternalPlan, revokeInternalPlan };
|
|
122
157
|
};
|
|
123
158
|
/** The subscription store of a context — one per context. */
|
|
124
159
|
export const subscriptionCommitOf = memoHelper.oncePer(makeSubscriptionCommitHelper);
|
package/build/commit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEvH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAK9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../src/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEvH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAm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 @@ export declare const RES_PAYMENT_WEBHOOK = "payment-webhook";
|
|
|
30
30
|
export declare const RES_PAYMENT_USAGE = "payment-usage";
|
|
31
31
|
export declare const RES_PAYMENT_USAGE_COUNTER = "payment-usage-counter";
|
|
32
32
|
export declare const RES_PAYMENT_FINGERPRINT = "payment-fingerprint";
|
|
33
|
+
/** An organization's entitlement grants: extra units of a limit, or a capability, beside its plan. */
|
|
34
|
+
export declare const RES_PAYMENT_GRANT = "payment-grant";
|
|
35
|
+
/** What an entitlement grant gives: counted units of one limit, or one capability. */
|
|
36
|
+
export declare enum EntitlementGrantKind {
|
|
37
|
+
Units = "units",
|
|
38
|
+
Capability = "capability"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An entitlement grant's lifecycle. A grant is `active` until it is revoked; its `startsAt` /
|
|
42
|
+
* `endsAt` are read at read time, so an expired grant stays `active` and is simply out of force.
|
|
43
|
+
*/
|
|
44
|
+
export declare enum EntitlementGrantStatus {
|
|
45
|
+
Active = "active",
|
|
46
|
+
Revoked = "revoked"
|
|
47
|
+
}
|
|
48
|
+
/** The usage window of a unit held on an entitlement grant: `grant:<grantId>` — never a counter window. */
|
|
49
|
+
export declare const GRANT_WINDOW_PREFIX = "grant:";
|
|
33
50
|
/** One per organization: the billing country fixed at the first purchase. */
|
|
34
51
|
export declare const RES_BILLING_PROFILE = "payment-billing-profile";
|
|
35
52
|
/** One per paid checkout (a top-up, a subscription's first invoice): the contract and its window. */
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAA;AAEvC,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAC5C,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AACtD,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