@vapi-network/core 0.15.1 → 0.15.2

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 CHANGED
@@ -43375,7 +43375,7 @@ async function assertPublicUrl(url2, options) {
43375
43375
  options.timeoutMs ?? 5e3
43376
43376
  );
43377
43377
  } catch {
43378
- throw guardError(url2);
43378
+ throw guardError(url2, "unresolved");
43379
43379
  }
43380
43380
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43381
43381
  throw guardError(url2);
@@ -43530,10 +43530,67 @@ function isNonPublicIpv6(hextets) {
43530
43530
  const isDocumentation = first === 8193 && hextets[1] === 3512;
43531
43531
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
43532
43532
  }
43533
- function guardError(url2) {
43534
- return new Error(
43535
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
43533
+ var NetworkGuardError = class extends Error {
43534
+ constructor(message, reason) {
43535
+ super(message);
43536
+ this.reason = reason;
43537
+ this.name = "NetworkGuardError";
43538
+ }
43539
+ reason;
43540
+ };
43541
+ function guardError(url2, reason = "blocked") {
43542
+ return new NetworkGuardError(
43543
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
43544
+ reason
43545
+ );
43546
+ }
43547
+ var PROXY_VARIABLES = {
43548
+ "https:": ["HTTPS_PROXY", "https_proxy"],
43549
+ "http:": ["HTTP_PROXY", "http_proxy"]
43550
+ };
43551
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
43552
+ function describeNetworkFailure(error61, url2, env = process.env) {
43553
+ const host = url2.host;
43554
+ let reason;
43555
+ const guard = guardReason(error61);
43556
+ if (guard !== void 0) {
43557
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
43558
+ } else if (isTimeout(error61)) {
43559
+ reason = `the connection to ${host} timed out`;
43560
+ } else {
43561
+ const code = systemErrorCode(error61);
43562
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
43563
+ }
43564
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
43565
+ (name) => (env[name] ?? "").trim() !== ""
43536
43566
  );
43567
+ let hint = "";
43568
+ if (proxy !== void 0) {
43569
+ if (env.NODE_USE_ENV_PROXY !== "1") {
43570
+ hint = ` ${proxy} is set, but Node.js uses it only with NODE_USE_ENV_PROXY=1 (Node.js 22.21 or later): run the command again with NODE_USE_ENV_PROXY=1.`;
43571
+ } else if (guard === "unresolved") {
43572
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
43573
+ } else if (guard === void 0) {
43574
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
43575
+ }
43576
+ }
43577
+ return `${reason}.${hint}`;
43578
+ }
43579
+ function guardReason(error61) {
43580
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
43581
+ const reason = error61.reason;
43582
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
43583
+ }
43584
+ function isTimeout(error61) {
43585
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
43586
+ }
43587
+ function systemErrorCode(error61) {
43588
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
43589
+ const code = current.code;
43590
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
43591
+ current = current.cause;
43592
+ }
43593
+ return void 0;
43537
43594
  }
43538
43595
 
43539
43596
  // src/networks.ts
@@ -46668,12 +46725,12 @@ async function removeStaleLock(path) {
46668
46725
  const pid = lockOwnerPid(owner);
46669
46726
  if (pid !== void 0 && processIsAlive(pid)) return;
46670
46727
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
46671
- await removeOwnedLock(path, [owner]);
46728
+ await removeOwnedLock(path, [owner], true);
46672
46729
  } catch (error61) {
46673
46730
  if (!hasCode(error61, "ENOENT")) throw error61;
46674
46731
  }
46675
46732
  }
46676
- async function removeOwnedLock(path, owners) {
46733
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
46677
46734
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
46678
46735
  try {
46679
46736
  await rename(path, tombPath);
@@ -46682,7 +46739,7 @@ async function removeOwnedLock(path, owners) {
46682
46739
  await removeOwnedTombs(path, owners);
46683
46740
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
46684
46741
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
46685
- await removeOwnedLock(path, owners);
46742
+ await removeOwnedLock(path, owners, staleDeadOwner);
46686
46743
  }
46687
46744
  return;
46688
46745
  }
@@ -46691,6 +46748,7 @@ async function removeOwnedLock(path, owners) {
46691
46748
  let pendingError;
46692
46749
  let renamedOwner;
46693
46750
  try {
46751
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
46694
46752
  renamedOwner = await readFile(tombPath, "utf8");
46695
46753
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
46696
46754
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -46699,6 +46757,7 @@ async function removeOwnedLock(path, owners) {
46699
46757
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
46700
46758
  }
46701
46759
  } catch (error61) {
46760
+ if (hasCode(error61, "ENOENT")) return;
46702
46761
  pendingError = error61;
46703
46762
  }
46704
46763
  try {
@@ -46707,7 +46766,7 @@ async function removeOwnedLock(path, owners) {
46707
46766
  } catch (error61) {
46708
46767
  if (!tombUnlinkTolerated(
46709
46768
  error61,
46710
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
46769
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
46711
46770
  ) && pendingError === void 0) {
46712
46771
  pendingError = error61;
46713
46772
  }
@@ -47939,16 +47998,25 @@ function withBearer(init, accessToken) {
47939
47998
  async function safeFetch(fetchImpl, input2, init) {
47940
47999
  try {
47941
48000
  return await fetchImpl(input2, init);
47942
- } catch {
47943
- throw httpError("The vAPI agent link request failed.");
48001
+ } catch (error61) {
48002
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
47944
48003
  }
47945
48004
  }
47946
48005
  async function safeAgentFetch(fetchImpl, input2, init) {
47947
48006
  try {
47948
48007
  return await fetchImpl(input2, init);
48008
+ } catch (error61) {
48009
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48010
+ }
48011
+ }
48012
+ function networkFailure(error61, input2) {
48013
+ let url2;
48014
+ try {
48015
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
47949
48016
  } catch {
47950
- throw httpError("The vAPI agent request failed.");
48017
+ return "the request did not reach vAPI.";
47951
48018
  }
48019
+ return describeNetworkFailure(error61, url2);
47952
48020
  }
47953
48021
  function deviceAuthorizationError(status, payload) {
47954
48022
  const error61 = stringField(payload, "error");
@@ -77990,7 +78058,7 @@ function createRunBudget(args) {
77990
78058
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
77991
78059
  import { arch, platform, release } from "node:os";
77992
78060
  import { join as join14 } from "node:path";
77993
- var VAPI_CLIENT_VERSION = "0.15.1";
78061
+ var VAPI_CLIENT_VERSION = "0.15.2";
77994
78062
  async function createSupportReport(options) {
77995
78063
  const message = options.message.trim();
77996
78064
  if (!message) throw new Error("Support report message must not be empty.");
@@ -83400,6 +83468,7 @@ export {
83400
83468
  NATIVE_ETH_FEE_MARGIN_PERCENT,
83401
83469
  NATIVE_ETH_L1_FEE_FALLBACK_WEI,
83402
83470
  NETWORKS,
83471
+ NetworkGuardError,
83403
83472
  ONRAMP_FALLBACK_INSTRUCTIONS,
83404
83473
  ONRAMP_NETWORK,
83405
83474
  PASSPHRASE_ENVIRONMENT_VARIABLE,
@@ -83506,6 +83575,7 @@ export {
83506
83575
  deleteSwarmFile,
83507
83576
  deriveEvmPrivateKey,
83508
83577
  deriveSolanaPrivateKey,
83578
+ describeNetworkFailure,
83509
83579
  deviceName,
83510
83580
  discardBody,
83511
83581
  discover,