@engini/cli 0.19.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 +701 -1
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -37,6 +37,11 @@ engini connect [<app>] # create a connection (interactive / a
37
37
  engini connections list | get # inspect connections
38
38
  engini connections create | delete | check | refresh | objects | select-objects # primitives
39
39
  engini connections sign-in-url | oauth-complete # OAuth2 start / finish primitives
40
+ engini triggers types | types get # the catalog of what can be triggered
41
+ engini triggers list | get | create | enable | disable | delete # trigger instances
42
+ engini triggers events | events get | events replay # the event LOG (real delivery state)
43
+ engini triggers listen # the live event STREAM (local dev only)
44
+ engini triggers destinations set | add | list | show | enable | rm | rotate-secret
40
45
  ```
41
46
 
42
47
  The `mcp` group maintains the MCP endpoints Engini **exposes** (not the
@@ -58,6 +63,19 @@ unchanged; a supplied one replaces the whole set — it never merges), so
58
63
  resulting, plus explicit added/removed lists) rather than just echoing the
59
64
  outgoing request.
60
65
 
66
+ A trigger instance (`ti_…`) is an entity, not a workflow step — created from a
67
+ trigger type against a connection. There are two ways to receive its events, and
68
+ they need opposite code: a **destination** is production delivery (signed via
69
+ `destinations`); `listen` is a live SSE stream for local dev only (unsigned, no
70
+ delivery guarantees). `events` is the historical log with real delivery state;
71
+ `listen`'s `delivery` field is always the literal `"pending"` — the two are
72
+ deliberately never merged under one `--follow` flag. `listen` prints one compact
73
+ JSON line per event (not gated by `--json`, since a multi-line pretty payload
74
+ isn't a parseable stream), and `--forward <url> [--sign-with <secret>]` rehearses
75
+ the production delivery path against a local receiver. `triggers test` isn't
76
+ implemented yet — the server endpoint (`POST /v1/triggers/{id}/test`) doesn't
77
+ exist.
78
+
61
79
  Run `engini <command> --help` for details and examples on any command.
62
80
 
63
81
  `connect <app>` discovers the app's authentication methods, collects credentials
package/dist/cli.js CHANGED
@@ -390,6 +390,7 @@ import {
390
390
  EnginiOpaApplicationAmbiguousError,
391
391
  EnginiTimeoutError,
392
392
  EnginiToolsetNotFoundError,
393
+ EnginiTriggerGapError,
393
394
  EnginiValidationError
394
395
  } from "@engini/sdk";
395
396
 
@@ -441,7 +442,7 @@ function saveConfig(config, path = configPath()) {
441
442
  }
442
443
 
443
444
  // src/version.ts
444
- var VERSION = true ? "0.19.0" : "0.0.0";
445
+ var VERSION = true ? "0.20.0" : "0.0.0";
445
446
 
446
447
  // src/http.ts
447
448
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -469,6 +470,7 @@ function exitForError(err) {
469
470
  if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
470
471
  if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
471
472
  if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
473
+ if (err instanceof EnginiTriggerGapError) return 4 /* NOT_FOUND */;
472
474
  if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
473
475
  if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
474
476
  if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
@@ -1611,6 +1613,33 @@ ON-PREMISE AGENTS
1611
1613
  Note: an agent polls Engini, so anything that "talks to" it waits for its next poll.
1612
1614
  A settings update on an offline agent still stores - the response says applied_to_agent: false.
1613
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
+
1614
1643
  OUTPUT & EXIT CODES
1615
1644
  Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
1616
1645
  JSON with --json. Universal flags on every command:
@@ -3689,6 +3718,676 @@ function registerToolsets(program) {
3689
3718
  registerToolsetsDelete(toolsets);
3690
3719
  }
3691
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
+
3692
4391
  // src/whoami.ts
3693
4392
  function summary5(me) {
3694
4393
  return {
@@ -3729,6 +4428,7 @@ function buildProgram() {
3729
4428
  registerToolsets(program);
3730
4429
  registerMcp(program);
3731
4430
  registerOpa(program);
4431
+ registerTriggers(program);
3732
4432
  installHelp(program);
3733
4433
  return program;
3734
4434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.19.0",
3
+ "version": "0.20.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.19.0",
29
+ "@engini/sdk": "^0.20.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },