@zeroxyz/cli 1.31.0 → 1.33.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.
Files changed (2) hide show
  1. package/dist/index.js +313 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -93043,7 +93043,7 @@ init_esm_shims();
93043
93043
  // ../sdk/dist/index.js
93044
93044
  init_esm_shims();
93045
93045
 
93046
- // ../sdk/dist/chunk-QHTPKBCA.js
93046
+ // ../sdk/dist/chunk-QNTZREQD.js
93047
93047
  init_esm_shims();
93048
93048
 
93049
93049
  // ../../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
@@ -166839,7 +166839,7 @@ var redactUrl = (raw) => {
166839
166839
  };
166840
166840
  var truncateError = (raw) => raw.length > ERROR_MAX ? `${raw.slice(0, ERROR_MAX)}\u2026` : raw;
166841
166841
  var package_default = {
166842
- version: "0.24.0"
166842
+ version: "0.26.0"
166843
166843
  };
166844
166844
  var SDK_VERSION2 = package_default.version;
166845
166845
  var ZeroError = class extends Error {
@@ -167352,12 +167352,12 @@ var request2 = async (client, opts, schema) => {
167352
167352
  }
167353
167353
  continue;
167354
167354
  }
167355
- const errorBody = await parseErrorBody(response);
167355
+ const errorBody2 = await parseErrorBody(response);
167356
167356
  const requestId = response.headers.get("x-request-id") ?? void 0;
167357
- throw new ZeroApiError(errorMessageFromBody(errorBody, response.status), {
167357
+ throw new ZeroApiError(errorMessageFromBody(errorBody2, response.status), {
167358
167358
  status: response.status,
167359
167359
  requestId,
167360
- body: errorBody
167360
+ body: errorBody2
167361
167361
  });
167362
167362
  }
167363
167363
  throw new ZeroApiError("Exhausted retries", {
@@ -167631,6 +167631,17 @@ var withSynthesizedX402Header = (baseFetch) => async (input, init) => {
167631
167631
  headers
167632
167632
  });
167633
167633
  };
167634
+ var readPaymentRejectionReason = (body) => {
167635
+ if (!body || typeof body !== "object" || Array.isArray(body)) return null;
167636
+ const b = body;
167637
+ const str = (v) => typeof v === "string" && v.trim().length > 0 ? v.trim() : null;
167638
+ const code = str(b.reason) ?? str(b.error);
167639
+ if (!code) return null;
167640
+ const outer = str(b.error);
167641
+ const label = outer && outer !== code ? `${code} (${outer})` : code;
167642
+ const detail = str(b.detail) ?? str(b.message) ?? str(b.hint);
167643
+ return detail ? `${label} \u2014 ${detail}` : label;
167644
+ };
167634
167645
  var USDC_BASE2 = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
167635
167646
  var USDC_BASE_SEPOLIA = "0x036cbd53842c5426634e7929541ec2318f3dcf7e";
167636
167647
  var UINT_RE = /^[0-9]+$/;
@@ -168280,10 +168291,23 @@ var Payments = class {
168280
168291
  if (text) body = JSON.parse(text);
168281
168292
  } catch {
168282
168293
  }
168283
- return httpClient.getPaymentRequiredResponse(
168284
- (name) => challengeResponse.headers.get(name),
168285
- body
168286
- );
168294
+ try {
168295
+ return httpClient.getPaymentRequiredResponse(
168296
+ (name) => challengeResponse.headers.get(name),
168297
+ body
168298
+ );
168299
+ } catch (err) {
168300
+ const reason = readPaymentRejectionReason(body);
168301
+ if (!reason) throw err;
168302
+ input.diagnostics?.fail(
168303
+ "paid_replay",
168304
+ FETCH_DIAGNOSTIC_CODES.paymentRejected
168305
+ );
168306
+ throw new ZeroPaymentError(
168307
+ `the seller rejected the payment: ${reason}`,
168308
+ { cause: err }
168309
+ );
168310
+ }
168287
168311
  };
168288
168312
  let paymentRequired2 = await parseChallenge(response);
168289
168313
  const hookHeaders = await httpClient.handlePaymentRequired(paymentRequired2);
@@ -169568,6 +169592,9 @@ var computeFixHint = (status, message2, bodyRaw) => {
169568
169592
  if (status === 415 || /content-?type|unsupported media|media type/.test(hay)) {
169569
169593
  return "set the Content-Type header to what the capability expects (usually application/json), then retry";
169570
169594
  }
169595
+ if ((status === 401 || status === 403) && /bearer|identity|unauthorized|credential|agent_auth/.test(hay)) {
169596
+ return 'the seller requires an agent identity credential \u2014 run `zero auth identity <host>` and resend with `-H "Authorization: Bearer <token>"`';
169597
+ }
169571
169598
  if (/required|missing|must (include|provide|have|contain)|is expected/.test(hay)) {
169572
169599
  const field = extractFieldName(message2 ?? "");
169573
169600
  return field ? `add the required field '${field}' to the request body, then retry` : "the request is missing one or more required fields \u2014 check the capability schema (`zero get <slug>`), then retry";
@@ -169743,6 +169770,12 @@ var withDefaultContentType = (headers, body) => {
169743
169770
  }
169744
169771
  return next;
169745
169772
  };
169773
+ var withDefaultUserAgent = (headers) => {
169774
+ const next = headers ? { ...headers } : {};
169775
+ const hasUa = Object.keys(next).some((k) => k.toLowerCase() === "user-agent");
169776
+ if (!hasUa) next["user-agent"] = `zero-sdk/${SDK_VERSION2}`;
169777
+ return next;
169778
+ };
169746
169779
  var clientFetch = async (client, url4, opts = {}, diagnostics) => {
169747
169780
  const startedAt = Date.now();
169748
169781
  const fetchId = diagnostics.fetchId;
@@ -169770,7 +169803,9 @@ var clientFetch = async (client, url4, opts = {}, diagnostics) => {
169770
169803
  );
169771
169804
  return null;
169772
169805
  }) : Promise.resolve(null);
169773
- const probeHeaders = withDefaultContentType(opts.headers, requestBody);
169806
+ const probeHeaders = withDefaultUserAgent(
169807
+ withDefaultContentType(opts.headers, requestBody)
169808
+ );
169774
169809
  const requestInit = {
169775
169810
  method,
169776
169811
  headers: probeHeaders,
@@ -169850,7 +169885,9 @@ var clientFetch = async (client, url4, opts = {}, diagnostics) => {
169850
169885
  // Fresh clone for the paid retry — same rationale as
169851
169886
  // the probe-side clone above. Re-derives the default
169852
169887
  // Content-Type so the paid leg matches the probe.
169853
- headers: withDefaultContentType(opts.headers, requestBody),
169888
+ headers: withDefaultUserAgent(
169889
+ withDefaultContentType(opts.headers, requestBody)
169890
+ ),
169854
169891
  body: requestBody,
169855
169892
  maxPay: opts.maxPay,
169856
169893
  account: opts.account,
@@ -170280,6 +170317,214 @@ var clientFetch = async (client, url4, opts = {}, diagnostics) => {
170280
170317
  result.capabilityResolution = capabilityResolution;
170281
170318
  return result;
170282
170319
  };
170320
+ var usdAmountSchema = external_exports3.string().regex(/^\d+(?:\.\d{1,6})?$/, "Expected a decimal USD amount");
170321
+ var creditPurchaseSchema = external_exports3.object({
170322
+ url: external_exports3.string().url(),
170323
+ amountRequired: external_exports3.literal(true),
170324
+ minimumUsd: usdAmountSchema
170325
+ });
170326
+ var storefrontPlanSchema = external_exports3.object({
170327
+ id: external_exports3.string().min(1),
170328
+ name: external_exports3.string().min(1),
170329
+ slug: external_exports3.string().min(1),
170330
+ billingMode: external_exports3.string().min(1),
170331
+ purchase: creditPurchaseSchema.nullable()
170332
+ });
170333
+ var storefrontManifestSchema = external_exports3.object({
170334
+ seller: external_exports3.object({
170335
+ id: external_exports3.string().min(1),
170336
+ name: external_exports3.string().min(1),
170337
+ slug: external_exports3.string().min(1)
170338
+ }),
170339
+ plans: external_exports3.array(storefrontPlanSchema)
170340
+ });
170341
+ var USD_MICROS = 1000000n;
170342
+ var CENT_MICROS = 10000n;
170343
+ var parseUsdMicros = (amount2) => {
170344
+ if (!/^\d+(?:\.\d{1,6})?$/.test(amount2)) {
170345
+ throw new ZeroValidationError(
170346
+ "Credit purchase amount must be a positive decimal with at most 6 fractional digits."
170347
+ );
170348
+ }
170349
+ const [whole = "0", fraction = ""] = amount2.split(".");
170350
+ return BigInt(whole) * USD_MICROS + BigInt(fraction.padEnd(6, "0"));
170351
+ };
170352
+ var formatUsdMicros = (amount2) => {
170353
+ const whole = amount2 / USD_MICROS;
170354
+ const fraction = (amount2 % USD_MICROS).toString().padStart(6, "0");
170355
+ return `${whole}.${fraction}`;
170356
+ };
170357
+ var resourceOrigin = (resourceUrl) => {
170358
+ let parsed;
170359
+ try {
170360
+ parsed = new URL(resourceUrl);
170361
+ } catch (cause) {
170362
+ throw new ZeroValidationError(
170363
+ "Credit access requires a valid resource URL.",
170364
+ {
170365
+ cause
170366
+ }
170367
+ );
170368
+ }
170369
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
170370
+ throw new ZeroValidationError(
170371
+ "Credit access only supports HTTP or HTTPS resources."
170372
+ );
170373
+ }
170374
+ return parsed.origin;
170375
+ };
170376
+ var errorBody = async (response) => {
170377
+ const text = await response.text().catch(() => "");
170378
+ try {
170379
+ return JSON.parse(text);
170380
+ } catch {
170381
+ return text || null;
170382
+ }
170383
+ };
170384
+ var Access = class {
170385
+ constructor(client) {
170386
+ this.client = client;
170387
+ }
170388
+ discoverCreditPlans = async (resourceUrl, opts = {}) => {
170389
+ const origin2 = resourceOrigin(resourceUrl);
170390
+ const manifestUrl = new URL("/manifest.json", origin2).href;
170391
+ let response;
170392
+ try {
170393
+ response = await this.client.fetchImpl(manifestUrl, {
170394
+ headers: { accept: "application/json" },
170395
+ signal: opts.signal
170396
+ });
170397
+ } catch (cause) {
170398
+ throw new ZeroApiError("Seller manifest request failed", {
170399
+ status: 0,
170400
+ cause
170401
+ });
170402
+ }
170403
+ if (!response.ok) {
170404
+ throw new ZeroApiError("Seller manifest request failed", {
170405
+ status: response.status,
170406
+ body: await errorBody(response)
170407
+ });
170408
+ }
170409
+ const text = await response.text();
170410
+ let json3;
170411
+ try {
170412
+ json3 = JSON.parse(text);
170413
+ } catch (cause) {
170414
+ throw new ZeroValidationError(
170415
+ "Seller manifest did not contain valid JSON.",
170416
+ { cause, body: text }
170417
+ );
170418
+ }
170419
+ const parsed = storefrontManifestSchema.safeParse(json3);
170420
+ if (!parsed.success) {
170421
+ throw new ZeroValidationError(
170422
+ "Seller manifest did not match the expected access schema.",
170423
+ { cause: parsed.error, body: text }
170424
+ );
170425
+ }
170426
+ const creditPlans = [];
170427
+ for (const plan of parsed.data.plans) {
170428
+ if (plan.billingMode !== "credit" || !plan.purchase) continue;
170429
+ const purchaseUrl = new URL(plan.purchase.url);
170430
+ if (purchaseUrl.origin !== origin2) {
170431
+ throw new ZeroValidationError(
170432
+ "Seller manifest advertised a cross-origin credit purchase URL."
170433
+ );
170434
+ }
170435
+ creditPlans.push({
170436
+ id: plan.id,
170437
+ name: plan.name,
170438
+ slug: plan.slug,
170439
+ minimumUsd: formatUsdMicros(parseUsdMicros(plan.purchase.minimumUsd))
170440
+ });
170441
+ }
170442
+ return {
170443
+ resourceOrigin: origin2,
170444
+ seller: parsed.data.seller,
170445
+ onlyCreditPlans: parsed.data.plans.length > 0 && parsed.data.plans.every((plan) => plan.billingMode === "credit"),
170446
+ plans: creditPlans
170447
+ };
170448
+ };
170449
+ prepareCreditPurchase = async (input) => {
170450
+ const discovery = await this.discoverCreditPlans(input.resourceUrl, {
170451
+ signal: input.signal
170452
+ });
170453
+ const plan = discovery.plans.find(
170454
+ (candidate) => candidate.id === input.planId
170455
+ );
170456
+ if (!plan) {
170457
+ throw new ZeroValidationError(
170458
+ "The requested credit plan is not purchasable in the seller's current manifest."
170459
+ );
170460
+ }
170461
+ const amount2 = parseUsdMicros(input.amountUsd);
170462
+ const minimum = parseUsdMicros(plan.minimumUsd);
170463
+ if (amount2 <= 0n || amount2 < minimum) {
170464
+ throw new ZeroValidationError(
170465
+ `Credit purchase amount must be at least $${plan.minimumUsd}.`
170466
+ );
170467
+ }
170468
+ if (amount2 % CENT_MICROS !== 0n) {
170469
+ throw new ZeroValidationError(
170470
+ "Credit purchase amount must be in whole-cent increments."
170471
+ );
170472
+ }
170473
+ const manifest = storefrontManifestSchema.parse(
170474
+ await this.fetchManifest(discovery.resourceOrigin, input.signal)
170475
+ );
170476
+ const current = manifest.plans.find(
170477
+ (candidate) => candidate.id === input.planId && candidate.billingMode === "credit"
170478
+ );
170479
+ if (!current?.purchase) {
170480
+ throw new ZeroValidationError(
170481
+ "The requested credit plan is no longer purchasable."
170482
+ );
170483
+ }
170484
+ const currentMinimum = parseUsdMicros(current.purchase.minimumUsd);
170485
+ if (amount2 < currentMinimum) {
170486
+ throw new ZeroValidationError(
170487
+ `Credit purchase amount must be at least $${formatUsdMicros(currentMinimum)}.`
170488
+ );
170489
+ }
170490
+ const purchaseUrl = new URL(current.purchase.url);
170491
+ if (purchaseUrl.origin !== discovery.resourceOrigin) {
170492
+ throw new ZeroValidationError(
170493
+ "Seller manifest advertised a cross-origin credit purchase URL."
170494
+ );
170495
+ }
170496
+ const amountUsd = formatUsdMicros(amount2);
170497
+ return {
170498
+ resourceOrigin: discovery.resourceOrigin,
170499
+ plan: {
170500
+ id: current.id,
170501
+ name: current.name,
170502
+ slug: current.slug,
170503
+ minimumUsd: formatUsdMicros(currentMinimum)
170504
+ },
170505
+ url: purchaseUrl.href,
170506
+ method: "POST",
170507
+ body: JSON.stringify({ amountUsd }),
170508
+ amountUsd
170509
+ };
170510
+ };
170511
+ fetchManifest = async (origin2, signal) => {
170512
+ const response = await this.client.fetchImpl(
170513
+ new URL("/manifest.json", origin2),
170514
+ {
170515
+ headers: { accept: "application/json" },
170516
+ signal
170517
+ }
170518
+ );
170519
+ if (!response.ok) {
170520
+ throw new ZeroApiError("Seller manifest request failed", {
170521
+ status: response.status,
170522
+ body: await errorBody(response)
170523
+ });
170524
+ }
170525
+ return response.json();
170526
+ };
170527
+ };
170283
170528
  var agentAuthMetadataSchema = external_exports3.object({
170284
170529
  token_endpoint: external_exports3.string().optional(),
170285
170530
  agent_auth: external_exports3.object({
@@ -172322,6 +172567,7 @@ var ZeroClient = class _ZeroClient {
172322
172567
  // is called. Lazy getters would tree-shake better but break the discoverable
172323
172568
  // `client.<tab>` ergonomics that make resource-namespaced SDKs pleasant.
172324
172569
  auth;
172570
+ access;
172325
172571
  bugReports;
172326
172572
  capabilities;
172327
172573
  payments;
@@ -172344,6 +172590,7 @@ var ZeroClient = class _ZeroClient {
172344
172590
  this.analyticsOptions = options.analytics;
172345
172591
  this.refreshOverride = options.refresh;
172346
172592
  this.withAccountCache = options._sharedAccountCache ?? /* @__PURE__ */ new Map();
172593
+ this.access = new Access(this);
172347
172594
  this.auth = new Auth(this);
172348
172595
  this.bugReports = new BugReports(this);
172349
172596
  this.capabilities = new Capabilities(this);
@@ -176416,7 +176663,51 @@ var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName,
176416
176663
 
176417
176664
  // package.json
176418
176665
  var package_default2 = {
176419
- version: "1.31.0"};
176666
+ name: "@zeroxyz/cli",
176667
+ version: "1.33.0",
176668
+ type: "module",
176669
+ bin: {
176670
+ zero: "dist/index.js",
176671
+ zerocli: "dist/index.js"
176672
+ },
176673
+ files: [
176674
+ "dist"
176675
+ ],
176676
+ publishConfig: {
176677
+ access: "public"
176678
+ },
176679
+ scripts: {
176680
+ build: "tsup",
176681
+ "build:binary": "tsup --config tsup.binary.ts && pnpm exec pkg dist/pkg/index.cjs --config pkg.json --targets node24-macos-arm64,node24-macos-x64,node24-linux-x64,node24-linux-arm64,node24-win-x64 --output dist/bin/zero",
176682
+ prepublishOnly: "pnpm run build",
176683
+ dev: "ZERO_ENV=development tsx src/index.ts",
176684
+ cli: "ZERO_ENV=development ZERO_API_URL=http://localhost:1111 tsx src/index.ts",
176685
+ "test:integration": "vitest run --project integration",
176686
+ "test:e2e": "tsup && vitest run --project e2e",
176687
+ "test:online": "vitest run --project online",
176688
+ "test:unit": "vitest run --project unit",
176689
+ test: "pnpm run test:unit && pnpm run test:integration",
176690
+ typecheck: "tsc"
176691
+ },
176692
+ devDependencies: {
176693
+ "@clack/prompts": "^0.11.0",
176694
+ "@types/node": "^25.0.7",
176695
+ "@types/semver": "^7.7.1",
176696
+ "@yao-pkg/pkg": "^6.15.0",
176697
+ "@zero/test-fixtures": "workspace:*",
176698
+ "@zeroxyz/sdk": "workspace:^",
176699
+ commander: "^13.0.0",
176700
+ open: "^11.0.0",
176701
+ "posthog-node": "^5.29.2",
176702
+ semver: "^7.8.5",
176703
+ tsup: "^8.5.1",
176704
+ tsx: "^4.21.0",
176705
+ typescript: "^5.9.3",
176706
+ viem: "^2.47.10",
176707
+ vitest: "^4.0.17",
176708
+ zod: "^4.3.5"
176709
+ }
176710
+ };
176420
176711
 
176421
176712
  // src/app.ts
176422
176713
  init_esm_shims();
@@ -178673,12 +178964,20 @@ var fetchCommand = (appContext) => new Command("fetch").description(
178673
178964
  process.exitCode = 1;
178674
178965
  return;
178675
178966
  }
178676
- const headers = {};
178967
+ const headers = {
178968
+ "user-agent": `zero-cli/${package_default2.version}`
178969
+ };
178677
178970
  if (options.header) {
178678
178971
  for (const h of options.header) {
178679
178972
  const colonIdx = h.indexOf(":");
178680
178973
  if (colonIdx > 0) {
178681
- headers[h.slice(0, colonIdx).trim()] = h.slice(colonIdx + 1).trim();
178974
+ const name = h.slice(0, colonIdx).trim();
178975
+ for (const existing of Object.keys(headers)) {
178976
+ if (existing !== name && existing.toLowerCase() === name.toLowerCase()) {
178977
+ delete headers[existing];
178978
+ }
178979
+ }
178980
+ headers[name] = h.slice(colonIdx + 1).trim();
178682
178981
  }
178683
178982
  }
178684
178983
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeroxyz/cli",
3
- "version": "1.31.0",
3
+ "version": "1.33.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "zero": "dist/index.js",