pubblue 0.4.7 → 0.4.10
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.
|
@@ -34,7 +34,11 @@ var TunnelApiClient = class {
|
|
|
34
34
|
if (!res.ok) {
|
|
35
35
|
if (res.status === 429) {
|
|
36
36
|
const retrySuffix = retryAfterSeconds !== void 0 ? ` Retry after ${retryAfterSeconds}s.` : "";
|
|
37
|
-
throw new TunnelApiError(
|
|
37
|
+
throw new TunnelApiError(
|
|
38
|
+
`Rate limit exceeded.${retrySuffix}`,
|
|
39
|
+
res.status,
|
|
40
|
+
retryAfterSeconds
|
|
41
|
+
);
|
|
38
42
|
}
|
|
39
43
|
throw new TunnelApiError(data.error || `Request failed: ${res.status}`, res.status);
|
|
40
44
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/lib/tunnel-ipc.ts
|
|
2
|
+
import * as net from "net";
|
|
3
|
+
function getSocketPath(tunnelId) {
|
|
4
|
+
return `/tmp/pubblue-${tunnelId}.sock`;
|
|
5
|
+
}
|
|
6
|
+
async function ipcCall(socketPath, request) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
let settled = false;
|
|
9
|
+
let timeoutId = null;
|
|
10
|
+
const finish = (fn) => {
|
|
11
|
+
if (settled) return;
|
|
12
|
+
settled = true;
|
|
13
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
14
|
+
fn();
|
|
15
|
+
};
|
|
16
|
+
const client = net.createConnection(socketPath, () => {
|
|
17
|
+
client.write(`${JSON.stringify(request)}
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
let data = "";
|
|
21
|
+
client.on("data", (chunk) => {
|
|
22
|
+
data += chunk.toString();
|
|
23
|
+
const newlineIdx = data.indexOf("\n");
|
|
24
|
+
if (newlineIdx !== -1) {
|
|
25
|
+
const line = data.slice(0, newlineIdx);
|
|
26
|
+
client.end();
|
|
27
|
+
try {
|
|
28
|
+
finish(() => resolve(JSON.parse(line)));
|
|
29
|
+
} catch {
|
|
30
|
+
finish(() => reject(new Error("Invalid response from daemon")));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
client.on("error", (err) => {
|
|
35
|
+
if (err.code === "ECONNREFUSED" || err.code === "ENOENT") {
|
|
36
|
+
finish(() => reject(new Error("Daemon not running. Is the tunnel still active?")));
|
|
37
|
+
} else {
|
|
38
|
+
finish(() => reject(err));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
client.on("end", () => {
|
|
42
|
+
if (!data.includes("\n")) {
|
|
43
|
+
finish(() => reject(new Error("Daemon closed connection unexpectedly")));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
timeoutId = setTimeout(() => {
|
|
47
|
+
client.destroy();
|
|
48
|
+
finish(() => reject(new Error("Daemon request timed out")));
|
|
49
|
+
}, 1e4);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
getSocketPath,
|
|
55
|
+
ipcCall
|
|
56
|
+
};
|