@devlab.group/agent-commerce 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/filename.ts","../../src/core/domain/resource.ts","../../src/core/errors/codes.ts","../../src/core/errors/commerce-error.ts","../../src/core/errors/index.ts","../../src/core/interfaces/logger.ts","../../src/core/execution/backend-http.ts","../../src/core/execution/event-bus.ts","../../src/core/domain/wire.ts","../../src/core/execution/validation.ts","../../src/core/execution/pipeline.ts","../../src/core/execution/registry.ts","../../src/core/execution/index.ts","../../src/core/domain/event.ts","../../src/core/interfaces/protocol-adapter.ts","../../src/core/interfaces/runtime.ts","../../src/core/public-types.ts","../../src/core/index.ts","../../src/payments/x402/networks.ts","../../src/config/env.ts","../../src/payments/x402/local-chain/accounts.ts","../../src/payments/x402/dev-key-guard.ts","../../src/payments/x402/guardrails.ts","../../src/config/schema.ts","../../src/config/load.ts","../../src/config/index.ts","../../src/cli/program.ts","../../src/cli/commands/demo.ts","../../src/cli/commands/doctor.ts","../../src/protocols/a2a/constants.ts","../../src/protocols/a2a/descriptor.ts","../../src/storage/receipts/store.ts","../../src/version.ts","../../src/storage/receipts/redact.ts","../../src/storage/receipts/rows.ts","../../src/storage/receipts/schema.ts","../../src/cli/lib/config-client.ts","../../src/cli/lib/http.ts","../../src/cli/lib/init-config.ts","../../src/payments/x402/local-chain/manifest.ts","../../src/cli/lib/manifest-env.ts","../../src/cli/lib/mask.ts","../../src/cli/lib/versions.ts","../../src/cli/commands/init.ts","../../src/cli/commands/validate.ts","../../src/cli/commands/version.ts","../../src/cli/lib/io.ts","../../src/cli/index.ts"],"names":["path","isPlainObject","text","fs","parseYaml","fsConstants","existsSync","createRequire","sameAddress","loadConfig","resolve","dirname","mkdirSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAYa,uBAAA;AAZb,IAAA,aAAA,GAAA,KAAA,CAAA;A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AQ,QAAA,GAAW,IAAA;AAAA,EACrB,CAAC,CAAA;AAEH,EAAA,OAAA,CACG,OAAA,CAAQ,MAAM,CAAA,CACd,WAAA;AAAA,IACC;AAAA,GACF,CACC,OAAO,YAAY;AAClB,IAAA,OAAA,CAAQ,QAAA,GAAW,MAAM,OAAA,CAAQ,EAAE,CAAA;AAAA,EACrC,CAAC,CAAA;AAEH,EAAA,OAAO,OAAA;AACT;;;AqBhFA,KAAA,MAAW,UAAU,CAAC,OAAA,CAAQ,MAAA,EAAQ,OAAA,CAAQ,MAAM,CAAA,EAAG;AACrD,EAAA,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,CAAC,GAAA,KAA+B;AACjD,IAAA,IAAI,GAAA,CAAI,IAAA,KAAS,OAAA,EAAS,OAAA,CAAQ,KAAK,CAAC,CAAA;AACxC,IAAA,MAAM,GAAA;AAAA,EACR,CAAC,CAAA;AACH;AAEA,eAAe,IAAA,GAAsB;AACnC,EAAA,MAAM,UAAU,YAAA,EAAa;AAC7B,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,CAAQ,UAAA,CAAW,OAAA,CAAQ,IAAI,CAAA;AAAA,EACvC,SAAS,GAAA,EAAK;AACZ,IAAA,IAAI,eAAe,cAAA,EAAgB;AACjC,MAAA,OAAA,CAAQ,WAAW,GAAA,CAAI,QAAA;AACvB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACF;AAEA,KAAK,IAAA,EAAK","file":"index.js","sourcesContent":["/**\n * The default configuration filename, in one place.\n *\n * Deliberately its own module with **no imports**: `src/cli` reaches the rest\n * of `src/config` only through a dynamic import (see\n * `src/cli/lib/config-client.ts`), so that a broken config module cannot take\n * down commands that never read configuration. A leaf file holding a single\n * string has no module graph to break, so the CLI can import it directly\n * without reopening that seam — and `init`'s default output path, `--config`'s\n * help text and the loader's own lookup cannot drift apart, which is what\n * three separate copies of this string invited.\n */\nexport const DEFAULT_CONFIG_FILENAME = 'config.yaml';\n","/**\n * Canonical resource model.\n *\n * FROZEN CONTRACT.\n */\nimport type { DecimalAmount, JsonSchema, PaymentMethodName, ProtocolName } from './common.js';\n\n/** HTTP methods a backend handler may use. */\nexport type BackendMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * Describes how the gateway calls the merchant's existing backend.\n *\n * Backend URLs are administrator-controlled configuration only. User- or\n * agent-controlled backend URLs are forbidden (see docs/security.md, SSRF).\n * Secret header values must come from `${ENV_VAR}` placeholders resolved by\n * the config loader, never from plaintext configuration.\n */\nexport interface BackendHandler {\n readonly type: 'http';\n readonly method: BackendMethod;\n readonly url: string;\n readonly headers?: Readonly<Record<string, string>>;\n /** Hard upper bound on the backend call. Defaults to DEFAULT_BACKEND_TIMEOUT_MS. */\n readonly timeoutMs?: number;\n}\n\n/** Default backend timeout when a resource does not specify one. */\nexport const DEFAULT_BACKEND_TIMEOUT_MS = 10_000;\n\n/**\n * Canonical pricing.\n *\n * `dynamic` exists in the type system for forward compatibility but is\n * REJECTED by config validation in this release.\n */\nexport type Pricing =\n | { readonly type: 'free' }\n | {\n readonly type: 'fixed';\n readonly amount: DecimalAmount;\n readonly currency: string;\n }\n | {\n readonly type: 'dynamic';\n readonly resolver: string;\n };\n\n/**\n * A merchant capability exposed to agents.\n *\n * The canonical resource is the single source of truth: protocol adapters map\n * it outward, they never define their own parallel notion of a resource.\n */\nexport interface CommerceResource {\n readonly id: string;\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: JsonSchema;\n readonly outputSchema?: JsonSchema;\n readonly handler: BackendHandler;\n readonly pricing: Pricing;\n readonly exposedVia: readonly ProtocolName[];\n readonly paymentMethods: readonly PaymentMethodName[];\n}\n\n/** Read-only view of every configured resource. */\nexport interface ResourceRegistry {\n get(id: string): CommerceResource | undefined;\n list(): readonly CommerceResource[];\n /** Resources exposed through a given protocol surface. */\n listExposedVia(protocol: ProtocolName): readonly CommerceResource[];\n has(id: string): boolean;\n}\n","/**\n * Typed domain error codes.\n *\n * FROZEN CONTRACT. Protocol adapters map these codes into their own response\n * format. Never throw a bare string or untyped Error across a package boundary.\n */\nexport const COMMERCE_ERROR_CODES = [\n 'CONFIG_INVALID',\n 'RESOURCE_NOT_FOUND',\n 'INPUT_INVALID',\n 'PAYMENT_REQUIRED',\n 'PAYMENT_INVALID',\n 'PAYMENT_REPLAYED',\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'PAYMENT_SETTLEMENT_FAILED',\n 'BACKEND_TIMEOUT',\n 'BACKEND_ERROR',\n 'PROTOCOL_UNSUPPORTED',\n 'GATEWAY_BUSY',\n 'STORAGE_ERROR',\n 'INTERNAL_ERROR',\n] as const;\n\nexport type CommerceErrorCode = (typeof COMMERCE_ERROR_CODES)[number];\n\n/**\n * Canonical HTTP status for each error code.\n *\n * Paid resources fail closed: every payment failure maps to a 4xx/5xx status\n * and never to a successful delivery.\n */\nexport const COMMERCE_ERROR_HTTP_STATUS: Readonly<Record<CommerceErrorCode, number>> = {\n CONFIG_INVALID: 500,\n RESOURCE_NOT_FOUND: 404,\n INPUT_INVALID: 400,\n PAYMENT_REQUIRED: 402,\n PAYMENT_INVALID: 402,\n PAYMENT_REPLAYED: 409,\n PAYMENT_PROVIDER_UNAVAILABLE: 503,\n PAYMENT_SETTLEMENT_FAILED: 502,\n BACKEND_TIMEOUT: 504,\n BACKEND_ERROR: 502,\n PROTOCOL_UNSUPPORTED: 501,\n GATEWAY_BUSY: 503,\n STORAGE_ERROR: 500,\n INTERNAL_ERROR: 500,\n};\n\n/** Codes for which a client may reasonably retry the same request. */\nexport const RETRYABLE_ERROR_CODES: ReadonlySet<CommerceErrorCode> = new Set([\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'BACKEND_TIMEOUT',\n // Load shedding is transient by definition: the caller should back off and\n // try again. Before this code existed the MCP adapter's queue-full path threw\n // PROTOCOL_UNSUPPORTED — HTTP 501, retryable:false — so an agent framework\n // keyed on the machine-readable flag (which exists precisely so clients need\n // not parse prose) would read a momentary throttle as a permanent capability\n // gap and stop calling the tool.\n 'GATEWAY_BUSY',\n]);\n","/**\n * The single error type crossing package boundaries.\n *\n * FROZEN CONTRACT.\n */\nimport {\n COMMERCE_ERROR_HTTP_STATUS,\n type CommerceErrorCode,\n RETRYABLE_ERROR_CODES,\n} from './codes.js';\n\nexport interface CommerceErrorOptions {\n /** Structured, non-secret detail safe to return to a client. */\n readonly details?: Readonly<Record<string, unknown>>;\n readonly cause?: unknown;\n readonly requestId?: string;\n readonly resourceId?: string;\n /** Override the default HTTP status for this code. */\n readonly httpStatus?: number;\n}\n\n/** Serialisable wire form of a CommerceError. */\nexport interface CommerceErrorInfo {\n readonly code: CommerceErrorCode;\n readonly message: string;\n readonly httpStatus: number;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly resourceId?: string;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\nexport class CommerceError extends Error {\n readonly code: CommerceErrorCode;\n readonly httpStatus: number;\n readonly retryable: boolean;\n readonly details?: Readonly<Record<string, unknown>>;\n readonly requestId?: string;\n readonly resourceId?: string;\n\n constructor(code: CommerceErrorCode, message: string, options: CommerceErrorOptions = {}) {\n super(message, options.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = 'CommerceError';\n this.code = code;\n this.httpStatus = options.httpStatus ?? COMMERCE_ERROR_HTTP_STATUS[code];\n this.retryable = RETRYABLE_ERROR_CODES.has(code);\n if (options.details !== undefined) this.details = options.details;\n if (options.requestId !== undefined) this.requestId = options.requestId;\n if (options.resourceId !== undefined) this.resourceId = options.resourceId;\n Error.captureStackTrace?.(this, CommerceError);\n }\n\n /** Non-secret, client-safe representation. */\n toInfo(): CommerceErrorInfo {\n return {\n code: this.code,\n message: this.message,\n httpStatus: this.httpStatus,\n retryable: this.retryable,\n ...(this.requestId !== undefined ? { requestId: this.requestId } : {}),\n ...(this.resourceId !== undefined ? { resourceId: this.resourceId } : {}),\n ...(this.details !== undefined ? { details: this.details } : {}),\n };\n }\n}\n\nexport function isCommerceError(value: unknown): value is CommerceError {\n return value instanceof CommerceError;\n}\n\n/**\n * Normalise any thrown value into a CommerceError.\n *\n * Used at package boundaries so an unexpected failure never escapes untyped.\n *\n * SECURITY — do not \"improve\" this by propagating `value.message`.\n * `CommerceError.message` is client-visible: it is serialised by `toInfo()`\n * and `toErrorEnvelope()` and returned over HTTP and MCP. An arbitrary thrown\n * Error's message routinely carries internal detail — database connection\n * strings, internal hostnames, filesystem paths, backend URLs. Copying it into\n * a client-facing field turns every unexpected exception into an information\n * disclosure.\n *\n * The original value is preserved on `cause`, which is never serialised, so\n * logs and diagnostics keep the full detail while clients get only the\n * caller's deliberate, reviewed `fallbackMessage`.\n *\n * A caller that *wants* a specific client-facing message passes one:\n * toCommerceError(err, 'BACKEND_ERROR', 'Backend call failed')\n */\nexport function toCommerceError(\n value: unknown,\n fallbackCode: CommerceErrorCode = 'INTERNAL_ERROR',\n fallbackMessage = 'Unexpected internal error',\n): CommerceError {\n if (isCommerceError(value)) return value;\n return new CommerceError(fallbackCode, fallbackMessage, { cause: value });\n}\n","export * from './codes.js';\nexport * from './commerce-error.js';\n","/**\n * Minimal structural logger interface.\n *\n * Core must not depend on pino directly; the gateway injects a pino instance\n * that satisfies this shape. Never log secrets: private keys, seed phrases,\n * Authorization headers or payment authorisation payloads.\n */\nexport interface Logger {\n debug(obj: Record<string, unknown>, msg?: string): void;\n info(obj: Record<string, unknown>, msg?: string): void;\n warn(obj: Record<string, unknown>, msg?: string): void;\n error(obj: Record<string, unknown>, msg?: string): void;\n child(bindings: Record<string, unknown>): Logger;\n}\n\n/** A logger that discards everything. Useful in unit tests. */\nexport const NOOP_LOGGER: Logger = {\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n child: () => NOOP_LOGGER,\n};\n","/**\n * The only outbound HTTP path to a merchant backend.\n *\n * - Uses global `fetch` and always applies a bound timeout via `AbortSignal.timeout`.\n * - `redirect: 'manual'` — a 3xx response is treated as a `BACKEND_ERROR`, never\n * followed (SSRF hardening).\n * - `{param}` segments in `handler.url` are filled from validated input and\n * URL-encoded; whatever remains goes to the query string (GET/DELETE) or a\n * JSON body (POST/PUT/PATCH).\n */\nimport { type BackendHandler, DEFAULT_BACKEND_TIMEOUT_MS } from '../domain/resource.js';\nimport { CommerceError } from '../errors/index.js';\nimport type { BackendExecutor, BackendRequest, BackendResponse } from '../interfaces/backend.js';\nimport { type Logger, NOOP_LOGGER } from '../interfaces/logger.js';\n\nconst MAX_BODY_SNIPPET_LENGTH = 512;\n/**\n * The one canonical `{param}` grammar. Extraction, substitution, the config\n * gate and `doctor`'s probe all go through it.\n *\n * `-` and `.` are admitted: `/report/{report-id}` is ordinary\n * REST, and under the previous `[a-zA-Z0-9_]+` class it matched *nothing*. It\n * was therefore invisible to the config gate, survived substitution as a\n * literal, and a paid resource settled the buyer's payment before sending\n * `/report/%7Breport-id%7D` to a backend that 404s — the earlier money bug,\n * reachable again through the character class rather than through the check.\n */\nconst PATH_PARAM_PATTERN = /\\{([a-zA-Z0-9_.-]+)\\}/g;\n/** A hostile or broken backend can otherwise materialise an arbitrarily\n * large response in memory — AbortSignal.timeout bounds it by *time*, not\n * bytes. 1 MB is generous for a JSON API response. */\nconst MAX_RESPONSE_BODY_BYTES = 1024 * 1024;\n\nexport interface HttpBackendExecutorOptions {\n /** Override for `fetch`, used in tests. Defaults to the global implementation. */\n readonly fetchImpl?: typeof fetch;\n /** A non-2xx backend body is logged here (debug), never shipped to the client. */\n readonly logger?: Logger;\n}\n\nexport class HttpBackendExecutor implements BackendExecutor {\n private readonly fetchImpl: typeof fetch;\n private readonly logger: Logger;\n\n constructor(options: HttpBackendExecutorOptions = {}) {\n this.fetchImpl = options.fetchImpl ?? fetch;\n this.logger = options.logger ?? NOOP_LOGGER;\n }\n\n async call(handler: BackendHandler, request: BackendRequest): Promise<BackendResponse> {\n const timeoutMs = handler.timeoutMs ?? DEFAULT_BACKEND_TIMEOUT_MS;\n const inputRecord = isPlainObject(request.input) ? request.input : {};\n\n let target: URL;\n let remaining: Record<string, unknown>;\n try {\n const templated = applyPathTemplate(handler.url, inputRecord);\n target = new URL(templated.url);\n remaining = templated.remaining;\n } catch (error) {\n if (error instanceof Error && error.message.startsWith('invalid-path-parameter:')) {\n const field = error.message.slice('invalid-path-parameter:'.length);\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${field}\" is not a valid value`, {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { field },\n });\n }\n // Mirrors validateBackendRequestShape()'s own copy\n // — the pipeline calls that one first, so this branch is defence in\n // depth for a caller that bypasses it, not the normal path.\n if (error instanceof Error && error.message.startsWith('missing-path-parameter:')) {\n const field = error.message.slice('missing-path-parameter:'.length);\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${field}\" was not supplied`, {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { field },\n });\n }\n throw new CommerceError('BACKEND_ERROR', 'Backend URL could not be constructed from input', {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { reason: describeConstructionError(error) },\n cause: error,\n });\n }\n\n // Belt-and-braces beyond the per-parameter check above: whatever the\n // templated path resolved to must still live under the template's own\n // literal (pre-`{param}`) prefix. Templating something other than a path\n // segment (e.g. the host) is not a documented usage; if the literal\n // prefix does not even parse as a URL, skip this extra check rather than\n // fail a request the per-parameter check already covers.\n const literalPrefix = handler.url.split('{')[0] ?? handler.url;\n try {\n const literalPrefixPathname = new URL(literalPrefix).pathname;\n if (!target.pathname.startsWith(literalPrefixPathname)) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'Path parameters resolved outside the configured backend path',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n },\n );\n }\n } catch (error) {\n if (error instanceof CommerceError) throw error;\n }\n\n const headers: Record<string, string> = { ...(handler.headers ?? {}) };\n let body: string | undefined;\n\n if (handler.method === 'GET' || handler.method === 'DELETE') {\n //.set() REPLACES an existing param, so without this check a caller\n // input key with the same name as an operator-baked-in query param\n // (?apikey=SECRET in handler.url) silently overwrites it.\n // Shared with validateBackendRequestShape() — that copy runs\n // *before* payment, this one is defence in depth.\n checkQueryCollision(target, remaining, {\n requestId: request.requestId,\n resourceId: request.resourceId,\n });\n for (const [key, value] of Object.entries(remaining)) {\n target.searchParams.set(key, stringifyPrimitive(value));\n }\n } else {\n body = JSON.stringify(remaining);\n if (!hasHeader(headers, 'content-type')) {\n headers['content-type'] = 'application/json';\n }\n }\n\n const started = performance.now();\n let response: Response;\n try {\n response = await this.fetchImpl(target, {\n method: handler.method,\n headers,\n ...(body !== undefined ? { body } : {}),\n redirect: 'manual',\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n const durationMs = Math.round(performance.now() - started);\n if (isAbortError(error)) {\n throw new CommerceError(\n 'BACKEND_TIMEOUT',\n `Backend request timed out after ${timeoutMs}ms`,\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { timeoutMs, durationMs },\n cause: error,\n },\n );\n }\n throw new CommerceError('BACKEND_ERROR', 'Backend request failed (transport error)', {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { durationMs },\n cause: error,\n });\n }\n const durationMs = Math.round(performance.now() - started);\n\n const isRedirect =\n response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400);\n if (isRedirect) {\n throw new CommerceError(\n 'BACKEND_ERROR',\n 'Backend responded with a redirect, which is not followed',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { status: response.status, reason: 'redirect-not-followed' },\n },\n );\n }\n\n const responseHeaders = headersToRecord(response.headers);\n const contentType = response.headers.get('content-type') ?? '';\n let parsedBody: unknown;\n try {\n parsedBody = await parseBody(response, contentType);\n } catch (error) {\n const tooLarge =\n error instanceof Error && error.message.startsWith('response-body-too-large');\n throw new CommerceError(\n 'BACKEND_ERROR',\n tooLarge\n ? 'Backend response exceeded the maximum allowed size'\n : 'Backend response could not be read',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: tooLarge\n ? { reason: 'response-too-large', maxBytes: MAX_RESPONSE_BODY_BYTES }\n : { reason: 'read-error' },\n cause: error,\n },\n );\n }\n\n if (response.status < 200 || response.status >= 300) {\n // The backend status is ours to state; the backend's own response body\n // is not — a merchant backend in verbose/dev-error mode routinely\n // emits stack traces, hostnames or SQL fragments, and this gateway is\n // not the one who gets to decide those are safe to forward to whoever\n // called the (possibly free, possibly unauthenticated) resource. Log\n // it for the operator; never put it in a client-visible field.\n this.logger.debug(\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n status: response.status,\n bodySnippet: truncateSnippet(parsedBody),\n },\n 'Backend responded with a non-2xx status',\n );\n throw new CommerceError('BACKEND_ERROR', `Backend responded with status ${response.status}`, {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { status: response.status },\n });\n }\n\n return {\n status: response.status,\n headers: responseHeaders,\n body: parsedBody,\n durationMs,\n };\n }\n}\n\n/**\n * The traversal and query-collision checks below must run before payment,\n * not only inside `call()` — pipeline step 6, which is *after*\n * verify -> reserve -> settle.\n * Both throw INPUT_INVALID, which schema validation (step 2) cannot catch\n * (it validates against `resource.inputSchema`, which knows nothing about\n * the URL template a bad value would collide with). Concretely: a paid,\n * path-templated resource called with `{ city: \"\" }` would settle the buyer's\n * payment on-chain and then never call the backend — payment without\n * delivery, no refund, no release of the reserved authorisation. Both\n * checks are pure functions of `(handler.url, input)` with no I/O, so the\n * pipeline calls this immediately after schema validation, *before* price\n * resolution — before any payment provider is even selected. `call()` keeps\n * its own copy as defence in depth (it is a public class; the pipeline is\n * not the only possible caller).\n */\n/**\n * `{param}` names in a `backend.url` template, in declaration order.\n * Exported so `src/config`'s `normaliseResource` can\n * cross-check every template parameter against the resource's input schema\n * at config load — the same regex, not a second copy that could silently\n * drift out of sync with what this file actually treats as a path\n * parameter.\n */\nexport function extractPathParameterNames(url: string): string[] {\n return [...url.matchAll(PATH_PARAM_PATTERN)].map((match) => match[1] as string);\n}\n\n/**\n * A brace left over after every legal `{param}` is removed, or `undefined`.\n *\n * Widening the grammar fixes the *common* spelling; it cannot fix every one.\n * `{report id}`, `{a/b}`, `{}` and an unbalanced `{` still match nothing, and\n * \"matches nothing\" is precisely the silent-literal shape that costs a buyer\n * money on a paid resource. So the rule is inverted: rather than enumerating\n * what is illegal, anything brace-shaped that is *not* a recognised parameter\n * is refused at config load. Exported so `src/config` applies it — the\n * grammar and its residue must never live in two files.\n */\nexport function findUnparsedBraceToken(url: string): string | undefined {\n const residue = url.replace(PATH_PARAM_PATTERN, '');\n const index = residue.search(/[{}]/);\n if (index === -1) return undefined;\n // Report the offending run, not just the character, so the error is fixable.\n const token = /\\{[^{}]*\\}?|\\}/.exec(residue.slice(index));\n return token?.[0] ?? residue[index];\n}\n\nexport function validateBackendRequestShape(\n handler: BackendHandler,\n input: unknown,\n context: { readonly requestId: string; readonly resourceId: string },\n): void {\n const inputRecord = isPlainObject(input) ? input : {};\n\n let templated: { url: string; remaining: Record<string, unknown> };\n try {\n templated = applyPathTemplate(handler.url, inputRecord);\n } catch (error) {\n if (error instanceof Error && error.message.startsWith('invalid-path-parameter:')) {\n const field = error.message.slice('invalid-path-parameter:'.length);\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${field}\" is not a valid value`, {\n requestId: context.requestId,\n resourceId: context.resourceId,\n details: { field },\n });\n }\n if (error instanceof Error && error.message.startsWith('missing-path-parameter:')) {\n // Returning here is tempting: a missing path parameter is a\n // config/schema mismatch, not caller input, and so arguably not this\n // function's job. But that lets a paid, `{param}`-templated resource\n // whose schema can never supply it reach settle() on every call — the buyer pays, the backend is never\n // called, and there is no refund. The request genuinely cannot be\n // served, so it throws here, before payment, the same as an invalid\n // value does two lines up. `normaliseResource` (src/config) is\n // the root-cause fix — it rejects this shape at config load — but a\n // hand-built `CommerceResource` or a future adapter must not be able\n // to reintroduce the money bug just by skipping config validation.\n const field = error.message.slice('missing-path-parameter:'.length);\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${field}\" was not supplied`, {\n requestId: context.requestId,\n resourceId: context.resourceId,\n details: { field },\n });\n }\n return;\n }\n\n if (handler.method === 'GET' || handler.method === 'DELETE') {\n let target: URL;\n try {\n target = new URL(templated.url);\n } catch {\n return; // call() surfaces the real BACKEND_ERROR for an unparseable URL.\n }\n checkQueryCollision(target, templated.remaining, context);\n }\n}\n\nfunction checkQueryCollision(\n target: URL,\n remaining: Record<string, unknown>,\n context: { readonly requestId: string; readonly resourceId: string },\n): void {\n const templateKeys = new Set(target.searchParams.keys());\n for (const key of Object.keys(remaining)) {\n if (templateKeys.has(key)) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `Input key \"${key}\" collides with a query parameter already set on backend.url`,\n { requestId: context.requestId, resourceId: context.resourceId, details: { field: key } },\n );\n }\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n// encodeURIComponent does not escape \".\" — a raw \"..\"/\".\" path-parameter\n// value survives it and new URL() then normalises the segment away, letting\n// a caller step outside the template's own directory (bounded traversal:\n// slashes ARE escaped, so only removing segments, never adding them). Reject\n// these exact values at substitution time instead of shipping them.\nconst TRAVERSAL_PATH_VALUES = new Set(['', '.', '..']);\n\nfunction applyPathTemplate(\n template: string,\n input: Record<string, unknown>,\n): { url: string; remaining: Record<string, unknown> } {\n const remaining: Record<string, unknown> = { ...input };\n let missing: string | undefined;\n let invalid: string | undefined;\n const url = template.replace(PATH_PARAM_PATTERN, (_match, key: string) => {\n // Object.hasOwn, not `key in remaining`: `in` also matches inherited\n // Object.prototype names (\"constructor\", \"toString\", …), which a\n // config-authored template naming a path param after one of them would\n // otherwise silently resolve to the wrong (inherited) value.\n if (!Object.hasOwn(remaining, key)) {\n missing = key;\n return '';\n }\n const value = remaining[key];\n delete remaining[key];\n const raw = stringifyPrimitive(value);\n if (TRAVERSAL_PATH_VALUES.has(raw)) {\n invalid = key;\n return '';\n }\n return encodeURIComponent(raw);\n });\n if (missing !== undefined) {\n throw new Error(`missing-path-parameter:${missing}`);\n }\n if (invalid !== undefined) {\n throw new Error(`invalid-path-parameter:${invalid}`);\n }\n return { url, remaining };\n}\n\nfunction describeConstructionError(error: unknown): string {\n if (error instanceof Error && error.message.startsWith('missing-path-parameter:')) {\n return error.message;\n }\n return 'invalid-url';\n}\n\nfunction stringifyPrimitive(value: unknown): string {\n if (value === undefined || value === null) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction hasHeader(headers: Record<string, string>, name: string): boolean {\n const target = name.toLowerCase();\n return Object.keys(headers).some((key) => key.toLowerCase() === target);\n}\n\nfunction headersToRecord(headers: Headers): Record<string, string> {\n const record: Record<string, string> = {};\n headers.forEach((value, key) => {\n record[key] = value;\n });\n return record;\n}\n\nasync function readBodyCapped(response: Response, maxBytes: number): Promise<string> {\n if (!response.body) return '';\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > maxBytes) {\n await reader.cancel();\n throw new Error(`response-body-too-large:${maxBytes}`);\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n return Buffer.concat(chunks).toString('utf8');\n}\n\nasync function parseBody(response: Response, contentType: string): Promise<unknown> {\n const text = await readBodyCapped(response, MAX_RESPONSE_BODY_BYTES);\n if (text.length === 0) return text;\n if (contentType.includes('json')) {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n }\n return text;\n}\n\nfunction truncateSnippet(body: unknown): string {\n const text = typeof body === 'string' ? body : safeStringify(body);\n return text.length > MAX_BODY_SNIPPET_LENGTH\n ? `${text.slice(0, MAX_BODY_SNIPPET_LENGTH)}…`\n : text;\n}\n\nfunction safeStringify(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError');\n}\n","/**\n * Fan-out `EventSink`: persists every event to the receipt store and notifies\n * in-process subscribers (the gateway's SSE feed). Never throws to the caller —\n * a store or subscriber failure is caught and logged.\n */\nimport type { CommerceEvent, EventSink } from '../domain/event.js';\nimport type { Logger } from '../interfaces/logger.js';\nimport type { Clock, IdGenerator } from '../interfaces/runtime.js';\nimport type { ReceiptStore } from '../interfaces/store.js';\n\nexport interface CreateEventBusOptions {\n readonly store: ReceiptStore;\n readonly logger: Logger;\n /** Reserved for callers that want the bus to mint ids/timestamps itself. */\n readonly ids?: IdGenerator;\n readonly clock?: Clock;\n}\n\nexport interface EventBus extends EventSink {\n /** Subscribe to every emitted event. Returns an unsubscribe function. */\n subscribe(fn: (event: CommerceEvent) => void): () => void;\n}\n\nexport function createEventBus(options: CreateEventBusOptions): EventBus {\n const subscribers = new Set<(event: CommerceEvent) => void>();\n\n return {\n async emit(event: CommerceEvent): Promise<void> {\n try {\n await options.store.appendEvent(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Failed to persist commerce event',\n );\n }\n\n for (const subscriber of subscribers) {\n try {\n subscriber(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Event subscriber threw',\n );\n }\n }\n },\n\n subscribe(fn: (event: CommerceEvent) => void): () => void {\n subscribers.add(fn);\n return () => {\n subscribers.delete(fn);\n };\n },\n };\n}\n\nfunction describeError(error: unknown): { message: string; name?: string } {\n if (error instanceof Error) {\n return { message: error.message, name: error.name };\n }\n return { message: String(error) };\n}\n","/**\n * Gateway-defined wire envelopes.\n *\n * FROZEN CONTRACT. These are the *only* representations of \"payment required\"\n * and \"error\" that leave the gateway, whichever protocol carries them. The HTTP\n * routes, the MCP adapter and the demo buyer agent all use these helpers so the\n * three can never drift apart.\n */\n\nimport type { CommerceError, CommerceErrorCode } from '../errors/index.js';\nimport type { DecimalAmount, IsoTimestamp, PaymentMethodName } from './common.js';\nimport type { DeliveredOutcome, PaymentRequiredOutcome } from './request.js';\n\n/**\n * Reserved input property carrying a payment proof on protocols that have no\n * header channel (MCP tool calls). Over HTTP the `PAYMENT-SIGNATURE` header is\n * used.\n */\nexport const PAYMENT_INPUT_FIELD = '_payment';\n\n/**\n * HTTP request header carrying the payment proof.\n *\n * x402 v2 header names, lowercased because that is how Node presents incoming\n * headers. v1's `X-PAYMENT` / `X-PAYMENT-RESPONSE` pair is not accepted: this\n * gateway speaks one protocol version, and quietly honouring both would mean\n * two verification paths for the same money.\n */\nexport const PAYMENT_HEADER = 'payment-signature';\n\n/** HTTP response header carrying the settlement result. */\nexport const PAYMENT_RESPONSE_HEADER = 'payment-response';\n\n/**\n * HTTP response header carrying the base64 payment challenge on a 402.\n *\n * The 402 body still carries {@link PaymentRequiredEnvelope} — richer, and the\n * only channel MCP has — but an x402 v2 client reads the challenge from this\n * header and ignores the body, so both are sent.\n */\nexport const PAYMENT_REQUIRED_HEADER = 'payment-required';\n\n/**\n * Key under which a protocol adapter attaches a {@link DeliverySummary} to its\n * result metadata — MCP's `CallToolResult._meta`, and anywhere else a protocol\n * offers an out-of-band metadata channel.\n *\n * Frozen deliberately. The bug this whole mechanism exists to fix was two\n * surfaces disagreeing about what a payer gets back; a key name enforced only\n * by one side's tests would reintroduce exactly that drift. Producer and\n * consumer both import this constant.\n *\n * Follows MCP's `<namespace>/<name>` convention for `_meta` keys.\n */\nexport const DELIVERY_SUMMARY_META_KEY = 'agent-commerce/delivery';\n\nexport interface PaymentRequiredEnvelope {\n readonly status: 'payment-required';\n readonly code: 'PAYMENT_REQUIRED';\n readonly requestId: string;\n readonly resourceId: string;\n readonly message: string;\n readonly payment: {\n readonly provider: PaymentMethodName;\n readonly version: string;\n readonly amount: DecimalAmount;\n readonly currency: string;\n readonly destination: string;\n readonly network?: string;\n readonly asset?: string;\n readonly expiresAt?: IsoTimestamp;\n /** Provider-native requirement objects, passed through verbatim. */\n readonly accepts: readonly Readonly<Record<string, unknown>>[];\n /**\n * The provider's own challenge document, verbatim — see\n * {@link PaymentChallenge.envelope}. Present for providers that have one;\n * a buyer's protocol client can hand this straight to its SDK.\n */\n readonly envelope?: Readonly<Record<string, unknown>>;\n };\n}\n\nexport interface ErrorEnvelope {\n readonly status: 'error';\n readonly code: CommerceErrorCode;\n readonly message: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly resourceId?: string;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * What a buyer learns about their own completed purchase.\n *\n * A payer is entitled to the record of their own transaction — the request it\n * belonged to, whether it settled, and the settlement reference they can check\n * on-chain. They are NOT entitled to the merchant's ledger, which is why\n * `/api/receipts` is an operator route behind `server.adminToken`.\n *\n * Before this existed the two surfaces disagreed: HTTP callers received a\n * settlement summary in the payment-response header while MCP callers received\n * nothing, so an MCP buyer's only route to their own receipt was the merchant's\n * ledger. Both surfaces now emit this same shape.\n */\nexport interface DeliverySummary {\n readonly requestId: string;\n readonly resourceId: string;\n readonly receiptId: string;\n readonly deliveredAt: IsoTimestamp;\n readonly payment?: {\n readonly status: 'verified' | 'settled' | 'rejected';\n readonly amount: DecimalAmount;\n readonly currency: string;\n /** Settlement reference, e.g. an on-chain transaction hash. */\n readonly externalReference?: string;\n readonly network?: string;\n };\n}\n\n/** Build the payer-facing summary of a delivered outcome. */\nexport function toDeliverySummary(outcome: DeliveredOutcome): DeliverySummary {\n const p = outcome.payment;\n return {\n requestId: outcome.requestId,\n resourceId: outcome.resourceId,\n receiptId: outcome.receipt.id,\n deliveredAt: outcome.receipt.deliveredAt,\n ...(p !== undefined\n ? {\n payment: {\n status: p.status,\n amount: p.amount,\n currency: p.currency,\n ...(p.externalReference !== undefined\n ? { externalReference: p.externalReference }\n : {}),\n ...(p.network !== undefined ? { network: p.network } : {}),\n },\n }\n : {}),\n };\n}\n\nexport function toPaymentRequiredEnvelope(\n outcome: PaymentRequiredOutcome,\n): PaymentRequiredEnvelope {\n const r = outcome.requirement;\n return {\n status: 'payment-required',\n code: 'PAYMENT_REQUIRED',\n requestId: outcome.requestId,\n resourceId: outcome.resourceId,\n message: `Payment of ${r.amount} ${r.currency} is required for resource \"${outcome.resourceId}\". Retry with a ${r.provider} payment proof.`,\n payment: {\n provider: r.provider,\n version: r.challenge.version,\n amount: r.amount,\n currency: r.currency,\n destination: r.destination,\n ...(r.network !== undefined ? { network: r.network } : {}),\n ...(r.asset !== undefined ? { asset: r.asset } : {}),\n ...(r.expiresAt !== undefined ? { expiresAt: r.expiresAt } : {}),\n accepts: r.challenge.accepts,\n ...(r.challenge.envelope !== undefined ? { envelope: r.challenge.envelope } : {}),\n },\n };\n}\n\nexport function toErrorEnvelope(error: CommerceError): ErrorEnvelope {\n const info = error.toInfo();\n return {\n status: 'error',\n code: info.code,\n message: info.message,\n retryable: info.retryable,\n ...(info.requestId !== undefined ? { requestId: info.requestId } : {}),\n ...(info.resourceId !== undefined ? { resourceId: info.resourceId } : {}),\n ...(info.details !== undefined ? { details: info.details } : {}),\n };\n}\n\nexport function isPaymentRequiredEnvelope(value: unknown): value is PaymentRequiredEnvelope {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as PaymentRequiredEnvelope).status === 'payment-required' &&\n typeof (value as PaymentRequiredEnvelope).payment === 'object'\n );\n}\n","/**\n * A small, honest JSON Schema validator for resource input.\n *\n * Supported subset (draft-2020-12 vocabulary, structural only):\n * - `type`: \"object\" | \"string\" | \"number\" | \"integer\" | \"boolean\" | \"array\" | \"null\",\n * or an array of any of those (draft-2020-12 union form, e.g. `[\"object\",\"null\"]`)\n * - `properties` (object schemas, validated recursively)\n * - `required` (string[])\n * - `additionalProperties` (boolean, or a schema applied to extra properties)\n * - `enum` (array of allowed literal values, deep-equality compared)\n * - `items` (single schema applied to every array element — no tuple form)\n *\n * Explicitly NOT supported and silently ignored (never enforced):\n * `minLength`, `maxLength`, `pattern`, `format`, `minimum`, `maximum`,\n * `exclusiveMinimum/Maximum`, `multipleOf`, `oneOf`, `anyOf`, `allOf`, `not`,\n * `$ref`, `const`, `patternProperties`, `minItems`, `maxItems`, `uniqueItems`,\n * tuple-style `items` arrays. An unrecognised `type` value is not enforced\n * either. This is a deliberate, documented limitation of this release — do\n * not assume any of the above is validated.\n */\nimport type { JsonSchema } from '../domain/common.js';\n\nexport interface FieldError {\n readonly path: string;\n readonly message: string;\n}\n\nexport type ValidationResult =\n | { readonly valid: true; readonly value: unknown }\n | { readonly valid: false; readonly errors: readonly FieldError[] };\n\nexport type Validator = (input: unknown) => ValidationResult;\n\nconst SUPPORTED_TYPES = new Set([\n 'object',\n 'string',\n 'number',\n 'integer',\n 'boolean',\n 'array',\n 'null',\n]);\n\n/** Compile a resource `inputSchema` into a reusable validator function. */\nexport function compileJsonSchema(schema: JsonSchema | undefined): Validator {\n return (input: unknown): ValidationResult => {\n if (schema === undefined) return { valid: true, value: input };\n const errors = validateNode(schema, input, '$');\n return errors.length === 0 ? { valid: true, value: input } : { valid: false, errors };\n };\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction matchesType(type: string, value: unknown): boolean {\n switch (type) {\n case 'object':\n return isPlainObject(value);\n case 'array':\n return Array.isArray(value);\n case 'string':\n return typeof value === 'string';\n case 'boolean':\n return typeof value === 'boolean';\n case 'number':\n return typeof value === 'number' && Number.isFinite(value);\n case 'integer':\n return typeof value === 'number' && Number.isInteger(value);\n case 'null':\n return value === null;\n default:\n return true;\n }\n}\n\nfunction describeType(value: unknown): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n return typeof value;\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (typeof a !== 'object') return false;\n try {\n return JSON.stringify(a) === JSON.stringify(b);\n } catch {\n return false;\n }\n}\n\nfunction own(obj: Record<string, unknown>, key: string): unknown {\n return Object.hasOwn(obj, key) ? obj[key] : undefined;\n}\n\n/**\n * `type` may be a single string or (draft-2020-12) an array of strings,\n * e.g. `[\"object\", \"null\"]`. Only recognised when every entry is a string —\n * same conservative \"skip rather than guess\" rule the single-string form\n * already followed for an unrecognised type name.\n */\nfunction typeList(raw: unknown): string[] | undefined {\n if (typeof raw === 'string') return [raw];\n if (Array.isArray(raw) && raw.every((entry): entry is string => typeof entry === 'string')) {\n return raw;\n }\n return undefined;\n}\n\n/**\n * A bare `type === 'object'` string comparison is not enough: `type:\n * [\"object\", \"null\"]` — valid JSON Schema — would never route into\n * `validateObject`, so neither `required` nor `additionalProperties` would be\n * enforced on it, while `defaultClosedObjectSchema` (src/config) stamps\n * `additionalProperties: false` on it believing it closed. Also treats a node\n * with `properties`/`required` and no `type`\n * at all as an object schema, the same shape config's own stamping already\n * recognises via a bare `properties` check — a schema author relying on\n * `type` being implied by `properties` should not be silently unenforced.\n *\n * **exported**, and now the only definition of \"this node is\n * an object schema\" in the codebase. `src/config`'s `defaultClosedObjectSchema`\n * carried its own — `declaresObjectType || properties` — one keyword short of\n * this one, so a schema declaring only `required` was stamped by neither:\n * config left it open and this validator then enforced nothing on it, quietly\n * forwarding every unknown caller key to the merchant's backend while\n * docs/security.md promised \"closed by default at every level\". These two\n * definitions have been aligned once already; keeping them as two definitions\n * is what let them drift again.\n */\nexport function isObjectSchemaNode(schema: Record<string, unknown>): boolean {\n const types = typeList(schema['type']);\n if (types !== undefined) return types.includes('object');\n return Object.hasOwn(schema, 'properties') || Object.hasOwn(schema, 'required');\n}\n\nfunction validateNode(schema: JsonSchema, value: unknown, path: string): FieldError[] {\n const errors: FieldError[] = [];\n const types = typeList(own(schema, 'type'));\n const recognisedTypes = types?.filter((entry) => SUPPORTED_TYPES.has(entry));\n\n if (\n types !== undefined &&\n recognisedTypes !== undefined &&\n recognisedTypes.length === types.length &&\n types.length > 0\n ) {\n if (!types.some((entry) => matchesType(entry, value))) {\n errors.push({\n path,\n message: `expected type \"${types.join(' | ')}\" but got ${describeType(value)}`,\n });\n return errors;\n }\n }\n\n const enumRaw = own(schema, 'enum');\n if (Array.isArray(enumRaw)) {\n const allowed = enumRaw as unknown[];\n if (!allowed.some((candidate) => deepEqual(candidate, value))) {\n errors.push({ path, message: `must be one of ${JSON.stringify(allowed)}` });\n }\n }\n\n if (isObjectSchemaNode(schema) && isPlainObject(value)) {\n errors.push(...validateObject(schema, value, path));\n } else if ((types?.includes('array') ?? false) && Array.isArray(value)) {\n errors.push(...validateArray(schema, value, path));\n }\n\n return errors;\n}\n\nfunction validateObject(\n schema: JsonSchema,\n value: Record<string, unknown>,\n path: string,\n): FieldError[] {\n const errors: FieldError[] = [];\n const propsRaw = own(schema, 'properties');\n const properties = isPlainObject(propsRaw) ? propsRaw : {};\n const requiredRaw = own(schema, 'required');\n const required = Array.isArray(requiredRaw)\n ? requiredRaw.filter((entry): entry is string => typeof entry === 'string')\n : [];\n\n for (const key of required) {\n // Object.hasOwn, not `in`: `in` walks the prototype chain, so a schema\n // requiring \"toString\"/\"constructor\"/\"valueOf\"/\"hasOwnProperty\"/\n // \"__proto__\" could never actually enforce it — those names are always\n // present via inheritance, so `!(key in value)` is always false. This is\n // the same bug class every other lookup in this file already\n // guards against by using own().\n if (!Object.hasOwn(value, key)) {\n errors.push({ path: `${path}.${key}`, message: 'is required' });\n }\n }\n\n const additional = own(schema, 'additionalProperties');\n\n for (const key of Object.keys(value)) {\n // Object.hasOwn, not `properties[key]`: a plain-object lookup for\n // \"__proto__\"/\"constructor\"/\"toString\"/\"valueOf\"/\"hasOwnProperty\" resolves\n // to an inherited Object.prototype member instead of undefined, so those\n // keys would otherwise silently skip the additionalProperties check below.\n const propSchemaRaw = own(properties, key);\n if (propSchemaRaw !== undefined) {\n if (isPlainObject(propSchemaRaw)) {\n errors.push(...validateNode(propSchemaRaw, value[key], `${path}.${key}`));\n }\n continue;\n }\n if (additional === false) {\n errors.push({ path: `${path}.${key}`, message: 'additional property not allowed' });\n } else if (isPlainObject(additional)) {\n errors.push(...validateNode(additional, value[key], `${path}.${key}`));\n }\n }\n\n return errors;\n}\n\nfunction validateArray(schema: JsonSchema, value: unknown[], path: string): FieldError[] {\n const errors: FieldError[] = [];\n const itemsRaw = own(schema, 'items');\n if (isPlainObject(itemsRaw)) {\n value.forEach((item, index) => {\n errors.push(...validateNode(itemsRaw, item, `${path}[${index}]`));\n });\n }\n return errors;\n}\n","/**\n * The single execution path every protocol adapter converges on.\n *\n * Order is a security boundary — do not reorder:\n * 1. resolve resource RESOURCE_NOT_FOUND\n * 2. strip `_payment`, validate input INPUT_INVALID\n * 3. resolve price\n * 4. free -> straight to backend\n * 5. paid -> pick provider -> createRequirement -> (challenge | verify ->\n * reserve replay key -> settle), fail closed at every step\n * 6. call backend BACKEND_TIMEOUT / BACKEND_ERROR\n * 7. persist receipt, emit events, return outcome\n */\n\nimport type { PaymentMethodName } from '../domain/common.js';\nimport type { CommerceEvent, EventSink } from '../domain/event.js';\nimport type { PaymentProvider, PaymentRequirement, PaymentResult } from '../domain/payment.js';\nimport type { CommerceReceipt } from '../domain/receipt.js';\nimport type { CanonicalRequest, ExecutionOutcome, ExecutionPipeline } from '../domain/request.js';\nimport type { CommerceResource, ResourceRegistry } from '../domain/resource.js';\nimport { PAYMENT_INPUT_FIELD } from '../domain/wire.js';\nimport { CommerceError, isCommerceError, toCommerceError } from '../errors/index.js';\nimport type { BackendExecutor, BackendResponse } from '../interfaces/backend.js';\nimport type { Logger } from '../interfaces/logger.js';\nimport type { Clock, IdGenerator } from '../interfaces/runtime.js';\nimport type { ReceiptStore } from '../interfaces/store.js';\nimport { validateBackendRequestShape } from './backend-http.js';\nimport { compileJsonSchema, type Validator } from './validation.js';\n\nexport interface CreateExecutionPipelineOptions {\n readonly resources: ResourceRegistry;\n readonly paymentProviders: readonly PaymentProvider[];\n readonly store: ReceiptStore;\n readonly backend: BackendExecutor;\n readonly events: EventSink;\n readonly logger: Logger;\n readonly clock: Clock;\n readonly ids: IdGenerator;\n}\n\nexport function createExecutionPipeline(\n options: CreateExecutionPipelineOptions,\n): ExecutionPipeline {\n const validators = new Map<string, Validator>();\n\n function getValidator(resource: CommerceResource): Validator {\n const cached = validators.get(resource.id);\n if (cached) return cached;\n const compiled = compileJsonSchema(resource.inputSchema);\n validators.set(resource.id, compiled);\n return compiled;\n }\n\n async function safeEmit(event: CommerceEvent): Promise<void> {\n try {\n await options.events.emit(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Event sink failed; commerce flow continues',\n );\n }\n }\n\n async function safePersist(\n op: () => Promise<void>,\n label: string,\n requestId: string,\n ): Promise<void> {\n try {\n await op();\n } catch (error) {\n options.logger.error(\n { err: describeError(error), requestId },\n `Persistence failed: ${label}`,\n );\n }\n }\n\n function buildEvent(partial: Omit<CommerceEvent, 'id' | 'at'>): CommerceEvent {\n return { id: options.ids.next('evt'), at: options.clock.nowIso(), ...partial };\n }\n\n async function execute(request: CanonicalRequest): Promise<ExecutionOutcome> {\n const pipelineStart = options.clock.monotonicMs();\n\n // 1. resolve resource\n const resource = options.resources.get(request.resourceId);\n // Same code, same message as a genuine miss: `expose` is an admin scoping\n // decision enforced on the one execution path every adapter shares — a\n // caller on a protocol the resource isn't exposed via must not be able to\n // distinguish \"doesn't exist\" from \"exists but not for you\".\n if (!resource || !resource.exposedVia.includes(request.protocol)) {\n throw new CommerceError(\n 'RESOURCE_NOT_FOUND',\n `Resource \"${request.resourceId}\" was not found`,\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n },\n );\n }\n\n await safeEmit(\n buildEvent({\n type: 'resource.requested',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n }),\n );\n\n // 2. strip reserved payment field, then validate input\n const strippedInput = stripPaymentField(request.input);\n const validation = getValidator(resource)(strippedInput);\n if (!validation.valid) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `Input for resource \"${resource.id}\" failed validation`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n details: { errors: validation.errors },\n },\n );\n }\n const validInput = validation.value;\n\n // validate the backend request shape (path-traversal, query-param\n // collision) here — before price resolution, so a resource that fails\n // this check never reaches payment. Both checks are pure functions of\n // (handler.url, input); doing them at pipeline step 6 (inside the actual\n // backend call) meant a bad value like `{ city: \"\" }` against a paid,\n // path-templated resource settled the buyer's payment and then never\n // called the backend at all — payment without delivery. call() keeps its\n // own copy of these checks as defence in depth.\n validateBackendRequestShape(resource.handler, validInput, {\n requestId: request.requestId,\n resourceId: resource.id,\n });\n\n // 3. resolve price\n if (resource.pricing.type === 'dynamic') {\n // Config validation rejects this before the gateway starts; this is defence-in-depth.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${resource.id}\" uses unsupported dynamic pricing`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n let paymentResult: PaymentResult | undefined;\n\n if (resource.pricing.type === 'fixed') {\n const pricing = resource.pricing;\n const provider = pickProvider(options.paymentProviders, resource.paymentMethods);\n if (!provider) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n `No enabled payment provider for resource \"${resource.id}\"`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n details: { paymentMethods: resource.paymentMethods },\n },\n );\n }\n\n let requirement: PaymentRequirement;\n try {\n requirement = await provider.createRequirement({\n requestId: request.requestId,\n resource,\n amount: pricing.amount,\n currency: pricing.currency,\n requestedAt: options.clock.nowIso(),\n });\n } catch (error) {\n throw isCommerceError(error)\n ? error\n : new CommerceError('PAYMENT_PROVIDER_UNAVAILABLE', 'Payment provider is unavailable', {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n });\n }\n\n if (!request.payment) {\n await safeEmit(\n buildEvent({\n type: 'payment.required',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n }),\n );\n return {\n kind: 'payment-required',\n requestId: request.requestId,\n resourceId: resource.id,\n requirement,\n };\n }\n\n const payment = request.payment;\n\n let verification: PaymentResult;\n try {\n verification = await provider.verify({\n requestId: request.requestId,\n resource,\n requirement,\n submission: payment,\n });\n } catch (error) {\n // Any typed CommerceError the provider throws is rethrown as-is (a\n // provider can legitimately fail with STORAGE_ERROR, etc. — flattening\n // every code to PAYMENT_INVALID would hide the real cause and the\n // real, possibly-retryable HTTP status). Only a genuinely untyped\n // throw is mapped, with a fixed client-facing message — never the\n // raw error's own message.\n const mapped = isCommerceError(error)\n ? error\n : new CommerceError('PAYMENT_INVALID', 'Payment verification failed', {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n });\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: mapped.code },\n }),\n );\n throw mapped;\n }\n\n if (verification.status !== 'verified') {\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: verification.rejectionReason ? { reason: verification.rejectionReason } : {},\n }),\n );\n throw new CommerceError(\n 'PAYMENT_INVALID',\n verification.rejectionReason ?? 'Payment was rejected',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n if (!verification.replayKey) {\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: 'missing-replay-key' },\n }),\n );\n throw new CommerceError('PAYMENT_INVALID', 'Payment provider did not return a replay key', {\n requestId: request.requestId,\n resourceId: resource.id,\n });\n }\n const replayKey = verification.replayKey;\n\n try {\n await options.store.reservePaymentAttempt({\n requestId: request.requestId,\n resourceId: resource.id,\n provider: provider.name,\n replayKey,\n amount: verification.amount,\n currency: verification.currency,\n ...(verification.payer !== undefined ? { payer: verification.payer } : {}),\n ...(verification.payee !== undefined ? { payee: verification.payee } : {}),\n });\n } catch (error) {\n // The store contract only promises PAYMENT_REPLAYED for an actual\n // duplicate replayKey (already a CommerceError with that code, so\n // isCommerceError below preserves it as-is). Anything else — a disk-\n // full error, a dropped connection — is a storage failure, not a\n // replay, and must not be mislabelled as one: telling a buyer\n // \"duplicate payment\" for a transient outage is actively false, and\n // poisons any alerting keyed on replay counts.\n const mapped = toCommerceError(\n error,\n 'STORAGE_ERROR',\n 'Payment attempt could not be recorded',\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: mapped.code },\n }),\n );\n throw mapped;\n }\n\n await safeEmit(\n buildEvent({\n type: 'payment.verified',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'ok',\n }),\n );\n\n let settlement: PaymentResult;\n try {\n settlement = await provider.settle({\n requestId: request.requestId,\n resource,\n requirement,\n submission: payment,\n verification,\n });\n } catch (error) {\n // / \"the RPC did not answer\" and \"the transfer did not\n // happen\" are different facts. A provider that broadcast a settlement\n // transaction and then failed to confirm it throws\n // PAYMENT_PROVIDER_UNAVAILABLE with details.transactionHash attached\n // (the hash is known before confirmation). Recording that as plain\n // `failed` would tell the merchant's reconciliation artefact a\n // falsehood — the buyer's funds may already have moved. The resource\n // is still not delivered either way: only what gets *recorded*\n // changes, never the fail-closed outcome.\n const uncertainTxHash = uncertainSettlementTxHash(error);\n await safePersist(\n () =>\n options.store.updatePaymentAttempt(\n uncertainTxHash !== undefined\n ? { replayKey, status: 'settlement-uncertain', externalReference: uncertainTxHash }\n : {\n replayKey,\n status: 'failed',\n ...(error instanceof Error ? { rejectionReason: error.message } : {}),\n },\n ),\n uncertainTxHash !== undefined\n ? 'updatePaymentAttempt(settlement-uncertain)'\n : 'updatePaymentAttempt(failed)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data:\n uncertainTxHash !== undefined\n ? { reason: 'settlement-uncertain', transactionHash: uncertainTxHash }\n : { reason: 'settlement-threw' },\n }),\n );\n // The merchant's record now tells the truth (above); the buyer must\n // too — they are the party whose funds may have moved, and the\n // client-visible error is their only way to find out. Code stays\n // PAYMENT_SETTLEMENT_FAILED (not PAYMENT_PROVIDER_UNAVAILABLE, which\n // is retryable) — a retry would reuse the already-reserved replay\n // key. The transaction hash is safe to disclose: it's the buyer's\n // own payment, public on-chain the moment it lands. Nothing else\n // from the underlying error travels — only this flag and the hash.\n throw new CommerceError(\n 'PAYMENT_SETTLEMENT_FAILED',\n uncertainTxHash !== undefined\n ? 'Settlement could not be confirmed'\n : 'Payment settlement failed',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n ...(uncertainTxHash !== undefined\n ? { details: { settlementUncertain: true, transactionHash: uncertainTxHash } }\n : {}),\n },\n );\n }\n\n if (settlement.status !== 'settled') {\n await safePersist(\n () =>\n options.store.updatePaymentAttempt({\n replayKey,\n status: 'rejected',\n ...(settlement.rejectionReason !== undefined\n ? { rejectionReason: settlement.rejectionReason }\n : {}),\n }),\n 'updatePaymentAttempt(rejected)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: settlement.rejectionReason ? { reason: settlement.rejectionReason } : {},\n }),\n );\n throw new CommerceError(\n 'PAYMENT_SETTLEMENT_FAILED',\n settlement.rejectionReason ?? 'Settlement was rejected',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n await safePersist(\n () =>\n options.store.updatePaymentAttempt({\n replayKey,\n status: 'settled',\n ...(settlement.externalReference !== undefined\n ? { externalReference: settlement.externalReference }\n : {}),\n }),\n 'updatePaymentAttempt(settled)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.settled',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'ok',\n }),\n );\n\n paymentResult = settlement;\n }\n\n // 6. call backend\n const backendStart = options.clock.monotonicMs();\n let backendResponse: BackendResponse;\n try {\n backendResponse = await options.backend.call(resource.handler, {\n requestId: request.requestId,\n resourceId: resource.id,\n input: validInput,\n });\n } catch (error) {\n const commerceError = toCommerceError(error, 'BACKEND_ERROR', 'Backend call failed');\n await safeEmit(\n buildEvent({\n type: 'backend.failed',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'error',\n durationMs: Math.round(options.clock.monotonicMs() - backendStart),\n data: { code: commerceError.code },\n }),\n );\n\n if (paymentResult !== undefined) {\n // Settlement already succeeded (verify -> reserve -> settle all\n // completed) before the backend call failed, so the\n // uncertain-settlement rule (\"the merchant's record now tells the\n // truth; the buyer must too\") applies to this far more common\n // *certain*-loss branch as well, not only to the uncertain-RPC-timeout\n // one 100 lines above. A backend 500 is more likely than an RPC\n // confirmation timeout, so disclosing strictly *less* here than there\n // would be backwards. The tx hash is\n // safe to disclose: it is the buyer's own payment, public\n // on-chain the moment it lands.\n const failedReceipt: CommerceReceipt = {\n id: options.ids.next('receipt'),\n requestId: request.requestId,\n resourceId: resource.id,\n deliveredAt: options.clock.nowIso(),\n backendStatus: backendErrorStatus(commerceError),\n protocol: request.protocol,\n payment: paymentResult,\n metadata: { delivered: false, backendErrorCode: commerceError.code },\n };\n await safePersist(\n () => options.store.saveReceipt(failedReceipt),\n 'saveReceipt(backend-failed-after-settlement)',\n request.requestId,\n );\n\n throw new CommerceError(\n 'BACKEND_ERROR',\n 'Payment settled but the backend call failed; the payment was not refunded automatically',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: commerceError,\n details: {\n payment: {\n status: paymentResult.status,\n provider: paymentResult.provider,\n amount: paymentResult.amount,\n currency: paymentResult.currency,\n ...(paymentResult.network !== undefined ? { network: paymentResult.network } : {}),\n ...(paymentResult.externalReference !== undefined\n ? { externalReference: paymentResult.externalReference }\n : {}),\n },\n },\n },\n );\n }\n\n throw commerceError;\n }\n\n await safeEmit(\n buildEvent({\n type: 'backend.called',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'ok',\n durationMs: backendResponse.durationMs,\n data: { status: backendResponse.status },\n }),\n );\n\n // 7. persist receipt, emit final event, return outcome\n const receipt: CommerceReceipt = {\n id: options.ids.next('receipt'),\n requestId: request.requestId,\n resourceId: resource.id,\n deliveredAt: options.clock.nowIso(),\n backendStatus: backendResponse.status,\n durationMs: backendResponse.durationMs,\n protocol: request.protocol,\n ...(paymentResult !== undefined ? { payment: paymentResult } : {}),\n };\n\n await safePersist(() => options.store.saveReceipt(receipt), 'saveReceipt', request.requestId);\n\n const totalDurationMs = Math.round(options.clock.monotonicMs() - pipelineStart);\n\n await safeEmit(\n buildEvent({\n type: 'resource.delivered',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'ok',\n durationMs: totalDurationMs,\n }),\n );\n\n return {\n kind: 'delivered',\n requestId: request.requestId,\n resourceId: resource.id,\n backendStatus: backendResponse.status,\n body: backendResponse.body,\n headers: backendResponse.headers,\n ...(paymentResult !== undefined ? { payment: paymentResult } : {}),\n receipt,\n durationMs: totalDurationMs,\n };\n }\n\n return { execute };\n}\n\n/** The HTTP status the backend actually returned, when known (backend-http.ts\n * attaches it as `details.status` for a non-2xx response). 0 means \"no\n * response was received at all\" (timeout/transport failure) — distinct from\n * any real HTTP status. */\nfunction backendErrorStatus(error: CommerceError): number {\n const status = error.details?.['status'];\n return typeof status === 'number' ? status : 0;\n}\n\nfunction uncertainSettlementTxHash(error: unknown): string | undefined {\n if (!isCommerceError(error) || error.code !== 'PAYMENT_PROVIDER_UNAVAILABLE') return undefined;\n const hash = error.details?.['transactionHash'];\n return typeof hash === 'string' ? hash : undefined;\n}\n\nfunction pickProvider(\n providers: readonly PaymentProvider[],\n methods: readonly PaymentMethodName[],\n): PaymentProvider | undefined {\n for (const method of methods) {\n const found = providers.find((provider) => provider.name === method);\n if (found) return found;\n }\n return undefined;\n}\n\nconst RESERVED_INPUT_KEYS = new Set([PAYMENT_INPUT_FIELD, '__proto__']);\n\nfunction stripPaymentField(input: unknown): unknown {\n if (typeof input !== 'object' || input === null || Array.isArray(input)) return input;\n const record = input as Record<string, unknown>;\n // Object.hasOwn: `in` would also match inherited names and strip things\n // that were never actually present on this input.\n const hasReserved = [...RESERVED_INPUT_KEYS].some((key) => Object.hasOwn(record, key));\n if (!hasReserved) return input;\n const rest: Record<string, unknown> = {};\n for (const key of Object.keys(record)) {\n // \"__proto__\" is dropped, not just excluded from the reserved-field\n // check: `rest[key] = record[key]` for key === \"__proto__\" would invoke\n // the inherited setter and reassign rest's own prototype instead of\n // creating a data property (belt-and-braces — validation.ts's\n // Object.hasOwn fix is the primary control).\n if (!RESERVED_INPUT_KEYS.has(key)) rest[key] = record[key];\n }\n return rest;\n}\n\nfunction describeError(error: unknown): { message: string; name?: string } {\n if (error instanceof Error) return { message: error.message, name: error.name };\n return { message: String(error) };\n}\n","/**\n * In-memory implementation of the frozen `ResourceRegistry` interface.\n */\nimport type { ProtocolName } from '../domain/common.js';\nimport type { CommerceResource, ResourceRegistry } from '../domain/resource.js';\nimport { CommerceError } from '../errors/index.js';\n\nexport class ResourceRegistryImpl implements ResourceRegistry {\n private readonly byId = new Map<string, CommerceResource>();\n private readonly ordered: readonly CommerceResource[];\n\n constructor(resources: readonly CommerceResource[]) {\n for (const resource of resources) {\n if (this.byId.has(resource.id)) {\n throw new CommerceError('CONFIG_INVALID', `Duplicate resource id \"${resource.id}\"`, {\n details: { resourceId: resource.id },\n });\n }\n this.byId.set(resource.id, resource);\n }\n this.ordered = [...resources];\n }\n\n get(id: string): CommerceResource | undefined {\n return this.byId.get(id);\n }\n\n list(): readonly CommerceResource[] {\n return this.ordered;\n }\n\n listExposedVia(protocol: ProtocolName): readonly CommerceResource[] {\n return this.ordered.filter((resource) => resource.exposedVia.includes(protocol));\n }\n\n has(id: string): boolean {\n return this.byId.has(id);\n }\n}\n\n/** Build a `ResourceRegistry` from a validated list of canonical resources. */\nexport function createResourceRegistry(resources: readonly CommerceResource[]): ResourceRegistry {\n return new ResourceRegistryImpl(resources);\n}\n","/**\n * src/core/execution\n *\n * The execution pipeline implementation: resource registry, backend executor,\n * event bus and the pipeline itself. Not part of the frozen `public-types.ts`\n * barrel — this is implementation, not contract — but exported as a stable\n * subpath so `src/gateway` (and tests) can wire it up.\n */\n\nexport type { HttpBackendExecutorOptions } from './backend-http.js';\nexport {\n extractPathParameterNames,\n findUnparsedBraceToken,\n HttpBackendExecutor,\n validateBackendRequestShape,\n} from './backend-http.js';\nexport type { CreateEventBusOptions, EventBus } from './event-bus.js';\nexport { createEventBus } from './event-bus.js';\nexport type { CreateExecutionPipelineOptions } from './pipeline.js';\nexport { createExecutionPipeline } from './pipeline.js';\nexport { createResourceRegistry, ResourceRegistryImpl } from './registry.js';\nexport type { FieldError, ValidationResult, Validator } from './validation.js';\nexport { compileJsonSchema, isObjectSchemaNode } from './validation.js';\n","/**\n * Canonical commerce events.\n *\n * FROZEN CONTRACT. Every event in a single flow shares one `requestId` so that\n * logs, payment attempts, backend calls and receipts are correlatable.\n */\nimport type { IsoTimestamp } from './common.js';\n\nexport const COMMERCE_EVENT_TYPES = [\n 'resource.discovered',\n 'resource.requested',\n 'payment.required',\n 'payment.rejected',\n 'payment.verified',\n 'payment.settled',\n 'backend.called',\n 'backend.failed',\n 'resource.delivered',\n] as const;\n\nexport type CommerceEventType = (typeof COMMERCE_EVENT_TYPES)[number];\n\nexport interface CommerceEvent {\n readonly id: string;\n readonly type: CommerceEventType;\n readonly requestId: string;\n readonly resourceId?: string;\n readonly at: IsoTimestamp;\n /** Protocol adapter that originated the request, e.g. 'mcp' or 'http'. */\n readonly adapter?: string;\n readonly paymentProvider?: string;\n readonly durationMs?: number;\n readonly status?: 'ok' | 'error';\n /** Non-secret, structured detail. Must never contain keys, headers or proofs. */\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Sink for canonical events.\n *\n * Implementations must be non-throwing from the caller's perspective: an event\n * sink failure must never fail an otherwise successful commerce flow.\n */\nexport interface EventSink {\n emit(event: CommerceEvent): Promise<void>;\n}\n","/**\n * Protocol adapter boundary.\n *\n * FROZEN CONTRACT. An adapter translates a protocol's wire format into a\n * `CanonicalRequest`, hands it to the execution pipeline and maps the outcome\n * back. It must not call merchant backends, implement payment logic, or hold\n * its own copy of the canonical model.\n *\n * Adapter isolation: a failure while starting or serving one adapter must not\n * prevent the others from operating.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { AdapterDescriptor, AdapterHealth, ProtocolName } from '../domain/common.js';\nimport type { EventSink } from '../domain/event.js';\nimport type { ExecutionPipeline } from '../domain/request.js';\nimport type { ResourceRegistry } from '../domain/resource.js';\nimport type { Logger } from './logger.js';\nimport type { Clock, IdGenerator } from './runtime.js';\n\n/** Everything an adapter is given. Nothing else is available to it. */\nexport interface ProtocolAdapterContext {\n readonly pipeline: ExecutionPipeline;\n readonly resources: ResourceRegistry;\n readonly events: EventSink;\n readonly logger: Logger;\n readonly clock: Clock;\n readonly ids: IdGenerator;\n /** Externally reachable base URL of the gateway, from config. */\n readonly publicBaseUrl: string;\n}\n\nexport interface ProtocolAdapter {\n readonly name: ProtocolName;\n readonly descriptor: AdapterDescriptor;\n\n start(context: ProtocolAdapterContext): Promise<void>;\n health(): Promise<AdapterHealth>;\n stop(): Promise<void>;\n}\n\n/**\n * A protocol adapter served over HTTP.\n *\n * The gateway mounts `handleHttp` at `mountPath` using raw Node request and\n * response objects, so adapters stay independent of the HTTP framework.\n *\n * GUARANTEE — the request body is **unconsumed**.\n *\n * `req` is handed over with its stream unread: the gateway suppresses every\n * body parser on this mount, so an adapter whose SDK reads the body itself\n * (MCP's Streamable HTTP transport does) can do so. The adapter owns reading,\n * size-limiting beyond the gateway's own cap, and parsing.\n *\n * This is load-bearing and easy to break silently. Fastify pre-registers\n * exact-match parsers for `application/json` and `text/plain` and prefers them\n * over a `'*'` wildcard, so registering only a wildcard no-op leaves the\n * built-in JSON parser draining the body first — the adapter then reads an\n * empty stream and every request fails to parse. That exact regression shipped\n * once and no unit test caught it, because adapter conformance suites drive\n * `handleHttp` over a bare `node:http` server and never traverse the gateway.\n *\n * Any change to how adapters are mounted must be covered by a test that POSTs\n * a real JSON body through the real gateway and asserts the adapter received\n * it intact.\n */\nexport interface HttpProtocolAdapter extends ProtocolAdapter {\n /** Path prefix the gateway mounts this adapter at, e.g. '/mcp'. */\n readonly mountPath: string;\n handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;\n /**\n * Fixed paths this adapter owns *outside* its mount, for protocols whose\n * specification pins a discovery URL (A2A's `/.well-known/agent-card.json`).\n * The gateway mounts them with the same guarantees as `mountPath` — same\n * unconsumed body, same concurrency cap, same failure isolation — so the\n * gateway needs no per-protocol routing knowledge.\n *\n * Omitted by adapters that need none.\n */\n readonly additionalHttpRoutes?: readonly AdapterHttpRoute[];\n}\n\n/**\n * One fixed, method-scoped route owned by an adapter. Unlike `mountPath` it\n * registers no wildcard: it matches exactly the path given.\n */\nexport interface AdapterHttpRoute {\n readonly method: 'GET' | 'POST';\n /** Absolute gateway path, e.g. '/.well-known/agent-card.json'. */\n readonly path: string;\n handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;\n}\n\nexport function isHttpProtocolAdapter(adapter: ProtocolAdapter): adapter is HttpProtocolAdapter {\n return typeof (adapter as HttpProtocolAdapter).handleHttp === 'function';\n}\n","/**\n * Injected runtime primitives.\n *\n * Everything non-deterministic (time, ids) is injected so tests can be exact.\n */\nimport type { IsoTimestamp } from '../domain/common.js';\n\nexport interface Clock {\n now(): Date;\n nowIso(): IsoTimestamp;\n /** Milliseconds since an arbitrary origin; use for durations only. */\n monotonicMs(): number;\n}\n\nexport interface IdGenerator {\n /** Opaque, collision-resistant identifier. */\n next(prefix?: string): string;\n}\n\nexport const systemClock: Clock = {\n now: () => new Date(),\n nowIso: () => new Date().toISOString(),\n monotonicMs: () => performance.now(),\n};\n","/**\n * ============================================================================\n * FROZEN PUBLIC CONTRACT — frozen at v0.1.0-alpha\n * ============================================================================\n *\n * Every cross-package type and interface in the project is re-exported here.\n * This barrel is frozen. Everything reachable from it is public API that\n * consumers code against, so a change to any of it is a breaking change and\n * needs the decision record updated to match.\n *\n * Do not redeclare these shapes locally. If something is missing, add it here\n * rather than creating a parallel type.\n *\n * See docs/contracts.md for the freeze record.\n */\n\n// --- canonical domain ------------------------------------------------------\nexport type {\n AdapterDescriptor,\n AdapterHealth,\n DecimalAmount,\n IsoTimestamp,\n JsonSchema,\n PaymentMethodName,\n ProtocolName,\n} from './domain/common.js';\nexport type { CommerceEvent, CommerceEventType, EventSink } from './domain/event.js';\nexport { COMMERCE_EVENT_TYPES } from './domain/event.js';\n\nexport type {\n PaymentChallenge,\n PaymentContext,\n PaymentProvider,\n PaymentRequirement,\n PaymentResult,\n PaymentSettlementContext,\n PaymentSubmission,\n PaymentVerificationContext,\n} from './domain/payment.js';\n\nexport type { CommerceReceipt, PaymentAttempt } from './domain/receipt.js';\nexport type {\n CanonicalRequest,\n DeliveredOutcome,\n ExecutionOutcome,\n ExecutionPipeline,\n PaymentRequiredOutcome,\n} from './domain/request.js';\nexport type {\n BackendHandler,\n BackendMethod,\n CommerceResource,\n Pricing,\n ResourceRegistry,\n} from './domain/resource.js';\nexport { DEFAULT_BACKEND_TIMEOUT_MS } from './domain/resource.js';\nexport type {\n DeliverySummary,\n ErrorEnvelope,\n PaymentRequiredEnvelope,\n} from './domain/wire.js';\nexport {\n DELIVERY_SUMMARY_META_KEY,\n isPaymentRequiredEnvelope,\n PAYMENT_HEADER,\n PAYMENT_INPUT_FIELD,\n PAYMENT_REQUIRED_HEADER,\n PAYMENT_RESPONSE_HEADER,\n toDeliverySummary,\n toErrorEnvelope,\n toPaymentRequiredEnvelope,\n} from './domain/wire.js';\n\n// --- errors ----------------------------------------------------------------\nexport type { CommerceErrorCode, CommerceErrorInfo, CommerceErrorOptions } from './errors/index.js';\nexport {\n COMMERCE_ERROR_CODES,\n COMMERCE_ERROR_HTTP_STATUS,\n CommerceError,\n isCommerceError,\n RETRYABLE_ERROR_CODES,\n toCommerceError,\n} from './errors/index.js';\n\n// --- injection boundaries --------------------------------------------------\nexport type { BackendExecutor, BackendRequest, BackendResponse } from './interfaces/backend.js';\nexport type { Logger } from './interfaces/logger.js';\nexport { NOOP_LOGGER } from './interfaces/logger.js';\nexport type {\n AdapterHttpRoute,\n HttpProtocolAdapter,\n ProtocolAdapter,\n ProtocolAdapterContext,\n} from './interfaces/protocol-adapter.js';\nexport { isHttpProtocolAdapter } from './interfaces/protocol-adapter.js';\nexport type { Clock, IdGenerator } from './interfaces/runtime.js';\nexport { systemClock } from './interfaces/runtime.js';\nexport type {\n ListOptions,\n PaymentAttemptReservation,\n PaymentAttemptUpdate,\n ReceiptStore,\n} from './interfaces/store.js';\n","/**\n * src/core\n *\n * Canonical commerce domain model, typed errors and the execution pipeline.\n * Contains no protocol- or payment-rail-specific code.\n */\nexport * from './public-types.js';\n","/**\n * The networks this gateway will settle on, as data.\n *\n * x402 v2 identifies a network by its CAIP-2 id, so the only thing an\n * operator has to change to move between environments is that string. What\n * the code needs on top of it — the chain id to sign against, a name a human\n * recognises, and whether real money is involved — lives here rather than\n * being derived at each call site.\n *\n * A registry rather than \"parse any `eip155:*`\" on purpose. The chain id is\n * parseable from any such string, but `mainnet` is not, and every guardrail in\n * `guardrails.ts` keys off it. An unknown id is refused at startup instead of\n * being quietly treated as a testnet.\n *\n * Base Sepolia and the local dev chain share the id `eip155:84532`: the local\n * chain deliberately reuses Base Sepolia's chain id so the unmodified x402 SDK\n * can talk to it. Nothing may infer \"public network\" from the network id alone\n * — that is what `resolveDeploymentMode` and the Anvil probe in `provider.ts`\n * are for.\n */\nimport { CommerceError } from '../../core/index.js';\n\nexport interface NetworkProfile {\n /** CAIP-2 identifier, e.g. `eip155:84532`. */\n readonly id: string;\n /** Signed into the buyer's EIP-712 domain. */\n readonly chainId: number;\n readonly displayName: string;\n readonly kind: 'testnet' | 'mainnet';\n /**\n * The USDC deployment this network is expected to settle in, with the EIP-712\n * domain the token actually reports. Enforced only on mainnet (see\n * `guardrails.ts`) — a testnet is where a mock token is a legitimate thing to\n * point at.\n *\n * `name` is not decorative and is not the symbol: it is signed into every\n * buyer's EIP-712 domain, and the two USDC deployments disagree. Base Sepolia\n * reports `\"USDC\"`; Base mainnet reports `\"USD Coin\"`. Configure the wrong\n * one and every payment is refused `invalid_exact_evm_token_name_mismatch`\n * after the buyer has signed. Read back from the contracts, not assumed.\n */\n readonly canonicalAsset?: {\n readonly symbol: string;\n readonly address: string;\n readonly name: string;\n readonly version: string;\n };\n}\n\nconst PROFILES: readonly NetworkProfile[] = [\n {\n id: 'eip155:84532',\n chainId: 84532,\n displayName: 'Base Sepolia',\n kind: 'testnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n name: 'USDC',\n version: '2',\n },\n },\n {\n id: 'eip155:8453',\n chainId: 8453,\n displayName: 'Base',\n kind: 'mainnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n name: 'USD Coin',\n version: '2',\n },\n },\n];\n\nconst BY_ID = new Map(PROFILES.map((profile) => [profile.id, profile]));\n\nexport const SUPPORTED_NETWORK_IDS: readonly string[] = PROFILES.map((p) => p.id);\n\nexport function findNetworkProfile(id: string): NetworkProfile | undefined {\n return BY_ID.get(id);\n}\n\nexport function requireNetworkProfile(id: string, path: string): NetworkProfile {\n const profile = BY_ID.get(id);\n if (!profile) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `${path}: \"${id}\" is not a supported network. Supported CAIP-2 identifiers: ${SUPPORTED_NETWORK_IDS.join(', ')}`,\n { details: { path, network: id } },\n );\n }\n return profile;\n}\n\n/**\n * What this deployment actually is, as opposed to what it is called.\n *\n * `local` is a property of the *facilitator*, not the network: settling\n * through the in-process facilitator against a dev node is local regardless of\n * the CAIP-2 id that node answers to. This distinction is the whole reason\n * diagnostics can say `eip155:84532` without claiming to be on public Base\n * Sepolia.\n */\nexport type DeploymentMode = 'local' | 'testnet' | 'mainnet';\n\nexport function resolveDeploymentMode(\n profile: NetworkProfile,\n facilitatorMode: 'local' | 'remote',\n): DeploymentMode {\n if (facilitatorMode === 'local') return 'local';\n return profile.kind;\n}\n\n/** The banner an operator must not be able to miss. Never printed for anything else. */\nexport const LIVE_MAINNET_BANNER = 'LIVE MAINNET MODE — REAL FUNDS';\n\nexport function describeDeploymentMode(mode: DeploymentMode): string {\n return mode === 'mainnet' ? LIVE_MAINNET_BANNER : mode.toUpperCase();\n}\n","/**\n * `${VAR}` / `${VAR:-default}` substitution over an arbitrary parsed-YAML value.\n *\n * Only string leaves are touched; numbers/booleans/null pass through untouched\n * (the caller coerces the *resulting* string back into a number/boolean where\n * the schema expects one). An unresolved placeholder fails config loading\n * immediately — startup must never proceed with an unresolved secret. That\n * includes one left behind by a *nested* placeholder such as `${A:-${B}}`,\n * which is rejected rather than silently passed through. There is no\n * escape syntax for a literal `${NAME}`; nothing in this config format needs\n * one, and adding it would mean two ways to write every value.\n *\n * `${VAR}` (no default) requires `VAR` to be present in `env` (any value,\n * including an empty string, counts as present).\n * `${VAR:-default}` falls back to `default` when `VAR` is absent OR empty,\n * matching common shell semantics.\n *\n * Anything else brace-shaped is refused: `${VAR-x}`, `${VAR:=x}`, `${VAR:?x}`\n * are valid *shell* and would otherwise load as literal strings. That is\n * harmless where a downstream check rejects the literal, and quietly wrong for\n * a free-string field — `adminToken: ${ADMIN_TOKEN-fallback}` would run the\n * gateway with that literal as the ledger credential while the operator\n * believed an env secret gated it. A bare `$VAR` is deliberately left alone: it\n * is not brace-shaped, and refusing it would reject values that legitimately\n * contain a dollar sign.\n *\n * Every rule above is decided from the **template**, before substitution.\n * Deciding afterwards is how `${A:-${B}}` used to corrupt a value on the one\n * branch its guard did not cover, and how a resolved secret containing a\n * `${…}`-shaped fragment used to get quoted back in the error text.\n *\n * The resolved *value* of a variable is never included in any error message —\n * only the variable *name* and the config path are.\n */\nimport { CommerceError } from '../core/index.js';\n\nconst PLACEHOLDER_PATTERN = /\\$\\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?\\}/g;\n\n/** An innermost brace token: `${` … `}` with no braces between. */\nconst BRACE_TOKEN = /\\$\\{[^{}]*\\}/g;\n\n/** The same grammar as PLACEHOLDER_PATTERN, anchored, for validating one token. */\nconst SUPPORTED_TOKEN = /^\\$\\{[A-Za-z_][A-Za-z0-9_]*(:-[^}]*)?\\}$/;\n\n/** A placeholder whose default segment opens another placeholder. */\nconst NESTED_PLACEHOLDER = /\\$\\{[^{}]*\\$\\{/;\n\nexport function substituteEnv(value: unknown, env: NodeJS.ProcessEnv, path = '$'): unknown {\n if (typeof value === 'string') {\n return substituteString(value, env, path);\n }\n if (Array.isArray(value)) {\n return value.map((entry, index) => substituteEnv(entry, env, `${path}[${index}]`));\n }\n if (isPlainObject(value)) {\n const result: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n result[key] = substituteEnv(entry, env, `${path}.${key}`);\n }\n return result;\n }\n return value;\n}\n\nfunction substituteString(value: string, env: NodeJS.ProcessEnv, path: string): string {\n assertTemplateIsSupported(value, path);\n return substituteOnce(value, env, path);\n}\n\n/**\n * Refuses a template this module cannot honour, before any substitution runs.\n *\n * `${A:-${B}}` is the case that motivated this. `[^}]*` cannot span the inner\n * `}`, so the match consumes `${A:-${B` and leaves a stray `}` behind. When `A`\n * is unset the leftover `${B}` was visible afterwards and got caught; when `A`\n * is *set* — the normal case, and the whole reason someone writes a default —\n * substitution succeeded and the stray `}` was appended to the resolved value\n * with nothing to notice it. For `adminToken` that means the gateway compares\n * against a credential the operator does not hold, with no diagnostic.\n *\n * Deciding from the template covers both branches with one rule, and means no\n * error message is ever derived from a resolved value.\n */\nfunction assertTemplateIsSupported(value: string, path: string): void {\n if (NESTED_PLACEHOLDER.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" nests placeholders (e.g. \"\\${A:-\\${B}}\"), which is not supported — the inner one is not resolved and its closing brace ends up in the value. Use a plain default, or set the variable.`,\n { details: { path } },\n );\n }\n\n BRACE_TOKEN.lastIndex = 0;\n for (const [token] of value.matchAll(BRACE_TOKEN)) {\n if (SUPPORTED_TOKEN.test(token)) continue;\n // The token itself, never the surrounding value: this runs pre-substitution,\n // so it cannot contain a resolved secret.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" contains \"${token}\", which is not a supported placeholder. Only \"\\${VAR}\" and \"\\${VAR:-default}\" are recognised; shell forms such as \"\\${VAR-default}\", \"\\${VAR:=default}\" and \"\\${VAR:?message}\" would load as literal text.`,\n { details: { path, token } },\n );\n }\n}\n\nfunction substituteOnce(value: string, env: NodeJS.ProcessEnv, path: string): string {\n return value.replace(\n PLACEHOLDER_PATTERN,\n (_match, name: string, hasDefault: string | undefined, def: string | undefined) => {\n const envValue = env[name];\n\n if (hasDefault !== undefined) {\n if (envValue === undefined || envValue === '') return def ?? '';\n return envValue;\n }\n\n if (envValue === undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Unresolved environment variable \"\\${${name}}\" referenced at config path \"${path}\"`,\n { details: { variable: name, path } },\n );\n }\n return envValue;\n },\n );\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","/**\n * Anvil's well-known development accounts.\n *\n * LOCAL DEVELOPMENT ONLY — DO NOT FUND. These addresses and private keys are\n * derived from Foundry's public, well-documented default test mnemonic\n * (\"test test test test test test test test test test test junk\") and are\n * known to everyone who has ever run `anvil`. Anyone who sends real value to\n * one of these addresses on a real network will lose it.\n *\n * Index layout used by the local demo chain (see docs/contracts.md):\n * 0 — deployer / local facilitator signer (pays gas, broadcasts settlement)\n * 1 — merchant settlement destination (`payTo`)\n * 2 — buyer (signs EIP-3009 authorisations; never held by the gateway)\n */\nexport interface AnvilWellKnownAccount {\n readonly address: `0x${string}`;\n readonly privateKey: `0x${string}`;\n}\n\n/** Fixed-length tuple (not a bare array) so indexing by the documented layout above is fully typed. */\nexport const ANVIL_WELL_KNOWN_ACCOUNTS: readonly [\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n] = [\n {\n address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',\n privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',\n },\n {\n address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',\n privateKey: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',\n },\n {\n address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',\n privateKey: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',\n },\n];\n\nexport const LOCAL_FACILITATOR_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[0];\nexport const LOCAL_MERCHANT_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[1];\nexport const LOCAL_BUYER_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[2];\n\n/** Safe label used everywhere a dev key appears in output, logs or manifests. */\nexport const DEV_KEY_LABEL = 'LOCAL DEVELOPMENT ONLY - DO NOT FUND';\n","/**\n * Prevents a well-known Anvil development private key — or a well-known\n * Anvil development *address* — from ever being used against anything other\n * than a loopback/private/dev RPC. Two symmetric mistakes, both covered:\n * signing settlement with a dev key (`assertDevKeyIsLocalOnly`), and routing\n * settlement revenue to a dev address (`assertPayToIsNotDevAddress`). The\n * second is the more consequential of the two — a wrong key merely fails to\n * sign, a wrong payTo silently succeeds and gives the money away, since the\n * private key behind every well-known Anvil address is public knowledge.\n *\n * Chain id alone cannot tell a real network from this project's local dev\n * chain: Base Sepolia's own chain id is 84532, the same id this project\n * deliberately reuses for the local chain so the unmodified x402 SDK can talk\n * to it. A dev key or dev payTo pointed at a real RPC by a config mistake is\n * instantly drainable — this is checked once at provider construction, not per\n * payment.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from './local-chain/accounts.js';\n\nconst WELL_KNOWN_DEV_KEYS: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.privateKey.toLowerCase()),\n);\n\nconst WELL_KNOWN_DEV_ADDRESSES: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.address.toLowerCase()),\n);\n\n/** `0x` + 64 hex chars — the only shape `privateKeyToAccount` accepts. */\nconst PRIVATE_KEY_SHAPE = /^0x[0-9a-fA-F]{64}$/;\n\nexport function isWellKnownDevKey(privateKey: string): boolean {\n return WELL_KNOWN_DEV_KEYS.has(privateKey.toLowerCase());\n}\n\nexport function isWellKnownDevAddress(address: string): boolean {\n return WELL_KNOWN_DEV_ADDRESSES.has(address.toLowerCase());\n}\n\n/**\n * True for loopback addresses, RFC1918 private ranges, and bare (dot-free)\n * hostnames — the shape of a docker-compose/k8s service name (e.g.\n * \"anvil\"), which a real public DNS name essentially never has.\n *\n * ASSUMPTION, and the loosest edge of this guard: every dot-free, colon-free\n * hostname is treated as private, with no exceptions. A single-label *public* hostname (no dots) is\n * essentially nonexistent in practice — ICANN does not delegate bare\n * gTLDs/TLDs as public A/AAAA records — but this function cannot tell \"no\n * dots because it's a compose service name\" from \"no dots because it's an\n * unusual real host\" if one somehow existed. If that assumption ever stops\n * holding, this is the line to revisit.\n */\nexport function isLikelyLocalOrPrivateHost(hostname: string): boolean {\n const h = hostname.toLowerCase().replace(/^\\[|\\]$/g, '');\n if (h === 'localhost' || h === '127.0.0.1' || h === '::1') return true;\n if (/^127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^192\\.168\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^172\\.(1[6-9]|2\\d|3[01])\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (!h.includes('.') && !h.includes(':')) return true; // bare hostname\n return false;\n}\n\nfunction parseHostnameOrThrow(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).hostname;\n } catch (cause) {\n // Not the URL itself: every commercial EVM RPC provider embeds an API key\n // in the path, and these messages reach `validate`, `doctor`, startup\n // output and CI logs.\n throw new CommerceError('CONFIG_INVALID', 'x402 provider: rpcUrl is not a valid URL', {\n cause,\n });\n }\n}\n\n/** Host only, for diagnostics. An RPC URL's path routinely carries a key. */\nfunction describeRpc(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).origin;\n } catch {\n return '[unparseable rpcUrl]';\n }\n}\n\n/**\n * Throws CONFIG_INVALID if a well-known dev key would sign against a non-local\n * RPC — or if `signerPrivateKey` isn't shaped like a private key at all.\n *\n * The shape check runs first and unconditionally. \"Not a key I recognise\"\n * (falls through `isWellKnownDevKey`, silently treated as someone's own real\n * facilitator key) and \"not a key at all\" (e.g. a truncated 63-char string)\n * must never share a code path: a malformed key that slips past this guard\n * only fails later, inside `settle()`, after the buyer's replayKey is already\n * reserved.\n */\nexport function assertDevKeyIsLocalOnly(rpcUrl: string, signerPrivateKey: string): void {\n if (!PRIVATE_KEY_SHAPE.test(signerPrivateKey)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is not a well-formed private key ' +\n '(expected \"0x\" followed by exactly 64 hex characters).',\n );\n }\n\n if (!isWellKnownDevKey(signerPrivateKey)) return; // a real facilitator key: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is a well-known Anvil development key, but rpcUrl ' +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. A public dev key must never sign against ` +\n 'a public network — it is instantly drainable and can grief real settlements via nonce exhaustion. ' +\n 'Use a real facilitator key for any non-local RPC, or point rpcUrl at your local/dev chain.',\n );\n }\n}\n\n/**\n * Throws CONFIG_INVALID if `payTo` (the settlement destination) is a\n * well-known Anvil development address and `rpcUrl` doesn't look\n * local/private.\n *\n * Mirrors `assertDevKeyIsLocalOnly`, but guards the *receiving* side of the\n * payment instead of the signing side, and — unlike the key guard — applies\n * regardless of facilitator mode: which account signs the settlement\n * transaction has no bearing on whether the destination address is one whose\n * private key is public knowledge. `agent-commerce init` defaults `payTo` to\n * a well-known Anvil address as a local-demo convenience; on a real network\n * that default routes every payment to an address anyone on earth can sweep.\n */\nexport function assertPayToIsNotDevAddress(rpcUrl: string, payTo: string): void {\n if (!isWellKnownDevAddress(payTo)) return; // not a dev address: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"payTo\" (${payTo}) is a well-known Anvil development address, but rpcUrl ` +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. The private key behind that address ` +\n 'is public knowledge, so any revenue settled to it is immediately spendable by anyone. Set ' +\n '\"payTo\" to your own merchant wallet for any non-local RPC, or point rpcUrl at your ' +\n 'local/dev chain.',\n );\n }\n}\n","/**\n * Everything that must be true before this gateway is allowed to settle a\n * payment on the configured network.\n *\n * One definition, two callers: the provider runs it at construction so a\n * library consumer who never touches our config loader still gets the checks,\n * and `doctor` runs it against the parsed config so an operator sees the same\n * verdict without starting the gateway. Sharing a *call* is not sharing a\n * definition — the checks live here, and nothing re-implements them.\n *\n * Every failure is a startup failure. None of these are request-time\n * decisions: a deployment that is unsafe is unsafe before the first buyer\n * arrives, and finding out during `settle()` means the buyer's authorisation\n * is already burned.\n *\n * Peer-free by construction (no viem, no `@x402/*`) so the CLI can import it.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { isLikelyLocalOrPrivateHost, isWellKnownDevAddress } from './dev-key-guard.js';\nimport {\n type DeploymentMode,\n type NetworkProfile,\n requireNetworkProfile,\n resolveDeploymentMode,\n} from './networks.js';\n\n/**\n * How the gateway authenticates to a remote facilitator.\n *\n * Deliberately a list, not a vendor: x402 facilitators are not a Coinbase-only\n * category, and a scheme that only fitted one vendor's credentials would make\n * the abstraction a fiction.\n *\n * - `none` — the facilitator takes no credential (the public testnet one).\n * - `bearer` — a static token. Covers most self-hosted and third-party\n * facilitators, and needs nothing installed.\n * - `cdp` — Coinbase Developer Platform, which signs a fresh JWT per request\n * over method + host + path, so a static header cannot express it. Handled by\n * the optional peer `@coinbase/x402`, imported only when this type is\n * configured. Anyone not using CDP never installs it.\n *\n * A facilitator whose scheme is none of these is refused at config load rather\n * than sent nothing.\n */\nexport type FacilitatorAuth =\n | { readonly type: 'none' }\n | { readonly type: 'bearer'; readonly token: string }\n | { readonly type: 'cdp'; readonly apiKeyId: string; readonly apiKeySecret: string };\n\nexport type X402FacilitatorConfig =\n | { readonly mode: 'local'; readonly signerPrivateKey: string }\n | { readonly mode: 'remote'; readonly url: string; readonly auth: FacilitatorAuth };\n\nexport interface X402DeploymentInput {\n readonly network: string;\n readonly payTo: string;\n readonly asset: string;\n /** EIP-712 domain of the asset, as the token itself reports it. */\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly facilitator: X402FacilitatorConfig;\n /** Required, and required to be `true`, before anything settles on a mainnet. */\n readonly allowMainnet?: boolean;\n /**\n * Required, and required to be `true`, to settle on a mainnet through a\n * facilitator that takes no credential.\n *\n * Separate from `allowMainnet` because it names a different decision: not\n * \"I meant to use real money\" but \"I accept this particular counterparty\n * without an account, terms, or anyone to call\".\n */\n readonly allowUnauthenticatedFacilitator?: boolean;\n}\n\nexport interface X402Deployment {\n readonly profile: NetworkProfile;\n readonly mode: DeploymentMode;\n}\n\nfunction invalid(message: string, path: string): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path } });\n}\n\n/**\n * Resolves the deployment and refuses every combination that could move real\n * money by accident. Order matters only in that the network must resolve\n * first; the rest are independent.\n */\nexport function resolveX402Deployment(input: X402DeploymentInput): X402Deployment {\n const profile = requireNetworkProfile(input.network, 'payments.x402.network');\n const mode = resolveDeploymentMode(profile, input.facilitator.mode);\n\n // The in-process facilitator signs with a key this process holds. Not a\n // custody problem — that signer never holds buyer or merchant funds, it pays\n // gas and broadcasts `transferWithAuthorization`, and the money moves buyer\n // to merchant directly on-chain. What it *is*, on a mainnet, is a funded key\n // inside the resource server: compromise that process and an attacker drains\n // the gas wallet and broadcasts from it. Separate processes, separate blast\n // radius — so it is refused, not warned about.\n if (profile.kind === 'mainnet' && input.facilitator.mode === 'local') {\n throw invalid(\n `payments.x402: network \"${profile.id}\" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode \"local\". A mainnet deployment must settle through a remote facilitator.`,\n 'payments.x402.facilitator.mode',\n );\n }\n\n if (mode === 'mainnet' && input.allowMainnet !== true) {\n throw invalid(\n `payments.x402: network \"${profile.id}\" (${profile.displayName}) settles real funds. Set payments.x402.allowMainnet: true to acknowledge this explicitly — it is never the default.`,\n 'payments.x402.allowMainnet',\n );\n }\n\n if (input.facilitator.mode === 'remote') {\n assertFacilitatorUrlIsSafe(input.facilitator.url, mode);\n // Not a funds check. An EIP-3009 authorisation names its recipient, its\n // amount and its chain, so a facilitator can broadcast exactly that\n // transfer or nothing — it cannot redirect the money. What a credential\n // buys is a *relationship*: rate limits, terms, someone to call when\n // settlement stops. Running production payments through a counterparty you\n // have none of that with is a real choice, and this is where it gets made\n // explicitly rather than by omission.\n if (\n mode === 'mainnet' &&\n input.facilitator.auth.type === 'none' &&\n input.allowUnauthenticatedFacilitator !== true\n ) {\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(input.facilitator.url)} takes no credential, and this is a mainnet deployment. It will see every payment authorisation you handle, with no account, terms or support behind it. Set payments.x402.allowUnauthenticatedFacilitator: true to accept that, or configure facilitator.auth.`,\n 'payments.x402.allowUnauthenticatedFacilitator',\n );\n }\n // An empty credential is refused rather than sent: a blank token or key\n // reaches the facilitator as \"unauthenticated\" and fails every payment\n // after the buyer has already signed. `${VAR:- }` resolving to whitespace\n // is the realistic way this happens.\n for (const [field, value] of credentialFields(input.facilitator.auth)) {\n if (value.trim() === '') {\n throw invalid(\n `payments.x402: facilitator.auth.type is \"${input.facilitator.auth.type}\" but ${field} is empty. An empty credential is refused rather than sent.`,\n `payments.x402.facilitator.auth.${field}`,\n );\n }\n }\n }\n\n // The private key behind every well-known Anvil address is public knowledge.\n // `dev-key-guard` already refuses one against a public *RPC*; this refuses\n // one on any non-local *deployment*, which is the case a remote facilitator\n // creates — there the RPC host says nothing about where settlement lands.\n // The zero address lived only in the config loader, so a library consumer\n // calling `createX402PaymentProvider` directly — the path this shared\n // definition exists to cover — could boot a mainnet provider whose every\n // payment burns — sharing a *call* is not sharing a definition, and this\n // check had drifted out of the shared one.\n if (/^0x0{40}$/i.test(input.payTo)) {\n throw invalid(\n 'payments.x402: \"payTo\" is the zero address. Every payment settled there is destroyed.',\n 'payments.x402.payTo',\n );\n }\n\n if (mode !== 'local' && isWellKnownDevAddress(input.payTo)) {\n throw invalid(\n `payments.x402: \"payTo\" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set payTo to your own merchant wallet.`,\n 'payments.x402.payTo',\n );\n }\n\n // Mainnet only. A testnet is exactly where pointing at a mock token is the\n // right thing to do, so the same check there would block the normal case.\n const canonical = profile.canonicalAsset;\n if (mode === 'mainnet' && canonical) {\n if (!sameAddress(input.asset, canonical.address)) {\n throw invalid(\n `payments.x402: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). Settling a mainnet payment in an unintended token is refused.`,\n 'payments.x402.asset',\n );\n }\n // The EIP-712 domain is signed by the buyer and checked by the scheme. Get\n // it wrong and every payment is refused `invalid_exact_evm_token_name_mismatch`\n // *after* the buyer signed — a config error charged to the buyer's patience.\n // Caught here instead, before the gateway starts.\n if (input.assetName !== undefined && input.assetName !== canonical.name) {\n throw invalid(\n `payments.x402: assetName \"${input.assetName}\" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.name}\"). Every payment would be refused after the buyer signed.`,\n 'payments.x402.assetName',\n );\n }\n if (input.assetVersion !== undefined && input.assetVersion !== canonical.version) {\n throw invalid(\n `payments.x402: assetVersion \"${input.assetVersion}\" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.version}\").`,\n 'payments.x402.assetVersion',\n );\n }\n }\n\n return { profile, mode };\n}\n\n/**\n * A facilitator sees every payment authorisation this gateway handles. Plain\n * HTTP to one on a public network puts those on the wire in the clear and\n * lets anyone in the path rewrite a settlement result, so it is allowed only\n * where the endpoint cannot leave the host — a local or private address.\n */\nfunction assertFacilitatorUrlIsSafe(url: string, mode: DeploymentMode): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch (cause) {\n throw new CommerceError('CONFIG_INVALID', `payments.x402: facilitator.url is not a valid URL`, {\n cause,\n details: { path: 'payments.x402.facilitator.url' },\n });\n }\n\n if (parsed.protocol === 'https:') return;\n if (parsed.protocol !== 'http:') {\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got \"${parsed.protocol}//\"`,\n 'payments.x402.facilitator.url',\n );\n }\n if (mode !== 'mainnet' && isLikelyLocalOrPrivateHost(parsed.hostname)) return;\n\n // The origin, never the whole URL: the path can carry a tenant or an API\n // key, which is why `/.well-known` withholds this field entirely. A refusal\n // message goes to `validate`, `doctor`, startup output and CI logs.\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorisations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,\n 'payments.x402.facilitator.url',\n );\n}\n\n/** Host only — a facilitator URL can carry a tenant path or an API key. */\nfunction describeOrigin(url: string): string {\n try {\n return new URL(url).origin;\n } catch {\n return '[unparseable facilitator.url]';\n }\n}\n\n/** The secret-bearing fields of an auth block, for emptiness checks only. Never logged. */\nfunction credentialFields(auth: FacilitatorAuth): readonly (readonly [string, string])[] {\n switch (auth.type) {\n case 'bearer':\n return [['token', auth.token]];\n case 'cdp':\n return [\n ['apiKeyId', auth.apiKeyId],\n ['apiKeySecret', auth.apiKeySecret],\n ];\n default:\n return [];\n }\n}\n\nfunction sameAddress(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n","/**\n * `config.yaml` schema, validation and normalisation into the\n * canonical `GatewayConfig` (docs/contracts.md).\n *\n * Two-phase validation:\n * 1. Zod validates *shape* (types, required fields, unknown-key rejection).\n * Numeric/boolean leaves accept either their native type or a string\n * (env substitution always produces a string), and are left as-is here —\n * Zod's typed transforms have surprising inference interactions with\n * `.strict()` objects, so numeric/boolean coercion is done explicitly,\n * in plain TypeScript, in the normalisation pass below.\n * 2. A manual business-rule pass validates cross-references that need a\n * specific, actionable message (duplicate ids, disabled protocols/payment\n * methods, dynamic pricing, destination-address plausibility) and\n * performs the numeric/boolean coercion.\n *\n * Env substitution (`${VAR}` / `${VAR:-default}`) runs over the raw parsed\n * value *before* either phase, so numeric/boolean fields can be templated too.\n * One exception, deliberate: `checkVersion` runs **before** substitution, so\n * `version:` cannot itself be templated. It is the compatibility gate that\n * decides whether this parser understands the document at all; resolving\n * environment variables to find out which schema version to expect would be\n * backwards. The order is intended; `version:` is the one exception to the\n * substitution rule, which this sentence exists to record.\n */\n\nimport { type ZodError, type ZodIssue, type ZodTypeAny, z } from 'zod';\nimport {\n extractPathParameterNames,\n findUnparsedBraceToken,\n isObjectSchemaNode,\n} from '../core/execution/index.js';\nimport {\n CommerceError,\n type CommerceResource,\n PAYMENT_INPUT_FIELD,\n type Pricing,\n} from '../core/index.js';\nimport { resolveX402Deployment, type X402FacilitatorConfig } from '../payments/x402/guardrails.js';\nimport { substituteEnv } from './env.js';\n\nconst SUPPORTED_CONFIG_VERSION = 1;\n\n/** `0x` + 40 hex chars. Checksum-insensitive: casing is not enforced. */\nconst ADDRESS_PATTERN = /^0x[0-9a-fA-F]{40}$/;\nconst ZERO_ADDRESS_PATTERN = /^0x0{40}$/i;\n\n/**\n * A resource `id` doubles as its MCP tool name (protocol-mcp registers one\n * tool per resource, named by id). Value verified against the regex actually\n * shipped in the installed `@modelcontextprotocol/sdk@1.30.0`\n * (`shared/toolNameValidation.js`, SEP-986 \"Specify Format for Tool Names\") —\n * not duplicated as an SDK dependency, since config stays protocol-agnostic.\n */\nconst MCP_TOOL_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;\n\n// ---------------------------------------------------------------------------\n// Zod schema for the *shape* of the raw (post-substitution) document.\n// ---------------------------------------------------------------------------\n\n/** Accepts a real number or a (post env-substitution) numeric string. */\nconst NumberOrString = z.union([z.number(), z.string()]);\n/** Accepts a real boolean or a (post env-substitution) \"true\"/\"false\" string. */\nconst BooleanOrString = z.union([z.boolean(), z.string()]);\n\nconst MerchantSchema = z\n .object({\n id: z.string().min(1),\n name: z.string().min(1),\n publicBaseUrl: z.string().min(1),\n })\n .strict();\n\nconst ServerSchema = z\n .object({\n port: NumberOrString,\n host: z.string().min(1),\n /** Shared secret gating /api/receipts, /api/events, /api/events/stream. No token -> those routes 404. */\n adminToken: z.string().min(1).optional(),\n /** Browser origins allowed to read the dashboard-facing routes. Empty by default: closed. */\n // Entries are matched literally against the browser's\n // `Origin` header, so `\"*\"` and a trailing slash match nothing at all —\n // fail-closed (a lockout, not a bypass), but silently, and a lockout with\n // no explanation is the kind of thing an operator \"fixes\" by disabling the\n // check. Reject those two shapes with a pointer instead.\n allowedOrigins: z\n .array(\n z\n .string()\n .min(1)\n .refine((origin) => origin !== '*', {\n message:\n 'wildcard \"*\" is not supported — allowedOrigins entries are matched literally against the browser\\'s Origin header, so \"*\" would match nothing. List each scheme://host[:port] explicitly.',\n })\n .refine((origin) => !origin.endsWith('/'), {\n message:\n 'must not end with \"/\" — a browser Origin header never has a trailing slash, so this entry would match nothing. Use e.g. \"http://localhost:5173\".',\n }),\n )\n .optional(),\n })\n .strict();\n\nconst StorageSchema = z\n .object({\n receipts: z\n .object({\n driver: z.literal('sqlite'),\n path: z.string().min(1),\n })\n .strict(),\n })\n .strict();\n\n/**\n * Every path the gateway registers itself (`src/gateway/routes.ts`), plus the\n * fixed discovery paths adapters own. An adapter mount that equals one of\n * these makes Fastify's `.all()` a duplicate of the registered route; one that\n * is a path-prefix of them swallows their 404s through the mount's\n * `${mountPath}/*` wildcard.\n */\nconst RESERVED_GATEWAY_PATHS = [\n '/health',\n '/ready',\n '/.well-known/agent-commerce',\n // Fixed by the A2A specification, so it is the adapter's to serve and never\n // a configurable mount's to claim.\n '/.well-known/agent-card.json',\n '/api/resources',\n '/api/resources/:id/invoke',\n '/api/receipts',\n '/api/events',\n '/api/events/stream',\n] as const;\n\n/**\n * `mountPath` reaches Fastify as a route pattern, and a bad one throws inside\n * route registration — deferred to `server.ready()`, so `createGateway` fails\n * wholesale with an opaque `FST_ERR_*` instead of the adapter alone degrading.\n * Catching the shape here turns that into a CONFIG_INVALID naming the value.\n * Fastify pattern syntax (`:param`, `*`) is rejected rather than supported:\n * the mount registers its own wildcard, so a pattern here has no meaning.\n */\nconst MountPathSchema = z\n .string()\n .min(1)\n .refine((value) => value.startsWith('/'), {\n message: 'must start with \"/\" — it is an absolute gateway path, e.g. \"/mcp\".',\n })\n .refine((value) => !/[:*?\\s]/.test(value), {\n message:\n 'must not contain \":\", \"*\", \"?\" or whitespace — the mount is a literal path prefix, not a Fastify route pattern, and registers its own wildcard.',\n })\n .refine(\n (value) => {\n const base = value.replace(/\\/+$/, '');\n return !RESERVED_GATEWAY_PATHS.some(\n (reserved) => reserved === base || reserved.startsWith(`${base}/`),\n );\n },\n {\n message: `must not collide with a route the gateway already serves (${RESERVED_GATEWAY_PATHS.join(', ')}); pick a dedicated prefix such as \"/mcp\".`,\n },\n );\n\nconst ProtocolsSchema = z\n .object({\n http: z.object({ enabled: BooleanOrString }).strict(),\n mcp: z\n .object({\n enabled: BooleanOrString,\n mountPath: MountPathSchema,\n })\n .strict(),\n // Optional block: A2A is off unless an operator asks for it, and an\n // existing config predating the adapter stays valid.\n a2a: z\n .object({\n enabled: BooleanOrString,\n mountPath: MountPathSchema.optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\n/** Applied when `protocols.a2a` is absent or names no mount. */\nconst DEFAULT_A2A_MOUNT_PATH = '/a2a';\n\nconst BackendMethodSchema = z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);\n\nconst BackendHandlerSchema = z\n .object({\n type: z.literal('http'),\n method: BackendMethodSchema,\n url: z.string().min(1),\n headers: z.record(z.string(), z.string()).optional(),\n timeoutMs: NumberOrString.optional(),\n })\n .strict();\n\nconst PricingSchema = z.discriminatedUnion('type', [\n z.object({ type: z.literal('free') }).strict(),\n z\n .object({\n type: z.literal('fixed'),\n amount: z.string().min(1),\n currency: z.string().min(1),\n })\n .strict(),\n z\n .object({\n type: z.literal('dynamic'),\n resolver: z.string().min(1),\n })\n .strict(),\n]);\n\nconst JsonSchemaValueSchema: ZodTypeAny = z.record(z.string(), z.unknown());\n\nconst ResourceEntrySchema = z\n .object({\n name: z.string().min(1),\n description: z.string().optional(),\n input: JsonSchemaValueSchema.optional(),\n output: JsonSchemaValueSchema.optional(),\n backend: BackendHandlerSchema,\n pricing: PricingSchema,\n expose: z.array(z.string().min(1)).min(1),\n payments: z.array(z.string().min(1)).optional(),\n })\n .strict();\n\nconst ResourcesMapSchema = z.record(z.string().min(1), ResourceEntrySchema);\n\n/**\n * Facilitator credentials, kept generic on purpose: x402 facilitators are not\n * a single-vendor category, and an auth block shaped around one provider's\n * credentials would make the abstraction a fiction. A facilitator needing\n * per-request signed credentials is refused rather than sent nothing.\n */\nconst FacilitatorAuthSchema = z.discriminatedUnion('type', [\n z.object({ type: z.literal('none') }).strict(),\n z.object({ type: z.literal('bearer'), token: z.string().min(1) }).strict(),\n // Coinbase Developer Platform. Needs the optional peer `@coinbase/x402`,\n // which signs a fresh JWT per request; a static header cannot express it.\n z\n .object({\n type: z.literal('cdp'),\n apiKeyId: z.string().min(1),\n apiKeySecret: z.string().min(1),\n })\n .strict(),\n]);\n\nconst FacilitatorSchema = z.discriminatedUnion('mode', [\n z\n .object({\n mode: z.literal('local'),\n signerPrivateKey: z.string().min(1),\n })\n .strict(),\n z\n .object({\n mode: z.literal('remote'),\n url: z.string().min(1),\n // Absent means \"this facilitator takes no credential\" — an explicit\n // statement, normalised to `{ type: 'none' }` below. On a mainnet that\n // combination is refused outright, so the default can never quietly\n // become an unauthenticated production facilitator.\n auth: FacilitatorAuthSchema.optional(),\n })\n .strict(),\n]);\n\nconst X402Schema = z\n .object({\n enabled: BooleanOrString,\n network: z.string().min(1),\n rpcUrl: z.string().min(1),\n asset: z.string().min(1),\n assetName: z.string().min(1),\n assetVersion: z.string().min(1),\n assetDecimals: NumberOrString,\n payTo: z.string().min(1),\n maxTimeoutSeconds: NumberOrString,\n facilitator: FacilitatorSchema,\n /** Real funds. Never defaulted — see src/payments/x402/guardrails.ts. */\n allowMainnet: BooleanOrString.optional(),\n /** Accepts a mainnet facilitator that takes no credential. Never defaulted. */\n allowUnauthenticatedFacilitator: BooleanOrString.optional(),\n })\n .strict();\n\nconst PaymentsSchema = z\n .object({\n x402: X402Schema.optional(),\n })\n .strict();\n\nconst RawConfigSchema = z\n .object({\n version: z.literal(SUPPORTED_CONFIG_VERSION),\n merchant: MerchantSchema,\n server: ServerSchema,\n storage: StorageSchema,\n protocols: ProtocolsSchema,\n resources: ResourcesMapSchema,\n payments: PaymentsSchema,\n })\n .strict();\n\ntype RawConfig = z.infer<typeof RawConfigSchema>;\ntype RawResourceEntry = z.infer<typeof ResourceEntrySchema>;\n\n// ---------------------------------------------------------------------------\n// Public shape (docs/contracts.md — exact).\n// ---------------------------------------------------------------------------\n\nexport interface GatewayConfig {\n readonly version: 1;\n readonly merchant: { readonly id: string; readonly name: string; readonly publicBaseUrl: string };\n readonly server: {\n readonly port: number;\n readonly host: string;\n readonly adminToken?: string;\n readonly allowedOrigins: readonly string[];\n };\n readonly storage: { readonly receipts: { readonly driver: 'sqlite'; readonly path: string } };\n readonly protocols: {\n readonly http: { readonly enabled: boolean };\n readonly mcp: { readonly enabled: boolean; readonly mountPath: string };\n readonly a2a: { readonly enabled: boolean; readonly mountPath: string };\n };\n /** Canonical resources, already normalised. */\n readonly resources: readonly CommerceResource[];\n readonly payments: {\n readonly x402?: {\n readonly enabled: boolean;\n readonly network: string;\n readonly rpcUrl: string;\n readonly asset: string;\n readonly assetName: string;\n readonly assetVersion: string;\n readonly assetDecimals: number;\n readonly payTo: string;\n readonly maxTimeoutSeconds: number;\n readonly facilitator: X402FacilitatorConfig;\n readonly allowMainnet?: boolean;\n readonly allowUnauthenticatedFacilitator?: boolean;\n };\n };\n}\n\n// ---------------------------------------------------------------------------\n// Entry point\n// ---------------------------------------------------------------------------\n\nexport function parseConfig(raw: unknown, env: NodeJS.ProcessEnv): GatewayConfig {\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'Configuration root must be a mapping (object) at \"$\"',\n {\n details: { path: '$' },\n },\n );\n }\n\n checkVersion(raw as Record<string, unknown>);\n\n const substituted = substituteEnv(raw, env);\n const parsed = parseWithZod(RawConfigSchema, substituted);\n return normalise(parsed);\n}\n\nfunction checkVersion(raw: Record<string, unknown>): void {\n if (!('version' in raw)) {\n throw new CommerceError('CONFIG_INVALID', 'Configuration is missing required field \"version\"', {\n details: { path: 'version' },\n });\n }\n const rawVersion = raw['version'];\n const version = typeof rawVersion === 'string' ? Number(rawVersion) : rawVersion;\n if (version !== SUPPORTED_CONFIG_VERSION) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Unsupported config version \"${String(rawVersion)}\": this gateway only supports version ${SUPPORTED_CONFIG_VERSION}`,\n { details: { path: 'version', supported: SUPPORTED_CONFIG_VERSION } },\n );\n }\n}\n\nfunction parseWithZod<T>(schema: z.ZodType<T>, value: unknown): T {\n const result = schema.safeParse(value);\n if (!result.success) {\n throw zodErrorToConfigError(result.error);\n }\n return result.data;\n}\n\nfunction zodErrorToConfigError(error: ZodError): CommerceError {\n const issues = error.issues.map(describeIssue);\n const first = issues[0];\n const message = first\n ? `Configuration invalid at \"${first.path}\": ${first.message}`\n : 'Configuration invalid';\n return new CommerceError('CONFIG_INVALID', message, { details: { issues } });\n}\n\nfunction describeIssue(issue: ZodIssue): { path: string; message: string; code: string } {\n const path = issue.path.length > 0 ? issue.path.join('.') : '$';\n return { path, message: issue.message, code: issue.code };\n}\n\n// ---------------------------------------------------------------------------\n// Numeric / boolean coercion (explicit, not via Zod — see file header).\n// ---------------------------------------------------------------------------\n\nfunction toNumber(\n value: number | string,\n path: string,\n bounds: { min?: number; max?: number } = {},\n): number {\n // `Number('')` is 0 — finite, integral, and inside\n // `server.port`'s deliberate `min: 0` (\"let the OS pick\"). So `port: ${PORT:-}`\n // or an exported-but-empty PORT validated PASS and the gateway bound a random\n // port, after which `doctor` derived `http://127.0.0.1:0`, failed to connect,\n // and reported the gateway unreachable while it was serving. `Number` also\n // accepts `\"0x50\"` (80) and `\"1e3\"` (1000) for fields that are decimal\n // integers everywhere they are documented. Require plain digits instead.\n if (typeof value === 'string' && !/^\\s*\\d+\\s*$/.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be an integer written in decimal digits (got ${value === '' ? 'an empty string' : `\"${value}\"`})`,\n { details: { path } },\n );\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n) || !Number.isInteger(n)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be an integer`,\n {\n details: { path },\n },\n );\n }\n if (bounds.min !== undefined && n < bounds.min) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be >= ${bounds.min}`,\n {\n details: { path },\n },\n );\n }\n if (bounds.max !== undefined && n > bounds.max) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be <= ${bounds.max}`,\n {\n details: { path },\n },\n );\n }\n return n;\n}\n\nfunction toBoolean(value: boolean | string, path: string): boolean {\n if (typeof value === 'boolean') return value;\n const normalized = value.trim().toLowerCase();\n if (normalized === 'true') return true;\n if (normalized === 'false') return false;\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be a boolean (\"true\" or \"false\")`,\n { details: { path } },\n );\n}\n\n// ---------------------------------------------------------------------------\n// Business-rule validation + normalisation into the canonical shape.\n// ---------------------------------------------------------------------------\n\nconst SUPPORTED_PROTOCOLS = new Set(['http', 'mcp', 'a2a']);\nconst SUPPORTED_PAYMENT_METHODS = new Set(['x402']);\n\nfunction normalise(raw: RawConfig): GatewayConfig {\n const protocols = {\n http: { enabled: toBoolean(raw.protocols.http.enabled, 'protocols.http.enabled') },\n mcp: {\n enabled: toBoolean(raw.protocols.mcp.enabled, 'protocols.mcp.enabled'),\n mountPath: raw.protocols.mcp.mountPath,\n },\n a2a: {\n enabled: toBoolean(raw.protocols.a2a?.enabled ?? false, 'protocols.a2a.enabled'),\n mountPath: raw.protocols.a2a?.mountPath ?? DEFAULT_A2A_MOUNT_PATH,\n },\n };\n validateMountPaths(protocols);\n\n const x402Raw = raw.payments.x402;\n const facilitator: X402FacilitatorConfig | undefined =\n x402Raw === undefined\n ? undefined\n : x402Raw.facilitator.mode === 'local'\n ? { mode: 'local', signerPrivateKey: x402Raw.facilitator.signerPrivateKey }\n : {\n mode: 'remote',\n url: x402Raw.facilitator.url,\n auth: x402Raw.facilitator.auth ?? { type: 'none' },\n };\n const x402 =\n x402Raw && facilitator\n ? {\n enabled: toBoolean(x402Raw.enabled, 'payments.x402.enabled'),\n network: x402Raw.network,\n rpcUrl: x402Raw.rpcUrl,\n asset: x402Raw.asset,\n assetName: x402Raw.assetName,\n assetVersion: x402Raw.assetVersion,\n assetDecimals: toNumber(x402Raw.assetDecimals, 'payments.x402.assetDecimals', {\n min: 0,\n max: 36,\n }),\n payTo: x402Raw.payTo,\n maxTimeoutSeconds: toNumber(\n x402Raw.maxTimeoutSeconds,\n 'payments.x402.maxTimeoutSeconds',\n {\n min: 1,\n },\n ),\n facilitator,\n ...(x402Raw.allowMainnet !== undefined\n ? { allowMainnet: toBoolean(x402Raw.allowMainnet, 'payments.x402.allowMainnet') }\n : {}),\n ...(x402Raw.allowUnauthenticatedFacilitator !== undefined\n ? {\n allowUnauthenticatedFacilitator: toBoolean(\n x402Raw.allowUnauthenticatedFacilitator,\n 'payments.x402.allowUnauthenticatedFacilitator',\n ),\n }\n : {}),\n }\n : undefined;\n\n if (x402) {\n validateAddress('payments.x402.payTo', x402.payTo);\n validateAddress('payments.x402.asset', x402.asset);\n // The same call the provider makes at construction, run here so\n // `agent-commerce validate` reports an unsafe deployment where an operator\n // expects to hear about it, rather than at first boot.\n resolveX402Deployment({\n network: x402.network,\n payTo: x402.payTo,\n asset: x402.asset,\n assetName: x402.assetName,\n assetVersion: x402.assetVersion,\n facilitator: x402.facilitator,\n ...(x402.allowMainnet !== undefined ? { allowMainnet: x402.allowMainnet } : {}),\n ...(x402.allowUnauthenticatedFacilitator !== undefined\n ? { allowUnauthenticatedFacilitator: x402.allowUnauthenticatedFacilitator }\n : {}),\n });\n }\n\n const resources = Object.entries(raw.resources).map(([id, entry]) =>\n normaliseResource(id, entry, protocols, x402),\n );\n\n return {\n version: SUPPORTED_CONFIG_VERSION,\n merchant: {\n id: raw.merchant.id,\n name: raw.merchant.name,\n publicBaseUrl: raw.merchant.publicBaseUrl,\n },\n // min 0, not 1: port 0 is the standard \"let the OS pick a free port\"\n // convention, useful for tests and ephemeral dev/demo instances.\n server: {\n port: toNumber(raw.server.port, 'server.port', { min: 0, max: 65535 }),\n host: raw.server.host,\n ...(raw.server.adminToken !== undefined ? { adminToken: raw.server.adminToken } : {}),\n allowedOrigins: raw.server.allowedOrigins ?? [],\n },\n storage: { receipts: { driver: 'sqlite', path: raw.storage.receipts.path } },\n protocols,\n resources,\n payments: {\n ...(x402 !== undefined ? { x402 } : {}),\n },\n };\n}\n\ninterface NormalisedProtocols {\n readonly http: { readonly enabled: boolean };\n readonly mcp: { readonly enabled: boolean; readonly mountPath: string };\n readonly a2a: { readonly enabled: boolean; readonly mountPath: string };\n}\n\n/**\n * Two enabled mounts may not overlap: each registers a `${mountPath}/*`\n * wildcard, so a shared prefix means one adapter silently answers for the\n * other. Disabled protocols mount nothing and are not compared.\n */\nfunction validateMountPaths(protocols: NormalisedProtocols): void {\n const mounts = (\n [\n ['mcp', protocols.mcp],\n ['a2a', protocols.a2a],\n ] as const\n ).filter(([, p]) => p.enabled);\n\n for (const [index, [nameA, a]] of mounts.entries()) {\n for (const [nameB, b] of mounts.slice(index + 1)) {\n const baseA = a.mountPath.replace(/\\/+$/, '');\n const baseB = b.mountPath.replace(/\\/+$/, '');\n if (baseA === baseB || baseA.startsWith(`${baseB}/`) || baseB.startsWith(`${baseA}/`)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `protocols.${nameA}.mountPath (\"${a.mountPath}\") collides with protocols.${nameB}.mountPath (\"${b.mountPath}\") — each mount registers a wildcard, so overlapping prefixes cannot both be served`,\n { details: { path: `protocols.${nameA}.mountPath` } },\n );\n }\n }\n }\n}\n\ninterface NormalisedX402 {\n readonly enabled: boolean;\n readonly assetDecimals: number;\n}\n\nfunction normaliseResource(\n id: string,\n entry: RawResourceEntry,\n protocols: NormalisedProtocols,\n x402: NormalisedX402 | undefined,\n): CommerceResource {\n if (entry.input !== undefined) validateResourceSchemaKeywords(id, 'input', entry.input);\n\n const inputProperties = entry.input?.['properties'];\n if (\n inputProperties &&\n typeof inputProperties === 'object' &&\n PAYMENT_INPUT_FIELD in inputProperties\n ) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" declares an input property \"${PAYMENT_INPUT_FIELD}\", which is reserved for payment proofs`,\n {\n details: {\n path: `resources.${id}.input.properties.${PAYMENT_INPUT_FIELD}`,\n resourceId: id,\n },\n },\n );\n }\n\n for (const protocol of entry.expose) {\n if (!SUPPORTED_PROTOCOLS.has(protocol)) {\n const hint = protocol === 'ucp' ? ' (UCP is planned, not supported in this release)' : '';\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" exposes unsupported protocol \"${protocol}\"${hint}. Supported: http, mcp, a2a.`,\n { details: { path: `resources.${id}.expose`, resourceId: id, protocol } },\n );\n }\n }\n if (entry.expose.includes('mcp')) {\n if (!protocols.mcp.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"mcp\" but protocols.mcp.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n if (!MCP_TOOL_NAME_PATTERN.test(id)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"mcp\" but its id is not a legal MCP tool name (allowed: A-Z, a-z, 0-9, \"_\", \"-\", \".\", 1-128 chars)`,\n { details: { path: `resources.${id}`, resourceId: id } },\n );\n }\n }\n if (entry.expose.includes('a2a') && !protocols.a2a.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"a2a\" but protocols.a2a.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n if (entry.expose.includes('http') && !protocols.http.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"http\" but protocols.http.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n\n validateBackendUrl(id, entry.backend.url);\n validatePathParametersDeclared(id, entry.backend.url, entry.input);\n\n if (entry.pricing.type === 'dynamic') {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" uses pricing.type \"dynamic\", which is not supported in this release`,\n { details: { path: `resources.${id}.pricing.type`, resourceId: id } },\n );\n }\n\n if (entry.pricing.type === 'fixed') {\n validatePricingAmount(id, entry.pricing.amount, x402);\n }\n\n const paymentMethods = entry.payments ?? [];\n\n if (entry.pricing.type === 'fixed') {\n if (paymentMethods.length === 0) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has fixed pricing but declares no \"payments\" (a paid resource must name at least one payment method)`,\n { details: { path: `resources.${id}.payments`, resourceId: id } },\n );\n }\n for (const method of paymentMethods) {\n if (!SUPPORTED_PAYMENT_METHODS.has(method)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" names unsupported payment method \"${method}\". Supported: x402.`,\n { details: { path: `resources.${id}.payments`, resourceId: id, method } },\n );\n }\n if (method === 'x402' && (!x402 || !x402.enabled)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" names payment method \"x402\" which is not configured or not enabled under payments.x402`,\n { details: { path: `resources.${id}.payments`, resourceId: id, method } },\n );\n }\n }\n }\n\n const pricing: Pricing =\n entry.pricing.type === 'free'\n ? { type: 'free' }\n : { type: 'fixed', amount: entry.pricing.amount, currency: entry.pricing.currency };\n\n return {\n id,\n name: entry.name,\n ...(entry.description !== undefined ? { description: entry.description } : {}),\n inputSchema:\n entry.input !== undefined\n ? defaultClosedObjectSchema(entry.input)\n : EMPTY_CLOSED_OBJECT_SCHEMA,\n ...(entry.output !== undefined ? { outputSchema: entry.output } : {}),\n handler: {\n type: 'http',\n method: entry.backend.method,\n url: entry.backend.url,\n ...(entry.backend.headers !== undefined ? { headers: entry.backend.headers } : {}),\n ...(entry.backend.timeoutMs !== undefined\n ? {\n timeoutMs: toNumber(entry.backend.timeoutMs, `resources.${id}.backend.timeoutMs`, {\n min: 1,\n }),\n }\n : {}),\n },\n pricing,\n exposedVia: entry.expose as CommerceResource['exposedVia'],\n paymentMethods: paymentMethods as CommerceResource['paymentMethods'],\n };\n}\n\n/**\n * `{param}` templates (e.g. `.../weather/{city}`) parse fine as a URL — the\n * WHATWG parser just percent-encodes the braces — so this only rejects\n * genuinely malformed strings and non-http(s) schemes, not templating.\n */\n/**\n * Permissive-by-default is the wrong default for a value forwarded to\n * someone else's API: an object schema that\n * omits `additionalProperties` defaults, per JSON Schema itself, to\n * \"anything goes\" — so default it to `false` here instead, unless the\n * operator set it explicitly (including explicitly to `true`, which is\n * respected).\n *\n * An earlier fix only stamped the ROOT schema, so\n * `filter: { type: object }` *looked* closed (the top level really was)\n * while every key one level down under `properties.filter` still passed\n * verbatim — `core`'s validator (execution/validation.ts) only enforces\n * `additionalProperties` where the schema states it explicitly, at every\n * level independently. Recurse into `properties` and `items` the same way\n * `validateResourceSchemaKeywords` below already does, so \"closed\" actually\n * means closed at every depth, not just the one an operator happened to\n * write `additionalProperties: false` on.\n *\n * `type` can be an array (`[\"object\",\"null\"]`, valid JSON\n * Schema) — a bare `=== 'object'` string comparison missed it, so a schema\n * in that shape got stamped as open. `declaresObjectType` below is the same\n * check `core`'s validator now makes (`execution/validation.ts`'s\n * `isObjectSchemaNode`) so the two stay in agreement.\n */\nfunction defaultClosedObjectSchema(schema: Record<string, unknown>): Record<string, unknown> {\n // imported, never re-implemented. The local predicate this\n // replaces recognised `type`/`properties` but not `required`, while core's\n // validator recognised `properties`/`required` — so `input: { required: [q] }`\n // was an object to the validator and not to the stamper, and every unknown\n // key sailed through to the merchant backend. One definition, one drift.\n const isObjectSchema = isObjectSchemaNode(schema);\n const result: Record<string, unknown> = { ...schema };\n\n if (isObjectSchema) {\n const properties = schema['properties'];\n if (isPlainObject(properties)) {\n result['properties'] = Object.fromEntries(\n Object.entries(properties).map(([key, sub]) => [\n key,\n isPlainObject(sub) ? defaultClosedObjectSchema(sub) : sub,\n ]),\n );\n }\n if (!Object.hasOwn(schema, 'additionalProperties')) {\n result['additionalProperties'] = false;\n }\n }\n\n const items = schema['items'];\n if (isPlainObject(items)) {\n result['items'] = defaultClosedObjectSchema(items);\n }\n\n // The third place this stamper drifted from the validator, after `required`\n // and tuple `items`. `additionalProperties: {schema}` is the idiomatic\n // \"map of typed objects\" shape, and core's validator applies that subschema\n // recursively at unbounded depth — so without this branch, every node under\n // it stayed open and unknown keys reached the merchant backend. Recursion\n // here is not conditional on `isObjectSchema`: the validator applies the\n // subschema wherever it finds one.\n const additional = schema['additionalProperties'];\n if (isPlainObject(additional)) {\n result['additionalProperties'] = defaultClosedObjectSchema(additional);\n }\n\n return result;\n}\n\n/**\n * A resource that declares no `input:` at all got\n * `inputSchema: undefined`, and `compileJsonSchema(undefined)` is an\n * always-valid validator — every caller key was forwarded to the merchant\n * backend verbatim. The decision: default \"declared nothing\" to \"accepts\n * nothing\" (an empty closed object) rather than rejecting the config at load\n * time — a no-argument resource that omits `input:` is a legitimate shape,\n * and rejecting it would break every existing config that uses it.\n */\nconst EMPTY_CLOSED_OBJECT_SCHEMA: Record<string, unknown> = {\n type: 'object',\n properties: {},\n additionalProperties: false,\n};\n\n/**\n * `src/core`'s validator only enforces the subset documented in\n * `execution/validation.ts` (type/properties/required/additionalProperties/\n * enum/items) — everything else (`pattern`, `minLength`, `format`, `oneOf`,\n * …) is silently ignored at runtime. An operator who writes `pattern` and\n * never sees it enforced has no way to know that from the config alone, so\n * warn at load time instead of letting them find out the hard way.\n */\nconst UNSUPPORTED_SCHEMA_KEYWORDS = [\n 'pattern',\n 'minLength',\n 'maxLength',\n 'format',\n 'minimum',\n 'maximum',\n 'exclusiveMinimum',\n 'exclusiveMaximum',\n 'multipleOf',\n 'oneOf',\n 'anyOf',\n 'allOf',\n 'not',\n '$ref',\n 'const',\n 'patternProperties',\n 'minItems',\n 'maxItems',\n 'uniqueItems',\n];\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** `type` explicitly set to something that rules out \"object\" (a bare\n * value, or an array not containing \"object\"). `undefined` — no `type` at\n * all — is deliberately NOT treated as excluding: core's validator treats\n * `properties`/`required` with no `type` as an object schema, so that shape\n * is fine, not another instance of this bug. */\nfunction excludesObjectType(schema: Record<string, unknown>): boolean {\n const type = schema['type'];\n if (type === undefined || type === 'object') return false;\n if (Array.isArray(type)) return !type.includes('object');\n return true;\n}\n\n/**\n * Walks a resource's input schema once, both warning (existing, unenforced\n * keywords) and rejecting (a node whose declared `type`\n * cannot structurally be an object, yet which still carries `properties` or\n * `required`). The `properties`/`required`-with-no-`type` shape is not\n * this function's problem any more, since the\n * validator now treats that shape as an object; what's still a trap is a\n * `type` that actively rules \"object\" out while `properties`/`required`\n * imply it was meant to be one, e.g. a copy-pasted sibling schema whose\n * `type` was never updated. Rejecting (not just warning) here is the\n * decision — a warning is exactly what let this bug class ship silently in\n * the first place (`validate`/`doctor` both said PASS).\n */\nfunction validateResourceSchemaKeywords(\n id: string,\n path: string,\n schema: Record<string, unknown>,\n): void {\n for (const keyword of UNSUPPORTED_SCHEMA_KEYWORDS) {\n if (Object.hasOwn(schema, keyword)) {\n // eslint-disable-next-line no-console\n console.warn(\n `[agent-commerce] resource \"${id}\" ${path} uses JSON Schema keyword \"${keyword}\", which this gateway does not enforce (see src/core/execution/validation.ts for the supported subset). Remove it or treat it as documentation only.`,\n );\n }\n }\n if (\n (Object.hasOwn(schema, 'properties') || Object.hasOwn(schema, 'required')) &&\n excludesObjectType(schema)\n ) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" ${path} declares \"properties\" and/or \"required\" but its \"type\" (${JSON.stringify(schema['type'])}) does not include \"object\" — the validator will never route a value through either check under that type, so this schema claims to constrain input it does not actually enforce. Remove \"properties\"/\"required\", or include \"object\" in \"type\".`,\n { details: { path: `resources.${id}.${path}`, resourceId: id } },\n );\n }\n // the other half. Closing a `required`-only node is\n // correct JSON Schema and quietly unsatisfiable: `required: [\"q\"]` demands a\n // property that `properties` never declares, so the stamped\n // `additionalProperties: false` rejects `q` as an unknown key — the schema\n // can never be satisfied by any input at all. Fail-closed, so no money is at\n // risk, but every call would 400 with a config that loaded cleanly. Say so\n // at load instead. Only when the node really will be closed: an explicit\n // `additionalProperties` other than `false` leaves the name reachable.\n const requiredRaw = schema['required'];\n const closed = !Object.hasOwn(schema, 'additionalProperties')\n ? true\n : schema['additionalProperties'] === false;\n if (Array.isArray(requiredRaw) && closed && isObjectSchemaNode(schema)) {\n const declared = isPlainObject(schema['properties']) ? schema['properties'] : {};\n const undeclared = requiredRaw.filter(\n (name): name is string => typeof name === 'string' && !Object.hasOwn(declared, name),\n );\n if (undeclared.length > 0) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" ${path} lists ${undeclared.map((n) => `\"${n}\"`).join(', ')} in \"required\" but does not declare ${undeclared.length === 1 ? 'it' : 'them'} in \"properties\". The schema is closed (additionalProperties: false), so ${undeclared.length === 1 ? 'that name is' : 'those names are'} rejected as an unknown key and no input can ever satisfy this schema. Declare ${undeclared.length === 1 ? 'it' : 'them'} in \"properties\".`,\n { details: { path: `resources.${id}.${path}`, resourceId: id, undeclared } },\n );\n }\n }\n\n const properties = schema['properties'];\n if (isPlainObject(properties)) {\n for (const [key, sub] of Object.entries(properties)) {\n if (isPlainObject(sub)) validateResourceSchemaKeywords(id, `${path}.properties.${key}`, sub);\n }\n }\n const additional = schema['additionalProperties'];\n if (isPlainObject(additional)) {\n validateResourceSchemaKeywords(id, `${path}.additionalProperties`, additional);\n }\n const items = schema['items'];\n if (isPlainObject(items)) {\n validateResourceSchemaKeywords(id, `${path}.items`, items);\n } else if (Array.isArray(items)) {\n // tuple-form `items` (an array of per-position\n // schemas) is valid JSON Schema, but `core`'s validator only supports\n // the single-schema form applied to every element — a tuple silently\n // enforces nothing, invisibly rather than wrongly, so warn the same way\n // an unsupported keyword does.\n // eslint-disable-next-line no-console\n console.warn(\n `[agent-commerce] resource \"${id}\" ${path}.items is a tuple (an array of schemas), which this gateway does not enforce — only a single schema applied to every array element is supported (see src/core/execution/validation.ts). Each position's schema is unenforced; treat it as documentation only.`,\n );\n }\n}\n\n/**\n * `amount: z.string().min(1)` alone let \"0,01\", \"$0.01\", \"1e-2\", \"-1\" and an\n * over-precise \"0.0000001\" all pass config + `doctor`, then throw on every\n * purchase. A plain\n * positive decimal only — no currency symbol, no thousands separator, no\n * exponent notation.\n */\nconst PRICING_AMOUNT_PATTERN = /^\\d+(?:\\.\\d+)?$/;\nconst ZERO_AMOUNT_PATTERN = /^0(?:\\.0+)?$/;\n\nfunction validatePricingAmount(id: string, amount: string, x402: NormalisedX402 | undefined): void {\n const path = `resources.${id}.pricing.amount`;\n if (!PRICING_AMOUNT_PATTERN.test(amount)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"${amount}\", which is not a plain positive decimal (no currency symbol, no thousands separator, no exponent — e.g. \"0.01\")`,\n { details: { path, resourceId: id } },\n );\n }\n if (ZERO_AMOUNT_PATTERN.test(amount)) {\n // A zero-priced \"paid\" resource settles a zero-value transfer, which is\n // nonsense — if something is free, it should say so.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"0\" — a paid resource cannot cost zero; use \"pricing: { type: free }\" instead`,\n { details: { path, resourceId: id } },\n );\n }\n if (x402 !== undefined) {\n const fractionalDigits = amount.includes('.') ? (amount.split('.')[1]?.length ?? 0) : 0;\n if (fractionalDigits > x402.assetDecimals) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"${amount}\" with more precision (${fractionalDigits} fractional digits) than the configured asset supports (${x402.assetDecimals} decimals)`,\n { details: { path, resourceId: id } },\n );\n }\n }\n}\n\n/**\n * The root-cause half. `validateBackendRequestShape`\n * (src/core) rejects a missing path parameter at request time — after\n * schema validation but, without this check, on every single call, because\n * a schema that never declares `{city}` can never satisfy it. A paid\n * resource in that shape settles the buyer's payment and then always fails\n * to reach the backend: no refund, replay key burned, on every call, not an\n * unlucky one. Every `{param}` in `backend.url` must be BOTH declared in\n * `properties` AND listed in `required` — an optional value hits the exact\n * same \"caller structurally cannot supply it on every call that omits it\"\n * problem as an undeclared one, just less often. This is the config-load\n * gate `agent-commerce validate`/`doctor` catch it at; the runtime\n * `INPUT_INVALID` in `validateBackendRequestShape` is defence in depth for\n * a hand-built `CommerceResource` this check never saw.\n */\nfunction validatePathParametersDeclared(\n id: string,\n url: string,\n input: Record<string, unknown> | undefined,\n): void {\n // Before anything else: a brace token the canonical grammar does not\n // recognise is neither extracted here nor substituted at request time, so it\n // would travel to the backend as a percent-encoded literal. On a paid\n // resource that is payment-without-delivery on every single call. Refuse it\n // at load rather than letting \"matches nothing\" mean \"nothing to check\".\n const stray = findUnparsedBraceToken(url);\n if (stray !== undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url containing \"${stray}\", which is not a valid path parameter (allowed characters: A-Z a-z 0-9 _ . -). It would be sent to the backend literally, so a paid resource would settle payment and then never reach the backend`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id, token: stray } },\n );\n }\n\n const params = extractPathParameterNames(url);\n if (params.length === 0) return;\n\n // Every defence around `{param}` guards the *path* position, and in the host\n // position all of them fail open at once: `new URL('http://{host}/api')`\n // parses (the hostname is literally `{host}`) so the URL check passes; the\n // runtime containment check is skipped because its literal prefix\n // (`http://`) does not itself parse as a URL; and `encodeURIComponent` does\n // not escape dots, so a hostname survives it whole. Caller input then chooses\n // which host the gateway calls — the metadata service, an internal address,\n // anything. `http://{region}.api.internal/...` is an ordinary-looking\n // multi-tenant template, so this is refused here rather than warned about.\n //\n // The rule: everything before the first `{` must already be a complete\n // authority — a parseable origin followed by the path's leading `/`.\n const firstBrace = url.indexOf('{');\n if (firstBrace !== -1) {\n const prefix = url.slice(0, firstBrace);\n let origin: string | undefined;\n try {\n const parsedPrefix = new URL(prefix);\n origin = parsedPrefix.hostname === '' ? undefined : parsedPrefix.origin;\n } catch {\n // Not a URL at all — the parameter starts before the authority is done.\n }\n if (origin === undefined || !prefix.startsWith(`${origin}/`)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has a backend.url parameter before the end of the host (\"${url}\"). A caller-supplied value would choose which host the gateway calls, which is request forgery with the gateway's own network position. Parameters are supported inside the path and query only`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n }\n\n const propertiesRaw = input?.['properties'];\n const properties = isPlainObject(propertiesRaw) ? propertiesRaw : {};\n const requiredRaw = input?.['required'];\n const required = new Set(\n Array.isArray(requiredRaw)\n ? requiredRaw.filter((entry): entry is string => typeof entry === 'string')\n : [],\n );\n\n for (const param of params) {\n const path = `resources.${id}.backend.url`;\n if (!Object.hasOwn(properties, param)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url path parameter \"{${param}}\" which is not declared in its input schema — the caller has no way to supply it, so every call would settle payment (if priced) and then fail to reach the backend`,\n { details: { path, resourceId: id, param } },\n );\n }\n if (!required.has(param)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url path parameter \"{${param}}\" declared in its input schema but not listed in \"required\" — a caller that omits it hits the same unservable-request problem as an undeclared parameter`,\n { details: { path, resourceId: id, param } },\n );\n }\n }\n}\n\nfunction validateBackendUrl(id: string, url: string): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has an invalid backend.url \"${url}\": must be an absolute http:// or https:// URL`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has a backend.url with scheme \"${parsed.protocol}\": must be http:// or https://`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n}\n\nfunction validateAddress(path: string, value: string): void {\n if (!ADDRESS_PATTERN.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" is not a plausible address (expected \"0x\" followed by 40 hex characters)`,\n { details: { path } },\n );\n }\n if (ZERO_ADDRESS_PATTERN.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must not be the zero address`,\n {\n details: { path },\n },\n );\n }\n}\n","/**\n * Locates and parses `config.yaml`, then hands the raw value to\n * `parseConfig`. Never trusts raw YAML before Zod validation.\n */\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { parse as parseYaml, YAMLError } from 'yaml';\nimport { CommerceError } from '../core/index.js';\nimport { DEFAULT_CONFIG_FILENAME } from './filename.js';\nimport { type GatewayConfig, parseConfig } from './schema.js';\n\nconst CONFIG_PATH_ENV_VAR = 'AGENT_COMMERCE_CONFIG';\n\nexport interface LoadConfigOptions {\n readonly path?: string;\n readonly env?: NodeJS.ProcessEnv;\n readonly cwd?: string;\n}\n\nexport async function loadConfig(options: LoadConfigOptions = {}): Promise<GatewayConfig> {\n const env = options.env ?? process.env;\n const cwd = options.cwd ?? process.cwd();\n const configPath = resolveConfigPath(options.path, env, cwd);\n\n let text: string;\n try {\n text = await fs.readFile(configPath, 'utf8');\n } catch (error) {\n throw new CommerceError('CONFIG_INVALID', `Could not read configuration file \"${configPath}\"`, {\n details: { path: configPath },\n cause: error,\n });\n }\n\n let raw: unknown;\n try {\n raw = parseYaml(text);\n } catch (error) {\n const { reason, details } = describeYamlError(error);\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration file \"${configPath}\" is not valid YAML: ${reason}`,\n {\n details: { path: configPath, ...details },\n // Retained for programmatic callers. Nothing in the CLI prints a\n // `cause`, and nothing should start: this is the object whose\n // `.message` carries the source excerpt (see below).\n cause: error,\n },\n );\n }\n\n return parseConfig(raw, env);\n}\n\n/**\n * A YAML failure described from the error's *structured* fields only.\n *\n * Deliberately not `error.message`: the `yaml` package builds that message\n * with a **code frame excerpt of the source line**, so a syntax error next to\n * an inline secret would reproduce it verbatim into `validate`/`doctor` output — including `doctor --json`, the output most\n * likely to be pasted into an issue or captured by CI:\n *\n * … is not valid YAML: Nested mappings are not allowed … at line 2, column 15:\n *\n * adminToken: super-secret-token-value\n * ^\n *\n * `server.adminToken` and `payments.x402.facilitator.signerPrivateKey` are\n * both legal as inline literals, so this was a real sink rather than a\n * hypothetical one — and it contradicted `validate`'s own promise never to\n * print a resolved value: it never printed a resolved `${ENV}`, only an\n * inlined one. `code` and `linePos` locate the fault exactly as well and\n * cannot contain file content.\n */\n/**\n * Plain-English phrasing for the codes an operator actually hits, so replacing\n * the excerpt does not also cost the diagnostic its readability. These are\n * fixed strings chosen here — they can never contain file content, which is\n * the entire property that matters. Anything unlisted degrades to the bare\n * code, which is still precise.\n */\nconst YAML_ERROR_EXPLANATIONS: Readonly<Record<string, string>> = {\n DUPLICATE_KEY: 'map keys must be unique',\n BAD_INDENT: 'bad indentation',\n TAB_AS_INDENT: 'tabs cannot be used for indentation',\n MISSING_CHAR: 'a required character is missing',\n BLOCK_AS_IMPLICIT_KEY: 'a block value cannot be used as a key (missing quotes, or a stray colon)',\n MULTILINE_IMPLICIT_KEY: 'a key spans multiple lines (missing quotes, or a stray colon)',\n UNEXPECTED_TOKEN: 'unexpected token',\n};\n\nfunction describeYamlError(error: unknown): {\n reason: string;\n details: Record<string, unknown>;\n} {\n if (!(error instanceof YAMLError)) {\n return { reason: 'unknown YAML parse error', details: {} };\n }\n const start = error.linePos?.[0];\n const where =\n start === undefined ? '' : ` at line ${String(start.line)}, column ${String(start.col)}`;\n const explanation = YAML_ERROR_EXPLANATIONS[error.code];\n const what = explanation === undefined ? error.code : `${error.code} (${explanation})`;\n return {\n reason: `${what}${where}`,\n details: {\n yamlErrorCode: error.code,\n ...(start === undefined ? {} : { line: start.line, column: start.col }),\n },\n };\n}\n\nfunction resolveConfigPath(\n explicitPath: string | undefined,\n env: NodeJS.ProcessEnv,\n cwd: string,\n): string {\n if (explicitPath) return path.resolve(cwd, explicitPath);\n const fromEnv = env[CONFIG_PATH_ENV_VAR];\n if (fromEnv) return path.resolve(cwd, fromEnv);\n return path.resolve(cwd, DEFAULT_CONFIG_FILENAME);\n}\n","/**\n * src/config\n *\n * `config.yaml` schema, loader and environment substitution.\n */\n\nexport { substituteEnv } from './env.js';\nexport type { LoadConfigOptions } from './load.js';\nexport { loadConfig } from './load.js';\nexport type { GatewayConfig } from './schema.js';\nexport { parseConfig } from './schema.js';\n","import { Command } from 'commander';\nimport { DEFAULT_CONFIG_FILENAME } from '../config/filename.js';\nimport { runDemo } from './commands/demo.js';\nimport { printDoctorReport, runDoctor } from './commands/doctor.js';\nimport { runInit } from './commands/init.js';\nimport { runValidate } from './commands/validate.js';\nimport { runVersion } from './commands/version.js';\nimport { type Io, processIo } from './lib/io.js';\nimport { readVersionReport } from './lib/versions.js';\n\n/**\n * Builds the `agent-commerce` Commander program.\n *\n * `io` is injectable so tests can capture output instead of writing to the\n * real process streams; `exitOverride()` + `configureOutput()` mean\n * `--help`/errors never call `process.exit()` directly, so a caller (index.ts\n * or a test) fully controls process lifecycle.\n */\nexport function buildProgram(io: Io = processIo): Command {\n const program = new Command();\n\n program\n .name('agent-commerce')\n .description('CLI for the Agent Commerce Gateway: init, validate, doctor, demo.')\n // `--version` is required of the published binary. The `version`\n // subcommand stays: it additionally prints the pinned protocol/SDK\n // versions, which is what `doctor` and the support matrix are checked\n // against. Both read the same source, so they cannot disagree.\n .version(readVersionReport().cliVersion, '-v, --version', 'Print the CLI version.')\n .exitOverride()\n .configureOutput({\n writeOut: (str) => io.stdout(str.replace(/\\n+$/, '')),\n writeErr: (str) => io.stderr(str.replace(/\\n+$/, '')),\n });\n\n program\n .command('version')\n .description('Print the CLI version and pinned protocol/SDK versions.')\n .action(() => {\n process.exitCode = runVersion(io);\n });\n\n program\n .command('validate')\n .description(`Validate ${DEFAULT_CONFIG_FILENAME} and exit non-zero if it is invalid.`)\n .option('--config <path>', `path to ${DEFAULT_CONFIG_FILENAME}`)\n .action(async (opts: { config?: string }) => {\n const code = await runValidate(\n opts.config !== undefined ? { configPath: opts.config } : {},\n io,\n );\n process.exitCode = code;\n });\n\n program\n .command('doctor')\n .description('Diagnose config, gateway, backend, protocol and payment health.')\n .option('--config <path>', `path to ${DEFAULT_CONFIG_FILENAME}`)\n .option(\n '--gateway <url>',\n 'gateway base URL (default: derived from config, else http://localhost:8080)',\n )\n .option('--json', 'emit machine-readable JSON instead of a formatted report', false)\n .action(async (opts: { config?: string; gateway?: string; json?: boolean }) => {\n const report = await runDoctor({\n ...(opts.config !== undefined ? { configPath: opts.config } : {}),\n ...(opts.gateway !== undefined ? { gatewayUrl: opts.gateway } : {}),\n });\n printDoctorReport(report, io, opts.json === true);\n process.exitCode = report.exitCode;\n });\n\n program\n .command('init')\n .description(`Interactively generate ${DEFAULT_CONFIG_FILENAME}.`)\n .option('--output <path>', 'output path', DEFAULT_CONFIG_FILENAME)\n .option('--force', 'overwrite an existing file', false)\n .option('--yes', 'use non-interactive defaults (required for scripting/tests)', false)\n .action(async (opts: { output: string; force: boolean; yes: boolean }) => {\n const code = await runInit({ outputPath: opts.output, force: opts.force, yes: opts.yes }, io);\n process.exitCode = code;\n });\n\n program\n .command('demo')\n .description(\n 'Run the documented docker compose + demo agent quickstart, verifying health between steps.',\n )\n .action(async () => {\n process.exitCode = await runDemo(io);\n });\n\n return program;\n}\n","/**\n * `agent-commerce demo` — a thin, honest wrapper around the documented\n * `docker compose up` + `npm run demo:agent` steps (README/ commands).\n *\n * No orchestration magic: each step's exit code is checked, and a failing\n * step is reported with exactly what failed and what to run to retry it, not\n * swallowed into a generic \"demo failed\" message.\n */\nimport type { Io } from '../lib/io.js';\n\nexport interface DemoStep {\n readonly name: string;\n readonly command: string;\n readonly args: readonly string[];\n /** Optional health check run after the step; returns true when healthy. */\n readonly healthCheck?: () => Promise<boolean>;\n}\n\nexport interface RunResult {\n readonly code: number;\n readonly stderrTail?: string;\n}\n\nexport type RunCommand = (command: string, args: readonly string[]) => Promise<RunResult>;\n\nexport interface DemoDeps {\n readonly run?: RunCommand;\n readonly steps?: readonly DemoStep[];\n}\n\nexport function defaultDemoSteps(): readonly DemoStep[] {\n return [\n {\n name: 'Start local chain + gateway + merchant (docker compose)',\n command: 'docker',\n args: ['compose', 'up', '--build', '-d'],\n },\n { name: 'Run the deterministic buyer agent', command: 'npm', args: ['run', 'demo:agent'] },\n ];\n}\n\n/** `agent-commerce demo`. Returns process exit code. */\nexport async function runDemo(io: Io, deps: DemoDeps = {}): Promise<number> {\n const steps = deps.steps ?? defaultDemoSteps();\n const run = deps.run ?? execCommand;\n\n io.stdout('agent-commerce demo — running the documented quickstart steps:');\n for (const step of steps) {\n io.stdout('');\n io.stdout(`==> ${step.name}`);\n io.stdout(` $ ${step.command} ${step.args.join(' ')}`);\n const result = await run(step.command, step.args);\n if (result.code !== 0) {\n io.stderr(`FAIL \"${step.name}\" exited with code ${result.code}.`);\n if (result.stderrTail !== undefined && result.stderrTail.length > 0) {\n io.stderr(result.stderrTail);\n }\n io.stderr('');\n io.stderr('Nothing further was run. To retry manually:');\n io.stderr(` ${step.command} ${step.args.join(' ')}`);\n return 1;\n }\n if (step.healthCheck !== undefined) {\n const healthy = await step.healthCheck();\n if (!healthy) {\n io.stderr(`FAIL \"${step.name}\" completed but its health check did not pass.`);\n return 1;\n }\n }\n io.stdout(`OK ${step.name}`);\n }\n io.stdout('');\n io.stdout('PASS Demo is up. Try: agent-commerce doctor --config config-demo.yaml');\n return 0;\n}\n\nasync function execCommand(command: string, args: readonly string[]): Promise<RunResult> {\n const { spawn } = await import('node:child_process');\n return new Promise((resolvePromise) => {\n let stderr = '';\n const child = spawn(command, args, { stdio: ['ignore', 'inherit', 'pipe'] });\n child.stderr?.on('data', (chunk: Buffer) => {\n stderr += chunk.toString('utf8');\n });\n child.on('error', (err) => {\n resolvePromise({ code: 1, stderrTail: err.message });\n });\n child.on('close', (code) => {\n const tail = stderr.trim().split('\\n').slice(-10).join('\\n');\n resolvePromise({ code: code ?? 1, ...(tail.length > 0 ? { stderrTail: tail } : {}) });\n });\n });\n}\n","import { existsSync } from 'node:fs';\nimport picocolors from 'picocolors';\nimport { extractPathParameterNames } from '../../core/execution/index.js';\nimport { type CommerceResource, isCommerceError, type ReceiptStore } from '../../core/index.js';\nimport {\n describeDeploymentMode,\n findNetworkProfile,\n resolveDeploymentMode,\n} from '../../payments/x402/networks.js';\n// Narrow modules, not the package barrel: the CLI must pull in no protocol\n// SDK, and these two are plain constants and strings.\nimport {\n A2A_AGENT_CARD_PATH,\n A2A_PROTOCOL_BINDING,\n A2A_PROTOCOL_VERSION,\n A2A_SPEC_VERSION,\n} from '../../protocols/a2a/constants.js';\nimport { A2A_UNSUPPORTED } from '../../protocols/a2a/descriptor.js';\nimport { createSqliteReceiptStore } from '../../storage/receipts/index.js';\nimport { type ConfigLoader, type GatewayConfig, loadConfigDynamic } from '../lib/config-client.js';\nimport { type FetchLike, fetchJson } from '../lib/http.js';\nimport { PLACEHOLDER_ASSET_ADDRESS } from '../lib/init-config.js';\nimport type { Io } from '../lib/io.js';\nimport {\n fillEnvFromLocalChainManifest,\n LOCAL_CHAIN_MANIFEST_PATH,\n MANIFEST_FILLABLE_ENV_VAR_NAMES,\n type ManifestEnvFill,\n} from '../lib/manifest-env.js';\nimport { maskMiddle } from '../lib/mask.js';\nimport { readVersionReport } from '../lib/versions.js';\n\nexport type CheckStatus = 'PASS' | 'WARN' | 'FAIL' | 'INFO';\n\nexport interface DoctorCheck {\n readonly name: string;\n readonly status: CheckStatus;\n readonly detail: string;\n}\n\nexport interface DoctorReport {\n readonly checks: readonly DoctorCheck[];\n readonly score: { readonly passed: number; readonly total: number };\n readonly exitCode: number;\n}\n\nexport interface DoctorOptions {\n readonly configPath?: string;\n readonly gatewayUrl?: string;\n}\n\nexport interface DoctorDeps {\n readonly fetchImpl?: FetchLike;\n readonly loadConfig?: ConfigLoader;\n readonly createStore?: (path: string) => ReceiptStore;\n readonly fillEnvFromManifest?: (env: NodeJS.ProcessEnv) => ManifestEnvFill;\n}\n\nconst CHECK_TIMEOUT_MS = 1500;\n\nfunction deriveGatewayUrl(explicit: string | undefined, config: GatewayConfig | undefined): string {\n if (explicit !== undefined) return explicit.replace(/\\/$/, '');\n if (config !== undefined) {\n // `0.0.0.0` means \"all interfaces\"; probe the loopback one. `::` is its\n // IPv6 equivalent. A literal IPv6 host such as `::1`\n // must be bracketed or the derived URL is invalid (`http://::1:8080`) and\n // doctor reported every running gateway as unreachable.\n const raw = config.server.host;\n const host = raw === '0.0.0.0' ? '127.0.0.1' : raw === '::' ? '::1' : raw;\n const authority = host.includes(':') ? `[${host}]` : host;\n return `http://${authority}:${config.server.port}`;\n }\n return 'http://localhost:8080';\n}\n\n/**\n * Fill `{param}` slots with a probe value, using the *canonical* grammar.\n *\n * A local `/\\{[^}]+\\}/g` here would recognise more than the runtime does. A\n * kebab-case token like `{report-id}` would match here and not there, so\n * `doctor` would probe `/report/demo-check` — the URL the operator meant —\n * and report the backend reachable, while every real request went to\n * `/report/%7Breport-id%7D` and 404'd after settling payment. A diagnostic\n * that probes a URL the runtime would never build is\n * worse than no diagnostic: it certifies the broken thing as healthy. Anything\n * the shared extractor does not recognise is deliberately left as-is, so the\n * probe hits exactly what the gateway would send.\n */\nfunction substitutePathParams(url: string): string {\n let filled = url;\n for (const name of extractPathParameterNames(url)) {\n filled = filled.split(`{${name}}`).join('demo-check');\n }\n return filled;\n}\n\ninterface LiveX402 {\n readonly asset: string;\n readonly network: string;\n readonly payTo: string;\n}\n\n/**\n * Pulls the gateway's *effective* x402 settlement config out of\n * `/.well-known/agent-commerce` (src/gateway/well-known.ts). Returns\n * undefined for anything short of \"the gateway confirms x402 is enabled and\n * reports all three fields\" — a doctor cross-check must never itself become\n * an unchecked cast on network-supplied JSON.\n */\n/**\n * `undefined` must not be allowed to mean three different things — gateway\n * down, document malformed, and *the gateway positively reporting x402\n * disabled*. The third is not an absence of information, it is a\n * disagreement: local config enables x402, the running gateway says it does\n * not, which is exactly the deployment-mismatch this cross-check was built to\n * catch. Reporting it as \"could not be verified\" turned the finding into a\n * shrug. `'disabled'` separates it out.\n */\ntype LiveX402Result = LiveX402 | 'disabled' | undefined;\n\nfunction extractWellKnownX402(body: Record<string, unknown> | undefined): LiveX402Result {\n const payments = body?.['payments'];\n if (typeof payments !== 'object' || payments === null) return undefined;\n const x402 = (payments as Record<string, unknown>)['x402'];\n if (typeof x402 !== 'object' || x402 === null) return undefined;\n const rec = x402 as Record<string, unknown>;\n // Only an explicit `false` is a positive statement. Anything else (absent,\n // null, a non-boolean) is still \"cannot tell\".\n if (rec['enabled'] === false) return 'disabled';\n if (rec['enabled'] !== true) return undefined;\n const { asset, network, payTo } = rec;\n if (typeof asset !== 'string' || typeof network !== 'string' || typeof payTo !== 'string') {\n return undefined;\n }\n return { asset, network, payTo };\n}\n\n/** Addresses are checksum-insensitive throughout this project (src/config/schema.ts). */\nfunction sameAddress(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\n/**\n * A doctor that reports healthy against a mismatched deployment is worse\n * than no diagnostic at all false-green finding). Compares\n * the gateway's live settlement config against what the local config\n * resolved to, and names both values so the operator knows exactly what to\n * check rather than just that something disagrees.\n */\nfunction findX402Mismatch(configured: LiveX402, live: LiveX402): string | undefined {\n const diffs: string[] = [];\n if (!sameAddress(configured.asset, live.asset)) {\n diffs.push(\n `asset: gateway is using ${live.asset} but local config resolves to ${configured.asset}`,\n );\n }\n if (configured.network !== live.network) {\n diffs.push(\n `network: gateway is using \"${live.network}\" but local config resolves to \"${configured.network}\"`,\n );\n }\n if (!sameAddress(configured.payTo, live.payTo)) {\n diffs.push(\n `payTo: gateway is using ${live.payTo} but local config resolves to ${configured.payTo}`,\n );\n }\n if (diffs.length === 0) return undefined;\n return `${diffs.join('; ')} — the gateway may be running against an older deployment; restart it or re-run chain:deploy`;\n}\n\n/** `agent-commerce doctor [--config] [--gateway] [--json]`. */\nexport async function runDoctor(\n options: DoctorOptions,\n deps: DoctorDeps = {},\n): Promise<DoctorReport> {\n const fetchImpl = deps.fetchImpl ?? globalThis.fetch;\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const createStore = deps.createStore ?? ((path: string) => createSqliteReceiptStore({ path }));\n const fillEnvFromManifest = deps.fillEnvFromManifest ?? fillEnvFromLocalChainManifest;\n\n const checks: DoctorCheck[] = [];\n let config: GatewayConfig | undefined;\n\n // 1. Config\n const { env, filled, manifestFound } = fillEnvFromManifest(process.env);\n const filledSuffix =\n filled.length > 0\n ? ` (using local chain manifest ${LOCAL_CHAIN_MANIFEST_PATH} for ${filled.join(', ')})`\n : '';\n try {\n config = await loadConfig({\n ...(options.configPath !== undefined ? { path: options.configPath } : {}),\n env,\n });\n checks.push({\n name: 'Config',\n status: 'PASS',\n detail: `valid — ${config.resources.length} resource(s), merchant \"${config.merchant.name}\"${filledSuffix}`,\n });\n } catch (err) {\n const variable = isCommerceError(err) ? err.details?.['variable'] : undefined;\n const hint =\n !manifestFound &&\n typeof variable === 'string' &&\n MANIFEST_FILLABLE_ENV_VAR_NAMES.has(variable)\n ? ` — run \"npm run chain:deploy\" (writes ${LOCAL_CHAIN_MANIFEST_PATH}, read automatically for local X402_*/MERCHANT_WALLET placeholders)`\n : '';\n checks.push({\n name: 'Config',\n status: 'FAIL',\n detail: `${err instanceof Error ? err.message : String(err)}${hint}`,\n });\n }\n\n const gatewayUrl = deriveGatewayUrl(options.gatewayUrl, config);\n\n // 2. Gateway\n const health = await fetchJson(fetchImpl, `${gatewayUrl}/health`, CHECK_TIMEOUT_MS);\n let gatewayUp = false;\n if (!health.ok) {\n checks.push({\n name: 'Gateway',\n status: 'FAIL',\n detail: `unreachable at ${gatewayUrl} (${health.error ?? `HTTP ${health.status}`})`,\n });\n } else {\n gatewayUp = true;\n const ready = await fetchJson(fetchImpl, `${gatewayUrl}/ready`, CHECK_TIMEOUT_MS);\n checks.push(\n ready.ok\n ? { name: 'Gateway', status: 'PASS', detail: `healthy and ready at ${gatewayUrl}` }\n : {\n name: 'Gateway',\n status: 'WARN',\n detail: `healthy but not ready at ${gatewayUrl} (${ready.error ?? `HTTP ${ready.status}`})`,\n },\n );\n }\n\n // 3. Backend(s)\n if (config === undefined) {\n checks.push({ name: 'Backend', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (config.resources.length === 0) {\n checks.push({ name: 'Backend', status: 'INFO', detail: 'no resources configured' });\n } else {\n const resources = config.resources as readonly CommerceResource[];\n const urls: string[] = [...new Set(resources.map((r) => substitutePathParams(r.handler.url)))];\n const results = await Promise.all(\n urls.map((url) => fetchJson(fetchImpl, url, CHECK_TIMEOUT_MS)),\n );\n const reachable = results.filter((r) => r.status !== 0).length;\n const status: CheckStatus =\n reachable === urls.length ? 'PASS' : reachable === 0 ? 'FAIL' : 'WARN';\n checks.push({\n name: 'Backend',\n status,\n detail: `${reachable}/${urls.length} backend host(s) reachable`,\n });\n }\n\n // 4. Well-known document (feeds Protocols + Protocol versions)\n const wellKnown = gatewayUp\n ? await fetchJson<Record<string, unknown>>(\n fetchImpl,\n `${gatewayUrl}/.well-known/agent-commerce`,\n CHECK_TIMEOUT_MS,\n )\n : undefined;\n\n // 5. Protocols\n if (config === undefined) {\n checks.push({ name: 'Protocols', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (wellKnown === undefined || !wellKnown.ok) {\n checks.push({ name: 'Protocols', status: 'FAIL', detail: 'well-known document unreachable' });\n } else {\n const mcpMountPath = config.protocols.mcp.enabled ? config.protocols.mcp.mountPath : undefined;\n const a2aMountPath = config.protocols.a2a.enabled ? config.protocols.a2a.mountPath : undefined;\n checks.push({\n name: 'Protocols',\n status: 'PASS',\n detail: `http=${config.protocols.http.enabled ? 'on' : 'off'} mcp=${config.protocols.mcp.enabled ? `on (${mcpMountPath})` : 'off'} a2a=${config.protocols.a2a.enabled ? `on (${a2aMountPath})` : 'off'}`,\n });\n }\n\n // 5b. A2A specifics. Reported from the pins rather than from the live\n // gateway so the spec revision, the negotiation version and the binding are\n // three separate, named values an operator can check against a client — the\n // first two look alike and are routinely conflated.\n if (config === undefined) {\n checks.push({ name: 'A2A', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (!config.protocols.a2a.enabled) {\n checks.push({ name: 'A2A', status: 'INFO', detail: 'disabled' });\n } else {\n checks.push({\n name: 'A2A',\n status: 'PASS',\n detail: `experimental · spec ${A2A_SPEC_VERSION} · protocol ${A2A_PROTOCOL_VERSION} · binding ${A2A_PROTOCOL_BINDING} · mount ${config.protocols.a2a.mountPath} · card ${A2A_AGENT_CARD_PATH}`,\n });\n // Listed in full, never summarised as a count: \"18 unsupported\" tells an\n // operator nothing about whether the one operation their client needs is\n // among them.\n checks.push({\n name: 'A2A unsupported',\n status: 'INFO',\n detail: A2A_UNSUPPORTED.join(', '),\n });\n }\n\n // 6. Payments\n const x402 = config?.payments.x402;\n if (x402 === undefined || !x402.enabled) {\n checks.push({ name: 'Payments', status: 'INFO', detail: 'x402 not configured' });\n } else {\n // The protocol version is named because chain id 84532 is shared with the\n // public Base Sepolia testnet: the *mode* is what says whether this\n // deployment settles on a local dev node or a public network, and nothing\n // here may be read as a claim about a public network on its own.\n //\n // A config whose network is unknown cannot reach here in normal operation\n // — `parseConfig` refuses it — so an absent profile means doctor is\n // reading a config some other loader produced. Say so rather than guess.\n const profile = findNetworkProfile(x402.network);\n const mode = profile ? resolveDeploymentMode(profile, x402.facilitator.mode) : undefined;\n // Naming the public network while in local mode would read as a claim to\n // be on it — the exact confusion the shared chain id creates. Local says\n // \"dev chain\"; only a remote facilitator earns the network's name.\n const where =\n profile === undefined || mode === undefined\n ? `unknown network ${x402.network}`\n : mode === 'local'\n ? `LOCAL dev chain (${x402.network}, chain id shared with ${profile.displayName})`\n : `${describeDeploymentMode(mode)} on ${profile.displayName} (${x402.network})`;\n const facilitatorDetail =\n x402.facilitator.mode === 'local' ? 'local' : `remote (auth=${x402.facilitator.auth.type})`;\n const summary = `x402 v2 (scheme=exact) enabled — ${where}, destination=${maskMiddle(x402.payTo)}, facilitator=${facilitatorDetail}`;\n const live = wellKnown?.ok ? extractWellKnownX402(wellKnown.body) : undefined;\n if (sameAddress(x402.asset, PLACEHOLDER_ASSET_ADDRESS)) {\n // `init --yes` writes this placeholder, and the\n // live cross-check compares config against the gateway's echo of the\n // same config — so everything matched and the report said 7/7 PASS on a\n // deployment where no paid call can ever succeed, because no token\n // contract exists at that address. Fail-closed holds and no funds are at\n // risk; the overstatement is the defect.\n checks.push({\n name: 'Payments',\n status: 'WARN',\n detail: `${summary}, but the asset is still the init placeholder ${maskMiddle(PLACEHOLDER_ASSET_ADDRESS)} — no token contract exists there, so every paid call will fail. Set payments.x402.asset (\\${X402_ASSET} is filled from .deploy/local.json by \"npm run chain:deploy\")`,\n });\n } else if (live === 'disabled') {\n // Verified, and it disagrees. Every paid call against this gateway will\n // be served free or refused, depending on the resource — either way the\n // deployment is not what this config describes.\n checks.push({\n name: 'Payments',\n status: 'FAIL',\n detail: `${summary}, but the gateway at ${gatewayUrl} reports x402 disabled — it is running a different configuration`,\n });\n } else if (live === undefined) {\n // Gateway unreachable, x402 not (yet) reported live, or the document\n // didn't parse as expected — can't judge a match either way, so this\n // is not a FAIL: a doctor that fails on things it cannot check is as\n // untrustworthy as one that passes on things it never checked.\n checks.push({\n name: 'Payments',\n status: 'INFO',\n detail: `${summary} (gateway's live settlement config could not be verified)`,\n });\n } else {\n const mismatch = findX402Mismatch(x402, live);\n checks.push(\n mismatch === undefined\n ? { name: 'Payments', status: 'PASS', detail: summary }\n : { name: 'Payments', status: 'FAIL', detail: mismatch },\n );\n }\n if (mode === 'mainnet') {\n // Reporting, not re-checking. Every one of these is refused at config\n // load (src/payments/x402/guardrails.ts), so a config that got this far\n // has already passed them — but an operator about to move real money\n // should be told which guarantees they are relying on, and see the\n // banner without having to read a log.\n // An unauthenticated mainnet facilitator is allowed, but only by name.\n // Saying so here is the point: the acknowledgement lives in a config\n // file someone wrote weeks ago, and this is where they look today.\n const unauthenticated =\n x402.facilitator.mode === 'remote' && x402.facilitator.auth.type === 'none';\n checks.push({\n name: 'Mainnet safety',\n status: unauthenticated ? 'WARN' : 'INFO',\n detail: unauthenticated\n ? `${describeDeploymentMode('mainnet')} — settling through a facilitator that takes no ` +\n 'credential, accepted via allowUnauthenticatedFacilitator. It sees every payment ' +\n 'authorisation you handle, with no account or terms behind it. Everything else is ' +\n 'enforced at config load: explicit allowMainnet opt-in, HTTPS, non-development ' +\n 'payTo, canonical asset. Payments are fail-closed.'\n : `${describeDeploymentMode('mainnet')} — enforced at config load: explicit allowMainnet ` +\n 'opt-in, remote facilitator over HTTPS with a credential, non-development payTo, ' +\n 'and the canonical asset for this network. Payments are fail-closed.',\n });\n }\n }\n checks.push({\n name: 'Payments (MPP)',\n status: 'INFO',\n detail: 'planned — not implemented in this release',\n });\n\n // 7. Storage\n if (config === undefined) {\n checks.push({ name: 'Storage', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (\n // Diagnose without creating: createSqliteReceiptStore mkdir+creates the\n // file, so calling it on a wrong path (a typo, or a container path read\n // from the host) silently produces a fresh empty database and a false\n // \"healthy, receipts=0\" PASS — a read-only command must not have this\n // side effect, and it shadows the real store's real receipts entirely.\n // `:memory:` never exists on disk by definition, so it always falls\n // through to the real open/health/count branch below, same as today.\n config.storage.receipts.path !== ':memory:' &&\n !existsSync(config.storage.receipts.path)\n ) {\n checks.push({\n name: 'Storage',\n status: 'WARN',\n detail:\n `no store exists yet at \"${config.storage.receipts.path}\" — it is created ` +\n 'automatically the first time the gateway starts. If the gateway is already ' +\n 'running, this path does not match the one it actually uses.',\n });\n } else {\n let store: ReceiptStore | undefined;\n try {\n store = createStore(config.storage.receipts.path);\n await store.init();\n const storeHealth = await store.health();\n let receiptCount: number | undefined;\n try {\n // Exact count, not a list length: listReceipts clamps to\n // MAX_LIST_LIMIT (500, a store-level invariant) so counting via the\n // list silently saturated at 500 forever.\n receiptCount = await store.countReceipts();\n } catch {\n receiptCount = undefined;\n }\n let undeliveredCount: number | undefined;\n try {\n // A paid-but-undelivered purchase looks identical to a successful\n // one everywhere else; this is what makes it visible to an operator\n // running doctor. Same signal the\n // dashboard's receipt table uses, so the two views cannot disagree.\n undeliveredCount = await store.countUndeliveredReceipts();\n } catch {\n undeliveredCount = undefined;\n }\n const status: CheckStatus =\n storeHealth.status === 'pass' ? 'PASS' : storeHealth.status === 'warn' ? 'WARN' : 'FAIL';\n const receiptsSuffix =\n receiptCount !== undefined\n ? `; receipts=${receiptCount}${undeliveredCount !== undefined && undeliveredCount > 0 ? ` (${undeliveredCount} undelivered)` : ''}`\n : '';\n checks.push({\n name: 'Storage',\n status,\n detail: `${storeHealth.detail ?? 'sqlite'}${receiptsSuffix}`,\n });\n } catch (err) {\n checks.push({\n name: 'Storage',\n status: 'FAIL',\n detail: err instanceof Error ? err.message : String(err),\n });\n } finally {\n await store?.close();\n }\n }\n\n // 8. Protocol versions\n if (wellKnown !== undefined && wellKnown.ok) {\n checks.push({\n name: 'Protocol versions',\n status: 'PASS',\n detail: 'reported by gateway /.well-known/agent-commerce',\n });\n } else {\n const local = readVersionReport();\n checks.push({\n name: 'Protocol versions',\n status: 'INFO',\n detail: `gateway unreachable — local pins: ${local.pinned.map((p) => `${p.name}@${p.version}`).join(', ')}`,\n });\n }\n\n const scored = checks.filter((c) => c.status !== 'INFO');\n const passed = scored.filter((c) => c.status === 'PASS').length;\n const exitCode = checks.some((c) => c.status === 'FAIL') ? 1 : 0;\n\n return { checks, score: { passed, total: scored.length }, exitCode };\n}\n\nfunction statusColor(status: CheckStatus, text: string): string {\n switch (status) {\n case 'PASS':\n return picocolors.green(text);\n case 'WARN':\n return picocolors.yellow(text);\n case 'FAIL':\n return picocolors.red(text);\n case 'INFO':\n return picocolors.cyan(text);\n }\n}\n\nexport function printDoctorReport(report: DoctorReport, io: Io, json: boolean): void {\n if (json) {\n io.stdout(JSON.stringify(report, null, 2));\n return;\n }\n for (const check of report.checks) {\n const label = statusColor(check.status, check.status.padEnd(5));\n io.stdout(`${label} ${check.name.padEnd(20)} ${check.detail}`);\n }\n io.stdout('');\n io.stdout(`Score: ${report.score.passed}/${report.score.total} checks passed`);\n}\n","/**\n * A2A pins, kept in one place so nothing infers one version from another.\n *\n * The specification revision and the protocol negotiation version are\n * different values that look similar: `1.0.0` names the document this adapter\n * was written against, `1.0` is what a client negotiates on the wire. Neither\n * is this package's version — that is `PACKAGE_VERSION`.\n */\n\n/** A2A specification revision this adapter targets. */\nexport const A2A_SPEC_VERSION = '1.0.0';\n\n/** Protocol negotiation version carried on the wire. */\nexport const A2A_PROTOCOL_VERSION = '1.0';\n\n/** The only transport binding this adapter serves. */\nexport const A2A_PROTOCOL_BINDING = 'JSONRPC';\n\n/**\n * Fixed by the A2A specification: a client fetches the card from this exact\n * path, so it is not configurable. `src/config` reserves it against adapter\n * mounts for the same reason.\n */\nexport const A2A_AGENT_CARD_PATH = '/.well-known/agent-card.json';\n\n/** Mount serving the JSON-RPC endpoint, unless configuration says otherwise. */\nexport const A2A_DEFAULT_MOUNT_PATH = '/a2a';\n\n/** Content type on both sides of every supported A2A exchange. */\nexport const A2A_JSON_MEDIA_TYPE = 'application/json';\n\n/** Card identity when the operator names none. Matches the MCP server name. */\nexport const A2A_DEFAULT_AGENT_NAME = 'agent-commerce';\n\n/**\n * Version negotiation header. A2A v1 carries the protocol version out of band,\n * so a request that omits it is a client speaking an older negotiation\n * convention — treated as unsupported rather than optimistically accepted.\n */\nexport const A2A_VERSION_HEADER = 'a2a-version';\n\n/** The one JSON-RPC method this adapter serves. Not the legacy `message/send`. */\nexport const A2A_METHOD_SEND_MESSAGE = 'SendMessage';\n\n/**\n * A2A methods that exist and are deliberately not served here. Kept apart from\n * unknown methods so a caller learns which of the two they hit: a real method\n * this deployment refuses, or a typo. One list, read by both the descriptor\n * and the transport — a second copy would drift the moment one gains a method.\n */\nexport const A2A_UNSUPPORTED_METHODS: readonly string[] = [\n 'SendStreamingMessage',\n 'GetTask',\n 'ListTasks',\n 'CancelTask',\n 'SubscribeToTask',\n 'CreateTaskPushNotificationConfig',\n 'GetTaskPushNotificationConfig',\n 'ListTaskPushNotificationConfigs',\n 'DeleteTaskPushNotificationConfig',\n 'GetExtendedAgentCard',\n];\n\n/**\n * Terminal task states. Only these two are ever returned: a synchronous\n * execution is finished by the time the response is written, and no task\n * store exists for a caller to poll a non-terminal one against.\n */\nexport const A2A_TASK_STATE_COMPLETED = 'TASK_STATE_COMPLETED';\nexport const A2A_TASK_STATE_FAILED = 'TASK_STATE_FAILED';\n","/**\n * Adapter self-description.\n *\n * `supportedSpec` is the A2A specification revision (`1.0.0`), never the\n * negotiation version (`1.0`) and never this package's version. Status is\n * `experimental` and stays that way until the unsupported list below shrinks\n * on purpose rather than by omission.\n */\nimport type { AdapterDescriptor } from '../../core/index.js';\nimport { A2A_SPEC_VERSION, A2A_UNSUPPORTED_METHODS } from './constants.js';\n\n/** What this adapter actually implements. */\nexport const A2A_CAPABILITIES: readonly string[] = ['agent-card', 'jsonrpc', 'SendMessage'];\n\n/**\n * Everything an A2A client may reasonably expect and will not get here.\n * Complete on purpose: a short list reads as \"mostly compatible\", which is\n * exactly the blanket claim alpha honesty forbids. `doctor` and\n * `/.well-known/agent-commerce` surface this verbatim.\n */\nexport const A2A_UNSUPPORTED: readonly string[] = [\n // Methods, named as the protocol names them. Same list the transport\n // rejects by name, so the descriptor cannot promise less than it refuses.\n ...A2A_UNSUPPORTED_METHODS,\n // Transports other than the one binding served.\n 'HTTP+JSON/REST binding',\n 'gRPC binding',\n // Behaviours.\n 'SSE',\n 'long-running task persistence',\n 'task resumption',\n 'push notifications',\n 'multi-turn conversational continuation',\n 'authenticated extended agent cards',\n 'A2A authentication schemes',\n 'artifact types beyond Agent Commerce outcome data',\n];\n\nexport function buildDescriptor(implementationVersion: string): AdapterDescriptor {\n return {\n name: 'a2a',\n kind: 'protocol',\n implementationVersion,\n supportedSpec: A2A_SPEC_VERSION,\n capabilities: A2A_CAPABILITIES,\n status: 'experimental',\n unsupported: A2A_UNSUPPORTED,\n };\n}\n","/**\n * SQLite implementation of the frozen ReceiptStore interface.\n *\n * Thin repository layer — no ORM. Every write goes through a prepared\n * statement; the only thing that varies between calls is parameters.\n */\nimport { randomUUID } from 'node:crypto';\nimport {\n accessSync,\n chmodSync,\n closeSync,\n existsSync,\n constants as fsConstants,\n mkdirSync,\n openSync,\n} from 'node:fs';\nimport { dirname } from 'node:path';\nimport Database from 'better-sqlite3';\nimport {\n type AdapterDescriptor,\n type AdapterHealth,\n type Clock,\n CommerceError,\n type CommerceEvent,\n type CommerceReceipt,\n type IdGenerator,\n type ListOptions,\n type Logger,\n NOOP_LOGGER,\n type PaymentAttempt,\n type PaymentAttemptReservation,\n type PaymentAttemptUpdate,\n type ReceiptStore,\n systemClock,\n toCommerceError,\n} from '../../core/index.js';\nimport { PACKAGE_VERSION } from '../../version.js';\nimport {\n type EventRow,\n eventToRow,\n type PaymentAttemptRow,\n type ReceiptRow,\n receiptToRow,\n rowToEvent,\n rowToPaymentAttempt,\n rowToReceipt,\n} from './rows.js';\nimport { migrate, SCHEMA_VERSION } from './schema.js';\n\nconst DEFAULT_LIST_LIMIT = 50;\n/**\n * Hard ceiling on every list query, applied here rather than only at the\n * gateway route, so every caller (HTTP, CLI, a future adapter) is covered.\n * SQLite treats a negative `LIMIT` as \"no limit\" —\n * confirmed `{ limit: -1 }` returns the entire table.\n */\nconst MAX_LIST_LIMIT = 500;\n\n/**\n * Clamps to a whole number in [1, MAX_LIST_LIMIT], defaulting when absent OR\n * non-finite (NaN/Infinity) — a store-level invariant that must hold\n * regardless of whether the current caller already filters those out.\n */\nfunction clampListLimit(limit: number | undefined): number {\n const base = limit !== undefined && Number.isFinite(limit) ? limit : DEFAULT_LIST_LIMIT;\n return Math.min(Math.max(Math.trunc(base), 1), MAX_LIST_LIMIT);\n}\n\nexport interface SqliteReceiptStoreOptions {\n /** File path, or ':memory:' for tests. Parent directory is created if missing. */\n readonly path: string;\n readonly logger?: Logger;\n readonly clock?: Clock;\n readonly ids?: IdGenerator;\n}\n\nconst defaultIds: IdGenerator = {\n next: (prefix) => (prefix !== undefined ? `${prefix}_${randomUUID()}` : randomUUID()),\n};\n\nfunction isUniqueConstraintOn(err: unknown, column: string): boolean {\n return (\n err instanceof Error &&\n 'code' in err &&\n (err as { code?: unknown }).code === 'SQLITE_CONSTRAINT_UNIQUE' &&\n err.message.includes(column)\n );\n}\n\n/**\n * Narrow the database and its WAL sidecars to owner-only.\n *\n * `new Database(path)` opens with `0666 & ~umask`, so on a\n * standard host the `.sqlite`, `-wal` and `-shm` files landed at 0644 — any\n * other local user could read the whole commerce ledger: payer and payee\n * addresses, amounts, settlement transaction hashes, replay keys and the\n * entire event stream. No key material (the gateway is non-custodial and\n * `redact.ts` is recursive), but business metadata all the same.\n *\n * Called *after* `journal_mode = WAL`, because the sidecars do not exist until\n * then. Belt-and-braces since the main file is now pre-created at 0600 (see\n * `createSqliteReceiptStore`): this still tightens a database that already\n * existed with a looser mode. Best-effort by design: a filesystem without\n * POSIX modes must not stop the gateway from starting, so a failure warns\n * rather than throws.\n */\nfunction restrictDatabasePermissions(path: string, logger: Logger): void {\n for (const file of [path, `${path}-wal`, `${path}-shm`]) {\n try {\n chmodSync(file, 0o600);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'ENOENT') continue;\n logger.warn(\n { file, error: code ?? 'unknown' },\n 'could not restrict receipt database permissions to owner-only',\n );\n }\n }\n}\n\nexport function createSqliteReceiptStore(options: SqliteReceiptStoreOptions): ReceiptStore {\n const logger = options.logger ?? NOOP_LOGGER;\n const clock = options.clock ?? systemClock;\n const ids = options.ids ?? defaultIds;\n const path = options.path;\n const isFileBacked = path !== ':memory:';\n\n if (isFileBacked) {\n const dir = dirname(path);\n if (dir !== '' && dir !== '.' && !existsSync(dir)) {\n // 0700 on directories we create ourselves. An existing directory is the\n // operator's to own and is deliberately left alone.\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n }\n\n // Fail at startup, not on the first payment. `new Database(path)`\n // happily opens a file the process cannot write, and SQLite only says\n // \"attempt to write a readonly database\" once a write is attempted — which\n // on a paid resource is *after* the payment attempt reservation, surfacing\n // as an opaque STORAGE_ERROR per request. Readiness does catch it (503), but\n // the operator is left guessing. This is not hypothetical: switching the\n // demo containers to a non-root user left an existing named volume\n // root-owned, and that is exactly how it presented.\n if (isFileBacked && existsSync(path)) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `Receipt database \"${path}\" exists but is not writable by this process (uid ${typeof process.getuid === 'function' ? process.getuid() : 'unknown'}). If this is a container that recently changed user, an existing volume may still be owned by the previous one — recreate it (docker compose down -v) or fix its ownership.`,\n { details: { path } },\n );\n }\n }\n\n // Create the file ourselves, at 0600, *before* SQLite can create it at\n // `0666 & ~umask`. The chmod below only narrows the mode after the fact: a\n // local co-tenant who opens the file inside that window keeps a readable\n // descriptor across the chmod and reads every receipt written afterwards.\n // SQLite copies the main file's mode onto the -wal/-shm sidecars, so this\n // one call covers all three. `mode` applies on creation only, so an\n // existing file is untouched here and left to the chmod.\n if (isFileBacked) {\n try {\n closeSync(openSync(path, 'a', 0o600));\n } catch {\n // Deliberately silent: whatever stopped us (unwritable directory,\n // exotic filesystem) is about to be reported by `new Database` with a\n // better message, or is harmless and covered by the chmod below.\n }\n }\n\n const db = new Database(path);\n db.pragma('journal_mode = WAL');\n db.pragma('foreign_keys = ON');\n migrate(db);\n if (isFileBacked) restrictDatabasePermissions(path, logger);\n\n const insertReceiptStmt = db.prepare(\n `INSERT INTO receipts (id, request_id, resource_id, payment_json, delivered_at, backend_status, duration_ms, protocol, metadata_json)\n VALUES (@id, @request_id, @resource_id, @payment_json, @delivered_at, @backend_status, @duration_ms, @protocol, @metadata_json)`,\n );\n const getReceiptStmt = db.prepare<[string], ReceiptRow>('SELECT * FROM receipts WHERE id = ?');\n const listReceiptsStmt = db.prepare<[number], ReceiptRow>(\n 'SELECT * FROM receipts ORDER BY delivered_at DESC, seq DESC LIMIT ?',\n );\n const listReceiptsByRequestStmt = db.prepare<[string, number], ReceiptRow>(\n 'SELECT * FROM receipts WHERE request_id = ? ORDER BY delivered_at DESC, seq DESC LIMIT ?',\n );\n const countReceiptsStmt = db.prepare<[], { count: number }>(\n 'SELECT COUNT(*) AS count FROM receipts',\n );\n // backend_status is INTEGER NOT NULL (schema.ts) so NOT BETWEEN never has\n // a NULL row to silently miss; 0 (backend never responded at all) and\n // every non-2xx status both count as undelivered, matching the dashboard's\n // deliveryResult() (ReceiptList.tsx) — the two views must not disagree\n // about what \"delivered\" means, which is the confusion.\n const countUndeliveredReceiptsStmt = db.prepare<[], { count: number }>(\n 'SELECT COUNT(*) AS count FROM receipts WHERE backend_status NOT BETWEEN 200 AND 299',\n );\n\n const insertEventStmt = db.prepare(\n `INSERT INTO events (id, type, request_id, resource_id, at, adapter, payment_provider, duration_ms, status, data_json)\n VALUES (@id, @type, @request_id, @resource_id, @at, @adapter, @payment_provider, @duration_ms, @status, @data_json)`,\n );\n const listEventsStmt = db.prepare<[number], EventRow>(\n 'SELECT * FROM events ORDER BY at DESC, seq DESC LIMIT ?',\n );\n const listEventsByRequestStmt = db.prepare<[string, number], EventRow>(\n 'SELECT * FROM events WHERE request_id = ? ORDER BY at DESC, seq DESC LIMIT ?',\n );\n\n const insertPaymentAttemptStmt = db.prepare(\n `INSERT INTO payment_attempts (id, request_id, resource_id, provider, replay_key, status, amount, currency, payer, payee, external_reference, rejection_reason, created_at, updated_at)\n VALUES (@id, @request_id, @resource_id, @provider, @replay_key, @status, @amount, @currency, @payer, @payee, @external_reference, @rejection_reason, @created_at, @updated_at)`,\n );\n const getPaymentAttemptByIdStmt = db.prepare<[string], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts WHERE id = ?',\n );\n // COALESCE: an omitted field (bound as NULL — see updatePaymentAttempt)\n // means \"leave the existing value alone\", not \"clear it\". Without this, a\n // second update that doesn't re-supply external_reference/rejection_reason\n // erases it — exactly the field that carries the on-chain tx hash for a\n // settlement-uncertain attempt, the one record proving the buyer's funds\n // may have moved. There is no current caller that needs to clear an\n // already-set value; if one appears, it needs an explicit sentinel rather\n // than overloading `undefined` to mean two different things again.\n const updatePaymentAttemptStmt = db.prepare(\n `UPDATE payment_attempts SET status = @status,\n external_reference = COALESCE(@external_reference, external_reference),\n rejection_reason = COALESCE(@rejection_reason, rejection_reason),\n updated_at = @updated_at\n WHERE replay_key = @replay_key`,\n );\n const listPaymentAttemptsStmt = db.prepare<[number], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts ORDER BY created_at DESC, seq DESC LIMIT ?',\n );\n const listPaymentAttemptsByRequestStmt = db.prepare<[string, number], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts WHERE request_id = ? ORDER BY created_at DESC, seq DESC LIMIT ?',\n );\n\n let closed = false;\n\n const descriptor: AdapterDescriptor = {\n name: 'sqlite-receipt-store',\n kind: 'storage',\n implementationVersion: PACKAGE_VERSION,\n supportedSpec: `sqlite-schema-v${SCHEMA_VERSION}`,\n capabilities: ['receipts', 'events', 'payment-attempts'],\n status: 'stable',\n };\n\n const store: ReceiptStore = {\n async init(): Promise<void> {\n // Schema setup already happened synchronously above (better-sqlite3 is\n // sync). This re-check makes init() a meaningful, idempotent gate for\n // callers that treat it as the lifecycle hook that must succeed before\n // any other method is used.\n const version = db.pragma('user_version', { simple: true }) as number;\n if (version !== SCHEMA_VERSION) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `Receipt store schema version mismatch (found ${version}, expected ${SCHEMA_VERSION})`,\n );\n }\n },\n\n async appendEvent(event: CommerceEvent): Promise<void> {\n try {\n insertEventStmt.run(eventToRow(event));\n } catch (err) {\n logger.warn(\n {\n err: err instanceof Error ? err.message : String(err),\n eventId: event.id,\n requestId: event.requestId,\n },\n 'receipt-store: failed to persist commerce event',\n );\n }\n },\n\n async reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt> {\n const now = clock.nowIso();\n const id = ids.next('attempt');\n try {\n insertPaymentAttemptStmt.run({\n id,\n request_id: reservation.requestId,\n resource_id: reservation.resourceId,\n provider: reservation.provider,\n replay_key: reservation.replayKey,\n status: 'reserved' satisfies PaymentAttempt['status'],\n amount: reservation.amount,\n currency: reservation.currency,\n payer: reservation.payer ?? null,\n payee: reservation.payee ?? null,\n external_reference: null,\n rejection_reason: null,\n created_at: now,\n updated_at: now,\n });\n } catch (err) {\n if (isUniqueConstraintOn(err, 'payment_attempts.replay_key')) {\n throw new CommerceError(\n 'PAYMENT_REPLAYED',\n `Payment authorisation has already been used (replayKey=${reservation.replayKey})`,\n { requestId: reservation.requestId, resourceId: reservation.resourceId },\n );\n }\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to reserve payment attempt');\n }\n const row = getPaymentAttemptByIdStmt.get(id);\n if (row === undefined) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n 'Payment attempt vanished immediately after insert',\n );\n }\n return rowToPaymentAttempt(row);\n },\n\n async updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void> {\n try {\n const result = updatePaymentAttemptStmt.run({\n replay_key: update.replayKey,\n status: update.status,\n external_reference: update.externalReference ?? null,\n rejection_reason: update.rejectionReason ?? null,\n updated_at: clock.nowIso(),\n });\n if (result.changes === 0) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `No payment attempt found for replayKey=${update.replayKey}`,\n );\n }\n } catch (err) {\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to update payment attempt');\n }\n },\n\n async saveReceipt(receipt: CommerceReceipt): Promise<void> {\n try {\n insertReceiptStmt.run(receiptToRow(receipt));\n } catch (err) {\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to save receipt');\n }\n },\n\n async getReceipt(id: string): Promise<CommerceReceipt | undefined> {\n const row = getReceiptStmt.get(id);\n return row !== undefined ? rowToReceipt(row) : undefined;\n },\n\n async listReceipts(listOptions: ListOptions = {}): Promise<readonly CommerceReceipt[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listReceiptsByRequestStmt.all(listOptions.requestId, limit)\n : listReceiptsStmt.all(limit);\n return rows.map(rowToReceipt);\n },\n\n /** Exact total, ignoring the listReceipts clamp — see the interface doc for why this exists. */\n async countReceipts(): Promise<number> {\n return countReceiptsStmt.get()?.count ?? 0;\n },\n\n /** Exact count of non-2xx receipts — see the interface doc for why this exists. */\n async countUndeliveredReceipts(): Promise<number> {\n return countUndeliveredReceiptsStmt.get()?.count ?? 0;\n },\n\n async listEvents(listOptions: ListOptions = {}): Promise<readonly CommerceEvent[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listEventsByRequestStmt.all(listOptions.requestId, limit)\n : listEventsStmt.all(limit);\n return rows.map(rowToEvent);\n },\n\n async listPaymentAttempts(listOptions: ListOptions = {}): Promise<readonly PaymentAttempt[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listPaymentAttemptsByRequestStmt.all(listOptions.requestId, limit)\n : listPaymentAttemptsStmt.all(limit);\n return rows.map(rowToPaymentAttempt);\n },\n\n descriptor,\n\n async health(): Promise<AdapterHealth> {\n // Same discipline: a client-visible field is authored from a\n // fixed vocabulary, never inherited from a caught error's `.message`.\n // `accessSync` on a real deployment throws e.g.\n // \"EACCES: permission denied, access '/workspace/data/receipts.sqlite'\"\n // — an absolute host path that must never reach the unauthenticated\n // `/ready` response). The raw message still goes\n // to the injected logger, so nothing is lost for diagnosis.\n const startedAt = clock.monotonicMs();\n if (closed) {\n return { status: 'fail', detail: 'store-unavailable', checkedAt: clock.nowIso() };\n }\n if (isFileBacked) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch (err) {\n logger.warn(\n { err: err instanceof Error ? err.message : String(err) },\n 'receipt-store: health check failed (store not writable)',\n );\n return {\n status: 'fail',\n detail: 'store-unwritable',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n }\n try {\n const version = db.pragma('user_version', { simple: true }) as number;\n if (version !== SCHEMA_VERSION) {\n logger.warn(\n { found: version, expected: SCHEMA_VERSION },\n 'receipt-store: health check failed (schema version mismatch)',\n );\n return {\n status: 'fail',\n detail: 'store-schema-mismatch',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n return {\n status: 'pass',\n detail: `sqlite schema v${SCHEMA_VERSION} writable`,\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n } catch (err) {\n logger.warn(\n { err: err instanceof Error ? err.message : String(err) },\n 'receipt-store: health check failed (store unavailable)',\n );\n return {\n status: 'fail',\n detail: 'store-unavailable',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n },\n\n async close(): Promise<void> {\n if (!closed) {\n closed = true;\n db.close();\n }\n },\n };\n\n return store;\n}\n","/**\n * The package version, resolved once for the whole package.\n *\n * Two paths, deliberately:\n *\n * - **Development** reads the root manifest, so the number is always live.\n * - **The published bundle cannot.** tsup collapses `src/**` into\n * `dist/index.js` and `dist/cli/index.js`, so any `require('../../package.json')`\n * written against a source path resolves from the wrong depth once bundled —\n * which is exactly how this broke during the single-package refactor, and how\n * it earlier produced a CLI reporting `v0.0.0-unknown`. The build injects\n * `__OAC_PACKAGE_VERSION__` instead (see tsup.config.ts).\n *\n * `typeof` on an undeclared identifier is safe in JS, so the dev path is\n * unaffected by the constant not existing.\n */\nimport { createRequire } from 'node:module';\n\ndeclare const __OAC_PACKAGE_VERSION__: string | undefined;\n\nfunction readFromManifest(): string {\n try {\n const require = createRequire(import.meta.url);\n // src/version.ts -> repository root\n return (require('../package.json') as { version?: string }).version ?? '0.0.0-unknown';\n } catch {\n return '0.0.0-unknown';\n }\n}\n\nexport const PACKAGE_VERSION: string =\n typeof __OAC_PACKAGE_VERSION__ === 'string' ? __OAC_PACKAGE_VERSION__ : readFromManifest();\n","/**\n * Defence-in-depth against accidentally persisting secrets.\n *\n * The gateway and payment providers are expected to never place secrets into\n * `CommerceReceipt.metadata`, `CommerceEvent.data` or `PaymentResult.metadata`\n * (see docs/contracts.md, \"Store NO secrets\"). This module is a second line\n * of defence at the persistence boundary: any key that *looks* like it holds\n * a private key, an auth header or a raw payment proof is stripped — never\n * persisted — rather than rejecting the whole write, so a logging bug never\n * takes down an otherwise-successful commerce flow (appendEvent especially\n * must never throw into the caller's flow).\n */\n/**\n * The bearer-token family was missing — `token`, `bearerToken`,\n * `adminToken`, `authToken`, `credential`, `cookie`, `sessionId`, `jwt` all\n * returned false. Nothing writes such a key today, which is exactly the state\n * a second line of defence is for; and this data also lands in a\n * file that is now owner-only precisely because it is worth protecting.\n */\nconst SECRET_KEY_PATTERN =\n /private[-_ ]?key|secret|password|mnemonic|seed[-_ ]?phrase|api[-_ ]?key|authoriz(e|ation)|^auth$|auth[-_]?header|payment[-_ ]?proof|^proof$|x-payment|signature|signed[-_ ]?message|token|bearer|credential|cookie|session|jwt/i;\n\nconst REDACTED = '[REDACTED]';\n\n/** True if `key` looks like it names a secret value. */\nexport function isSecretKey(key: string): boolean {\n return SECRET_KEY_PATTERN.test(key);\n}\n\n/**\n * Recursively strip values whose key looks secret-shaped, returning a new\n * object. Safe to call on already-clean data (no-op in that case).\n */\nexport function redact<T>(value: T): T {\n return redactValue(value) as T;\n}\n\nfunction redactValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(redactValue);\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n out[key] = isSecretKey(key) ? REDACTED : redactValue(inner);\n }\n return out;\n }\n return value;\n}\n\n/** True if `value` (recursively) contains any key that looks secret-shaped. */\nexport function containsSecretKey(value: unknown): boolean {\n if (Array.isArray(value)) {\n return value.some(containsSecretKey);\n }\n if (value !== null && typeof value === 'object') {\n return Object.entries(value as Record<string, unknown>).some(\n ([key, inner]) => isSecretKey(key) || containsSecretKey(inner),\n );\n }\n return false;\n}\n","/**\n * SQLite row shapes and mapping to/from the canonical domain model.\n *\n * `exactOptionalPropertyTypes` is on: optional fields are only assigned when\n * present (see docs/contracts.md, assumption 8).\n */\nimport type {\n CommerceEvent,\n CommerceEventType,\n CommerceReceipt,\n PaymentAttempt,\n PaymentResult,\n} from '../../core/index.js';\nimport { redact } from './redact.js';\n\nexport interface ReceiptRow {\n readonly id: string;\n readonly request_id: string;\n readonly resource_id: string;\n readonly payment_json: string | null;\n readonly delivered_at: string;\n readonly backend_status: number;\n readonly duration_ms: number | null;\n readonly protocol: string | null;\n readonly metadata_json: string | null;\n}\n\nexport interface EventRow {\n readonly id: string;\n readonly type: string;\n readonly request_id: string;\n readonly resource_id: string | null;\n readonly at: string;\n readonly adapter: string | null;\n readonly payment_provider: string | null;\n readonly duration_ms: number | null;\n readonly status: string | null;\n readonly data_json: string | null;\n}\n\nexport interface PaymentAttemptRow {\n readonly id: string;\n readonly request_id: string;\n readonly resource_id: string;\n readonly provider: string;\n readonly replay_key: string;\n readonly status: string;\n readonly amount: string;\n readonly currency: string;\n readonly payer: string | null;\n readonly payee: string | null;\n readonly external_reference: string | null;\n readonly rejection_reason: string | null;\n readonly created_at: string;\n readonly updated_at: string;\n}\n\nexport function receiptToRow(receipt: CommerceReceipt): {\n id: string;\n request_id: string;\n resource_id: string;\n payment_json: string | null;\n delivered_at: string;\n backend_status: number;\n duration_ms: number | null;\n protocol: string | null;\n metadata_json: string | null;\n} {\n return {\n id: receipt.id,\n request_id: receipt.requestId,\n resource_id: receipt.resourceId,\n payment_json: receipt.payment !== undefined ? JSON.stringify(redact(receipt.payment)) : null,\n delivered_at: receipt.deliveredAt,\n backend_status: receipt.backendStatus,\n duration_ms: receipt.durationMs !== undefined ? receipt.durationMs : null,\n protocol: receipt.protocol !== undefined ? receipt.protocol : null,\n metadata_json: receipt.metadata !== undefined ? JSON.stringify(redact(receipt.metadata)) : null,\n };\n}\n\nexport function rowToReceipt(row: ReceiptRow): CommerceReceipt {\n const payment =\n row.payment_json !== null ? (JSON.parse(row.payment_json) as PaymentResult) : undefined;\n const metadata =\n row.metadata_json !== null\n ? (JSON.parse(row.metadata_json) as Record<string, unknown>)\n : undefined;\n return {\n id: row.id,\n requestId: row.request_id,\n resourceId: row.resource_id,\n deliveredAt: row.delivered_at,\n backendStatus: row.backend_status,\n ...(payment !== undefined ? { payment } : {}),\n ...(row.duration_ms !== null ? { durationMs: row.duration_ms } : {}),\n ...(row.protocol !== null ? { protocol: row.protocol } : {}),\n ...(metadata !== undefined ? { metadata } : {}),\n };\n}\n\nexport function eventToRow(event: CommerceEvent): {\n id: string;\n type: string;\n request_id: string;\n resource_id: string | null;\n at: string;\n adapter: string | null;\n payment_provider: string | null;\n duration_ms: number | null;\n status: string | null;\n data_json: string | null;\n} {\n return {\n id: event.id,\n type: event.type,\n request_id: event.requestId,\n resource_id: event.resourceId !== undefined ? event.resourceId : null,\n at: event.at,\n adapter: event.adapter !== undefined ? event.adapter : null,\n payment_provider: event.paymentProvider !== undefined ? event.paymentProvider : null,\n duration_ms: event.durationMs !== undefined ? event.durationMs : null,\n status: event.status !== undefined ? event.status : null,\n data_json: event.data !== undefined ? JSON.stringify(redact(event.data)) : null,\n };\n}\n\nexport function rowToEvent(row: EventRow): CommerceEvent {\n const data =\n row.data_json !== null ? (JSON.parse(row.data_json) as Record<string, unknown>) : undefined;\n return {\n id: row.id,\n type: row.type as CommerceEventType,\n requestId: row.request_id,\n at: row.at,\n ...(row.resource_id !== null ? { resourceId: row.resource_id } : {}),\n ...(row.adapter !== null ? { adapter: row.adapter } : {}),\n ...(row.payment_provider !== null ? { paymentProvider: row.payment_provider } : {}),\n ...(row.duration_ms !== null ? { durationMs: row.duration_ms } : {}),\n ...(row.status !== null ? { status: row.status as 'ok' | 'error' } : {}),\n ...(data !== undefined ? { data } : {}),\n };\n}\n\nexport function rowToPaymentAttempt(row: PaymentAttemptRow): PaymentAttempt {\n return {\n id: row.id,\n requestId: row.request_id,\n resourceId: row.resource_id,\n provider: row.provider,\n replayKey: row.replay_key,\n status: row.status as PaymentAttempt['status'],\n amount: row.amount,\n currency: row.currency,\n ...(row.payer !== null ? { payer: row.payer } : {}),\n ...(row.payee !== null ? { payee: row.payee } : {}),\n ...(row.external_reference !== null ? { externalReference: row.external_reference } : {}),\n ...(row.rejection_reason !== null ? { rejectionReason: row.rejection_reason } : {}),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n","/**\n * Explicit migration scheme for the receipt-store SQLite schema.\n *\n * Uses SQLite's built-in `PRAGMA user_version` as the migration marker so a\n * restart against an existing database file re-opens without re-creating or\n * losing data (required negative test: \"gateway restart with receipt storage\n * preserved\").\n */\nimport type Database from 'better-sqlite3';\n\ninterface Migration {\n readonly version: number;\n up(db: Database.Database): void;\n}\n\nconst MIGRATIONS: readonly Migration[] = [\n {\n version: 1,\n up(db) {\n db.exec(`\n CREATE TABLE IF NOT EXISTS receipts (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n request_id TEXT NOT NULL,\n resource_id TEXT NOT NULL,\n payment_json TEXT,\n delivered_at TEXT NOT NULL,\n backend_status INTEGER NOT NULL,\n duration_ms INTEGER,\n protocol TEXT,\n metadata_json TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_receipts_request_id ON receipts(request_id);\n CREATE INDEX IF NOT EXISTS idx_receipts_delivered_at ON receipts(delivered_at);\n\n CREATE TABLE IF NOT EXISTS events (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n type TEXT NOT NULL,\n request_id TEXT NOT NULL,\n resource_id TEXT,\n at TEXT NOT NULL,\n adapter TEXT,\n payment_provider TEXT,\n duration_ms INTEGER,\n status TEXT,\n data_json TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_events_request_id ON events(request_id);\n CREATE INDEX IF NOT EXISTS idx_events_at ON events(at);\n\n CREATE TABLE IF NOT EXISTS payment_attempts (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n request_id TEXT NOT NULL,\n resource_id TEXT NOT NULL,\n provider TEXT NOT NULL,\n replay_key TEXT NOT NULL UNIQUE,\n status TEXT NOT NULL,\n amount TEXT NOT NULL,\n currency TEXT NOT NULL,\n payer TEXT,\n payee TEXT,\n external_reference TEXT,\n rejection_reason TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_payment_attempts_request_id ON payment_attempts(request_id);\n CREATE INDEX IF NOT EXISTS idx_payment_attempts_created_at ON payment_attempts(created_at);\n `);\n },\n },\n];\n\n/** Current target schema version — the version of the last migration. */\nexport const SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;\n\n/**\n * Bring `db` up to {@link SCHEMA_VERSION}. Idempotent: re-opening an existing,\n * already-migrated file is a fast no-op check against `PRAGMA user_version`.\n */\nexport function migrate(db: Database.Database): void {\n const current = db.pragma('user_version', { simple: true }) as number;\n for (const migration of MIGRATIONS) {\n if (migration.version <= current) continue;\n const apply = db.transaction(() => {\n migration.up(db);\n db.pragma(`user_version = ${migration.version}`);\n });\n apply();\n }\n}\n","/**\n * Single seam for the CLI's dependency on `src/config`.\n *\n * The import is dynamic, not static, on purpose: a static\n * `import … from '../../config/index.js'` would fail the whole module\n * graph the instant the package became unavailable for any reason (mid-flight\n * refactor, a broken build), taking down every CLI command — even `version`,\n * which never touches config — the moment this file is loaded. A dynamic\n * import only fails, catchably, when a command actually needs configuration.\n *\n * `runValidate` / `runDoctor` / `runInit` also accept the loader as an\n * injected dependency (defaulting to {@link loadConfigDynamic}), which keeps\n * their logic unit-testable without touching the filesystem or the real\n * package.\n */\nimport type { GatewayConfig as GatewayConfigType } from '../../config/index.js';\n\nexport type GatewayConfig = GatewayConfigType;\n\nexport interface LoadConfigOptions {\n readonly path?: string;\n readonly env?: NodeJS.ProcessEnv;\n readonly cwd?: string;\n}\n\nexport type ConfigLoader = (options?: LoadConfigOptions) => Promise<GatewayConfig>;\n\n/** Validates an already-built raw config object, without touching the disk. */\nexport type ConfigParser = (raw: unknown, env?: NodeJS.ProcessEnv) => Promise<GatewayConfig>;\n\nexport async function loadConfigDynamic(options: LoadConfigOptions = {}): Promise<GatewayConfig> {\n let mod: typeof import('../../config/index.js');\n try {\n mod = await import('../../config/index.js');\n } catch (err) {\n throw new Error(\n `the configuration module could not be loaded: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n return mod.loadConfig(options);\n}\n\n/**\n * In-memory validation, same module and same seam as {@link loadConfigDynamic}.\n *\n * Validating the object before writing means nothing lands unless it is\n * valid. Writing the file and *then* loading it back would leave an answer\n * that legitimately fails validation — no protocol selected, a typo'd\n * settlement address, a scheme-less backend URL — on disk under a printed\n * \"PASS Wrote …\", and tell the user to report their own input as a bug.\n */\nexport async function parseConfigDynamic(\n raw: unknown,\n env: NodeJS.ProcessEnv = process.env,\n): Promise<GatewayConfig> {\n let mod: typeof import('../../config/index.js');\n try {\n mod = await import('../../config/index.js');\n } catch (err) {\n throw new Error(\n `the configuration module could not be loaded: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n return mod.parseConfig(raw, env);\n}\n","/**\n * Small fetch-with-timeout helper for `doctor`. Injectable so tests never hit\n * a real network — they point it at a local stub HTTP server instead.\n */\nexport type FetchLike = typeof fetch;\n\nexport interface FetchJsonResult<T> {\n readonly ok: boolean;\n readonly status: number;\n readonly body?: T;\n readonly error?: string;\n}\n\nexport async function fetchJson<T = unknown>(\n fetchImpl: FetchLike,\n url: string,\n timeoutMs = 1500,\n): Promise<FetchJsonResult<T>> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const res = await fetchImpl(url, { signal: controller.signal });\n let body: T | undefined;\n try {\n body = (await res.json()) as T;\n } catch {\n body = undefined;\n }\n return { ok: res.ok, status: res.status, ...(body !== undefined ? { body } : {}) };\n } catch (err) {\n return {\n ok: false,\n status: 0,\n error: err instanceof Error ? err.message : 'unknown fetch error',\n };\n } finally {\n clearTimeout(timer);\n }\n}\n","/**\n * Pure YAML-rendering logic for `agent-commerce init`, kept separate from\n * prompt/IO concerns so it is trivially unit-testable.\n *\n * The on-disk shape here is the *raw* `config.yaml` document consumed\n * by `src/config`'s `parseConfig` (src/config/schema.ts):\n * `resources` is a map keyed by resource id, with `backend` / `expose` /\n * `payments` / `input` / `output` field names — distinct from the normalised\n * `CommerceResource` shape (`handler` / `exposedVia` / `paymentMethods` /\n * `inputSchema` / `outputSchema`) that `loadConfig()` returns.\n *\n * Addresses below are Anvil's well-known local dev accounts #0 (facilitator\n * signer) and #1 (merchant `payTo`) — public, fixed, printed by every\n * `anvil` startup banner. Never fund them.\n * Imported from `src/payments/x402/testing.ts` — the\n * canonical source (docs/contracts.md) — rather than duplicated as literals,\n * so `init` can never drift from `scripts/chain/deploy.ts`'s account layout.\n * A hand-copied or truncated literal here breaks every paid request and\n * silently defeats the dev-key guard. The MockUSDC `asset` address is a clearly labelled placeholder: it\n * cannot be known before `npm run chain:deploy` writes `.deploy/local.json`, so\n * it must not be the zero address (rejected by config validation) and must\n * be replaced by the real deployed address.\n */\n\nimport { stringify } from 'yaml';\n// Narrow module, not the `testing.js` barrel — see manifest-env.ts for why.\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from '../../payments/x402/local-chain/accounts.js';\n\n/** Anvil account #1 — merchant settlement destination, never the gateway/facilitator. */\nexport const LOCAL_DEV_MERCHANT_ADDRESS = ANVIL_WELL_KNOWN_ACCOUNTS[1].address;\n/** Anvil account #0 — local facilitator signer (broadcasts settlement on the dev chain only). */\nexport const LOCAL_DEV_FACILITATOR_PRIVATE_KEY = ANVIL_WELL_KNOWN_ACCOUNTS[0].privateKey;\n/** Placeholder only — replace with the MockUSDC address from `.deploy/local.json`. */\nexport const PLACEHOLDER_ASSET_ADDRESS = '0x000000000000000000000000000000000000dEaD';\n\nexport type InitResourceChoice = 'weather' | 'report';\nexport type InitProtocolChoice = 'http' | 'mcp';\n\nexport interface InitAnswers {\n readonly backendBaseUrl: string;\n readonly resources: readonly InitResourceChoice[];\n readonly protocols: readonly InitProtocolChoice[];\n readonly x402Enabled: boolean;\n readonly merchantPayTo: string;\n}\n\nexport function defaultInitAnswers(): InitAnswers {\n return {\n backendBaseUrl: 'http://localhost:3000',\n resources: ['weather', 'report'],\n protocols: ['http', 'mcp'],\n x402Enabled: true,\n merchantPayTo: LOCAL_DEV_MERCHANT_ADDRESS,\n };\n}\n\nfunction buildResourcesMap(answers: InitAnswers): Record<string, unknown> {\n const resources: Record<string, unknown> = {};\n const expose = [...answers.protocols];\n\n if (answers.resources.includes('weather')) {\n resources.weather = {\n name: 'Get weather',\n description: 'Deterministic demo weather lookup (free resource).',\n input: {\n type: 'object',\n properties: { city: { type: 'string' } },\n required: ['city'],\n additionalProperties: false,\n },\n backend: {\n type: 'http',\n method: 'GET',\n url: `${answers.backendBaseUrl}/api/weather/{city}`,\n },\n pricing: { type: 'free' },\n expose,\n };\n }\n\n if (answers.resources.includes('report')) {\n const paid = answers.x402Enabled;\n resources.report = {\n name: 'Get market report',\n description: 'Deterministic demo premium market report.',\n // No caller-supplied fields for this resource: an explicit empty,\n // closed schema (rather than omitting `input`) so a missing schema can\n // never be read as \"anything goes\".\n input: {\n type: 'object',\n properties: {},\n additionalProperties: false,\n },\n backend: {\n type: 'http',\n method: 'GET',\n url: `${answers.backendBaseUrl}/api/report`,\n },\n pricing: paid ? { type: 'fixed', amount: '0.01', currency: 'USDC' } : { type: 'free' },\n expose,\n ...(paid ? { payments: ['x402'] } : {}),\n };\n }\n\n return resources;\n}\n\n/** Builds the raw config object accepted by `parseConfig` (src/config). */\nexport function buildInitConfigObject(answers: InitAnswers): Record<string, unknown> {\n return {\n version: 1,\n merchant: {\n id: 'demo-merchant',\n name: 'Demo Merchant',\n publicBaseUrl: 'http://localhost:8080',\n },\n server: { port: 8080, host: '127.0.0.1' },\n storage: { receipts: { driver: 'sqlite', path: './data/receipts.db' } },\n protocols: {\n http: { enabled: answers.protocols.includes('http') },\n mcp: { enabled: answers.protocols.includes('mcp'), mountPath: '/mcp' },\n },\n resources: buildResourcesMap(answers),\n payments: answers.x402Enabled\n ? {\n x402: {\n enabled: true,\n network: 'eip155:84532',\n rpcUrl: 'http://127.0.0.1:8545',\n asset: PLACEHOLDER_ASSET_ADDRESS,\n assetName: 'MockUSDC',\n assetVersion: '2',\n assetDecimals: 6,\n payTo: answers.merchantPayTo,\n maxTimeoutSeconds: 60,\n facilitator: { mode: 'local', signerPrivateKey: LOCAL_DEV_FACILITATOR_PRIVATE_KEY },\n },\n }\n : {},\n };\n}\n\nconst HEADER = `# Generated by \\`agent-commerce init\\`.\n#\n# Any address/key below labelled \"LOCAL DEVELOPMENT ONLY\" or \"placeholder\" is\n# either one of Anvil's well-known, public dev accounts (never fund them,\n# never use them outside a local chain) or a\n# not-yet-real address. Before running against the local chain, run\n# \\`npm run chain:deploy\\` and replace \\`payments.x402.asset\\` with the deployed\n# MockUSDC address from \\`.deploy/local.json\\`. Replace \\`payments.x402.payTo\\`\n# with your real merchant-controlled settlement address before ever pointing\n# this at a funded network.\n#\n# server.host is loopback (127.0.0.1) on purpose: binding every interface\n# should be a deliberate edit, not something you inherit from a generator.\n#\n# server.adminToken / server.allowedOrigins are left unset here — a generated\n# secret in a file you might commit is its own problem, so this is left as a\n# placeholder for you to fill in rather than a real token. Without a token,\n# the operator routes (/api/receipts, /api/events, /api/events/stream) —\n# the merchant's commerce ledger: payer addresses, amounts, settlement\n# hashes — return 404 rather than serving openly. To enable them, uncomment\n# and set:\n# server:\n# adminToken: \\${ADMIN_TOKEN}\n# allowedOrigins:\n# - http://localhost:5173\n# See SECURITY.md before exposing this gateway beyond localhost.\n`;\n\nexport function renderInitConfigYaml(answers: InitAnswers): string {\n const body = stringify(buildInitConfigObject(answers), { indent: 2 });\n return `${HEADER}\\n${body}`;\n}\n","/**\n * Local chain deployment manifest — read/write contract for `.deploy/local.json`.\n *\n * Exact shape frozen in docs/contracts.md. Everything else in the repo reads\n * chain addresses through `readLocalChainManifest()` — no hard-coded\n * addresses anywhere else.\n *\n * Lives inside `src/payments/x402` (not `scripts/chain`, which is\n * outside `src/` and is run directly by npm scripts —\n * see `deploy-engine.ts`'s header comment for the same reasoning) so any\n * workspace package can import it via `src/payments/x402/testing.ts`\n * (see `docs/contracts.md`, \"Local chain deployment manifest\"). It has no\n * dependency on viem/zod/x402 regardless — plain Node built-ins only —\n * `scripts/chain/manifest.ts` re-exports this module unchanged so\n * `npm run chain:deploy` keeps working as a thin CLI wrapper.\n */\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport const LOCAL_CHAIN_MANIFEST_PATH = '.deploy/local.json';\n\nexport interface LocalChainManifestMerchant {\n readonly address: string;\n readonly privateKeyLabel: string;\n}\n\nexport interface LocalChainManifestKeyedAccount {\n readonly address: string;\n readonly privateKey: string;\n readonly note: string;\n}\n\nexport interface LocalChainManifest {\n readonly chainId: number;\n readonly rpcUrl: string;\n /**\n * The same chain, reachable from the *host* — distinct from `rpcUrl` only\n * when the deployer ran inside a Docker network (there `rpcUrl` is the\n * container-internal address, e.g. \"http://anvil:8545\", unresolvable from\n * the host). A host deploy records the same value in both fields, since on\n * the host they genuinely are the same endpoint. Host-side consumers\n * (demo agent, CLI) should prefer `hostRpcUrl ?? rpcUrl`. Optional so a\n * manifest written before this field existed still parses.\n */\n readonly hostRpcUrl?: string;\n readonly asset: string;\n readonly assetName: string;\n readonly assetVersion: string;\n readonly assetDecimals: number;\n readonly merchant: LocalChainManifestMerchant;\n readonly buyer: LocalChainManifestKeyedAccount;\n readonly facilitator: LocalChainManifestKeyedAccount;\n readonly buyerInitialBalance: string;\n}\n\nconst REQUIRED_TOP_LEVEL_STRING_FIELDS = [\n 'rpcUrl',\n 'asset',\n 'assetName',\n 'assetVersion',\n 'buyerInitialBalance',\n] as const;\n\n/**\n * Reads and structurally validates `.deploy/local.json`.\n *\n * Throws a clear, actionable error if the manifest is missing or malformed —\n * every consumer of this function is expected to let that error propagate\n * rather than silently falling back to a hard-coded address.\n */\nexport function readLocalChainManifest(cwd: string = process.cwd()): LocalChainManifest {\n const path = join(cwd, LOCAL_CHAIN_MANIFEST_PATH);\n\n if (!existsSync(path)) {\n throw new Error(\n `Local chain manifest not found at \"${path}\". Run \"npm run chain:start\" then \"npm run chain:deploy\" first.`,\n );\n }\n\n let raw: string;\n try {\n raw = readFileSync(path, 'utf8');\n } catch (cause) {\n throw new Error(`Could not read local chain manifest at \"${path}\".`, { cause });\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new Error(\n `Local chain manifest at \"${path}\" is not valid JSON. Re-run \"npm run chain:deploy\" to regenerate it.`,\n { cause },\n );\n }\n\n return validateManifestShape(parsed, path);\n}\n\nfunction validateManifestShape(value: unknown, path: string): LocalChainManifest {\n const fail = (detail: string): never => {\n throw new Error(\n `Local chain manifest at \"${path}\" is invalid: ${detail}. Re-run \"npm run chain:deploy\".`,\n );\n };\n\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return fail('expected a JSON object');\n }\n const record = value as Record<string, unknown>;\n\n if (typeof record.chainId !== 'number') {\n return fail('\"chainId\" must be a number');\n }\n if (typeof record.assetDecimals !== 'number') {\n return fail('\"assetDecimals\" must be a number');\n }\n for (const field of REQUIRED_TOP_LEVEL_STRING_FIELDS) {\n if (typeof record[field] !== 'string' || record[field] === '') {\n return fail(`\"${field}\" must be a non-empty string`);\n }\n }\n // Optional: absent entirely on a manifest written before this field\n // existed, but if present it must be well-formed — never silently ignore a\n // malformed value on a trust-boundary read.\n if ('hostRpcUrl' in record && record.hostRpcUrl !== undefined) {\n if (typeof record.hostRpcUrl !== 'string' || record.hostRpcUrl === '') {\n return fail('\"hostRpcUrl\" must be a non-empty string when present');\n }\n }\n\n const merchant = record.merchant;\n if (\n typeof merchant !== 'object' ||\n merchant === null ||\n typeof (merchant as Record<string, unknown>).address !== 'string' ||\n typeof (merchant as Record<string, unknown>).privateKeyLabel !== 'string'\n ) {\n return fail('\"merchant\" must be { address: string, privateKeyLabel: string }');\n }\n\n for (const key of ['buyer', 'facilitator'] as const) {\n const account = record[key];\n if (\n typeof account !== 'object' ||\n account === null ||\n typeof (account as Record<string, unknown>).address !== 'string' ||\n typeof (account as Record<string, unknown>).privateKey !== 'string' ||\n typeof (account as Record<string, unknown>).note !== 'string'\n ) {\n return fail(`\"${key}\" must be { address: string, privateKey: string, note: string }`);\n }\n }\n\n return record as unknown as LocalChainManifest;\n}\n","/**\n * Local-development convenience: fills `X402_*`/`MERCHANT_WALLET`\n * placeholders in `config.yaml` from `.deploy/local.json` (written\n * by `npm run chain:deploy`) when the host shell hasn't set them itself.\n *\n * Why this exists: inside `docker compose`, `docker/gateway-entrypoint.sh`\n * exports these from the manifest before the gateway process starts. Running\n * `agent-commerce validate`/`doctor` on the host has no equivalent step, so\n * the exact same config that starts the (containerised) gateway fine fails\n * host-side with \"Unresolved environment variable\" — reporting a healthy\n * stack as broken. See docs/contracts.md \"Local chain deployment manifest\".\n *\n * Deliberately narrow: only fills a variable that is completely unset (a\n * real environment always wins — this can never override a deployment), only\n * from the exact fields the manifest declares, and only for `validate`/\n * `doctor` — never inside the config loader itself, so gateway startup is\n * unaffected either way.\n */\n// Imported from the narrow module, not the `testing.js` barrel: that barrel\n// also re-exports the Anvil bootstrap and the deploy engine, which import\n// `viem`. Tree-shaking drops the unused bindings but esbuild still emits a\n// bare `import 'viem'` for side effects, and viem is an optional peer — the\n// CLI would refuse to start on a default install. Caught by a bare\n// clean-consumer install, not by any in-repo test.\nimport {\n LOCAL_CHAIN_MANIFEST_PATH,\n type LocalChainManifest,\n readLocalChainManifest,\n} from '../../payments/x402/local-chain/manifest.js';\n\nexport { LOCAL_CHAIN_MANIFEST_PATH };\n\n/** `config.yaml` placeholder name -> the manifest field it maps to. */\nconst MANIFEST_ENV_VARS: readonly (readonly [string, (m: LocalChainManifest) => string])[] = [\n ['X402_ASSET', (m) => m.asset],\n ['X402_ASSET_NAME', (m) => m.assetName],\n ['X402_ASSET_VERSION', (m) => m.assetVersion],\n ['X402_ASSET_DECIMALS', (m) => String(m.assetDecimals)],\n ['MERCHANT_WALLET', (m) => m.merchant.address],\n ['X402_FACILITATOR_PRIVATE_KEY', (m) => m.facilitator.privateKey],\n];\n\n/** The subset of {@link MANIFEST_ENV_VARS} names, for checking a failed variable against. */\nexport const MANIFEST_FILLABLE_ENV_VAR_NAMES: ReadonlySet<string> = new Set(\n MANIFEST_ENV_VARS.map(([name]) => name),\n);\n\nexport interface ManifestEnvFill {\n /** `baseEnv`, plus any variables filled. Never mutates `baseEnv` itself. */\n readonly env: NodeJS.ProcessEnv;\n /** Names actually filled — empty when the manifest was absent or nothing needed filling. */\n readonly filled: readonly string[];\n /** True once a manifest was found at all, whether or not anything needed filling. */\n readonly manifestFound: boolean;\n}\n\n/**\n * Reads `.deploy/local.json` (relative to `cwd`) and fills only the\n * currently-unset variables in {@link MANIFEST_ENV_VARS}. Never throws — a\n * missing or invalid manifest just means nothing gets filled, and the\n * existing \"unresolved environment variable\" error from `src/config`\n * surfaces exactly as it does today.\n */\nexport function fillEnvFromLocalChainManifest(\n baseEnv: NodeJS.ProcessEnv,\n cwd: string = process.cwd(),\n): ManifestEnvFill {\n let manifest: LocalChainManifest;\n try {\n manifest = readLocalChainManifest(cwd);\n } catch {\n return { env: baseEnv, filled: [], manifestFound: false };\n }\n\n const filled: string[] = [];\n const env: NodeJS.ProcessEnv = { ...baseEnv };\n for (const [name, read] of MANIFEST_ENV_VARS) {\n if (env[name] === undefined) {\n env[name] = read(manifest);\n filled.push(name);\n }\n }\n return { env, filled, manifestFound: true };\n}\n","/**\n * Safe, visible-but-non-secret display of an address/destination for\n * `doctor`. Shows enough to eyeball correctness without ever printing a full\n * value that could be sensitive-adjacent (e.g. an RPC URL with an embedded\n * API key).\n *\n * Returning the value whole when it is short enough (`length <= keep * 2`)\n * would contradict the promise above — harmless for the 42-character\n * addresses this is used on today, and a trap for the next caller who reaches\n * for it with a short secret. A short value is masked entirely instead.\n */\nexport function maskMiddle(value: string, keep = 6): string {\n if (value.length <= keep * 2) return value.length === 0 ? value : '…';\n return `${value.slice(0, keep)}…${value.slice(-4)}`;\n}\n","/**\n * The CLI's own version and every pinned protocol/SDK version — never\n * hard-coded, so a pin bump (see docs/contracts.md) is reflected automatically.\n *\n * Two resolution paths, deliberately:\n *\n * - **Development** reads the root manifest directly, so the numbers are\n * always live.\n * - **The published npm package** cannot: the build collapses `src/**` into\n * two bundled files, so a relative manifest path written against a source\n * location resolves from the wrong depth once bundled. That has now failed\n * twice — it silently produced `v0.0.0-unknown` before packaging, and it\n * crashed both entry points during the single-package refactor. So the\n * build injects the resolved report as `__OAC_VERSION_REPORT__` (see\n * tsup.config.ts) and it is preferred when present.\n *\n * `typeof` on an undeclared identifier is safe in JS, so the dev path is\n * unaffected by the constant not existing.\n */\nimport { createRequire } from 'node:module';\n\ndeclare const __OAC_VERSION_REPORT__: string | undefined;\n\nconst require = createRequire(import.meta.url);\n\ninterface PackageManifest {\n readonly version: string;\n readonly dependencies?: Readonly<Record<string, string>>;\n readonly peerDependencies?: Readonly<Record<string, string>>;\n}\n\nfunction readManifest(relativePath: string): PackageManifest | undefined {\n try {\n return require(relativePath) as PackageManifest;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Peers count as pins. The three heaviest pins — the MCP SDK, x402 and viem —\n * are *optional peer* dependencies so a default install stays small, and\n * reading only `dependencies` silently emptied this report of exactly the\n * protocol/SDK versions it exists to show.\n */\nfunction depVersion(manifest: PackageManifest | undefined, name: string): string | undefined {\n return manifest?.dependencies?.[name] ?? manifest?.peerDependencies?.[name];\n}\n\nexport interface PinnedVersion {\n readonly name: string;\n readonly version: string;\n readonly via: string;\n}\n\nexport interface VersionReport {\n readonly cliVersion: string;\n readonly pinned: readonly PinnedVersion[];\n}\n\n/** Missing entries are omitted (rather than shown as \"unknown\") so nothing is ever fabricated. */\nexport function readVersionReport(): VersionReport {\n const injected = typeof __OAC_VERSION_REPORT__ === 'string' ? __OAC_VERSION_REPORT__ : undefined;\n if (injected !== undefined) {\n return JSON.parse(injected) as VersionReport;\n }\n\n // One package, one manifest. `via` names the module that owns each pin,\n // which is what a reader of `agent-commerce version` actually wants to know;\n // the names are src/ directories, not package manifests.\n const manifest = readManifest('../../../package.json');\n\n const candidates: readonly [string, string][] = [\n ['@modelcontextprotocol/sdk', 'protocols/mcp'],\n ['@coinbase/x402', 'payments/x402'],\n ['@x402/core', 'payments/x402'],\n ['@x402/evm', 'payments/x402'],\n ['viem', 'payments/x402'],\n ['better-sqlite3', 'storage/receipts'],\n ['fastify', 'gateway'],\n ['pino', 'gateway'],\n ['zod', 'config'],\n ];\n\n const pinned: PinnedVersion[] = [];\n for (const [name, via] of candidates) {\n const version = depVersion(manifest, name);\n if (version !== undefined) {\n pinned.push({ name, version, via });\n }\n }\n\n return {\n cliVersion: manifest?.version ?? '0.0.0-unknown',\n pinned,\n };\n}\n","import { existsSync, mkdirSync } from 'node:fs';\nimport { writeFile } from 'node:fs/promises';\nimport { dirname, resolve } from 'node:path';\nimport * as clack from '@clack/prompts';\nimport { DEFAULT_CONFIG_FILENAME } from '../../config/filename.js';\nimport {\n type ConfigLoader,\n type ConfigParser,\n type GatewayConfig,\n loadConfigDynamic,\n parseConfigDynamic,\n} from '../lib/config-client.js';\nimport {\n buildInitConfigObject,\n defaultInitAnswers,\n type InitAnswers,\n type InitProtocolChoice,\n type InitResourceChoice,\n renderInitConfigYaml,\n} from '../lib/init-config.js';\nimport type { Io } from '../lib/io.js';\nimport { formatConfigError } from './validate.js';\n\nexport interface InitOptions {\n readonly outputPath?: string;\n readonly force?: boolean;\n readonly yes?: boolean;\n}\n\nexport interface InitDeps {\n readonly loadConfig?: ConfigLoader;\n readonly parseConfig?: ConfigParser;\n readonly collectAnswers?: () => Promise<InitAnswers | undefined>;\n readonly fileExists?: (path: string) => boolean;\n readonly writeFile?: (path: string, content: string) => Promise<void>;\n}\n\n/** Exported for testing: the real interactive prompt flow (mocks `@clack/prompts`). */\nexport async function collectAnswersInteractive(): Promise<InitAnswers | undefined> {\n clack.intro('agent-commerce init');\n\n const backendBaseUrl = await clack.text({\n message: 'Backend base URL (your existing merchant API)',\n initialValue: 'http://localhost:3000',\n // shape-checked here, where the user can retype it,\n // rather than surfacing as a config error after the fact.\n validate: (value) => {\n const trimmed = (value ?? '').trim();\n if (trimmed.length === 0) return 'Required';\n let parsed: URL;\n try {\n parsed = new URL(trimmed);\n } catch {\n return 'Must be an absolute URL, e.g. http://localhost:3000';\n }\n return parsed.protocol === 'http:' || parsed.protocol === 'https:'\n ? undefined\n : 'Must use http:// or https://';\n },\n });\n if (clack.isCancel(backendBaseUrl)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const resources = await clack.multiselect<InitResourceChoice>({\n message: 'Which example resource(s) do you want to expose?',\n options: [\n { value: 'weather', label: 'Weather (free)' },\n { value: 'report', label: 'Market report (paid)' },\n ],\n initialValues: ['weather', 'report'],\n required: false,\n });\n if (clack.isCancel(resources)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const protocols = await clack.multiselect<InitProtocolChoice>({\n message: 'Which protocols should be enabled?',\n options: [\n { value: 'http', label: 'HTTP' },\n { value: 'mcp', label: 'MCP' },\n ],\n initialValues: ['http', 'mcp'],\n // `required: false` permits an empty selection, which renders\n // `expose: []` on every resource and fails the schema's min(1). clack's\n // multiselect has no `validate` hook, so this is caught by the in-memory\n // validation in `runInit` — which now reports the real schema error and\n // writes nothing, instead of leaving an invalid file behind.\n required: false,\n });\n if (clack.isCancel(protocols)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const x402Enabled = await clack.confirm({ message: 'Enable x402 payments?', initialValue: true });\n if (clack.isCancel(x402Enabled)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n let merchantPayTo = defaultInitAnswers().merchantPayTo;\n if (x402Enabled) {\n const answer = await clack.text({\n message:\n 'Merchant settlement destination address (merchant-controlled — never a gateway-owned wallet)',\n initialValue: merchantPayTo,\n validate: (value) => {\n const trimmed = (value ?? '').trim();\n if (trimmed.length === 0) return 'Required';\n // Same shape the config schema enforces; catching it here means a\n // typo'd address never reaches the \"generated config is invalid\" path.\n return /^0x[0-9a-fA-F]{40}$/.test(trimmed)\n ? undefined\n : 'Must be a 0x-prefixed 20-byte EVM address (42 characters)';\n },\n });\n if (clack.isCancel(answer)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n merchantPayTo = answer;\n }\n\n clack.outro('Configuration answers collected.');\n\n return { backendBaseUrl, resources, protocols, x402Enabled, merchantPayTo };\n}\n\n/** `agent-commerce init [--yes] [--force] [--output <path>]`. */\nexport async function runInit(options: InitOptions, io: Io, deps: InitDeps = {}): Promise<number> {\n const outputPath = options.outputPath ?? DEFAULT_CONFIG_FILENAME;\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const parseConfigInMemory = deps.parseConfig ?? parseConfigDynamic;\n const fileExists = deps.fileExists ?? existsSync;\n const writeFileImpl =\n deps.writeFile ??\n (async (path: string, content: string) => {\n await writeFile(path, content, 'utf8');\n });\n\n if (fileExists(outputPath) && options.force !== true) {\n io.stderr(`FAIL ${outputPath} already exists. Re-run with --force to overwrite.`);\n return 1;\n }\n\n const answers =\n options.yes === true\n ? defaultInitAnswers()\n : await (deps.collectAnswers ?? collectAnswersInteractive)();\n\n if (answers === undefined) {\n io.stderr('FAIL init aborted, nothing was written.');\n return 1;\n }\n\n // Validate BEFORE writing. Interactive answers can legitimately fail\n // validation — an empty protocol multiselect, a typo'd settlement address,\n // a scheme-less backend URL — and writing first would print \"PASS Wrote …\"\n // and then blame the tool: \"please report this as a bug\". Nothing is\n // written unless it is valid, and the message is the real configuration\n // error, which names the field the user can fix.\n let config: GatewayConfig;\n try {\n config = await parseConfigInMemory(buildInitConfigObject(answers));\n } catch (err) {\n io.stderr(formatConfigError(err));\n io.stderr(`FAIL Nothing was written to ${outputPath}.`);\n return 1;\n }\n\n const yamlContent = renderInitConfigYaml(answers);\n const resolvedPath = resolve(outputPath);\n const dir = dirname(resolvedPath);\n if (dir !== '' && !existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n await writeFileImpl(outputPath, yamlContent);\n io.stdout(`PASS Wrote ${outputPath}`);\n io.stdout(`PASS ${outputPath} is valid — ${config.resources.length} resource(s)`);\n\n // The YAML is rendered from the very object just validated, but it is\n // rendered, not serialised from it — so read it back and confirm the two\n // agree. A renderer bug is the one failure the in-memory check cannot see,\n // and it IS a bug worth reporting.\n try {\n await loadConfig({ path: outputPath });\n } catch (err) {\n io.stderr(formatConfigError(err));\n io.stderr(\n `FAIL ${outputPath} was written but does not parse, although the same answers validated in memory — this is a bug in the config renderer, please report it.`,\n );\n return 1;\n }\n\n io.stdout('');\n io.stdout('Next steps:');\n io.stdout(` agent-commerce validate --config ${outputPath}`);\n // Only commands the reader can actually run. `npm run dev:merchant` and\n // `npm run dev:gateway` exist solely inside the development repo, and this\n // CLI ships to npm — telling an installed user to run them is a dead end.\n io.stdout(' docker compose up # start the local demo stack (from a repo clone)');\n io.stdout(` agent-commerce doctor --config ${outputPath}`);\n\n return 0;\n}\n","import { ZodError } from 'zod';\nimport { isCommerceError } from '../../core/index.js';\nimport { type ConfigLoader, loadConfigDynamic } from '../lib/config-client.js';\nimport type { Io } from '../lib/io.js';\nimport {\n fillEnvFromLocalChainManifest,\n LOCAL_CHAIN_MANIFEST_PATH,\n MANIFEST_FILLABLE_ENV_VAR_NAMES,\n type ManifestEnvFill,\n} from '../lib/manifest-env.js';\n\nexport interface ValidateOptions {\n readonly configPath?: string;\n}\n\nexport interface ValidateDeps {\n readonly loadConfig?: ConfigLoader;\n readonly fillEnvFromManifest?: (env: NodeJS.ProcessEnv) => ManifestEnvFill;\n}\n\n/**\n * Formats a config-loading failure into an actionable report.\n *\n * Handles the three error shapes `src/config` can produce:\n * a `CommerceError('CONFIG_INVALID', …)` with structured details, a raw\n * `ZodError` (schema errors, one line per failing path), or a plain Error\n * (e.g. a YAML syntax error, or the \"config package not available yet\"\n * integration-gap error). Never prints a resolved `${ENV}` value — only ever\n * the variable name, which the underlying error message is expected to carry.\n *\n * `manifestFound` adds one more hint line when the failure is specifically an\n * unresolved variable that `.deploy/local.json` would have supplied, had\n * `npm run chain:deploy` been run — see `../lib/manifest-env.js`.\n */\nexport function formatConfigError(err: unknown, manifestFound = false): string {\n if (isCommerceError(err)) {\n const lines = [`FAIL ${err.code}: ${err.message}`];\n if (err.details !== undefined) {\n lines.push(` details: ${JSON.stringify(err.details)}`);\n }\n const variable = err.details?.['variable'];\n if (\n !manifestFound &&\n typeof variable === 'string' &&\n MANIFEST_FILLABLE_ENV_VAR_NAMES.has(variable)\n ) {\n lines.push(\n ` hint: \"npm run chain:deploy\" writes ${LOCAL_CHAIN_MANIFEST_PATH}, which validate/doctor read automatically to fill local X402_*/MERCHANT_WALLET placeholders.`,\n );\n }\n return lines.join('\\n');\n }\n if (err instanceof ZodError) {\n const lines = ['FAIL Configuration schema errors:'];\n for (const issue of err.issues) {\n const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';\n lines.push(` - ${path}: ${issue.message}`);\n }\n return lines.join('\\n');\n }\n if (err instanceof Error) {\n return `FAIL ${err.message}`;\n }\n return `FAIL ${String(err)}`;\n}\n\n/** `agent-commerce validate [--config <path>]`. Exit code is non-zero on invalid configuration. */\nexport async function runValidate(\n options: ValidateOptions,\n io: Io,\n deps: ValidateDeps = {},\n): Promise<number> {\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const fillEnvFromManifest = deps.fillEnvFromManifest ?? fillEnvFromLocalChainManifest;\n const { env, filled, manifestFound } = fillEnvFromManifest(process.env);\n if (filled.length > 0) {\n io.stdout(`using local chain manifest ${LOCAL_CHAIN_MANIFEST_PATH} for ${filled.join(', ')}`);\n }\n try {\n const config = await loadConfig({\n ...(options.configPath !== undefined ? { path: options.configPath } : {}),\n env,\n });\n io.stdout('PASS Configuration is valid');\n io.stdout(` merchant: ${config.merchant.name} (${config.merchant.id})`);\n io.stdout(` resources: ${config.resources.length}`);\n io.stdout(\n ` protocols: http=${config.protocols.http.enabled ? 'on' : 'off'} mcp=${config.protocols.mcp.enabled ? 'on' : 'off'} a2a=${config.protocols.a2a.enabled ? 'on' : 'off'}`,\n );\n io.stdout(` payments: x402=${config.payments.x402?.enabled === true ? 'on' : 'off'}`);\n return 0;\n } catch (err) {\n io.stderr(formatConfigError(err, manifestFound));\n return 1;\n }\n}\n","import type { Io } from '../lib/io.js';\nimport { readVersionReport, type VersionReport } from '../lib/versions.js';\n\nexport interface VersionDeps {\n readonly readVersionReport?: () => VersionReport;\n}\n\n/** `agent-commerce version` — CLI version + pinned protocol/SDK versions. */\nexport function runVersion(io: Io, deps: VersionDeps = {}): number {\n const report = (deps.readVersionReport ?? readVersionReport)();\n io.stdout(`agent-commerce v${report.cliVersion}`);\n if (report.pinned.length > 0) {\n io.stdout('');\n io.stdout('Pinned protocol / SDK versions:');\n for (const pin of report.pinned) {\n io.stdout(` ${pin.name.padEnd(24)} ${pin.version.padEnd(12)} (via ${pin.via})`);\n }\n }\n return 0;\n}\n","/**\n * Minimal, injectable stdout/stderr so command logic is testable without\n * capturing real process streams.\n */\nexport interface Io {\n stdout(line: string): void;\n stderr(line: string): void;\n}\n\nexport const processIo: Io = {\n stdout: (line) => {\n process.stdout.write(`${line}\\n`);\n },\n stderr: (line) => {\n process.stderr.write(`${line}\\n`);\n },\n};\n\n/** Collects lines instead of writing anywhere. Useful for tests. */\nexport function createCapturingIo(): Io & { out: string[]; err: string[] } {\n const out: string[] = [];\n const err: string[] = [];\n return {\n out,\n err,\n stdout: (line) => out.push(line),\n stderr: (line) => err.push(line),\n };\n}\n","#!/usr/bin/env node\nimport { CommanderError } from 'commander';\nimport { buildProgram } from './program.js';\n\n/**\n * `agent-commerce version | grep -q x402` is an ordinary thing to type, and\n * `grep -q` exits on its first match — closing the pipe while the CLI is still\n * writing. Node's default for that is an unhandled `EPIPE` error event on the\n * socket, which aborts the process with a stack trace: a command that did\n * exactly what was asked, reported as a crash, and a red CI step.\n *\n * Exit quietly instead. Every other stream error still throws.\n */\nfor (const stream of [process.stdout, process.stderr]) {\n stream.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EPIPE') process.exit(0);\n throw err;\n });\n}\n\nasync function main(): Promise<void> {\n const program = buildProgram();\n try {\n await program.parseAsync(process.argv);\n } catch (err) {\n if (err instanceof CommanderError) {\n process.exitCode = err.exitCode;\n return;\n }\n throw err;\n }\n}\n\nvoid main();\n"]}
1
+ {"version":3,"sources":["../../src/config/filename.ts","../../src/core/domain/common.ts","../../src/core/domain/event.ts","../../src/core/domain/resource.ts","../../src/core/domain/wire.ts","../../src/core/errors/codes.ts","../../src/core/errors/commerce-error.ts","../../src/core/errors/index.ts","../../src/core/interfaces/logger.ts","../../src/core/interfaces/protocol-adapter.ts","../../src/core/interfaces/runtime.ts","../../src/core/public-types.ts","../../src/core/index.ts","../../src/core/execution/backend-http.ts","../../src/core/execution/event-bus.ts","../../src/core/execution/validation.ts","../../src/core/execution/pipeline.ts","../../src/core/execution/registry.ts","../../src/core/execution/index.ts","../../src/payments/x402/networks.ts","../../src/protocols/acp/constants.ts","../../src/config/env.ts","../../src/payments/x402/local-chain/accounts.ts","../../src/payments/x402/dev-key-guard.ts","../../src/payments/x402/guardrails.ts","../../src/config/schema.ts","../../src/config/load.ts","../../src/config/index.ts","../../src/cli/program.ts","../../src/cli/commands/demo.ts","../../src/cli/commands/doctor.ts","../../src/protocols/a2a/constants.ts","../../src/protocols/a2a/descriptor.ts","../../src/protocols/acp/descriptor.ts","../../src/storage/receipts/store.ts","../../src/version.ts","../../src/storage/sqlite.ts","../../src/storage/receipts/redact.ts","../../src/storage/receipts/rows.ts","../../src/storage/receipts/schema.ts","../../src/cli/lib/config-client.ts","../../src/cli/lib/http.ts","../../src/cli/lib/init-config.ts","../../src/payments/x402/local-chain/manifest.ts","../../src/cli/lib/manifest-env.ts","../../src/cli/lib/mask.ts","../../src/cli/lib/versions.ts","../../src/cli/commands/import-openapi.ts","../../src/openapi/discover.ts","../../src/openapi/refs.ts","../../src/openapi/request.ts","../../src/openapi/schema.ts","../../src/openapi/draft.ts","../../src/openapi/load.ts","../../src/cli/commands/init.ts","../../src/cli/commands/validate.ts","../../src/cli/commands/version.ts","../../src/cli/lib/io.ts","../../src/cli/index.ts"],"names":["path","isPlainObject","text","fs","parseYaml","fsConstants","accessSync","existsSync","createRequire","sameAddress","dirname","loadConfig","typeList","isRecord","required","response","content","invalid","basename","extname","resolve","writeFile","mkdirSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAYa,uBAAA;AAZb,IAAA,aAAA,GAAA,KAAA,CAAA;AAAA,EAAA,wBAAA,GAAA;AAYO,IAAM,uBAAA,GAA0B,aAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;ACZvC,IAgCa,cAAA;AAhCb,IAAA,WAAA,GAAA,KAAA,CAAA;AAAA,EAAA,2BAAA,GAAA;AAgCO,IAAM,cAAA,GAA0C,CAAC,MAAA,EAAQ,KAAA,EAAO,OAAO,KAAK,CAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;AChCnF,IAAA,UAAA,GAAA,KAAA,CAAA;AAAA,EAAA,0BAAA,GAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;ACAA,IAAA,aAAA,GAAA,KAAA,CAAA;AAAA,EAAA,6BAAA,GAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;ACAA,IAkBa,mBAAA;AAlBb,IAAA,SAAA,GAAA,KAAA,CAAA;AAAA,EAAA,yBAAA,GAAA;AAkBO,IAAM,mBAAA,GAAsB,UAAA;AAAA,EAAA;AAAA,CAAA,CAAA;;;AClBnC,IA+Ba,0BAAA,EAkBA,qBAAA;AAjDb,IAAA,UAAA,GAAA,KAAA,CAAA;AAAA,EAAA,0BAAA,GAAA;AA+BO,IAAM,0BAAA,GAA0E;AAAA,MACrF,cAAA,EAAgB,GAAA;AAAA,MAChB,kBAAA,EAAoB,GAAA;AAAA,MACpB,aAAA,EAAe,GAAA;AAAA,MACf,gBAAA,EAAkB,GAAA;AAAA,MAClB,eAA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;AACF,IAAA,MAAM,OAAA,CAAQ,UAAA,CAAW,OAAA,CAAQ,IAAI,CAAA;AAAA,EACvC,SAAS,GAAA,EAAK;AACZ,IAAA,IAAI,eAAe,cAAA,EAAgB;AACjC,MAAA,OAAA,CAAQ,WAAW,GAAA,CAAI,QAAA;AACvB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACF;AAEA,KAAK,IAAA,EAAK","file":"index.js","sourcesContent":["/**\n * The default configuration filename, in one place.\n *\n * Deliberately its own module with **no imports**: `src/cli` reaches the rest\n * of `src/config` only through a dynamic import (see\n * `src/cli/lib/config-client.ts`), so that a broken config module cannot take\n * down commands that never read configuration. A leaf file holding a single\n * string has no module graph to break, so the CLI can import it directly\n * without reopening that seam — and `init`'s default output path, `--config`'s\n * help text and the loader's own lookup cannot drift apart, which is what\n * three separate copies of this string invited.\n */\nexport const DEFAULT_CONFIG_FILENAME = 'config.yaml';\n","/**\n * Shared primitive aliases used across the canonical domain model.\n *\n * FROZEN CONTRACT. Every consumer codes against these shapes; changing one\n * is a breaking change.\n */\n\n/**\n * A JSON Schema document (draft 2020-12 subset in practice).\n *\n * Deliberately loose: protocol adapters translate this to their own schema\n * representation, and the gateway only validates structurally at trust\n * boundaries. Never treat this as trusted input without validation.\n */\nexport type JsonSchema = Record<string, unknown>;\n\n/**\n * Protocol surfaces a resource can be exposed through in this release.\n *\n * The runtime list is the definition and the type is derived from it, so a\n * caller that has to *check* a name (config validation, the OpenAPI\n * importer's `--expose`) reads the same strings the type is built from\n * rather than keeping a second copy that can drift.\n */\nexport type ProtocolName = 'http' | 'mcp' | 'a2a' | 'acp';\n\n/**\n * The same names as a value, for code that has to *check* one at\n * runtime - config validation, the OpenAPI importer's `--expose`. Typed\n * against `ProtocolName` so an unsupported name cannot enter the list, which\n * is what keeps this from becoming a second definition that drifts.\n */\nexport const PROTOCOL_NAMES: readonly ProtocolName[] = ['http', 'mcp', 'a2a', 'acp'];\n\n/** Payment methods a resource can accept in this release. */\nexport type PaymentMethodName = 'x402';\n\n/** ISO-8601 timestamp string, always UTC with millisecond precision. */\nexport type IsoTimestamp = string;\n\n/**\n * A decimal amount expressed as a string in the *display* unit of the currency\n * (for example \"0.01\" USDC), never as a float and never in base units.\n *\n * Conversion to on-chain base units is a payment-provider responsibility.\n */\nexport type DecimalAmount = string;\n\n/** Health of an individual adapter or subsystem. */\nexport interface AdapterHealth {\n readonly status: 'pass' | 'warn' | 'fail';\n readonly detail?: string;\n readonly checkedAt: IsoTimestamp;\n readonly durationMs?: number;\n}\n\n/**\n * Self-description every adapter must expose so diagnostics can report exactly\n * what is supported instead of implying blanket protocol compatibility.\n *\n *\n */\nexport interface AdapterDescriptor {\n readonly name: string;\n readonly kind: 'protocol' | 'payment' | 'storage';\n /** Version of this adapter implementation (independent of the spec). */\n readonly implementationVersion: string;\n /** Exact pinned specification revision this adapter targets. */\n readonly supportedSpec: string;\n readonly capabilities: readonly string[];\n readonly status: 'stable' | 'experimental' | 'planned';\n /** Capabilities explicitly NOT implemented, surfaced by `doctor`. */\n readonly unsupported?: readonly string[];\n}\n","/**\n * Canonical commerce events.\n *\n * FROZEN CONTRACT. Every event in a single flow shares one `requestId` so that\n * logs, payment attempts, backend calls and receipts are correlatable.\n */\nimport type { IsoTimestamp } from './common.js';\n\nexport const COMMERCE_EVENT_TYPES = [\n 'resource.discovered',\n 'resource.requested',\n 'payment.required',\n 'payment.rejected',\n 'payment.verified',\n 'payment.settled',\n 'backend.called',\n 'backend.failed',\n 'resource.delivered',\n] as const;\n\nexport type CommerceEventType = (typeof COMMERCE_EVENT_TYPES)[number];\n\nexport interface CommerceEvent {\n readonly id: string;\n readonly type: CommerceEventType;\n readonly requestId: string;\n readonly resourceId?: string;\n readonly at: IsoTimestamp;\n /** Protocol adapter that originated the request, e.g. 'mcp' or 'http'. */\n readonly adapter?: string;\n readonly paymentProvider?: string;\n readonly durationMs?: number;\n readonly status?: 'ok' | 'error';\n /** Non-secret, structured detail. Must never contain keys, headers or proofs. */\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Sink for canonical events.\n *\n * Implementations must be non-throwing from the caller's perspective: an event\n * sink failure must never fail an otherwise successful commerce flow.\n */\nexport interface EventSink {\n emit(event: CommerceEvent): Promise<void>;\n}\n","/**\n * Canonical resource model.\n *\n * FROZEN CONTRACT.\n */\nimport type { DecimalAmount, JsonSchema, PaymentMethodName, ProtocolName } from './common.js';\n\n/** HTTP methods a backend handler may use. */\nexport type BackendMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * Describes how the gateway calls the merchant's existing backend.\n *\n * Backend URLs are administrator-controlled configuration only. User- or\n * agent-controlled backend URLs are forbidden (see docs/security.md, SSRF).\n * Secret header values must come from `${ENV_VAR}` placeholders resolved by\n * the config loader, never from plaintext configuration.\n */\nexport interface BackendHandler {\n readonly type: 'http';\n readonly method: BackendMethod;\n readonly url: string;\n readonly headers?: Readonly<Record<string, string>>;\n /** Hard upper bound on the backend call. Defaults to DEFAULT_BACKEND_TIMEOUT_MS. */\n readonly timeoutMs?: number;\n /**\n * Names the top-level input properties carrying each part of the request.\n *\n * Absent (the default) keeps the original mapping: `{param}` values are read\n * from top-level input and everything left over becomes either the query\n * string (GET/DELETE) or the entire JSON body (POST/PUT/PATCH). That mapping\n * cannot express `POST /users/{userId}/orders?notify=true` with a JSON body\n * - one perfectly ordinary REST operation with all three parts at once.\n *\n * When present, each group is sourced independently and top-level input that\n * no binding names is not forwarded to the backend at all.\n */\n readonly inputBindings?: {\n readonly path?: string;\n readonly query?: string;\n readonly body?: string;\n };\n}\n\n/** Default backend timeout when a resource does not specify one. */\nexport const DEFAULT_BACKEND_TIMEOUT_MS = 10_000;\n\n/**\n * Canonical pricing.\n *\n * `dynamic` exists in the type system for forward compatibility but is\n * REJECTED by config validation in this release.\n */\nexport type Pricing =\n | { readonly type: 'free' }\n | {\n readonly type: 'fixed';\n readonly amount: DecimalAmount;\n readonly currency: string;\n }\n | {\n readonly type: 'dynamic';\n readonly resolver: string;\n };\n\n/**\n * A merchant capability exposed to agents.\n *\n * The canonical resource is the single source of truth: protocol adapters map\n * it outward, they never define their own parallel notion of a resource.\n */\nexport interface CommerceResource {\n readonly id: string;\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: JsonSchema;\n readonly outputSchema?: JsonSchema;\n readonly handler: BackendHandler;\n readonly pricing: Pricing;\n readonly exposedVia: readonly ProtocolName[];\n readonly paymentMethods: readonly PaymentMethodName[];\n}\n\n/** Read-only view of every configured resource. */\nexport interface ResourceRegistry {\n get(id: string): CommerceResource | undefined;\n list(): readonly CommerceResource[];\n /** Resources exposed through a given protocol surface. */\n listExposedVia(protocol: ProtocolName): readonly CommerceResource[];\n has(id: string): boolean;\n}\n","/**\n * Gateway-defined wire envelopes.\n *\n * FROZEN CONTRACT. These are the *only* representations of \"payment required\"\n * and \"error\" that leave the gateway, whichever protocol carries them. The HTTP\n * routes, the MCP adapter and the demo buyer agent all use these helpers so the\n * three can never drift apart.\n */\n\nimport type { CommerceError, CommerceErrorCode } from '../errors/index.js';\nimport type { DecimalAmount, IsoTimestamp, PaymentMethodName } from './common.js';\nimport type { DeliveredOutcome, PaymentRequiredOutcome } from './request.js';\n\n/**\n * Reserved input property carrying a payment proof on protocols that have no\n * header channel (MCP tool calls). Over HTTP the `PAYMENT-SIGNATURE` header is\n * used.\n */\nexport const PAYMENT_INPUT_FIELD = '_payment';\n\n/**\n * HTTP request header carrying the payment proof.\n *\n * x402 v2 header names, lowercased because that is how Node presents incoming\n * headers. v1's `X-PAYMENT` / `X-PAYMENT-RESPONSE` pair is not accepted: this\n * gateway speaks one protocol version, and quietly honouring both would mean\n * two verification paths for the same money.\n */\nexport const PAYMENT_HEADER = 'payment-signature';\n\n/** HTTP response header carrying the settlement result. */\nexport const PAYMENT_RESPONSE_HEADER = 'payment-response';\n\n/**\n * HTTP response header carrying the base64 payment challenge on a 402.\n *\n * The 402 body still carries {@link PaymentRequiredEnvelope} — richer, and the\n * only channel MCP has — but an x402 v2 client reads the challenge from this\n * header and ignores the body, so both are sent.\n */\nexport const PAYMENT_REQUIRED_HEADER = 'payment-required';\n\n/**\n * Key under which a protocol adapter attaches a {@link DeliverySummary} to its\n * result metadata — MCP's `CallToolResult._meta`, and anywhere else a protocol\n * offers an out-of-band metadata channel.\n *\n * Frozen deliberately. The bug this whole mechanism exists to fix was two\n * surfaces disagreeing about what a payer gets back; a key name enforced only\n * by one side's tests would reintroduce exactly that drift. Producer and\n * consumer both import this constant.\n *\n * Follows MCP's `<namespace>/<name>` convention for `_meta` keys.\n */\nexport const DELIVERY_SUMMARY_META_KEY = 'agent-commerce/delivery';\n\nexport interface PaymentRequiredEnvelope {\n readonly status: 'payment-required';\n readonly code: 'PAYMENT_REQUIRED';\n readonly requestId: string;\n readonly resourceId: string;\n readonly message: string;\n readonly payment: {\n readonly provider: PaymentMethodName;\n readonly version: string;\n readonly amount: DecimalAmount;\n readonly currency: string;\n readonly destination: string;\n readonly network?: string;\n readonly asset?: string;\n readonly expiresAt?: IsoTimestamp;\n /** Provider-native requirement objects, passed through verbatim. */\n readonly accepts: readonly Readonly<Record<string, unknown>>[];\n /**\n * The provider's own challenge document, verbatim — see\n * {@link PaymentChallenge.envelope}. Present for providers that have one;\n * a buyer's protocol client can hand this straight to its SDK.\n */\n readonly envelope?: Readonly<Record<string, unknown>>;\n };\n}\n\nexport interface ErrorEnvelope {\n readonly status: 'error';\n readonly code: CommerceErrorCode;\n readonly message: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly resourceId?: string;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * What a buyer learns about their own completed purchase.\n *\n * A payer is entitled to the record of their own transaction — the request it\n * belonged to, whether it settled, and the settlement reference they can check\n * on-chain. They are NOT entitled to the merchant's ledger, which is why\n * `/api/receipts` is an operator route behind `server.adminToken`.\n *\n * Before this existed the two surfaces disagreed: HTTP callers received a\n * settlement summary in the payment-response header while MCP callers received\n * nothing, so an MCP buyer's only route to their own receipt was the merchant's\n * ledger. Both surfaces now emit this same shape.\n */\nexport interface DeliverySummary {\n readonly requestId: string;\n readonly resourceId: string;\n readonly receiptId: string;\n readonly deliveredAt: IsoTimestamp;\n readonly payment?: {\n readonly status: 'verified' | 'settled' | 'rejected';\n readonly amount: DecimalAmount;\n readonly currency: string;\n /** Settlement reference, e.g. an on-chain transaction hash. */\n readonly externalReference?: string;\n readonly network?: string;\n };\n}\n\n/** Build the payer-facing summary of a delivered outcome. */\nexport function toDeliverySummary(outcome: DeliveredOutcome): DeliverySummary {\n const p = outcome.payment;\n return {\n requestId: outcome.requestId,\n resourceId: outcome.resourceId,\n receiptId: outcome.receipt.id,\n deliveredAt: outcome.receipt.deliveredAt,\n ...(p !== undefined\n ? {\n payment: {\n status: p.status,\n amount: p.amount,\n currency: p.currency,\n ...(p.externalReference !== undefined\n ? { externalReference: p.externalReference }\n : {}),\n ...(p.network !== undefined ? { network: p.network } : {}),\n },\n }\n : {}),\n };\n}\n\nexport function toPaymentRequiredEnvelope(\n outcome: PaymentRequiredOutcome,\n): PaymentRequiredEnvelope {\n const r = outcome.requirement;\n return {\n status: 'payment-required',\n code: 'PAYMENT_REQUIRED',\n requestId: outcome.requestId,\n resourceId: outcome.resourceId,\n message: `Payment of ${r.amount} ${r.currency} is required for resource \"${outcome.resourceId}\". Retry with a ${r.provider} payment proof.`,\n payment: {\n provider: r.provider,\n version: r.challenge.version,\n amount: r.amount,\n currency: r.currency,\n destination: r.destination,\n ...(r.network !== undefined ? { network: r.network } : {}),\n ...(r.asset !== undefined ? { asset: r.asset } : {}),\n ...(r.expiresAt !== undefined ? { expiresAt: r.expiresAt } : {}),\n accepts: r.challenge.accepts,\n ...(r.challenge.envelope !== undefined ? { envelope: r.challenge.envelope } : {}),\n },\n };\n}\n\nexport function toErrorEnvelope(error: CommerceError): ErrorEnvelope {\n const info = error.toInfo();\n return {\n status: 'error',\n code: info.code,\n message: info.message,\n retryable: info.retryable,\n ...(info.requestId !== undefined ? { requestId: info.requestId } : {}),\n ...(info.resourceId !== undefined ? { resourceId: info.resourceId } : {}),\n ...(info.details !== undefined ? { details: info.details } : {}),\n };\n}\n\nexport function isPaymentRequiredEnvelope(value: unknown): value is PaymentRequiredEnvelope {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as PaymentRequiredEnvelope).status === 'payment-required' &&\n typeof (value as PaymentRequiredEnvelope).payment === 'object'\n );\n}\n","/**\n * Typed domain error codes.\n *\n * FROZEN CONTRACT. Protocol adapters map these codes into their own response\n * format. Never throw a bare string or untyped Error across a package boundary.\n */\nexport const COMMERCE_ERROR_CODES = [\n 'CONFIG_INVALID',\n 'RESOURCE_NOT_FOUND',\n 'INPUT_INVALID',\n 'PAYMENT_REQUIRED',\n 'PAYMENT_INVALID',\n 'PAYMENT_REPLAYED',\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'PAYMENT_SETTLEMENT_FAILED',\n 'BACKEND_TIMEOUT',\n 'BACKEND_ERROR',\n 'PROTOCOL_UNSUPPORTED',\n 'GATEWAY_BUSY',\n 'STORAGE_ERROR',\n 'INTERNAL_ERROR',\n] as const;\n\nexport type CommerceErrorCode = (typeof COMMERCE_ERROR_CODES)[number];\n\n/**\n * Canonical HTTP status for each error code.\n *\n * Paid resources fail closed: every payment failure maps to a 4xx/5xx status\n * and never to a successful delivery.\n */\nexport const COMMERCE_ERROR_HTTP_STATUS: Readonly<Record<CommerceErrorCode, number>> = {\n CONFIG_INVALID: 500,\n RESOURCE_NOT_FOUND: 404,\n INPUT_INVALID: 400,\n PAYMENT_REQUIRED: 402,\n PAYMENT_INVALID: 402,\n PAYMENT_REPLAYED: 409,\n PAYMENT_PROVIDER_UNAVAILABLE: 503,\n PAYMENT_SETTLEMENT_FAILED: 502,\n BACKEND_TIMEOUT: 504,\n BACKEND_ERROR: 502,\n PROTOCOL_UNSUPPORTED: 501,\n GATEWAY_BUSY: 503,\n STORAGE_ERROR: 500,\n INTERNAL_ERROR: 500,\n};\n\n/** Codes for which a client may reasonably retry the same request. */\nexport const RETRYABLE_ERROR_CODES: ReadonlySet<CommerceErrorCode> = new Set([\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'BACKEND_TIMEOUT',\n // Load shedding is transient by definition: the caller should back off and\n // try again. Before this code existed the MCP adapter's queue-full path threw\n // PROTOCOL_UNSUPPORTED — HTTP 501, retryable:false — so an agent framework\n // keyed on the machine-readable flag (which exists precisely so clients need\n // not parse prose) would read a momentary throttle as a permanent capability\n // gap and stop calling the tool.\n 'GATEWAY_BUSY',\n]);\n","/**\n * The single error type crossing package boundaries.\n *\n * FROZEN CONTRACT.\n */\nimport {\n COMMERCE_ERROR_HTTP_STATUS,\n type CommerceErrorCode,\n RETRYABLE_ERROR_CODES,\n} from './codes.js';\n\nexport interface CommerceErrorOptions {\n /** Structured, non-secret detail safe to return to a client. */\n readonly details?: Readonly<Record<string, unknown>>;\n readonly cause?: unknown;\n readonly requestId?: string;\n readonly resourceId?: string;\n /** Override the default HTTP status for this code. */\n readonly httpStatus?: number;\n}\n\n/** Serialisable wire form of a CommerceError. */\nexport interface CommerceErrorInfo {\n readonly code: CommerceErrorCode;\n readonly message: string;\n readonly httpStatus: number;\n readonly retryable: boolean;\n readonly requestId?: string;\n readonly resourceId?: string;\n readonly details?: Readonly<Record<string, unknown>>;\n}\n\nexport class CommerceError extends Error {\n readonly code: CommerceErrorCode;\n readonly httpStatus: number;\n readonly retryable: boolean;\n readonly details?: Readonly<Record<string, unknown>>;\n readonly requestId?: string;\n readonly resourceId?: string;\n\n constructor(code: CommerceErrorCode, message: string, options: CommerceErrorOptions = {}) {\n super(message, options.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = 'CommerceError';\n this.code = code;\n this.httpStatus = options.httpStatus ?? COMMERCE_ERROR_HTTP_STATUS[code];\n this.retryable = RETRYABLE_ERROR_CODES.has(code);\n if (options.details !== undefined) this.details = options.details;\n if (options.requestId !== undefined) this.requestId = options.requestId;\n if (options.resourceId !== undefined) this.resourceId = options.resourceId;\n Error.captureStackTrace?.(this, CommerceError);\n }\n\n /** Non-secret, client-safe representation. */\n toInfo(): CommerceErrorInfo {\n return {\n code: this.code,\n message: this.message,\n httpStatus: this.httpStatus,\n retryable: this.retryable,\n ...(this.requestId !== undefined ? { requestId: this.requestId } : {}),\n ...(this.resourceId !== undefined ? { resourceId: this.resourceId } : {}),\n ...(this.details !== undefined ? { details: this.details } : {}),\n };\n }\n}\n\nexport function isCommerceError(value: unknown): value is CommerceError {\n return value instanceof CommerceError;\n}\n\n/**\n * Normalise any thrown value into a CommerceError.\n *\n * Used at package boundaries so an unexpected failure never escapes untyped.\n *\n * SECURITY — do not \"improve\" this by propagating `value.message`.\n * `CommerceError.message` is client-visible: it is serialised by `toInfo()`\n * and `toErrorEnvelope()` and returned over HTTP and MCP. An arbitrary thrown\n * Error's message routinely carries internal detail — database connection\n * strings, internal hostnames, filesystem paths, backend URLs. Copying it into\n * a client-facing field turns every unexpected exception into an information\n * disclosure.\n *\n * The original value is preserved on `cause`, which is never serialised, so\n * logs and diagnostics keep the full detail while clients get only the\n * caller's deliberate, reviewed `fallbackMessage`.\n *\n * A caller that *wants* a specific client-facing message passes one:\n * toCommerceError(err, 'BACKEND_ERROR', 'Backend call failed')\n */\nexport function toCommerceError(\n value: unknown,\n fallbackCode: CommerceErrorCode = 'INTERNAL_ERROR',\n fallbackMessage = 'Unexpected internal error',\n): CommerceError {\n if (isCommerceError(value)) return value;\n return new CommerceError(fallbackCode, fallbackMessage, { cause: value });\n}\n","export * from './codes.js';\nexport * from './commerce-error.js';\n","/**\n * Minimal structural logger interface.\n *\n * Core must not depend on pino directly; the gateway injects a pino instance\n * that satisfies this shape. Never log secrets: private keys, seed phrases,\n * Authorization headers or payment authorisation payloads.\n */\nexport interface Logger {\n debug(obj: Record<string, unknown>, msg?: string): void;\n info(obj: Record<string, unknown>, msg?: string): void;\n warn(obj: Record<string, unknown>, msg?: string): void;\n error(obj: Record<string, unknown>, msg?: string): void;\n child(bindings: Record<string, unknown>): Logger;\n}\n\n/** A logger that discards everything. Useful in unit tests. */\nexport const NOOP_LOGGER: Logger = {\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n child: () => NOOP_LOGGER,\n};\n","/**\n * Protocol adapter boundary.\n *\n * FROZEN CONTRACT. An adapter translates a protocol's wire format into a\n * `CanonicalRequest`, hands it to the execution pipeline and maps the outcome\n * back. It must not call merchant backends, implement payment logic, or hold\n * its own copy of the canonical model.\n *\n * Adapter isolation: a failure while starting or serving one adapter must not\n * prevent the others from operating.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { AdapterDescriptor, AdapterHealth, ProtocolName } from '../domain/common.js';\nimport type { EventSink } from '../domain/event.js';\nimport type { ExecutionPipeline } from '../domain/request.js';\nimport type { ResourceRegistry } from '../domain/resource.js';\nimport type { Logger } from './logger.js';\nimport type { Clock, IdGenerator } from './runtime.js';\n\n/** Everything an adapter is given. Nothing else is available to it. */\nexport interface ProtocolAdapterContext {\n readonly pipeline: ExecutionPipeline;\n readonly resources: ResourceRegistry;\n readonly events: EventSink;\n readonly logger: Logger;\n readonly clock: Clock;\n readonly ids: IdGenerator;\n /** Externally reachable base URL of the gateway, from config. */\n readonly publicBaseUrl: string;\n}\n\nexport interface ProtocolAdapter {\n readonly name: ProtocolName;\n readonly descriptor: AdapterDescriptor;\n\n start(context: ProtocolAdapterContext): Promise<void>;\n health(): Promise<AdapterHealth>;\n stop(): Promise<void>;\n}\n\n/**\n * A protocol adapter served over HTTP.\n *\n * The gateway mounts `handleHttp` at `mountPath` using raw Node request and\n * response objects, so adapters stay independent of the HTTP framework.\n *\n * GUARANTEE — the request body is **unconsumed**.\n *\n * `req` is handed over with its stream unread: the gateway suppresses every\n * body parser on this mount, so an adapter whose SDK reads the body itself\n * (MCP's Streamable HTTP transport does) can do so. The adapter owns reading,\n * size-limiting beyond the gateway's own cap, and parsing.\n *\n * This is load-bearing and easy to break silently. Fastify pre-registers\n * exact-match parsers for `application/json` and `text/plain` and prefers them\n * over a `'*'` wildcard, so registering only a wildcard no-op leaves the\n * built-in JSON parser draining the body first — the adapter then reads an\n * empty stream and every request fails to parse. That exact regression shipped\n * once and no unit test caught it, because adapter conformance suites drive\n * `handleHttp` over a bare `node:http` server and never traverse the gateway.\n *\n * Any change to how adapters are mounted must be covered by a test that POSTs\n * a real JSON body through the real gateway and asserts the adapter received\n * it intact.\n */\nexport interface HttpProtocolAdapter extends ProtocolAdapter {\n /** Path prefix the gateway mounts this adapter at, e.g. '/mcp'. */\n readonly mountPath: string;\n handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;\n /**\n * Fixed paths this adapter owns *outside* its mount, for protocols whose\n * specification pins a discovery URL (A2A's `/.well-known/agent-card.json`).\n * The gateway mounts them with the same guarantees as `mountPath` — same\n * unconsumed body, same concurrency cap, same failure isolation — so the\n * gateway needs no per-protocol routing knowledge.\n *\n * Omitted by adapters that need none.\n */\n readonly additionalHttpRoutes?: readonly AdapterHttpRoute[];\n}\n\n/**\n * One fixed, method-scoped route owned by an adapter. Unlike `mountPath` it\n * registers no wildcard: it matches exactly the path given.\n */\nexport interface AdapterHttpRoute {\n readonly method: 'GET' | 'POST';\n /** Absolute gateway path, e.g. '/.well-known/agent-card.json'. */\n readonly path: string;\n handleHttp(req: IncomingMessage, res: ServerResponse): Promise<void>;\n}\n\nexport function isHttpProtocolAdapter(adapter: ProtocolAdapter): adapter is HttpProtocolAdapter {\n return typeof (adapter as HttpProtocolAdapter).handleHttp === 'function';\n}\n","/**\n * Injected runtime primitives.\n *\n * Everything non-deterministic (time, ids) is injected so tests can be exact.\n */\nimport type { IsoTimestamp } from '../domain/common.js';\n\nexport interface Clock {\n now(): Date;\n nowIso(): IsoTimestamp;\n /** Milliseconds since an arbitrary origin; use for durations only. */\n monotonicMs(): number;\n}\n\nexport interface IdGenerator {\n /** Opaque, collision-resistant identifier. */\n next(prefix?: string): string;\n}\n\nexport const systemClock: Clock = {\n now: () => new Date(),\n nowIso: () => new Date().toISOString(),\n monotonicMs: () => performance.now(),\n};\n","/**\n * ============================================================================\n * FROZEN PUBLIC CONTRACT — frozen at v0.1.0-alpha\n * ============================================================================\n *\n * Every cross-package type and interface in the project is re-exported here.\n * This barrel is frozen. Everything reachable from it is public API that\n * consumers code against, so a change to any of it is a breaking change and\n * needs the decision record updated to match.\n *\n * Do not redeclare these shapes locally. If something is missing, add it here\n * rather than creating a parallel type.\n *\n * See docs/contracts.md for the freeze record.\n */\n\n// --- canonical domain ------------------------------------------------------\nexport type {\n AdapterDescriptor,\n AdapterHealth,\n DecimalAmount,\n IsoTimestamp,\n JsonSchema,\n PaymentMethodName,\n ProtocolName,\n} from './domain/common.js';\nexport { PROTOCOL_NAMES } from './domain/common.js';\nexport type { CommerceEvent, CommerceEventType, EventSink } from './domain/event.js';\nexport { COMMERCE_EVENT_TYPES } from './domain/event.js';\n\nexport type {\n PaymentChallenge,\n PaymentContext,\n PaymentProvider,\n PaymentRequirement,\n PaymentResult,\n PaymentSettlementContext,\n PaymentSubmission,\n PaymentVerificationContext,\n} from './domain/payment.js';\n\nexport type { CommerceReceipt, PaymentAttempt } from './domain/receipt.js';\nexport type {\n CanonicalRequest,\n DeliveredOutcome,\n ExecutionOutcome,\n ExecutionPipeline,\n PaymentRequiredOutcome,\n} from './domain/request.js';\nexport type {\n BackendHandler,\n BackendMethod,\n CommerceResource,\n Pricing,\n ResourceRegistry,\n} from './domain/resource.js';\nexport { DEFAULT_BACKEND_TIMEOUT_MS } from './domain/resource.js';\nexport type {\n DeliverySummary,\n ErrorEnvelope,\n PaymentRequiredEnvelope,\n} from './domain/wire.js';\nexport {\n DELIVERY_SUMMARY_META_KEY,\n isPaymentRequiredEnvelope,\n PAYMENT_HEADER,\n PAYMENT_INPUT_FIELD,\n PAYMENT_REQUIRED_HEADER,\n PAYMENT_RESPONSE_HEADER,\n toDeliverySummary,\n toErrorEnvelope,\n toPaymentRequiredEnvelope,\n} from './domain/wire.js';\n\n// --- errors ----------------------------------------------------------------\nexport type { CommerceErrorCode, CommerceErrorInfo, CommerceErrorOptions } from './errors/index.js';\nexport {\n COMMERCE_ERROR_CODES,\n COMMERCE_ERROR_HTTP_STATUS,\n CommerceError,\n isCommerceError,\n RETRYABLE_ERROR_CODES,\n toCommerceError,\n} from './errors/index.js';\n\n// --- injection boundaries --------------------------------------------------\nexport type { BackendExecutor, BackendRequest, BackendResponse } from './interfaces/backend.js';\nexport type { Logger } from './interfaces/logger.js';\nexport { NOOP_LOGGER } from './interfaces/logger.js';\nexport type {\n AdapterHttpRoute,\n HttpProtocolAdapter,\n ProtocolAdapter,\n ProtocolAdapterContext,\n} from './interfaces/protocol-adapter.js';\nexport { isHttpProtocolAdapter } from './interfaces/protocol-adapter.js';\nexport type { Clock, IdGenerator } from './interfaces/runtime.js';\nexport { systemClock } from './interfaces/runtime.js';\nexport type {\n ListOptions,\n PaymentAttemptReservation,\n PaymentAttemptUpdate,\n ReceiptStore,\n} from './interfaces/store.js';\n","/**\n * src/core\n *\n * Canonical commerce domain model, typed errors and the execution pipeline.\n * Contains no protocol- or payment-rail-specific code.\n */\nexport * from './public-types.js';\n","/**\n * The only outbound HTTP path to a merchant backend.\n *\n * - Uses global `fetch` and always applies a bound timeout via `AbortSignal.timeout`.\n * - `redirect: 'manual'` - a 3xx response is treated as a `BACKEND_ERROR`, never\n * followed (SSRF hardening).\n * - `{param}` segments in `handler.url` are filled from validated input and\n * URL-encoded; whatever remains goes to the query string (GET/DELETE) or a\n * JSON body (POST/PUT/PATCH). `handler.inputBindings` replaces that\n * leftover rule with one that names each group explicitly - see\n * `buildBackendRequestParts`.\n */\nimport {\n type BackendHandler,\n type BackendMethod,\n DEFAULT_BACKEND_TIMEOUT_MS,\n} from '../domain/resource.js';\nimport { CommerceError } from '../errors/index.js';\nimport type { BackendExecutor, BackendRequest, BackendResponse } from '../interfaces/backend.js';\nimport { type Logger, NOOP_LOGGER } from '../interfaces/logger.js';\n\nconst MAX_BODY_SNIPPET_LENGTH = 512;\n/**\n * The one canonical `{param}` grammar. Extraction, substitution, the config\n * gate and `doctor`'s probe all go through it.\n *\n * `-` and `.` are admitted: `/report/{report-id}` is ordinary\n * REST, and under the previous `[a-zA-Z0-9_]+` class it matched *nothing*. It\n * was therefore invisible to the config gate, survived substitution as a\n * literal, and a paid resource settled the buyer's payment before sending\n * `/report/%7Breport-id%7D` to a backend that 404s - the earlier money bug,\n * reachable again through the character class rather than through the check.\n */\nconst PATH_PARAM_PATTERN = /\\{([a-zA-Z0-9_.-]+)\\}/g;\n/** A hostile or broken backend can otherwise materialise an arbitrarily\n * large response in memory - AbortSignal.timeout bounds it by *time*, not\n * bytes. 1 MB is generous for a JSON API response. */\nconst MAX_RESPONSE_BODY_BYTES = 1024 * 1024;\n\nexport interface HttpBackendExecutorOptions {\n /** Override for `fetch`, used in tests. Defaults to the global implementation. */\n readonly fetchImpl?: typeof fetch;\n /** A non-2xx backend body is logged here (debug), never shipped to the client. */\n readonly logger?: Logger;\n}\n\nexport class HttpBackendExecutor implements BackendExecutor {\n private readonly fetchImpl: typeof fetch;\n private readonly logger: Logger;\n\n constructor(options: HttpBackendExecutorOptions = {}) {\n this.fetchImpl = options.fetchImpl ?? fetch;\n this.logger = options.logger ?? NOOP_LOGGER;\n }\n\n async call(handler: BackendHandler, request: BackendRequest): Promise<BackendResponse> {\n const timeoutMs = handler.timeoutMs ?? DEFAULT_BACKEND_TIMEOUT_MS;\n const inputRecord = isPlainObject(request.input) ? request.input : {};\n\n const context = { requestId: request.requestId, resourceId: request.resourceId };\n // Throws INPUT_INVALID for every shape problem. The pipeline already ran\n // the same call pre-payment through validateBackendRequestShape(); this is\n // defence in depth for a caller that bypasses it, not the normal path.\n const parts = buildBackendRequestParts(handler, inputRecord, context);\n\n let target: URL;\n try {\n target = new URL(parts.url);\n } catch (error) {\n throw new CommerceError('BACKEND_ERROR', 'Backend URL could not be constructed from input', {\n ...context,\n details: { reason: 'invalid-url' },\n cause: error,\n });\n }\n\n // Belt-and-braces beyond the per-parameter check above: whatever the\n // templated path resolved to must still live under the template's own\n // literal (pre-`{param}`) prefix. Templating something other than a path\n // segment (e.g. the host) is not a documented usage; if the literal\n // prefix does not even parse as a URL, skip this extra check rather than\n // fail a request the per-parameter check already covers.\n const literalPrefix = handler.url.split('{')[0] ?? handler.url;\n try {\n const literalPrefixPathname = new URL(literalPrefix).pathname;\n if (!target.pathname.startsWith(literalPrefixPathname)) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'Path parameters resolved outside the configured backend path',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n },\n );\n }\n } catch (error) {\n if (error instanceof CommerceError) throw error;\n }\n\n const headers: Record<string, string> = { ...(handler.headers ?? {}) };\n let body: string | undefined;\n\n //.set() REPLACES an existing param, so without this check a caller\n // input key with the same name as an operator-baked-in query param\n // (?apikey=SECRET in handler.url) silently overwrites it.\n // Shared with validateBackendRequestShape() - that copy runs\n // *before* payment, this one is defence in depth.\n checkQueryCollision(target, parts.query, context);\n for (const [key, value] of Object.entries(parts.query)) {\n target.searchParams.set(key, stringifyPrimitive(value));\n }\n if (parts.body !== undefined) {\n body = JSON.stringify(parts.body.value);\n // A configured Content-Type stays authoritative: a backend wanting\n // `application/vnd.x+json` says so in config and we do not override it.\n if (!hasHeader(headers, 'content-type')) {\n headers['content-type'] = 'application/json';\n }\n }\n\n const started = performance.now();\n let response: Response;\n try {\n response = await this.fetchImpl(target, {\n method: handler.method,\n headers,\n ...(body !== undefined ? { body } : {}),\n redirect: 'manual',\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n const durationMs = Math.round(performance.now() - started);\n if (isAbortError(error)) {\n throw new CommerceError(\n 'BACKEND_TIMEOUT',\n `Backend request timed out after ${timeoutMs}ms`,\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { timeoutMs, durationMs },\n cause: error,\n },\n );\n }\n throw new CommerceError('BACKEND_ERROR', 'Backend request failed (transport error)', {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { durationMs },\n cause: error,\n });\n }\n const durationMs = Math.round(performance.now() - started);\n\n const isRedirect =\n response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400);\n if (isRedirect) {\n throw new CommerceError(\n 'BACKEND_ERROR',\n 'Backend responded with a redirect, which is not followed',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { status: response.status, reason: 'redirect-not-followed' },\n },\n );\n }\n\n const responseHeaders = headersToRecord(response.headers);\n const contentType = response.headers.get('content-type') ?? '';\n let parsedBody: unknown;\n try {\n parsedBody = await parseBody(response, contentType);\n } catch (error) {\n const tooLarge =\n error instanceof Error && error.message.startsWith('response-body-too-large');\n throw new CommerceError(\n 'BACKEND_ERROR',\n tooLarge\n ? 'Backend response exceeded the maximum allowed size'\n : 'Backend response could not be read',\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: tooLarge\n ? { reason: 'response-too-large', maxBytes: MAX_RESPONSE_BODY_BYTES }\n : { reason: 'read-error' },\n cause: error,\n },\n );\n }\n\n if (response.status < 200 || response.status >= 300) {\n // The backend status is ours to state; the backend's own response body\n // is not - a merchant backend in verbose/dev-error mode routinely\n // emits stack traces, hostnames or SQL fragments, and this gateway is\n // not the one who gets to decide those are safe to forward to whoever\n // called the (possibly free, possibly unauthenticated) resource. Log\n // it for the operator; never put it in a client-visible field.\n this.logger.debug(\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n status: response.status,\n bodySnippet: truncateSnippet(parsedBody),\n },\n 'Backend responded with a non-2xx status',\n );\n throw new CommerceError('BACKEND_ERROR', `Backend responded with status ${response.status}`, {\n requestId: request.requestId,\n resourceId: request.resourceId,\n details: { status: response.status },\n });\n }\n\n return {\n status: response.status,\n headers: responseHeaders,\n body: parsedBody,\n durationMs,\n };\n }\n}\n\n/**\n * The traversal and query-collision checks below must run before payment,\n * not only inside `call()` - pipeline step 6, which is *after*\n * verify -> reserve -> settle.\n * Both throw INPUT_INVALID, which schema validation (step 2) cannot catch\n * (it validates against `resource.inputSchema`, which knows nothing about\n * the URL template a bad value would collide with). Concretely: a paid,\n * path-templated resource called with `{ city: \"\" }` would settle the buyer's\n * payment on-chain and then never call the backend - payment without\n * delivery, no refund, no release of the reserved authorisation. Both\n * checks are pure functions of `(handler.url, input)` with no I/O, so the\n * pipeline calls this immediately after schema validation, *before* price\n * resolution - before any payment provider is even selected. `call()` keeps\n * its own copy as defence in depth (it is a public class; the pipeline is\n * not the only possible caller).\n */\n/**\n * `{param}` names in a `backend.url` template, in declaration order.\n * Exported so `src/config`'s `normaliseResource` can\n * cross-check every template parameter against the resource's input schema\n * at config load - the same regex, not a second copy that could silently\n * drift out of sync with what this file actually treats as a path\n * parameter.\n */\nexport function extractPathParameterNames(url: string): string[] {\n return [...url.matchAll(PATH_PARAM_PATTERN)].map((match) => match[1] as string);\n}\n\n/**\n * A brace left over after every legal `{param}` is removed, or `undefined`.\n *\n * Widening the grammar fixes the *common* spelling; it cannot fix every one.\n * `{report id}`, `{a/b}`, `{}` and an unbalanced `{` still match nothing, and\n * \"matches nothing\" is precisely the silent-literal shape that costs a buyer\n * money on a paid resource. So the rule is inverted: rather than enumerating\n * what is illegal, anything brace-shaped that is *not* a recognised parameter\n * is refused at config load. Exported so `src/config` applies it - the\n * grammar and its residue must never live in two files.\n */\nexport function findUnparsedBraceToken(url: string): string | undefined {\n const residue = url.replace(PATH_PARAM_PATTERN, '');\n const index = residue.search(/[{}]/);\n if (index === -1) return undefined;\n // Report the offending run, not just the character, so the error is fixable.\n const token = /\\{[^{}]*\\}?|\\}/.exec(residue.slice(index));\n return token?.[0] ?? residue[index];\n}\n\nexport function validateBackendRequestShape(\n handler: BackendHandler,\n input: unknown,\n context: ShapeContext,\n): void {\n const inputRecord = isPlainObject(input) ? input : {};\n\n // Every shape error - missing or invalid path parameter, a bound group that\n // is not an object - throws INPUT_INVALID from here, before payment.\n const parts = buildBackendRequestParts(handler, inputRecord, context);\n\n let target: URL;\n try {\n target = new URL(parts.url);\n } catch {\n return; // call() surfaces the real BACKEND_ERROR for an unparseable URL.\n }\n checkQueryCollision(target, parts.query, context);\n}\n\ntype ShapeContext = { readonly requestId: string; readonly resourceId: string };\n\n/** The path-templated URL plus the query and body values a request carries. */\ninterface BackendRequestParts {\n readonly url: string;\n readonly query: Record<string, unknown>;\n /** Present when a JSON body should be sent; `value` is what gets encoded. */\n readonly body?: { readonly value: unknown };\n}\n\nfunction acceptsBody(method: BackendMethod): boolean {\n return method !== 'GET' && method !== 'DELETE';\n}\n\n/**\n * Split validated input into URL, query and body according to\n * `handler.inputBindings` - the single place either mode is decided, so\n * `call()` and the pre-payment `validateBackendRequestShape()` can never\n * disagree about what request the input describes.\n *\n * Throws only `CommerceError('INPUT_INVALID')`, which is what makes it safe to\n * run before pricing.\n */\nfunction buildBackendRequestParts(\n handler: BackendHandler,\n input: Record<string, unknown>,\n context: ShapeContext,\n): BackendRequestParts {\n const bindings = handler.inputBindings;\n if (bindings === undefined) {\n const { url, remaining } = applyPathTemplate(handler.url, input, context);\n return acceptsBody(handler.method)\n ? { url, query: {}, body: { value: remaining } }\n : { url, query: remaining };\n }\n\n const pathValues =\n bindings.path === undefined ? {} : resolveBoundGroup(input, bindings.path, 'path', context);\n const { url } = applyPathTemplate(handler.url, pathValues, context);\n const query =\n bindings.query === undefined ? {} : resolveBoundGroup(input, bindings.query, 'query', context);\n\n // An absent body value sends no body at all rather than `null`: a request\n // body the operation does not require is simply not there. A body the\n // operation *does* require is caught one step earlier, by `required` in the\n // resource's input schema - also before payment.\n const bodyValue = bindings.body === undefined ? undefined : input[bindings.body];\n if (bodyValue === undefined || !acceptsBody(handler.method)) return { url, query };\n return { url, query, body: { value: bodyValue } };\n}\n\nfunction resolveBoundGroup(\n input: Record<string, unknown>,\n key: string,\n kind: 'path' | 'query',\n context: ShapeContext,\n): Record<string, unknown> {\n const value = input[key];\n if (value === undefined) return {};\n if (!isPlainObject(value)) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `Input \"${key}\" must be an object of ${kind} parameters`,\n { ...context, details: { field: key } },\n );\n }\n return value;\n}\n\nfunction checkQueryCollision(\n target: URL,\n remaining: Record<string, unknown>,\n context: { readonly requestId: string; readonly resourceId: string },\n): void {\n const templateKeys = new Set(target.searchParams.keys());\n for (const key of Object.keys(remaining)) {\n if (templateKeys.has(key)) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `Input key \"${key}\" collides with a query parameter already set on backend.url`,\n { requestId: context.requestId, resourceId: context.resourceId, details: { field: key } },\n );\n }\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n// encodeURIComponent does not escape \".\" - a raw \"..\"/\".\" path-parameter\n// value survives it and new URL() then normalises the segment away, letting\n// a caller step outside the template's own directory (bounded traversal:\n// slashes ARE escaped, so only removing segments, never adding them). Reject\n// these exact values at substitution time instead of shipping them.\nconst TRAVERSAL_PATH_VALUES = new Set(['', '.', '..']);\n\nfunction applyPathTemplate(\n template: string,\n input: Record<string, unknown>,\n context: ShapeContext,\n): { url: string; remaining: Record<string, unknown> } {\n const remaining: Record<string, unknown> = { ...input };\n let missing: string | undefined;\n let invalid: string | undefined;\n const url = template.replace(PATH_PARAM_PATTERN, (_match, key: string) => {\n // Object.hasOwn, not `key in remaining`: `in` also matches inherited\n // Object.prototype names (\"constructor\", \"toString\", …), which a\n // config-authored template naming a path param after one of them would\n // otherwise silently resolve to the wrong (inherited) value.\n if (!Object.hasOwn(remaining, key)) {\n missing = key;\n return '';\n }\n const value = remaining[key];\n delete remaining[key];\n const raw = stringifyPrimitive(value);\n if (TRAVERSAL_PATH_VALUES.has(raw)) {\n invalid = key;\n return '';\n }\n return encodeURIComponent(raw);\n });\n if (missing !== undefined) {\n // Tempting to shrug this off as a config/schema mismatch rather than bad\n // caller input. But a paid, `{param}`-templated resource whose input can\n // never supply it would reach settle() on every call - the buyer pays, the\n // backend is never called, no refund. `normaliseResource` (src/config) is\n // the root-cause fix, rejecting the shape at config load; throwing here\n // stops a hand-built `CommerceResource` from reintroducing the money bug\n // by skipping config validation.\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${missing}\" was not supplied`, {\n ...context,\n details: { field: missing },\n });\n }\n if (invalid !== undefined) {\n throw new CommerceError('INPUT_INVALID', `Path parameter \"${invalid}\" is not a valid value`, {\n ...context,\n details: { field: invalid },\n });\n }\n return { url, remaining };\n}\n\nfunction stringifyPrimitive(value: unknown): string {\n if (value === undefined || value === null) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction hasHeader(headers: Record<string, string>, name: string): boolean {\n const target = name.toLowerCase();\n return Object.keys(headers).some((key) => key.toLowerCase() === target);\n}\n\nfunction headersToRecord(headers: Headers): Record<string, string> {\n const record: Record<string, string> = {};\n headers.forEach((value, key) => {\n record[key] = value;\n });\n return record;\n}\n\nasync function readBodyCapped(response: Response, maxBytes: number): Promise<string> {\n if (!response.body) return '';\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > maxBytes) {\n await reader.cancel();\n throw new Error(`response-body-too-large:${maxBytes}`);\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n return Buffer.concat(chunks).toString('utf8');\n}\n\nasync function parseBody(response: Response, contentType: string): Promise<unknown> {\n const text = await readBodyCapped(response, MAX_RESPONSE_BODY_BYTES);\n if (text.length === 0) return text;\n if (contentType.includes('json')) {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n }\n return text;\n}\n\nfunction truncateSnippet(body: unknown): string {\n const text = typeof body === 'string' ? body : safeStringify(body);\n return text.length > MAX_BODY_SNIPPET_LENGTH\n ? `${text.slice(0, MAX_BODY_SNIPPET_LENGTH)}…`\n : text;\n}\n\nfunction safeStringify(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError');\n}\n","/**\n * Fan-out `EventSink`: persists every event to the receipt store and notifies\n * in-process subscribers (the gateway's SSE feed). Never throws to the caller —\n * a store or subscriber failure is caught and logged.\n */\nimport type { CommerceEvent, EventSink } from '../domain/event.js';\nimport type { Logger } from '../interfaces/logger.js';\nimport type { Clock, IdGenerator } from '../interfaces/runtime.js';\nimport type { ReceiptStore } from '../interfaces/store.js';\n\nexport interface CreateEventBusOptions {\n readonly store: ReceiptStore;\n readonly logger: Logger;\n /** Reserved for callers that want the bus to mint ids/timestamps itself. */\n readonly ids?: IdGenerator;\n readonly clock?: Clock;\n}\n\nexport interface EventBus extends EventSink {\n /** Subscribe to every emitted event. Returns an unsubscribe function. */\n subscribe(fn: (event: CommerceEvent) => void): () => void;\n}\n\nexport function createEventBus(options: CreateEventBusOptions): EventBus {\n const subscribers = new Set<(event: CommerceEvent) => void>();\n\n return {\n async emit(event: CommerceEvent): Promise<void> {\n try {\n await options.store.appendEvent(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Failed to persist commerce event',\n );\n }\n\n for (const subscriber of subscribers) {\n try {\n subscriber(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Event subscriber threw',\n );\n }\n }\n },\n\n subscribe(fn: (event: CommerceEvent) => void): () => void {\n subscribers.add(fn);\n return () => {\n subscribers.delete(fn);\n };\n },\n };\n}\n\nfunction describeError(error: unknown): { message: string; name?: string } {\n if (error instanceof Error) {\n return { message: error.message, name: error.name };\n }\n return { message: String(error) };\n}\n","/**\n * A small, honest JSON Schema validator for resource input.\n *\n * Supported subset (draft-2020-12 vocabulary, structural only):\n * - `type`: \"object\" | \"string\" | \"number\" | \"integer\" | \"boolean\" | \"array\" | \"null\",\n * or an array of any of those (draft-2020-12 union form, e.g. `[\"object\",\"null\"]`)\n * - `properties` (object schemas, validated recursively)\n * - `required` (string[])\n * - `additionalProperties` (boolean, or a schema applied to extra properties)\n * - `enum` (array of allowed literal values, deep-equality compared)\n * - `items` (single schema applied to every array element — no tuple form)\n *\n * Explicitly NOT supported and silently ignored (never enforced):\n * `minLength`, `maxLength`, `pattern`, `format`, `minimum`, `maximum`,\n * `exclusiveMinimum/Maximum`, `multipleOf`, `oneOf`, `anyOf`, `allOf`, `not`,\n * `$ref`, `const`, `patternProperties`, `minItems`, `maxItems`, `uniqueItems`,\n * tuple-style `items` arrays. An unrecognised `type` value is not enforced\n * either. This is a deliberate, documented limitation of this release — do\n * not assume any of the above is validated.\n */\nimport type { JsonSchema } from '../domain/common.js';\n\nexport interface FieldError {\n readonly path: string;\n readonly message: string;\n}\n\nexport type ValidationResult =\n | { readonly valid: true; readonly value: unknown }\n | { readonly valid: false; readonly errors: readonly FieldError[] };\n\nexport type Validator = (input: unknown) => ValidationResult;\n\nconst SUPPORTED_TYPES = new Set([\n 'object',\n 'string',\n 'number',\n 'integer',\n 'boolean',\n 'array',\n 'null',\n]);\n\n/** Compile a resource `inputSchema` into a reusable validator function. */\nexport function compileJsonSchema(schema: JsonSchema | undefined): Validator {\n return (input: unknown): ValidationResult => {\n if (schema === undefined) return { valid: true, value: input };\n const errors = validateNode(schema, input, '$');\n return errors.length === 0 ? { valid: true, value: input } : { valid: false, errors };\n };\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction matchesType(type: string, value: unknown): boolean {\n switch (type) {\n case 'object':\n return isPlainObject(value);\n case 'array':\n return Array.isArray(value);\n case 'string':\n return typeof value === 'string';\n case 'boolean':\n return typeof value === 'boolean';\n case 'number':\n return typeof value === 'number' && Number.isFinite(value);\n case 'integer':\n return typeof value === 'number' && Number.isInteger(value);\n case 'null':\n return value === null;\n default:\n return true;\n }\n}\n\nfunction describeType(value: unknown): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n return typeof value;\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (typeof a !== 'object') return false;\n try {\n return JSON.stringify(a) === JSON.stringify(b);\n } catch {\n return false;\n }\n}\n\nfunction own(obj: Record<string, unknown>, key: string): unknown {\n return Object.hasOwn(obj, key) ? obj[key] : undefined;\n}\n\n/**\n * `type` may be a single string or (draft-2020-12) an array of strings,\n * e.g. `[\"object\", \"null\"]`. Only recognised when every entry is a string —\n * same conservative \"skip rather than guess\" rule the single-string form\n * already followed for an unrecognised type name.\n */\nfunction typeList(raw: unknown): string[] | undefined {\n if (typeof raw === 'string') return [raw];\n if (Array.isArray(raw) && raw.every((entry): entry is string => typeof entry === 'string')) {\n return raw;\n }\n return undefined;\n}\n\n/**\n * A bare `type === 'object'` string comparison is not enough: `type:\n * [\"object\", \"null\"]` — valid JSON Schema — would never route into\n * `validateObject`, so neither `required` nor `additionalProperties` would be\n * enforced on it, while `defaultClosedObjectSchema` (src/config) stamps\n * `additionalProperties: false` on it believing it closed. Also treats a node\n * with `properties`/`required` and no `type`\n * at all as an object schema, the same shape config's own stamping already\n * recognises via a bare `properties` check — a schema author relying on\n * `type` being implied by `properties` should not be silently unenforced.\n *\n * **exported**, and now the only definition of \"this node is\n * an object schema\" in the codebase. `src/config`'s `defaultClosedObjectSchema`\n * carried its own — `declaresObjectType || properties` — one keyword short of\n * this one, so a schema declaring only `required` was stamped by neither:\n * config left it open and this validator then enforced nothing on it, quietly\n * forwarding every unknown caller key to the merchant's backend while\n * docs/security.md promised \"closed by default at every level\". These two\n * definitions have been aligned once already; keeping them as two definitions\n * is what let them drift again.\n */\nexport function isObjectSchemaNode(schema: Record<string, unknown>): boolean {\n const types = typeList(schema['type']);\n if (types !== undefined) return types.includes('object');\n return Object.hasOwn(schema, 'properties') || Object.hasOwn(schema, 'required');\n}\n\nfunction validateNode(schema: JsonSchema, value: unknown, path: string): FieldError[] {\n const errors: FieldError[] = [];\n const types = typeList(own(schema, 'type'));\n const recognisedTypes = types?.filter((entry) => SUPPORTED_TYPES.has(entry));\n\n if (\n types !== undefined &&\n recognisedTypes !== undefined &&\n recognisedTypes.length === types.length &&\n types.length > 0\n ) {\n if (!types.some((entry) => matchesType(entry, value))) {\n errors.push({\n path,\n message: `expected type \"${types.join(' | ')}\" but got ${describeType(value)}`,\n });\n return errors;\n }\n }\n\n const enumRaw = own(schema, 'enum');\n if (Array.isArray(enumRaw)) {\n const allowed = enumRaw as unknown[];\n if (!allowed.some((candidate) => deepEqual(candidate, value))) {\n errors.push({ path, message: `must be one of ${JSON.stringify(allowed)}` });\n }\n }\n\n if (isObjectSchemaNode(schema) && isPlainObject(value)) {\n errors.push(...validateObject(schema, value, path));\n } else if ((types?.includes('array') ?? false) && Array.isArray(value)) {\n errors.push(...validateArray(schema, value, path));\n }\n\n return errors;\n}\n\nfunction validateObject(\n schema: JsonSchema,\n value: Record<string, unknown>,\n path: string,\n): FieldError[] {\n const errors: FieldError[] = [];\n const propsRaw = own(schema, 'properties');\n const properties = isPlainObject(propsRaw) ? propsRaw : {};\n const requiredRaw = own(schema, 'required');\n const required = Array.isArray(requiredRaw)\n ? requiredRaw.filter((entry): entry is string => typeof entry === 'string')\n : [];\n\n for (const key of required) {\n // Object.hasOwn, not `in`: `in` walks the prototype chain, so a schema\n // requiring \"toString\"/\"constructor\"/\"valueOf\"/\"hasOwnProperty\"/\n // \"__proto__\" could never actually enforce it — those names are always\n // present via inheritance, so `!(key in value)` is always false. This is\n // the same bug class every other lookup in this file already\n // guards against by using own().\n if (!Object.hasOwn(value, key)) {\n errors.push({ path: `${path}.${key}`, message: 'is required' });\n }\n }\n\n const additional = own(schema, 'additionalProperties');\n\n for (const key of Object.keys(value)) {\n // Object.hasOwn, not `properties[key]`: a plain-object lookup for\n // \"__proto__\"/\"constructor\"/\"toString\"/\"valueOf\"/\"hasOwnProperty\" resolves\n // to an inherited Object.prototype member instead of undefined, so those\n // keys would otherwise silently skip the additionalProperties check below.\n const propSchemaRaw = own(properties, key);\n if (propSchemaRaw !== undefined) {\n if (isPlainObject(propSchemaRaw)) {\n errors.push(...validateNode(propSchemaRaw, value[key], `${path}.${key}`));\n }\n continue;\n }\n if (additional === false) {\n errors.push({ path: `${path}.${key}`, message: 'additional property not allowed' });\n } else if (isPlainObject(additional)) {\n errors.push(...validateNode(additional, value[key], `${path}.${key}`));\n }\n }\n\n return errors;\n}\n\nfunction validateArray(schema: JsonSchema, value: unknown[], path: string): FieldError[] {\n const errors: FieldError[] = [];\n const itemsRaw = own(schema, 'items');\n if (isPlainObject(itemsRaw)) {\n value.forEach((item, index) => {\n errors.push(...validateNode(itemsRaw, item, `${path}[${index}]`));\n });\n }\n return errors;\n}\n","/**\n * The single execution path every protocol adapter converges on.\n *\n * Order is a security boundary — do not reorder:\n * 1. resolve resource RESOURCE_NOT_FOUND\n * 2. strip `_payment`, validate input INPUT_INVALID\n * 3. resolve price\n * 4. free -> straight to backend\n * 5. paid -> pick provider -> createRequirement -> (challenge | verify ->\n * reserve replay key -> settle), fail closed at every step\n * 6. call backend BACKEND_TIMEOUT / BACKEND_ERROR\n * 7. persist receipt, emit events, return outcome\n */\n\nimport type { PaymentMethodName } from '../domain/common.js';\nimport type { CommerceEvent, EventSink } from '../domain/event.js';\nimport type { PaymentProvider, PaymentRequirement, PaymentResult } from '../domain/payment.js';\nimport type { CommerceReceipt } from '../domain/receipt.js';\nimport type { CanonicalRequest, ExecutionOutcome, ExecutionPipeline } from '../domain/request.js';\nimport type { CommerceResource, ResourceRegistry } from '../domain/resource.js';\nimport { PAYMENT_INPUT_FIELD } from '../domain/wire.js';\nimport { CommerceError, isCommerceError, toCommerceError } from '../errors/index.js';\nimport type { BackendExecutor, BackendResponse } from '../interfaces/backend.js';\nimport type { Logger } from '../interfaces/logger.js';\nimport type { Clock, IdGenerator } from '../interfaces/runtime.js';\nimport type { ReceiptStore } from '../interfaces/store.js';\nimport { validateBackendRequestShape } from './backend-http.js';\nimport { compileJsonSchema, type Validator } from './validation.js';\n\nexport interface CreateExecutionPipelineOptions {\n readonly resources: ResourceRegistry;\n readonly paymentProviders: readonly PaymentProvider[];\n readonly store: ReceiptStore;\n readonly backend: BackendExecutor;\n readonly events: EventSink;\n readonly logger: Logger;\n readonly clock: Clock;\n readonly ids: IdGenerator;\n}\n\nexport function createExecutionPipeline(\n options: CreateExecutionPipelineOptions,\n): ExecutionPipeline {\n const validators = new Map<string, Validator>();\n\n function getValidator(resource: CommerceResource): Validator {\n const cached = validators.get(resource.id);\n if (cached) return cached;\n const compiled = compileJsonSchema(resource.inputSchema);\n validators.set(resource.id, compiled);\n return compiled;\n }\n\n async function safeEmit(event: CommerceEvent): Promise<void> {\n try {\n await options.events.emit(event);\n } catch (error) {\n options.logger.error(\n { err: describeError(error), eventType: event.type, requestId: event.requestId },\n 'Event sink failed; commerce flow continues',\n );\n }\n }\n\n async function safePersist(\n op: () => Promise<void>,\n label: string,\n requestId: string,\n ): Promise<void> {\n try {\n await op();\n } catch (error) {\n options.logger.error(\n { err: describeError(error), requestId },\n `Persistence failed: ${label}`,\n );\n }\n }\n\n function buildEvent(partial: Omit<CommerceEvent, 'id' | 'at'>): CommerceEvent {\n return { id: options.ids.next('evt'), at: options.clock.nowIso(), ...partial };\n }\n\n async function execute(request: CanonicalRequest): Promise<ExecutionOutcome> {\n const pipelineStart = options.clock.monotonicMs();\n\n // 1. resolve resource\n const resource = options.resources.get(request.resourceId);\n // Same code, same message as a genuine miss: `expose` is an admin scoping\n // decision enforced on the one execution path every adapter shares — a\n // caller on a protocol the resource isn't exposed via must not be able to\n // distinguish \"doesn't exist\" from \"exists but not for you\".\n if (!resource || !resource.exposedVia.includes(request.protocol)) {\n throw new CommerceError(\n 'RESOURCE_NOT_FOUND',\n `Resource \"${request.resourceId}\" was not found`,\n {\n requestId: request.requestId,\n resourceId: request.resourceId,\n },\n );\n }\n\n await safeEmit(\n buildEvent({\n type: 'resource.requested',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n }),\n );\n\n // 2. strip reserved payment field, then validate input\n const strippedInput = stripPaymentField(request.input);\n const validation = getValidator(resource)(strippedInput);\n if (!validation.valid) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `Input for resource \"${resource.id}\" failed validation`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n details: { errors: validation.errors },\n },\n );\n }\n const validInput = validation.value;\n\n // validate the backend request shape (path-traversal, query-param\n // collision) here — before price resolution, so a resource that fails\n // this check never reaches payment. Both checks are pure functions of\n // (handler.url, input); doing them at pipeline step 6 (inside the actual\n // backend call) meant a bad value like `{ city: \"\" }` against a paid,\n // path-templated resource settled the buyer's payment and then never\n // called the backend at all — payment without delivery. call() keeps its\n // own copy of these checks as defence in depth.\n validateBackendRequestShape(resource.handler, validInput, {\n requestId: request.requestId,\n resourceId: resource.id,\n });\n\n // 3. resolve price\n if (resource.pricing.type === 'dynamic') {\n // Config validation rejects this before the gateway starts; this is defence-in-depth.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${resource.id}\" uses unsupported dynamic pricing`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n let paymentResult: PaymentResult | undefined;\n\n if (resource.pricing.type === 'fixed') {\n const pricing = resource.pricing;\n const provider = pickProvider(options.paymentProviders, resource.paymentMethods);\n if (!provider) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n `No enabled payment provider for resource \"${resource.id}\"`,\n {\n requestId: request.requestId,\n resourceId: resource.id,\n details: { paymentMethods: resource.paymentMethods },\n },\n );\n }\n\n let requirement: PaymentRequirement;\n try {\n requirement = await provider.createRequirement({\n requestId: request.requestId,\n resource,\n amount: pricing.amount,\n currency: pricing.currency,\n requestedAt: options.clock.nowIso(),\n });\n } catch (error) {\n throw isCommerceError(error)\n ? error\n : new CommerceError('PAYMENT_PROVIDER_UNAVAILABLE', 'Payment provider is unavailable', {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n });\n }\n\n if (!request.payment) {\n await safeEmit(\n buildEvent({\n type: 'payment.required',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n }),\n );\n return {\n kind: 'payment-required',\n requestId: request.requestId,\n resourceId: resource.id,\n requirement,\n };\n }\n\n const payment = request.payment;\n\n let verification: PaymentResult;\n try {\n verification = await provider.verify({\n requestId: request.requestId,\n resource,\n requirement,\n submission: payment,\n });\n } catch (error) {\n // Any typed CommerceError the provider throws is rethrown as-is (a\n // provider can legitimately fail with STORAGE_ERROR, etc. — flattening\n // every code to PAYMENT_INVALID would hide the real cause and the\n // real, possibly-retryable HTTP status). Only a genuinely untyped\n // throw is mapped, with a fixed client-facing message — never the\n // raw error's own message.\n const mapped = isCommerceError(error)\n ? error\n : new CommerceError('PAYMENT_INVALID', 'Payment verification failed', {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n });\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: mapped.code },\n }),\n );\n throw mapped;\n }\n\n if (verification.status !== 'verified') {\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: verification.rejectionReason ? { reason: verification.rejectionReason } : {},\n }),\n );\n throw new CommerceError(\n 'PAYMENT_INVALID',\n verification.rejectionReason ?? 'Payment was rejected',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n if (!verification.replayKey) {\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: 'missing-replay-key' },\n }),\n );\n throw new CommerceError('PAYMENT_INVALID', 'Payment provider did not return a replay key', {\n requestId: request.requestId,\n resourceId: resource.id,\n });\n }\n const replayKey = verification.replayKey;\n\n try {\n await options.store.reservePaymentAttempt({\n requestId: request.requestId,\n resourceId: resource.id,\n provider: provider.name,\n replayKey,\n amount: verification.amount,\n currency: verification.currency,\n ...(verification.payer !== undefined ? { payer: verification.payer } : {}),\n ...(verification.payee !== undefined ? { payee: verification.payee } : {}),\n });\n } catch (error) {\n // The store contract only promises PAYMENT_REPLAYED for an actual\n // duplicate replayKey (already a CommerceError with that code, so\n // isCommerceError below preserves it as-is). Anything else — a disk-\n // full error, a dropped connection — is a storage failure, not a\n // replay, and must not be mislabelled as one: telling a buyer\n // \"duplicate payment\" for a transient outage is actively false, and\n // poisons any alerting keyed on replay counts.\n const mapped = toCommerceError(\n error,\n 'STORAGE_ERROR',\n 'Payment attempt could not be recorded',\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: { reason: mapped.code },\n }),\n );\n throw mapped;\n }\n\n await safeEmit(\n buildEvent({\n type: 'payment.verified',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'ok',\n }),\n );\n\n let settlement: PaymentResult;\n try {\n settlement = await provider.settle({\n requestId: request.requestId,\n resource,\n requirement,\n submission: payment,\n verification,\n });\n } catch (error) {\n // / \"the RPC did not answer\" and \"the transfer did not\n // happen\" are different facts. A provider that broadcast a settlement\n // transaction and then failed to confirm it throws\n // PAYMENT_PROVIDER_UNAVAILABLE with details.transactionHash attached\n // (the hash is known before confirmation). Recording that as plain\n // `failed` would tell the merchant's reconciliation artefact a\n // falsehood — the buyer's funds may already have moved. The resource\n // is still not delivered either way: only what gets *recorded*\n // changes, never the fail-closed outcome.\n const uncertainTxHash = uncertainSettlementTxHash(error);\n await safePersist(\n () =>\n options.store.updatePaymentAttempt(\n uncertainTxHash !== undefined\n ? { replayKey, status: 'settlement-uncertain', externalReference: uncertainTxHash }\n : {\n replayKey,\n status: 'failed',\n ...(error instanceof Error ? { rejectionReason: error.message } : {}),\n },\n ),\n uncertainTxHash !== undefined\n ? 'updatePaymentAttempt(settlement-uncertain)'\n : 'updatePaymentAttempt(failed)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data:\n uncertainTxHash !== undefined\n ? { reason: 'settlement-uncertain', transactionHash: uncertainTxHash }\n : { reason: 'settlement-threw' },\n }),\n );\n // The merchant's record now tells the truth (above); the buyer must\n // too — they are the party whose funds may have moved, and the\n // client-visible error is their only way to find out. Code stays\n // PAYMENT_SETTLEMENT_FAILED (not PAYMENT_PROVIDER_UNAVAILABLE, which\n // is retryable) — a retry would reuse the already-reserved replay\n // key. The transaction hash is safe to disclose: it's the buyer's\n // own payment, public on-chain the moment it lands. Nothing else\n // from the underlying error travels — only this flag and the hash.\n throw new CommerceError(\n 'PAYMENT_SETTLEMENT_FAILED',\n uncertainTxHash !== undefined\n ? 'Settlement could not be confirmed'\n : 'Payment settlement failed',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: error,\n ...(uncertainTxHash !== undefined\n ? { details: { settlementUncertain: true, transactionHash: uncertainTxHash } }\n : {}),\n },\n );\n }\n\n if (settlement.status !== 'settled') {\n await safePersist(\n () =>\n options.store.updatePaymentAttempt({\n replayKey,\n status: 'rejected',\n ...(settlement.rejectionReason !== undefined\n ? { rejectionReason: settlement.rejectionReason }\n : {}),\n }),\n 'updatePaymentAttempt(rejected)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.rejected',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'error',\n data: settlement.rejectionReason ? { reason: settlement.rejectionReason } : {},\n }),\n );\n throw new CommerceError(\n 'PAYMENT_SETTLEMENT_FAILED',\n settlement.rejectionReason ?? 'Settlement was rejected',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n },\n );\n }\n\n await safePersist(\n () =>\n options.store.updatePaymentAttempt({\n replayKey,\n status: 'settled',\n ...(settlement.externalReference !== undefined\n ? { externalReference: settlement.externalReference }\n : {}),\n }),\n 'updatePaymentAttempt(settled)',\n request.requestId,\n );\n await safeEmit(\n buildEvent({\n type: 'payment.settled',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n paymentProvider: provider.name,\n status: 'ok',\n }),\n );\n\n paymentResult = settlement;\n }\n\n // 6. call backend\n const backendStart = options.clock.monotonicMs();\n let backendResponse: BackendResponse;\n try {\n backendResponse = await options.backend.call(resource.handler, {\n requestId: request.requestId,\n resourceId: resource.id,\n input: validInput,\n });\n } catch (error) {\n const commerceError = toCommerceError(error, 'BACKEND_ERROR', 'Backend call failed');\n await safeEmit(\n buildEvent({\n type: 'backend.failed',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'error',\n durationMs: Math.round(options.clock.monotonicMs() - backendStart),\n data: { code: commerceError.code },\n }),\n );\n\n if (paymentResult !== undefined) {\n // Settlement already succeeded (verify -> reserve -> settle all\n // completed) before the backend call failed, so the\n // uncertain-settlement rule (\"the merchant's record now tells the\n // truth; the buyer must too\") applies to this far more common\n // *certain*-loss branch as well, not only to the uncertain-RPC-timeout\n // one 100 lines above. A backend 500 is more likely than an RPC\n // confirmation timeout, so disclosing strictly *less* here than there\n // would be backwards. The tx hash is\n // safe to disclose: it is the buyer's own payment, public\n // on-chain the moment it lands.\n const failedReceipt: CommerceReceipt = {\n id: options.ids.next('receipt'),\n requestId: request.requestId,\n resourceId: resource.id,\n deliveredAt: options.clock.nowIso(),\n backendStatus: backendErrorStatus(commerceError),\n protocol: request.protocol,\n payment: paymentResult,\n metadata: { delivered: false, backendErrorCode: commerceError.code },\n };\n await safePersist(\n () => options.store.saveReceipt(failedReceipt),\n 'saveReceipt(backend-failed-after-settlement)',\n request.requestId,\n );\n\n throw new CommerceError(\n 'BACKEND_ERROR',\n 'Payment settled but the backend call failed; the payment was not refunded automatically',\n {\n requestId: request.requestId,\n resourceId: resource.id,\n cause: commerceError,\n details: {\n payment: {\n status: paymentResult.status,\n provider: paymentResult.provider,\n amount: paymentResult.amount,\n currency: paymentResult.currency,\n ...(paymentResult.network !== undefined ? { network: paymentResult.network } : {}),\n ...(paymentResult.externalReference !== undefined\n ? { externalReference: paymentResult.externalReference }\n : {}),\n },\n },\n },\n );\n }\n\n throw commerceError;\n }\n\n await safeEmit(\n buildEvent({\n type: 'backend.called',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'ok',\n durationMs: backendResponse.durationMs,\n data: { status: backendResponse.status },\n }),\n );\n\n // 7. persist receipt, emit final event, return outcome\n const receipt: CommerceReceipt = {\n id: options.ids.next('receipt'),\n requestId: request.requestId,\n resourceId: resource.id,\n deliveredAt: options.clock.nowIso(),\n backendStatus: backendResponse.status,\n durationMs: backendResponse.durationMs,\n protocol: request.protocol,\n ...(paymentResult !== undefined ? { payment: paymentResult } : {}),\n };\n\n await safePersist(() => options.store.saveReceipt(receipt), 'saveReceipt', request.requestId);\n\n const totalDurationMs = Math.round(options.clock.monotonicMs() - pipelineStart);\n\n await safeEmit(\n buildEvent({\n type: 'resource.delivered',\n requestId: request.requestId,\n resourceId: resource.id,\n adapter: request.protocol,\n status: 'ok',\n durationMs: totalDurationMs,\n }),\n );\n\n return {\n kind: 'delivered',\n requestId: request.requestId,\n resourceId: resource.id,\n backendStatus: backendResponse.status,\n body: backendResponse.body,\n headers: backendResponse.headers,\n ...(paymentResult !== undefined ? { payment: paymentResult } : {}),\n receipt,\n durationMs: totalDurationMs,\n };\n }\n\n return { execute };\n}\n\n/** The HTTP status the backend actually returned, when known (backend-http.ts\n * attaches it as `details.status` for a non-2xx response). 0 means \"no\n * response was received at all\" (timeout/transport failure) — distinct from\n * any real HTTP status. */\nfunction backendErrorStatus(error: CommerceError): number {\n const status = error.details?.['status'];\n return typeof status === 'number' ? status : 0;\n}\n\nfunction uncertainSettlementTxHash(error: unknown): string | undefined {\n if (!isCommerceError(error) || error.code !== 'PAYMENT_PROVIDER_UNAVAILABLE') return undefined;\n const hash = error.details?.['transactionHash'];\n return typeof hash === 'string' ? hash : undefined;\n}\n\nfunction pickProvider(\n providers: readonly PaymentProvider[],\n methods: readonly PaymentMethodName[],\n): PaymentProvider | undefined {\n for (const method of methods) {\n const found = providers.find((provider) => provider.name === method);\n if (found) return found;\n }\n return undefined;\n}\n\nconst RESERVED_INPUT_KEYS = new Set([PAYMENT_INPUT_FIELD, '__proto__']);\n\nfunction stripPaymentField(input: unknown): unknown {\n if (typeof input !== 'object' || input === null || Array.isArray(input)) return input;\n const record = input as Record<string, unknown>;\n // Object.hasOwn: `in` would also match inherited names and strip things\n // that were never actually present on this input.\n const hasReserved = [...RESERVED_INPUT_KEYS].some((key) => Object.hasOwn(record, key));\n if (!hasReserved) return input;\n const rest: Record<string, unknown> = {};\n for (const key of Object.keys(record)) {\n // \"__proto__\" is dropped, not just excluded from the reserved-field\n // check: `rest[key] = record[key]` for key === \"__proto__\" would invoke\n // the inherited setter and reassign rest's own prototype instead of\n // creating a data property (belt-and-braces — validation.ts's\n // Object.hasOwn fix is the primary control).\n if (!RESERVED_INPUT_KEYS.has(key)) rest[key] = record[key];\n }\n return rest;\n}\n\nfunction describeError(error: unknown): { message: string; name?: string } {\n if (error instanceof Error) return { message: error.message, name: error.name };\n return { message: String(error) };\n}\n","/**\n * In-memory implementation of the frozen `ResourceRegistry` interface.\n */\nimport type { ProtocolName } from '../domain/common.js';\nimport type { CommerceResource, ResourceRegistry } from '../domain/resource.js';\nimport { CommerceError } from '../errors/index.js';\n\nexport class ResourceRegistryImpl implements ResourceRegistry {\n private readonly byId = new Map<string, CommerceResource>();\n private readonly ordered: readonly CommerceResource[];\n\n constructor(resources: readonly CommerceResource[]) {\n for (const resource of resources) {\n if (this.byId.has(resource.id)) {\n throw new CommerceError('CONFIG_INVALID', `Duplicate resource id \"${resource.id}\"`, {\n details: { resourceId: resource.id },\n });\n }\n this.byId.set(resource.id, resource);\n }\n this.ordered = [...resources];\n }\n\n get(id: string): CommerceResource | undefined {\n return this.byId.get(id);\n }\n\n list(): readonly CommerceResource[] {\n return this.ordered;\n }\n\n listExposedVia(protocol: ProtocolName): readonly CommerceResource[] {\n return this.ordered.filter((resource) => resource.exposedVia.includes(protocol));\n }\n\n has(id: string): boolean {\n return this.byId.has(id);\n }\n}\n\n/** Build a `ResourceRegistry` from a validated list of canonical resources. */\nexport function createResourceRegistry(resources: readonly CommerceResource[]): ResourceRegistry {\n return new ResourceRegistryImpl(resources);\n}\n","/**\n * src/core/execution\n *\n * The execution pipeline implementation: resource registry, backend executor,\n * event bus and the pipeline itself. Not part of the frozen `public-types.ts`\n * barrel — this is implementation, not contract — but exported as a stable\n * subpath so `src/gateway` (and tests) can wire it up.\n */\n\nexport type { HttpBackendExecutorOptions } from './backend-http.js';\nexport {\n extractPathParameterNames,\n findUnparsedBraceToken,\n HttpBackendExecutor,\n validateBackendRequestShape,\n} from './backend-http.js';\nexport type { CreateEventBusOptions, EventBus } from './event-bus.js';\nexport { createEventBus } from './event-bus.js';\nexport type { CreateExecutionPipelineOptions } from './pipeline.js';\nexport { createExecutionPipeline } from './pipeline.js';\nexport { createResourceRegistry, ResourceRegistryImpl } from './registry.js';\nexport type { FieldError, ValidationResult, Validator } from './validation.js';\nexport { compileJsonSchema, isObjectSchemaNode } from './validation.js';\n","/**\n * The networks this gateway will settle on, as data.\n *\n * x402 v2 identifies a network by its CAIP-2 id, so the only thing an\n * operator has to change to move between environments is that string. What\n * the code needs on top of it — the chain id to sign against, a name a human\n * recognises, and whether real money is involved — lives here rather than\n * being derived at each call site.\n *\n * A registry rather than \"parse any `eip155:*`\" on purpose. The chain id is\n * parseable from any such string, but `mainnet` is not, and every guardrail in\n * `guardrails.ts` keys off it. An unknown id is refused at startup instead of\n * being quietly treated as a testnet.\n *\n * Base Sepolia and the local dev chain share the id `eip155:84532`: the local\n * chain deliberately reuses Base Sepolia's chain id so the unmodified x402 SDK\n * can talk to it. Nothing may infer \"public network\" from the network id alone\n * — that is what `resolveDeploymentMode` and the Anvil probe in `provider.ts`\n * are for.\n */\nimport { CommerceError } from '../../core/index.js';\n\nexport interface NetworkProfile {\n /** CAIP-2 identifier, e.g. `eip155:84532`. */\n readonly id: string;\n /** Signed into the buyer's EIP-712 domain. */\n readonly chainId: number;\n readonly displayName: string;\n readonly kind: 'testnet' | 'mainnet';\n /**\n * The USDC deployment this network is expected to settle in, with the EIP-712\n * domain the token actually reports. Enforced only on mainnet (see\n * `guardrails.ts`) — a testnet is where a mock token is a legitimate thing to\n * point at.\n *\n * `name` is not decorative and is not the symbol: it is signed into every\n * buyer's EIP-712 domain, and the two USDC deployments disagree. Base Sepolia\n * reports `\"USDC\"`; Base mainnet reports `\"USD Coin\"`. Configure the wrong\n * one and every payment is refused `invalid_exact_evm_token_name_mismatch`\n * after the buyer has signed. Read back from the contracts, not assumed.\n */\n readonly canonicalAsset?: {\n readonly symbol: string;\n readonly address: string;\n readonly name: string;\n readonly version: string;\n };\n}\n\nconst PROFILES: readonly NetworkProfile[] = [\n {\n id: 'eip155:84532',\n chainId: 84532,\n displayName: 'Base Sepolia',\n kind: 'testnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n name: 'USDC',\n version: '2',\n },\n },\n {\n id: 'eip155:8453',\n chainId: 8453,\n displayName: 'Base',\n kind: 'mainnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n name: 'USD Coin',\n version: '2',\n },\n },\n];\n\nconst BY_ID = new Map(PROFILES.map((profile) => [profile.id, profile]));\n\nexport const SUPPORTED_NETWORK_IDS: readonly string[] = PROFILES.map((p) => p.id);\n\nexport function findNetworkProfile(id: string): NetworkProfile | undefined {\n return BY_ID.get(id);\n}\n\nexport function requireNetworkProfile(id: string, path: string): NetworkProfile {\n const profile = BY_ID.get(id);\n if (!profile) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `${path}: \"${id}\" is not a supported network. Supported CAIP-2 identifiers: ${SUPPORTED_NETWORK_IDS.join(', ')}`,\n { details: { path, network: id } },\n );\n }\n return profile;\n}\n\n/**\n * What this deployment actually is, as opposed to what it is called.\n *\n * `local` is a property of the *facilitator*, not the network: settling\n * through the in-process facilitator against a dev node is local regardless of\n * the CAIP-2 id that node answers to. This distinction is the whole reason\n * diagnostics can say `eip155:84532` without claiming to be on public Base\n * Sepolia.\n */\nexport type DeploymentMode = 'local' | 'testnet' | 'mainnet';\n\nexport function resolveDeploymentMode(\n profile: NetworkProfile,\n facilitatorMode: 'local' | 'remote',\n): DeploymentMode {\n if (facilitatorMode === 'local') return 'local';\n return profile.kind;\n}\n\n/** The banner an operator must not be able to miss. Never printed for anything else. */\nexport const LIVE_MAINNET_BANNER = 'LIVE MAINNET MODE — REAL FUNDS';\n\nexport function describeDeploymentMode(mode: DeploymentMode): string {\n return mode === 'mainnet' ? LIVE_MAINNET_BANNER : mode.toUpperCase();\n}\n","/**\n * ACP protocol constants shared by the config layer and the adapter.\n *\n * Kept dependency-free: `src/config` reads the operation set at load time, so\n * anything imported here would become a config-load dependency too.\n */\n\n/**\n * The ACP stable snapshot this adapter implements, and the only value accepted\n * in the `API-Version` request header. Both name the same released snapshot;\n * they are separate constants because ACP versions the wire contract and the\n * header independently, and a future snapshot may accept more than one.\n *\n * Changing either means vendoring a new schema directory beside\n * `spec/2026-04-17/` - never editing the vendored one in place.\n */\nexport const ACP_SPEC_VERSION = '2026-04-17';\nexport const ACP_API_VERSION = '2026-04-17';\n\n/** Discovery path fixed by the ACP specification - never a configurable mount. */\nexport const ACP_WELL_KNOWN_PATH = '/.well-known/acp.json';\n\n/**\n * The stable checkout operations, by ACP operation id. All five are required\n * when ACP is enabled: a partially configured checkout lifecycle would be\n * advertised as a whole service the seller cannot actually serve.\n */\nexport const ACP_CHECKOUT_OPERATIONS = [\n 'createCheckoutSession',\n 'updateCheckoutSession',\n 'getCheckoutSession',\n 'completeCheckoutSession',\n 'cancelCheckoutSession',\n] as const;\n\nexport type AcpCheckoutOperation = (typeof ACP_CHECKOUT_OPERATIONS)[number];\n\n/**\n * Top-level canonical-input properties each operation always supplies.\n *\n * `path` carries `{ checkout_session_id }`, `body` the ACP request document.\n * Cancel is deliberately absent a body: the pinned schema does not require\n * one, and inventing one would make every cancel resource declare a property\n * ACP may never fill.\n */\nexport const ACP_OPERATION_INPUT_KEYS: Readonly<\n Record<AcpCheckoutOperation, readonly ('path' | 'body')[]>\n> = {\n createCheckoutSession: ['body'],\n updateCheckoutSession: ['path', 'body'],\n getCheckoutSession: ['path'],\n completeCheckoutSession: ['path', 'body'],\n cancelCheckoutSession: ['path'],\n};\n\n/** Media type for every ACP request and response body. */\nexport const ACP_JSON_MEDIA_TYPE = 'application/json';\n\n/**\n * Protocol headers, lowercased as Node delivers them.\n *\n * `API-Version` is mandatory on checkout requests and is never defaulted:\n * answering an unversioned request as if it named the pinned snapshot would be\n * guessing on the caller's behalf about a contract that changes.\n */\nexport const ACP_API_VERSION_HEADER = 'api-version';\nexport const ACP_REQUEST_ID_HEADER = 'request-id';\nexport const ACP_IDEMPOTENCY_KEY_HEADER = 'idempotency-key';\nexport const ACP_IDEMPOTENT_REPLAYED_HEADER = 'idempotent-replayed';\n\n/**\n * Seconds a client is told to wait before retrying a key whose first request is\n * still running. Short: the original is a live HTTP call, not a queue.\n */\nexport const ACP_IN_FLIGHT_RETRY_AFTER_SECONDS = 1;\n\n/**\n * Longest `Request-Id` echoed back. The value is the caller's, so it is\n * bounded and filtered before it is ever written into a response header.\n */\nexport const ACP_MAX_REQUEST_ID_LENGTH = 128;\n","/**\n * `${VAR}` / `${VAR:-default}` substitution over an arbitrary parsed-YAML value.\n *\n * Only string leaves are touched; numbers/booleans/null pass through untouched\n * (the caller coerces the *resulting* string back into a number/boolean where\n * the schema expects one). An unresolved placeholder fails config loading\n * immediately — startup must never proceed with an unresolved secret. That\n * includes one left behind by a *nested* placeholder such as `${A:-${B}}`,\n * which is rejected rather than silently passed through. There is no\n * escape syntax for a literal `${NAME}`; nothing in this config format needs\n * one, and adding it would mean two ways to write every value.\n *\n * `${VAR}` (no default) requires `VAR` to be present in `env` (any value,\n * including an empty string, counts as present).\n * `${VAR:-default}` falls back to `default` when `VAR` is absent OR empty,\n * matching common shell semantics.\n *\n * Anything else brace-shaped is refused: `${VAR-x}`, `${VAR:=x}`, `${VAR:?x}`\n * are valid *shell* and would otherwise load as literal strings. That is\n * harmless where a downstream check rejects the literal, and quietly wrong for\n * a free-string field — `adminToken: ${ADMIN_TOKEN-fallback}` would run the\n * gateway with that literal as the ledger credential while the operator\n * believed an env secret gated it. A bare `$VAR` is deliberately left alone: it\n * is not brace-shaped, and refusing it would reject values that legitimately\n * contain a dollar sign.\n *\n * Every rule above is decided from the **template**, before substitution.\n * Deciding afterwards is how `${A:-${B}}` used to corrupt a value on the one\n * branch its guard did not cover, and how a resolved secret containing a\n * `${…}`-shaped fragment used to get quoted back in the error text.\n *\n * The resolved *value* of a variable is never included in any error message —\n * only the variable *name* and the config path are.\n */\nimport { CommerceError } from '../core/index.js';\n\nconst PLACEHOLDER_PATTERN = /\\$\\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?\\}/g;\n\n/** An innermost brace token: `${` … `}` with no braces between. */\nconst BRACE_TOKEN = /\\$\\{[^{}]*\\}/g;\n\n/** The same grammar as PLACEHOLDER_PATTERN, anchored, for validating one token. */\nconst SUPPORTED_TOKEN = /^\\$\\{[A-Za-z_][A-Za-z0-9_]*(:-[^}]*)?\\}$/;\n\n/** A placeholder whose default segment opens another placeholder. */\nconst NESTED_PLACEHOLDER = /\\$\\{[^{}]*\\$\\{/;\n\nexport function substituteEnv(value: unknown, env: NodeJS.ProcessEnv, path = '$'): unknown {\n if (typeof value === 'string') {\n return substituteString(value, env, path);\n }\n if (Array.isArray(value)) {\n return value.map((entry, index) => substituteEnv(entry, env, `${path}[${index}]`));\n }\n if (isPlainObject(value)) {\n const result: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n result[key] = substituteEnv(entry, env, `${path}.${key}`);\n }\n return result;\n }\n return value;\n}\n\nfunction substituteString(value: string, env: NodeJS.ProcessEnv, path: string): string {\n assertTemplateIsSupported(value, path);\n return substituteOnce(value, env, path);\n}\n\n/**\n * Refuses a template this module cannot honour, before any substitution runs.\n *\n * `${A:-${B}}` is the case that motivated this. `[^}]*` cannot span the inner\n * `}`, so the match consumes `${A:-${B` and leaves a stray `}` behind. When `A`\n * is unset the leftover `${B}` was visible afterwards and got caught; when `A`\n * is *set* — the normal case, and the whole reason someone writes a default —\n * substitution succeeded and the stray `}` was appended to the resolved value\n * with nothing to notice it. For `adminToken` that means the gateway compares\n * against a credential the operator does not hold, with no diagnostic.\n *\n * Deciding from the template covers both branches with one rule, and means no\n * error message is ever derived from a resolved value.\n */\nfunction assertTemplateIsSupported(value: string, path: string): void {\n if (NESTED_PLACEHOLDER.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" nests placeholders (e.g. \"\\${A:-\\${B}}\"), which is not supported — the inner one is not resolved and its closing brace ends up in the value. Use a plain default, or set the variable.`,\n { details: { path } },\n );\n }\n\n BRACE_TOKEN.lastIndex = 0;\n for (const [token] of value.matchAll(BRACE_TOKEN)) {\n if (SUPPORTED_TOKEN.test(token)) continue;\n // The token itself, never the surrounding value: this runs pre-substitution,\n // so it cannot contain a resolved secret.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" contains \"${token}\", which is not a supported placeholder. Only \"\\${VAR}\" and \"\\${VAR:-default}\" are recognised; shell forms such as \"\\${VAR-default}\", \"\\${VAR:=default}\" and \"\\${VAR:?message}\" would load as literal text.`,\n { details: { path, token } },\n );\n }\n}\n\nfunction substituteOnce(value: string, env: NodeJS.ProcessEnv, path: string): string {\n return value.replace(\n PLACEHOLDER_PATTERN,\n (_match, name: string, hasDefault: string | undefined, def: string | undefined) => {\n const envValue = env[name];\n\n if (hasDefault !== undefined) {\n if (envValue === undefined || envValue === '') return def ?? '';\n return envValue;\n }\n\n if (envValue === undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Unresolved environment variable \"\\${${name}}\" referenced at config path \"${path}\"`,\n { details: { variable: name, path } },\n );\n }\n return envValue;\n },\n );\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","/**\n * Anvil's well-known development accounts.\n *\n * LOCAL DEVELOPMENT ONLY — DO NOT FUND. These addresses and private keys are\n * derived from Foundry's public, well-documented default test mnemonic\n * (\"test test test test test test test test test test test junk\") and are\n * known to everyone who has ever run `anvil`. Anyone who sends real value to\n * one of these addresses on a real network will lose it.\n *\n * Index layout used by the local demo chain (see docs/contracts.md):\n * 0 — deployer / local facilitator signer (pays gas, broadcasts settlement)\n * 1 — merchant settlement destination (`payTo`)\n * 2 — buyer (signs EIP-3009 authorisations; never held by the gateway)\n */\nexport interface AnvilWellKnownAccount {\n readonly address: `0x${string}`;\n readonly privateKey: `0x${string}`;\n}\n\n/** Fixed-length tuple (not a bare array) so indexing by the documented layout above is fully typed. */\nexport const ANVIL_WELL_KNOWN_ACCOUNTS: readonly [\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n] = [\n {\n address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',\n privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',\n },\n {\n address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',\n privateKey: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',\n },\n {\n address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',\n privateKey: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',\n },\n];\n\nexport const LOCAL_FACILITATOR_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[0];\nexport const LOCAL_MERCHANT_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[1];\nexport const LOCAL_BUYER_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[2];\n\n/** Safe label used everywhere a dev key appears in output, logs or manifests. */\nexport const DEV_KEY_LABEL = 'LOCAL DEVELOPMENT ONLY - DO NOT FUND';\n","/**\n * Prevents a well-known Anvil development private key — or a well-known\n * Anvil development *address* — from ever being used against anything other\n * than a loopback/private/dev RPC. Two symmetric mistakes, both covered:\n * signing settlement with a dev key (`assertDevKeyIsLocalOnly`), and routing\n * settlement revenue to a dev address (`assertPayToIsNotDevAddress`). The\n * second is the more consequential of the two — a wrong key merely fails to\n * sign, a wrong payTo silently succeeds and gives the money away, since the\n * private key behind every well-known Anvil address is public knowledge.\n *\n * Chain id alone cannot tell a real network from this project's local dev\n * chain: Base Sepolia's own chain id is 84532, the same id this project\n * deliberately reuses for the local chain so the unmodified x402 SDK can talk\n * to it. A dev key or dev payTo pointed at a real RPC by a config mistake is\n * instantly drainable — this is checked once at provider construction, not per\n * payment.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from './local-chain/accounts.js';\n\nconst WELL_KNOWN_DEV_KEYS: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.privateKey.toLowerCase()),\n);\n\nconst WELL_KNOWN_DEV_ADDRESSES: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.address.toLowerCase()),\n);\n\n/** `0x` + 64 hex chars — the only shape `privateKeyToAccount` accepts. */\nconst PRIVATE_KEY_SHAPE = /^0x[0-9a-fA-F]{64}$/;\n\nexport function isWellKnownDevKey(privateKey: string): boolean {\n return WELL_KNOWN_DEV_KEYS.has(privateKey.toLowerCase());\n}\n\nexport function isWellKnownDevAddress(address: string): boolean {\n return WELL_KNOWN_DEV_ADDRESSES.has(address.toLowerCase());\n}\n\n/**\n * True for loopback addresses, RFC1918 private ranges, and bare (dot-free)\n * hostnames — the shape of a docker-compose/k8s service name (e.g.\n * \"anvil\"), which a real public DNS name essentially never has.\n *\n * ASSUMPTION, and the loosest edge of this guard: every dot-free, colon-free\n * hostname is treated as private, with no exceptions. A single-label *public* hostname (no dots) is\n * essentially nonexistent in practice — ICANN does not delegate bare\n * gTLDs/TLDs as public A/AAAA records — but this function cannot tell \"no\n * dots because it's a compose service name\" from \"no dots because it's an\n * unusual real host\" if one somehow existed. If that assumption ever stops\n * holding, this is the line to revisit.\n */\nexport function isLikelyLocalOrPrivateHost(hostname: string): boolean {\n const h = hostname.toLowerCase().replace(/^\\[|\\]$/g, '');\n if (h === 'localhost' || h === '127.0.0.1' || h === '::1') return true;\n if (/^127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^192\\.168\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^172\\.(1[6-9]|2\\d|3[01])\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (!h.includes('.') && !h.includes(':')) return true; // bare hostname\n return false;\n}\n\nfunction parseHostnameOrThrow(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).hostname;\n } catch (cause) {\n // Not the URL itself: every commercial EVM RPC provider embeds an API key\n // in the path, and these messages reach `validate`, `doctor`, startup\n // output and CI logs.\n throw new CommerceError('CONFIG_INVALID', 'x402 provider: rpcUrl is not a valid URL', {\n cause,\n });\n }\n}\n\n/** Host only, for diagnostics. An RPC URL's path routinely carries a key. */\nfunction describeRpc(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).origin;\n } catch {\n return '[unparseable rpcUrl]';\n }\n}\n\n/**\n * Throws CONFIG_INVALID if a well-known dev key would sign against a non-local\n * RPC — or if `signerPrivateKey` isn't shaped like a private key at all.\n *\n * The shape check runs first and unconditionally. \"Not a key I recognise\"\n * (falls through `isWellKnownDevKey`, silently treated as someone's own real\n * facilitator key) and \"not a key at all\" (e.g. a truncated 63-char string)\n * must never share a code path: a malformed key that slips past this guard\n * only fails later, inside `settle()`, after the buyer's replayKey is already\n * reserved.\n */\nexport function assertDevKeyIsLocalOnly(rpcUrl: string, signerPrivateKey: string): void {\n if (!PRIVATE_KEY_SHAPE.test(signerPrivateKey)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is not a well-formed private key ' +\n '(expected \"0x\" followed by exactly 64 hex characters).',\n );\n }\n\n if (!isWellKnownDevKey(signerPrivateKey)) return; // a real facilitator key: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is a well-known Anvil development key, but rpcUrl ' +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. A public dev key must never sign against ` +\n 'a public network — it is instantly drainable and can grief real settlements via nonce exhaustion. ' +\n 'Use a real facilitator key for any non-local RPC, or point rpcUrl at your local/dev chain.',\n );\n }\n}\n\n/**\n * Throws CONFIG_INVALID if `payTo` (the settlement destination) is a\n * well-known Anvil development address and `rpcUrl` doesn't look\n * local/private.\n *\n * Mirrors `assertDevKeyIsLocalOnly`, but guards the *receiving* side of the\n * payment instead of the signing side, and — unlike the key guard — applies\n * regardless of facilitator mode: which account signs the settlement\n * transaction has no bearing on whether the destination address is one whose\n * private key is public knowledge. `agent-commerce init` defaults `payTo` to\n * a well-known Anvil address as a local-demo convenience; on a real network\n * that default routes every payment to an address anyone on earth can sweep.\n */\nexport function assertPayToIsNotDevAddress(rpcUrl: string, payTo: string): void {\n if (!isWellKnownDevAddress(payTo)) return; // not a dev address: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"payTo\" (${payTo}) is a well-known Anvil development address, but rpcUrl ` +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. The private key behind that address ` +\n 'is public knowledge, so any revenue settled to it is immediately spendable by anyone. Set ' +\n '\"payTo\" to your own merchant wallet for any non-local RPC, or point rpcUrl at your ' +\n 'local/dev chain.',\n );\n }\n}\n","/**\n * Everything that must be true before this gateway is allowed to settle a\n * payment on the configured network.\n *\n * One definition, two callers: the provider runs it at construction so a\n * library consumer who never touches our config loader still gets the checks,\n * and `doctor` runs it against the parsed config so an operator sees the same\n * verdict without starting the gateway. Sharing a *call* is not sharing a\n * definition — the checks live here, and nothing re-implements them.\n *\n * Every failure is a startup failure. None of these are request-time\n * decisions: a deployment that is unsafe is unsafe before the first buyer\n * arrives, and finding out during `settle()` means the buyer's authorisation\n * is already burned.\n *\n * Peer-free by construction (no viem, no `@x402/*`) so the CLI can import it.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { isLikelyLocalOrPrivateHost, isWellKnownDevAddress } from './dev-key-guard.js';\nimport {\n type DeploymentMode,\n type NetworkProfile,\n requireNetworkProfile,\n resolveDeploymentMode,\n} from './networks.js';\n\n/**\n * How the gateway authenticates to a remote facilitator.\n *\n * Deliberately a list, not a vendor: x402 facilitators are not a Coinbase-only\n * category, and a scheme that only fitted one vendor's credentials would make\n * the abstraction a fiction.\n *\n * - `none` — the facilitator takes no credential (the public testnet one).\n * - `bearer` — a static token. Covers most self-hosted and third-party\n * facilitators, and needs nothing installed.\n * - `cdp` — Coinbase Developer Platform, which signs a fresh JWT per request\n * over method + host + path, so a static header cannot express it. Handled by\n * the optional peer `@coinbase/x402`, imported only when this type is\n * configured. Anyone not using CDP never installs it.\n *\n * A facilitator whose scheme is none of these is refused at config load rather\n * than sent nothing.\n */\nexport type FacilitatorAuth =\n | { readonly type: 'none' }\n | { readonly type: 'bearer'; readonly token: string }\n | { readonly type: 'cdp'; readonly apiKeyId: string; readonly apiKeySecret: string };\n\nexport type X402FacilitatorConfig =\n | { readonly mode: 'local'; readonly signerPrivateKey: string }\n | { readonly mode: 'remote'; readonly url: string; readonly auth: FacilitatorAuth };\n\nexport interface X402DeploymentInput {\n readonly network: string;\n readonly payTo: string;\n readonly asset: string;\n /** EIP-712 domain of the asset, as the token itself reports it. */\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly facilitator: X402FacilitatorConfig;\n /** Required, and required to be `true`, before anything settles on a mainnet. */\n readonly allowMainnet?: boolean;\n /**\n * Required, and required to be `true`, to settle on a mainnet through a\n * facilitator that takes no credential.\n *\n * Separate from `allowMainnet` because it names a different decision: not\n * \"I meant to use real money\" but \"I accept this particular counterparty\n * without an account, terms, or anyone to call\".\n */\n readonly allowUnauthenticatedFacilitator?: boolean;\n}\n\nexport interface X402Deployment {\n readonly profile: NetworkProfile;\n readonly mode: DeploymentMode;\n}\n\nfunction invalid(message: string, path: string): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path } });\n}\n\n/**\n * Resolves the deployment and refuses every combination that could move real\n * money by accident. Order matters only in that the network must resolve\n * first; the rest are independent.\n */\nexport function resolveX402Deployment(input: X402DeploymentInput): X402Deployment {\n const profile = requireNetworkProfile(input.network, 'payments.x402.network');\n const mode = resolveDeploymentMode(profile, input.facilitator.mode);\n\n // The in-process facilitator signs with a key this process holds. Not a\n // custody problem — that signer never holds buyer or merchant funds, it pays\n // gas and broadcasts `transferWithAuthorization`, and the money moves buyer\n // to merchant directly on-chain. What it *is*, on a mainnet, is a funded key\n // inside the resource server: compromise that process and an attacker drains\n // the gas wallet and broadcasts from it. Separate processes, separate blast\n // radius — so it is refused, not warned about.\n if (profile.kind === 'mainnet' && input.facilitator.mode === 'local') {\n throw invalid(\n `payments.x402: network \"${profile.id}\" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode \"local\". A mainnet deployment must settle through a remote facilitator.`,\n 'payments.x402.facilitator.mode',\n );\n }\n\n if (mode === 'mainnet' && input.allowMainnet !== true) {\n throw invalid(\n `payments.x402: network \"${profile.id}\" (${profile.displayName}) settles real funds. Set payments.x402.allowMainnet: true to acknowledge this explicitly — it is never the default.`,\n 'payments.x402.allowMainnet',\n );\n }\n\n if (input.facilitator.mode === 'remote') {\n assertFacilitatorUrlIsSafe(input.facilitator.url, mode);\n // Not a funds check. An EIP-3009 authorisation names its recipient, its\n // amount and its chain, so a facilitator can broadcast exactly that\n // transfer or nothing — it cannot redirect the money. What a credential\n // buys is a *relationship*: rate limits, terms, someone to call when\n // settlement stops. Running production payments through a counterparty you\n // have none of that with is a real choice, and this is where it gets made\n // explicitly rather than by omission.\n if (\n mode === 'mainnet' &&\n input.facilitator.auth.type === 'none' &&\n input.allowUnauthenticatedFacilitator !== true\n ) {\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(input.facilitator.url)} takes no credential, and this is a mainnet deployment. It will see every payment authorisation you handle, with no account, terms or support behind it. Set payments.x402.allowUnauthenticatedFacilitator: true to accept that, or configure facilitator.auth.`,\n 'payments.x402.allowUnauthenticatedFacilitator',\n );\n }\n // An empty credential is refused rather than sent: a blank token or key\n // reaches the facilitator as \"unauthenticated\" and fails every payment\n // after the buyer has already signed. `${VAR:- }` resolving to whitespace\n // is the realistic way this happens.\n for (const [field, value] of credentialFields(input.facilitator.auth)) {\n if (value.trim() === '') {\n throw invalid(\n `payments.x402: facilitator.auth.type is \"${input.facilitator.auth.type}\" but ${field} is empty. An empty credential is refused rather than sent.`,\n `payments.x402.facilitator.auth.${field}`,\n );\n }\n }\n }\n\n // The private key behind every well-known Anvil address is public knowledge.\n // `dev-key-guard` already refuses one against a public *RPC*; this refuses\n // one on any non-local *deployment*, which is the case a remote facilitator\n // creates — there the RPC host says nothing about where settlement lands.\n // The zero address lived only in the config loader, so a library consumer\n // calling `createX402PaymentProvider` directly — the path this shared\n // definition exists to cover — could boot a mainnet provider whose every\n // payment burns — sharing a *call* is not sharing a definition, and this\n // check had drifted out of the shared one.\n if (/^0x0{40}$/i.test(input.payTo)) {\n throw invalid(\n 'payments.x402: \"payTo\" is the zero address. Every payment settled there is destroyed.',\n 'payments.x402.payTo',\n );\n }\n\n if (mode !== 'local' && isWellKnownDevAddress(input.payTo)) {\n throw invalid(\n `payments.x402: \"payTo\" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set payTo to your own merchant wallet.`,\n 'payments.x402.payTo',\n );\n }\n\n // Mainnet only. A testnet is exactly where pointing at a mock token is the\n // right thing to do, so the same check there would block the normal case.\n const canonical = profile.canonicalAsset;\n if (mode === 'mainnet' && canonical) {\n if (!sameAddress(input.asset, canonical.address)) {\n throw invalid(\n `payments.x402: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). Settling a mainnet payment in an unintended token is refused.`,\n 'payments.x402.asset',\n );\n }\n // The EIP-712 domain is signed by the buyer and checked by the scheme. Get\n // it wrong and every payment is refused `invalid_exact_evm_token_name_mismatch`\n // *after* the buyer signed — a config error charged to the buyer's patience.\n // Caught here instead, before the gateway starts.\n if (input.assetName !== undefined && input.assetName !== canonical.name) {\n throw invalid(\n `payments.x402: assetName \"${input.assetName}\" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.name}\"). Every payment would be refused after the buyer signed.`,\n 'payments.x402.assetName',\n );\n }\n if (input.assetVersion !== undefined && input.assetVersion !== canonical.version) {\n throw invalid(\n `payments.x402: assetVersion \"${input.assetVersion}\" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.version}\").`,\n 'payments.x402.assetVersion',\n );\n }\n }\n\n return { profile, mode };\n}\n\n/**\n * A facilitator sees every payment authorisation this gateway handles. Plain\n * HTTP to one on a public network puts those on the wire in the clear and\n * lets anyone in the path rewrite a settlement result, so it is allowed only\n * where the endpoint cannot leave the host — a local or private address.\n */\nfunction assertFacilitatorUrlIsSafe(url: string, mode: DeploymentMode): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch (cause) {\n throw new CommerceError('CONFIG_INVALID', `payments.x402: facilitator.url is not a valid URL`, {\n cause,\n details: { path: 'payments.x402.facilitator.url' },\n });\n }\n\n if (parsed.protocol === 'https:') return;\n if (parsed.protocol !== 'http:') {\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got \"${parsed.protocol}//\"`,\n 'payments.x402.facilitator.url',\n );\n }\n if (mode !== 'mainnet' && isLikelyLocalOrPrivateHost(parsed.hostname)) return;\n\n // The origin, never the whole URL: the path can carry a tenant or an API\n // key, which is why `/.well-known` withholds this field entirely. A refusal\n // message goes to `validate`, `doctor`, startup output and CI logs.\n throw invalid(\n `payments.x402: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorisations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,\n 'payments.x402.facilitator.url',\n );\n}\n\n/** Host only — a facilitator URL can carry a tenant path or an API key. */\nfunction describeOrigin(url: string): string {\n try {\n return new URL(url).origin;\n } catch {\n return '[unparseable facilitator.url]';\n }\n}\n\n/** The secret-bearing fields of an auth block, for emptiness checks only. Never logged. */\nfunction credentialFields(auth: FacilitatorAuth): readonly (readonly [string, string])[] {\n switch (auth.type) {\n case 'bearer':\n return [['token', auth.token]];\n case 'cdp':\n return [\n ['apiKeyId', auth.apiKeyId],\n ['apiKeySecret', auth.apiKeySecret],\n ];\n default:\n return [];\n }\n}\n\nfunction sameAddress(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n","/**\n * `config.yaml` schema, validation and normalisation into the\n * canonical `GatewayConfig` (docs/contracts.md).\n *\n * Two-phase validation:\n * 1. Zod validates *shape* (types, required fields, unknown-key rejection).\n * Numeric/boolean leaves accept either their native type or a string\n * (env substitution always produces a string), and are left as-is here -\n * Zod's typed transforms have surprising inference interactions with\n * `.strict()` objects, so numeric/boolean coercion is done explicitly,\n * in plain TypeScript, in the normalisation pass below.\n * 2. A manual business-rule pass validates cross-references that need a\n * specific, actionable message (duplicate ids, disabled protocols/payment\n * methods, dynamic pricing, destination-address plausibility) and\n * performs the numeric/boolean coercion.\n *\n * Env substitution (`${VAR}` / `${VAR:-default}`) runs over the raw parsed\n * value *before* either phase, so numeric/boolean fields can be templated too.\n * One exception, deliberate: `checkVersion` runs **before** substitution, so\n * `version:` cannot itself be templated. It is the compatibility gate that\n * decides whether this parser understands the document at all; resolving\n * environment variables to find out which schema version to expect would be\n * backwards. The order is intended; `version:` is the one exception to the\n * substitution rule, which this sentence exists to record.\n */\n\nimport { type ZodError, type ZodIssue, type ZodTypeAny, z } from 'zod';\nimport {\n extractPathParameterNames,\n findUnparsedBraceToken,\n isObjectSchemaNode,\n} from '../core/execution/index.js';\nimport {\n CommerceError,\n type CommerceResource,\n PAYMENT_INPUT_FIELD,\n PROTOCOL_NAMES,\n type Pricing,\n} from '../core/index.js';\nimport { resolveX402Deployment, type X402FacilitatorConfig } from '../payments/x402/guardrails.js';\nimport {\n ACP_CHECKOUT_OPERATIONS,\n ACP_OPERATION_INPUT_KEYS,\n ACP_WELL_KNOWN_PATH,\n type AcpCheckoutOperation,\n} from '../protocols/acp/constants.js';\nimport { substituteEnv } from './env.js';\n\nconst SUPPORTED_CONFIG_VERSION = 1;\n\n/** `0x` + 40 hex chars. Checksum-insensitive: casing is not enforced. */\nconst ADDRESS_PATTERN = /^0x[0-9a-fA-F]{40}$/;\nconst ZERO_ADDRESS_PATTERN = /^0x0{40}$/i;\n\n/**\n * A resource `id` doubles as its MCP tool name (protocol-mcp registers one\n * tool per resource, named by id). Value verified against the regex actually\n * shipped in the installed `@modelcontextprotocol/sdk@1.30.0`\n * (`shared/toolNameValidation.js`, SEP-986 \"Specify Format for Tool Names\") -\n * not duplicated as an SDK dependency, since config stays protocol-agnostic.\n */\nconst MCP_TOOL_NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;\n\n// ---------------------------------------------------------------------------\n// Zod schema for the *shape* of the raw (post-substitution) document.\n// ---------------------------------------------------------------------------\n\n/** Accepts a real number or a (post env-substitution) numeric string. */\nconst NumberOrString = z.union([z.number(), z.string()]);\n/** Accepts a real boolean or a (post env-substitution) \"true\"/\"false\" string. */\nconst BooleanOrString = z.union([z.boolean(), z.string()]);\n\nconst MerchantSchema = z\n .object({\n id: z.string().min(1),\n name: z.string().min(1),\n publicBaseUrl: z.string().min(1),\n })\n .strict();\n\nconst ServerSchema = z\n .object({\n port: NumberOrString,\n host: z.string().min(1),\n /** Shared secret gating /api/receipts, /api/events, /api/events/stream. No token -> those routes 404. */\n adminToken: z.string().min(1).optional(),\n /** Browser origins allowed to read the dashboard-facing routes. Empty by default: closed. */\n // Entries are matched literally against the browser's\n // `Origin` header, so `\"*\"` and a trailing slash match nothing at all -\n // fail-closed (a lockout, not a bypass), but silently, and a lockout with\n // no explanation is the kind of thing an operator \"fixes\" by disabling the\n // check. Reject those two shapes with a pointer instead.\n allowedOrigins: z\n .array(\n z\n .string()\n .min(1)\n .refine((origin) => origin !== '*', {\n message:\n 'wildcard \"*\" is not supported - allowedOrigins entries are matched literally against the browser\\'s Origin header, so \"*\" would match nothing. List each scheme://host[:port] explicitly.',\n })\n .refine((origin) => !origin.endsWith('/'), {\n message:\n 'must not end with \"/\" - a browser Origin header never has a trailing slash, so this entry would match nothing. Use e.g. \"http://localhost:5173\".',\n }),\n )\n .optional(),\n })\n .strict();\n\nconst StorageSchema = z\n .object({\n receipts: z\n .object({\n driver: z.literal('sqlite'),\n path: z.string().min(1),\n })\n .strict(),\n })\n .strict();\n\n/**\n * Every path the gateway registers itself (`src/gateway/routes.ts`), plus the\n * fixed discovery paths adapters own. An adapter mount that equals one of\n * these makes Fastify's `.all()` a duplicate of the registered route; one that\n * is a path-prefix of them swallows their 404s through the mount's\n * `${mountPath}/*` wildcard.\n */\nconst RESERVED_GATEWAY_PATHS = [\n '/health',\n '/ready',\n '/.well-known/agent-commerce',\n // Fixed by the A2A specification, so it is the adapter's to serve and never\n // a configurable mount's to claim.\n '/.well-known/agent-card.json',\n // Likewise fixed by the ACP specification.\n ACP_WELL_KNOWN_PATH,\n '/api/resources',\n '/api/resources/:id/invoke',\n '/api/receipts',\n '/api/events',\n '/api/events/stream',\n] as const;\n\n/**\n * `mountPath` reaches Fastify as a route pattern, and a bad one throws inside\n * route registration - deferred to `server.ready()`, so `createGateway` fails\n * wholesale with an opaque `FST_ERR_*` instead of the adapter alone degrading.\n * Catching the shape here turns that into a CONFIG_INVALID naming the value.\n * Fastify pattern syntax (`:param`, `*`) is rejected rather than supported:\n * the mount registers its own wildcard, so a pattern here has no meaning.\n */\nconst MountPathSchema = z\n .string()\n .min(1)\n .refine((value) => value.startsWith('/'), {\n message: 'must start with \"/\" - it is an absolute gateway path, e.g. \"/mcp\".',\n })\n .refine((value) => !/[:*?\\s]/.test(value), {\n message:\n 'must not contain \":\", \"*\", \"?\" or whitespace - the mount is a literal path prefix, not a Fastify route pattern, and registers its own wildcard.',\n })\n .refine(\n (value) => {\n const base = value.replace(/\\/+$/, '');\n return !RESERVED_GATEWAY_PATHS.some(\n (reserved) => reserved === base || reserved.startsWith(`${base}/`),\n );\n },\n {\n message: `must not collide with a route the gateway already serves (${RESERVED_GATEWAY_PATHS.join(', ')}); pick a dedicated prefix such as \"/mcp\".`,\n },\n );\n\n/** Bearer is the only ACP auth scheme in this release - `none` is not offered. */\nconst AcpAuthSchema = z.object({ type: z.literal('bearer'), token: z.string().min(1) }).strict();\n\nconst AcpIdempotencySchema = z\n .object({ path: z.string().min(1), retentionHours: NumberOrString.optional() })\n .strict();\n\n/**\n * Operation ids are validated against `ACP_CHECKOUT_OPERATIONS` in the business\n * pass rather than spelled out again here: one list of the five names, and a\n * missing or misspelled key gets a message naming the operation.\n */\nconst AcpCheckoutSchema = z.object({ operations: z.record(z.string().min(1)) }).strict();\n\n/** Optional discovery metadata. Omitted when not configured - never guessed. */\nconst AcpDiscoverySchema = z\n .object({\n documentationUrl: z.string().min(1).optional(),\n supportedCurrencies: z.array(z.string().min(1)).optional(),\n supportedLocales: z.array(z.string().min(1)).optional(),\n interventionTypes: z.array(z.string().min(1)).optional(),\n })\n .strict();\n\nconst ProtocolsSchema = z\n .object({\n http: z.object({ enabled: BooleanOrString }).strict(),\n mcp: z\n .object({\n enabled: BooleanOrString,\n mountPath: MountPathSchema,\n })\n .strict(),\n // Optional block: A2A is off unless an operator asks for it, and an\n // existing config predating the adapter stays valid.\n a2a: z\n .object({\n enabled: BooleanOrString,\n mountPath: MountPathSchema.optional(),\n })\n .strict()\n .optional(),\n // Likewise optional and off by default. The sub-blocks are optional here\n // and required by the business pass only when ACP is enabled, so a\n // disabled placeholder block stays writable and an enabled one gets a\n // message naming the piece it is missing.\n acp: z\n .object({\n enabled: BooleanOrString,\n mountPath: MountPathSchema.optional(),\n auth: AcpAuthSchema.optional(),\n idempotency: AcpIdempotencySchema.optional(),\n checkout: AcpCheckoutSchema.optional(),\n discovery: AcpDiscoverySchema.optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\n/** Applied when `protocols.a2a` is absent or names no mount. */\nconst DEFAULT_A2A_MOUNT_PATH = '/a2a';\n\n/** Applied when `protocols.acp` is absent or names no mount. */\nconst DEFAULT_ACP_MOUNT_PATH = '/acp';\n\n/**\n * Idempotency records must outlive the window in which a client may retry, and\n * ACP fixes that window at 24 hours. A shorter retention would let a replayed\n * key past an expired record and run a checkout side effect twice, so it is\n * both the default and the floor.\n */\nconst ACP_RETENTION_HOURS = 24;\n\nconst BackendMethodSchema = z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);\n\n/**\n * Names the top-level input properties carrying each part of the backend\n * request. Strict: a typo like `bodyy` must fail at load, not silently mean\n * \"no body binding\" and ship a request missing its payload.\n */\nconst BackendInputBindingsSchema = z\n .object({\n path: z.string().min(1).optional(),\n query: z.string().min(1).optional(),\n body: z.string().min(1).optional(),\n })\n .strict();\n\nconst BackendHandlerSchema = z\n .object({\n type: z.literal('http'),\n method: BackendMethodSchema,\n url: z.string().min(1),\n headers: z.record(z.string(), z.string()).optional(),\n timeoutMs: NumberOrString.optional(),\n inputBindings: BackendInputBindingsSchema.optional(),\n })\n .strict();\n\nconst PricingSchema = z.discriminatedUnion('type', [\n z.object({ type: z.literal('free') }).strict(),\n z\n .object({\n type: z.literal('fixed'),\n amount: z.string().min(1),\n currency: z.string().min(1),\n })\n .strict(),\n z\n .object({\n type: z.literal('dynamic'),\n resolver: z.string().min(1),\n })\n .strict(),\n]);\n\nconst JsonSchemaValueSchema: ZodTypeAny = z.record(z.string(), z.unknown());\n\nconst ResourceEntrySchema = z\n .object({\n name: z.string().min(1),\n description: z.string().optional(),\n input: JsonSchemaValueSchema.optional(),\n output: JsonSchemaValueSchema.optional(),\n backend: BackendHandlerSchema,\n pricing: PricingSchema,\n expose: z.array(z.string().min(1)).min(1),\n payments: z.array(z.string().min(1)).optional(),\n })\n .strict();\n\nconst ResourcesMapSchema = z.record(z.string().min(1), ResourceEntrySchema);\n\n/**\n * Facilitator credentials, kept generic on purpose: x402 facilitators are not\n * a single-vendor category, and an auth block shaped around one provider's\n * credentials would make the abstraction a fiction. A facilitator needing\n * per-request signed credentials is refused rather than sent nothing.\n */\nconst FacilitatorAuthSchema = z.discriminatedUnion('type', [\n z.object({ type: z.literal('none') }).strict(),\n z.object({ type: z.literal('bearer'), token: z.string().min(1) }).strict(),\n // Coinbase Developer Platform. Needs the optional peer `@coinbase/x402`,\n // which signs a fresh JWT per request; a static header cannot express it.\n z\n .object({\n type: z.literal('cdp'),\n apiKeyId: z.string().min(1),\n apiKeySecret: z.string().min(1),\n })\n .strict(),\n]);\n\nconst FacilitatorSchema = z.discriminatedUnion('mode', [\n z\n .object({\n mode: z.literal('local'),\n signerPrivateKey: z.string().min(1),\n })\n .strict(),\n z\n .object({\n mode: z.literal('remote'),\n url: z.string().min(1),\n // Absent means \"this facilitator takes no credential\" - an explicit\n // statement, normalised to `{ type: 'none' }` below. On a mainnet that\n // combination is refused outright, so the default can never quietly\n // become an unauthenticated production facilitator.\n auth: FacilitatorAuthSchema.optional(),\n })\n .strict(),\n]);\n\nconst X402Schema = z\n .object({\n enabled: BooleanOrString,\n network: z.string().min(1),\n rpcUrl: z.string().min(1),\n asset: z.string().min(1),\n assetName: z.string().min(1),\n assetVersion: z.string().min(1),\n assetDecimals: NumberOrString,\n payTo: z.string().min(1),\n maxTimeoutSeconds: NumberOrString,\n facilitator: FacilitatorSchema,\n /** Real funds. Never defaulted - see src/payments/x402/guardrails.ts. */\n allowMainnet: BooleanOrString.optional(),\n /** Accepts a mainnet facilitator that takes no credential. Never defaulted. */\n allowUnauthenticatedFacilitator: BooleanOrString.optional(),\n })\n .strict();\n\nconst PaymentsSchema = z\n .object({\n x402: X402Schema.optional(),\n })\n .strict();\n\nconst RawConfigSchema = z\n .object({\n version: z.literal(SUPPORTED_CONFIG_VERSION),\n merchant: MerchantSchema,\n server: ServerSchema,\n storage: StorageSchema,\n protocols: ProtocolsSchema,\n resources: ResourcesMapSchema,\n payments: PaymentsSchema,\n })\n .strict();\n\ntype RawConfig = z.infer<typeof RawConfigSchema>;\ntype RawResourceEntry = z.infer<typeof ResourceEntrySchema>;\n\n// ---------------------------------------------------------------------------\n// Public shape (docs/contracts.md - exact).\n// ---------------------------------------------------------------------------\n\n/** Optional ACP discovery metadata. Absent fields are omitted from the document. */\nexport interface AcpDiscoveryConfig {\n readonly documentationUrl?: string;\n readonly supportedCurrencies?: readonly string[];\n readonly supportedLocales?: readonly string[];\n readonly interventionTypes?: readonly string[];\n}\n\n/**\n * Discriminated on `enabled` so an enabled ACP config carries everything the\n * adapter needs, with no optional-field assertions at the mount point: a\n * half-configured checkout lifecycle is rejected at load instead.\n */\nexport type AcpProtocolConfig =\n | { readonly enabled: false; readonly mountPath: string }\n | {\n readonly enabled: true;\n readonly mountPath: string;\n readonly auth: { readonly type: 'bearer'; readonly token: string };\n readonly idempotency: { readonly path: string; readonly retentionHours: number };\n readonly checkout: {\n readonly operations: Readonly<Record<AcpCheckoutOperation, string>>;\n };\n readonly discovery?: AcpDiscoveryConfig;\n };\n\nexport interface GatewayConfig {\n readonly version: 1;\n readonly merchant: { readonly id: string; readonly name: string; readonly publicBaseUrl: string };\n readonly server: {\n readonly port: number;\n readonly host: string;\n readonly adminToken?: string;\n readonly allowedOrigins: readonly string[];\n };\n readonly storage: { readonly receipts: { readonly driver: 'sqlite'; readonly path: string } };\n readonly protocols: {\n readonly http: { readonly enabled: boolean };\n readonly mcp: { readonly enabled: boolean; readonly mountPath: string };\n readonly a2a: { readonly enabled: boolean; readonly mountPath: string };\n readonly acp: AcpProtocolConfig;\n };\n /** Canonical resources, already normalised. */\n readonly resources: readonly CommerceResource[];\n readonly payments: {\n readonly x402?: {\n readonly enabled: boolean;\n readonly network: string;\n readonly rpcUrl: string;\n readonly asset: string;\n readonly assetName: string;\n readonly assetVersion: string;\n readonly assetDecimals: number;\n readonly payTo: string;\n readonly maxTimeoutSeconds: number;\n readonly facilitator: X402FacilitatorConfig;\n readonly allowMainnet?: boolean;\n readonly allowUnauthenticatedFacilitator?: boolean;\n };\n };\n}\n\n// ---------------------------------------------------------------------------\n// Entry point\n// ---------------------------------------------------------------------------\n\nexport function parseConfig(raw: unknown, env: NodeJS.ProcessEnv): GatewayConfig {\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'Configuration root must be a mapping (object) at \"$\"',\n {\n details: { path: '$' },\n },\n );\n }\n\n checkVersion(raw as Record<string, unknown>);\n\n const substituted = substituteEnv(raw, env);\n const parsed = parseWithZod(RawConfigSchema, substituted);\n return normalise(parsed);\n}\n\nfunction checkVersion(raw: Record<string, unknown>): void {\n if (!('version' in raw)) {\n throw new CommerceError('CONFIG_INVALID', 'Configuration is missing required field \"version\"', {\n details: { path: 'version' },\n });\n }\n const rawVersion = raw['version'];\n const version = typeof rawVersion === 'string' ? Number(rawVersion) : rawVersion;\n if (version !== SUPPORTED_CONFIG_VERSION) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Unsupported config version \"${String(rawVersion)}\": this gateway only supports version ${SUPPORTED_CONFIG_VERSION}`,\n { details: { path: 'version', supported: SUPPORTED_CONFIG_VERSION } },\n );\n }\n}\n\nfunction parseWithZod<T>(schema: z.ZodType<T>, value: unknown): T {\n const result = schema.safeParse(value);\n if (!result.success) {\n throw zodErrorToConfigError(result.error);\n }\n return result.data;\n}\n\nfunction zodErrorToConfigError(error: ZodError): CommerceError {\n const issues = error.issues.map(describeIssue);\n const first = issues[0];\n const message = first\n ? `Configuration invalid at \"${first.path}\": ${first.message}`\n : 'Configuration invalid';\n return new CommerceError('CONFIG_INVALID', message, { details: { issues } });\n}\n\nfunction describeIssue(issue: ZodIssue): { path: string; message: string; code: string } {\n const path = issue.path.length > 0 ? issue.path.join('.') : '$';\n return { path, message: issue.message, code: issue.code };\n}\n\n// ---------------------------------------------------------------------------\n// Numeric / boolean coercion (explicit, not via Zod - see file header).\n// ---------------------------------------------------------------------------\n\nfunction toNumber(\n value: number | string,\n path: string,\n bounds: { min?: number; max?: number } = {},\n): number {\n // `Number('')` is 0 - finite, integral, and inside\n // `server.port`'s deliberate `min: 0` (\"let the OS pick\"). So `port: ${PORT:-}`\n // or an exported-but-empty PORT validated PASS and the gateway bound a random\n // port, after which `doctor` derived `http://127.0.0.1:0`, failed to connect,\n // and reported the gateway unreachable while it was serving. `Number` also\n // accepts `\"0x50\"` (80) and `\"1e3\"` (1000) for fields that are decimal\n // integers everywhere they are documented. Require plain digits instead.\n if (typeof value === 'string' && !/^\\s*\\d+\\s*$/.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be an integer written in decimal digits (got ${value === '' ? 'an empty string' : `\"${value}\"`})`,\n { details: { path } },\n );\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n) || !Number.isInteger(n)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be an integer`,\n {\n details: { path },\n },\n );\n }\n if (bounds.min !== undefined && n < bounds.min) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be >= ${bounds.min}`,\n {\n details: { path },\n },\n );\n }\n if (bounds.max !== undefined && n > bounds.max) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be <= ${bounds.max}`,\n {\n details: { path },\n },\n );\n }\n return n;\n}\n\nfunction toBoolean(value: boolean | string, path: string): boolean {\n if (typeof value === 'boolean') return value;\n const normalized = value.trim().toLowerCase();\n if (normalized === 'true') return true;\n if (normalized === 'false') return false;\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must be a boolean (\"true\" or \"false\")`,\n { details: { path } },\n );\n}\n\n// ---------------------------------------------------------------------------\n// Business-rule validation + normalisation into the canonical shape.\n// ---------------------------------------------------------------------------\n\nconst SUPPORTED_PROTOCOLS: ReadonlySet<string> = new Set(PROTOCOL_NAMES);\nconst SUPPORTED_PAYMENT_METHODS = new Set(['x402']);\n\nfunction normalise(raw: RawConfig): GatewayConfig {\n const protocols = {\n http: { enabled: toBoolean(raw.protocols.http.enabled, 'protocols.http.enabled') },\n mcp: {\n enabled: toBoolean(raw.protocols.mcp.enabled, 'protocols.mcp.enabled'),\n mountPath: raw.protocols.mcp.mountPath,\n },\n a2a: {\n enabled: toBoolean(raw.protocols.a2a?.enabled ?? false, 'protocols.a2a.enabled'),\n mountPath: raw.protocols.a2a?.mountPath ?? DEFAULT_A2A_MOUNT_PATH,\n },\n acp: normaliseAcp(raw.protocols.acp),\n };\n validateMountPaths(protocols);\n\n const x402Raw = raw.payments.x402;\n const facilitator: X402FacilitatorConfig | undefined =\n x402Raw === undefined\n ? undefined\n : x402Raw.facilitator.mode === 'local'\n ? { mode: 'local', signerPrivateKey: x402Raw.facilitator.signerPrivateKey }\n : {\n mode: 'remote',\n url: x402Raw.facilitator.url,\n auth: x402Raw.facilitator.auth ?? { type: 'none' },\n };\n const x402 =\n x402Raw && facilitator\n ? {\n enabled: toBoolean(x402Raw.enabled, 'payments.x402.enabled'),\n network: x402Raw.network,\n rpcUrl: x402Raw.rpcUrl,\n asset: x402Raw.asset,\n assetName: x402Raw.assetName,\n assetVersion: x402Raw.assetVersion,\n assetDecimals: toNumber(x402Raw.assetDecimals, 'payments.x402.assetDecimals', {\n min: 0,\n max: 36,\n }),\n payTo: x402Raw.payTo,\n maxTimeoutSeconds: toNumber(\n x402Raw.maxTimeoutSeconds,\n 'payments.x402.maxTimeoutSeconds',\n {\n min: 1,\n },\n ),\n facilitator,\n ...(x402Raw.allowMainnet !== undefined\n ? { allowMainnet: toBoolean(x402Raw.allowMainnet, 'payments.x402.allowMainnet') }\n : {}),\n ...(x402Raw.allowUnauthenticatedFacilitator !== undefined\n ? {\n allowUnauthenticatedFacilitator: toBoolean(\n x402Raw.allowUnauthenticatedFacilitator,\n 'payments.x402.allowUnauthenticatedFacilitator',\n ),\n }\n : {}),\n }\n : undefined;\n\n if (x402) {\n validateAddress('payments.x402.payTo', x402.payTo);\n validateAddress('payments.x402.asset', x402.asset);\n // The same call the provider makes at construction, run here so\n // `agent-commerce validate` reports an unsafe deployment where an operator\n // expects to hear about it, rather than at first boot.\n resolveX402Deployment({\n network: x402.network,\n payTo: x402.payTo,\n asset: x402.asset,\n assetName: x402.assetName,\n assetVersion: x402.assetVersion,\n facilitator: x402.facilitator,\n ...(x402.allowMainnet !== undefined ? { allowMainnet: x402.allowMainnet } : {}),\n ...(x402.allowUnauthenticatedFacilitator !== undefined\n ? { allowUnauthenticatedFacilitator: x402.allowUnauthenticatedFacilitator }\n : {}),\n });\n }\n\n const resources = Object.entries(raw.resources).map(([id, entry]) =>\n normaliseResource(id, entry, protocols, x402),\n );\n if (protocols.acp.enabled) validateAcpCheckoutMapping(protocols.acp, resources);\n\n return {\n version: SUPPORTED_CONFIG_VERSION,\n merchant: {\n id: raw.merchant.id,\n name: raw.merchant.name,\n publicBaseUrl: raw.merchant.publicBaseUrl,\n },\n // min 0, not 1: port 0 is the standard \"let the OS pick a free port\"\n // convention, useful for tests and ephemeral dev/demo instances.\n server: {\n port: toNumber(raw.server.port, 'server.port', { min: 0, max: 65535 }),\n host: raw.server.host,\n ...(raw.server.adminToken !== undefined ? { adminToken: raw.server.adminToken } : {}),\n allowedOrigins: raw.server.allowedOrigins ?? [],\n },\n storage: { receipts: { driver: 'sqlite', path: raw.storage.receipts.path } },\n protocols,\n resources,\n payments: {\n ...(x402 !== undefined ? { x402 } : {}),\n },\n };\n}\n\ninterface NormalisedProtocols {\n readonly http: { readonly enabled: boolean };\n readonly mcp: { readonly enabled: boolean; readonly mountPath: string };\n readonly a2a: { readonly enabled: boolean; readonly mountPath: string };\n readonly acp: AcpProtocolConfig;\n}\n\n/**\n * Two enabled mounts may not overlap: each registers a `${mountPath}/*`\n * wildcard, so a shared prefix means one adapter silently answers for the\n * other. Disabled protocols mount nothing and are not compared.\n */\nfunction validateMountPaths(protocols: NormalisedProtocols): void {\n const mounts = (\n [\n ['mcp', protocols.mcp],\n ['a2a', protocols.a2a],\n ['acp', protocols.acp],\n ] as const\n ).filter(([, p]) => p.enabled);\n\n for (const [index, [nameA, a]] of mounts.entries()) {\n for (const [nameB, b] of mounts.slice(index + 1)) {\n const baseA = a.mountPath.replace(/\\/+$/, '');\n const baseB = b.mountPath.replace(/\\/+$/, '');\n if (baseA === baseB || baseA.startsWith(`${baseB}/`) || baseB.startsWith(`${baseA}/`)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `protocols.${nameA}.mountPath (\"${a.mountPath}\") collides with protocols.${nameB}.mountPath (\"${b.mountPath}\") - each mount registers a wildcard, so overlapping prefixes cannot both be served`,\n { details: { path: `protocols.${nameA}.mountPath` } },\n );\n }\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// ACP (experimental)\n// ---------------------------------------------------------------------------\n\ntype RawAcp = NonNullable<RawConfig['protocols']['acp']>;\ntype EnabledAcpConfig = Extract<AcpProtocolConfig, { enabled: true }>;\n\nfunction acpInvalid(\n path: string,\n message: string,\n extra: Record<string, unknown> = {},\n): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path, ...extra } });\n}\n\nfunction normaliseAcp(raw: RawAcp | undefined): AcpProtocolConfig {\n const mountPath = raw?.mountPath ?? DEFAULT_ACP_MOUNT_PATH;\n if (raw === undefined || !toBoolean(raw.enabled, 'protocols.acp.enabled')) {\n return { enabled: false, mountPath };\n }\n\n if (raw.auth === undefined) {\n throw acpInvalid(\n 'protocols.acp.auth',\n 'protocols.acp.auth is required when ACP is enabled - every ACP checkout endpoint is authenticated, and \"bearer\" is the only scheme supported in this release',\n );\n }\n if (raw.idempotency === undefined) {\n throw acpInvalid(\n 'protocols.acp.idempotency',\n 'protocols.acp.idempotency is required when ACP is enabled - it names the SQLite file holding checkout idempotency records, and ACP makes the Idempotency-Key mandatory on every checkout POST',\n );\n }\n\n const discovery = raw.discovery;\n\n return {\n enabled: true,\n mountPath,\n auth: raw.auth,\n idempotency: {\n path: raw.idempotency.path,\n retentionHours: toNumber(\n raw.idempotency.retentionHours ?? ACP_RETENTION_HOURS,\n 'protocols.acp.idempotency.retentionHours',\n { min: ACP_RETENTION_HOURS },\n ),\n },\n checkout: { operations: normaliseAcpOperations(raw.checkout) },\n // Built key by key rather than passed through: absent metadata must stay\n // absent from the discovery document, not appear there as `undefined`.\n ...(discovery !== undefined\n ? {\n discovery: {\n ...(discovery.documentationUrl !== undefined\n ? { documentationUrl: discovery.documentationUrl }\n : {}),\n ...(discovery.supportedCurrencies !== undefined\n ? { supportedCurrencies: discovery.supportedCurrencies }\n : {}),\n ...(discovery.supportedLocales !== undefined\n ? { supportedLocales: discovery.supportedLocales }\n : {}),\n ...(discovery.interventionTypes !== undefined\n ? { interventionTypes: discovery.interventionTypes }\n : {}),\n },\n }\n : {}),\n };\n}\n\n/**\n * All five operations, each on its own resource.\n *\n * Partial mappings are refused because ACP discovery advertises `checkout` as\n * one service: a seller announcing it must be able to serve the whole\n * lifecycle. One resource serving two operations is refused because the\n * operations differ in method, canonical input and success status - a resource\n * that satisfies both is a resource that implements neither faithfully.\n */\nfunction normaliseAcpOperations(\n checkout: RawAcp['checkout'],\n): Readonly<Record<AcpCheckoutOperation, string>> {\n const configured: Record<string, string> = checkout?.operations ?? {};\n\n for (const key of Object.keys(configured)) {\n if (!(ACP_CHECKOUT_OPERATIONS as readonly string[]).includes(key)) {\n throw acpInvalid(\n `protocols.acp.checkout.operations.${key}`,\n `protocols.acp.checkout.operations names unknown ACP checkout operation \"${key}\". Supported: ${ACP_CHECKOUT_OPERATIONS.join(', ')}.`,\n );\n }\n }\n\n const operations: Record<string, string> = {};\n const claimedBy = new Map<string, AcpCheckoutOperation>();\n for (const operation of ACP_CHECKOUT_OPERATIONS) {\n const path = `protocols.acp.checkout.operations.${operation}`;\n const resourceId = configured[operation];\n if (resourceId === undefined) {\n throw acpInvalid(\n path,\n `${path} is required when ACP is enabled - all five checkout operations must be mapped, since ACP discovery advertises the checkout service as a whole`,\n );\n }\n const claimed = claimedBy.get(resourceId);\n if (claimed !== undefined) {\n throw acpInvalid(\n path,\n `${path} maps resource \"${resourceId}\", which is already mapped to \"${claimed}\" - each ACP checkout operation needs its own resource`,\n { resourceId },\n );\n }\n claimedBy.set(resourceId, operation);\n operations[operation] = resourceId;\n }\n return operations as Record<AcpCheckoutOperation, string>;\n}\n\nfunction validateAcpCheckoutMapping(\n acp: EnabledAcpConfig,\n resources: readonly CommerceResource[],\n): void {\n const byId = new Map(resources.map((resource) => [resource.id, resource]));\n\n for (const operation of ACP_CHECKOUT_OPERATIONS) {\n const resourceId = acp.checkout.operations[operation];\n const path = `protocols.acp.checkout.operations.${operation}`;\n const resource = byId.get(resourceId);\n if (resource === undefined) {\n throw acpInvalid(\n path,\n `${path} maps resource \"${resourceId}\", which is not defined under \"resources\"`,\n { resourceId },\n );\n }\n if (!resource.exposedVia.includes('acp')) {\n throw acpInvalid(\n path,\n `Resource \"${resourceId}\" implements ACP operation \"${operation}\" but does not list \"acp\" in its expose - the mapping says which resource serves the operation, expose says ACP may invoke it, and both are required`,\n { resourceId },\n );\n }\n // ACP checkout carries its own purchase payment (`payment_data` on\n // completion). Charging an Agent Commerce payment to *invoke* the operation\n // would stack a second, unrelated payment layer on one call, and ACP has no\n // wire representation for our payment-required outcome to negotiate it.\n if (resource.pricing.type !== 'free' || resource.paymentMethods.length > 0) {\n throw acpInvalid(\n path,\n `Resource \"${resourceId}\" implements ACP operation \"${operation}\" and must use pricing.type \"free\" with no \"payments\" - ACP checkout carries the merchant's own purchase payment, so the gateway does not also charge for the invocation`,\n { resourceId },\n );\n }\n validateAcpOperationInput(path, operation, resource);\n }\n}\n\n/**\n * The adapter sends a fixed canonical envelope per operation, so a resource\n * whose input schema forbids a key ACP always sends - or demands one ACP never\n * sends - can only ever fail at request time with INPUT_INVALID. Cheaper to\n * say so at load.\n */\nfunction validateAcpOperationInput(\n path: string,\n operation: AcpCheckoutOperation,\n resource: CommerceResource,\n): void {\n const schema = resource.inputSchema;\n if (schema === undefined) return;\n const keys: readonly string[] = ACP_OPERATION_INPUT_KEYS[operation];\n const properties = schema['properties'];\n\n if (schema['additionalProperties'] === false && isPlainObject(properties)) {\n for (const key of keys) {\n if (!Object.hasOwn(properties, key)) {\n throw acpInvalid(\n path,\n `Resource \"${resource.id}\" implements ACP operation \"${operation}\" but its input schema sets additionalProperties: false without declaring \"${key}\", which the adapter always sends for this operation`,\n { resourceId: resource.id },\n );\n }\n }\n }\n\n const required = schema['required'];\n if (Array.isArray(required)) {\n for (const entry of required) {\n if (typeof entry === 'string' && !keys.includes(entry)) {\n throw acpInvalid(\n path,\n `Resource \"${resource.id}\" implements ACP operation \"${operation}\" but its input schema requires \"${entry}\", which that operation never supplies (it sends: ${keys.join(', ')})`,\n { resourceId: resource.id },\n );\n }\n }\n }\n}\n\ninterface NormalisedX402 {\n readonly enabled: boolean;\n readonly assetDecimals: number;\n}\n\nfunction normaliseResource(\n id: string,\n entry: RawResourceEntry,\n protocols: NormalisedProtocols,\n x402: NormalisedX402 | undefined,\n): CommerceResource {\n if (entry.input !== undefined) validateResourceSchemaKeywords(id, 'input', entry.input);\n\n const inputProperties = entry.input?.['properties'];\n if (\n inputProperties &&\n typeof inputProperties === 'object' &&\n PAYMENT_INPUT_FIELD in inputProperties\n ) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" declares an input property \"${PAYMENT_INPUT_FIELD}\", which is reserved for payment proofs`,\n {\n details: {\n path: `resources.${id}.input.properties.${PAYMENT_INPUT_FIELD}`,\n resourceId: id,\n },\n },\n );\n }\n\n for (const protocol of entry.expose) {\n if (!SUPPORTED_PROTOCOLS.has(protocol)) {\n const hint = protocol === 'ucp' ? ' (UCP is planned, not supported in this release)' : '';\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" exposes unsupported protocol \"${protocol}\"${hint}. Supported: ${PROTOCOL_NAMES.join(', ')}.`,\n { details: { path: `resources.${id}.expose`, resourceId: id, protocol } },\n );\n }\n }\n if (entry.expose.includes('mcp')) {\n if (!protocols.mcp.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"mcp\" but protocols.mcp.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n if (!MCP_TOOL_NAME_PATTERN.test(id)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"mcp\" but its id is not a legal MCP tool name (allowed: A-Z, a-z, 0-9, \"_\", \"-\", \".\", 1-128 chars)`,\n { details: { path: `resources.${id}`, resourceId: id } },\n );\n }\n }\n if (entry.expose.includes('a2a') && !protocols.a2a.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"a2a\" but protocols.a2a.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n if (entry.expose.includes('acp') && !protocols.acp.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"acp\" but protocols.acp.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n if (entry.expose.includes('http') && !protocols.http.enabled) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" is exposed via \"http\" but protocols.http.enabled is false`,\n { details: { path: `resources.${id}.expose`, resourceId: id } },\n );\n }\n\n validateBackendUrl(id, entry.backend.url);\n const pathScope = validateInputBindings(id, entry.backend, entry.input);\n validatePathParametersDeclared(id, entry.backend.url, pathScope.schema, pathScope.where);\n\n if (entry.pricing.type === 'dynamic') {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" uses pricing.type \"dynamic\", which is not supported in this release`,\n { details: { path: `resources.${id}.pricing.type`, resourceId: id } },\n );\n }\n\n if (entry.pricing.type === 'fixed') {\n validatePricingAmount(id, entry.pricing.amount, x402);\n }\n\n const paymentMethods = entry.payments ?? [];\n\n if (entry.pricing.type === 'fixed') {\n if (paymentMethods.length === 0) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has fixed pricing but declares no \"payments\" (a paid resource must name at least one payment method)`,\n { details: { path: `resources.${id}.payments`, resourceId: id } },\n );\n }\n for (const method of paymentMethods) {\n if (!SUPPORTED_PAYMENT_METHODS.has(method)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" names unsupported payment method \"${method}\". Supported: x402.`,\n { details: { path: `resources.${id}.payments`, resourceId: id, method } },\n );\n }\n if (method === 'x402' && (!x402 || !x402.enabled)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" names payment method \"x402\" which is not configured or not enabled under payments.x402`,\n { details: { path: `resources.${id}.payments`, resourceId: id, method } },\n );\n }\n }\n }\n\n const pricing: Pricing =\n entry.pricing.type === 'free'\n ? { type: 'free' }\n : { type: 'fixed', amount: entry.pricing.amount, currency: entry.pricing.currency };\n\n return {\n id,\n name: entry.name,\n ...(entry.description !== undefined ? { description: entry.description } : {}),\n inputSchema:\n entry.input !== undefined\n ? defaultClosedObjectSchema(entry.input)\n : EMPTY_CLOSED_OBJECT_SCHEMA,\n ...(entry.output !== undefined ? { outputSchema: entry.output } : {}),\n handler: {\n type: 'http',\n method: entry.backend.method,\n url: entry.backend.url,\n ...(entry.backend.headers !== undefined ? { headers: entry.backend.headers } : {}),\n ...(entry.backend.timeoutMs !== undefined\n ? {\n timeoutMs: toNumber(entry.backend.timeoutMs, `resources.${id}.backend.timeoutMs`, {\n min: 1,\n }),\n }\n : {}),\n ...(entry.backend.inputBindings !== undefined\n ? { inputBindings: pickDefined(entry.backend.inputBindings) }\n : {}),\n },\n pricing,\n exposedVia: entry.expose as CommerceResource['exposedVia'],\n paymentMethods: paymentMethods as CommerceResource['paymentMethods'],\n };\n}\n\n/**\n * `{param}` templates (e.g. `.../weather/{city}`) parse fine as a URL - the\n * WHATWG parser just percent-encodes the braces - so this only rejects\n * genuinely malformed strings and non-http(s) schemes, not templating.\n */\n/**\n * Permissive-by-default is the wrong default for a value forwarded to\n * someone else's API: an object schema that\n * omits `additionalProperties` defaults, per JSON Schema itself, to\n * \"anything goes\" - so default it to `false` here instead, unless the\n * operator set it explicitly (including explicitly to `true`, which is\n * respected).\n *\n * An earlier fix only stamped the ROOT schema, so\n * `filter: { type: object }` *looked* closed (the top level really was)\n * while every key one level down under `properties.filter` still passed\n * verbatim - `core`'s validator (execution/validation.ts) only enforces\n * `additionalProperties` where the schema states it explicitly, at every\n * level independently. Recurse into `properties` and `items` the same way\n * `validateResourceSchemaKeywords` below already does, so \"closed\" actually\n * means closed at every depth, not just the one an operator happened to\n * write `additionalProperties: false` on.\n *\n * `type` can be an array (`[\"object\",\"null\"]`, valid JSON\n * Schema) - a bare `=== 'object'` string comparison missed it, so a schema\n * in that shape got stamped as open. `declaresObjectType` below is the same\n * check `core`'s validator now makes (`execution/validation.ts`'s\n * `isObjectSchemaNode`) so the two stay in agreement.\n */\nfunction defaultClosedObjectSchema(schema: Record<string, unknown>): Record<string, unknown> {\n // imported, never re-implemented. The local predicate this\n // replaces recognised `type`/`properties` but not `required`, while core's\n // validator recognised `properties`/`required` - so `input: { required: [q] }`\n // was an object to the validator and not to the stamper, and every unknown\n // key sailed through to the merchant backend. One definition, one drift.\n const isObjectSchema = isObjectSchemaNode(schema);\n const result: Record<string, unknown> = { ...schema };\n\n if (isObjectSchema) {\n const properties = schema['properties'];\n if (isPlainObject(properties)) {\n result['properties'] = Object.fromEntries(\n Object.entries(properties).map(([key, sub]) => [\n key,\n isPlainObject(sub) ? defaultClosedObjectSchema(sub) : sub,\n ]),\n );\n }\n if (!Object.hasOwn(schema, 'additionalProperties')) {\n result['additionalProperties'] = false;\n }\n }\n\n const items = schema['items'];\n if (isPlainObject(items)) {\n result['items'] = defaultClosedObjectSchema(items);\n }\n\n // The third place this stamper drifted from the validator, after `required`\n // and tuple `items`. `additionalProperties: {schema}` is the idiomatic\n // \"map of typed objects\" shape, and core's validator applies that subschema\n // recursively at unbounded depth - so without this branch, every node under\n // it stayed open and unknown keys reached the merchant backend. Recursion\n // here is not conditional on `isObjectSchema`: the validator applies the\n // subschema wherever it finds one.\n const additional = schema['additionalProperties'];\n if (isPlainObject(additional)) {\n result['additionalProperties'] = defaultClosedObjectSchema(additional);\n }\n\n return result;\n}\n\n/**\n * A resource that declares no `input:` at all got\n * `inputSchema: undefined`, and `compileJsonSchema(undefined)` is an\n * always-valid validator - every caller key was forwarded to the merchant\n * backend verbatim. The decision: default \"declared nothing\" to \"accepts\n * nothing\" (an empty closed object) rather than rejecting the config at load\n * time - a no-argument resource that omits `input:` is a legitimate shape,\n * and rejecting it would break every existing config that uses it.\n */\nconst EMPTY_CLOSED_OBJECT_SCHEMA: Record<string, unknown> = {\n type: 'object',\n properties: {},\n additionalProperties: false,\n};\n\n/**\n * `src/core`'s validator only enforces the subset documented in\n * `execution/validation.ts` (type/properties/required/additionalProperties/\n * enum/items) - everything else (`pattern`, `minLength`, `format`, `oneOf`,\n * …) is silently ignored at runtime. An operator who writes `pattern` and\n * never sees it enforced has no way to know that from the config alone, so\n * warn at load time instead of letting them find out the hard way.\n */\nconst UNSUPPORTED_SCHEMA_KEYWORDS = [\n 'pattern',\n 'minLength',\n 'maxLength',\n 'format',\n 'minimum',\n 'maximum',\n 'exclusiveMinimum',\n 'exclusiveMaximum',\n 'multipleOf',\n 'oneOf',\n 'anyOf',\n 'allOf',\n 'not',\n '$ref',\n 'const',\n 'patternProperties',\n 'minItems',\n 'maxItems',\n 'uniqueItems',\n];\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** `type` explicitly set to something that rules out \"object\" (a bare\n * value, or an array not containing \"object\"). `undefined` - no `type` at\n * all - is deliberately NOT treated as excluding: core's validator treats\n * `properties`/`required` with no `type` as an object schema, so that shape\n * is fine, not another instance of this bug. */\nfunction excludesObjectType(schema: Record<string, unknown>): boolean {\n const type = schema['type'];\n if (type === undefined || type === 'object') return false;\n if (Array.isArray(type)) return !type.includes('object');\n return true;\n}\n\n/**\n * Walks a resource's input schema once, both warning (existing, unenforced\n * keywords) and rejecting (a node whose declared `type`\n * cannot structurally be an object, yet which still carries `properties` or\n * `required`). The `properties`/`required`-with-no-`type` shape is not\n * this function's problem any more, since the\n * validator now treats that shape as an object; what's still a trap is a\n * `type` that actively rules \"object\" out while `properties`/`required`\n * imply it was meant to be one, e.g. a copy-pasted sibling schema whose\n * `type` was never updated. Rejecting (not just warning) here is the\n * decision - a warning is exactly what let this bug class ship silently in\n * the first place (`validate`/`doctor` both said PASS).\n */\nfunction validateResourceSchemaKeywords(\n id: string,\n path: string,\n schema: Record<string, unknown>,\n): void {\n for (const keyword of UNSUPPORTED_SCHEMA_KEYWORDS) {\n if (Object.hasOwn(schema, keyword)) {\n // eslint-disable-next-line no-console\n console.warn(\n `[agent-commerce] resource \"${id}\" ${path} uses JSON Schema keyword \"${keyword}\", which this gateway does not enforce (see src/core/execution/validation.ts for the supported subset). Remove it or treat it as documentation only.`,\n );\n }\n }\n if (\n (Object.hasOwn(schema, 'properties') || Object.hasOwn(schema, 'required')) &&\n excludesObjectType(schema)\n ) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" ${path} declares \"properties\" and/or \"required\" but its \"type\" (${JSON.stringify(schema['type'])}) does not include \"object\" - the validator will never route a value through either check under that type, so this schema claims to constrain input it does not actually enforce. Remove \"properties\"/\"required\", or include \"object\" in \"type\".`,\n { details: { path: `resources.${id}.${path}`, resourceId: id } },\n );\n }\n // the other half. Closing a `required`-only node is\n // correct JSON Schema and quietly unsatisfiable: `required: [\"q\"]` demands a\n // property that `properties` never declares, so the stamped\n // `additionalProperties: false` rejects `q` as an unknown key - the schema\n // can never be satisfied by any input at all. Fail-closed, so no money is at\n // risk, but every call would 400 with a config that loaded cleanly. Say so\n // at load instead. Only when the node really will be closed: an explicit\n // `additionalProperties` other than `false` leaves the name reachable.\n const requiredRaw = schema['required'];\n const closed = !Object.hasOwn(schema, 'additionalProperties')\n ? true\n : schema['additionalProperties'] === false;\n if (Array.isArray(requiredRaw) && closed && isObjectSchemaNode(schema)) {\n const declared = isPlainObject(schema['properties']) ? schema['properties'] : {};\n const undeclared = requiredRaw.filter(\n (name): name is string => typeof name === 'string' && !Object.hasOwn(declared, name),\n );\n if (undeclared.length > 0) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" ${path} lists ${undeclared.map((n) => `\"${n}\"`).join(', ')} in \"required\" but does not declare ${undeclared.length === 1 ? 'it' : 'them'} in \"properties\". The schema is closed (additionalProperties: false), so ${undeclared.length === 1 ? 'that name is' : 'those names are'} rejected as an unknown key and no input can ever satisfy this schema. Declare ${undeclared.length === 1 ? 'it' : 'them'} in \"properties\".`,\n { details: { path: `resources.${id}.${path}`, resourceId: id, undeclared } },\n );\n }\n }\n\n const properties = schema['properties'];\n if (isPlainObject(properties)) {\n for (const [key, sub] of Object.entries(properties)) {\n if (isPlainObject(sub)) validateResourceSchemaKeywords(id, `${path}.properties.${key}`, sub);\n }\n }\n const additional = schema['additionalProperties'];\n if (isPlainObject(additional)) {\n validateResourceSchemaKeywords(id, `${path}.additionalProperties`, additional);\n }\n const items = schema['items'];\n if (isPlainObject(items)) {\n validateResourceSchemaKeywords(id, `${path}.items`, items);\n } else if (Array.isArray(items)) {\n // tuple-form `items` (an array of per-position\n // schemas) is valid JSON Schema, but `core`'s validator only supports\n // the single-schema form applied to every element - a tuple silently\n // enforces nothing, invisibly rather than wrongly, so warn the same way\n // an unsupported keyword does.\n // eslint-disable-next-line no-console\n console.warn(\n `[agent-commerce] resource \"${id}\" ${path}.items is a tuple (an array of schemas), which this gateway does not enforce - only a single schema applied to every array element is supported (see src/core/execution/validation.ts). Each position's schema is unenforced; treat it as documentation only.`,\n );\n }\n}\n\n/**\n * `amount: z.string().min(1)` alone let \"0,01\", \"$0.01\", \"1e-2\", \"-1\" and an\n * over-precise \"0.0000001\" all pass config + `doctor`, then throw on every\n * purchase. A plain\n * positive decimal only - no currency symbol, no thousands separator, no\n * exponent notation.\n */\nconst PRICING_AMOUNT_PATTERN = /^\\d+(?:\\.\\d+)?$/;\nconst ZERO_AMOUNT_PATTERN = /^0(?:\\.0+)?$/;\n\nfunction validatePricingAmount(id: string, amount: string, x402: NormalisedX402 | undefined): void {\n const path = `resources.${id}.pricing.amount`;\n if (!PRICING_AMOUNT_PATTERN.test(amount)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"${amount}\", which is not a plain positive decimal (no currency symbol, no thousands separator, no exponent - e.g. \"0.01\")`,\n { details: { path, resourceId: id } },\n );\n }\n if (ZERO_AMOUNT_PATTERN.test(amount)) {\n // A zero-priced \"paid\" resource settles a zero-value transfer, which is\n // nonsense - if something is free, it should say so.\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"0\" - a paid resource cannot cost zero; use \"pricing: { type: free }\" instead`,\n { details: { path, resourceId: id } },\n );\n }\n if (x402 !== undefined) {\n const fractionalDigits = amount.includes('.') ? (amount.split('.')[1]?.length ?? 0) : 0;\n if (fractionalDigits > x402.assetDecimals) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has pricing.amount \"${amount}\" with more precision (${fractionalDigits} fractional digits) than the configured asset supports (${x402.assetDecimals} decimals)`,\n { details: { path, resourceId: id } },\n );\n }\n }\n}\n\n/**\n * `backend.inputBindings` names top-level input properties; this is the gate\n * that makes those names mean something at load time rather than at the first\n * paid call. Input schemas are closed by default at every depth\n * (`defaultClosedObjectSchema`), so a binding naming a property the schema\n * never declares can never be satisfied - the group would be silently empty\n * on every request, which on a paid resource is payment for a request the\n * backend receives incomplete.\n *\n * Returns the schema node `{param}` declarations must be found in: the path\n * group in explicit mode, the whole input in legacy mode.\n */\nfunction validateInputBindings(\n id: string,\n backend: RawResourceEntry['backend'],\n input: Record<string, unknown> | undefined,\n): { readonly schema: Record<string, unknown> | undefined; readonly where: string } {\n const legacy = { schema: input, where: 'its input schema' } as const;\n const bindings = backend.inputBindings;\n const templated = extractPathParameterNames(backend.url).length > 0;\n if (bindings === undefined) return legacy;\n\n const path = `resources.${id}.backend.inputBindings`;\n const fail = (message: string, details: Record<string, unknown> = {}): never => {\n throw new CommerceError('CONFIG_INVALID', `Resource \"${id}\" ${message}`, {\n details: { path, resourceId: id, ...details },\n });\n };\n\n const entries = Object.entries(bindings).filter(\n (entry): entry is [string, string] => entry[1] !== undefined,\n );\n if (entries.length === 0) {\n fail('has an empty backend.inputBindings - remove the block to use the default mapping');\n }\n if (backend.method === 'GET' || backend.method === 'DELETE') {\n if (bindings.body !== undefined) {\n fail(\n `binds a request body on a ${backend.method}, which sends none - the value would be silently dropped`,\n );\n }\n }\n if (templated && bindings.path === undefined) {\n fail(\n 'has backend.url path parameters but no \"path\" binding - in explicit binding mode nothing else supplies them, so every call would fail to reach the backend',\n );\n }\n\n const seen = new Map<string, string>();\n const properties = isPlainObject(input?.['properties']) ? input['properties'] : {};\n const required = new Set(\n Array.isArray(input?.['required'])\n ? input['required'].filter((value): value is string => typeof value === 'string')\n : [],\n );\n\n for (const [location, property] of entries) {\n if (property === PAYMENT_INPUT_FIELD) {\n fail(\n `binds \"${location}\" to \"${PAYMENT_INPUT_FIELD}\", which is reserved for payment proofs`,\n { location },\n );\n }\n const other = seen.get(property);\n if (other !== undefined) {\n fail(`binds both \"${other}\" and \"${location}\" to the input property \"${property}\"`, {\n location,\n property,\n });\n }\n seen.set(property, location);\n\n if (!Object.hasOwn(properties, property)) {\n fail(\n `binds \"${location}\" to input property \"${property}\", which the input schema does not declare - the schema is closed, so a caller could never supply it`,\n { location, property },\n );\n }\n // `body` may legitimately be any JSON value; only the two groups the\n // executor iterates as key/value pairs have to be objects.\n const declared = properties[property];\n if (location !== 'body' && isPlainObject(declared) && !isObjectSchemaNode(declared)) {\n fail(\n `binds \"${location}\" to input property \"${property}\", which is not an object schema - ${location} parameters are read as an object of name/value pairs`,\n { location, property },\n );\n }\n }\n\n if (templated && bindings.path !== undefined && !required.has(bindings.path)) {\n fail(\n `binds path parameters to input property \"${bindings.path}\" without listing it in the input schema's \"required\" - a caller that omits it cannot supply any path parameter, so the request could never be built`,\n { property: bindings.path },\n );\n }\n\n if (bindings.path === undefined) return { schema: undefined, where: 'its input schema' };\n const group = properties[bindings.path];\n return {\n schema: isPlainObject(group) ? group : undefined,\n where: `input.properties.${bindings.path}`,\n };\n}\n\n/** Strips absent optional keys so the result satisfies `exactOptionalPropertyTypes`. */\nfunction pickDefined<T extends Record<string, string | undefined>>(\n value: T,\n): { [K in keyof T]?: string } {\n return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined)) as {\n [K in keyof T]?: string;\n };\n}\n\n/**\n * The root-cause half. `validateBackendRequestShape`\n * (src/core) rejects a missing path parameter at request time - after\n * schema validation but, without this check, on every single call, because\n * a schema that never declares `{city}` can never satisfy it. A paid\n * resource in that shape settles the buyer's payment and then always fails\n * to reach the backend: no refund, replay key burned, on every call, not an\n * unlucky one. Every `{param}` in `backend.url` must be BOTH declared in\n * `properties` AND listed in `required` - an optional value hits the exact\n * same \"caller structurally cannot supply it on every call that omits it\"\n * problem as an undeclared one, just less often. This is the config-load\n * gate `agent-commerce validate`/`doctor` catch it at; the runtime\n * `INPUT_INVALID` in `validateBackendRequestShape` is defence in depth for\n * a hand-built `CommerceResource` this check never saw.\n */\nfunction validatePathParametersDeclared(\n id: string,\n url: string,\n input: Record<string, unknown> | undefined,\n where: string,\n): void {\n // Before anything else: a brace token the canonical grammar does not\n // recognise is neither extracted here nor substituted at request time, so it\n // would travel to the backend as a percent-encoded literal. On a paid\n // resource that is payment-without-delivery on every single call. Refuse it\n // at load rather than letting \"matches nothing\" mean \"nothing to check\".\n const stray = findUnparsedBraceToken(url);\n if (stray !== undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url containing \"${stray}\", which is not a valid path parameter (allowed characters: A-Z a-z 0-9 _ . -). It would be sent to the backend literally, so a paid resource would settle payment and then never reach the backend`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id, token: stray } },\n );\n }\n\n const params = extractPathParameterNames(url);\n if (params.length === 0) return;\n\n // Every defence around `{param}` guards the *path* position, and in the host\n // position all of them fail open at once: `new URL('http://{host}/api')`\n // parses (the hostname is literally `{host}`) so the URL check passes; the\n // runtime containment check is skipped because its literal prefix\n // (`http://`) does not itself parse as a URL; and `encodeURIComponent` does\n // not escape dots, so a hostname survives it whole. Caller input then chooses\n // which host the gateway calls - the metadata service, an internal address,\n // anything. `http://{region}.api.internal/...` is an ordinary-looking\n // multi-tenant template, so this is refused here rather than warned about.\n //\n // The rule: everything before the first `{` must already be a complete\n // authority - a parseable origin followed by the path's leading `/`.\n const firstBrace = url.indexOf('{');\n if (firstBrace !== -1) {\n const prefix = url.slice(0, firstBrace);\n let origin: string | undefined;\n try {\n const parsedPrefix = new URL(prefix);\n origin = parsedPrefix.hostname === '' ? undefined : parsedPrefix.origin;\n } catch {\n // Not a URL at all - the parameter starts before the authority is done.\n }\n if (origin === undefined || !prefix.startsWith(`${origin}/`)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has a backend.url parameter before the end of the host (\"${url}\"). A caller-supplied value would choose which host the gateway calls, which is request forgery with the gateway's own network position. Parameters are supported inside the path and query only`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n }\n\n const propertiesRaw = input?.['properties'];\n const properties = isPlainObject(propertiesRaw) ? propertiesRaw : {};\n const requiredRaw = input?.['required'];\n const required = new Set(\n Array.isArray(requiredRaw)\n ? requiredRaw.filter((entry): entry is string => typeof entry === 'string')\n : [],\n );\n\n for (const param of params) {\n const path = `resources.${id}.backend.url`;\n if (!Object.hasOwn(properties, param)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url path parameter \"{${param}}\" which is not declared in ${where} - the caller has no way to supply it, so every call would settle payment (if priced) and then fail to reach the backend`,\n { details: { path, resourceId: id, param } },\n );\n }\n if (!required.has(param)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has backend.url path parameter \"{${param}}\" declared in ${where} but not listed in its \"required\" - a caller that omits it hits the same unservable-request problem as an undeclared parameter`,\n { details: { path, resourceId: id, param } },\n );\n }\n }\n}\n\nfunction validateBackendUrl(id: string, url: string): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has an invalid backend.url \"${url}\": must be an absolute http:// or https:// URL`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Resource \"${id}\" has a backend.url with scheme \"${parsed.protocol}\": must be http:// or https://`,\n { details: { path: `resources.${id}.backend.url`, resourceId: id } },\n );\n }\n}\n\nfunction validateAddress(path: string, value: string): void {\n if (!ADDRESS_PATTERN.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" is not a plausible address (expected \"0x\" followed by 40 hex characters)`,\n { details: { path } },\n );\n }\n if (ZERO_ADDRESS_PATTERN.test(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration value at \"${path}\" must not be the zero address`,\n {\n details: { path },\n },\n );\n }\n}\n","/**\n * Locates and parses `config.yaml`, then hands the raw value to\n * `parseConfig`. Never trusts raw YAML before Zod validation.\n */\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { parse as parseYaml, YAMLError } from 'yaml';\nimport { CommerceError } from '../core/index.js';\nimport { DEFAULT_CONFIG_FILENAME } from './filename.js';\nimport { type GatewayConfig, parseConfig } from './schema.js';\n\nconst CONFIG_PATH_ENV_VAR = 'AGENT_COMMERCE_CONFIG';\n\nexport interface LoadConfigOptions {\n readonly path?: string;\n readonly env?: NodeJS.ProcessEnv;\n readonly cwd?: string;\n}\n\nexport async function loadConfig(options: LoadConfigOptions = {}): Promise<GatewayConfig> {\n const env = options.env ?? process.env;\n const cwd = options.cwd ?? process.cwd();\n const configPath = resolveConfigPath(options.path, env, cwd);\n\n let text: string;\n try {\n text = await fs.readFile(configPath, 'utf8');\n } catch (error) {\n throw new CommerceError('CONFIG_INVALID', `Could not read configuration file \"${configPath}\"`, {\n details: { path: configPath },\n cause: error,\n });\n }\n\n let raw: unknown;\n try {\n raw = parseYaml(text);\n } catch (error) {\n const { reason, details } = describeYamlError(error);\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Configuration file \"${configPath}\" is not valid YAML: ${reason}`,\n {\n details: { path: configPath, ...details },\n // Retained for programmatic callers. Nothing in the CLI prints a\n // `cause`, and nothing should start: this is the object whose\n // `.message` carries the source excerpt (see below).\n cause: error,\n },\n );\n }\n\n return parseConfig(raw, env);\n}\n\n/**\n * A YAML failure described from the error's *structured* fields only.\n *\n * Deliberately not `error.message`: the `yaml` package builds that message\n * with a **code frame excerpt of the source line**, so a syntax error next to\n * an inline secret would reproduce it verbatim into `validate`/`doctor` output — including `doctor --json`, the output most\n * likely to be pasted into an issue or captured by CI:\n *\n * … is not valid YAML: Nested mappings are not allowed … at line 2, column 15:\n *\n * adminToken: super-secret-token-value\n * ^\n *\n * `server.adminToken` and `payments.x402.facilitator.signerPrivateKey` are\n * both legal as inline literals, so this was a real sink rather than a\n * hypothetical one — and it contradicted `validate`'s own promise never to\n * print a resolved value: it never printed a resolved `${ENV}`, only an\n * inlined one. `code` and `linePos` locate the fault exactly as well and\n * cannot contain file content.\n */\n/**\n * Plain-English phrasing for the codes an operator actually hits, so replacing\n * the excerpt does not also cost the diagnostic its readability. These are\n * fixed strings chosen here — they can never contain file content, which is\n * the entire property that matters. Anything unlisted degrades to the bare\n * code, which is still precise.\n */\nconst YAML_ERROR_EXPLANATIONS: Readonly<Record<string, string>> = {\n DUPLICATE_KEY: 'map keys must be unique',\n BAD_INDENT: 'bad indentation',\n TAB_AS_INDENT: 'tabs cannot be used for indentation',\n MISSING_CHAR: 'a required character is missing',\n BLOCK_AS_IMPLICIT_KEY: 'a block value cannot be used as a key (missing quotes, or a stray colon)',\n MULTILINE_IMPLICIT_KEY: 'a key spans multiple lines (missing quotes, or a stray colon)',\n UNEXPECTED_TOKEN: 'unexpected token',\n};\n\nfunction describeYamlError(error: unknown): {\n reason: string;\n details: Record<string, unknown>;\n} {\n if (!(error instanceof YAMLError)) {\n return { reason: 'unknown YAML parse error', details: {} };\n }\n const start = error.linePos?.[0];\n const where =\n start === undefined ? '' : ` at line ${String(start.line)}, column ${String(start.col)}`;\n const explanation = YAML_ERROR_EXPLANATIONS[error.code];\n const what = explanation === undefined ? error.code : `${error.code} (${explanation})`;\n return {\n reason: `${what}${where}`,\n details: {\n yamlErrorCode: error.code,\n ...(start === undefined ? {} : { line: start.line, column: start.col }),\n },\n };\n}\n\nfunction resolveConfigPath(\n explicitPath: string | undefined,\n env: NodeJS.ProcessEnv,\n cwd: string,\n): string {\n if (explicitPath) return path.resolve(cwd, explicitPath);\n const fromEnv = env[CONFIG_PATH_ENV_VAR];\n if (fromEnv) return path.resolve(cwd, fromEnv);\n return path.resolve(cwd, DEFAULT_CONFIG_FILENAME);\n}\n","/**\n * src/config\n *\n * `config.yaml` schema, loader and environment substitution.\n */\n\nexport { substituteEnv } from './env.js';\nexport type { LoadConfigOptions } from './load.js';\nexport { loadConfig } from './load.js';\nexport type { GatewayConfig } from './schema.js';\nexport { parseConfig } from './schema.js';\n","import { Command } from 'commander';\nimport { DEFAULT_CONFIG_FILENAME } from '../config/filename.js';\nimport { PROTOCOL_NAMES } from '../core/index.js';\nimport { runDemo } from './commands/demo.js';\nimport { printDoctorReport, runDoctor } from './commands/doctor.js';\nimport { runImportOpenApi } from './commands/import-openapi.js';\nimport { runInit } from './commands/init.js';\nimport { runValidate } from './commands/validate.js';\nimport { runVersion } from './commands/version.js';\nimport { type Io, processIo } from './lib/io.js';\nimport { readVersionReport } from './lib/versions.js';\n\n/**\n * Builds the `agent-commerce` Commander program.\n *\n * `io` is injectable so tests can capture output instead of writing to the\n * real process streams; `exitOverride()` + `configureOutput()` mean\n * `--help`/errors never call `process.exit()` directly, so a caller (index.ts\n * or a test) fully controls process lifecycle.\n */\nexport function buildProgram(io: Io = processIo): Command {\n const program = new Command();\n\n program\n .name('agent-commerce')\n .description('CLI for the Agent Commerce Gateway: init, import, validate, doctor, demo.')\n // `--version` is required of the published binary. The `version`\n // subcommand stays: it additionally prints the pinned protocol/SDK\n // versions, which is what `doctor` and the support matrix are checked\n // against. Both read the same source, so they cannot disagree.\n .version(readVersionReport().cliVersion, '-v, --version', 'Print the CLI version.')\n .exitOverride()\n .configureOutput({\n writeOut: (str) => io.stdout(str.replace(/\\n+$/, '')),\n writeErr: (str) => io.stderr(str.replace(/\\n+$/, '')),\n });\n\n program\n .command('version')\n .description('Print the CLI version and pinned protocol/SDK versions.')\n .action(() => {\n process.exitCode = runVersion(io);\n });\n\n program\n .command('validate')\n .description(`Validate ${DEFAULT_CONFIG_FILENAME} and exit non-zero if it is invalid.`)\n .option('--config <path>', `path to ${DEFAULT_CONFIG_FILENAME}`)\n .action(async (opts: { config?: string }) => {\n const code = await runValidate(\n opts.config !== undefined ? { configPath: opts.config } : {},\n io,\n );\n process.exitCode = code;\n });\n\n program\n .command('doctor')\n .description('Diagnose config, gateway, backend, protocol and payment health.')\n .option('--config <path>', `path to ${DEFAULT_CONFIG_FILENAME}`)\n .option(\n '--gateway <url>',\n 'gateway base URL (default: derived from config, else http://localhost:8080)',\n )\n .option('--json', 'emit machine-readable JSON instead of a formatted report', false)\n .action(async (opts: { config?: string; gateway?: string; json?: boolean }) => {\n const report = await runDoctor({\n ...(opts.config !== undefined ? { configPath: opts.config } : {}),\n ...(opts.gateway !== undefined ? { gatewayUrl: opts.gateway } : {}),\n });\n printDoctorReport(report, io, opts.json === true);\n process.exitCode = report.exitCode;\n });\n\n program\n .command('init')\n .description(`Interactively generate ${DEFAULT_CONFIG_FILENAME}.`)\n .option('--output <path>', 'output path', DEFAULT_CONFIG_FILENAME)\n .option('--force', 'overwrite an existing file', false)\n .option('--yes', 'use non-interactive defaults (required for scripting/tests)', false)\n .action(async (opts: { output: string; force: boolean; yes: boolean }) => {\n const code = await runInit({ outputPath: opts.output, force: opts.force, yes: opts.yes }, io);\n process.exitCode = code;\n });\n\n // `import` is a group so a future `import postman`/`import graphql` is a\n // sibling rather than a rename of an established command.\n const importCommand = program\n .command('import')\n .description('Generate Agent Commerce resource drafts from an API description.');\n\n importCommand\n .command('openapi')\n .description('Convert a local OpenAPI 3.0/3.1/3.2 document into resource drafts.')\n .argument('<source>', 'path to a local .yaml, .yml or .json OpenAPI document')\n .option('--output <path>', 'output path (default: <source>.agent-commerce.yaml)')\n .option('--force', 'overwrite an existing output file', false)\n .option('--base-url <url>', 'backend base URL, overriding the document servers')\n .option(\n '--operation <operationId>',\n 'import only this operation (repeatable)',\n collect,\n undefined,\n )\n .option('--tag <tag>', 'import only operations with this tag (repeatable, OR-ed)', collect)\n .option('--free', 'mark generated resources as pricing.type free', false)\n .option('--expose <protocols>', `comma-separated: ${PROTOCOL_NAMES.join(',')}`)\n .option('--strict', 'exit non-zero when the import produced warnings', false)\n .option('--json', 'emit a machine-readable summary instead of a report', false)\n .action(\n async (\n source: string,\n opts: {\n output?: string;\n force: boolean;\n baseUrl?: string;\n operation?: string[];\n tag?: string[];\n free: boolean;\n expose?: string;\n strict: boolean;\n json: boolean;\n },\n ) => {\n process.exitCode = await runImportOpenApi(\n {\n source,\n ...(opts.output !== undefined ? { output: opts.output } : {}),\n force: opts.force,\n ...(opts.baseUrl !== undefined ? { baseUrl: opts.baseUrl } : {}),\n ...(opts.operation !== undefined ? { operations: opts.operation } : {}),\n ...(opts.tag !== undefined ? { tags: opts.tag } : {}),\n free: opts.free,\n ...(opts.expose !== undefined ? { expose: opts.expose } : {}),\n strict: opts.strict,\n json: opts.json,\n },\n io,\n );\n },\n );\n\n program\n .command('demo')\n .description(\n 'Run the documented docker compose + demo agent quickstart, verifying health between steps.',\n )\n .action(async () => {\n process.exitCode = await runDemo(io);\n });\n\n return program;\n}\n\n/** Commander's repeatable-option collector. */\nfunction collect(value: string, previous: string[] | undefined): string[] {\n return [...(previous ?? []), value];\n}\n","/**\n * `agent-commerce demo` — a thin, honest wrapper around the documented\n * `docker compose up` + `npm run demo:agent` steps (README/ commands).\n *\n * No orchestration magic: each step's exit code is checked, and a failing\n * step is reported with exactly what failed and what to run to retry it, not\n * swallowed into a generic \"demo failed\" message.\n */\nimport type { Io } from '../lib/io.js';\n\nexport interface DemoStep {\n readonly name: string;\n readonly command: string;\n readonly args: readonly string[];\n /** Optional health check run after the step; returns true when healthy. */\n readonly healthCheck?: () => Promise<boolean>;\n}\n\nexport interface RunResult {\n readonly code: number;\n readonly stderrTail?: string;\n}\n\nexport type RunCommand = (command: string, args: readonly string[]) => Promise<RunResult>;\n\nexport interface DemoDeps {\n readonly run?: RunCommand;\n readonly steps?: readonly DemoStep[];\n}\n\nexport function defaultDemoSteps(): readonly DemoStep[] {\n return [\n {\n name: 'Start local chain + gateway + merchant (docker compose)',\n command: 'docker',\n args: ['compose', 'up', '--build', '-d'],\n },\n { name: 'Run the deterministic buyer agent', command: 'npm', args: ['run', 'demo:agent'] },\n ];\n}\n\n/** `agent-commerce demo`. Returns process exit code. */\nexport async function runDemo(io: Io, deps: DemoDeps = {}): Promise<number> {\n const steps = deps.steps ?? defaultDemoSteps();\n const run = deps.run ?? execCommand;\n\n io.stdout('agent-commerce demo — running the documented quickstart steps:');\n for (const step of steps) {\n io.stdout('');\n io.stdout(`==> ${step.name}`);\n io.stdout(` $ ${step.command} ${step.args.join(' ')}`);\n const result = await run(step.command, step.args);\n if (result.code !== 0) {\n io.stderr(`FAIL \"${step.name}\" exited with code ${result.code}.`);\n if (result.stderrTail !== undefined && result.stderrTail.length > 0) {\n io.stderr(result.stderrTail);\n }\n io.stderr('');\n io.stderr('Nothing further was run. To retry manually:');\n io.stderr(` ${step.command} ${step.args.join(' ')}`);\n return 1;\n }\n if (step.healthCheck !== undefined) {\n const healthy = await step.healthCheck();\n if (!healthy) {\n io.stderr(`FAIL \"${step.name}\" completed but its health check did not pass.`);\n return 1;\n }\n }\n io.stdout(`OK ${step.name}`);\n }\n io.stdout('');\n io.stdout('PASS Demo is up. Try: agent-commerce doctor --config config-demo.yaml');\n return 0;\n}\n\nasync function execCommand(command: string, args: readonly string[]): Promise<RunResult> {\n const { spawn } = await import('node:child_process');\n return new Promise((resolvePromise) => {\n let stderr = '';\n const child = spawn(command, args, { stdio: ['ignore', 'inherit', 'pipe'] });\n child.stderr?.on('data', (chunk: Buffer) => {\n stderr += chunk.toString('utf8');\n });\n child.on('error', (err) => {\n resolvePromise({ code: 1, stderrTail: err.message });\n });\n child.on('close', (code) => {\n const tail = stderr.trim().split('\\n').slice(-10).join('\\n');\n resolvePromise({ code: code ?? 1, ...(tail.length > 0 ? { stderrTail: tail } : {}) });\n });\n });\n}\n","import { accessSync, existsSync, constants as fsConstants } from 'node:fs';\nimport { dirname } from 'node:path';\nimport picocolors from 'picocolors';\nimport { extractPathParameterNames } from '../../core/execution/index.js';\nimport { type CommerceResource, isCommerceError, type ReceiptStore } from '../../core/index.js';\nimport {\n describeDeploymentMode,\n findNetworkProfile,\n resolveDeploymentMode,\n} from '../../payments/x402/networks.js';\n// Narrow modules, not the package barrel: the CLI must pull in no protocol\n// SDK, and these two are plain constants and strings.\nimport {\n A2A_AGENT_CARD_PATH,\n A2A_PROTOCOL_BINDING,\n A2A_PROTOCOL_VERSION,\n A2A_SPEC_VERSION,\n} from '../../protocols/a2a/constants.js';\nimport { A2A_UNSUPPORTED } from '../../protocols/a2a/descriptor.js';\nimport {\n ACP_API_VERSION,\n ACP_SPEC_VERSION,\n ACP_WELL_KNOWN_PATH,\n} from '../../protocols/acp/constants.js';\nimport { ACP_UNSUPPORTED } from '../../protocols/acp/descriptor.js';\nimport { createSqliteReceiptStore } from '../../storage/receipts/index.js';\nimport { type ConfigLoader, type GatewayConfig, loadConfigDynamic } from '../lib/config-client.js';\nimport { type FetchLike, fetchJson } from '../lib/http.js';\nimport { PLACEHOLDER_ASSET_ADDRESS } from '../lib/init-config.js';\nimport type { Io } from '../lib/io.js';\nimport {\n fillEnvFromLocalChainManifest,\n LOCAL_CHAIN_MANIFEST_PATH,\n MANIFEST_FILLABLE_ENV_VAR_NAMES,\n type ManifestEnvFill,\n} from '../lib/manifest-env.js';\nimport { maskMiddle } from '../lib/mask.js';\nimport { readVersionReport } from '../lib/versions.js';\n\nexport type CheckStatus = 'PASS' | 'WARN' | 'FAIL' | 'INFO';\n\nexport interface DoctorCheck {\n readonly name: string;\n readonly status: CheckStatus;\n readonly detail: string;\n}\n\nexport interface DoctorReport {\n readonly checks: readonly DoctorCheck[];\n readonly score: { readonly passed: number; readonly total: number };\n readonly exitCode: number;\n}\n\nexport interface DoctorOptions {\n readonly configPath?: string;\n readonly gatewayUrl?: string;\n}\n\nexport interface DoctorDeps {\n readonly fetchImpl?: FetchLike;\n readonly loadConfig?: ConfigLoader;\n readonly createStore?: (path: string) => ReceiptStore;\n readonly fillEnvFromManifest?: (env: NodeJS.ProcessEnv) => ManifestEnvFill;\n}\n\nconst CHECK_TIMEOUT_MS = 1500;\n\nfunction deriveGatewayUrl(explicit: string | undefined, config: GatewayConfig | undefined): string {\n if (explicit !== undefined) return explicit.replace(/\\/$/, '');\n if (config !== undefined) {\n // `0.0.0.0` means \"all interfaces\"; probe the loopback one. `::` is its\n // IPv6 equivalent. A literal IPv6 host such as `::1`\n // must be bracketed or the derived URL is invalid (`http://::1:8080`) and\n // doctor reported every running gateway as unreachable.\n const raw = config.server.host;\n const host = raw === '0.0.0.0' ? '127.0.0.1' : raw === '::' ? '::1' : raw;\n const authority = host.includes(':') ? `[${host}]` : host;\n return `http://${authority}:${config.server.port}`;\n }\n return 'http://localhost:8080';\n}\n\n/**\n * Fill `{param}` slots with a probe value, using the *canonical* grammar.\n *\n * A local `/\\{[^}]+\\}/g` here would recognise more than the runtime does. A\n * kebab-case token like `{report-id}` would match here and not there, so\n * `doctor` would probe `/report/demo-check` — the URL the operator meant —\n * and report the backend reachable, while every real request went to\n * `/report/%7Breport-id%7D` and 404'd after settling payment. A diagnostic\n * that probes a URL the runtime would never build is\n * worse than no diagnostic: it certifies the broken thing as healthy. Anything\n * the shared extractor does not recognise is deliberately left as-is, so the\n * probe hits exactly what the gateway would send.\n */\nfunction substitutePathParams(url: string): string {\n let filled = url;\n for (const name of extractPathParameterNames(url)) {\n filled = filled.split(`{${name}}`).join('demo-check');\n }\n return filled;\n}\n\ninterface LiveX402 {\n readonly asset: string;\n readonly network: string;\n readonly payTo: string;\n}\n\n/**\n * Pulls the gateway's *effective* x402 settlement config out of\n * `/.well-known/agent-commerce` (src/gateway/well-known.ts). Returns\n * undefined for anything short of \"the gateway confirms x402 is enabled and\n * reports all three fields\" — a doctor cross-check must never itself become\n * an unchecked cast on network-supplied JSON.\n */\n/**\n * `undefined` must not be allowed to mean three different things — gateway\n * down, document malformed, and *the gateway positively reporting x402\n * disabled*. The third is not an absence of information, it is a\n * disagreement: local config enables x402, the running gateway says it does\n * not, which is exactly the deployment-mismatch this cross-check was built to\n * catch. Reporting it as \"could not be verified\" turned the finding into a\n * shrug. `'disabled'` separates it out.\n */\ntype LiveX402Result = LiveX402 | 'disabled' | undefined;\n\nfunction extractWellKnownX402(body: Record<string, unknown> | undefined): LiveX402Result {\n const payments = body?.['payments'];\n if (typeof payments !== 'object' || payments === null) return undefined;\n const x402 = (payments as Record<string, unknown>)['x402'];\n if (typeof x402 !== 'object' || x402 === null) return undefined;\n const rec = x402 as Record<string, unknown>;\n // Only an explicit `false` is a positive statement. Anything else (absent,\n // null, a non-boolean) is still \"cannot tell\".\n if (rec['enabled'] === false) return 'disabled';\n if (rec['enabled'] !== true) return undefined;\n const { asset, network, payTo } = rec;\n if (typeof asset !== 'string' || typeof network !== 'string' || typeof payTo !== 'string') {\n return undefined;\n }\n return { asset, network, payTo };\n}\n\n/** Addresses are checksum-insensitive throughout this project (src/config/schema.ts). */\nfunction sameAddress(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\n/**\n * A doctor that reports healthy against a mismatched deployment is worse\n * than no diagnostic at all false-green finding). Compares\n * the gateway's live settlement config against what the local config\n * resolved to, and names both values so the operator knows exactly what to\n * check rather than just that something disagrees.\n */\nfunction findX402Mismatch(configured: LiveX402, live: LiveX402): string | undefined {\n const diffs: string[] = [];\n if (!sameAddress(configured.asset, live.asset)) {\n diffs.push(\n `asset: gateway is using ${live.asset} but local config resolves to ${configured.asset}`,\n );\n }\n if (configured.network !== live.network) {\n diffs.push(\n `network: gateway is using \"${live.network}\" but local config resolves to \"${configured.network}\"`,\n );\n }\n if (!sameAddress(configured.payTo, live.payTo)) {\n diffs.push(\n `payTo: gateway is using ${live.payTo} but local config resolves to ${configured.payTo}`,\n );\n }\n if (diffs.length === 0) return undefined;\n return `${diffs.join('; ')} — the gateway may be running against an older deployment; restart it or re-run chain:deploy`;\n}\n\n/**\n * The idempotency database, diagnosed without creating it: `doctor` is\n * read-only, and opening a mistyped path would leave a fresh empty database\n * behind and report it as healthy.\n */\nfunction acpIdempotencyCheck(idempotency: {\n readonly path: string;\n readonly retentionHours: number;\n}): DoctorCheck {\n // Config refuses anything below 24h, so this states the window rather than\n // policing it - if it ever reads lower, the two layers have drifted.\n const retention = `retention ${idempotency.retentionHours}h`;\n if (idempotency.retentionHours < 24) {\n return {\n name: 'ACP idempotency',\n status: 'FAIL',\n detail: `${retention} is below the 24h ACP minimum — a replayed key could run a checkout twice`,\n };\n }\n if (idempotency.path === ':memory:') {\n return {\n name: 'ACP idempotency',\n status: 'WARN',\n detail: `in-memory store, ${retention} — replay protection is lost on every restart; use a file path in production`,\n };\n }\n const directory = dirname(idempotency.path);\n if (existsSync(idempotency.path)) {\n try {\n accessSync(idempotency.path, fsConstants.W_OK);\n return { name: 'ACP idempotency', status: 'PASS', detail: `writable, ${retention}` };\n } catch {\n return {\n name: 'ACP idempotency',\n status: 'FAIL',\n detail: `\"${idempotency.path}\" exists but is not writable by this user — the adapter cannot claim idempotency keys`,\n };\n }\n }\n if (directory !== '' && directory !== '.' && !existsSync(directory)) {\n return {\n name: 'ACP idempotency',\n status: 'WARN',\n detail: `no store yet at \"${idempotency.path}\" and its directory does not exist — it is created when the gateway starts, provided that path is writable`,\n };\n }\n return {\n name: 'ACP idempotency',\n status: 'WARN',\n detail: `no store yet at \"${idempotency.path}\" — it is created the first time the gateway starts (${retention})`,\n };\n}\n\n/**\n * The five mapped resources, re-checked against the same rules config enforces:\n * present, acp-exposed, and free to invoke. Resource *ids* are named here\n * because an operator needs them to fix a mapping; the mapping itself is\n * config, not a secret, and never leaves this local report.\n */\nfunction acpMappingCheck(\n config: GatewayConfig,\n operations: Readonly<Record<string, string>>,\n): DoctorCheck {\n const byId = new Map(config.resources.map((resource) => [resource.id, resource]));\n const problems: string[] = [];\n\n for (const [operation, resourceId] of Object.entries(operations)) {\n const resource = byId.get(resourceId);\n if (resource === undefined) {\n problems.push(`${operation} -> \"${resourceId}\" does not exist`);\n continue;\n }\n if (!resource.exposedVia.includes('acp')) {\n problems.push(`${operation} -> \"${resourceId}\" is not exposed via acp`);\n }\n // ACP checkout carries the merchant's own purchase payment; charging for\n // the invocation as well would put two payment layers on one call.\n if (resource.pricing.type !== 'free' || resource.paymentMethods.length > 0) {\n problems.push(`${operation} -> \"${resourceId}\" is not free to invoke`);\n }\n }\n\n if (problems.length > 0) {\n return { name: 'ACP checkout mapping', status: 'FAIL', detail: problems.join('; ') };\n }\n return {\n name: 'ACP checkout mapping',\n status: 'PASS',\n detail: `5 operations mapped to free acp-exposed resources (${Object.values(operations).join(', ')})`,\n };\n}\n\n/** `agent-commerce doctor [--config] [--gateway] [--json]`. */\nexport async function runDoctor(\n options: DoctorOptions,\n deps: DoctorDeps = {},\n): Promise<DoctorReport> {\n const fetchImpl = deps.fetchImpl ?? globalThis.fetch;\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const createStore = deps.createStore ?? ((path: string) => createSqliteReceiptStore({ path }));\n const fillEnvFromManifest = deps.fillEnvFromManifest ?? fillEnvFromLocalChainManifest;\n\n const checks: DoctorCheck[] = [];\n let config: GatewayConfig | undefined;\n\n // 1. Config\n const { env, filled, manifestFound } = fillEnvFromManifest(process.env);\n const filledSuffix =\n filled.length > 0\n ? ` (using local chain manifest ${LOCAL_CHAIN_MANIFEST_PATH} for ${filled.join(', ')})`\n : '';\n try {\n config = await loadConfig({\n ...(options.configPath !== undefined ? { path: options.configPath } : {}),\n env,\n });\n checks.push({\n name: 'Config',\n status: 'PASS',\n detail: `valid — ${config.resources.length} resource(s), merchant \"${config.merchant.name}\"${filledSuffix}`,\n });\n } catch (err) {\n const variable = isCommerceError(err) ? err.details?.['variable'] : undefined;\n const hint =\n !manifestFound &&\n typeof variable === 'string' &&\n MANIFEST_FILLABLE_ENV_VAR_NAMES.has(variable)\n ? ` — run \"npm run chain:deploy\" (writes ${LOCAL_CHAIN_MANIFEST_PATH}, read automatically for local X402_*/MERCHANT_WALLET placeholders)`\n : '';\n checks.push({\n name: 'Config',\n status: 'FAIL',\n detail: `${err instanceof Error ? err.message : String(err)}${hint}`,\n });\n }\n\n const gatewayUrl = deriveGatewayUrl(options.gatewayUrl, config);\n\n // 2. Gateway\n const health = await fetchJson(fetchImpl, `${gatewayUrl}/health`, CHECK_TIMEOUT_MS);\n let gatewayUp = false;\n if (!health.ok) {\n checks.push({\n name: 'Gateway',\n status: 'FAIL',\n detail: `unreachable at ${gatewayUrl} (${health.error ?? `HTTP ${health.status}`})`,\n });\n } else {\n gatewayUp = true;\n const ready = await fetchJson(fetchImpl, `${gatewayUrl}/ready`, CHECK_TIMEOUT_MS);\n checks.push(\n ready.ok\n ? { name: 'Gateway', status: 'PASS', detail: `healthy and ready at ${gatewayUrl}` }\n : {\n name: 'Gateway',\n status: 'WARN',\n detail: `healthy but not ready at ${gatewayUrl} (${ready.error ?? `HTTP ${ready.status}`})`,\n },\n );\n }\n\n // 3. Backend(s)\n if (config === undefined) {\n checks.push({ name: 'Backend', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (config.resources.length === 0) {\n checks.push({ name: 'Backend', status: 'INFO', detail: 'no resources configured' });\n } else {\n const resources = config.resources as readonly CommerceResource[];\n const urls: string[] = [...new Set(resources.map((r) => substitutePathParams(r.handler.url)))];\n const results = await Promise.all(\n urls.map((url) => fetchJson(fetchImpl, url, CHECK_TIMEOUT_MS)),\n );\n const reachable = results.filter((r) => r.status !== 0).length;\n const status: CheckStatus =\n reachable === urls.length ? 'PASS' : reachable === 0 ? 'FAIL' : 'WARN';\n checks.push({\n name: 'Backend',\n status,\n detail: `${reachable}/${urls.length} backend host(s) reachable`,\n });\n }\n\n // 4. Well-known document (feeds Protocols + Protocol versions)\n const wellKnown = gatewayUp\n ? await fetchJson<Record<string, unknown>>(\n fetchImpl,\n `${gatewayUrl}/.well-known/agent-commerce`,\n CHECK_TIMEOUT_MS,\n )\n : undefined;\n\n // 5. Protocols\n if (config === undefined) {\n checks.push({ name: 'Protocols', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (wellKnown === undefined || !wellKnown.ok) {\n checks.push({ name: 'Protocols', status: 'FAIL', detail: 'well-known document unreachable' });\n } else {\n const mcpMountPath = config.protocols.mcp.enabled ? config.protocols.mcp.mountPath : undefined;\n const a2aMountPath = config.protocols.a2a.enabled ? config.protocols.a2a.mountPath : undefined;\n checks.push({\n name: 'Protocols',\n status: 'PASS',\n detail: `http=${config.protocols.http.enabled ? 'on' : 'off'} mcp=${config.protocols.mcp.enabled ? `on (${mcpMountPath})` : 'off'} a2a=${config.protocols.a2a.enabled ? `on (${a2aMountPath})` : 'off'} acp=${config.protocols.acp.enabled ? `on (${config.protocols.acp.mountPath})` : 'off'}`,\n });\n }\n\n // 5b. A2A specifics. Reported from the pins rather than from the live\n // gateway so the spec revision, the negotiation version and the binding are\n // three separate, named values an operator can check against a client — the\n // first two look alike and are routinely conflated.\n if (config === undefined) {\n checks.push({ name: 'A2A', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (!config.protocols.a2a.enabled) {\n checks.push({ name: 'A2A', status: 'INFO', detail: 'disabled' });\n } else {\n checks.push({\n name: 'A2A',\n status: 'PASS',\n detail: `experimental · spec ${A2A_SPEC_VERSION} · protocol ${A2A_PROTOCOL_VERSION} · binding ${A2A_PROTOCOL_BINDING} · mount ${config.protocols.a2a.mountPath} · card ${A2A_AGENT_CARD_PATH}`,\n });\n // Listed in full, never summarised as a count: \"18 unsupported\" tells an\n // operator nothing about whether the one operation their client needs is\n // among them.\n checks.push({\n name: 'A2A unsupported',\n status: 'INFO',\n detail: A2A_UNSUPPORTED.join(', '),\n });\n }\n\n // 5c. ACP specifics. Read from config and the pins, never from the live\n // gateway: the bearer token, the idempotency database path and the\n // operation-to-resource mapping are all things this report must not print,\n // and the well-known document deliberately does not carry them either.\n if (config === undefined) {\n checks.push({ name: 'ACP', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (!config.protocols.acp.enabled) {\n checks.push({ name: 'ACP', status: 'INFO', detail: 'disabled' });\n } else {\n const acp = config.protocols.acp;\n checks.push({\n name: 'ACP',\n status: 'PASS',\n detail: `experimental · spec ${ACP_SPEC_VERSION} · API-Version ${ACP_API_VERSION} · service checkout · mount ${acp.mountPath} · discovery ${ACP_WELL_KNOWN_PATH}`,\n });\n\n // Whether a token is configured, never which one. An empty one cannot\n // reach here - config refuses it - so this states the shape, not a secret.\n checks.push({\n name: 'ACP auth',\n status: 'PASS',\n detail: `bearer token configured (${acp.auth.token.length} characters, not shown)`,\n });\n\n checks.push(acpIdempotencyCheck(acp.idempotency));\n checks.push(acpMappingCheck(config, acp.checkout.operations));\n\n // Listed in full, never summarised as a count: \"16 unsupported\" tells an\n // operator nothing about whether the one service their client needs is\n // among them.\n checks.push({\n name: 'ACP unsupported',\n status: 'INFO',\n detail: ACP_UNSUPPORTED.join(', '),\n });\n }\n\n // 6. Payments\n const x402 = config?.payments.x402;\n if (x402 === undefined || !x402.enabled) {\n checks.push({ name: 'Payments', status: 'INFO', detail: 'x402 not configured' });\n } else {\n // The protocol version is named because chain id 84532 is shared with the\n // public Base Sepolia testnet: the *mode* is what says whether this\n // deployment settles on a local dev node or a public network, and nothing\n // here may be read as a claim about a public network on its own.\n //\n // A config whose network is unknown cannot reach here in normal operation\n // — `parseConfig` refuses it — so an absent profile means doctor is\n // reading a config some other loader produced. Say so rather than guess.\n const profile = findNetworkProfile(x402.network);\n const mode = profile ? resolveDeploymentMode(profile, x402.facilitator.mode) : undefined;\n // Naming the public network while in local mode would read as a claim to\n // be on it — the exact confusion the shared chain id creates. Local says\n // \"dev chain\"; only a remote facilitator earns the network's name.\n const where =\n profile === undefined || mode === undefined\n ? `unknown network ${x402.network}`\n : mode === 'local'\n ? `LOCAL dev chain (${x402.network}, chain id shared with ${profile.displayName})`\n : `${describeDeploymentMode(mode)} on ${profile.displayName} (${x402.network})`;\n const facilitatorDetail =\n x402.facilitator.mode === 'local' ? 'local' : `remote (auth=${x402.facilitator.auth.type})`;\n const summary = `x402 v2 (scheme=exact) enabled — ${where}, destination=${maskMiddle(x402.payTo)}, facilitator=${facilitatorDetail}`;\n const live = wellKnown?.ok ? extractWellKnownX402(wellKnown.body) : undefined;\n if (sameAddress(x402.asset, PLACEHOLDER_ASSET_ADDRESS)) {\n // `init --yes` writes this placeholder, and the\n // live cross-check compares config against the gateway's echo of the\n // same config — so everything matched and the report said 7/7 PASS on a\n // deployment where no paid call can ever succeed, because no token\n // contract exists at that address. Fail-closed holds and no funds are at\n // risk; the overstatement is the defect.\n checks.push({\n name: 'Payments',\n status: 'WARN',\n detail: `${summary}, but the asset is still the init placeholder ${maskMiddle(PLACEHOLDER_ASSET_ADDRESS)} — no token contract exists there, so every paid call will fail. Set payments.x402.asset (\\${X402_ASSET} is filled from .deploy/local.json by \"npm run chain:deploy\")`,\n });\n } else if (live === 'disabled') {\n // Verified, and it disagrees. Every paid call against this gateway will\n // be served free or refused, depending on the resource — either way the\n // deployment is not what this config describes.\n checks.push({\n name: 'Payments',\n status: 'FAIL',\n detail: `${summary}, but the gateway at ${gatewayUrl} reports x402 disabled — it is running a different configuration`,\n });\n } else if (live === undefined) {\n // Gateway unreachable, x402 not (yet) reported live, or the document\n // didn't parse as expected — can't judge a match either way, so this\n // is not a FAIL: a doctor that fails on things it cannot check is as\n // untrustworthy as one that passes on things it never checked.\n checks.push({\n name: 'Payments',\n status: 'INFO',\n detail: `${summary} (gateway's live settlement config could not be verified)`,\n });\n } else {\n const mismatch = findX402Mismatch(x402, live);\n checks.push(\n mismatch === undefined\n ? { name: 'Payments', status: 'PASS', detail: summary }\n : { name: 'Payments', status: 'FAIL', detail: mismatch },\n );\n }\n if (mode === 'mainnet') {\n // Reporting, not re-checking. Every one of these is refused at config\n // load (src/payments/x402/guardrails.ts), so a config that got this far\n // has already passed them — but an operator about to move real money\n // should be told which guarantees they are relying on, and see the\n // banner without having to read a log.\n // An unauthenticated mainnet facilitator is allowed, but only by name.\n // Saying so here is the point: the acknowledgement lives in a config\n // file someone wrote weeks ago, and this is where they look today.\n const unauthenticated =\n x402.facilitator.mode === 'remote' && x402.facilitator.auth.type === 'none';\n checks.push({\n name: 'Mainnet safety',\n status: unauthenticated ? 'WARN' : 'INFO',\n detail: unauthenticated\n ? `${describeDeploymentMode('mainnet')} — settling through a facilitator that takes no ` +\n 'credential, accepted via allowUnauthenticatedFacilitator. It sees every payment ' +\n 'authorisation you handle, with no account or terms behind it. Everything else is ' +\n 'enforced at config load: explicit allowMainnet opt-in, HTTPS, non-development ' +\n 'payTo, canonical asset. Payments are fail-closed.'\n : `${describeDeploymentMode('mainnet')} — enforced at config load: explicit allowMainnet ` +\n 'opt-in, remote facilitator over HTTPS with a credential, non-development payTo, ' +\n 'and the canonical asset for this network. Payments are fail-closed.',\n });\n }\n }\n checks.push({\n name: 'Payments (MPP)',\n status: 'INFO',\n detail: 'planned — not implemented in this release',\n });\n\n // 7. Storage\n if (config === undefined) {\n checks.push({ name: 'Storage', status: 'WARN', detail: 'skipped — config invalid' });\n } else if (\n // Diagnose without creating: createSqliteReceiptStore mkdir+creates the\n // file, so calling it on a wrong path (a typo, or a container path read\n // from the host) silently produces a fresh empty database and a false\n // \"healthy, receipts=0\" PASS — a read-only command must not have this\n // side effect, and it shadows the real store's real receipts entirely.\n // `:memory:` never exists on disk by definition, so it always falls\n // through to the real open/health/count branch below, same as today.\n config.storage.receipts.path !== ':memory:' &&\n !existsSync(config.storage.receipts.path)\n ) {\n checks.push({\n name: 'Storage',\n status: 'WARN',\n detail:\n `no store exists yet at \"${config.storage.receipts.path}\" — it is created ` +\n 'automatically the first time the gateway starts. If the gateway is already ' +\n 'running, this path does not match the one it actually uses.',\n });\n } else {\n let store: ReceiptStore | undefined;\n try {\n store = createStore(config.storage.receipts.path);\n await store.init();\n const storeHealth = await store.health();\n let receiptCount: number | undefined;\n try {\n // Exact count, not a list length: listReceipts clamps to\n // MAX_LIST_LIMIT (500, a store-level invariant) so counting via the\n // list silently saturated at 500 forever.\n receiptCount = await store.countReceipts();\n } catch {\n receiptCount = undefined;\n }\n let undeliveredCount: number | undefined;\n try {\n // A paid-but-undelivered purchase looks identical to a successful\n // one everywhere else; this is what makes it visible to an operator\n // running doctor. Same signal the\n // dashboard's receipt table uses, so the two views cannot disagree.\n undeliveredCount = await store.countUndeliveredReceipts();\n } catch {\n undeliveredCount = undefined;\n }\n const status: CheckStatus =\n storeHealth.status === 'pass' ? 'PASS' : storeHealth.status === 'warn' ? 'WARN' : 'FAIL';\n const receiptsSuffix =\n receiptCount !== undefined\n ? `; receipts=${receiptCount}${undeliveredCount !== undefined && undeliveredCount > 0 ? ` (${undeliveredCount} undelivered)` : ''}`\n : '';\n checks.push({\n name: 'Storage',\n status,\n detail: `${storeHealth.detail ?? 'sqlite'}${receiptsSuffix}`,\n });\n } catch (err) {\n checks.push({\n name: 'Storage',\n status: 'FAIL',\n detail: err instanceof Error ? err.message : String(err),\n });\n } finally {\n await store?.close();\n }\n }\n\n // 8. Protocol versions\n if (wellKnown !== undefined && wellKnown.ok) {\n checks.push({\n name: 'Protocol versions',\n status: 'PASS',\n detail: 'reported by gateway /.well-known/agent-commerce',\n });\n } else {\n const local = readVersionReport();\n checks.push({\n name: 'Protocol versions',\n status: 'INFO',\n detail: `gateway unreachable — local pins: ${local.pinned.map((p) => `${p.name}@${p.version}`).join(', ')}`,\n });\n }\n\n const scored = checks.filter((c) => c.status !== 'INFO');\n const passed = scored.filter((c) => c.status === 'PASS').length;\n const exitCode = checks.some((c) => c.status === 'FAIL') ? 1 : 0;\n\n return { checks, score: { passed, total: scored.length }, exitCode };\n}\n\nfunction statusColor(status: CheckStatus, text: string): string {\n switch (status) {\n case 'PASS':\n return picocolors.green(text);\n case 'WARN':\n return picocolors.yellow(text);\n case 'FAIL':\n return picocolors.red(text);\n case 'INFO':\n return picocolors.cyan(text);\n }\n}\n\nexport function printDoctorReport(report: DoctorReport, io: Io, json: boolean): void {\n if (json) {\n io.stdout(JSON.stringify(report, null, 2));\n return;\n }\n for (const check of report.checks) {\n const label = statusColor(check.status, check.status.padEnd(5));\n io.stdout(`${label} ${check.name.padEnd(20)} ${check.detail}`);\n }\n io.stdout('');\n io.stdout(`Score: ${report.score.passed}/${report.score.total} checks passed`);\n}\n","/**\n * A2A pins, kept in one place so nothing infers one version from another.\n *\n * The specification revision and the protocol negotiation version are\n * different values that look similar: `1.0.0` names the document this adapter\n * was written against, `1.0` is what a client negotiates on the wire. Neither\n * is this package's version — that is `PACKAGE_VERSION`.\n */\n\n/** A2A specification revision this adapter targets. */\nexport const A2A_SPEC_VERSION = '1.0.0';\n\n/** Protocol negotiation version carried on the wire. */\nexport const A2A_PROTOCOL_VERSION = '1.0';\n\n/** The only transport binding this adapter serves. */\nexport const A2A_PROTOCOL_BINDING = 'JSONRPC';\n\n/**\n * Fixed by the A2A specification: a client fetches the card from this exact\n * path, so it is not configurable. `src/config` reserves it against adapter\n * mounts for the same reason.\n */\nexport const A2A_AGENT_CARD_PATH = '/.well-known/agent-card.json';\n\n/** Mount serving the JSON-RPC endpoint, unless configuration says otherwise. */\nexport const A2A_DEFAULT_MOUNT_PATH = '/a2a';\n\n/** Content type on both sides of every supported A2A exchange. */\nexport const A2A_JSON_MEDIA_TYPE = 'application/json';\n\n/** Card identity when the operator names none. Matches the MCP server name. */\nexport const A2A_DEFAULT_AGENT_NAME = 'agent-commerce';\n\n/**\n * Version negotiation header. A2A v1 carries the protocol version out of band,\n * so a request that omits it is a client speaking an older negotiation\n * convention — treated as unsupported rather than optimistically accepted.\n */\nexport const A2A_VERSION_HEADER = 'a2a-version';\n\n/** The one JSON-RPC method this adapter serves. Not the legacy `message/send`. */\nexport const A2A_METHOD_SEND_MESSAGE = 'SendMessage';\n\n/**\n * A2A methods that exist and are deliberately not served here. Kept apart from\n * unknown methods so a caller learns which of the two they hit: a real method\n * this deployment refuses, or a typo. One list, read by both the descriptor\n * and the transport — a second copy would drift the moment one gains a method.\n */\nexport const A2A_UNSUPPORTED_METHODS: readonly string[] = [\n 'SendStreamingMessage',\n 'GetTask',\n 'ListTasks',\n 'CancelTask',\n 'SubscribeToTask',\n 'CreateTaskPushNotificationConfig',\n 'GetTaskPushNotificationConfig',\n 'ListTaskPushNotificationConfigs',\n 'DeleteTaskPushNotificationConfig',\n 'GetExtendedAgentCard',\n];\n\n/**\n * Terminal task states. Only these two are ever returned: a synchronous\n * execution is finished by the time the response is written, and no task\n * store exists for a caller to poll a non-terminal one against.\n */\nexport const A2A_TASK_STATE_COMPLETED = 'TASK_STATE_COMPLETED';\nexport const A2A_TASK_STATE_FAILED = 'TASK_STATE_FAILED';\n","/**\n * Adapter self-description.\n *\n * `supportedSpec` is the A2A specification revision (`1.0.0`), never the\n * negotiation version (`1.0`) and never this package's version. Status is\n * `experimental` and stays that way until the unsupported list below shrinks\n * on purpose rather than by omission.\n */\nimport type { AdapterDescriptor } from '../../core/index.js';\nimport { A2A_SPEC_VERSION, A2A_UNSUPPORTED_METHODS } from './constants.js';\n\n/** What this adapter actually implements. */\nexport const A2A_CAPABILITIES: readonly string[] = ['agent-card', 'jsonrpc', 'SendMessage'];\n\n/**\n * Everything an A2A client may reasonably expect and will not get here.\n * Complete on purpose: a short list reads as \"mostly compatible\", which is\n * exactly the blanket claim alpha honesty forbids. `doctor` and\n * `/.well-known/agent-commerce` surface this verbatim.\n */\nexport const A2A_UNSUPPORTED: readonly string[] = [\n // Methods, named as the protocol names them. Same list the transport\n // rejects by name, so the descriptor cannot promise less than it refuses.\n ...A2A_UNSUPPORTED_METHODS,\n // Transports other than the one binding served.\n 'HTTP+JSON/REST binding',\n 'gRPC binding',\n // Behaviours.\n 'SSE',\n 'long-running task persistence',\n 'task resumption',\n 'push notifications',\n 'multi-turn conversational continuation',\n 'authenticated extended agent cards',\n 'A2A authentication schemes',\n 'artifact types beyond Agent Commerce outcome data',\n];\n\nexport function buildDescriptor(implementationVersion: string): AdapterDescriptor {\n return {\n name: 'a2a',\n kind: 'protocol',\n implementationVersion,\n supportedSpec: A2A_SPEC_VERSION,\n capabilities: A2A_CAPABILITIES,\n status: 'experimental',\n unsupported: A2A_UNSUPPORTED,\n };\n}\n","/**\n * Adapter self-description.\n *\n * `supportedSpec` is the pinned ACP snapshot, never this package's version.\n * Status is `experimental` and stays that way until the unsupported list below\n * shrinks on purpose rather than by omission.\n */\nimport type { AdapterDescriptor } from '../../core/index.js';\nimport { ACP_CHECKOUT_OPERATIONS, ACP_SPEC_VERSION } from './constants.js';\n\n/** What this adapter actually implements. */\nexport const ACP_CAPABILITIES: readonly string[] = [\n 'rest transport',\n 'well-known discovery',\n 'bearer authentication',\n 'API-Version negotiation',\n 'checkout service',\n ...ACP_CHECKOUT_OPERATIONS,\n];\n\n/**\n * Everything an ACP client may reasonably expect and will not get here.\n * Complete on purpose: a short list reads as \"mostly compatible\", which is\n * exactly the blanket claim alpha honesty forbids. `doctor` and\n * `/.well-known/agent-commerce` surface this verbatim.\n */\nexport const ACP_UNSUPPORTED: readonly string[] = [\n // Services this seller does not implement, named as ACP names them. The\n // discovery document advertises `checkout` alone, and these are the reason.\n 'carts service',\n 'feed service',\n 'standalone orders service',\n 'delegate_payment',\n 'delegate_authentication',\n // Bindings and delivery directions.\n 'ACP MCP transport binding',\n 'webhooks',\n 'outbound merchant-to-agent delivery',\n 'ACP client role',\n // Request authentication beyond the bearer token.\n 'Signature header verification',\n 'Timestamp replay-window verification',\n // Extensions and versioning.\n 'discount extension',\n 'general ACP extension framework',\n 'multiple ACP API versions',\n 'seller-backed payment handler integration',\n];\n\nexport function buildDescriptor(implementationVersion: string): AdapterDescriptor {\n return {\n name: 'acp',\n kind: 'protocol',\n implementationVersion,\n supportedSpec: ACP_SPEC_VERSION,\n capabilities: ACP_CAPABILITIES,\n status: 'experimental',\n unsupported: ACP_UNSUPPORTED,\n };\n}\n","/**\n * SQLite implementation of the frozen ReceiptStore interface.\n *\n * Thin repository layer — no ORM. Every write goes through a prepared\n * statement; the only thing that varies between calls is parameters.\n */\nimport { randomUUID } from 'node:crypto';\nimport { accessSync, constants as fsConstants } from 'node:fs';\nimport {\n type AdapterDescriptor,\n type AdapterHealth,\n type Clock,\n CommerceError,\n type CommerceEvent,\n type CommerceReceipt,\n type IdGenerator,\n type ListOptions,\n type Logger,\n NOOP_LOGGER,\n type PaymentAttempt,\n type PaymentAttemptReservation,\n type PaymentAttemptUpdate,\n type ReceiptStore,\n systemClock,\n toCommerceError,\n} from '../../core/index.js';\nimport { PACKAGE_VERSION } from '../../version.js';\nimport { openSqliteDatabase } from '../sqlite.js';\nimport {\n type EventRow,\n eventToRow,\n type PaymentAttemptRow,\n type ReceiptRow,\n receiptToRow,\n rowToEvent,\n rowToPaymentAttempt,\n rowToReceipt,\n} from './rows.js';\nimport { migrate, SCHEMA_VERSION } from './schema.js';\n\nconst DEFAULT_LIST_LIMIT = 50;\n/**\n * Hard ceiling on every list query, applied here rather than only at the\n * gateway route, so every caller (HTTP, CLI, a future adapter) is covered.\n * SQLite treats a negative `LIMIT` as \"no limit\" —\n * confirmed `{ limit: -1 }` returns the entire table.\n */\nconst MAX_LIST_LIMIT = 500;\n\n/**\n * Clamps to a whole number in [1, MAX_LIST_LIMIT], defaulting when absent OR\n * non-finite (NaN/Infinity) — a store-level invariant that must hold\n * regardless of whether the current caller already filters those out.\n */\nfunction clampListLimit(limit: number | undefined): number {\n const base = limit !== undefined && Number.isFinite(limit) ? limit : DEFAULT_LIST_LIMIT;\n return Math.min(Math.max(Math.trunc(base), 1), MAX_LIST_LIMIT);\n}\n\nexport interface SqliteReceiptStoreOptions {\n /** File path, or ':memory:' for tests. Parent directory is created if missing. */\n readonly path: string;\n readonly logger?: Logger;\n readonly clock?: Clock;\n readonly ids?: IdGenerator;\n}\n\nconst defaultIds: IdGenerator = {\n next: (prefix) => (prefix !== undefined ? `${prefix}_${randomUUID()}` : randomUUID()),\n};\n\nfunction isUniqueConstraintOn(err: unknown, column: string): boolean {\n return (\n err instanceof Error &&\n 'code' in err &&\n (err as { code?: unknown }).code === 'SQLITE_CONSTRAINT_UNIQUE' &&\n err.message.includes(column)\n );\n}\n\nexport function createSqliteReceiptStore(options: SqliteReceiptStoreOptions): ReceiptStore {\n const logger = options.logger ?? NOOP_LOGGER;\n const clock = options.clock ?? systemClock;\n const ids = options.ids ?? defaultIds;\n const path = options.path;\n const isFileBacked = path !== ':memory:';\n\n // Opening and hardening the file is shared with the ACP idempotency store -\n // see src/storage/sqlite.ts. Two copies of that logic is how one of them\n // ends up shipping a world-readable database.\n const db = openSqliteDatabase({ path, label: 'Receipt database', logger });\n migrate(db);\n\n const insertReceiptStmt = db.prepare(\n `INSERT INTO receipts (id, request_id, resource_id, payment_json, delivered_at, backend_status, duration_ms, protocol, metadata_json)\n VALUES (@id, @request_id, @resource_id, @payment_json, @delivered_at, @backend_status, @duration_ms, @protocol, @metadata_json)`,\n );\n const getReceiptStmt = db.prepare<[string], ReceiptRow>('SELECT * FROM receipts WHERE id = ?');\n const listReceiptsStmt = db.prepare<[number], ReceiptRow>(\n 'SELECT * FROM receipts ORDER BY delivered_at DESC, seq DESC LIMIT ?',\n );\n const listReceiptsByRequestStmt = db.prepare<[string, number], ReceiptRow>(\n 'SELECT * FROM receipts WHERE request_id = ? ORDER BY delivered_at DESC, seq DESC LIMIT ?',\n );\n const countReceiptsStmt = db.prepare<[], { count: number }>(\n 'SELECT COUNT(*) AS count FROM receipts',\n );\n // backend_status is INTEGER NOT NULL (schema.ts) so NOT BETWEEN never has\n // a NULL row to silently miss; 0 (backend never responded at all) and\n // every non-2xx status both count as undelivered, matching the dashboard's\n // deliveryResult() (ReceiptList.tsx) — the two views must not disagree\n // about what \"delivered\" means, which is the confusion.\n const countUndeliveredReceiptsStmt = db.prepare<[], { count: number }>(\n 'SELECT COUNT(*) AS count FROM receipts WHERE backend_status NOT BETWEEN 200 AND 299',\n );\n\n const insertEventStmt = db.prepare(\n `INSERT INTO events (id, type, request_id, resource_id, at, adapter, payment_provider, duration_ms, status, data_json)\n VALUES (@id, @type, @request_id, @resource_id, @at, @adapter, @payment_provider, @duration_ms, @status, @data_json)`,\n );\n const listEventsStmt = db.prepare<[number], EventRow>(\n 'SELECT * FROM events ORDER BY at DESC, seq DESC LIMIT ?',\n );\n const listEventsByRequestStmt = db.prepare<[string, number], EventRow>(\n 'SELECT * FROM events WHERE request_id = ? ORDER BY at DESC, seq DESC LIMIT ?',\n );\n\n const insertPaymentAttemptStmt = db.prepare(\n `INSERT INTO payment_attempts (id, request_id, resource_id, provider, replay_key, status, amount, currency, payer, payee, external_reference, rejection_reason, created_at, updated_at)\n VALUES (@id, @request_id, @resource_id, @provider, @replay_key, @status, @amount, @currency, @payer, @payee, @external_reference, @rejection_reason, @created_at, @updated_at)`,\n );\n const getPaymentAttemptByIdStmt = db.prepare<[string], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts WHERE id = ?',\n );\n // COALESCE: an omitted field (bound as NULL — see updatePaymentAttempt)\n // means \"leave the existing value alone\", not \"clear it\". Without this, a\n // second update that doesn't re-supply external_reference/rejection_reason\n // erases it — exactly the field that carries the on-chain tx hash for a\n // settlement-uncertain attempt, the one record proving the buyer's funds\n // may have moved. There is no current caller that needs to clear an\n // already-set value; if one appears, it needs an explicit sentinel rather\n // than overloading `undefined` to mean two different things again.\n const updatePaymentAttemptStmt = db.prepare(\n `UPDATE payment_attempts SET status = @status,\n external_reference = COALESCE(@external_reference, external_reference),\n rejection_reason = COALESCE(@rejection_reason, rejection_reason),\n updated_at = @updated_at\n WHERE replay_key = @replay_key`,\n );\n const listPaymentAttemptsStmt = db.prepare<[number], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts ORDER BY created_at DESC, seq DESC LIMIT ?',\n );\n const listPaymentAttemptsByRequestStmt = db.prepare<[string, number], PaymentAttemptRow>(\n 'SELECT * FROM payment_attempts WHERE request_id = ? ORDER BY created_at DESC, seq DESC LIMIT ?',\n );\n\n let closed = false;\n\n const descriptor: AdapterDescriptor = {\n name: 'sqlite-receipt-store',\n kind: 'storage',\n implementationVersion: PACKAGE_VERSION,\n supportedSpec: `sqlite-schema-v${SCHEMA_VERSION}`,\n capabilities: ['receipts', 'events', 'payment-attempts'],\n status: 'stable',\n };\n\n const store: ReceiptStore = {\n async init(): Promise<void> {\n // Schema setup already happened synchronously above (better-sqlite3 is\n // sync). This re-check makes init() a meaningful, idempotent gate for\n // callers that treat it as the lifecycle hook that must succeed before\n // any other method is used.\n const version = db.pragma('user_version', { simple: true }) as number;\n if (version !== SCHEMA_VERSION) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `Receipt store schema version mismatch (found ${version}, expected ${SCHEMA_VERSION})`,\n );\n }\n },\n\n async appendEvent(event: CommerceEvent): Promise<void> {\n try {\n insertEventStmt.run(eventToRow(event));\n } catch (err) {\n logger.warn(\n {\n err: err instanceof Error ? err.message : String(err),\n eventId: event.id,\n requestId: event.requestId,\n },\n 'receipt-store: failed to persist commerce event',\n );\n }\n },\n\n async reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt> {\n const now = clock.nowIso();\n const id = ids.next('attempt');\n try {\n insertPaymentAttemptStmt.run({\n id,\n request_id: reservation.requestId,\n resource_id: reservation.resourceId,\n provider: reservation.provider,\n replay_key: reservation.replayKey,\n status: 'reserved' satisfies PaymentAttempt['status'],\n amount: reservation.amount,\n currency: reservation.currency,\n payer: reservation.payer ?? null,\n payee: reservation.payee ?? null,\n external_reference: null,\n rejection_reason: null,\n created_at: now,\n updated_at: now,\n });\n } catch (err) {\n if (isUniqueConstraintOn(err, 'payment_attempts.replay_key')) {\n throw new CommerceError(\n 'PAYMENT_REPLAYED',\n `Payment authorisation has already been used (replayKey=${reservation.replayKey})`,\n { requestId: reservation.requestId, resourceId: reservation.resourceId },\n );\n }\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to reserve payment attempt');\n }\n const row = getPaymentAttemptByIdStmt.get(id);\n if (row === undefined) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n 'Payment attempt vanished immediately after insert',\n );\n }\n return rowToPaymentAttempt(row);\n },\n\n async updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void> {\n try {\n const result = updatePaymentAttemptStmt.run({\n replay_key: update.replayKey,\n status: update.status,\n external_reference: update.externalReference ?? null,\n rejection_reason: update.rejectionReason ?? null,\n updated_at: clock.nowIso(),\n });\n if (result.changes === 0) {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `No payment attempt found for replayKey=${update.replayKey}`,\n );\n }\n } catch (err) {\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to update payment attempt');\n }\n },\n\n async saveReceipt(receipt: CommerceReceipt): Promise<void> {\n try {\n insertReceiptStmt.run(receiptToRow(receipt));\n } catch (err) {\n throw toCommerceError(err, 'STORAGE_ERROR', 'Failed to save receipt');\n }\n },\n\n async getReceipt(id: string): Promise<CommerceReceipt | undefined> {\n const row = getReceiptStmt.get(id);\n return row !== undefined ? rowToReceipt(row) : undefined;\n },\n\n async listReceipts(listOptions: ListOptions = {}): Promise<readonly CommerceReceipt[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listReceiptsByRequestStmt.all(listOptions.requestId, limit)\n : listReceiptsStmt.all(limit);\n return rows.map(rowToReceipt);\n },\n\n /** Exact total, ignoring the listReceipts clamp — see the interface doc for why this exists. */\n async countReceipts(): Promise<number> {\n return countReceiptsStmt.get()?.count ?? 0;\n },\n\n /** Exact count of non-2xx receipts — see the interface doc for why this exists. */\n async countUndeliveredReceipts(): Promise<number> {\n return countUndeliveredReceiptsStmt.get()?.count ?? 0;\n },\n\n async listEvents(listOptions: ListOptions = {}): Promise<readonly CommerceEvent[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listEventsByRequestStmt.all(listOptions.requestId, limit)\n : listEventsStmt.all(limit);\n return rows.map(rowToEvent);\n },\n\n async listPaymentAttempts(listOptions: ListOptions = {}): Promise<readonly PaymentAttempt[]> {\n const limit = clampListLimit(listOptions.limit);\n const rows =\n listOptions.requestId !== undefined\n ? listPaymentAttemptsByRequestStmt.all(listOptions.requestId, limit)\n : listPaymentAttemptsStmt.all(limit);\n return rows.map(rowToPaymentAttempt);\n },\n\n descriptor,\n\n async health(): Promise<AdapterHealth> {\n // Same discipline: a client-visible field is authored from a\n // fixed vocabulary, never inherited from a caught error's `.message`.\n // `accessSync` on a real deployment throws e.g.\n // \"EACCES: permission denied, access '/workspace/data/receipts.sqlite'\"\n // — an absolute host path that must never reach the unauthenticated\n // `/ready` response). The raw message still goes\n // to the injected logger, so nothing is lost for diagnosis.\n const startedAt = clock.monotonicMs();\n if (closed) {\n return { status: 'fail', detail: 'store-unavailable', checkedAt: clock.nowIso() };\n }\n if (isFileBacked) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch (err) {\n logger.warn(\n { err: err instanceof Error ? err.message : String(err) },\n 'receipt-store: health check failed (store not writable)',\n );\n return {\n status: 'fail',\n detail: 'store-unwritable',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n }\n try {\n const version = db.pragma('user_version', { simple: true }) as number;\n if (version !== SCHEMA_VERSION) {\n logger.warn(\n { found: version, expected: SCHEMA_VERSION },\n 'receipt-store: health check failed (schema version mismatch)',\n );\n return {\n status: 'fail',\n detail: 'store-schema-mismatch',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n return {\n status: 'pass',\n detail: `sqlite schema v${SCHEMA_VERSION} writable`,\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n } catch (err) {\n logger.warn(\n { err: err instanceof Error ? err.message : String(err) },\n 'receipt-store: health check failed (store unavailable)',\n );\n return {\n status: 'fail',\n detail: 'store-unavailable',\n checkedAt: clock.nowIso(),\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n },\n\n async close(): Promise<void> {\n if (!closed) {\n closed = true;\n db.close();\n }\n },\n };\n\n return store;\n}\n","/**\n * The package version, resolved once for the whole package.\n *\n * Two paths, deliberately:\n *\n * - **Development** reads the root manifest, so the number is always live.\n * - **The published bundle cannot.** tsup collapses `src/**` into\n * `dist/index.js` and `dist/cli/index.js`, so any `require('../../package.json')`\n * written against a source path resolves from the wrong depth once bundled —\n * which is exactly how this broke during the single-package refactor, and how\n * it earlier produced a CLI reporting `v0.0.0-unknown`. The build injects\n * `__OAC_PACKAGE_VERSION__` instead (see tsup.config.ts).\n *\n * `typeof` on an undeclared identifier is safe in JS, so the dev path is\n * unaffected by the constant not existing.\n */\nimport { createRequire } from 'node:module';\n\ndeclare const __OAC_PACKAGE_VERSION__: string | undefined;\n\nfunction readFromManifest(): string {\n try {\n const require = createRequire(import.meta.url);\n // src/version.ts -> repository root\n return (require('../package.json') as { version?: string }).version ?? '0.0.0-unknown';\n } catch {\n return '0.0.0-unknown';\n }\n}\n\nexport const PACKAGE_VERSION: string =\n typeof __OAC_PACKAGE_VERSION__ === 'string' ? __OAC_PACKAGE_VERSION__ : readFromManifest();\n","/**\n * Opening a SQLite file safely.\n *\n * One definition, because every rule below was learned once and must not be\n * re-learned per store: the file is pre-created at 0600 before SQLite can\n * create it at `0666 & ~umask`, the WAL sidecars are narrowed after WAL is\n * enabled (they do not exist until then), and an existing but unwritable file\n * fails at startup instead of on the first write.\n *\n * Callers own their schema. This function opens and hardens; it migrates\n * nothing.\n */\nimport {\n accessSync,\n chmodSync,\n closeSync,\n existsSync,\n constants as fsConstants,\n mkdirSync,\n openSync,\n} from 'node:fs';\nimport { dirname } from 'node:path';\nimport Database from 'better-sqlite3';\nimport { CommerceError, type Logger } from '../core/index.js';\n\nexport interface OpenSqliteOptions {\n /** File path, or ':memory:' for tests. Parent directory is created if missing. */\n readonly path: string;\n /** Names the database in operator-facing errors, e.g. \"Receipt database\". */\n readonly label: string;\n readonly logger: Logger;\n}\n\nexport function openSqliteDatabase(options: OpenSqliteOptions): Database.Database {\n const { path, label, logger } = options;\n const isFileBacked = path !== ':memory:';\n\n if (isFileBacked) {\n const dir = dirname(path);\n if (dir !== '' && dir !== '.' && !existsSync(dir)) {\n // 0700 on directories we create ourselves. An existing directory is the\n // operator's to own and is deliberately left alone.\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n }\n\n // Fail at startup, not on the first write. `new Database(path)` happily opens\n // a file the process cannot write, and SQLite only says \"attempt to write a\n // readonly database\" once a write is attempted - which on a paid resource is\n // *after* the payment attempt reservation, surfacing as an opaque\n // STORAGE_ERROR per request. Readiness does catch it (503), but the operator\n // is left guessing. This is not hypothetical: switching the demo containers\n // to a non-root user left an existing named volume root-owned, and that is\n // exactly how it presented.\n if (isFileBacked && existsSync(path)) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `${label} \"${path}\" exists but is not writable by this process (uid ${typeof process.getuid === 'function' ? process.getuid() : 'unknown'}). If this is a container that recently changed user, an existing volume may still be owned by the previous one - recreate it (docker compose down -v) or fix its ownership.`,\n { details: { path } },\n );\n }\n }\n\n // Create the file ourselves, at 0600, *before* SQLite can create it at\n // `0666 & ~umask`. The chmod below only narrows the mode after the fact: a\n // local co-tenant who opens the file inside that window keeps a readable\n // descriptor across the chmod and reads everything written afterwards.\n // SQLite copies the main file's mode onto the -wal/-shm sidecars, so this one\n // call covers all three. `mode` applies on creation only, so an existing file\n // is untouched here and left to the chmod.\n if (isFileBacked) {\n try {\n closeSync(openSync(path, 'a', 0o600));\n } catch {\n // Deliberately silent: whatever stopped us (unwritable directory, exotic\n // filesystem) is about to be reported by `new Database` with a better\n // message, or is harmless and covered by the chmod below.\n }\n }\n\n const db = new Database(path);\n db.pragma('journal_mode = WAL');\n db.pragma('foreign_keys = ON');\n if (isFileBacked) restrictDatabasePermissions(path, label, logger);\n return db;\n}\n\n/**\n * Narrow the database and its WAL sidecars to owner-only.\n *\n * `new Database(path)` opens with `0666 & ~umask`, so on a standard host the\n * `.sqlite`, `-wal` and `-shm` files landed at 0644 - any other local user\n * could read the whole commerce ledger: payer and payee addresses, amounts,\n * settlement transaction hashes, replay keys and the entire event stream. No\n * key material (the gateway is non-custodial and `redact.ts` is recursive), but\n * business metadata all the same.\n *\n * Called *after* `journal_mode = WAL`, because the sidecars do not exist until\n * then. Belt-and-braces since the main file is pre-created at 0600 above: this\n * still tightens a database that already existed with a looser mode.\n * Best-effort by design: a filesystem without POSIX modes must not stop the\n * gateway from starting, so a failure warns rather than throws.\n */\nfunction restrictDatabasePermissions(path: string, label: string, logger: Logger): void {\n for (const file of [path, `${path}-wal`, `${path}-shm`]) {\n try {\n chmodSync(file, 0o600);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'ENOENT') continue;\n logger.warn(\n { file, label, error: code ?? 'unknown' },\n 'could not restrict database permissions to owner-only',\n );\n }\n }\n}\n","/**\n * Defence-in-depth against accidentally persisting secrets.\n *\n * The gateway and payment providers are expected to never place secrets into\n * `CommerceReceipt.metadata`, `CommerceEvent.data` or `PaymentResult.metadata`\n * (see docs/contracts.md, \"Store NO secrets\"). This module is a second line\n * of defence at the persistence boundary: any key that *looks* like it holds\n * a private key, an auth header or a raw payment proof is stripped — never\n * persisted — rather than rejecting the whole write, so a logging bug never\n * takes down an otherwise-successful commerce flow (appendEvent especially\n * must never throw into the caller's flow).\n */\n/**\n * The bearer-token family was missing — `token`, `bearerToken`,\n * `adminToken`, `authToken`, `credential`, `cookie`, `sessionId`, `jwt` all\n * returned false. Nothing writes such a key today, which is exactly the state\n * a second line of defence is for; and this data also lands in a\n * file that is now owner-only precisely because it is worth protecting.\n */\nconst SECRET_KEY_PATTERN =\n /private[-_ ]?key|secret|password|mnemonic|seed[-_ ]?phrase|api[-_ ]?key|authoriz(e|ation)|^auth$|auth[-_]?header|payment[-_ ]?proof|^proof$|x-payment|signature|signed[-_ ]?message|token|bearer|credential|cookie|session|jwt/i;\n\nconst REDACTED = '[REDACTED]';\n\n/** True if `key` looks like it names a secret value. */\nexport function isSecretKey(key: string): boolean {\n return SECRET_KEY_PATTERN.test(key);\n}\n\n/**\n * Recursively strip values whose key looks secret-shaped, returning a new\n * object. Safe to call on already-clean data (no-op in that case).\n */\nexport function redact<T>(value: T): T {\n return redactValue(value) as T;\n}\n\nfunction redactValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(redactValue);\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n out[key] = isSecretKey(key) ? REDACTED : redactValue(inner);\n }\n return out;\n }\n return value;\n}\n\n/** True if `value` (recursively) contains any key that looks secret-shaped. */\nexport function containsSecretKey(value: unknown): boolean {\n if (Array.isArray(value)) {\n return value.some(containsSecretKey);\n }\n if (value !== null && typeof value === 'object') {\n return Object.entries(value as Record<string, unknown>).some(\n ([key, inner]) => isSecretKey(key) || containsSecretKey(inner),\n );\n }\n return false;\n}\n","/**\n * SQLite row shapes and mapping to/from the canonical domain model.\n *\n * `exactOptionalPropertyTypes` is on: optional fields are only assigned when\n * present (see docs/contracts.md, assumption 8).\n */\nimport type {\n CommerceEvent,\n CommerceEventType,\n CommerceReceipt,\n PaymentAttempt,\n PaymentResult,\n} from '../../core/index.js';\nimport { redact } from './redact.js';\n\nexport interface ReceiptRow {\n readonly id: string;\n readonly request_id: string;\n readonly resource_id: string;\n readonly payment_json: string | null;\n readonly delivered_at: string;\n readonly backend_status: number;\n readonly duration_ms: number | null;\n readonly protocol: string | null;\n readonly metadata_json: string | null;\n}\n\nexport interface EventRow {\n readonly id: string;\n readonly type: string;\n readonly request_id: string;\n readonly resource_id: string | null;\n readonly at: string;\n readonly adapter: string | null;\n readonly payment_provider: string | null;\n readonly duration_ms: number | null;\n readonly status: string | null;\n readonly data_json: string | null;\n}\n\nexport interface PaymentAttemptRow {\n readonly id: string;\n readonly request_id: string;\n readonly resource_id: string;\n readonly provider: string;\n readonly replay_key: string;\n readonly status: string;\n readonly amount: string;\n readonly currency: string;\n readonly payer: string | null;\n readonly payee: string | null;\n readonly external_reference: string | null;\n readonly rejection_reason: string | null;\n readonly created_at: string;\n readonly updated_at: string;\n}\n\nexport function receiptToRow(receipt: CommerceReceipt): {\n id: string;\n request_id: string;\n resource_id: string;\n payment_json: string | null;\n delivered_at: string;\n backend_status: number;\n duration_ms: number | null;\n protocol: string | null;\n metadata_json: string | null;\n} {\n return {\n id: receipt.id,\n request_id: receipt.requestId,\n resource_id: receipt.resourceId,\n payment_json: receipt.payment !== undefined ? JSON.stringify(redact(receipt.payment)) : null,\n delivered_at: receipt.deliveredAt,\n backend_status: receipt.backendStatus,\n duration_ms: receipt.durationMs !== undefined ? receipt.durationMs : null,\n protocol: receipt.protocol !== undefined ? receipt.protocol : null,\n metadata_json: receipt.metadata !== undefined ? JSON.stringify(redact(receipt.metadata)) : null,\n };\n}\n\nexport function rowToReceipt(row: ReceiptRow): CommerceReceipt {\n const payment =\n row.payment_json !== null ? (JSON.parse(row.payment_json) as PaymentResult) : undefined;\n const metadata =\n row.metadata_json !== null\n ? (JSON.parse(row.metadata_json) as Record<string, unknown>)\n : undefined;\n return {\n id: row.id,\n requestId: row.request_id,\n resourceId: row.resource_id,\n deliveredAt: row.delivered_at,\n backendStatus: row.backend_status,\n ...(payment !== undefined ? { payment } : {}),\n ...(row.duration_ms !== null ? { durationMs: row.duration_ms } : {}),\n ...(row.protocol !== null ? { protocol: row.protocol } : {}),\n ...(metadata !== undefined ? { metadata } : {}),\n };\n}\n\nexport function eventToRow(event: CommerceEvent): {\n id: string;\n type: string;\n request_id: string;\n resource_id: string | null;\n at: string;\n adapter: string | null;\n payment_provider: string | null;\n duration_ms: number | null;\n status: string | null;\n data_json: string | null;\n} {\n return {\n id: event.id,\n type: event.type,\n request_id: event.requestId,\n resource_id: event.resourceId !== undefined ? event.resourceId : null,\n at: event.at,\n adapter: event.adapter !== undefined ? event.adapter : null,\n payment_provider: event.paymentProvider !== undefined ? event.paymentProvider : null,\n duration_ms: event.durationMs !== undefined ? event.durationMs : null,\n status: event.status !== undefined ? event.status : null,\n data_json: event.data !== undefined ? JSON.stringify(redact(event.data)) : null,\n };\n}\n\nexport function rowToEvent(row: EventRow): CommerceEvent {\n const data =\n row.data_json !== null ? (JSON.parse(row.data_json) as Record<string, unknown>) : undefined;\n return {\n id: row.id,\n type: row.type as CommerceEventType,\n requestId: row.request_id,\n at: row.at,\n ...(row.resource_id !== null ? { resourceId: row.resource_id } : {}),\n ...(row.adapter !== null ? { adapter: row.adapter } : {}),\n ...(row.payment_provider !== null ? { paymentProvider: row.payment_provider } : {}),\n ...(row.duration_ms !== null ? { durationMs: row.duration_ms } : {}),\n ...(row.status !== null ? { status: row.status as 'ok' | 'error' } : {}),\n ...(data !== undefined ? { data } : {}),\n };\n}\n\nexport function rowToPaymentAttempt(row: PaymentAttemptRow): PaymentAttempt {\n return {\n id: row.id,\n requestId: row.request_id,\n resourceId: row.resource_id,\n provider: row.provider,\n replayKey: row.replay_key,\n status: row.status as PaymentAttempt['status'],\n amount: row.amount,\n currency: row.currency,\n ...(row.payer !== null ? { payer: row.payer } : {}),\n ...(row.payee !== null ? { payee: row.payee } : {}),\n ...(row.external_reference !== null ? { externalReference: row.external_reference } : {}),\n ...(row.rejection_reason !== null ? { rejectionReason: row.rejection_reason } : {}),\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n","/**\n * Explicit migration scheme for the receipt-store SQLite schema.\n *\n * Uses SQLite's built-in `PRAGMA user_version` as the migration marker so a\n * restart against an existing database file re-opens without re-creating or\n * losing data (required negative test: \"gateway restart with receipt storage\n * preserved\").\n */\nimport type Database from 'better-sqlite3';\n\ninterface Migration {\n readonly version: number;\n up(db: Database.Database): void;\n}\n\nconst MIGRATIONS: readonly Migration[] = [\n {\n version: 1,\n up(db) {\n db.exec(`\n CREATE TABLE IF NOT EXISTS receipts (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n request_id TEXT NOT NULL,\n resource_id TEXT NOT NULL,\n payment_json TEXT,\n delivered_at TEXT NOT NULL,\n backend_status INTEGER NOT NULL,\n duration_ms INTEGER,\n protocol TEXT,\n metadata_json TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_receipts_request_id ON receipts(request_id);\n CREATE INDEX IF NOT EXISTS idx_receipts_delivered_at ON receipts(delivered_at);\n\n CREATE TABLE IF NOT EXISTS events (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n type TEXT NOT NULL,\n request_id TEXT NOT NULL,\n resource_id TEXT,\n at TEXT NOT NULL,\n adapter TEXT,\n payment_provider TEXT,\n duration_ms INTEGER,\n status TEXT,\n data_json TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_events_request_id ON events(request_id);\n CREATE INDEX IF NOT EXISTS idx_events_at ON events(at);\n\n CREATE TABLE IF NOT EXISTS payment_attempts (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n request_id TEXT NOT NULL,\n resource_id TEXT NOT NULL,\n provider TEXT NOT NULL,\n replay_key TEXT NOT NULL UNIQUE,\n status TEXT NOT NULL,\n amount TEXT NOT NULL,\n currency TEXT NOT NULL,\n payer TEXT,\n payee TEXT,\n external_reference TEXT,\n rejection_reason TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_payment_attempts_request_id ON payment_attempts(request_id);\n CREATE INDEX IF NOT EXISTS idx_payment_attempts_created_at ON payment_attempts(created_at);\n `);\n },\n },\n];\n\n/** Current target schema version — the version of the last migration. */\nexport const SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;\n\n/**\n * Bring `db` up to {@link SCHEMA_VERSION}. Idempotent: re-opening an existing,\n * already-migrated file is a fast no-op check against `PRAGMA user_version`.\n */\nexport function migrate(db: Database.Database): void {\n const current = db.pragma('user_version', { simple: true }) as number;\n for (const migration of MIGRATIONS) {\n if (migration.version <= current) continue;\n const apply = db.transaction(() => {\n migration.up(db);\n db.pragma(`user_version = ${migration.version}`);\n });\n apply();\n }\n}\n","/**\n * Single seam for the CLI's dependency on `src/config`.\n *\n * The import is dynamic, not static, on purpose: a static\n * `import … from '../../config/index.js'` would fail the whole module\n * graph the instant the package became unavailable for any reason (mid-flight\n * refactor, a broken build), taking down every CLI command — even `version`,\n * which never touches config — the moment this file is loaded. A dynamic\n * import only fails, catchably, when a command actually needs configuration.\n *\n * `runValidate` / `runDoctor` / `runInit` also accept the loader as an\n * injected dependency (defaulting to {@link loadConfigDynamic}), which keeps\n * their logic unit-testable without touching the filesystem or the real\n * package.\n */\nimport type { GatewayConfig as GatewayConfigType } from '../../config/index.js';\n\nexport type GatewayConfig = GatewayConfigType;\n\nexport interface LoadConfigOptions {\n readonly path?: string;\n readonly env?: NodeJS.ProcessEnv;\n readonly cwd?: string;\n}\n\nexport type ConfigLoader = (options?: LoadConfigOptions) => Promise<GatewayConfig>;\n\n/** Validates an already-built raw config object, without touching the disk. */\nexport type ConfigParser = (raw: unknown, env?: NodeJS.ProcessEnv) => Promise<GatewayConfig>;\n\nexport async function loadConfigDynamic(options: LoadConfigOptions = {}): Promise<GatewayConfig> {\n let mod: typeof import('../../config/index.js');\n try {\n mod = await import('../../config/index.js');\n } catch (err) {\n throw new Error(\n `the configuration module could not be loaded: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n return mod.loadConfig(options);\n}\n\n/**\n * In-memory validation, same module and same seam as {@link loadConfigDynamic}.\n *\n * Validating the object before writing means nothing lands unless it is\n * valid. Writing the file and *then* loading it back would leave an answer\n * that legitimately fails validation — no protocol selected, a typo'd\n * settlement address, a scheme-less backend URL — on disk under a printed\n * \"PASS Wrote …\", and tell the user to report their own input as a bug.\n */\nexport async function parseConfigDynamic(\n raw: unknown,\n env: NodeJS.ProcessEnv = process.env,\n): Promise<GatewayConfig> {\n let mod: typeof import('../../config/index.js');\n try {\n mod = await import('../../config/index.js');\n } catch (err) {\n throw new Error(\n `the configuration module could not be loaded: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n return mod.parseConfig(raw, env);\n}\n","/**\n * Small fetch-with-timeout helper for `doctor`. Injectable so tests never hit\n * a real network — they point it at a local stub HTTP server instead.\n */\nexport type FetchLike = typeof fetch;\n\nexport interface FetchJsonResult<T> {\n readonly ok: boolean;\n readonly status: number;\n readonly body?: T;\n readonly error?: string;\n}\n\nexport async function fetchJson<T = unknown>(\n fetchImpl: FetchLike,\n url: string,\n timeoutMs = 1500,\n): Promise<FetchJsonResult<T>> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const res = await fetchImpl(url, { signal: controller.signal });\n let body: T | undefined;\n try {\n body = (await res.json()) as T;\n } catch {\n body = undefined;\n }\n return { ok: res.ok, status: res.status, ...(body !== undefined ? { body } : {}) };\n } catch (err) {\n return {\n ok: false,\n status: 0,\n error: err instanceof Error ? err.message : 'unknown fetch error',\n };\n } finally {\n clearTimeout(timer);\n }\n}\n","/**\n * Pure YAML-rendering logic for `agent-commerce init`, kept separate from\n * prompt/IO concerns so it is trivially unit-testable.\n *\n * The on-disk shape here is the *raw* `config.yaml` document consumed\n * by `src/config`'s `parseConfig` (src/config/schema.ts):\n * `resources` is a map keyed by resource id, with `backend` / `expose` /\n * `payments` / `input` / `output` field names — distinct from the normalised\n * `CommerceResource` shape (`handler` / `exposedVia` / `paymentMethods` /\n * `inputSchema` / `outputSchema`) that `loadConfig()` returns.\n *\n * Addresses below are Anvil's well-known local dev accounts #0 (facilitator\n * signer) and #1 (merchant `payTo`) — public, fixed, printed by every\n * `anvil` startup banner. Never fund them.\n * Imported from `src/payments/x402/testing.ts` — the\n * canonical source (docs/contracts.md) — rather than duplicated as literals,\n * so `init` can never drift from `scripts/chain/deploy.ts`'s account layout.\n * A hand-copied or truncated literal here breaks every paid request and\n * silently defeats the dev-key guard. The MockUSDC `asset` address is a clearly labelled placeholder: it\n * cannot be known before `npm run chain:deploy` writes `.deploy/local.json`, so\n * it must not be the zero address (rejected by config validation) and must\n * be replaced by the real deployed address.\n */\n\nimport { stringify } from 'yaml';\n// Narrow module, not the `testing.js` barrel — see manifest-env.ts for why.\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from '../../payments/x402/local-chain/accounts.js';\n\n/** Anvil account #1 — merchant settlement destination, never the gateway/facilitator. */\nexport const LOCAL_DEV_MERCHANT_ADDRESS = ANVIL_WELL_KNOWN_ACCOUNTS[1].address;\n/** Anvil account #0 — local facilitator signer (broadcasts settlement on the dev chain only). */\nexport const LOCAL_DEV_FACILITATOR_PRIVATE_KEY = ANVIL_WELL_KNOWN_ACCOUNTS[0].privateKey;\n/** Placeholder only — replace with the MockUSDC address from `.deploy/local.json`. */\nexport const PLACEHOLDER_ASSET_ADDRESS = '0x000000000000000000000000000000000000dEaD';\n\nexport type InitResourceChoice = 'weather' | 'report';\nexport type InitProtocolChoice = 'http' | 'mcp';\n\nexport interface InitAnswers {\n readonly backendBaseUrl: string;\n readonly resources: readonly InitResourceChoice[];\n readonly protocols: readonly InitProtocolChoice[];\n readonly x402Enabled: boolean;\n readonly merchantPayTo: string;\n}\n\nexport function defaultInitAnswers(): InitAnswers {\n return {\n backendBaseUrl: 'http://localhost:3000',\n resources: ['weather', 'report'],\n protocols: ['http', 'mcp'],\n x402Enabled: true,\n merchantPayTo: LOCAL_DEV_MERCHANT_ADDRESS,\n };\n}\n\nfunction buildResourcesMap(answers: InitAnswers): Record<string, unknown> {\n const resources: Record<string, unknown> = {};\n const expose = [...answers.protocols];\n\n if (answers.resources.includes('weather')) {\n resources.weather = {\n name: 'Get weather',\n description: 'Deterministic demo weather lookup (free resource).',\n input: {\n type: 'object',\n properties: { city: { type: 'string' } },\n required: ['city'],\n additionalProperties: false,\n },\n backend: {\n type: 'http',\n method: 'GET',\n url: `${answers.backendBaseUrl}/api/weather/{city}`,\n },\n pricing: { type: 'free' },\n expose,\n };\n }\n\n if (answers.resources.includes('report')) {\n const paid = answers.x402Enabled;\n resources.report = {\n name: 'Get market report',\n description: 'Deterministic demo premium market report.',\n // No caller-supplied fields for this resource: an explicit empty,\n // closed schema (rather than omitting `input`) so a missing schema can\n // never be read as \"anything goes\".\n input: {\n type: 'object',\n properties: {},\n additionalProperties: false,\n },\n backend: {\n type: 'http',\n method: 'GET',\n url: `${answers.backendBaseUrl}/api/report`,\n },\n pricing: paid ? { type: 'fixed', amount: '0.01', currency: 'USDC' } : { type: 'free' },\n expose,\n ...(paid ? { payments: ['x402'] } : {}),\n };\n }\n\n return resources;\n}\n\n/** Builds the raw config object accepted by `parseConfig` (src/config). */\nexport function buildInitConfigObject(answers: InitAnswers): Record<string, unknown> {\n return {\n version: 1,\n merchant: {\n id: 'demo-merchant',\n name: 'Demo Merchant',\n publicBaseUrl: 'http://localhost:8080',\n },\n server: { port: 8080, host: '127.0.0.1' },\n storage: { receipts: { driver: 'sqlite', path: './data/receipts.db' } },\n protocols: {\n http: { enabled: answers.protocols.includes('http') },\n mcp: { enabled: answers.protocols.includes('mcp'), mountPath: '/mcp' },\n },\n resources: buildResourcesMap(answers),\n payments: answers.x402Enabled\n ? {\n x402: {\n enabled: true,\n network: 'eip155:84532',\n rpcUrl: 'http://127.0.0.1:8545',\n asset: PLACEHOLDER_ASSET_ADDRESS,\n assetName: 'MockUSDC',\n assetVersion: '2',\n assetDecimals: 6,\n payTo: answers.merchantPayTo,\n maxTimeoutSeconds: 60,\n facilitator: { mode: 'local', signerPrivateKey: LOCAL_DEV_FACILITATOR_PRIVATE_KEY },\n },\n }\n : {},\n };\n}\n\nconst HEADER = `# Generated by \\`agent-commerce init\\`.\n#\n# Any address/key below labelled \"LOCAL DEVELOPMENT ONLY\" or \"placeholder\" is\n# either one of Anvil's well-known, public dev accounts (never fund them,\n# never use them outside a local chain) or a\n# not-yet-real address. Before running against the local chain, run\n# \\`npm run chain:deploy\\` and replace \\`payments.x402.asset\\` with the deployed\n# MockUSDC address from \\`.deploy/local.json\\`. Replace \\`payments.x402.payTo\\`\n# with your real merchant-controlled settlement address before ever pointing\n# this at a funded network.\n#\n# server.host is loopback (127.0.0.1) on purpose: binding every interface\n# should be a deliberate edit, not something you inherit from a generator.\n#\n# server.adminToken / server.allowedOrigins are left unset here — a generated\n# secret in a file you might commit is its own problem, so this is left as a\n# placeholder for you to fill in rather than a real token. Without a token,\n# the operator routes (/api/receipts, /api/events, /api/events/stream) —\n# the merchant's commerce ledger: payer addresses, amounts, settlement\n# hashes — return 404 rather than serving openly. To enable them, uncomment\n# and set:\n# server:\n# adminToken: \\${ADMIN_TOKEN}\n# allowedOrigins:\n# - http://localhost:5173\n# See SECURITY.md before exposing this gateway beyond localhost.\n`;\n\nexport function renderInitConfigYaml(answers: InitAnswers): string {\n const body = stringify(buildInitConfigObject(answers), { indent: 2 });\n return `${HEADER}\\n${body}`;\n}\n","/**\n * Local chain deployment manifest — read/write contract for `.deploy/local.json`.\n *\n * Exact shape frozen in docs/contracts.md. Everything else in the repo reads\n * chain addresses through `readLocalChainManifest()` — no hard-coded\n * addresses anywhere else.\n *\n * Lives inside `src/payments/x402` (not `scripts/chain`, which is\n * outside `src/` and is run directly by npm scripts —\n * see `deploy-engine.ts`'s header comment for the same reasoning) so any\n * workspace package can import it via `src/payments/x402/testing.ts`\n * (see `docs/contracts.md`, \"Local chain deployment manifest\"). It has no\n * dependency on viem/zod/x402 regardless — plain Node built-ins only —\n * `scripts/chain/manifest.ts` re-exports this module unchanged so\n * `npm run chain:deploy` keeps working as a thin CLI wrapper.\n */\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport const LOCAL_CHAIN_MANIFEST_PATH = '.deploy/local.json';\n\nexport interface LocalChainManifestMerchant {\n readonly address: string;\n readonly privateKeyLabel: string;\n}\n\nexport interface LocalChainManifestKeyedAccount {\n readonly address: string;\n readonly privateKey: string;\n readonly note: string;\n}\n\nexport interface LocalChainManifest {\n readonly chainId: number;\n readonly rpcUrl: string;\n /**\n * The same chain, reachable from the *host* — distinct from `rpcUrl` only\n * when the deployer ran inside a Docker network (there `rpcUrl` is the\n * container-internal address, e.g. \"http://anvil:8545\", unresolvable from\n * the host). A host deploy records the same value in both fields, since on\n * the host they genuinely are the same endpoint. Host-side consumers\n * (demo agent, CLI) should prefer `hostRpcUrl ?? rpcUrl`. Optional so a\n * manifest written before this field existed still parses.\n */\n readonly hostRpcUrl?: string;\n readonly asset: string;\n readonly assetName: string;\n readonly assetVersion: string;\n readonly assetDecimals: number;\n readonly merchant: LocalChainManifestMerchant;\n readonly buyer: LocalChainManifestKeyedAccount;\n readonly facilitator: LocalChainManifestKeyedAccount;\n readonly buyerInitialBalance: string;\n}\n\nconst REQUIRED_TOP_LEVEL_STRING_FIELDS = [\n 'rpcUrl',\n 'asset',\n 'assetName',\n 'assetVersion',\n 'buyerInitialBalance',\n] as const;\n\n/**\n * Reads and structurally validates `.deploy/local.json`.\n *\n * Throws a clear, actionable error if the manifest is missing or malformed —\n * every consumer of this function is expected to let that error propagate\n * rather than silently falling back to a hard-coded address.\n */\nexport function readLocalChainManifest(cwd: string = process.cwd()): LocalChainManifest {\n const path = join(cwd, LOCAL_CHAIN_MANIFEST_PATH);\n\n if (!existsSync(path)) {\n throw new Error(\n `Local chain manifest not found at \"${path}\". Run \"npm run chain:start\" then \"npm run chain:deploy\" first.`,\n );\n }\n\n let raw: string;\n try {\n raw = readFileSync(path, 'utf8');\n } catch (cause) {\n throw new Error(`Could not read local chain manifest at \"${path}\".`, { cause });\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new Error(\n `Local chain manifest at \"${path}\" is not valid JSON. Re-run \"npm run chain:deploy\" to regenerate it.`,\n { cause },\n );\n }\n\n return validateManifestShape(parsed, path);\n}\n\nfunction validateManifestShape(value: unknown, path: string): LocalChainManifest {\n const fail = (detail: string): never => {\n throw new Error(\n `Local chain manifest at \"${path}\" is invalid: ${detail}. Re-run \"npm run chain:deploy\".`,\n );\n };\n\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return fail('expected a JSON object');\n }\n const record = value as Record<string, unknown>;\n\n if (typeof record.chainId !== 'number') {\n return fail('\"chainId\" must be a number');\n }\n if (typeof record.assetDecimals !== 'number') {\n return fail('\"assetDecimals\" must be a number');\n }\n for (const field of REQUIRED_TOP_LEVEL_STRING_FIELDS) {\n if (typeof record[field] !== 'string' || record[field] === '') {\n return fail(`\"${field}\" must be a non-empty string`);\n }\n }\n // Optional: absent entirely on a manifest written before this field\n // existed, but if present it must be well-formed — never silently ignore a\n // malformed value on a trust-boundary read.\n if ('hostRpcUrl' in record && record.hostRpcUrl !== undefined) {\n if (typeof record.hostRpcUrl !== 'string' || record.hostRpcUrl === '') {\n return fail('\"hostRpcUrl\" must be a non-empty string when present');\n }\n }\n\n const merchant = record.merchant;\n if (\n typeof merchant !== 'object' ||\n merchant === null ||\n typeof (merchant as Record<string, unknown>).address !== 'string' ||\n typeof (merchant as Record<string, unknown>).privateKeyLabel !== 'string'\n ) {\n return fail('\"merchant\" must be { address: string, privateKeyLabel: string }');\n }\n\n for (const key of ['buyer', 'facilitator'] as const) {\n const account = record[key];\n if (\n typeof account !== 'object' ||\n account === null ||\n typeof (account as Record<string, unknown>).address !== 'string' ||\n typeof (account as Record<string, unknown>).privateKey !== 'string' ||\n typeof (account as Record<string, unknown>).note !== 'string'\n ) {\n return fail(`\"${key}\" must be { address: string, privateKey: string, note: string }`);\n }\n }\n\n return record as unknown as LocalChainManifest;\n}\n","/**\n * Local-development convenience: fills `X402_*`/`MERCHANT_WALLET`\n * placeholders in `config.yaml` from `.deploy/local.json` (written\n * by `npm run chain:deploy`) when the host shell hasn't set them itself.\n *\n * Why this exists: inside `docker compose`, `docker/gateway-entrypoint.sh`\n * exports these from the manifest before the gateway process starts. Running\n * `agent-commerce validate`/`doctor` on the host has no equivalent step, so\n * the exact same config that starts the (containerised) gateway fine fails\n * host-side with \"Unresolved environment variable\" — reporting a healthy\n * stack as broken. See docs/contracts.md \"Local chain deployment manifest\".\n *\n * Deliberately narrow: only fills a variable that is completely unset (a\n * real environment always wins — this can never override a deployment), only\n * from the exact fields the manifest declares, and only for `validate`/\n * `doctor` — never inside the config loader itself, so gateway startup is\n * unaffected either way.\n */\n// Imported from the narrow module, not the `testing.js` barrel: that barrel\n// also re-exports the Anvil bootstrap and the deploy engine, which import\n// `viem`. Tree-shaking drops the unused bindings but esbuild still emits a\n// bare `import 'viem'` for side effects, and viem is an optional peer — the\n// CLI would refuse to start on a default install. Caught by a bare\n// clean-consumer install, not by any in-repo test.\nimport {\n LOCAL_CHAIN_MANIFEST_PATH,\n type LocalChainManifest,\n readLocalChainManifest,\n} from '../../payments/x402/local-chain/manifest.js';\n\nexport { LOCAL_CHAIN_MANIFEST_PATH };\n\n/** `config.yaml` placeholder name -> the manifest field it maps to. */\nconst MANIFEST_ENV_VARS: readonly (readonly [string, (m: LocalChainManifest) => string])[] = [\n ['X402_ASSET', (m) => m.asset],\n ['X402_ASSET_NAME', (m) => m.assetName],\n ['X402_ASSET_VERSION', (m) => m.assetVersion],\n ['X402_ASSET_DECIMALS', (m) => String(m.assetDecimals)],\n ['MERCHANT_WALLET', (m) => m.merchant.address],\n ['X402_FACILITATOR_PRIVATE_KEY', (m) => m.facilitator.privateKey],\n];\n\n/** The subset of {@link MANIFEST_ENV_VARS} names, for checking a failed variable against. */\nexport const MANIFEST_FILLABLE_ENV_VAR_NAMES: ReadonlySet<string> = new Set(\n MANIFEST_ENV_VARS.map(([name]) => name),\n);\n\nexport interface ManifestEnvFill {\n /** `baseEnv`, plus any variables filled. Never mutates `baseEnv` itself. */\n readonly env: NodeJS.ProcessEnv;\n /** Names actually filled — empty when the manifest was absent or nothing needed filling. */\n readonly filled: readonly string[];\n /** True once a manifest was found at all, whether or not anything needed filling. */\n readonly manifestFound: boolean;\n}\n\n/**\n * Reads `.deploy/local.json` (relative to `cwd`) and fills only the\n * currently-unset variables in {@link MANIFEST_ENV_VARS}. Never throws — a\n * missing or invalid manifest just means nothing gets filled, and the\n * existing \"unresolved environment variable\" error from `src/config`\n * surfaces exactly as it does today.\n */\nexport function fillEnvFromLocalChainManifest(\n baseEnv: NodeJS.ProcessEnv,\n cwd: string = process.cwd(),\n): ManifestEnvFill {\n let manifest: LocalChainManifest;\n try {\n manifest = readLocalChainManifest(cwd);\n } catch {\n return { env: baseEnv, filled: [], manifestFound: false };\n }\n\n const filled: string[] = [];\n const env: NodeJS.ProcessEnv = { ...baseEnv };\n for (const [name, read] of MANIFEST_ENV_VARS) {\n if (env[name] === undefined) {\n env[name] = read(manifest);\n filled.push(name);\n }\n }\n return { env, filled, manifestFound: true };\n}\n","/**\n * Safe, visible-but-non-secret display of an address/destination for\n * `doctor`. Shows enough to eyeball correctness without ever printing a full\n * value that could be sensitive-adjacent (e.g. an RPC URL with an embedded\n * API key).\n *\n * Returning the value whole when it is short enough (`length <= keep * 2`)\n * would contradict the promise above — harmless for the 42-character\n * addresses this is used on today, and a trap for the next caller who reaches\n * for it with a short secret. A short value is masked entirely instead.\n */\nexport function maskMiddle(value: string, keep = 6): string {\n if (value.length <= keep * 2) return value.length === 0 ? value : '…';\n return `${value.slice(0, keep)}…${value.slice(-4)}`;\n}\n","/**\n * The CLI's own version and every pinned protocol/SDK version — never\n * hard-coded, so a pin bump (see docs/contracts.md) is reflected automatically.\n *\n * Two resolution paths, deliberately:\n *\n * - **Development** reads the root manifest directly, so the numbers are\n * always live.\n * - **The published npm package** cannot: the build collapses `src/**` into\n * two bundled files, so a relative manifest path written against a source\n * location resolves from the wrong depth once bundled. That has now failed\n * twice — it silently produced `v0.0.0-unknown` before packaging, and it\n * crashed both entry points during the single-package refactor. So the\n * build injects the resolved report as `__OAC_VERSION_REPORT__` (see\n * tsup.config.ts) and it is preferred when present.\n *\n * `typeof` on an undeclared identifier is safe in JS, so the dev path is\n * unaffected by the constant not existing.\n */\nimport { createRequire } from 'node:module';\n\ndeclare const __OAC_VERSION_REPORT__: string | undefined;\n\nconst require = createRequire(import.meta.url);\n\ninterface PackageManifest {\n readonly version: string;\n readonly dependencies?: Readonly<Record<string, string>>;\n readonly peerDependencies?: Readonly<Record<string, string>>;\n}\n\nfunction readManifest(relativePath: string): PackageManifest | undefined {\n try {\n return require(relativePath) as PackageManifest;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Peers count as pins. The three heaviest pins — the MCP SDK, x402 and viem —\n * are *optional peer* dependencies so a default install stays small, and\n * reading only `dependencies` silently emptied this report of exactly the\n * protocol/SDK versions it exists to show.\n */\nfunction depVersion(manifest: PackageManifest | undefined, name: string): string | undefined {\n return manifest?.dependencies?.[name] ?? manifest?.peerDependencies?.[name];\n}\n\nexport interface PinnedVersion {\n readonly name: string;\n readonly version: string;\n readonly via: string;\n}\n\nexport interface VersionReport {\n readonly cliVersion: string;\n readonly pinned: readonly PinnedVersion[];\n}\n\n/** Missing entries are omitted (rather than shown as \"unknown\") so nothing is ever fabricated. */\nexport function readVersionReport(): VersionReport {\n const injected = typeof __OAC_VERSION_REPORT__ === 'string' ? __OAC_VERSION_REPORT__ : undefined;\n if (injected !== undefined) {\n return JSON.parse(injected) as VersionReport;\n }\n\n // One package, one manifest. `via` names the module that owns each pin,\n // which is what a reader of `agent-commerce version` actually wants to know;\n // the names are src/ directories, not package manifests.\n const manifest = readManifest('../../../package.json');\n\n const candidates: readonly [string, string][] = [\n ['@modelcontextprotocol/sdk', 'protocols/mcp'],\n ['@coinbase/x402', 'payments/x402'],\n ['@x402/core', 'payments/x402'],\n ['@x402/evm', 'payments/x402'],\n ['viem', 'payments/x402'],\n ['better-sqlite3', 'storage/receipts'],\n ['fastify', 'gateway'],\n ['pino', 'gateway'],\n ['zod', 'config'],\n ];\n\n const pinned: PinnedVersion[] = [];\n for (const [name, via] of candidates) {\n const version = depVersion(manifest, name);\n if (version !== undefined) {\n pinned.push({ name, version, via });\n }\n }\n\n return {\n cliVersion: manifest?.version ?? '0.0.0-unknown',\n pinned,\n };\n}\n","/**\n * `agent-commerce import openapi <source>`.\n *\n * Generates reviewable resource drafts from a local OpenAPI description. It\n * never touches config.yaml and never invents commerce policy: without\n * `--free` / `--expose` the generated file is deliberately incomplete, so a\n * human has to decide what an operation costs and who can see it before\n * anything can load.\n */\nimport { existsSync } from 'node:fs';\nimport { rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, extname, resolve } from 'node:path';\nimport { PROTOCOL_NAMES } from '../../core/index.js';\nimport {\n buildResourceDrafts,\n type ImportPolicy,\n type ImportResult,\n loadOpenApiDocument,\n renderResourcesYaml,\n} from '../../openapi/index.js';\nimport type { Io } from '../lib/io.js';\n\nexport interface ImportOpenApiOptions {\n readonly source: string;\n readonly output?: string;\n readonly force?: boolean;\n readonly baseUrl?: string;\n readonly operations?: readonly string[];\n readonly tags?: readonly string[];\n readonly free?: boolean;\n readonly expose?: string;\n readonly strict?: boolean;\n readonly json?: boolean;\n}\n\nexport interface ImportOpenApiDeps {\n readonly fileExists?: (path: string) => boolean;\n readonly writeFile?: (path: string, content: string) => Promise<void>;\n}\n\n/** `<source-basename>.agent-commerce.yaml`, in the working directory. */\nexport function defaultOutputPath(source: string): string {\n const name = basename(source);\n const stem = name.slice(0, name.length - extname(name).length) || name;\n return `${stem}.agent-commerce.yaml`;\n}\n\nexport async function runImportOpenApi(\n options: ImportOpenApiOptions,\n io: Io,\n deps: ImportOpenApiDeps = {},\n): Promise<number> {\n const fileExists = deps.fileExists ?? existsSync;\n const outputPath = options.output ?? defaultOutputPath(options.source);\n\n let policy: ImportPolicy;\n try {\n policy = buildPolicy(options);\n } catch (error) {\n io.stderr(`FAIL ${error instanceof Error ? error.message : String(error)}`);\n return 1;\n }\n\n // Before doing any work: an existing file the operator did not ask to\n // replace is a stop, not something to discover after the import ran.\n if (fileExists(outputPath) && options.force !== true) {\n io.stderr(`FAIL ${outputPath} already exists. Re-run with --force to overwrite.`);\n return 1;\n }\n\n let result: ImportResult;\n try {\n const loaded = await loadOpenApiDocument(options.source);\n result = buildResourceDrafts(loaded, {\n ...(options.baseUrl !== undefined ? { baseUrl: options.baseUrl } : {}),\n ...(Object.keys(policy).length > 0 ? { policy } : {}),\n ...(options.operations !== undefined || options.tags !== undefined\n ? {\n include: {\n ...(options.operations !== undefined ? { operationIds: options.operations } : {}),\n ...(options.tags !== undefined ? { tags: options.tags } : {}),\n },\n }\n : {}),\n });\n } catch (error) {\n io.stderr(`FAIL ${error instanceof Error ? error.message : String(error)}`);\n return 1;\n }\n\n const skipped = result.diagnostics.filter((entry) => entry.severity === 'error');\n const warnings = result.diagnostics.filter((entry) => entry.severity === 'warning');\n\n const failures: string[] = [];\n if (result.unmatchedOperationIds.length > 0) {\n failures.push(`no operation matched ${result.unmatchedOperationIds.join(', ')}`);\n }\n if (result.drafts.length === 0) {\n failures.push('no supported operations were imported');\n }\n if (options.strict === true && warnings.length > 0) {\n failures.push(`${warnings.length} warning(s) with --strict`);\n }\n\n // Nothing is written when the run failed: a half-useful file that the next\n // command silently picks up is worse than no file.\n const wrote = failures.length === 0;\n if (wrote) {\n try {\n await writeAtomically(outputPath, renderResourcesYaml(result), deps);\n } catch (error) {\n io.stderr(`FAIL ${outputPath} could not be written: ${describe(error)}`);\n return 1;\n }\n }\n\n if (options.json === true) {\n io.stdout(\n JSON.stringify(\n {\n source: options.source,\n openapi: result.version,\n output: wrote ? outputPath : null,\n imported: result.drafts.length,\n skipped: skipped.length,\n warnings: warnings.length,\n resources: result.drafts.map((draft) => ({\n id: draft.id,\n source: draft.source,\n ...(draft.operationId !== undefined ? { operationId: draft.operationId } : {}),\n tags: draft.tags,\n })),\n diagnostics: result.diagnostics,\n unmatchedOperationIds: result.unmatchedOperationIds,\n exitCode: failures.length === 0 ? 0 : 1,\n },\n null,\n 2,\n ),\n );\n } else {\n printSummary(result, { outputPath, wrote, policy }, io);\n }\n\n for (const failure of failures) io.stderr(`FAIL ${failure}`);\n return failures.length === 0 ? 0 : 1;\n}\n\nfunction buildPolicy(options: ImportOpenApiOptions): ImportPolicy {\n const policy: { pricing?: Record<string, unknown>; expose?: readonly string[] } = {};\n if (options.free === true) policy.pricing = { type: 'free' };\n if (options.expose !== undefined) {\n const requested = options.expose\n .split(',')\n .map((name) => name.trim())\n .filter((name) => name !== '');\n if (requested.length === 0) {\n throw new Error(`--expose needs at least one protocol (${PROTOCOL_NAMES.join(', ')})`);\n }\n for (const name of requested) {\n if (!PROTOCOL_NAMES.includes(name as (typeof PROTOCOL_NAMES)[number])) {\n throw new Error(\n `--expose \"${name}\" is not a supported protocol. Supported: ${PROTOCOL_NAMES.join(', ')}`,\n );\n }\n }\n policy.expose = requested;\n }\n return policy;\n}\n\nasync function writeAtomically(\n outputPath: string,\n content: string,\n deps: ImportOpenApiDeps,\n): Promise<void> {\n if (deps.writeFile !== undefined) {\n await deps.writeFile(outputPath, content);\n return;\n }\n // Temp sibling then rename: a crash or a full disk must not leave a\n // half-written file where a complete one used to be.\n const target = resolve(outputPath);\n const temporary = `${target}.${process.pid}.tmp`;\n try {\n await writeFile(temporary, content, 'utf8');\n await rename(temporary, target);\n } catch (error) {\n await rm(temporary, { force: true });\n throw error;\n }\n}\n\nfunction printSummary(\n result: ImportResult,\n context: { outputPath: string; wrote: boolean; policy: ImportPolicy },\n io: Io,\n): void {\n const skipped = result.diagnostics.filter((entry) => entry.severity === 'error');\n const warnings = result.diagnostics.filter((entry) => entry.severity === 'warning');\n\n io.stdout(`OpenAPI ${result.version}: ${result.sourcePath}`);\n io.stdout('');\n io.stdout(`Imported: ${result.drafts.length}`);\n io.stdout(`Skipped: ${skipped.length}`);\n io.stdout(`Warnings: ${warnings.length}`);\n\n if (skipped.length > 0) {\n io.stdout('');\n io.stdout('Skipped operations:');\n for (const entry of skipped) io.stdout(` ${entry.message}`);\n }\n if (warnings.length > 0) {\n io.stdout('');\n io.stdout('Warnings:');\n for (const entry of warnings) io.stdout(` ${entry.message}`);\n }\n\n if (context.wrote) {\n io.stdout('');\n io.stdout('Generated:');\n io.stdout(` ${context.outputPath}`);\n }\n\n io.stdout('');\n if (context.policy.pricing === undefined || context.policy.expose === undefined) {\n io.stdout('Pricing/exposure were not inferred.');\n }\n io.stdout('Review the generated resources before merging them into config.yaml.');\n}\n\nfunction describe(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n","/**\n * Turns OpenAPI path operations into a deterministic list of candidates.\n *\n * Determinism is the point: a resource id is what an agent discovers and\n * hard-codes, so it must depend only on the document, never on iteration order\n * or on how many times the importer has run. Anything ambiguous fails the\n * import instead of being silently renamed.\n */\nimport type { BackendMethod } from '../core/domain/resource.js';\nimport { CommerceError } from '../core/errors/index.js';\nimport { findUnparsedBraceToken } from '../core/execution/index.js';\nimport { dereference } from './refs.js';\nimport type {\n ImportDiagnostic,\n LoadedOpenApiDocument,\n OpenApiOperationCandidate,\n} from './types.js';\n\nconst SUPPORTED_METHODS: Readonly<Record<string, BackendMethod>> = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n};\n\n/** Path Item members that are not operations. Anything else that is not a\n * supported method gets an explicit diagnostic rather than silent skipping. */\nconst NON_OPERATION_KEYS = new Set(['summary', 'description', 'servers', 'parameters', '$ref']);\n\n/** The id character set Agent Commerce and MCP tool names already share. */\nconst ID_ALLOWED = /[^A-Za-z0-9_.-]+/g;\nconst MAX_ID_LENGTH = 128;\n\nexport interface DiscoverOptions {\n /** CLI `--base-url`. Wins over every server declared in the document. */\n readonly baseUrl?: string;\n}\n\nexport interface DiscoveryResult {\n readonly operations: readonly OpenApiOperationCandidate[];\n readonly diagnostics: readonly ImportDiagnostic[];\n}\n\nexport function discoverOperations(\n loaded: LoadedOpenApiDocument,\n options: DiscoverOptions = {},\n): DiscoveryResult {\n const { document } = loaded;\n const diagnostics: ImportDiagnostic[] = [];\n const operations: OpenApiOperationCandidate[] = [];\n /** resource id -> the `METHOD path` that claimed it, for the collision message. */\n const claimed = new Map<string, string>();\n\n if (options.baseUrl !== undefined) assertAbsoluteHttpUrl(options.baseUrl, '--base-url');\n\n const paths = document['paths'];\n if (!isRecord(paths)) {\n return { operations, diagnostics };\n }\n\n const rootServers = document['servers'];\n const rootSecurity = document['security'];\n\n for (const [path, rawPathItem] of Object.entries(paths)) {\n if (path.startsWith('x-')) continue;\n if (!path.startsWith('/')) {\n diagnostics.push({\n severity: 'warning',\n code: 'invalid-path-key',\n operation: path,\n message: `Skipped \"${path}\": a Paths key must start with \"/\"`,\n });\n continue;\n }\n const pathItem = dereference(document, rawPathItem).value;\n if (!isRecord(pathItem)) continue;\n\n for (const [key, rawOperation] of Object.entries(pathItem)) {\n if (NON_OPERATION_KEYS.has(key) || key.startsWith('x-')) continue;\n const method = SUPPORTED_METHODS[key.toLowerCase()];\n if (method === undefined) {\n diagnostics.push({\n severity: 'warning',\n code: 'unsupported-method',\n operation: `${key.toUpperCase()} ${path}`,\n message: `Skipped ${key.toUpperCase()} ${path}: only GET, POST, PUT, PATCH and DELETE are supported`,\n });\n continue;\n }\n const operation = dereference(document, rawOperation).value;\n if (!isRecord(operation)) continue;\n\n const where = `${method} ${path}`;\n const operationId =\n typeof operation['operationId'] === 'string' ? operation['operationId'] : undefined;\n const resourceId = toResourceId(operationId, method, path);\n const previous = claimed.get(resourceId);\n if (previous !== undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `Operations \"${previous}\" and \"${where}\" both produce the resource id \"${resourceId}\". Give one of them a distinct operationId - ids are what agents discover, so the importer will not rename either`,\n { details: { resourceId, operations: [previous, where] } },\n );\n }\n claimed.set(resourceId, where);\n\n const server = selectServer(\n document,\n [operation['servers'], pathItem['servers'], rootServers],\n { where, resourceId },\n options,\n diagnostics,\n );\n if (server === undefined) continue;\n\n const backendUrl = `${server.replace(/\\/+$/, '')}${path}`;\n const stray = findUnparsedBraceToken(backendUrl);\n if (stray !== undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'unsupported-path-template',\n operation: resourceId,\n message: `Skipped ${where}: path template \"${stray}\" uses characters the gateway cannot substitute (allowed: A-Z a-z 0-9 _ . -)`,\n });\n continue;\n }\n\n const summary = typeof operation['summary'] === 'string' ? operation['summary'] : undefined;\n const description =\n typeof operation['description'] === 'string' ? operation['description'] : summary;\n const security = operation['security'] ?? rootSecurity;\n\n operations.push({\n resourceId,\n method,\n path,\n backendUrl,\n ...(operationId !== undefined ? { operationId } : {}),\n tags: toArray(operation['tags']).filter((tag): tag is string => typeof tag === 'string'),\n name: summary ?? operationId ?? resourceId,\n ...(description !== undefined ? { description } : {}),\n parameters: [\n ...toArray(pathItem['parameters']),\n // Operation parameters last: Phase 4 lets the later one win, which is\n // the OpenAPI override rule (same name + in).\n ...toArray(operation['parameters']),\n ],\n ...(operation['requestBody'] !== undefined\n ? { requestBody: operation['requestBody'] }\n : {}),\n ...(operation['responses'] !== undefined ? { responses: operation['responses'] } : {}),\n security: toArray(security),\n });\n }\n }\n\n return { operations, diagnostics };\n}\n\n/**\n * `operationId` if it survives normalisation, otherwise `method_path`.\n *\n * No counters and no random suffixes: two runs over the same document must\n * produce the same ids, and a collision is reported rather than papered over.\n */\nfunction toResourceId(\n operationId: string | undefined,\n method: BackendMethod,\n path: string,\n): string {\n const fromOperationId = operationId === undefined ? '' : normaliseId(operationId);\n if (fromOperationId !== '') return fromOperationId;\n return normaliseId(`${method.toLowerCase()}_${path}`);\n}\n\nfunction normaliseId(value: string): string {\n return value\n .replace(ID_ALLOWED, '_')\n .replace(/_+/g, '_')\n .replace(/^[_.-]+|[_.-]+$/g, '')\n .slice(0, MAX_ID_LENGTH);\n}\n\n/**\n * `--base-url` > operation servers > path-item servers > root servers.\n *\n * A relative server URL (`/v1`, the OpenAPI default of `/`) names no host, and\n * guessing one from the filename or from localhost would silently point a\n * merchant's gateway at the wrong backend - so it is refused and `--base-url`\n * asked for instead.\n */\nfunction selectServer(\n document: Record<string, unknown>,\n candidates: readonly unknown[],\n context: { readonly where: string; readonly resourceId: string },\n options: DiscoverOptions,\n diagnostics: ImportDiagnostic[],\n): string | undefined {\n if (options.baseUrl !== undefined) return options.baseUrl;\n\n for (const candidate of candidates) {\n const servers = toArray(candidate);\n const first = servers.length > 0 ? dereference(document, servers[0]).value : undefined;\n if (!isRecord(first)) continue;\n const url = first['url'];\n if (typeof url !== 'string' || url === '') continue;\n\n const substituted = substituteServerVariables(url, first['variables'], context, diagnostics);\n if (substituted === undefined) return undefined;\n if (!isAbsoluteHttpUrl(substituted)) {\n diagnostics.push({\n severity: 'error',\n code: 'relative-server-url',\n operation: context.resourceId,\n message: `Skipped ${context.where}: server URL \"${substituted}\" is relative, so no backend host is known. Pass --base-url`,\n });\n return undefined;\n }\n return substituted;\n }\n\n diagnostics.push({\n severity: 'error',\n code: 'no-server-url',\n operation: context.resourceId,\n message: `Skipped ${context.where}: the document declares no server URL. Pass --base-url`,\n });\n return undefined;\n}\n\nfunction substituteServerVariables(\n url: string,\n variables: unknown,\n context: { readonly where: string; readonly resourceId: string },\n diagnostics: ImportDiagnostic[],\n): string | undefined {\n if (!url.includes('{')) return url;\n const declared = isRecord(variables) ? variables : {};\n const used: string[] = [];\n let missing: string | undefined;\n const substituted = url.replace(/\\{([^{}]*)\\}/g, (match, name: string) => {\n const variable = declared[name];\n const fallback = isRecord(variable) ? variable['default'] : undefined;\n if (typeof fallback !== 'string') {\n missing = name;\n return match;\n }\n used.push(`${name}=${fallback}`);\n return fallback;\n });\n if (missing !== undefined) {\n diagnostics.push({\n severity: 'error',\n code: 'server-variable-without-default',\n operation: context.resourceId,\n message: `Skipped ${context.where}: server variable \"{${missing}}\" has no default value. Pass --base-url`,\n });\n return undefined;\n }\n if (used.length > 0) {\n diagnostics.push({\n severity: 'warning',\n code: 'server-variable-default',\n operation: context.resourceId,\n message: `Server URL for ${context.where} uses declared defaults (${used.join(', ')}); override with --base-url if that is not the deployment you mean`,\n });\n }\n return substituted;\n}\n\n/**\n * An absolute http(s) origin plus path, and nothing after it. A query or\n * fragment on the base would land *before* the operation path once the two\n * are concatenated (`.../api?key=x` + `/users/{id}`), producing a URL that\n * parses fine and calls the wrong endpoint.\n */\nfunction isAbsoluteHttpUrl(value: string): boolean {\n try {\n const parsed = new URL(value);\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return false;\n return parsed.search === '' && parsed.hash === '';\n } catch {\n return false;\n }\n}\n\nfunction assertAbsoluteHttpUrl(value: string, label: string): void {\n if (!isAbsoluteHttpUrl(value)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `${label} \"${value}\" must be an absolute http:// or https:// URL with no query string or fragment`,\n { details: { value } },\n );\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction toArray(value: unknown): readonly unknown[] {\n return Array.isArray(value) ? value : [];\n}\n","/**\n * Lazy internal `$ref` resolution.\n *\n * The document is deliberately *not* dereferenced up front. A recursive schema\n * (`Node.children[] -> Node`) expands without bound, so a whole-document\n * dereference turns a 30 kB file into an out-of-memory kill - an importer that\n * a merchant points at their own API must not be a way to do that. Instead\n * each pointer is followed on demand, with the chain that led here carried\n * along so a cycle is a diagnostic rather than a hang.\n */\nimport { CommerceError } from '../core/errors/index.js';\n\n/** Bounds a pathological but non-cyclic chain of `$ref`s pointing at `$ref`s. */\nconst MAX_REF_DEPTH = 100;\n\nexport interface Dereferenced {\n readonly value: unknown;\n /** Pointers already followed, oldest first. Pass it back in to keep detecting cycles. */\n readonly stack: readonly string[];\n}\n\nexport function isRefNode(value: unknown): value is { $ref: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { $ref?: unknown }).$ref === 'string'\n );\n}\n\n/**\n * Follows a chain of `$ref` nodes to the first value that is not one.\n *\n * Throws `CONFIG_INVALID` for a cycle, an unresolvable pointer, or an external\n * reference - the last is refused at load time too, so reaching it here means\n * a caller built a node the loader never saw.\n */\nexport function dereference(\n document: Record<string, unknown>,\n node: unknown,\n stack: readonly string[] = [],\n): Dereferenced {\n let current = node;\n let chain = stack;\n while (isRefNode(current)) {\n const pointer = current.$ref;\n if (!pointer.startsWith('#')) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `OpenAPI document contains an external reference \"${pointer}\". Only internal references (#/...) are supported`,\n { details: { ref: pointer } },\n );\n }\n if (chain.includes(pointer)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `OpenAPI reference \"${pointer}\" is circular (${[...chain, pointer].join(' -> ')})`,\n { details: { ref: pointer, chain: [...chain, pointer] } },\n );\n }\n if (chain.length >= MAX_REF_DEPTH) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `OpenAPI reference chain exceeds ${MAX_REF_DEPTH} hops at \"${pointer}\"`,\n { details: { ref: pointer } },\n );\n }\n current = resolvePointer(document, pointer);\n chain = [...chain, pointer];\n }\n return { value: current, stack: chain };\n}\n\n/** RFC 6901 JSON Pointer, rooted at the document (`#` or `#/a/b`). */\nfunction resolvePointer(document: Record<string, unknown>, ref: string): unknown {\n const pointer = ref.slice(1);\n if (pointer === '' || pointer === '/') return document;\n if (!pointer.startsWith('/')) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `OpenAPI reference \"${ref}\" is not a JSON Pointer. Plain names and anchors are not supported`,\n { details: { ref } },\n );\n }\n let current: unknown = document;\n for (const rawSegment of pointer.slice(1).split('/')) {\n // `~1` before `~0`: the reverse order turns an escaped \"~1\" back into \"/\".\n const segment = decodeURIComponent(rawSegment).replaceAll('~1', '/').replaceAll('~0', '~');\n if (Array.isArray(current)) {\n const index = Number(segment);\n current = Number.isInteger(index) ? current[index] : undefined;\n } else if (typeof current === 'object' && current !== null) {\n current = (current as Record<string, unknown>)[segment];\n } else {\n current = undefined;\n }\n if (current === undefined) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `OpenAPI reference \"${ref}\" does not resolve to anything in the document`,\n { details: { ref } },\n );\n }\n }\n return current;\n}\n","/**\n * OpenAPI parameters and request body -> a canonical input schema plus\n * `backend.inputBindings`.\n *\n * Locations are namespaced (`path` / `query` / `body`) so a `?id=` and a\n * `{id}` in the same operation cannot collide, and so the executor can source\n * each group independently. Anything the executor would not send the way the\n * API expects is refused rather than approximated: a required parameter we\n * cannot represent skips the operation, an optional one is omitted with a\n * warning. Approximating it would produce a resource that looks importable,\n * takes payment, and then calls the backend wrongly.\n */\nimport type { JsonSchema } from '../core/domain/common.js';\nimport { extractPathParameterNames } from '../core/execution/index.js';\nimport { dereference } from './refs.js';\nimport { convertSchema, isPrimitiveSchema } from './schema.js';\nimport type {\n ImportDiagnostic,\n LoadedOpenApiDocument,\n OpenApiOperationCandidate,\n} from './types.js';\n\n/** Top-level input property names. Also the binding values. */\nconst PATH_GROUP = 'path';\nconst QUERY_GROUP = 'query';\nconst BODY_GROUP = 'body';\n\n/**\n * OpenAPI: parameters named these \"SHALL be ignored\" - they are transport\n * concerns, and `Authorization` in particular is operator configuration that\n * must never become an agent-supplied input.\n */\nconst IGNORED_HEADER_NAMES = new Set(['accept', 'content-type', 'authorization']);\n\n/** Serialization styles the executor's plain `key=value` query cannot produce. */\nconst UNSUPPORTED_QUERY_STYLES = new Set(['deepObject', 'spaceDelimited', 'pipeDelimited']);\n\nexport interface RequestBindings {\n readonly path?: string;\n readonly query?: string;\n readonly body?: string;\n}\n\nexport type RequestMapping =\n | {\n readonly supported: true;\n readonly inputSchema: JsonSchema;\n readonly inputBindings: RequestBindings;\n /** Set only for a vendor `+json` body, which needs a static Content-Type. */\n readonly contentType?: string;\n /** Schema constraints dropped because the gateway does not enforce them. */\n readonly droppedKeywords: readonly string[];\n readonly diagnostics: readonly ImportDiagnostic[];\n }\n | { readonly supported: false; readonly diagnostics: readonly ImportDiagnostic[] };\n\nexport function mapRequest(\n loaded: LoadedOpenApiDocument,\n candidate: OpenApiOperationCandidate,\n): RequestMapping {\n const { document } = loaded;\n const diagnostics: ImportDiagnostic[] = [];\n const dropped = new Set<string>();\n const operation = candidate.resourceId;\n\n const warn = (code: string, message: string): void => {\n diagnostics.push({ severity: 'warning', code, operation, message });\n };\n const skip = (code: string, message: string): RequestMapping => {\n diagnostics.push({\n severity: 'error',\n code,\n operation,\n message: `Skipped ${candidate.method} ${candidate.path}: ${message}`,\n });\n return { supported: false, diagnostics };\n };\n\n const pathProperties: Record<string, unknown> = {};\n const queryProperties: Record<string, unknown> = {};\n const requiredQuery: string[] = [];\n const templateParams = new Set(extractPathParameterNames(candidate.path));\n\n for (const parameter of mergeParameters(document, candidate.parameters)) {\n const name = typeof parameter['name'] === 'string' ? parameter['name'] : undefined;\n const location = typeof parameter['in'] === 'string' ? parameter['in'] : undefined;\n if (name === undefined || location === undefined) continue;\n const required = parameter['required'] === true || location === 'path';\n const label = `${location} parameter \"${name}\"`;\n\n if (location === 'header' || location === 'cookie') {\n if (location === 'header' && IGNORED_HEADER_NAMES.has(name.toLowerCase())) continue;\n if (required) {\n return skip(\n 'unsupported-required-parameter',\n `${label} is required, and ${location} parameters are operator configuration in this release, not agent input`,\n );\n }\n warn(\n 'unsupported-optional-parameter',\n `Omitted optional ${label}: ${location} parameters are not imported. Configure it under backend.headers if the API needs it`,\n );\n continue;\n }\n if (location !== 'path' && location !== 'query') {\n if (required) return skip('unsupported-required-parameter', `${label} has unknown location`);\n warn('unsupported-optional-parameter', `Omitted optional ${label}: unknown location`);\n continue;\n }\n\n const unsupported = describeUnsupportedParameter(document, parameter, location);\n if (unsupported !== undefined) {\n if (required) return skip('unsupported-required-parameter', `${label} ${unsupported}`);\n warn('unsupported-optional-parameter', `Omitted optional ${label}: it ${unsupported}`);\n continue;\n }\n\n const converted = convertSchema(document, parameter['schema']);\n if (!converted.supported) {\n if (required) return skip('unsupported-required-parameter', `${label} ${converted.reason}`);\n warn('unsupported-optional-parameter', `Omitted optional ${label}: ${converted.reason}`);\n continue;\n }\n for (const keyword of converted.dropped) dropped.add(keyword);\n\n if (location === 'path') {\n if (!templateParams.has(name)) {\n warn(\n 'path-parameter-not-in-template',\n `Ignored path parameter \"${name}\": it does not appear in \"${candidate.path}\"`,\n );\n continue;\n }\n pathProperties[name] = converted.schema;\n } else {\n queryProperties[name] = converted.schema;\n if (required) requiredQuery.push(name);\n }\n }\n\n for (const param of templateParams) {\n if (!Object.hasOwn(pathProperties, param)) {\n return skip(\n 'undeclared-path-parameter',\n `\"{${param}}\" appears in the path but is not declared as a path parameter, so a caller could never supply it`,\n );\n }\n }\n\n const body = resolveBody(document, candidate);\n if (body.kind === 'unsupported') {\n if (body.required) return skip('unsupported-request-body', body.reason);\n warn('unsupported-request-body', `Omitted the request body: ${body.reason}`);\n }\n if (body.kind === 'schema') {\n for (const keyword of body.dropped) dropped.add(keyword);\n }\n\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n const bindings: { path?: string; query?: string; body?: string } = {};\n\n if (Object.keys(pathProperties).length > 0) {\n properties[PATH_GROUP] = closedObject(pathProperties, Object.keys(pathProperties));\n // OpenAPI path parameters are always required, and a missing one makes the\n // request unbuildable - which on a paid resource is payment with no\n // delivery, so config rejects the shape at load time too.\n required.push(PATH_GROUP);\n bindings.path = PATH_GROUP;\n }\n if (Object.keys(queryProperties).length > 0) {\n properties[QUERY_GROUP] = closedObject(queryProperties, requiredQuery);\n if (requiredQuery.length > 0) required.push(QUERY_GROUP);\n bindings.query = QUERY_GROUP;\n }\n if (body.kind === 'schema') {\n properties[BODY_GROUP] = body.schema;\n if (body.required) required.push(BODY_GROUP);\n bindings.body = BODY_GROUP;\n }\n\n return {\n supported: true,\n inputSchema: {\n type: 'object',\n properties,\n ...(required.length > 0 ? { required } : {}),\n additionalProperties: false,\n },\n inputBindings: bindings,\n ...(body.kind === 'schema' && body.contentType !== undefined\n ? { contentType: body.contentType }\n : {}),\n droppedKeywords: [...dropped],\n diagnostics,\n };\n}\n\n/**\n * Path Item parameters first, operation parameters second, with the OpenAPI\n * identity rule: a parameter is the same one when `name` *and* `in` match, and\n * the operation's own definition wins.\n */\nfunction mergeParameters(\n document: Record<string, unknown>,\n parameters: readonly unknown[],\n): Record<string, unknown>[] {\n const byIdentity = new Map<string, Record<string, unknown>>();\n for (const raw of parameters) {\n const resolved = dereference(document, raw).value;\n if (typeof resolved !== 'object' || resolved === null || Array.isArray(resolved)) continue;\n const parameter = resolved as Record<string, unknown>;\n byIdentity.set(`${String(parameter['in'])}:${String(parameter['name'])}`, parameter);\n }\n return [...byIdentity.values()];\n}\n\n/**\n * Whether the executor can actually send this parameter the way the API reads\n * it. It writes one `key=value` pair per query parameter and substitutes one\n * URL-encoded value per path segment, so anything that serialises to several\n * pairs or to a structured segment is out of scope for this release.\n */\nfunction describeUnsupportedParameter(\n document: Record<string, unknown>,\n parameter: Record<string, unknown>,\n location: 'path' | 'query',\n): string | undefined {\n if (parameter['content'] !== undefined) {\n return 'uses the `content` form, whose media-type serialization the gateway does not perform';\n }\n const style = parameter['style'];\n if (location === 'query' && typeof style === 'string' && UNSUPPORTED_QUERY_STYLES.has(style)) {\n return `uses style \"${style}\", which the gateway does not serialize`;\n }\n if (location === 'path' && typeof style === 'string' && style !== 'simple') {\n return `uses style \"${style}\"; the gateway substitutes plain values only`;\n }\n const converted = convertSchema(document, parameter['schema']);\n if (!converted.supported) return converted.reason;\n if (!isPrimitiveSchema(converted.schema)) {\n return 'is not a primitive; object and array parameters need serialization the gateway does not perform';\n }\n return undefined;\n}\n\ntype BodyResult =\n | { readonly kind: 'none' }\n | {\n readonly kind: 'schema';\n readonly schema: JsonSchema;\n readonly required: boolean;\n readonly contentType?: string;\n readonly dropped: readonly string[];\n }\n | { readonly kind: 'unsupported'; readonly required: boolean; readonly reason: string };\n\nfunction resolveBody(\n document: Record<string, unknown>,\n candidate: OpenApiOperationCandidate,\n): BodyResult {\n if (candidate.requestBody === undefined) return { kind: 'none' };\n const resolved = dereference(document, candidate.requestBody).value;\n if (typeof resolved !== 'object' || resolved === null || Array.isArray(resolved)) {\n return { kind: 'none' };\n }\n const requestBody = resolved as Record<string, unknown>;\n const required = requestBody['required'] === true;\n\n if (candidate.method === 'GET' || candidate.method === 'DELETE') {\n // The executor sends no body on these, and config refuses a body binding\n // for them. Silently generating one would produce a resource whose\n // payload never arrives.\n return {\n kind: 'unsupported',\n required: false,\n reason: `a ${candidate.method} request body is not sent by the gateway`,\n };\n }\n\n const content = requestBody['content'];\n if (!isRecord(content)) return { kind: 'none' };\n const mediaType = pickJsonMediaType(Object.keys(content));\n if (mediaType === undefined) {\n return {\n kind: 'unsupported',\n required,\n reason: `no JSON request body content type (found: ${Object.keys(content).join(', ') || 'none'}). Only application/json and application/*+json are supported - multipart and form data are never serialized as JSON`,\n };\n }\n const media = content[mediaType];\n const schemaNode = isRecord(media) ? media['schema'] : undefined;\n if (schemaNode === undefined) {\n // A body with no schema accepts anything; an open object is the honest\n // representation and the loader closes nothing it was not told to close.\n return {\n kind: 'schema',\n schema: { type: 'object', additionalProperties: true },\n required,\n ...(mediaType === 'application/json' ? {} : { contentType: mediaType }),\n dropped: [],\n };\n }\n const converted = convertSchema(document, schemaNode);\n if (!converted.supported) return { kind: 'unsupported', required, reason: converted.reason };\n return {\n kind: 'schema',\n schema: converted.schema,\n required,\n ...(mediaType === 'application/json' ? {} : { contentType: mediaType }),\n dropped: converted.dropped,\n };\n}\n\n/** Exact `application/json` wins; otherwise the first `+json` in sorted order. */\nexport function pickJsonMediaType(keys: readonly string[]): string | undefined {\n const normalised = keys.map((key) => ({ key, type: key.split(';')[0]?.trim().toLowerCase() }));\n const exact = normalised.find((entry) => entry.type === 'application/json');\n if (exact !== undefined) return exact.key;\n return [...normalised]\n .sort((a, b) => (a.type ?? '').localeCompare(b.type ?? ''))\n .find((entry) => entry.type?.startsWith('application/') && entry.type.endsWith('+json'))?.key;\n}\n\nfunction closedObject(\n properties: Record<string, unknown>,\n required: readonly string[],\n): JsonSchema {\n return {\n type: 'object',\n properties,\n ...(required.length > 0 ? { required: [...required] } : {}),\n additionalProperties: false,\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","/**\n * OpenAPI schema -> the JSON Schema subset this gateway actually enforces.\n *\n * The honesty rule drives every decision here. `src/core`'s validator enforces\n * `type`/`properties`/`required`/`additionalProperties`/`enum`/`items` and\n * silently ignores everything else, so copying a `pattern` or a `oneOf` into a\n * generated resource would advertise validation to agents that no code\n * performs - and on a paid resource, the request the merchant's backend\n * receives is the one the buyer already paid for. Unenforceable constraints\n * are therefore dropped from the generated schema and reported, never\n * carried along quietly.\n */\nimport type { JsonSchema } from '../core/domain/common.js';\nimport { isCommerceError } from '../core/errors/index.js';\nimport { dereference } from './refs.js';\n\n/** Enforced by `compileJsonSchema`. Everything else is documentation at best. */\nconst SUPPORTED_TYPES = new Set([\n 'object',\n 'string',\n 'number',\n 'integer',\n 'boolean',\n 'array',\n 'null',\n]);\n\n/** Copied through: descriptive, never a constraint, so it cannot overstate. */\nconst METADATA_KEYWORDS = ['title', 'description', 'default', 'example', 'examples', 'deprecated'];\n\n/**\n * Annotations, not constraints: dropping them changes nothing a caller could\n * observe, so they are not worth telling the operator about. Reporting them\n * would bury the keywords that *do* matter (`pattern`, `minimum`, `format`)\n * in noise, which is how a real warning gets ignored.\n */\nconst ANNOTATION_KEYWORDS = new Set([\n 'xml',\n 'externalDocs',\n 'readOnly',\n 'writeOnly',\n '$schema',\n '$id',\n '$comment',\n '$defs',\n 'definitions',\n]);\n\nexport type SchemaConversion =\n | {\n readonly supported: true;\n readonly schema: JsonSchema;\n /** Keyword names encountered and dropped, deduplicated, in first-seen order. */\n readonly dropped: readonly string[];\n }\n | { readonly supported: false; readonly reason: string };\n\n/** Types a path or query parameter may have: the executor stringifies one value. */\nexport function isPrimitiveSchema(schema: JsonSchema): boolean {\n const types = typeList(schema['type']);\n if (types === undefined) return false;\n return types.every((type) => type !== 'object' && type !== 'array' && SUPPORTED_TYPES.has(type));\n}\n\nexport function convertSchema(\n document: Record<string, unknown>,\n node: unknown,\n stack: readonly string[] = [],\n): SchemaConversion {\n const dropped = new Set<string>();\n try {\n const schema = convertNode(document, node, stack, dropped);\n return schema === undefined\n ? { supported: false, reason: 'schema could not be represented' }\n : { supported: true, schema, dropped: [...dropped] };\n } catch (error) {\n if (error instanceof UnsupportedSchema) return { supported: false, reason: error.message };\n // A reference cycle or a dangling pointer arrives as CONFIG_INVALID from\n // the resolver. For a *schema* that is a skip-this-operation condition,\n // not a fail-the-whole-import one: the rest of the document is fine.\n if (isCommerceError(error)) return { supported: false, reason: error.message };\n throw error;\n }\n}\n\nclass UnsupportedSchema extends Error {}\n\nfunction convertNode(\n document: Record<string, unknown>,\n node: unknown,\n stack: readonly string[],\n dropped: Set<string>,\n): JsonSchema | undefined {\n // OpenAPI 3.1 allows boolean schemas: `true` accepts anything, `false`\n // accepts nothing - and nothing is not a request shape we can generate.\n if (node === true) return {};\n if (node === false) throw new UnsupportedSchema('schema is `false`, which accepts no value');\n\n const resolved = dereference(document, node, stack);\n const source = resolved.value;\n if (typeof source !== 'object' || source === null || Array.isArray(source)) {\n throw new UnsupportedSchema('schema node is not an object');\n }\n const schemaNode = source as Record<string, unknown>;\n\n if (Array.isArray(schemaNode['allOf'])) {\n return mergeAllOf(document, schemaNode, resolved.stack, dropped);\n }\n for (const keyword of ['oneOf', 'anyOf', 'not', 'discriminator']) {\n if (Object.hasOwn(schemaNode, keyword)) {\n throw new UnsupportedSchema(\n `schema uses \"${keyword}\", which this gateway cannot enforce - accepting it would advertise validation that never runs`,\n );\n }\n }\n\n const result: Record<string, unknown> = {};\n const types = resolveTypes(schemaNode);\n if (types !== undefined) result['type'] = types.length === 1 ? types[0] : types;\n\n for (const keyword of METADATA_KEYWORDS) {\n if (Object.hasOwn(schemaNode, keyword)) result[keyword] = schemaNode[keyword];\n }\n if (Array.isArray(schemaNode['enum'])) result['enum'] = [...schemaNode['enum']];\n\n const properties = schemaNode['properties'];\n if (isRecord(properties)) {\n const converted: Record<string, unknown> = {};\n for (const [name, sub] of Object.entries(properties)) {\n const child = convertNode(document, sub, resolved.stack, dropped);\n if (child !== undefined) converted[name] = child;\n }\n result['properties'] = converted;\n }\n\n // Independent of `properties`: `required` without them is legal, and core's\n // validator enforces it, so dropping it here would be a silent weakening.\n // Emitted here so every generated object schema orders its keys the same\n // way - the output is meant to be reviewed in a diff.\n const required = schemaNode['required'];\n if (Array.isArray(required)) {\n const names = required.filter((name): name is string => typeof name === 'string');\n if (names.length > 0) result['required'] = names;\n }\n\n const additional = schemaNode['additionalProperties'];\n if (typeof additional === 'boolean') {\n result['additionalProperties'] = additional;\n } else if (additional !== undefined) {\n const child = convertNode(document, additional, resolved.stack, dropped);\n if (child !== undefined) result['additionalProperties'] = child;\n } else if (isRecord(properties)) {\n result['additionalProperties'] = false;\n }\n\n const items = schemaNode['items'];\n if (Array.isArray(items)) {\n // Tuple `items` is not enforced; keeping it would look like it was.\n dropped.add('items (tuple form)');\n } else if (items !== undefined) {\n const child = convertNode(document, items, resolved.stack, dropped);\n if (child !== undefined) result['items'] = child;\n }\n\n for (const keyword of Object.keys(schemaNode)) {\n if (isCarriedKeyword(keyword) || ANNOTATION_KEYWORDS.has(keyword) || keyword.startsWith('x-')) {\n continue;\n }\n dropped.add(keyword);\n }\n\n return result;\n}\n\nfunction isCarriedKeyword(keyword: string): boolean {\n return (\n keyword === 'type' ||\n keyword === 'properties' ||\n keyword === 'required' ||\n keyword === 'additionalProperties' ||\n keyword === 'enum' ||\n keyword === 'items' ||\n keyword === 'nullable' ||\n keyword === '$ref' ||\n METADATA_KEYWORDS.includes(keyword)\n );\n}\n\n/**\n * OpenAPI 3.0's `nullable: true` becomes draft-2020-12's union type, which is\n * what the runtime validator understands. 3.1 already writes it that way.\n */\nfunction resolveTypes(schema: Record<string, unknown>): string[] | undefined {\n const declared = typeList(schema['type']);\n if (declared === undefined) return undefined;\n const known = declared.filter((type) => SUPPORTED_TYPES.has(type));\n if (known.length === 0) {\n throw new UnsupportedSchema(`schema type \"${String(schema['type'])}\" is not a JSON type`);\n }\n if (schema['nullable'] === true && !known.includes('null')) known.push('null');\n return known;\n}\n\nfunction typeList(raw: unknown): string[] | undefined {\n if (typeof raw === 'string') return [raw];\n if (Array.isArray(raw) && raw.every((entry) => typeof entry === 'string')) {\n return raw as string[];\n }\n return undefined;\n}\n\n/**\n * A simple `allOf` of object schemas is merged; anything else is refused.\n *\n * Merging is only safe while the branches agree - two branches declaring the\n * same property differently have a meaning (\"both must hold\") that this\n * validator cannot express, and picking one would quietly accept requests the\n * API rejects, or reject ones it accepts.\n */\nfunction mergeAllOf(\n document: Record<string, unknown>,\n schema: Record<string, unknown>,\n stack: readonly string[],\n dropped: Set<string>,\n): JsonSchema {\n const branches = schema['allOf'] as readonly unknown[];\n const siblings = { ...schema };\n delete siblings['allOf'];\n\n const merged: Record<string, unknown> = { type: 'object', properties: {}, required: [] };\n const properties = merged['properties'] as Record<string, unknown>;\n const required = new Set<string>();\n\n const parts = [...branches, ...(Object.keys(siblings).length > 0 ? [siblings] : [])];\n for (const branch of parts) {\n const converted = convertNode(document, branch, stack, dropped);\n if (converted === undefined) throw new UnsupportedSchema('allOf branch is empty');\n const types = typeList(converted['type']);\n if (types !== undefined && !types.includes('object')) {\n throw new UnsupportedSchema('allOf mixes object and non-object schemas');\n }\n const branchProperties = converted['properties'];\n if (isRecord(branchProperties)) {\n for (const [name, sub] of Object.entries(branchProperties)) {\n const existing = properties[name];\n if (existing !== undefined && JSON.stringify(existing) !== JSON.stringify(sub)) {\n throw new UnsupportedSchema(\n `allOf branches declare property \"${name}\" differently, which cannot be merged`,\n );\n }\n properties[name] = sub;\n }\n }\n for (const name of Array.isArray(converted['required']) ? converted['required'] : []) {\n if (typeof name === 'string') required.add(name);\n }\n for (const keyword of ['enum', 'items']) {\n if (Object.hasOwn(converted, keyword)) {\n throw new UnsupportedSchema(`allOf branch uses \"${keyword}\", which cannot be merged`);\n }\n }\n if (typeof converted['description'] === 'string' && merged['description'] === undefined) {\n merged['description'] = converted['description'];\n }\n }\n\n if (required.size > 0) merged['required'] = [...required];\n else delete merged['required'];\n merged['additionalProperties'] = false;\n return merged;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","/**\n * Operation candidates -> Agent Commerce resource drafts.\n *\n * A draft describes the *API shape* and nothing else. Pricing, exposure and\n * payment methods are commerce policy: an OpenAPI document has no opinion on\n * whether an operation should cost money or be visible to agents, so guessing\n * one would put a merchant's endpoint on an agent network - or give it away\n * free - on the strength of a file that never mentioned either. Without\n * explicit CLI policy the generated file is deliberately incomplete: it will\n * not load until a human fills those fields in.\n */\nimport { Document, type Node, type Pair, type YAMLMap } from 'yaml';\nimport type { JsonSchema } from '../core/domain/common.js';\nimport { discoverOperations } from './discover.js';\nimport { mapRequest, pickJsonMediaType } from './request.js';\nimport { convertSchema } from './schema.js';\nimport type {\n ImportDiagnostic,\n LoadedOpenApiDocument,\n OpenApiOperationCandidate,\n OpenApiVersion,\n} from './types.js';\n\n/** Commerce policy the operator supplied explicitly. Never inferred. */\nexport interface ImportPolicy {\n readonly pricing?: Record<string, unknown>;\n readonly expose?: readonly string[];\n readonly payments?: readonly string[];\n}\n\nexport interface ImportOptions {\n readonly baseUrl?: string;\n readonly policy?: ImportPolicy;\n /** `--operation` / `--tag`. Applied before mapping, so unselected operations produce no noise. */\n readonly include?: {\n readonly operationIds?: readonly string[];\n /** Multiple tags are OR-ed. */\n readonly tags?: readonly string[];\n };\n}\n\nexport interface ResourceDraft {\n readonly id: string;\n readonly operationId?: string;\n readonly tags: readonly string[];\n /** `METHOD /path`, for the console summary. */\n readonly source: string;\n /** YAML-ready, in the field order it will be written in. */\n readonly resource: Record<string, unknown>;\n /** Comment lines written above this resource. */\n readonly review: readonly string[];\n}\n\nexport interface ImportResult {\n readonly version: OpenApiVersion;\n readonly sourcePath: string;\n readonly drafts: readonly ResourceDraft[];\n readonly diagnostics: readonly ImportDiagnostic[];\n /** `--operation` values that matched nothing. The CLI exits non-zero on these. */\n readonly unmatchedOperationIds: readonly string[];\n}\n\nexport function buildResourceDrafts(\n loaded: LoadedOpenApiDocument,\n options: ImportOptions = {},\n): ImportResult {\n const discovery = discoverOperations(\n loaded,\n options.baseUrl !== undefined ? { baseUrl: options.baseUrl } : {},\n );\n const diagnostics: ImportDiagnostic[] = [...discovery.diagnostics];\n const drafts: ResourceDraft[] = [];\n\n const wanted = options.include?.operationIds;\n const wantedTags = options.include?.tags;\n const matched = new Set<string>();\n\n for (const candidate of discovery.operations) {\n if (wanted !== undefined && !selects(wanted, candidate)) continue;\n if (wantedTags !== undefined && !candidate.tags.some((tag) => wantedTags.includes(tag))) {\n continue;\n }\n if (wanted !== undefined) {\n for (const id of wanted) if (selects([id], candidate)) matched.add(id);\n }\n\n const mapping = mapRequest(loaded, candidate);\n diagnostics.push(...mapping.diagnostics);\n if (!mapping.supported) continue;\n\n const dropped = new Set(mapping.droppedKeywords);\n const output = selectOutputSchema(loaded.document, candidate, diagnostics, dropped);\n if (dropped.size > 0) {\n diagnostics.push({\n severity: 'warning',\n code: 'unenforced-schema-constraints',\n operation: candidate.resourceId,\n message: `${candidate.resourceId}: dropped ${[...dropped].join(', ')} - this gateway validates structure only, and keeping them would advertise checks it never performs`,\n });\n }\n\n const review: string[] = [];\n if (declaresSecurity(candidate)) {\n diagnostics.push({\n severity: 'warning',\n code: 'backend-authentication-required',\n operation: candidate.resourceId,\n message: `${candidate.resourceId} declares backend authentication. OpenAPI credentials were not imported. Configure backend.headers with environment placeholders before enabling the resource`,\n });\n review.push(\n 'This operation declares backend authentication. No credential was imported.',\n 'Add it under backend.headers with an ${ENV_VAR} placeholder before enabling.',\n );\n }\n if (options.policy?.pricing === undefined || options.policy.expose === undefined) {\n review.push(\n 'REVIEW: pricing and exposure are not inferred from OpenAPI. Add e.g.',\n ' pricing: { type: free } # or { type: fixed, amount: \"0.01\", currency: USDC }',\n ' expose: [http] # http | mcp | a2a',\n );\n }\n\n drafts.push({\n id: candidate.resourceId,\n ...(candidate.operationId !== undefined ? { operationId: candidate.operationId } : {}),\n tags: candidate.tags,\n source: `${candidate.method} ${candidate.path}`,\n resource: {\n name: candidate.name,\n ...(candidate.description !== undefined ? { description: candidate.description } : {}),\n input: mapping.inputSchema,\n ...(output !== undefined ? { output } : {}),\n backend: {\n type: 'http',\n method: candidate.method,\n url: candidate.backendUrl,\n ...(mapping.contentType !== undefined\n ? { headers: { 'Content-Type': mapping.contentType } }\n : {}),\n ...(Object.keys(mapping.inputBindings).length > 0\n ? { inputBindings: mapping.inputBindings }\n : {}),\n },\n // Policy is written only when the operator asked for it. An absent\n // `pricing`/`expose` is what makes the draft fail config validation\n // until a human has decided.\n ...(options.policy?.pricing !== undefined ? { pricing: options.policy.pricing } : {}),\n ...(options.policy?.expose !== undefined ? { expose: [...options.policy.expose] } : {}),\n ...(options.policy?.payments !== undefined\n ? { payments: [...options.policy.payments] }\n : {}),\n },\n review,\n });\n }\n\n return {\n version: loaded.version,\n sourcePath: loaded.sourcePath,\n drafts,\n diagnostics,\n unmatchedOperationIds: (wanted ?? []).filter((id) => !matched.has(id)),\n };\n}\n\n/** `--operation` accepts the OpenAPI operationId or the generated resource id. */\nfunction selects(ids: readonly string[], candidate: OpenApiOperationCandidate): boolean {\n return (\n ids.includes(candidate.resourceId) ||\n (candidate.operationId !== undefined && ids.includes(candidate.operationId))\n );\n}\n\n/** `security: []` means \"explicitly none\"; `[{}]` means optional. Neither needs a credential. */\nfunction declaresSecurity(candidate: OpenApiOperationCandidate): boolean {\n return candidate.security.some(\n (requirement) =>\n typeof requirement === 'object' &&\n requirement !== null &&\n Object.keys(requirement).length > 0,\n );\n}\n\n/**\n * One success response, chosen the same way every run: 200, then 201, then\n * 202, then the remaining explicit 2xx in ascending order. Status-dependent\n * unions are out of scope, so when several 2xx carry materially different\n * schemas the operator is told which one was taken rather than left to\n * discover it from the diff.\n */\nfunction selectOutputSchema(\n document: Record<string, unknown>,\n candidate: OpenApiOperationCandidate,\n diagnostics: ImportDiagnostic[],\n dropped: Set<string>,\n): JsonSchema | undefined {\n const responses = candidate.responses;\n if (!isRecord(responses)) return undefined;\n\n const successes = Object.keys(responses)\n .filter((status) => /^2\\d\\d$/.test(status))\n .sort((a, b) => rank(a) - rank(b));\n if (successes.length === 0) return undefined;\n\n const withBody = successes.filter((status) => {\n const response = responses[status];\n const content = isRecord(response) ? response['content'] : undefined;\n return isRecord(content) && pickJsonMediaType(Object.keys(content)) !== undefined;\n });\n const chosen = withBody[0];\n if (chosen === undefined) return undefined; // 204, or no JSON representation\n\n const response = responses[chosen] as Record<string, unknown>;\n const content = response['content'] as Record<string, unknown>;\n const mediaType = pickJsonMediaType(Object.keys(content)) as string;\n const media = content[mediaType];\n const schemaNode = isRecord(media) ? media['schema'] : undefined;\n if (schemaNode === undefined) return undefined;\n\n const converted = convertSchema(document, schemaNode);\n if (!converted.supported) {\n // Output schema is descriptive: omitting it costs discovery detail, not\n // request safety, so it never skips the operation.\n diagnostics.push({\n severity: 'warning',\n code: 'unsupported-output-schema',\n operation: candidate.resourceId,\n message: `${candidate.resourceId}: omitted the output schema (${converted.reason})`,\n });\n return undefined;\n }\n for (const keyword of converted.dropped) dropped.add(keyword);\n\n if (withBody.length > 1) {\n diagnostics.push({\n severity: 'warning',\n code: 'multiple-success-responses',\n operation: candidate.resourceId,\n message: `${candidate.resourceId}: responses ${withBody.join(', ')} all carry a JSON body; used ${chosen}`,\n });\n }\n return converted.schema;\n}\n\nfunction rank(status: string): number {\n const preferred = ['200', '201', '202'].indexOf(status);\n return preferred === -1 ? 100 + Number(status) : preferred;\n}\n\n/**\n * Renders the drafts as a config fragment: the same `resources:` shape\n * `config.yaml` uses, so a reviewed block can be moved across whole.\n */\nexport function renderResourcesYaml(result: ImportResult): string {\n const resources: Record<string, unknown> = {};\n for (const draft of result.drafts) resources[draft.id] = draft.resource;\n\n const doc = new Document({ resources });\n doc.commentBefore = [\n ' Generated by agent-commerce import openapi. Review before use.',\n ` Source: ${basename(result.sourcePath)} (OpenAPI ${result.version})`,\n ' Merge the resources below into config.yaml once pricing, exposure and',\n ' any backend authentication have been decided.',\n ].join('\\n');\n\n // Comments hang off the key node; a Pair has nowhere to put one. Map items\n // are in insertion order, which is draft order.\n const map = doc.getIn(['resources'], true) as YAMLMap | undefined;\n map?.items.forEach((item, index) => {\n const draft = result.drafts[index];\n const key = (item as Pair<Node, unknown>).key;\n if (draft === undefined || draft.review.length === 0 || key === null) return;\n key.commentBefore = draft.review.map((line) => ` ${line}`).join('\\n');\n });\n\n // lineWidth 0 disables folding: a wrapped description would otherwise\n // re-flow whenever an unrelated word changed, and the generated file is\n // meant to be reviewed in a diff.\n return doc.toString({ lineWidth: 0 });\n}\n\nfunction basename(path: string): string {\n return path.split(/[\\\\/]/).pop() ?? path;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","/**\n * Reads and validates a local OpenAPI description.\n *\n * Offline by construction: the document is parsed here, every `$ref` is\n * checked to be internal *before* the validator ever sees the document, and no\n * URL-fetching plugin is passed to it. The importer must not turn \"point it at\n * your API description\" into \"the gateway machine makes outbound requests to\n * whatever the file names\".\n */\nimport { readFile, stat } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { validate } from '@scalar/openapi-parser';\nimport { parse as parseYaml } from 'yaml';\nimport { CommerceError } from '../core/errors/index.js';\nimport type { LoadedOpenApiDocument, OpenApiVersion } from './types.js';\n\n/** Generous for a hand-written description; small enough that a stray file is refused. */\nexport const MAX_SOURCE_BYTES = 10 * 1024 * 1024;\n\nconst SUPPORTED_EXTENSIONS = new Set(['.yaml', '.yml', '.json']);\nconst SUPPORTED_VERSIONS: ReadonlySet<string> = new Set(['3.0', '3.1', '3.2']);\n\nfunction invalid(\n message: string,\n details: Record<string, unknown>,\n cause?: unknown,\n): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, {\n details,\n ...(cause !== undefined ? { cause } : {}),\n });\n}\n\nexport async function loadOpenApiDocument(sourcePath: string): Promise<LoadedOpenApiDocument> {\n const details = { sourcePath };\n\n let stats: Awaited<ReturnType<typeof stat>>;\n try {\n stats = await stat(sourcePath);\n } catch (error) {\n throw invalid(`OpenAPI document \"${sourcePath}\" could not be read`, details, error);\n }\n if (stats.isDirectory()) {\n throw invalid(`\"${sourcePath}\" is a directory, not an OpenAPI document`, details);\n }\n if (stats.size > MAX_SOURCE_BYTES) {\n throw invalid(\n `OpenAPI document \"${sourcePath}\" is ${stats.size} bytes, over the ${MAX_SOURCE_BYTES}-byte limit`,\n { ...details, size: stats.size, maxBytes: MAX_SOURCE_BYTES },\n );\n }\n\n const extension = extname(sourcePath).toLowerCase();\n if (!SUPPORTED_EXTENSIONS.has(extension)) {\n throw invalid(\n `OpenAPI document \"${sourcePath}\" has an unsupported extension \"${extension || '(none)'}\". Supported: .yaml, .yml, .json`,\n details,\n );\n }\n\n const source = await readFile(sourcePath, 'utf8');\n if (source.trim() === '') {\n throw invalid(`OpenAPI document \"${sourcePath}\" is empty`, details);\n }\n\n let parsed: unknown;\n try {\n // YAML is a superset of JSON, but JSON.parse gives the better message for a\n // file that claims to be JSON, and refuses YAML that a .json file should\n // not contain.\n parsed = extension === '.json' ? JSON.parse(source) : parseYaml(source);\n } catch (error) {\n throw invalid(\n `OpenAPI document \"${sourcePath}\" is not valid ${extension === '.json' ? 'JSON' : 'YAML'}: ${error instanceof Error ? error.message : String(error)}`,\n details,\n error,\n );\n }\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw invalid(`OpenAPI document \"${sourcePath}\" is not an object`, details);\n }\n const document = parsed as Record<string, unknown>;\n\n const version = readVersion(document, sourcePath);\n // Before validation, not after: the validator resolves references, and the\n // no-network guarantee is only worth something if nothing external ever\n // reaches it.\n rejectExternalReferences(document, sourcePath);\n\n const result = await validate(document);\n if (!result.valid) {\n const first = result.errors?.[0];\n throw invalid(\n `OpenAPI document \"${sourcePath}\" is not a valid OpenAPI ${version} description: ${first ? `${first.message}${first.path ? ` (at ${first.path})` : ''}` : 'unknown validation error'}`,\n { ...details, errors: result.errors?.slice(0, 10) ?? [] },\n );\n }\n\n return { version, document, sourcePath };\n}\n\n/**\n * The `openapi` field decides, not the validator's own verdict: the validator\n * happily calls a Swagger 2.0 document valid, and importing one would mean\n * `host`/`basePath`/`schemes` and body-parameter conversion semantics that\n * nothing downstream understands. Refuse it by name so the operator is told to\n * convert rather than left guessing.\n */\nfunction readVersion(document: Record<string, unknown>, sourcePath: string): OpenApiVersion {\n const details = { sourcePath };\n if (typeof document['swagger'] === 'string') {\n throw invalid(\n `\"${sourcePath}\" is a Swagger ${document['swagger']} document. Only OpenAPI 3.0, 3.1 and 3.2 are supported - convert it first`,\n details,\n );\n }\n const declared = document['openapi'];\n if (typeof declared !== 'string') {\n throw invalid(`\"${sourcePath}\" has no \"openapi\" version field`, details);\n }\n const featureVersion = /^(\\d+\\.\\d+)(?:\\.|$)/.exec(declared)?.[1];\n if (featureVersion === undefined || !SUPPORTED_VERSIONS.has(featureVersion)) {\n throw invalid(\n `OpenAPI version \"${declared}\" is not supported. Supported: 3.0.x, 3.1.x, 3.2.x`,\n { ...details, version: declared },\n );\n }\n return featureVersion as OpenApiVersion;\n}\n\n/**\n * An external `$ref` is refused rather than fetched or read from disk. Both\n * would be the importer acting on behalf of a document it was merely asked to\n * read - one as an outbound request from wherever the CLI runs, the other as a\n * filesystem read outside the source file. Multi-file descriptions are a later\n * feature; until then, saying so beats a silent partial import.\n */\nfunction rejectExternalReferences(document: Record<string, unknown>, sourcePath: string): void {\n // Iterative with a seen set: YAML aliases can make the parsed graph cyclic,\n // and a deeply nested document would otherwise blow the call stack.\n const seen = new WeakSet<object>();\n const queue: unknown[] = [document];\n while (queue.length > 0) {\n const node = queue.pop();\n if (typeof node !== 'object' || node === null) continue;\n if (seen.has(node)) continue;\n seen.add(node);\n if (Array.isArray(node)) {\n queue.push(...node);\n continue;\n }\n for (const [key, value] of Object.entries(node)) {\n if (key === '$ref' && typeof value === 'string' && !value.startsWith('#')) {\n throw invalid(\n `OpenAPI document \"${sourcePath}\" contains an external reference \"${value}\". Only internal references (#/...) are supported; the importer performs no network or filesystem lookups`,\n { sourcePath, ref: value },\n );\n }\n queue.push(value);\n }\n }\n}\n","import { existsSync, mkdirSync } from 'node:fs';\nimport { writeFile } from 'node:fs/promises';\nimport { dirname, resolve } from 'node:path';\nimport * as clack from '@clack/prompts';\nimport { DEFAULT_CONFIG_FILENAME } from '../../config/filename.js';\nimport {\n type ConfigLoader,\n type ConfigParser,\n type GatewayConfig,\n loadConfigDynamic,\n parseConfigDynamic,\n} from '../lib/config-client.js';\nimport {\n buildInitConfigObject,\n defaultInitAnswers,\n type InitAnswers,\n type InitProtocolChoice,\n type InitResourceChoice,\n renderInitConfigYaml,\n} from '../lib/init-config.js';\nimport type { Io } from '../lib/io.js';\nimport { formatConfigError } from './validate.js';\n\nexport interface InitOptions {\n readonly outputPath?: string;\n readonly force?: boolean;\n readonly yes?: boolean;\n}\n\nexport interface InitDeps {\n readonly loadConfig?: ConfigLoader;\n readonly parseConfig?: ConfigParser;\n readonly collectAnswers?: () => Promise<InitAnswers | undefined>;\n readonly fileExists?: (path: string) => boolean;\n readonly writeFile?: (path: string, content: string) => Promise<void>;\n}\n\n/** Exported for testing: the real interactive prompt flow (mocks `@clack/prompts`). */\nexport async function collectAnswersInteractive(): Promise<InitAnswers | undefined> {\n clack.intro('agent-commerce init');\n\n const backendBaseUrl = await clack.text({\n message: 'Backend base URL (your existing merchant API)',\n initialValue: 'http://localhost:3000',\n // shape-checked here, where the user can retype it,\n // rather than surfacing as a config error after the fact.\n validate: (value) => {\n const trimmed = (value ?? '').trim();\n if (trimmed.length === 0) return 'Required';\n let parsed: URL;\n try {\n parsed = new URL(trimmed);\n } catch {\n return 'Must be an absolute URL, e.g. http://localhost:3000';\n }\n return parsed.protocol === 'http:' || parsed.protocol === 'https:'\n ? undefined\n : 'Must use http:// or https://';\n },\n });\n if (clack.isCancel(backendBaseUrl)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const resources = await clack.multiselect<InitResourceChoice>({\n message: 'Which example resource(s) do you want to expose?',\n options: [\n { value: 'weather', label: 'Weather (free)' },\n { value: 'report', label: 'Market report (paid)' },\n ],\n initialValues: ['weather', 'report'],\n required: false,\n });\n if (clack.isCancel(resources)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const protocols = await clack.multiselect<InitProtocolChoice>({\n message: 'Which protocols should be enabled?',\n options: [\n { value: 'http', label: 'HTTP' },\n { value: 'mcp', label: 'MCP' },\n ],\n initialValues: ['http', 'mcp'],\n // `required: false` permits an empty selection, which renders\n // `expose: []` on every resource and fails the schema's min(1). clack's\n // multiselect has no `validate` hook, so this is caught by the in-memory\n // validation in `runInit` — which now reports the real schema error and\n // writes nothing, instead of leaving an invalid file behind.\n required: false,\n });\n if (clack.isCancel(protocols)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n const x402Enabled = await clack.confirm({ message: 'Enable x402 payments?', initialValue: true });\n if (clack.isCancel(x402Enabled)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n\n let merchantPayTo = defaultInitAnswers().merchantPayTo;\n if (x402Enabled) {\n const answer = await clack.text({\n message:\n 'Merchant settlement destination address (merchant-controlled — never a gateway-owned wallet)',\n initialValue: merchantPayTo,\n validate: (value) => {\n const trimmed = (value ?? '').trim();\n if (trimmed.length === 0) return 'Required';\n // Same shape the config schema enforces; catching it here means a\n // typo'd address never reaches the \"generated config is invalid\" path.\n return /^0x[0-9a-fA-F]{40}$/.test(trimmed)\n ? undefined\n : 'Must be a 0x-prefixed 20-byte EVM address (42 characters)';\n },\n });\n if (clack.isCancel(answer)) {\n clack.cancel('Aborted.');\n return undefined;\n }\n merchantPayTo = answer;\n }\n\n clack.outro('Configuration answers collected.');\n\n return { backendBaseUrl, resources, protocols, x402Enabled, merchantPayTo };\n}\n\n/** `agent-commerce init [--yes] [--force] [--output <path>]`. */\nexport async function runInit(options: InitOptions, io: Io, deps: InitDeps = {}): Promise<number> {\n const outputPath = options.outputPath ?? DEFAULT_CONFIG_FILENAME;\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const parseConfigInMemory = deps.parseConfig ?? parseConfigDynamic;\n const fileExists = deps.fileExists ?? existsSync;\n const writeFileImpl =\n deps.writeFile ??\n (async (path: string, content: string) => {\n await writeFile(path, content, 'utf8');\n });\n\n if (fileExists(outputPath) && options.force !== true) {\n io.stderr(`FAIL ${outputPath} already exists. Re-run with --force to overwrite.`);\n return 1;\n }\n\n const answers =\n options.yes === true\n ? defaultInitAnswers()\n : await (deps.collectAnswers ?? collectAnswersInteractive)();\n\n if (answers === undefined) {\n io.stderr('FAIL init aborted, nothing was written.');\n return 1;\n }\n\n // Validate BEFORE writing. Interactive answers can legitimately fail\n // validation — an empty protocol multiselect, a typo'd settlement address,\n // a scheme-less backend URL — and writing first would print \"PASS Wrote …\"\n // and then blame the tool: \"please report this as a bug\". Nothing is\n // written unless it is valid, and the message is the real configuration\n // error, which names the field the user can fix.\n let config: GatewayConfig;\n try {\n config = await parseConfigInMemory(buildInitConfigObject(answers));\n } catch (err) {\n io.stderr(formatConfigError(err));\n io.stderr(`FAIL Nothing was written to ${outputPath}.`);\n return 1;\n }\n\n const yamlContent = renderInitConfigYaml(answers);\n const resolvedPath = resolve(outputPath);\n const dir = dirname(resolvedPath);\n if (dir !== '' && !existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n await writeFileImpl(outputPath, yamlContent);\n io.stdout(`PASS Wrote ${outputPath}`);\n io.stdout(`PASS ${outputPath} is valid — ${config.resources.length} resource(s)`);\n\n // The YAML is rendered from the very object just validated, but it is\n // rendered, not serialised from it — so read it back and confirm the two\n // agree. A renderer bug is the one failure the in-memory check cannot see,\n // and it IS a bug worth reporting.\n try {\n await loadConfig({ path: outputPath });\n } catch (err) {\n io.stderr(formatConfigError(err));\n io.stderr(\n `FAIL ${outputPath} was written but does not parse, although the same answers validated in memory — this is a bug in the config renderer, please report it.`,\n );\n return 1;\n }\n\n io.stdout('');\n io.stdout('Next steps:');\n io.stdout(` agent-commerce validate --config ${outputPath}`);\n // Only commands the reader can actually run. `npm run dev:merchant` and\n // `npm run dev:gateway` exist solely inside the development repo, and this\n // CLI ships to npm — telling an installed user to run them is a dead end.\n io.stdout(' docker compose up # start the local demo stack (from a repo clone)');\n io.stdout(` agent-commerce doctor --config ${outputPath}`);\n\n return 0;\n}\n","import { ZodError } from 'zod';\nimport { isCommerceError } from '../../core/index.js';\nimport { type ConfigLoader, loadConfigDynamic } from '../lib/config-client.js';\nimport type { Io } from '../lib/io.js';\nimport {\n fillEnvFromLocalChainManifest,\n LOCAL_CHAIN_MANIFEST_PATH,\n MANIFEST_FILLABLE_ENV_VAR_NAMES,\n type ManifestEnvFill,\n} from '../lib/manifest-env.js';\n\nexport interface ValidateOptions {\n readonly configPath?: string;\n}\n\nexport interface ValidateDeps {\n readonly loadConfig?: ConfigLoader;\n readonly fillEnvFromManifest?: (env: NodeJS.ProcessEnv) => ManifestEnvFill;\n}\n\n/**\n * Formats a config-loading failure into an actionable report.\n *\n * Handles the three error shapes `src/config` can produce:\n * a `CommerceError('CONFIG_INVALID', …)` with structured details, a raw\n * `ZodError` (schema errors, one line per failing path), or a plain Error\n * (e.g. a YAML syntax error, or the \"config package not available yet\"\n * integration-gap error). Never prints a resolved `${ENV}` value — only ever\n * the variable name, which the underlying error message is expected to carry.\n *\n * `manifestFound` adds one more hint line when the failure is specifically an\n * unresolved variable that `.deploy/local.json` would have supplied, had\n * `npm run chain:deploy` been run — see `../lib/manifest-env.js`.\n */\nexport function formatConfigError(err: unknown, manifestFound = false): string {\n if (isCommerceError(err)) {\n const lines = [`FAIL ${err.code}: ${err.message}`];\n if (err.details !== undefined) {\n lines.push(` details: ${JSON.stringify(err.details)}`);\n }\n const variable = err.details?.['variable'];\n if (\n !manifestFound &&\n typeof variable === 'string' &&\n MANIFEST_FILLABLE_ENV_VAR_NAMES.has(variable)\n ) {\n lines.push(\n ` hint: \"npm run chain:deploy\" writes ${LOCAL_CHAIN_MANIFEST_PATH}, which validate/doctor read automatically to fill local X402_*/MERCHANT_WALLET placeholders.`,\n );\n }\n return lines.join('\\n');\n }\n if (err instanceof ZodError) {\n const lines = ['FAIL Configuration schema errors:'];\n for (const issue of err.issues) {\n const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';\n lines.push(` - ${path}: ${issue.message}`);\n }\n return lines.join('\\n');\n }\n if (err instanceof Error) {\n return `FAIL ${err.message}`;\n }\n return `FAIL ${String(err)}`;\n}\n\n/** `agent-commerce validate [--config <path>]`. Exit code is non-zero on invalid configuration. */\nexport async function runValidate(\n options: ValidateOptions,\n io: Io,\n deps: ValidateDeps = {},\n): Promise<number> {\n const loadConfig = deps.loadConfig ?? loadConfigDynamic;\n const fillEnvFromManifest = deps.fillEnvFromManifest ?? fillEnvFromLocalChainManifest;\n const { env, filled, manifestFound } = fillEnvFromManifest(process.env);\n if (filled.length > 0) {\n io.stdout(`using local chain manifest ${LOCAL_CHAIN_MANIFEST_PATH} for ${filled.join(', ')}`);\n }\n try {\n const config = await loadConfig({\n ...(options.configPath !== undefined ? { path: options.configPath } : {}),\n env,\n });\n io.stdout('PASS Configuration is valid');\n io.stdout(` merchant: ${config.merchant.name} (${config.merchant.id})`);\n io.stdout(` resources: ${config.resources.length}`);\n io.stdout(\n ` protocols: http=${config.protocols.http.enabled ? 'on' : 'off'} mcp=${config.protocols.mcp.enabled ? 'on' : 'off'} a2a=${config.protocols.a2a.enabled ? 'on' : 'off'} acp=${config.protocols.acp.enabled ? 'on' : 'off'}`,\n );\n io.stdout(` payments: x402=${config.payments.x402?.enabled === true ? 'on' : 'off'}`);\n return 0;\n } catch (err) {\n io.stderr(formatConfigError(err, manifestFound));\n return 1;\n }\n}\n","import type { Io } from '../lib/io.js';\nimport { readVersionReport, type VersionReport } from '../lib/versions.js';\n\nexport interface VersionDeps {\n readonly readVersionReport?: () => VersionReport;\n}\n\n/** `agent-commerce version` — CLI version + pinned protocol/SDK versions. */\nexport function runVersion(io: Io, deps: VersionDeps = {}): number {\n const report = (deps.readVersionReport ?? readVersionReport)();\n io.stdout(`agent-commerce v${report.cliVersion}`);\n if (report.pinned.length > 0) {\n io.stdout('');\n io.stdout('Pinned protocol / SDK versions:');\n for (const pin of report.pinned) {\n io.stdout(` ${pin.name.padEnd(24)} ${pin.version.padEnd(12)} (via ${pin.via})`);\n }\n }\n return 0;\n}\n","/**\n * Minimal, injectable stdout/stderr so command logic is testable without\n * capturing real process streams.\n */\nexport interface Io {\n stdout(line: string): void;\n stderr(line: string): void;\n}\n\nexport const processIo: Io = {\n stdout: (line) => {\n process.stdout.write(`${line}\\n`);\n },\n stderr: (line) => {\n process.stderr.write(`${line}\\n`);\n },\n};\n\n/** Collects lines instead of writing anywhere. Useful for tests. */\nexport function createCapturingIo(): Io & { out: string[]; err: string[] } {\n const out: string[] = [];\n const err: string[] = [];\n return {\n out,\n err,\n stdout: (line) => out.push(line),\n stderr: (line) => err.push(line),\n };\n}\n","#!/usr/bin/env node\nimport { CommanderError } from 'commander';\nimport { buildProgram } from './program.js';\n\n/**\n * `agent-commerce version | grep -q x402` is an ordinary thing to type, and\n * `grep -q` exits on its first match — closing the pipe while the CLI is still\n * writing. Node's default for that is an unhandled `EPIPE` error event on the\n * socket, which aborts the process with a stack trace: a command that did\n * exactly what was asked, reported as a crash, and a red CI step.\n *\n * Exit quietly instead. Every other stream error still throws.\n */\nfor (const stream of [process.stdout, process.stderr]) {\n stream.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EPIPE') process.exit(0);\n throw err;\n });\n}\n\nasync function main(): Promise<void> {\n const program = buildProgram();\n try {\n await program.parseAsync(process.argv);\n } catch (err) {\n if (err instanceof CommanderError) {\n process.exitCode = err.exitCode;\n return;\n }\n throw err;\n }\n}\n\nvoid main();\n"]}