@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,3 @@
|
|
|
1
|
+
export { B as BAZAAR, a as BazaarClientExtension, b as BodyDiscoveryExtension, c as BodyDiscoveryInfo, D as DeclareBodyDiscoveryExtensionConfig, d as DeclareDiscoveryExtensionConfig, e as DeclareDiscoveryExtensionInput, f as DeclareMcpDiscoveryExtensionConfig, g as DeclareQueryDiscoveryExtensionConfig, h as DiscoveredHTTPResource, i as DiscoveredMCPResource, j as DiscoveredResource, k as DiscoveryExtension, l as DiscoveryInfo, m as DiscoveryResource, n as DiscoveryResourcesResponse, L as ListDiscoveryResourcesParams, M as McpDiscoveryExtension, o as McpDiscoveryInfo, Q as QueryDiscoveryExtension, p as QueryDiscoveryInfo, V as ValidationResult, q as bazaarResourceServerExtension, r as declareDiscoveryExtension, s as extractDiscoveryInfo, t as extractDiscoveryInfoFromExtension, u as extractDiscoveryInfoV1, v as extractResourceMetadataV1, w as isBodyExtensionConfig, x as isDiscoverableV1, y as isMcpExtensionConfig, z as isQueryExtensionConfig, A as validateAndExtract, C as validateDiscoveryExtension, E as withBazaar } from '../index-DPJQYYGe.js';
|
|
2
|
+
import '@bankofai/x402-core/types';
|
|
3
|
+
import '@bankofai/x402-core/http';
|
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/bazaar/index.ts
|
|
31
|
+
var bazaar_exports = {};
|
|
32
|
+
__export(bazaar_exports, {
|
|
33
|
+
BAZAAR: () => BAZAAR,
|
|
34
|
+
bazaarResourceServerExtension: () => bazaarResourceServerExtension,
|
|
35
|
+
declareDiscoveryExtension: () => declareDiscoveryExtension,
|
|
36
|
+
extractDiscoveryInfo: () => extractDiscoveryInfo,
|
|
37
|
+
extractDiscoveryInfoFromExtension: () => extractDiscoveryInfoFromExtension,
|
|
38
|
+
extractDiscoveryInfoV1: () => extractDiscoveryInfoV1,
|
|
39
|
+
extractResourceMetadataV1: () => extractResourceMetadataV1,
|
|
40
|
+
isBodyExtensionConfig: () => isBodyExtensionConfig,
|
|
41
|
+
isDiscoverableV1: () => isDiscoverableV1,
|
|
42
|
+
isMcpExtensionConfig: () => isMcpExtensionConfig,
|
|
43
|
+
isQueryExtensionConfig: () => isQueryExtensionConfig,
|
|
44
|
+
validateAndExtract: () => validateAndExtract,
|
|
45
|
+
validateDiscoveryExtension: () => validateDiscoveryExtension,
|
|
46
|
+
withBazaar: () => withBazaar
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(bazaar_exports);
|
|
49
|
+
|
|
50
|
+
// src/bazaar/http/types.ts
|
|
51
|
+
var isQueryExtensionConfig = (config) => {
|
|
52
|
+
return !("bodyType" in config) && !("toolName" in config);
|
|
53
|
+
};
|
|
54
|
+
var isBodyExtensionConfig = (config) => {
|
|
55
|
+
return "bodyType" in config;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/bazaar/mcp/types.ts
|
|
59
|
+
var isMcpExtensionConfig = (config) => {
|
|
60
|
+
return "toolName" in config;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/bazaar/types.ts
|
|
64
|
+
var BAZAAR = { key: "bazaar" };
|
|
65
|
+
|
|
66
|
+
// src/bazaar/http/resourceService.ts
|
|
67
|
+
function createQueryDiscoveryExtension({
|
|
68
|
+
method,
|
|
69
|
+
input = {},
|
|
70
|
+
inputSchema = { properties: {} },
|
|
71
|
+
output
|
|
72
|
+
}) {
|
|
73
|
+
return {
|
|
74
|
+
info: {
|
|
75
|
+
input: {
|
|
76
|
+
type: "http",
|
|
77
|
+
...method ? { method } : {},
|
|
78
|
+
...input ? { queryParams: input } : {}
|
|
79
|
+
},
|
|
80
|
+
...output?.example ? {
|
|
81
|
+
output: {
|
|
82
|
+
type: "json",
|
|
83
|
+
example: output.example
|
|
84
|
+
}
|
|
85
|
+
} : {}
|
|
86
|
+
},
|
|
87
|
+
schema: {
|
|
88
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
input: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
type: {
|
|
95
|
+
type: "string",
|
|
96
|
+
const: "http"
|
|
97
|
+
},
|
|
98
|
+
method: {
|
|
99
|
+
type: "string",
|
|
100
|
+
enum: ["GET", "HEAD", "DELETE"]
|
|
101
|
+
},
|
|
102
|
+
...inputSchema ? {
|
|
103
|
+
queryParams: {
|
|
104
|
+
type: "object",
|
|
105
|
+
...typeof inputSchema === "object" ? inputSchema : {}
|
|
106
|
+
}
|
|
107
|
+
} : {}
|
|
108
|
+
},
|
|
109
|
+
required: ["type"],
|
|
110
|
+
additionalProperties: false
|
|
111
|
+
},
|
|
112
|
+
...output?.example ? {
|
|
113
|
+
output: {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
type: {
|
|
117
|
+
type: "string"
|
|
118
|
+
},
|
|
119
|
+
example: {
|
|
120
|
+
type: "object",
|
|
121
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
required: ["type"]
|
|
125
|
+
}
|
|
126
|
+
} : {}
|
|
127
|
+
},
|
|
128
|
+
required: ["input"]
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function createBodyDiscoveryExtension({
|
|
133
|
+
method,
|
|
134
|
+
input = {},
|
|
135
|
+
inputSchema = { properties: {} },
|
|
136
|
+
bodyType,
|
|
137
|
+
output
|
|
138
|
+
}) {
|
|
139
|
+
return {
|
|
140
|
+
info: {
|
|
141
|
+
input: {
|
|
142
|
+
type: "http",
|
|
143
|
+
...method ? { method } : {},
|
|
144
|
+
bodyType,
|
|
145
|
+
body: input
|
|
146
|
+
},
|
|
147
|
+
...output?.example ? {
|
|
148
|
+
output: {
|
|
149
|
+
type: "json",
|
|
150
|
+
example: output.example
|
|
151
|
+
}
|
|
152
|
+
} : {}
|
|
153
|
+
},
|
|
154
|
+
schema: {
|
|
155
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
input: {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: {
|
|
161
|
+
type: {
|
|
162
|
+
type: "string",
|
|
163
|
+
const: "http"
|
|
164
|
+
},
|
|
165
|
+
method: {
|
|
166
|
+
type: "string",
|
|
167
|
+
enum: ["POST", "PUT", "PATCH"]
|
|
168
|
+
},
|
|
169
|
+
bodyType: {
|
|
170
|
+
type: "string",
|
|
171
|
+
enum: ["json", "form-data", "text"]
|
|
172
|
+
},
|
|
173
|
+
body: inputSchema
|
|
174
|
+
},
|
|
175
|
+
required: ["type", "bodyType", "body"],
|
|
176
|
+
additionalProperties: false
|
|
177
|
+
},
|
|
178
|
+
...output?.example ? {
|
|
179
|
+
output: {
|
|
180
|
+
type: "object",
|
|
181
|
+
properties: {
|
|
182
|
+
type: {
|
|
183
|
+
type: "string"
|
|
184
|
+
},
|
|
185
|
+
example: {
|
|
186
|
+
type: "object",
|
|
187
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
required: ["type"]
|
|
191
|
+
}
|
|
192
|
+
} : {}
|
|
193
|
+
},
|
|
194
|
+
required: ["input"]
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/bazaar/mcp/resourceService.ts
|
|
200
|
+
function createMcpDiscoveryExtension({
|
|
201
|
+
toolName,
|
|
202
|
+
description,
|
|
203
|
+
transport,
|
|
204
|
+
inputSchema,
|
|
205
|
+
example,
|
|
206
|
+
output
|
|
207
|
+
}) {
|
|
208
|
+
return {
|
|
209
|
+
info: {
|
|
210
|
+
input: {
|
|
211
|
+
type: "mcp",
|
|
212
|
+
toolName,
|
|
213
|
+
...description !== void 0 ? { description } : {},
|
|
214
|
+
...transport !== void 0 ? { transport } : {},
|
|
215
|
+
inputSchema,
|
|
216
|
+
...example !== void 0 ? { example } : {}
|
|
217
|
+
},
|
|
218
|
+
...output?.example ? {
|
|
219
|
+
output: {
|
|
220
|
+
type: "json",
|
|
221
|
+
example: output.example
|
|
222
|
+
}
|
|
223
|
+
} : {}
|
|
224
|
+
},
|
|
225
|
+
schema: {
|
|
226
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
227
|
+
type: "object",
|
|
228
|
+
properties: {
|
|
229
|
+
input: {
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {
|
|
232
|
+
type: {
|
|
233
|
+
type: "string",
|
|
234
|
+
const: "mcp"
|
|
235
|
+
},
|
|
236
|
+
toolName: {
|
|
237
|
+
type: "string"
|
|
238
|
+
},
|
|
239
|
+
...description !== void 0 ? {
|
|
240
|
+
description: {
|
|
241
|
+
type: "string"
|
|
242
|
+
}
|
|
243
|
+
} : {},
|
|
244
|
+
...transport !== void 0 ? {
|
|
245
|
+
transport: {
|
|
246
|
+
type: "string",
|
|
247
|
+
enum: ["streamable-http", "sse"]
|
|
248
|
+
}
|
|
249
|
+
} : {},
|
|
250
|
+
inputSchema: {
|
|
251
|
+
type: "object"
|
|
252
|
+
},
|
|
253
|
+
...example !== void 0 ? {
|
|
254
|
+
example: {
|
|
255
|
+
type: "object"
|
|
256
|
+
}
|
|
257
|
+
} : {}
|
|
258
|
+
},
|
|
259
|
+
required: ["type", "toolName", "inputSchema"],
|
|
260
|
+
additionalProperties: false
|
|
261
|
+
},
|
|
262
|
+
...output?.example ? {
|
|
263
|
+
output: {
|
|
264
|
+
type: "object",
|
|
265
|
+
properties: {
|
|
266
|
+
type: {
|
|
267
|
+
type: "string"
|
|
268
|
+
},
|
|
269
|
+
example: {
|
|
270
|
+
type: "object",
|
|
271
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
required: ["type"]
|
|
275
|
+
}
|
|
276
|
+
} : {}
|
|
277
|
+
},
|
|
278
|
+
required: ["input"]
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/bazaar/resourceService.ts
|
|
284
|
+
function declareDiscoveryExtension(config) {
|
|
285
|
+
if ("toolName" in config) {
|
|
286
|
+
const extension2 = createMcpDiscoveryExtension(config);
|
|
287
|
+
return { bazaar: extension2 };
|
|
288
|
+
}
|
|
289
|
+
const bodyType = config.bodyType;
|
|
290
|
+
const isBodyMethod2 = bodyType !== void 0;
|
|
291
|
+
const extension = isBodyMethod2 ? createBodyDiscoveryExtension(config) : createQueryDiscoveryExtension(config);
|
|
292
|
+
return { bazaar: extension };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/bazaar/server.ts
|
|
296
|
+
function isHTTPRequestContext(ctx) {
|
|
297
|
+
return ctx !== null && typeof ctx === "object" && "method" in ctx && "adapter" in ctx;
|
|
298
|
+
}
|
|
299
|
+
var bazaarResourceServerExtension = {
|
|
300
|
+
key: BAZAAR.key,
|
|
301
|
+
enrichDeclaration: (declaration, transportContext) => {
|
|
302
|
+
if (!isHTTPRequestContext(transportContext)) {
|
|
303
|
+
return declaration;
|
|
304
|
+
}
|
|
305
|
+
const extension = declaration;
|
|
306
|
+
if (extension.info?.input?.type === "mcp") {
|
|
307
|
+
return declaration;
|
|
308
|
+
}
|
|
309
|
+
const method = transportContext.method;
|
|
310
|
+
const existingInputProps = extension.schema?.properties?.input?.properties || {};
|
|
311
|
+
const updatedInputProps = {
|
|
312
|
+
...existingInputProps,
|
|
313
|
+
method: {
|
|
314
|
+
type: "string",
|
|
315
|
+
enum: [method]
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
return {
|
|
319
|
+
...extension,
|
|
320
|
+
info: {
|
|
321
|
+
...extension.info || {},
|
|
322
|
+
input: {
|
|
323
|
+
...extension.info?.input || {},
|
|
324
|
+
method
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
schema: {
|
|
328
|
+
...extension.schema || {},
|
|
329
|
+
properties: {
|
|
330
|
+
...extension.schema?.properties || {},
|
|
331
|
+
input: {
|
|
332
|
+
...extension.schema?.properties?.input || {},
|
|
333
|
+
properties: updatedInputProps,
|
|
334
|
+
required: [
|
|
335
|
+
...extension.schema?.properties?.input?.required || [],
|
|
336
|
+
...!(extension.schema?.properties?.input?.required || []).includes("method") ? ["method"] : []
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/bazaar/facilitator.ts
|
|
346
|
+
var import__ = __toESM(require("ajv/dist/2020.js"));
|
|
347
|
+
|
|
348
|
+
// src/bazaar/v1/facilitator.ts
|
|
349
|
+
function hasV1OutputSchema(obj) {
|
|
350
|
+
return obj !== null && typeof obj === "object" && "input" in obj && obj.input !== null && typeof obj.input === "object" && "type" in obj.input && obj.input.type === "http" && "method" in obj.input;
|
|
351
|
+
}
|
|
352
|
+
function isQueryMethod(method) {
|
|
353
|
+
const upperMethod = method.toUpperCase();
|
|
354
|
+
return upperMethod === "GET" || upperMethod === "HEAD" || upperMethod === "DELETE";
|
|
355
|
+
}
|
|
356
|
+
function isBodyMethod(method) {
|
|
357
|
+
const upperMethod = method.toUpperCase();
|
|
358
|
+
return upperMethod === "POST" || upperMethod === "PUT" || upperMethod === "PATCH";
|
|
359
|
+
}
|
|
360
|
+
function extractQueryParams(v1Input) {
|
|
361
|
+
if (v1Input.queryParams && typeof v1Input.queryParams === "object") {
|
|
362
|
+
return v1Input.queryParams;
|
|
363
|
+
}
|
|
364
|
+
if (v1Input.query_params && typeof v1Input.query_params === "object") {
|
|
365
|
+
return v1Input.query_params;
|
|
366
|
+
}
|
|
367
|
+
if (v1Input.query && typeof v1Input.query === "object") {
|
|
368
|
+
return v1Input.query;
|
|
369
|
+
}
|
|
370
|
+
if (v1Input.params && typeof v1Input.params === "object") {
|
|
371
|
+
return v1Input.params;
|
|
372
|
+
}
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
375
|
+
function extractBodyInfo(v1Input) {
|
|
376
|
+
let bodyType = "json";
|
|
377
|
+
const bodyTypeField = v1Input.bodyType || v1Input.body_type;
|
|
378
|
+
if (bodyTypeField && typeof bodyTypeField === "string") {
|
|
379
|
+
const type = bodyTypeField.toLowerCase();
|
|
380
|
+
if (type.includes("form") || type.includes("multipart")) {
|
|
381
|
+
bodyType = "form-data";
|
|
382
|
+
} else if (type.includes("text") || type.includes("plain")) {
|
|
383
|
+
bodyType = "text";
|
|
384
|
+
} else {
|
|
385
|
+
bodyType = "json";
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
let body = {};
|
|
389
|
+
if (v1Input.bodyFields && typeof v1Input.bodyFields === "object") {
|
|
390
|
+
body = v1Input.bodyFields;
|
|
391
|
+
} else if (v1Input.body_fields && v1Input.body_fields !== null && typeof v1Input.body_fields === "object") {
|
|
392
|
+
body = v1Input.body_fields;
|
|
393
|
+
} else if (v1Input.bodyParams && typeof v1Input.bodyParams === "object") {
|
|
394
|
+
body = v1Input.bodyParams;
|
|
395
|
+
} else if (v1Input.body && typeof v1Input.body === "object") {
|
|
396
|
+
body = v1Input.body;
|
|
397
|
+
} else if (v1Input.data && typeof v1Input.data === "object") {
|
|
398
|
+
body = v1Input.data;
|
|
399
|
+
} else if (v1Input.properties && typeof v1Input.properties === "object") {
|
|
400
|
+
body = v1Input.properties;
|
|
401
|
+
}
|
|
402
|
+
return { body, bodyType };
|
|
403
|
+
}
|
|
404
|
+
function extractDiscoveryInfoV1(paymentRequirements) {
|
|
405
|
+
const { outputSchema } = paymentRequirements;
|
|
406
|
+
if (!outputSchema || !hasV1OutputSchema(outputSchema)) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
const v1Input = outputSchema.input;
|
|
410
|
+
const isDiscoverable = v1Input.discoverable ?? true;
|
|
411
|
+
if (!isDiscoverable) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
const method = typeof v1Input.method === "string" ? v1Input.method.toUpperCase() : "";
|
|
415
|
+
const headersRaw = v1Input.headerFields || v1Input.header_fields || v1Input.headers;
|
|
416
|
+
const headers = headersRaw && typeof headersRaw === "object" ? headersRaw : void 0;
|
|
417
|
+
const output = outputSchema.output ? {
|
|
418
|
+
type: "json",
|
|
419
|
+
example: outputSchema.output
|
|
420
|
+
} : void 0;
|
|
421
|
+
if (isQueryMethod(method)) {
|
|
422
|
+
const queryParams = extractQueryParams(v1Input);
|
|
423
|
+
const discoveryInfo = {
|
|
424
|
+
input: {
|
|
425
|
+
type: "http",
|
|
426
|
+
method,
|
|
427
|
+
...queryParams ? { queryParams } : {},
|
|
428
|
+
...headers ? { headers } : {}
|
|
429
|
+
},
|
|
430
|
+
...output ? { output } : {}
|
|
431
|
+
};
|
|
432
|
+
return discoveryInfo;
|
|
433
|
+
} else if (isBodyMethod(method)) {
|
|
434
|
+
const { body, bodyType } = extractBodyInfo(v1Input);
|
|
435
|
+
const queryParams = extractQueryParams(v1Input);
|
|
436
|
+
const discoveryInfo = {
|
|
437
|
+
input: {
|
|
438
|
+
type: "http",
|
|
439
|
+
method,
|
|
440
|
+
bodyType,
|
|
441
|
+
body,
|
|
442
|
+
...queryParams ? { queryParams } : {},
|
|
443
|
+
...headers ? { headers } : {}
|
|
444
|
+
},
|
|
445
|
+
...output ? { output } : {}
|
|
446
|
+
};
|
|
447
|
+
return discoveryInfo;
|
|
448
|
+
}
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
function isDiscoverableV1(paymentRequirements) {
|
|
452
|
+
return extractDiscoveryInfoV1(paymentRequirements) !== null;
|
|
453
|
+
}
|
|
454
|
+
function extractResourceMetadataV1(paymentRequirements) {
|
|
455
|
+
return {
|
|
456
|
+
url: paymentRequirements.resource,
|
|
457
|
+
description: paymentRequirements.description,
|
|
458
|
+
mimeType: paymentRequirements.mimeType
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/bazaar/facilitator.ts
|
|
463
|
+
function validateDiscoveryExtension(extension) {
|
|
464
|
+
try {
|
|
465
|
+
const ajv = new import__.default({ strict: false, allErrors: true });
|
|
466
|
+
const validate = ajv.compile(extension.schema);
|
|
467
|
+
const valid = validate(extension.info);
|
|
468
|
+
if (valid) {
|
|
469
|
+
return { valid: true };
|
|
470
|
+
}
|
|
471
|
+
const errors = validate.errors?.map((err) => {
|
|
472
|
+
const path = err.instancePath || "(root)";
|
|
473
|
+
return `${path}: ${err.message}`;
|
|
474
|
+
}) || ["Unknown validation error"];
|
|
475
|
+
return { valid: false, errors };
|
|
476
|
+
} catch (error) {
|
|
477
|
+
return {
|
|
478
|
+
valid: false,
|
|
479
|
+
errors: [
|
|
480
|
+
`Schema validation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
481
|
+
]
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function extractDiscoveryInfo(paymentPayload, paymentRequirements, validate = true) {
|
|
486
|
+
let discoveryInfo = null;
|
|
487
|
+
let resourceUrl;
|
|
488
|
+
if (paymentPayload.x402Version === 2) {
|
|
489
|
+
resourceUrl = paymentPayload.resource?.url ?? "";
|
|
490
|
+
if (paymentPayload.extensions) {
|
|
491
|
+
const bazaarExtension = paymentPayload.extensions[BAZAAR.key];
|
|
492
|
+
if (bazaarExtension && typeof bazaarExtension === "object") {
|
|
493
|
+
try {
|
|
494
|
+
const extension = bazaarExtension;
|
|
495
|
+
if (validate) {
|
|
496
|
+
const result = validateDiscoveryExtension(extension);
|
|
497
|
+
if (!result.valid) {
|
|
498
|
+
console.warn(
|
|
499
|
+
`V2 discovery extension validation failed: ${result.errors?.join(", ")}`
|
|
500
|
+
);
|
|
501
|
+
} else {
|
|
502
|
+
discoveryInfo = extension.info;
|
|
503
|
+
}
|
|
504
|
+
} else {
|
|
505
|
+
discoveryInfo = extension.info;
|
|
506
|
+
}
|
|
507
|
+
} catch (error) {
|
|
508
|
+
console.warn(`V2 discovery extension extraction failed: ${error}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
} else if (paymentPayload.x402Version === 1) {
|
|
513
|
+
const requirementsV1 = paymentRequirements;
|
|
514
|
+
resourceUrl = requirementsV1.resource;
|
|
515
|
+
discoveryInfo = extractDiscoveryInfoV1(requirementsV1);
|
|
516
|
+
} else {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
if (!discoveryInfo) {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
const url = new URL(resourceUrl);
|
|
523
|
+
const normalizedResourceUrl = `${url.origin}${url.pathname}`;
|
|
524
|
+
let description;
|
|
525
|
+
let mimeType;
|
|
526
|
+
if (paymentPayload.x402Version === 2) {
|
|
527
|
+
description = paymentPayload.resource?.description;
|
|
528
|
+
mimeType = paymentPayload.resource?.mimeType;
|
|
529
|
+
} else if (paymentPayload.x402Version === 1) {
|
|
530
|
+
const requirementsV1 = paymentRequirements;
|
|
531
|
+
description = requirementsV1.description;
|
|
532
|
+
mimeType = requirementsV1.mimeType;
|
|
533
|
+
}
|
|
534
|
+
const base = {
|
|
535
|
+
resourceUrl: normalizedResourceUrl,
|
|
536
|
+
description,
|
|
537
|
+
mimeType,
|
|
538
|
+
x402Version: paymentPayload.x402Version,
|
|
539
|
+
discoveryInfo
|
|
540
|
+
};
|
|
541
|
+
if (discoveryInfo.input.type === "mcp") {
|
|
542
|
+
return { ...base, toolName: discoveryInfo.input.toolName };
|
|
543
|
+
}
|
|
544
|
+
return { ...base, method: discoveryInfo.input.method };
|
|
545
|
+
}
|
|
546
|
+
function extractDiscoveryInfoFromExtension(extension, validate = true) {
|
|
547
|
+
if (validate) {
|
|
548
|
+
const result = validateDiscoveryExtension(extension);
|
|
549
|
+
if (!result.valid) {
|
|
550
|
+
throw new Error(
|
|
551
|
+
`Invalid discovery extension: ${result.errors?.join(", ") || "Unknown error"}`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return extension.info;
|
|
556
|
+
}
|
|
557
|
+
function validateAndExtract(extension) {
|
|
558
|
+
const result = validateDiscoveryExtension(extension);
|
|
559
|
+
if (result.valid) {
|
|
560
|
+
return {
|
|
561
|
+
valid: true,
|
|
562
|
+
info: extension.info
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
valid: false,
|
|
567
|
+
errors: result.errors
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/bazaar/facilitatorClient.ts
|
|
572
|
+
function withBazaar(client) {
|
|
573
|
+
const existingExtensions = client.extensions ?? {};
|
|
574
|
+
const extended = client;
|
|
575
|
+
extended.extensions = {
|
|
576
|
+
...existingExtensions,
|
|
577
|
+
discovery: {
|
|
578
|
+
async listResources(params) {
|
|
579
|
+
let headers = {
|
|
580
|
+
"Content-Type": "application/json"
|
|
581
|
+
};
|
|
582
|
+
const authHeaders = await client.createAuthHeaders("discovery");
|
|
583
|
+
headers = { ...headers, ...authHeaders.headers };
|
|
584
|
+
const queryParams = new URLSearchParams();
|
|
585
|
+
if (params?.type !== void 0) {
|
|
586
|
+
queryParams.set("type", params.type);
|
|
587
|
+
}
|
|
588
|
+
if (params?.limit !== void 0) {
|
|
589
|
+
queryParams.set("limit", params.limit.toString());
|
|
590
|
+
}
|
|
591
|
+
if (params?.offset !== void 0) {
|
|
592
|
+
queryParams.set("offset", params.offset.toString());
|
|
593
|
+
}
|
|
594
|
+
const queryString = queryParams.toString();
|
|
595
|
+
const endpoint = `${client.url}/discovery/resources${queryString ? `?${queryString}` : ""}`;
|
|
596
|
+
const response = await fetch(endpoint, {
|
|
597
|
+
method: "GET",
|
|
598
|
+
headers
|
|
599
|
+
});
|
|
600
|
+
if (!response.ok) {
|
|
601
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
602
|
+
throw new Error(
|
|
603
|
+
`Facilitator listDiscoveryResources failed (${response.status}): ${errorText}`
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
return await response.json();
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
return extended;
|
|
611
|
+
}
|
|
612
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
613
|
+
0 && (module.exports = {
|
|
614
|
+
BAZAAR,
|
|
615
|
+
bazaarResourceServerExtension,
|
|
616
|
+
declareDiscoveryExtension,
|
|
617
|
+
extractDiscoveryInfo,
|
|
618
|
+
extractDiscoveryInfoFromExtension,
|
|
619
|
+
extractDiscoveryInfoV1,
|
|
620
|
+
extractResourceMetadataV1,
|
|
621
|
+
isBodyExtensionConfig,
|
|
622
|
+
isDiscoverableV1,
|
|
623
|
+
isMcpExtensionConfig,
|
|
624
|
+
isQueryExtensionConfig,
|
|
625
|
+
validateAndExtract,
|
|
626
|
+
validateDiscoveryExtension,
|
|
627
|
+
withBazaar
|
|
628
|
+
});
|
|
629
|
+
//# sourceMappingURL=index.js.map
|