@engini/cli 0.18.0 → 0.20.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 -0
  2. package/dist/cli.js +1178 -17
  3. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -386,8 +386,11 @@ import {
386
386
  EnginiError,
387
387
  EnginiMcpServerNotFoundError,
388
388
  EnginiNotFoundError,
389
+ EnginiOpaAgentTimeoutError,
390
+ EnginiOpaApplicationAmbiguousError,
389
391
  EnginiTimeoutError,
390
392
  EnginiToolsetNotFoundError,
393
+ EnginiTriggerGapError,
391
394
  EnginiValidationError
392
395
  } from "@engini/sdk";
393
396
 
@@ -439,7 +442,7 @@ function saveConfig(config, path = configPath()) {
439
442
  }
440
443
 
441
444
  // src/version.ts
442
- var VERSION = true ? "0.18.0" : "0.0.0";
445
+ var VERSION = true ? "0.20.0" : "0.0.0";
443
446
 
444
447
  // src/http.ts
445
448
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -463,8 +466,11 @@ function buildClient(overrides = {}) {
463
466
  }
464
467
  function exitForError(err) {
465
468
  if (err instanceof EnginiAuthError) return 3 /* AUTH */;
469
+ if (err instanceof EnginiOpaApplicationAmbiguousError) return 5 /* VALIDATION */;
470
+ if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
466
471
  if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
467
472
  if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
473
+ if (err instanceof EnginiTriggerGapError) return 4 /* NOT_FOUND */;
468
474
  if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
469
475
  if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
470
476
  if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
@@ -1534,8 +1540,9 @@ CONNECTIONS
1534
1540
  --connection <id> (object selection). No app \u2192 web page.
1535
1541
  connections list [--application <slug>] [--kind <kind>]
1536
1542
  List your connections. --kind filters on
1537
- Regular | Key | OPA | MCPClient. The web UI's
1538
- "Keys" tab is --kind Key.
1543
+ Regular | Key | MCPClient. The web UI's
1544
+ "Keys" tab is --kind Key. On-premise agents are
1545
+ not connections - see ON-PREMISE AGENTS.
1539
1546
  connections get <id> Inspect a connection.
1540
1547
  connections create <app> --auth <id> --name <n> --field k=v
1541
1548
  Create a direct-credential connection.
@@ -1590,6 +1597,49 @@ MCP SERVERS
1590
1597
  Note: the server token is part of the server's SSE URL \u2014 treat it as a secret.
1591
1598
  --dry-run previews every mutating command's resulting set before you commit to it.
1592
1599
 
1600
+ ON-PREMISE AGENTS
1601
+ The Engini component a customer installs behind their firewall to reach SQL Server,
1602
+ Oracle, Priority ERP and file shares. Not connections: connections list never shows them.
1603
+ opa list [--status <s>] [--name <substr>] List the account's on-premise agents.
1604
+ opa get <id> Status, version, last heartbeat, settings.
1605
+ opa create --name <n> [...] Register an agent. PRINTS ITS TOKEN.
1606
+ opa update <id> [...] Change name/description/settings (merges).
1607
+ opa delete <id> [--force] Permanently delete an agent.
1608
+ opa enable <id> | opa disable <id> Toggle whether the agent is marked online.
1609
+ opa token get <id> Read the agent's token (a credential).
1610
+ opa token rotate <id> [--force] New token; the running agent stops until reconfigured.
1611
+ opa logs <id> -o <file> Collect the agent's logs as a zip (agent must be Online).
1612
+ opa download [-o <file>] [--json] Fetch the current installer; --json prints the manifest.
1613
+ Note: an agent polls Engini, so anything that "talks to" it waits for its next poll.
1614
+ A settings update on an offline agent still stores - the response says applied_to_agent: false.
1615
+
1616
+ TRIGGERS
1617
+ A trigger instance (ti_\u2026) is an entity, not a workflow step - created from a trigger
1618
+ type (a catalog slug) against a connection.
1619
+ triggers types [--app <slug>] [--search <q>] [--connection <id>] List the catalog.
1620
+ triggers types get <trigger_slug> [--app <slug>] config_schema/payload_schema/parameters.
1621
+ triggers list [--app <s>] [--connection <id>] [--status <s>] [--include workflow] [--top <n>]
1622
+ triggers get <trigger_id> Status, schedule, last-error detail.
1623
+ triggers create <trigger_slug> --connection <name|id> [--config <json>] [--every <n><s|m|h|d>]
1624
+ [--weekdays <spec>] [--window <HH:mm-HH:mm>] [--listen <col>...] [--destination <name>]
1625
+ [--dedupe-window-hours <n>]
1626
+ triggers enable <id> | triggers disable <id> Toggle capture; not a delete.
1627
+ triggers delete <id> [--force] Permanent; deletes event history too.
1628
+ triggers events <trigger_id> [--limit <n>] The LOG - real delivery state.
1629
+ triggers events get <event_id> One event plus its delivery attempts.
1630
+ triggers events replay <event_id> Re-deliver a captured event.
1631
+ triggers listen [--trigger <id>] [--slug <s>] [--app <s>] [--since <event_id>] [--no-resume]
1632
+ [--forward <url>] [--sign-with <secret>]
1633
+ Note: 'events' is the historical log (real delivery state); 'listen' is the live stream,
1634
+ whose delivery field is always "pending" - they are never merged under one flag.
1635
+ triggers destinations set <url> [--name <n>] [--max-failures <n>] Account default.
1636
+ triggers destinations add <name> <url> [--default] [--max-failures <n>]
1637
+ triggers destinations list | triggers destinations show <name>
1638
+ triggers destinations enable <name> Recover an auto-disabled destination.
1639
+ triggers destinations rm <name> [--reassign <name>] [--force]
1640
+ triggers destinations rotate-secret <name> [--force]
1641
+ Note: add/rotate-secret/set(create) print the signing secret in the clear, once.
1642
+
1593
1643
  OUTPUT & EXIT CODES
1594
1644
  Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
1595
1645
  JSON with --json. Universal flags on every command:
@@ -2370,6 +2420,445 @@ function registerMcp(program) {
2370
2420
  registerMcpWorkflows(mcp);
2371
2421
  }
2372
2422
 
2423
+ // src/opa/shared.ts
2424
+ function parseAgentId(raw) {
2425
+ if (raw === void 0 || raw === "") fail(2 /* USAGE */, "An agent id is required.");
2426
+ if (!/^[1-9]\d*$/.test(raw)) {
2427
+ fail(2 /* USAGE */, `'${raw}' is not a valid agent id (expected a positive integer).`);
2428
+ }
2429
+ return Number(raw);
2430
+ }
2431
+ function summarizeAgent(agent) {
2432
+ return {
2433
+ agent_id: agent.agentId,
2434
+ name: clean(agent.name),
2435
+ status: agent.status,
2436
+ version: clean(agent.version),
2437
+ last_seen_at: clean(agent.lastSeenAt)
2438
+ };
2439
+ }
2440
+ function renderSettings(settings) {
2441
+ return {
2442
+ parallel_tasks: clean(settings?.parallelTasks),
2443
+ pull_period_seconds: clean(settings?.pullPeriodSeconds),
2444
+ log_level: clean(settings?.logLevel)
2445
+ };
2446
+ }
2447
+ function parseSettingsFlags(flags) {
2448
+ const integer = (raw, flag) => {
2449
+ if (raw === void 0) return void 0;
2450
+ if (!/^\d+$/.test(raw)) {
2451
+ fail(2 /* USAGE */, `${flag} must be a non-negative integer, got '${raw}'.`);
2452
+ }
2453
+ return Number(raw);
2454
+ };
2455
+ const out = {};
2456
+ const parallelTasks = integer(flags.parallelTasks, "--parallel-tasks");
2457
+ const pullPeriodSeconds = integer(flags.pullPeriod, "--pull-period");
2458
+ if (parallelTasks !== void 0) out.parallelTasks = parallelTasks;
2459
+ if (pullPeriodSeconds !== void 0) out.pullPeriodSeconds = pullPeriodSeconds;
2460
+ if (flags.logLevel !== void 0) out.logLevel = flags.logLevel;
2461
+ return out;
2462
+ }
2463
+ function settingsPreview(settings) {
2464
+ return Object.keys(settings).length === 0 ? void 0 : { ...settings };
2465
+ }
2466
+ function addSettingsOptions(cmd) {
2467
+ return cmd.option(
2468
+ "--parallel-tasks <n>",
2469
+ "Concurrent tasks the agent runs (server-declared range, currently 1-100)"
2470
+ ).option(
2471
+ "--pull-period <seconds>",
2472
+ "Seconds between task polls (server-declared minimum, currently 10)"
2473
+ ).option("--log-level <level>", "Agent log level, e.g. Information, Debug");
2474
+ }
2475
+
2476
+ // src/opa/create.ts
2477
+ async function createBody2(opts) {
2478
+ if (opts.name === void 0 || opts.name.trim() === "") fail(2 /* USAGE */, "--name is required.");
2479
+ const settings = parseSettingsFlags(opts);
2480
+ const preview = settingsPreview(settings);
2481
+ if (dryRun()) {
2482
+ printOutput({
2483
+ would_create: {
2484
+ name: opts.name,
2485
+ ...opts.description !== void 0 ? { description: opts.description } : {},
2486
+ ...opts.applicationSlug !== void 0 ? { applicationSlug: opts.applicationSlug } : {},
2487
+ ...preview ? { settings: preview } : {}
2488
+ }
2489
+ });
2490
+ return;
2491
+ }
2492
+ const agent = await apiErrors(
2493
+ async () => buildClient().opa.create({
2494
+ name: opts.name,
2495
+ description: opts.description,
2496
+ applicationSlug: opts.applicationSlug,
2497
+ ...settings
2498
+ })
2499
+ );
2500
+ printOutput({
2501
+ ...summarizeAgent(agent),
2502
+ settings: renderSettings(agent.settings),
2503
+ token: agent.token
2504
+ });
2505
+ }
2506
+ function registerOpaCreate(opa) {
2507
+ const cmd = opa.command("create").description(
2508
+ "Register a new on-premise agent. Prints its token - treat the output as a secret."
2509
+ ).option("--name <name>", "Display name (required)").option("--description <text>", "Optional description").option(
2510
+ "--application-slug <slug>",
2511
+ "Only when more than one agent application exists; the 409 lists the candidates"
2512
+ );
2513
+ addSettingsOptions(cmd);
2514
+ cmd.addHelpText(
2515
+ "after",
2516
+ '\nExamples:\n engini opa create --name "Warehouse SQL" --json\n engini opa create --name Backoffice --pull-period 30 --log-level Debug\n engini opa create --name Backoffice --dry-run'
2517
+ );
2518
+ addUniversalOptions(cmd, { mutating: true });
2519
+ cmd.action(async (opts, command) => {
2520
+ await runCommand(command, opts, true, () => createBody2(opts));
2521
+ });
2522
+ }
2523
+
2524
+ // src/opa/delete.ts
2525
+ async function deleteBody2(raw, opts) {
2526
+ const agentId = parseAgentId(raw);
2527
+ if (dryRun()) {
2528
+ printOutput({ would_delete: agentId });
2529
+ return;
2530
+ }
2531
+ await confirmOrFail(
2532
+ `Delete on-premise agent ${agentId}? Workflows routed through it will stop working.`,
2533
+ { force: Boolean(opts.force) }
2534
+ );
2535
+ await apiErrors(async () => buildClient().opa.delete(agentId));
2536
+ printOutput({ deleted: agentId });
2537
+ }
2538
+ function registerOpaDelete(opa) {
2539
+ const cmd = opa.command("delete").description("Permanently delete an on-premise agent.").argument("[agent_id]", "Agent id").option("--force", "Delete without confirming");
2540
+ cmd.addHelpText("after", "\nExamples:\n engini opa delete 41 --force");
2541
+ addUniversalOptions(cmd, { mutating: true });
2542
+ cmd.action(async (raw, opts, command) => {
2543
+ await runCommand(
2544
+ command,
2545
+ opts,
2546
+ true,
2547
+ () => deleteBody2(raw, opts)
2548
+ );
2549
+ });
2550
+ }
2551
+
2552
+ // src/opa/download.ts
2553
+ import { createHash } from "crypto";
2554
+ import { writeFile } from "fs/promises";
2555
+ import { basename } from "path";
2556
+ function targetFromManifest(url) {
2557
+ let name;
2558
+ try {
2559
+ name = basename(new URL(url).pathname);
2560
+ } catch {
2561
+ fail(1 /* GENERIC */, `The release manifest carries an unusable installer URL: ${url}`);
2562
+ }
2563
+ if (name === "" || name === "." || name === ".." || name.includes("/") || name.includes("\\")) {
2564
+ fail(
2565
+ 1 /* GENERIC */,
2566
+ `Cannot derive a filename from the manifest URL (${url}). Pass -o <file>.`
2567
+ );
2568
+ }
2569
+ return name;
2570
+ }
2571
+ async function downloadBody(opts) {
2572
+ const manifest = await apiErrors(async () => buildClient().opa.latestRelease());
2573
+ if (outputFlags().forceJson && opts.out === void 0) {
2574
+ printOutput(manifest);
2575
+ return;
2576
+ }
2577
+ const target = opts.out ?? targetFromManifest(manifest.url);
2578
+ if (dryRun()) {
2579
+ printOutput({
2580
+ would_write: target,
2581
+ version: manifest.version,
2582
+ url: manifest.url,
2583
+ degraded: manifest.degraded
2584
+ });
2585
+ return;
2586
+ }
2587
+ const response = await fetch(manifest.url);
2588
+ if (!response.ok) {
2589
+ fail(
2590
+ 1 /* GENERIC */,
2591
+ `Installer download failed: HTTP ${response.status} from ${manifest.url}`
2592
+ );
2593
+ }
2594
+ const bytes = new Uint8Array(await response.arrayBuffer());
2595
+ let verified;
2596
+ if (manifest.sha256) {
2597
+ const actual = createHash("sha256").update(bytes).digest("hex");
2598
+ if (actual !== manifest.sha256.toLowerCase()) {
2599
+ fail(
2600
+ 5 /* VALIDATION */,
2601
+ `sha256 mismatch: the manifest says ${manifest.sha256}, the download is ${actual}. Nothing written.`
2602
+ );
2603
+ }
2604
+ verified = true;
2605
+ } else {
2606
+ verified = false;
2607
+ }
2608
+ await writeFile(target, bytes);
2609
+ printOutput({
2610
+ wrote: target,
2611
+ bytes: bytes.length,
2612
+ version: manifest.version,
2613
+ verified,
2614
+ degraded: manifest.degraded
2615
+ });
2616
+ }
2617
+ function registerOpaDownload(opa) {
2618
+ const cmd = opa.command("download").description("Download the current on-premise agent installer.").option(
2619
+ "-o, --out <file>",
2620
+ "Where to write the installer (default: the manifest's filename, in the current directory)"
2621
+ );
2622
+ cmd.addHelpText(
2623
+ "after",
2624
+ "\nExamples:\n engini opa download # writes EnginiAgent-<version>.exe here\n engini opa download -o ./agent.exe\n engini opa download --json # print the manifest, download nothing\n engini opa download --dry-run # show where it would land"
2625
+ );
2626
+ addUniversalOptions(cmd, { mutating: true });
2627
+ cmd.action(async (opts, command) => {
2628
+ await runCommand(command, opts, true, () => downloadBody(opts));
2629
+ });
2630
+ }
2631
+
2632
+ // src/opa/get.ts
2633
+ async function getBody4(raw) {
2634
+ const agentId = parseAgentId(raw);
2635
+ const agent = await apiErrors(async () => buildClient().opa.get(agentId));
2636
+ printOutput({
2637
+ ...summarizeAgent(agent),
2638
+ description: clean(agent.description),
2639
+ settings: renderSettings(agent.settings),
2640
+ created_date: clean(agent.createdDate),
2641
+ updated_date: clean(agent.updatedDate)
2642
+ });
2643
+ }
2644
+ function registerOpaGet(opa) {
2645
+ const cmd = opa.command("get").description("Show full detail for one on-premise agent.").argument("[agent_id]", "Agent id");
2646
+ cmd.addHelpText("after", "\nExamples:\n engini opa get 41 --json");
2647
+ addUniversalOptions(cmd);
2648
+ cmd.action(async (raw, opts, command) => {
2649
+ await runCommand(command, opts, false, () => getBody4(raw));
2650
+ });
2651
+ }
2652
+
2653
+ // src/opa/list.ts
2654
+ async function listBody6(opts) {
2655
+ const agents = await apiErrors(
2656
+ async () => buildClient().opa.list({ status: opts.status, name: opts.name })
2657
+ );
2658
+ printOutput(agents.map(summarizeAgent));
2659
+ }
2660
+ function registerOpaList(opa) {
2661
+ const cmd = opa.command("list").description("List the account's on-premise agents.").option(
2662
+ "--status <status>",
2663
+ "Filter: WaitingForConnection | Online | Offline | Disabled (case-insensitive)"
2664
+ ).option("--name <substring>", "Filter by name substring");
2665
+ cmd.addHelpText(
2666
+ "after",
2667
+ "\nExamples:\n engini opa list\n engini opa list --status offline --json"
2668
+ );
2669
+ addUniversalOptions(cmd);
2670
+ cmd.action(async (opts, command) => {
2671
+ await runCommand(command, opts, false, () => listBody6(opts));
2672
+ });
2673
+ }
2674
+
2675
+ // src/opa/logs.ts
2676
+ import { writeFile as writeFile2 } from "fs/promises";
2677
+ async function logsBody(raw, opts) {
2678
+ const agentId = parseAgentId(raw);
2679
+ if (opts.out === void 0 || opts.out === "") {
2680
+ fail(2 /* USAGE */, "-o <file> is required: where to write the log archive.");
2681
+ }
2682
+ if (dryRun()) {
2683
+ printOutput({ would_write: opts.out, agent_id: agentId });
2684
+ return;
2685
+ }
2686
+ const bytes = await apiErrors(async () => buildClient().opa.downloadLogs(agentId));
2687
+ await writeFile2(opts.out, bytes);
2688
+ printOutput({ wrote: opts.out, bytes: bytes.length, agent_id: agentId });
2689
+ }
2690
+ function registerOpaLogs(opa) {
2691
+ const cmd = opa.command("logs").description("Collect an agent's logs as a zip archive. The agent must be Online.").argument("[agent_id]", "Agent id").option("-o, --out <file>", "Where to write the archive (required)");
2692
+ cmd.addHelpText(
2693
+ "after",
2694
+ "\nExamples:\n engini opa logs 41 -o ./opa-41-logs.zip\n engini opa logs 41 -o ./opa-41-logs.zip --json"
2695
+ );
2696
+ addUniversalOptions(cmd, { mutating: true });
2697
+ cmd.action(async (raw, opts, command) => {
2698
+ await runCommand(
2699
+ command,
2700
+ opts,
2701
+ true,
2702
+ () => logsBody(raw, opts)
2703
+ );
2704
+ });
2705
+ }
2706
+
2707
+ // src/opa/status.ts
2708
+ async function toggleBody(raw, enabled) {
2709
+ const agentId = parseAgentId(raw);
2710
+ if (dryRun()) {
2711
+ printOutput(enabled ? { would_enable: agentId } : { would_disable: agentId });
2712
+ return;
2713
+ }
2714
+ const agent = await apiErrors(async () => {
2715
+ const client = buildClient();
2716
+ return enabled ? client.opa.enable(agentId) : client.opa.disable(agentId);
2717
+ });
2718
+ printOutput(summarizeAgent(agent));
2719
+ }
2720
+ function register2(opa, name, description) {
2721
+ const cmd = opa.command(name).description(description).argument("[agent_id]", "Agent id");
2722
+ cmd.addHelpText("after", `
2723
+ Examples:
2724
+ engini opa ${name} 41`);
2725
+ addUniversalOptions(cmd, { mutating: true });
2726
+ cmd.action(async (raw, opts, command) => {
2727
+ await runCommand(command, opts, true, () => toggleBody(raw, name === "enable"));
2728
+ });
2729
+ }
2730
+ function registerOpaEnable(opa) {
2731
+ register2(
2732
+ opa,
2733
+ "enable",
2734
+ "Re-enable a disabled agent; it returns to WaitingForConnection. A no-op if it is not disabled."
2735
+ );
2736
+ }
2737
+ function registerOpaDisable(opa) {
2738
+ register2(
2739
+ opa,
2740
+ "disable",
2741
+ "Stop an agent being marked online. Tasks it already holds still complete."
2742
+ );
2743
+ }
2744
+
2745
+ // src/opa/token.ts
2746
+ async function getBody5(raw) {
2747
+ const agentId = parseAgentId(raw);
2748
+ const token = await apiErrors(async () => buildClient().opa.getToken(agentId));
2749
+ printOutput({ agent_id: token.agentId, token: token.token });
2750
+ }
2751
+ async function rotateBody(raw, opts) {
2752
+ const agentId = parseAgentId(raw);
2753
+ if (dryRun()) {
2754
+ printOutput({ would_rotate_token_for: agentId });
2755
+ return;
2756
+ }
2757
+ await confirmOrFail(
2758
+ `Rotate the token for on-premise agent ${agentId}? The running agent stops authenticating immediately and stays down until it is reconfigured with the new token.`,
2759
+ { force: Boolean(opts.force) }
2760
+ );
2761
+ const token = await apiErrors(async () => buildClient().opa.rotateToken(agentId));
2762
+ printOutput({
2763
+ agent_id: token.agentId,
2764
+ token: token.token,
2765
+ note: "Reconfigure the agent with this token; the previous one no longer works."
2766
+ });
2767
+ }
2768
+ function registerOpaToken(opa) {
2769
+ const token = opa.command("token").description("Read or rotate an agent's token (a live credential).");
2770
+ const get = token.command("get").description("Print the agent's current token.").argument("[agent_id]", "Agent id");
2771
+ get.addHelpText("after", "\nExamples:\n engini opa token get 41 --json");
2772
+ addUniversalOptions(get);
2773
+ get.action(async (raw, opts, command) => {
2774
+ await runCommand(command, opts, false, () => getBody5(raw));
2775
+ });
2776
+ const rotate = token.command("rotate").description(
2777
+ "Issue a new token, invalidating the current one. Stops the running agent until it is reconfigured."
2778
+ ).argument("[agent_id]", "Agent id").option("--force", "Rotate without confirming");
2779
+ rotate.addHelpText("after", "\nExamples:\n engini opa token rotate 41 --force --json");
2780
+ addUniversalOptions(rotate, { mutating: true });
2781
+ rotate.action(
2782
+ async (raw, opts, command) => {
2783
+ await runCommand(
2784
+ command,
2785
+ opts,
2786
+ true,
2787
+ () => rotateBody(raw, opts)
2788
+ );
2789
+ }
2790
+ );
2791
+ }
2792
+
2793
+ // src/opa/update.ts
2794
+ async function updateBody2(raw, opts) {
2795
+ const agentId = parseAgentId(raw);
2796
+ const settings = parseSettingsFlags(opts);
2797
+ const preview = settingsPreview(settings);
2798
+ const changes = {
2799
+ ...opts.name !== void 0 ? { name: opts.name } : {},
2800
+ ...opts.description !== void 0 ? { description: opts.description } : {},
2801
+ ...preview ? { settings: preview } : {}
2802
+ };
2803
+ if (Object.keys(changes).length === 0) {
2804
+ fail(
2805
+ 2 /* USAGE */,
2806
+ "Nothing to update - pass at least one of --name, --description, --parallel-tasks, --pull-period, --log-level."
2807
+ );
2808
+ }
2809
+ if (dryRun()) {
2810
+ printOutput({ would_update: agentId, changes });
2811
+ return;
2812
+ }
2813
+ const agent = await apiErrors(
2814
+ async () => buildClient().opa.update(agentId, {
2815
+ name: opts.name,
2816
+ description: opts.description,
2817
+ ...settings
2818
+ })
2819
+ );
2820
+ printOutput({
2821
+ ...summarizeAgent(agent),
2822
+ settings: renderSettings(agent.settings),
2823
+ applied_to_agent: clean(agent.appliedToAgent),
2824
+ dispatched_task_ids: agent.dispatchedTaskIds ?? []
2825
+ });
2826
+ }
2827
+ function registerOpaUpdate(opa) {
2828
+ const cmd = opa.command("update").description(
2829
+ "Change an agent's name, description or settings. Merges - omitted flags leave the field alone."
2830
+ ).argument("[agent_id]", "Agent id").option("--name <name>", "New display name").option("--description <text>", "New description");
2831
+ addSettingsOptions(cmd);
2832
+ cmd.addHelpText(
2833
+ "after",
2834
+ "\nExamples:\n engini opa update 41 --log-level Debug\n engini opa update 41 --parallel-tasks 8 --pull-period 15 --json\n engini opa update 41 --log-level Debug --dry-run"
2835
+ );
2836
+ addUniversalOptions(cmd, { mutating: true });
2837
+ cmd.action(async (raw, opts, command) => {
2838
+ await runCommand(
2839
+ command,
2840
+ opts,
2841
+ true,
2842
+ () => updateBody2(raw, opts)
2843
+ );
2844
+ });
2845
+ }
2846
+
2847
+ // src/opa/index.ts
2848
+ function registerOpa(program) {
2849
+ const opa = program.command("opa").description("Provision, inspect, configure and credential on-premise agents.");
2850
+ registerOpaList(opa);
2851
+ registerOpaGet(opa);
2852
+ registerOpaCreate(opa);
2853
+ registerOpaUpdate(opa);
2854
+ registerOpaDelete(opa);
2855
+ registerOpaEnable(opa);
2856
+ registerOpaDisable(opa);
2857
+ registerOpaToken(opa);
2858
+ registerOpaLogs(opa);
2859
+ registerOpaDownload(opa);
2860
+ }
2861
+
2373
2862
  // src/tools/call.ts
2374
2863
  import { readFileSync as readFileSync4 } from "fs";
2375
2864
  import {
@@ -2792,7 +3281,7 @@ function detail3(schema) {
2792
3281
  max_sorts: clean(schema.maxSorts)
2793
3282
  };
2794
3283
  }
2795
- async function getBody4(toolId) {
3284
+ async function getBody6(toolId) {
2796
3285
  if (!toolId) {
2797
3286
  fail(2 /* USAGE */, "Missing required argument 'tool_id'.");
2798
3287
  }
@@ -2806,7 +3295,7 @@ function registerToolsGet(tools) {
2806
3295
  const cmd = tools.command("get").description("Show full canonical detail for one tool.").argument("[tool_id]", "Tool slug");
2807
3296
  addUniversalOptions(cmd);
2808
3297
  cmd.action(async (toolId, opts, command) => {
2809
- await runCommand(command, opts, false, () => getBody4(toolId));
3298
+ await runCommand(command, opts, false, () => getBody6(toolId));
2810
3299
  });
2811
3300
  }
2812
3301
 
@@ -2829,7 +3318,7 @@ function parseLimit2(value) {
2829
3318
  }
2830
3319
  return limit;
2831
3320
  }
2832
- async function listBody6(opts) {
3321
+ async function listBody7(opts) {
2833
3322
  if (opts.application && opts.toolset) {
2834
3323
  fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
2835
3324
  }
@@ -2852,7 +3341,7 @@ function registerToolsList(tools) {
2852
3341
  const cmd = tools.command("list").description("List available tools, optionally filtered.").option("--application <slug>", "Filter by application slug (e.g. monday)").option("--toolset <id>", "List the tools of a server toolset (by id)").option("--limit <n>", "Cap the number of tools returned");
2853
3342
  addUniversalOptions(cmd);
2854
3343
  cmd.action(async (opts, command) => {
2855
- await runCommand(command, opts, false, () => listBody6(opts));
3344
+ await runCommand(command, opts, false, () => listBody7(opts));
2856
3345
  });
2857
3346
  }
2858
3347
 
@@ -3043,7 +3532,7 @@ function buildRequestBody(opts) {
3043
3532
  workflows: workflowsFromFlagsOrUndefined(opts.workflow)
3044
3533
  };
3045
3534
  }
3046
- async function createBody2(opts) {
3535
+ async function createBody3(opts) {
3047
3536
  const body = buildRequestBody(opts);
3048
3537
  if (dryRun()) {
3049
3538
  printOutput({
@@ -3077,12 +3566,12 @@ function registerToolsetsCreate(toolsets) {
3077
3566
  );
3078
3567
  addUniversalOptions(cmd, { mutating: true });
3079
3568
  cmd.action(async (opts, command) => {
3080
- await runCommand(command, opts, true, () => createBody2(opts));
3569
+ await runCommand(command, opts, true, () => createBody3(opts));
3081
3570
  });
3082
3571
  }
3083
3572
 
3084
3573
  // src/toolsets/delete.ts
3085
- async function deleteBody2(toolsetId, opts) {
3574
+ async function deleteBody3(toolsetId, opts) {
3086
3575
  const id = parseToolsetId(toolsetId);
3087
3576
  if (dryRun()) {
3088
3577
  printOutput({ would_delete: id });
@@ -3100,12 +3589,12 @@ function registerToolsetsDelete(toolsets) {
3100
3589
  cmd.addHelpText("after", "\nExamples:\n engini toolsets delete <toolset_id> --force");
3101
3590
  addUniversalOptions(cmd, { mutating: true });
3102
3591
  cmd.action(async (id, opts, command) => {
3103
- await runCommand(command, opts, true, () => deleteBody2(id, opts));
3592
+ await runCommand(command, opts, true, () => deleteBody3(id, opts));
3104
3593
  });
3105
3594
  }
3106
3595
 
3107
3596
  // src/toolsets/get.ts
3108
- async function getBody5(toolsetId) {
3597
+ async function getBody7(toolsetId) {
3109
3598
  const id = parseToolsetId(toolsetId);
3110
3599
  const toolset = await apiErrors(async () => {
3111
3600
  const client = buildClient();
@@ -3123,12 +3612,12 @@ function registerToolsetsGet(toolsets) {
3123
3612
  cmd.addHelpText("after", "\nExamples:\n engini toolsets get <toolset_id> --json");
3124
3613
  addUniversalOptions(cmd);
3125
3614
  cmd.action(async (id, opts, command) => {
3126
- await runCommand(command, opts, false, () => getBody5(id));
3615
+ await runCommand(command, opts, false, () => getBody7(id));
3127
3616
  });
3128
3617
  }
3129
3618
 
3130
3619
  // src/toolsets/list.ts
3131
- async function listBody7() {
3620
+ async function listBody8() {
3132
3621
  const toolsets = await apiErrors(async () => {
3133
3622
  const client = buildClient();
3134
3623
  return client.toolsets.list();
@@ -3143,7 +3632,7 @@ function registerToolsetsList(toolsets) {
3143
3632
  );
3144
3633
  addUniversalOptions(cmd);
3145
3634
  cmd.action(async (opts, command) => {
3146
- await runCommand(command, opts, false, () => listBody7());
3635
+ await runCommand(command, opts, false, () => listBody8());
3147
3636
  });
3148
3637
  }
3149
3638
 
@@ -3178,7 +3667,7 @@ async function previewDryRun(toolsetId, body) {
3178
3667
  }
3179
3668
  });
3180
3669
  }
3181
- async function updateBody2(toolsetId, opts) {
3670
+ async function updateBody3(toolsetId, opts) {
3182
3671
  const id = parseToolsetId(toolsetId);
3183
3672
  const body = buildRequestBody2(opts);
3184
3673
  if (body.name === void 0 && body.connections === void 0 && body.workflows === void 0) {
@@ -3215,7 +3704,7 @@ function registerToolsetsUpdate(toolsets) {
3215
3704
  );
3216
3705
  addUniversalOptions(cmd, { mutating: true });
3217
3706
  cmd.action(async (id, opts, command) => {
3218
- await runCommand(command, opts, true, () => updateBody2(id, opts));
3707
+ await runCommand(command, opts, true, () => updateBody3(id, opts));
3219
3708
  });
3220
3709
  }
3221
3710
 
@@ -3229,6 +3718,676 @@ function registerToolsets(program) {
3229
3718
  registerToolsetsDelete(toolsets);
3230
3719
  }
3231
3720
 
3721
+ // src/triggers/create.ts
3722
+ import { EnginiNotFoundError as EnginiNotFoundError2 } from "@engini/sdk";
3723
+
3724
+ // src/triggers/shared.ts
3725
+ var TRIGGER_ID_RE = /^ti_[A-Za-z0-9]+$/;
3726
+ function parseTriggerId(raw) {
3727
+ if (raw === void 0 || raw === "") fail(2 /* USAGE */, "A trigger id is required.");
3728
+ if (!TRIGGER_ID_RE.test(raw)) {
3729
+ fail(2 /* USAGE */, `'${raw}' is not a valid trigger id (expected 'ti_\u2026').`);
3730
+ }
3731
+ return raw;
3732
+ }
3733
+ function parseDestName(raw) {
3734
+ if (raw === void 0 || raw === "") fail(2 /* USAGE */, "A destination name is required.");
3735
+ return raw;
3736
+ }
3737
+ function collect3(value, previous = []) {
3738
+ return [...previous, value];
3739
+ }
3740
+ function parseConfig(raw) {
3741
+ if (raw === void 0) return void 0;
3742
+ try {
3743
+ return JSON.parse(raw);
3744
+ } catch {
3745
+ fail(2 /* USAGE */, `--config is not valid JSON: '${raw}'.`);
3746
+ }
3747
+ }
3748
+ var WEEKDAY_NAMES = {
3749
+ sun: 0,
3750
+ mon: 1,
3751
+ tue: 2,
3752
+ wed: 3,
3753
+ thu: 4,
3754
+ fri: 5,
3755
+ sat: 6
3756
+ };
3757
+ function parseWeekdays(raw) {
3758
+ if (raw === void 0) return void 0;
3759
+ const days = /* @__PURE__ */ new Set();
3760
+ for (const part of raw.split(",")) {
3761
+ const token = part.trim().toLowerCase();
3762
+ if (token === "") continue;
3763
+ const range = token.split("-");
3764
+ if (range.length === 2) {
3765
+ const start = WEEKDAY_NAMES[range[0]];
3766
+ const end = WEEKDAY_NAMES[range[1]];
3767
+ if (start === void 0 || end === void 0) {
3768
+ fail(2 /* USAGE */, `--weekdays has an unrecognised day in '${token}'.`);
3769
+ }
3770
+ for (let i = start; ; i = (i + 1) % 7) {
3771
+ days.add(i);
3772
+ if (i === end) break;
3773
+ }
3774
+ } else {
3775
+ const day = WEEKDAY_NAMES[token];
3776
+ if (day === void 0) fail(2 /* USAGE */, `--weekdays has an unrecognised day '${token}'.`);
3777
+ days.add(day);
3778
+ }
3779
+ }
3780
+ return [...days].sort((a, b) => a - b);
3781
+ }
3782
+ function parseEvery(raw) {
3783
+ if (raw === void 0) return void 0;
3784
+ const match = /^(\d+)(s|m|h|d)$/.exec(raw.trim());
3785
+ if (!match) {
3786
+ fail(2 /* USAGE */, `--every must look like '15m', '2h' or '1d', got '${raw}'.`);
3787
+ }
3788
+ const interval = Number(match[1]);
3789
+ const unit = match[2];
3790
+ const frequency = unit === "s" ? "seconds" : unit === "m" ? "minute" : unit === "h" ? "hour" : "day";
3791
+ return { frequency, interval };
3792
+ }
3793
+ var WINDOW_RE = /^(\d{2}:\d{2})-(\d{2}:\d{2})$/;
3794
+ function parseWindow(raw) {
3795
+ if (raw === void 0) return void 0;
3796
+ const match = WINDOW_RE.exec(raw.trim());
3797
+ if (!match) {
3798
+ fail(2 /* USAGE */, `--window must look like '09:00-17:00', got '${raw}'.`);
3799
+ }
3800
+ return [{ start_hour: match[1], end_hour: match[2] }];
3801
+ }
3802
+ function parseSchedule(flags) {
3803
+ if (flags.every === void 0 && flags.weekdays === void 0 && flags.window === void 0) {
3804
+ return void 0;
3805
+ }
3806
+ const every = parseEvery(flags.every);
3807
+ const weekDays = parseWeekdays(flags.weekdays);
3808
+ const timeFrames = parseWindow(flags.window);
3809
+ return {
3810
+ frequency: every?.frequency ?? (weekDays !== void 0 ? "week" : "day"),
3811
+ interval: every?.interval ?? 1,
3812
+ ...weekDays !== void 0 ? { week_days: weekDays } : {},
3813
+ ...timeFrames !== void 0 ? { time_frames: timeFrames } : {}
3814
+ };
3815
+ }
3816
+ function summarizeTrigger(t) {
3817
+ return {
3818
+ id: clean(t.id),
3819
+ trigger_slug: clean(t.trigger_slug),
3820
+ kind: t.kind,
3821
+ status: t.status,
3822
+ status_reason: clean(t.status_reason),
3823
+ last_event_at: clean(t.last_event_at),
3824
+ next_run_at: clean(t.next_run_at)
3825
+ };
3826
+ }
3827
+ function summarizeDestination(d) {
3828
+ return {
3829
+ id: d.id,
3830
+ name: d.name,
3831
+ url: d.url,
3832
+ is_default: clean(d.is_default),
3833
+ status: d.status,
3834
+ consecutive_failures: clean(d.consecutive_failures),
3835
+ max_consecutive_failures: clean(d.max_consecutive_failures),
3836
+ last_delivery_at: clean(d.last_delivery_at),
3837
+ last_failure_at: clean(d.last_failure_at),
3838
+ last_failure: clean(d.last_failure)
3839
+ };
3840
+ }
3841
+ function summarizeEvent(e) {
3842
+ return {
3843
+ id: clean(e.id),
3844
+ trigger_id: clean(e.trigger_id),
3845
+ occurred_at: clean(e.occurred_at),
3846
+ payload: e.payload,
3847
+ payload_truncated: clean(e.payload_truncated),
3848
+ payload_hash: clean(e.payload_hash),
3849
+ delivery: e.delivery
3850
+ };
3851
+ }
3852
+
3853
+ // src/triggers/create.ts
3854
+ function connectionRef(raw) {
3855
+ return /^\d+$/.test(raw) ? { connectionId: Number(raw) } : { connectionName: raw };
3856
+ }
3857
+ async function hasAccountDefaultDestination() {
3858
+ try {
3859
+ await buildClient().triggers.destination.get();
3860
+ return true;
3861
+ } catch (err) {
3862
+ if (err instanceof EnginiNotFoundError2) return false;
3863
+ throw err;
3864
+ }
3865
+ }
3866
+ async function createBody4(triggerSlug, opts) {
3867
+ if (triggerSlug === void 0 || triggerSlug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
3868
+ if (opts.connection === void 0 || opts.connection === "") {
3869
+ fail(2 /* USAGE */, "--connection is required (a connection name or id).");
3870
+ }
3871
+ const config = parseConfig(opts.config);
3872
+ const schedule = parseSchedule(opts);
3873
+ const dedupeWindowHours = opts.dedupeWindowHours !== void 0 ? Number(opts.dedupeWindowHours) : void 0;
3874
+ if (dryRun()) {
3875
+ printOutput({
3876
+ would_create: {
3877
+ trigger_slug: triggerSlug,
3878
+ connection: opts.connection,
3879
+ config,
3880
+ schedule,
3881
+ listen_columns: opts.listen,
3882
+ destination: opts.destination,
3883
+ dedupe_window_hours: dedupeWindowHours
3884
+ }
3885
+ });
3886
+ return;
3887
+ }
3888
+ let destinationId;
3889
+ if (opts.destination !== void 0) {
3890
+ const dest = await apiErrors(async () => buildClient().triggers.destinations.get(opts.destination));
3891
+ destinationId = dest.id;
3892
+ }
3893
+ const trigger = await apiErrors(
3894
+ async () => buildClient().triggers.create({
3895
+ triggerSlug,
3896
+ ...connectionRef(opts.connection),
3897
+ config,
3898
+ schedule,
3899
+ listenColumns: opts.listen,
3900
+ destinationId,
3901
+ dedupeWindowHours
3902
+ })
3903
+ );
3904
+ if (opts.destination === void 0) {
3905
+ const hasDefault = await apiErrors(hasAccountDefaultDestination);
3906
+ if (!hasDefault) {
3907
+ progress(
3908
+ "No destination is set for this trigger and the account has no default \u2014 events will accrue but nothing will be delivered. Set one with `engini triggers destinations set <url>`."
3909
+ );
3910
+ }
3911
+ }
3912
+ printOutput({
3913
+ ...summarizeTrigger(trigger),
3914
+ destination_id: clean(trigger.destination_id),
3915
+ schedule: trigger.schedule ?? null
3916
+ });
3917
+ }
3918
+ function registerTriggerCreate(triggers) {
3919
+ const create = triggers.command("create").description("Create a trigger instance from a trigger type.").argument("[trigger_slug]", "Trigger type slug, as listed by `types`").option("--connection <name|id>", "The connection to run against (required)").option("--config <json>", "The trigger activity's own inputs, as JSON (server-validated)").option("--every <n><s|m|h|d>", "Polling cadence, e.g. 15m, 2h, 1d").option("--weekdays <spec>", "e.g. mon-fri, sun,wed \u2014 only meaningful with a week schedule").option("--window <HH:mm-HH:mm>", "Restrict polling to a time-of-day window").option("--listen <column>", "A column to watch (repeatable)", collect3, []).option("--destination <name>", "Deliver to this named destination instead of the account default").option("--dedupe-window-hours <n>", "Hours to suppress duplicate events");
3920
+ create.addHelpText(
3921
+ "after",
3922
+ "\nExamples:\n engini triggers create monday_item_created --connection 12 --dry-run\n engini triggers create monday_item_created --connection billing --every 15m\n engini triggers create netsuite_record_updated --connection 3 --weekdays mon-fri --window 09:00-17:00"
3923
+ );
3924
+ addUniversalOptions(create, { mutating: true });
3925
+ create.action(async (triggerSlug, opts, command) => {
3926
+ await runCommand(command, opts, true, () => createBody4(triggerSlug, opts));
3927
+ });
3928
+ }
3929
+
3930
+ // src/triggers/delete.ts
3931
+ async function deleteBody4(raw, opts) {
3932
+ const triggerId = parseTriggerId(raw);
3933
+ if (dryRun()) {
3934
+ printOutput({ would_delete: triggerId });
3935
+ return;
3936
+ }
3937
+ await confirmOrFail(
3938
+ `Permanently delete trigger ${triggerId}? Its event history is deleted with it.`,
3939
+ { force: Boolean(opts.force) }
3940
+ );
3941
+ await apiErrors(async () => buildClient().triggers.delete(triggerId));
3942
+ printOutput({ deleted: triggerId });
3943
+ }
3944
+ function registerTriggerDelete(triggers) {
3945
+ const cmd = triggers.command("delete").description("Permanently delete a trigger instance and its hidden system workflow.").argument("[trigger_id]", "Trigger instance id (ti_\u2026)").option("--force", "Delete without confirming");
3946
+ cmd.addHelpText("after", "\nExamples:\n engini triggers delete ti_abc123 --force");
3947
+ addUniversalOptions(cmd, { mutating: true });
3948
+ cmd.action(
3949
+ async (raw, opts, command) => {
3950
+ await runCommand(command, opts, true, () => deleteBody4(raw, opts));
3951
+ }
3952
+ );
3953
+ }
3954
+
3955
+ // src/triggers/destinations.ts
3956
+ var SECRET_NOTE = "Shown once \u2014 store it now.";
3957
+ function withSecret(created) {
3958
+ return { ...summarizeDestination(created.destination), secret: created.signing_secret, note: SECRET_NOTE };
3959
+ }
3960
+ function renderPutResult(result) {
3961
+ return "destination" in result ? withSecret(result) : summarizeDestination(result);
3962
+ }
3963
+ async function setBody3(url, opts) {
3964
+ if (url === void 0 || url === "") fail(2 /* USAGE */, "A destination url is required.");
3965
+ if (dryRun()) {
3966
+ printOutput({ would_set_default: { url, name: opts.name } });
3967
+ return;
3968
+ }
3969
+ const result = await apiErrors(
3970
+ async () => buildClient().triggers.destination.put({
3971
+ url,
3972
+ name: opts.name,
3973
+ maxConsecutiveFailures: opts.maxFailures !== void 0 ? Number(opts.maxFailures) : void 0
3974
+ })
3975
+ );
3976
+ printOutput(renderPutResult(result));
3977
+ }
3978
+ async function addBody(name, url, opts) {
3979
+ if (name === void 0 || name === "") fail(2 /* USAGE */, "A destination name is required.");
3980
+ if (url === void 0 || url === "") fail(2 /* USAGE */, "A destination url is required.");
3981
+ if (dryRun()) {
3982
+ printOutput({ would_add: { name, url, is_default: Boolean(opts.default) } });
3983
+ return;
3984
+ }
3985
+ const created = await apiErrors(
3986
+ async () => buildClient().triggers.destinations.create({
3987
+ name,
3988
+ url,
3989
+ isDefault: opts.default,
3990
+ maxConsecutiveFailures: opts.maxFailures !== void 0 ? Number(opts.maxFailures) : void 0
3991
+ })
3992
+ );
3993
+ printOutput(withSecret(created));
3994
+ }
3995
+ async function listBody9() {
3996
+ const destinations = await apiErrors(async () => buildClient().triggers.destinations.list());
3997
+ printOutput(destinations.map(summarizeDestination));
3998
+ }
3999
+ async function showBody(raw) {
4000
+ const name = parseDestName(raw);
4001
+ const destination = await apiErrors(async () => buildClient().triggers.destinations.get(name));
4002
+ printOutput(summarizeDestination(destination));
4003
+ }
4004
+ async function enableBody(raw) {
4005
+ const name = parseDestName(raw);
4006
+ if (dryRun()) {
4007
+ printOutput({ would_enable: name });
4008
+ return;
4009
+ }
4010
+ const destination = await apiErrors(
4011
+ async () => buildClient().triggers.destinations.update(name, { status: "active" })
4012
+ );
4013
+ printOutput(summarizeDestination(destination));
4014
+ }
4015
+ async function rmBody(raw, opts) {
4016
+ const name = parseDestName(raw);
4017
+ if (dryRun()) {
4018
+ printOutput({ would_delete: name, reassign_to: opts.reassign ?? null });
4019
+ return;
4020
+ }
4021
+ await confirmOrFail(`Delete destination '${name}'?`, { force: Boolean(opts.force) });
4022
+ await apiErrors(async () => buildClient().triggers.destinations.delete(name, { reassignTo: opts.reassign }));
4023
+ printOutput({ deleted: name });
4024
+ }
4025
+ async function rotateBody2(raw, opts) {
4026
+ const name = parseDestName(raw);
4027
+ if (dryRun()) {
4028
+ printOutput({ would_rotate_secret_for: name });
4029
+ return;
4030
+ }
4031
+ await confirmOrFail(
4032
+ `Rotate the signing secret for '${name}'? Deliveries signed with the old secret stop verifying immediately \u2014 deploy the new secret to the receiver first.`,
4033
+ { force: Boolean(opts.force) }
4034
+ );
4035
+ const created = await apiErrors(async () => buildClient().triggers.destinations.rotateSecret(name));
4036
+ printOutput(withSecret(created));
4037
+ }
4038
+ function registerTriggerDestinations(triggers) {
4039
+ const destinations = triggers.command("destinations").description("Registered HTTPS delivery endpoints for trigger events.");
4040
+ const set = destinations.command("set").description("Set (or re-point) the account's default destination. Prints its signing secret on create.").argument("[url]", "HTTPS delivery URL").option("--name <name>", "Name if this call creates the default (ignored when re-pointing)").option("--max-failures <n>", "Consecutive dead-lettered events before auto-disable (default 5)");
4041
+ set.addHelpText("after", "\nExamples:\n engini triggers destinations set https://hooks.example.com/engini");
4042
+ addUniversalOptions(set, { mutating: true });
4043
+ set.action(async (url, opts, command) => {
4044
+ await runCommand(command, opts, true, () => setBody3(url, opts));
4045
+ });
4046
+ const add = destinations.command("add").description("Register a named destination. Prints its signing secret \u2014 shown once.").argument("[name]", "Destination name").argument("[url]", "HTTPS delivery URL").option("--default", "Promote this destination to the account default").option("--max-failures <n>", "Consecutive dead-lettered events before auto-disable (default 5)");
4047
+ add.addHelpText(
4048
+ "after",
4049
+ "\nExamples:\n engini triggers destinations add billing https://hooks.example.com/billing --default"
4050
+ );
4051
+ addUniversalOptions(add, { mutating: true });
4052
+ add.action(
4053
+ async (name, url, opts, command) => {
4054
+ await runCommand(command, opts, true, () => addBody(name, url, opts));
4055
+ }
4056
+ );
4057
+ const list = destinations.command("list").description("List every destination on the account.");
4058
+ list.addHelpText("after", "\nExamples:\n engini triggers destinations list --json");
4059
+ addUniversalOptions(list);
4060
+ list.action(async (opts, command) => {
4061
+ await runCommand(command, opts, false, listBody9);
4062
+ });
4063
+ const show = destinations.command("show").description("One destination's failure counters and status.").argument("[name]", "Destination name");
4064
+ show.addHelpText("after", "\nExamples:\n engini triggers destinations show billing");
4065
+ addUniversalOptions(show);
4066
+ show.action(async (raw, opts, command) => {
4067
+ await runCommand(command, opts, false, () => showBody(raw));
4068
+ });
4069
+ const enable = destinations.command("enable").description("Re-enable an auto-disabled destination and reset its failure counter.").argument("[name]", "Destination name");
4070
+ enable.addHelpText("after", "\nExamples:\n engini triggers destinations enable billing");
4071
+ addUniversalOptions(enable, { mutating: true });
4072
+ enable.action(async (raw, opts, command) => {
4073
+ await runCommand(command, opts, true, () => enableBody(raw));
4074
+ });
4075
+ const rm = destinations.command("rm").description("Delete a destination.").argument("[name]", "Destination name").option("--reassign <name>", "Re-point triggers that reference this destination instead of failing").option("--force", "Delete without confirming");
4076
+ rm.addHelpText(
4077
+ "after",
4078
+ "\nExamples:\n engini triggers destinations rm billing --reassign default --force\nNote: without --reassign, deleting a destination triggers still reference is a 409 (let it surface)."
4079
+ );
4080
+ addUniversalOptions(rm, { mutating: true });
4081
+ rm.action(
4082
+ async (raw, opts, command) => {
4083
+ await runCommand(command, opts, true, () => rmBody(raw, opts));
4084
+ }
4085
+ );
4086
+ const rotate = destinations.command("rotate-secret").description("Issue a new signing secret, invalidating the current one immediately.").argument("[name]", "Destination name").option("--force", "Rotate without confirming");
4087
+ rotate.addHelpText("after", "\nExamples:\n engini triggers destinations rotate-secret billing --force");
4088
+ addUniversalOptions(rotate, { mutating: true });
4089
+ rotate.action(
4090
+ async (raw, opts, command) => {
4091
+ await runCommand(command, opts, true, () => rotateBody2(raw, opts));
4092
+ }
4093
+ );
4094
+ }
4095
+
4096
+ // src/triggers/events.ts
4097
+ async function listBody10(triggerId, opts) {
4098
+ if (triggerId === void 0 || triggerId === "") fail(2 /* USAGE */, "A trigger_id is required.");
4099
+ const top = opts.limit !== void 0 ? Number(opts.limit) : void 0;
4100
+ const events = await apiErrors(async () => buildClient().triggers.events.list(triggerId, { top }));
4101
+ printOutput(events.map(summarizeEvent));
4102
+ }
4103
+ async function getBody8(eventId) {
4104
+ if (eventId === void 0 || eventId === "") fail(2 /* USAGE */, "An event_id is required.");
4105
+ const detail4 = await apiErrors(async () => buildClient().triggers.events.get(eventId));
4106
+ printOutput({ event: summarizeEvent(detail4.event), attempts: detail4.attempts });
4107
+ }
4108
+ async function replayBody(eventId) {
4109
+ if (eventId === void 0 || eventId === "") fail(2 /* USAGE */, "An event_id is required.");
4110
+ if (dryRun()) {
4111
+ printOutput({ would_replay: eventId });
4112
+ return;
4113
+ }
4114
+ const detail4 = await apiErrors(async () => buildClient().triggers.events.replay(eventId));
4115
+ printOutput({ event: summarizeEvent(detail4.event), attempts: detail4.attempts });
4116
+ }
4117
+ function registerTriggerEvents(triggers) {
4118
+ const events = triggers.command("events").description("The captured event log for one trigger \u2014 real delivery state, unlike `listen`.").argument("[trigger_id]", "Trigger instance id (ti_\u2026)").option("--limit <n>", "Cap the number of events returned (one page; never a full drain)");
4119
+ events.addHelpText(
4120
+ "after",
4121
+ "\nExamples:\n engini triggers events ti_abc123 --limit 20\nNote: for live events use `engini triggers listen`, not this in a poll loop."
4122
+ );
4123
+ addUniversalOptions(events);
4124
+ events.action(
4125
+ async (triggerId, opts, command) => {
4126
+ await runCommand(command, opts, false, () => listBody10(triggerId, opts));
4127
+ }
4128
+ );
4129
+ const get = events.command("get").description("One event plus its delivery attempts \u2014 the only place a real delivery state is read.").argument("[event_id]", "Event id (te_\u2026)");
4130
+ get.addHelpText("after", "\nExamples:\n engini triggers events get te_abc123 --json");
4131
+ addUniversalOptions(get);
4132
+ get.action(async (eventId, opts, command) => {
4133
+ await runCommand(command, opts, false, () => getBody8(eventId));
4134
+ });
4135
+ const replay = events.command("replay").description("Re-deliver a captured event to its destination.").argument("[event_id]", "Event id (te_\u2026)");
4136
+ replay.addHelpText(
4137
+ "after",
4138
+ "\nExamples:\n engini triggers events replay te_abc123\nHint: a DESTINATION_DISABLED error means the destination auto-disabled \u2014 `engini triggers destinations enable <name>` first."
4139
+ );
4140
+ addUniversalOptions(replay, { mutating: true });
4141
+ replay.action(async (eventId, opts, command) => {
4142
+ await runCommand(command, opts, true, () => replayBody(eventId));
4143
+ });
4144
+ }
4145
+
4146
+ // src/triggers/get.ts
4147
+ async function getBody9(raw) {
4148
+ const triggerId = parseTriggerId(raw);
4149
+ const trigger = await apiErrors(async () => buildClient().triggers.get(triggerId));
4150
+ printOutput(summarizeTrigger(trigger));
4151
+ }
4152
+ function registerTriggersGet(triggers) {
4153
+ const get = triggers.command("get").description("One trigger instance's status, schedule and last-error detail.").argument("[trigger_id]", "Trigger instance id (ti_\u2026)");
4154
+ get.addHelpText("after", "\nExamples:\n engini triggers get ti_abc123 --json");
4155
+ addUniversalOptions(get);
4156
+ get.action(async (raw, opts, command) => {
4157
+ await runCommand(command, opts, false, () => getBody9(raw));
4158
+ });
4159
+ }
4160
+
4161
+ // src/triggers/listen.ts
4162
+ import { createHmac } from "crypto";
4163
+ function emitEvent(frame) {
4164
+ console.log(JSON.stringify(frame));
4165
+ }
4166
+ function buildDeliveryBody(frame) {
4167
+ return {
4168
+ id: frame.id,
4169
+ trigger_id: frame.trigger_id,
4170
+ trigger_slug: frame.trigger_slug ?? null,
4171
+ occurred_at: frame.occurred_at,
4172
+ attempt: 1,
4173
+ payload_truncated: frame.payload_truncated,
4174
+ payload_hash: frame.payload_hash,
4175
+ payload: frame.payload
4176
+ };
4177
+ }
4178
+ function sign(secret, bodyBytes) {
4179
+ const t = Math.floor(Date.now() / 1e3);
4180
+ const mac = createHmac("sha256", Buffer.from(secret, "utf8")).update(Buffer.concat([Buffer.from(`${t}.`, "utf8"), bodyBytes])).digest("hex");
4181
+ return `t=${t},v1=${mac}`;
4182
+ }
4183
+ async function forwardEvent(frame, url, secret) {
4184
+ const body = buildDeliveryBody(frame);
4185
+ const bytes = Buffer.from(JSON.stringify(body), "utf8");
4186
+ const headers = {
4187
+ "Content-Type": "application/json",
4188
+ "X-Engini-Timestamp": String(Math.floor(Date.now() / 1e3))
4189
+ };
4190
+ if (typeof frame.id === "string") headers["X-Engini-Event-Id"] = frame.id;
4191
+ if (typeof frame.trigger_id === "string") headers["X-Engini-Trigger-Id"] = frame.trigger_id;
4192
+ if (frame.trigger_slug !== void 0 && frame.trigger_slug !== null) {
4193
+ headers["X-Engini-Trigger-Slug"] = frame.trigger_slug;
4194
+ }
4195
+ if (secret) headers["X-Engini-Signature"] = sign(secret, bytes);
4196
+ try {
4197
+ const res = await fetch(url, { method: "POST", headers, body: bytes });
4198
+ if (!res.ok) {
4199
+ console.error(`forward to ${url} failed: HTTP ${res.status}`);
4200
+ return false;
4201
+ }
4202
+ return true;
4203
+ } catch (err) {
4204
+ console.error(`forward to ${url} failed: ${err instanceof Error ? err.message : String(err)}`);
4205
+ return false;
4206
+ }
4207
+ }
4208
+ async function listenBody(opts) {
4209
+ const secret = opts.signWith ?? process.env.ENGINI_TRIGGER_SIGNING_SECRET;
4210
+ if (opts.forward !== void 0 && !secret) {
4211
+ progress(
4212
+ "--forward is unsigned (no --sign-with / ENGINI_TRIGGER_SIGNING_SECRET) \u2014 the X-Engini-Signature header is omitted, never sent empty."
4213
+ );
4214
+ }
4215
+ let interrupted = false;
4216
+ const onSigint = () => {
4217
+ interrupted = true;
4218
+ };
4219
+ process.once("SIGINT", onSigint);
4220
+ let events = 0;
4221
+ let forwarded = 0;
4222
+ let failed = 0;
4223
+ try {
4224
+ await apiErrors(async () => {
4225
+ const stream = buildClient().triggers.subscribe({
4226
+ triggerId: opts.trigger,
4227
+ triggerSlug: opts.slug,
4228
+ applicationSlug: opts.app,
4229
+ since: opts.since,
4230
+ autoResume: opts.resume
4231
+ });
4232
+ for await (const frame of stream) {
4233
+ if (interrupted) break;
4234
+ events += 1;
4235
+ emitEvent(frame);
4236
+ if (opts.forward !== void 0) {
4237
+ const ok = await forwardEvent(frame, opts.forward, secret);
4238
+ if (ok) forwarded += 1;
4239
+ else failed += 1;
4240
+ }
4241
+ if (interrupted) break;
4242
+ }
4243
+ });
4244
+ } finally {
4245
+ process.removeListener("SIGINT", onSigint);
4246
+ }
4247
+ console.log(JSON.stringify({ events, forwarded, failed }));
4248
+ if (!interrupted && failed > 0) {
4249
+ throw new CliError(1 /* GENERIC */);
4250
+ }
4251
+ }
4252
+ function registerTriggerListen(triggers) {
4253
+ const listen = triggers.command("listen").description(
4254
+ "Stream trigger events live (local dev only \u2014 not a delivery mechanism). See `events` for the historical log."
4255
+ ).option("--trigger <id>", "Filter to one trigger instance (ti_\u2026)").option("--slug <slug>", "Filter to one trigger type").option("--app <slug>", "Filter to one application").option("--since <event_id>", "Resume strictly after this event id").option("--no-resume", "Stop at the first stream ending instead of reconnecting").option("--forward <url>", "POST each event to this URL as a delivery rehearsal").option(
4256
+ "--sign-with <secret>",
4257
+ "Sign forwarded events with this destination secret (or ENGINI_TRIGGER_SIGNING_SECRET)"
4258
+ );
4259
+ listen.addHelpText(
4260
+ "after",
4261
+ "\nExamples:\n engini triggers listen --trigger ti_abc123\n engini triggers listen --slug monday_item_created --forward http://localhost:4000/hook --sign-with esec_...\nNote: prints one compact JSON line per event, always (not gated by --json). Ctrl-C exits 0."
4262
+ );
4263
+ addUniversalOptions(listen);
4264
+ listen.action(async (opts, command) => {
4265
+ await runCommand(command, opts, false, () => listenBody(opts));
4266
+ });
4267
+ }
4268
+
4269
+ // src/triggers/list.ts
4270
+ async function listBody11(opts) {
4271
+ const top = opts.top !== void 0 ? Number(opts.top) : void 0;
4272
+ const triggers = await apiErrors(
4273
+ async () => buildClient().triggers.list({
4274
+ applicationSlug: opts.app,
4275
+ connectionId: opts.connection !== void 0 ? Number(opts.connection) : void 0,
4276
+ status: opts.status,
4277
+ include: opts.include,
4278
+ top
4279
+ })
4280
+ );
4281
+ if (opts.include !== void 0) {
4282
+ progress(
4283
+ `--include ${opts.include} returns a single page of at most ${top ?? 100} rows (server bug 13003703309 \u2014 Take(top) with no Skip(offset) \u2014 this never paginates).`
4284
+ );
4285
+ }
4286
+ printOutput(triggers.map(summarizeTrigger));
4287
+ }
4288
+ function registerTriggersList(triggers) {
4289
+ const list = triggers.command("list").description("List trigger instances on the account.").option("--app <slug>", "Narrow to one application").option("--connection <id>", "Narrow to one connection").option("--status <status>", "enabled | disabled | errored").option(
4290
+ "--include <what>",
4291
+ "Pass 'workflow' to also surface designer-built triggers (single page \u2014 see Note)"
4292
+ ).option("--top <n>", "Page size (also the row cap under --include)");
4293
+ list.addHelpText(
4294
+ "after",
4295
+ "\nExamples:\n engini triggers list --status errored\n engini triggers list --include workflow --top 50\nNote: --include workflow returns one page only (server bug 13003703309), not the full list."
4296
+ );
4297
+ addUniversalOptions(list);
4298
+ list.action(async (opts, command) => {
4299
+ await runCommand(command, opts, false, () => listBody11(opts));
4300
+ });
4301
+ }
4302
+
4303
+ // src/triggers/status.ts
4304
+ async function toggleBody2(raw, enable) {
4305
+ const triggerId = parseTriggerId(raw);
4306
+ if (dryRun()) {
4307
+ printOutput(enable ? { would_enable: triggerId } : { would_disable: triggerId });
4308
+ return;
4309
+ }
4310
+ const trigger = await apiErrors(async () => {
4311
+ const client = buildClient();
4312
+ return enable ? client.triggers.enable(triggerId) : client.triggers.disable(triggerId);
4313
+ });
4314
+ printOutput(summarizeTrigger(trigger));
4315
+ }
4316
+ function register3(triggers, name, description) {
4317
+ const cmd = triggers.command(name).description(description).argument("[trigger_id]", "Trigger instance id (ti_\u2026)");
4318
+ cmd.addHelpText("after", `
4319
+ Examples:
4320
+ engini triggers ${name} ti_abc123`);
4321
+ addUniversalOptions(cmd, { mutating: true });
4322
+ cmd.action(async (raw, opts, command) => {
4323
+ await runCommand(command, opts, true, () => toggleBody2(raw, name === "enable"));
4324
+ });
4325
+ }
4326
+ function registerTriggerEnable(triggers) {
4327
+ register3(
4328
+ triggers,
4329
+ "enable",
4330
+ "Re-enable a trigger; clears its status_reason. A deleted connection can re-block it immediately."
4331
+ );
4332
+ }
4333
+ function registerTriggerDisable(triggers) {
4334
+ register3(triggers, "disable", "Stop a trigger capturing events. Not a delete \u2014 its event history stays.");
4335
+ }
4336
+
4337
+ // src/triggers/types.ts
4338
+ async function listBody12(opts) {
4339
+ const types = await apiErrors(
4340
+ async () => buildClient().triggers.types.list({
4341
+ applicationSlug: opts.app,
4342
+ search: opts.search,
4343
+ connectionId: opts.connection !== void 0 ? Number(opts.connection) : void 0
4344
+ })
4345
+ );
4346
+ printOutput(types);
4347
+ }
4348
+ async function getBody10(slug, opts) {
4349
+ if (slug === void 0 || slug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
4350
+ const type = await apiErrors(
4351
+ async () => buildClient().triggers.types.get(slug, { applicationSlug: opts.app })
4352
+ );
4353
+ printOutput(type);
4354
+ }
4355
+ function registerTriggerTypes(triggers) {
4356
+ const types = triggers.command("types").description("The catalog of trigger types you can create an instance from.").option("--app <slug>", "Narrow to one application").option("--search <q>", "Filter by name/description").option("--connection <id>", "Narrow to types that connection can actually serve");
4357
+ types.addHelpText(
4358
+ "after",
4359
+ "\nExamples:\n engini triggers types --app monday\n engini triggers types --connection 12 --json"
4360
+ );
4361
+ addUniversalOptions(types);
4362
+ types.action(async (opts, command) => {
4363
+ await runCommand(command, opts, false, () => listBody12(opts));
4364
+ });
4365
+ const get = types.command("get").description("One trigger type's config_schema, payload_schema and parameters.").argument("[trigger_slug]", "Trigger type slug").option("--app <slug>", "Disambiguate a slug shared by more than one application");
4366
+ get.addHelpText("after", "\nExamples:\n engini triggers types get monday_item_created --json");
4367
+ addUniversalOptions(get);
4368
+ get.action(
4369
+ async (slug, opts, command) => {
4370
+ await runCommand(command, opts, false, () => getBody10(slug, opts));
4371
+ }
4372
+ );
4373
+ }
4374
+
4375
+ // src/triggers/index.ts
4376
+ function registerTriggers(program) {
4377
+ program.enablePositionalOptions();
4378
+ const triggers = program.command("triggers").description("Trigger instances, their event log/stream, and their delivery destinations.");
4379
+ registerTriggerTypes(triggers);
4380
+ registerTriggersList(triggers);
4381
+ registerTriggersGet(triggers);
4382
+ registerTriggerCreate(triggers);
4383
+ registerTriggerEnable(triggers);
4384
+ registerTriggerDisable(triggers);
4385
+ registerTriggerDelete(triggers);
4386
+ registerTriggerEvents(triggers);
4387
+ registerTriggerListen(triggers);
4388
+ registerTriggerDestinations(triggers);
4389
+ }
4390
+
3232
4391
  // src/whoami.ts
3233
4392
  function summary5(me) {
3234
4393
  return {
@@ -3268,6 +4427,8 @@ function buildProgram() {
3268
4427
  registerConnections(program);
3269
4428
  registerToolsets(program);
3270
4429
  registerMcp(program);
4430
+ registerOpa(program);
4431
+ registerTriggers(program);
3271
4432
  installHelp(program);
3272
4433
  return program;
3273
4434
  }