@devlab.group/agent-commerce 1.4.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -183
- package/dist/ap2.d.ts +21 -24
- package/dist/ap2.js +68 -82
- package/dist/ap2.js.map +1 -1
- package/dist/authorization-BpbWGGrf.d.ts +115 -0
- package/dist/{chunk-NWIQLJNU.js → chunk-74BSEXB5.js} +37 -34
- package/dist/chunk-74BSEXB5.js.map +1 -0
- package/dist/chunk-AFI2CEZS.js +10 -0
- package/dist/chunk-AFI2CEZS.js.map +1 -0
- package/dist/chunk-ATTWSFQP.js +680 -0
- package/dist/chunk-ATTWSFQP.js.map +1 -0
- package/dist/{chunk-ZEGFLRGV.js → chunk-IVJC5YLE.js} +63 -26
- package/dist/chunk-IVJC5YLE.js.map +1 -0
- package/dist/{chunk-GF6KHHKL.js → chunk-RAJGPGJG.js} +5 -8
- package/dist/chunk-RAJGPGJG.js.map +1 -0
- package/dist/chunk-V2V2E7HX.js +27 -0
- package/dist/chunk-V2V2E7HX.js.map +1 -0
- package/dist/cli/index.js +812 -573
- package/dist/cli/index.js.map +1 -1
- package/dist/constants-Bkq04FRZ.d.ts +48 -0
- package/dist/guardrails-71XwtXlT.d.ts +31 -0
- package/dist/index.d.ts +245 -265
- package/dist/index.js +1222 -626
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +6 -59
- package/dist/mcp.js +64 -53
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +50 -0
- package/dist/mpp.js +353 -0
- package/dist/mpp.js.map +1 -0
- package/dist/protocol-adapter-DTkrXTev.d.ts +238 -0
- package/dist/runtime-CiYbgGpi.d.ts +303 -0
- package/dist/{types-CJtwLu1c.d.ts → types-O6lg3Q5V.d.ts} +17 -23
- package/dist/x402.d.ts +43 -75
- package/dist/x402.js +13 -693
- package/dist/x402.js.map +1 -1
- package/package.json +13 -2
- package/dist/authorization-CPDcpJVa.d.ts +0 -123
- package/dist/chunk-GF6KHHKL.js.map +0 -1
- package/dist/chunk-NWIQLJNU.js.map +0 -1
- package/dist/chunk-ZEGFLRGV.js.map +0 -1
- package/dist/guardrails-Dmwi63KB.d.ts +0 -38
- package/dist/protocol-adapter-Bebmggf_.d.ts +0 -273
- package/dist/runtime-CKq3d_3K.d.ts +0 -340
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared primitive aliases used across the canonical domain model.
|
|
3
|
-
*
|
|
4
|
-
* FROZEN CONTRACT. Every consumer codes against these shapes; changing one
|
|
5
|
-
* is a breaking change.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* A JSON Schema document (draft 2020-12 subset in practice).
|
|
9
|
-
*
|
|
10
|
-
* Deliberately loose: protocol adapters translate this to their own schema
|
|
11
|
-
* representation, and the gateway only validates structurally at trust
|
|
12
|
-
* boundaries. Never treat this as trusted input without validation.
|
|
13
|
-
*/
|
|
14
|
-
type JsonSchema = Record<string, unknown>;
|
|
15
|
-
/**
|
|
16
|
-
* Protocol surfaces a resource can be exposed through in this release.
|
|
17
|
-
*
|
|
18
|
-
* The runtime list is the definition and the type is derived from it, so a
|
|
19
|
-
* caller that has to *check* a name (config validation, the OpenAPI
|
|
20
|
-
* importer's `--expose`) reads the same strings the type is built from
|
|
21
|
-
* rather than keeping a second copy that can drift.
|
|
22
|
-
*/
|
|
23
|
-
type ProtocolName = 'http' | 'mcp' | 'a2a' | 'acp';
|
|
24
|
-
/**
|
|
25
|
-
* The same names as a value, for code that has to *check* one at
|
|
26
|
-
* runtime - config validation, the OpenAPI importer's `--expose`. Typed
|
|
27
|
-
* against `ProtocolName` so an unsupported name cannot enter the list, which
|
|
28
|
-
* is what keeps this from becoming a second definition that drifts.
|
|
29
|
-
*/
|
|
30
|
-
declare const PROTOCOL_NAMES: readonly ProtocolName[];
|
|
31
|
-
/** Payment methods a resource can accept in this release. */
|
|
32
|
-
type PaymentMethodName = 'x402';
|
|
33
|
-
/**
|
|
34
|
-
* Authorization methods a resource can require in this release.
|
|
35
|
-
*
|
|
36
|
-
* Deliberately not a `ProtocolName` and not a `PaymentMethodName`: an
|
|
37
|
-
* authorization method is neither a transport nor a payment rail. It proves
|
|
38
|
-
* the purchase was approved, and sits beside the payment rather than
|
|
39
|
-
* replacing it.
|
|
40
|
-
*/
|
|
41
|
-
type AuthorizationMethodName = 'ap2';
|
|
42
|
-
/** ISO-8601 timestamp string, always UTC with millisecond precision. */
|
|
43
|
-
type IsoTimestamp = string;
|
|
44
|
-
/**
|
|
45
|
-
* A decimal amount expressed as a string in the *display* unit of the currency
|
|
46
|
-
* (for example "0.01" USDC), never as a float and never in base units.
|
|
47
|
-
*
|
|
48
|
-
* Conversion to on-chain base units is a payment-provider responsibility.
|
|
49
|
-
*/
|
|
50
|
-
type DecimalAmount = string;
|
|
51
|
-
/** Health of an individual adapter or subsystem. */
|
|
52
|
-
interface AdapterHealth {
|
|
53
|
-
readonly status: 'pass' | 'warn' | 'fail';
|
|
54
|
-
readonly detail?: string;
|
|
55
|
-
readonly checkedAt: IsoTimestamp;
|
|
56
|
-
readonly durationMs?: number;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Self-description every adapter must expose so diagnostics can report exactly
|
|
60
|
-
* what is supported instead of implying blanket protocol compatibility.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*/
|
|
64
|
-
interface AdapterDescriptor {
|
|
65
|
-
readonly name: string;
|
|
66
|
-
readonly kind: 'protocol' | 'payment' | 'storage' | 'authorization';
|
|
67
|
-
/** Version of this adapter implementation (independent of the spec). */
|
|
68
|
-
readonly implementationVersion: string;
|
|
69
|
-
/** Exact pinned specification revision this adapter targets. */
|
|
70
|
-
readonly supportedSpec: string;
|
|
71
|
-
readonly capabilities: readonly string[];
|
|
72
|
-
readonly status: 'stable' | 'experimental' | 'planned';
|
|
73
|
-
/** Capabilities explicitly NOT implemented, surfaced by `doctor`. */
|
|
74
|
-
readonly unsupported?: readonly string[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Canonical resource model.
|
|
79
|
-
*
|
|
80
|
-
* FROZEN CONTRACT.
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/** HTTP methods a backend handler may use. */
|
|
84
|
-
type BackendMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
85
|
-
/**
|
|
86
|
-
* Describes how the gateway calls the merchant's existing backend.
|
|
87
|
-
*
|
|
88
|
-
* Backend URLs are administrator-controlled configuration only. User- or
|
|
89
|
-
* agent-controlled backend URLs are forbidden (see docs/security.md, SSRF).
|
|
90
|
-
* Secret header values must come from `${ENV_VAR}` placeholders resolved by
|
|
91
|
-
* the config loader, never from plaintext configuration.
|
|
92
|
-
*/
|
|
93
|
-
interface BackendHandler {
|
|
94
|
-
readonly type: 'http';
|
|
95
|
-
readonly method: BackendMethod;
|
|
96
|
-
readonly url: string;
|
|
97
|
-
readonly headers?: Readonly<Record<string, string>>;
|
|
98
|
-
/** Hard upper bound on the backend call. Defaults to DEFAULT_BACKEND_TIMEOUT_MS. */
|
|
99
|
-
readonly timeoutMs?: number;
|
|
100
|
-
/**
|
|
101
|
-
* Names the top-level input properties carrying each part of the request.
|
|
102
|
-
*
|
|
103
|
-
* Absent (the default) keeps the original mapping: `{param}` values are read
|
|
104
|
-
* from top-level input and everything left over becomes either the query
|
|
105
|
-
* string (GET/DELETE) or the entire JSON body (POST/PUT/PATCH). That mapping
|
|
106
|
-
* cannot express `POST /users/{userId}/orders?notify=true` with a JSON body
|
|
107
|
-
* - one perfectly ordinary REST operation with all three parts at once.
|
|
108
|
-
*
|
|
109
|
-
* When present, each group is sourced independently and top-level input that
|
|
110
|
-
* no binding names is not forwarded to the backend at all.
|
|
111
|
-
*/
|
|
112
|
-
readonly inputBindings?: {
|
|
113
|
-
readonly path?: string;
|
|
114
|
-
readonly query?: string;
|
|
115
|
-
readonly body?: string;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/** Default backend timeout when a resource does not specify one. */
|
|
119
|
-
declare const DEFAULT_BACKEND_TIMEOUT_MS = 10000;
|
|
120
|
-
/**
|
|
121
|
-
* Canonical pricing.
|
|
122
|
-
*
|
|
123
|
-
* `dynamic` exists in the type system for forward compatibility but is
|
|
124
|
-
* REJECTED by config validation in this release.
|
|
125
|
-
*/
|
|
126
|
-
type Pricing = {
|
|
127
|
-
readonly type: 'free';
|
|
128
|
-
} | {
|
|
129
|
-
readonly type: 'fixed';
|
|
130
|
-
readonly amount: DecimalAmount;
|
|
131
|
-
readonly currency: string;
|
|
132
|
-
} | {
|
|
133
|
-
readonly type: 'dynamic';
|
|
134
|
-
readonly resolver: string;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* A merchant capability exposed to agents.
|
|
138
|
-
*
|
|
139
|
-
* The canonical resource is the single source of truth: protocol adapters map
|
|
140
|
-
* it outward, they never define their own parallel notion of a resource.
|
|
141
|
-
*/
|
|
142
|
-
interface CommerceResource {
|
|
143
|
-
readonly id: string;
|
|
144
|
-
readonly name: string;
|
|
145
|
-
readonly description?: string;
|
|
146
|
-
readonly inputSchema?: JsonSchema;
|
|
147
|
-
readonly outputSchema?: JsonSchema;
|
|
148
|
-
readonly handler: BackendHandler;
|
|
149
|
-
readonly pricing: Pricing;
|
|
150
|
-
readonly exposedVia: readonly ProtocolName[];
|
|
151
|
-
readonly paymentMethods: readonly PaymentMethodName[];
|
|
152
|
-
/**
|
|
153
|
-
* Authorization the buyer must present in addition to payment.
|
|
154
|
-
*
|
|
155
|
-
* Opt-in per resource and absent by default, so every resource configured
|
|
156
|
-
* before this existed behaves exactly as it did. It sits beside
|
|
157
|
-
* `paymentMethods` rather than inside it: an authorization method is not a
|
|
158
|
-
* payment rail and must never be selectable as one.
|
|
159
|
-
*/
|
|
160
|
-
readonly authorization?: {
|
|
161
|
-
readonly required: readonly AuthorizationMethodName[];
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/** Read-only view of every configured resource. */
|
|
165
|
-
interface ResourceRegistry {
|
|
166
|
-
get(id: string): CommerceResource | undefined;
|
|
167
|
-
list(): readonly CommerceResource[];
|
|
168
|
-
/** Resources exposed through a given protocol surface. */
|
|
169
|
-
listExposedVia(protocol: ProtocolName): readonly CommerceResource[];
|
|
170
|
-
has(id: string): boolean;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Canonical payment model.
|
|
175
|
-
*
|
|
176
|
-
* FROZEN CONTRACT.
|
|
177
|
-
*
|
|
178
|
-
* Core decides *that* a payment is required and for how much.
|
|
179
|
-
* Payment providers decide *how* the challenge is encoded, verified and settled.
|
|
180
|
-
* No x402/EVM-specific type may appear in this file.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Provider-native payment challenge, opaque to core.
|
|
185
|
-
*
|
|
186
|
-
* For x402 the `accepts` entries are x402 `PaymentRequirements` objects; core
|
|
187
|
-
* passes them through to protocol adapters verbatim and never inspects them.
|
|
188
|
-
*/
|
|
189
|
-
interface PaymentChallenge {
|
|
190
|
-
readonly provider: PaymentMethodName;
|
|
191
|
-
/** Provider protocol version, e.g. the x402 `x402Version` value as a string. */
|
|
192
|
-
readonly version: string;
|
|
193
|
-
readonly accepts: readonly Readonly<Record<string, unknown>>[];
|
|
194
|
-
/**
|
|
195
|
-
* The provider's own challenge document, verbatim — for x402 v2 the
|
|
196
|
-
* `PaymentRequired` object a buyer's client consumes.
|
|
197
|
-
*
|
|
198
|
-
* `accepts` alone is not that document: v2 moves the resource description
|
|
199
|
-
* out of the individual requirements and up onto the envelope, and the
|
|
200
|
-
* protocol version rides there too. Protocol adapters that have a native
|
|
201
|
-
* channel for it (the HTTP `PAYMENT-REQUIRED` header) emit this as-is
|
|
202
|
-
* rather than reassembling it, so every surface offers the same challenge
|
|
203
|
-
* instead of each building its own from parts. Opaque to core.
|
|
204
|
-
*/
|
|
205
|
-
readonly envelope?: Readonly<Record<string, unknown>>;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* What the buyer must pay, in canonical terms, plus the provider-native
|
|
209
|
-
* challenge the buyer's client needs in order to construct a payment.
|
|
210
|
-
*/
|
|
211
|
-
interface PaymentRequirement {
|
|
212
|
-
readonly id: string;
|
|
213
|
-
readonly requestId: string;
|
|
214
|
-
readonly resourceId: string;
|
|
215
|
-
readonly provider: PaymentMethodName;
|
|
216
|
-
readonly amount: DecimalAmount;
|
|
217
|
-
readonly currency: string;
|
|
218
|
-
/** Merchant-controlled settlement destination. Never a gateway-owned wallet. */
|
|
219
|
-
readonly destination: string;
|
|
220
|
-
readonly network?: string;
|
|
221
|
-
readonly asset?: string;
|
|
222
|
-
readonly expiresAt?: IsoTimestamp;
|
|
223
|
-
readonly challenge: PaymentChallenge;
|
|
224
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Opaque payment proof supplied by the buyer's client.
|
|
228
|
-
*
|
|
229
|
-
* For x402 over HTTP this is the base64 `PAYMENT-SIGNATURE` header value; over
|
|
230
|
-
* MCP it is the same string carried in the tool input's `_payment` field.
|
|
231
|
-
*/
|
|
232
|
-
interface PaymentSubmission {
|
|
233
|
-
readonly method: PaymentMethodName;
|
|
234
|
-
readonly payload: string;
|
|
235
|
-
}
|
|
236
|
-
/** Outcome of verification or settlement. */
|
|
237
|
-
interface PaymentResult {
|
|
238
|
-
readonly status: 'verified' | 'settled' | 'rejected';
|
|
239
|
-
readonly provider: PaymentMethodName;
|
|
240
|
-
/** Settlement reference, e.g. an on-chain transaction hash. */
|
|
241
|
-
readonly externalReference?: string;
|
|
242
|
-
readonly payer?: string;
|
|
243
|
-
readonly payee?: string;
|
|
244
|
-
readonly amount: DecimalAmount;
|
|
245
|
-
readonly currency: string;
|
|
246
|
-
readonly network?: string;
|
|
247
|
-
readonly asset?: string;
|
|
248
|
-
/**
|
|
249
|
-
* Stable, provider-computed identity of the payment authorisation itself.
|
|
250
|
-
*
|
|
251
|
-
* The gateway reserves this key before settlement and rejects any second
|
|
252
|
-
* request presenting the same key (see PAYMENT_REPLAYED). Providers MUST
|
|
253
|
-
* derive it only from the authorisation (payer, nonce, asset, network) so
|
|
254
|
-
* that the same authorisation always maps to the same key.
|
|
255
|
-
*/
|
|
256
|
-
readonly replayKey?: string;
|
|
257
|
-
/** Machine-readable rejection reason when status is `rejected`. */
|
|
258
|
-
readonly rejectionReason?: string;
|
|
259
|
-
readonly settledAt?: IsoTimestamp;
|
|
260
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
261
|
-
}
|
|
262
|
-
/** Input to {@link PaymentProvider.createRequirement}. */
|
|
263
|
-
interface PaymentContext {
|
|
264
|
-
readonly requestId: string;
|
|
265
|
-
readonly resource: CommerceResource;
|
|
266
|
-
readonly amount: DecimalAmount;
|
|
267
|
-
readonly currency: string;
|
|
268
|
-
readonly requestedAt: IsoTimestamp;
|
|
269
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
270
|
-
}
|
|
271
|
-
/** Input to {@link PaymentProvider.verify}. */
|
|
272
|
-
interface PaymentVerificationContext {
|
|
273
|
-
readonly requestId: string;
|
|
274
|
-
readonly resource: CommerceResource;
|
|
275
|
-
readonly requirement: PaymentRequirement;
|
|
276
|
-
readonly submission: PaymentSubmission;
|
|
277
|
-
}
|
|
278
|
-
/** Input to {@link PaymentProvider.settle}. */
|
|
279
|
-
interface PaymentSettlementContext extends PaymentVerificationContext {
|
|
280
|
-
readonly verification: PaymentResult;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Contract every payment rail implements.
|
|
284
|
-
*
|
|
285
|
-
* Implementations must be non-custodial: they orchestrate an external payment
|
|
286
|
-
* protocol and must never hold buyer or merchant production signing keys.
|
|
287
|
-
*/
|
|
288
|
-
interface PaymentProvider {
|
|
289
|
-
readonly name: PaymentMethodName;
|
|
290
|
-
readonly descriptor: AdapterDescriptor;
|
|
291
|
-
/** Build the challenge presented to an unpaid request. */
|
|
292
|
-
createRequirement(context: PaymentContext): Promise<PaymentRequirement>;
|
|
293
|
-
/**
|
|
294
|
-
* Validate a submitted proof against the requirement.
|
|
295
|
-
*
|
|
296
|
-
* Must return `rejected` (or throw a CommerceError) rather than throwing an
|
|
297
|
-
* untyped error. Must never have side effects that move funds.
|
|
298
|
-
*/
|
|
299
|
-
verify(context: PaymentVerificationContext): Promise<PaymentResult>;
|
|
300
|
-
/** Execute settlement. Called only after `verify` returned `verified`. */
|
|
301
|
-
settle(context: PaymentSettlementContext): Promise<PaymentResult>;
|
|
302
|
-
health(): Promise<AdapterHealth>;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Minimal structural logger interface.
|
|
307
|
-
*
|
|
308
|
-
* Core must not depend on pino directly; the gateway injects a pino instance
|
|
309
|
-
* that satisfies this shape. Never log secrets: private keys, seed phrases,
|
|
310
|
-
* Authorization headers or payment authorisation payloads.
|
|
311
|
-
*/
|
|
312
|
-
interface Logger {
|
|
313
|
-
debug(obj: Record<string, unknown>, msg?: string): void;
|
|
314
|
-
info(obj: Record<string, unknown>, msg?: string): void;
|
|
315
|
-
warn(obj: Record<string, unknown>, msg?: string): void;
|
|
316
|
-
error(obj: Record<string, unknown>, msg?: string): void;
|
|
317
|
-
child(bindings: Record<string, unknown>): Logger;
|
|
318
|
-
}
|
|
319
|
-
/** A logger that discards everything. Useful in unit tests. */
|
|
320
|
-
declare const NOOP_LOGGER: Logger;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Injected runtime primitives.
|
|
324
|
-
*
|
|
325
|
-
* Everything non-deterministic (time, ids) is injected so tests can be exact.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
interface Clock {
|
|
329
|
-
now(): Date;
|
|
330
|
-
nowIso(): IsoTimestamp;
|
|
331
|
-
/** Milliseconds since an arbitrary origin; use for durations only. */
|
|
332
|
-
monotonicMs(): number;
|
|
333
|
-
}
|
|
334
|
-
interface IdGenerator {
|
|
335
|
-
/** Opaque, collision-resistant identifier. */
|
|
336
|
-
next(prefix?: string): string;
|
|
337
|
-
}
|
|
338
|
-
declare const systemClock: Clock;
|
|
339
|
-
|
|
340
|
-
export { type AdapterDescriptor as A, type BackendHandler as B, type Clock as C, type DecimalAmount as D, type IsoTimestamp as I, type JsonSchema as J, type Logger as L, NOOP_LOGGER as N, type PaymentMethodName as P, type ResourceRegistry as R, type CommerceResource as a, type PaymentSubmission as b, type AdapterHealth as c, type PaymentProvider as d, type IdGenerator as e, type AuthorizationMethodName as f, type BackendMethod as g, DEFAULT_BACKEND_TIMEOUT_MS as h, PROTOCOL_NAMES as i, type PaymentChallenge as j, type PaymentContext as k, type PaymentRequirement as l, type PaymentResult as m, type PaymentSettlementContext as n, type PaymentVerificationContext as o, type Pricing as p, type ProtocolName as q, systemClock as s };
|