@engini/cli 0.22.0 → 0.24.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 +5 -4
- package/dist/cli.js +170 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ resulting, plus explicit added/removed lists) rather than just echoing the
|
|
|
64
64
|
outgoing request.
|
|
65
65
|
|
|
66
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
|
|
67
|
+
trigger type, against a connection when the application requires one. There are two ways to receive its events, and
|
|
68
68
|
they need opposite code: a **destination** is production delivery (signed via
|
|
69
69
|
`destinations`); `listen` is a live SSE stream for local dev only (unsigned, no
|
|
70
70
|
delivery guarantees). `events` is the historical log with real delivery state;
|
|
@@ -96,9 +96,10 @@ engini connect monday --json # → {need:"fields", resume:"engi
|
|
|
96
96
|
engini connect monday --auth 0 --field ApiKey=<key> # creates → checks → refreshes
|
|
97
97
|
|
|
98
98
|
# OAuth2 (e.g. outlook) — never opens a browser for the agent
|
|
99
|
-
engini connect outlook --json # → {need:"oauth", sign_in_url, state, resume:"engini connect outlook --oauth-state <state>"}
|
|
100
|
-
# show sign_in_url to the user
|
|
101
|
-
|
|
99
|
+
engini connect outlook --json # → {need:"oauth", sign_in_url, state, state_expires_in_seconds, resume:"engini connect outlook --auth 0 --oauth-state <state>"}
|
|
100
|
+
# show sign_in_url to the user - they must sign in within state_expires_in_seconds of
|
|
101
|
+
# minting; past that the server has purged the state and the resume below fails fast, not hangs:
|
|
102
|
+
engini connect outlook --auth 0 --oauth-state <state> # polls token → creates → checks → refreshes
|
|
102
103
|
|
|
103
104
|
# re-authenticate an EXISTING OAuth2 connection in place — same sign-in flow,
|
|
104
105
|
# but --oauth-state alone (no --field/--name/--metadata) is a valid edit and
|
package/dist/cli.js
CHANGED
|
@@ -442,7 +442,7 @@ function saveConfig(config, path = configPath()) {
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
// src/version.ts
|
|
445
|
-
var VERSION = true ? "0.
|
|
445
|
+
var VERSION = true ? "0.24.0" : "0.0.0";
|
|
446
446
|
|
|
447
447
|
// src/http.ts
|
|
448
448
|
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
@@ -592,6 +592,7 @@ async function safeTrigger(action, what) {
|
|
|
592
592
|
var OAUTH_DONE = /* @__PURE__ */ new Set(["completed", "complete", "success", "succeeded"]);
|
|
593
593
|
var OAUTH_FAILED = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled", "denied"]);
|
|
594
594
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
595
|
+
var OAUTH_STATE_TTL_SECONDS = 300;
|
|
595
596
|
function collect(value, previous = []) {
|
|
596
597
|
return [...previous, value];
|
|
597
598
|
}
|
|
@@ -648,6 +649,13 @@ async function pollAccessToken(client, state, opts) {
|
|
|
648
649
|
const deadline = Date.now() + opts.timeout * 1e3;
|
|
649
650
|
for (; ; ) {
|
|
650
651
|
const resp = await client.connections.getAccessToken(state);
|
|
652
|
+
if (resp == null) {
|
|
653
|
+
fail(
|
|
654
|
+
4 /* NOT_FOUND */,
|
|
655
|
+
`OAuth sign-in state not found - it may have expired (states are purged ${OAUTH_STATE_TTL_SECONDS} seconds after they're minted) or never existed.`,
|
|
656
|
+
"Start over: `engini connect <app>` mints a fresh sign_in_url + state."
|
|
657
|
+
);
|
|
658
|
+
}
|
|
651
659
|
const status = (resp.status ?? "").toLowerCase();
|
|
652
660
|
if (OAUTH_DONE.has(status)) return resp;
|
|
653
661
|
if (OAUTH_FAILED.has(status)) {
|
|
@@ -662,13 +670,14 @@ async function pollAccessToken(client, state, opts) {
|
|
|
662
670
|
function oauthFields(token) {
|
|
663
671
|
const fields = {};
|
|
664
672
|
for (const [key, value] of Object.entries(token.connectionData ?? {})) {
|
|
665
|
-
if (value === null || value === void 0) continue;
|
|
673
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
666
674
|
fields[key] = typeof value === "string" ? value : JSON.stringify(value);
|
|
667
675
|
}
|
|
668
676
|
return fields;
|
|
669
677
|
}
|
|
670
678
|
|
|
671
679
|
// src/connect.ts
|
|
680
|
+
var PLACEHOLDER = "<value>";
|
|
672
681
|
function connectionsUrl(config) {
|
|
673
682
|
return `${config.identity_url.replace(/\/+$/, "")}/connections#integrations`;
|
|
674
683
|
}
|
|
@@ -711,7 +720,7 @@ async function connectBody(application, opts) {
|
|
|
711
720
|
return;
|
|
712
721
|
}
|
|
713
722
|
const name = await resolveName(opts.name, application);
|
|
714
|
-
const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, timing) : { fields: await collectFields(method, application, opts.field) };
|
|
723
|
+
const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, opts.field, timing) : { fields: await collectFields(method, application, parseFields(opts.field)) };
|
|
715
724
|
progress(`Creating connection '${name}'\u2026`);
|
|
716
725
|
const created = await client.connections.create(
|
|
717
726
|
application,
|
|
@@ -800,7 +809,7 @@ async function chooseAuth(methods, auth, application) {
|
|
|
800
809
|
resume: `engini connect ${application} --auth <id>`
|
|
801
810
|
});
|
|
802
811
|
}
|
|
803
|
-
async function collectFields(method, application,
|
|
812
|
+
async function collectFields(method, application, provided, oauthState, fieldOptions) {
|
|
804
813
|
async function readSecretField(label) {
|
|
805
814
|
const { value, truncated } = await promptHidden(label);
|
|
806
815
|
if (truncated) {
|
|
@@ -812,8 +821,26 @@ async function collectFields(method, application, field) {
|
|
|
812
821
|
}
|
|
813
822
|
return value;
|
|
814
823
|
}
|
|
815
|
-
const provided = parseFields(field);
|
|
816
824
|
const schema = method.connectionFields.filter((f) => !f.isHidden);
|
|
825
|
+
const resumeHint = oauthState ? `Resume with: engini connect ${application} --auth ${method.authenticationId} --oauth-state ${oauthState}` : void 0;
|
|
826
|
+
for (const [k, v] of Object.entries(provided)) {
|
|
827
|
+
if (v === PLACEHOLDER) delete provided[k];
|
|
828
|
+
}
|
|
829
|
+
for (const f of schema) {
|
|
830
|
+
const opts = fieldOptions?.[f.fieldName];
|
|
831
|
+
const val = provided[f.fieldName];
|
|
832
|
+
if (!opts || Object.keys(opts).length === 0 || val === void 0) continue;
|
|
833
|
+
if (!Object.hasOwn(opts, val)) {
|
|
834
|
+
fail(
|
|
835
|
+
2 /* USAGE */,
|
|
836
|
+
`'${val}' is not a legal ${f.fieldName} for this org. Legal values: ${Object.keys(opts).join(", ")}`,
|
|
837
|
+
// A TTY caller who just completed the inline browser sign-in and then supplied this bad
|
|
838
|
+
// value must recover the same way a mistyped picker digit does (below) - not with a
|
|
839
|
+
// hard fail that has no resume hint and forces a full re-auth.
|
|
840
|
+
resumeHint
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
817
844
|
const required = schema.filter((f) => f.isRequired);
|
|
818
845
|
const missing = required.filter((f) => !(f.fieldName in provided));
|
|
819
846
|
if (missing.length === 0) return provided;
|
|
@@ -821,19 +848,43 @@ async function collectFields(method, application, field) {
|
|
|
821
848
|
for (const f of schema) {
|
|
822
849
|
if (f.fieldName in provided) continue;
|
|
823
850
|
const label = fieldLabel(f);
|
|
824
|
-
const
|
|
851
|
+
const options = fieldOptions?.[f.fieldName];
|
|
852
|
+
const value = options && Object.keys(options).length > 0 ? await promptFieldOption(label, options, f.isRequired, resumeHint) : f.isPassword ? await readSecretField(label) : await promptText(label, clean(f.defaultValue) ?? "");
|
|
825
853
|
if (value) provided[f.fieldName] = value;
|
|
826
854
|
}
|
|
827
855
|
return provided;
|
|
828
856
|
}
|
|
829
|
-
const fieldsFlags =
|
|
857
|
+
const fieldsFlags = missing.map((f) => `--field ${f.fieldName}=${PLACEHOLDER}`).join(" ");
|
|
858
|
+
const resumeParts = [
|
|
859
|
+
`engini connect ${application}`,
|
|
860
|
+
`--auth ${method.authenticationId}`,
|
|
861
|
+
...oauthState ? [`--oauth-state ${oauthState}`] : [],
|
|
862
|
+
fieldsFlags
|
|
863
|
+
].filter(Boolean);
|
|
830
864
|
return need({
|
|
831
865
|
need: "fields",
|
|
832
866
|
application,
|
|
833
867
|
authentication_id: method.authenticationId,
|
|
834
|
-
fields: schema.map(fieldSummary),
|
|
835
|
-
resume:
|
|
868
|
+
fields: schema.map((f) => fieldSummary(f, fieldOptions?.[f.fieldName])),
|
|
869
|
+
resume: resumeParts.join(" ")
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
async function promptFieldOption(label, options, isRequired, resumeHint) {
|
|
873
|
+
const entries = Object.entries(options);
|
|
874
|
+
entries.forEach(([value, optionLabel], i) => {
|
|
875
|
+
console.error(` ${i + 1}: ${optionLabel} (${value})`);
|
|
836
876
|
});
|
|
877
|
+
const range = `1-${entries.length}`;
|
|
878
|
+
const answer = await promptText(
|
|
879
|
+
isRequired ? `Choose ${label} (${range})` : `Choose ${label} (${range}, blank to skip)`
|
|
880
|
+
);
|
|
881
|
+
if (answer.trim() === "" && !isRequired) return "";
|
|
882
|
+
const index = Number(answer);
|
|
883
|
+
const chosen = entries[index - 1];
|
|
884
|
+
if (!chosen) {
|
|
885
|
+
fail(2 /* USAGE */, `Choose a number between 1 and ${entries.length} for ${label}.`, resumeHint);
|
|
886
|
+
}
|
|
887
|
+
return chosen[0];
|
|
837
888
|
}
|
|
838
889
|
async function resolveName(name, application) {
|
|
839
890
|
if (name) return name;
|
|
@@ -870,27 +921,70 @@ async function resolveObjects(objs, connectionId, application) {
|
|
|
870
921
|
resume: `engini connect ${app} --connection ${connectionId} --object <id>`
|
|
871
922
|
});
|
|
872
923
|
}
|
|
873
|
-
async function oauthFieldsFor(client, application, method, oauthState, timing) {
|
|
924
|
+
async function oauthFieldsFor(client, application, method, oauthState, field, timing) {
|
|
925
|
+
const cliFields = parseFields(field);
|
|
874
926
|
if (oauthState) {
|
|
875
927
|
const token = await pollAccessToken(client, oauthState, timing);
|
|
876
|
-
|
|
928
|
+
const merged = { ...cliFields, ...oauthFields(token) };
|
|
929
|
+
return {
|
|
930
|
+
fields: await collectFields(method, application, merged, oauthState, token.fieldOptions),
|
|
931
|
+
state: oauthState
|
|
932
|
+
};
|
|
877
933
|
}
|
|
878
|
-
const resp = await client.connections.getSignInUrl(application, method.authenticationId
|
|
934
|
+
const resp = await client.connections.getSignInUrl(application, method.authenticationId, {
|
|
935
|
+
fields: field && field.length > 0 ? cliFields : void 0
|
|
936
|
+
});
|
|
879
937
|
if (isTty() && timing.wait) {
|
|
880
938
|
openBrowser(resp.signInUrl);
|
|
881
939
|
progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
|
|
882
940
|
const token = await pollAccessToken(client, resp.state, timing);
|
|
883
|
-
|
|
941
|
+
const merged = { ...cliFields, ...oauthFields(token) };
|
|
942
|
+
return {
|
|
943
|
+
fields: await collectFields(method, application, merged, resp.state, token.fieldOptions),
|
|
944
|
+
state: resp.state
|
|
945
|
+
};
|
|
884
946
|
}
|
|
947
|
+
const secretFields = new Set(
|
|
948
|
+
method.connectionFields.filter(isSecretField).map((f) => f.fieldName)
|
|
949
|
+
);
|
|
885
950
|
return need({
|
|
886
951
|
need: "oauth",
|
|
887
952
|
application,
|
|
888
953
|
authentication_id: method.authenticationId,
|
|
889
954
|
sign_in_url: resp.signInUrl,
|
|
890
955
|
state: resp.state,
|
|
891
|
-
|
|
956
|
+
// The state is perishable - the server purges it this long after minting, regardless of
|
|
957
|
+
// whether anyone has signed in yet - so a caller replaying `resume` late (the common case
|
|
958
|
+
// once a human is in the loop) can tell a stale state from one that's still good.
|
|
959
|
+
state_expires_in_seconds: OAUTH_STATE_TTL_SECONDS,
|
|
960
|
+
// Replayable verbatim: --auth plus every --field the caller already passed, so resuming
|
|
961
|
+
// this exact string never falls back to need:"auth" or silently drops --field again
|
|
962
|
+
// (reproduced against production with the old bare `--oauth-state <state>` hint). A
|
|
963
|
+
// password field's value is placeholdered rather than echoed (never print a secret to
|
|
964
|
+
// stdout), and every value is shell-quoted when it needs it (field values can contain
|
|
965
|
+
// spaces or shell metacharacters).
|
|
966
|
+
resume: [
|
|
967
|
+
`engini connect ${application}`,
|
|
968
|
+
`--auth ${method.authenticationId}`,
|
|
969
|
+
`--oauth-state ${resp.state}`,
|
|
970
|
+
...(field ?? []).map((spec) => resumeFieldFlag(spec, secretFields))
|
|
971
|
+
].join(" ")
|
|
892
972
|
});
|
|
893
973
|
}
|
|
974
|
+
var SAFE_BAREWORD = /^[A-Za-z0-9_@%+:,./=-]+$/;
|
|
975
|
+
function shellQuoteFieldSpec(spec) {
|
|
976
|
+
if (SAFE_BAREWORD.test(spec)) return spec;
|
|
977
|
+
return `'${spec.replace(/'/g, `'\\''`)}'`;
|
|
978
|
+
}
|
|
979
|
+
function isSecretField(f) {
|
|
980
|
+
return f.isPassword || Boolean(f.maskInLogs);
|
|
981
|
+
}
|
|
982
|
+
function resumeFieldFlag(spec, secretFields) {
|
|
983
|
+
const eq = spec.indexOf("=");
|
|
984
|
+
const key = spec.slice(0, eq);
|
|
985
|
+
if (secretFields.has(key)) return `--field ${key}=${PLACEHOLDER}`;
|
|
986
|
+
return `--field ${shellQuoteFieldSpec(spec)}`;
|
|
987
|
+
}
|
|
894
988
|
function fieldLabel(f) {
|
|
895
989
|
const label = clean(f.fieldDescription) ?? f.fieldName;
|
|
896
990
|
const placeholder = clean(f.placeholder);
|
|
@@ -909,20 +1003,28 @@ function methodSummary(m) {
|
|
|
909
1003
|
is_default: Boolean(m.isDefault),
|
|
910
1004
|
help_url: methodHelpUrl(m),
|
|
911
1005
|
requires_oauth: m.requiresOAuthSignIn,
|
|
912
|
-
|
|
1006
|
+
// No fieldOptions here - this listing runs before any sign-in, so there is no org yet
|
|
1007
|
+
// to have discovered them from. Each field's `options` therefore comes back `null` in
|
|
1008
|
+
// this `need: "auth"` payload specifically because it's not knowable yet, not because
|
|
1009
|
+
// the field has none - that's a distinct case (`{}`, once a sign-in has run - see
|
|
1010
|
+
// `fieldSummary` and the `AccessTokenResponse.fieldOptions` doc in @engini/sdk). Worth
|
|
1011
|
+
// calling out explicitly wherever step 5 documents this payload, since the two look the
|
|
1012
|
+
// same on the wire (both fall out here as `options: null`) but mean different things.
|
|
1013
|
+
fields: m.connectionFields.map((f) => fieldSummary(f))
|
|
913
1014
|
};
|
|
914
1015
|
}
|
|
915
1016
|
function methodHelpUrl(m) {
|
|
916
1017
|
return typeof m.helpUrl === "string" && m.helpUrl.trim() !== "" ? m.helpUrl : null;
|
|
917
1018
|
}
|
|
918
|
-
function fieldSummary(f) {
|
|
1019
|
+
function fieldSummary(f, options) {
|
|
919
1020
|
return {
|
|
920
1021
|
field_name: f.fieldName,
|
|
921
1022
|
is_required: f.isRequired,
|
|
922
1023
|
is_password: f.isPassword,
|
|
923
1024
|
description: clean(f.fieldDescription),
|
|
924
1025
|
default: clean(f.defaultValue),
|
|
925
|
-
list_values: clean(f.listValues)
|
|
1026
|
+
list_values: clean(f.listValues),
|
|
1027
|
+
options: options && Object.keys(options).length > 0 ? options : null
|
|
926
1028
|
};
|
|
927
1029
|
}
|
|
928
1030
|
function objectSummary(o) {
|
|
@@ -1647,12 +1749,12 @@ ON-PREMISE AGENTS
|
|
|
1647
1749
|
|
|
1648
1750
|
TRIGGERS
|
|
1649
1751
|
A trigger instance (ti_\u2026) is an entity, not a workflow step - created from a trigger
|
|
1650
|
-
type (a catalog slug) against a connection.
|
|
1752
|
+
type (a catalog slug), against a connection when the application requires one.
|
|
1651
1753
|
triggers types [--app <slug>] [--search <q>] [--connection <id>] List the catalog.
|
|
1652
1754
|
triggers types get <trigger_slug> [--app <slug>] config_schema/payload_schema/parameters.
|
|
1653
1755
|
triggers list [--app <s>] [--connection <id>] [--status <s>] [--include workflow] [--top <n>]
|
|
1654
1756
|
triggers get <trigger_id> Status, schedule, last-error detail.
|
|
1655
|
-
triggers create <trigger_slug> --connection <name|id> [--config <json>] [--every <n><s|m|h|d>]
|
|
1757
|
+
triggers create <trigger_slug> [--connection <name|id>] [--config <json>] [--every <n><s|m|h|d>]
|
|
1656
1758
|
[--weekdays <spec>] [--window <HH:mm-HH:mm>] [--listen <col>...] [--destination <name>]
|
|
1657
1759
|
[--dedupe-window-hours <n>]
|
|
1658
1760
|
triggers enable <id> | triggers disable <id> Toggle capture; not a delete.
|
|
@@ -3754,6 +3856,9 @@ function registerToolsets(program) {
|
|
|
3754
3856
|
import { EnginiNotFoundError as EnginiNotFoundError2 } from "@engini/sdk";
|
|
3755
3857
|
|
|
3756
3858
|
// src/triggers/shared.ts
|
|
3859
|
+
import {
|
|
3860
|
+
EnginiValidationError as EnginiValidationError2
|
|
3861
|
+
} from "@engini/sdk";
|
|
3757
3862
|
var TRIGGER_ID_RE = /^ti_[A-Za-z0-9]+$/;
|
|
3758
3863
|
function parseTriggerId(raw) {
|
|
3759
3864
|
if (raw === void 0 || raw === "") fail(2 /* USAGE */, "A trigger id is required.");
|
|
@@ -3777,6 +3882,19 @@ function parseConfig(raw) {
|
|
|
3777
3882
|
fail(2 /* USAGE */, `--config is not valid JSON: '${raw}'.`);
|
|
3778
3883
|
}
|
|
3779
3884
|
}
|
|
3885
|
+
function rewriteConnectionRequired(err, triggerSlug) {
|
|
3886
|
+
if (!(err instanceof EnginiValidationError2) || err.errorCode !== "EMPTY_QUERY") {
|
|
3887
|
+
return err;
|
|
3888
|
+
}
|
|
3889
|
+
const namesConnection = err.details.some(
|
|
3890
|
+
(d) => d.field === "connection_id"
|
|
3891
|
+
);
|
|
3892
|
+
if (!namesConnection) return err;
|
|
3893
|
+
return new EnginiValidationError2(
|
|
3894
|
+
`Trigger type '${triggerSlug}' requires a connection. Pass --connection NAME|ID.`,
|
|
3895
|
+
{ errorCode: err.errorCode, details: err.details }
|
|
3896
|
+
);
|
|
3897
|
+
}
|
|
3780
3898
|
var WEEKDAY_NAMES = {
|
|
3781
3899
|
sun: 0,
|
|
3782
3900
|
mon: 1,
|
|
@@ -3884,6 +4002,7 @@ function summarizeEvent(e) {
|
|
|
3884
4002
|
|
|
3885
4003
|
// src/triggers/create.ts
|
|
3886
4004
|
function connectionRef(raw) {
|
|
4005
|
+
if (raw === void 0) return {};
|
|
3887
4006
|
return /^\d+$/.test(raw) ? { connectionId: Number(raw) } : { connectionName: raw };
|
|
3888
4007
|
}
|
|
3889
4008
|
async function hasAccountDefaultDestination() {
|
|
@@ -3897,8 +4016,11 @@ async function hasAccountDefaultDestination() {
|
|
|
3897
4016
|
}
|
|
3898
4017
|
async function createBody4(triggerSlug, opts) {
|
|
3899
4018
|
if (triggerSlug === void 0 || triggerSlug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
|
|
3900
|
-
if (opts.connection ===
|
|
3901
|
-
fail(
|
|
4019
|
+
if (opts.connection === "") {
|
|
4020
|
+
fail(
|
|
4021
|
+
2 /* USAGE */,
|
|
4022
|
+
"--connection cannot be empty; omit the flag entirely to use the trigger type's own connection, or pass a name or id."
|
|
4023
|
+
);
|
|
3902
4024
|
}
|
|
3903
4025
|
const config = parseConfig(opts.config);
|
|
3904
4026
|
const schedule = parseSchedule(opts);
|
|
@@ -3907,7 +4029,7 @@ async function createBody4(triggerSlug, opts) {
|
|
|
3907
4029
|
printOutput({
|
|
3908
4030
|
would_create: {
|
|
3909
4031
|
trigger_slug: triggerSlug,
|
|
3910
|
-
connection: opts.connection,
|
|
4032
|
+
connection: opts.connection ?? null,
|
|
3911
4033
|
config,
|
|
3912
4034
|
schedule,
|
|
3913
4035
|
listen_columns: opts.listen,
|
|
@@ -3922,17 +4044,21 @@ async function createBody4(triggerSlug, opts) {
|
|
|
3922
4044
|
const dest = await apiErrors(async () => buildClient().triggers.destinations.get(opts.destination));
|
|
3923
4045
|
destinationId = dest.id;
|
|
3924
4046
|
}
|
|
3925
|
-
const trigger = await apiErrors(
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
4047
|
+
const trigger = await apiErrors(async () => {
|
|
4048
|
+
try {
|
|
4049
|
+
return await buildClient().triggers.create({
|
|
4050
|
+
triggerSlug,
|
|
4051
|
+
...connectionRef(opts.connection),
|
|
4052
|
+
config,
|
|
4053
|
+
schedule,
|
|
4054
|
+
listenColumns: opts.listen,
|
|
4055
|
+
destinationId,
|
|
4056
|
+
dedupeWindowHours
|
|
4057
|
+
});
|
|
4058
|
+
} catch (err) {
|
|
4059
|
+
throw rewriteConnectionRequired(err, triggerSlug);
|
|
4060
|
+
}
|
|
4061
|
+
});
|
|
3936
4062
|
if (opts.destination === void 0) {
|
|
3937
4063
|
const hasDefault = await apiErrors(hasAccountDefaultDestination);
|
|
3938
4064
|
if (!hasDefault) {
|
|
@@ -3948,7 +4074,10 @@ async function createBody4(triggerSlug, opts) {
|
|
|
3948
4074
|
});
|
|
3949
4075
|
}
|
|
3950
4076
|
function registerTriggerCreate(triggers) {
|
|
3951
|
-
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(
|
|
4077
|
+
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(
|
|
4078
|
+
"--connection <name|id>",
|
|
4079
|
+
"The connection to run against (defaults to the trigger type's own connection for types that need none)"
|
|
4080
|
+
).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");
|
|
3952
4081
|
create.addHelpText(
|
|
3953
4082
|
"after",
|
|
3954
4083
|
"\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"
|
|
@@ -4212,7 +4341,7 @@ function sign(secret, bodyBytes) {
|
|
|
4212
4341
|
const mac = createHmac("sha256", Buffer.from(secret, "utf8")).update(Buffer.concat([Buffer.from(`${t}.`, "utf8"), bodyBytes])).digest("hex");
|
|
4213
4342
|
return `t=${t},v1=${mac}`;
|
|
4214
4343
|
}
|
|
4215
|
-
async function forwardEvent(frame, url, secret) {
|
|
4344
|
+
async function forwardEvent(frame, url, secret, signal) {
|
|
4216
4345
|
const body = buildDeliveryBody(frame);
|
|
4217
4346
|
const bytes = Buffer.from(JSON.stringify(body), "utf8");
|
|
4218
4347
|
const headers = {
|
|
@@ -4226,7 +4355,7 @@ async function forwardEvent(frame, url, secret) {
|
|
|
4226
4355
|
}
|
|
4227
4356
|
if (secret) headers["X-Engini-Signature"] = sign(secret, bytes);
|
|
4228
4357
|
try {
|
|
4229
|
-
const res = await fetch(url, { method: "POST", headers, body: bytes });
|
|
4358
|
+
const res = await fetch(url, { method: "POST", headers, body: bytes, signal });
|
|
4230
4359
|
if (!res.ok) {
|
|
4231
4360
|
console.error(`forward to ${url} failed: HTTP ${res.status}`);
|
|
4232
4361
|
return false;
|
|
@@ -4245,8 +4374,10 @@ async function listenBody(opts) {
|
|
|
4245
4374
|
);
|
|
4246
4375
|
}
|
|
4247
4376
|
let interrupted = false;
|
|
4377
|
+
const controller = new AbortController();
|
|
4248
4378
|
const onSigint = () => {
|
|
4249
4379
|
interrupted = true;
|
|
4380
|
+
controller.abort();
|
|
4250
4381
|
};
|
|
4251
4382
|
process.once("SIGINT", onSigint);
|
|
4252
4383
|
let events = 0;
|
|
@@ -4259,14 +4390,15 @@ async function listenBody(opts) {
|
|
|
4259
4390
|
triggerSlug: opts.slug,
|
|
4260
4391
|
applicationSlug: opts.app,
|
|
4261
4392
|
since: opts.since,
|
|
4262
|
-
autoResume: opts.resume
|
|
4393
|
+
autoResume: opts.resume,
|
|
4394
|
+
signal: controller.signal
|
|
4263
4395
|
});
|
|
4264
4396
|
for await (const frame of stream) {
|
|
4265
4397
|
if (interrupted) break;
|
|
4266
4398
|
events += 1;
|
|
4267
4399
|
emitEvent(frame);
|
|
4268
4400
|
if (opts.forward !== void 0) {
|
|
4269
|
-
const ok = await forwardEvent(frame, opts.forward, secret);
|
|
4401
|
+
const ok = await forwardEvent(frame, opts.forward, secret, controller.signal);
|
|
4270
4402
|
if (ok) forwarded += 1;
|
|
4271
4403
|
else failed += 1;
|
|
4272
4404
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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.24.0",
|
|
30
30
|
"commander": "^12.1.0",
|
|
31
31
|
"smol-toml": "^1.3.0"
|
|
32
32
|
},
|