@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, dirname } from "node:path";
2
+ import { join } from "node:path";
4
3
  let cache = null;
5
4
  function resolveOpenClawDist() {
6
- // Resolve any known openclaw SDK module to find the dist directory.
7
- // This works cross-platform since the gateway's module loader
8
- // maps `openclaw/*` to the installed dist.
9
- const gatewayRequire = createRequire(import.meta.url);
10
- try {
11
- const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
12
- return dirname(dirname(corePath)); // dist/plugin-sdk/core.js → dist/
13
- }
14
- catch {
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
- throw new Error("OpenClaw dist directory not found");
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
- cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
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
- const { listNodePairing, approveNodePairing } = loadNodePairingModule();
36
- let listData;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@syengup/friday-channel-next",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,44 +1,48 @@
1
- import { createRequire } from "node:module";
2
1
  import { readdirSync } from "node:fs";
3
- import { join, dirname } from "node:path";
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
- // Resolve any known openclaw SDK module to find the dist directory.
9
- // This works cross-platform since the gateway's module loader
10
- // maps `openclaw/*` to the installed dist.
11
- const gatewayRequire = createRequire(import.meta.url);
12
- try {
13
- const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
14
- return dirname(dirname(corePath)); // dist/plugin-sdk/core.js dist/
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
- cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
41
- return cache!;
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
- const { listNodePairing, approveNodePairing } = loadNodePairingModule();
66
-
67
- let listData;
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) {