@carthooks/arcubase-cli 0.1.19 → 0.1.20

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.
@@ -0,0 +1,48 @@
1
+ import { helpExamplesIndex } from '../generated/help_examples.generated.js';
2
+ function binaryForScope(scope) {
3
+ return scope === 'admin' ? 'arcubase-admin' : 'arcubase';
4
+ }
5
+ function getFixedValue(value) {
6
+ if (!('fixedValue' in value)) {
7
+ return undefined;
8
+ }
9
+ const fixedValue = value.fixedValue;
10
+ return typeof fixedValue === 'string' ? fixedValue : undefined;
11
+ }
12
+ function pathFlagPlaceholders(command) {
13
+ const parts = command.pathParams
14
+ .filter((item) => !getFixedValue(item))
15
+ .map((item) => `--${item.flag} <${item.flag.replace(/-/g, '_')}>`);
16
+ return parts.length > 0 ? `${parts.join(' ')} ` : '';
17
+ }
18
+ function helpExampleKey(scope, command) {
19
+ return `${scope}.${command.commandPath.join('.')}`;
20
+ }
21
+ export function getCommandHelpExamples(scope, command) {
22
+ return helpExamplesIndex[helpExampleKey(scope, command)]?.examples ?? [];
23
+ }
24
+ export function renderCommandHelpExamples(scope, command) {
25
+ const binary = binaryForScope(scope);
26
+ const examples = getCommandHelpExamples(scope, command);
27
+ const header = `${binary} ${command.commandPath.join(' ')} --help-examples`;
28
+ if (examples.length === 0) {
29
+ return [
30
+ header,
31
+ '',
32
+ 'No dedicated examples for this final command yet.',
33
+ `Use ${binary} ${command.commandPath.join(' ')} --help for flags, docs, and type paths.`,
34
+ ].join('\n');
35
+ }
36
+ return [
37
+ header,
38
+ '',
39
+ ...examples.flatMap((example) => [
40
+ `${example.title}:`,
41
+ ...(example.body === undefined
42
+ ? []
43
+ : [` ${binary} ${command.commandPath.join(' ')} ${pathFlagPlaceholders(command)}--body-json '${JSON.stringify(example.body)}'`.replace(/\s+/g, ' ').trim()]),
44
+ ...(example.notes ?? []).map((note) => ` - ${note}`),
45
+ '',
46
+ ]),
47
+ ].join('\n').trimEnd();
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carthooks/arcubase-cli",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Arcubase runtime CLI for admin and user command execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,9 +22,10 @@
22
22
  "codegen:commands": "node scripts/generate-command-registry.mjs",
23
23
  "codegen:zod": "node scripts/generate-zod-registry.mjs",
24
24
  "codegen:type-index": "node scripts/generate-type-index.mjs",
25
- "bundle": "npm run codegen:commands && npm run codegen:zod && npm run codegen:type-index && tsc && node scripts/bundle-cli.mjs",
25
+ "codegen:help-examples": "node scripts/generate-help-examples.mjs",
26
+ "bundle": "npm run codegen:commands && npm run codegen:zod && npm run codegen:type-index && npm run codegen:help-examples && tsc && node scripts/bundle-cli.mjs",
26
27
  "build": "npm run bundle && npm run docs:llms",
27
- "test": "npm run codegen:commands && npm run codegen:zod && npm run codegen:type-index && tsx --test src/tests/*.test.ts",
28
+ "test": "npm run codegen:commands && npm run codegen:zod && npm run codegen:type-index && npm run codegen:help-examples && tsx --test src/tests/*.test.ts",
28
29
  "watch": "tsc --watch",
29
30
  "type-check": "tsc --noEmit",
30
31
  "docs:llms": "node -e \"\""
@@ -0,0 +1,23 @@
1
+ {
2
+ "scope": "admin",
3
+ "command": ["access-rule", "assign-users"],
4
+ "examples": [
5
+ {
6
+ "title": "replace user_scope with user, department, and actor scopes",
7
+ "body": {
8
+ "update": ["user_scope"],
9
+ "options": {
10
+ "user_scope": [
11
+ {"type": "user", "id": 2188889901},
12
+ {"type": "department", "id": 2188881201},
13
+ {"type": "actor", "id": 2188883301}
14
+ ]
15
+ }
16
+ },
17
+ "notes": [
18
+ "id must be numeric arcubaseUserId, department ID, or actor ID",
19
+ "assign-users updates user_scope only and preserves the existing policy"
20
+ ]
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,95 @@
1
+ {
2
+ "scope": "admin",
3
+ "command": ["access-rule", "create"],
4
+ "examples": [
5
+ {
6
+ "title": "full access for a specific arcubaseUserId",
7
+ "body": {
8
+ "name": "Admin full access",
9
+ "enabled": true,
10
+ "type": "form",
11
+ "options": {
12
+ "user_scope": [{"type": "user", "id": 2188889977}],
13
+ "policy": {
14
+ "key": "custom",
15
+ "actions": ["view", "add", "edit", "delete"],
16
+ "all_fields_read": true,
17
+ "all_fields_write": true
18
+ },
19
+ "list_options": {}
20
+ }
21
+ }
22
+ },
23
+ {
24
+ "title": "department can view/add/edit only rows created by themselves",
25
+ "body": {
26
+ "name": "Sales own rows",
27
+ "enabled": true,
28
+ "type": "form",
29
+ "options": {
30
+ "user_scope": [{"type": "department", "id": 2188881201}],
31
+ "policy": {
32
+ "key": "custom",
33
+ "actions": ["view", "add", "edit"],
34
+ "all_fields_read": true,
35
+ "all_fields_write": true,
36
+ "condition": {
37
+ "mode": "and",
38
+ "conditions": [
39
+ {"column": "creator", "operator": "$eq", "value": "[[current_user]]", "value_from": 0, "value_relation": ""}
40
+ ]
41
+ }
42
+ },
43
+ "list_options": {}
44
+ }
45
+ },
46
+ "notes": [
47
+ "department scope includes child departments",
48
+ "row-owner isolation uses [[current_user]] on creator"
49
+ ]
50
+ },
51
+ {
52
+ "title": "role actor can view rows matching a complex AND/OR condition",
53
+ "body": {
54
+ "name": "Sales manager review queue",
55
+ "enabled": true,
56
+ "type": "form",
57
+ "options": {
58
+ "user_scope": [{"type": "actor", "id": 2188883301}],
59
+ "policy": {
60
+ "key": "custom",
61
+ "actions": ["view", "edit"],
62
+ "all_fields_read": true,
63
+ "all_fields_write": true,
64
+ "condition": {
65
+ "mode": "and",
66
+ "conditions": [
67
+ {"column": ":1004", "operator": "$eq", "value": "pending", "value_from": 0, "value_relation": ""},
68
+ {
69
+ "column": "",
70
+ "operator": "",
71
+ "value": null,
72
+ "value_from": 0,
73
+ "value_relation": "",
74
+ "subset": {
75
+ "mode": "or",
76
+ "conditions": [
77
+ {"column": "creator", "operator": "$eq", "value": "[[current_user]]", "value_from": 0, "value_relation": ""},
78
+ {"column": ":1005", "operator": "$eq", "value": "high", "value_from": 0, "value_relation": ""}
79
+ ]
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ },
85
+ "list_options": {}
86
+ }
87
+ },
88
+ "notes": [
89
+ "actor means Arcubase role id",
90
+ "condition mode \"and\" and \"or\" are canonical; legacy \"all\" also reads as AND",
91
+ "nested OR uses subset and leaves the wrapper column/operator empty"
92
+ ]
93
+ }
94
+ ]
95
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "scope": "user",
3
+ "command": ["row", "bulk-update"],
4
+ "examples": [
5
+ {
6
+ "title": "bulk update explicit row ids",
7
+ "body": {
8
+ "selection": {"type": "ids", "ids": [2188890411, 2188890412], "length": 2},
9
+ "fields": [{"id": 1003, "action": {"type": "set", "value": 2}}]
10
+ }
11
+ },
12
+ {
13
+ "title": "bulk update rows selected by a search condition",
14
+ "body": {
15
+ "selection": {"type": "condition", "condition": {"selectAll": true, "q": "SO-1001"}, "length": 0},
16
+ "fields": [{"id": 1003, "action": {"type": "set", "value": 2}}]
17
+ },
18
+ "notes": [
19
+ "condition selection uses row-query style keys such as q, tab, and filter_:1002"
20
+ ]
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "scope": "user",
3
+ "command": ["row", "selection-action"],
4
+ "examples": [
5
+ {
6
+ "title": "run a custom action against explicit row ids",
7
+ "body": {
8
+ "selection": {"type": "ids", "ids": [2188890411], "length": 1}
9
+ },
10
+ "notes": [
11
+ "pass the backend action code with --action",
12
+ "for query action, use ids or all selection instead of condition selection"
13
+ ]
14
+ },
15
+ {
16
+ "title": "run a custom action against a filtered selection",
17
+ "body": {
18
+ "selection": {"type": "condition", "condition": {"selectAll": true, "q": "SO-1001"}, "length": 0}
19
+ },
20
+ "notes": [
21
+ "condition selection uses row-query style keys such as q, tab, and filter_:1002"
22
+ ]
23
+ }
24
+ ]
25
+ }
@@ -0,0 +1,289 @@
1
+ // Generated by scripts/generate-help-examples.mjs. Do not edit by hand.
2
+
3
+ export type GeneratedHelpExample = {
4
+ title: string
5
+ body?: unknown
6
+ notes?: readonly string[]
7
+ }
8
+
9
+ export const helpExamplesIndex = {
10
+ "admin.access-rule.assign-users": {
11
+ "command": [
12
+ "access-rule",
13
+ "assign-users"
14
+ ],
15
+ "examples": [
16
+ {
17
+ "title": "replace user_scope with user, department, and actor scopes",
18
+ "body": {
19
+ "update": [
20
+ "user_scope"
21
+ ],
22
+ "options": {
23
+ "user_scope": [
24
+ {
25
+ "type": "user",
26
+ "id": 2188889901
27
+ },
28
+ {
29
+ "type": "department",
30
+ "id": 2188881201
31
+ },
32
+ {
33
+ "type": "actor",
34
+ "id": 2188883301
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ "notes": [
40
+ "id must be numeric arcubaseUserId, department ID, or actor ID",
41
+ "assign-users updates user_scope only and preserves the existing policy"
42
+ ]
43
+ }
44
+ ]
45
+ },
46
+ "admin.access-rule.create": {
47
+ "command": [
48
+ "access-rule",
49
+ "create"
50
+ ],
51
+ "examples": [
52
+ {
53
+ "title": "full access for a specific arcubaseUserId",
54
+ "body": {
55
+ "name": "Admin full access",
56
+ "enabled": true,
57
+ "type": "form",
58
+ "options": {
59
+ "user_scope": [
60
+ {
61
+ "type": "user",
62
+ "id": 2188889977
63
+ }
64
+ ],
65
+ "policy": {
66
+ "key": "custom",
67
+ "actions": [
68
+ "view",
69
+ "add",
70
+ "edit",
71
+ "delete"
72
+ ],
73
+ "all_fields_read": true,
74
+ "all_fields_write": true
75
+ },
76
+ "list_options": {}
77
+ }
78
+ }
79
+ },
80
+ {
81
+ "title": "department can view/add/edit only rows created by themselves",
82
+ "body": {
83
+ "name": "Sales own rows",
84
+ "enabled": true,
85
+ "type": "form",
86
+ "options": {
87
+ "user_scope": [
88
+ {
89
+ "type": "department",
90
+ "id": 2188881201
91
+ }
92
+ ],
93
+ "policy": {
94
+ "key": "custom",
95
+ "actions": [
96
+ "view",
97
+ "add",
98
+ "edit"
99
+ ],
100
+ "all_fields_read": true,
101
+ "all_fields_write": true,
102
+ "condition": {
103
+ "mode": "and",
104
+ "conditions": [
105
+ {
106
+ "column": "creator",
107
+ "operator": "$eq",
108
+ "value": "[[current_user]]",
109
+ "value_from": 0,
110
+ "value_relation": ""
111
+ }
112
+ ]
113
+ }
114
+ },
115
+ "list_options": {}
116
+ }
117
+ },
118
+ "notes": [
119
+ "department scope includes child departments",
120
+ "row-owner isolation uses [[current_user]] on creator"
121
+ ]
122
+ },
123
+ {
124
+ "title": "role actor can view rows matching a complex AND/OR condition",
125
+ "body": {
126
+ "name": "Sales manager review queue",
127
+ "enabled": true,
128
+ "type": "form",
129
+ "options": {
130
+ "user_scope": [
131
+ {
132
+ "type": "actor",
133
+ "id": 2188883301
134
+ }
135
+ ],
136
+ "policy": {
137
+ "key": "custom",
138
+ "actions": [
139
+ "view",
140
+ "edit"
141
+ ],
142
+ "all_fields_read": true,
143
+ "all_fields_write": true,
144
+ "condition": {
145
+ "mode": "and",
146
+ "conditions": [
147
+ {
148
+ "column": ":1004",
149
+ "operator": "$eq",
150
+ "value": "pending",
151
+ "value_from": 0,
152
+ "value_relation": ""
153
+ },
154
+ {
155
+ "column": "",
156
+ "operator": "",
157
+ "value": null,
158
+ "value_from": 0,
159
+ "value_relation": "",
160
+ "subset": {
161
+ "mode": "or",
162
+ "conditions": [
163
+ {
164
+ "column": "creator",
165
+ "operator": "$eq",
166
+ "value": "[[current_user]]",
167
+ "value_from": 0,
168
+ "value_relation": ""
169
+ },
170
+ {
171
+ "column": ":1005",
172
+ "operator": "$eq",
173
+ "value": "high",
174
+ "value_from": 0,
175
+ "value_relation": ""
176
+ }
177
+ ]
178
+ }
179
+ }
180
+ ]
181
+ }
182
+ },
183
+ "list_options": {}
184
+ }
185
+ },
186
+ "notes": [
187
+ "actor means Arcubase role id",
188
+ "condition mode \"and\" and \"or\" are canonical; legacy \"all\" also reads as AND",
189
+ "nested OR uses subset and leaves the wrapper column/operator empty"
190
+ ]
191
+ }
192
+ ]
193
+ },
194
+ "user.row.bulk-update": {
195
+ "command": [
196
+ "row",
197
+ "bulk-update"
198
+ ],
199
+ "examples": [
200
+ {
201
+ "title": "bulk update explicit row ids",
202
+ "body": {
203
+ "selection": {
204
+ "type": "ids",
205
+ "ids": [
206
+ 2188890411,
207
+ 2188890412
208
+ ],
209
+ "length": 2
210
+ },
211
+ "fields": [
212
+ {
213
+ "id": 1003,
214
+ "action": {
215
+ "type": "set",
216
+ "value": 2
217
+ }
218
+ }
219
+ ]
220
+ }
221
+ },
222
+ {
223
+ "title": "bulk update rows selected by a search condition",
224
+ "body": {
225
+ "selection": {
226
+ "type": "condition",
227
+ "condition": {
228
+ "selectAll": true,
229
+ "q": "SO-1001"
230
+ },
231
+ "length": 0
232
+ },
233
+ "fields": [
234
+ {
235
+ "id": 1003,
236
+ "action": {
237
+ "type": "set",
238
+ "value": 2
239
+ }
240
+ }
241
+ ]
242
+ },
243
+ "notes": [
244
+ "condition selection uses row-query style keys such as q, tab, and filter_:1002"
245
+ ]
246
+ }
247
+ ]
248
+ },
249
+ "user.row.selection-action": {
250
+ "command": [
251
+ "row",
252
+ "selection-action"
253
+ ],
254
+ "examples": [
255
+ {
256
+ "title": "run a custom action against explicit row ids",
257
+ "body": {
258
+ "selection": {
259
+ "type": "ids",
260
+ "ids": [
261
+ 2188890411
262
+ ],
263
+ "length": 1
264
+ }
265
+ },
266
+ "notes": [
267
+ "pass the backend action code with --action",
268
+ "for query action, use ids or all selection instead of condition selection"
269
+ ]
270
+ },
271
+ {
272
+ "title": "run a custom action against a filtered selection",
273
+ "body": {
274
+ "selection": {
275
+ "type": "condition",
276
+ "condition": {
277
+ "selectAll": true,
278
+ "q": "SO-1001"
279
+ },
280
+ "length": 0
281
+ }
282
+ },
283
+ "notes": [
284
+ "condition selection uses row-query style keys such as q, tab, and filter_:1002"
285
+ ]
286
+ }
287
+ ]
288
+ }
289
+ } as const satisfies Record<string, { command: readonly string[]; examples: readonly GeneratedHelpExample[] }>