@devlab.group/agent-commerce 2.5.0 → 2.7.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 +78 -21
- package/dist/ap2.d.ts +19 -6
- package/dist/ap2.js +56 -18
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
- package/dist/chunk-77HLISG4.js.map +1 -0
- package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
- package/dist/chunk-D7FPSGUQ.js.map +1 -0
- package/dist/{chunk-VUCMBGUR.js → chunk-DJRWYDKJ.js} +3 -3
- package/dist/{chunk-VUCMBGUR.js.map → chunk-DJRWYDKJ.js.map} +1 -1
- package/dist/{chunk-4K7FIBJM.js → chunk-EMKITGVV.js} +4 -4
- package/dist/chunk-EMKITGVV.js.map +1 -0
- package/dist/chunk-IWXVQYG5.js +6 -0
- package/dist/chunk-IWXVQYG5.js.map +1 -0
- package/dist/chunk-O3ACF45K.js +8 -0
- package/dist/chunk-O3ACF45K.js.map +1 -0
- package/dist/chunk-WDD2ZUR3.js +20 -0
- package/dist/chunk-WDD2ZUR3.js.map +1 -0
- package/dist/{chunk-3OTCFFFT.js → chunk-YHNTTMED.js} +7 -7
- package/dist/chunk-YHNTTMED.js.map +1 -0
- package/dist/{chunk-FKQK5XZA.js → chunk-ZSIUZPNB.js} +183 -80
- package/dist/chunk-ZSIUZPNB.js.map +1 -0
- package/dist/cli/{ap2-YAPLERSC.js → ap2-5FFGSW6F.js} +61 -25
- package/dist/cli/ap2-5FFGSW6F.js.map +1 -0
- package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
- package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
- package/dist/cli/{chunk-NIU5EMSB.js → chunk-3NVJAQRO.js} +5 -5
- package/dist/cli/{chunk-NIU5EMSB.js.map → chunk-3NVJAQRO.js.map} +1 -1
- package/dist/cli/{chunk-IDY2735M.js → chunk-55AI6CLW.js} +6 -4
- package/dist/cli/chunk-55AI6CLW.js.map +1 -0
- package/dist/cli/{chunk-QA2OPHBF.js → chunk-5K2JDM4G.js} +185 -83
- package/dist/cli/chunk-5K2JDM4G.js.map +1 -0
- package/dist/cli/{chunk-QLUCNPRT.js → chunk-5TID36YG.js} +860 -170
- package/dist/cli/chunk-5TID36YG.js.map +1 -0
- package/dist/cli/{chunk-5R7DM5LM.js → chunk-66NTYSXI.js} +27 -27
- package/dist/cli/chunk-66NTYSXI.js.map +1 -0
- package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
- package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
- package/dist/cli/{chunk-4H2QLHQI.js → chunk-AGQ4U7IN.js} +5 -5
- package/dist/cli/chunk-AGQ4U7IN.js.map +1 -0
- package/dist/cli/chunk-APC5BTQM.js +6 -0
- package/dist/cli/chunk-APC5BTQM.js.map +1 -0
- package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
- package/dist/cli/chunk-C5YISPT6.js.map +1 -0
- package/dist/cli/chunk-DKWO6LLX.js +34 -0
- package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
- package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
- package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
- package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
- package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
- package/dist/cli/{chunk-Z34UMZBB.js → chunk-OETKXDGA.js} +546 -175
- package/dist/cli/chunk-OETKXDGA.js.map +1 -0
- package/dist/cli/{chunk-JFVRG2HH.js → chunk-PLHPKXAT.js} +8 -8
- package/dist/cli/chunk-PLHPKXAT.js.map +1 -0
- package/dist/cli/{chunk-2UPPX3FJ.js → chunk-VSSSU4AU.js} +76 -14
- package/dist/cli/chunk-VSSSU4AU.js.map +1 -0
- package/dist/cli/chunk-ZCW56PZ3.js +8 -0
- package/dist/cli/{chunk-M7NXVRU5.js.map → chunk-ZCW56PZ3.js.map} +1 -1
- package/dist/cli/{chunk-2J2IQQ4X.js → chunk-ZFVQWOGG.js} +95 -42
- package/dist/cli/chunk-ZFVQWOGG.js.map +1 -0
- package/dist/cli/config-WT5HHDRR.js +13 -0
- package/dist/cli/{config-BWFMN2ZB.js.map → config-WT5HHDRR.js.map} +1 -1
- package/dist/cli/index.js +560 -252
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-KZEMXLHR.js → mcp-HHGNOUKE.js} +7 -7
- package/dist/cli/{mcp-KZEMXLHR.js.map → mcp-HHGNOUKE.js.map} +1 -1
- package/dist/cli/payment-providers-EWXZFBIE.js +6 -0
- package/dist/cli/{payment-providers-SZL36H3Y.js.map → payment-providers-EWXZFBIE.js.map} +1 -1
- package/dist/cli/{provider-6TKB5ADJ.js → provider-XUPLYNQ7.js} +36 -18
- package/dist/cli/provider-XUPLYNQ7.js.map +1 -0
- package/dist/cli/receipts-3DSV4DIK.js +9 -0
- package/dist/cli/{receipts-ZGLJWMQG.js.map → receipts-3DSV4DIK.js.map} +1 -1
- package/dist/cli/reconcile-GS25MQ42.js +4 -0
- package/dist/cli/{reconcile-IC22MJD5.js.map → reconcile-GS25MQ42.js.map} +1 -1
- package/dist/cli/{run-ZTYPQI4D.js → run-7KLKW3HE.js} +310 -91
- package/dist/cli/run-7KLKW3HE.js.map +1 -0
- package/dist/cli/{x402-WLYBLODI.js → x402-HP4E3QET.js} +11 -10
- package/dist/cli/x402-HP4E3QET.js.map +1 -0
- package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
- package/dist/index.d.ts +119 -206
- package/dist/index.js +1703 -427
- 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 +4 -3
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +2 -1
- package/dist/mpp.js +32 -13
- package/dist/mpp.js.map +1 -1
- package/dist/{protocol-adapter-DEXpdp8m.d.ts → protocol-adapter-DdFL5LBU.d.ts} +15 -132
- package/dist/{runtime-Dz2fSO-P.d.ts → runtime-BmaSp2Ce.d.ts} +36 -23
- package/dist/store-BVvMzpuV.d.ts +389 -0
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +2050 -0
- package/dist/testing.js.map +1 -0
- package/dist/transaction-BXXJltZ-.d.ts +129 -0
- package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
- package/dist/x402.d.ts +9 -3
- package/dist/x402.js +7 -5
- package/dist/x402.js.map +1 -1
- package/package.json +17 -29
- package/dist/chunk-3OTCFFFT.js.map +0 -1
- package/dist/chunk-4K7FIBJM.js.map +0 -1
- package/dist/chunk-5ZYXBCDX.js.map +0 -1
- package/dist/chunk-ES3V6ECS.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-4H2QLHQI.js.map +0 -1
- package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
- package/dist/cli/chunk-5R7DM5LM.js.map +0 -1
- package/dist/cli/chunk-FHCFR2GS.js +0 -17
- package/dist/cli/chunk-FHCFR2GS.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-SPAYKVUP.js.map +0 -1
- package/dist/cli/chunk-SYQLJXIU.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/dist/cli/x402-WLYBLODI.js.map +0 -1
package/README.md
CHANGED
|
@@ -120,7 +120,6 @@ free HTTP resources does not install MCP, EVM, JOSE or SD-JWT packages.
|
|
|
120
120
|
| accept x402 on NEAR | x402 peers `+ @x402/near` | (no import - loaded for a NEAR offer) |
|
|
121
121
|
| accept MPP payments | `+ mppx viem @x402/core @x402/evm` | `from '@devlab.group/agent-commerce/mpp'` |
|
|
122
122
|
| verify AP2 mandates, sign checkout JWTs | `+ jose @sd-jwt/core canonicalize` | `from '@devlab.group/agent-commerce/ap2'` |
|
|
123
|
-
| authenticate to a CDP facilitator | `+ @coinbase/x402` | (no import - loaded on demand) |
|
|
124
123
|
|
|
125
124
|
The x402 entry needs `@x402/core`, `@x402/evm` and `viem` even when every
|
|
126
125
|
offer is on Solana or NEAR. MPP settles through an x402 facilitator, so its
|
|
@@ -144,14 +143,38 @@ boundary, so a version skew is a correctness problem rather than a convenience
|
|
|
144
143
|
one. Importing a subpath without its peer fails at load time and names the
|
|
145
144
|
missing package.
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
### Testing a custom store
|
|
147
|
+
|
|
148
|
+
`createGateway` accepts a custom `ReceiptStore`. The experimental `./testing`
|
|
149
|
+
entry exports conformance cases to test it. The cases use `node:assert/strict`
|
|
150
|
+
and import no test runner or optional peers, so you can wrap them with your
|
|
151
|
+
runner:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { receiptStoreConformanceCases } from '@devlab.group/agent-commerce/testing';
|
|
155
|
+
import { it } from 'vitest';
|
|
156
|
+
|
|
157
|
+
const cases = await receiptStoreConformanceCases(({ clock }) => ({
|
|
158
|
+
store: createMyStore({ clock }),
|
|
159
|
+
}));
|
|
160
|
+
for (const c of cases) it.skipIf(c.skip !== undefined)(c.name, () => c.run());
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Have the factory return a new, empty store for each case. The suite calls
|
|
164
|
+
`init()` and `close()`. Pass the supplied `clock` to the store so expiry cases
|
|
165
|
+
can advance time without waiting.
|
|
166
|
+
|
|
167
|
+
Each optional method group, such as authorization holds, must be implemented
|
|
168
|
+
in full or omitted; one case checks this. Cases that need missing methods are
|
|
169
|
+
marked to skip. Durability cases also skip unless the factory returns `reopen()`,
|
|
170
|
+
which must close the current store and open another over the same data.
|
|
171
|
+
Concurrency cases submit competing reservations, resolutions, idempotency
|
|
172
|
+
claims and pending-task takes, then check that exactly one caller wins.
|
|
150
173
|
|
|
151
174
|
## Integrate with an AI coding agent
|
|
152
175
|
|
|
153
176
|
The repository includes an experimental [Agent Skills](https://agentskills.io)
|
|
154
|
-
skill, [`
|
|
177
|
+
skill, [`agent-commerce`](plugins/agent-commerce-gateway/skills/agent-commerce/SKILL.md), for adding the
|
|
155
178
|
gateway to an existing API. It covers Base Sepolia configuration, startup and
|
|
156
179
|
checks through an unpaid 402 challenge. Its instructions keep secrets out of
|
|
157
180
|
chat and leave payment signing to the user. The skill has automated CLI and
|
|
@@ -160,7 +183,7 @@ config checks.
|
|
|
160
183
|
```text
|
|
161
184
|
# Claude Code
|
|
162
185
|
/plugin marketplace add devlab-group/agent-commerce
|
|
163
|
-
/plugin install agent-commerce@agent-commerce
|
|
186
|
+
/plugin install agent-commerce-gateway@agent-commerce
|
|
164
187
|
|
|
165
188
|
# Codex, Cursor and other agents (a third-party installer)
|
|
166
189
|
DISABLE_TELEMETRY=1 npx skills add devlab-group/agent-commerce --skill agent-commerce
|
|
@@ -311,11 +334,15 @@ prints the `unsupported` lists for A2A, ACP and AP2 when they are enabled.
|
|
|
311
334
|
### Versioning
|
|
312
335
|
|
|
313
336
|
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
|
-
|
|
337
|
+
MPP, A2A, ACP, AP2, ERC-8409 quotes, `agent-commerce import openapi`,
|
|
338
|
+
`PaymentProvider.reconcile`, the `ReceiptStore` methods and types added in
|
|
339
|
+
2.6.0, the `idempotency` resource settings with the store and provider methods
|
|
340
|
+
added in 2.7.0, and the `./testing` entry.
|
|
341
|
+
|
|
342
|
+
The journal's `Transaction` type, `ReceiptStore` journal methods and
|
|
343
|
+
`/api/transactions` response shape are supported. The `transactionId` fields,
|
|
344
|
+
`receiptCommitted` and flags accepted by `reconcile` and `resolve` are also
|
|
345
|
+
supported.
|
|
319
346
|
|
|
320
347
|
Experimental runtime adapters and providers identify themselves with
|
|
321
348
|
`status: experimental` in `GET /.well-known/agent-commerce`. Pin experimental
|
|
@@ -334,6 +361,14 @@ differ from 2.0; see [Upgrading from 2.0 to 2.x](docs/migration-2.1.md).
|
|
|
334
361
|
- **Replay-safe twice over.** The EIP-3009 or Permit2 nonce stops a double
|
|
335
362
|
spend on-chain; the gateway additionally reserves a `replayKey` derived from
|
|
336
363
|
the authorization before it settles anything.
|
|
364
|
+
- **Retry after a lost response (experimental, disabled by default).** With
|
|
365
|
+
`idempotency.redelivery`, buyers can retrieve a stored response without
|
|
366
|
+
another charge using the same wallet, input and x402 `payment-identifier`
|
|
367
|
+
`id` or MPP `Idempotency-Key`. Matching exact resends skip verification
|
|
368
|
+
until retention ends, an exception to fail closed. Responses are stored
|
|
369
|
+
unencrypted in the receipt database. `idempotency.merchantKey` sends a
|
|
370
|
+
derived `Idempotency-Key` to the merchant for paid operations. See
|
|
371
|
+
[Retry after a lost response](docs/payment-flow.md#retry-after-a-lost-response).
|
|
337
372
|
- **On-chain settlement in CI.** The end-to-end test asserts the buyer's balance
|
|
338
373
|
falls and the merchant's rises by exactly the price, with a real transaction
|
|
339
374
|
hash in the receipt. A log line saying "payment successful" would not count.
|
|
@@ -395,9 +430,9 @@ EIP-3009 authorization without ETH, and the facilitator pays gas. Because the
|
|
|
395
430
|
authorization fixes the recipient, amount and chain, the facilitator cannot
|
|
396
431
|
redirect the transfer. It can see authorizations and refuse service.
|
|
397
432
|
|
|
398
|
-
Remote facilitator auth supports `none`, `bearer` and `cdp`.
|
|
399
|
-
|
|
400
|
-
|
|
433
|
+
Remote facilitator auth supports `none`, `bearer` and `cdp`. CDP auth signs a
|
|
434
|
+
fresh JWT per request with the CDP API key. No auth mode needs an extra peer
|
|
435
|
+
package. Config load rejects other types.
|
|
401
436
|
|
|
402
437
|
### Base Sepolia
|
|
403
438
|
|
|
@@ -467,10 +502,11 @@ INFO ACP disabled
|
|
|
467
502
|
INFO AP2 disabled
|
|
468
503
|
PASS Payments x402 v2 (scheme=exact) enabled - LOCAL dev chain (eip155:31337), destination=0x7099…79C8, facilitator=local (in-process), paymentFlow=authorization
|
|
469
504
|
INFO Payments (MPP) MPP not configured
|
|
470
|
-
PASS Storage sqlite schema
|
|
505
|
+
PASS Storage sqlite schema v5 writable; receipts=2
|
|
506
|
+
PASS Transactions none unresolved
|
|
471
507
|
PASS Protocol versions reported by gateway /.well-known/agent-commerce
|
|
472
508
|
|
|
473
|
-
Score:
|
|
509
|
+
Score: 8/8 checks passed
|
|
474
510
|
```
|
|
475
511
|
|
|
476
512
|
`doctor` compares live settlement terms with local config for each rail and
|
|
@@ -511,7 +547,11 @@ checked by state: `payment-uncertain`, `payment-pending`, then
|
|
|
511
547
|
attempts are considered. A capped batch of attempts without journal entries
|
|
512
548
|
follows.
|
|
513
549
|
It exits 0 after a completed run, even if attempts remain unresolved, and 1 if
|
|
514
|
-
the run fails to complete.
|
|
550
|
+
the run fails to complete. If a store error stops a hold scan, the command
|
|
551
|
+
prints the report, preserving any saved resolutions, and exits 1.
|
|
552
|
+
`reconcile` and `resolve` refuse receipt databases below schema v5 without
|
|
553
|
+
migrating them. Back up the database, then start the gateway once before
|
|
554
|
+
retrying either command.
|
|
515
555
|
|
|
516
556
|
Each family needs its own evidence:
|
|
517
557
|
|
|
@@ -536,10 +576,14 @@ sandbox. Public-network validation is pending. EVM and NEAR can report
|
|
|
536
576
|
|
|
537
577
|
With `authorization.ap2` enabled, reconciliation also updates AP2 holds on
|
|
538
578
|
resolved payments: `settled` consumes the mandate; `rejected` releases it.
|
|
539
|
-
It
|
|
579
|
+
It updates holds in the receipt database without verifying mandates.
|
|
540
580
|
The report's `holds` list (`--json`) covers pending holds whose payments are
|
|
541
|
-
resolved in the database.
|
|
542
|
-
|
|
581
|
+
resolved in the database. It also attempts to release `reserved` holds older
|
|
582
|
+
than `--min-age` whose request has no current or archived payment attempt.
|
|
583
|
+
The pipeline reserves an attempt before calling settlement. Scanned orphan
|
|
584
|
+
holds appear in `orphanHolds`; dry runs list at most one page of them.
|
|
585
|
+
Dry runs write no resolutions or hold changes, but still open and initialize
|
|
586
|
+
the database.
|
|
543
587
|
Later runs can retry holds left pending after earlier payment resolutions,
|
|
544
588
|
including those recorded by `resolve` while AP2 was disabled.
|
|
545
589
|
|
|
@@ -572,6 +616,17 @@ run can retry it.
|
|
|
572
616
|
the admin token controls access without identifying the operator. Exit 0
|
|
573
617
|
means the resolution was written; 1 means a refusal or error.
|
|
574
618
|
|
|
619
|
+
### `agent-commerce backup`
|
|
620
|
+
|
|
621
|
+
```bash
|
|
622
|
+
npm run agent-commerce -- backup --out ./backups/2026-11-01
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
Copies the receipt database into a new or empty directory with a `backup.json`
|
|
626
|
+
manifest. It also copies existing, unimported legacy files configured for enabled
|
|
627
|
+
AP2 or ACP. It can run alongside a live gateway. See [Storage](docs/storage.md)
|
|
628
|
+
for restore and shutdown instructions.
|
|
629
|
+
|
|
575
630
|
### `agent-commerce version`
|
|
576
631
|
|
|
577
632
|
```bash
|
|
@@ -620,7 +675,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
620
675
|
mainnet, Solana devnet and Solana mainnet, receipts, doctor, deterministic
|
|
621
676
|
demo, experimental A2A v1.0.1 and ACP `2026-04-17` checkout adapters,
|
|
622
677
|
experimental AP2 v0.2.0 mandate verification, experimental MPP `charge`
|
|
623
|
-
payments, and experimental
|
|
678
|
+
payments, experimental OpenAPI import, and experimental retries after a lost
|
|
679
|
+
response.
|
|
624
680
|
|
|
625
681
|
**Next** - a `doctor` GitHub Action · UCP ·
|
|
626
682
|
autonomous-mode AP2 (open mandates, agent key binding, constraint evaluation) ·
|
|
@@ -639,6 +695,7 @@ they are added to a release.
|
|
|
639
695
|
| [Protocols](docs/protocols.md) | supported and unsupported protocol features |
|
|
640
696
|
| [AP2](docs/protocols/ap2.md) | mandate verification and the trust model |
|
|
641
697
|
| [Configuration](docs/configuration.md) | `config.yaml` reference |
|
|
698
|
+
| [Storage](docs/storage.md) | upgrade, backup, restore and shutdown |
|
|
642
699
|
| [Upgrading from 2.0](docs/migration-2.1.md) | changes that can break a 2.0 setup |
|
|
643
700
|
| [Smoke tests](docs/smoke-tests.md) | settling on public networks, by hand |
|
|
644
701
|
| [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-BXXJltZ-.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-DJRWYDKJ.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-DJRWYDKJ.js';
|
|
3
|
+
import { PACKAGE_VERSION } from './chunk-O3ACF45K.js';
|
|
4
|
+
import { hasMethodGroup } from './chunk-WDD2ZUR3.js';
|
|
5
|
+
import { systemClock, NOOP_LOGGER, CommerceError } from './chunk-YHNTTMED.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
|
}
|