@withone/cli 2.11.1 → 2.13.0

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/README.md CHANGED
@@ -739,12 +739,16 @@ Drop a `.onerc` file in your project root to override global settings per-projec
739
739
  |-----|---------|
740
740
  | `ONE_SECRET` | API key (also honored as env var) |
741
741
  | `ONE_API_BASE` | API base URL, `https://api.withone.ai` or `https://development-api.withone.ai` only (the env var accepts any origin) |
742
- | `ONE_PERMISSIONS` | `admin` / `write` / `read` |
743
- | `ONE_CONNECTION_KEYS` | Comma-separated connection-key allowlist |
744
- | `ONE_ACTION_IDS` | Comma-separated action-ID allowlist |
745
- | `ONE_KNOWLEDGE_AGENT` | `true` / `false` — knowledge-only mode |
742
+ | `ONE_PERMISSIONS` | `admin` / `write` / `read`, can only lower the configured level |
743
+ | `ONE_CONNECTION_KEYS` | Comma-separated connection-key allowlist, intersected with the configured one |
744
+ | `ONE_ACTION_IDS` | Comma-separated action-ID allowlist, intersected with the configured one |
745
+ | `ONE_KNOWLEDGE_AGENT` | `true` turns knowledge-only mode on; it cannot turn it off |
746
746
 
747
- Precedence: env var > `.onerc` > `~/.one/config.json`.
747
+ Precedence: env var > `.onerc` > `~/.one/config.json`. The access keys are the exception: a `.onerc` can only narrow the access settings in your config, never widen them, because it can arrive with a cloned repository. A value that would widen them is ignored with a warning; use `one config` instead.
748
+
749
+ The access settings are enforced on every call to a connected app, whatever the command: `actions execute`, flows, sync and its validation runs. Headers named `x-one-secret`, `x-one-connection-key` or `x-one-action-id` cannot be passed with `--headers`, method-override headers are judged against the permission level, and a path variable cannot be `.` or `..`.
750
+
751
+ They also apply to commands that change One's own resources. Creating, updating or activating a relay needs the `write` level and deleting one needs `admin`; `connection delete` needs `admin`; knowledge-only refuses all of them. A relay's `passthrough` actions are checked like `actions execute` when they are set, because they run later on One's servers. `url` and `agent` relay actions are allowed only when the connection and action allowlists are both `*`. With a connection allowlist, relay endpoints, events and deliveries on other connections are hidden or refused.
748
752
 
749
753
  ```bash
750
754
  # .onerc
@@ -3,7 +3,7 @@ import {
3
3
  readConfig,
4
4
  setOpenAiApiKey,
5
5
  writeConfig
6
- } from "./chunk-FR4VGZUI.js";
6
+ } from "./chunk-XUAUDMQE.js";
7
7
 
8
8
  // src/lib/memory/config.ts
9
9
  var DEFAULT_MEMORY_CONFIG = {
@@ -5,11 +5,11 @@ import {
5
5
  getMemoryConfig,
6
6
  getMemoryConfigOrDefault,
7
7
  updateMemoryConfig
8
- } from "./chunk-NC3HVQ7O.js";
8
+ } from "./chunk-2OIJGF77.js";
9
9
  import {
10
10
  getOpenAiApiKey,
11
11
  homeDir
12
- } from "./chunk-FR4VGZUI.js";
12
+ } from "./chunk-XUAUDMQE.js";
13
13
 
14
14
  // src/lib/memory/schema.ts
15
15
  var SCHEMA_VERSION = "2.3.1";
@@ -5,11 +5,11 @@ import {
5
5
  } from "./chunk-Q6PWTATS.js";
6
6
  import {
7
7
  getMemoryConfigOrDefault
8
- } from "./chunk-NC3HVQ7O.js";
8
+ } from "./chunk-2OIJGF77.js";
9
9
  import {
10
10
  getOpenAiApiKey,
11
11
  readConfig
12
- } from "./chunk-FR4VGZUI.js";
12
+ } from "./chunk-XUAUDMQE.js";
13
13
 
14
14
  // src/commands/mem/util.ts
15
15
  function requireMemoryInit() {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  okJson,
6
6
  requireMemoryInit
7
- } from "./chunk-VYOIHD4B.js";
7
+ } from "./chunk-B5YDLVY5.js";
8
8
  import {
9
9
  isAgentMode,
10
10
  note
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  getBackend,
14
14
  upsertRecord
15
- } from "./chunk-UYOXEMF5.js";
15
+ } from "./chunk-4H5L3SBY.js";
16
16
 
17
17
  // src/commands/mem/migrate.ts
18
18
  import fs4 from "fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  requireMemoryInit
3
- } from "./chunk-VYOIHD4B.js";
3
+ } from "./chunk-B5YDLVY5.js";
4
4
  import {
5
5
  error,
6
6
  isAgentMode,
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-Q6PWTATS.js";
9
9
  import {
10
10
  getBackend
11
- } from "./chunk-UYOXEMF5.js";
11
+ } from "./chunk-4H5L3SBY.js";
12
12
 
13
13
  // src/commands/mem/sql.ts
14
14
  async function memSqlCommand(sql) {
@@ -6,9 +6,12 @@ import {
6
6
  isAgentMode
7
7
  } from "./chunk-Q6PWTATS.js";
8
8
  import {
9
+ IDENTITY_HEADERS,
9
10
  appendAnalyticsQueue,
10
11
  appendUsageLog,
12
+ checkPassthroughAccess,
11
13
  claimUsageLog,
14
+ getAccessControlFromAllSources,
12
15
  getApiKey,
13
16
  getCacheTtl,
14
17
  getDeviceId,
@@ -16,6 +19,8 @@ import {
16
19
  getProjectRoot,
17
20
  getWhoAmI,
18
21
  homeDir,
22
+ isActionAllowed,
23
+ isMethodAllowed,
19
24
  markTelemetryNoticeShown,
20
25
  readAnalyticsQueue,
21
26
  readConfig,
@@ -24,7 +29,7 @@ import {
24
29
  writeAnalyticsQueue,
25
30
  writeUsageLog,
26
31
  writeUsageState
27
- } from "./chunk-FR4VGZUI.js";
32
+ } from "./chunk-XUAUDMQE.js";
28
33
 
29
34
  // src/lib/flow-runner.ts
30
35
  import fs5 from "fs";
@@ -725,11 +730,17 @@ function parseRetryAfter(value) {
725
730
  return void 0;
726
731
  }
727
732
  var OneApi = class {
728
- constructor(apiKey, apiBase) {
733
+ constructor(apiKey, apiBase, accessSettings) {
729
734
  this.apiKey = apiKey;
735
+ this.accessSettings = accessSettings;
730
736
  this.apiBase = apiBase ?? "https://api.withone.ai/v1";
731
737
  }
732
738
  apiBase;
739
+ /**
740
+ * The local access settings every passthrough call is checked against.
741
+ * Read from config and `.onerc` at call time unless a caller supplies them.
742
+ */
743
+ accessSettings;
733
744
  async request(path7) {
734
745
  return this.requestFull({ path: path7 });
735
746
  }
@@ -967,10 +978,13 @@ var OneApi = class {
967
978
  const action = preloadedAction ?? await this.getActionDetails(args.actionId);
968
979
  const method = action.method;
969
980
  const contentType = args.isFormData ? "multipart/form-data" : args.isFormUrlEncoded ? "application/x-www-form-urlencoded" : "application/json";
981
+ checkPassthroughAccess(this.accessSettings ?? getAccessControlFromAllSources(), {
982
+ actionId: action._id,
983
+ connectionKey: args.connectionKey,
984
+ method,
985
+ headers: args.headers
986
+ });
970
987
  const requestHeaders = {
971
- "x-one-secret": this.apiKey,
972
- "x-one-connection-key": args.connectionKey,
973
- "x-one-action-id": action._id,
974
988
  "Content-Type": contentType,
975
989
  Accept: "application/json, text/event-stream, */*",
976
990
  // Who is calling, for the Logs page. Before the caller's own headers so
@@ -978,9 +992,17 @@ var OneApi = class {
978
992
  ...callerHeaders(),
979
993
  ...args.headers
980
994
  };
995
+ for (const name of Object.keys(requestHeaders)) {
996
+ if (IDENTITY_HEADERS.includes(name.toLowerCase())) delete requestHeaders[name];
997
+ }
998
+ requestHeaders["x-one-secret"] = this.apiKey;
999
+ requestHeaders["x-one-connection-key"] = args.connectionKey;
1000
+ requestHeaders["x-one-action-id"] = action._id;
981
1001
  const finalActionPath = args.pathVariables ? replacePathVariables(action.path, args.pathVariables) : action.path;
982
1002
  const normalizedPath = finalActionPath.startsWith("/") ? finalActionPath : `/${finalActionPath}`;
983
- const url = `${this.apiBase.replace("/v1", "")}/v1/passthrough${normalizedPath}`;
1003
+ const passthroughBase = `${this.apiBase.replace("/v1", "")}/v1/passthrough`;
1004
+ const url = `${passthroughBase}${normalizedPath}`;
1005
+ assertUnderPassthrough(passthroughBase, url);
984
1006
  const isCustomAction = action.tags?.includes("custom");
985
1007
  let requestData = args.data;
986
1008
  if (isCustomAction && method?.toLowerCase() !== "get") {
@@ -1200,6 +1222,20 @@ var TimeoutError = class extends Error {
1200
1222
  function sleep(ms) {
1201
1223
  return new Promise((resolve2) => setTimeout(resolve2, ms));
1202
1224
  }
1225
+ function encodePathValue(name, value) {
1226
+ const text = value.toString();
1227
+ if (text === "." || text === "..") {
1228
+ throw new Error(`Path variable "${name}" cannot be "${text}".`);
1229
+ }
1230
+ return encodeURIComponent(text).replace(/%3A/gi, ":");
1231
+ }
1232
+ function assertUnderPassthrough(passthroughBase, url) {
1233
+ const prefix = new URL(passthroughBase).pathname.replace(/\/+$/, "");
1234
+ const resolved = new URL(url).pathname;
1235
+ if (resolved !== prefix && !resolved.startsWith(`${prefix}/`)) {
1236
+ throw new Error(`Action path resolves outside ${prefix} (${resolved}).`);
1237
+ }
1238
+ }
1203
1239
  function replacePathVariables(path7, variables) {
1204
1240
  if (!path7) return path7;
1205
1241
  let result = path7;
@@ -1209,7 +1245,7 @@ function replacePathVariables(path7, variables) {
1209
1245
  if (value === void 0 || value === null || value === "") {
1210
1246
  throw new Error(`Missing value for path variable: ${trimmedVariable}`);
1211
1247
  }
1212
- return encodeURIComponent(value.toString()).replace(/%3A/gi, ":");
1248
+ return encodePathValue(trimmedVariable, value);
1213
1249
  });
1214
1250
  result = result.replace(/\{([^}]+)\}/g, (_match, variable) => {
1215
1251
  const trimmedVariable = variable.trim();
@@ -1217,23 +1253,10 @@ function replacePathVariables(path7, variables) {
1217
1253
  if (value === void 0 || value === null || value === "") {
1218
1254
  throw new Error(`Missing value for path variable: ${trimmedVariable}`);
1219
1255
  }
1220
- return encodeURIComponent(value.toString()).replace(/%3A/gi, ":");
1256
+ return encodePathValue(trimmedVariable, value);
1221
1257
  });
1222
1258
  return result;
1223
1259
  }
1224
- var PERMISSION_METHODS = {
1225
- read: ["GET"],
1226
- write: ["GET", "POST", "PUT", "PATCH"],
1227
- admin: null
1228
- };
1229
- function isMethodAllowed(method, permissions) {
1230
- const allowed = PERMISSION_METHODS[permissions];
1231
- if (allowed === null) return true;
1232
- return allowed.includes(method.toUpperCase());
1233
- }
1234
- function isActionAllowed(actionId, allowedActionIds) {
1235
- return allowedActionIds.includes("*") || allowedActionIds.includes(actionId);
1236
- }
1237
1260
 
1238
1261
  // src/lib/cache.ts
1239
1262
  import fs3 from "fs";
@@ -2977,7 +3000,7 @@ async function executeSubflowStep(step, context, api, permissions, allowedAction
2977
3000
  if (flowStack.includes(resolvedKey)) {
2978
3001
  throw new Error(`Circular flow detected: ${[...flowStack, resolvedKey].join(" \u2192 ")}`);
2979
3002
  }
2980
- const { loadFlowWithMeta: loadFlowWithMeta2 } = await import("./flow-runner-36I4G5BS.js");
3003
+ const { loadFlowWithMeta: loadFlowWithMeta2 } = await import("./flow-runner-Y4DW3UD3.js");
2981
3004
  const { flow: subFlow, rootDir: subRootDir } = loadFlowWithMeta2(resolvedKey);
2982
3005
  const subContext = await executeFlow(
2983
3006
  subFlow,
@@ -3907,9 +3930,6 @@ export {
3907
3930
  ApiError,
3908
3931
  OneApi,
3909
3932
  TimeoutError,
3910
- PERMISSION_METHODS,
3911
- isMethodAllowed,
3912
- isActionAllowed,
3913
3933
  knowledgeCachePath,
3914
3934
  readCache,
3915
3935
  writeCache,
@@ -10,6 +10,112 @@ function homeDir() {
10
10
  import fs from "fs";
11
11
  import path from "path";
12
12
  import { randomUUID } from "crypto";
13
+
14
+ // src/lib/access-gate.ts
15
+ var PERMISSION_METHODS = {
16
+ read: ["GET"],
17
+ write: ["GET", "POST", "PUT", "PATCH"],
18
+ admin: null
19
+ };
20
+ function isMethodAllowed(method, permissions) {
21
+ const allowed = PERMISSION_METHODS[permissions];
22
+ if (allowed === null) return true;
23
+ return allowed.includes(method.toUpperCase());
24
+ }
25
+ function isActionAllowed(actionId, allowedActionIds) {
26
+ return allowedActionIds.includes("*") || allowedActionIds.includes(actionId);
27
+ }
28
+ function isConnectionAllowed(connectionKey, allowedConnectionKeys) {
29
+ return allowedConnectionKeys.includes("*") || allowedConnectionKeys.includes(connectionKey);
30
+ }
31
+ var IDENTITY_HEADERS = ["x-one-secret", "x-one-connection-key", "x-one-action-id"];
32
+ var METHOD_OVERRIDE_HEADERS = ["x-http-method-override", "x-http-method", "x-method-override"];
33
+ var AccessDeniedError = class extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = "AccessDeniedError";
37
+ }
38
+ };
39
+ function checkPassthroughAccess(settings, req) {
40
+ const permissions = settings.permissions ?? "admin";
41
+ const actionIds = settings.actionIds ?? ["*"];
42
+ const connectionKeys = settings.connectionKeys ?? ["*"];
43
+ if (settings.knowledgeAgent) {
44
+ throw new AccessDeniedError("Action execution is disabled (knowledge-only mode).");
45
+ }
46
+ if (!isActionAllowed(req.actionId, actionIds)) {
47
+ throw new AccessDeniedError(`Action "${req.actionId}" is not in the allowed action list.`);
48
+ }
49
+ if (!isConnectionAllowed(req.connectionKey, connectionKeys)) {
50
+ throw new AccessDeniedError(`Connection key "${req.connectionKey}" is not allowed.`);
51
+ }
52
+ if (!isMethodAllowed(req.method, permissions)) {
53
+ throw new AccessDeniedError(`Method "${req.method}" is not allowed under "${permissions}" permission level.`);
54
+ }
55
+ for (const [name, value] of Object.entries(req.headers ?? {})) {
56
+ const lower = name.toLowerCase();
57
+ if (IDENTITY_HEADERS.includes(lower)) {
58
+ throw new AccessDeniedError(
59
+ `Header "${name}" is set by the CLI and cannot be passed. Use --connection-key and the action id instead.`
60
+ );
61
+ }
62
+ if (METHOD_OVERRIDE_HEADERS.includes(lower) && !isMethodAllowed(String(value), permissions)) {
63
+ throw new AccessDeniedError(
64
+ `Header "${name}: ${value}" asks for a method that is not allowed under "${permissions}" permission level.`
65
+ );
66
+ }
67
+ }
68
+ }
69
+ var LEVEL_RANK = { read: 0, write: 1, admin: 2 };
70
+ function isPermissionLevel(value) {
71
+ return value in LEVEL_RANK;
72
+ }
73
+ function stricterLevel(a, b) {
74
+ return LEVEL_RANK[a] <= LEVEL_RANK[b] ? a : b;
75
+ }
76
+ function intersectAllowlists(a, b) {
77
+ if (a.includes("*")) return b;
78
+ if (b.includes("*")) return a;
79
+ return a.filter((x) => b.includes(x));
80
+ }
81
+ function checkManagementAccess(settings, op, what) {
82
+ const permissions = settings.permissions ?? "admin";
83
+ if (settings.knowledgeAgent) {
84
+ throw new AccessDeniedError(`${what} is disabled (knowledge-only mode).`);
85
+ }
86
+ const method = op === "delete" ? "DELETE" : "POST";
87
+ if (!isMethodAllowed(method, permissions)) {
88
+ throw new AccessDeniedError(`${what} needs ${op === "delete" ? 'the "admin"' : 'the "write" or "admin"'} permission level (current: "${permissions}").`);
89
+ }
90
+ }
91
+ function allowlistsUnrestricted(settings) {
92
+ return (settings.actionIds ?? ["*"]).includes("*") && (settings.connectionKeys ?? ["*"]).includes("*");
93
+ }
94
+ async function checkRelayActions(settings, actions, methodOf) {
95
+ if (actions === void 0 || actions === null) return;
96
+ if (!Array.isArray(actions)) throw new AccessDeniedError("--actions must be a JSON array.");
97
+ for (const [i, raw] of actions.entries()) {
98
+ const action = raw ?? {};
99
+ if (action.type === "passthrough") {
100
+ const actionId = String(action.actionId ?? "");
101
+ const connectionKey = String(action.connectionKey ?? "");
102
+ if (!actionId || !connectionKey) {
103
+ throw new AccessDeniedError(`Relay action [${i}] needs an actionId and a connectionKey.`);
104
+ }
105
+ checkPassthroughAccess({ ...settings, permissions: "admin", knowledgeAgent: false }, { actionId, connectionKey, method: "GET" });
106
+ const headers = action.headers && typeof action.headers === "object" ? action.headers : void 0;
107
+ checkPassthroughAccess(settings, { actionId, connectionKey, method: await methodOf(actionId), headers });
108
+ continue;
109
+ }
110
+ if (!allowlistsUnrestricted(settings)) {
111
+ throw new AccessDeniedError(
112
+ `Relay action [${i}] of type "${String(action.type)}" forwards events outside the connection and action allowlists, so it is allowed only when both are "*".`
113
+ );
114
+ }
115
+ }
116
+ }
117
+
118
+ // src/lib/config.ts
13
119
  function configDir() {
14
120
  return path.join(homeDir(), ".one");
15
121
  }
@@ -158,21 +264,44 @@ function setOpenAiApiKey(key) {
158
264
  }
159
265
  writeConfig(resolved.config, resolved.scope ?? "global");
160
266
  }
267
+ var warnedOneRcAccess = false;
161
268
  function getAccessControlFromAllSources() {
162
269
  const rc = readOneRc();
163
270
  const fileAc = getAccessControl();
164
271
  const merged = { ...fileAc };
165
- if (rc.ONE_PERMISSIONS) {
166
- merged.permissions = rc.ONE_PERMISSIONS;
167
- }
168
- if (rc.ONE_CONNECTION_KEYS) {
169
- merged.connectionKeys = rc.ONE_CONNECTION_KEYS.split(",").map((s) => s.trim()).filter(Boolean);
170
- }
171
- if (rc.ONE_ACTION_IDS) {
172
- merged.actionIds = rc.ONE_ACTION_IDS.split(",").map((s) => s.trim()).filter(Boolean);
272
+ const ignored = [];
273
+ const rcLevel = rc.ONE_PERMISSIONS?.trim();
274
+ if (rcLevel) {
275
+ const current = fileAc.permissions ?? "admin";
276
+ if (isPermissionLevel(rcLevel)) {
277
+ merged.permissions = stricterLevel(current, rcLevel);
278
+ if (merged.permissions !== rcLevel) ignored.push(`ONE_PERMISSIONS=${rcLevel}`);
279
+ } else {
280
+ ignored.push(`ONE_PERMISSIONS=${rcLevel}`);
281
+ }
173
282
  }
174
- if (rc.ONE_KNOWLEDGE_AGENT) {
175
- merged.knowledgeAgent = rc.ONE_KNOWLEDGE_AGENT === "true";
283
+ const narrowList = (rcKey, current) => {
284
+ const raw = rc[rcKey];
285
+ if (!raw) return current;
286
+ const asked = raw.split(",").map((s) => s.trim()).filter(Boolean);
287
+ if (asked.length === 0) return current;
288
+ const result = intersectAllowlists(current ?? ["*"], asked);
289
+ if (asked.some((x) => !result.includes(x))) ignored.push(`${rcKey}=${raw}`);
290
+ return result;
291
+ };
292
+ merged.connectionKeys = narrowList("ONE_CONNECTION_KEYS", fileAc.connectionKeys);
293
+ merged.actionIds = narrowList("ONE_ACTION_IDS", fileAc.actionIds);
294
+ if (merged.connectionKeys === void 0) delete merged.connectionKeys;
295
+ if (merged.actionIds === void 0) delete merged.actionIds;
296
+ const rcKnowledge = rc.ONE_KNOWLEDGE_AGENT?.trim();
297
+ if (rcKnowledge === "true") merged.knowledgeAgent = true;
298
+ else if (rcKnowledge && fileAc.knowledgeAgent) ignored.push(`ONE_KNOWLEDGE_AGENT=${rcKnowledge}`);
299
+ if (ignored.length > 0 && !warnedOneRcAccess) {
300
+ warnedOneRcAccess = true;
301
+ process.stderr.write(
302
+ `Ignoring ${ignored.join(", ")} from .onerc: .onerc can only narrow the access settings in your config. Use \`one config\` to widen them.
303
+ `
304
+ );
176
305
  }
177
306
  return merged;
178
307
  }
@@ -439,6 +568,14 @@ function writeUsageState(state) {
439
568
 
440
569
  export {
441
570
  homeDir,
571
+ PERMISSION_METHODS,
572
+ isMethodAllowed,
573
+ isActionAllowed,
574
+ isConnectionAllowed,
575
+ IDENTITY_HEADERS,
576
+ checkPassthroughAccess,
577
+ checkManagementAccess,
578
+ checkRelayActions,
442
579
  getProjectRoot,
443
580
  getProjectConfigPath,
444
581
  getGlobalConfigPath,
@@ -2,8 +2,8 @@ import {
2
2
  defaultSearchableText,
3
3
  embed,
4
4
  embedBatch
5
- } from "./chunk-NC3HVQ7O.js";
6
- import "./chunk-FR4VGZUI.js";
5
+ } from "./chunk-2OIJGF77.js";
6
+ import "./chunk-XUAUDMQE.js";
7
7
  export {
8
8
  defaultSearchableText,
9
9
  embed,
@@ -12,10 +12,10 @@ import {
12
12
  stripStepsAlias,
13
13
  summarizeFlowInputs,
14
14
  walkSteps
15
- } from "./chunk-RUVW6QYK.js";
15
+ } from "./chunk-UZC3IHLW.js";
16
16
  import "./chunk-44CV5IMX.js";
17
17
  import "./chunk-Q6PWTATS.js";
18
- import "./chunk-FR4VGZUI.js";
18
+ import "./chunk-XUAUDMQE.js";
19
19
  export {
20
20
  FlowRunner,
21
21
  collectStepTypes,
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  FLOW_SCHEMA,
7
7
  FlowRunner,
8
8
  OneApi,
9
- PERMISSION_METHODS,
10
9
  TimeoutError,
11
10
  clearAll,
12
11
  clearEntry,
@@ -25,9 +24,7 @@ import {
25
24
  getStepTypeDescriptor,
26
25
  installContextToParams,
27
26
  installMcpConfig,
28
- isActionAllowed,
29
27
  isFresh,
30
- isMethodAllowed,
31
28
  knowledgeCachePath,
32
29
  listCacheEntries,
33
30
  listFlows,
@@ -42,10 +39,10 @@ import {
42
39
  validateActionInput,
43
40
  walkSteps,
44
41
  writeCache
45
- } from "./chunk-RUVW6QYK.js";
42
+ } from "./chunk-UZC3IHLW.js";
46
43
  import {
47
44
  memSqlCommand
48
- } from "./chunk-WWPH6JOO.js";
45
+ } from "./chunk-TSMVFVQ3.js";
49
46
  import {
50
47
  collectIdentityKeys,
51
48
  countRecords,
@@ -76,7 +73,7 @@ import {
76
73
  writeDraftProfile,
77
74
  writePageToMemory,
78
75
  writeProfile
79
- } from "./chunk-5O5OUAHJ.js";
76
+ } from "./chunk-LEJKEGB6.js";
80
77
  import {
81
78
  getByDotPath
82
79
  } from "./chunk-44CV5IMX.js";
@@ -90,7 +87,7 @@ import {
90
87
  requireMemoryInit,
91
88
  semanticSearchUpgradeHint,
92
89
  semanticSearchUpgradeLine
93
- } from "./chunk-VYOIHD4B.js";
90
+ } from "./chunk-B5YDLVY5.js";
94
91
  import {
95
92
  cancel,
96
93
  createSpinner,
@@ -112,7 +109,7 @@ import {
112
109
  listBackendPlugins,
113
110
  loadBackendFromConfig,
114
111
  updateRecord
115
- } from "./chunk-UYOXEMF5.js";
112
+ } from "./chunk-4H5L3SBY.js";
116
113
  import {
117
114
  DEFAULT_MEMORY_CONFIG,
118
115
  defaultSearchableText,
@@ -122,8 +119,11 @@ import {
122
119
  memoryConfigExists,
123
120
  setOpenAiApiKey,
124
121
  updateMemoryConfig
125
- } from "./chunk-NC3HVQ7O.js";
122
+ } from "./chunk-2OIJGF77.js";
126
123
  import {
124
+ PERMISSION_METHODS,
125
+ checkManagementAccess,
126
+ checkRelayActions,
127
127
  configExists,
128
128
  ensureWhoAmI,
129
129
  getAccessControl,
@@ -138,6 +138,9 @@ import {
138
138
  getWhoAmI,
139
139
  globalConfigExists,
140
140
  homeDir,
141
+ isActionAllowed,
142
+ isConnectionAllowed,
143
+ isMethodAllowed,
141
144
  projectConfigExists,
142
145
  readConfig,
143
146
  readGlobalConfig,
@@ -148,7 +151,7 @@ import {
148
151
  updateApiBase,
149
152
  updateWhoAmI,
150
153
  writeConfig
151
- } from "./chunk-FR4VGZUI.js";
154
+ } from "./chunk-XUAUDMQE.js";
152
155
 
153
156
  // src/cli.ts
154
157
  import { createRequire } from "module";
@@ -2448,6 +2451,11 @@ async function connectionDeleteCommand(connectionKey, options) {
2448
2451
  if (!apiKey) {
2449
2452
  error("Not configured. Run `one init` first.");
2450
2453
  }
2454
+ try {
2455
+ checkManagementAccess(getAccessControlFromAllSources(), "delete", "Deleting a connection");
2456
+ } catch (error2) {
2457
+ error(error2 instanceof Error ? error2.message : String(error2));
2458
+ }
2451
2459
  const api = new OneApi(apiKey, getApiBase());
2452
2460
  const spinner = createSpinner();
2453
2461
  spinner.start("Finding connection...");
@@ -5525,9 +5533,45 @@ function getConfig3() {
5525
5533
  if (!apiKey) {
5526
5534
  error("Not configured. Run `one init` first.");
5527
5535
  }
5528
- const ac = getAccessControlFromAllSources();
5529
- const connectionKeys = ac.connectionKeys || ["*"];
5530
- return { apiKey, connectionKeys };
5536
+ const settings = getAccessControlFromAllSources();
5537
+ const connectionKeys = settings.connectionKeys || ["*"];
5538
+ return { apiKey, connectionKeys, settings };
5539
+ }
5540
+ async function connectionIdFilter(api, settings) {
5541
+ const keys = settings.connectionKeys ?? ["*"];
5542
+ if (keys.includes("*")) return () => true;
5543
+ const connections = await api.listConnections();
5544
+ const ids = new Set(connections.filter((c) => isConnectionAllowed(c.key, keys)).map((c) => c.id));
5545
+ return (id) => ids.has(id);
5546
+ }
5547
+ function restricted(settings) {
5548
+ return !(settings.connectionKeys ?? ["*"]).includes("*");
5549
+ }
5550
+ async function allowedEndpoint(api, settings, id) {
5551
+ const allowed = await connectionIdFilter(api, settings);
5552
+ const endpoint = await api.getRelayEndpoint(id);
5553
+ if (!allowed(endpoint.connectionId)) {
5554
+ throw new Error(`Relay endpoint "${id}" is on a connection that is not allowed.`);
5555
+ }
5556
+ return endpoint;
5557
+ }
5558
+ async function allowedEvent(api, settings, id) {
5559
+ const allowed = await connectionIdFilter(api, settings);
5560
+ const event = await api.getRelayEvent(id);
5561
+ if (!allowed(event.connectionId)) {
5562
+ throw new Error(`Relay event "${id}" is on a connection that is not allowed.`);
5563
+ }
5564
+ return event;
5565
+ }
5566
+ function actionMethod(api) {
5567
+ return async (actionId) => (await resolveActionDetails(api, actionId)).details.method;
5568
+ }
5569
+ function guard(check) {
5570
+ try {
5571
+ check();
5572
+ } catch (error2) {
5573
+ error(error2 instanceof Error ? error2.message : String(error2));
5574
+ }
5531
5575
  }
5532
5576
  function parseJsonArg3(value, argName) {
5533
5577
  try {
@@ -5537,7 +5581,8 @@ function parseJsonArg3(value, argName) {
5537
5581
  }
5538
5582
  }
5539
5583
  async function relayCreateCommand(options) {
5540
- const { apiKey, connectionKeys } = getConfig3();
5584
+ const { apiKey, connectionKeys, settings } = getConfig3();
5585
+ guard(() => checkManagementAccess(settings, "write", "Creating a relay endpoint"));
5541
5586
  if (!connectionKeys.includes("*") && !connectionKeys.includes(options.connectionKey)) {
5542
5587
  error(`Connection key "${options.connectionKey}" is not allowed.`);
5543
5588
  }
@@ -5577,7 +5622,7 @@ async function relayCreateCommand(options) {
5577
5622
  }
5578
5623
  }
5579
5624
  async function relayListCommand(options) {
5580
- const { apiKey } = getConfig3();
5625
+ const { apiKey, settings } = getConfig3();
5581
5626
  const api = new OneApi(apiKey, getApiBase());
5582
5627
  const spinner = createSpinner();
5583
5628
  spinner.start("Loading relay endpoints...");
@@ -5586,10 +5631,13 @@ async function relayListCommand(options) {
5586
5631
  if (options.limit) query.limit = options.limit;
5587
5632
  if (options.page) query.page = options.page;
5588
5633
  const result = await api.listRelayEndpoints(query);
5589
- const endpoints = result.rows || [];
5634
+ const allowed = await connectionIdFilter(api, settings);
5635
+ const endpoints = (result.rows || []).filter((e) => allowed(e.connectionId));
5590
5636
  if (isAgentMode()) {
5591
5637
  json({
5592
- total: result.total,
5638
+ // With a connection allowlist the server's total also counts rows
5639
+ // the allowlist hides, so report only what is shown.
5640
+ total: restricted(settings) ? endpoints.length : result.total,
5593
5641
  showing: endpoints.length,
5594
5642
  endpoints: endpoints.map((e) => ({
5595
5643
  id: e.id,
@@ -5630,12 +5678,12 @@ async function relayListCommand(options) {
5630
5678
  }
5631
5679
  }
5632
5680
  async function relayGetCommand(id) {
5633
- const { apiKey } = getConfig3();
5681
+ const { apiKey, settings } = getConfig3();
5634
5682
  const api = new OneApi(apiKey, getApiBase());
5635
5683
  const spinner = createSpinner();
5636
5684
  spinner.start("Loading relay endpoint...");
5637
5685
  try {
5638
- const result = await api.getRelayEndpoint(id);
5686
+ const result = await allowedEndpoint(api, settings, id);
5639
5687
  if (isAgentMode()) {
5640
5688
  json(result);
5641
5689
  return;
@@ -5661,7 +5709,8 @@ async function relayGetCommand(id) {
5661
5709
  }
5662
5710
  }
5663
5711
  async function relayUpdateCommand(id, options) {
5664
- const { apiKey } = getConfig3();
5712
+ const { apiKey, settings } = getConfig3();
5713
+ guard(() => checkManagementAccess(settings, "write", "Updating a relay endpoint"));
5665
5714
  const api = new OneApi(apiKey, getApiBase());
5666
5715
  const spinner = createSpinner();
5667
5716
  spinner.start("Updating relay endpoint...");
@@ -5672,6 +5721,9 @@ async function relayUpdateCommand(id, options) {
5672
5721
  if (options.eventFilters) body.eventFilters = parseJsonArg3(options.eventFilters, "--event-filters");
5673
5722
  if (options.tags) body.tags = parseJsonArg3(options.tags, "--tags");
5674
5723
  if (options.actions) body.actions = parseJsonArg3(options.actions, "--actions");
5724
+ const existing = await allowedEndpoint(api, settings, id);
5725
+ const effective = body.actions ?? (options.active === true ? existing.actions : void 0);
5726
+ await checkRelayActions(settings, effective, actionMethod(api));
5675
5727
  const result = await api.updateRelayEndpoint(id, body);
5676
5728
  if (isAgentMode()) {
5677
5729
  json(result);
@@ -5688,11 +5740,13 @@ async function relayUpdateCommand(id, options) {
5688
5740
  }
5689
5741
  }
5690
5742
  async function relayDeleteCommand(id) {
5691
- const { apiKey } = getConfig3();
5743
+ const { apiKey, settings } = getConfig3();
5744
+ guard(() => checkManagementAccess(settings, "delete", "Deleting a relay endpoint"));
5692
5745
  const api = new OneApi(apiKey, getApiBase());
5693
5746
  const spinner = createSpinner();
5694
5747
  spinner.start("Deleting relay endpoint...");
5695
5748
  try {
5749
+ await allowedEndpoint(api, settings, id);
5696
5750
  const result = await api.deleteRelayEndpoint(id);
5697
5751
  if (isAgentMode()) {
5698
5752
  json({ deleted: true, id: result.id });
@@ -5707,12 +5761,15 @@ async function relayDeleteCommand(id) {
5707
5761
  }
5708
5762
  }
5709
5763
  async function relayActivateCommand(id, options) {
5710
- const { apiKey } = getConfig3();
5764
+ const { apiKey, settings } = getConfig3();
5765
+ guard(() => checkManagementAccess(settings, "write", "Activating a relay endpoint"));
5711
5766
  const api = new OneApi(apiKey, getApiBase());
5712
5767
  const spinner = createSpinner();
5713
5768
  spinner.start("Activating relay endpoint...");
5714
5769
  try {
5715
5770
  const actions2 = parseJsonArg3(options.actions, "--actions");
5771
+ await allowedEndpoint(api, settings, id);
5772
+ await checkRelayActions(settings, actions2, actionMethod(api));
5716
5773
  const body = { actions: actions2 };
5717
5774
  if (options.webhookSecret) body.webhookSecret = options.webhookSecret;
5718
5775
  const result = await api.activateRelayEndpoint(id, body);
@@ -5731,7 +5788,7 @@ async function relayActivateCommand(id, options) {
5731
5788
  }
5732
5789
  }
5733
5790
  async function relayEventsCommand(options) {
5734
- const { apiKey } = getConfig3();
5791
+ const { apiKey, settings } = getConfig3();
5735
5792
  const api = new OneApi(apiKey, getApiBase());
5736
5793
  const spinner = createSpinner();
5737
5794
  spinner.start("Loading relay events...");
@@ -5744,10 +5801,13 @@ async function relayEventsCommand(options) {
5744
5801
  if (options.after) query.after = options.after;
5745
5802
  if (options.before) query.before = options.before;
5746
5803
  const result = await api.listRelayEvents(query);
5747
- const events = result.rows || [];
5804
+ const allowed = await connectionIdFilter(api, settings);
5805
+ const events = (result.rows || []).filter((e) => allowed(e.connectionId));
5748
5806
  if (isAgentMode()) {
5749
5807
  json({
5750
- total: result.total,
5808
+ // With a connection allowlist the server's total also counts rows
5809
+ // the allowlist hides, so report only what is shown.
5810
+ total: restricted(settings) ? events.length : result.total,
5751
5811
  showing: events.length,
5752
5812
  events: events.map((e) => ({
5753
5813
  id: e.id,
@@ -5783,12 +5843,12 @@ async function relayEventsCommand(options) {
5783
5843
  }
5784
5844
  }
5785
5845
  async function relayEventGetCommand(id) {
5786
- const { apiKey } = getConfig3();
5846
+ const { apiKey, settings } = getConfig3();
5787
5847
  const api = new OneApi(apiKey, getApiBase());
5788
5848
  const spinner = createSpinner();
5789
5849
  spinner.start("Loading relay event...");
5790
5850
  try {
5791
- const result = await api.getRelayEvent(id);
5851
+ const result = await allowedEvent(api, settings, id);
5792
5852
  if (isAgentMode()) {
5793
5853
  json(result);
5794
5854
  return;
@@ -5811,11 +5871,13 @@ async function relayDeliveriesCommand(options) {
5811
5871
  if (!options.endpointId && !options.eventId) {
5812
5872
  error("Provide either --endpoint-id or --event-id");
5813
5873
  }
5814
- const { apiKey } = getConfig3();
5874
+ const { apiKey, settings } = getConfig3();
5815
5875
  const api = new OneApi(apiKey, getApiBase());
5816
5876
  const spinner = createSpinner();
5817
5877
  spinner.start("Loading deliveries...");
5818
5878
  try {
5879
+ if (options.endpointId) await allowedEndpoint(api, settings, options.endpointId);
5880
+ else await allowedEvent(api, settings, options.eventId);
5819
5881
  const deliveries = options.endpointId ? await api.listRelayEndpointDeliveries(options.endpointId) : await api.listRelayEventDeliveries(options.eventId);
5820
5882
  const items = Array.isArray(deliveries) ? deliveries : deliveries.rows || [];
5821
5883
  if (isAgentMode()) {
@@ -7427,7 +7489,7 @@ async function syncModel(api, profile, options) {
7427
7489
  updateModelState(platform, model, { status: "failed", pagesProcessed, lastCursor }),
7428
7490
  (async () => {
7429
7491
  try {
7430
- const { getBackend: getBackend2 } = await import("./runtime-J4TQCY7Z.js");
7492
+ const { getBackend: getBackend2 } = await import("./runtime-2OVXKNJS.js");
7431
7493
  const backend = await getBackend2();
7432
7494
  await Promise.race([
7433
7495
  backend.close(),
@@ -7793,7 +7855,7 @@ async function syncModel(api, profile, options) {
7793
7855
  db.exec(`DROP TABLE IF EXISTS _seen_ids`);
7794
7856
  }
7795
7857
  if (options.toMemory !== false) {
7796
- const backend = await (await import("./runtime-J4TQCY7Z.js")).getBackend();
7858
+ const backend = await (await import("./runtime-2OVXKNJS.js")).getBackend();
7797
7859
  const type = `${platform}/${model}`;
7798
7860
  const existing = await backend.listKeysByType(type);
7799
7861
  const sourcePrefix = `${type}:`;
@@ -7894,7 +7956,7 @@ async function syncModel(api, profile, options) {
7894
7956
  let statusCounts;
7895
7957
  if (options.toMemory !== false) {
7896
7958
  try {
7897
- const backend = await (await import("./runtime-J4TQCY7Z.js")).getBackend();
7959
+ const backend = await (await import("./runtime-2OVXKNJS.js")).getBackend();
7898
7960
  const typeName = `${platform}/${model}`;
7899
7961
  const [active, archived] = await Promise.all([
7900
7962
  backend.count(typeName, { status: "active" }),
@@ -9616,7 +9678,7 @@ ${result.total} results`);
9616
9678
  }
9617
9679
  }
9618
9680
  async function syncSqlCommand(platformModel, sql) {
9619
- const { syncSqlCommand: runSyncSql } = await import("./sql-XCMEVSVD.js");
9681
+ const { syncSqlCommand: runSyncSql } = await import("./sql-KRQUWOPT.js");
9620
9682
  await runSyncSql(platformModel, sql);
9621
9683
  }
9622
9684
  async function syncDeleteCommand(platformModel, options) {
@@ -9694,7 +9756,7 @@ async function syncDeleteCommand(platformModel, options) {
9694
9756
  async function maybeAutoMigrateLegacy(platform, models) {
9695
9757
  const dbSize = getDatabaseSize(platform);
9696
9758
  if (!dbSize || dbSize === "0 B") return;
9697
- const { getBackend: getBackend2 } = await import("./runtime-J4TQCY7Z.js");
9759
+ const { getBackend: getBackend2 } = await import("./runtime-2OVXKNJS.js");
9698
9760
  const backend = await getBackend2();
9699
9761
  let memoryHasData = false;
9700
9762
  for (const model of models) {
@@ -9710,7 +9772,7 @@ async function maybeAutoMigrateLegacy(platform, models) {
9710
9772
  ` detected legacy .one/sync/data/${platform}.db (${dbSize}) \u2014 auto-migrating into memory before sync.
9711
9773
  `
9712
9774
  );
9713
- const { memMigrateCommand: memMigrateCommand3 } = await import("./migrate-IKK2N3VW.js");
9775
+ const { memMigrateCommand: memMigrateCommand3 } = await import("./migrate-RJ7F2LPT.js");
9714
9776
  await memMigrateCommand3({ platform, yes: true });
9715
9777
  return;
9716
9778
  }
@@ -9719,7 +9781,7 @@ async function maybeAutoMigrateLegacy(platform, models) {
9719
9781
  initialValue: true
9720
9782
  });
9721
9783
  if (p6.isCancel(shouldMigrate) || !shouldMigrate) return;
9722
- const { memMigrateCommand: memMigrateCommand2 } = await import("./migrate-IKK2N3VW.js");
9784
+ const { memMigrateCommand: memMigrateCommand2 } = await import("./migrate-RJ7F2LPT.js");
9723
9785
  await memMigrateCommand2({ platform, yes: true });
9724
9786
  }
9725
9787
  async function syncSuggestSearchableCommand(platformModel, options = {}) {
@@ -9780,7 +9842,7 @@ async function syncSuggestSearchableCommand(platformModel, options = {}) {
9780
9842
  async function syncListCommand(platform) {
9781
9843
  const profiles = listProfiles(platform);
9782
9844
  const state = await readSyncState();
9783
- const { getBackend: getBackend2 } = await import("./runtime-J4TQCY7Z.js");
9845
+ const { getBackend: getBackend2 } = await import("./runtime-2OVXKNJS.js");
9784
9846
  const backend = await getBackend2();
9785
9847
  const syncs = await Promise.all(profiles.map(async (p9) => {
9786
9848
  const modelState = state[p9.platform]?.[p9.model];
@@ -10056,7 +10118,7 @@ function registerSyncSubcommands(sync) {
10056
10118
  await syncSqlCommand(platformModel, sql);
10057
10119
  });
10058
10120
  sync.command("schema <platform/model>").description("Inspect the JSON structure of synced records (field paths, types, examples) \u2014 useful before writing `sync sql` queries").action(async (platformModel) => {
10059
- const { syncSchemaCommand } = await import("./schema-JKYKFQZD.js");
10121
+ const { syncSchemaCommand } = await import("./schema-FIIT33OD.js");
10060
10122
  await syncSchemaCommand(platformModel);
10061
10123
  });
10062
10124
  sync.command("delete <platform/model>").description('Delete records from local sync data (e.g. one sync delete notion/pages --id "abc-123")').option("--id <value>", "Delete record by ID").option("--where <conditions>", 'Delete records matching conditions (e.g. "status=archived")').option("--where-sql <predicate>", `Delete using a raw SQL WHERE clause (e.g. "json_extract(data, '$.type') = 'promotion'")`).option("--yes", "Skip confirmation prompt").action(async (platformModel, options) => {
@@ -10833,7 +10895,7 @@ async function memDoctorCommand() {
10833
10895
  }
10834
10896
  if (cfg.embedding.provider === "openai") {
10835
10897
  try {
10836
- const { embed: embed2 } = await import("./embedding-MVPO6QW7.js");
10898
+ const { embed: embed2 } = await import("./embedding-YIXO45HW.js");
10837
10899
  const result = await embed2("connectivity check");
10838
10900
  checks.push({
10839
10901
  name: "OpenAI embedding provider reachable",
@@ -3,13 +3,13 @@ import {
3
3
  dotPathToJsonbExpr,
4
4
  memMigrateCommand,
5
5
  reviveStringifiedJson
6
- } from "./chunk-5O5OUAHJ.js";
6
+ } from "./chunk-LEJKEGB6.js";
7
7
  import "./chunk-44CV5IMX.js";
8
- import "./chunk-VYOIHD4B.js";
8
+ import "./chunk-B5YDLVY5.js";
9
9
  import "./chunk-Q6PWTATS.js";
10
- import "./chunk-UYOXEMF5.js";
11
- import "./chunk-NC3HVQ7O.js";
12
- import "./chunk-FR4VGZUI.js";
10
+ import "./chunk-4H5L3SBY.js";
11
+ import "./chunk-2OIJGF77.js";
12
+ import "./chunk-XUAUDMQE.js";
13
13
  export {
14
14
  buildIdentityMap,
15
15
  dotPathToJsonbExpr,
@@ -5,9 +5,9 @@ import {
5
5
  resetBackendSingleton,
6
6
  updateRecord,
7
7
  upsertRecord
8
- } from "./chunk-UYOXEMF5.js";
9
- import "./chunk-NC3HVQ7O.js";
10
- import "./chunk-FR4VGZUI.js";
8
+ } from "./chunk-4H5L3SBY.js";
9
+ import "./chunk-2OIJGF77.js";
10
+ import "./chunk-XUAUDMQE.js";
11
11
  export {
12
12
  addRecord,
13
13
  closeBackendIfCached,
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  okJson,
3
3
  requireMemoryInit
4
- } from "./chunk-VYOIHD4B.js";
4
+ } from "./chunk-B5YDLVY5.js";
5
5
  import {
6
6
  isAgentMode,
7
7
  note
8
8
  } from "./chunk-Q6PWTATS.js";
9
9
  import {
10
10
  getBackend
11
- } from "./chunk-UYOXEMF5.js";
12
- import "./chunk-NC3HVQ7O.js";
13
- import "./chunk-FR4VGZUI.js";
11
+ } from "./chunk-4H5L3SBY.js";
12
+ import "./chunk-2OIJGF77.js";
13
+ import "./chunk-XUAUDMQE.js";
14
14
 
15
15
  // src/lib/memory/sync/schema.ts
16
16
  import pc from "picocolors";
@@ -0,0 +1,13 @@
1
+ import {
2
+ memSqlCommand,
3
+ syncSqlCommand
4
+ } from "./chunk-TSMVFVQ3.js";
5
+ import "./chunk-B5YDLVY5.js";
6
+ import "./chunk-Q6PWTATS.js";
7
+ import "./chunk-4H5L3SBY.js";
8
+ import "./chunk-2OIJGF77.js";
9
+ import "./chunk-XUAUDMQE.js";
10
+ export {
11
+ memSqlCommand,
12
+ syncSqlCommand
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/cli",
3
- "version": "2.11.1",
3
+ "version": "2.13.0",
4
4
  "description": "CLI for managing One",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,13 +0,0 @@
1
- import {
2
- memSqlCommand,
3
- syncSqlCommand
4
- } from "./chunk-WWPH6JOO.js";
5
- import "./chunk-VYOIHD4B.js";
6
- import "./chunk-Q6PWTATS.js";
7
- import "./chunk-UYOXEMF5.js";
8
- import "./chunk-NC3HVQ7O.js";
9
- import "./chunk-FR4VGZUI.js";
10
- export {
11
- memSqlCommand,
12
- syncSqlCommand
13
- };