@xona-labs/xpay 0.1.23 → 0.1.24
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/CHANGELOG.md +20 -0
- package/dist/cli/bento.d.ts +23 -0
- package/dist/cli/bento.d.ts.map +1 -0
- package/dist/cli/bento.js +71 -0
- package/dist/cli/bento.js.map +1 -0
- package/dist/cli/index.js +20 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/guardrail/index.d.ts +26 -2
- package/dist/guardrail/index.d.ts.map +1 -1
- package/dist/guardrail/index.js +87 -0
- package/dist/guardrail/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/profile/index.d.ts +8 -0
- package/dist/profile/index.d.ts.map +1 -1
- package/dist/profile/index.js +20 -0
- package/dist/profile/index.js.map +1 -1
- package/dist/profile/types.d.ts +11 -0
- package/dist/profile/types.d.ts.map +1 -1
- package/package.json +4 -1
- package/dist/cli/history.d.ts +0 -16
- package/dist/cli/history.d.ts.map +0 -1
- package/dist/cli/history.js +0 -59
- package/dist/cli/history.js.map +0 -1
- package/dist/cli/probe.d.ts +0 -11
- package/dist/cli/probe.d.ts.map +0 -1
- package/dist/cli/probe.js +0 -55
- package/dist/cli/probe.js.map +0 -1
- package/dist/history/evm.d.ts +0 -21
- package/dist/history/evm.d.ts.map +0 -1
- package/dist/history/evm.js +0 -118
- package/dist/history/evm.js.map +0 -1
- package/dist/history/index.d.ts +0 -19
- package/dist/history/index.d.ts.map +0 -1
- package/dist/history/index.js +0 -45
- package/dist/history/index.js.map +0 -1
- package/dist/history/solana.d.ts +0 -20
- package/dist/history/solana.d.ts.map +0 -1
- package/dist/history/solana.js +0 -96
- package/dist/history/solana.js.map +0 -1
- package/dist/history/types.d.ts +0 -26
- package/dist/history/types.d.ts.map +0 -1
- package/dist/history/types.js +0 -10
- package/dist/history/types.js.map +0 -1
- package/dist/probe/index.d.ts +0 -41
- package/dist/probe/index.d.ts.map +0 -1
- package/dist/probe/index.js +0 -80
- package/dist/probe/index.js.map +0 -1
package/dist/probe/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Probe / verify a resource — does it actually return a valid x402 challenge?
|
|
3
|
-
*
|
|
4
|
-
* Read-only: it calls the endpoint WITHOUT paying, expects a 402, and validates
|
|
5
|
-
* the payment-requirements schema (x402 v1 or v2). No wallet needed. Use it to
|
|
6
|
-
* health-check discovered services before routing real traffic to them.
|
|
7
|
-
*/
|
|
8
|
-
import { extractRequirements } from "../x402/extract.js";
|
|
9
|
-
export async function probe(target, opts = {}) {
|
|
10
|
-
const url = typeof target === "string" ? target : target.resource;
|
|
11
|
-
const method = opts.method ?? (typeof target === "string" ? "GET" : target.method) ?? "GET";
|
|
12
|
-
const fetchImpl = opts.fetch ?? fetch;
|
|
13
|
-
const t0 = Date.now();
|
|
14
|
-
const controller = new AbortController();
|
|
15
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 8000);
|
|
16
|
-
try {
|
|
17
|
-
const headers = { accept: "application/json", ...opts.headers };
|
|
18
|
-
let body;
|
|
19
|
-
if (opts.body !== undefined && method !== "GET") {
|
|
20
|
-
headers["content-type"] = "application/json";
|
|
21
|
-
body = JSON.stringify(opts.body);
|
|
22
|
-
}
|
|
23
|
-
const res = await fetchImpl(url, { method, headers, body, signal: controller.signal });
|
|
24
|
-
const text = await res.text();
|
|
25
|
-
let data = text;
|
|
26
|
-
try {
|
|
27
|
-
data = JSON.parse(text);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
/* keep as string */
|
|
31
|
-
}
|
|
32
|
-
const elapsedMs = Date.now() - t0;
|
|
33
|
-
if (res.status !== 402) {
|
|
34
|
-
return {
|
|
35
|
-
url,
|
|
36
|
-
ok: false,
|
|
37
|
-
status: res.status,
|
|
38
|
-
accepts: [],
|
|
39
|
-
networks: [],
|
|
40
|
-
elapsedMs,
|
|
41
|
-
error: `expected HTTP 402, got ${res.status}`,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
// requirements may be in the body OR a response header
|
|
45
|
-
const { accepts, source, x402Version } = extractRequirements(res.headers, data);
|
|
46
|
-
const networks = [...new Set(accepts.map((a) => a.network))];
|
|
47
|
-
const ok = accepts.length > 0;
|
|
48
|
-
return {
|
|
49
|
-
url,
|
|
50
|
-
ok,
|
|
51
|
-
status: 402,
|
|
52
|
-
x402Version,
|
|
53
|
-
source,
|
|
54
|
-
accepts,
|
|
55
|
-
networks,
|
|
56
|
-
elapsedMs,
|
|
57
|
-
error: ok ? undefined : "402 returned but no parseable accepts[] in body or headers",
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
const isAbort = err.name === "AbortError";
|
|
62
|
-
return {
|
|
63
|
-
url,
|
|
64
|
-
ok: false,
|
|
65
|
-
status: 0,
|
|
66
|
-
accepts: [],
|
|
67
|
-
networks: [],
|
|
68
|
-
elapsedMs: Date.now() - t0,
|
|
69
|
-
error: isAbort ? "timeout" : err.message,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** Probe many resources in parallel. Handy for filtering discover() output. */
|
|
77
|
-
export async function probeAll(targets, opts = {}) {
|
|
78
|
-
return Promise.all(targets.map((t) => probe(t, opts)));
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=index.js.map
|
package/dist/probe/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/probe/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiCzD,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,MAAyB,EAAE,OAAqB,EAAE;IAC5E,MAAM,GAA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