@engini/cli 0.33.0 → 0.35.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.
Files changed (3) hide show
  1. package/README.md +18 -2
  2. package/dist/cli.js +161 -5
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -45,8 +45,10 @@ engini triggers list | get | create | enable | disable | delete # trigger inst
45
45
  engini triggers events | events get | events replay # the event LOG (real delivery state)
46
46
  engini triggers listen # the live event STREAM (local dev only)
47
47
  engini triggers destinations set | add | list | show | enable | rm | rotate-secret
48
- engini executions list | get | log | data # read-only run history (no rerun)
48
+ engini executions list | get | log | data | rerun # run history; rerun one execution
49
49
  engini workflows list | folders # find a workflow id / a folder id by name
50
+ engini workflows get | revisions # one workflow with its steps; its stored revisions
51
+ engini workflows enable | disable | delete | run # turn on/off, soft-delete (--force), start a run (--body)
50
52
  engini workflows search | schema | options | tables | columns | connections # builder lookups
51
53
  engini workflows compile | plan | create | update # dry-run a plan; create (turned off) / update from it
52
54
  ```
@@ -58,6 +60,9 @@ drains every page of a step's recorded payloads unless `--top` is given (`--offs
58
60
  at 300 characters; the full connector error body is in `executions data <id> <step> --type response`).
59
61
  On a terminal the log prints as a table with each failed step's error under it; piped or with
60
62
  `--json` it stays the plain snake_case array.
63
+ `executions data --type status` entries carry `duration` (active seconds of that one iteration or
64
+ retry attempt, set once its status is final; absent on request/response/input entries and while it
65
+ is still running). The step-level `duration` in `executions log` is the cumulative sum.
61
66
  Note the difference from `triggers list`: that prints a bare JSON array, while `executions list`
62
67
  prints one page as an object (use `--all` to drain, still as the object).
63
68
 
@@ -67,7 +72,18 @@ prints one page as an object (use `--all` to drain, still as the object).
67
72
  several rows; compare the name yourself for an exact one. `list` narrows to a folder with
68
73
  `--folder <name>` (exact name, resolved through `workflows folders`; an unknown or ambiguous
69
74
  name is an error listing the matches) or `--folder-id <id>` (`0` = workflows with no folder).
70
- `folders` shows workflow folders only. `list` rows carry no steps: read one back with `plan <workflowId>`.
75
+ `folders` shows workflow folders only. `list` rows carry no steps: read one back with `get <workflowId>`
76
+ (the steps, plus `webhookUrl` for a webhook trigger - it carries the trigger's token, so treat it like a
77
+ credential) or as an editable plan with `plan <workflowId>`. `revisions <workflowId>` prints one page of
78
+ stored revisions, newest first, as `{ items, totalCount, offset, top }`.
79
+
80
+ `enable`, `disable`, `delete`, `run` and `executions rerun` change state and need a workspace-scoped API
81
+ key: an unscoped key is refused `403 SCOPE_READ_ONLY` (exit 3, with a hint) and still reads. `delete` is a
82
+ soft delete; it confirms on a terminal and scripts must pass `--force`. `run <workflowId>` starts one run
83
+ now - `--body <json|@file|->` is the trigger payload (default `{}`) - and prints the started execution in
84
+ snake_case, like `executions get`. `executions rerun <id>` prints the new execution. Neither asks first, and
85
+ the API has no idempotency key, so a retry after a lost answer starts a second run. A `409` (not runnable,
86
+ run still in progress) exits 1 with the server's message. Every one takes `--dry-run`.
71
87
 
72
88
  The `workflows` group prints the API's own camelCase JSON so `plan <id> > plan.json` feeds
73
89
  `update --file plan.json`. `compile`, `create` and `update` read the plan from `--file <path>`
package/dist/cli.js CHANGED
@@ -465,7 +465,7 @@ function saveConfig(config, path = configPath()) {
465
465
  }
466
466
 
467
467
  // src/version.ts
468
- var VERSION = true ? "0.33.0" : "0.0.0";
468
+ var VERSION = true ? "0.35.0" : "0.0.0";
469
469
 
470
470
  // src/http.ts
471
471
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -516,6 +516,7 @@ function exitForError(err) {
516
516
  if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
517
517
  return 1 /* GENERIC */;
518
518
  }
519
+ var SCOPE_READ_ONLY_HINT = "Use an API key scoped to the workspace and environment that holds the resource: a key without a scope can only read.";
519
520
  async function apiErrors(fn) {
520
521
  try {
521
522
  return await fn();
@@ -528,6 +529,9 @@ async function apiErrors(fn) {
528
529
  diagnostics: err.diagnostics
529
530
  });
530
531
  }
532
+ if (err instanceof EnginiAuthError && err.errorCode === "SCOPE_READ_ONLY") {
533
+ fail(exitForError(err), err.message, SCOPE_READ_ONLY_HINT);
534
+ }
531
535
  if (err instanceof EnginiError) {
532
536
  fail(exitForError(err), err.message);
533
537
  }
@@ -2339,7 +2343,7 @@ TRIGGERS
2339
2343
  Note: add/rotate-secret/set(create) print the signing secret in the clear, once.
2340
2344
 
2341
2345
  EXECUTIONS
2342
- Read-only run history of workflows, table automations and business rules (no rerun).
2346
+ Run history of workflows, table automations and business rules; 'rerun' runs one again.
2343
2347
  executions list [--workflow <id>] [--type <t>] [--trigger-type <t>] [--status <s>...]
2344
2348
  [--context <text>] [--created-by <id>] [--created-after|--created-before <iso>]
2345
2349
  [--closed-after|--closed-before <iso>] [--sort <spec>] [--cursor <c>] [--top <n>] [--all]
@@ -2349,6 +2353,7 @@ EXECUTIONS
2349
2353
  executions data <execution_id> <step_no> [--type <kind>] [--loop-path <s:i>...] [--run-number <n>]
2350
2354
  [--retry-no <n>] [--status <s>] [--top <n>] [--offset <n>]
2351
2355
  Recorded step payloads; drains every page unless --top.
2356
+ executions rerun <execution_id> Run it again; prints the new execution. No prompt, no idempotency key.
2352
2357
  Note: step detail is deleted after the workflow's history retention window (410).
2353
2358
 
2354
2359
  WORKFLOW BUILDER
@@ -2360,6 +2365,16 @@ WORKFLOW BUILDER
2360
2365
  Workflows with their ids (no steps); { items, totalCount, offset, top }.
2361
2366
  workflows folders [--name <text>] [--top <n>] [--offset <n>] [--all]
2362
2367
  Workflow folders ({ id, name, workspaceId, environmentId, itemsCount }).
2368
+ workflows get <workflow_id> One workflow with its steps (and webhookUrl for a webhook trigger).
2369
+ workflows revisions <workflow_id> [--created-by <id>] [--created-after|--created-before <iso>]
2370
+ [--sort <spec>] [--top <n>] [--offset <n>]
2371
+ Stored revisions, newest first; { items, totalCount, offset, top }.
2372
+ workflows enable <workflow_id> | workflows disable <workflow_id>
2373
+ Turn it on / off; prints the workflow afterwards.
2374
+ workflows delete <workflow_id> [--force] Soft delete; confirms on a terminal, scripts pass --force.
2375
+ workflows run <workflow_id> [--body <json|@file|->]
2376
+ Start one run now (payload default {}); prints the execution
2377
+ in snake_case. No prompt, no idempotency key.
2363
2378
  workflows search [query] [--kind <k>] [--app <slug>] [--table <id>] [--top <n>]
2364
2379
  workflows schema <slug> [--connection <id>] [--kind <k>] [--table <id>]
2365
2380
  workflows options <slug> [--field <f>] [--connection <id>] [--depends-on <field=value>...]
@@ -2371,6 +2386,8 @@ WORKFLOW BUILDER
2371
2386
  workflows update <workflow_id> [--file <path>|stdin] [--expected-revision-id <n>]
2372
2387
  Note: list/folders print one page of up to 100 unless --all; --folder-id 0 means no folder.
2373
2388
  Note: compile returns a plan with errors (hasErrors: true); create/update refuse it.
2389
+ Note: enable/disable/delete/run/rerun need a workspace-scoped key (403 SCOPE_READ_ONLY -> exit 3);
2390
+ a 409 (not runnable, still running) exits 1 with the server's message.
2374
2391
 
2375
2392
  OUTPUT & EXIT CODES
2376
2393
  Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
@@ -5192,6 +5209,9 @@ function readJsonObject(file, what) {
5192
5209
  file === void 0 || file === "-" ? `Cannot read the ${what} from stdin: ${err.message}` : `Cannot read ${file}: ${err.message}`
5193
5210
  );
5194
5211
  }
5212
+ return parseJsonObject(text, what);
5213
+ }
5214
+ function parseJsonObject(text, what) {
5195
5215
  let data;
5196
5216
  try {
5197
5217
  data = JSON.parse(text);
@@ -5203,6 +5223,25 @@ function readJsonObject(file, what) {
5203
5223
  }
5204
5224
  return data;
5205
5225
  }
5226
+ function readBodyOption(raw, what = "body") {
5227
+ if (raw === void 0) return {};
5228
+ if (raw === "-" || raw.startsWith("@")) {
5229
+ if (raw === "-" && process.stdin.isTTY) {
5230
+ fail(2 /* USAGE */, `Pipe the ${what} on stdin, or pass it inline / with @file.`);
5231
+ }
5232
+ const source = raw === "-" ? 0 : raw.slice(1);
5233
+ try {
5234
+ return parseJsonObject(readFileSync5(source, "utf8"), what);
5235
+ } catch (err) {
5236
+ if (err instanceof CliError) throw err;
5237
+ return fail(
5238
+ 2 /* USAGE */,
5239
+ `Cannot read the ${what} from ${raw === "-" ? "stdin" : source}: ${err.message}`
5240
+ );
5241
+ }
5242
+ }
5243
+ return parseJsonObject(raw, what);
5244
+ }
5206
5245
  var snake = (key) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
5207
5246
  function snakeKeys(value, keep = []) {
5208
5247
  if (Array.isArray(value)) return value.map((v) => snakeKeys(v, keep));
@@ -5256,6 +5295,14 @@ async function getBody12(rawId) {
5256
5295
  const id = parseInt1(rawId, "execution id");
5257
5296
  printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.get(id))));
5258
5297
  }
5298
+ async function rerunBody(rawId) {
5299
+ const id = parseInt1(rawId, "execution id");
5300
+ if (dryRun()) {
5301
+ printOutput({ would_rerun: id });
5302
+ return;
5303
+ }
5304
+ printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.rerun(id))));
5305
+ }
5259
5306
  function terminalSafe(text) {
5260
5307
  return text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ").trim();
5261
5308
  }
@@ -5308,7 +5355,7 @@ async function dataBody(rawId, rawStep, opts) {
5308
5355
  printOutput(snakeKeys(entries, ["value", "additional"]));
5309
5356
  }
5310
5357
  function registerExecutions(program) {
5311
- const executions = program.command("executions").description("Read-only run history: list, inspect, step log and recorded step data.");
5358
+ const executions = program.command("executions").description("Run history: list, inspect, step log and recorded step data; rerun an execution.");
5312
5359
  const list = executions.command("list").description("List executions, newest first. Prints { items, next_cursor, total_count }.").option("--workflow <id>", "Only this workflow / automation / business rule").option("--type <type>", "workflow | automation | businessRule").option("--trigger-type <type>", "instant, scheduled, recordUpdate, api, \u2026").option("--status <status>", "Match a status; repeat to match any of several", collect4).option("--context <text>", "Substring of the caller-supplied context id").option("--created-by <id>", "Account-user id that started the run").option("--created-after <iso>", "Queued at or after").option("--created-before <iso>", "Queued at or before").option("--closed-after <iso>", "Finished at or after").option("--closed-before <iso>", "Finished at or before").option("--sort <spec>", "e.g. 'createdAt desc' (cursor paging needs one createdAt/executionId key)").option("--cursor <cursor>", "next_cursor from a previous page").option("--top <n>", "Page size (server cap 100; default 100)").option("--offset <n>", "Skip n rows (ignored by the server with --cursor)").option("--all", "Drain every page (follows next_cursor); not with --top/--cursor/--offset");
5313
5360
  list.addHelpText(
5314
5361
  "after",
@@ -5324,6 +5371,15 @@ function registerExecutions(program) {
5324
5371
  get.action(async (id, opts, command) => {
5325
5372
  await runCommand(command, opts, false, () => getBody12(id));
5326
5373
  });
5374
+ const rerun = executions.command("rerun").description("Run an execution again. Prints the new execution.").argument("[execution_id]", "Execution id");
5375
+ rerun.addHelpText(
5376
+ "after",
5377
+ "\nExamples:\n engini executions rerun 4567 --json\nNote: runs immediately, without a prompt. A run still in progress, a kind that cannot be re-run, or an account limit is refused (409, exit 1 with the server's message). Needs a workspace-scoped API key. The API has no idempotency key: a retry after a lost answer starts a second run."
5378
+ );
5379
+ addUniversalOptions(rerun, { mutating: true });
5380
+ rerun.action(async (id, opts, command) => {
5381
+ await runCommand(command, opts, true, () => rerunBody(id));
5382
+ });
5327
5383
  const log = executions.command("log").description(
5328
5384
  "The execution's per-step log (step_no, name, status, runs_count, duration, error_message, loop)."
5329
5385
  ).argument("[execution_id]", "Execution id");
@@ -5336,7 +5392,10 @@ function registerExecutions(program) {
5336
5392
  await runCommand(command, opts, false, () => logBody(id));
5337
5393
  });
5338
5394
  const data = executions.command("data").description("Recorded request / response / input / status payloads of one step.").argument("[execution_id]", "Execution id").argument("[step_no]", "Step number from `executions log`").option("--type <kind>", "request | response | input | status").option("--loop-path <step:iteration>", "Loop position, repeat per nesting level, outermost first", collect4).option("--run-number <n>", "Only this run of the step").option("--retry-no <n>", "Only this retry attempt").option("--status <status>", "Only payloads recorded at this step status").option("--top <n>", "One page of at most n entries (server cap 10); default drains every page").option("--offset <n>", "With --top: skip n entries");
5339
- data.addHelpText("after", "\nExamples:\n engini executions data 4567 3 --type response --json");
5395
+ data.addHelpText(
5396
+ "after",
5397
+ "\nExamples:\n engini executions data 4567 3 --type response --json\n engini executions data 4567 3 --type status --json\nduration: status entries only - active seconds of that iteration or retry attempt, set once its\n status is final (absent on request/response/input entries and while running). The step-level\n duration in `executions log` is the cumulative sum over iterations, attempts and runs."
5398
+ );
5340
5399
  addUniversalOptions(data);
5341
5400
  data.action(
5342
5401
  async (id, step2, opts, command) => {
@@ -5467,8 +5526,51 @@ async function listFoldersBody(opts) {
5467
5526
  () => client.folders.listPage({ ...filters, top, offset })
5468
5527
  );
5469
5528
  }
5529
+ async function revisionsBody(rawId, opts) {
5530
+ const workflowId = parseInt1(rawId, "workflow id");
5531
+ const page = await apiErrors(
5532
+ async () => buildClient().workflows.revisions(workflowId, {
5533
+ createdBy: parseOptId(opts.createdBy, "--created-by"),
5534
+ createdAfter: opts.createdAfter,
5535
+ createdBefore: opts.createdBefore,
5536
+ sort: opts.sort,
5537
+ top: parseCount(opts.top, "--top"),
5538
+ offset: parseCount(opts.offset, "--offset")
5539
+ })
5540
+ );
5541
+ printOutput({ items: page.items ?? [], totalCount: page.totalCount ?? null, offset: page.offset ?? null, top: page.top ?? null });
5542
+ }
5543
+ async function setEnabledBody(rawId, enabled) {
5544
+ const workflowId = parseInt1(rawId, "workflow id");
5545
+ if (dryRun()) {
5546
+ printOutput({ [enabled ? "would_enable" : "would_disable"]: workflowId });
5547
+ return;
5548
+ }
5549
+ printOutput(await apiErrors(async () => buildClient().workflows.setEnabled(workflowId, enabled)));
5550
+ }
5551
+ async function deleteBody6(rawId, opts) {
5552
+ const workflowId = parseInt1(rawId, "workflow id");
5553
+ if (dryRun()) {
5554
+ printOutput({ would_delete: workflowId });
5555
+ return;
5556
+ }
5557
+ await confirmOrFail(`Delete workflow ${workflowId}?`, { force: Boolean(opts.force) });
5558
+ await apiErrors(async () => buildClient().workflows.delete(workflowId));
5559
+ printOutput({ deleted: workflowId });
5560
+ }
5561
+ async function runBody(rawId, opts) {
5562
+ const workflowId = parseInt1(rawId, "workflow id");
5563
+ const body = readBodyOption(opts.body);
5564
+ if (dryRun()) {
5565
+ printOutput({ would_run: workflowId, body });
5566
+ return;
5567
+ }
5568
+ printOutput(snakeKeys(await apiErrors(async () => buildClient().workflows.run(workflowId, body))));
5569
+ }
5470
5570
  function registerWorkflows(program) {
5471
- const workflows = program.command("workflows").description("List workflows and folders; build workflows from a plan: catalog lookups, dry-run compile, create, update.");
5571
+ const workflows = program.command("workflows").description(
5572
+ "List, read, enable/disable, delete and run workflows; build workflows from a plan: catalog lookups, dry-run compile, create, update."
5573
+ );
5472
5574
  const list = workflows.command("list").description("List workflows (id, name, type, folder, enabled) - no steps. Prints { items, totalCount, offset, top }.").option("--name <text>", "Case-insensitive substring of the workflow name").option("--folder <name>", "Only this folder, by its exact name (resolved with `workflows folders`)").option("--folder-id <id>", "Only this folder id; 0 = workflows with no folder").option("--top <n>", "Page size (server cap 100; default 100)").option("--offset <n>", "Skip n rows").option("--all", "Drain every page; not with --top/--offset");
5473
5575
  list.addHelpText(
5474
5576
  "after",
@@ -5478,6 +5580,60 @@ function registerWorkflows(program) {
5478
5580
  list.action(async (opts, command) => {
5479
5581
  await runCommand(command, opts, false, () => listWorkflowsBody(opts));
5480
5582
  });
5583
+ const get = workflows.command("get").description("One workflow with its steps (and webhookUrl for a webhook trigger). Prints the API's camelCase JSON.").argument("[workflow_id]", "Workflow id");
5584
+ get.addHelpText(
5585
+ "after",
5586
+ "\nExamples:\n engini workflows get 1234 --json\nNote: step `configuration` is connector-defined and outside the v1 compatibility guarantee. `webhookUrl` carries the trigger's token: treat it like a credential. To edit, read the workflow back as a plan with `workflows plan`."
5587
+ );
5588
+ addUniversalOptions(get);
5589
+ get.action(async (id, opts, command) => {
5590
+ await runCommand(command, opts, false, async () => {
5591
+ const workflowId = parseInt1(id, "workflow id");
5592
+ printOutput(await apiErrors(async () => buildClient().workflows.get(workflowId)));
5593
+ });
5594
+ });
5595
+ const revisions = workflows.command("revisions").description("A workflow's stored revisions, newest first. Prints { items, totalCount, offset, top }.").argument("[workflow_id]", "Workflow id").option("--created-by <id>", "Account-user id that made the change").option("--created-after <iso>", "Recorded at or after").option("--created-before <iso>", "Recorded at or before").option("--sort <spec>", "e.g. 'createdAt asc,revisionId asc' (default: revisionId desc)").option("--top <n>", "Page size (server cap 100; default 100)").option("--offset <n>", "Skip n rows");
5596
+ revisions.addHelpText(
5597
+ "after",
5598
+ "\nExamples:\n engini workflows revisions 1234 --top 10 --json\nNote: one page; page on with --offset. A revisionId is what `update --expected-revision-id` takes. Restoring a revision is not available."
5599
+ );
5600
+ addUniversalOptions(revisions);
5601
+ revisions.action(async (id, opts, command) => {
5602
+ await runCommand(command, opts, false, () => revisionsBody(id, opts));
5603
+ });
5604
+ for (const enabled of [true, false]) {
5605
+ const verb = enabled ? "enable" : "disable";
5606
+ const toggle = workflows.command(verb).description(`Turn a workflow ${enabled ? "on" : "off"}. Prints the workflow as it stands afterwards.`).argument("[workflow_id]", "Workflow id");
5607
+ toggle.addHelpText(
5608
+ "after",
5609
+ `
5610
+ Examples:
5611
+ engini workflows ${verb} 1234
5612
+ Note: needs a workspace-scoped API key (403 SCOPE_READ_ONLY otherwise). A workflow created through the API starts turned off.`
5613
+ );
5614
+ addUniversalOptions(toggle, { mutating: true });
5615
+ toggle.action(async (id, opts, command) => {
5616
+ await runCommand(command, opts, true, () => setEnabledBody(id, enabled));
5617
+ });
5618
+ }
5619
+ const del = workflows.command("delete").description("Delete a workflow (a soft delete; deleting a deleted one succeeds).").argument("[workflow_id]", "Workflow id").option("--force", "Delete without confirming");
5620
+ del.addHelpText(
5621
+ "after",
5622
+ "\nExamples:\n engini workflows delete 1234 --force\nNote: confirms on a terminal; scripts and pipes must pass --force. Needs a workspace-scoped API key."
5623
+ );
5624
+ addUniversalOptions(del, { mutating: true });
5625
+ del.action(async (id, opts, command) => {
5626
+ await runCommand(command, opts, true, () => deleteBody6(id, opts));
5627
+ });
5628
+ const run = workflows.command("run").description("Start one run of a workflow now. Prints the started execution (snake_case, as `executions get`).").argument("[workflow_id]", "Workflow id").option("--body <json|@file|->", "Trigger payload: inline JSON, @path to a file, or - for stdin (default {})");
5629
+ run.addHelpText(
5630
+ "after",
5631
+ '\nExamples:\n engini workflows run 1234\n engini workflows run 1234 --body \'{"email":"a@b.co"}\'\n engini workflows run 1234 --body @payload.json\nNote: runs immediately, without a prompt, even when the workflow is turned off. The API has no idempotency key: a retry after a lost answer starts a second run. Follow it with `engini executions get <execution_id>`.'
5632
+ );
5633
+ addUniversalOptions(run, { mutating: true });
5634
+ run.action(async (id, opts, command) => {
5635
+ await runCommand(command, opts, true, () => runBody(id, opts));
5636
+ });
5481
5637
  const folders = workflows.command("folders").description("List workflow folders ({ id, name, workspaceId, environmentId, itemsCount }). Prints { items, totalCount, offset, top }.").option("--name <text>", "Case-insensitive substring of the folder name").option("--top <n>", "Page size (server cap 100; default 100)").option("--offset <n>", "Skip n rows").option("--all", "Drain every page; not with --top/--offset");
5482
5638
  folders.addHelpText(
5483
5639
  "after",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Engini CLI — machine-first command line over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "test": "vitest run"
27
27
  },
28
28
  "dependencies": {
29
- "@engini/sdk": "^0.33.0",
29
+ "@engini/sdk": "^0.35.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },