@zeroxyz/sdk 0.1.0 → 0.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.
@@ -1098,7 +1098,7 @@ var Payments = class {
1098
1098
 
1099
1099
  // package.json
1100
1100
  var package_default = {
1101
- version: "0.1.0"};
1101
+ version: "0.2.0"};
1102
1102
 
1103
1103
  // src/version.ts
1104
1104
  var SDK_VERSION = package_default.version;
@@ -1150,7 +1150,13 @@ var deviceStartResponseSchema = z.object({
1150
1150
  expiresAt: z.number()
1151
1151
  });
1152
1152
  var devicePollResponseSchema = z.union([
1153
- z.object({ error: z.literal("authorization_pending") }),
1153
+ // userCode + verificationUri are optional: older API deployments don't
1154
+ // echo them on pending.
1155
+ z.object({
1156
+ error: z.literal("authorization_pending"),
1157
+ userCode: z.string().optional(),
1158
+ verificationUri: z.string().optional()
1159
+ }),
1154
1160
  z.object({ error: z.literal("expired_token") }),
1155
1161
  z.object({
1156
1162
  accessToken: z.string(),
@@ -1424,7 +1430,11 @@ var AuthDevice = class {
1424
1430
  devicePollResponseSchema
1425
1431
  );
1426
1432
  if ("error" in parsed) {
1427
- return parsed.error === "authorization_pending" ? { status: "pending" } : { status: "expired" };
1433
+ return parsed.error === "authorization_pending" ? {
1434
+ status: "pending",
1435
+ userCode: parsed.userCode,
1436
+ verificationUri: parsed.verificationUri
1437
+ } : { status: "expired" };
1428
1438
  }
1429
1439
  return {
1430
1440
  status: "ok",
@@ -2072,7 +2082,7 @@ var Wallet = class {
2072
2082
 
2073
2083
  // src/options.ts
2074
2084
  var DEFAULT_BASE_URL = "https://api.zero.xyz";
2075
- var DEFAULT_TIMEOUT_MS = 6e4;
2085
+ var DEFAULT_TIMEOUT_MS = 18e4;
2076
2086
  var DEFAULT_MAX_RETRIES = 2;
2077
2087
 
2078
2088
  // src/auth/credentials.ts
@@ -2358,11 +2368,44 @@ var recordErrorFetchRun = async (client, opts, result) => {
2358
2368
  } catch {
2359
2369
  }
2360
2370
  };
2371
+ var recordTimeoutRun = async (client, opts, err, startedAt, capabilityIdRequested) => {
2372
+ const result = errorFetchResult(
2373
+ startedAt,
2374
+ err.message,
2375
+ "timeout",
2376
+ capabilityIdRequested,
2377
+ "network_error"
2378
+ );
2379
+ await recordErrorFetchRun(client, opts, result);
2380
+ };
2381
+ var sniffJsonShapeBytes = (buf) => {
2382
+ let i = 0;
2383
+ if (buf.length >= 3 && buf[0] === 239 && buf[1] === 187 && buf[2] === 191) {
2384
+ i = 3;
2385
+ }
2386
+ while (i < buf.length && (buf[i] === 32 || buf[i] === 9 || buf[i] === 10 || buf[i] === 13)) {
2387
+ i++;
2388
+ }
2389
+ if (i >= buf.length) return false;
2390
+ return buf[i] === 123 || buf[i] === 91;
2391
+ };
2392
+ var withDefaultContentType = (headers, body) => {
2393
+ if (!headers && body === void 0) return void 0;
2394
+ const next = headers ? { ...headers } : {};
2395
+ if (body === void 0) return next;
2396
+ const hasContentType = Object.keys(next).some(
2397
+ (k) => k.toLowerCase() === "content-type"
2398
+ );
2399
+ if (!hasContentType) {
2400
+ next["content-type"] = typeof body === "string" || sniffJsonShapeBytes(body) ? "application/json" : "application/octet-stream";
2401
+ }
2402
+ return next;
2403
+ };
2361
2404
  var clientFetch = async (client, url, opts = {}) => {
2362
2405
  const startedAt = Date.now();
2363
2406
  const capabilityIdRequested = opts.capabilityId !== void 0;
2364
2407
  const method = opts.method ?? (opts.body !== void 0 ? "POST" : "GET");
2365
- const probeHeaders = opts.headers ? { ...opts.headers } : void 0;
2408
+ const probeHeaders = withDefaultContentType(opts.headers, opts.body);
2366
2409
  const requestInit = {
2367
2410
  method,
2368
2411
  headers: probeHeaders,
@@ -2379,6 +2422,16 @@ var clientFetch = async (client, url, opts = {}) => {
2379
2422
  try {
2380
2423
  response = await configuredFetch(url, requestInit);
2381
2424
  } catch (err) {
2425
+ if (err instanceof ZeroTimeoutError) {
2426
+ await recordTimeoutRun(
2427
+ client,
2428
+ opts,
2429
+ err,
2430
+ startedAt,
2431
+ capabilityIdRequested
2432
+ );
2433
+ throw err;
2434
+ }
2382
2435
  if (err instanceof ZeroError) throw err;
2383
2436
  const errMessage = err instanceof Error ? err.message : String(err);
2384
2437
  const result2 = errorFetchResult(
@@ -2400,8 +2453,9 @@ var clientFetch = async (client, url, opts = {}) => {
2400
2453
  url,
2401
2454
  method,
2402
2455
  // Fresh clone for the paid retry — same rationale as
2403
- // the probe-side clone above.
2404
- headers: opts.headers ? { ...opts.headers } : void 0,
2456
+ // the probe-side clone above. Re-derives the default
2457
+ // Content-Type so the paid leg matches the probe.
2458
+ headers: withDefaultContentType(opts.headers, opts.body),
2405
2459
  body: opts.body,
2406
2460
  maxPay: opts.maxPay,
2407
2461
  account: opts.account,
@@ -2437,6 +2491,15 @@ var clientFetch = async (client, url, opts = {}) => {
2437
2491
  );
2438
2492
  await recordErrorFetchRun(client, opts, result2);
2439
2493
  return result2;
2494
+ } else if (err instanceof ZeroTimeoutError) {
2495
+ await recordTimeoutRun(
2496
+ client,
2497
+ opts,
2498
+ err,
2499
+ startedAt,
2500
+ capabilityIdRequested
2501
+ );
2502
+ throw err;
2440
2503
  } else {
2441
2504
  throw err;
2442
2505
  }
@@ -3013,5 +3076,5 @@ var ZeroClient = class _ZeroClient {
3013
3076
  };
3014
3077
 
3015
3078
  export { Auth, AuthDevice, BUG_REPORT_CATEGORIES, BugReports, Capabilities, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, FETCH_SKIP_REASONS, FETCH_WARNINGS, Payments, Runs, SDK_VERSION, TEMPO_CHAIN_ID, TEMPO_TESTNET_CHAIN_ID, Wallet, ZeroApiError, ZeroAuthError, ZeroClient, ZeroConfigurationError, ZeroError, ZeroPaymentError, ZeroSessionCloseFailedError, ZeroTimeoutError, ZeroValidationError, ZeroWalletError, coerceTempoChainId, createManagedAccount, paymentHasAnchor, tempoChainLabelFromId };
3016
- //# sourceMappingURL=chunk-XQEHJX2X.js.map
3017
- //# sourceMappingURL=chunk-XQEHJX2X.js.map
3079
+ //# sourceMappingURL=chunk-SLXRHGE4.js.map
3080
+ //# sourceMappingURL=chunk-SLXRHGE4.js.map