@doist/automations-cli 1.8.1 → 1.9.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 +99 -73
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
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.
|
|
18
|
+
version: "1.9.0",
|
|
19
19
|
description: "Command-line client for Todoist Automations",
|
|
20
20
|
type: "module",
|
|
21
21
|
bin: {
|
|
@@ -24867,6 +24867,93 @@ function summarizeRun(run) {
|
|
|
24867
24867
|
};
|
|
24868
24868
|
}
|
|
24869
24869
|
|
|
24870
|
+
// ../../packages/sdk/dist/esm/connectors/connector-catalog.js
|
|
24871
|
+
var ConnectorNotFoundError = class extends Error {
|
|
24872
|
+
connectorId;
|
|
24873
|
+
constructor(connectorId) {
|
|
24874
|
+
super(`Connector ${connectorId} was not found.`);
|
|
24875
|
+
this.name = "ConnectorNotFoundError";
|
|
24876
|
+
this.connectorId = connectorId;
|
|
24877
|
+
}
|
|
24878
|
+
};
|
|
24879
|
+
async function* iterateConnectorPages(api, query, options) {
|
|
24880
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
24881
|
+
let cursor;
|
|
24882
|
+
while (true) {
|
|
24883
|
+
const page = await api.connectors.list({ query, cursor, limit: MAX_PAGINATION_LIMIT }, options);
|
|
24884
|
+
if (page.nextCursor && seenCursors.has(page.nextCursor)) {
|
|
24885
|
+
throw new Error("The API returned a repeated pagination cursor.");
|
|
24886
|
+
}
|
|
24887
|
+
yield page;
|
|
24888
|
+
if (!page.nextCursor)
|
|
24889
|
+
return;
|
|
24890
|
+
seenCursors.add(page.nextCursor);
|
|
24891
|
+
cursor = page.nextCursor;
|
|
24892
|
+
}
|
|
24893
|
+
}
|
|
24894
|
+
async function findConnector(api, connectorId, options) {
|
|
24895
|
+
for await (const page of iterateConnectorPages(api, void 0, options)) {
|
|
24896
|
+
const connector = page.data.find((item) => item.id === connectorId);
|
|
24897
|
+
if (connector)
|
|
24898
|
+
return connector;
|
|
24899
|
+
}
|
|
24900
|
+
throw new ConnectorNotFoundError(connectorId);
|
|
24901
|
+
}
|
|
24902
|
+
async function listConnectors(api, options, requestOptions) {
|
|
24903
|
+
const [connectors, connectionResponse] = await Promise.all([
|
|
24904
|
+
collectConnectorPages(api, options.query, requestOptions),
|
|
24905
|
+
options.connections ? api.connections.list({}, requestOptions) : void 0
|
|
24906
|
+
]);
|
|
24907
|
+
const connectionsByConnector = groupConnectionsByConnector(connectionResponse?.connections ?? []);
|
|
24908
|
+
const data = connectors.filter((connector) => connectorSupportsCapability(connector, options.capability)).map((connector) => options.connections ? enrichConnector(connector, connectionsByConnector.get(connector.id) ?? []) : connector).filter((connector) => matchesConnectionFilters(connector, options));
|
|
24909
|
+
return { connectionsIncluded: options.connections, data };
|
|
24910
|
+
}
|
|
24911
|
+
function getConnectorCapabilities(connector) {
|
|
24912
|
+
return [
|
|
24913
|
+
...connector.capabilities.mcp ? ["mcp"] : [],
|
|
24914
|
+
...connector.capabilities.triggers ? ["trigger"] : []
|
|
24915
|
+
];
|
|
24916
|
+
}
|
|
24917
|
+
function connectorSupportsCapability(connector, capability) {
|
|
24918
|
+
return !capability || getConnectorCapabilities(connector).includes(capability);
|
|
24919
|
+
}
|
|
24920
|
+
function enrichConnector(connector, connections) {
|
|
24921
|
+
return { ...connector, connections: connections.map(summarizeConnectorConnection) };
|
|
24922
|
+
}
|
|
24923
|
+
function groupConnectionsByConnector(connections) {
|
|
24924
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
24925
|
+
for (const connection of connections) {
|
|
24926
|
+
const group = grouped.get(connection.connectorId) ?? [];
|
|
24927
|
+
group.push(connection);
|
|
24928
|
+
grouped.set(connection.connectorId, group);
|
|
24929
|
+
}
|
|
24930
|
+
return grouped;
|
|
24931
|
+
}
|
|
24932
|
+
function matchesConnectionFilters(connector, options) {
|
|
24933
|
+
if (!connector.connections)
|
|
24934
|
+
return true;
|
|
24935
|
+
if (options.withoutConnections)
|
|
24936
|
+
return connector.connections.length === 0;
|
|
24937
|
+
if (!options.connectionStatus)
|
|
24938
|
+
return true;
|
|
24939
|
+
return connector.connections.some((connection) => connection.status === options.connectionStatus && (!options.capability || connection.capabilities.some((item) => item.capability === options.capability)));
|
|
24940
|
+
}
|
|
24941
|
+
async function collectConnectorPages(api, query, options) {
|
|
24942
|
+
const connectors = [];
|
|
24943
|
+
for await (const page of iterateConnectorPages(api, query, options)) {
|
|
24944
|
+
connectors.push(...page.data);
|
|
24945
|
+
}
|
|
24946
|
+
return connectors;
|
|
24947
|
+
}
|
|
24948
|
+
function summarizeConnectorConnection(connection) {
|
|
24949
|
+
return {
|
|
24950
|
+
id: connection.id,
|
|
24951
|
+
status: connection.status,
|
|
24952
|
+
capabilities: connection.capabilities,
|
|
24953
|
+
createdAt: connection.createdAt
|
|
24954
|
+
};
|
|
24955
|
+
}
|
|
24956
|
+
|
|
24870
24957
|
// src/lib/auth-environment.ts
|
|
24871
24958
|
import { InvalidArgumentError } from "commander";
|
|
24872
24959
|
var ENVIRONMENTS = {
|
|
@@ -28266,31 +28353,19 @@ function formatConnectionChange(result) {
|
|
|
28266
28353
|
return `Connection ${result.connectionId} authorized.`;
|
|
28267
28354
|
}
|
|
28268
28355
|
}
|
|
28269
|
-
function getConnectorCapabilities(connector) {
|
|
28270
|
-
return [
|
|
28271
|
-
...connector.capabilities.mcp ? ["mcp"] : [],
|
|
28272
|
-
...connector.capabilities.triggers ? ["trigger"] : []
|
|
28273
|
-
];
|
|
28274
|
-
}
|
|
28275
28356
|
|
|
28276
28357
|
// src/commands/connector/connector-service.ts
|
|
28277
|
-
async function
|
|
28358
|
+
async function listConnectors2(api, options, signal) {
|
|
28278
28359
|
validateListOptions(options);
|
|
28279
|
-
|
|
28280
|
-
listAllConnectors(api, options.query, signal),
|
|
28281
|
-
options.connections ? api.connections.list({}, { signal }) : void 0
|
|
28282
|
-
]);
|
|
28283
|
-
const connectionsByConnector = groupConnections(connectionResponse?.connections ?? []);
|
|
28284
|
-
const data = connectors.filter((connector) => connectorSupportsCapability(connector, options.capability)).map(
|
|
28285
|
-
(connector) => options.connections ? enrichConnector(connector, connectionsByConnector.get(connector.id) ?? []) : connector
|
|
28286
|
-
).filter((connector) => matchesConnectionFilters(connector, options));
|
|
28287
|
-
return { connectionsIncluded: options.connections, data };
|
|
28360
|
+
return listConnectors(api, options, { signal });
|
|
28288
28361
|
}
|
|
28289
28362
|
async function* streamConnectorNdjsonItems(api, options, signal) {
|
|
28290
28363
|
validateListOptions(options);
|
|
28291
28364
|
const connectionResponse = options.connections ? await api.connections.list({}, { signal }) : void 0;
|
|
28292
|
-
const connectionsByConnector =
|
|
28293
|
-
|
|
28365
|
+
const connectionsByConnector = groupConnectionsByConnector(
|
|
28366
|
+
connectionResponse?.connections ?? []
|
|
28367
|
+
);
|
|
28368
|
+
for await (const page of iterateConnectorPages(api, options.query, { signal })) {
|
|
28294
28369
|
for (const connector of page.data) {
|
|
28295
28370
|
if (!connectorSupportsCapability(connector, options.capability)) continue;
|
|
28296
28371
|
const enriched = options.connections ? enrichConnector(connector, connectionsByConnector.get(connector.id) ?? []) : connector;
|
|
@@ -28299,49 +28374,8 @@ async function* streamConnectorNdjsonItems(api, options, signal) {
|
|
|
28299
28374
|
}
|
|
28300
28375
|
yield { _meta: true, connectionsIncluded: options.connections };
|
|
28301
28376
|
}
|
|
28302
|
-
|
|
28303
|
-
|
|
28304
|
-
const connector = page.data.find((item) => item.id === connectorId);
|
|
28305
|
-
if (connector) return connector;
|
|
28306
|
-
}
|
|
28307
|
-
throw new Error(`Connector ${connectorId} was not found.`);
|
|
28308
|
-
}
|
|
28309
|
-
function enrichConnector(connector, connections) {
|
|
28310
|
-
return { ...connector, connections: connections.map(summarizeConnection) };
|
|
28311
|
-
}
|
|
28312
|
-
function connectorSupportsCapability(connector, capability) {
|
|
28313
|
-
if (!capability) return true;
|
|
28314
|
-
return capability === "mcp" ? connector.capabilities.mcp !== void 0 : connector.capabilities.triggers !== void 0;
|
|
28315
|
-
}
|
|
28316
|
-
async function listAllConnectors(api, query, signal) {
|
|
28317
|
-
const { data } = await collectCursorPages(
|
|
28318
|
-
{ all: true },
|
|
28319
|
-
(args) => api.connectors.list({ query, ...args }, { signal })
|
|
28320
|
-
);
|
|
28321
|
-
return data;
|
|
28322
|
-
}
|
|
28323
|
-
function iterateConnectorPages(api, query, signal) {
|
|
28324
|
-
return iterateCursorPages(
|
|
28325
|
-
{ all: true },
|
|
28326
|
-
(args) => api.connectors.list({ query, ...args }, { signal })
|
|
28327
|
-
);
|
|
28328
|
-
}
|
|
28329
|
-
function groupConnections(connections) {
|
|
28330
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
28331
|
-
for (const connection of connections) {
|
|
28332
|
-
const group = grouped.get(connection.connectorId) ?? [];
|
|
28333
|
-
group.push(connection);
|
|
28334
|
-
grouped.set(connection.connectorId, group);
|
|
28335
|
-
}
|
|
28336
|
-
return grouped;
|
|
28337
|
-
}
|
|
28338
|
-
function summarizeConnection(connection) {
|
|
28339
|
-
return {
|
|
28340
|
-
id: connection.id,
|
|
28341
|
-
status: connection.status,
|
|
28342
|
-
capabilities: connection.capabilities,
|
|
28343
|
-
createdAt: connection.createdAt
|
|
28344
|
-
};
|
|
28377
|
+
function findConnector2(api, connectorId, signal) {
|
|
28378
|
+
return findConnector(api, connectorId, { signal });
|
|
28345
28379
|
}
|
|
28346
28380
|
function validateListOptions(options) {
|
|
28347
28381
|
if (!options.connections && (options.connectionStatus || options.withoutConnections)) {
|
|
@@ -28351,14 +28385,6 @@ function validateListOptions(options) {
|
|
|
28351
28385
|
throw new Error("--connection-status cannot be combined with --without-connections.");
|
|
28352
28386
|
}
|
|
28353
28387
|
}
|
|
28354
|
-
function matchesConnectionFilters(connector, options) {
|
|
28355
|
-
if (!connector.connections) return true;
|
|
28356
|
-
if (options.withoutConnections) return connector.connections.length === 0;
|
|
28357
|
-
if (!options.connectionStatus) return true;
|
|
28358
|
-
return connector.connections.some(
|
|
28359
|
-
(connection) => connection.status === options.connectionStatus && (!options.capability || connection.capabilities.some((item) => item.capability === options.capability))
|
|
28360
|
-
);
|
|
28361
|
-
}
|
|
28362
28388
|
|
|
28363
28389
|
// src/commands/connector/authorization-command.ts
|
|
28364
28390
|
async function runAuthorizationCommand(command, operation) {
|
|
@@ -28480,7 +28506,7 @@ function registerConnectorMutationCommands(connector) {
|
|
|
28480
28506
|
new Option3("--capability <capability>", "Capability to authorize").choices(["mcp", "trigger"]).makeOptionMandatory()
|
|
28481
28507
|
).action(async (connectorId, options, command) => {
|
|
28482
28508
|
await runAuthorizationCommand(command, async ({ api, authorizer, signal }) => {
|
|
28483
|
-
const selected2 = await
|
|
28509
|
+
const selected2 = await findConnector2(api, connectorId, signal);
|
|
28484
28510
|
assertConnectorSupportsCapability(selected2, options.capability);
|
|
28485
28511
|
if (!selected2.requiresConnection) {
|
|
28486
28512
|
throw new Error(`${selected2.name} does not require a connection.`);
|
|
@@ -28580,7 +28606,7 @@ function registerConnectorReadCommands(connector) {
|
|
|
28580
28606
|
).option("--without-connections", "Only include connectors with no connection records").option("--no-connections", "Do not fetch or include user connections").action(async (options, command) => {
|
|
28581
28607
|
await runApiCommand(
|
|
28582
28608
|
command,
|
|
28583
|
-
({ api, signal }) =>
|
|
28609
|
+
({ api, signal }) => listConnectors2(api, options, signal),
|
|
28584
28610
|
{
|
|
28585
28611
|
human: formatConnectorList
|
|
28586
28612
|
},
|
|
@@ -28595,7 +28621,7 @@ function registerConnectorReadCommands(connector) {
|
|
|
28595
28621
|
command,
|
|
28596
28622
|
async ({ api, signal }) => {
|
|
28597
28623
|
const [selected2, connections] = await Promise.all([
|
|
28598
|
-
|
|
28624
|
+
findConnector2(api, connectorId, signal),
|
|
28599
28625
|
api.connections.list({ connectorId }, { signal })
|
|
28600
28626
|
]);
|
|
28601
28627
|
return enrichConnector(selected2, connections.connections);
|