@nr-connect/node-red 0.0.0-stage → 1.0.1

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/index.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ const {
4
+ verifyWorkerHeaders,
5
+ isLocalEscapeHatchActive,
6
+ installExpressInterceptor,
7
+ } = require("./lib/expressInterceptor");
8
+ const {
9
+ attachDashboardIoProtection,
10
+ createDashboardPluginHooks,
11
+ } = require("./lib/dashboardRbac");
12
+ const {
13
+ createConnectionManager,
14
+ registerAdminRoutes,
15
+ } = require("./lib/connectionManager");
16
+ const { setActiveConfigProvider } = require("./lib/pushAgent");
17
+ const { installStatusEndpoint } = require("./lib/statusEndpoint");
18
+
19
+ module.exports = function (RED) {
20
+ const socketUserCache = new Map();
21
+ const manager = createConnectionManager({ RED });
22
+ setActiveConfigProvider(manager.getActiveConfig);
23
+ let uninstallStatusEndpoint = () => {};
24
+
25
+ const mountStatusEndpoint = () => {
26
+ uninstallStatusEndpoint = installStatusEndpoint(RED, {
27
+ getPluginConfig: manager.getActiveConfig,
28
+ getRuntimeStatus: manager.getStatus,
29
+ });
30
+ };
31
+
32
+ const dashboardDeps = {
33
+ RED,
34
+ getPluginConfig: manager.getActiveConfig,
35
+ socketUserCache,
36
+ verifyWorkerHeaders,
37
+ isLocalEscapeHatchActive,
38
+ logger: RED?.log,
39
+ };
40
+
41
+ // 1. Register Primary Node-RED Runtime Plugin
42
+ RED.plugins.registerPlugin("nr-connect", {
43
+ type: "nr-connect",
44
+ onadd: function () {
45
+ RED.log?.info?.("[NR Connect] Runtime plugin initialized");
46
+ installExpressInterceptor(RED, manager.getActiveConfig);
47
+ mountStatusEndpoint();
48
+ attachDashboardIoProtection(RED, manager.getActiveConfig, dashboardDeps);
49
+ manager.init();
50
+ },
51
+ onremove: function () {
52
+ socketUserCache.clear();
53
+ uninstallStatusEndpoint();
54
+ manager.stop();
55
+ },
56
+ });
57
+
58
+ // 2. Register FlowFuse Dashboard 2.0 Auth & Page RBAC Hooks (Injects msg._client.user & enforces page access)
59
+ RED.plugins.registerPlugin("nr-connect-d2-auth", {
60
+ type: "node-red-dashboard-2",
61
+ hooks: createDashboardPluginHooks(dashboardDeps),
62
+ });
63
+
64
+ // 3. Attach Dashboard Socket.IO Protection, Auto-Discover Dashboard Pages & Sync on Deploy
65
+ RED.events?.on?.("flows:started", () => {
66
+ attachDashboardIoProtection(RED, manager.getActiveConfig, dashboardDeps);
67
+ manager.handleFlowsStarted();
68
+ });
69
+
70
+ // 4. Install Express Interceptor & Status Endpoint immediately if httpNode/server is already active
71
+ installExpressInterceptor(RED, manager.getActiveConfig);
72
+ mountStatusEndpoint();
73
+
74
+ // 5. Expose /nr-connect/* Admin API Routes for Sidebar UI
75
+ registerAdminRoutes(RED, manager);
76
+ };
@@ -0,0 +1,557 @@
1
+ "use strict";
2
+
3
+ const crypto = require("crypto");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { execFileSync } = require("child_process");
7
+ const PINNED_CONNECTOR_MANIFEST = require("./connectorManifest.json");
8
+
9
+ const CLOUDFLARED_BASE_URL = PINNED_CONNECTOR_MANIFEST.baseUrl;
10
+ const ALLOWED_CONNECTOR_URL_PREFIX =
11
+ "https://github.com/cloudflare/cloudflared/releases/download/";
12
+ const ALLOWED_BIN_NAMES = new Set(["cloudflared", "cloudflared.exe"]);
13
+ const METADATA_FILENAME = "cloudflared-meta.json";
14
+
15
+ function validateConnectorAssetSpec(url, binName) {
16
+ if (typeof binName !== "string" || !ALLOWED_BIN_NAMES.has(binName)) {
17
+ throw new Error(`Disallowed connector binary name: ${String(binName)}`);
18
+ }
19
+ let parsed;
20
+ try {
21
+ parsed = new URL(String(url || ""));
22
+ } catch {
23
+ throw new Error("Invalid connector download URL");
24
+ }
25
+ if (
26
+ parsed.protocol !== "https:" ||
27
+ !parsed.href.startsWith(ALLOWED_CONNECTOR_URL_PREFIX)
28
+ ) {
29
+ throw new Error(
30
+ "Connector download URL must originate from official Cloudflare GitHub releases"
31
+ );
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Parse a version string like `cloudflared version 2026.11.0 (built ...)` or `v1.2.3`.
37
+ * @param {string} raw
38
+ * @returns {string|null}
39
+ */
40
+ function parseVersionString(raw) {
41
+ if (typeof raw !== "string") return null;
42
+ const match = raw.match(/\bv?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\b/);
43
+ return match ? match[1] : null;
44
+ }
45
+
46
+ /**
47
+ * Compare two dotted numeric versions (`2026.11.0`, `0.2.0`).
48
+ * Returns `-1` if `a < b`, `0` if equal, `1` if `a > b`, or `null` if unparseable.
49
+ * @param {string|null|undefined} a
50
+ * @param {string|null|undefined} b
51
+ * @returns {number|null}
52
+ */
53
+ function compareVersions(a, b) {
54
+ const normA = parseVersionString(String(a || ""));
55
+ const normB = parseVersionString(String(b || ""));
56
+ if (!normA || !normB) return null;
57
+
58
+ const splitParts = (v) =>
59
+ v
60
+ .split("-")[0]
61
+ .split("+")[0]
62
+ .split(".")
63
+ .map((n) => Number.parseInt(n, 10));
64
+
65
+ const partsA = splitParts(normA);
66
+ const partsB = splitParts(normB);
67
+ const len = Math.max(partsA.length, partsB.length);
68
+
69
+ for (let i = 0; i < len; i += 1) {
70
+ const numA = partsA[i] || 0;
71
+ const numB = partsB[i] || 0;
72
+ if (Number.isNaN(numA) || Number.isNaN(numB)) return null;
73
+ if (numA < numB) return -1;
74
+ if (numA > numB) return 1;
75
+ }
76
+ return 0;
77
+ }
78
+
79
+ /**
80
+ * Resolve the pinned cloudflared download URL, binary filename, and SHA-256 digest
81
+ * for a given platform/arch using an optional override manifest or single-asset spec.
82
+ *
83
+ * @param {string} [platform]
84
+ * @param {string} [arch]
85
+ * @param {object} [manifestOverride]
86
+ * @returns {{ url: string, binName: string, isTgz: boolean, sha256: string|null, version: string|null }}
87
+ */
88
+ function resolveBinaryUrl(platform = process.platform, arch = process.arch, manifestOverride = null) {
89
+ const key = `${platform}-${arch}`;
90
+
91
+ if (manifestOverride && typeof manifestOverride === "object") {
92
+ if (manifestOverride.asset && typeof manifestOverride.asset === "object") {
93
+ const a = manifestOverride.asset;
94
+ const base = String(manifestOverride.baseUrl || "").replace(/\/+$/, "");
95
+ const url = a.url || (base && a.filename ? `${base}/${a.filename}` : null);
96
+ if (url && a.binName) {
97
+ return {
98
+ url,
99
+ binName: a.binName,
100
+ isTgz: Boolean(a.isTgz),
101
+ sha256: typeof a.sha256 === "string" ? a.sha256.toLowerCase() : null,
102
+ version: manifestOverride.version || manifestOverride.latest || null,
103
+ };
104
+ }
105
+ }
106
+
107
+ const overrideAsset = manifestOverride.assets?.[key];
108
+ if (overrideAsset) {
109
+ const base = String(manifestOverride.baseUrl || "").replace(/\/+$/, "");
110
+ const url = overrideAsset.url || (base && overrideAsset.filename ? `${base}/${overrideAsset.filename}` : null);
111
+ if (url) {
112
+ return {
113
+ url,
114
+ binName: overrideAsset.binName,
115
+ isTgz: Boolean(overrideAsset.isTgz),
116
+ sha256: typeof overrideAsset.sha256 === "string" ? overrideAsset.sha256.toLowerCase() : null,
117
+ version: manifestOverride.version || manifestOverride.latest || null,
118
+ };
119
+ }
120
+ }
121
+ }
122
+
123
+ const asset = PINNED_CONNECTOR_MANIFEST.assets[key];
124
+ if (!asset) {
125
+ if (platform === "linux") {
126
+ throw new Error(`Unsupported Linux architecture for connector: ${arch}`);
127
+ }
128
+ if (platform === "darwin") {
129
+ throw new Error(`Unsupported macOS architecture for connector: ${arch}`);
130
+ }
131
+ if (platform === "win32") {
132
+ throw new Error(`Unsupported Windows architecture for connector: ${arch}`);
133
+ }
134
+ throw new Error(`Unsupported operating system for connector: ${platform}`);
135
+ }
136
+
137
+ return {
138
+ url: `${PINNED_CONNECTOR_MANIFEST.baseUrl}/${asset.filename}`,
139
+ binName: asset.binName,
140
+ isTgz: Boolean(asset.isTgz),
141
+ sha256: asset.sha256.toLowerCase(),
142
+ version: PINNED_CONNECTOR_MANIFEST.version,
143
+ };
144
+ }
145
+
146
+ /**
147
+ * Verify a buffer's SHA-256 hex digest in constant time.
148
+ * @param {Buffer} buffer
149
+ * @param {string} expectedHex
150
+ */
151
+ function verifySha256(buffer, expectedHex) {
152
+ if (typeof expectedHex !== "string" || !/^[0-9a-f]{64}$/i.test(expectedHex.trim())) {
153
+ throw new Error("Missing or invalid expected SHA-256 checksum for connector download");
154
+ }
155
+ const normalizedExpected = expectedHex.trim().toLowerCase();
156
+ const actualHex = crypto.createHash("sha256").update(buffer).digest("hex");
157
+ const expectedBuf = Buffer.from(normalizedExpected, "utf8");
158
+ const actualBuf = Buffer.from(actualHex, "utf8");
159
+ if (expectedBuf.length !== actualBuf.length || !crypto.timingSafeEqual(expectedBuf, actualBuf)) {
160
+ throw new Error(
161
+ `Connector checksum verification failed (expected ${normalizedExpected}, got ${actualHex})`
162
+ );
163
+ }
164
+ return actualHex;
165
+ }
166
+
167
+ /**
168
+ * Run `<binaryPath> --version` and parse the semantic/calendar version.
169
+ * @param {string} binaryPath
170
+ * @param {Function} [execFileSyncImpl]
171
+ * @returns {string|null}
172
+ */
173
+ function getBinaryVersion(binaryPath, execFileSyncImpl = execFileSync) {
174
+ if (!binaryPath) return null;
175
+ try {
176
+ const out = execFileSyncImpl(binaryPath, ["--version"], {
177
+ encoding: "utf8",
178
+ stdio: ["ignore", "pipe", "pipe"],
179
+ timeout: 3000,
180
+ });
181
+ return parseVersionString(String(out || ""));
182
+ } catch {
183
+ return null;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Check if `cloudflared` is already installed on the system PATH.
189
+ * @param {Function} [execFileSyncImpl]
190
+ * @returns {string|null}
191
+ */
192
+ function findSystemCloudflared(execFileSyncImpl = execFileSync) {
193
+ try {
194
+ execFileSyncImpl("cloudflared", ["--version"], { stdio: "ignore", timeout: 3000 });
195
+ return "cloudflared";
196
+ } catch {
197
+ return null;
198
+ }
199
+ }
200
+
201
+ function getMetadataPath(storageDir) {
202
+ return path.join(storageDir, "bin", METADATA_FILENAME);
203
+ }
204
+
205
+ function readBinaryMetadata(storageDir, fsImpl = fs) {
206
+ try {
207
+ const metaPath = getMetadataPath(storageDir);
208
+ if (!fsImpl.existsSync(metaPath)) return null;
209
+ const parsed = JSON.parse(fsImpl.readFileSync(metaPath, "utf8"));
210
+ return parsed && typeof parsed === "object" ? parsed : null;
211
+ } catch {
212
+ return null;
213
+ }
214
+ }
215
+
216
+ function writeBinaryMetadata(storageDir, meta, fsImpl = fs) {
217
+ const metaPath = getMetadataPath(storageDir);
218
+ fsImpl.mkdirSync(path.dirname(metaPath), { recursive: true });
219
+ fsImpl.writeFileSync(metaPath, JSON.stringify(meta, null, 2));
220
+ }
221
+
222
+ /**
223
+ * Inspect whether a runnable cloudflared binary comes from system PATH or `<userDir>/bin`,
224
+ * along with its detected version.
225
+ * @param {string} storageDir
226
+ * @param {{ platform?: string, arch?: string, execFileSyncImpl?: Function, fsImpl?: object }} [options]
227
+ * @returns {{ path: string|null, source: "system"|"managed"|"missing", version: string|null }}
228
+ */
229
+ function resolveConnectorBinaryInfo(storageDir, options = {}) {
230
+ const platform = options.platform || process.platform;
231
+ const arch = options.arch || process.arch;
232
+ const execFileSyncImpl = options.execFileSyncImpl || execFileSync;
233
+ const fsImpl = options.fsImpl || fs;
234
+
235
+ const systemBin = findSystemCloudflared(execFileSyncImpl);
236
+ if (systemBin) {
237
+ return {
238
+ path: systemBin,
239
+ source: "system",
240
+ version: getBinaryVersion(systemBin, execFileSyncImpl),
241
+ };
242
+ }
243
+
244
+ const { binName } = resolveBinaryUrl(platform, arch);
245
+ const targetPath = path.join(storageDir, "bin", binName);
246
+ if (fsImpl.existsSync(targetPath)) {
247
+ const meta = readBinaryMetadata(storageDir, fsImpl);
248
+ const liveVersion = getBinaryVersion(targetPath, execFileSyncImpl);
249
+ return {
250
+ path: targetPath,
251
+ source: "managed",
252
+ version: liveVersion || (typeof meta?.version === "string" ? meta.version : null),
253
+ };
254
+ }
255
+
256
+ return {
257
+ path: null,
258
+ source: "missing",
259
+ version: null,
260
+ };
261
+ }
262
+
263
+ function moveFileReplacing(src, dest, fsImpl = fs) {
264
+ try {
265
+ fsImpl.renameSync(src, dest);
266
+ } catch (err) {
267
+ if (err && err.code === "EXDEV") {
268
+ fsImpl.copyFileSync(src, dest);
269
+ fsImpl.unlinkSync(src);
270
+ return;
271
+ }
272
+ throw err;
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Download, verify SHA-256 checksum, extract if needed, and smoke-test a cloudflared
278
+ * binary inside a temporary staging directory before touching any active binary.
279
+ */
280
+ async function downloadAndStageBinary(storageDir, logger = console, options = {}) {
281
+ const platform = options.platform || process.platform;
282
+ const arch = options.arch || process.arch;
283
+ const fetchImpl = options.fetchImpl || globalThis.fetch;
284
+ const execFileSyncImpl = options.execFileSyncImpl || execFileSync;
285
+ const fsImpl = options.fsImpl || fs;
286
+ const requireChecksum = options.requireChecksum !== false;
287
+ const smokeCheck = options.smokeCheck !== false;
288
+
289
+ if (typeof fetchImpl !== "function") {
290
+ throw new Error("Global fetch API is unavailable to download connector");
291
+ }
292
+
293
+ const { url, binName, isTgz, sha256, version } = resolveBinaryUrl(
294
+ platform,
295
+ arch,
296
+ options.manifest || null
297
+ );
298
+
299
+ validateConnectorAssetSpec(url, binName);
300
+
301
+ if (requireChecksum && !sha256) {
302
+ throw new Error("Pinned SHA-256 checksum is required to download connector");
303
+ }
304
+
305
+ const binDir = path.join(storageDir, "bin");
306
+ const targetPath = path.join(binDir, binName);
307
+ const stagingDir = path.join(
308
+ binDir,
309
+ `.staging-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
310
+ );
311
+
312
+ fsImpl.mkdirSync(stagingDir, { recursive: true });
313
+
314
+ try {
315
+ logger.info?.(`[NR Connect] Downloading connector${version ? ` (${version})` : ""}...`);
316
+ const response = await fetchImpl(url, { redirect: "follow" });
317
+ if (!response.ok) {
318
+ throw new Error(`Failed to download connector (${response.status} ${response.statusText})`);
319
+ }
320
+
321
+ const buffer = Buffer.from(await response.arrayBuffer());
322
+ const verifiedSha256 = sha256
323
+ ? verifySha256(buffer, sha256)
324
+ : crypto.createHash("sha256").update(buffer).digest("hex");
325
+
326
+ const stagedPath = path.join(stagingDir, binName);
327
+ if (isTgz) {
328
+ const archivePath = path.join(stagingDir, "cloudflared.tgz");
329
+ fsImpl.writeFileSync(archivePath, buffer);
330
+ try {
331
+ execFileSyncImpl("tar", ["-xzf", archivePath, "-C", stagingDir], {
332
+ stdio: "ignore",
333
+ timeout: 15000,
334
+ });
335
+ } finally {
336
+ if (fsImpl.existsSync(archivePath)) {
337
+ fsImpl.unlinkSync(archivePath);
338
+ }
339
+ }
340
+ } else {
341
+ fsImpl.writeFileSync(stagedPath, buffer);
342
+ }
343
+
344
+ if (!fsImpl.existsSync(stagedPath)) {
345
+ throw new Error("Connector binary was not found after extraction");
346
+ }
347
+
348
+ if (platform !== "win32") {
349
+ fsImpl.chmodSync(stagedPath, 0o755);
350
+ }
351
+
352
+ let detectedVersion = version;
353
+ if (smokeCheck) {
354
+ const probed = getBinaryVersion(stagedPath, execFileSyncImpl);
355
+ if (!probed) {
356
+ throw new Error("Staged connector binary failed '--version' smoke check");
357
+ }
358
+ if (version && compareVersions(probed, version) !== 0) {
359
+ throw new Error(
360
+ `Staged connector version mismatch (expected ${version}, got ${probed})`
361
+ );
362
+ }
363
+ detectedVersion = probed;
364
+ }
365
+
366
+ return {
367
+ stagingDir,
368
+ stagedPath,
369
+ targetPath,
370
+ version: detectedVersion,
371
+ sha256: verifiedSha256,
372
+ };
373
+ } catch (err) {
374
+ fsImpl.rmSync(stagingDir, { recursive: true, force: true });
375
+ throw err;
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Stop any active daemon, atomically swap the staged binary into `targetPath` with rollback
381
+ * protection, and persist metadata.
382
+ */
383
+ async function promoteStagedBinary({
384
+ storageDir,
385
+ stagingDir,
386
+ stagedPath,
387
+ targetPath,
388
+ version,
389
+ sha256,
390
+ stopDaemon,
391
+ platform = process.platform,
392
+ fsImpl = fs,
393
+ }) {
394
+ const backupPath = `${targetPath}.bak`;
395
+
396
+ try {
397
+ if (typeof stopDaemon === "function") {
398
+ await stopDaemon();
399
+ }
400
+
401
+ if (fsImpl.existsSync(backupPath)) {
402
+ fsImpl.rmSync(backupPath, { force: true });
403
+ }
404
+
405
+ if (fsImpl.existsSync(targetPath)) {
406
+ moveFileReplacing(targetPath, backupPath, fsImpl);
407
+ }
408
+
409
+ try {
410
+ moveFileReplacing(stagedPath, targetPath, fsImpl);
411
+ } catch (swapErr) {
412
+ if (fsImpl.existsSync(backupPath) && !fsImpl.existsSync(targetPath)) {
413
+ try {
414
+ moveFileReplacing(backupPath, targetPath, fsImpl);
415
+ } catch {
416
+ // Best-effort rollback
417
+ }
418
+ }
419
+ throw swapErr;
420
+ }
421
+
422
+ if (platform !== "win32") {
423
+ try {
424
+ fsImpl.chmodSync(targetPath, 0o755);
425
+ } catch {
426
+ // Ignore chmod errors on read-only fs
427
+ }
428
+ }
429
+
430
+ if (fsImpl.existsSync(backupPath)) {
431
+ fsImpl.rmSync(backupPath, { force: true });
432
+ }
433
+
434
+ writeBinaryMetadata(
435
+ storageDir,
436
+ {
437
+ version: version || null,
438
+ sha256: sha256 || null,
439
+ installedAt: new Date().toISOString(),
440
+ },
441
+ fsImpl
442
+ );
443
+
444
+ return targetPath;
445
+ } finally {
446
+ if (stagingDir) {
447
+ fsImpl.rmSync(stagingDir, { recursive: true, force: true });
448
+ }
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Ensure a runnable cloudflared binary exists, preferring system PATH, then local storageDir,
454
+ * and finally downloading a verified release from Cloudflare's official GitHub releases.
455
+ * @param {string} storageDir
456
+ * @param {{ info?: Function, warn?: Function, error?: Function }} [logger]
457
+ * @param {{ fetchImpl?: Function, platform?: string, arch?: string, manifest?: object, execFileSyncImpl?: Function, fsImpl?: object, smokeCheck?: boolean }} [options]
458
+ * @returns {Promise<string>}
459
+ */
460
+ async function ensureCloudflaredBinary(storageDir, logger = console, options = {}) {
461
+ const platform = options.platform || process.platform;
462
+ const arch = options.arch || process.arch;
463
+ const execFileSyncImpl = options.execFileSyncImpl || execFileSync;
464
+ const fsImpl = options.fsImpl || fs;
465
+
466
+ const systemBin = findSystemCloudflared(execFileSyncImpl);
467
+ if (systemBin) {
468
+ logger.info?.("[NR Connect] Using host-managed connector binary");
469
+ return systemBin;
470
+ }
471
+
472
+ const { binName } = resolveBinaryUrl(platform, arch, options.manifest || null);
473
+ const binDir = path.join(storageDir, "bin");
474
+ const targetPath = path.join(binDir, binName);
475
+
476
+ if (fsImpl.existsSync(targetPath)) {
477
+ if (platform !== "win32") {
478
+ try {
479
+ fsImpl.chmodSync(targetPath, 0o755);
480
+ } catch {
481
+ // Ignore chmod errors if read-only
482
+ }
483
+ }
484
+ logger.info?.("[NR Connect] Using cached connector binary");
485
+ return targetPath;
486
+ }
487
+
488
+ const staged = await downloadAndStageBinary(storageDir, logger, options);
489
+ await promoteStagedBinary({
490
+ storageDir,
491
+ ...staged,
492
+ platform,
493
+ fsImpl,
494
+ });
495
+
496
+ logger.info?.("[NR Connect] Connector binary ready");
497
+ return targetPath;
498
+ }
499
+
500
+ /**
501
+ * Download, verify, and atomically swap `<userDir>/bin/cloudflared[.exe]` to a new release.
502
+ * Refuses to overwrite binaries installed on the system PATH.
503
+ */
504
+ async function updateCloudflaredBinary(storageDir, logger = console, options = {}) {
505
+ const platform = options.platform || process.platform;
506
+ const execFileSyncImpl = options.execFileSyncImpl || execFileSync;
507
+ const fsImpl = options.fsImpl || fs;
508
+
509
+ const systemBin = findSystemCloudflared(execFileSyncImpl);
510
+ if (systemBin) {
511
+ return {
512
+ updated: false,
513
+ reason: "system_managed",
514
+ binaryPath: systemBin,
515
+ version: getBinaryVersion(systemBin, execFileSyncImpl),
516
+ };
517
+ }
518
+
519
+ const staged = await downloadAndStageBinary(storageDir, logger, options);
520
+ const binaryPath = await promoteStagedBinary({
521
+ storageDir,
522
+ ...staged,
523
+ stopDaemon: options.stopDaemon,
524
+ platform,
525
+ fsImpl,
526
+ });
527
+
528
+ logger.info?.(
529
+ `[NR Connect] Updated connector to ${staged.version || "latest"}`
530
+ );
531
+
532
+ return {
533
+ updated: true,
534
+ reason: "updated",
535
+ binaryPath,
536
+ version: staged.version,
537
+ sha256: staged.sha256,
538
+ };
539
+ }
540
+
541
+ module.exports = {
542
+ CLOUDFLARED_BASE_URL,
543
+ PINNED_CONNECTOR_MANIFEST,
544
+ parseVersionString,
545
+ compareVersions,
546
+ resolveBinaryUrl,
547
+ verifySha256,
548
+ getBinaryVersion,
549
+ findSystemCloudflared,
550
+ readBinaryMetadata,
551
+ writeBinaryMetadata,
552
+ resolveConnectorBinaryInfo,
553
+ downloadAndStageBinary,
554
+ promoteStagedBinary,
555
+ ensureCloudflaredBinary,
556
+ updateCloudflaredBinary,
557
+ };