@engini/cli 0.24.0 → 0.27.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 +30 -1
- package/dist/cli.js +650 -120
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,13 @@ var PromptStreamEnded = class extends Error {
|
|
|
30
30
|
this.name = "PromptStreamEnded";
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
async function readStdin(stream = process.stdin) {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
for await (const chunk of stream) {
|
|
36
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
37
|
+
}
|
|
38
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
39
|
+
}
|
|
33
40
|
function ask(rl, question) {
|
|
34
41
|
return new Promise((resolve, reject) => {
|
|
35
42
|
let answered = false;
|
|
@@ -383,6 +390,7 @@ import {
|
|
|
383
390
|
ENV_COMPANY_TOKEN_VAR,
|
|
384
391
|
ENV_TOKEN_VAR,
|
|
385
392
|
EnginiAuthError,
|
|
393
|
+
EnginiConflictError,
|
|
386
394
|
EnginiError,
|
|
387
395
|
EnginiMcpServerNotFoundError,
|
|
388
396
|
EnginiNotFoundError,
|
|
@@ -442,7 +450,7 @@ function saveConfig(config, path = configPath()) {
|
|
|
442
450
|
}
|
|
443
451
|
|
|
444
452
|
// src/version.ts
|
|
445
|
-
var VERSION = true ? "0.
|
|
453
|
+
var VERSION = true ? "0.27.0" : "0.0.0";
|
|
446
454
|
|
|
447
455
|
// src/http.ts
|
|
448
456
|
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
@@ -464,10 +472,19 @@ function buildClient(overrides = {}) {
|
|
|
464
472
|
userAgentPrefix: USER_AGENT_PREFIX
|
|
465
473
|
});
|
|
466
474
|
}
|
|
475
|
+
var AUTH_PROVIDER_CONFLICT_CODES = /* @__PURE__ */ new Set([
|
|
476
|
+
"AUTH_PROVIDER_IN_USE",
|
|
477
|
+
"AUTH_PROVIDER_NOT_SUPPORTED",
|
|
478
|
+
"AUTH_PROVIDER_NAME_TAKEN",
|
|
479
|
+
"CONNECTOR_REMOVED"
|
|
480
|
+
]);
|
|
467
481
|
function exitForError(err) {
|
|
468
482
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
469
483
|
if (err instanceof EnginiOpaApplicationAmbiguousError) return 5 /* VALIDATION */;
|
|
470
484
|
if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
|
|
485
|
+
if (err instanceof EnginiConflictError && err.errorCode !== void 0 && AUTH_PROVIDER_CONFLICT_CODES.has(err.errorCode)) {
|
|
486
|
+
return 5 /* VALIDATION */;
|
|
487
|
+
}
|
|
471
488
|
if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
|
|
472
489
|
if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
|
|
473
490
|
if (err instanceof EnginiTriggerGapError) return 4 /* NOT_FOUND */;
|
|
@@ -568,6 +585,42 @@ function registerApplications(program) {
|
|
|
568
585
|
registerApplicationsGet(applications);
|
|
569
586
|
}
|
|
570
587
|
|
|
588
|
+
// src/connections/auth-providers/resolve.ts
|
|
589
|
+
var PROVIDER_OPTION_HELP = "Auth provider: a name, a numeric id, or 'none' for the connector's own OAuth client";
|
|
590
|
+
async function resolveProvider(client, spec) {
|
|
591
|
+
if (spec === void 0) return void 0;
|
|
592
|
+
const value = spec.trim();
|
|
593
|
+
if (value === "") fail(2 /* USAGE */, "--provider needs a name, an id, or 'none'.");
|
|
594
|
+
if (value.toLowerCase() === "none" || value === "0") return { id: 0 };
|
|
595
|
+
const usable = await client.authProviders.usable();
|
|
596
|
+
const matches = /^\d+$/.test(value) ? usable.filter((p) => p.id === Number(value)) : usable.filter((p) => p.providerName === value);
|
|
597
|
+
if (matches.length === 0) {
|
|
598
|
+
fail(
|
|
599
|
+
4 /* NOT_FOUND */,
|
|
600
|
+
`No usable auth provider '${value}'. It may not exist, be disabled, or be unavailable to you.`,
|
|
601
|
+
"Run `engini connections auth-providers usable` to list the providers you can use."
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
if (matches.length > 1) {
|
|
605
|
+
fail(
|
|
606
|
+
2 /* USAGE */,
|
|
607
|
+
`Several auth providers are named '${value}': ids ${matches.map((p) => p.id).join(", ")}.`,
|
|
608
|
+
"Pass the numeric id to --provider."
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
return { id: matches[0].id, sourceAuthenticationId: matches[0].sourceAuthenticationId };
|
|
612
|
+
}
|
|
613
|
+
function assertProviderFitsMethod(provider, authenticationId) {
|
|
614
|
+
if (provider?.sourceAuthenticationId === void 0) return;
|
|
615
|
+
if (provider.sourceAuthenticationId !== authenticationId) {
|
|
616
|
+
fail(
|
|
617
|
+
2 /* USAGE */,
|
|
618
|
+
`Auth provider ${provider.id} is for authentication method ${provider.sourceAuthenticationId}, not ${authenticationId}.`,
|
|
619
|
+
"Drop --auth to use the provider's own method, or pick a provider for this method."
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
571
624
|
// src/connections/shared.ts
|
|
572
625
|
import { EnginiNetworkError, EnginiServerError, refreshFailed } from "@engini/sdk";
|
|
573
626
|
var GATEWAY_TIMEOUT_MARKERS = ["502", "503", "504", "gateway", "timeout"];
|
|
@@ -589,8 +642,6 @@ async function safeTrigger(action, what) {
|
|
|
589
642
|
throw err;
|
|
590
643
|
}
|
|
591
644
|
}
|
|
592
|
-
var OAUTH_DONE = /* @__PURE__ */ new Set(["completed", "complete", "success", "succeeded"]);
|
|
593
|
-
var OAUTH_FAILED = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled", "denied"]);
|
|
594
645
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
595
646
|
var OAUTH_STATE_TTL_SECONDS = 300;
|
|
596
647
|
function collect(value, previous = []) {
|
|
@@ -642,24 +693,31 @@ async function pollRefresh(client, connectionId, opts) {
|
|
|
642
693
|
}
|
|
643
694
|
return "completed";
|
|
644
695
|
}
|
|
645
|
-
async function
|
|
696
|
+
async function pollSignInStatus(client, state, opts) {
|
|
646
697
|
progress(
|
|
647
698
|
`Waiting for you to finish signing in (up to ${Math.round(opts.timeout)}s, Ctrl-C to abort)\u2026`
|
|
648
699
|
);
|
|
649
700
|
const deadline = Date.now() + opts.timeout * 1e3;
|
|
650
701
|
for (; ; ) {
|
|
651
|
-
const resp = await client.connections.
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
702
|
+
const resp = await client.connections.getSignInStatus(state);
|
|
703
|
+
switch (resp.status) {
|
|
704
|
+
case "signed_in":
|
|
705
|
+
return resp;
|
|
706
|
+
case "expired":
|
|
707
|
+
fail(
|
|
708
|
+
4 /* NOT_FOUND */,
|
|
709
|
+
`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.`,
|
|
710
|
+
"Start over: `engini connect <app>` mints a fresh sign_in_url + state."
|
|
711
|
+
);
|
|
712
|
+
break;
|
|
713
|
+
case "failed":
|
|
714
|
+
case "cancelled":
|
|
715
|
+
fail(
|
|
716
|
+
1 /* GENERIC */,
|
|
717
|
+
`OAuth sign-in ${resp.status}.`,
|
|
718
|
+
"Start over: `engini connect <app>` mints a fresh sign_in_url + state."
|
|
719
|
+
);
|
|
720
|
+
break;
|
|
663
721
|
}
|
|
664
722
|
if (Date.now() >= deadline) {
|
|
665
723
|
fail(124 /* TIMEOUT */, "OAuth sign-in did not complete in time.");
|
|
@@ -667,14 +725,6 @@ async function pollAccessToken(client, state, opts) {
|
|
|
667
725
|
await sleep(opts.interval * 1e3);
|
|
668
726
|
}
|
|
669
727
|
}
|
|
670
|
-
function oauthFields(token) {
|
|
671
|
-
const fields = {};
|
|
672
|
-
for (const [key, value] of Object.entries(token.connectionData ?? {})) {
|
|
673
|
-
if (value === null || value === void 0 || value === "") continue;
|
|
674
|
-
fields[key] = typeof value === "string" ? value : JSON.stringify(value);
|
|
675
|
-
}
|
|
676
|
-
return fields;
|
|
677
|
-
}
|
|
678
728
|
|
|
679
729
|
// src/connect.ts
|
|
680
730
|
var PLACEHOLDER = "<value>";
|
|
@@ -708,27 +758,52 @@ async function connectBody(application, opts) {
|
|
|
708
758
|
}
|
|
709
759
|
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
710
760
|
const detail4 = await client.applications.get(application);
|
|
711
|
-
const
|
|
761
|
+
const provider = await resolveProvider(client, opts.provider);
|
|
762
|
+
if (provider?.sourceAuthenticationId !== void 0) {
|
|
763
|
+
const methods = detail4.authenticationMethods ?? [];
|
|
764
|
+
if (!methods.some((m) => m.authenticationId === provider.sourceAuthenticationId)) {
|
|
765
|
+
fail(
|
|
766
|
+
2 /* USAGE */,
|
|
767
|
+
`Auth provider ${provider.id} is not for '${application}'.`,
|
|
768
|
+
"Run `engini connections auth-providers usable` to see which application each provider is for."
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
const method = await chooseAuth(
|
|
773
|
+
detail4.authenticationMethods ?? [],
|
|
774
|
+
opts.auth ?? (provider?.sourceAuthenticationId !== void 0 ? String(provider.sourceAuthenticationId) : void 0),
|
|
775
|
+
application,
|
|
776
|
+
provider
|
|
777
|
+
);
|
|
778
|
+
assertProviderFitsMethod(provider, method.authenticationId);
|
|
712
779
|
if (dryRun()) {
|
|
713
780
|
printOutput({
|
|
714
781
|
would_connect: {
|
|
715
782
|
application,
|
|
716
783
|
authentication_id: method.authenticationId,
|
|
717
|
-
oauth: Boolean(method.requiresOAuthSignIn)
|
|
784
|
+
oauth: Boolean(method.requiresOAuthSignIn),
|
|
785
|
+
...provider ? { auth_provider_id: provider.id } : {}
|
|
718
786
|
}
|
|
719
787
|
});
|
|
720
788
|
return;
|
|
721
789
|
}
|
|
722
790
|
const name = await resolveName(opts.name, application);
|
|
723
|
-
const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, opts.field, timing) : {
|
|
791
|
+
const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, opts.field, timing, provider) : {
|
|
792
|
+
fields: await collectFields(method, application, parseFields(opts.field), void 0, void 0, provider)
|
|
793
|
+
};
|
|
724
794
|
progress(`Creating connection '${name}'\u2026`);
|
|
725
795
|
const created = await client.connections.create(
|
|
726
796
|
application,
|
|
727
797
|
name,
|
|
728
798
|
method.authenticationId,
|
|
729
799
|
credentials.fields,
|
|
730
|
-
|
|
731
|
-
|
|
800
|
+
{
|
|
801
|
+
// Present only for OAuth methods; a non-OAuth create has no sign-in to point at.
|
|
802
|
+
...credentials.state ? { oauthState: credentials.state } : {},
|
|
803
|
+
// On create the provider is a query parameter the server honours only for a method
|
|
804
|
+
// with no sign-in; an OAuth sign-in already pinned it in get-sign-in-url.
|
|
805
|
+
...provider && !method.requiresOAuthSignIn ? { authProviderId: provider.id } : {}
|
|
806
|
+
}
|
|
732
807
|
);
|
|
733
808
|
const connectionId = created.connectionId;
|
|
734
809
|
progress(`Checking connection ${connectionId}\u2026`);
|
|
@@ -762,7 +837,7 @@ function parseObjectIds(specs) {
|
|
|
762
837
|
return n;
|
|
763
838
|
});
|
|
764
839
|
}
|
|
765
|
-
async function chooseAuth(methods, auth, application) {
|
|
840
|
+
async function chooseAuth(methods, auth, application, provider) {
|
|
766
841
|
if (methods.length === 0) {
|
|
767
842
|
fail(1 /* GENERIC */, `Application '${application}' exposes no authentication methods.`);
|
|
768
843
|
}
|
|
@@ -806,10 +881,10 @@ async function chooseAuth(methods, auth, application) {
|
|
|
806
881
|
need: "auth",
|
|
807
882
|
application,
|
|
808
883
|
methods: methods.map(methodSummary),
|
|
809
|
-
resume: `engini connect ${application} --auth <id
|
|
884
|
+
resume: `engini connect ${application} --auth <id>${providerResumeFlag(provider)}`
|
|
810
885
|
});
|
|
811
886
|
}
|
|
812
|
-
async function collectFields(method, application, provided, oauthState, fieldOptions) {
|
|
887
|
+
async function collectFields(method, application, provided, oauthState, fieldOptions, provider, derived) {
|
|
813
888
|
async function readSecretField(label) {
|
|
814
889
|
const { value, truncated } = await promptHidden(label);
|
|
815
890
|
if (truncated) {
|
|
@@ -821,8 +896,11 @@ async function collectFields(method, application, provided, oauthState, fieldOpt
|
|
|
821
896
|
}
|
|
822
897
|
return value;
|
|
823
898
|
}
|
|
824
|
-
const
|
|
825
|
-
const
|
|
899
|
+
const providerPinned = provider !== void 0 && provider.id > 0;
|
|
900
|
+
const schema = method.connectionFields.filter(
|
|
901
|
+
(f) => !f.isHidden && !(providerPinned && f.setOnProvider)
|
|
902
|
+
);
|
|
903
|
+
const resumeHint = oauthState ? `Resume with: engini connect ${application} --auth ${method.authenticationId} --oauth-state ${oauthState}${providerResumeFlag(provider)}` : void 0;
|
|
826
904
|
for (const [k, v] of Object.entries(provided)) {
|
|
827
905
|
if (v === PLACEHOLDER) delete provided[k];
|
|
828
906
|
}
|
|
@@ -841,12 +919,14 @@ async function collectFields(method, application, provided, oauthState, fieldOpt
|
|
|
841
919
|
);
|
|
842
920
|
}
|
|
843
921
|
}
|
|
922
|
+
for (const k of derived ?? []) delete provided[k];
|
|
923
|
+
const isSatisfied = (name) => name in provided || (derived?.has(name) ?? false);
|
|
844
924
|
const required = schema.filter((f) => f.isRequired);
|
|
845
|
-
const missing = required.filter((f) => !(f.fieldName
|
|
925
|
+
const missing = required.filter((f) => !isSatisfied(f.fieldName));
|
|
846
926
|
if (missing.length === 0) return provided;
|
|
847
927
|
if (isInteractive()) {
|
|
848
928
|
for (const f of schema) {
|
|
849
|
-
if (f.fieldName
|
|
929
|
+
if (isSatisfied(f.fieldName)) continue;
|
|
850
930
|
const label = fieldLabel(f);
|
|
851
931
|
const options = fieldOptions?.[f.fieldName];
|
|
852
932
|
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) ?? "");
|
|
@@ -859,6 +939,7 @@ async function collectFields(method, application, provided, oauthState, fieldOpt
|
|
|
859
939
|
`engini connect ${application}`,
|
|
860
940
|
`--auth ${method.authenticationId}`,
|
|
861
941
|
...oauthState ? [`--oauth-state ${oauthState}`] : [],
|
|
942
|
+
...provider ? [`--provider ${provider.id}`] : [],
|
|
862
943
|
fieldsFlags
|
|
863
944
|
].filter(Boolean);
|
|
864
945
|
return need({
|
|
@@ -921,26 +1002,25 @@ async function resolveObjects(objs, connectionId, application) {
|
|
|
921
1002
|
resume: `engini connect ${app} --connection ${connectionId} --object <id>`
|
|
922
1003
|
});
|
|
923
1004
|
}
|
|
924
|
-
async function oauthFieldsFor(client, application, method, oauthState, field, timing) {
|
|
1005
|
+
async function oauthFieldsFor(client, application, method, oauthState, field, timing, provider) {
|
|
925
1006
|
const cliFields = parseFields(field);
|
|
926
1007
|
if (oauthState) {
|
|
927
|
-
const
|
|
928
|
-
const merged = { ...cliFields, ...oauthFields(token) };
|
|
1008
|
+
const status = await pollSignInStatus(client, oauthState, timing);
|
|
929
1009
|
return {
|
|
930
|
-
fields: await collectFields(method, application,
|
|
1010
|
+
fields: await collectFields(method, application, cliFields, oauthState, status.fieldOptions, provider, new Set(status.derivedFields)),
|
|
931
1011
|
state: oauthState
|
|
932
1012
|
};
|
|
933
1013
|
}
|
|
934
1014
|
const resp = await client.connections.getSignInUrl(application, method.authenticationId, {
|
|
935
|
-
fields: field && field.length > 0 ? cliFields : void 0
|
|
1015
|
+
fields: field && field.length > 0 ? cliFields : void 0,
|
|
1016
|
+
authProviderId: provider?.id
|
|
936
1017
|
});
|
|
937
1018
|
if (isTty() && timing.wait) {
|
|
938
1019
|
openBrowser(resp.signInUrl);
|
|
939
1020
|
progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
|
|
940
|
-
const
|
|
941
|
-
const merged = { ...cliFields, ...oauthFields(token) };
|
|
1021
|
+
const status = await pollSignInStatus(client, resp.state, timing);
|
|
942
1022
|
return {
|
|
943
|
-
fields: await collectFields(method, application,
|
|
1023
|
+
fields: await collectFields(method, application, cliFields, resp.state, status.fieldOptions, provider, new Set(status.derivedFields)),
|
|
944
1024
|
state: resp.state
|
|
945
1025
|
};
|
|
946
1026
|
}
|
|
@@ -967,10 +1047,16 @@ async function oauthFieldsFor(client, application, method, oauthState, field, ti
|
|
|
967
1047
|
`engini connect ${application}`,
|
|
968
1048
|
`--auth ${method.authenticationId}`,
|
|
969
1049
|
`--oauth-state ${resp.state}`,
|
|
1050
|
+
// The state pins the provider server-side, but the replay still needs it client-side to
|
|
1051
|
+
// know which "Set on provider" fields not to ask for again.
|
|
1052
|
+
...provider ? [`--provider ${provider.id}`] : [],
|
|
970
1053
|
...(field ?? []).map((spec) => resumeFieldFlag(spec, secretFields))
|
|
971
1054
|
].join(" ")
|
|
972
1055
|
});
|
|
973
1056
|
}
|
|
1057
|
+
function providerResumeFlag(provider) {
|
|
1058
|
+
return provider ? ` --provider ${provider.id}` : "";
|
|
1059
|
+
}
|
|
974
1060
|
var SAFE_BAREWORD = /^[A-Za-z0-9_@%+:,./=-]+$/;
|
|
975
1061
|
function shellQuoteFieldSpec(spec) {
|
|
976
1062
|
if (SAFE_BAREWORD.test(spec)) return spec;
|
|
@@ -1007,7 +1093,7 @@ function methodSummary(m) {
|
|
|
1007
1093
|
// to have discovered them from. Each field's `options` therefore comes back `null` in
|
|
1008
1094
|
// this `need: "auth"` payload specifically because it's not knowable yet, not because
|
|
1009
1095
|
// the field has none - that's a distinct case (`{}`, once a sign-in has run - see
|
|
1010
|
-
// `fieldSummary` and the `
|
|
1096
|
+
// `fieldSummary` and the `SignInStatusResponse.fieldOptions` doc in @engini/sdk). Worth
|
|
1011
1097
|
// calling out explicitly wherever step 5 documents this payload, since the two look the
|
|
1012
1098
|
// same on the wire (both fall out here as `options: null`) but mean different things.
|
|
1013
1099
|
fields: m.connectionFields.map((f) => fieldSummary(f))
|
|
@@ -1036,7 +1122,7 @@ function objectSummary(o) {
|
|
|
1036
1122
|
};
|
|
1037
1123
|
}
|
|
1038
1124
|
function registerConnect(program) {
|
|
1039
|
-
const cmd = program.command("connect").description("Create a connection (interactive/agent-resumable), or open the connections page.").argument("[application]", "Application slug to connect").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--object <id>", "Object id to select (repeatable)", collect).option("--no-objects", "Skip object selection").option("--oauth-state <state>", "Resume an OAuth2 sign-in by its state token").option("--connection <id>", "Resume object selection for an existing connection id").option("--no-wait", "Return early instead of waiting for async jobs").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between polls");
|
|
1125
|
+
const cmd = program.command("connect").description("Create a connection (interactive/agent-resumable), or open the connections page.").argument("[application]", "Application slug to connect").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--object <id>", "Object id to select (repeatable)", collect).option("--no-objects", "Skip object selection").option("--provider <name|id|none>", PROVIDER_OPTION_HELP).option("--oauth-state <state>", "Resume an OAuth2 sign-in by its state token").option("--connection <id>", "Resume object selection for an existing connection id").option("--no-wait", "Return early instead of waiting for async jobs").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between polls");
|
|
1040
1126
|
cmd.addHelpText(
|
|
1041
1127
|
"after",
|
|
1042
1128
|
[
|
|
@@ -1046,6 +1132,8 @@ function registerConnect(program) {
|
|
|
1046
1132
|
" engini connect monday # interactive walkthrough (TTY)",
|
|
1047
1133
|
" engini connect monday --field ApiKey=\u2026 --name 'My Monday'",
|
|
1048
1134
|
" engini connect monday --json # agent: prints the next step + exit 5",
|
|
1135
|
+
" engini connect salesforce --provider 'Acme prod' # sign in through your own OAuth app",
|
|
1136
|
+
" engini connect salesforce --provider none # the connector's own OAuth client",
|
|
1049
1137
|
" engini connect outlook --oauth-state <state> # resume an OAuth sign-in",
|
|
1050
1138
|
" engini connect monday --connection 42 --object 5 # resume object selection"
|
|
1051
1139
|
].join("\n")
|
|
@@ -1061,6 +1149,411 @@ function registerConnect(program) {
|
|
|
1061
1149
|
});
|
|
1062
1150
|
}
|
|
1063
1151
|
|
|
1152
|
+
// src/connections/auth-providers/shared.ts
|
|
1153
|
+
var SLOTS = [
|
|
1154
|
+
...Array.from({ length: 10 }, (_, i) => `Key${i + 1}`),
|
|
1155
|
+
"ApiUser",
|
|
1156
|
+
"ApiPassword",
|
|
1157
|
+
"BaseUrl"
|
|
1158
|
+
];
|
|
1159
|
+
var SLOT_HINT = `Valid slots: ${SLOTS.join(", ")}.`;
|
|
1160
|
+
function parseProviderId(value) {
|
|
1161
|
+
if (!value) fail(2 /* USAGE */, "Missing required argument 'id'.");
|
|
1162
|
+
if (!/^[1-9]\d*$/.test(value)) fail(2 /* USAGE */, "id must be a positive integer.");
|
|
1163
|
+
return Number(value);
|
|
1164
|
+
}
|
|
1165
|
+
function renderField(f) {
|
|
1166
|
+
return {
|
|
1167
|
+
slot: f.slot,
|
|
1168
|
+
label: clean(f.label),
|
|
1169
|
+
is_password: f.isPassword,
|
|
1170
|
+
is_required: f.isRequired,
|
|
1171
|
+
// A secret is write-only: never render a value for it, whatever the server sent.
|
|
1172
|
+
value: f.isPassword ? null : clean(f.value) ?? null,
|
|
1173
|
+
has_value: Boolean(f.hasValue)
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
function renderProvider(p) {
|
|
1177
|
+
return {
|
|
1178
|
+
id: p.id,
|
|
1179
|
+
provider_name: p.providerName,
|
|
1180
|
+
application_id: p.applicationId,
|
|
1181
|
+
application_name: clean(p.applicationName),
|
|
1182
|
+
source_authentication_id: p.sourceAuthenticationId,
|
|
1183
|
+
source_authentication_name: clean(p.sourceAuthenticationName),
|
|
1184
|
+
is_default: p.isDefault,
|
|
1185
|
+
is_sandbox: p.isSandbox,
|
|
1186
|
+
status: p.status === 1 ? "active" : "disabled",
|
|
1187
|
+
scopes_override: clean(p.scopesOverride),
|
|
1188
|
+
extra_options: clean(p.extraOptions),
|
|
1189
|
+
connection_count: p.connectionCount,
|
|
1190
|
+
connector_removed: p.connectorRemoved,
|
|
1191
|
+
no_longer_supported: p.noLongerSupported,
|
|
1192
|
+
fields_need_review: p.fieldsNeedReview,
|
|
1193
|
+
fields: p.fields.map(renderField)
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
function requireSlot(slot) {
|
|
1197
|
+
if (!SLOTS.includes(slot)) {
|
|
1198
|
+
fail(2 /* USAGE */, `Not a valid provider field slot. ${SLOT_HINT}`);
|
|
1199
|
+
}
|
|
1200
|
+
return slot;
|
|
1201
|
+
}
|
|
1202
|
+
async function collectFieldValues(specs, stdinSlots, opts) {
|
|
1203
|
+
const requests = [];
|
|
1204
|
+
for (const spec of specs ?? []) {
|
|
1205
|
+
const eq = spec.indexOf("=");
|
|
1206
|
+
if (eq === 0) fail(2 /* USAGE */, `--field needs a slot name before '='. ${SLOT_HINT}`);
|
|
1207
|
+
if (eq > 0) {
|
|
1208
|
+
requests.push({ slot: requireSlot(spec.slice(0, eq)), value: spec.slice(eq + 1), source: "inline" });
|
|
1209
|
+
} else {
|
|
1210
|
+
requests.push({ slot: requireSlot(spec), source: "prompt" });
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
if ((stdinSlots?.length ?? 0) > 1) fail(2 /* USAGE */, "--field-stdin can be given only once.");
|
|
1214
|
+
for (const slot of stdinSlots ?? []) requests.push({ slot: requireSlot(slot), source: "stdin" });
|
|
1215
|
+
if (requests.length === 0) return void 0;
|
|
1216
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1217
|
+
for (const r of requests) {
|
|
1218
|
+
if (seen.has(r.slot)) fail(2 /* USAGE */, `Field slot ${r.slot} was given more than once.`);
|
|
1219
|
+
seen.add(r.slot);
|
|
1220
|
+
}
|
|
1221
|
+
const out = {};
|
|
1222
|
+
for (const r of requests) {
|
|
1223
|
+
if (opts.dryRun) {
|
|
1224
|
+
out[r.slot] = "";
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
if (r.source === "inline") {
|
|
1228
|
+
out[r.slot] = r.value;
|
|
1229
|
+
} else if (r.source === "prompt") {
|
|
1230
|
+
if (!isInteractive()) {
|
|
1231
|
+
fail(
|
|
1232
|
+
2 /* USAGE */,
|
|
1233
|
+
`--field ${r.slot} has no value and there is no terminal to prompt on.`,
|
|
1234
|
+
`Pass --field ${r.slot}=<value>, or pipe the secret in: --field-stdin ${r.slot}`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
const { value, truncated } = await promptHidden(r.slot);
|
|
1238
|
+
if (truncated) {
|
|
1239
|
+
fail(2 /* USAGE */, `${r.slot} contained a line break - only the first line was captured.`);
|
|
1240
|
+
}
|
|
1241
|
+
out[r.slot] = nonBlank(value, r.slot);
|
|
1242
|
+
} else {
|
|
1243
|
+
if (process.stdin.isTTY) {
|
|
1244
|
+
fail(2 /* USAGE */, `--field-stdin ${r.slot} reads a piped value, but stdin is a terminal.`);
|
|
1245
|
+
}
|
|
1246
|
+
out[r.slot] = nonBlank(await readStdin(), r.slot);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return out;
|
|
1250
|
+
}
|
|
1251
|
+
function nonBlank(value, slot) {
|
|
1252
|
+
if (value === "") {
|
|
1253
|
+
fail(
|
|
1254
|
+
2 /* USAGE */,
|
|
1255
|
+
`No value for ${slot}; aborting.`,
|
|
1256
|
+
`To clear a slot on update, pass --field ${slot}= explicitly.`
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
return value;
|
|
1260
|
+
}
|
|
1261
|
+
async function resolveApplicationId(client, app) {
|
|
1262
|
+
if (/^\d+$/.test(app)) return Number(app);
|
|
1263
|
+
const detail4 = await client.applications.get(app);
|
|
1264
|
+
const name = clean(detail4.applicationName) ?? detail4.slug;
|
|
1265
|
+
const matches = (await client.authProviders.sources()).filter(
|
|
1266
|
+
(s) => (s.applicationName ?? "").toLowerCase() === name.toLowerCase()
|
|
1267
|
+
);
|
|
1268
|
+
if (matches.length === 1) return matches[0].applicationId;
|
|
1269
|
+
if (matches.length === 0) {
|
|
1270
|
+
fail(
|
|
1271
|
+
4 /* NOT_FOUND */,
|
|
1272
|
+
`Application '${app}' has no authentication method that allows auth providers.`,
|
|
1273
|
+
"Run `engini connections auth-providers sources` to list eligible applications."
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
return fail(
|
|
1277
|
+
2 /* USAGE */,
|
|
1278
|
+
`'${app}' matches several applications named '${name}': ids ${matches.map((m) => m.applicationId).join(", ")}.`,
|
|
1279
|
+
"Pass the numeric id to --app."
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
function parseIntOption(name, value) {
|
|
1283
|
+
if (!/^\d+$/.test(value)) fail(2 /* USAGE */, `${name} must be a non-negative integer.`);
|
|
1284
|
+
return Number(value);
|
|
1285
|
+
}
|
|
1286
|
+
async function defaultAuthenticationId(client, applicationId) {
|
|
1287
|
+
const source = (await client.authProviders.sources()).find((s) => s.applicationId === applicationId);
|
|
1288
|
+
if (!source) {
|
|
1289
|
+
fail(
|
|
1290
|
+
4 /* NOT_FOUND */,
|
|
1291
|
+
`Application ${applicationId} has no authentication method that allows auth providers.`,
|
|
1292
|
+
"Run `engini connections auth-providers sources` to list eligible applications."
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
if (source.methods.length === 1) return source.methods[0].authenticationId;
|
|
1296
|
+
return fail(
|
|
1297
|
+
2 /* USAGE */,
|
|
1298
|
+
`Application ${applicationId} has several eligible methods; pass --auth <id>: ${source.methods.map((m) => `${m.authenticationId} (${m.displayName ?? m.authenticationType})`).join(", ")}.`
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// src/connections/auth-providers/create.ts
|
|
1303
|
+
async function createBody(opts) {
|
|
1304
|
+
if (!opts.app) fail(2 /* USAGE */, "Missing required option '--app'.");
|
|
1305
|
+
if (!opts.name) fail(2 /* USAGE */, "Missing required option '--name'.");
|
|
1306
|
+
const app = opts.app;
|
|
1307
|
+
const name = opts.name;
|
|
1308
|
+
const auth = opts.auth !== void 0 ? parseIntOption("--auth", opts.auth) : void 0;
|
|
1309
|
+
const fieldValues = await collectFieldValues(opts.field, opts.fieldStdin, { dryRun: dryRun() });
|
|
1310
|
+
if (dryRun()) {
|
|
1311
|
+
printOutput({
|
|
1312
|
+
would_create: {
|
|
1313
|
+
application: app,
|
|
1314
|
+
authentication_id: auth ?? null,
|
|
1315
|
+
provider_name: name,
|
|
1316
|
+
is_default: Boolean(opts.default),
|
|
1317
|
+
is_sandbox: Boolean(opts.sandbox),
|
|
1318
|
+
scopes_override: opts.scopes ?? null,
|
|
1319
|
+
extra_options: opts.extraOptions ?? null,
|
|
1320
|
+
// Slot names only - a dry run must never print a value.
|
|
1321
|
+
field_slots: Object.keys(fieldValues ?? {})
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const created = await apiErrors(async () => {
|
|
1327
|
+
const client = buildClient();
|
|
1328
|
+
const applicationId = await resolveApplicationId(client, app);
|
|
1329
|
+
const sourceAuthenticationId = auth ?? await defaultAuthenticationId(client, applicationId);
|
|
1330
|
+
return client.authProviders.create({
|
|
1331
|
+
providerName: name,
|
|
1332
|
+
applicationId,
|
|
1333
|
+
sourceAuthenticationId,
|
|
1334
|
+
isDefault: Boolean(opts.default),
|
|
1335
|
+
isSandbox: Boolean(opts.sandbox),
|
|
1336
|
+
...opts.scopes !== void 0 ? { scopesOverride: opts.scopes } : {},
|
|
1337
|
+
...opts.extraOptions !== void 0 ? { extraOptions: opts.extraOptions } : {},
|
|
1338
|
+
...fieldValues !== void 0 ? { fieldValues } : {}
|
|
1339
|
+
});
|
|
1340
|
+
});
|
|
1341
|
+
printOutput(renderProvider(created));
|
|
1342
|
+
}
|
|
1343
|
+
function registerAuthProvidersCreate(group) {
|
|
1344
|
+
const cmd = group.command("create").description("Create an auth provider for one authentication method of an application.").option("--app <slug|id>", "Application slug, or numeric application id").option("--auth <id>", "Authentication method id (optional when the app has one eligible method)").option("--name <name>", "Provider name (unique within the account)").option("--default", "Make this the application's default provider").option("--sandbox", "The provider is for the vendor's sandbox environment").option("--scopes <scopes>", "Scopes that replace the method's own scope option").option("--extra-options <json>", "Extra OAuth options as a JSON object of strings").option("--field <slot[=value]>", "Provider field: Slot=value, or a bare Slot to prompt (repeatable)", collect).option("--field-stdin <slot>", "Read one provider field value from stdin (e.g. a secret)", collect);
|
|
1345
|
+
cmd.addHelpText(
|
|
1346
|
+
"after",
|
|
1347
|
+
[
|
|
1348
|
+
"",
|
|
1349
|
+
"Examples:",
|
|
1350
|
+
" engini connections auth-providers sources # find the app, method and slots",
|
|
1351
|
+
" engini connections auth-providers redirect-uri --app salesforce",
|
|
1352
|
+
" engini connections auth-providers create --app salesforce --name 'Acme prod' \\",
|
|
1353
|
+
" --field Key1=<client-id> --field Key2 # Key2 prompts, hidden",
|
|
1354
|
+
' printf %s "$SECRET" | engini connections auth-providers create --app salesforce \\',
|
|
1355
|
+
" --name 'Acme prod' --field Key1=<client-id> --field-stdin Key2"
|
|
1356
|
+
].join("\n")
|
|
1357
|
+
);
|
|
1358
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1359
|
+
cmd.action(async (opts, command) => {
|
|
1360
|
+
await runCommand(command, opts, true, () => createBody(opts));
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// src/connections/auth-providers/delete.ts
|
|
1365
|
+
async function deleteBody(idArg, opts) {
|
|
1366
|
+
const id = parseProviderId(idArg);
|
|
1367
|
+
if (dryRun()) {
|
|
1368
|
+
printOutput({ would_delete: id });
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
await confirmOrFail(`Delete auth provider ${id}?`, { force: Boolean(opts.force) });
|
|
1372
|
+
await apiErrors(async () => buildClient().authProviders.delete(id));
|
|
1373
|
+
printOutput({ deleted: id });
|
|
1374
|
+
}
|
|
1375
|
+
function registerAuthProvidersDelete(group) {
|
|
1376
|
+
const cmd = group.command("delete").description("Remove an auth provider (refused while a connection uses it).").argument("[id]", "Auth provider id").option("--force", "Delete without confirming");
|
|
1377
|
+
cmd.addHelpText("after", "\nExamples:\n engini connections auth-providers delete 7 --force");
|
|
1378
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1379
|
+
cmd.action(async (id, opts, command) => {
|
|
1380
|
+
await runCommand(command, opts, true, () => deleteBody(id, opts));
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
// src/connections/auth-providers/get.ts
|
|
1385
|
+
async function getBody2(idArg) {
|
|
1386
|
+
const id = parseProviderId(idArg);
|
|
1387
|
+
const provider = await apiErrors(async () => buildClient().authProviders.get(id));
|
|
1388
|
+
printOutput(renderProvider(provider));
|
|
1389
|
+
}
|
|
1390
|
+
function registerAuthProvidersGet(group) {
|
|
1391
|
+
const cmd = group.command("get").description("Show one auth provider.").argument("[id]", "Auth provider id");
|
|
1392
|
+
addUniversalOptions(cmd);
|
|
1393
|
+
cmd.action(async (id, opts, command) => {
|
|
1394
|
+
await runCommand(command, opts, false, () => getBody2(id));
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
// src/connections/auth-providers/list.ts
|
|
1399
|
+
async function listBody2() {
|
|
1400
|
+
const providers = await apiErrors(async () => buildClient().authProviders.list());
|
|
1401
|
+
printOutput(providers.map(renderProvider));
|
|
1402
|
+
}
|
|
1403
|
+
function registerAuthProvidersList(group) {
|
|
1404
|
+
const cmd = group.command("list").description("List the account's auth providers (needs permission to manage them).");
|
|
1405
|
+
cmd.addHelpText(
|
|
1406
|
+
"after",
|
|
1407
|
+
"\nA secret slot reads back as has_value: true with a null value.\nPlain members can resolve a provider by name with `auth-providers usable`."
|
|
1408
|
+
);
|
|
1409
|
+
addUniversalOptions(cmd);
|
|
1410
|
+
cmd.action(async (opts, command) => {
|
|
1411
|
+
await runCommand(command, opts, false, listBody2);
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/connections/auth-providers/redirect-uri.ts
|
|
1416
|
+
async function redirectUriBody(opts) {
|
|
1417
|
+
if (!opts.app) fail(2 /* USAGE */, "Missing required option '--app'.");
|
|
1418
|
+
const authenticationId = opts.auth !== void 0 ? parseIntOption("--auth", opts.auth) : void 0;
|
|
1419
|
+
const result = await apiErrors(async () => {
|
|
1420
|
+
const client = buildClient();
|
|
1421
|
+
const applicationId = await resolveApplicationId(client, opts.app);
|
|
1422
|
+
return client.authProviders.redirectUri(applicationId, {
|
|
1423
|
+
authenticationId,
|
|
1424
|
+
sandbox: Boolean(opts.sandbox)
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
printOutput({ redirect_uri: result.redirectUri });
|
|
1428
|
+
}
|
|
1429
|
+
function registerAuthProvidersRedirectUri(group) {
|
|
1430
|
+
const cmd = group.command("redirect-uri").description("Show the callback URL to register in your own OAuth app.").option("--app <slug|id>", "Application slug, or numeric application id").option("--auth <id>", "Authentication method id (optional when the app has one eligible method)").option("--sandbox", "Use the vendor's sandbox environment");
|
|
1431
|
+
cmd.addHelpText(
|
|
1432
|
+
"after",
|
|
1433
|
+
"\nExamples:\n engini connections auth-providers redirect-uri --app salesforce --sandbox"
|
|
1434
|
+
);
|
|
1435
|
+
addUniversalOptions(cmd);
|
|
1436
|
+
cmd.action(async (opts, command) => {
|
|
1437
|
+
await runCommand(command, opts, false, () => redirectUriBody(opts));
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// src/connections/auth-providers/sources.ts
|
|
1442
|
+
async function sourcesBody() {
|
|
1443
|
+
const sources = await apiErrors(async () => buildClient().authProviders.sources());
|
|
1444
|
+
printOutput(
|
|
1445
|
+
sources.map((s) => ({
|
|
1446
|
+
application_id: s.applicationId,
|
|
1447
|
+
application_name: clean(s.applicationName),
|
|
1448
|
+
methods: s.methods.map((m) => ({
|
|
1449
|
+
authentication_id: m.authenticationId,
|
|
1450
|
+
display_name: clean(m.displayName),
|
|
1451
|
+
authentication_type: m.authenticationType,
|
|
1452
|
+
fields: m.fields.map((f) => ({
|
|
1453
|
+
slot: f.slot,
|
|
1454
|
+
label: clean(f.label),
|
|
1455
|
+
is_password: f.isPassword,
|
|
1456
|
+
is_required: f.isRequired
|
|
1457
|
+
}))
|
|
1458
|
+
}))
|
|
1459
|
+
}))
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
function registerAuthProvidersSources(group) {
|
|
1463
|
+
const cmd = group.command("sources").description("List applications and methods a provider can be based on, with their field slots.");
|
|
1464
|
+
cmd.addHelpText(
|
|
1465
|
+
"after",
|
|
1466
|
+
"\nUse the application_id / authentication_id / slots with `auth-providers create`."
|
|
1467
|
+
);
|
|
1468
|
+
addUniversalOptions(cmd);
|
|
1469
|
+
cmd.action(async (opts, command) => {
|
|
1470
|
+
await runCommand(command, opts, false, sourcesBody);
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/connections/auth-providers/update.ts
|
|
1475
|
+
function parseStatus(value) {
|
|
1476
|
+
const v = value.toLowerCase();
|
|
1477
|
+
if (v === "active" || v === "1") return 1;
|
|
1478
|
+
if (v === "disabled" || v === "0") return 0;
|
|
1479
|
+
return fail(2 /* USAGE */, "--status must be 'active' or 'disabled'.");
|
|
1480
|
+
}
|
|
1481
|
+
async function updateBody(idArg, opts) {
|
|
1482
|
+
const id = parseProviderId(idArg);
|
|
1483
|
+
const fieldValues = await collectFieldValues(opts.field, opts.fieldStdin, { dryRun: dryRun() });
|
|
1484
|
+
const body = {
|
|
1485
|
+
...opts.name !== void 0 ? { providerName: opts.name } : {},
|
|
1486
|
+
...opts.default !== void 0 ? { isDefault: opts.default } : {},
|
|
1487
|
+
...opts.sandbox !== void 0 ? { isSandbox: opts.sandbox } : {},
|
|
1488
|
+
...opts.status !== void 0 ? { status: parseStatus(opts.status) } : {},
|
|
1489
|
+
...opts.scopes !== void 0 ? { scopesOverride: opts.scopes } : {},
|
|
1490
|
+
...opts.extraOptions !== void 0 ? { extraOptions: opts.extraOptions } : {},
|
|
1491
|
+
...fieldValues !== void 0 ? { fieldValues } : {}
|
|
1492
|
+
};
|
|
1493
|
+
if (Object.keys(body).length === 0) fail(2 /* USAGE */, "Nothing to update: pass at least one option.");
|
|
1494
|
+
if (dryRun()) {
|
|
1495
|
+
const { fieldValues: fv, ...rest } = body;
|
|
1496
|
+
printOutput({ would_update: { id, ...rest, ...fv ? { field_slots: Object.keys(fv) } : {} } });
|
|
1497
|
+
return;
|
|
1498
|
+
}
|
|
1499
|
+
const updated = await apiErrors(async () => buildClient().authProviders.update(id, body));
|
|
1500
|
+
printOutput(renderProvider(updated));
|
|
1501
|
+
}
|
|
1502
|
+
function registerAuthProvidersUpdate(group) {
|
|
1503
|
+
const cmd = group.command("update").description("Update an auth provider; omitted options and field slots are left unchanged.").argument("[id]", "Auth provider id").option("--name <name>", "New provider name").option("--default", "Make this the application's default provider").option("--no-default", "Stop this being the default provider").option("--sandbox", "Mark as the vendor's sandbox environment").option("--no-sandbox", "Mark as the vendor's production environment").option("--status <active|disabled>", "Enable or disable the provider").option("--scopes <scopes>", "New scopes override ('' clears it)").option("--extra-options <json>", "New extra OAuth options ('' clears them)").option("--field <slot[=value]>", "Field to change: Slot=value, bare Slot to prompt, Slot= to clear (repeatable)", collect).option("--field-stdin <slot>", "Read one field value from stdin (e.g. a secret)", collect);
|
|
1504
|
+
cmd.addHelpText(
|
|
1505
|
+
"after",
|
|
1506
|
+
[
|
|
1507
|
+
"",
|
|
1508
|
+
"Examples:",
|
|
1509
|
+
" engini connections auth-providers update 7 --status disabled",
|
|
1510
|
+
" engini connections auth-providers update 7 --field Key1=<new-client-id>",
|
|
1511
|
+
" engini connections auth-providers update 7 --field Key3= # clears Key3"
|
|
1512
|
+
].join("\n")
|
|
1513
|
+
);
|
|
1514
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1515
|
+
cmd.action(async (id, opts, command) => {
|
|
1516
|
+
await runCommand(command, opts, true, () => updateBody(id, opts));
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/connections/auth-providers/usable.ts
|
|
1521
|
+
async function usableBody() {
|
|
1522
|
+
const usable = await apiErrors(async () => buildClient().authProviders.usable());
|
|
1523
|
+
printOutput(
|
|
1524
|
+
usable.map((p) => ({
|
|
1525
|
+
id: p.id,
|
|
1526
|
+
provider_name: p.providerName,
|
|
1527
|
+
application_id: p.applicationId,
|
|
1528
|
+
application_name: clean(p.applicationName),
|
|
1529
|
+
source_authentication_id: p.sourceAuthenticationId,
|
|
1530
|
+
source_authentication_name: clean(p.sourceAuthenticationName),
|
|
1531
|
+
is_default: p.isDefault
|
|
1532
|
+
}))
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
function registerAuthProvidersUsable(group) {
|
|
1536
|
+
const cmd = group.command("usable").description("List active providers you can use for a connection (ids and names only).");
|
|
1537
|
+
cmd.addHelpText("after", "\nThe id is what `connect --provider <id>` takes; no field values are shown.");
|
|
1538
|
+
addUniversalOptions(cmd);
|
|
1539
|
+
cmd.action(async (opts, command) => {
|
|
1540
|
+
await runCommand(command, opts, false, usableBody);
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// src/connections/auth-providers/index.ts
|
|
1545
|
+
function registerAuthProviders(connections) {
|
|
1546
|
+
const group = connections.command("auth-providers").description("Manage your own OAuth/credential providers for connections.");
|
|
1547
|
+
registerAuthProvidersList(group);
|
|
1548
|
+
registerAuthProvidersGet(group);
|
|
1549
|
+
registerAuthProvidersCreate(group);
|
|
1550
|
+
registerAuthProvidersUpdate(group);
|
|
1551
|
+
registerAuthProvidersDelete(group);
|
|
1552
|
+
registerAuthProvidersRedirectUri(group);
|
|
1553
|
+
registerAuthProvidersSources(group);
|
|
1554
|
+
registerAuthProvidersUsable(group);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1064
1557
|
// src/connections/check.ts
|
|
1065
1558
|
async function checkBody(connectionId) {
|
|
1066
1559
|
const id = parseId(connectionId);
|
|
@@ -1093,7 +1586,7 @@ function summary(c) {
|
|
|
1093
1586
|
use_select_db_objects: clean(c.useSelectDBObjects)
|
|
1094
1587
|
};
|
|
1095
1588
|
}
|
|
1096
|
-
async function
|
|
1589
|
+
async function createBody2(application, opts) {
|
|
1097
1590
|
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
1098
1591
|
if (!opts.auth) fail(2 /* USAGE */, "Missing required option '--auth'.");
|
|
1099
1592
|
if (!opts.name) fail(2 /* USAGE */, "Missing required option '--name'.");
|
|
@@ -1107,21 +1600,25 @@ async function createBody(application, opts) {
|
|
|
1107
1600
|
connection_name: opts.name,
|
|
1108
1601
|
authentication_id: auth,
|
|
1109
1602
|
fields: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, maskSecret(v)])),
|
|
1110
|
-
description: opts.description ?? null
|
|
1603
|
+
description: opts.description ?? null,
|
|
1604
|
+
...opts.provider !== void 0 ? { provider: opts.provider } : {}
|
|
1111
1605
|
}
|
|
1112
1606
|
});
|
|
1113
1607
|
return;
|
|
1114
1608
|
}
|
|
1115
1609
|
const conn = await apiErrors(async () => {
|
|
1116
1610
|
const client = buildClient();
|
|
1611
|
+
const provider = await resolveProvider(client, opts.provider);
|
|
1612
|
+
assertProviderFitsMethod(provider, auth);
|
|
1117
1613
|
return client.connections.create(application, opts.name, auth, fields, {
|
|
1118
|
-
description: opts.description
|
|
1614
|
+
description: opts.description,
|
|
1615
|
+
authProviderId: provider?.id
|
|
1119
1616
|
});
|
|
1120
1617
|
});
|
|
1121
1618
|
printOutput(summary(conn));
|
|
1122
1619
|
}
|
|
1123
1620
|
function registerConnectionsCreate(connections) {
|
|
1124
|
-
const cmd = connections.command("create").description("Create a direct-credential connection.").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--description <text>", "Connection description");
|
|
1621
|
+
const cmd = connections.command("create").description("Create a direct-credential connection.").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--description <text>", "Connection description").option("--provider <name|id|none>", PROVIDER_OPTION_HELP);
|
|
1125
1622
|
cmd.addHelpText(
|
|
1126
1623
|
"after",
|
|
1127
1624
|
"\nExamples:\n engini connections create slack --auth 2 --name Sales --field token=xoxb-1"
|
|
@@ -1132,7 +1629,7 @@ function registerConnectionsCreate(connections) {
|
|
|
1132
1629
|
command,
|
|
1133
1630
|
opts,
|
|
1134
1631
|
true,
|
|
1135
|
-
() =>
|
|
1632
|
+
() => createBody2(application, opts)
|
|
1136
1633
|
);
|
|
1137
1634
|
});
|
|
1138
1635
|
}
|
|
@@ -1145,7 +1642,7 @@ function summarize2(d) {
|
|
|
1145
1642
|
connection_name: clean(d.connectionName)
|
|
1146
1643
|
};
|
|
1147
1644
|
}
|
|
1148
|
-
async function
|
|
1645
|
+
async function listBody3() {
|
|
1149
1646
|
const rows = await apiErrors(async () => {
|
|
1150
1647
|
const client = buildClient();
|
|
1151
1648
|
return client.connections.defaults();
|
|
@@ -1184,7 +1681,7 @@ function registerConnectionsDefaults(connections) {
|
|
|
1184
1681
|
);
|
|
1185
1682
|
addUniversalOptions(list);
|
|
1186
1683
|
list.action(async (opts, command) => {
|
|
1187
|
-
await runCommand(command, opts, false, () =>
|
|
1684
|
+
await runCommand(command, opts, false, () => listBody3());
|
|
1188
1685
|
});
|
|
1189
1686
|
const set = connections.command("set-default").description("Make a connection the default for its application.").argument("[connection_id]", "Connection id");
|
|
1190
1687
|
set.addHelpText("after", "\nExamples:\n engini connections set-default 481");
|
|
@@ -1203,7 +1700,7 @@ function registerConnectionsDefaults(connections) {
|
|
|
1203
1700
|
}
|
|
1204
1701
|
|
|
1205
1702
|
// src/connections/delete.ts
|
|
1206
|
-
async function
|
|
1703
|
+
async function deleteBody2(connectionId, opts) {
|
|
1207
1704
|
const id = parseId(connectionId);
|
|
1208
1705
|
if (dryRun()) {
|
|
1209
1706
|
printOutput({ would_delete: id });
|
|
@@ -1221,7 +1718,7 @@ function registerConnectionsDelete(connections) {
|
|
|
1221
1718
|
cmd.addHelpText("after", "\nExamples:\n engini connections delete 42 --force");
|
|
1222
1719
|
addUniversalOptions(cmd, { mutating: true });
|
|
1223
1720
|
cmd.action(async (id, opts, command) => {
|
|
1224
|
-
await runCommand(command, opts, true, () =>
|
|
1721
|
+
await runCommand(command, opts, true, () => deleteBody2(id, opts));
|
|
1225
1722
|
});
|
|
1226
1723
|
}
|
|
1227
1724
|
|
|
@@ -1252,7 +1749,7 @@ function parseId2(value) {
|
|
|
1252
1749
|
}
|
|
1253
1750
|
return id;
|
|
1254
1751
|
}
|
|
1255
|
-
async function
|
|
1752
|
+
async function getBody3(connectionId) {
|
|
1256
1753
|
const id = parseId2(connectionId);
|
|
1257
1754
|
const connection = await apiErrors(async () => {
|
|
1258
1755
|
const client = buildClient();
|
|
@@ -1265,7 +1762,7 @@ function registerConnectionsGet(connections) {
|
|
|
1265
1762
|
cmd.addHelpText("after", "\nExamples:\n engini connections get 42 --json");
|
|
1266
1763
|
addUniversalOptions(cmd);
|
|
1267
1764
|
cmd.action(async (id, opts, command) => {
|
|
1268
|
-
await runCommand(command, opts, false, () =>
|
|
1765
|
+
await runCommand(command, opts, false, () => getBody3(id));
|
|
1269
1766
|
});
|
|
1270
1767
|
}
|
|
1271
1768
|
|
|
@@ -1282,7 +1779,7 @@ function summarize3(c) {
|
|
|
1282
1779
|
created_date: c.createdDate
|
|
1283
1780
|
};
|
|
1284
1781
|
}
|
|
1285
|
-
async function
|
|
1782
|
+
async function listBody4(opts) {
|
|
1286
1783
|
const conns = await apiErrors(async () => {
|
|
1287
1784
|
const client = buildClient();
|
|
1288
1785
|
return client.connections.list(opts.application, opts.kind);
|
|
@@ -1302,7 +1799,7 @@ Examples:
|
|
|
1302
1799
|
);
|
|
1303
1800
|
addUniversalOptions(cmd);
|
|
1304
1801
|
cmd.action(async (opts, command) => {
|
|
1305
|
-
await runCommand(command, opts, false, () =>
|
|
1802
|
+
await runCommand(command, opts, false, () => listBody4(opts));
|
|
1306
1803
|
});
|
|
1307
1804
|
}
|
|
1308
1805
|
|
|
@@ -1329,12 +1826,12 @@ async function oauthCompleteBody(application, opts) {
|
|
|
1329
1826
|
}
|
|
1330
1827
|
const conn = await apiErrors(async () => {
|
|
1331
1828
|
const client = buildClient();
|
|
1332
|
-
|
|
1829
|
+
await pollSignInStatus(client, opts.state, {
|
|
1333
1830
|
timeout: Number(opts.timeout ?? 300),
|
|
1334
1831
|
interval: Number(opts.pollInterval ?? 2)
|
|
1335
1832
|
});
|
|
1336
1833
|
progress(`Creating connection '${name}'\u2026`);
|
|
1337
|
-
return client.connections.create(application, name, auth,
|
|
1834
|
+
return client.connections.create(application, name, auth, {}, {
|
|
1338
1835
|
oauthState: opts.state
|
|
1339
1836
|
});
|
|
1340
1837
|
});
|
|
@@ -1503,7 +2000,12 @@ async function signInUrlBody(application, opts) {
|
|
|
1503
2000
|
const fields = opts.field ? parseFields(opts.field) : void 0;
|
|
1504
2001
|
const resp = await apiErrors(async () => {
|
|
1505
2002
|
const client = buildClient();
|
|
1506
|
-
|
|
2003
|
+
const provider = await resolveProvider(client, opts.provider);
|
|
2004
|
+
assertProviderFitsMethod(provider, auth);
|
|
2005
|
+
return client.connections.getSignInUrl(application, auth, {
|
|
2006
|
+
fields,
|
|
2007
|
+
authProviderId: provider?.id
|
|
2008
|
+
});
|
|
1507
2009
|
});
|
|
1508
2010
|
printOutput({
|
|
1509
2011
|
sign_in_url: resp.signInUrl,
|
|
@@ -1512,7 +2014,7 @@ async function signInUrlBody(application, opts) {
|
|
|
1512
2014
|
});
|
|
1513
2015
|
}
|
|
1514
2016
|
function registerConnectionsSignInUrl(connections) {
|
|
1515
|
-
const cmd = connections.command("sign-in-url").description("Start an OAuth2 sign-in (returns the URL + state).").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--field <spec>", "Pre-sign-in field: key=value (repeatable)", collect);
|
|
2017
|
+
const cmd = connections.command("sign-in-url").description("Start an OAuth2 sign-in (returns the URL + state).").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--field <spec>", "Pre-sign-in field: key=value (repeatable)", collect).option("--provider <name|id|none>", PROVIDER_OPTION_HELP);
|
|
1516
2018
|
cmd.addHelpText("after", "\nExamples:\n engini connections sign-in-url outlook --auth 0");
|
|
1517
2019
|
addUniversalOptions(cmd);
|
|
1518
2020
|
cmd.action(async (application, opts, command) => {
|
|
@@ -1536,7 +2038,7 @@ function summary4(c) {
|
|
|
1536
2038
|
is_alive: clean(c.isAlive)
|
|
1537
2039
|
};
|
|
1538
2040
|
}
|
|
1539
|
-
async function
|
|
2041
|
+
async function updateBody2(idRaw, opts) {
|
|
1540
2042
|
const connectionId = parseId(idRaw);
|
|
1541
2043
|
const patch = {};
|
|
1542
2044
|
if (opts.name !== void 0) patch.name = opts.name;
|
|
@@ -1589,7 +2091,7 @@ function registerConnectionsUpdate(connections) {
|
|
|
1589
2091
|
command,
|
|
1590
2092
|
opts,
|
|
1591
2093
|
true,
|
|
1592
|
-
() =>
|
|
2094
|
+
() => updateBody2(idRaw, opts)
|
|
1593
2095
|
);
|
|
1594
2096
|
});
|
|
1595
2097
|
}
|
|
@@ -1610,12 +2112,13 @@ function registerConnections(program) {
|
|
|
1610
2112
|
registerConnectionsSelectObjects(connections);
|
|
1611
2113
|
registerConnectionsSignInUrl(connections);
|
|
1612
2114
|
registerConnectionsOauthComplete(connections);
|
|
2115
|
+
registerAuthProviders(connections);
|
|
1613
2116
|
}
|
|
1614
2117
|
|
|
1615
2118
|
// src/help.ts
|
|
1616
2119
|
import { Help } from "commander";
|
|
1617
2120
|
var REPO_URL = "https://github.com/engini/engini-sdk";
|
|
1618
|
-
var KEYS_URL = "https://app.engini.io/
|
|
2121
|
+
var KEYS_URL = "https://app.engini.io/api-keys";
|
|
1619
2122
|
var EXIT_LABELS = {
|
|
1620
2123
|
[0 /* OK */]: "success",
|
|
1621
2124
|
[1 /* GENERIC */]: "general error",
|
|
@@ -1668,17 +2171,20 @@ ACCOUNT
|
|
|
1668
2171
|
whoami Show the authenticated user/company.
|
|
1669
2172
|
|
|
1670
2173
|
CONNECTIONS
|
|
1671
|
-
connect [<app>]
|
|
2174
|
+
connect [<app>] [--provider <name|id|none>]
|
|
2175
|
+
Create a connection \u2014 interactive on a TTY, or
|
|
1672
2176
|
agent-resumable when piped (prints {need, resume}).
|
|
1673
2177
|
Resume with --oauth-state <state> (OAuth) or
|
|
1674
2178
|
--connection <id> (object selection). No app \u2192 web page.
|
|
2179
|
+
--provider signs in through your own auth provider
|
|
2180
|
+
(see AUTH PROVIDERS); 'none' = the connector's own client.
|
|
1675
2181
|
connections list [--application <slug>] [--kind <kind>]
|
|
1676
2182
|
List your connections. --kind filters on
|
|
1677
2183
|
Regular | Key | MCPClient. The web UI's
|
|
1678
2184
|
"Keys" tab is --kind Key. On-premise agents are
|
|
1679
2185
|
not connections - see ON-PREMISE AGENTS.
|
|
1680
2186
|
connections get <id> Inspect a connection.
|
|
1681
|
-
connections create <app> --auth <id> --name <n> --field k=v
|
|
2187
|
+
connections create <app> --auth <id> --name <n> --field k=v [--provider <name|id|none>]
|
|
1682
2188
|
Create a direct-credential connection.
|
|
1683
2189
|
connections update <id> [--name <n>] [--description <t>] [--field k=v] [--metadata k=v]
|
|
1684
2190
|
Update a connection. --field/--metadata REPLACE
|
|
@@ -1688,7 +2194,8 @@ CONNECTIONS
|
|
|
1688
2194
|
connections defaults List your per-application default connections.
|
|
1689
2195
|
connections set-default <id> Make a connection its application's default.
|
|
1690
2196
|
connections clear-default <app> Clear an application's default (takes a slug).
|
|
1691
|
-
connections sign-in-url <app> --auth <id>
|
|
2197
|
+
connections sign-in-url <app> --auth <id> [--provider <name|id|none>]
|
|
2198
|
+
Start an OAuth2 sign-in (returns URL + state).
|
|
1692
2199
|
connections oauth-complete <app> --auth <id> --state <state>
|
|
1693
2200
|
Finish an OAuth2 sign-in and create the connection.
|
|
1694
2201
|
connections check <id> Test a connection's liveness.
|
|
@@ -1697,6 +2204,29 @@ CONNECTIONS
|
|
|
1697
2204
|
connections select-objects <id> --object <id> Choose which objects to sync (async).
|
|
1698
2205
|
connections delete <id> [--force] Remove a connection.
|
|
1699
2206
|
|
|
2207
|
+
AUTH PROVIDERS
|
|
2208
|
+
Your own OAuth app / credentials for one authentication method of an app, filled once and
|
|
2209
|
+
used by every connection signed in through it. A provider is a name plus values for the
|
|
2210
|
+
connector's "Set on provider" fields, addressed by slot (Key1..Key10, ApiUser, ApiPassword,
|
|
2211
|
+
BaseUrl) - there is no client-id/client-secret flag; every value is a --field.
|
|
2212
|
+
connections auth-providers sources Which apps/methods can have a provider, and the slots to fill.
|
|
2213
|
+
connections auth-providers redirect-uri --app <slug|id> [--auth <id>] [--sandbox]
|
|
2214
|
+
The callback URL to register in your OAuth app FIRST.
|
|
2215
|
+
connections auth-providers create --app <slug|id> --name <n> [--auth <id>] [--default] [--sandbox]
|
|
2216
|
+
[--scopes <s>] [--extra-options <json>] [--field Slot=value ...] [--field-stdin Slot]
|
|
2217
|
+
Create a provider. A bare "--field Slot" prompts hidden on a
|
|
2218
|
+
terminal; "--field-stdin Slot" reads a secret from a pipe, so it
|
|
2219
|
+
never reaches shell history or ps.
|
|
2220
|
+
connections auth-providers update <id> [--name <n>] [--status active|disabled] [--default|--no-default]
|
|
2221
|
+
[--sandbox|--no-sandbox] [--scopes <s>] [--extra-options <json>] [--field ...]
|
|
2222
|
+
Change a provider. Omitted fields/slots are kept; "--field Slot="
|
|
2223
|
+
(empty) clears that slot. A secret reads back as has_value only.
|
|
2224
|
+
connections auth-providers list List providers with their field values (manager-only).
|
|
2225
|
+
connections auth-providers get <id> Show one provider.
|
|
2226
|
+
connections auth-providers usable Providers you may connect through (ids + names only).
|
|
2227
|
+
connections auth-providers delete <id> [--force]
|
|
2228
|
+
Remove a provider (refused while a connection uses it).
|
|
2229
|
+
|
|
1700
2230
|
TOOLSETS
|
|
1701
2231
|
toolsets list List your toolsets.
|
|
1702
2232
|
toolsets get <id> Show full detail for one toolset.
|
|
@@ -1898,7 +2428,7 @@ function installHelp(program) {
|
|
|
1898
2428
|
|
|
1899
2429
|
// src/login.ts
|
|
1900
2430
|
function keysUrl(config) {
|
|
1901
|
-
return `${config.identity_url.replace(/\/+$/, "")}/
|
|
2431
|
+
return `${config.identity_url.replace(/\/+$/, "")}/api-keys`;
|
|
1902
2432
|
}
|
|
1903
2433
|
var MAX_KEY_ATTEMPTS = 3;
|
|
1904
2434
|
function charCount(key) {
|
|
@@ -2296,7 +2826,7 @@ function registerMcpConnections(mcp) {
|
|
|
2296
2826
|
}
|
|
2297
2827
|
|
|
2298
2828
|
// src/mcp/get.ts
|
|
2299
|
-
async function
|
|
2829
|
+
async function getBody4(token) {
|
|
2300
2830
|
const mcpServerToken = parseMcpServerToken(token);
|
|
2301
2831
|
const server = await apiErrors(async () => {
|
|
2302
2832
|
const client = buildClient();
|
|
@@ -2315,12 +2845,12 @@ function registerMcpGet(mcp) {
|
|
|
2315
2845
|
cmd.addHelpText("after", "\nExamples:\n engini mcp get <mcp_server_token> --json");
|
|
2316
2846
|
addUniversalOptions(cmd);
|
|
2317
2847
|
cmd.action(async (token, opts, command) => {
|
|
2318
|
-
await runCommand(command, opts, false, () =>
|
|
2848
|
+
await runCommand(command, opts, false, () => getBody4(token));
|
|
2319
2849
|
});
|
|
2320
2850
|
}
|
|
2321
2851
|
|
|
2322
2852
|
// src/mcp/list.ts
|
|
2323
|
-
async function
|
|
2853
|
+
async function listBody5() {
|
|
2324
2854
|
const servers = await apiErrors(async () => {
|
|
2325
2855
|
const client = buildClient();
|
|
2326
2856
|
return client.mcp.list();
|
|
@@ -2335,7 +2865,7 @@ function registerMcpList(mcp) {
|
|
|
2335
2865
|
);
|
|
2336
2866
|
addUniversalOptions(cmd);
|
|
2337
2867
|
cmd.action(async (opts, command) => {
|
|
2338
|
-
await runCommand(command, opts, false, () =>
|
|
2868
|
+
await runCommand(command, opts, false, () => listBody5());
|
|
2339
2869
|
});
|
|
2340
2870
|
}
|
|
2341
2871
|
|
|
@@ -2373,7 +2903,7 @@ function registerMcpStatus(mcp) {
|
|
|
2373
2903
|
}
|
|
2374
2904
|
|
|
2375
2905
|
// src/mcp/tools.ts
|
|
2376
|
-
async function
|
|
2906
|
+
async function listBody6(token, connectionIdRaw) {
|
|
2377
2907
|
const mcpServerToken = parseMcpServerToken(token);
|
|
2378
2908
|
if (!connectionIdRaw) fail(2 /* USAGE */, "Missing required option '--connection-id'.");
|
|
2379
2909
|
const [connectionId] = parseConnectionIds([connectionIdRaw]);
|
|
@@ -2437,7 +2967,7 @@ function registerMcpTools(mcp) {
|
|
|
2437
2967
|
command,
|
|
2438
2968
|
opts,
|
|
2439
2969
|
false,
|
|
2440
|
-
() =>
|
|
2970
|
+
() => listBody6(token, opts.connectionId)
|
|
2441
2971
|
);
|
|
2442
2972
|
}
|
|
2443
2973
|
);
|
|
@@ -2608,7 +3138,7 @@ function addSettingsOptions(cmd) {
|
|
|
2608
3138
|
}
|
|
2609
3139
|
|
|
2610
3140
|
// src/opa/create.ts
|
|
2611
|
-
async function
|
|
3141
|
+
async function createBody3(opts) {
|
|
2612
3142
|
if (opts.name === void 0 || opts.name.trim() === "") fail(2 /* USAGE */, "--name is required.");
|
|
2613
3143
|
const settings = parseSettingsFlags(opts);
|
|
2614
3144
|
const preview = settingsPreview(settings);
|
|
@@ -2651,12 +3181,12 @@ function registerOpaCreate(opa) {
|
|
|
2651
3181
|
);
|
|
2652
3182
|
addUniversalOptions(cmd, { mutating: true });
|
|
2653
3183
|
cmd.action(async (opts, command) => {
|
|
2654
|
-
await runCommand(command, opts, true, () =>
|
|
3184
|
+
await runCommand(command, opts, true, () => createBody3(opts));
|
|
2655
3185
|
});
|
|
2656
3186
|
}
|
|
2657
3187
|
|
|
2658
3188
|
// src/opa/delete.ts
|
|
2659
|
-
async function
|
|
3189
|
+
async function deleteBody3(raw, opts) {
|
|
2660
3190
|
const agentId = parseAgentId(raw);
|
|
2661
3191
|
if (dryRun()) {
|
|
2662
3192
|
printOutput({ would_delete: agentId });
|
|
@@ -2678,7 +3208,7 @@ function registerOpaDelete(opa) {
|
|
|
2678
3208
|
command,
|
|
2679
3209
|
opts,
|
|
2680
3210
|
true,
|
|
2681
|
-
() =>
|
|
3211
|
+
() => deleteBody3(raw, opts)
|
|
2682
3212
|
);
|
|
2683
3213
|
});
|
|
2684
3214
|
}
|
|
@@ -2764,7 +3294,7 @@ function registerOpaDownload(opa) {
|
|
|
2764
3294
|
}
|
|
2765
3295
|
|
|
2766
3296
|
// src/opa/get.ts
|
|
2767
|
-
async function
|
|
3297
|
+
async function getBody5(raw) {
|
|
2768
3298
|
const agentId = parseAgentId(raw);
|
|
2769
3299
|
const agent = await apiErrors(async () => buildClient().opa.get(agentId));
|
|
2770
3300
|
printOutput({
|
|
@@ -2780,12 +3310,12 @@ function registerOpaGet(opa) {
|
|
|
2780
3310
|
cmd.addHelpText("after", "\nExamples:\n engini opa get 41 --json");
|
|
2781
3311
|
addUniversalOptions(cmd);
|
|
2782
3312
|
cmd.action(async (raw, opts, command) => {
|
|
2783
|
-
await runCommand(command, opts, false, () =>
|
|
3313
|
+
await runCommand(command, opts, false, () => getBody5(raw));
|
|
2784
3314
|
});
|
|
2785
3315
|
}
|
|
2786
3316
|
|
|
2787
3317
|
// src/opa/list.ts
|
|
2788
|
-
async function
|
|
3318
|
+
async function listBody7(opts) {
|
|
2789
3319
|
const agents = await apiErrors(
|
|
2790
3320
|
async () => buildClient().opa.list({ status: opts.status, name: opts.name })
|
|
2791
3321
|
);
|
|
@@ -2802,7 +3332,7 @@ function registerOpaList(opa) {
|
|
|
2802
3332
|
);
|
|
2803
3333
|
addUniversalOptions(cmd);
|
|
2804
3334
|
cmd.action(async (opts, command) => {
|
|
2805
|
-
await runCommand(command, opts, false, () =>
|
|
3335
|
+
await runCommand(command, opts, false, () => listBody7(opts));
|
|
2806
3336
|
});
|
|
2807
3337
|
}
|
|
2808
3338
|
|
|
@@ -2877,7 +3407,7 @@ function registerOpaDisable(opa) {
|
|
|
2877
3407
|
}
|
|
2878
3408
|
|
|
2879
3409
|
// src/opa/token.ts
|
|
2880
|
-
async function
|
|
3410
|
+
async function getBody6(raw) {
|
|
2881
3411
|
const agentId = parseAgentId(raw);
|
|
2882
3412
|
const token = await apiErrors(async () => buildClient().opa.getToken(agentId));
|
|
2883
3413
|
printOutput({ agent_id: token.agentId, token: token.token });
|
|
@@ -2905,7 +3435,7 @@ function registerOpaToken(opa) {
|
|
|
2905
3435
|
get.addHelpText("after", "\nExamples:\n engini opa token get 41 --json");
|
|
2906
3436
|
addUniversalOptions(get);
|
|
2907
3437
|
get.action(async (raw, opts, command) => {
|
|
2908
|
-
await runCommand(command, opts, false, () =>
|
|
3438
|
+
await runCommand(command, opts, false, () => getBody6(raw));
|
|
2909
3439
|
});
|
|
2910
3440
|
const rotate = token.command("rotate").description(
|
|
2911
3441
|
"Issue a new token, invalidating the current one. Stops the running agent until it is reconfigured."
|
|
@@ -2925,7 +3455,7 @@ function registerOpaToken(opa) {
|
|
|
2925
3455
|
}
|
|
2926
3456
|
|
|
2927
3457
|
// src/opa/update.ts
|
|
2928
|
-
async function
|
|
3458
|
+
async function updateBody3(raw, opts) {
|
|
2929
3459
|
const agentId = parseAgentId(raw);
|
|
2930
3460
|
const settings = parseSettingsFlags(opts);
|
|
2931
3461
|
const preview = settingsPreview(settings);
|
|
@@ -2973,7 +3503,7 @@ function registerOpaUpdate(opa) {
|
|
|
2973
3503
|
command,
|
|
2974
3504
|
opts,
|
|
2975
3505
|
true,
|
|
2976
|
-
() =>
|
|
3506
|
+
() => updateBody3(raw, opts)
|
|
2977
3507
|
);
|
|
2978
3508
|
});
|
|
2979
3509
|
}
|
|
@@ -3415,7 +3945,7 @@ function detail3(schema) {
|
|
|
3415
3945
|
max_sorts: clean(schema.maxSorts)
|
|
3416
3946
|
};
|
|
3417
3947
|
}
|
|
3418
|
-
async function
|
|
3948
|
+
async function getBody7(toolId) {
|
|
3419
3949
|
if (!toolId) {
|
|
3420
3950
|
fail(2 /* USAGE */, "Missing required argument 'tool_id'.");
|
|
3421
3951
|
}
|
|
@@ -3429,7 +3959,7 @@ function registerToolsGet(tools) {
|
|
|
3429
3959
|
const cmd = tools.command("get").description("Show full canonical detail for one tool.").argument("[tool_id]", "Tool slug");
|
|
3430
3960
|
addUniversalOptions(cmd);
|
|
3431
3961
|
cmd.action(async (toolId, opts, command) => {
|
|
3432
|
-
await runCommand(command, opts, false, () =>
|
|
3962
|
+
await runCommand(command, opts, false, () => getBody7(toolId));
|
|
3433
3963
|
});
|
|
3434
3964
|
}
|
|
3435
3965
|
|
|
@@ -3452,7 +3982,7 @@ function parseLimit2(value) {
|
|
|
3452
3982
|
}
|
|
3453
3983
|
return limit;
|
|
3454
3984
|
}
|
|
3455
|
-
async function
|
|
3985
|
+
async function listBody8(opts) {
|
|
3456
3986
|
if (opts.application && opts.toolset) {
|
|
3457
3987
|
fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
|
|
3458
3988
|
}
|
|
@@ -3475,7 +4005,7 @@ function registerToolsList(tools) {
|
|
|
3475
4005
|
const cmd = tools.command("list").description("List available tools, optionally filtered.").option("--application <slug>", "Filter by application slug (e.g. monday)").option("--toolset <id>", "List the tools of a server toolset (by id)").option("--limit <n>", "Cap the number of tools returned");
|
|
3476
4006
|
addUniversalOptions(cmd);
|
|
3477
4007
|
cmd.action(async (opts, command) => {
|
|
3478
|
-
await runCommand(command, opts, false, () =>
|
|
4008
|
+
await runCommand(command, opts, false, () => listBody8(opts));
|
|
3479
4009
|
});
|
|
3480
4010
|
}
|
|
3481
4011
|
|
|
@@ -3666,7 +4196,7 @@ function buildRequestBody(opts) {
|
|
|
3666
4196
|
workflows: workflowsFromFlagsOrUndefined(opts.workflow)
|
|
3667
4197
|
};
|
|
3668
4198
|
}
|
|
3669
|
-
async function
|
|
4199
|
+
async function createBody4(opts) {
|
|
3670
4200
|
const body = buildRequestBody(opts);
|
|
3671
4201
|
if (dryRun()) {
|
|
3672
4202
|
printOutput({
|
|
@@ -3700,12 +4230,12 @@ function registerToolsetsCreate(toolsets) {
|
|
|
3700
4230
|
);
|
|
3701
4231
|
addUniversalOptions(cmd, { mutating: true });
|
|
3702
4232
|
cmd.action(async (opts, command) => {
|
|
3703
|
-
await runCommand(command, opts, true, () =>
|
|
4233
|
+
await runCommand(command, opts, true, () => createBody4(opts));
|
|
3704
4234
|
});
|
|
3705
4235
|
}
|
|
3706
4236
|
|
|
3707
4237
|
// src/toolsets/delete.ts
|
|
3708
|
-
async function
|
|
4238
|
+
async function deleteBody4(toolsetId, opts) {
|
|
3709
4239
|
const id = parseToolsetId(toolsetId);
|
|
3710
4240
|
if (dryRun()) {
|
|
3711
4241
|
printOutput({ would_delete: id });
|
|
@@ -3723,12 +4253,12 @@ function registerToolsetsDelete(toolsets) {
|
|
|
3723
4253
|
cmd.addHelpText("after", "\nExamples:\n engini toolsets delete <toolset_id> --force");
|
|
3724
4254
|
addUniversalOptions(cmd, { mutating: true });
|
|
3725
4255
|
cmd.action(async (id, opts, command) => {
|
|
3726
|
-
await runCommand(command, opts, true, () =>
|
|
4256
|
+
await runCommand(command, opts, true, () => deleteBody4(id, opts));
|
|
3727
4257
|
});
|
|
3728
4258
|
}
|
|
3729
4259
|
|
|
3730
4260
|
// src/toolsets/get.ts
|
|
3731
|
-
async function
|
|
4261
|
+
async function getBody8(toolsetId) {
|
|
3732
4262
|
const id = parseToolsetId(toolsetId);
|
|
3733
4263
|
const toolset = await apiErrors(async () => {
|
|
3734
4264
|
const client = buildClient();
|
|
@@ -3746,12 +4276,12 @@ function registerToolsetsGet(toolsets) {
|
|
|
3746
4276
|
cmd.addHelpText("after", "\nExamples:\n engini toolsets get <toolset_id> --json");
|
|
3747
4277
|
addUniversalOptions(cmd);
|
|
3748
4278
|
cmd.action(async (id, opts, command) => {
|
|
3749
|
-
await runCommand(command, opts, false, () =>
|
|
4279
|
+
await runCommand(command, opts, false, () => getBody8(id));
|
|
3750
4280
|
});
|
|
3751
4281
|
}
|
|
3752
4282
|
|
|
3753
4283
|
// src/toolsets/list.ts
|
|
3754
|
-
async function
|
|
4284
|
+
async function listBody9() {
|
|
3755
4285
|
const toolsets = await apiErrors(async () => {
|
|
3756
4286
|
const client = buildClient();
|
|
3757
4287
|
return client.toolsets.list();
|
|
@@ -3766,7 +4296,7 @@ function registerToolsetsList(toolsets) {
|
|
|
3766
4296
|
);
|
|
3767
4297
|
addUniversalOptions(cmd);
|
|
3768
4298
|
cmd.action(async (opts, command) => {
|
|
3769
|
-
await runCommand(command, opts, false, () =>
|
|
4299
|
+
await runCommand(command, opts, false, () => listBody9());
|
|
3770
4300
|
});
|
|
3771
4301
|
}
|
|
3772
4302
|
|
|
@@ -3801,7 +4331,7 @@ async function previewDryRun(toolsetId, body) {
|
|
|
3801
4331
|
}
|
|
3802
4332
|
});
|
|
3803
4333
|
}
|
|
3804
|
-
async function
|
|
4334
|
+
async function updateBody4(toolsetId, opts) {
|
|
3805
4335
|
const id = parseToolsetId(toolsetId);
|
|
3806
4336
|
const body = buildRequestBody2(opts);
|
|
3807
4337
|
if (body.name === void 0 && body.connections === void 0 && body.workflows === void 0) {
|
|
@@ -3838,7 +4368,7 @@ function registerToolsetsUpdate(toolsets) {
|
|
|
3838
4368
|
);
|
|
3839
4369
|
addUniversalOptions(cmd, { mutating: true });
|
|
3840
4370
|
cmd.action(async (id, opts, command) => {
|
|
3841
|
-
await runCommand(command, opts, true, () =>
|
|
4371
|
+
await runCommand(command, opts, true, () => updateBody4(id, opts));
|
|
3842
4372
|
});
|
|
3843
4373
|
}
|
|
3844
4374
|
|
|
@@ -4014,7 +4544,7 @@ async function hasAccountDefaultDestination() {
|
|
|
4014
4544
|
throw err;
|
|
4015
4545
|
}
|
|
4016
4546
|
}
|
|
4017
|
-
async function
|
|
4547
|
+
async function createBody5(triggerSlug, opts) {
|
|
4018
4548
|
if (triggerSlug === void 0 || triggerSlug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
|
|
4019
4549
|
if (opts.connection === "") {
|
|
4020
4550
|
fail(
|
|
@@ -4084,12 +4614,12 @@ function registerTriggerCreate(triggers) {
|
|
|
4084
4614
|
);
|
|
4085
4615
|
addUniversalOptions(create, { mutating: true });
|
|
4086
4616
|
create.action(async (triggerSlug, opts, command) => {
|
|
4087
|
-
await runCommand(command, opts, true, () =>
|
|
4617
|
+
await runCommand(command, opts, true, () => createBody5(triggerSlug, opts));
|
|
4088
4618
|
});
|
|
4089
4619
|
}
|
|
4090
4620
|
|
|
4091
4621
|
// src/triggers/delete.ts
|
|
4092
|
-
async function
|
|
4622
|
+
async function deleteBody5(raw, opts) {
|
|
4093
4623
|
const triggerId = parseTriggerId(raw);
|
|
4094
4624
|
if (dryRun()) {
|
|
4095
4625
|
printOutput({ would_delete: triggerId });
|
|
@@ -4108,7 +4638,7 @@ function registerTriggerDelete(triggers) {
|
|
|
4108
4638
|
addUniversalOptions(cmd, { mutating: true });
|
|
4109
4639
|
cmd.action(
|
|
4110
4640
|
async (raw, opts, command) => {
|
|
4111
|
-
await runCommand(command, opts, true, () =>
|
|
4641
|
+
await runCommand(command, opts, true, () => deleteBody5(raw, opts));
|
|
4112
4642
|
}
|
|
4113
4643
|
);
|
|
4114
4644
|
}
|
|
@@ -4153,7 +4683,7 @@ async function addBody(name, url, opts) {
|
|
|
4153
4683
|
);
|
|
4154
4684
|
printOutput(withSecret(created));
|
|
4155
4685
|
}
|
|
4156
|
-
async function
|
|
4686
|
+
async function listBody10() {
|
|
4157
4687
|
const destinations = await apiErrors(async () => buildClient().triggers.destinations.list());
|
|
4158
4688
|
printOutput(destinations.map(summarizeDestination));
|
|
4159
4689
|
}
|
|
@@ -4219,7 +4749,7 @@ function registerTriggerDestinations(triggers) {
|
|
|
4219
4749
|
list.addHelpText("after", "\nExamples:\n engini triggers destinations list --json");
|
|
4220
4750
|
addUniversalOptions(list);
|
|
4221
4751
|
list.action(async (opts, command) => {
|
|
4222
|
-
await runCommand(command, opts, false,
|
|
4752
|
+
await runCommand(command, opts, false, listBody10);
|
|
4223
4753
|
});
|
|
4224
4754
|
const show = destinations.command("show").description("One destination's failure counters and status.").argument("[name]", "Destination name");
|
|
4225
4755
|
show.addHelpText("after", "\nExamples:\n engini triggers destinations show billing");
|
|
@@ -4255,13 +4785,13 @@ function registerTriggerDestinations(triggers) {
|
|
|
4255
4785
|
}
|
|
4256
4786
|
|
|
4257
4787
|
// src/triggers/events.ts
|
|
4258
|
-
async function
|
|
4788
|
+
async function listBody11(triggerId, opts) {
|
|
4259
4789
|
if (triggerId === void 0 || triggerId === "") fail(2 /* USAGE */, "A trigger_id is required.");
|
|
4260
4790
|
const top = opts.limit !== void 0 ? Number(opts.limit) : void 0;
|
|
4261
4791
|
const events = await apiErrors(async () => buildClient().triggers.events.list(triggerId, { top }));
|
|
4262
4792
|
printOutput(events.map(summarizeEvent));
|
|
4263
4793
|
}
|
|
4264
|
-
async function
|
|
4794
|
+
async function getBody9(eventId) {
|
|
4265
4795
|
if (eventId === void 0 || eventId === "") fail(2 /* USAGE */, "An event_id is required.");
|
|
4266
4796
|
const detail4 = await apiErrors(async () => buildClient().triggers.events.get(eventId));
|
|
4267
4797
|
printOutput({ event: summarizeEvent(detail4.event), attempts: detail4.attempts });
|
|
@@ -4284,14 +4814,14 @@ function registerTriggerEvents(triggers) {
|
|
|
4284
4814
|
addUniversalOptions(events);
|
|
4285
4815
|
events.action(
|
|
4286
4816
|
async (triggerId, opts, command) => {
|
|
4287
|
-
await runCommand(command, opts, false, () =>
|
|
4817
|
+
await runCommand(command, opts, false, () => listBody11(triggerId, opts));
|
|
4288
4818
|
}
|
|
4289
4819
|
);
|
|
4290
4820
|
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)");
|
|
4291
4821
|
get.addHelpText("after", "\nExamples:\n engini triggers events get te_abc123 --json");
|
|
4292
4822
|
addUniversalOptions(get);
|
|
4293
4823
|
get.action(async (eventId, opts, command) => {
|
|
4294
|
-
await runCommand(command, opts, false, () =>
|
|
4824
|
+
await runCommand(command, opts, false, () => getBody9(eventId));
|
|
4295
4825
|
});
|
|
4296
4826
|
const replay = events.command("replay").description("Re-deliver a captured event to its destination.").argument("[event_id]", "Event id (te_\u2026)");
|
|
4297
4827
|
replay.addHelpText(
|
|
@@ -4305,7 +4835,7 @@ function registerTriggerEvents(triggers) {
|
|
|
4305
4835
|
}
|
|
4306
4836
|
|
|
4307
4837
|
// src/triggers/get.ts
|
|
4308
|
-
async function
|
|
4838
|
+
async function getBody10(raw) {
|
|
4309
4839
|
const triggerId = parseTriggerId(raw);
|
|
4310
4840
|
const trigger = await apiErrors(async () => buildClient().triggers.get(triggerId));
|
|
4311
4841
|
printOutput(summarizeTrigger(trigger));
|
|
@@ -4315,7 +4845,7 @@ function registerTriggersGet(triggers) {
|
|
|
4315
4845
|
get.addHelpText("after", "\nExamples:\n engini triggers get ti_abc123 --json");
|
|
4316
4846
|
addUniversalOptions(get);
|
|
4317
4847
|
get.action(async (raw, opts, command) => {
|
|
4318
|
-
await runCommand(command, opts, false, () =>
|
|
4848
|
+
await runCommand(command, opts, false, () => getBody10(raw));
|
|
4319
4849
|
});
|
|
4320
4850
|
}
|
|
4321
4851
|
|
|
@@ -4431,7 +4961,7 @@ function registerTriggerListen(triggers) {
|
|
|
4431
4961
|
}
|
|
4432
4962
|
|
|
4433
4963
|
// src/triggers/list.ts
|
|
4434
|
-
async function
|
|
4964
|
+
async function listBody12(opts) {
|
|
4435
4965
|
const top = opts.top !== void 0 ? Number(opts.top) : void 0;
|
|
4436
4966
|
const triggers = await apiErrors(
|
|
4437
4967
|
async () => buildClient().triggers.list({
|
|
@@ -4460,7 +4990,7 @@ function registerTriggersList(triggers) {
|
|
|
4460
4990
|
);
|
|
4461
4991
|
addUniversalOptions(list);
|
|
4462
4992
|
list.action(async (opts, command) => {
|
|
4463
|
-
await runCommand(command, opts, false, () =>
|
|
4993
|
+
await runCommand(command, opts, false, () => listBody12(opts));
|
|
4464
4994
|
});
|
|
4465
4995
|
}
|
|
4466
4996
|
|
|
@@ -4499,7 +5029,7 @@ function registerTriggerDisable(triggers) {
|
|
|
4499
5029
|
}
|
|
4500
5030
|
|
|
4501
5031
|
// src/triggers/types.ts
|
|
4502
|
-
async function
|
|
5032
|
+
async function listBody13(opts) {
|
|
4503
5033
|
const types = await apiErrors(
|
|
4504
5034
|
async () => buildClient().triggers.types.list({
|
|
4505
5035
|
applicationSlug: opts.app,
|
|
@@ -4509,7 +5039,7 @@ async function listBody12(opts) {
|
|
|
4509
5039
|
);
|
|
4510
5040
|
printOutput(types);
|
|
4511
5041
|
}
|
|
4512
|
-
async function
|
|
5042
|
+
async function getBody11(slug, opts) {
|
|
4513
5043
|
if (slug === void 0 || slug === "") fail(2 /* USAGE */, "A trigger_slug is required.");
|
|
4514
5044
|
const type = await apiErrors(
|
|
4515
5045
|
async () => buildClient().triggers.types.get(slug, { applicationSlug: opts.app })
|
|
@@ -4524,14 +5054,14 @@ function registerTriggerTypes(triggers) {
|
|
|
4524
5054
|
);
|
|
4525
5055
|
addUniversalOptions(types);
|
|
4526
5056
|
types.action(async (opts, command) => {
|
|
4527
|
-
await runCommand(command, opts, false, () =>
|
|
5057
|
+
await runCommand(command, opts, false, () => listBody13(opts));
|
|
4528
5058
|
});
|
|
4529
5059
|
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");
|
|
4530
5060
|
get.addHelpText("after", "\nExamples:\n engini triggers types get monday_item_created --json");
|
|
4531
5061
|
addUniversalOptions(get);
|
|
4532
5062
|
get.action(
|
|
4533
5063
|
async (slug, opts, command) => {
|
|
4534
|
-
await runCommand(command, opts, false, () =>
|
|
5064
|
+
await runCommand(command, opts, false, () => getBody11(slug, opts));
|
|
4535
5065
|
}
|
|
4536
5066
|
);
|
|
4537
5067
|
}
|