@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/README.md +1 -1
- package/dist/agent-link.js +73 -7
- package/dist/agent-link.js.map +1 -1
- package/dist/atomic-file.d.ts +1 -0
- package/dist/atomic-file.d.ts.map +1 -1
- package/dist/backup.js +6 -4
- package/dist/backup.js.map +1 -1
- package/dist/cloud-backup.js +79 -11
- package/dist/cloud-backup.js.map +2 -2
- package/dist/index.js +82 -12
- package/dist/index.js.map +2 -2
- package/dist/net-guard.d.ts +17 -0
- package/dist/net-guard.d.ts.map +1 -1
- package/dist/router-client.js +80 -12
- package/dist/router-client.js.map +2 -2
- package/dist/secrets.js +19 -8
- package/dist/secrets.js.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/tasks.js +77 -9
- package/dist/tasks.js.map +2 -2
- package/package.json +1 -1
package/dist/cloud-backup.js
CHANGED
|
@@ -45644,12 +45644,12 @@ async function removeStaleLock(path) {
|
|
|
45644
45644
|
const pid = lockOwnerPid(owner);
|
|
45645
45645
|
if (pid !== void 0 && processIsAlive(pid)) return;
|
|
45646
45646
|
await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
|
|
45647
|
-
await removeOwnedLock(path, [owner]);
|
|
45647
|
+
await removeOwnedLock(path, [owner], true);
|
|
45648
45648
|
} catch (error61) {
|
|
45649
45649
|
if (!hasCode(error61, "ENOENT")) throw error61;
|
|
45650
45650
|
}
|
|
45651
45651
|
}
|
|
45652
|
-
async function removeOwnedLock(path, owners) {
|
|
45652
|
+
async function removeOwnedLock(path, owners, staleDeadOwner = false) {
|
|
45653
45653
|
const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
|
|
45654
45654
|
try {
|
|
45655
45655
|
await rename(path, tombPath);
|
|
@@ -45658,7 +45658,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
45658
45658
|
await removeOwnedTombs(path, owners);
|
|
45659
45659
|
const currentOwner = await readFile(path, "utf8").catch(() => void 0);
|
|
45660
45660
|
if (currentOwner !== void 0 && owners.includes(currentOwner)) {
|
|
45661
|
-
await removeOwnedLock(path, owners);
|
|
45661
|
+
await removeOwnedLock(path, owners, staleDeadOwner);
|
|
45662
45662
|
}
|
|
45663
45663
|
return;
|
|
45664
45664
|
}
|
|
@@ -45667,6 +45667,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
45667
45667
|
let pendingError;
|
|
45668
45668
|
let renamedOwner;
|
|
45669
45669
|
try {
|
|
45670
|
+
await atomicFileTestHooks?.afterLockRename?.(tombPath);
|
|
45670
45671
|
renamedOwner = await readFile(tombPath, "utf8");
|
|
45671
45672
|
if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
|
|
45672
45673
|
await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
|
|
@@ -45675,6 +45676,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
45675
45676
|
await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
|
|
45676
45677
|
}
|
|
45677
45678
|
} catch (error61) {
|
|
45679
|
+
if (hasCode(error61, "ENOENT")) return;
|
|
45678
45680
|
pendingError = error61;
|
|
45679
45681
|
}
|
|
45680
45682
|
try {
|
|
@@ -45683,7 +45685,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
45683
45685
|
} catch (error61) {
|
|
45684
45686
|
if (!tombUnlinkTolerated(
|
|
45685
45687
|
error61,
|
|
45686
|
-
renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
|
|
45688
|
+
renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
|
|
45687
45689
|
) && pendingError === void 0) {
|
|
45688
45690
|
pendingError = error61;
|
|
45689
45691
|
}
|
|
@@ -45864,7 +45866,7 @@ async function assertPublicUrl(url2, options) {
|
|
|
45864
45866
|
options.timeoutMs ?? 5e3
|
|
45865
45867
|
);
|
|
45866
45868
|
} catch {
|
|
45867
|
-
throw guardError(url2);
|
|
45869
|
+
throw guardError(url2, "unresolved");
|
|
45868
45870
|
}
|
|
45869
45871
|
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
45870
45872
|
throw guardError(url2);
|
|
@@ -46019,10 +46021,67 @@ function isNonPublicIpv6(hextets) {
|
|
|
46019
46021
|
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
46020
46022
|
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
46021
46023
|
}
|
|
46022
|
-
|
|
46023
|
-
|
|
46024
|
-
|
|
46024
|
+
var NetworkGuardError = class extends Error {
|
|
46025
|
+
constructor(message, reason) {
|
|
46026
|
+
super(message);
|
|
46027
|
+
this.reason = reason;
|
|
46028
|
+
this.name = "NetworkGuardError";
|
|
46029
|
+
}
|
|
46030
|
+
reason;
|
|
46031
|
+
};
|
|
46032
|
+
function guardError(url2, reason = "blocked") {
|
|
46033
|
+
return new NetworkGuardError(
|
|
46034
|
+
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
|
|
46035
|
+
reason
|
|
46036
|
+
);
|
|
46037
|
+
}
|
|
46038
|
+
var PROXY_VARIABLES = {
|
|
46039
|
+
"https:": ["HTTPS_PROXY", "https_proxy"],
|
|
46040
|
+
"http:": ["HTTP_PROXY", "http_proxy"]
|
|
46041
|
+
};
|
|
46042
|
+
var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
|
|
46043
|
+
function describeNetworkFailure(error61, url2, env = process.env) {
|
|
46044
|
+
const host = url2.host;
|
|
46045
|
+
let reason;
|
|
46046
|
+
const guard = guardReason(error61);
|
|
46047
|
+
if (guard !== void 0) {
|
|
46048
|
+
reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
|
|
46049
|
+
} else if (isTimeout(error61)) {
|
|
46050
|
+
reason = `the connection to ${host} timed out`;
|
|
46051
|
+
} else {
|
|
46052
|
+
const code = systemErrorCode(error61);
|
|
46053
|
+
reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
|
|
46054
|
+
}
|
|
46055
|
+
const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
|
|
46056
|
+
(name) => (env[name] ?? "").trim() !== ""
|
|
46025
46057
|
);
|
|
46058
|
+
let hint = "";
|
|
46059
|
+
if (proxy !== void 0) {
|
|
46060
|
+
if (env.NODE_USE_ENV_PROXY !== "1") {
|
|
46061
|
+
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.`;
|
|
46062
|
+
} else if (guard === "unresolved") {
|
|
46063
|
+
hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
|
|
46064
|
+
} else if (guard === void 0) {
|
|
46065
|
+
hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
|
|
46066
|
+
}
|
|
46067
|
+
}
|
|
46068
|
+
return `${reason}.${hint}`;
|
|
46069
|
+
}
|
|
46070
|
+
function guardReason(error61) {
|
|
46071
|
+
if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
|
|
46072
|
+
const reason = error61.reason;
|
|
46073
|
+
return reason === "blocked" || reason === "unresolved" ? reason : void 0;
|
|
46074
|
+
}
|
|
46075
|
+
function isTimeout(error61) {
|
|
46076
|
+
return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
|
|
46077
|
+
}
|
|
46078
|
+
function systemErrorCode(error61) {
|
|
46079
|
+
for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
|
|
46080
|
+
const code = current.code;
|
|
46081
|
+
if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
|
|
46082
|
+
current = current.cause;
|
|
46083
|
+
}
|
|
46084
|
+
return void 0;
|
|
46026
46085
|
}
|
|
46027
46086
|
|
|
46028
46087
|
// src/networks.ts
|
|
@@ -47094,16 +47153,25 @@ function withBearer(init, accessToken) {
|
|
|
47094
47153
|
async function safeFetch(fetchImpl, input2, init) {
|
|
47095
47154
|
try {
|
|
47096
47155
|
return await fetchImpl(input2, init);
|
|
47097
|
-
} catch {
|
|
47098
|
-
throw httpError(
|
|
47156
|
+
} catch (error61) {
|
|
47157
|
+
throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
|
|
47099
47158
|
}
|
|
47100
47159
|
}
|
|
47101
47160
|
async function safeAgentFetch(fetchImpl, input2, init) {
|
|
47102
47161
|
try {
|
|
47103
47162
|
return await fetchImpl(input2, init);
|
|
47163
|
+
} catch (error61) {
|
|
47164
|
+
throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
|
|
47165
|
+
}
|
|
47166
|
+
}
|
|
47167
|
+
function networkFailure(error61, input2) {
|
|
47168
|
+
let url2;
|
|
47169
|
+
try {
|
|
47170
|
+
url2 = new URL(input2 instanceof Request ? input2.url : input2);
|
|
47104
47171
|
} catch {
|
|
47105
|
-
|
|
47172
|
+
return "the request did not reach vAPI.";
|
|
47106
47173
|
}
|
|
47174
|
+
return describeNetworkFailure(error61, url2);
|
|
47107
47175
|
}
|
|
47108
47176
|
function notLinkedError() {
|
|
47109
47177
|
return new AgentLinkError("not_linked", "Run vapi login first.");
|