@zeroxyz/cli 1.1.0 → 1.2.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/index.js +197 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76582,7 +76582,7 @@ init_esm_shims();
|
|
|
76582
76582
|
|
|
76583
76583
|
// package.json
|
|
76584
76584
|
var package_default = {
|
|
76585
|
-
version: "1.
|
|
76585
|
+
version: "1.2.0"};
|
|
76586
76586
|
|
|
76587
76587
|
// src/app.ts
|
|
76588
76588
|
init_esm_shims();
|
|
@@ -77578,7 +77578,7 @@ init_esm_shims();
|
|
|
77578
77578
|
// ../sdk/dist/index.js
|
|
77579
77579
|
init_esm_shims();
|
|
77580
77580
|
|
|
77581
|
-
// ../sdk/dist/chunk-
|
|
77581
|
+
// ../sdk/dist/chunk-SLXRHGE4.js
|
|
77582
77582
|
init_esm_shims();
|
|
77583
77583
|
|
|
77584
77584
|
// ../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/index.js
|
|
@@ -144034,7 +144034,7 @@ var Payments = class {
|
|
|
144034
144034
|
};
|
|
144035
144035
|
};
|
|
144036
144036
|
var package_default2 = {
|
|
144037
|
-
version: "0.
|
|
144037
|
+
version: "0.2.0"
|
|
144038
144038
|
};
|
|
144039
144039
|
var SDK_VERSION2 = package_default2.version;
|
|
144040
144040
|
var userWalletDtoSchema = external_exports3.object({
|
|
@@ -144999,7 +144999,7 @@ var Wallet = class {
|
|
|
144999
144999
|
};
|
|
145000
145000
|
};
|
|
145001
145001
|
var DEFAULT_BASE_URL = "https://api.zero.xyz";
|
|
145002
|
-
var DEFAULT_TIMEOUT_MS =
|
|
145002
|
+
var DEFAULT_TIMEOUT_MS = 18e4;
|
|
145003
145003
|
var DEFAULT_MAX_RETRIES = 2;
|
|
145004
145004
|
var noopRefresh = async () => {
|
|
145005
145005
|
};
|
|
@@ -145283,11 +145283,44 @@ var recordErrorFetchRun = async (client, opts, result) => {
|
|
|
145283
145283
|
} catch {
|
|
145284
145284
|
}
|
|
145285
145285
|
};
|
|
145286
|
+
var recordTimeoutRun = async (client, opts, err, startedAt, capabilityIdRequested) => {
|
|
145287
|
+
const result = errorFetchResult(
|
|
145288
|
+
startedAt,
|
|
145289
|
+
err.message,
|
|
145290
|
+
"timeout",
|
|
145291
|
+
capabilityIdRequested,
|
|
145292
|
+
"network_error"
|
|
145293
|
+
);
|
|
145294
|
+
await recordErrorFetchRun(client, opts, result);
|
|
145295
|
+
};
|
|
145296
|
+
var sniffJsonShapeBytes = (buf) => {
|
|
145297
|
+
let i = 0;
|
|
145298
|
+
if (buf.length >= 3 && buf[0] === 239 && buf[1] === 187 && buf[2] === 191) {
|
|
145299
|
+
i = 3;
|
|
145300
|
+
}
|
|
145301
|
+
while (i < buf.length && (buf[i] === 32 || buf[i] === 9 || buf[i] === 10 || buf[i] === 13)) {
|
|
145302
|
+
i++;
|
|
145303
|
+
}
|
|
145304
|
+
if (i >= buf.length) return false;
|
|
145305
|
+
return buf[i] === 123 || buf[i] === 91;
|
|
145306
|
+
};
|
|
145307
|
+
var withDefaultContentType = (headers, body) => {
|
|
145308
|
+
if (!headers && body === void 0) return void 0;
|
|
145309
|
+
const next = headers ? { ...headers } : {};
|
|
145310
|
+
if (body === void 0) return next;
|
|
145311
|
+
const hasContentType = Object.keys(next).some(
|
|
145312
|
+
(k3) => k3.toLowerCase() === "content-type"
|
|
145313
|
+
);
|
|
145314
|
+
if (!hasContentType) {
|
|
145315
|
+
next["content-type"] = typeof body === "string" || sniffJsonShapeBytes(body) ? "application/json" : "application/octet-stream";
|
|
145316
|
+
}
|
|
145317
|
+
return next;
|
|
145318
|
+
};
|
|
145286
145319
|
var clientFetch = async (client, url4, opts = {}) => {
|
|
145287
145320
|
const startedAt = Date.now();
|
|
145288
145321
|
const capabilityIdRequested = opts.capabilityId !== void 0;
|
|
145289
145322
|
const method = opts.method ?? (opts.body !== void 0 ? "POST" : "GET");
|
|
145290
|
-
const probeHeaders = opts.headers
|
|
145323
|
+
const probeHeaders = withDefaultContentType(opts.headers, opts.body);
|
|
145291
145324
|
const requestInit = {
|
|
145292
145325
|
method,
|
|
145293
145326
|
headers: probeHeaders,
|
|
@@ -145304,6 +145337,16 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145304
145337
|
try {
|
|
145305
145338
|
response = await configuredFetch(url4, requestInit);
|
|
145306
145339
|
} catch (err) {
|
|
145340
|
+
if (err instanceof ZeroTimeoutError) {
|
|
145341
|
+
await recordTimeoutRun(
|
|
145342
|
+
client,
|
|
145343
|
+
opts,
|
|
145344
|
+
err,
|
|
145345
|
+
startedAt,
|
|
145346
|
+
capabilityIdRequested
|
|
145347
|
+
);
|
|
145348
|
+
throw err;
|
|
145349
|
+
}
|
|
145307
145350
|
if (err instanceof ZeroError) throw err;
|
|
145308
145351
|
const errMessage = err instanceof Error ? err.message : String(err);
|
|
145309
145352
|
const result2 = errorFetchResult(
|
|
@@ -145325,8 +145368,9 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145325
145368
|
url: url4,
|
|
145326
145369
|
method,
|
|
145327
145370
|
// Fresh clone for the paid retry — same rationale as
|
|
145328
|
-
// the probe-side clone above.
|
|
145329
|
-
|
|
145371
|
+
// the probe-side clone above. Re-derives the default
|
|
145372
|
+
// Content-Type so the paid leg matches the probe.
|
|
145373
|
+
headers: withDefaultContentType(opts.headers, opts.body),
|
|
145330
145374
|
body: opts.body,
|
|
145331
145375
|
maxPay: opts.maxPay,
|
|
145332
145376
|
account: opts.account,
|
|
@@ -145362,6 +145406,15 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
145362
145406
|
);
|
|
145363
145407
|
await recordErrorFetchRun(client, opts, result2);
|
|
145364
145408
|
return result2;
|
|
145409
|
+
} else if (err instanceof ZeroTimeoutError) {
|
|
145410
|
+
await recordTimeoutRun(
|
|
145411
|
+
client,
|
|
145412
|
+
opts,
|
|
145413
|
+
err,
|
|
145414
|
+
startedAt,
|
|
145415
|
+
capabilityIdRequested
|
|
145416
|
+
);
|
|
145417
|
+
throw err;
|
|
145365
145418
|
} else {
|
|
145366
145419
|
throw err;
|
|
145367
145420
|
}
|
|
@@ -146367,7 +146420,7 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
146367
146420
|
"Read the request body from stdin (equivalent to `-d @-`)."
|
|
146368
146421
|
).option("-H, --header <header...>", "Headers in Key:Value format").option("--max-pay <amount>", "Maximum per-call spend limit (USDC)").option(
|
|
146369
146422
|
"--timeout <seconds>",
|
|
146370
|
-
"Per-request timeout in seconds, overriding the default (
|
|
146423
|
+
"Per-request timeout in seconds, overriding the default (180). Applies to each HTTP leg of the call (probe and paid retry), not as a wall-clock deadline."
|
|
146371
146424
|
).option(
|
|
146372
146425
|
"--capability <id>",
|
|
146373
146426
|
"Bind this fetch to a capability (uid or slug) so a reviewable run is recorded even without a prior `zero search`"
|
|
@@ -146858,29 +146911,140 @@ var formatRating = (rating) => {
|
|
|
146858
146911
|
return `${successPct} success, ${reviews} reviews`;
|
|
146859
146912
|
};
|
|
146860
146913
|
var asNode = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
146861
|
-
var
|
|
146914
|
+
var schemaType = (node) => {
|
|
146915
|
+
const t = node?.type;
|
|
146916
|
+
if (typeof t === "string") return t;
|
|
146917
|
+
if (Array.isArray(t)) {
|
|
146918
|
+
const first = t.find((x2) => typeof x2 === "string" && x2 !== "null");
|
|
146919
|
+
return typeof first === "string" ? first : void 0;
|
|
146920
|
+
}
|
|
146921
|
+
return void 0;
|
|
146922
|
+
};
|
|
146923
|
+
var coerceToType = (value, type2) => {
|
|
146924
|
+
if (typeof value !== "string") return value;
|
|
146925
|
+
if (type2 === "number" || type2 === "integer") {
|
|
146926
|
+
const n = Number(value);
|
|
146927
|
+
return value.trim() !== "" && Number.isFinite(n) ? n : value;
|
|
146928
|
+
}
|
|
146929
|
+
if (type2 === "boolean") {
|
|
146930
|
+
if (value === "true") return true;
|
|
146931
|
+
if (value === "false") return false;
|
|
146932
|
+
}
|
|
146933
|
+
return value;
|
|
146934
|
+
};
|
|
146935
|
+
var sampleValueFor = (fieldName, propSchema) => {
|
|
146862
146936
|
const node = asNode(propSchema);
|
|
146937
|
+
const type2 = schemaType(node);
|
|
146863
146938
|
const example = node?.example ?? node?.default;
|
|
146864
|
-
if (
|
|
146865
|
-
|
|
146866
|
-
|
|
146939
|
+
if (example !== void 0 && example !== null) {
|
|
146940
|
+
return coerceToType(example, type2);
|
|
146941
|
+
}
|
|
146942
|
+
switch (type2) {
|
|
146943
|
+
case "number":
|
|
146944
|
+
case "integer":
|
|
146945
|
+
return 0;
|
|
146946
|
+
case "boolean":
|
|
146947
|
+
return false;
|
|
146948
|
+
case "array":
|
|
146949
|
+
return [];
|
|
146950
|
+
case "object":
|
|
146951
|
+
return {};
|
|
146952
|
+
default:
|
|
146953
|
+
return `<${fieldName.toUpperCase()}>`;
|
|
146867
146954
|
}
|
|
146868
|
-
return `<${fieldName.toUpperCase()}>`;
|
|
146869
146955
|
};
|
|
146956
|
+
var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName, propSchema));
|
|
146870
146957
|
var extractInputEnvelope = (bodySchema, method) => {
|
|
146871
|
-
|
|
146872
|
-
|
|
146958
|
+
const root = asNode(bodySchema);
|
|
146959
|
+
if (!root) return {};
|
|
146960
|
+
const props = asNode(root.properties);
|
|
146873
146961
|
if (!props) return {};
|
|
146874
146962
|
const inputProps = asNode(asNode(props.input)?.properties);
|
|
146875
146963
|
if (inputProps) {
|
|
146876
146964
|
return {
|
|
146877
|
-
queryParams: asNode(
|
|
146878
|
-
body: asNode(
|
|
146965
|
+
queryParams: asNode(inputProps.queryParams) ?? void 0,
|
|
146966
|
+
body: asNode(inputProps.body) ?? void 0
|
|
146879
146967
|
};
|
|
146880
146968
|
}
|
|
146881
146969
|
const upperMethod = method.toUpperCase();
|
|
146882
146970
|
const isGetLike = upperMethod === "GET" || upperMethod === "DELETE";
|
|
146883
|
-
return isGetLike ? { queryParams:
|
|
146971
|
+
return isGetLike ? { queryParams: root } : { body: root };
|
|
146972
|
+
};
|
|
146973
|
+
var schemaTypeLabel = (node) => {
|
|
146974
|
+
const t = node.type;
|
|
146975
|
+
if (typeof t === "string") return t;
|
|
146976
|
+
if (Array.isArray(t)) {
|
|
146977
|
+
const parts = t.filter((x2) => typeof x2 === "string");
|
|
146978
|
+
return parts.length > 0 ? parts.join(" | ") : "any";
|
|
146979
|
+
}
|
|
146980
|
+
return "any";
|
|
146981
|
+
};
|
|
146982
|
+
var constraintHint = (node) => {
|
|
146983
|
+
const num2 = (k3) => typeof node[k3] === "number" ? node[k3] : void 0;
|
|
146984
|
+
const min = num2("minimum");
|
|
146985
|
+
const max = num2("maximum");
|
|
146986
|
+
if (min !== void 0 && max !== void 0) return `range: ${min}..${max}`;
|
|
146987
|
+
if (min !== void 0) return `min: ${min}`;
|
|
146988
|
+
if (max !== void 0) return `max: ${max}`;
|
|
146989
|
+
const minLen = num2("minLength");
|
|
146990
|
+
const maxLen = num2("maxLength");
|
|
146991
|
+
if (minLen !== void 0 && maxLen !== void 0)
|
|
146992
|
+
return `length: ${minLen}..${maxLen}`;
|
|
146993
|
+
if (maxLen !== void 0) return `maxLength: ${maxLen}`;
|
|
146994
|
+
if (minLen !== void 0) return `minLength: ${minLen}`;
|
|
146995
|
+
return null;
|
|
146996
|
+
};
|
|
146997
|
+
var renderParam = (name, propSchema, required3) => {
|
|
146998
|
+
const node = asNode(propSchema) ?? {};
|
|
146999
|
+
const attrs = [schemaTypeLabel(node)];
|
|
147000
|
+
if (required3) attrs.push("required");
|
|
147001
|
+
if (node.default !== void 0)
|
|
147002
|
+
attrs.push(`default: ${JSON.stringify(node.default)}`);
|
|
147003
|
+
if (Array.isArray(node.enum))
|
|
147004
|
+
attrs.push(`one of: ${node.enum.map((v) => String(v)).join(" | ")}`);
|
|
147005
|
+
const hint = constraintHint(node);
|
|
147006
|
+
if (hint) attrs.push(hint);
|
|
147007
|
+
const lines = [` ${name} (${attrs.join(", ")})`];
|
|
147008
|
+
const desc = typeof node.description === "string" ? node.description.trim() : "";
|
|
147009
|
+
if (desc) lines.push(` ${desc}`);
|
|
147010
|
+
return lines;
|
|
147011
|
+
};
|
|
147012
|
+
var renderProps = (node) => {
|
|
147013
|
+
const props = node ? asNode(node.properties) : null;
|
|
147014
|
+
if (!props) return [];
|
|
147015
|
+
const entries = Object.entries(props);
|
|
147016
|
+
if (entries.length === 0) return [];
|
|
147017
|
+
const requiredSet = new Set(
|
|
147018
|
+
Array.isArray(node?.required) ? node.required.filter((x2) => typeof x2 === "string") : []
|
|
147019
|
+
);
|
|
147020
|
+
return entries.flatMap(
|
|
147021
|
+
([name, schema]) => renderParam(name, schema, requiredSet.has(name))
|
|
147022
|
+
);
|
|
147023
|
+
};
|
|
147024
|
+
var buildSchemaSection = (capability) => {
|
|
147025
|
+
const { queryParams, body } = extractInputEnvelope(
|
|
147026
|
+
capability.bodySchema,
|
|
147027
|
+
capability.method
|
|
147028
|
+
);
|
|
147029
|
+
return [...renderProps(queryParams), ...renderProps(body)];
|
|
147030
|
+
};
|
|
147031
|
+
var buildResponseSection = (capability) => {
|
|
147032
|
+
const rs = asNode(capability.responseSchema);
|
|
147033
|
+
if (!rs) return [];
|
|
147034
|
+
if (rs.example !== void 0) {
|
|
147035
|
+
const example = JSON.stringify(rs.example);
|
|
147036
|
+
const truncated = example.length > 300 ? `${example.slice(0, 300)}\u2026` : example;
|
|
147037
|
+
return [" Returns (example):", ` ${truncated}`];
|
|
147038
|
+
}
|
|
147039
|
+
const props = asNode(rs.properties);
|
|
147040
|
+
if (props) {
|
|
147041
|
+
const fields = Object.entries(props).map(
|
|
147042
|
+
([k3, v]) => `${k3}: ${schemaTypeLabel(asNode(v) ?? {})}`
|
|
147043
|
+
);
|
|
147044
|
+
if (fields.length > 0)
|
|
147045
|
+
return [" Returns:", ` { ${fields.join(", ")} }`];
|
|
147046
|
+
}
|
|
147047
|
+
return [];
|
|
146884
147048
|
};
|
|
146885
147049
|
var buildTryItExample = (capability) => {
|
|
146886
147050
|
const method = capability.method.toUpperCase();
|
|
@@ -146894,7 +147058,8 @@ var buildTryItExample = (capability) => {
|
|
|
146894
147058
|
([k3, v]) => `-H "${k3}: ${v}" # [caller-provided]`
|
|
146895
147059
|
);
|
|
146896
147060
|
if (method === "GET" || queryParams && !body) {
|
|
146897
|
-
const
|
|
147061
|
+
const qpProps = queryParams ? asNode(queryParams.properties) : null;
|
|
147062
|
+
const qs = qpProps ? Object.entries(qpProps).map(
|
|
146898
147063
|
([k3, schema]) => `${encodeURIComponent(k3)}=${encodeURIComponent(placeholderFor(k3, schema))}`
|
|
146899
147064
|
).join("&") : "";
|
|
146900
147065
|
const url4 = qs ? `${capability.url}?${qs}` : capability.url;
|
|
@@ -146908,15 +147073,16 @@ var buildTryItExample = (capability) => {
|
|
|
146908
147073
|
}
|
|
146909
147074
|
if (!queryParams && method === "GET") {
|
|
146910
147075
|
lines.push(
|
|
146911
|
-
" # bodySchema did not expose queryParams \u2014 call the URL as-is
|
|
147076
|
+
" # bodySchema did not expose queryParams \u2014 call the URL as-is."
|
|
146912
147077
|
);
|
|
146913
147078
|
}
|
|
146914
147079
|
return lines;
|
|
146915
147080
|
}
|
|
146916
|
-
const
|
|
146917
|
-
|
|
147081
|
+
const bodyProps = body ? asNode(body.properties) : null;
|
|
147082
|
+
const samplePayload = bodyProps ? Object.fromEntries(
|
|
147083
|
+
Object.entries(bodyProps).map(([k3, schema]) => [
|
|
146918
147084
|
k3,
|
|
146919
|
-
|
|
147085
|
+
sampleValueFor(k3, schema)
|
|
146920
147086
|
])
|
|
146921
147087
|
) : null;
|
|
146922
147088
|
const bodyJson = samplePayload ? JSON.stringify(samplePayload) : "<BODY_JSON>";
|
|
@@ -146924,9 +147090,9 @@ var buildTryItExample = (capability) => {
|
|
|
146924
147090
|
if (method !== "POST") lines.push(` -X ${method} \\`);
|
|
146925
147091
|
for (const h2 of headerFlags) lines.push(` ${h2} \\`);
|
|
146926
147092
|
lines.push(` -d '${bodyJson}'`);
|
|
146927
|
-
if (!
|
|
147093
|
+
if (!bodyProps) {
|
|
146928
147094
|
lines.push(
|
|
146929
|
-
" # bodySchema did not expose input.body \u2014 replace <BODY_JSON> with the
|
|
147095
|
+
" # bodySchema did not expose input.body \u2014 replace <BODY_JSON> with the documented request shape."
|
|
146930
147096
|
);
|
|
146931
147097
|
}
|
|
146932
147098
|
return lines;
|
|
@@ -146948,6 +147114,12 @@ var formatCapability = (capability) => {
|
|
|
146948
147114
|
lines.push(` ${promptLine}`);
|
|
146949
147115
|
}
|
|
146950
147116
|
}
|
|
147117
|
+
const schemaLines = buildSchemaSection(capability);
|
|
147118
|
+
if (schemaLines.length > 0) {
|
|
147119
|
+
lines.push("", "Parameters:");
|
|
147120
|
+
lines.push(...schemaLines);
|
|
147121
|
+
}
|
|
147122
|
+
lines.push(...buildResponseSection(capability));
|
|
146951
147123
|
lines.push(...buildTryItExample(capability));
|
|
146952
147124
|
return lines.join("\n");
|
|
146953
147125
|
};
|