@agentcash/discovery 1.6.3 → 1.6.4
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 +37 -11
- package/dist/cli.js +33 -7
- package/dist/index.cjs +45 -19
- package/dist/index.js +33 -7
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -15626,7 +15626,7 @@ function getWarningsForFavicon(origin) {
|
|
|
15626
15626
|
}
|
|
15627
15627
|
|
|
15628
15628
|
// src/core/source/probe/index.ts
|
|
15629
|
-
var
|
|
15629
|
+
var import_neverthrow8 = require("neverthrow");
|
|
15630
15630
|
|
|
15631
15631
|
// src/core/protocols/x402/index.ts
|
|
15632
15632
|
function parseVersion(payload) {
|
|
@@ -15676,11 +15676,36 @@ async function parsePaymentRequiredBody(response) {
|
|
|
15676
15676
|
return payload;
|
|
15677
15677
|
}
|
|
15678
15678
|
|
|
15679
|
+
// src/core/lib/base64.ts
|
|
15680
|
+
var import_neverthrow7 = require("neverthrow");
|
|
15681
|
+
function safeBase64DecodeUtf8(encoded) {
|
|
15682
|
+
return import_neverthrow7.Result.fromThrowable(
|
|
15683
|
+
() => {
|
|
15684
|
+
if (typeof Buffer !== "undefined") {
|
|
15685
|
+
return Buffer.from(encoded, "base64").toString("utf8");
|
|
15686
|
+
}
|
|
15687
|
+
const binaryString = atob(encoded);
|
|
15688
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
15689
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
15690
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
15691
|
+
}
|
|
15692
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
15693
|
+
},
|
|
15694
|
+
(e) => e instanceof Error ? e : new Error(String(e))
|
|
15695
|
+
)();
|
|
15696
|
+
}
|
|
15697
|
+
|
|
15679
15698
|
// src/core/protocols/x402/v2/parse-payment-required.ts
|
|
15680
15699
|
function parsePaymentRequiredBody2(headerValue) {
|
|
15681
|
-
const
|
|
15682
|
-
if (
|
|
15683
|
-
|
|
15700
|
+
const decoded = safeBase64DecodeUtf8(headerValue);
|
|
15701
|
+
if (decoded.isErr()) return null;
|
|
15702
|
+
try {
|
|
15703
|
+
const payload = JSON.parse(decoded.value);
|
|
15704
|
+
if (!isRecord(payload) || payload.x402Version !== 2) return null;
|
|
15705
|
+
return payload;
|
|
15706
|
+
} catch {
|
|
15707
|
+
return null;
|
|
15708
|
+
}
|
|
15684
15709
|
}
|
|
15685
15710
|
|
|
15686
15711
|
// src/core/source/probe/index.ts
|
|
@@ -15722,8 +15747,8 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
15722
15747
|
...hasBody ? { body: JSON.stringify(inputBody) } : {},
|
|
15723
15748
|
signal
|
|
15724
15749
|
}).andThen((response) => {
|
|
15725
|
-
if (!isUsableStatus(response.status)) return
|
|
15726
|
-
return
|
|
15750
|
+
if (!isUsableStatus(response.status)) return import_neverthrow8.ResultAsync.fromSafePromise(Promise.resolve(null));
|
|
15751
|
+
return import_neverthrow8.ResultAsync.fromSafePromise(
|
|
15727
15752
|
(async () => {
|
|
15728
15753
|
let authHint = response.status === 402 ? "paid" : "unprotected";
|
|
15729
15754
|
let paymentRequiredBody;
|
|
@@ -15754,7 +15779,7 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
15754
15779
|
}
|
|
15755
15780
|
function getProbe(url2, headers, signal, inputBody) {
|
|
15756
15781
|
const path = normalizePath(new URL(url2).pathname || "/");
|
|
15757
|
-
return
|
|
15782
|
+
return import_neverthrow8.ResultAsync.fromSafePromise(
|
|
15758
15783
|
Promise.all(
|
|
15759
15784
|
[...HTTP_METHODS].map(
|
|
15760
15785
|
(method) => probeMethod(url2, method, path, headers, signal, inputBody).match(
|
|
@@ -15767,12 +15792,13 @@ function getProbe(url2, headers, signal, inputBody) {
|
|
|
15767
15792
|
}
|
|
15768
15793
|
|
|
15769
15794
|
// src/core/protocols/mpp/index.ts
|
|
15770
|
-
var
|
|
15795
|
+
var import_neverthrow9 = require("neverthrow");
|
|
15771
15796
|
function parseBase64Json(encoded) {
|
|
15772
|
-
return
|
|
15797
|
+
return import_neverthrow9.Result.fromThrowable(
|
|
15773
15798
|
() => {
|
|
15774
|
-
const decoded =
|
|
15775
|
-
|
|
15799
|
+
const decoded = safeBase64DecodeUtf8(encoded);
|
|
15800
|
+
if (decoded.isErr()) throw decoded.error;
|
|
15801
|
+
const parsed = JSON.parse(decoded.value);
|
|
15776
15802
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
15777
15803
|
throw new Error("not an object");
|
|
15778
15804
|
}
|
package/dist/cli.js
CHANGED
|
@@ -15646,11 +15646,36 @@ async function parsePaymentRequiredBody(response) {
|
|
|
15646
15646
|
return payload;
|
|
15647
15647
|
}
|
|
15648
15648
|
|
|
15649
|
+
// src/core/lib/base64.ts
|
|
15650
|
+
import { Result as Result2 } from "neverthrow";
|
|
15651
|
+
function safeBase64DecodeUtf8(encoded) {
|
|
15652
|
+
return Result2.fromThrowable(
|
|
15653
|
+
() => {
|
|
15654
|
+
if (typeof Buffer !== "undefined") {
|
|
15655
|
+
return Buffer.from(encoded, "base64").toString("utf8");
|
|
15656
|
+
}
|
|
15657
|
+
const binaryString = atob(encoded);
|
|
15658
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
15659
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
15660
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
15661
|
+
}
|
|
15662
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
15663
|
+
},
|
|
15664
|
+
(e) => e instanceof Error ? e : new Error(String(e))
|
|
15665
|
+
)();
|
|
15666
|
+
}
|
|
15667
|
+
|
|
15649
15668
|
// src/core/protocols/x402/v2/parse-payment-required.ts
|
|
15650
15669
|
function parsePaymentRequiredBody2(headerValue) {
|
|
15651
|
-
const
|
|
15652
|
-
if (
|
|
15653
|
-
|
|
15670
|
+
const decoded = safeBase64DecodeUtf8(headerValue);
|
|
15671
|
+
if (decoded.isErr()) return null;
|
|
15672
|
+
try {
|
|
15673
|
+
const payload = JSON.parse(decoded.value);
|
|
15674
|
+
if (!isRecord(payload) || payload.x402Version !== 2) return null;
|
|
15675
|
+
return payload;
|
|
15676
|
+
} catch {
|
|
15677
|
+
return null;
|
|
15678
|
+
}
|
|
15654
15679
|
}
|
|
15655
15680
|
|
|
15656
15681
|
// src/core/source/probe/index.ts
|
|
@@ -15737,12 +15762,13 @@ function getProbe(url2, headers, signal, inputBody) {
|
|
|
15737
15762
|
}
|
|
15738
15763
|
|
|
15739
15764
|
// src/core/protocols/mpp/index.ts
|
|
15740
|
-
import { Result as
|
|
15765
|
+
import { Result as Result3 } from "neverthrow";
|
|
15741
15766
|
function parseBase64Json(encoded) {
|
|
15742
|
-
return
|
|
15767
|
+
return Result3.fromThrowable(
|
|
15743
15768
|
() => {
|
|
15744
|
-
const decoded =
|
|
15745
|
-
|
|
15769
|
+
const decoded = safeBase64DecodeUtf8(encoded);
|
|
15770
|
+
if (decoded.isErr()) throw decoded.error;
|
|
15771
|
+
const parsed = JSON.parse(decoded.value);
|
|
15746
15772
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
15747
15773
|
throw new Error("not an object");
|
|
15748
15774
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -14627,7 +14627,7 @@ async function discoverOriginSchema(options) {
|
|
|
14627
14627
|
}
|
|
14628
14628
|
|
|
14629
14629
|
// src/core/source/probe/index.ts
|
|
14630
|
-
var
|
|
14630
|
+
var import_neverthrow7 = require("neverthrow");
|
|
14631
14631
|
|
|
14632
14632
|
// src/core/protocols/x402/v1/schema.ts
|
|
14633
14633
|
function extractSchemas(accepts) {
|
|
@@ -15031,11 +15031,36 @@ async function parsePaymentRequiredBody(response) {
|
|
|
15031
15031
|
return payload;
|
|
15032
15032
|
}
|
|
15033
15033
|
|
|
15034
|
+
// src/core/lib/base64.ts
|
|
15035
|
+
var import_neverthrow6 = require("neverthrow");
|
|
15036
|
+
function safeBase64DecodeUtf8(encoded) {
|
|
15037
|
+
return import_neverthrow6.Result.fromThrowable(
|
|
15038
|
+
() => {
|
|
15039
|
+
if (typeof Buffer !== "undefined") {
|
|
15040
|
+
return Buffer.from(encoded, "base64").toString("utf8");
|
|
15041
|
+
}
|
|
15042
|
+
const binaryString = atob(encoded);
|
|
15043
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
15044
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
15045
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
15046
|
+
}
|
|
15047
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
15048
|
+
},
|
|
15049
|
+
(e) => e instanceof Error ? e : new Error(String(e))
|
|
15050
|
+
)();
|
|
15051
|
+
}
|
|
15052
|
+
|
|
15034
15053
|
// src/core/protocols/x402/v2/parse-payment-required.ts
|
|
15035
15054
|
function parsePaymentRequiredBody2(headerValue) {
|
|
15036
|
-
const
|
|
15037
|
-
if (
|
|
15038
|
-
|
|
15055
|
+
const decoded = safeBase64DecodeUtf8(headerValue);
|
|
15056
|
+
if (decoded.isErr()) return null;
|
|
15057
|
+
try {
|
|
15058
|
+
const payload = JSON.parse(decoded.value);
|
|
15059
|
+
if (!isRecord(payload) || payload.x402Version !== 2) return null;
|
|
15060
|
+
return payload;
|
|
15061
|
+
} catch {
|
|
15062
|
+
return null;
|
|
15063
|
+
}
|
|
15039
15064
|
}
|
|
15040
15065
|
|
|
15041
15066
|
// src/core/source/probe/index.ts
|
|
@@ -15077,8 +15102,8 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
15077
15102
|
...hasBody ? { body: JSON.stringify(inputBody) } : {},
|
|
15078
15103
|
signal
|
|
15079
15104
|
}).andThen((response) => {
|
|
15080
|
-
if (!isUsableStatus(response.status)) return
|
|
15081
|
-
return
|
|
15105
|
+
if (!isUsableStatus(response.status)) return import_neverthrow7.ResultAsync.fromSafePromise(Promise.resolve(null));
|
|
15106
|
+
return import_neverthrow7.ResultAsync.fromSafePromise(
|
|
15082
15107
|
(async () => {
|
|
15083
15108
|
let authHint = response.status === 402 ? "paid" : "unprotected";
|
|
15084
15109
|
let paymentRequiredBody;
|
|
@@ -15109,7 +15134,7 @@ function probeMethod(url2, method, path, headers, signal, inputBody) {
|
|
|
15109
15134
|
}
|
|
15110
15135
|
function getProbe(url2, headers, signal, inputBody) {
|
|
15111
15136
|
const path = normalizePath(new URL(url2).pathname || "/");
|
|
15112
|
-
return
|
|
15137
|
+
return import_neverthrow7.ResultAsync.fromSafePromise(
|
|
15113
15138
|
Promise.all(
|
|
15114
15139
|
[...HTTP_METHODS].map(
|
|
15115
15140
|
(method) => probeMethod(url2, method, path, headers, signal, inputBody).match(
|
|
@@ -15122,12 +15147,13 @@ function getProbe(url2, headers, signal, inputBody) {
|
|
|
15122
15147
|
}
|
|
15123
15148
|
|
|
15124
15149
|
// src/core/protocols/mpp/index.ts
|
|
15125
|
-
var
|
|
15150
|
+
var import_neverthrow8 = require("neverthrow");
|
|
15126
15151
|
function parseBase64Json(encoded) {
|
|
15127
|
-
return
|
|
15152
|
+
return import_neverthrow8.Result.fromThrowable(
|
|
15128
15153
|
() => {
|
|
15129
|
-
const decoded =
|
|
15130
|
-
|
|
15154
|
+
const decoded = safeBase64DecodeUtf8(encoded);
|
|
15155
|
+
if (decoded.isErr()) throw decoded.error;
|
|
15156
|
+
const parsed = JSON.parse(decoded.value);
|
|
15131
15157
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
15132
15158
|
throw new Error("not an object");
|
|
15133
15159
|
}
|
|
@@ -16266,7 +16292,7 @@ function getWarningsForL4(l4) {
|
|
|
16266
16292
|
}
|
|
16267
16293
|
|
|
16268
16294
|
// src/audit/warnings/favicon.ts
|
|
16269
|
-
var
|
|
16295
|
+
var import_neverthrow9 = require("neverthrow");
|
|
16270
16296
|
var COMMON_PATHS = ["/favicon.ico", "/favicon.png", "/favicon.svg"];
|
|
16271
16297
|
var TIMEOUT = AbortSignal.timeout(5e3);
|
|
16272
16298
|
function isImage(res) {
|
|
@@ -16274,12 +16300,12 @@ function isImage(res) {
|
|
|
16274
16300
|
}
|
|
16275
16301
|
function checkUrl(url2) {
|
|
16276
16302
|
return fetchSafe(url2, { method: "HEAD", signal: TIMEOUT }).andThen((res) => {
|
|
16277
|
-
if (res.ok) return (0,
|
|
16303
|
+
if (res.ok) return (0, import_neverthrow9.okAsync)(isImage(res));
|
|
16278
16304
|
if (res.status === 405 || res.status === 403) {
|
|
16279
16305
|
return fetchSafe(url2, { signal: TIMEOUT }).map((getRes) => getRes.ok && isImage(getRes));
|
|
16280
16306
|
}
|
|
16281
|
-
return (0,
|
|
16282
|
-
}).orElse(() => (0,
|
|
16307
|
+
return (0, import_neverthrow9.okAsync)(false);
|
|
16308
|
+
}).orElse(() => (0, import_neverthrow9.okAsync)(false));
|
|
16283
16309
|
}
|
|
16284
16310
|
function resolveHref(href, origin) {
|
|
16285
16311
|
if (href.startsWith("//")) return `https:${href}`;
|
|
@@ -16308,15 +16334,15 @@ function extractIconHrefs(html, origin) {
|
|
|
16308
16334
|
function getHtmlIconHrefs(origin) {
|
|
16309
16335
|
return fetchSafe(origin, { signal: TIMEOUT }).andThen((res) => {
|
|
16310
16336
|
if (!res.ok || !(res.headers.get("content-type") ?? "").includes("text/html"))
|
|
16311
|
-
return (0,
|
|
16312
|
-
return
|
|
16313
|
-
}).map((html) => html ? extractIconHrefs(html, origin) : []).orElse(() => (0,
|
|
16337
|
+
return (0, import_neverthrow9.okAsync)("");
|
|
16338
|
+
return import_neverthrow9.ResultAsync.fromSafePromise(res.text());
|
|
16339
|
+
}).map((html) => html ? extractIconHrefs(html, origin) : []).orElse(() => (0, import_neverthrow9.okAsync)([]));
|
|
16314
16340
|
}
|
|
16315
16341
|
function checkFavicon(origin) {
|
|
16316
16342
|
const normalizedOrigin = origin.replace(/\/$/, "");
|
|
16317
16343
|
return getHtmlIconHrefs(normalizedOrigin).andThen((hrefs) => {
|
|
16318
16344
|
const candidates = [...hrefs, ...COMMON_PATHS.map((p) => `${normalizedOrigin}${p}`)];
|
|
16319
|
-
return
|
|
16345
|
+
return import_neverthrow9.ResultAsync.fromSafePromise(
|
|
16320
16346
|
Promise.all(candidates.map((url2) => checkUrl(url2).then((r) => r.isOk() && r.value))).then(
|
|
16321
16347
|
(results) => results.some(Boolean)
|
|
16322
16348
|
)
|
package/dist/index.js
CHANGED
|
@@ -14969,11 +14969,36 @@ async function parsePaymentRequiredBody(response) {
|
|
|
14969
14969
|
return payload;
|
|
14970
14970
|
}
|
|
14971
14971
|
|
|
14972
|
+
// src/core/lib/base64.ts
|
|
14973
|
+
import { Result as Result2 } from "neverthrow";
|
|
14974
|
+
function safeBase64DecodeUtf8(encoded) {
|
|
14975
|
+
return Result2.fromThrowable(
|
|
14976
|
+
() => {
|
|
14977
|
+
if (typeof Buffer !== "undefined") {
|
|
14978
|
+
return Buffer.from(encoded, "base64").toString("utf8");
|
|
14979
|
+
}
|
|
14980
|
+
const binaryString = atob(encoded);
|
|
14981
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
14982
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
14983
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
14984
|
+
}
|
|
14985
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
14986
|
+
},
|
|
14987
|
+
(e) => e instanceof Error ? e : new Error(String(e))
|
|
14988
|
+
)();
|
|
14989
|
+
}
|
|
14990
|
+
|
|
14972
14991
|
// src/core/protocols/x402/v2/parse-payment-required.ts
|
|
14973
14992
|
function parsePaymentRequiredBody2(headerValue) {
|
|
14974
|
-
const
|
|
14975
|
-
if (
|
|
14976
|
-
|
|
14993
|
+
const decoded = safeBase64DecodeUtf8(headerValue);
|
|
14994
|
+
if (decoded.isErr()) return null;
|
|
14995
|
+
try {
|
|
14996
|
+
const payload = JSON.parse(decoded.value);
|
|
14997
|
+
if (!isRecord(payload) || payload.x402Version !== 2) return null;
|
|
14998
|
+
return payload;
|
|
14999
|
+
} catch {
|
|
15000
|
+
return null;
|
|
15001
|
+
}
|
|
14977
15002
|
}
|
|
14978
15003
|
|
|
14979
15004
|
// src/core/source/probe/index.ts
|
|
@@ -15060,12 +15085,13 @@ function getProbe(url2, headers, signal, inputBody) {
|
|
|
15060
15085
|
}
|
|
15061
15086
|
|
|
15062
15087
|
// src/core/protocols/mpp/index.ts
|
|
15063
|
-
import { Result as
|
|
15088
|
+
import { Result as Result3 } from "neverthrow";
|
|
15064
15089
|
function parseBase64Json(encoded) {
|
|
15065
|
-
return
|
|
15090
|
+
return Result3.fromThrowable(
|
|
15066
15091
|
() => {
|
|
15067
|
-
const decoded =
|
|
15068
|
-
|
|
15092
|
+
const decoded = safeBase64DecodeUtf8(encoded);
|
|
15093
|
+
if (decoded.isErr()) throw decoded.error;
|
|
15094
|
+
const parsed = JSON.parse(decoded.value);
|
|
15069
15095
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
15070
15096
|
throw new Error("not an object");
|
|
15071
15097
|
}
|