@doist/automations-cli 1.13.0 → 1.14.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/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import { fileURLToPath } from "node:url";
15
15
  // package.json
16
16
  var package_default = {
17
17
  name: "@doist/automations-cli",
18
- version: "1.13.0",
18
+ version: "1.14.0",
19
19
  description: "Command-line client for Todoist Automations",
20
20
  type: "module",
21
21
  bin: {
@@ -25031,6 +25031,24 @@ function summarizeConnectorConnection(connection) {
25031
25031
  };
25032
25032
  }
25033
25033
 
25034
+ // ../../packages/sdk/dist/esm/connectors/connection-usage.js
25035
+ async function findAutomationsUsingConnection(api, connectionId, options) {
25036
+ const matches = [];
25037
+ const seenCursors = /* @__PURE__ */ new Set();
25038
+ let cursor;
25039
+ while (true) {
25040
+ const page = await api.automations.list({ cursor, limit: MAX_PAGINATION_LIMIT }, options);
25041
+ matches.push(...page.data.filter((automation) => automation.connections.some((connection) => connection.id === connectionId)));
25042
+ if (!page.nextCursor)
25043
+ return matches;
25044
+ if (seenCursors.has(page.nextCursor)) {
25045
+ throw new Error("The API returned a repeated pagination cursor.");
25046
+ }
25047
+ seenCursors.add(page.nextCursor);
25048
+ cursor = page.nextCursor;
25049
+ }
25050
+ }
25051
+
25034
25052
  // src/lib/auth-environment.ts
25035
25053
  import { InvalidArgumentError } from "commander";
25036
25054
  var ENVIRONMENTS = {
@@ -28627,7 +28645,7 @@ async function disconnectConnection(api, connectionId, { confirmed, force }, sig
28627
28645
  return {
28628
28646
  action: "disconnect_preview",
28629
28647
  connectionId,
28630
- affectedAutomations: await findAutomationsUsingConnection(api, connectionId, signal)
28648
+ affectedAutomations: await findAffectedAutomations(api, connectionId, signal)
28631
28649
  };
28632
28650
  }
28633
28651
  try {
@@ -28644,19 +28662,9 @@ async function disconnectConnection(api, connectionId, { confirmed, force }, sig
28644
28662
  }
28645
28663
  return { action: "disconnected", connectionId };
28646
28664
  }
28647
- async function findAutomationsUsingConnection(api, connectionId, signal) {
28648
- const matches = [];
28649
- for await (const page of iterateCursorPages(
28650
- { all: true },
28651
- (args) => api.automations.list(args, { signal })
28652
- )) {
28653
- matches.push(
28654
- ...page.data.filter(
28655
- (automation) => automation.connections.some((connection) => connection.id === connectionId)
28656
- ).map(summarizeAffectedAutomation)
28657
- );
28658
- }
28659
- return matches;
28665
+ async function findAffectedAutomations(api, connectionId, signal) {
28666
+ const automations = await findAutomationsUsingConnection(api, connectionId, { signal });
28667
+ return automations.map(summarizeAffectedAutomation);
28660
28668
  }
28661
28669
  function summarizeAffectedAutomation(automation) {
28662
28670
  return {
@@ -28727,11 +28735,7 @@ function registerConnectorMutationCommands(connector) {
28727
28735
  await authorizer.resume(request2, connection.id, connection.setup, signal);
28728
28736
  return { action: "connected", connectionId };
28729
28737
  }
28730
- const affectedAutomations = await findAutomationsUsingConnection(
28731
- api,
28732
- connectionId,
28733
- signal
28734
- );
28738
+ const affectedAutomations = await findAffectedAutomations(api, connectionId, signal);
28735
28739
  const repairedConnectionId = await authorizer.authorize(
28736
28740
  {
28737
28741
  ...request2,