@devlab.group/agent-commerce 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -11
- package/dist/ap2.d.ts +19 -6
- package/dist/ap2.js +56 -18
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-FKQK5XZA.js → chunk-DRLBML7Z.js} +13 -11
- package/dist/chunk-DRLBML7Z.js.map +1 -0
- package/dist/{chunk-VUCMBGUR.js → chunk-G3EYYHKF.js} +3 -3
- package/dist/{chunk-VUCMBGUR.js.map → chunk-G3EYYHKF.js.map} +1 -1
- package/dist/{chunk-3OTCFFFT.js → chunk-M52FBNJX.js} +3 -5
- package/dist/chunk-M52FBNJX.js.map +1 -0
- package/dist/chunk-M6BSXXTF.js +8 -0
- package/dist/chunk-M6BSXXTF.js.map +1 -0
- package/dist/{chunk-4K7FIBJM.js → chunk-M6MQ3FYS.js} +3 -3
- package/dist/{chunk-4K7FIBJM.js.map → chunk-M6MQ3FYS.js.map} +1 -1
- package/dist/chunk-M6WW6QIT.js +18 -0
- package/dist/chunk-M6WW6QIT.js.map +1 -0
- package/dist/cli/{ap2-YAPLERSC.js → ap2-2YMYA2H6.js} +57 -20
- package/dist/cli/ap2-2YMYA2H6.js.map +1 -0
- package/dist/cli/{chunk-5R7DM5LM.js → chunk-3NOMLMJW.js} +26 -26
- package/dist/cli/chunk-3NOMLMJW.js.map +1 -0
- package/dist/cli/chunk-4KLYFXMW.js +8 -0
- package/dist/cli/{chunk-M7NXVRU5.js.map → chunk-4KLYFXMW.js.map} +1 -1
- package/dist/cli/chunk-6R6WJ4FD.js +18 -0
- package/dist/cli/chunk-6R6WJ4FD.js.map +1 -0
- package/dist/cli/{chunk-2J2IQQ4X.js → chunk-AZL7RPFU.js} +37 -32
- package/dist/cli/chunk-AZL7RPFU.js.map +1 -0
- package/dist/cli/{chunk-JFVRG2HH.js → chunk-DHFMIBPG.js} +7 -7
- package/dist/cli/chunk-DHFMIBPG.js.map +1 -0
- package/dist/cli/{chunk-IDY2735M.js → chunk-GET3CZGR.js} +2 -2
- package/dist/cli/chunk-GET3CZGR.js.map +1 -0
- package/dist/cli/{chunk-QLUCNPRT.js → chunk-NSYSMDQN.js} +831 -169
- package/dist/cli/chunk-NSYSMDQN.js.map +1 -0
- package/dist/cli/{chunk-Z34UMZBB.js → chunk-PTL7SNOI.js} +83 -57
- package/dist/cli/chunk-PTL7SNOI.js.map +1 -0
- package/dist/cli/{chunk-2UPPX3FJ.js → chunk-TFV3K6YS.js} +75 -13
- package/dist/cli/chunk-TFV3K6YS.js.map +1 -0
- package/dist/cli/{chunk-NIU5EMSB.js → chunk-VJH6RYRK.js} +5 -5
- package/dist/cli/{chunk-NIU5EMSB.js.map → chunk-VJH6RYRK.js.map} +1 -1
- package/dist/cli/{chunk-QA2OPHBF.js → chunk-YOF7IK4V.js} +14 -13
- package/dist/cli/chunk-YOF7IK4V.js.map +1 -0
- package/dist/cli/{chunk-4H2QLHQI.js → chunk-YWG2ZN3L.js} +3 -3
- package/dist/cli/{chunk-4H2QLHQI.js.map → chunk-YWG2ZN3L.js.map} +1 -1
- package/dist/cli/config-3K65QJ22.js +12 -0
- package/dist/cli/{config-BWFMN2ZB.js.map → config-3K65QJ22.js.map} +1 -1
- package/dist/cli/index.js +524 -230
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-KZEMXLHR.js → mcp-6F64A7KE.js} +4 -4
- package/dist/cli/{mcp-KZEMXLHR.js.map → mcp-6F64A7KE.js.map} +1 -1
- package/dist/cli/payment-providers-2ITS6KNR.js +6 -0
- package/dist/cli/{payment-providers-SZL36H3Y.js.map → payment-providers-2ITS6KNR.js.map} +1 -1
- package/dist/cli/{provider-6TKB5ADJ.js → provider-5BGG5YKQ.js} +34 -16
- package/dist/cli/provider-5BGG5YKQ.js.map +1 -0
- package/dist/cli/receipts-I4IIE7U6.js +8 -0
- package/dist/cli/{receipts-ZGLJWMQG.js.map → receipts-I4IIE7U6.js.map} +1 -1
- package/dist/cli/reconcile-55WNCSFC.js +4 -0
- package/dist/cli/{reconcile-IC22MJD5.js.map → reconcile-55WNCSFC.js.map} +1 -1
- package/dist/cli/{run-ZTYPQI4D.js → run-2P6ZGFUE.js} +220 -73
- package/dist/cli/run-2P6ZGFUE.js.map +1 -0
- package/dist/cli/{x402-WLYBLODI.js → x402-4LPIIELI.js} +8 -8
- package/dist/cli/{x402-WLYBLODI.js.map → x402-4LPIIELI.js.map} +1 -1
- package/dist/index.d.ts +104 -201
- package/dist/index.js +1048 -262
- package/dist/index.js.map +1 -1
- package/dist/logger-CllGwQ8i.d.ts +19 -0
- package/dist/mcp.d.ts +3 -1
- package/dist/mcp.js +2 -1
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +2 -1
- package/dist/mpp.js +31 -12
- package/dist/mpp.js.map +1 -1
- package/dist/{protocol-adapter-DEXpdp8m.d.ts → protocol-adapter-1WbtM3xG.d.ts} +5 -132
- package/dist/{runtime-Dz2fSO-P.d.ts → runtime-B-kARa2f.d.ts} +5 -20
- package/dist/store-kIIMpUA-.d.ts +372 -0
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +1896 -0
- package/dist/testing.js.map +1 -0
- package/dist/transaction-Dv0UFGg5.d.ts +129 -0
- package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
- package/dist/x402.d.ts +2 -1
- package/dist/x402.js +5 -4
- package/dist/x402.js.map +1 -1
- package/package.json +5 -1
- package/dist/chunk-3OTCFFFT.js.map +0 -1
- package/dist/chunk-FKQK5XZA.js.map +0 -1
- package/dist/cli/ap2-YAPLERSC.js.map +0 -1
- package/dist/cli/chunk-2J2IQQ4X.js.map +0 -1
- package/dist/cli/chunk-2UPPX3FJ.js.map +0 -1
- package/dist/cli/chunk-5R7DM5LM.js.map +0 -1
- package/dist/cli/chunk-IDY2735M.js.map +0 -1
- package/dist/cli/chunk-JFVRG2HH.js.map +0 -1
- package/dist/cli/chunk-M7NXVRU5.js +0 -8
- package/dist/cli/chunk-QA2OPHBF.js.map +0 -1
- package/dist/cli/chunk-QLUCNPRT.js.map +0 -1
- package/dist/cli/chunk-Z34UMZBB.js.map +0 -1
- package/dist/cli/config-BWFMN2ZB.js +0 -12
- package/dist/cli/payment-providers-SZL36H3Y.js +0 -6
- package/dist/cli/provider-6TKB5ADJ.js.map +0 -1
- package/dist/cli/receipts-ZGLJWMQG.js +0 -8
- package/dist/cli/reconcile-IC22MJD5.js +0 -4
- package/dist/cli/run-ZTYPQI4D.js.map +0 -1
package/README.md
CHANGED
|
@@ -148,6 +148,34 @@ missing package.
|
|
|
148
148
|
`facilitator.auth.type: cdp` and brings the larger CDP dependency tree. A
|
|
149
149
|
facilitator with a static token can use `auth.type: bearer` without it.
|
|
150
150
|
|
|
151
|
+
### Testing a custom store
|
|
152
|
+
|
|
153
|
+
`createGateway` accepts a custom `ReceiptStore`. The experimental `./testing`
|
|
154
|
+
entry exports conformance cases to test it. The cases use `node:assert/strict`
|
|
155
|
+
and import no test runner or optional peers, so you can wrap them with your
|
|
156
|
+
runner:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { receiptStoreConformanceCases } from '@devlab.group/agent-commerce/testing';
|
|
160
|
+
import { it } from 'vitest';
|
|
161
|
+
|
|
162
|
+
const cases = await receiptStoreConformanceCases(({ clock }) => ({
|
|
163
|
+
store: createMyStore({ clock }),
|
|
164
|
+
}));
|
|
165
|
+
for (const c of cases) it.skipIf(c.skip !== undefined)(c.name, () => c.run());
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Have the factory return a new, empty store for each case. The suite calls
|
|
169
|
+
`init()` and `close()`. Pass the supplied `clock` to the store so expiry cases
|
|
170
|
+
can advance time without waiting.
|
|
171
|
+
|
|
172
|
+
Each optional method group, such as authorization holds, must be implemented
|
|
173
|
+
in full or omitted; one case checks this. Cases that need missing methods are
|
|
174
|
+
marked to skip. Durability cases also skip unless the factory returns `reopen()`,
|
|
175
|
+
which must close the current store and open another over the same data.
|
|
176
|
+
Concurrency cases submit competing reservations, resolutions, idempotency
|
|
177
|
+
claims and pending-task takes, then check that exactly one caller wins.
|
|
178
|
+
|
|
151
179
|
## Integrate with an AI coding agent
|
|
152
180
|
|
|
153
181
|
The repository includes an experimental [Agent Skills](https://agentskills.io)
|
|
@@ -311,11 +339,14 @@ prints the `unsupported` lists for A2A, ACP and AP2 when they are enabled.
|
|
|
311
339
|
### Versioning
|
|
312
340
|
|
|
313
341
|
Minor releases may break experimental configurations, integrations or types:
|
|
314
|
-
MPP, A2A, ACP, AP2, ERC-8409 quotes, `agent-commerce import openapi`,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
`
|
|
342
|
+
MPP, A2A, ACP, AP2, ERC-8409 quotes, `agent-commerce import openapi`,
|
|
343
|
+
`PaymentProvider.reconcile`, the `ReceiptStore` methods and types added in
|
|
344
|
+
2.6.0, and the `./testing` entry.
|
|
345
|
+
|
|
346
|
+
The journal's `Transaction` type, `ReceiptStore` journal methods and
|
|
347
|
+
`/api/transactions` response shape are supported. The `transactionId` fields,
|
|
348
|
+
`receiptCommitted` and flags accepted by `reconcile` and `resolve` are also
|
|
349
|
+
supported.
|
|
319
350
|
|
|
320
351
|
Experimental runtime adapters and providers identify themselves with
|
|
321
352
|
`status: experimental` in `GET /.well-known/agent-commerce`. Pin experimental
|
|
@@ -467,10 +498,11 @@ INFO ACP disabled
|
|
|
467
498
|
INFO AP2 disabled
|
|
468
499
|
PASS Payments x402 v2 (scheme=exact) enabled - LOCAL dev chain (eip155:31337), destination=0x7099…79C8, facilitator=local (in-process), paymentFlow=authorization
|
|
469
500
|
INFO Payments (MPP) MPP not configured
|
|
470
|
-
PASS Storage sqlite schema
|
|
501
|
+
PASS Storage sqlite schema v5 writable; receipts=2
|
|
502
|
+
PASS Transactions none unresolved
|
|
471
503
|
PASS Protocol versions reported by gateway /.well-known/agent-commerce
|
|
472
504
|
|
|
473
|
-
Score:
|
|
505
|
+
Score: 8/8 checks passed
|
|
474
506
|
```
|
|
475
507
|
|
|
476
508
|
`doctor` compares live settlement terms with local config for each rail and
|
|
@@ -511,7 +543,11 @@ checked by state: `payment-uncertain`, `payment-pending`, then
|
|
|
511
543
|
attempts are considered. A capped batch of attempts without journal entries
|
|
512
544
|
follows.
|
|
513
545
|
It exits 0 after a completed run, even if attempts remain unresolved, and 1 if
|
|
514
|
-
the run fails to complete.
|
|
546
|
+
the run fails to complete. If a store error stops a hold scan, the command
|
|
547
|
+
prints the report, preserving any saved resolutions, and exits 1.
|
|
548
|
+
`reconcile` and `resolve` refuse receipt databases below schema v5 without
|
|
549
|
+
migrating them. Back up the database, then start the gateway once before
|
|
550
|
+
retrying either command.
|
|
515
551
|
|
|
516
552
|
Each family needs its own evidence:
|
|
517
553
|
|
|
@@ -536,10 +572,14 @@ sandbox. Public-network validation is pending. EVM and NEAR can report
|
|
|
536
572
|
|
|
537
573
|
With `authorization.ap2` enabled, reconciliation also updates AP2 holds on
|
|
538
574
|
resolved payments: `settled` consumes the mandate; `rejected` releases it.
|
|
539
|
-
It
|
|
575
|
+
It updates holds in the receipt database without verifying mandates.
|
|
540
576
|
The report's `holds` list (`--json`) covers pending holds whose payments are
|
|
541
|
-
resolved in the database.
|
|
542
|
-
|
|
577
|
+
resolved in the database. It also attempts to release `reserved` holds older
|
|
578
|
+
than `--min-age` whose request has no current or archived payment attempt.
|
|
579
|
+
The pipeline reserves an attempt before calling settlement. Scanned orphan
|
|
580
|
+
holds appear in `orphanHolds`; dry runs list at most one page of them.
|
|
581
|
+
Dry runs write no resolutions or hold changes, but still open and initialize
|
|
582
|
+
the database.
|
|
543
583
|
Later runs can retry holds left pending after earlier payment resolutions,
|
|
544
584
|
including those recorded by `resolve` while AP2 was disabled.
|
|
545
585
|
|
|
@@ -572,6 +612,17 @@ run can retry it.
|
|
|
572
612
|
the admin token controls access without identifying the operator. Exit 0
|
|
573
613
|
means the resolution was written; 1 means a refusal or error.
|
|
574
614
|
|
|
615
|
+
### `agent-commerce backup`
|
|
616
|
+
|
|
617
|
+
```bash
|
|
618
|
+
npm run agent-commerce -- backup --out ./backups/2026-11-01
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
Copies the receipt database into a new or empty directory with a `backup.json`
|
|
622
|
+
manifest. It also copies existing, unimported legacy files configured for enabled
|
|
623
|
+
AP2 or ACP. It can run alongside a live gateway. See [Storage](docs/storage.md)
|
|
624
|
+
for restore and shutdown instructions.
|
|
625
|
+
|
|
575
626
|
### `agent-commerce version`
|
|
576
627
|
|
|
577
628
|
```bash
|
|
@@ -639,6 +690,7 @@ they are added to a release.
|
|
|
639
690
|
| [Protocols](docs/protocols.md) | supported and unsupported protocol features |
|
|
640
691
|
| [AP2](docs/protocols/ap2.md) | mandate verification and the trust model |
|
|
641
692
|
| [Configuration](docs/configuration.md) | `config.yaml` reference |
|
|
693
|
+
| [Storage](docs/storage.md) | upgrade, backup, restore and shutdown |
|
|
642
694
|
| [Upgrading from 2.0](docs/migration-2.1.md) | changes that can break a 2.0 setup |
|
|
643
695
|
| [Smoke tests](docs/smoke-tests.md) | settling on public networks, by hand |
|
|
644
696
|
| [OpenAPI import](docs/openapi-import.md) | generate resources from an existing API |
|
package/dist/ap2.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { E as EnabledAp2Config } from './types-
|
|
2
|
-
export { A as AP2_CHECKOUT_MANDATE_VCT, a as AP2_CHECKOUT_PROFILE, b as AP2_DEFAULT_CLOCK_SKEW_SECONDS, c as AP2_MAX_CLOCK_SKEW_SECONDS, d as AP2_SIGNING_ALGORITHM, e as AP2_SPEC_VERSION, f as Ap2AuthorizationConfig, g as Ap2Mode, h as Ap2TrustedIssuer, i as Ap2TrustedKey } from './types-
|
|
3
|
-
import { AuthorizationProvider, Clock
|
|
1
|
+
import { E as EnabledAp2Config } from './types-DWqjz81-.js';
|
|
2
|
+
export { A as AP2_CHECKOUT_MANDATE_VCT, a as AP2_CHECKOUT_PROFILE, b as AP2_DEFAULT_CLOCK_SKEW_SECONDS, c as AP2_MAX_CLOCK_SKEW_SECONDS, d as AP2_SIGNING_ALGORITHM, e as AP2_SPEC_VERSION, f as Ap2AuthorizationConfig, g as Ap2Mode, h as Ap2TrustedIssuer, i as Ap2TrustedKey } from './types-DWqjz81-.js';
|
|
3
|
+
import { AuthorizationProvider, Clock } from './index.js';
|
|
4
|
+
import { Logger } from './index.js';
|
|
5
|
+
import { ReceiptStore } from './index.js';
|
|
6
|
+
import './transaction-Dv0UFGg5.js';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* A private ES256 key: either a private JWK (the pair of the public one in the
|
|
@@ -153,7 +156,9 @@ interface Ap2ReplayStore {
|
|
|
153
156
|
* The AP2 authorization provider: the seam between core's generic contract and
|
|
154
157
|
* the mandate machinery.
|
|
155
158
|
*
|
|
156
|
-
*
|
|
159
|
+
* Choose the first available backend: `replayStore`, a receipt store with all
|
|
160
|
+
* hold methods, or the deprecated replay file. Creators must call `close()`:
|
|
161
|
+
* it closes the legacy replay backend but leaves the receipt store open.
|
|
157
162
|
* `createGateway` does not close authorization providers.
|
|
158
163
|
*/
|
|
159
164
|
|
|
@@ -161,11 +166,19 @@ interface Ap2AuthorizationProviderOptions {
|
|
|
161
166
|
readonly config: EnabledAp2Config;
|
|
162
167
|
readonly clock?: Clock;
|
|
163
168
|
readonly logger?: Logger;
|
|
164
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Holds mandates when all authorization-hold methods are present and no
|
|
171
|
+
* `replayStore` is supplied. `close()` leaves this shared store open.
|
|
172
|
+
*/
|
|
173
|
+
readonly store?: ReceiptStore;
|
|
174
|
+
/**
|
|
175
|
+
* Takes precedence over `store`, and `close()` closes it.
|
|
176
|
+
* @deprecated Pass `store`; 3.0.0 removes this option.
|
|
177
|
+
*/
|
|
165
178
|
readonly replayStore?: Ap2ReplayStore;
|
|
166
179
|
}
|
|
167
180
|
interface Ap2AuthorizationProvider extends AuthorizationProvider {
|
|
168
|
-
/**
|
|
181
|
+
/** Close the legacy replay store opened or supplied; leave the receipt store open */
|
|
169
182
|
close(): void;
|
|
170
183
|
}
|
|
171
184
|
declare function createAp2AuthorizationProvider(options: Ap2AuthorizationProviderOptions): Ap2AuthorizationProvider;
|
package/dist/ap2.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { AP2_CHECKOUT_MANDATE_VCT, AP2_SIGNING_ALGORITHM, AP2_DIGEST_ALGORITHM, AP2_CHECKOUT_PROFILE, AP2_SPEC_VERSION, AP2_KEY_TYPE, AP2_JWK_CURVE, openSqliteDatabase } from './chunk-
|
|
2
|
-
export { AP2_CHECKOUT_MANDATE_VCT, AP2_CHECKOUT_PROFILE, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_MAX_CLOCK_SKEW_SECONDS, AP2_SIGNING_ALGORITHM, AP2_SPEC_VERSION } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { AP2_CHECKOUT_MANDATE_VCT, AP2_SIGNING_ALGORITHM, AP2_DIGEST_ALGORITHM, AP2_CHECKOUT_PROFILE, AP2_SPEC_VERSION, AP2_KEY_TYPE, AP2_JWK_CURVE, openSqliteDatabase } from './chunk-G3EYYHKF.js';
|
|
2
|
+
export { AP2_CHECKOUT_MANDATE_VCT, AP2_CHECKOUT_PROFILE, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_MAX_CLOCK_SKEW_SECONDS, AP2_SIGNING_ALGORITHM, AP2_SPEC_VERSION } from './chunk-G3EYYHKF.js';
|
|
3
|
+
import { PACKAGE_VERSION } from './chunk-M6BSXXTF.js';
|
|
4
|
+
import { hasMethodGroup } from './chunk-M6WW6QIT.js';
|
|
5
|
+
import { systemClock, NOOP_LOGGER, CommerceError } from './chunk-M52FBNJX.js';
|
|
4
6
|
import { isRecord } from './chunk-2CJNA7MS.js';
|
|
5
7
|
import { SignJWT, importPKCS8, importJWK, jwtVerify, decodeProtectedHeader, decodeJwt } from 'jose';
|
|
6
8
|
import canonicalize from 'canonicalize';
|
|
@@ -632,11 +634,53 @@ function createAp2MandateVerifier(options) {
|
|
|
632
634
|
}
|
|
633
635
|
|
|
634
636
|
// src/authorization/ap2/provider.ts
|
|
637
|
+
var HOLD_STATES = {
|
|
638
|
+
consume: "consumed",
|
|
639
|
+
release: "released",
|
|
640
|
+
markUncertain: "uncertain"
|
|
641
|
+
};
|
|
642
|
+
function fileHolds(replay) {
|
|
643
|
+
return {
|
|
644
|
+
reserve: async (request) => replay.reserve(request),
|
|
645
|
+
transition: async (action, reference, requestId) => replay[action](reference, requestId),
|
|
646
|
+
stateOf: async (reference) => replay.stateOf(reference),
|
|
647
|
+
close: () => replay.close()
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
function storeHolds(store) {
|
|
651
|
+
return {
|
|
652
|
+
reserve: (request) => store.reserveAuthorizationHold({
|
|
653
|
+
method: "ap2",
|
|
654
|
+
reference: request.reference,
|
|
655
|
+
bindingReference: request.checkoutJti,
|
|
656
|
+
resourceId: request.resourceId,
|
|
657
|
+
requestId: request.requestId,
|
|
658
|
+
metadata: { mandateIssuer: request.mandateIssuer, checkoutIssuer: request.checkoutIssuer }
|
|
659
|
+
}),
|
|
660
|
+
transition: (action, reference, requestId) => store.transitionAuthorizationHold(reference, HOLD_STATES[action], requestId),
|
|
661
|
+
stateOf: (reference) => store.getAuthorizationHoldState(reference),
|
|
662
|
+
close: () => {
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function openHolds(options, logger) {
|
|
667
|
+
if (options.replayStore !== void 0) return fileHolds(options.replayStore);
|
|
668
|
+
if (hasMethodGroup(options.store, "authorization_holds")) return storeHolds(options.store);
|
|
669
|
+
const path = options.config.replay?.path;
|
|
670
|
+
if (path === void 0) {
|
|
671
|
+
throw new CommerceError(
|
|
672
|
+
"CONFIG_INVALID",
|
|
673
|
+
"AP2 needs somewhere to record spent mandates: pass a receipt store with authorization holds, or set authorization.ap2.replay.path",
|
|
674
|
+
{ details: { path: "authorization.ap2.replay.path" } }
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
return fileHolds(createAp2ReplayStore({ path, logger }));
|
|
678
|
+
}
|
|
635
679
|
function createAp2AuthorizationProvider(options) {
|
|
636
680
|
const clock = options.clock ?? systemClock;
|
|
637
681
|
const logger = options.logger ?? NOOP_LOGGER;
|
|
638
682
|
const verifier = createAp2MandateVerifier({ config: options.config, clock });
|
|
639
|
-
const
|
|
683
|
+
const holds = openHolds(options, logger);
|
|
640
684
|
const requirement = {
|
|
641
685
|
method: "ap2",
|
|
642
686
|
version: AP2_SPEC_VERSION,
|
|
@@ -651,7 +695,7 @@ function createAp2AuthorizationProvider(options) {
|
|
|
651
695
|
await bindMandateToPurchase(mandate, context, errorContext);
|
|
652
696
|
let reservation;
|
|
653
697
|
try {
|
|
654
|
-
reservation =
|
|
698
|
+
reservation = await holds.reserve({
|
|
655
699
|
reference: mandate.reference,
|
|
656
700
|
checkoutJti: mandate.checkoutJwtId,
|
|
657
701
|
mandateIssuer: mandate.mandateIssuer,
|
|
@@ -683,10 +727,10 @@ function createAp2AuthorizationProvider(options) {
|
|
|
683
727
|
}
|
|
684
728
|
};
|
|
685
729
|
}
|
|
686
|
-
const finalize = (action, reservationId, context) => {
|
|
730
|
+
const finalize = async (action, reservationId, context) => {
|
|
687
731
|
let applied;
|
|
688
732
|
try {
|
|
689
|
-
applied =
|
|
733
|
+
applied = await holds.transition(action, reservationId, context.requestId);
|
|
690
734
|
} catch (cause) {
|
|
691
735
|
throw ap2Unavailable(`replay store could not record ${action}`, { ...context, cause });
|
|
692
736
|
}
|
|
@@ -699,21 +743,15 @@ function createAp2AuthorizationProvider(options) {
|
|
|
699
743
|
descriptor: buildAp2Descriptor(PACKAGE_VERSION),
|
|
700
744
|
requirement,
|
|
701
745
|
verifyAndReserve,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
async release(reservationId, context) {
|
|
706
|
-
finalize("release", reservationId, context);
|
|
707
|
-
},
|
|
708
|
-
async markUncertain(reservationId, context) {
|
|
709
|
-
finalize("markUncertain", reservationId, context);
|
|
710
|
-
},
|
|
746
|
+
consume: (reservationId, context) => finalize("consume", reservationId, context),
|
|
747
|
+
release: (reservationId, context) => finalize("release", reservationId, context),
|
|
748
|
+
markUncertain: (reservationId, context) => finalize("markUncertain", reservationId, context),
|
|
711
749
|
async health() {
|
|
712
750
|
const startedAt = clock.monotonicMs();
|
|
713
751
|
const checkedAt = clock.nowIso();
|
|
714
752
|
let available = true;
|
|
715
753
|
try {
|
|
716
|
-
|
|
754
|
+
await holds.stateOf("health-probe");
|
|
717
755
|
} catch {
|
|
718
756
|
available = false;
|
|
719
757
|
}
|
|
@@ -730,7 +768,7 @@ function createAp2AuthorizationProvider(options) {
|
|
|
730
768
|
};
|
|
731
769
|
},
|
|
732
770
|
close() {
|
|
733
|
-
|
|
771
|
+
holds.close();
|
|
734
772
|
}
|
|
735
773
|
};
|
|
736
774
|
}
|