@devlab.group/agent-commerce 1.6.1 → 2.1.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.
Files changed (57) hide show
  1. package/LICENSE +187 -2
  2. package/README.md +105 -54
  3. package/dist/ap2.d.ts +4 -4
  4. package/dist/ap2.js +95 -28
  5. package/dist/ap2.js.map +1 -1
  6. package/dist/{authorization-BpbWGGrf.d.ts → authorization-CMkIuAkO.d.ts} +1 -1
  7. package/dist/chunk-2CJNA7MS.js +8 -0
  8. package/dist/chunk-2CJNA7MS.js.map +1 -0
  9. package/dist/chunk-5ZYXBCDX.js +113 -0
  10. package/dist/chunk-5ZYXBCDX.js.map +1 -0
  11. package/dist/{chunk-V2V2E7HX.js → chunk-6Z2H53CG.js} +7 -6
  12. package/dist/chunk-6Z2H53CG.js.map +1 -0
  13. package/dist/chunk-ES3V6ECS.js +125 -0
  14. package/dist/chunk-ES3V6ECS.js.map +1 -0
  15. package/dist/chunk-IFGRCXME.js +581 -0
  16. package/dist/chunk-IFGRCXME.js.map +1 -0
  17. package/dist/chunk-KA2AX5FH.js +44 -0
  18. package/dist/chunk-KA2AX5FH.js.map +1 -0
  19. package/dist/{chunk-VKDXMXHL.js → chunk-LZS5BL3W.js} +3 -3
  20. package/dist/{chunk-VKDXMXHL.js.map → chunk-LZS5BL3W.js.map} +1 -1
  21. package/dist/{chunk-N5KRK7YA.js → chunk-SY6GUYSQ.js} +6 -10
  22. package/dist/chunk-SY6GUYSQ.js.map +1 -0
  23. package/dist/chunk-UHMYRV3J.js +1396 -0
  24. package/dist/chunk-UHMYRV3J.js.map +1 -0
  25. package/dist/cli/index.js +2980 -1964
  26. package/dist/cli/index.js.map +1 -1
  27. package/dist/{constants-Bkq04FRZ.d.ts → constants-nackLItD.d.ts} +4 -3
  28. package/dist/{guardrails-71XwtXlT.d.ts → guardrails-CX_jYXvZ.d.ts} +9 -1
  29. package/dist/index.d.ts +88 -49
  30. package/dist/index.js +3432 -2161
  31. package/dist/index.js.map +1 -1
  32. package/dist/mcp.d.ts +3 -3
  33. package/dist/mcp.js +252 -94
  34. package/dist/mcp.js.map +1 -1
  35. package/dist/mpp.d.ts +15 -4
  36. package/dist/mpp.js +115 -74
  37. package/dist/mpp.js.map +1 -1
  38. package/dist/near-D6C42VPE.js +58 -0
  39. package/dist/near-D6C42VPE.js.map +1 -0
  40. package/dist/networks-olfflCI_.d.ts +38 -0
  41. package/dist/{protocol-adapter-DTkrXTev.d.ts → protocol-adapter-CfxU8Z2T.d.ts} +4 -2
  42. package/dist/{runtime-CiYbgGpi.d.ts → runtime-7vLNYvmU.d.ts} +25 -3
  43. package/dist/svm-QEUAUNPQ.js +33 -0
  44. package/dist/svm-QEUAUNPQ.js.map +1 -0
  45. package/dist/{types-O6lg3Q5V.d.ts → types-CVw6Sf46.d.ts} +11 -0
  46. package/dist/x402.d.ts +78 -63
  47. package/dist/x402.js +13 -4
  48. package/dist/x402.js.map +1 -1
  49. package/package.json +36 -13
  50. package/dist/chunk-AFI2CEZS.js +0 -10
  51. package/dist/chunk-AFI2CEZS.js.map +0 -1
  52. package/dist/chunk-CBJIT7QP.js +0 -258
  53. package/dist/chunk-CBJIT7QP.js.map +0 -1
  54. package/dist/chunk-JKEKKXRJ.js +0 -680
  55. package/dist/chunk-JKEKKXRJ.js.map +0 -1
  56. package/dist/chunk-N5KRK7YA.js.map +0 -1
  57. package/dist/chunk-V2V2E7HX.js.map +0 -1
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * Importing this metadata does not load `mppx`.
9
9
  */
10
+
10
11
  /** Upstream specification repository the pinned drafts were read from */
11
12
  declare const MPP_SPEC_REPOSITORY = "https://github.com/tempoxyz/mpp-specs";
12
13
  /**
@@ -18,12 +19,12 @@ declare const MPP_SPEC_REPOSITORY = "https://github.com/tempoxyz/mpp-specs";
18
19
  declare const MPP_SPEC_COMMIT = "806fdb8b8c92cda5c84b8660558921b6bbeef7e0";
19
20
  /** The core HTTP authentication draft, the `charge` intent, and its EVM method */
20
21
  declare const MPP_SPEC_DRAFTS: {
21
- readonly core: "draft-httpauth-payment-00";
22
+ readonly core: "draft-httpauth-payment-01";
22
23
  readonly intent: "draft-payment-intent-charge-00";
23
24
  readonly method: "draft-evm-charge-00";
24
25
  };
25
26
  /** Exact `mppx` release the rail is pinned to */
26
- declare const MPPX_VERSION = "0.10.1";
27
+ declare const MPPX_VERSION = "0.13.1";
27
28
  /**
28
29
  * The pinned profile.
29
30
  *
@@ -40,7 +41,7 @@ declare const MPP_PROFILE: {
40
41
  readonly assetDecimals: 6;
41
42
  };
42
43
  /** Supported CAIP-2 networks; gateway config applies the x402 mainnet guardrails */
43
- declare const MPP_NETWORKS: readonly ["eip155:84532", "eip155:8453"];
44
+ declare const MPP_NETWORKS: readonly ["eip155:31337", "eip155:84532", "eip155:8453"];
44
45
  type MppNetwork = (typeof MPP_NETWORKS)[number];
45
46
  /** Compact descriptor value naming the core draft, intent and method */
46
47
  declare const MPP_SUPPORTED_SPEC: string;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * x402 exact-scheme flows, shared by the config loader and CLI.
3
+ * The default `authorization` flow settles after a successful backend call;
4
+ * `upfront` settles first.
5
+ */
6
+ declare const X402_PAYMENT_FLOWS: readonly ["authorization", "upfront"];
7
+ type X402PaymentFlow = (typeof X402_PAYMENT_FLOWS)[number];
8
+
1
9
  /**
2
10
  * How the gateway authenticates to a remote facilitator.
3
11
  *
@@ -28,4 +36,4 @@ type X402FacilitatorConfig = {
28
36
  readonly auth: FacilitatorAuth;
29
37
  };
30
38
 
31
- export type { FacilitatorAuth as F, X402FacilitatorConfig as X };
39
+ export type { FacilitatorAuth as F, X402PaymentFlow as X, X402FacilitatorConfig as a };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { f as Ap2AuthorizationConfig } from './types-O6lg3Q5V.js';
2
- import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as CommerceResource, b as PaymentSubmission, B as BackendHandler, A as AdapterDescriptor, c as AdapterHealth, R as ResourceRegistry, d as PaymentProvider, L as Logger, C as Clock, e as IdGenerator } from './runtime-CiYbgGpi.js';
3
- export { f as AuthorizationMethodName, g as BackendMethod, h as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, i as PAYMENT_METHOD_NAMES, j as PROTOCOL_NAMES, k as PaymentChallenge, l as PaymentContext, m as PaymentRequirement, n as PaymentResult, o as PaymentSettlementContext, p as PaymentVerificationContext, q as Pricing, r as ProtocolName, s as systemClock } from './runtime-CiYbgGpi.js';
4
- import { M as MppNetwork } from './constants-Bkq04FRZ.js';
5
- import { X as X402FacilitatorConfig } from './guardrails-71XwtXlT.js';
6
- import { a as AuthorizationRequirement, b as AuthorizationSubmission, A as AuthorizationProvider } from './authorization-BpbWGGrf.js';
7
- export { c as AuthorizationFinalizeContext, d as AuthorizationRecord, e as AuthorizationVerification, f as AuthorizationVerificationContext } from './authorization-BpbWGGrf.js';
8
- import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, a as PaymentAttempt, b as CommerceReceipt, E as ExecutionPipeline, c as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, d as ProtocolAdapterContext } from './protocol-adapter-DTkrXTev.js';
9
- export { e as COMMERCE_EVENT_TYPES, f as CanonicalRequest, g as CommerceEventType, h as EventSink, i as ExecutionOutcome, j as isHttpProtocolAdapter } from './protocol-adapter-DTkrXTev.js';
1
+ import { f as Ap2AuthorizationConfig } from './types-CVw6Sf46.js';
2
+ import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, a as CommerceResource, b as PaymentSubmission, B as BackendHandler, A as AdapterDescriptor, c as AdapterHealth, R as ResourceRegistry, d as PaymentProvider, L as Logger, C as Clock, e as IdGenerator } from './runtime-7vLNYvmU.js';
3
+ export { f as AdapterHealthComponent, g as AuthorizationMethodName, h as BackendMethod, i as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, j as PAYMENT_METHOD_NAMES, k as PROTOCOL_NAMES, l as PaymentChallenge, m as PaymentContext, n as PaymentRequirement, o as PaymentResult, p as PaymentSettlementContext, q as PaymentVerificationContext, r as Pricing, s as ProtocolName, t as systemClock } from './runtime-7vLNYvmU.js';
4
+ import { M as MppNetwork } from './constants-nackLItD.js';
5
+ import { X as X402PaymentFlow, a as X402FacilitatorConfig } from './guardrails-CX_jYXvZ.js';
6
+ import { C as CustomNetworks } from './networks-olfflCI_.js';
7
+ import { a as AuthorizationRequirement, b as AuthorizationSubmission, A as AuthorizationProvider } from './authorization-CMkIuAkO.js';
8
+ export { c as AuthorizationFinalizeContext, d as AuthorizationRecord, e as AuthorizationVerification, f as AuthorizationVerificationContext } from './authorization-CMkIuAkO.js';
9
+ import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, a as PaymentAttempt, b as CommerceReceipt, E as ExecutionPipeline, c as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, d as ProtocolAdapterContext } from './protocol-adapter-CfxU8Z2T.js';
10
+ export { e as COMMERCE_EVENT_TYPES, f as CanonicalRequest, g as CommerceEventType, h as EventSink, i as ExecutionOutcome, j as isHttpProtocolAdapter } from './protocol-adapter-CfxU8Z2T.js';
10
11
  import { FastifyInstance } from 'fastify';
11
12
  import { IncomingMessage, ServerResponse } from 'node:http';
12
13
 
@@ -152,8 +153,14 @@ interface PaymentRequiredEnvelope {
152
153
  readonly version: string;
153
154
  readonly amount: DecimalAmount;
154
155
  readonly currency: string;
155
- readonly destination: string;
156
+ /**
157
+ * @deprecated Read each offer's `payTo` in `accepts`. Absent when the
158
+ * challenge offers several destinations.
159
+ */
160
+ readonly destination?: string;
161
+ /** @deprecated Read each offer's `network` in `accepts` */
156
162
  readonly network?: string;
163
+ /** @deprecated Read each offer's `asset` in `accepts` */
157
164
  readonly asset?: string;
158
165
  readonly expiresAt?: IsoTimestamp;
159
166
  /** Provider-native requirement objects, passed through verbatim */
@@ -265,6 +272,12 @@ interface BackendRequest {
265
272
  * when absent, the executor adds none.
266
273
  */
267
274
  readonly idempotencyKey?: string;
275
+ /**
276
+ * Adapter-supplied headers for the backend. Configured and executor-set
277
+ * headers take precedence. The HTTP executor filters sensitive and transport
278
+ * headers and rejects invalid names or values with `INPUT_INVALID`.
279
+ */
280
+ readonly backendHeaders?: Readonly<Record<string, string>>;
268
281
  }
269
282
  interface BackendResponse {
270
283
  readonly status: number;
@@ -299,6 +312,12 @@ interface PaymentAttemptReservation {
299
312
  readonly currency: string;
300
313
  readonly payer?: string;
301
314
  readonly payee?: string;
315
+ /**
316
+ * Reclaim this `replayKey` if the same `provider` rejected it, which
317
+ * settled nothing. Set only for rails whose authorizations remain reusable
318
+ * until settled.
319
+ */
320
+ readonly reclaimRejected?: boolean;
302
321
  }
303
322
  interface PaymentAttemptUpdate {
304
323
  readonly replayKey: string;
@@ -315,9 +334,14 @@ interface ReceiptStore {
315
334
  /** Append a canonical event. Must not throw into the caller's flow */
316
335
  appendEvent(event: CommerceEvent): Promise<void>;
317
336
  /**
318
- * Atomically claim a payment authorization before settlement: the gateway's
319
- * replay defense, run for every paid request. Throws
320
- * `CommerceError('PAYMENT_REPLAYED')` if `replayKey` was already reserved.
337
+ * Atomically reserve a payment authorization before settlement. If its
338
+ * `replayKey` is already reserved, throws `CommerceError('PAYMENT_REPLAYED')`
339
+ * with the existing attempt's `PaymentAttempt.status` in
340
+ * `details.attemptStatus` when available.
341
+ *
342
+ * With `reclaimRejected`, replace the same provider's `rejected` attempt,
343
+ * which settled nothing. Only one concurrent claim can replace it with the
344
+ * new reservation.
321
345
  */
322
346
  reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt>;
323
347
  updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void>;
@@ -374,25 +398,6 @@ declare const ACP_WELL_KNOWN_PATH = "/.well-known/acp.json";
374
398
  declare const ACP_CHECKOUT_OPERATIONS: readonly ["createCheckoutSession", "updateCheckoutSession", "getCheckoutSession", "completeCheckoutSession", "cancelCheckoutSession"];
375
399
  type AcpCheckoutOperation = (typeof ACP_CHECKOUT_OPERATIONS)[number];
376
400
 
377
- /**
378
- * `config.yaml` schema, validation and normalization into the canonical
379
- * `GatewayConfig` (docs/contracts.md).
380
- *
381
- * 1. Zod validates shape: types, required fields, unknown keys. Numeric and
382
- * boolean leaves accept their native type or a string, because env
383
- * substitution produces strings. Zod transforms interact badly with
384
- * `.strict()` inference, so coercion happens in plain TypeScript in step 2.
385
- * 2. A business-rule pass coerces those leaves and checks what needs a
386
- * specific message: cross-references, disabled protocols and payment
387
- * methods, dynamic pricing, addresses, duplicate trust entries.
388
- *
389
- * Env substitution (`${VAR}` / `${VAR:-default}`) runs over the raw value
390
- * before both steps, so numeric and boolean fields can be templated. The one
391
- * exception is `version:`, checked before substitution: it decides whether this
392
- * parser understands the document at all, so it cannot depend on the
393
- * environment.
394
- */
395
-
396
401
  /** Optional ACP discovery metadata. Absent fields are omitted from the document */
397
402
  interface AcpDiscoveryConfig {
398
403
  readonly documentationUrl?: string;
@@ -417,12 +422,27 @@ type AcpProtocolConfig = {
417
422
  readonly idempotency: {
418
423
  readonly path: string;
419
424
  readonly retentionHours: number;
425
+ readonly merchantIdempotent: boolean;
420
426
  };
421
427
  readonly checkout: {
422
428
  readonly operations: Readonly<Record<AcpCheckoutOperation, string>>;
423
429
  };
424
430
  readonly discovery?: AcpDiscoveryConfig;
425
431
  };
432
+ /** One resolved x402 option: where a payment settles and in which token */
433
+ interface X402OptionConfig {
434
+ readonly network: string;
435
+ /** This network's RPC: `payments.x402.networks.<id>.rpcUrl`, else `payments.x402.rpcUrl` */
436
+ readonly rpcUrl: string;
437
+ readonly asset: string;
438
+ /** EIP-712 domain of the token; always present for EIP-3009 */
439
+ readonly assetName?: string;
440
+ readonly assetVersion?: string;
441
+ readonly assetDecimals: number;
442
+ readonly payTo: string;
443
+ /** Absent for EIP-3009, the default */
444
+ readonly assetTransferMethod?: 'permit2';
445
+ }
426
446
  interface GatewayConfig {
427
447
  readonly version: 1;
428
448
  readonly merchant: {
@@ -464,14 +484,33 @@ interface GatewayConfig {
464
484
  readonly network: string;
465
485
  readonly rpcUrl: string;
466
486
  readonly asset: string;
467
- readonly assetName: string;
468
- readonly assetVersion: string;
487
+ /** Always present for EIP-3009; a Permit2 option may have none */
488
+ readonly assetName?: string;
489
+ readonly assetVersion?: string;
469
490
  readonly assetDecimals: number;
470
491
  readonly payTo: string;
492
+ /** Absent for EIP-3009, the default */
493
+ readonly assetTransferMethod?: 'permit2';
471
494
  readonly maxTimeoutSeconds: number;
495
+ /** Defaults to `authorization`, the x402 default */
496
+ readonly paymentFlow?: X402PaymentFlow;
497
+ /** Resources whose `paymentFlow` overrides the rail's, by resource id */
498
+ readonly resourcePaymentFlows?: Readonly<Record<string, X402PaymentFlow>>;
472
499
  readonly facilitator: X402FacilitatorConfig;
473
500
  readonly allowMainnet?: boolean;
474
501
  readonly allowUnauthenticatedFacilitator?: boolean;
502
+ /** EVM networks declared beside the built-in ones, by CAIP-2 id */
503
+ readonly networks?: CustomNetworks;
504
+ /**
505
+ * Resolved options in challenge order; fields above mirror the first.
506
+ * Omit for manually built single-option configs that skip `parseConfig`
507
+ */
508
+ readonly options?: readonly X402OptionConfig[];
509
+ /**
510
+ * Resource `x402.accepts` overrides by id, replacing `options`.
511
+ * Absent when no resource overrides its offers.
512
+ */
513
+ readonly resourceOptions?: Readonly<Record<string, readonly X402OptionConfig[]>>;
475
514
  };
476
515
  readonly mpp?: {
477
516
  readonly enabled: boolean;
@@ -484,6 +523,10 @@ interface GatewayConfig {
484
523
  readonly realm: string;
485
524
  readonly challengeSecret: string;
486
525
  readonly challengeTtlSeconds?: number;
526
+ /** Defaults to `upfront`: settle before the backend call */
527
+ readonly paymentFlow?: X402PaymentFlow;
528
+ /** Resources whose `paymentFlow` overrides the rail's, by resource id */
529
+ readonly resourcePaymentFlows?: Readonly<Record<string, X402PaymentFlow>>;
487
530
  readonly facilitator: X402FacilitatorConfig;
488
531
  readonly allowMainnet?: boolean;
489
532
  readonly allowUnauthenticatedFacilitator?: boolean;
@@ -494,6 +537,7 @@ interface GatewayConfig {
494
537
  readonly ap2: Ap2AuthorizationConfig;
495
538
  };
496
539
  }
540
+
497
541
  declare function parseConfig(raw: unknown, env: NodeJS.ProcessEnv): GatewayConfig;
498
542
 
499
543
  interface LoadConfigOptions {
@@ -528,18 +572,6 @@ interface GatewayInstance {
528
572
  }
529
573
  declare function createGateway(options: GatewayOptions): Promise<GatewayInstance>;
530
574
 
531
- /**
532
- * A2A (Agent2Agent) protocol adapter, experimental.
533
- *
534
- * Serves two paths: the configured mount (`/a2a`), where the JSON-RPC endpoint
535
- * lives, and the specification-fixed `/.well-known/agent-card.json`, declared
536
- * through `additionalHttpRoutes` so the gateway needs no A2A-specific routing.
537
- *
538
- * Only the synchronous `SendMessage` path is in scope; every other A2A method
539
- * is listed in `descriptor.unsupported` rather than half-served. This file
540
- * never calls a merchant backend and never inspects a payment object.
541
- */
542
-
543
575
  interface A2aAdapterOptions {
544
576
  readonly mountPath?: string;
545
577
  /** Agent name published on the card */
@@ -560,6 +592,9 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
560
592
  private started;
561
593
  private skillsById;
562
594
  private card;
595
+ private cardBody;
596
+ private cardEtag;
597
+ private pendingPayments;
563
598
  constructor(options?: A2aAdapterOptions);
564
599
  start(context: ProtocolAdapterContext): Promise<void>;
565
600
  /** `GET /.well-known/agent-card.json` */
@@ -569,7 +604,6 @@ declare class A2aProtocolAdapter implements HttpProtocolAdapter {
569
604
  private dispatch;
570
605
  private execute;
571
606
  private taskIdentity;
572
- private taskResult;
573
607
  health(): Promise<AdapterHealth>;
574
608
  stop(): Promise<void>;
575
609
  private writeJson;
@@ -580,12 +614,12 @@ declare function createA2aAdapter(options?: A2aAdapterOptions): A2aProtocolAdapt
580
614
  * A2A pins, kept in one place so nothing infers one version from another.
581
615
  *
582
616
  * The specification revision and the negotiation version look alike but
583
- * differ: `1.0.0` names the document this adapter was written against, `1.0`
617
+ * differ: `1.0.1` names the document this adapter was written against, `1.0`
584
618
  * is what a client negotiates on the wire. Neither is this package's version
585
619
  * (`PACKAGE_VERSION`).
586
620
  */
587
621
  /** A2A specification revision this adapter targets */
588
- declare const A2A_SPEC_VERSION = "1.0.0";
622
+ declare const A2A_SPEC_VERSION = "1.0.1";
589
623
  /** Protocol negotiation version carried on the wire */
590
624
  declare const A2A_PROTOCOL_VERSION = "1.0";
591
625
  /**
@@ -626,6 +660,11 @@ interface AcpAdapterOptions {
626
660
  readonly idempotency: {
627
661
  readonly path: string;
628
662
  readonly retentionHours: number;
663
+ /**
664
+ * Declare that the merchant deduplicates by the derived `Idempotency-Key`.
665
+ * Allows a fresh retry after a 5xx. Defaults to false.
666
+ */
667
+ readonly merchantIdempotent?: boolean;
629
668
  };
630
669
  readonly discovery?: AcpDiscoveryMetadata;
631
670
  }