@syengup/friday-channel-next 0.0.42 → 0.0.44
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare function loadNodePairingModule(): {
|
|
1
|
+
export declare function loadNodePairingModule(): Promise<{
|
|
2
2
|
listNodePairing: Function;
|
|
3
3
|
approveNodePairing: Function;
|
|
4
|
-
}
|
|
4
|
+
}>;
|
|
5
5
|
/** Vitest-only: inject mock pairing functions. */
|
|
6
6
|
export declare function __setMockNodePairingForTests(mock: {
|
|
7
7
|
listNodePairing: Function;
|
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { readdirSync } from "node:fs";
|
|
3
|
-
import { join
|
|
2
|
+
import { join } from "node:path";
|
|
4
3
|
let cache = null;
|
|
5
4
|
function resolveOpenClawDist() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// Fallback for when the plugin runs outside the gateway process.
|
|
16
|
-
// Probe common install paths.
|
|
17
|
-
for (const root of [
|
|
18
|
-
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"), // Windows npm -g
|
|
19
|
-
"/opt/homebrew/lib/node_modules/openclaw/dist", // macOS Homebrew
|
|
20
|
-
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist", // Linux Homebrew
|
|
21
|
-
"/usr/local/lib/node_modules/openclaw/dist", // Unix npm -g
|
|
22
|
-
]) {
|
|
23
|
-
try {
|
|
24
|
-
readdirSync(root);
|
|
25
|
-
return root;
|
|
26
|
-
}
|
|
27
|
-
catch { }
|
|
5
|
+
for (const root of [
|
|
6
|
+
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
|
|
7
|
+
"/opt/homebrew/lib/node_modules/openclaw/dist",
|
|
8
|
+
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
|
|
9
|
+
"/usr/local/lib/node_modules/openclaw/dist",
|
|
10
|
+
]) {
|
|
11
|
+
try {
|
|
12
|
+
readdirSync(root);
|
|
13
|
+
return root;
|
|
28
14
|
}
|
|
29
|
-
|
|
15
|
+
catch { }
|
|
30
16
|
}
|
|
17
|
+
throw new Error("OpenClaw dist directory not found");
|
|
31
18
|
}
|
|
32
|
-
export function loadNodePairingModule() {
|
|
19
|
+
export async function loadNodePairingModule() {
|
|
33
20
|
if (cache)
|
|
34
21
|
return cache;
|
|
35
22
|
const dist = resolveOpenClawDist();
|
|
36
23
|
const file = readdirSync(dist).find((f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"));
|
|
37
24
|
if (!file)
|
|
38
25
|
throw new Error("node-pairing module not found in OpenClaw dist");
|
|
39
|
-
|
|
26
|
+
// ESM import() returns the minified export names (r, t, …) because the
|
|
27
|
+
// bundled module uses `export { listNodePairing as r, … }`. Resolve the
|
|
28
|
+
// correct functions by Function.name, which preserves the original name.
|
|
29
|
+
const mod = await import(join(dist, file));
|
|
30
|
+
let listNodePairing;
|
|
31
|
+
let approveNodePairing;
|
|
32
|
+
for (const value of Object.values(mod)) {
|
|
33
|
+
if (typeof value === "function") {
|
|
34
|
+
if (value.name === "listNodePairing")
|
|
35
|
+
listNodePairing = value;
|
|
36
|
+
else if (value.name === "approveNodePairing")
|
|
37
|
+
approveNodePairing = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!listNodePairing || !approveNodePairing) {
|
|
41
|
+
throw new Error("node-pairing module did not export expected functions");
|
|
42
|
+
}
|
|
43
|
+
cache = { listNodePairing, approveNodePairing };
|
|
40
44
|
return cache;
|
|
41
45
|
}
|
|
42
46
|
/** Vitest-only: inject mock pairing functions. */
|
|
@@ -32,8 +32,17 @@ export async function handleNodesApprove(req, res) {
|
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
const normalizedNodeId = rawNodeId.trim().toUpperCase();
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
let listData, listNodePairing, approveNodePairing;
|
|
36
|
+
try {
|
|
37
|
+
({ listNodePairing, approveNodePairing } = await loadNodePairingModule());
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
log.error(`loadNodePairingModule failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
41
|
+
res.statusCode = 502;
|
|
42
|
+
res.setHeader("Content-Type", "application/json");
|
|
43
|
+
res.end(JSON.stringify({ error: "Failed to load node pairing module" }));
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
37
46
|
try {
|
|
38
47
|
listData = await listNodePairing();
|
|
39
48
|
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { readdirSync } from "node:fs";
|
|
3
|
-
import { join
|
|
2
|
+
import { join } from "node:path";
|
|
4
3
|
|
|
5
4
|
let cache: { listNodePairing: Function; approveNodePairing: Function } | null = null;
|
|
6
5
|
|
|
7
6
|
function resolveOpenClawDist(): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} catch {
|
|
16
|
-
// Fallback for when the plugin runs outside the gateway process.
|
|
17
|
-
// Probe common install paths.
|
|
18
|
-
for (const root of [
|
|
19
|
-
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"), // Windows npm -g
|
|
20
|
-
"/opt/homebrew/lib/node_modules/openclaw/dist", // macOS Homebrew
|
|
21
|
-
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist", // Linux Homebrew
|
|
22
|
-
"/usr/local/lib/node_modules/openclaw/dist", // Unix npm -g
|
|
23
|
-
]) {
|
|
24
|
-
try { readdirSync(root); return root; } catch {}
|
|
25
|
-
}
|
|
26
|
-
throw new Error("OpenClaw dist directory not found");
|
|
7
|
+
for (const root of [
|
|
8
|
+
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
|
|
9
|
+
"/opt/homebrew/lib/node_modules/openclaw/dist",
|
|
10
|
+
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
|
|
11
|
+
"/usr/local/lib/node_modules/openclaw/dist",
|
|
12
|
+
]) {
|
|
13
|
+
try { readdirSync(root); return root; } catch {}
|
|
27
14
|
}
|
|
15
|
+
throw new Error("OpenClaw dist directory not found");
|
|
28
16
|
}
|
|
29
17
|
|
|
30
|
-
export function loadNodePairingModule(): {
|
|
18
|
+
export async function loadNodePairingModule(): Promise<{
|
|
31
19
|
listNodePairing: Function;
|
|
32
20
|
approveNodePairing: Function;
|
|
33
|
-
} {
|
|
21
|
+
}> {
|
|
34
22
|
if (cache) return cache;
|
|
35
23
|
const dist = resolveOpenClawDist();
|
|
36
24
|
const file = readdirSync(dist).find(
|
|
37
25
|
(f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"),
|
|
38
26
|
);
|
|
39
27
|
if (!file) throw new Error("node-pairing module not found in OpenClaw dist");
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
|
|
29
|
+
// ESM import() returns the minified export names (r, t, …) because the
|
|
30
|
+
// bundled module uses `export { listNodePairing as r, … }`. Resolve the
|
|
31
|
+
// correct functions by Function.name, which preserves the original name.
|
|
32
|
+
const mod = await import(join(dist, file));
|
|
33
|
+
let listNodePairing: Function | undefined;
|
|
34
|
+
let approveNodePairing: Function | undefined;
|
|
35
|
+
for (const value of Object.values(mod)) {
|
|
36
|
+
if (typeof value === "function") {
|
|
37
|
+
if (value.name === "listNodePairing") listNodePairing = value;
|
|
38
|
+
else if (value.name === "approveNodePairing") approveNodePairing = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!listNodePairing || !approveNodePairing) {
|
|
42
|
+
throw new Error("node-pairing module did not export expected functions");
|
|
43
|
+
}
|
|
44
|
+
cache = { listNodePairing, approveNodePairing };
|
|
45
|
+
return cache;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/** Vitest-only: inject mock pairing functions. */
|
|
@@ -62,9 +62,16 @@ export async function handleNodesApprove(
|
|
|
62
62
|
|
|
63
63
|
const normalizedNodeId = rawNodeId.trim().toUpperCase();
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
let listData, listNodePairing, approveNodePairing;
|
|
66
|
+
try {
|
|
67
|
+
({ listNodePairing, approveNodePairing } = await loadNodePairingModule());
|
|
68
|
+
} catch (err) {
|
|
69
|
+
log.error(`loadNodePairingModule failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
|
+
res.statusCode = 502;
|
|
71
|
+
res.setHeader("Content-Type", "application/json");
|
|
72
|
+
res.end(JSON.stringify({ error: "Failed to load node pairing module" }));
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
68
75
|
try {
|
|
69
76
|
listData = await listNodePairing();
|
|
70
77
|
} catch (err) {
|