@zeroxyz/sdk 0.4.0 → 0.5.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.
@@ -1144,7 +1144,7 @@ var Payments = class {
1144
1144
 
1145
1145
  // package.json
1146
1146
  var package_default = {
1147
- version: "0.4.0"};
1147
+ version: "0.5.0"};
1148
1148
 
1149
1149
  // src/version.ts
1150
1150
  var SDK_VERSION = package_default.version;
@@ -1801,6 +1801,11 @@ var capabilityResponseSchema = z.object({
1801
1801
  lastUsedAt: z.string().nullable().optional(),
1802
1802
  lastSuccessfullyRanAt: z.string().nullable().optional()
1803
1803
  });
1804
+ var resolveCapabilityResponseSchema = z.object({
1805
+ capabilityId: z.string(),
1806
+ capabilitySlug: z.string(),
1807
+ matchedVia: z.enum(["exact", "template"])
1808
+ });
1804
1809
 
1805
1810
  // src/namespaces/capabilities.ts
1806
1811
  var Capabilities = class {
@@ -1817,6 +1822,31 @@ var Capabilities = class {
1817
1822
  },
1818
1823
  capabilityResponseSchema
1819
1824
  );
1825
+ // Resolve a raw endpoint URL + method back to the capability that owns it,
1826
+ // for the `zero fetch <url>` case where the client has no local search
1827
+ // context to match against (a memoized/cross-session URL). Returns null on
1828
+ // 404 — i.e. no match or an ambiguous multi-match, both of which the server
1829
+ // reports as 404 (resolveByUrl fails closed rather than mis-attribute).
1830
+ // The URL travels in the POST body so it stays out of access logs and is
1831
+ // never stored; the caller uses the returned capabilityId to record an
1832
+ // attributed run without the URL ever touching the run row (ZERO-335).
1833
+ resolveByUrl = async (url, method, opts = {}) => {
1834
+ try {
1835
+ return await request(
1836
+ this.client,
1837
+ {
1838
+ method: "POST",
1839
+ path: "/v1/capabilities/resolve",
1840
+ body: { url, method },
1841
+ signal: opts.signal
1842
+ },
1843
+ resolveCapabilityResponseSchema
1844
+ );
1845
+ } catch (err) {
1846
+ if (err instanceof ZeroApiError && err.status === 404) return null;
1847
+ throw err;
1848
+ }
1849
+ };
1820
1850
  };
1821
1851
  var createRunResponseSchema = z.object({
1822
1852
  runId: z.string()
@@ -2397,14 +2427,17 @@ var resolveRecordingClient = (client, opts) => {
2397
2427
  const canRecord = opts.account !== void 0 || credentials.kind === "account" || credentials.kind === "session";
2398
2428
  return { recordingClient, canRecord };
2399
2429
  };
2400
- var recordErrorFetchRun = async (client, opts, result) => {
2401
- if (opts.capabilityId === void 0) return;
2430
+ var recordErrorFetchRun = async (client, opts, result, capabilityIdOverride) => {
2431
+ const effectiveCapId = opts.capabilityId;
2432
+ if (effectiveCapId === void 0) return;
2402
2433
  const { recordingClient, canRecord } = resolveRecordingClient(client, opts);
2403
2434
  if (!canRecord) return;
2435
+ const fetchOriginForRecord = opts.capabilityId === void 0 ? "direct_url" : opts.fetchOrigin;
2404
2436
  try {
2405
2437
  const created = await recordingClient.runs.create({
2406
- capabilityId: opts.capabilityId,
2438
+ capabilityId: effectiveCapId,
2407
2439
  ...opts.searchId && { searchId: opts.searchId },
2440
+ ...fetchOriginForRecord && { fetchOrigin: fetchOriginForRecord },
2408
2441
  ...result.status !== null && { status: result.status },
2409
2442
  latencyMs: result.latencyMs,
2410
2443
  ...opts.requestSchema && { requestSchema: opts.requestSchema }
@@ -2414,7 +2447,7 @@ var recordErrorFetchRun = async (client, opts, result) => {
2414
2447
  } catch {
2415
2448
  }
2416
2449
  };
2417
- var recordTimeoutRun = async (client, opts, err, startedAt, capabilityIdRequested) => {
2450
+ var recordTimeoutRun = async (client, opts, err, startedAt, capabilityIdRequested, capabilityIdOverride) => {
2418
2451
  const result = errorFetchResult(
2419
2452
  startedAt,
2420
2453
  err.message,
@@ -2451,6 +2484,11 @@ var clientFetch = async (client, url, opts = {}) => {
2451
2484
  const startedAt = Date.now();
2452
2485
  const capabilityIdRequested = opts.capabilityId !== void 0;
2453
2486
  const method = opts.method ?? (opts.body !== void 0 ? "POST" : "GET");
2487
+ const { canRecord: canRecordForResolve } = resolveRecordingClient(
2488
+ client,
2489
+ opts
2490
+ );
2491
+ const resolvePromise = !capabilityIdRequested && canRecordForResolve ? client.capabilities.resolveByUrl(redactUrl(url), method).catch(() => null) : Promise.resolve(null);
2454
2492
  const probeHeaders = withDefaultContentType(opts.headers, opts.body);
2455
2493
  const requestInit = {
2456
2494
  method,
@@ -2642,7 +2680,15 @@ var clientFetch = async (client, url, opts = {}) => {
2642
2680
  else if (closeFailed)
2643
2681
  skipReasons.push(FETCH_SKIP_REASONS.mppSessionCloseFailedNotRecorded);
2644
2682
  }
2645
- if (opts.capabilityId !== void 0 && !paidButStill402 && !closeFailed) {
2683
+ const resolvedCap = await resolvePromise;
2684
+ const effectiveCapabilityId = opts.capabilityId ?? resolvedCap?.capabilityId;
2685
+ const capabilityResolution = !capabilityIdRequested && canRecordForResolve ? resolvedCap !== null ? {
2686
+ resolved: true,
2687
+ capabilityId: resolvedCap.capabilityId,
2688
+ capabilitySlug: resolvedCap.capabilitySlug,
2689
+ matchedVia: resolvedCap.matchedVia
2690
+ } : { resolved: false } : void 0;
2691
+ if (effectiveCapabilityId !== void 0 && !paidButStill402 && !closeFailed) {
2646
2692
  const { recordingClient, canRecord } = resolveRecordingClient(client, opts);
2647
2693
  if (!canRecord) {
2648
2694
  skipReasons.push("no_credentials");
@@ -2662,8 +2708,11 @@ var clientFetch = async (client, url, opts = {}) => {
2662
2708
  }
2663
2709
  }
2664
2710
  const result2 = await recordingClient.runs.create({
2665
- capabilityId: opts.capabilityId,
2711
+ capabilityId: effectiveCapabilityId,
2666
2712
  searchId: opts.searchId,
2713
+ // Auto-resolved runs are always direct_url — they only fire when
2714
+ // no capabilityId was supplied (the direct_url path by definition).
2715
+ ...opts.capabilityId === void 0 ? { fetchOrigin: "direct_url" } : opts.fetchOrigin && { fetchOrigin: opts.fetchOrigin },
2667
2716
  status: response.status,
2668
2717
  latencyMs,
2669
2718
  ...opts.requestSchema && { requestSchema: opts.requestSchema },
@@ -2696,7 +2745,7 @@ var clientFetch = async (client, url, opts = {}) => {
2696
2745
  message: "Failed to record run for fetch",
2697
2746
  meta: {
2698
2747
  url: redactUrl(url),
2699
- capabilityId: opts.capabilityId,
2748
+ capabilityId: effectiveCapabilityId,
2700
2749
  error: errorMessage2,
2701
2750
  errorCode: code
2702
2751
  }
@@ -2724,6 +2773,8 @@ var clientFetch = async (client, url, opts = {}) => {
2724
2773
  result.runTrackingSkipped = skipReasons;
2725
2774
  }
2726
2775
  if (warnings.length > 0) result.warnings = warnings;
2776
+ if (capabilityResolution !== void 0)
2777
+ result.capabilityResolution = capabilityResolution;
2727
2778
  return result;
2728
2779
  };
2729
2780
  var searchResultSchema = z.object({
@@ -3138,5 +3189,5 @@ var ZeroClient = class _ZeroClient {
3138
3189
  };
3139
3190
 
3140
3191
  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 };
3141
- //# sourceMappingURL=chunk-RPL7VC32.js.map
3142
- //# sourceMappingURL=chunk-RPL7VC32.js.map
3192
+ //# sourceMappingURL=chunk-RY3VFSIE.js.map
3193
+ //# sourceMappingURL=chunk-RY3VFSIE.js.map