@devlab.group/agent-commerce 1.2.0 → 1.3.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/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, B as BackendHandler, A as AdapterDescriptor, a as AdapterHealth, C as CommerceResource, R as ResourceRegistry, b as PaymentProvider, L as Logger, c as Clock, d as IdGenerator } from './runtime-Bqg9qW3t.js';
2
- export { e as BackendMethod, f as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, g as PROTOCOL_NAMES, h as PaymentChallenge, i as PaymentContext, j as PaymentRequirement, k as PaymentResult, l as PaymentSettlementContext, m as PaymentSubmission, n as PaymentVerificationContext, o as Pricing, p as ProtocolName, s as systemClock } from './runtime-Bqg9qW3t.js';
1
+ import { I as IsoTimestamp, D as DecimalAmount, P as PaymentMethodName, B as BackendHandler, A as AdapterDescriptor, a as AdapterHealth, C as CommerceResource, R as ResourceRegistry, b as PaymentProvider, L as Logger, c as Clock, d as IdGenerator } from './runtime-Plk5Peqi.js';
2
+ export { e as BackendMethod, f as DEFAULT_BACKEND_TIMEOUT_MS, J as JsonSchema, N as NOOP_LOGGER, g as PROTOCOL_NAMES, h as PaymentChallenge, i as PaymentContext, j as PaymentRequirement, k as PaymentResult, l as PaymentSettlementContext, m as PaymentSubmission, n as PaymentVerificationContext, o as Pricing, p as ProtocolName, s as systemClock } from './runtime-Plk5Peqi.js';
3
3
  import { X as X402FacilitatorConfig } from './guardrails-Dmwi63KB.js';
4
- import { D as DeliveredOutcome, P as PaymentRequiredOutcome, C as CommerceEvent, a as PaymentAttempt, b as CommerceReceipt, E as ExecutionPipeline, c as ProtocolAdapter } from './protocol-adapter-BAKGnuZ4.js';
5
- export { A as AdapterHttpRoute, d as COMMERCE_EVENT_TYPES, e as CanonicalRequest, f as CommerceEventType, g as EventSink, h as ExecutionOutcome, H as HttpProtocolAdapter, i as ProtocolAdapterContext, j as isHttpProtocolAdapter } from './protocol-adapter-BAKGnuZ4.js';
4
+ 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-DTFGWGXq.js';
5
+ export { e as COMMERCE_EVENT_TYPES, f as CanonicalRequest, g as CommerceEventType, h as EventSink, i as ExecutionOutcome, j as isHttpProtocolAdapter } from './protocol-adapter-DTFGWGXq.js';
6
6
  import { FastifyInstance } from 'fastify';
7
- import 'node:http';
7
+ import { IncomingMessage, ServerResponse } from 'node:http';
8
8
 
9
9
  /**
10
10
  * Typed domain error codes.
@@ -309,6 +309,33 @@ interface ReceiptStore {
309
309
  close(): Promise<void>;
310
310
  }
311
311
 
312
+ /**
313
+ * ACP protocol constants shared by the config layer and the adapter.
314
+ *
315
+ * Kept dependency-free: `src/config` reads the operation set at load time, so
316
+ * anything imported here would become a config-load dependency too.
317
+ */
318
+ /**
319
+ * The ACP stable snapshot this adapter implements, and the only value accepted
320
+ * in the `API-Version` request header. Both name the same released snapshot;
321
+ * they are separate constants because ACP versions the wire contract and the
322
+ * header independently, and a future snapshot may accept more than one.
323
+ *
324
+ * Changing either means vendoring a new schema directory beside
325
+ * `spec/2026-04-17/` - never editing the vendored one in place.
326
+ */
327
+ declare const ACP_SPEC_VERSION = "2026-04-17";
328
+ declare const ACP_API_VERSION = "2026-04-17";
329
+ /** Discovery path fixed by the ACP specification - never a configurable mount. */
330
+ declare const ACP_WELL_KNOWN_PATH = "/.well-known/acp.json";
331
+ /**
332
+ * The stable checkout operations, by ACP operation id. All five are required
333
+ * when ACP is enabled: a partially configured checkout lifecycle would be
334
+ * advertised as a whole service the seller cannot actually serve.
335
+ */
336
+ declare const ACP_CHECKOUT_OPERATIONS: readonly ["createCheckoutSession", "updateCheckoutSession", "getCheckoutSession", "completeCheckoutSession", "cancelCheckoutSession"];
337
+ type AcpCheckoutOperation = (typeof ACP_CHECKOUT_OPERATIONS)[number];
338
+
312
339
  /**
313
340
  * `config.yaml` schema, validation and normalisation into the
314
341
  * canonical `GatewayConfig` (docs/contracts.md).
@@ -335,6 +362,37 @@ interface ReceiptStore {
335
362
  * substitution rule, which this sentence exists to record.
336
363
  */
337
364
 
365
+ /** Optional ACP discovery metadata. Absent fields are omitted from the document. */
366
+ interface AcpDiscoveryConfig {
367
+ readonly documentationUrl?: string;
368
+ readonly supportedCurrencies?: readonly string[];
369
+ readonly supportedLocales?: readonly string[];
370
+ readonly interventionTypes?: readonly string[];
371
+ }
372
+ /**
373
+ * Discriminated on `enabled` so an enabled ACP config carries everything the
374
+ * adapter needs, with no optional-field assertions at the mount point: a
375
+ * half-configured checkout lifecycle is rejected at load instead.
376
+ */
377
+ type AcpProtocolConfig = {
378
+ readonly enabled: false;
379
+ readonly mountPath: string;
380
+ } | {
381
+ readonly enabled: true;
382
+ readonly mountPath: string;
383
+ readonly auth: {
384
+ readonly type: 'bearer';
385
+ readonly token: string;
386
+ };
387
+ readonly idempotency: {
388
+ readonly path: string;
389
+ readonly retentionHours: number;
390
+ };
391
+ readonly checkout: {
392
+ readonly operations: Readonly<Record<AcpCheckoutOperation, string>>;
393
+ };
394
+ readonly discovery?: AcpDiscoveryConfig;
395
+ };
338
396
  interface GatewayConfig {
339
397
  readonly version: 1;
340
398
  readonly merchant: {
@@ -366,6 +424,7 @@ interface GatewayConfig {
366
424
  readonly enabled: boolean;
367
425
  readonly mountPath: string;
368
426
  };
427
+ readonly acp: AcpProtocolConfig;
369
428
  };
370
429
  /** Canonical resources, already normalised. */
371
430
  readonly resources: readonly CommerceResource[];
@@ -423,6 +482,94 @@ interface GatewayInstance {
423
482
  }
424
483
  declare function createGateway(options: GatewayOptions): Promise<GatewayInstance>;
425
484
 
485
+ /** Discovery metadata an operator may configure. Absent fields are omitted, never guessed. */
486
+ interface AcpDiscoveryMetadata {
487
+ readonly documentationUrl?: string;
488
+ readonly supportedCurrencies?: readonly string[];
489
+ readonly supportedLocales?: readonly string[];
490
+ readonly interventionTypes?: readonly string[];
491
+ }
492
+
493
+ /**
494
+ * ACP (Agentic Commerce Protocol) adapter - experimental.
495
+ *
496
+ * Serves two paths: the configured mount (`/acp`), where the five stable
497
+ * checkout routes live, and the specification-fixed `/.well-known/acp.json`,
498
+ * declared through `additionalHttpRoutes` so the gateway needs no ACP-specific
499
+ * routing.
500
+ *
501
+ * Discovery and every protocol guard that must hold before canonical execution
502
+ * are implemented. A guarded request is not executed yet: until checkout
503
+ * operations reach the pipeline, a fully-valid request is answered with an
504
+ * honest "not implemented" rather than a fabricated session.
505
+ *
506
+ * This file never calls a merchant backend and never inspects a payment
507
+ * object.
508
+ */
509
+
510
+ interface AcpAdapterOptions {
511
+ readonly mountPath: string;
512
+ /** The configured bearer token. Never logged, never echoed, never published. */
513
+ readonly token: string;
514
+ /** Which canonical resource implements each ACP checkout operation. */
515
+ readonly operations: Readonly<Record<AcpCheckoutOperation, string>>;
516
+ /** Where checkout idempotency records live, and how long they are kept. */
517
+ readonly idempotency: {
518
+ readonly path: string;
519
+ readonly retentionHours: number;
520
+ };
521
+ readonly discovery?: AcpDiscoveryMetadata;
522
+ }
523
+ declare class AcpProtocolAdapter implements HttpProtocolAdapter {
524
+ readonly name: "acp";
525
+ readonly mountPath: string;
526
+ readonly descriptor: AdapterDescriptor;
527
+ readonly additionalHttpRoutes: readonly AdapterHttpRoute[];
528
+ private readonly token;
529
+ private readonly operations;
530
+ private readonly idempotencyOptions;
531
+ /** Derived once: the token is fixed, and only its digest may be persisted. */
532
+ private readonly identityHash;
533
+ private readonly discoveryMetadata;
534
+ private idempotency;
535
+ private resources;
536
+ private context;
537
+ private started;
538
+ private discovery;
539
+ constructor(options: AcpAdapterOptions);
540
+ start(context: ProtocolAdapterContext): Promise<void>;
541
+ /** `GET /.well-known/acp.json` - public, unauthenticated, cacheable. */
542
+ handleDiscovery(req: IncomingMessage, res: ServerResponse): Promise<void>;
543
+ /** `<mountPath>/checkout_sessions...` - the five stable checkout routes. */
544
+ handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;
545
+ /**
546
+ * One request, at most one execution.
547
+ *
548
+ * A body-bearing route claims its idempotency key *before* the work starts,
549
+ * so a retry that arrives while the first one is still running finds the
550
+ * claim instead of starting a second checkout. A route with no key (the GET)
551
+ * is read-only and needs none.
552
+ */
553
+ private dispatch;
554
+ /**
555
+ * One accepted request, one `pipeline.execute()`.
556
+ *
557
+ * Nothing here prices a resource, inspects a payment proof or calls a
558
+ * merchant backend: the adapter builds a canonical request and reads back
559
+ * what the pipeline decided.
560
+ */
561
+ private runCheckout;
562
+ /**
563
+ * Protocol-owned headers only. A merchant backend's own headers are never
564
+ * proxied onto an ACP response.
565
+ */
566
+ private responseHeaders;
567
+ private fail;
568
+ health(): Promise<AdapterHealth>;
569
+ stop(): Promise<void>;
570
+ }
571
+ declare function createAcpAdapter(options: AcpAdapterOptions): AcpProtocolAdapter;
572
+
426
573
  interface SqliteReceiptStoreOptions {
427
574
  /** File path, or ':memory:' for tests. Parent directory is created if missing. */
428
575
  readonly path: string;
@@ -432,4 +579,4 @@ interface SqliteReceiptStoreOptions {
432
579
  }
433
580
  declare function createSqliteReceiptStore(options: SqliteReceiptStoreOptions): ReceiptStore;
434
581
 
435
- export { AdapterDescriptor, AdapterHealth, type BackendExecutor, BackendHandler, type BackendRequest, type BackendResponse, COMMERCE_ERROR_CODES, COMMERCE_ERROR_HTTP_STATUS, Clock, CommerceError, type CommerceErrorCode, type CommerceErrorInfo, type CommerceErrorOptions, CommerceEvent, CommerceReceipt, CommerceResource, DELIVERY_SUMMARY_META_KEY, DecimalAmount, DeliveredOutcome, type DeliverySummary, type ErrorEnvelope, ExecutionPipeline, type GatewayConfig, type GatewayInstance, type GatewayOptions, IdGenerator, IsoTimestamp, type ListOptions, Logger, PAYMENT_HEADER, PAYMENT_INPUT_FIELD, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAttempt, type PaymentAttemptReservation, type PaymentAttemptUpdate, PaymentMethodName, PaymentProvider, type PaymentRequiredEnvelope, PaymentRequiredOutcome, ProtocolAdapter, RETRYABLE_ERROR_CODES, type ReceiptStore, ResourceRegistry, createGateway, createSqliteReceiptStore, isCommerceError, isPaymentRequiredEnvelope, loadConfig, parseConfig, createSqliteReceiptStore as receipts, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope };
582
+ export { ACP_API_VERSION, ACP_SPEC_VERSION, ACP_WELL_KNOWN_PATH, type AcpAdapterOptions, AdapterDescriptor, AdapterHealth, AdapterHttpRoute, type BackendExecutor, BackendHandler, type BackendRequest, type BackendResponse, COMMERCE_ERROR_CODES, COMMERCE_ERROR_HTTP_STATUS, Clock, CommerceError, type CommerceErrorCode, type CommerceErrorInfo, type CommerceErrorOptions, CommerceEvent, CommerceReceipt, CommerceResource, DELIVERY_SUMMARY_META_KEY, DecimalAmount, DeliveredOutcome, type DeliverySummary, type ErrorEnvelope, ExecutionPipeline, type GatewayConfig, type GatewayInstance, type GatewayOptions, HttpProtocolAdapter, IdGenerator, IsoTimestamp, type ListOptions, Logger, PAYMENT_HEADER, PAYMENT_INPUT_FIELD, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAttempt, type PaymentAttemptReservation, type PaymentAttemptUpdate, PaymentMethodName, PaymentProvider, type PaymentRequiredEnvelope, PaymentRequiredOutcome, ProtocolAdapter, ProtocolAdapterContext, RETRYABLE_ERROR_CODES, type ReceiptStore, ResourceRegistry, createAcpAdapter, createGateway, createSqliteReceiptStore, isCommerceError, isPaymentRequiredEnvelope, loadConfig, parseConfig, createSqliteReceiptStore as receipts, toCommerceError, toDeliverySummary, toErrorEnvelope, toPaymentRequiredEnvelope };