@syengup/friday-channel-next 0.0.41 → 0.0.43

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,24 +1,20 @@
1
- import { createRequire } from "node:module";
2
1
  import { readdirSync } from "node:fs";
3
2
  import { join, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
4
  let cache = null;
5
5
  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);
6
+ // Walk up from the gateway-resolved SDK module to find the dist directory.
7
+ // import.meta.resolve is available in Node 20.6+.
10
8
  try {
11
- const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
9
+ const corePath = fileURLToPath(import.meta.resolve("openclaw/plugin-sdk/core"));
12
10
  return dirname(dirname(corePath)); // dist/plugin-sdk/core.js → dist/
13
11
  }
14
12
  catch {
15
- // Fallback for when the plugin runs outside the gateway process.
16
- // Probe common install paths.
17
13
  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
14
+ join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
15
+ "/opt/homebrew/lib/node_modules/openclaw/dist",
16
+ "/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
17
+ "/usr/local/lib/node_modules/openclaw/dist",
22
18
  ]) {
23
19
  try {
24
20
  readdirSync(root);
@@ -29,14 +25,16 @@ function resolveOpenClawDist() {
29
25
  throw new Error("OpenClaw dist directory not found");
30
26
  }
31
27
  }
32
- export function loadNodePairingModule() {
28
+ export async function loadNodePairingModule() {
33
29
  if (cache)
34
30
  return cache;
35
31
  const dist = resolveOpenClawDist();
36
32
  const file = readdirSync(dist).find((f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"));
37
33
  if (!file)
38
34
  throw new Error("node-pairing module not found in OpenClaw dist");
39
- cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
35
+ // ESM import() correctly resolves named exports (listNodePairing, approveNodePairing)
36
+ // unlike createRequire which exposes the minified export names (r, t).
37
+ cache = await import(join(dist, file));
40
38
  return cache;
41
39
  }
42
40
  /** 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
  }
@@ -49,9 +58,15 @@ export async function handleNodesApprove(req, res) {
49
58
  if (pendingMatch) {
50
59
  const requestId = pendingMatch.requestId;
51
60
  log.info(`approving nodeId=${normalizedNodeId} requestId=${requestId}`);
61
+ const callerScopes = [
62
+ "operator.admin",
63
+ "operator.pairing",
64
+ "operator.read",
65
+ "operator.write",
66
+ ];
52
67
  let approved;
53
68
  try {
54
- approved = await approveNodePairing(requestId, {});
69
+ approved = await approveNodePairing(requestId, { callerScopes });
55
70
  }
56
71
  catch (err) {
57
72
  log.error(`approveNodePairing failed: ${err instanceof Error ? err.message : String(err)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syengup/friday-channel-next",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,25 +1,21 @@
1
- import { createRequire } from "node:module";
2
1
  import { readdirSync } from "node:fs";
3
2
  import { join, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
4
 
5
5
  let cache: { listNodePairing: Function; approveNodePairing: Function } | null = null;
6
6
 
7
7
  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);
8
+ // Walk up from the gateway-resolved SDK module to find the dist directory.
9
+ // import.meta.resolve is available in Node 20.6+.
12
10
  try {
13
- const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
11
+ const corePath = fileURLToPath(import.meta.resolve("openclaw/plugin-sdk/core"));
14
12
  return dirname(dirname(corePath)); // dist/plugin-sdk/core.js → dist/
15
13
  } catch {
16
- // Fallback for when the plugin runs outside the gateway process.
17
- // Probe common install paths.
18
14
  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
15
+ join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"),
16
+ "/opt/homebrew/lib/node_modules/openclaw/dist",
17
+ "/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist",
18
+ "/usr/local/lib/node_modules/openclaw/dist",
23
19
  ]) {
24
20
  try { readdirSync(root); return root; } catch {}
25
21
  }
@@ -27,17 +23,19 @@ function resolveOpenClawDist(): string {
27
23
  }
28
24
  }
29
25
 
30
- export function loadNodePairingModule(): {
26
+ export async function loadNodePairingModule(): Promise<{
31
27
  listNodePairing: Function;
32
28
  approveNodePairing: Function;
33
- } {
29
+ }> {
34
30
  if (cache) return cache;
35
31
  const dist = resolveOpenClawDist();
36
32
  const file = readdirSync(dist).find(
37
33
  (f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"),
38
34
  );
39
35
  if (!file) throw new Error("node-pairing module not found in OpenClaw dist");
40
- cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
36
+ // ESM import() correctly resolves named exports (listNodePairing, approveNodePairing)
37
+ // unlike createRequire which exposes the minified export names (r, t).
38
+ cache = await import(join(dist, file));
41
39
  return cache!;
42
40
  }
43
41
 
@@ -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) {
@@ -84,9 +91,16 @@ const { listNodePairing, approveNodePairing } = loadNodePairingModule();
84
91
  const requestId = pendingMatch.requestId;
85
92
  log.info(`approving nodeId=${normalizedNodeId} requestId=${requestId}`);
86
93
 
94
+ const callerScopes = [
95
+ "operator.admin",
96
+ "operator.pairing",
97
+ "operator.read",
98
+ "operator.write",
99
+ ];
100
+
87
101
  let approved;
88
102
  try {
89
- approved = await approveNodePairing(requestId, {});
103
+ approved = await approveNodePairing(requestId, { callerScopes });
90
104
  } catch (err) {
91
105
  log.error(`approveNodePairing failed: ${err instanceof Error ? err.message : String(err)}`);
92
106
  res.statusCode = 502;