@bankofai/x402-extensions 2.6.0-beta.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 +792 -0
- package/dist/cjs/bazaar/index.d.ts +3 -0
- package/dist/cjs/bazaar/index.js +629 -0
- package/dist/cjs/bazaar/index.js.map +1 -0
- package/dist/cjs/index-DPJQYYGe.d.ts +662 -0
- package/dist/cjs/index.d.ts +360 -0
- package/dist/cjs/index.js +1880 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/payment-identifier/index.d.ts +345 -0
- package/dist/cjs/payment-identifier/index.js +285 -0
- package/dist/cjs/payment-identifier/index.js.map +1 -0
- package/dist/cjs/sign-in-with-x/index.d.ts +1091 -0
- package/dist/cjs/sign-in-with-x/index.js +845 -0
- package/dist/cjs/sign-in-with-x/index.js.map +1 -0
- package/dist/esm/bazaar/index.d.mts +3 -0
- package/dist/esm/bazaar/index.mjs +33 -0
- package/dist/esm/bazaar/index.mjs.map +1 -0
- package/dist/esm/chunk-MTWK6ERV.mjs +777 -0
- package/dist/esm/chunk-MTWK6ERV.mjs.map +1 -0
- package/dist/esm/chunk-RERA4OZZ.mjs +233 -0
- package/dist/esm/chunk-RERA4OZZ.mjs.map +1 -0
- package/dist/esm/chunk-UHTNEDIJ.mjs +580 -0
- package/dist/esm/chunk-UHTNEDIJ.mjs.map +1 -0
- package/dist/esm/index-DPJQYYGe.d.mts +662 -0
- package/dist/esm/index.d.mts +360 -0
- package/dist/esm/index.mjs +323 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/payment-identifier/index.d.mts +345 -0
- package/dist/esm/payment-identifier/index.mjs +39 -0
- package/dist/esm/payment-identifier/index.mjs.map +1 -0
- package/dist/esm/sign-in-with-x/index.d.mts +1091 -0
- package/dist/esm/sign-in-with-x/index.mjs +71 -0
- package/dist/esm/sign-in-with-x/index.mjs.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
import { FacilitatorExtension, ResourceServerExtension, PaymentPayload, PaymentRequirements, PaymentRequirementsV1 } from '@bankofai/x402-core/types';
|
|
2
|
+
import { BodyMethods, QueryParamMethods, HTTPFacilitatorClient } from '@bankofai/x402-core/http';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared type utilities for x402 extensions
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Type utility to merge extensions properly when chaining.
|
|
9
|
+
* If T already has extensions, merge them; otherwise add new extensions.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Chaining multiple extensions preserves all types:
|
|
14
|
+
* const client = withBazaar(withOtherExtension(new HTTPFacilitatorClient()));
|
|
15
|
+
* // Type: HTTPFacilitatorClient & { extensions: OtherExtension & BazaarExtension }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type WithExtensions<T, E> = T extends {
|
|
19
|
+
extensions: infer Existing;
|
|
20
|
+
} ? Omit<T, "extensions"> & {
|
|
21
|
+
extensions: Existing & E;
|
|
22
|
+
} : T & {
|
|
23
|
+
extensions: E;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* HTTP-specific type definitions for the Bazaar Discovery Extension
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Discovery info for query parameter methods (GET, HEAD, DELETE)
|
|
32
|
+
*/
|
|
33
|
+
interface QueryDiscoveryInfo {
|
|
34
|
+
input: {
|
|
35
|
+
type: "http";
|
|
36
|
+
/** Absent at declaration time; set by bazaarResourceServerExtension.enrichDeclaration */
|
|
37
|
+
method?: QueryParamMethods;
|
|
38
|
+
queryParams?: Record<string, unknown>;
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
};
|
|
41
|
+
output?: {
|
|
42
|
+
type?: string;
|
|
43
|
+
format?: string;
|
|
44
|
+
example?: unknown;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Discovery info for body methods (POST, PUT, PATCH)
|
|
49
|
+
*/
|
|
50
|
+
interface BodyDiscoveryInfo {
|
|
51
|
+
input: {
|
|
52
|
+
type: "http";
|
|
53
|
+
/** Absent at declaration time; set by bazaarResourceServerExtension.enrichDeclaration */
|
|
54
|
+
method?: BodyMethods;
|
|
55
|
+
bodyType: "json" | "form-data" | "text";
|
|
56
|
+
body: Record<string, unknown>;
|
|
57
|
+
queryParams?: Record<string, unknown>;
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
output?: {
|
|
61
|
+
type?: string;
|
|
62
|
+
format?: string;
|
|
63
|
+
example?: unknown;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Discovery extension for query parameter methods (GET, HEAD, DELETE)
|
|
68
|
+
*/
|
|
69
|
+
interface QueryDiscoveryExtension {
|
|
70
|
+
info: QueryDiscoveryInfo;
|
|
71
|
+
schema: {
|
|
72
|
+
$schema: "https://json-schema.org/draft/2020-12/schema";
|
|
73
|
+
type: "object";
|
|
74
|
+
properties: {
|
|
75
|
+
input: {
|
|
76
|
+
type: "object";
|
|
77
|
+
properties: {
|
|
78
|
+
type: {
|
|
79
|
+
type: "string";
|
|
80
|
+
const: "http";
|
|
81
|
+
};
|
|
82
|
+
method: {
|
|
83
|
+
type: "string";
|
|
84
|
+
enum: QueryParamMethods[];
|
|
85
|
+
};
|
|
86
|
+
queryParams?: {
|
|
87
|
+
type: "object";
|
|
88
|
+
properties?: Record<string, unknown>;
|
|
89
|
+
required?: string[];
|
|
90
|
+
additionalProperties?: boolean;
|
|
91
|
+
};
|
|
92
|
+
headers?: {
|
|
93
|
+
type: "object";
|
|
94
|
+
additionalProperties: {
|
|
95
|
+
type: "string";
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
required: ("type" | "method")[];
|
|
100
|
+
additionalProperties?: boolean;
|
|
101
|
+
};
|
|
102
|
+
output?: {
|
|
103
|
+
type: "object";
|
|
104
|
+
properties?: Record<string, unknown>;
|
|
105
|
+
required?: readonly string[];
|
|
106
|
+
additionalProperties?: boolean;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
required: ["input"];
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Discovery extension for body methods (POST, PUT, PATCH)
|
|
114
|
+
*/
|
|
115
|
+
interface BodyDiscoveryExtension {
|
|
116
|
+
info: BodyDiscoveryInfo;
|
|
117
|
+
schema: {
|
|
118
|
+
$schema: "https://json-schema.org/draft/2020-12/schema";
|
|
119
|
+
type: "object";
|
|
120
|
+
properties: {
|
|
121
|
+
input: {
|
|
122
|
+
type: "object";
|
|
123
|
+
properties: {
|
|
124
|
+
type: {
|
|
125
|
+
type: "string";
|
|
126
|
+
const: "http";
|
|
127
|
+
};
|
|
128
|
+
method: {
|
|
129
|
+
type: "string";
|
|
130
|
+
enum: BodyMethods[];
|
|
131
|
+
};
|
|
132
|
+
bodyType: {
|
|
133
|
+
type: "string";
|
|
134
|
+
enum: ["json", "form-data", "text"];
|
|
135
|
+
};
|
|
136
|
+
body: Record<string, unknown>;
|
|
137
|
+
queryParams?: {
|
|
138
|
+
type: "object";
|
|
139
|
+
properties?: Record<string, unknown>;
|
|
140
|
+
required?: string[];
|
|
141
|
+
additionalProperties?: boolean;
|
|
142
|
+
};
|
|
143
|
+
headers?: {
|
|
144
|
+
type: "object";
|
|
145
|
+
additionalProperties: {
|
|
146
|
+
type: "string";
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
required: ("type" | "method" | "bodyType" | "body")[];
|
|
151
|
+
additionalProperties?: boolean;
|
|
152
|
+
};
|
|
153
|
+
output?: {
|
|
154
|
+
type: "object";
|
|
155
|
+
properties?: Record<string, unknown>;
|
|
156
|
+
required?: readonly string[];
|
|
157
|
+
additionalProperties?: boolean;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
required: ["input"];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface DeclareQueryDiscoveryExtensionConfig {
|
|
164
|
+
method?: QueryParamMethods;
|
|
165
|
+
input?: Record<string, unknown>;
|
|
166
|
+
inputSchema?: Record<string, unknown>;
|
|
167
|
+
output?: {
|
|
168
|
+
example?: unknown;
|
|
169
|
+
schema?: Record<string, unknown>;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
interface DeclareBodyDiscoveryExtensionConfig {
|
|
173
|
+
method?: BodyMethods;
|
|
174
|
+
input?: Record<string, unknown>;
|
|
175
|
+
inputSchema?: Record<string, unknown>;
|
|
176
|
+
bodyType: "json" | "form-data" | "text";
|
|
177
|
+
output?: {
|
|
178
|
+
example?: unknown;
|
|
179
|
+
schema?: Record<string, unknown>;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
interface DiscoveredHTTPResource {
|
|
183
|
+
resourceUrl: string;
|
|
184
|
+
description?: string;
|
|
185
|
+
mimeType?: string;
|
|
186
|
+
/** Present after server extension enrichment; may be absent for pre-enrichment data */
|
|
187
|
+
method?: string;
|
|
188
|
+
x402Version: number;
|
|
189
|
+
discoveryInfo: DiscoveryInfo;
|
|
190
|
+
}
|
|
191
|
+
declare const isQueryExtensionConfig: (config: DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig) => config is DeclareQueryDiscoveryExtensionConfig;
|
|
192
|
+
declare const isBodyExtensionConfig: (config: DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig) => config is DeclareBodyDiscoveryExtensionConfig;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* MCP-specific type definitions for the Bazaar Discovery Extension
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Discovery info for MCP tools
|
|
200
|
+
*/
|
|
201
|
+
interface McpDiscoveryInfo {
|
|
202
|
+
input: {
|
|
203
|
+
type: "mcp";
|
|
204
|
+
toolName: string;
|
|
205
|
+
description?: string;
|
|
206
|
+
transport?: "streamable-http" | "sse";
|
|
207
|
+
inputSchema: Record<string, unknown>;
|
|
208
|
+
example?: Record<string, unknown>;
|
|
209
|
+
};
|
|
210
|
+
output?: {
|
|
211
|
+
type?: string;
|
|
212
|
+
format?: string;
|
|
213
|
+
example?: unknown;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Discovery extension for MCP tools
|
|
218
|
+
*/
|
|
219
|
+
interface McpDiscoveryExtension {
|
|
220
|
+
info: McpDiscoveryInfo;
|
|
221
|
+
schema: {
|
|
222
|
+
$schema: "https://json-schema.org/draft/2020-12/schema";
|
|
223
|
+
type: "object";
|
|
224
|
+
properties: {
|
|
225
|
+
input: {
|
|
226
|
+
type: "object";
|
|
227
|
+
properties: {
|
|
228
|
+
type: {
|
|
229
|
+
type: "string";
|
|
230
|
+
const: "mcp";
|
|
231
|
+
};
|
|
232
|
+
toolName: {
|
|
233
|
+
type: "string";
|
|
234
|
+
};
|
|
235
|
+
description?: {
|
|
236
|
+
type: "string";
|
|
237
|
+
};
|
|
238
|
+
transport?: {
|
|
239
|
+
type: "string";
|
|
240
|
+
enum: ["streamable-http", "sse"];
|
|
241
|
+
};
|
|
242
|
+
inputSchema: Record<string, unknown>;
|
|
243
|
+
example?: Record<string, unknown>;
|
|
244
|
+
};
|
|
245
|
+
required: ("type" | "toolName" | "inputSchema")[];
|
|
246
|
+
additionalProperties?: boolean;
|
|
247
|
+
};
|
|
248
|
+
output?: {
|
|
249
|
+
type: "object";
|
|
250
|
+
properties?: Record<string, unknown>;
|
|
251
|
+
required?: readonly string[];
|
|
252
|
+
additionalProperties?: boolean;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
required: ["input"];
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
interface DeclareMcpDiscoveryExtensionConfig {
|
|
259
|
+
toolName: string;
|
|
260
|
+
description?: string;
|
|
261
|
+
transport?: "streamable-http" | "sse";
|
|
262
|
+
inputSchema: Record<string, unknown>;
|
|
263
|
+
example?: Record<string, unknown>;
|
|
264
|
+
output?: {
|
|
265
|
+
example?: unknown;
|
|
266
|
+
schema?: Record<string, unknown>;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
interface DiscoveredMCPResource {
|
|
270
|
+
resourceUrl: string;
|
|
271
|
+
description?: string;
|
|
272
|
+
mimeType?: string;
|
|
273
|
+
toolName: string;
|
|
274
|
+
x402Version: number;
|
|
275
|
+
discoveryInfo: DiscoveryInfo;
|
|
276
|
+
}
|
|
277
|
+
declare const isMcpExtensionConfig: (config: DeclareMcpDiscoveryExtensionConfig | Record<string, unknown>) => config is DeclareMcpDiscoveryExtensionConfig;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Shared type definitions for the Bazaar Discovery Extension
|
|
281
|
+
*
|
|
282
|
+
* Protocol-specific types live in their own directories (http/, mcp/).
|
|
283
|
+
* This file defines the shared unions, constants, and utility types,
|
|
284
|
+
* and re-exports all protocol-specific types for backwards compatibility.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Extension identifier for the Bazaar discovery extension.
|
|
289
|
+
*/
|
|
290
|
+
declare const BAZAAR: FacilitatorExtension;
|
|
291
|
+
/**
|
|
292
|
+
* Combined discovery info type
|
|
293
|
+
*/
|
|
294
|
+
type DiscoveryInfo = QueryDiscoveryInfo | BodyDiscoveryInfo | McpDiscoveryInfo;
|
|
295
|
+
/**
|
|
296
|
+
* Combined discovery extension type
|
|
297
|
+
*/
|
|
298
|
+
type DiscoveryExtension = QueryDiscoveryExtension | BodyDiscoveryExtension | McpDiscoveryExtension;
|
|
299
|
+
type DeclareDiscoveryExtensionConfig = DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig | DeclareMcpDiscoveryExtensionConfig;
|
|
300
|
+
/**
|
|
301
|
+
* Distributive Omit - properly distributes Omit over union types.
|
|
302
|
+
*
|
|
303
|
+
* Standard `Omit<A | B, K>` collapses to common properties only,
|
|
304
|
+
* losing discriminant properties like `bodyType`.
|
|
305
|
+
*
|
|
306
|
+
* This type uses conditional type distribution to preserve the union:
|
|
307
|
+
* `DistributiveOmit<A | B, K>` = `Omit<A, K> | Omit<B, K>`
|
|
308
|
+
*/
|
|
309
|
+
type DistributiveOmit<T, K extends keyof T> = T extends T ? Omit<T, K> : never;
|
|
310
|
+
/**
|
|
311
|
+
* Config type for declareDiscoveryExtension function.
|
|
312
|
+
* Uses DistributiveOmit to preserve bodyType discriminant in the union for HTTP configs.
|
|
313
|
+
* MCP config has no `method` field so it's included directly.
|
|
314
|
+
*/
|
|
315
|
+
type DeclareDiscoveryExtensionInput = DistributiveOmit<DeclareQueryDiscoveryExtensionConfig, "method"> | DistributiveOmit<DeclareBodyDiscoveryExtensionConfig, "method"> | DeclareMcpDiscoveryExtensionConfig;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Resource Service entry point for creating Bazaar discovery extensions
|
|
319
|
+
*
|
|
320
|
+
* This module provides the unified `declareDiscoveryExtension` function that
|
|
321
|
+
* routes to protocol-specific builders in http/ and mcp/.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Create a discovery extension for any HTTP method or MCP tool
|
|
326
|
+
*
|
|
327
|
+
* This function helps servers declare how their endpoint should be called,
|
|
328
|
+
* including the expected input parameters/body and output format.
|
|
329
|
+
*
|
|
330
|
+
* @param config - Configuration object for the discovery extension
|
|
331
|
+
* @returns A discovery extension object with both info and schema
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* // For a GET endpoint with no input
|
|
336
|
+
* const getExtension = declareDiscoveryExtension({
|
|
337
|
+
* method: "GET",
|
|
338
|
+
* output: {
|
|
339
|
+
* example: { message: "Success", timestamp: "2024-01-01T00:00:00Z" }
|
|
340
|
+
* }
|
|
341
|
+
* });
|
|
342
|
+
*
|
|
343
|
+
* // For a GET endpoint with query params
|
|
344
|
+
* const getWithParams = declareDiscoveryExtension({
|
|
345
|
+
* method: "GET",
|
|
346
|
+
* input: { query: "example" },
|
|
347
|
+
* inputSchema: {
|
|
348
|
+
* properties: {
|
|
349
|
+
* query: { type: "string" }
|
|
350
|
+
* },
|
|
351
|
+
* required: ["query"]
|
|
352
|
+
* }
|
|
353
|
+
* });
|
|
354
|
+
*
|
|
355
|
+
* // For a POST endpoint with JSON body
|
|
356
|
+
* const postExtension = declareDiscoveryExtension({
|
|
357
|
+
* method: "POST",
|
|
358
|
+
* input: { name: "John", age: 30 },
|
|
359
|
+
* inputSchema: {
|
|
360
|
+
* properties: {
|
|
361
|
+
* name: { type: "string" },
|
|
362
|
+
* age: { type: "number" }
|
|
363
|
+
* },
|
|
364
|
+
* required: ["name"]
|
|
365
|
+
* },
|
|
366
|
+
* bodyType: "json",
|
|
367
|
+
* output: {
|
|
368
|
+
* example: { success: true, id: "123" }
|
|
369
|
+
* }
|
|
370
|
+
* });
|
|
371
|
+
*
|
|
372
|
+
* // For an MCP tool
|
|
373
|
+
* const mcpExtension = declareDiscoveryExtension({
|
|
374
|
+
* toolName: "financial_analysis",
|
|
375
|
+
* description: "Analyze financial data for a given ticker",
|
|
376
|
+
* inputSchema: {
|
|
377
|
+
* type: "object",
|
|
378
|
+
* properties: {
|
|
379
|
+
* ticker: { type: "string" },
|
|
380
|
+
* },
|
|
381
|
+
* required: ["ticker"],
|
|
382
|
+
* },
|
|
383
|
+
* output: {
|
|
384
|
+
* example: { pe_ratio: 28.5, recommendation: "hold" }
|
|
385
|
+
* }
|
|
386
|
+
* });
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
declare function declareDiscoveryExtension(config: DeclareDiscoveryExtensionInput): Record<string, DiscoveryExtension>;
|
|
390
|
+
|
|
391
|
+
declare const bazaarResourceServerExtension: ResourceServerExtension;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Facilitator functions for validating and extracting Bazaar discovery extensions
|
|
395
|
+
*
|
|
396
|
+
* These functions help facilitators validate extension data against schemas
|
|
397
|
+
* and extract the discovery information for cataloging in the Bazaar.
|
|
398
|
+
*
|
|
399
|
+
* Supports both v2 (extensions in PaymentRequired) and v1 (outputSchema in PaymentRequirements).
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Validation result for discovery extensions
|
|
404
|
+
*/
|
|
405
|
+
interface ValidationResult {
|
|
406
|
+
valid: boolean;
|
|
407
|
+
errors?: string[];
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Validates a discovery extension's info against its schema
|
|
411
|
+
*
|
|
412
|
+
* @param extension - The discovery extension containing info and schema
|
|
413
|
+
* @returns Validation result indicating if the info matches the schema
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* const extension = declareDiscoveryExtension(...);
|
|
418
|
+
* const result = validateDiscoveryExtension(extension);
|
|
419
|
+
*
|
|
420
|
+
* if (result.valid) {
|
|
421
|
+
* console.log("Extension is valid");
|
|
422
|
+
* } else {
|
|
423
|
+
* console.error("Validation errors:", result.errors);
|
|
424
|
+
* }
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
declare function validateDiscoveryExtension(extension: DiscoveryExtension): ValidationResult;
|
|
428
|
+
|
|
429
|
+
type DiscoveredResource = DiscoveredHTTPResource | DiscoveredMCPResource;
|
|
430
|
+
/**
|
|
431
|
+
* Extracts discovery information from payment payload and requirements.
|
|
432
|
+
* Combines resource URL, HTTP method, version, and discovery info into a single object.
|
|
433
|
+
*
|
|
434
|
+
* @param paymentPayload - The payment payload containing extensions and resource info
|
|
435
|
+
* @param paymentRequirements - The payment requirements to validate against
|
|
436
|
+
* @param validate - Whether to validate the discovery info against the schema (default: true)
|
|
437
|
+
* @returns Discovered resource info with URL, method, version and discovery data, or null if not found
|
|
438
|
+
*/
|
|
439
|
+
declare function extractDiscoveryInfo(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements | PaymentRequirementsV1, validate?: boolean): DiscoveredResource | null;
|
|
440
|
+
/**
|
|
441
|
+
* Extracts discovery info from a v2 extension directly
|
|
442
|
+
*
|
|
443
|
+
* This is a lower-level function for when you already have the extension object.
|
|
444
|
+
* For general use, prefer the main extractDiscoveryInfo function.
|
|
445
|
+
*
|
|
446
|
+
* @param extension - The discovery extension to extract info from
|
|
447
|
+
* @param validate - Whether to validate before extracting (default: true)
|
|
448
|
+
* @returns The discovery info if valid
|
|
449
|
+
* @throws Error if validation fails and validate is true
|
|
450
|
+
*/
|
|
451
|
+
declare function extractDiscoveryInfoFromExtension(extension: DiscoveryExtension, validate?: boolean): DiscoveryInfo;
|
|
452
|
+
/**
|
|
453
|
+
* Validates and extracts discovery info in one step
|
|
454
|
+
*
|
|
455
|
+
* This is a convenience function that combines validation and extraction,
|
|
456
|
+
* returning both the validation result and the info if valid.
|
|
457
|
+
*
|
|
458
|
+
* @param extension - The discovery extension to validate and extract
|
|
459
|
+
* @returns Object containing validation result and info (if valid)
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* const extension = declareDiscoveryExtension(...);
|
|
464
|
+
* const { valid, info, errors } = validateAndExtract(extension);
|
|
465
|
+
*
|
|
466
|
+
* if (valid && info) {
|
|
467
|
+
* // Store info in Bazaar catalog
|
|
468
|
+
* } else {
|
|
469
|
+
* console.error("Validation errors:", errors);
|
|
470
|
+
* }
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
declare function validateAndExtract(extension: DiscoveryExtension): {
|
|
474
|
+
valid: boolean;
|
|
475
|
+
info?: DiscoveryInfo;
|
|
476
|
+
errors?: string[];
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* V1 Facilitator functions for extracting Bazaar discovery information
|
|
481
|
+
*
|
|
482
|
+
* In v1, discovery information is stored in the `outputSchema` field
|
|
483
|
+
* of PaymentRequirements, which has a different structure than v2.
|
|
484
|
+
*
|
|
485
|
+
* This module transforms v1 data into v2 DiscoveryInfo format.
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Extracts discovery info from v1 PaymentRequirements and transforms to v2 format
|
|
490
|
+
*
|
|
491
|
+
* In v1, the discovery information is stored in the `outputSchema` field,
|
|
492
|
+
* which contains both input (endpoint shape) and output (response schema) information.
|
|
493
|
+
*
|
|
494
|
+
* This function makes smart assumptions to normalize v1 data into v2 DiscoveryInfo format:
|
|
495
|
+
* - For GET/HEAD/DELETE: Looks for queryParams, query, or params fields
|
|
496
|
+
* - For POST/PUT/PATCH: Looks for bodyFields, body, or data fields and normalizes bodyType
|
|
497
|
+
* - Extracts optional headers if present
|
|
498
|
+
*
|
|
499
|
+
* @param paymentRequirements - V1 payment requirements
|
|
500
|
+
* @returns Discovery info in v2 format if present and valid, or null if not discoverable
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const requirements: PaymentRequirementsV1 = {
|
|
505
|
+
* scheme: "exact",
|
|
506
|
+
* network: "eip155:8453",
|
|
507
|
+
* maxAmountRequired: "100000",
|
|
508
|
+
* resource: "https://api.example.com/data",
|
|
509
|
+
* description: "Get data",
|
|
510
|
+
* mimeType: "application/json",
|
|
511
|
+
* outputSchema: {
|
|
512
|
+
* input: {
|
|
513
|
+
* type: "http",
|
|
514
|
+
* method: "GET",
|
|
515
|
+
* discoverable: true,
|
|
516
|
+
* queryParams: { query: "string" }
|
|
517
|
+
* },
|
|
518
|
+
* output: { type: "object" }
|
|
519
|
+
* },
|
|
520
|
+
* payTo: "0x...",
|
|
521
|
+
* maxTimeoutSeconds: 300,
|
|
522
|
+
* asset: "0x...",
|
|
523
|
+
* extra: {}
|
|
524
|
+
* };
|
|
525
|
+
*
|
|
526
|
+
* const info = extractDiscoveryInfoV1(requirements);
|
|
527
|
+
* if (info) {
|
|
528
|
+
* console.log("Endpoint method:", info.input.method);
|
|
529
|
+
* }
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function extractDiscoveryInfoV1(paymentRequirements: PaymentRequirementsV1): DiscoveryInfo | null;
|
|
533
|
+
/**
|
|
534
|
+
* Checks if v1 PaymentRequirements contains discoverable information
|
|
535
|
+
*
|
|
536
|
+
* @param paymentRequirements - V1 payment requirements
|
|
537
|
+
* @returns True if the requirements contain valid discovery info
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* if (isDiscoverableV1(requirements)) {
|
|
542
|
+
* const info = extractDiscoveryInfoV1(requirements);
|
|
543
|
+
* // Catalog info in Bazaar
|
|
544
|
+
* }
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
declare function isDiscoverableV1(paymentRequirements: PaymentRequirementsV1): boolean;
|
|
548
|
+
/**
|
|
549
|
+
* Extracts resource metadata from v1 PaymentRequirements
|
|
550
|
+
*
|
|
551
|
+
* In v1, resource information is embedded directly in the payment requirements
|
|
552
|
+
* rather than in a separate resource object.
|
|
553
|
+
*
|
|
554
|
+
* @param paymentRequirements - V1 payment requirements
|
|
555
|
+
* @returns Resource metadata
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const metadata = extractResourceMetadataV1(requirements);
|
|
560
|
+
* console.log("Resource URL:", metadata.url);
|
|
561
|
+
* console.log("Description:", metadata.description);
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
declare function extractResourceMetadataV1(paymentRequirements: PaymentRequirementsV1): {
|
|
565
|
+
url: string;
|
|
566
|
+
description: string;
|
|
567
|
+
mimeType: string;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Client extensions for querying Bazaar discovery resources
|
|
572
|
+
*/
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Parameters for listing discovery resources.
|
|
576
|
+
* All parameters are optional and used for filtering/pagination.
|
|
577
|
+
*/
|
|
578
|
+
interface ListDiscoveryResourcesParams {
|
|
579
|
+
/**
|
|
580
|
+
* Filter by protocol type (e.g., "http", "mcp").
|
|
581
|
+
*/
|
|
582
|
+
type?: string;
|
|
583
|
+
/**
|
|
584
|
+
* The number of discovered x402 resources to return per page.
|
|
585
|
+
*/
|
|
586
|
+
limit?: number;
|
|
587
|
+
/**
|
|
588
|
+
* The offset of the first discovered x402 resource to return.
|
|
589
|
+
*/
|
|
590
|
+
offset?: number;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* A discovered x402 resource from the bazaar.
|
|
594
|
+
*/
|
|
595
|
+
interface DiscoveryResource {
|
|
596
|
+
/** The URL or identifier of the discovered resource */
|
|
597
|
+
resource: string;
|
|
598
|
+
/** The protocol type of the resource (e.g., "http") */
|
|
599
|
+
type: string;
|
|
600
|
+
/** The x402 protocol version supported by this resource */
|
|
601
|
+
x402Version: number;
|
|
602
|
+
/** Array of accepted payment methods for this resource */
|
|
603
|
+
accepts: PaymentRequirements[];
|
|
604
|
+
/** ISO 8601 timestamp of when the resource was last updated */
|
|
605
|
+
lastUpdated: string;
|
|
606
|
+
/** Additional metadata about the resource */
|
|
607
|
+
metadata?: Record<string, unknown>;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Response from listing discovery resources.
|
|
611
|
+
*/
|
|
612
|
+
interface DiscoveryResourcesResponse {
|
|
613
|
+
/** The x402 protocol version of this response */
|
|
614
|
+
x402Version: number;
|
|
615
|
+
/** The list of discovered resources */
|
|
616
|
+
items: DiscoveryResource[];
|
|
617
|
+
/** Pagination information for the response */
|
|
618
|
+
pagination: {
|
|
619
|
+
/** Maximum number of results returned */
|
|
620
|
+
limit: number;
|
|
621
|
+
/** Number of results skipped */
|
|
622
|
+
offset: number;
|
|
623
|
+
/** Total count of resources matching the query */
|
|
624
|
+
total: number;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Bazaar client extension interface providing discovery query functionality.
|
|
629
|
+
*/
|
|
630
|
+
interface BazaarClientExtension {
|
|
631
|
+
discovery: {
|
|
632
|
+
/**
|
|
633
|
+
* List x402 discovery resources from the bazaar.
|
|
634
|
+
*
|
|
635
|
+
* @param params - Optional filtering and pagination parameters
|
|
636
|
+
* @returns A promise resolving to the discovery resources response
|
|
637
|
+
*/
|
|
638
|
+
listResources(params?: ListDiscoveryResourcesParams): Promise<DiscoveryResourcesResponse>;
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Extends a facilitator client with Bazaar discovery query functionality.
|
|
643
|
+
* Preserves and merges with any existing extensions from prior chaining.
|
|
644
|
+
*
|
|
645
|
+
* @param client - The facilitator client to extend
|
|
646
|
+
* @returns The client extended with bazaar discovery capabilities
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts
|
|
650
|
+
* // Basic usage
|
|
651
|
+
* const client = withBazaar(new HTTPFacilitatorClient());
|
|
652
|
+
* const resources = await client.extensions.discovery.listResources({ type: "http" });
|
|
653
|
+
*
|
|
654
|
+
* // Chaining with other extensions
|
|
655
|
+
* const client = withBazaar(withOtherExtension(new HTTPFacilitatorClient()));
|
|
656
|
+
* await client.extensions.other.someMethod();
|
|
657
|
+
* await client.extensions.discovery.listResources();
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
declare function withBazaar<T extends HTTPFacilitatorClient>(client: T): WithExtensions<T, BazaarClientExtension>;
|
|
661
|
+
|
|
662
|
+
export { validateAndExtract as A, BAZAAR as B, validateDiscoveryExtension as C, type DeclareBodyDiscoveryExtensionConfig as D, withBazaar as E, type ListDiscoveryResourcesParams as L, type McpDiscoveryExtension as M, type QueryDiscoveryExtension as Q, type ValidationResult as V, type WithExtensions as W, type BazaarClientExtension as a, type BodyDiscoveryExtension as b, type BodyDiscoveryInfo as c, type DeclareDiscoveryExtensionConfig as d, type DeclareDiscoveryExtensionInput as e, type DeclareMcpDiscoveryExtensionConfig as f, type DeclareQueryDiscoveryExtensionConfig as g, type DiscoveredHTTPResource as h, type DiscoveredMCPResource as i, type DiscoveredResource as j, type DiscoveryExtension as k, type DiscoveryInfo as l, type DiscoveryResource as m, type DiscoveryResourcesResponse as n, type McpDiscoveryInfo as o, type QueryDiscoveryInfo as p, bazaarResourceServerExtension as q, declareDiscoveryExtension as r, extractDiscoveryInfo as s, extractDiscoveryInfoFromExtension as t, extractDiscoveryInfoV1 as u, extractResourceMetadataV1 as v, isBodyExtensionConfig as w, isDiscoverableV1 as x, isMcpExtensionConfig as y, isQueryExtensionConfig as z };
|