@agentcash/discovery 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +180 -24
- package/dist/cli.js +180 -24
- package/dist/index.cjs +183 -22
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +181 -22
- package/dist/schemas.cjs +2 -1
- package/dist/schemas.d.cts +1 -0
- package/dist/schemas.d.ts +1 -0
- package/dist/schemas.js +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -44,6 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
getL3: () => getL3,
|
|
45
45
|
getL3ForOpenAPI: () => getL3ForOpenAPI,
|
|
46
46
|
getL3ForProbe: () => getL3ForProbe,
|
|
47
|
+
getMppWellKnown: () => getMppWellKnown,
|
|
47
48
|
getOpenAPI: () => getOpenAPI,
|
|
48
49
|
getProbe: () => getProbe,
|
|
49
50
|
getWarningsFor402Body: () => getWarningsFor402Body,
|
|
@@ -54,6 +55,7 @@ __export(index_exports, {
|
|
|
54
55
|
getWarningsForOpenAPI: () => getWarningsForOpenAPI,
|
|
55
56
|
getWarningsForWellKnown: () => getWarningsForWellKnown,
|
|
56
57
|
getWellKnown: () => getWellKnown,
|
|
58
|
+
getX402WellKnown: () => getX402WellKnown,
|
|
57
59
|
validatePaymentRequiredDetailed: () => validatePaymentRequiredDetailed
|
|
58
60
|
});
|
|
59
61
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -13896,7 +13898,8 @@ var WellKnownParsedSchema = external_exports.object({
|
|
|
13896
13898
|
routes: external_exports.array(
|
|
13897
13899
|
external_exports.object({
|
|
13898
13900
|
path: external_exports.string(),
|
|
13899
|
-
method: external_exports.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE"])
|
|
13901
|
+
method: external_exports.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE"]),
|
|
13902
|
+
price: external_exports.string().optional()
|
|
13900
13903
|
})
|
|
13901
13904
|
),
|
|
13902
13905
|
instructions: external_exports.string().optional()
|
|
@@ -13989,9 +13992,9 @@ function toAbsoluteUrl(origin, value) {
|
|
|
13989
13992
|
|
|
13990
13993
|
// src/core/source/fetch.ts
|
|
13991
13994
|
var import_neverthrow = require("neverthrow");
|
|
13992
|
-
function toFetchError(
|
|
13993
|
-
const cause =
|
|
13994
|
-
return { cause, message: String(
|
|
13995
|
+
function toFetchError(err2) {
|
|
13996
|
+
const cause = err2 instanceof DOMException && (err2.name === "TimeoutError" || err2.name === "AbortError") ? "timeout" : "network";
|
|
13997
|
+
return { cause, message: String(err2) };
|
|
13995
13998
|
}
|
|
13996
13999
|
function fetchSafe(url2, init) {
|
|
13997
14000
|
return import_neverthrow.ResultAsync.fromPromise(fetch(url2, init), toFetchError);
|
|
@@ -14057,6 +14060,9 @@ function getOpenAPI(origin, headers, signal, specificationOverrideUrl) {
|
|
|
14057
14060
|
}
|
|
14058
14061
|
|
|
14059
14062
|
// src/core/source/wellknown/index.ts
|
|
14063
|
+
var import_neverthrow5 = require("neverthrow");
|
|
14064
|
+
|
|
14065
|
+
// src/core/source/wellknown/x402.ts
|
|
14060
14066
|
var import_neverthrow3 = require("neverthrow");
|
|
14061
14067
|
function toWellKnownParsed(origin, doc) {
|
|
14062
14068
|
const routes = doc.resources.flatMap((entry) => {
|
|
@@ -14083,12 +14089,17 @@ async function parseBody2(response, origin, url2) {
|
|
|
14083
14089
|
if (!doc.success) return null;
|
|
14084
14090
|
const parsed = WellKnownParsedSchema.safeParse(toWellKnownParsed(origin, doc.data));
|
|
14085
14091
|
if (!parsed.success) return null;
|
|
14086
|
-
return {
|
|
14092
|
+
return {
|
|
14093
|
+
raw: payload,
|
|
14094
|
+
...parsed.data,
|
|
14095
|
+
protocol: "x402",
|
|
14096
|
+
fetchedUrl: url2
|
|
14097
|
+
};
|
|
14087
14098
|
} catch {
|
|
14088
14099
|
return null;
|
|
14089
14100
|
}
|
|
14090
14101
|
}
|
|
14091
|
-
function
|
|
14102
|
+
function getX402WellKnown(origin, headers, signal) {
|
|
14092
14103
|
const url2 = `${origin}/.well-known/x402`;
|
|
14093
14104
|
return fetchSafe(url2, {
|
|
14094
14105
|
method: "GET",
|
|
@@ -14100,6 +14111,127 @@ function getWellKnown(origin, headers, signal) {
|
|
|
14100
14111
|
});
|
|
14101
14112
|
}
|
|
14102
14113
|
|
|
14114
|
+
// src/core/source/wellknown/mpp.ts
|
|
14115
|
+
var import_neverthrow4 = require("neverthrow");
|
|
14116
|
+
var MppEndpointSchema = external_exports.object({
|
|
14117
|
+
method: external_exports.string(),
|
|
14118
|
+
path: external_exports.string(),
|
|
14119
|
+
description: external_exports.string().optional(),
|
|
14120
|
+
payment: external_exports.object({
|
|
14121
|
+
intent: external_exports.string().optional(),
|
|
14122
|
+
method: external_exports.string().optional(),
|
|
14123
|
+
amount: external_exports.string().optional(),
|
|
14124
|
+
currency: external_exports.string().optional()
|
|
14125
|
+
}).optional()
|
|
14126
|
+
});
|
|
14127
|
+
var MppWellKnownDocSchema = external_exports.object({
|
|
14128
|
+
version: external_exports.number().optional(),
|
|
14129
|
+
name: external_exports.string().optional(),
|
|
14130
|
+
description: external_exports.string().optional(),
|
|
14131
|
+
categories: external_exports.array(external_exports.string()).optional(),
|
|
14132
|
+
methods: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
14133
|
+
endpoints: external_exports.array(MppEndpointSchema).default([]),
|
|
14134
|
+
docs: external_exports.object({
|
|
14135
|
+
homepage: external_exports.string().optional(),
|
|
14136
|
+
apiReference: external_exports.string().optional()
|
|
14137
|
+
}).optional()
|
|
14138
|
+
});
|
|
14139
|
+
var MPP_DECIMALS = 6;
|
|
14140
|
+
function formatMppAmount(raw) {
|
|
14141
|
+
if (!raw) return void 0;
|
|
14142
|
+
const n = Number(raw);
|
|
14143
|
+
if (!Number.isFinite(n)) return void 0;
|
|
14144
|
+
return `$${(n / 10 ** MPP_DECIMALS).toFixed(MPP_DECIMALS)}`;
|
|
14145
|
+
}
|
|
14146
|
+
function toWellKnownParsed2(doc) {
|
|
14147
|
+
const routes = doc.endpoints.flatMap((entry) => {
|
|
14148
|
+
const method = parseMethod(entry.method);
|
|
14149
|
+
if (!method) return [];
|
|
14150
|
+
const path = normalizePath(entry.path);
|
|
14151
|
+
if (!path) return [];
|
|
14152
|
+
const price = formatMppAmount(entry.payment?.amount);
|
|
14153
|
+
return [{ path, method, ...price ? { price } : {} }];
|
|
14154
|
+
});
|
|
14155
|
+
return {
|
|
14156
|
+
routes,
|
|
14157
|
+
...doc.description ? { instructions: doc.description } : {}
|
|
14158
|
+
};
|
|
14159
|
+
}
|
|
14160
|
+
async function parseBody3(response, url2) {
|
|
14161
|
+
try {
|
|
14162
|
+
const payload = await response.json();
|
|
14163
|
+
const doc = MppWellKnownDocSchema.safeParse(payload);
|
|
14164
|
+
if (!doc.success) return null;
|
|
14165
|
+
const parsed = WellKnownParsedSchema.safeParse(toWellKnownParsed2(doc.data));
|
|
14166
|
+
if (!parsed.success) return null;
|
|
14167
|
+
return {
|
|
14168
|
+
raw: payload,
|
|
14169
|
+
...parsed.data,
|
|
14170
|
+
...doc.data.name ? { title: doc.data.name } : {},
|
|
14171
|
+
...doc.data.description ? { description: doc.data.description } : {},
|
|
14172
|
+
protocol: "mpp",
|
|
14173
|
+
fetchedUrl: url2
|
|
14174
|
+
};
|
|
14175
|
+
} catch {
|
|
14176
|
+
return null;
|
|
14177
|
+
}
|
|
14178
|
+
}
|
|
14179
|
+
function getMppWellKnown(origin, headers, signal) {
|
|
14180
|
+
const url2 = `${origin}/.well-known/mpp`;
|
|
14181
|
+
return fetchSafe(url2, {
|
|
14182
|
+
method: "GET",
|
|
14183
|
+
headers: { Accept: "application/json", ...headers },
|
|
14184
|
+
signal
|
|
14185
|
+
}).andThen((response) => {
|
|
14186
|
+
if (!response.ok) return (0, import_neverthrow4.okAsync)(null);
|
|
14187
|
+
return import_neverthrow4.ResultAsync.fromSafePromise(parseBody3(response, url2));
|
|
14188
|
+
});
|
|
14189
|
+
}
|
|
14190
|
+
|
|
14191
|
+
// src/core/source/wellknown/index.ts
|
|
14192
|
+
function mergeError(a, b) {
|
|
14193
|
+
return {
|
|
14194
|
+
cause: a.cause === "network" || b.cause === "network" ? "network" : "timeout",
|
|
14195
|
+
message: `x402: ${a.message} | mpp: ${b.message}`
|
|
14196
|
+
};
|
|
14197
|
+
}
|
|
14198
|
+
function merge2(x402, mpp) {
|
|
14199
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14200
|
+
const routes = [...x402.routes, ...mpp.routes].filter((r) => {
|
|
14201
|
+
const key = `${r.method} ${r.path}`;
|
|
14202
|
+
if (seen.has(key)) return false;
|
|
14203
|
+
seen.add(key);
|
|
14204
|
+
return true;
|
|
14205
|
+
});
|
|
14206
|
+
return {
|
|
14207
|
+
raw: { ...mpp.raw, ...x402.raw },
|
|
14208
|
+
routes,
|
|
14209
|
+
protocol: "x402+mpp",
|
|
14210
|
+
// Prefer x402 instructions; fall back to mpp
|
|
14211
|
+
...x402.instructions || mpp.instructions ? { instructions: x402.instructions ?? mpp.instructions } : {},
|
|
14212
|
+
fetchedUrl: x402.fetchedUrl
|
|
14213
|
+
};
|
|
14214
|
+
}
|
|
14215
|
+
function getWellKnown(origin, headers, signal) {
|
|
14216
|
+
return new import_neverthrow5.ResultAsync(
|
|
14217
|
+
Promise.all([
|
|
14218
|
+
getX402WellKnown(origin, headers, signal),
|
|
14219
|
+
getMppWellKnown(origin, headers, signal)
|
|
14220
|
+
]).then(([x402Result, mppResult]) => {
|
|
14221
|
+
const x402 = x402Result.isOk() ? x402Result.value : null;
|
|
14222
|
+
const mpp = mppResult.isOk() ? mppResult.value : null;
|
|
14223
|
+
if (x402 && mpp) return (0, import_neverthrow5.ok)(merge2(x402, mpp));
|
|
14224
|
+
if (x402) return (0, import_neverthrow5.ok)(x402);
|
|
14225
|
+
if (mpp) return (0, import_neverthrow5.ok)(mpp);
|
|
14226
|
+
if (x402Result.isErr() && mppResult.isErr())
|
|
14227
|
+
return (0, import_neverthrow5.err)(mergeError(x402Result.error, mppResult.error));
|
|
14228
|
+
if (x402Result.isErr()) return (0, import_neverthrow5.err)(x402Result.error);
|
|
14229
|
+
if (mppResult.isErr()) return (0, import_neverthrow5.err)(mppResult.error);
|
|
14230
|
+
return (0, import_neverthrow5.ok)(null);
|
|
14231
|
+
})
|
|
14232
|
+
);
|
|
14233
|
+
}
|
|
14234
|
+
|
|
14103
14235
|
// src/core/layers/l2.ts
|
|
14104
14236
|
function formatPrice(pricing) {
|
|
14105
14237
|
if (pricing.pricingMode === "fixed") return `$${pricing.price}`;
|
|
@@ -14125,15 +14257,27 @@ function checkL2ForOpenAPI(openApi) {
|
|
|
14125
14257
|
source: "openapi"
|
|
14126
14258
|
};
|
|
14127
14259
|
}
|
|
14260
|
+
var WELL_KNOWN_PROTOCOLS = {
|
|
14261
|
+
x402: ["x402"],
|
|
14262
|
+
mpp: ["mpp"],
|
|
14263
|
+
"x402+mpp": ["x402", "mpp"]
|
|
14264
|
+
};
|
|
14128
14265
|
function checkL2ForWellknown(wellKnown) {
|
|
14266
|
+
const protocols = WELL_KNOWN_PROTOCOLS[wellKnown.protocol];
|
|
14129
14267
|
const routes = wellKnown.routes.map((route) => ({
|
|
14130
14268
|
path: route.path,
|
|
14131
14269
|
method: route.method,
|
|
14132
14270
|
summary: `${route.method} ${route.path}`,
|
|
14133
14271
|
authMode: "paid",
|
|
14134
|
-
protocols
|
|
14272
|
+
protocols,
|
|
14273
|
+
...route.price ? { price: route.price } : {}
|
|
14135
14274
|
}));
|
|
14136
|
-
return {
|
|
14275
|
+
return {
|
|
14276
|
+
...wellKnown.title ? { title: wellKnown.title } : {},
|
|
14277
|
+
...wellKnown.description ? { description: wellKnown.description } : {},
|
|
14278
|
+
routes,
|
|
14279
|
+
source: `well-known/${wellKnown.protocol}`
|
|
14280
|
+
};
|
|
14137
14281
|
}
|
|
14138
14282
|
|
|
14139
14283
|
// src/core/layers/l4.ts
|
|
@@ -14145,7 +14289,7 @@ function checkL4ForOpenAPI(openApi) {
|
|
|
14145
14289
|
}
|
|
14146
14290
|
function checkL4ForWellknown(wellKnown) {
|
|
14147
14291
|
if (wellKnown.instructions) {
|
|
14148
|
-
return { guidance: wellKnown.instructions, source:
|
|
14292
|
+
return { guidance: wellKnown.instructions, source: `well-known/${wellKnown.protocol}` };
|
|
14149
14293
|
}
|
|
14150
14294
|
return null;
|
|
14151
14295
|
}
|
|
@@ -14218,14 +14362,20 @@ async function discoverOriginSchema(options) {
|
|
|
14218
14362
|
const base = {
|
|
14219
14363
|
found: true,
|
|
14220
14364
|
origin,
|
|
14221
|
-
source:
|
|
14365
|
+
source: l2.source,
|
|
14366
|
+
...l2.title ? {
|
|
14367
|
+
info: {
|
|
14368
|
+
title: l2.title,
|
|
14369
|
+
...l2.description ? { description: l2.description } : {}
|
|
14370
|
+
}
|
|
14371
|
+
} : {},
|
|
14222
14372
|
endpoints: l2.routes
|
|
14223
14373
|
};
|
|
14224
14374
|
return withGuidance(base, l4, guidanceMode);
|
|
14225
14375
|
}
|
|
14226
14376
|
|
|
14227
14377
|
// src/core/source/probe/index.ts
|
|
14228
|
-
var
|
|
14378
|
+
var import_neverthrow6 = require("neverthrow");
|
|
14229
14379
|
|
|
14230
14380
|
// src/core/protocols/x402/v1/schema.ts
|
|
14231
14381
|
function extractSchemas(accepts) {
|
|
@@ -14675,8 +14825,8 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
14675
14825
|
...hasBody ? { body: JSON.stringify(inputBody) } : {},
|
|
14676
14826
|
signal
|
|
14677
14827
|
}).andThen((response) => {
|
|
14678
|
-
if (!isUsableStatus(response.status)) return
|
|
14679
|
-
return
|
|
14828
|
+
if (!isUsableStatus(response.status)) return import_neverthrow6.ResultAsync.fromSafePromise(Promise.resolve(null));
|
|
14829
|
+
return import_neverthrow6.ResultAsync.fromSafePromise(
|
|
14680
14830
|
(async () => {
|
|
14681
14831
|
let authHint = response.status === 402 ? "paid" : "unprotected";
|
|
14682
14832
|
let paymentRequiredBody;
|
|
@@ -14707,7 +14857,7 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
14707
14857
|
}
|
|
14708
14858
|
function getProbe(url2, headers, signal, inputBody) {
|
|
14709
14859
|
const path = normalizePath(new URL(url2).pathname || "/");
|
|
14710
|
-
return
|
|
14860
|
+
return import_neverthrow6.ResultAsync.fromSafePromise(
|
|
14711
14861
|
Promise.all(
|
|
14712
14862
|
[...HTTP_METHODS].map(
|
|
14713
14863
|
(method) => probeMethod(url2, method, path, headers, signal, inputBody).match(
|
|
@@ -14720,6 +14870,20 @@ function getProbe(url2, headers, signal, inputBody) {
|
|
|
14720
14870
|
}
|
|
14721
14871
|
|
|
14722
14872
|
// src/core/protocols/mpp/index.ts
|
|
14873
|
+
var import_neverthrow7 = require("neverthrow");
|
|
14874
|
+
function parseBase64Json(encoded) {
|
|
14875
|
+
return import_neverthrow7.Result.fromThrowable(
|
|
14876
|
+
() => {
|
|
14877
|
+
const decoded = typeof Buffer !== "undefined" ? Buffer.from(encoded, "base64").toString("utf8") : atob(encoded);
|
|
14878
|
+
const parsed = JSON.parse(decoded);
|
|
14879
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
14880
|
+
throw new Error("not an object");
|
|
14881
|
+
}
|
|
14882
|
+
return parsed;
|
|
14883
|
+
},
|
|
14884
|
+
(e) => e
|
|
14885
|
+
)();
|
|
14886
|
+
}
|
|
14723
14887
|
var TEMPO_DEFAULT_CHAIN_ID = 4217;
|
|
14724
14888
|
function parseAuthParams(segment) {
|
|
14725
14889
|
const params = {};
|
|
@@ -14742,14 +14906,9 @@ function extractPaymentOptions4(wwwAuthenticate) {
|
|
|
14742
14906
|
const description = params["description"];
|
|
14743
14907
|
const requestStr = params["request"];
|
|
14744
14908
|
if (!paymentMethod || !intent || !realm || !requestStr) continue;
|
|
14745
|
-
|
|
14746
|
-
|
|
14747
|
-
|
|
14748
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
14749
|
-
request = parsed;
|
|
14750
|
-
} catch {
|
|
14751
|
-
continue;
|
|
14752
|
-
}
|
|
14909
|
+
const requestResult = parseBase64Json(requestStr);
|
|
14910
|
+
if (requestResult.isErr()) continue;
|
|
14911
|
+
const request = requestResult.value;
|
|
14753
14912
|
const asset = typeof request["currency"] === "string" ? request["currency"] : void 0;
|
|
14754
14913
|
const amountRaw = request["amount"];
|
|
14755
14914
|
const amount = typeof amountRaw === "string" ? amountRaw : typeof amountRaw === "number" ? String(amountRaw) : void 0;
|
|
@@ -15738,6 +15897,7 @@ function getWarningsForL4(l4) {
|
|
|
15738
15897
|
getL3,
|
|
15739
15898
|
getL3ForOpenAPI,
|
|
15740
15899
|
getL3ForProbe,
|
|
15900
|
+
getMppWellKnown,
|
|
15741
15901
|
getOpenAPI,
|
|
15742
15902
|
getProbe,
|
|
15743
15903
|
getWarningsFor402Body,
|
|
@@ -15748,5 +15908,6 @@ function getWarningsForL4(l4) {
|
|
|
15748
15908
|
getWarningsForOpenAPI,
|
|
15749
15909
|
getWarningsForWellKnown,
|
|
15750
15910
|
getWellKnown,
|
|
15911
|
+
getX402WellKnown,
|
|
15751
15912
|
validatePaymentRequiredDetailed
|
|
15752
15913
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -89,12 +89,18 @@ interface OpenApiRoute {
|
|
|
89
89
|
interface WellKnownSource {
|
|
90
90
|
raw: Record<string, unknown>;
|
|
91
91
|
routes: WellKnownRoute[];
|
|
92
|
+
title?: string;
|
|
93
|
+
description?: string;
|
|
92
94
|
instructions?: string;
|
|
93
95
|
fetchedUrl: string;
|
|
96
|
+
/** Which well-known document(s) this source was built from. */
|
|
97
|
+
protocol: 'x402' | 'mpp' | 'x402+mpp';
|
|
94
98
|
}
|
|
95
99
|
interface WellKnownRoute {
|
|
96
100
|
path: string;
|
|
97
101
|
method: HttpMethod;
|
|
102
|
+
/** Raw price hint from the well-known document (e.g. MPP `payment.amount`). */
|
|
103
|
+
price?: string;
|
|
98
104
|
}
|
|
99
105
|
interface ProbeResult {
|
|
100
106
|
path: string;
|
|
@@ -111,7 +117,7 @@ interface L2Result {
|
|
|
111
117
|
description?: string;
|
|
112
118
|
version?: string;
|
|
113
119
|
routes: L2Route[];
|
|
114
|
-
source: 'openapi' | 'well-known/x402' | null;
|
|
120
|
+
source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp' | null;
|
|
115
121
|
}
|
|
116
122
|
interface L2Route {
|
|
117
123
|
path: string;
|
|
@@ -145,7 +151,7 @@ interface L3Result {
|
|
|
145
151
|
}
|
|
146
152
|
interface L4Result {
|
|
147
153
|
guidance: string;
|
|
148
|
-
source: 'openapi' | 'well-known/x402';
|
|
154
|
+
source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp';
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
declare enum GuidanceMode {
|
|
@@ -241,8 +247,21 @@ interface FetchError {
|
|
|
241
247
|
|
|
242
248
|
declare function getOpenAPI(origin: string, headers?: Record<string, string>, signal?: AbortSignal, specificationOverrideUrl?: string): ResultAsync<OpenApiSource | null, FetchError>;
|
|
243
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Fetches both `/.well-known/x402` and `/.well-known/mpp` in parallel and merges results.
|
|
252
|
+
*
|
|
253
|
+
* In practice these are mutually exclusive, but if both exist their routes are combined
|
|
254
|
+
* (deduplicated by method+path). x402 wins on instruction/fetchedUrl conflicts.
|
|
255
|
+
*
|
|
256
|
+
* Individual leg failures are treated as "not found" for that leg so valid data from
|
|
257
|
+
* the other is never suppressed. Returns Err(FetchError) only when both legs hard-fail.
|
|
258
|
+
*/
|
|
244
259
|
declare function getWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
245
260
|
|
|
261
|
+
declare function getX402WellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
262
|
+
|
|
263
|
+
declare function getMppWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
264
|
+
|
|
246
265
|
declare function getProbe(url: string, headers?: Record<string, string>, signal?: AbortSignal, inputBody?: Record<string, unknown>): ResultAsync<ProbeResult[], FetchError>;
|
|
247
266
|
|
|
248
267
|
declare function checkL2ForOpenAPI(openApi: OpenApiSource): L2Result;
|
|
@@ -424,4 +443,4 @@ declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
|
|
|
424
443
|
*/
|
|
425
444
|
declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
|
|
426
445
|
|
|
427
|
-
export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };
|
|
446
|
+
export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getMppWellKnown, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, getX402WellKnown, validatePaymentRequiredDetailed };
|
package/dist/index.d.ts
CHANGED
|
@@ -89,12 +89,18 @@ interface OpenApiRoute {
|
|
|
89
89
|
interface WellKnownSource {
|
|
90
90
|
raw: Record<string, unknown>;
|
|
91
91
|
routes: WellKnownRoute[];
|
|
92
|
+
title?: string;
|
|
93
|
+
description?: string;
|
|
92
94
|
instructions?: string;
|
|
93
95
|
fetchedUrl: string;
|
|
96
|
+
/** Which well-known document(s) this source was built from. */
|
|
97
|
+
protocol: 'x402' | 'mpp' | 'x402+mpp';
|
|
94
98
|
}
|
|
95
99
|
interface WellKnownRoute {
|
|
96
100
|
path: string;
|
|
97
101
|
method: HttpMethod;
|
|
102
|
+
/** Raw price hint from the well-known document (e.g. MPP `payment.amount`). */
|
|
103
|
+
price?: string;
|
|
98
104
|
}
|
|
99
105
|
interface ProbeResult {
|
|
100
106
|
path: string;
|
|
@@ -111,7 +117,7 @@ interface L2Result {
|
|
|
111
117
|
description?: string;
|
|
112
118
|
version?: string;
|
|
113
119
|
routes: L2Route[];
|
|
114
|
-
source: 'openapi' | 'well-known/x402' | null;
|
|
120
|
+
source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp' | null;
|
|
115
121
|
}
|
|
116
122
|
interface L2Route {
|
|
117
123
|
path: string;
|
|
@@ -145,7 +151,7 @@ interface L3Result {
|
|
|
145
151
|
}
|
|
146
152
|
interface L4Result {
|
|
147
153
|
guidance: string;
|
|
148
|
-
source: 'openapi' | 'well-known/x402';
|
|
154
|
+
source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp';
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
declare enum GuidanceMode {
|
|
@@ -241,8 +247,21 @@ interface FetchError {
|
|
|
241
247
|
|
|
242
248
|
declare function getOpenAPI(origin: string, headers?: Record<string, string>, signal?: AbortSignal, specificationOverrideUrl?: string): ResultAsync<OpenApiSource | null, FetchError>;
|
|
243
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Fetches both `/.well-known/x402` and `/.well-known/mpp` in parallel and merges results.
|
|
252
|
+
*
|
|
253
|
+
* In practice these are mutually exclusive, but if both exist their routes are combined
|
|
254
|
+
* (deduplicated by method+path). x402 wins on instruction/fetchedUrl conflicts.
|
|
255
|
+
*
|
|
256
|
+
* Individual leg failures are treated as "not found" for that leg so valid data from
|
|
257
|
+
* the other is never suppressed. Returns Err(FetchError) only when both legs hard-fail.
|
|
258
|
+
*/
|
|
244
259
|
declare function getWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
245
260
|
|
|
261
|
+
declare function getX402WellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
262
|
+
|
|
263
|
+
declare function getMppWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
|
|
264
|
+
|
|
246
265
|
declare function getProbe(url: string, headers?: Record<string, string>, signal?: AbortSignal, inputBody?: Record<string, unknown>): ResultAsync<ProbeResult[], FetchError>;
|
|
247
266
|
|
|
248
267
|
declare function checkL2ForOpenAPI(openApi: OpenApiSource): L2Result;
|
|
@@ -424,4 +443,4 @@ declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
|
|
|
424
443
|
*/
|
|
425
444
|
declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
|
|
426
445
|
|
|
427
|
-
export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };
|
|
446
|
+
export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getMppWellKnown, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, getX402WellKnown, validatePaymentRequiredDetailed };
|