@syengup/friday-channel-next 0.0.40 → 0.0.42

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,16 +1,42 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { readdirSync } from "node:fs";
3
- import { join } from "node:path";
4
- const OPENCLAW_DIST = "/opt/homebrew/lib/node_modules/openclaw/dist";
3
+ import { join, dirname } from "node:path";
5
4
  let cache = null;
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);
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 { }
28
+ }
29
+ throw new Error("OpenClaw dist directory not found");
30
+ }
31
+ }
6
32
  export function loadNodePairingModule() {
7
33
  if (cache)
8
34
  return cache;
9
- const file = readdirSync(OPENCLAW_DIST).find((f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"));
35
+ const dist = resolveOpenClawDist();
36
+ const file = readdirSync(dist).find((f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"));
10
37
  if (!file)
11
38
  throw new Error("node-pairing module not found in OpenClaw dist");
12
- const gatewayRequire = createRequire(join(OPENCLAW_DIST, "_"));
13
- cache = gatewayRequire(`./${file.replace(/\.js$/, "")}`);
39
+ cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
14
40
  return cache;
15
41
  }
16
42
  /** Vitest-only: inject mock pairing functions. */
@@ -49,9 +49,15 @@ export async function handleNodesApprove(req, res) {
49
49
  if (pendingMatch) {
50
50
  const requestId = pendingMatch.requestId;
51
51
  log.info(`approving nodeId=${normalizedNodeId} requestId=${requestId}`);
52
+ const callerScopes = [
53
+ "operator.admin",
54
+ "operator.pairing",
55
+ "operator.read",
56
+ "operator.write",
57
+ ];
52
58
  let approved;
53
59
  try {
54
- approved = await approveNodePairing(requestId, {});
60
+ approved = await approveNodePairing(requestId, { callerScopes });
55
61
  }
56
62
  catch (err) {
57
63
  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.40",
3
+ "version": "0.0.42",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,22 +1,43 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { readdirSync } from "node:fs";
3
- import { join } from "node:path";
4
-
5
- const OPENCLAW_DIST = "/opt/homebrew/lib/node_modules/openclaw/dist";
3
+ import { join, dirname } from "node:path";
6
4
 
7
5
  let cache: { listNodePairing: Function; approveNodePairing: Function } | null = null;
8
6
 
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);
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");
27
+ }
28
+ }
29
+
9
30
  export function loadNodePairingModule(): {
10
31
  listNodePairing: Function;
11
32
  approveNodePairing: Function;
12
33
  } {
13
34
  if (cache) return cache;
14
- const file = readdirSync(OPENCLAW_DIST).find(
35
+ const dist = resolveOpenClawDist();
36
+ const file = readdirSync(dist).find(
15
37
  (f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"),
16
38
  );
17
39
  if (!file) throw new Error("node-pairing module not found in OpenClaw dist");
18
- const gatewayRequire = createRequire(join(OPENCLAW_DIST, "_"));
19
- cache = gatewayRequire(`./${file.replace(/\.js$/, "")}`);
40
+ cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
20
41
  return cache!;
21
42
  }
22
43
 
@@ -84,9 +84,16 @@ const { listNodePairing, approveNodePairing } = loadNodePairingModule();
84
84
  const requestId = pendingMatch.requestId;
85
85
  log.info(`approving nodeId=${normalizedNodeId} requestId=${requestId}`);
86
86
 
87
+ const callerScopes = [
88
+ "operator.admin",
89
+ "operator.pairing",
90
+ "operator.read",
91
+ "operator.write",
92
+ ];
93
+
87
94
  let approved;
88
95
  try {
89
- approved = await approveNodePairing(requestId, {});
96
+ approved = await approveNodePairing(requestId, { callerScopes });
90
97
  } catch (err) {
91
98
  log.error(`approveNodePairing failed: ${err instanceof Error ? err.message : String(err)}`);
92
99
  res.statusCode = 502;