@erdoai/cli 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +74 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -103,6 +103,10 @@ function resolveOrgId(account, override) {
103
103
  }
104
104
 
105
105
  // src/client.ts
106
+ function formatOrg(name, slug) {
107
+ if (name && slug) return `${name} (${slug})`;
108
+ return name || slug || "";
109
+ }
106
110
  var TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
107
111
  var POLL_STOP_STATUSES = /* @__PURE__ */ new Set([...TERMINAL_RUN_STATUSES, "awaiting_approval"]);
108
112
  var ErdoApiError = class extends Error {
@@ -745,6 +749,19 @@ var ErdoClient = class {
745
749
  listIntegrations() {
746
750
  return this.request("GET", "/v1/integrations");
747
751
  }
752
+ getConnectionScope(integrationId) {
753
+ return this.request(
754
+ "GET",
755
+ `/v1/integrations/${encodeURIComponent(integrationId)}/connection-scope`
756
+ );
757
+ }
758
+ setConnectionScope(integrationId, accountId) {
759
+ return this.request(
760
+ "POST",
761
+ `/v1/integrations/${encodeURIComponent(integrationId)}/connection-scope`,
762
+ { account_id: accountId }
763
+ );
764
+ }
748
765
  searchIntegrationApps(query) {
749
766
  const qs = query ? `?query=${encodeURIComponent(query)}` : "";
750
767
  return this.request("GET", `/v1/integration-apps${qs}`);
@@ -929,6 +946,7 @@ var ErdoClient = class {
929
946
  if (opts.status) params.set("status", opts.status);
930
947
  if (opts.applicability) params.set("applicability", opts.applicability);
931
948
  if (opts.outcome) params.set("outcome", opts.outcome);
949
+ if (opts.approval_id) params.set("approval_id", opts.approval_id);
932
950
  if (opts.limit) params.set("limit", String(opts.limit));
933
951
  if (opts.offset) params.set("offset", String(opts.offset));
934
952
  const qs = params.toString();
@@ -1441,7 +1459,8 @@ program.command("logout [account]").description("Log out an account (default: th
1441
1459
  program.command("whoami").description("Show the active account and org").action(async () => {
1442
1460
  try {
1443
1461
  const me = await new ErdoClient().me();
1444
- console.log(`${me.email || me.user_id} \u2014 org: ${me.organization_name || me.organization_id}`);
1462
+ const org2 = formatOrg(me.organization_name, me.organization_slug) || me.organization_id;
1463
+ console.log(`${me.email || me.user_id} \u2014 org: ${org2}`);
1445
1464
  } catch (e) {
1446
1465
  fail(e);
1447
1466
  }
@@ -2498,7 +2517,10 @@ decisionsCmd.command("list").description("List decisions, newest first").option(
2498
2517
  ).option("--class <class>", "decision class, e.g. paid_media.ad_group.pause").option("--subject-kind <kind>", "only decisions about this kind of subject").option("--subject-ref <id>", "only decisions about this exact subject").option(
2499
2518
  "--status <status>",
2500
2519
  "proposed | authorized | executing | effective | measuring | settled | rejected | failed | censored"
2501
- ).option("--applicability <kind>", "standing | one_shot").option("--outcome <outcome>", "only decisions with a settled effect that came back met | not_met | inconclusive").option("-l, --limit <n>", "max rows (default 50, max 200)", (v) => parseInt(v, 10)).option("--offset <n>", "pagination offset", (v) => parseInt(v, 10)).option("--json", "output raw JSON").action(
2520
+ ).option("--applicability <kind>", "standing | one_shot").option("--outcome <outcome>", "only decisions with a settled effect that came back met | not_met | inconclusive").option(
2521
+ "--approval <id>",
2522
+ "only the decisions produced by answering this approval (approvals are referenced by id, not slug)"
2523
+ ).option("-l, --limit <n>", "max rows (default 50, max 200)", (v) => parseInt(v, 10)).option("--offset <n>", "pagination offset", (v) => parseInt(v, 10)).option("--json", "output raw JSON").action(
2502
2524
  async (opts) => {
2503
2525
  try {
2504
2526
  const res = await new ErdoClient().listDecisions({
@@ -2510,6 +2532,7 @@ decisionsCmd.command("list").description("List decisions, newest first").option(
2510
2532
  status: opts.status,
2511
2533
  applicability: opts.applicability,
2512
2534
  outcome: opts.outcome,
2535
+ approval_id: opts.approval,
2513
2536
  limit: opts.limit,
2514
2537
  offset: opts.offset
2515
2538
  });
@@ -3604,10 +3627,14 @@ integrationsCmd.command("connect <app>").description("Connect an app \u2014 pass
3604
3627
  }
3605
3628
  const res = await new ErdoClient().connectIntegration({ app, name: opts.name, credentials });
3606
3629
  print(res);
3630
+ const notes = [];
3631
+ const org2 = formatOrg(res.organization_name, res.organization_slug);
3632
+ if (org2) notes.push(`This connection belongs to ${org2}.`);
3607
3633
  if (res.connect_url) {
3608
- console.error(`
3609
- Open this URL in a browser to authorize, then run: erdo integrations status ${app}`);
3634
+ notes.push(`Open this URL in a browser to authorize, then run: erdo integrations status ${app}`);
3610
3635
  }
3636
+ if (notes.length) console.error(`
3637
+ ${notes.join("\n")}`);
3611
3638
  } catch (e) {
3612
3639
  fail(e);
3613
3640
  }
@@ -3619,6 +3646,46 @@ integrationsCmd.command("status <app>").description("Check whether an app is con
3619
3646
  fail(e);
3620
3647
  }
3621
3648
  });
3649
+ var accountCmd = integrationsCmd.command("account").description("Read or set which provider account a connection operates");
3650
+ accountCmd.command("show <integration-id>").description("Show which account a connection operates, and which it could (see: erdo integrations list)").action(async (integrationId) => {
3651
+ try {
3652
+ const scope = await new ErdoClient().getConnectionScope(integrationId);
3653
+ if (!scope.has_connection_scope) {
3654
+ console.log("This integration does not choose a provider account per connection.");
3655
+ return;
3656
+ }
3657
+ console.log(scope.description);
3658
+ const selected = new Set(scope.selected.map((a) => a.id));
3659
+ for (const account of scope.options) {
3660
+ const marker = selected.has(account.id) ? "*" : " ";
3661
+ const owner = account.parent ? ` ${account.parent}` : "";
3662
+ console.log(`${marker} ${account.id} ${account.name} ${account.type}${owner}`);
3663
+ }
3664
+ if (scope.options.length === 0) {
3665
+ console.error(
3666
+ `
3667
+ This login reaches no account yet. Set one here once it exists:
3668
+ erdo integrations account set ${integrationId} <account-id>`
3669
+ );
3670
+ } else if (selected.size === 0) {
3671
+ console.error(
3672
+ `
3673
+ No account chosen yet${scope.required ? " \u2014 this connection cannot resolve one until you set it" : ""}.
3674
+ Set it with: erdo integrations account set ${integrationId} <account-id>`
3675
+ );
3676
+ }
3677
+ } catch (e) {
3678
+ fail(e);
3679
+ }
3680
+ });
3681
+ accountCmd.command("set <integration-id> <account-id>").description("Record which account this connection operates \u2014 every dataset, sync, and agent action it serves runs against this account").action(async (integrationId, accountId) => {
3682
+ try {
3683
+ const scope = await new ErdoClient().setConnectionScope(integrationId, accountId);
3684
+ print(scope);
3685
+ } catch (e) {
3686
+ fail(e);
3687
+ }
3688
+ });
3622
3689
  integrationsCmd.command("tables <app> [schema]").description("List a connected database integration's schemas, or a schema's tables with columns").action(async (app, schema) => {
3623
3690
  try {
3624
3691
  const res = await new ErdoClient().discoverIntegrationTables(app, schema);
@@ -3645,10 +3712,12 @@ connectLinksCmd.command("create <app>").description("Mint a shareable connect li
3645
3712
  integration_id: opts.integrationId
3646
3713
  });
3647
3714
  print(res);
3715
+ const linkOrg = formatOrg(res.organization_name, res.organization_slug);
3648
3716
  process.stderr.write(
3649
3717
  `
3650
3718
  Share link_url with the person who holds the credentials. It expires ${res.expires_at} and completes once. Treat it as a secret \u2014 anyone with it can finish the connection.
3651
- `
3719
+ ` + (linkOrg ? `The connection they make will belong to ${linkOrg}.
3720
+ ` : "")
3652
3721
  );
3653
3722
  } catch (e) {
3654
3723
  fail(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "description": "Erdo CLI — drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {