@zalosai/zalos-cli 0.2.23 → 0.2.24

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/PUBLISHING.md CHANGED
@@ -59,6 +59,10 @@ Do not publish with uncommitted package changes or reuse an existing version.
59
59
 
60
60
  ## Central developer access release
61
61
 
62
+ Version 0.2.24 adds `zl file folder list` and `zl file folder create` for
63
+ organizing Team Files through the existing `/api/folders` API (`files` scope).
64
+ `create` accepts `--parent-folder-id` for nesting and `--dry-run` to preview.
65
+
62
66
  Version 0.2.23 adds explicit `--include-internal` reads for workflow setup and
63
67
  scheduled tasks. Deploy the schedule-preview visibility option first. The
64
68
  existing server-side team-owner check remains authoritative.
package/README.md CHANGED
@@ -124,6 +124,9 @@ zl workflow run <id>
124
124
  zl template list
125
125
  zl credential list
126
126
  zl file list
127
+ zl file folder list [--parent-folder-id <folder-id>]
128
+ zl file folder create <name> [--parent-folder-id <folder-id>] [--dry-run]
129
+ zl file upload ./report.xlsx --folder-id <folder-id>
127
130
  zl team list
128
131
  zl team switch <team-ref>
129
132
  zl team list --all-teams
@@ -8,6 +8,9 @@ import { downloadToNewFile } from '../utils/download-file.js';
8
8
  import { filterSingle, printJson } from '../utils/output.js';
9
9
  import { action, dataRow, dataRows, fields, isRow, printPage, resourceId, } from '../utils/product-api.js';
10
10
  const FILE_FIELDS = 'id,name,fileName,mimeType,size,fileSize,folderId,createdAt,updatedAt';
11
+ const FOLDER_FIELDS = 'id,name,parentFolderId,createdAt,updatedAt';
12
+ // Team Files folders live in the `files` folder scope; workflow folders use `workflows`.
13
+ const FILES_FOLDER_SCOPE = 'files';
11
14
  const MAX_FILE_SIZE_BYTES = 500 * 1024 * 1024;
12
15
  const UPLOAD_TIMEOUT_MS = 15 * 60_000;
13
16
  const MIME_TYPES = {
@@ -122,6 +125,29 @@ export async function uploadFileAction(localPath, options) {
122
125
  form.append('file', file, basename(localPath));
123
126
  printJson(dataRow(await client.postForm('/team-files/upload', form, { timeoutMs: UPLOAD_TIMEOUT_MS })));
124
127
  }
128
+ export async function listFoldersAction(options) {
129
+ const parentFolderId = options.parentFolderId ? resourceId(options.parentFolderId) : 'root';
130
+ const rows = dataRows(await client.get('/folders', { scope: FILES_FOLDER_SCOPE, parentFolderId })).map((row) => filterSingle(row, FOLDER_FIELDS));
131
+ printPage(rows, options);
132
+ }
133
+ export async function createFolderAction(name, options) {
134
+ const trimmed = name.trim();
135
+ if (!trimmed)
136
+ throw new ValidationError('name', 'Folder name must not be empty');
137
+ if (/[\\/]/.test(trimmed)) {
138
+ throw new ValidationError('name', 'Folder name cannot contain / or \\; use --parent-folder-id');
139
+ }
140
+ const payload = {
141
+ name: trimmed,
142
+ scope: FILES_FOLDER_SCOPE,
143
+ ...(options.parentFolderId ? { parentFolderId: resourceId(options.parentFolderId) } : {}),
144
+ };
145
+ if (options.dryRun) {
146
+ printJson({ dryRun: true, method: 'POST', path: '/folders', payload });
147
+ return;
148
+ }
149
+ printJson(filterSingle(dataRow(await client.post('/folders', payload)), FOLDER_FIELDS));
150
+ }
125
151
  export async function snapshotFilesAction(options) {
126
152
  if (options.teamId) {
127
153
  const snapshot = {
@@ -282,6 +308,20 @@ export function registerFileCommand(program) {
282
308
  .option('--mime-type <type>', 'Override the detected MIME type')
283
309
  .option('--overwrite', 'Replace an existing file with the same name')
284
310
  .action(async (path, o) => action(() => uploadFileAction(path, o)));
311
+ const folder = cmd.command('folder').description('Manage Team Files folders');
312
+ folder
313
+ .command('list')
314
+ .description('List Team Files folders under a parent folder')
315
+ .option('--parent-folder-id <id>', 'Parent folder ID (defaults to root)')
316
+ .option('--limit <n>', 'Maximum results', '100')
317
+ .option('--offset <n>', 'Result offset', '0')
318
+ .action(async (o) => action(() => listFoldersAction({ ...o, ...fields(program) })));
319
+ folder
320
+ .command('create <name>')
321
+ .description('Create a Team Files folder in the selected team')
322
+ .option('--parent-folder-id <id>', 'Parent folder ID (defaults to root)')
323
+ .option('--dry-run', 'Preview the request without creating the folder')
324
+ .action(async (name, o) => action(() => createFolderAction(name, o)));
285
325
  cmd
286
326
  .command('snapshot')
287
327
  .description('Snapshot metadata within a folder')
@@ -75,7 +75,7 @@ export async function evalSuiteSetAction(workflowId, options) {
75
75
  }
76
76
  if (!isRow(input) ||
77
77
  typeof input.name !== 'string' ||
78
- !['northwind_cash', 'ah_bill_reports'].includes(String(input.profile)) ||
78
+ !['northwind_cash', 'ah_bill_reports', 'configured'].includes(String(input.profile)) ||
79
79
  !Array.isArray(input.cases) ||
80
80
  typeof input.monitoringEnabled !== 'boolean')
81
81
  throw new ValidationError('input', 'Expected a suite with name, profile, cases and monitoringEnabled');
@@ -97,6 +97,7 @@ export async function evalSuiteSetAction(workflowId, options) {
97
97
  name: input.name,
98
98
  profile: input.profile,
99
99
  cases: input.cases,
100
+ ...(input.rules === undefined ? {} : { rules: input.rules }),
100
101
  monitoringEnabled: input.monitoringEnabled,
101
102
  expectedRevision: revision,
102
103
  };
@@ -1,7 +1,7 @@
1
1
  import { writeFile, stat } from 'node:fs/promises';
2
2
  import { resolve, join } from 'node:path';
3
3
  import { client } from '../client.js';
4
- import { readWorkflowFile, serializeWorkflow } from '../workflow-file.js';
4
+ import { parseWorkflowFile, readWorkflowFile, serializeWorkflow } from '../workflow-file.js';
5
5
  import { ApiError, ValidationError } from '../utils/errors.js';
6
6
  import { filterSingle, printJson } from '../utils/output.js';
7
7
  import { action, dataRow, dataRows, fields, isRow, printPage, resourceId, } from '../utils/product-api.js';
@@ -147,8 +147,11 @@ export async function importWorkflowAction(path, options) {
147
147
  printJson(dataRow(await client.post('/workflows', payload)));
148
148
  }
149
149
  export async function updateWorkflowAction(id, options) {
150
+ await saveWorkflowDraft(id, await readWorkflowFile(options.input, id), options);
151
+ }
152
+ async function saveWorkflowDraft(id, draft, options) {
150
153
  const path = `/workflows/${resourceId(id)}`;
151
- const { checksum, expectedChecksum, versionId: _versionId, publishedVersionId: _publishedVersionId, ...workflow } = await readWorkflowFile(options.input, id);
154
+ const { checksum, expectedChecksum, versionId: _versionId, publishedVersionId: _publishedVersionId, ...workflow } = draft;
152
155
  for (const value of [checksum, expectedChecksum]) {
153
156
  if (value !== undefined && (typeof value !== 'string' || !value.trim())) {
154
157
  throw new ValidationError('checksum', 'Workflow checksum must be a nonempty string');
@@ -219,8 +222,127 @@ export async function runWorkflowAction(id, options) {
219
222
  }
220
223
  printJson(dataRow(await client.post(path, payload)));
221
224
  }
225
+ function propertyContainer(draft, pointer, target) {
226
+ if (!pointer.startsWith('/') || /~(?![01])/.test(pointer))
227
+ throw new ValidationError('path', 'Use a JSON Pointer such as /instructions');
228
+ const segments = pointer
229
+ .slice(1)
230
+ .split('/')
231
+ .map((part) => part.replaceAll('~1', '/').replaceAll('~0', '~'));
232
+ if (segments.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key)))
233
+ throw new ValidationError('path', 'Unsafe property name');
234
+ let current = draft;
235
+ if (target.node !== undefined) {
236
+ const matches = draft.nodes.filter((node) => node.id === target.node);
237
+ if (matches.length !== 1)
238
+ throw new ValidationError('node', 'Expected exactly one node with that ID');
239
+ current = matches[0].parameters;
240
+ }
241
+ for (const [index, key] of segments.entries()) {
242
+ if (Array.isArray(current)) {
243
+ if (!/^(0|[1-9]\d*)$/.test(key) || !Object.hasOwn(current, key))
244
+ throw new ValidationError('path', 'Array index must identify an existing element');
245
+ if (index === segments.length - 1)
246
+ return { container: current, key };
247
+ current = current[Number(key)];
248
+ }
249
+ else if (isRow(current)) {
250
+ if (index === segments.length - 1)
251
+ return { container: current, key };
252
+ current = Object.hasOwn(current, key) ? current[key] : undefined;
253
+ }
254
+ else {
255
+ throw new ValidationError('path', 'Parent property does not exist or is not an object or array');
256
+ }
257
+ }
258
+ throw new ValidationError('path', 'Expected a property path');
259
+ }
260
+ export async function workflowPropertyAction(id, pointer, options) {
261
+ const path = `/workflows/${resourceId(id)}`;
262
+ const draft = dataRow(options.includeInternal
263
+ ? await client.get(path, { includeInternal: 'true' })
264
+ : await client.get(path));
265
+ const { container, key } = propertyContainer(draft, pointer, options);
266
+ const previous = Array.isArray(container)
267
+ ? container[Number(key)]
268
+ : Object.hasOwn(container, key)
269
+ ? container[key]
270
+ : undefined;
271
+ if (options.json === undefined) {
272
+ if (previous === undefined)
273
+ throw new ValidationError('path', 'Property does not exist');
274
+ printJson(previous);
275
+ return;
276
+ }
277
+ if (!options.node &&
278
+ /^\/(?:id|checksum|expectedChecksum|versionId|publishedVersionId|createdAt|updatedAt|active)(?:\/|$)/.test(pointer))
279
+ throw new ValidationError('path', 'This workflow field cannot be changed with property set');
280
+ const value = parseJson(options.json);
281
+ if (Array.isArray(container))
282
+ container[Number(key)] = value;
283
+ else
284
+ container[key] = value;
285
+ const updated = parseWorkflowFile(JSON.stringify(draft), id);
286
+ if (!options.apply || options.dryRun) {
287
+ printJson({
288
+ dryRun: true,
289
+ workflowId: id,
290
+ nodeId: options.node,
291
+ path: pointer,
292
+ previous,
293
+ value,
294
+ checksum: draft.checksum,
295
+ });
296
+ return;
297
+ }
298
+ await saveWorkflowDraft(id, updated, options);
299
+ }
222
300
  export function registerWorkflowCommand(program) {
223
301
  const cmd = program.command('workflow').description('Manage workflows through the regional API');
302
+ const property = cmd
303
+ .command('property')
304
+ .description('Inspect and edit workflow draft properties');
305
+ property
306
+ .command('get <id> <path>')
307
+ .description('Read a JSON Pointer from the workflow draft or selected node parameters')
308
+ .option('--node <id>', 'Resolve the pointer relative to this node’s parameters')
309
+ .option('--include-internal', 'Include internal workflows (team owners only)')
310
+ .action(async (id, path, o) => action(() => workflowPropertyAction(id, path, o)));
311
+ property
312
+ .command('set <id> <path>')
313
+ .description('Set a JSON Pointer on the workflow draft or selected node parameters')
314
+ .option('--node <id>', 'Resolve the pointer relative to this node’s parameters')
315
+ .option('--include-internal', 'Include internal workflows (team owners only)')
316
+ .requiredOption('--json <value>', 'New value as JSON')
317
+ .option('--apply', 'Save the draft')
318
+ .option('--dry-run', 'Preview the change')
319
+ .action(async (id, path, o) => action(() => workflowPropertyAction(id, path, o)));
320
+ cmd
321
+ .command('node-types [type]')
322
+ .description('Inspect node types and parameter definitions from the regional API')
323
+ .action(async (type) => action(async () => {
324
+ const types = dataRows(await client.get('/node-types'));
325
+ if (type === undefined) {
326
+ printJson(types.map(({ name, displayName }) => ({ name, displayName })));
327
+ return;
328
+ }
329
+ const definition = types.find((node) => node.name === type);
330
+ if (!definition)
331
+ throw new ValidationError('type', 'Unknown node type');
332
+ printJson(definition);
333
+ }));
334
+ property
335
+ .command('options <id> <node-id> <path>')
336
+ .description('List dynamic options for a JSON Pointer relative to the node parameters')
337
+ .option('--source <id>', 'List options within this source')
338
+ .option('--include-internal', 'Include internal workflows (team owners only)')
339
+ .action(async (id, nodeId, path, o) => action(async () => {
340
+ printJson(dataRows(await client.get(`/workflows/${resourceId(id)}/nodes/${resourceId(nodeId)}/property-options`, {
341
+ path,
342
+ ...(o.source !== undefined ? { source: o.source } : {}),
343
+ ...(o.includeInternal ? { includeInternal: 'true' } : {}),
344
+ })));
345
+ }));
224
346
  registerWorkflowEvalCommand(cmd, program);
225
347
  registerWorkflowScheduleCommand(cmd);
226
348
  cmd
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalosai/zalos-cli",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "API-only product command-line interface for Zalos",
5
5
  "repository": {
6
6
  "type": "git",