@engini/cli 0.29.0 → 0.31.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 +32 -0
- package/dist/cli.js +498 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -45,6 +45,38 @@ 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)
|
|
49
|
+
engini workflows list | folders # find a workflow id / a folder id by name
|
|
50
|
+
engini workflows search | schema | options | tables | columns | connections # builder lookups
|
|
51
|
+
engini workflows compile | plan | create | update # dry-run a plan; create (turned off) / update from it
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`executions list` prints one page as `{ items, next_cursor, total_count }` (keys snake_case);
|
|
55
|
+
`--cursor <next_cursor>` reads the next page and `--all` drains everything. `executions data`
|
|
56
|
+
drains every page of a step's recorded payloads unless `--top` is given (`--offset` needs `--top`).
|
|
57
|
+
Note the difference from `triggers list`: that prints a bare JSON array, while `executions list`
|
|
58
|
+
prints one page as an object (use `--all` to drain, still as the object).
|
|
59
|
+
|
|
60
|
+
`workflows list` and `workflows folders` print one page (up to 100) as
|
|
61
|
+
`{ items, totalCount, offset, top }`; `--all` drains every match as `{ items, totalCount }`
|
|
62
|
+
(not with `--top`/`--offset`). `--name` is a case-insensitive substring match, so it can return
|
|
63
|
+
several rows; compare the name yourself for an exact one. `list` narrows to a folder with
|
|
64
|
+
`--folder <name>` (exact name, resolved through `workflows folders`; an unknown or ambiguous
|
|
65
|
+
name is an error listing the matches) or `--folder-id <id>` (`0` = workflows with no folder).
|
|
66
|
+
`folders` shows workflow folders only. `list` rows carry no steps: read one back with `plan <workflowId>`.
|
|
67
|
+
|
|
68
|
+
The `workflows` group prints the API's own camelCase JSON so `plan <id> > plan.json` feeds
|
|
69
|
+
`update --file plan.json`. `compile`, `create` and `update` read the plan from `--file <path>`
|
|
70
|
+
or stdin; `update` takes `--expected-revision-id` to refuse a stale save. Writes need a
|
|
71
|
+
workspace-scoped API key. A refused plan prints its `code`, message, `fix` and a diagnostics
|
|
72
|
+
table on stderr (a JSON object when piped) and exits 3 (401/403, e.g. `API_KEY_REQUIRED`), 4 (not found) or 5 (400/409/422):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
engini workflows folders --name sales # folder ids (names are unique per workspace + environment)
|
|
76
|
+
engini workflows list --name "lead alert" --folder Sales
|
|
77
|
+
engini workflows compile --file plan.json # dry run: hasErrors + diagnostics
|
|
78
|
+
engini workflows create --file plan.json --folder-id 7
|
|
79
|
+
engini workflows plan 1234 > plan.json && engini workflows update 1234 --file plan.json --expected-revision-id 3
|
|
48
80
|
```
|
|
49
81
|
|
|
50
82
|
The `mcp` group maintains the MCP endpoints Engini **exposes** (not the
|
package/dist/cli.js
CHANGED
|
@@ -285,10 +285,13 @@ function printOutput(obj) {
|
|
|
285
285
|
function progress(message) {
|
|
286
286
|
if (isTty() && !context.quiet) console.error(message);
|
|
287
287
|
}
|
|
288
|
-
function fail(code, message, hint2) {
|
|
288
|
+
function fail(code, message, hint2, extra) {
|
|
289
289
|
if (isTty()) {
|
|
290
290
|
console.error(`Error: ${message}`);
|
|
291
291
|
if (hint2) console.error(`Hint: ${hint2}`);
|
|
292
|
+
if (extra?.diagnostics?.length) {
|
|
293
|
+
for (const line of diagnosticTable(extra.diagnostics)) console.error(line);
|
|
294
|
+
}
|
|
292
295
|
} else {
|
|
293
296
|
const payload = {
|
|
294
297
|
error: ERROR_NAMES[code] ?? "Error",
|
|
@@ -296,10 +299,21 @@ function fail(code, message, hint2) {
|
|
|
296
299
|
exit_code: code
|
|
297
300
|
};
|
|
298
301
|
if (hint2) payload.hint = hint2;
|
|
302
|
+
if (extra?.code !== void 0) payload.code = extra.code;
|
|
303
|
+
if (extra?.path) payload.path = extra.path;
|
|
304
|
+
if (extra?.currentRevisionId != null) payload.current_revision_id = extra.currentRevisionId;
|
|
305
|
+
if (extra?.diagnostics?.length) payload.diagnostics = extra.diagnostics;
|
|
299
306
|
console.error(JSON.stringify(payload));
|
|
300
307
|
}
|
|
301
308
|
throw new CliError(code);
|
|
302
309
|
}
|
|
310
|
+
function diagnosticTable(rows) {
|
|
311
|
+
const header = ["SEVERITY", "CODE", "STEP", "FIELD", "MESSAGE"];
|
|
312
|
+
const body = rows.map((d) => [d.severity, d.code, d.stepKey ?? "-", d.field ?? "-", d.message]);
|
|
313
|
+
const widths = header.map((h, i) => Math.max(h.length, ...body.map((r) => r[i].length)));
|
|
314
|
+
const line = (cells) => cells.map((c, i) => i === cells.length - 1 ? c : c.padEnd(widths[i])).join(" ");
|
|
315
|
+
return [line(header), ...body.map(line)];
|
|
316
|
+
}
|
|
303
317
|
function mapCommanderExitCode(exitCode) {
|
|
304
318
|
const code = exitCode ?? 1;
|
|
305
319
|
return code === 0 ? 0 /* OK */ : 2 /* USAGE */;
|
|
@@ -390,6 +404,7 @@ import {
|
|
|
390
404
|
ENV_COMPANY_TOKEN_VAR,
|
|
391
405
|
ENV_TOKEN_VAR,
|
|
392
406
|
EnginiAuthError,
|
|
407
|
+
EnginiBuilderError,
|
|
393
408
|
EnginiConflictError,
|
|
394
409
|
EnginiError,
|
|
395
410
|
EnginiMcpServerNotFoundError,
|
|
@@ -450,7 +465,7 @@ function saveConfig(config, path = configPath()) {
|
|
|
450
465
|
}
|
|
451
466
|
|
|
452
467
|
// src/version.ts
|
|
453
|
-
var VERSION = true ? "0.
|
|
468
|
+
var VERSION = true ? "0.31.0" : "0.0.0";
|
|
454
469
|
|
|
455
470
|
// src/http.ts
|
|
456
471
|
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
@@ -480,6 +495,14 @@ var AUTH_PROVIDER_CONFLICT_CODES = /* @__PURE__ */ new Set([
|
|
|
480
495
|
]);
|
|
481
496
|
function exitForError(err) {
|
|
482
497
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
498
|
+
if (err instanceof EnginiBuilderError) {
|
|
499
|
+
if (err.status === 401 || err.status === 403) return 3 /* AUTH */;
|
|
500
|
+
if (err.status === 404) return 4 /* NOT_FOUND */;
|
|
501
|
+
if (err.status !== void 0 && err.status >= 400 && err.status < 500 && err.status !== 429) {
|
|
502
|
+
return 5 /* VALIDATION */;
|
|
503
|
+
}
|
|
504
|
+
return 1 /* GENERIC */;
|
|
505
|
+
}
|
|
483
506
|
if (err instanceof EnginiOpaApplicationAmbiguousError) return 5 /* VALIDATION */;
|
|
484
507
|
if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
|
|
485
508
|
if (err instanceof EnginiConflictError && err.errorCode !== void 0 && AUTH_PROVIDER_CONFLICT_CODES.has(err.errorCode)) {
|
|
@@ -497,6 +520,14 @@ async function apiErrors(fn) {
|
|
|
497
520
|
try {
|
|
498
521
|
return await fn();
|
|
499
522
|
} catch (err) {
|
|
523
|
+
if (err instanceof EnginiBuilderError) {
|
|
524
|
+
fail(exitForError(err), err.message, err.fix ?? void 0, {
|
|
525
|
+
code: err.code,
|
|
526
|
+
path: err.path,
|
|
527
|
+
currentRevisionId: err.currentRevisionId,
|
|
528
|
+
diagnostics: err.diagnostics
|
|
529
|
+
});
|
|
530
|
+
}
|
|
500
531
|
if (err instanceof EnginiError) {
|
|
501
532
|
fail(exitForError(err), err.message);
|
|
502
533
|
}
|
|
@@ -2307,6 +2338,40 @@ TRIGGERS
|
|
|
2307
2338
|
triggers destinations rotate-secret <name> [--force]
|
|
2308
2339
|
Note: add/rotate-secret/set(create) print the signing secret in the clear, once.
|
|
2309
2340
|
|
|
2341
|
+
EXECUTIONS
|
|
2342
|
+
Read-only run history of workflows, table automations and business rules (no rerun).
|
|
2343
|
+
executions list [--workflow <id>] [--type <t>] [--trigger-type <t>] [--status <s>...]
|
|
2344
|
+
[--context <text>] [--created-by <id>] [--created-after|--created-before <iso>]
|
|
2345
|
+
[--closed-after|--closed-before <iso>] [--sort <spec>] [--cursor <c>] [--top <n>] [--all]
|
|
2346
|
+
One page -> { items, next_cursor, total_count }; --all drains.
|
|
2347
|
+
executions get <execution_id> Status, timing, activities run, who started it.
|
|
2348
|
+
executions log <execution_id> Per-step log (step_no, status, runs_count, duration, loop).
|
|
2349
|
+
executions data <execution_id> <step_no> [--type <kind>] [--loop-path <s:i>...] [--run-number <n>]
|
|
2350
|
+
[--retry-no <n>] [--status <s>] [--top <n>] [--offset <n>]
|
|
2351
|
+
Recorded step payloads; drains every page unless --top.
|
|
2352
|
+
Note: step detail is deleted after the workflow's history retention window (410).
|
|
2353
|
+
|
|
2354
|
+
WORKFLOW BUILDER
|
|
2355
|
+
Build a workflow from a plan (JSON). Output is the API's own camelCase JSON, so
|
|
2356
|
+
'plan <id> > p.json' feeds 'update'. Writes need a workspace-scoped API key; workflows
|
|
2357
|
+
are always created turned off. A refused plan prints code, message, fix and a
|
|
2358
|
+
diagnostics table on stderr and exits non-zero (404 -> 4; 400/409/422 -> 5).
|
|
2359
|
+
workflows list [--name <text>] [--folder <name>|--folder-id <id>] [--top <n>] [--offset <n>] [--all]
|
|
2360
|
+
Workflows with their ids (no steps); { items, totalCount, offset, top }.
|
|
2361
|
+
workflows folders [--name <text>] [--top <n>] [--offset <n>] [--all]
|
|
2362
|
+
Workflow folders ({ id, name, workspaceId, environmentId, itemsCount }).
|
|
2363
|
+
workflows search [query] [--kind <k>] [--app <slug>] [--table <id>] [--top <n>]
|
|
2364
|
+
workflows schema <slug> [--connection <id>] [--kind <k>] [--table <id>]
|
|
2365
|
+
workflows options <slug> [--field <f>] [--connection <id>] [--depends-on <field=value>...]
|
|
2366
|
+
workflows tables | workflows columns <table_id> [--trigger <slug>]
|
|
2367
|
+
workflows connections [--app <slug>]
|
|
2368
|
+
workflows compile [--file <path>|stdin] [--base-workflow-id <id>] Dry run; nothing written.
|
|
2369
|
+
workflows plan <workflow_id> A saved workflow read back as a plan.
|
|
2370
|
+
workflows create [--file <path>|stdin] [--folder-id <id>] Created turned off.
|
|
2371
|
+
workflows update <workflow_id> [--file <path>|stdin] [--expected-revision-id <n>]
|
|
2372
|
+
Note: list/folders print one page of up to 100 unless --all; --folder-id 0 means no folder.
|
|
2373
|
+
Note: compile returns a plan with errors (hasErrors: true); create/update refuse it.
|
|
2374
|
+
|
|
2310
2375
|
OUTPUT & EXIT CODES
|
|
2311
2376
|
Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
|
|
2312
2377
|
JSON with --json. Universal flags on every command:
|
|
@@ -5094,6 +5159,433 @@ function registerTriggers(program) {
|
|
|
5094
5159
|
registerTriggerDestinations(triggers);
|
|
5095
5160
|
}
|
|
5096
5161
|
|
|
5162
|
+
// src/shared/input.ts
|
|
5163
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
5164
|
+
function parseInt1(raw, what) {
|
|
5165
|
+
if (raw === void 0 || raw === "") fail(2 /* USAGE */, `${what} is required.`);
|
|
5166
|
+
if (!/^\d+$/.test(raw) || Number(raw) < 1) {
|
|
5167
|
+
fail(2 /* USAGE */, `'${raw}' is not a valid ${what} (expected a positive integer).`);
|
|
5168
|
+
}
|
|
5169
|
+
return Number(raw);
|
|
5170
|
+
}
|
|
5171
|
+
function parseCount(raw, flag) {
|
|
5172
|
+
if (raw === void 0) return void 0;
|
|
5173
|
+
if (!/^\d+$/.test(raw)) fail(2 /* USAGE */, `${flag} must be a non-negative integer, got '${raw}'.`);
|
|
5174
|
+
return Number(raw);
|
|
5175
|
+
}
|
|
5176
|
+
function parseOptId(raw, flag) {
|
|
5177
|
+
return raw === void 0 ? void 0 : parseInt1(raw, flag);
|
|
5178
|
+
}
|
|
5179
|
+
function collect4(value, previous = []) {
|
|
5180
|
+
return [...previous, value];
|
|
5181
|
+
}
|
|
5182
|
+
function readJsonObject(file, what) {
|
|
5183
|
+
let text;
|
|
5184
|
+
if (file === void 0 && process.stdin.isTTY) {
|
|
5185
|
+
fail(2 /* USAGE */, `Pass the ${what} with --file <path>, or pipe it on stdin.`);
|
|
5186
|
+
}
|
|
5187
|
+
try {
|
|
5188
|
+
text = readFileSync5(file === void 0 || file === "-" ? 0 : file, "utf8");
|
|
5189
|
+
} catch (err) {
|
|
5190
|
+
return fail(
|
|
5191
|
+
2 /* USAGE */,
|
|
5192
|
+
file === void 0 || file === "-" ? `Cannot read the ${what} from stdin: ${err.message}` : `Cannot read ${file}: ${err.message}`
|
|
5193
|
+
);
|
|
5194
|
+
}
|
|
5195
|
+
let data;
|
|
5196
|
+
try {
|
|
5197
|
+
data = JSON.parse(text);
|
|
5198
|
+
} catch (err) {
|
|
5199
|
+
return fail(2 /* USAGE */, `The ${what} is not valid JSON: ${err.message}`);
|
|
5200
|
+
}
|
|
5201
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
5202
|
+
return fail(2 /* USAGE */, `The ${what} must be a JSON object.`);
|
|
5203
|
+
}
|
|
5204
|
+
return data;
|
|
5205
|
+
}
|
|
5206
|
+
var snake = (key) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
5207
|
+
function snakeKeys(value, keep = []) {
|
|
5208
|
+
if (Array.isArray(value)) return value.map((v) => snakeKeys(v, keep));
|
|
5209
|
+
if (value === null || typeof value !== "object") return value;
|
|
5210
|
+
const out = {};
|
|
5211
|
+
for (const [k, v] of Object.entries(value)) {
|
|
5212
|
+
out[snake(k)] = keep.includes(k) ? v : snakeKeys(v, keep);
|
|
5213
|
+
}
|
|
5214
|
+
return out;
|
|
5215
|
+
}
|
|
5216
|
+
|
|
5217
|
+
// src/executions/index.ts
|
|
5218
|
+
async function listBody14(opts) {
|
|
5219
|
+
const top = parseCount(opts.top, "--top");
|
|
5220
|
+
const offset = parseCount(opts.offset, "--offset");
|
|
5221
|
+
if (opts.all && (top !== void 0 || opts.cursor !== void 0 || offset !== void 0)) {
|
|
5222
|
+
fail(2 /* USAGE */, "--all drains every page; it cannot be combined with --top, --cursor or --offset.");
|
|
5223
|
+
}
|
|
5224
|
+
if (opts.cursor !== void 0 && offset !== void 0) {
|
|
5225
|
+
fail(2 /* USAGE */, "--cursor and --offset are alternatives; the server ignores --offset with a cursor.");
|
|
5226
|
+
}
|
|
5227
|
+
const filters = {
|
|
5228
|
+
workflowId: parseOptId(opts.workflow, "--workflow"),
|
|
5229
|
+
type: opts.type,
|
|
5230
|
+
triggerType: opts.triggerType,
|
|
5231
|
+
status: opts.status,
|
|
5232
|
+
context: opts.context,
|
|
5233
|
+
createdBy: parseOptId(opts.createdBy, "--created-by"),
|
|
5234
|
+
createdAfter: opts.createdAfter,
|
|
5235
|
+
createdBefore: opts.createdBefore,
|
|
5236
|
+
closedAfter: opts.closedAfter,
|
|
5237
|
+
closedBefore: opts.closedBefore,
|
|
5238
|
+
sort: opts.sort
|
|
5239
|
+
};
|
|
5240
|
+
const client = buildClient();
|
|
5241
|
+
if (opts.all) {
|
|
5242
|
+
const items = await apiErrors(async () => client.executions.list(filters));
|
|
5243
|
+
printOutput({ items: snakeKeys(items), next_cursor: null, total_count: items.length });
|
|
5244
|
+
return;
|
|
5245
|
+
}
|
|
5246
|
+
const page = await apiErrors(
|
|
5247
|
+
async () => client.executions.listPage({ ...filters, top, cursor: opts.cursor, offset })
|
|
5248
|
+
);
|
|
5249
|
+
printOutput({
|
|
5250
|
+
items: snakeKeys(page.items ?? []),
|
|
5251
|
+
next_cursor: page.nextCursor ?? null,
|
|
5252
|
+
total_count: page.totalCount ?? null
|
|
5253
|
+
});
|
|
5254
|
+
}
|
|
5255
|
+
async function getBody12(rawId) {
|
|
5256
|
+
const id = parseInt1(rawId, "execution id");
|
|
5257
|
+
printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.get(id))));
|
|
5258
|
+
}
|
|
5259
|
+
async function logBody(rawId) {
|
|
5260
|
+
const id = parseInt1(rawId, "execution id");
|
|
5261
|
+
printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.log(id))));
|
|
5262
|
+
}
|
|
5263
|
+
async function dataBody(rawId, rawStep, opts) {
|
|
5264
|
+
const id = parseInt1(rawId, "execution id");
|
|
5265
|
+
const step2 = parseInt1(rawStep, "step number");
|
|
5266
|
+
if (opts.offset !== void 0 && opts.top === void 0) {
|
|
5267
|
+
fail(2 /* USAGE */, "--offset needs --top: without --top every page is drained from the start.");
|
|
5268
|
+
}
|
|
5269
|
+
const entries = await apiErrors(
|
|
5270
|
+
async () => buildClient().executions.data(id, step2, {
|
|
5271
|
+
type: opts.type,
|
|
5272
|
+
loopPath: opts.loopPath,
|
|
5273
|
+
runNumber: parseCount(opts.runNumber, "--run-number"),
|
|
5274
|
+
retryNo: parseCount(opts.retryNo, "--retry-no"),
|
|
5275
|
+
status: opts.status,
|
|
5276
|
+
top: parseCount(opts.top, "--top"),
|
|
5277
|
+
offset: parseCount(opts.offset, "--offset")
|
|
5278
|
+
})
|
|
5279
|
+
);
|
|
5280
|
+
printOutput(snakeKeys(entries, ["value", "additional"]));
|
|
5281
|
+
}
|
|
5282
|
+
function registerExecutions(program) {
|
|
5283
|
+
const executions = program.command("executions").description("Read-only run history: list, inspect, step log and recorded step data.");
|
|
5284
|
+
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");
|
|
5285
|
+
list.addHelpText(
|
|
5286
|
+
"after",
|
|
5287
|
+
"\nExamples:\n engini executions list --workflow 123 --status failed --top 20\n engini executions list --cursor <next_cursor> --top 20\n engini executions list --created-after 2026-11-01T00:00:00Z --all --json\nNote: one page by default; pass --all to read everything that matches."
|
|
5288
|
+
);
|
|
5289
|
+
addUniversalOptions(list);
|
|
5290
|
+
list.action(async (opts, command) => {
|
|
5291
|
+
await runCommand(command, opts, false, () => listBody14(opts));
|
|
5292
|
+
});
|
|
5293
|
+
const get = executions.command("get").description("One execution: status, timing, activities run, who started it.").argument("[execution_id]", "Execution id");
|
|
5294
|
+
get.addHelpText("after", "\nExamples:\n engini executions get 4567 --json");
|
|
5295
|
+
addUniversalOptions(get);
|
|
5296
|
+
get.action(async (id, opts, command) => {
|
|
5297
|
+
await runCommand(command, opts, false, () => getBody12(id));
|
|
5298
|
+
});
|
|
5299
|
+
const log = executions.command("log").description("The execution's per-step log (step_no, status, runs_count, duration, loop).").argument("[execution_id]", "Execution id");
|
|
5300
|
+
log.addHelpText(
|
|
5301
|
+
"after",
|
|
5302
|
+
"\nExamples:\n engini executions log 4567\nNote: step detail is deleted after the workflow's history retention window (410); the execution stays listed."
|
|
5303
|
+
);
|
|
5304
|
+
addUniversalOptions(log);
|
|
5305
|
+
log.action(async (id, opts, command) => {
|
|
5306
|
+
await runCommand(command, opts, false, () => logBody(id));
|
|
5307
|
+
});
|
|
5308
|
+
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");
|
|
5309
|
+
data.addHelpText("after", "\nExamples:\n engini executions data 4567 3 --type response --json");
|
|
5310
|
+
addUniversalOptions(data);
|
|
5311
|
+
data.action(
|
|
5312
|
+
async (id, step2, opts, command) => {
|
|
5313
|
+
await runCommand(command, opts, false, () => dataBody(id, step2, opts));
|
|
5314
|
+
}
|
|
5315
|
+
);
|
|
5316
|
+
}
|
|
5317
|
+
|
|
5318
|
+
// src/workflows/index.ts
|
|
5319
|
+
var PLAN_HELP = "Plan JSON: --file <path>, --file -, or piped stdin. A bare WorkflowPlan ({name, trigger, steps, \u2026}) \u2014 the same shape `engini workflows plan <id>` prints.";
|
|
5320
|
+
function fileOption(cmd) {
|
|
5321
|
+
return cmd.option("--file <path>", "Plan JSON file ('-' or omit to read stdin)");
|
|
5322
|
+
}
|
|
5323
|
+
async function searchBody(query, opts) {
|
|
5324
|
+
const hits = await apiErrors(
|
|
5325
|
+
async () => buildClient().workflows.searchCatalog({
|
|
5326
|
+
q: query,
|
|
5327
|
+
kind: opts.kind,
|
|
5328
|
+
app: opts.app,
|
|
5329
|
+
top: parseCount(opts.top, "--top"),
|
|
5330
|
+
table: opts.table
|
|
5331
|
+
})
|
|
5332
|
+
);
|
|
5333
|
+
printOutput(hits);
|
|
5334
|
+
}
|
|
5335
|
+
async function schemaBody(slug, opts) {
|
|
5336
|
+
if (!slug) fail(2 /* USAGE */, "A catalog slug is required.");
|
|
5337
|
+
const schema = await apiErrors(
|
|
5338
|
+
async () => buildClient().workflows.getSchema(slug, {
|
|
5339
|
+
connectionId: parseOptId(opts.connection, "--connection"),
|
|
5340
|
+
kind: opts.kind,
|
|
5341
|
+
table: opts.table
|
|
5342
|
+
})
|
|
5343
|
+
);
|
|
5344
|
+
printOutput(schema);
|
|
5345
|
+
}
|
|
5346
|
+
function parseDependsOn(pairs) {
|
|
5347
|
+
if (pairs === void 0) return void 0;
|
|
5348
|
+
const out = {};
|
|
5349
|
+
for (const pair of pairs) {
|
|
5350
|
+
const eq = pair.indexOf("=");
|
|
5351
|
+
if (eq <= 0) fail(2 /* USAGE */, `--depends-on must be field=value, got '${pair}'.`);
|
|
5352
|
+
out[pair.slice(0, eq)] = pair.slice(eq + 1);
|
|
5353
|
+
}
|
|
5354
|
+
return out;
|
|
5355
|
+
}
|
|
5356
|
+
async function optionsBody(slug, opts) {
|
|
5357
|
+
if (!slug) fail(2 /* USAGE */, "A catalog slug is required.");
|
|
5358
|
+
const items = await apiErrors(
|
|
5359
|
+
async () => buildClient().workflows.getOptions(slug, {
|
|
5360
|
+
field: opts.field,
|
|
5361
|
+
connectionId: parseOptId(opts.connection, "--connection"),
|
|
5362
|
+
kind: opts.kind,
|
|
5363
|
+
dependsOn: parseDependsOn(opts.dependsOn)
|
|
5364
|
+
})
|
|
5365
|
+
);
|
|
5366
|
+
printOutput(items);
|
|
5367
|
+
}
|
|
5368
|
+
function pagingOptions(opts) {
|
|
5369
|
+
const top = parseCount(opts.top, "--top");
|
|
5370
|
+
const offset = parseCount(opts.offset, "--offset");
|
|
5371
|
+
if (opts.all && (top !== void 0 || offset !== void 0)) {
|
|
5372
|
+
fail(2 /* USAGE */, "--all drains every page; it cannot be combined with --top or --offset.");
|
|
5373
|
+
}
|
|
5374
|
+
return { top, offset };
|
|
5375
|
+
}
|
|
5376
|
+
async function printList(all, drain, page) {
|
|
5377
|
+
if (all) {
|
|
5378
|
+
const items = await apiErrors(drain);
|
|
5379
|
+
printOutput({ items, totalCount: items.length });
|
|
5380
|
+
return;
|
|
5381
|
+
}
|
|
5382
|
+
const p = await apiErrors(page);
|
|
5383
|
+
printOutput({ items: p.items ?? [], totalCount: p.totalCount ?? null, offset: p.offset ?? null, top: p.top ?? null });
|
|
5384
|
+
}
|
|
5385
|
+
async function resolveFolderId(client, rawName) {
|
|
5386
|
+
const name = rawName.trim();
|
|
5387
|
+
if (!name) fail(2 /* USAGE */, "--folder needs a folder name; list them with 'engini workflows folders'.");
|
|
5388
|
+
const found = await apiErrors(async () => client.folders.list({ name }));
|
|
5389
|
+
let exact = found.filter((f) => f.name === name);
|
|
5390
|
+
if (exact.length === 0) exact = found.filter((f) => f.name?.toLowerCase() === name.toLowerCase());
|
|
5391
|
+
if (exact.length === 1) {
|
|
5392
|
+
const id = Number(exact[0].id);
|
|
5393
|
+
if (!Number.isInteger(id)) fail(1 /* GENERIC */, `Folder '${name}' has a non-numeric id '${exact[0].id}'.`);
|
|
5394
|
+
return id;
|
|
5395
|
+
}
|
|
5396
|
+
const describe = (list) => list.map((f) => ` id ${f.id} '${f.name}' workspace ${f.workspaceId} environment ${f.environmentId}`).join("\n");
|
|
5397
|
+
if (exact.length > 1) {
|
|
5398
|
+
return fail(
|
|
5399
|
+
2 /* USAGE */,
|
|
5400
|
+
`${exact.length} folders are named '${name}' (names are unique only per workspace and environment). Pass --folder-id:
|
|
5401
|
+
${describe(exact)}`
|
|
5402
|
+
);
|
|
5403
|
+
}
|
|
5404
|
+
return fail(
|
|
5405
|
+
4 /* NOT_FOUND */,
|
|
5406
|
+
found.length === 0 ? `No folder is named '${name}'. List them with 'engini workflows folders'.` : `No folder is named exactly '${name}'. Similar names (pass --folder-id):
|
|
5407
|
+
${describe(found)}`
|
|
5408
|
+
);
|
|
5409
|
+
}
|
|
5410
|
+
async function listWorkflowsBody(opts) {
|
|
5411
|
+
const { top, offset } = pagingOptions(opts);
|
|
5412
|
+
if (opts.folder !== void 0 && opts.folderId !== void 0) {
|
|
5413
|
+
fail(2 /* USAGE */, "--folder and --folder-id are alternatives; pass one.");
|
|
5414
|
+
}
|
|
5415
|
+
const explicitFolderId = parseCount(opts.folderId, "--folder-id");
|
|
5416
|
+
const client = buildClient();
|
|
5417
|
+
const folderId = opts.folder !== void 0 ? await resolveFolderId(client, opts.folder) : explicitFolderId;
|
|
5418
|
+
const filters = { name: opts.name, folderId };
|
|
5419
|
+
await printList(
|
|
5420
|
+
opts.all,
|
|
5421
|
+
() => client.workflows.list(filters),
|
|
5422
|
+
() => client.workflows.listPage({ ...filters, top, offset })
|
|
5423
|
+
);
|
|
5424
|
+
}
|
|
5425
|
+
async function listFoldersBody(opts) {
|
|
5426
|
+
const { top, offset } = pagingOptions(opts);
|
|
5427
|
+
const client = buildClient();
|
|
5428
|
+
const filters = { name: opts.name };
|
|
5429
|
+
await printList(
|
|
5430
|
+
opts.all,
|
|
5431
|
+
() => client.folders.list(filters),
|
|
5432
|
+
() => client.folders.listPage({ ...filters, top, offset })
|
|
5433
|
+
);
|
|
5434
|
+
}
|
|
5435
|
+
function registerWorkflows(program) {
|
|
5436
|
+
const workflows = program.command("workflows").description("List workflows and folders; build workflows from a plan: catalog lookups, dry-run compile, create, update.");
|
|
5437
|
+
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");
|
|
5438
|
+
list.addHelpText(
|
|
5439
|
+
"after",
|
|
5440
|
+
"\nExamples:\n engini workflows list --name 'lead alert'\n engini workflows list --folder Sales --all --json\nNote: one page of up to 100 by default; pass --all to read everything. Read one back as a plan with `workflows plan <workflowId>`."
|
|
5441
|
+
);
|
|
5442
|
+
addUniversalOptions(list);
|
|
5443
|
+
list.action(async (opts, command) => {
|
|
5444
|
+
await runCommand(command, opts, false, () => listWorkflowsBody(opts));
|
|
5445
|
+
});
|
|
5446
|
+
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");
|
|
5447
|
+
folders.addHelpText(
|
|
5448
|
+
"after",
|
|
5449
|
+
"\nExamples:\n engini workflows folders --name sales\nNote: folder names are unique only per workspace and environment; use the id with `workflows list --folder-id` or `workflows create --folder-id`."
|
|
5450
|
+
);
|
|
5451
|
+
addUniversalOptions(folders);
|
|
5452
|
+
folders.action(async (opts, command) => {
|
|
5453
|
+
await runCommand(command, opts, false, () => listFoldersBody(opts));
|
|
5454
|
+
});
|
|
5455
|
+
const search = workflows.command("search").description("Search the catalog of actions, triggers and blocks a plan step can name.").argument("[query]", "Free-text query").option("--kind <kind>", "action | trigger | block").option("--app <slug>", "Narrow to one application").option("--table <id>", "Narrow to a table's trigger / actions").option("--top <n>", "Maximum hits");
|
|
5456
|
+
search.addHelpText("after", "\nExamples:\n engini workflows search 'post message' --app slack --kind action");
|
|
5457
|
+
addUniversalOptions(search);
|
|
5458
|
+
search.action(async (q, opts, command) => {
|
|
5459
|
+
await runCommand(command, opts, false, () => searchBody(q, opts));
|
|
5460
|
+
});
|
|
5461
|
+
const schema = workflows.command("schema").description("Input/output schema of one catalog entry (the slug from `search`).").argument("[slug]", "Catalog slug, e.g. slack.post_message").option("--connection <id>", "Resolve dynamic fields against this connection").option("--kind <kind>", "action | trigger | block").option("--table <id>", "Table the entry is used on");
|
|
5462
|
+
addUniversalOptions(schema);
|
|
5463
|
+
schema.action(async (slug, opts, command) => {
|
|
5464
|
+
await runCommand(command, opts, false, () => schemaBody(slug, opts));
|
|
5465
|
+
});
|
|
5466
|
+
const options = workflows.command("options").description("Dropdown values ({id, label}) for one field of a catalog entry.").argument("[slug]", "Catalog slug").option("--field <name>", "The field to list values for").option("--connection <id>", "Connection to read the values through").option("--kind <kind>", "action | trigger | block").option("--depends-on <field=value>", "Value of a parent field; repeatable", collect4);
|
|
5467
|
+
options.addHelpText(
|
|
5468
|
+
"after",
|
|
5469
|
+
"\nExamples:\n engini workflows options slack.post_message --field channel --connection 42"
|
|
5470
|
+
);
|
|
5471
|
+
addUniversalOptions(options);
|
|
5472
|
+
options.action(
|
|
5473
|
+
async (slug, opts, command) => {
|
|
5474
|
+
await runCommand(command, opts, false, () => optionsBody(slug, opts));
|
|
5475
|
+
}
|
|
5476
|
+
);
|
|
5477
|
+
const tables = workflows.command("tables").description("The caller's tables ({id, name}).");
|
|
5478
|
+
addUniversalOptions(tables);
|
|
5479
|
+
tables.action(async (opts, command) => {
|
|
5480
|
+
await runCommand(command, opts, false, async () => {
|
|
5481
|
+
printOutput(await apiErrors(async () => buildClient().workflows.listTables()));
|
|
5482
|
+
});
|
|
5483
|
+
});
|
|
5484
|
+
const columns = workflows.command("columns").description("A table's columns, as a table automation reads them.").argument("[table_id]", "Table id from `workflows tables`").option("--trigger <slug>", "The automation's Tables trigger slug, e.g. tables.Tableonrecordupdated");
|
|
5485
|
+
addUniversalOptions(columns);
|
|
5486
|
+
columns.action(async (tableId, opts, command) => {
|
|
5487
|
+
await runCommand(command, opts, false, async () => {
|
|
5488
|
+
if (!tableId) fail(2 /* USAGE */, "A table id is required.");
|
|
5489
|
+
printOutput(
|
|
5490
|
+
await apiErrors(async () => buildClient().workflows.listTableColumns(tableId, { trigger: opts.trigger }))
|
|
5491
|
+
);
|
|
5492
|
+
});
|
|
5493
|
+
});
|
|
5494
|
+
const connections = workflows.command("connections").description("Connections a plan step may bind to.").option("--app <slug>", "Narrow to one application");
|
|
5495
|
+
addUniversalOptions(connections);
|
|
5496
|
+
connections.action(async (opts, command) => {
|
|
5497
|
+
await runCommand(command, opts, false, async () => {
|
|
5498
|
+
printOutput(await apiErrors(async () => buildClient().workflows.listConnections({ app: opts.app })));
|
|
5499
|
+
});
|
|
5500
|
+
});
|
|
5501
|
+
const compile = workflows.command("compile").description("Dry-run a plan: nothing is written. Prints the compiled workflow with its diagnostics and hasErrors.").option("--base-workflow-id <id>", "Compile the plan as an edit of this saved workflow");
|
|
5502
|
+
fileOption(compile);
|
|
5503
|
+
compile.addHelpText(
|
|
5504
|
+
"after",
|
|
5505
|
+
`
|
|
5506
|
+
${PLAN_HELP}
|
|
5507
|
+
Examples:
|
|
5508
|
+
engini workflows compile --file plan.json
|
|
5509
|
+
cat plan.json | engini workflows compile --json
|
|
5510
|
+
Note: a plan with errors is printed (hasErrors: true), not failed; create/update refuse it.`
|
|
5511
|
+
);
|
|
5512
|
+
addUniversalOptions(compile);
|
|
5513
|
+
compile.action(
|
|
5514
|
+
async (opts, command) => {
|
|
5515
|
+
await runCommand(command, opts, false, async () => {
|
|
5516
|
+
const baseWorkflowId = parseOptId(opts.baseWorkflowId, "--base-workflow-id");
|
|
5517
|
+
const plan2 = readJsonObject(opts.file, "plan");
|
|
5518
|
+
printOutput(await apiErrors(async () => buildClient().workflows.compile({ plan: plan2, baseWorkflowId })));
|
|
5519
|
+
});
|
|
5520
|
+
}
|
|
5521
|
+
);
|
|
5522
|
+
const plan = workflows.command("plan").description("A saved workflow read back as a plan (the input to `update`).").argument("[workflow_id]", "Workflow id");
|
|
5523
|
+
plan.addHelpText("after", "\nExamples:\n engini workflows plan 1234 > plan.json");
|
|
5524
|
+
addUniversalOptions(plan);
|
|
5525
|
+
plan.action(async (id, opts, command) => {
|
|
5526
|
+
await runCommand(command, opts, false, async () => {
|
|
5527
|
+
const workflowId = parseInt1(id, "workflow id");
|
|
5528
|
+
printOutput(await apiErrors(async () => buildClient().workflows.getPlan(workflowId)));
|
|
5529
|
+
});
|
|
5530
|
+
});
|
|
5531
|
+
const create = workflows.command("create").description("Create a workflow from a plan. It is created turned off.").option("--folder-id <id>", "Folder to put the workflow in");
|
|
5532
|
+
fileOption(create);
|
|
5533
|
+
create.addHelpText(
|
|
5534
|
+
"after",
|
|
5535
|
+
`
|
|
5536
|
+
${PLAN_HELP}
|
|
5537
|
+
Examples:
|
|
5538
|
+
engini workflows create --file plan.json --folder-id 7
|
|
5539
|
+
Note: needs a workspace-scoped API key (SCOPE_REQUIRED otherwise). Run \`compile\` first.`
|
|
5540
|
+
);
|
|
5541
|
+
addUniversalOptions(create, { mutating: true });
|
|
5542
|
+
create.action(
|
|
5543
|
+
async (opts, command) => {
|
|
5544
|
+
await runCommand(command, opts, true, async () => {
|
|
5545
|
+
const folderId = parseOptId(opts.folderId, "--folder-id");
|
|
5546
|
+
const body = readJsonObject(opts.file, "plan");
|
|
5547
|
+
if (dryRun()) {
|
|
5548
|
+
printOutput({ would_create: { name: body.name ?? null, folder_id: folderId ?? null } });
|
|
5549
|
+
return;
|
|
5550
|
+
}
|
|
5551
|
+
printOutput(
|
|
5552
|
+
await apiErrors(async () => buildClient().workflows.create({ plan: body, folderId }))
|
|
5553
|
+
);
|
|
5554
|
+
});
|
|
5555
|
+
}
|
|
5556
|
+
);
|
|
5557
|
+
const update = workflows.command("update").description("Replace a turned-off workflow's contents from a plan.").argument("[workflow_id]", "Workflow id").option("--expected-revision-id <n>", "Refuse (REVISION_CONFLICT) if the workflow was saved since this revision");
|
|
5558
|
+
fileOption(update);
|
|
5559
|
+
update.addHelpText(
|
|
5560
|
+
"after",
|
|
5561
|
+
`
|
|
5562
|
+
${PLAN_HELP}
|
|
5563
|
+
Examples:
|
|
5564
|
+
engini workflows plan 1234 > plan.json # edit plan.json
|
|
5565
|
+
engini workflows update 1234 --file plan.json --expected-revision-id 3
|
|
5566
|
+
Note: a turned-on workflow is refused (WORKFLOW_ACTIVE); turn it off in the designer first.`
|
|
5567
|
+
);
|
|
5568
|
+
addUniversalOptions(update, { mutating: true });
|
|
5569
|
+
update.action(
|
|
5570
|
+
async (id, opts, command) => {
|
|
5571
|
+
await runCommand(command, opts, true, async () => {
|
|
5572
|
+
const workflowId = parseInt1(id, "workflow id");
|
|
5573
|
+
const expectedRevisionId = parseOptId(opts.expectedRevisionId, "--expected-revision-id");
|
|
5574
|
+
const body = readJsonObject(opts.file, "plan");
|
|
5575
|
+
if (dryRun()) {
|
|
5576
|
+
printOutput({ would_update: workflowId, expected_revision_id: expectedRevisionId ?? null });
|
|
5577
|
+
return;
|
|
5578
|
+
}
|
|
5579
|
+
printOutput(
|
|
5580
|
+
await apiErrors(
|
|
5581
|
+
async () => buildClient().workflows.update(workflowId, { plan: body, expectedRevisionId })
|
|
5582
|
+
)
|
|
5583
|
+
);
|
|
5584
|
+
});
|
|
5585
|
+
}
|
|
5586
|
+
);
|
|
5587
|
+
}
|
|
5588
|
+
|
|
5097
5589
|
// src/whoami.ts
|
|
5098
5590
|
function summary5(me) {
|
|
5099
5591
|
const ws = me.workspace;
|
|
@@ -5143,12 +5635,14 @@ function buildProgram() {
|
|
|
5143
5635
|
registerMcp(program);
|
|
5144
5636
|
registerOpa(program);
|
|
5145
5637
|
registerTriggers(program);
|
|
5638
|
+
registerExecutions(program);
|
|
5639
|
+
registerWorkflows(program);
|
|
5146
5640
|
installHelp(program);
|
|
5147
5641
|
return program;
|
|
5148
5642
|
}
|
|
5149
5643
|
|
|
5150
5644
|
// src/update-notice.ts
|
|
5151
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
5645
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
5152
5646
|
import { dirname as dirname2, join as join3 } from "path";
|
|
5153
5647
|
var REGISTRY_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40engini%2Fcli/dist-tags";
|
|
5154
5648
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -5159,7 +5653,7 @@ function defaultCachePath() {
|
|
|
5159
5653
|
}
|
|
5160
5654
|
function readCache(path) {
|
|
5161
5655
|
try {
|
|
5162
|
-
const data = JSON.parse(
|
|
5656
|
+
const data = JSON.parse(readFileSync6(path, "utf8"));
|
|
5163
5657
|
if (typeof data.checked_at === "number" && typeof data.channel === "string" && (data.latest_version === null || typeof data.latest_version === "string")) {
|
|
5164
5658
|
return data;
|
|
5165
5659
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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.
|
|
29
|
+
"@engini/sdk": "^0.31.0",
|
|
30
30
|
"commander": "^12.1.0",
|
|
31
31
|
"smol-toml": "^1.3.0"
|
|
32
32
|
},
|