@engini/cli 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/cli.js +744 -11
- 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.
|
|
445
|
+
var VERSION = true ? "0.21.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 */;
|
|
@@ -709,13 +711,15 @@ async function connectBody(application, opts) {
|
|
|
709
711
|
return;
|
|
710
712
|
}
|
|
711
713
|
const name = await resolveName(opts.name, application);
|
|
712
|
-
const
|
|
714
|
+
const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, timing) : { fields: await collectFields(method, application, opts.field) };
|
|
713
715
|
progress(`Creating connection '${name}'\u2026`);
|
|
714
716
|
const created = await client.connections.create(
|
|
715
717
|
application,
|
|
716
718
|
name,
|
|
717
719
|
method.authenticationId,
|
|
718
|
-
fields
|
|
720
|
+
credentials.fields,
|
|
721
|
+
// Present only for OAuth methods; a non-OAuth create has no sign-in to point at.
|
|
722
|
+
credentials.state ? { oauthState: credentials.state } : {}
|
|
719
723
|
);
|
|
720
724
|
const connectionId = created.connectionId;
|
|
721
725
|
progress(`Checking connection ${connectionId}\u2026`);
|
|
@@ -769,9 +773,22 @@ async function chooseAuth(methods, auth, application) {
|
|
|
769
773
|
if (methods.length === 1) return methods[0];
|
|
770
774
|
if (isInteractive()) {
|
|
771
775
|
for (const m of methods) {
|
|
772
|
-
|
|
776
|
+
const marker = m.isDefault ? " [default]" : "";
|
|
777
|
+
console.error(
|
|
778
|
+
` ${m.authenticationId}: ${m.authenticationName} (${m.authenticationType})${marker}`
|
|
779
|
+
);
|
|
780
|
+
const description = clean(m.description);
|
|
781
|
+
if (description) console.error(` ${description}`);
|
|
782
|
+
const helpUrl = methodHelpUrl(m);
|
|
783
|
+
if (helpUrl) console.error(` ${helpUrl}`);
|
|
773
784
|
}
|
|
774
|
-
const
|
|
785
|
+
const preferred = methods.find((m) => m.isDefault);
|
|
786
|
+
const answer = await promptText(
|
|
787
|
+
"Choose an authentication method id",
|
|
788
|
+
preferred ? String(preferred.authenticationId) : ""
|
|
789
|
+
);
|
|
790
|
+
if (answer.trim() === "") fail(2 /* USAGE */, "Choose an authentication method id.");
|
|
791
|
+
const id = Number(answer);
|
|
775
792
|
const chosen = byId.get(id);
|
|
776
793
|
if (!chosen) fail(2 /* USAGE */, `No authentication method with id ${id}.`);
|
|
777
794
|
return chosen;
|
|
@@ -856,14 +873,14 @@ async function resolveObjects(objs, connectionId, application) {
|
|
|
856
873
|
async function oauthFieldsFor(client, application, method, oauthState, timing) {
|
|
857
874
|
if (oauthState) {
|
|
858
875
|
const token = await pollAccessToken(client, oauthState, timing);
|
|
859
|
-
return oauthFields(token);
|
|
876
|
+
return { fields: oauthFields(token), state: oauthState };
|
|
860
877
|
}
|
|
861
878
|
const resp = await client.connections.getSignInUrl(application, method.authenticationId);
|
|
862
879
|
if (isTty() && timing.wait) {
|
|
863
880
|
openBrowser(resp.signInUrl);
|
|
864
881
|
progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
|
|
865
882
|
const token = await pollAccessToken(client, resp.state, timing);
|
|
866
|
-
return oauthFields(token);
|
|
883
|
+
return { fields: oauthFields(token), state: resp.state };
|
|
867
884
|
}
|
|
868
885
|
return need({
|
|
869
886
|
need: "oauth",
|
|
@@ -884,10 +901,21 @@ function methodSummary(m) {
|
|
|
884
901
|
authentication_id: m.authenticationId,
|
|
885
902
|
authentication_type: m.authenticationType,
|
|
886
903
|
authentication_name: m.authenticationName,
|
|
904
|
+
description: clean(m.description),
|
|
905
|
+
// Boolean(), not the raw value: the generated type declares isDefault non-optional and
|
|
906
|
+
// hey-api does no runtime validation, so against a server that omits it this is undefined -
|
|
907
|
+
// and JSON.stringify drops undefined keys entirely, leaving an agent parsing need:auth with
|
|
908
|
+
// description: null, help_url: null and no is_default key at all. All three normalise now.
|
|
909
|
+
is_default: Boolean(m.isDefault),
|
|
910
|
+
help_url: methodHelpUrl(m),
|
|
887
911
|
requires_oauth: m.requiresOAuthSignIn,
|
|
888
912
|
fields: m.connectionFields.map(fieldSummary)
|
|
889
913
|
};
|
|
890
914
|
}
|
|
915
|
+
function methodHelpUrl(m) {
|
|
916
|
+
const value = m.helpUrl;
|
|
917
|
+
return typeof value === "string" && value.trim() !== "" ? value : null;
|
|
918
|
+
}
|
|
891
919
|
function fieldSummary(f) {
|
|
892
920
|
return {
|
|
893
921
|
field_name: f.fieldName,
|
|
@@ -1205,7 +1233,9 @@ async function oauthCompleteBody(application, opts) {
|
|
|
1205
1233
|
interval: Number(opts.pollInterval ?? 2)
|
|
1206
1234
|
});
|
|
1207
1235
|
progress(`Creating connection '${name}'\u2026`);
|
|
1208
|
-
return client.connections.create(application, name, auth, oauthFields(token)
|
|
1236
|
+
return client.connections.create(application, name, auth, oauthFields(token), {
|
|
1237
|
+
oauthState: opts.state
|
|
1238
|
+
});
|
|
1209
1239
|
});
|
|
1210
1240
|
printOutput(summary2(conn));
|
|
1211
1241
|
}
|
|
@@ -1412,10 +1442,11 @@ async function updateBody(idRaw, opts) {
|
|
|
1412
1442
|
if (opts.description !== void 0) patch.description = opts.description;
|
|
1413
1443
|
if (opts.field !== void 0) patch.fields = parseFields(opts.field);
|
|
1414
1444
|
if (opts.metadata !== void 0) patch.metadata = parseFields(opts.metadata);
|
|
1445
|
+
if (opts.oauthState !== void 0) patch.oauthState = opts.oauthState;
|
|
1415
1446
|
if (Object.keys(patch).length === 0) {
|
|
1416
1447
|
fail(
|
|
1417
1448
|
2 /* USAGE */,
|
|
1418
|
-
"Nothing to update. Supply at least one of --name, --description, --field, --metadata."
|
|
1449
|
+
"Nothing to update. Supply at least one of --name, --description, --field, --metadata, --oauth-state."
|
|
1419
1450
|
);
|
|
1420
1451
|
}
|
|
1421
1452
|
if (dryRun()) {
|
|
@@ -1428,6 +1459,7 @@ async function updateBody(idRaw, opts) {
|
|
|
1428
1459
|
Object.entries(patch.fields).map(([k, v]) => [k, maskSecret(v)])
|
|
1429
1460
|
),
|
|
1430
1461
|
metadata: patch.metadata ?? null,
|
|
1462
|
+
oauth_state: patch.oauthState ?? null,
|
|
1431
1463
|
// Loud on purpose: this is the field-loss trap.
|
|
1432
1464
|
replaces_entire_fields_map: patch.fields !== void 0,
|
|
1433
1465
|
replaces_entire_metadata_map: patch.metadata !== void 0
|
|
@@ -1442,10 +1474,13 @@ async function updateBody(idRaw, opts) {
|
|
|
1442
1474
|
printOutput(summary4(conn));
|
|
1443
1475
|
}
|
|
1444
1476
|
function registerConnectionsUpdate(connections) {
|
|
1445
|
-
const cmd = connections.command("update").description("Update a connection's name, description, credential fields, or metadata.").argument("[connection_id]", "Connection id").option("--name <name>", "New connection name").option("--description <text>", "New description").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--metadata <spec>", "Metadata entry: key=value (repeatable)", collect)
|
|
1477
|
+
const cmd = connections.command("update").description("Update a connection's name, description, credential fields, or metadata.").argument("[connection_id]", "Connection id").option("--name <name>", "New connection name").option("--description <text>", "New description").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--metadata <spec>", "Metadata entry: key=value (repeatable)", collect).option(
|
|
1478
|
+
"--oauth-state <state>",
|
|
1479
|
+
"Sign-in state proving a credential change on an OAuth2 connection"
|
|
1480
|
+
);
|
|
1446
1481
|
cmd.addHelpText(
|
|
1447
1482
|
"after",
|
|
1448
|
-
"\nExamples:\n engini connections update 481 --name 'prod key'\n engini connections update 481 --field apiKey=sk-new --dry-run\n engini connections update 481 --field apiKey=sk-new\n\nWARNING: --field and --metadata REPLACE the entire map \u2014 they do not merge.\nPassing one --field clears every other field on the connection. Read the\ncurrent values with `engini connections get <id>` and pass them all, or\npreview with --dry-run first (secrets are masked in the preview)."
|
|
1483
|
+
"\nExamples:\n engini connections update 481 --name 'prod key'\n engini connections update 481 --field apiKey=sk-new --dry-run\n engini connections update 481 --field apiKey=sk-new\n engini connections update 481 --field RefreshToken=rt-new --oauth-state st-1\n engini connections update 481 --oauth-state st-1 # re-authenticate in place,\n # no --field needed\n\nWARNING: --field and --metadata REPLACE the entire map \u2014 they do not merge.\nPassing one --field clears every other field on the connection. Read the\ncurrent values with `engini connections get <id>` and pass them all, or\npreview with --dry-run first (secrets are masked in the preview).\n\nOn an OAuth2 connection, changing ApiKey, RefreshToken or ExternalOrgId needs\n--oauth-state from a fresh `engini connect` sign-in: the server derives those\nfrom its own record and will not take them from a caller. Renames and edits to\nBaseUrl or any Key{N} setting need no state."
|
|
1449
1484
|
);
|
|
1450
1485
|
addUniversalOptions(cmd, { mutating: true });
|
|
1451
1486
|
cmd.action(async (idRaw, opts, command) => {
|
|
@@ -1611,6 +1646,33 @@ ON-PREMISE AGENTS
|
|
|
1611
1646
|
Note: an agent polls Engini, so anything that "talks to" it waits for its next poll.
|
|
1612
1647
|
A settings update on an offline agent still stores - the response says applied_to_agent: false.
|
|
1613
1648
|
|
|
1649
|
+
TRIGGERS
|
|
1650
|
+
A trigger instance (ti_\u2026) is an entity, not a workflow step - created from a trigger
|
|
1651
|
+
type (a catalog slug) against a connection.
|
|
1652
|
+
triggers types [--app <slug>] [--search <q>] [--connection <id>] List the catalog.
|
|
1653
|
+
triggers types get <trigger_slug> [--app <slug>] config_schema/payload_schema/parameters.
|
|
1654
|
+
triggers list [--app <s>] [--connection <id>] [--status <s>] [--include workflow] [--top <n>]
|
|
1655
|
+
triggers get <trigger_id> Status, schedule, last-error detail.
|
|
1656
|
+
triggers create <trigger_slug> --connection <name|id> [--config <json>] [--every <n><s|m|h|d>]
|
|
1657
|
+
[--weekdays <spec>] [--window <HH:mm-HH:mm>] [--listen <col>...] [--destination <name>]
|
|
1658
|
+
[--dedupe-window-hours <n>]
|
|
1659
|
+
triggers enable <id> | triggers disable <id> Toggle capture; not a delete.
|
|
1660
|
+
triggers delete <id> [--force] Permanent; deletes event history too.
|
|
1661
|
+
triggers events <trigger_id> [--limit <n>] The LOG - real delivery state.
|
|
1662
|
+
triggers events get <event_id> One event plus its delivery attempts.
|
|
1663
|
+
triggers events replay <event_id> Re-deliver a captured event.
|
|
1664
|
+
triggers listen [--trigger <id>] [--slug <s>] [--app <s>] [--since <event_id>] [--no-resume]
|
|
1665
|
+
[--forward <url>] [--sign-with <secret>]
|
|
1666
|
+
Note: 'events' is the historical log (real delivery state); 'listen' is the live stream,
|
|
1667
|
+
whose delivery field is always "pending" - they are never merged under one flag.
|
|
1668
|
+
triggers destinations set <url> [--name <n>] [--max-failures <n>] Account default.
|
|
1669
|
+
triggers destinations add <name> <url> [--default] [--max-failures <n>]
|
|
1670
|
+
triggers destinations list | triggers destinations show <name>
|
|
1671
|
+
triggers destinations enable <name> Recover an auto-disabled destination.
|
|
1672
|
+
triggers destinations rm <name> [--reassign <name>] [--force]
|
|
1673
|
+
triggers destinations rotate-secret <name> [--force]
|
|
1674
|
+
Note: add/rotate-secret/set(create) print the signing secret in the clear, once.
|
|
1675
|
+
|
|
1614
1676
|
OUTPUT & EXIT CODES
|
|
1615
1677
|
Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
|
|
1616
1678
|
JSON with --json. Universal flags on every command:
|
|
@@ -3689,6 +3751,676 @@ function registerToolsets(program) {
|
|
|
3689
3751
|
registerToolsetsDelete(toolsets);
|
|
3690
3752
|
}
|
|
3691
3753
|
|
|
3754
|
+
// src/triggers/create.ts
|
|
3755
|
+
import { EnginiNotFoundError as EnginiNotFoundError2 } from "@engini/sdk";
|
|
3756
|
+
|
|
3757
|
+
// src/triggers/shared.ts
|
|
3758
|
+
var TRIGGER_ID_RE = /^ti_[A-Za-z0-9]+$/;
|
|
3759
|
+
function parseTriggerId(raw) {
|
|
3760
|
+
if (raw === void 0 || raw === "") fail(2 /* USAGE */, "A trigger id is required.");
|
|
3761
|
+
if (!TRIGGER_ID_RE.test(raw)) {
|
|
3762
|
+
fail(2 /* USAGE */, `'${raw}' is not a valid trigger id (expected 'ti_\u2026').`);
|
|
3763
|
+
}
|
|
3764
|
+
return raw;
|
|
3765
|
+
}
|
|
3766
|
+
function parseDestName(raw) {
|
|
3767
|
+
if (raw === void 0 || raw === "") fail(2 /* USAGE */, "A destination name is required.");
|
|
3768
|
+
return raw;
|
|
3769
|
+
}
|
|
3770
|
+
function collect3(value, previous = []) {
|
|
3771
|
+
return [...previous, value];
|
|
3772
|
+
}
|
|
3773
|
+
function parseConfig(raw) {
|
|
3774
|
+
if (raw === void 0) return void 0;
|
|
3775
|
+
try {
|
|
3776
|
+
return JSON.parse(raw);
|
|
3777
|
+
} catch {
|
|
3778
|
+
fail(2 /* USAGE */, `--config is not valid JSON: '${raw}'.`);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
var WEEKDAY_NAMES = {
|
|
3782
|
+
sun: 0,
|
|
3783
|
+
mon: 1,
|
|
3784
|
+
tue: 2,
|
|
3785
|
+
wed: 3,
|
|
3786
|
+
thu: 4,
|
|
3787
|
+
fri: 5,
|
|
3788
|
+
sat: 6
|
|
3789
|
+
};
|
|
3790
|
+
function parseWeekdays(raw) {
|
|
3791
|
+
if (raw === void 0) return void 0;
|
|
3792
|
+
const days = /* @__PURE__ */ new Set();
|
|
3793
|
+
for (const part of raw.split(",")) {
|
|
3794
|
+
const token = part.trim().toLowerCase();
|
|
3795
|
+
if (token === "") continue;
|
|
3796
|
+
const range = token.split("-");
|
|
3797
|
+
if (range.length === 2) {
|
|
3798
|
+
const start = WEEKDAY_NAMES[range[0]];
|
|
3799
|
+
const end = WEEKDAY_NAMES[range[1]];
|
|
3800
|
+
if (start === void 0 || end === void 0) {
|
|
3801
|
+
fail(2 /* USAGE */, `--weekdays has an unrecognised day in '${token}'.`);
|
|
3802
|
+
}
|
|
3803
|
+
for (let i = start; ; i = (i + 1) % 7) {
|
|
3804
|
+
days.add(i);
|
|
3805
|
+
if (i === end) break;
|
|
3806
|
+
}
|
|
3807
|
+
} else {
|
|
3808
|
+
const day = WEEKDAY_NAMES[token];
|
|
3809
|
+
if (day === void 0) fail(2 /* USAGE */, `--weekdays has an unrecognised day '${token}'.`);
|
|
3810
|
+
days.add(day);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
return [...days].sort((a, b) => a - b);
|
|
3814
|
+
}
|
|
3815
|
+
function parseEvery(raw) {
|
|
3816
|
+
if (raw === void 0) return void 0;
|
|
3817
|
+
const match = /^(\d+)(s|m|h|d)$/.exec(raw.trim());
|
|
3818
|
+
if (!match) {
|
|
3819
|
+
fail(2 /* USAGE */, `--every must look like '15m', '2h' or '1d', got '${raw}'.`);
|
|
3820
|
+
}
|
|
3821
|
+
const interval = Number(match[1]);
|
|
3822
|
+
const unit = match[2];
|
|
3823
|
+
const frequency = unit === "s" ? "seconds" : unit === "m" ? "minute" : unit === "h" ? "hour" : "day";
|
|
3824
|
+
return { frequency, interval };
|
|
3825
|
+
}
|
|
3826
|
+
var WINDOW_RE = /^(\d{2}:\d{2})-(\d{2}:\d{2})$/;
|
|
3827
|
+
function parseWindow(raw) {
|
|
3828
|
+
if (raw === void 0) return void 0;
|
|
3829
|
+
const match = WINDOW_RE.exec(raw.trim());
|
|
3830
|
+
if (!match) {
|
|
3831
|
+
fail(2 /* USAGE */, `--window must look like '09:00-17:00', got '${raw}'.`);
|
|
3832
|
+
}
|
|
3833
|
+
return [{ start_hour: match[1], end_hour: match[2] }];
|
|
3834
|
+
}
|
|
3835
|
+
function parseSchedule(flags) {
|
|
3836
|
+
if (flags.every === void 0 && flags.weekdays === void 0 && flags.window === void 0) {
|
|
3837
|
+
return void 0;
|
|
3838
|
+
}
|
|
3839
|
+
const every = parseEvery(flags.every);
|
|
3840
|
+
const weekDays = parseWeekdays(flags.weekdays);
|
|
3841
|
+
const timeFrames = parseWindow(flags.window);
|
|
3842
|
+
return {
|
|
3843
|
+
frequency: every?.frequency ?? (weekDays !== void 0 ? "week" : "day"),
|
|
3844
|
+
interval: every?.interval ?? 1,
|
|
3845
|
+
...weekDays !== void 0 ? { week_days: weekDays } : {},
|
|
3846
|
+
...timeFrames !== void 0 ? { time_frames: timeFrames } : {}
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
function summarizeTrigger(t) {
|
|
3850
|
+
return {
|
|
3851
|
+
id: clean(t.id),
|
|
3852
|
+
trigger_slug: clean(t.trigger_slug),
|
|
3853
|
+
kind: t.kind,
|
|
3854
|
+
status: t.status,
|
|
3855
|
+
status_reason: clean(t.status_reason),
|
|
3856
|
+
last_event_at: clean(t.last_event_at),
|
|
3857
|
+
next_run_at: clean(t.next_run_at)
|
|
3858
|
+
};
|
|
3859
|
+
}
|
|
3860
|
+
function summarizeDestination(d) {
|
|
3861
|
+
return {
|
|
3862
|
+
id: d.id,
|
|
3863
|
+
name: d.name,
|
|
3864
|
+
url: d.url,
|
|
3865
|
+
is_default: clean(d.is_default),
|
|
3866
|
+
status: d.status,
|
|
3867
|
+
consecutive_failures: clean(d.consecutive_failures),
|
|
3868
|
+
max_consecutive_failures: clean(d.max_consecutive_failures),
|
|
3869
|
+
last_delivery_at: clean(d.last_delivery_at),
|
|
3870
|
+
last_failure_at: clean(d.last_failure_at),
|
|
3871
|
+
last_failure: clean(d.last_failure)
|
|
3872
|
+
};
|
|
3873
|
+
}
|
|
3874
|
+
function summarizeEvent(e) {
|
|
3875
|
+
return {
|
|
3876
|
+
id: clean(e.id),
|
|
3877
|
+
trigger_id: clean(e.trigger_id),
|
|
3878
|
+
occurred_at: clean(e.occurred_at),
|
|
3879
|
+
payload: e.payload,
|
|
3880
|
+
payload_truncated: clean(e.payload_truncated),
|
|
3881
|
+
payload_hash: clean(e.payload_hash),
|
|
3882
|
+
delivery: e.delivery
|
|
3883
|
+
};
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
// src/triggers/create.ts
|
|
3887
|
+
function connectionRef(raw) {
|
|
3888
|
+
return /^\d+$/.test(raw) ? { connectionId: Number(raw) } : { connectionName: raw };
|
|
3889
|
+
}
|
|
3890
|
+
async function hasAccountDefaultDestination() {
|
|
3891
|
+
try {
|
|
3892
|
+
await buildClient().triggers.destination.get();
|
|
3893
|
+
return true;
|
|
3894
|
+
} catch (err) {
|
|
3895
|
+
if (err instanceof EnginiNotFoundError2) return false;
|
|
3896
|
+
throw err;
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
async function createBody4(triggerSlug, opts) {
|
|
3900
|
+
if (triggerSlug === void 0 || triggerSlug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
|
|
3901
|
+
if (opts.connection === void 0 || opts.connection === "") {
|
|
3902
|
+
fail(2 /* USAGE */, "--connection is required (a connection name or id).");
|
|
3903
|
+
}
|
|
3904
|
+
const config = parseConfig(opts.config);
|
|
3905
|
+
const schedule = parseSchedule(opts);
|
|
3906
|
+
const dedupeWindowHours = opts.dedupeWindowHours !== void 0 ? Number(opts.dedupeWindowHours) : void 0;
|
|
3907
|
+
if (dryRun()) {
|
|
3908
|
+
printOutput({
|
|
3909
|
+
would_create: {
|
|
3910
|
+
trigger_slug: triggerSlug,
|
|
3911
|
+
connection: opts.connection,
|
|
3912
|
+
config,
|
|
3913
|
+
schedule,
|
|
3914
|
+
listen_columns: opts.listen,
|
|
3915
|
+
destination: opts.destination,
|
|
3916
|
+
dedupe_window_hours: dedupeWindowHours
|
|
3917
|
+
}
|
|
3918
|
+
});
|
|
3919
|
+
return;
|
|
3920
|
+
}
|
|
3921
|
+
let destinationId;
|
|
3922
|
+
if (opts.destination !== void 0) {
|
|
3923
|
+
const dest = await apiErrors(async () => buildClient().triggers.destinations.get(opts.destination));
|
|
3924
|
+
destinationId = dest.id;
|
|
3925
|
+
}
|
|
3926
|
+
const trigger = await apiErrors(
|
|
3927
|
+
async () => buildClient().triggers.create({
|
|
3928
|
+
triggerSlug,
|
|
3929
|
+
...connectionRef(opts.connection),
|
|
3930
|
+
config,
|
|
3931
|
+
schedule,
|
|
3932
|
+
listenColumns: opts.listen,
|
|
3933
|
+
destinationId,
|
|
3934
|
+
dedupeWindowHours
|
|
3935
|
+
})
|
|
3936
|
+
);
|
|
3937
|
+
if (opts.destination === void 0) {
|
|
3938
|
+
const hasDefault = await apiErrors(hasAccountDefaultDestination);
|
|
3939
|
+
if (!hasDefault) {
|
|
3940
|
+
progress(
|
|
3941
|
+
"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>`."
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
printOutput({
|
|
3946
|
+
...summarizeTrigger(trigger),
|
|
3947
|
+
destination_id: clean(trigger.destination_id),
|
|
3948
|
+
schedule: trigger.schedule ?? null
|
|
3949
|
+
});
|
|
3950
|
+
}
|
|
3951
|
+
function registerTriggerCreate(triggers) {
|
|
3952
|
+
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");
|
|
3953
|
+
create.addHelpText(
|
|
3954
|
+
"after",
|
|
3955
|
+
"\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"
|
|
3956
|
+
);
|
|
3957
|
+
addUniversalOptions(create, { mutating: true });
|
|
3958
|
+
create.action(async (triggerSlug, opts, command) => {
|
|
3959
|
+
await runCommand(command, opts, true, () => createBody4(triggerSlug, opts));
|
|
3960
|
+
});
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
// src/triggers/delete.ts
|
|
3964
|
+
async function deleteBody4(raw, opts) {
|
|
3965
|
+
const triggerId = parseTriggerId(raw);
|
|
3966
|
+
if (dryRun()) {
|
|
3967
|
+
printOutput({ would_delete: triggerId });
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
await confirmOrFail(
|
|
3971
|
+
`Permanently delete trigger ${triggerId}? Its event history is deleted with it.`,
|
|
3972
|
+
{ force: Boolean(opts.force) }
|
|
3973
|
+
);
|
|
3974
|
+
await apiErrors(async () => buildClient().triggers.delete(triggerId));
|
|
3975
|
+
printOutput({ deleted: triggerId });
|
|
3976
|
+
}
|
|
3977
|
+
function registerTriggerDelete(triggers) {
|
|
3978
|
+
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");
|
|
3979
|
+
cmd.addHelpText("after", "\nExamples:\n engini triggers delete ti_abc123 --force");
|
|
3980
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
3981
|
+
cmd.action(
|
|
3982
|
+
async (raw, opts, command) => {
|
|
3983
|
+
await runCommand(command, opts, true, () => deleteBody4(raw, opts));
|
|
3984
|
+
}
|
|
3985
|
+
);
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
// src/triggers/destinations.ts
|
|
3989
|
+
var SECRET_NOTE = "Shown once \u2014 store it now.";
|
|
3990
|
+
function withSecret(created) {
|
|
3991
|
+
return { ...summarizeDestination(created.destination), secret: created.signing_secret, note: SECRET_NOTE };
|
|
3992
|
+
}
|
|
3993
|
+
function renderPutResult(result) {
|
|
3994
|
+
return "destination" in result ? withSecret(result) : summarizeDestination(result);
|
|
3995
|
+
}
|
|
3996
|
+
async function setBody3(url, opts) {
|
|
3997
|
+
if (url === void 0 || url === "") fail(2 /* USAGE */, "A destination url is required.");
|
|
3998
|
+
if (dryRun()) {
|
|
3999
|
+
printOutput({ would_set_default: { url, name: opts.name } });
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
const result = await apiErrors(
|
|
4003
|
+
async () => buildClient().triggers.destination.put({
|
|
4004
|
+
url,
|
|
4005
|
+
name: opts.name,
|
|
4006
|
+
maxConsecutiveFailures: opts.maxFailures !== void 0 ? Number(opts.maxFailures) : void 0
|
|
4007
|
+
})
|
|
4008
|
+
);
|
|
4009
|
+
printOutput(renderPutResult(result));
|
|
4010
|
+
}
|
|
4011
|
+
async function addBody(name, url, opts) {
|
|
4012
|
+
if (name === void 0 || name === "") fail(2 /* USAGE */, "A destination name is required.");
|
|
4013
|
+
if (url === void 0 || url === "") fail(2 /* USAGE */, "A destination url is required.");
|
|
4014
|
+
if (dryRun()) {
|
|
4015
|
+
printOutput({ would_add: { name, url, is_default: Boolean(opts.default) } });
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
const created = await apiErrors(
|
|
4019
|
+
async () => buildClient().triggers.destinations.create({
|
|
4020
|
+
name,
|
|
4021
|
+
url,
|
|
4022
|
+
isDefault: opts.default,
|
|
4023
|
+
maxConsecutiveFailures: opts.maxFailures !== void 0 ? Number(opts.maxFailures) : void 0
|
|
4024
|
+
})
|
|
4025
|
+
);
|
|
4026
|
+
printOutput(withSecret(created));
|
|
4027
|
+
}
|
|
4028
|
+
async function listBody9() {
|
|
4029
|
+
const destinations = await apiErrors(async () => buildClient().triggers.destinations.list());
|
|
4030
|
+
printOutput(destinations.map(summarizeDestination));
|
|
4031
|
+
}
|
|
4032
|
+
async function showBody(raw) {
|
|
4033
|
+
const name = parseDestName(raw);
|
|
4034
|
+
const destination = await apiErrors(async () => buildClient().triggers.destinations.get(name));
|
|
4035
|
+
printOutput(summarizeDestination(destination));
|
|
4036
|
+
}
|
|
4037
|
+
async function enableBody(raw) {
|
|
4038
|
+
const name = parseDestName(raw);
|
|
4039
|
+
if (dryRun()) {
|
|
4040
|
+
printOutput({ would_enable: name });
|
|
4041
|
+
return;
|
|
4042
|
+
}
|
|
4043
|
+
const destination = await apiErrors(
|
|
4044
|
+
async () => buildClient().triggers.destinations.update(name, { status: "active" })
|
|
4045
|
+
);
|
|
4046
|
+
printOutput(summarizeDestination(destination));
|
|
4047
|
+
}
|
|
4048
|
+
async function rmBody(raw, opts) {
|
|
4049
|
+
const name = parseDestName(raw);
|
|
4050
|
+
if (dryRun()) {
|
|
4051
|
+
printOutput({ would_delete: name, reassign_to: opts.reassign ?? null });
|
|
4052
|
+
return;
|
|
4053
|
+
}
|
|
4054
|
+
await confirmOrFail(`Delete destination '${name}'?`, { force: Boolean(opts.force) });
|
|
4055
|
+
await apiErrors(async () => buildClient().triggers.destinations.delete(name, { reassignTo: opts.reassign }));
|
|
4056
|
+
printOutput({ deleted: name });
|
|
4057
|
+
}
|
|
4058
|
+
async function rotateBody2(raw, opts) {
|
|
4059
|
+
const name = parseDestName(raw);
|
|
4060
|
+
if (dryRun()) {
|
|
4061
|
+
printOutput({ would_rotate_secret_for: name });
|
|
4062
|
+
return;
|
|
4063
|
+
}
|
|
4064
|
+
await confirmOrFail(
|
|
4065
|
+
`Rotate the signing secret for '${name}'? Deliveries signed with the old secret stop verifying immediately \u2014 deploy the new secret to the receiver first.`,
|
|
4066
|
+
{ force: Boolean(opts.force) }
|
|
4067
|
+
);
|
|
4068
|
+
const created = await apiErrors(async () => buildClient().triggers.destinations.rotateSecret(name));
|
|
4069
|
+
printOutput(withSecret(created));
|
|
4070
|
+
}
|
|
4071
|
+
function registerTriggerDestinations(triggers) {
|
|
4072
|
+
const destinations = triggers.command("destinations").description("Registered HTTPS delivery endpoints for trigger events.");
|
|
4073
|
+
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)");
|
|
4074
|
+
set.addHelpText("after", "\nExamples:\n engini triggers destinations set https://hooks.example.com/engini");
|
|
4075
|
+
addUniversalOptions(set, { mutating: true });
|
|
4076
|
+
set.action(async (url, opts, command) => {
|
|
4077
|
+
await runCommand(command, opts, true, () => setBody3(url, opts));
|
|
4078
|
+
});
|
|
4079
|
+
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)");
|
|
4080
|
+
add.addHelpText(
|
|
4081
|
+
"after",
|
|
4082
|
+
"\nExamples:\n engini triggers destinations add billing https://hooks.example.com/billing --default"
|
|
4083
|
+
);
|
|
4084
|
+
addUniversalOptions(add, { mutating: true });
|
|
4085
|
+
add.action(
|
|
4086
|
+
async (name, url, opts, command) => {
|
|
4087
|
+
await runCommand(command, opts, true, () => addBody(name, url, opts));
|
|
4088
|
+
}
|
|
4089
|
+
);
|
|
4090
|
+
const list = destinations.command("list").description("List every destination on the account.");
|
|
4091
|
+
list.addHelpText("after", "\nExamples:\n engini triggers destinations list --json");
|
|
4092
|
+
addUniversalOptions(list);
|
|
4093
|
+
list.action(async (opts, command) => {
|
|
4094
|
+
await runCommand(command, opts, false, listBody9);
|
|
4095
|
+
});
|
|
4096
|
+
const show = destinations.command("show").description("One destination's failure counters and status.").argument("[name]", "Destination name");
|
|
4097
|
+
show.addHelpText("after", "\nExamples:\n engini triggers destinations show billing");
|
|
4098
|
+
addUniversalOptions(show);
|
|
4099
|
+
show.action(async (raw, opts, command) => {
|
|
4100
|
+
await runCommand(command, opts, false, () => showBody(raw));
|
|
4101
|
+
});
|
|
4102
|
+
const enable = destinations.command("enable").description("Re-enable an auto-disabled destination and reset its failure counter.").argument("[name]", "Destination name");
|
|
4103
|
+
enable.addHelpText("after", "\nExamples:\n engini triggers destinations enable billing");
|
|
4104
|
+
addUniversalOptions(enable, { mutating: true });
|
|
4105
|
+
enable.action(async (raw, opts, command) => {
|
|
4106
|
+
await runCommand(command, opts, true, () => enableBody(raw));
|
|
4107
|
+
});
|
|
4108
|
+
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");
|
|
4109
|
+
rm.addHelpText(
|
|
4110
|
+
"after",
|
|
4111
|
+
"\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)."
|
|
4112
|
+
);
|
|
4113
|
+
addUniversalOptions(rm, { mutating: true });
|
|
4114
|
+
rm.action(
|
|
4115
|
+
async (raw, opts, command) => {
|
|
4116
|
+
await runCommand(command, opts, true, () => rmBody(raw, opts));
|
|
4117
|
+
}
|
|
4118
|
+
);
|
|
4119
|
+
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");
|
|
4120
|
+
rotate.addHelpText("after", "\nExamples:\n engini triggers destinations rotate-secret billing --force");
|
|
4121
|
+
addUniversalOptions(rotate, { mutating: true });
|
|
4122
|
+
rotate.action(
|
|
4123
|
+
async (raw, opts, command) => {
|
|
4124
|
+
await runCommand(command, opts, true, () => rotateBody2(raw, opts));
|
|
4125
|
+
}
|
|
4126
|
+
);
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4129
|
+
// src/triggers/events.ts
|
|
4130
|
+
async function listBody10(triggerId, opts) {
|
|
4131
|
+
if (triggerId === void 0 || triggerId === "") fail(2 /* USAGE */, "A trigger_id is required.");
|
|
4132
|
+
const top = opts.limit !== void 0 ? Number(opts.limit) : void 0;
|
|
4133
|
+
const events = await apiErrors(async () => buildClient().triggers.events.list(triggerId, { top }));
|
|
4134
|
+
printOutput(events.map(summarizeEvent));
|
|
4135
|
+
}
|
|
4136
|
+
async function getBody8(eventId) {
|
|
4137
|
+
if (eventId === void 0 || eventId === "") fail(2 /* USAGE */, "An event_id is required.");
|
|
4138
|
+
const detail4 = await apiErrors(async () => buildClient().triggers.events.get(eventId));
|
|
4139
|
+
printOutput({ event: summarizeEvent(detail4.event), attempts: detail4.attempts });
|
|
4140
|
+
}
|
|
4141
|
+
async function replayBody(eventId) {
|
|
4142
|
+
if (eventId === void 0 || eventId === "") fail(2 /* USAGE */, "An event_id is required.");
|
|
4143
|
+
if (dryRun()) {
|
|
4144
|
+
printOutput({ would_replay: eventId });
|
|
4145
|
+
return;
|
|
4146
|
+
}
|
|
4147
|
+
const detail4 = await apiErrors(async () => buildClient().triggers.events.replay(eventId));
|
|
4148
|
+
printOutput({ event: summarizeEvent(detail4.event), attempts: detail4.attempts });
|
|
4149
|
+
}
|
|
4150
|
+
function registerTriggerEvents(triggers) {
|
|
4151
|
+
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)");
|
|
4152
|
+
events.addHelpText(
|
|
4153
|
+
"after",
|
|
4154
|
+
"\nExamples:\n engini triggers events ti_abc123 --limit 20\nNote: for live events use `engini triggers listen`, not this in a poll loop."
|
|
4155
|
+
);
|
|
4156
|
+
addUniversalOptions(events);
|
|
4157
|
+
events.action(
|
|
4158
|
+
async (triggerId, opts, command) => {
|
|
4159
|
+
await runCommand(command, opts, false, () => listBody10(triggerId, opts));
|
|
4160
|
+
}
|
|
4161
|
+
);
|
|
4162
|
+
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)");
|
|
4163
|
+
get.addHelpText("after", "\nExamples:\n engini triggers events get te_abc123 --json");
|
|
4164
|
+
addUniversalOptions(get);
|
|
4165
|
+
get.action(async (eventId, opts, command) => {
|
|
4166
|
+
await runCommand(command, opts, false, () => getBody8(eventId));
|
|
4167
|
+
});
|
|
4168
|
+
const replay = events.command("replay").description("Re-deliver a captured event to its destination.").argument("[event_id]", "Event id (te_\u2026)");
|
|
4169
|
+
replay.addHelpText(
|
|
4170
|
+
"after",
|
|
4171
|
+
"\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."
|
|
4172
|
+
);
|
|
4173
|
+
addUniversalOptions(replay, { mutating: true });
|
|
4174
|
+
replay.action(async (eventId, opts, command) => {
|
|
4175
|
+
await runCommand(command, opts, true, () => replayBody(eventId));
|
|
4176
|
+
});
|
|
4177
|
+
}
|
|
4178
|
+
|
|
4179
|
+
// src/triggers/get.ts
|
|
4180
|
+
async function getBody9(raw) {
|
|
4181
|
+
const triggerId = parseTriggerId(raw);
|
|
4182
|
+
const trigger = await apiErrors(async () => buildClient().triggers.get(triggerId));
|
|
4183
|
+
printOutput(summarizeTrigger(trigger));
|
|
4184
|
+
}
|
|
4185
|
+
function registerTriggersGet(triggers) {
|
|
4186
|
+
const get = triggers.command("get").description("One trigger instance's status, schedule and last-error detail.").argument("[trigger_id]", "Trigger instance id (ti_\u2026)");
|
|
4187
|
+
get.addHelpText("after", "\nExamples:\n engini triggers get ti_abc123 --json");
|
|
4188
|
+
addUniversalOptions(get);
|
|
4189
|
+
get.action(async (raw, opts, command) => {
|
|
4190
|
+
await runCommand(command, opts, false, () => getBody9(raw));
|
|
4191
|
+
});
|
|
4192
|
+
}
|
|
4193
|
+
|
|
4194
|
+
// src/triggers/listen.ts
|
|
4195
|
+
import { createHmac } from "crypto";
|
|
4196
|
+
function emitEvent(frame) {
|
|
4197
|
+
console.log(JSON.stringify(frame));
|
|
4198
|
+
}
|
|
4199
|
+
function buildDeliveryBody(frame) {
|
|
4200
|
+
return {
|
|
4201
|
+
id: frame.id,
|
|
4202
|
+
trigger_id: frame.trigger_id,
|
|
4203
|
+
trigger_slug: frame.trigger_slug ?? null,
|
|
4204
|
+
occurred_at: frame.occurred_at,
|
|
4205
|
+
attempt: 1,
|
|
4206
|
+
payload_truncated: frame.payload_truncated,
|
|
4207
|
+
payload_hash: frame.payload_hash,
|
|
4208
|
+
payload: frame.payload
|
|
4209
|
+
};
|
|
4210
|
+
}
|
|
4211
|
+
function sign(secret, bodyBytes) {
|
|
4212
|
+
const t = Math.floor(Date.now() / 1e3);
|
|
4213
|
+
const mac = createHmac("sha256", Buffer.from(secret, "utf8")).update(Buffer.concat([Buffer.from(`${t}.`, "utf8"), bodyBytes])).digest("hex");
|
|
4214
|
+
return `t=${t},v1=${mac}`;
|
|
4215
|
+
}
|
|
4216
|
+
async function forwardEvent(frame, url, secret) {
|
|
4217
|
+
const body = buildDeliveryBody(frame);
|
|
4218
|
+
const bytes = Buffer.from(JSON.stringify(body), "utf8");
|
|
4219
|
+
const headers = {
|
|
4220
|
+
"Content-Type": "application/json",
|
|
4221
|
+
"X-Engini-Timestamp": String(Math.floor(Date.now() / 1e3))
|
|
4222
|
+
};
|
|
4223
|
+
if (typeof frame.id === "string") headers["X-Engini-Event-Id"] = frame.id;
|
|
4224
|
+
if (typeof frame.trigger_id === "string") headers["X-Engini-Trigger-Id"] = frame.trigger_id;
|
|
4225
|
+
if (frame.trigger_slug !== void 0 && frame.trigger_slug !== null) {
|
|
4226
|
+
headers["X-Engini-Trigger-Slug"] = frame.trigger_slug;
|
|
4227
|
+
}
|
|
4228
|
+
if (secret) headers["X-Engini-Signature"] = sign(secret, bytes);
|
|
4229
|
+
try {
|
|
4230
|
+
const res = await fetch(url, { method: "POST", headers, body: bytes });
|
|
4231
|
+
if (!res.ok) {
|
|
4232
|
+
console.error(`forward to ${url} failed: HTTP ${res.status}`);
|
|
4233
|
+
return false;
|
|
4234
|
+
}
|
|
4235
|
+
return true;
|
|
4236
|
+
} catch (err) {
|
|
4237
|
+
console.error(`forward to ${url} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4238
|
+
return false;
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
async function listenBody(opts) {
|
|
4242
|
+
const secret = opts.signWith ?? process.env.ENGINI_TRIGGER_SIGNING_SECRET;
|
|
4243
|
+
if (opts.forward !== void 0 && !secret) {
|
|
4244
|
+
progress(
|
|
4245
|
+
"--forward is unsigned (no --sign-with / ENGINI_TRIGGER_SIGNING_SECRET) \u2014 the X-Engini-Signature header is omitted, never sent empty."
|
|
4246
|
+
);
|
|
4247
|
+
}
|
|
4248
|
+
let interrupted = false;
|
|
4249
|
+
const onSigint = () => {
|
|
4250
|
+
interrupted = true;
|
|
4251
|
+
};
|
|
4252
|
+
process.once("SIGINT", onSigint);
|
|
4253
|
+
let events = 0;
|
|
4254
|
+
let forwarded = 0;
|
|
4255
|
+
let failed = 0;
|
|
4256
|
+
try {
|
|
4257
|
+
await apiErrors(async () => {
|
|
4258
|
+
const stream = buildClient().triggers.subscribe({
|
|
4259
|
+
triggerId: opts.trigger,
|
|
4260
|
+
triggerSlug: opts.slug,
|
|
4261
|
+
applicationSlug: opts.app,
|
|
4262
|
+
since: opts.since,
|
|
4263
|
+
autoResume: opts.resume
|
|
4264
|
+
});
|
|
4265
|
+
for await (const frame of stream) {
|
|
4266
|
+
if (interrupted) break;
|
|
4267
|
+
events += 1;
|
|
4268
|
+
emitEvent(frame);
|
|
4269
|
+
if (opts.forward !== void 0) {
|
|
4270
|
+
const ok = await forwardEvent(frame, opts.forward, secret);
|
|
4271
|
+
if (ok) forwarded += 1;
|
|
4272
|
+
else failed += 1;
|
|
4273
|
+
}
|
|
4274
|
+
if (interrupted) break;
|
|
4275
|
+
}
|
|
4276
|
+
});
|
|
4277
|
+
} finally {
|
|
4278
|
+
process.removeListener("SIGINT", onSigint);
|
|
4279
|
+
}
|
|
4280
|
+
console.log(JSON.stringify({ events, forwarded, failed }));
|
|
4281
|
+
if (!interrupted && failed > 0) {
|
|
4282
|
+
throw new CliError(1 /* GENERIC */);
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
function registerTriggerListen(triggers) {
|
|
4286
|
+
const listen = triggers.command("listen").description(
|
|
4287
|
+
"Stream trigger events live (local dev only \u2014 not a delivery mechanism). See `events` for the historical log."
|
|
4288
|
+
).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(
|
|
4289
|
+
"--sign-with <secret>",
|
|
4290
|
+
"Sign forwarded events with this destination secret (or ENGINI_TRIGGER_SIGNING_SECRET)"
|
|
4291
|
+
);
|
|
4292
|
+
listen.addHelpText(
|
|
4293
|
+
"after",
|
|
4294
|
+
"\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."
|
|
4295
|
+
);
|
|
4296
|
+
addUniversalOptions(listen);
|
|
4297
|
+
listen.action(async (opts, command) => {
|
|
4298
|
+
await runCommand(command, opts, false, () => listenBody(opts));
|
|
4299
|
+
});
|
|
4300
|
+
}
|
|
4301
|
+
|
|
4302
|
+
// src/triggers/list.ts
|
|
4303
|
+
async function listBody11(opts) {
|
|
4304
|
+
const top = opts.top !== void 0 ? Number(opts.top) : void 0;
|
|
4305
|
+
const triggers = await apiErrors(
|
|
4306
|
+
async () => buildClient().triggers.list({
|
|
4307
|
+
applicationSlug: opts.app,
|
|
4308
|
+
connectionId: opts.connection !== void 0 ? Number(opts.connection) : void 0,
|
|
4309
|
+
status: opts.status,
|
|
4310
|
+
include: opts.include,
|
|
4311
|
+
top
|
|
4312
|
+
})
|
|
4313
|
+
);
|
|
4314
|
+
if (opts.include !== void 0) {
|
|
4315
|
+
progress(
|
|
4316
|
+
`--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).`
|
|
4317
|
+
);
|
|
4318
|
+
}
|
|
4319
|
+
printOutput(triggers.map(summarizeTrigger));
|
|
4320
|
+
}
|
|
4321
|
+
function registerTriggersList(triggers) {
|
|
4322
|
+
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(
|
|
4323
|
+
"--include <what>",
|
|
4324
|
+
"Pass 'workflow' to also surface designer-built triggers (single page \u2014 see Note)"
|
|
4325
|
+
).option("--top <n>", "Page size (also the row cap under --include)");
|
|
4326
|
+
list.addHelpText(
|
|
4327
|
+
"after",
|
|
4328
|
+
"\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."
|
|
4329
|
+
);
|
|
4330
|
+
addUniversalOptions(list);
|
|
4331
|
+
list.action(async (opts, command) => {
|
|
4332
|
+
await runCommand(command, opts, false, () => listBody11(opts));
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
|
|
4336
|
+
// src/triggers/status.ts
|
|
4337
|
+
async function toggleBody2(raw, enable) {
|
|
4338
|
+
const triggerId = parseTriggerId(raw);
|
|
4339
|
+
if (dryRun()) {
|
|
4340
|
+
printOutput(enable ? { would_enable: triggerId } : { would_disable: triggerId });
|
|
4341
|
+
return;
|
|
4342
|
+
}
|
|
4343
|
+
const trigger = await apiErrors(async () => {
|
|
4344
|
+
const client = buildClient();
|
|
4345
|
+
return enable ? client.triggers.enable(triggerId) : client.triggers.disable(triggerId);
|
|
4346
|
+
});
|
|
4347
|
+
printOutput(summarizeTrigger(trigger));
|
|
4348
|
+
}
|
|
4349
|
+
function register3(triggers, name, description) {
|
|
4350
|
+
const cmd = triggers.command(name).description(description).argument("[trigger_id]", "Trigger instance id (ti_\u2026)");
|
|
4351
|
+
cmd.addHelpText("after", `
|
|
4352
|
+
Examples:
|
|
4353
|
+
engini triggers ${name} ti_abc123`);
|
|
4354
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
4355
|
+
cmd.action(async (raw, opts, command) => {
|
|
4356
|
+
await runCommand(command, opts, true, () => toggleBody2(raw, name === "enable"));
|
|
4357
|
+
});
|
|
4358
|
+
}
|
|
4359
|
+
function registerTriggerEnable(triggers) {
|
|
4360
|
+
register3(
|
|
4361
|
+
triggers,
|
|
4362
|
+
"enable",
|
|
4363
|
+
"Re-enable a trigger; clears its status_reason. A deleted connection can re-block it immediately."
|
|
4364
|
+
);
|
|
4365
|
+
}
|
|
4366
|
+
function registerTriggerDisable(triggers) {
|
|
4367
|
+
register3(triggers, "disable", "Stop a trigger capturing events. Not a delete \u2014 its event history stays.");
|
|
4368
|
+
}
|
|
4369
|
+
|
|
4370
|
+
// src/triggers/types.ts
|
|
4371
|
+
async function listBody12(opts) {
|
|
4372
|
+
const types = await apiErrors(
|
|
4373
|
+
async () => buildClient().triggers.types.list({
|
|
4374
|
+
applicationSlug: opts.app,
|
|
4375
|
+
search: opts.search,
|
|
4376
|
+
connectionId: opts.connection !== void 0 ? Number(opts.connection) : void 0
|
|
4377
|
+
})
|
|
4378
|
+
);
|
|
4379
|
+
printOutput(types);
|
|
4380
|
+
}
|
|
4381
|
+
async function getBody10(slug, opts) {
|
|
4382
|
+
if (slug === void 0 || slug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
|
|
4383
|
+
const type = await apiErrors(
|
|
4384
|
+
async () => buildClient().triggers.types.get(slug, { applicationSlug: opts.app })
|
|
4385
|
+
);
|
|
4386
|
+
printOutput(type);
|
|
4387
|
+
}
|
|
4388
|
+
function registerTriggerTypes(triggers) {
|
|
4389
|
+
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");
|
|
4390
|
+
types.addHelpText(
|
|
4391
|
+
"after",
|
|
4392
|
+
"\nExamples:\n engini triggers types --app monday\n engini triggers types --connection 12 --json"
|
|
4393
|
+
);
|
|
4394
|
+
addUniversalOptions(types);
|
|
4395
|
+
types.action(async (opts, command) => {
|
|
4396
|
+
await runCommand(command, opts, false, () => listBody12(opts));
|
|
4397
|
+
});
|
|
4398
|
+
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");
|
|
4399
|
+
get.addHelpText("after", "\nExamples:\n engini triggers types get monday_item_created --json");
|
|
4400
|
+
addUniversalOptions(get);
|
|
4401
|
+
get.action(
|
|
4402
|
+
async (slug, opts, command) => {
|
|
4403
|
+
await runCommand(command, opts, false, () => getBody10(slug, opts));
|
|
4404
|
+
}
|
|
4405
|
+
);
|
|
4406
|
+
}
|
|
4407
|
+
|
|
4408
|
+
// src/triggers/index.ts
|
|
4409
|
+
function registerTriggers(program) {
|
|
4410
|
+
program.enablePositionalOptions();
|
|
4411
|
+
const triggers = program.command("triggers").description("Trigger instances, their event log/stream, and their delivery destinations.");
|
|
4412
|
+
registerTriggerTypes(triggers);
|
|
4413
|
+
registerTriggersList(triggers);
|
|
4414
|
+
registerTriggersGet(triggers);
|
|
4415
|
+
registerTriggerCreate(triggers);
|
|
4416
|
+
registerTriggerEnable(triggers);
|
|
4417
|
+
registerTriggerDisable(triggers);
|
|
4418
|
+
registerTriggerDelete(triggers);
|
|
4419
|
+
registerTriggerEvents(triggers);
|
|
4420
|
+
registerTriggerListen(triggers);
|
|
4421
|
+
registerTriggerDestinations(triggers);
|
|
4422
|
+
}
|
|
4423
|
+
|
|
3692
4424
|
// src/whoami.ts
|
|
3693
4425
|
function summary5(me) {
|
|
3694
4426
|
return {
|
|
@@ -3729,6 +4461,7 @@ function buildProgram() {
|
|
|
3729
4461
|
registerToolsets(program);
|
|
3730
4462
|
registerMcp(program);
|
|
3731
4463
|
registerOpa(program);
|
|
4464
|
+
registerTriggers(program);
|
|
3732
4465
|
installHelp(program);
|
|
3733
4466
|
return program;
|
|
3734
4467
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Engini CLI — machine-first command line over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "vitest run"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@engini/sdk": "^0.
|
|
29
|
+
"@engini/sdk": "^0.21.0",
|
|
30
30
|
"commander": "^12.1.0",
|
|
31
31
|
"smol-toml": "^1.3.0"
|
|
32
32
|
},
|