@composio/core 0.1.6-alpha.0 → 0.1.9-alpha.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 +3 -3
- package/dist/index.cjs +1271 -757
- package/dist/index.d.cts +598 -347
- package/dist/index.d.ts +598 -347
- package/dist/index.js +1239 -727
- package/package.json +4 -6
- package/src/index.ts +23 -0
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
AuthConfigTypes: () => AuthConfigTypes,
|
|
34
|
+
AuthSchemeTypes: () => AuthSchemeTypes,
|
|
33
35
|
BaseAgenticToolset: () => BaseAgenticToolset,
|
|
34
36
|
BaseNonAgenticToolset: () => BaseNonAgenticToolset,
|
|
35
37
|
BaseTelemetryTransport: () => BaseTelemetryTransport,
|
|
@@ -67,12 +69,12 @@ var ToolListResponseSchema = import_zod.z.object({
|
|
|
67
69
|
totalPages: import_zod.z.number()
|
|
68
70
|
});
|
|
69
71
|
var ToolListParamsSchema = import_zod.z.object({
|
|
72
|
+
tools: import_zod.z.array(import_zod.z.string()).optional(),
|
|
70
73
|
cursor: import_zod.z.string().optional(),
|
|
71
74
|
important: import_zod.z.string().optional(),
|
|
72
75
|
limit: import_zod.z.string().optional(),
|
|
73
76
|
search: import_zod.z.string().optional(),
|
|
74
|
-
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
75
|
-
tools: import_zod.z.array(import_zod.z.string()).optional()
|
|
77
|
+
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
76
78
|
});
|
|
77
79
|
var CustomAuthParamsSchema = import_zod.z.object({
|
|
78
80
|
baseURL: import_zod.z.string().optional(),
|
|
@@ -104,11 +106,212 @@ var ToolExecuteResponseSchema = import_zod.z.object({
|
|
|
104
106
|
|
|
105
107
|
// src/models/CustomTools.ts
|
|
106
108
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
|
|
109
|
+
|
|
110
|
+
// src/utils/env.ts
|
|
111
|
+
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
112
|
+
try {
|
|
113
|
+
return process.env[name] || defaultValue;
|
|
114
|
+
} catch (_e) {
|
|
115
|
+
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
116
|
+
return defaultValue;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/utils/logger.ts
|
|
121
|
+
var LOG_LEVELS = {
|
|
122
|
+
silent: -1,
|
|
123
|
+
// No logs
|
|
124
|
+
error: 0,
|
|
125
|
+
// Highest priority - critical errors
|
|
126
|
+
warn: 1,
|
|
127
|
+
// Warning messages
|
|
128
|
+
info: 2,
|
|
129
|
+
// General information
|
|
130
|
+
debug: 3
|
|
131
|
+
// Debug information
|
|
132
|
+
};
|
|
133
|
+
var getLogLevel = () => {
|
|
134
|
+
const envLevel = getEnvVariable("COMPOSIO_LOGGING_LEVEL", "info")?.toLowerCase();
|
|
135
|
+
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
136
|
+
};
|
|
137
|
+
var Logger = class {
|
|
138
|
+
level;
|
|
139
|
+
includeTimestamp;
|
|
140
|
+
console;
|
|
141
|
+
constructor(options = {}) {
|
|
142
|
+
this.level = options.level ?? getLogLevel();
|
|
143
|
+
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
144
|
+
this.console = console;
|
|
145
|
+
}
|
|
146
|
+
formatMessage(args) {
|
|
147
|
+
const formattedArgs = args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)).join("\n");
|
|
148
|
+
if (!this.includeTimestamp) {
|
|
149
|
+
return formattedArgs;
|
|
150
|
+
}
|
|
151
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
152
|
+
return `${timestamp} - ${formattedArgs}`;
|
|
153
|
+
}
|
|
154
|
+
shouldLog(level) {
|
|
155
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
156
|
+
}
|
|
157
|
+
error(...args) {
|
|
158
|
+
if (this.shouldLog("error")) {
|
|
159
|
+
this.console.error(this.formatMessage(args));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
warn(...args) {
|
|
163
|
+
if (this.shouldLog("warn")) {
|
|
164
|
+
this.console.warn(this.formatMessage(args));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
info(...args) {
|
|
168
|
+
if (this.shouldLog("info")) {
|
|
169
|
+
this.console.info(this.formatMessage(args));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
debug(...args) {
|
|
173
|
+
if (this.shouldLog("debug")) {
|
|
174
|
+
this.console.debug(this.formatMessage(args));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var logger = new Logger();
|
|
179
|
+
var logger_default = logger;
|
|
180
|
+
|
|
181
|
+
// src/errors/ComposioError.ts
|
|
182
|
+
var ComposioError = class extends Error {
|
|
183
|
+
name = "ComposioError";
|
|
184
|
+
code;
|
|
185
|
+
statusCode;
|
|
186
|
+
cause;
|
|
187
|
+
meta;
|
|
188
|
+
possibleFixes;
|
|
189
|
+
constructor(message, options = {}) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.code = options.code;
|
|
192
|
+
this.statusCode = options.statusCode;
|
|
193
|
+
this.cause = options.cause;
|
|
194
|
+
this.meta = options.meta;
|
|
195
|
+
this.possibleFixes = options.possibleFixes;
|
|
196
|
+
if (Error.captureStackTrace) {
|
|
197
|
+
Error.captureStackTrace(this, this.constructor);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
toJSON() {
|
|
201
|
+
return {
|
|
202
|
+
name: this.name,
|
|
203
|
+
message: this.message,
|
|
204
|
+
code: this.code,
|
|
205
|
+
statusCode: this.statusCode,
|
|
206
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
207
|
+
meta: this.meta,
|
|
208
|
+
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/errors/ToolErrors.ts
|
|
214
|
+
var ToolErrorCodes = {
|
|
215
|
+
TOOLSET_NOT_DEFINED: "TOOLSET_NOT_DEFINED",
|
|
216
|
+
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
|
|
217
|
+
INVALID_MODIFIER: "INVALID_MODIFIER",
|
|
218
|
+
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
219
|
+
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
220
|
+
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
|
|
221
|
+
};
|
|
222
|
+
var ComposioToolsetNotDefinedError = class extends ComposioError {
|
|
223
|
+
constructor(message = "Toolset not defined", meta = {}) {
|
|
224
|
+
super(message, {
|
|
225
|
+
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
226
|
+
meta,
|
|
227
|
+
possibleFixes: [
|
|
228
|
+
"Ensure that the toolset is defined in the Composio project and passed into the tool instance"
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
this.name = "ComposioToolsetNotDefinedError";
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var ComposioToolNotFoundError = class extends ComposioError {
|
|
235
|
+
constructor(message = "Tool not found", meta = {}) {
|
|
236
|
+
super(message, {
|
|
237
|
+
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
238
|
+
meta,
|
|
239
|
+
possibleFixes: ["Ensure the tool slug is correct and exists in the Composio project"]
|
|
240
|
+
});
|
|
241
|
+
this.name = "ComposioToolNotFoundError";
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var ComposioInvalidModifierError = class extends ComposioError {
|
|
245
|
+
constructor(message = "Invalid modifier", meta = {}) {
|
|
246
|
+
super(message, {
|
|
247
|
+
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
248
|
+
meta,
|
|
249
|
+
possibleFixes: ["Ensure the modifier is a function and returns a valid result"]
|
|
250
|
+
});
|
|
251
|
+
this.name = "ComposioInvalidModifierError";
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
255
|
+
constructor(message = "Custom tools not initialized", meta = {}) {
|
|
256
|
+
super(message, {
|
|
257
|
+
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
258
|
+
meta,
|
|
259
|
+
possibleFixes: ["Ensure the custom tools class is initialized in the Tools instance"]
|
|
260
|
+
});
|
|
261
|
+
this.name = "ComposioCustomToolsNotInitializedError";
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var ComposioToolExecutionError = class extends ComposioError {
|
|
265
|
+
error;
|
|
266
|
+
constructor(error, message = "Tool execution error", meta = {}) {
|
|
267
|
+
super(message, {
|
|
268
|
+
code: ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
269
|
+
cause: error,
|
|
270
|
+
meta,
|
|
271
|
+
possibleFixes: ["Ensure the tool is correctly configured and the input is valid"]
|
|
272
|
+
});
|
|
273
|
+
this.error = error;
|
|
274
|
+
this.name = "ComposioToolExecutionError";
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
278
|
+
constructor(message = "Invalid execute function", meta = {}) {
|
|
279
|
+
super(message, {
|
|
280
|
+
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
281
|
+
meta,
|
|
282
|
+
possibleFixes: ["Ensure the execute function is a valid function and returns a valid result"]
|
|
283
|
+
});
|
|
284
|
+
this.name = "ComposioInvalidExecuteFunctionError";
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/errors/ConnectedAccountsError.ts
|
|
289
|
+
var ConnectedAccountErrorCodes = {
|
|
290
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
291
|
+
};
|
|
292
|
+
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
293
|
+
constructor(message = "Connected account not found", meta = {}) {
|
|
294
|
+
super(message, {
|
|
295
|
+
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
296
|
+
statusCode: 404,
|
|
297
|
+
meta,
|
|
298
|
+
possibleFixes: [
|
|
299
|
+
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/models/CustomTools.ts
|
|
107
306
|
var CustomTools = class {
|
|
108
307
|
client;
|
|
109
|
-
customToolsRegistry
|
|
308
|
+
customToolsRegistry;
|
|
110
309
|
constructor(client) {
|
|
310
|
+
if (!client) {
|
|
311
|
+
throw new ComposioError("ComposioClient is required");
|
|
312
|
+
}
|
|
111
313
|
this.client = client;
|
|
314
|
+
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
112
315
|
}
|
|
113
316
|
/**
|
|
114
317
|
* Create a custom tool and registers it in the registry.
|
|
@@ -176,11 +379,16 @@ var CustomTools = class {
|
|
|
176
379
|
* @returns {Tool} The tool
|
|
177
380
|
*/
|
|
178
381
|
async getCustomToolBySlug(slug) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
382
|
+
if (!slug) {
|
|
383
|
+
throw new Error("Tool slug is required");
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
387
|
+
return tool?.schema;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
logger_default.error(`Error getting custom tool: ${error}`);
|
|
390
|
+
return void 0;
|
|
182
391
|
}
|
|
183
|
-
return tool.schema;
|
|
184
392
|
}
|
|
185
393
|
/**
|
|
186
394
|
* Get the connected account for the user and toolkit.
|
|
@@ -189,12 +397,25 @@ var CustomTools = class {
|
|
|
189
397
|
* @returns {ConnectedAccount} The connected account
|
|
190
398
|
*/
|
|
191
399
|
async getConnectedAccount(toolkitSlug, metadata) {
|
|
400
|
+
try {
|
|
401
|
+
await this.client.toolkits.retrieve(toolkitSlug);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
404
|
+
toolkitSlug,
|
|
405
|
+
error
|
|
406
|
+
});
|
|
407
|
+
}
|
|
192
408
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
193
409
|
toolkit_slug: toolkitSlug,
|
|
194
410
|
user_id: metadata.userId
|
|
195
411
|
});
|
|
196
412
|
if (!connectedAccounts.items.length) {
|
|
197
|
-
throw new
|
|
413
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
414
|
+
`No connected accounts found for toolkit ${toolkitSlug}`,
|
|
415
|
+
{
|
|
416
|
+
toolkitSlug
|
|
417
|
+
}
|
|
418
|
+
);
|
|
198
419
|
}
|
|
199
420
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
200
421
|
}
|
|
@@ -208,21 +429,29 @@ var CustomTools = class {
|
|
|
208
429
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
209
430
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
210
431
|
if (!tool) {
|
|
211
|
-
throw new
|
|
432
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
433
|
+
toolSlug: slug
|
|
434
|
+
});
|
|
212
435
|
}
|
|
213
436
|
let authCredentials = {};
|
|
214
437
|
const { toolkitSlug, execute } = tool.options;
|
|
215
|
-
if (toolkitSlug) {
|
|
438
|
+
if (toolkitSlug && toolkitSlug !== "custom") {
|
|
216
439
|
const connectedAccount = await this.getConnectedAccount(toolkitSlug, metadata);
|
|
217
440
|
if (!connectedAccount) {
|
|
218
|
-
throw new
|
|
219
|
-
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}
|
|
441
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
442
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
443
|
+
{
|
|
444
|
+
toolkitSlug,
|
|
445
|
+
userId: metadata.userId
|
|
446
|
+
}
|
|
220
447
|
);
|
|
221
448
|
}
|
|
222
449
|
authCredentials = connectedAccount.data?.connectionParams;
|
|
223
450
|
}
|
|
224
451
|
if (typeof execute !== "function") {
|
|
225
|
-
throw new
|
|
452
|
+
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
453
|
+
toolSlug: slug
|
|
454
|
+
});
|
|
226
455
|
}
|
|
227
456
|
const executeToolRequest = async (data) => {
|
|
228
457
|
return this.client.tools.proxy({
|
|
@@ -238,79 +467,42 @@ var CustomTools = class {
|
|
|
238
467
|
}
|
|
239
468
|
};
|
|
240
469
|
|
|
241
|
-
// src/
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
} catch (_e) {
|
|
246
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
247
|
-
return defaultValue;
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// src/utils/logger.ts
|
|
252
|
-
var LOG_LEVELS = {
|
|
253
|
-
silent: -1,
|
|
254
|
-
// No logs
|
|
255
|
-
error: 0,
|
|
256
|
-
// Highest priority - critical errors
|
|
257
|
-
warn: 1,
|
|
258
|
-
// Warning messages
|
|
259
|
-
info: 2,
|
|
260
|
-
// General information
|
|
261
|
-
debug: 3
|
|
262
|
-
// Debug information
|
|
263
|
-
};
|
|
264
|
-
var getLogLevel = () => {
|
|
265
|
-
const envLevel = getEnvVariable(
|
|
266
|
-
"COMPOSIO_LOGGING_LEVEL",
|
|
267
|
-
"info"
|
|
268
|
-
)?.toLowerCase();
|
|
269
|
-
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
470
|
+
// src/errors/ValidationError.ts
|
|
471
|
+
var import_zod2 = require("zod");
|
|
472
|
+
var ValidationErrorCodes = {
|
|
473
|
+
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
270
474
|
};
|
|
271
|
-
var
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
286
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
287
|
-
}
|
|
288
|
-
shouldLog(level) {
|
|
289
|
-
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
290
|
-
}
|
|
291
|
-
error(...args) {
|
|
292
|
-
if (this.shouldLog("error")) {
|
|
293
|
-
this.console.error(this.formatMessage(args));
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
warn(...args) {
|
|
297
|
-
if (this.shouldLog("warn")) {
|
|
298
|
-
this.console.warn(this.formatMessage(args));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
info(...args) {
|
|
302
|
-
if (this.shouldLog("info")) {
|
|
303
|
-
this.console.info(this.formatMessage(args));
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
debug(...args) {
|
|
307
|
-
if (this.shouldLog("debug")) {
|
|
308
|
-
this.console.debug(this.formatMessage(args));
|
|
475
|
+
var ValidationError = class extends ComposioError {
|
|
476
|
+
zodError;
|
|
477
|
+
constructor(zodError, message = "Input validation failed") {
|
|
478
|
+
let zodErrorInstance;
|
|
479
|
+
if (!(zodError instanceof import_zod2.ZodError)) {
|
|
480
|
+
zodErrorInstance = new import_zod2.ZodError([
|
|
481
|
+
{
|
|
482
|
+
path: [],
|
|
483
|
+
message: "Invalid input",
|
|
484
|
+
code: "custom"
|
|
485
|
+
}
|
|
486
|
+
]);
|
|
487
|
+
} else {
|
|
488
|
+
zodErrorInstance = zodError;
|
|
309
489
|
}
|
|
490
|
+
super(message, {
|
|
491
|
+
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
492
|
+
meta: {
|
|
493
|
+
issues: JSON.stringify(
|
|
494
|
+
zodErrorInstance.issues.map((issue) => ({
|
|
495
|
+
path: issue.path.join("."),
|
|
496
|
+
message: issue.message,
|
|
497
|
+
code: issue.code
|
|
498
|
+
}))
|
|
499
|
+
)
|
|
500
|
+
},
|
|
501
|
+
cause: zodErrorInstance
|
|
502
|
+
});
|
|
503
|
+
this.zodError = zodErrorInstance;
|
|
310
504
|
}
|
|
311
505
|
};
|
|
312
|
-
var logger = new Logger();
|
|
313
|
-
var logger_default = logger;
|
|
314
506
|
|
|
315
507
|
// src/models/Tools.ts
|
|
316
508
|
var Tools = class {
|
|
@@ -318,9 +510,18 @@ var Tools = class {
|
|
|
318
510
|
customTools;
|
|
319
511
|
toolset;
|
|
320
512
|
constructor(client, toolset) {
|
|
513
|
+
if (!client) {
|
|
514
|
+
throw new Error("ComposioClient is required");
|
|
515
|
+
}
|
|
516
|
+
if (!toolset) {
|
|
517
|
+
throw new ComposioToolsetNotDefinedError("Toolset not passed into Tools instance");
|
|
518
|
+
}
|
|
321
519
|
this.client = client;
|
|
322
520
|
this.customTools = new CustomTools(client);
|
|
323
521
|
this.toolset = toolset;
|
|
522
|
+
this.execute = this.execute.bind(this);
|
|
523
|
+
this.getComposioToolBySlug = this.getComposioToolBySlug.bind(this);
|
|
524
|
+
this.getComposioTools = this.getComposioTools.bind(this);
|
|
324
525
|
}
|
|
325
526
|
/**
|
|
326
527
|
* Transform the tool cases
|
|
@@ -429,15 +630,15 @@ var Tools = class {
|
|
|
429
630
|
async getComposioTools(userId, query = {}, modifier) {
|
|
430
631
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
431
632
|
if (queryParams.error) {
|
|
432
|
-
throw new
|
|
633
|
+
throw new ValidationError(queryParams.error);
|
|
433
634
|
}
|
|
434
635
|
const tools = await this.client.tools.list({
|
|
636
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
637
|
+
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
435
638
|
cursor: queryParams.data.cursor,
|
|
436
639
|
important: queryParams.data.important,
|
|
437
640
|
limit: queryParams.data.limit,
|
|
438
|
-
search: queryParams.data.search
|
|
439
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
440
|
-
tool_slugs: queryParams.data.tools?.join(",")
|
|
641
|
+
search: queryParams.data.search
|
|
441
642
|
});
|
|
442
643
|
if (!tools) {
|
|
443
644
|
return [];
|
|
@@ -450,10 +651,10 @@ var Tools = class {
|
|
|
450
651
|
if (modifier) {
|
|
451
652
|
if (typeof modifier === "function") {
|
|
452
653
|
modifiedTools = modifiedTools.map((tool) => {
|
|
453
|
-
return modifier(tool.slug, tool);
|
|
654
|
+
return modifier(tool.slug, tool.toolkit?.slug || "unkown", tool);
|
|
454
655
|
});
|
|
455
656
|
} else {
|
|
456
|
-
throw new
|
|
657
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
457
658
|
}
|
|
458
659
|
}
|
|
459
660
|
return modifiedTools;
|
|
@@ -470,14 +671,14 @@ var Tools = class {
|
|
|
470
671
|
}
|
|
471
672
|
const tool = await this.client.tools.retrieve(slug);
|
|
472
673
|
if (!tool) {
|
|
473
|
-
throw new
|
|
674
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
474
675
|
}
|
|
475
676
|
let modifiedToool = this.transformToolCases(tool);
|
|
476
677
|
if (modifier) {
|
|
477
678
|
if (typeof modifier === "function") {
|
|
478
|
-
modifiedToool = modifier(slug, modifiedToool);
|
|
679
|
+
modifiedToool = modifier(slug, modifiedToool.toolkit?.slug || "unkown", modifiedToool);
|
|
479
680
|
} else {
|
|
480
|
-
throw new
|
|
681
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
481
682
|
}
|
|
482
683
|
}
|
|
483
684
|
return modifiedToool;
|
|
@@ -512,6 +713,66 @@ var Tools = class {
|
|
|
512
713
|
};
|
|
513
714
|
return executeToolFn;
|
|
514
715
|
}
|
|
716
|
+
async handleCustomToolExecution(tool, body, modifiers) {
|
|
717
|
+
if (modifiers?.beforeToolExecute) {
|
|
718
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
719
|
+
body = modifiers.beforeToolExecute(tool.slug, "unkown", body);
|
|
720
|
+
} else {
|
|
721
|
+
throw new ComposioInvalidModifierError(
|
|
722
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
727
|
+
userId: body.userId || "default",
|
|
728
|
+
connectedAccountId: body.connectedAccountId
|
|
729
|
+
});
|
|
730
|
+
if (modifiers?.afterToolExecute) {
|
|
731
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
732
|
+
result = modifiers.afterToolExecute(tool.slug, "unkown", result);
|
|
733
|
+
} else {
|
|
734
|
+
throw new ComposioInvalidModifierError(
|
|
735
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return result;
|
|
740
|
+
}
|
|
741
|
+
async handleComposioToolExecution(tool, body, modifiers) {
|
|
742
|
+
if (modifiers?.beforeToolExecute) {
|
|
743
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
744
|
+
body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
745
|
+
} else {
|
|
746
|
+
throw new ComposioInvalidModifierError(
|
|
747
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
let connectedAccountId = body.connectedAccountId;
|
|
752
|
+
if (!connectedAccountId) {
|
|
753
|
+
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
754
|
+
}
|
|
755
|
+
let result = await this.client.tools.execute(tool.slug, {
|
|
756
|
+
allow_tracing: body.allowTracing,
|
|
757
|
+
connected_account_id: body.connectedAccountId,
|
|
758
|
+
custom_auth_params: body.customAuthParams,
|
|
759
|
+
arguments: body.arguments,
|
|
760
|
+
entity_id: body.userId,
|
|
761
|
+
version: body.version,
|
|
762
|
+
text: body.text
|
|
763
|
+
});
|
|
764
|
+
result = this.transformToolExecuteResponse(result);
|
|
765
|
+
if (modifiers?.afterToolExecute) {
|
|
766
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
767
|
+
result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
768
|
+
} else {
|
|
769
|
+
throw new ComposioInvalidModifierError(
|
|
770
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
515
776
|
/**
|
|
516
777
|
* Exectes a given tool with the provided parameters.
|
|
517
778
|
*
|
|
@@ -522,44 +783,28 @@ var Tools = class {
|
|
|
522
783
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
523
784
|
*/
|
|
524
785
|
async execute(slug, body, modifiers) {
|
|
525
|
-
if (
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
throw new Error("Invalid beforeToolExecute modifier. Not a function.");
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
let result;
|
|
533
|
-
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
534
|
-
if (customTool) {
|
|
535
|
-
result = await this.customTools.executeCustomTool(slug, body, {
|
|
536
|
-
userId: body.userId || "default",
|
|
537
|
-
connectedAccountId: body.connectedAccountId
|
|
538
|
-
});
|
|
539
|
-
} else {
|
|
540
|
-
let connectedAccountId = body.connectedAccountId;
|
|
541
|
-
if (!connectedAccountId) {
|
|
542
|
-
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, slug) || void 0;
|
|
543
|
-
}
|
|
544
|
-
result = await this.client.tools.execute(slug, {
|
|
545
|
-
allow_tracing: body.allowTracing,
|
|
546
|
-
connected_account_id: body.connectedAccountId,
|
|
547
|
-
custom_auth_params: body.customAuthParams,
|
|
548
|
-
arguments: body.arguments,
|
|
549
|
-
entity_id: body.userId,
|
|
550
|
-
version: body.version,
|
|
551
|
-
text: body.text
|
|
552
|
-
});
|
|
553
|
-
result = this.transformToolExecuteResponse(result);
|
|
786
|
+
if (!this.customTools) {
|
|
787
|
+
throw new ComposioCustomToolsNotInitializedError(
|
|
788
|
+
"CustomTools not initialized. Make sure Tools class is properly constructed."
|
|
789
|
+
);
|
|
554
790
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
791
|
+
try {
|
|
792
|
+
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
793
|
+
if (customTool) {
|
|
794
|
+
return this.handleCustomToolExecution(customTool, body, modifiers);
|
|
558
795
|
} else {
|
|
559
|
-
|
|
796
|
+
const composioTool = await this.getComposioToolBySlug(body.userId, slug);
|
|
797
|
+
if (!composioTool) {
|
|
798
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
799
|
+
}
|
|
800
|
+
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
560
801
|
}
|
|
802
|
+
} catch (error) {
|
|
803
|
+
throw new ComposioToolExecutionError(error, `Error executing tool ${slug}`, {
|
|
804
|
+
toolSlug: slug,
|
|
805
|
+
body
|
|
806
|
+
});
|
|
561
807
|
}
|
|
562
|
-
return result;
|
|
563
808
|
}
|
|
564
809
|
/**
|
|
565
810
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -602,773 +847,1039 @@ var Tools = class {
|
|
|
602
847
|
};
|
|
603
848
|
|
|
604
849
|
// src/types/toolkit.types.ts
|
|
605
|
-
var
|
|
606
|
-
var ToolkitMangedByEnumSchema =
|
|
607
|
-
var ToolkitSortByEnumSchema =
|
|
608
|
-
var ToolkitsListParamsSchema =
|
|
609
|
-
category:
|
|
610
|
-
isLocal:
|
|
850
|
+
var import_zod3 = require("zod");
|
|
851
|
+
var ToolkitMangedByEnumSchema = import_zod3.z.enum(["all", "composio_managed", "project_managed"]);
|
|
852
|
+
var ToolkitSortByEnumSchema = import_zod3.z.enum(["usage", "alphabetically"]);
|
|
853
|
+
var ToolkitsListParamsSchema = import_zod3.z.object({
|
|
854
|
+
category: import_zod3.z.string().optional(),
|
|
855
|
+
isLocal: import_zod3.z.boolean().optional(),
|
|
611
856
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
612
857
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
613
858
|
});
|
|
614
|
-
var ToolKitMetaSchema =
|
|
615
|
-
categories:
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
name:
|
|
859
|
+
var ToolKitMetaSchema = import_zod3.z.object({
|
|
860
|
+
categories: import_zod3.z.array(
|
|
861
|
+
import_zod3.z.object({
|
|
862
|
+
slug: import_zod3.z.string(),
|
|
863
|
+
name: import_zod3.z.string()
|
|
619
864
|
})
|
|
620
|
-
),
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
865
|
+
).optional(),
|
|
866
|
+
appUrl: import_zod3.z.string().optional(),
|
|
867
|
+
createdAt: import_zod3.z.string().optional(),
|
|
868
|
+
description: import_zod3.z.string().optional(),
|
|
869
|
+
logo: import_zod3.z.string().optional(),
|
|
870
|
+
toolsCount: import_zod3.z.number().optional(),
|
|
871
|
+
triggersCount: import_zod3.z.number().optional(),
|
|
872
|
+
updatedAt: import_zod3.z.string().optional()
|
|
627
873
|
});
|
|
628
|
-
var ToolKitItemSchema =
|
|
629
|
-
name:
|
|
630
|
-
slug:
|
|
874
|
+
var ToolKitItemSchema = import_zod3.z.object({
|
|
875
|
+
name: import_zod3.z.string(),
|
|
876
|
+
slug: import_zod3.z.string(),
|
|
631
877
|
meta: ToolKitMetaSchema,
|
|
632
|
-
isLocalToolkit:
|
|
633
|
-
authSchemes:
|
|
634
|
-
composioManagedAuthSchemes:
|
|
635
|
-
noAuth:
|
|
878
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
879
|
+
authSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
880
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
881
|
+
noAuth: import_zod3.z.boolean().optional()
|
|
636
882
|
});
|
|
637
|
-
var ToolKitListResponseSchema =
|
|
638
|
-
items:
|
|
639
|
-
nextCursor:
|
|
640
|
-
totalPages:
|
|
883
|
+
var ToolKitListResponseSchema = import_zod3.z.object({
|
|
884
|
+
items: import_zod3.z.array(ToolKitItemSchema),
|
|
885
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
886
|
+
totalPages: import_zod3.z.number()
|
|
641
887
|
});
|
|
642
|
-
var ToolkitAuthFieldSchema =
|
|
643
|
-
name:
|
|
644
|
-
displayName:
|
|
645
|
-
type:
|
|
646
|
-
default:
|
|
888
|
+
var ToolkitAuthFieldSchema = import_zod3.z.object({
|
|
889
|
+
name: import_zod3.z.string(),
|
|
890
|
+
displayName: import_zod3.z.string(),
|
|
891
|
+
type: import_zod3.z.string(),
|
|
892
|
+
default: import_zod3.z.string().nullable().optional()
|
|
647
893
|
});
|
|
648
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
649
|
-
name:
|
|
650
|
-
mode:
|
|
651
|
-
fields:
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
required: import_zod2.z.array(ToolkitAuthFieldSchema)
|
|
660
|
-
})
|
|
894
|
+
var ToolkitAuthConfigDetailsSchema = import_zod3.z.object({
|
|
895
|
+
name: import_zod3.z.string(),
|
|
896
|
+
mode: import_zod3.z.string(),
|
|
897
|
+
fields: import_zod3.z.object({
|
|
898
|
+
authConfigCreation: import_zod3.z.object({
|
|
899
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
900
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
901
|
+
}),
|
|
902
|
+
connectedAccountInitiation: import_zod3.z.object({
|
|
903
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
904
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
661
905
|
})
|
|
662
|
-
),
|
|
663
|
-
proxy:
|
|
664
|
-
|
|
906
|
+
}),
|
|
907
|
+
proxy: import_zod3.z.object({
|
|
908
|
+
baseUrl: import_zod3.z.string()
|
|
665
909
|
})
|
|
666
910
|
});
|
|
667
|
-
var ToolkitRetrieveResponseSchema =
|
|
668
|
-
name:
|
|
669
|
-
slug:
|
|
911
|
+
var ToolkitRetrieveResponseSchema = import_zod3.z.object({
|
|
912
|
+
name: import_zod3.z.string(),
|
|
913
|
+
slug: import_zod3.z.string(),
|
|
670
914
|
meta: ToolKitMetaSchema,
|
|
671
|
-
isLocalToolkit:
|
|
672
|
-
composioManagedAuthSchemes:
|
|
673
|
-
authConfigDetails:
|
|
915
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
916
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
917
|
+
authConfigDetails: import_zod3.z.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
674
918
|
});
|
|
675
|
-
var ToolkitCategorySchema =
|
|
676
|
-
id:
|
|
677
|
-
name:
|
|
919
|
+
var ToolkitCategorySchema = import_zod3.z.object({
|
|
920
|
+
id: import_zod3.z.string(),
|
|
921
|
+
name: import_zod3.z.string()
|
|
678
922
|
});
|
|
679
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
680
|
-
items:
|
|
681
|
-
nextCursor:
|
|
682
|
-
totalPages:
|
|
923
|
+
var ToolkitRetrieveCategoriesResponseSchema = import_zod3.z.object({
|
|
924
|
+
items: import_zod3.z.array(ToolkitCategorySchema),
|
|
925
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
926
|
+
totalPages: import_zod3.z.number()
|
|
683
927
|
});
|
|
684
928
|
|
|
685
929
|
// src/models/Toolkits.ts
|
|
686
|
-
var
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
930
|
+
var import_zod7 = require("zod");
|
|
931
|
+
|
|
932
|
+
// src/types/authConfigs.types.ts
|
|
933
|
+
var import_zod4 = require("zod");
|
|
934
|
+
var AuthConfigTypes = {
|
|
935
|
+
CUSTOM: "use_custom_auth",
|
|
936
|
+
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
937
|
+
};
|
|
938
|
+
var AuthSchemeTypes = {
|
|
939
|
+
OAUTH2: "OAUTH2",
|
|
940
|
+
OAUTH1: "OAUTH1",
|
|
941
|
+
OAUTH1A: "OAUTH1A",
|
|
942
|
+
API_KEY: "API_KEY",
|
|
943
|
+
BASIC: "BASIC",
|
|
944
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
945
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
946
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
947
|
+
NO_AUTH: "NO_AUTH",
|
|
948
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
949
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
950
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
951
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
952
|
+
};
|
|
953
|
+
var AuthSchemeEnum = import_zod4.z.enum([
|
|
954
|
+
"OAUTH2",
|
|
955
|
+
"OAUTH1",
|
|
956
|
+
"OAUTH1A",
|
|
957
|
+
"API_KEY",
|
|
958
|
+
"BASIC",
|
|
959
|
+
"BILLCOM_AUTH",
|
|
960
|
+
"BEARER_TOKEN",
|
|
961
|
+
"GOOGLE_SERVICE_ACCOUNT",
|
|
962
|
+
"NO_AUTH",
|
|
963
|
+
"BASIC_WITH_JWT",
|
|
964
|
+
"COMPOSIO_LINK",
|
|
965
|
+
"CALCOM_AUTH",
|
|
966
|
+
"SNOWFLAKE"
|
|
967
|
+
]);
|
|
968
|
+
var CreateCustomAuthConfigParamsSchema = import_zod4.z.object({
|
|
969
|
+
type: import_zod4.z.literal("use_custom_auth"),
|
|
970
|
+
name: import_zod4.z.string().optional(),
|
|
971
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
972
|
+
authScheme: AuthSchemeEnum
|
|
973
|
+
});
|
|
974
|
+
var CreateComposioManagedAuthConfigParamsSchema = import_zod4.z.object({
|
|
975
|
+
type: import_zod4.z.literal("use_composio_managed_auth"),
|
|
976
|
+
name: import_zod4.z.string().optional(),
|
|
977
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])).optional()
|
|
978
|
+
});
|
|
979
|
+
var CreateAuthConfigParamsSchema = import_zod4.z.discriminatedUnion("type", [
|
|
980
|
+
CreateCustomAuthConfigParamsSchema,
|
|
981
|
+
CreateComposioManagedAuthConfigParamsSchema
|
|
982
|
+
]);
|
|
983
|
+
var CreateAuthConfigResponseSchema = import_zod4.z.object({
|
|
984
|
+
id: import_zod4.z.string(),
|
|
985
|
+
authScheme: import_zod4.z.string(),
|
|
986
|
+
isComposioManaged: import_zod4.z.boolean(),
|
|
987
|
+
toolkit: import_zod4.z.string()
|
|
988
|
+
});
|
|
989
|
+
var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
990
|
+
id: import_zod4.z.string(),
|
|
991
|
+
name: import_zod4.z.string(),
|
|
992
|
+
toolkit: import_zod4.z.object({
|
|
993
|
+
logo: import_zod4.z.string(),
|
|
994
|
+
slug: import_zod4.z.string()
|
|
995
|
+
}),
|
|
996
|
+
noOfConnections: import_zod4.z.number(),
|
|
997
|
+
status: import_zod4.z.enum(["ENABLED", "DISABLED"]),
|
|
998
|
+
uuid: import_zod4.z.string(),
|
|
999
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
1000
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
1001
|
+
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1002
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1003
|
+
createdBy: import_zod4.z.string().optional(),
|
|
1004
|
+
createdAt: import_zod4.z.string().optional(),
|
|
1005
|
+
lastUpdatedAt: import_zod4.z.string().optional()
|
|
1006
|
+
});
|
|
1007
|
+
var AuthConfigListParamsSchema = import_zod4.z.object({
|
|
1008
|
+
cursor: import_zod4.z.string().optional(),
|
|
1009
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1010
|
+
limit: import_zod4.z.number().optional(),
|
|
1011
|
+
toolkitSlug: import_zod4.z.string().optional()
|
|
1012
|
+
});
|
|
1013
|
+
var AuthConfigListResponseSchema = import_zod4.z.object({
|
|
1014
|
+
items: import_zod4.z.array(AuthConfigRetrieveResponseSchema),
|
|
1015
|
+
nextCursor: import_zod4.z.string().optional(),
|
|
1016
|
+
totalPages: import_zod4.z.number()
|
|
1017
|
+
});
|
|
1018
|
+
var AuthConfigUpdateParamsSchema = import_zod4.z.object({
|
|
1019
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()]))
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
// src/models/AuthConfigs.ts
|
|
1023
|
+
var AuthConfigs = class {
|
|
1024
|
+
client;
|
|
1025
|
+
constructor(client) {
|
|
1026
|
+
this.client = client;
|
|
721
1027
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
1028
|
+
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1029
|
+
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1030
|
+
id: authConfig.id,
|
|
1031
|
+
name: authConfig.name,
|
|
1032
|
+
noOfConnections: authConfig.no_of_connections,
|
|
1033
|
+
status: authConfig.status,
|
|
1034
|
+
toolkit: {
|
|
1035
|
+
logo: authConfig.toolkit.logo,
|
|
1036
|
+
slug: authConfig.toolkit.slug
|
|
1037
|
+
},
|
|
1038
|
+
uuid: authConfig.uuid,
|
|
1039
|
+
authScheme: authConfig.auth_scheme,
|
|
1040
|
+
credentials: authConfig.credentials,
|
|
1041
|
+
expectedInputFields: authConfig.expected_input_fields,
|
|
1042
|
+
isComposioManaged: authConfig.is_composio_managed,
|
|
1043
|
+
createdBy: authConfig.created_by,
|
|
1044
|
+
createdAt: authConfig.created_at,
|
|
1045
|
+
lastUpdatedAt: authConfig.last_updated_at
|
|
738
1046
|
});
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
743
|
-
* This method retrieves the toolkit from the Composio API.
|
|
744
|
-
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
745
|
-
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
746
|
-
*/
|
|
747
|
-
async get(arg) {
|
|
748
|
-
if (typeof arg === "string") {
|
|
749
|
-
return this.getToolkitBySlug(arg);
|
|
1047
|
+
if (result.error) {
|
|
1048
|
+
throw new ValidationError(result.error);
|
|
750
1049
|
}
|
|
751
|
-
return
|
|
1050
|
+
return result.data;
|
|
752
1051
|
}
|
|
753
1052
|
/**
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* @
|
|
1053
|
+
* List all auth configs
|
|
1054
|
+
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
|
|
1055
|
+
* @param {RequestOptions} options - Request options
|
|
1056
|
+
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
757
1057
|
*/
|
|
758
|
-
async
|
|
759
|
-
const
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
1058
|
+
async list(query) {
|
|
1059
|
+
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
1060
|
+
const result = await this.client.authConfigs.list({
|
|
1061
|
+
cursor: parsedQuery?.cursor,
|
|
1062
|
+
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1063
|
+
limit: parsedQuery?.limit?.toString(),
|
|
1064
|
+
toolkit_slug: parsedQuery?.toolkitSlug
|
|
1065
|
+
});
|
|
1066
|
+
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1067
|
+
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
768
1068
|
nextCursor: result.next_cursor,
|
|
769
1069
|
totalPages: result.total_pages
|
|
770
1070
|
});
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
// src/utils/pusher.ts
|
|
776
|
-
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
777
|
-
var PUSHER_CLUSTER = "mt1";
|
|
778
|
-
var PusherUtils = class _PusherUtils {
|
|
779
|
-
static pusherClient;
|
|
780
|
-
static getPusherClient(baseURL, apiKey) {
|
|
781
|
-
if (!_PusherUtils.pusherClient) {
|
|
782
|
-
const PusherClient = require("pusher-js");
|
|
783
|
-
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
784
|
-
cluster: PUSHER_CLUSTER,
|
|
785
|
-
channelAuthorization: {
|
|
786
|
-
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
787
|
-
headers: {
|
|
788
|
-
"x-api-key": apiKey
|
|
789
|
-
},
|
|
790
|
-
transport: "ajax"
|
|
791
|
-
}
|
|
792
|
-
});
|
|
1071
|
+
if (parsedResult.error) {
|
|
1072
|
+
throw new ValidationError(parsedResult.error);
|
|
793
1073
|
}
|
|
794
|
-
return
|
|
1074
|
+
return parsedResult.data;
|
|
795
1075
|
}
|
|
796
1076
|
/**
|
|
797
|
-
*
|
|
798
|
-
* @param {string}
|
|
799
|
-
* @param {
|
|
800
|
-
* @
|
|
801
|
-
*
|
|
1077
|
+
* Create a new auth config
|
|
1078
|
+
* @param {string} toolkit - Unique identifier of the toolkit
|
|
1079
|
+
* @param {CreateAuthConfigParams} options - Options for creating a new auth config
|
|
1080
|
+
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1084
|
+
* type: AuthConfigTypes.CUSTOM,
|
|
1085
|
+
* name: 'My Custom Auth Config',
|
|
1086
|
+
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1087
|
+
* credentials: {
|
|
1088
|
+
* apiKey: '1234567890',
|
|
1089
|
+
* },
|
|
1090
|
+
* });
|
|
1091
|
+
*
|
|
1092
|
+
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
802
1093
|
*/
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
1094
|
+
async create(toolkit, options) {
|
|
1095
|
+
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1096
|
+
if (parsedOptions.error) {
|
|
1097
|
+
throw new ValidationError(parsedOptions.error);
|
|
1098
|
+
}
|
|
1099
|
+
const result = await this.client.authConfigs.create({
|
|
1100
|
+
toolkit: {
|
|
1101
|
+
slug: toolkit
|
|
1102
|
+
},
|
|
1103
|
+
auth_config: parsedOptions.data
|
|
1104
|
+
});
|
|
1105
|
+
const parsedResult = CreateAuthConfigResponseSchema.safeParse({
|
|
1106
|
+
id: result.auth_config.id,
|
|
1107
|
+
authScheme: result.auth_config.auth_scheme,
|
|
1108
|
+
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1109
|
+
toolkit: result.toolkit.slug
|
|
1110
|
+
});
|
|
1111
|
+
if (parsedResult.error) {
|
|
1112
|
+
throw new ValidationError(parsedResult.error);
|
|
810
1113
|
}
|
|
1114
|
+
return parsedResult.data;
|
|
811
1115
|
}
|
|
812
1116
|
/**
|
|
813
|
-
*
|
|
814
|
-
* @param {string}
|
|
815
|
-
* @
|
|
1117
|
+
* Get an auth config by nanoid
|
|
1118
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1119
|
+
* @param {RequestOptions} options - Request options
|
|
1120
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
|
|
816
1121
|
*/
|
|
817
|
-
|
|
818
|
-
|
|
1122
|
+
async get(nanoid) {
|
|
1123
|
+
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1124
|
+
return this.parseAuthConfigRetrieveResponse(result);
|
|
819
1125
|
}
|
|
820
1126
|
/**
|
|
821
|
-
*
|
|
822
|
-
* @param {
|
|
823
|
-
* @param {
|
|
824
|
-
* @param {
|
|
1127
|
+
* Update an auth config
|
|
1128
|
+
* @param {string} nanoid - Unique identifier of the auth config to update
|
|
1129
|
+
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1130
|
+
* @param {RequestOptions} options - Request options
|
|
1131
|
+
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
825
1132
|
*/
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const typedData = data;
|
|
831
|
-
if (!events.hasOwnProperty(typedData.id)) {
|
|
832
|
-
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
833
|
-
}
|
|
834
|
-
const ev = events[typedData.id];
|
|
835
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
836
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
837
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
838
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
839
|
-
delete events[typedData.id];
|
|
1133
|
+
async update(nanoid, data) {
|
|
1134
|
+
return this.client.authConfigs.update(nanoid, {
|
|
1135
|
+
auth_config: {
|
|
1136
|
+
credentials: data.credentials
|
|
840
1137
|
}
|
|
841
1138
|
});
|
|
842
1139
|
}
|
|
843
1140
|
/**
|
|
844
|
-
*
|
|
845
|
-
* @param {string}
|
|
846
|
-
* @param {
|
|
1141
|
+
* Delete an auth config
|
|
1142
|
+
* @param {string} nanoid - Unique identifier of the auth config to delete
|
|
1143
|
+
* @param {RequestOptions} options - Request options
|
|
1144
|
+
* @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
|
|
847
1145
|
*/
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
`private-${clientId}_triggers`
|
|
851
|
-
);
|
|
852
|
-
_PusherUtils.bindWithChunking(
|
|
853
|
-
channel,
|
|
854
|
-
"trigger_to_client",
|
|
855
|
-
fn
|
|
856
|
-
);
|
|
857
|
-
logger_default.info(
|
|
858
|
-
`Subscribed to triggers. You should start receiving events now.`
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
static triggerUnsubscribe(clientId) {
|
|
862
|
-
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
// src/models/Session.ts
|
|
867
|
-
var Session = class {
|
|
868
|
-
client;
|
|
869
|
-
constructor(client) {
|
|
870
|
-
this.client = client;
|
|
1146
|
+
async delete(nanoid) {
|
|
1147
|
+
return this.client.authConfigs.delete(nanoid);
|
|
871
1148
|
}
|
|
872
1149
|
/**
|
|
873
|
-
*
|
|
874
|
-
* @
|
|
1150
|
+
* Update the status of an auth config
|
|
1151
|
+
* @param {string} status - The status to update the auth config to
|
|
1152
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1153
|
+
* @param {RequestOptions} options - Request options
|
|
1154
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
875
1155
|
*/
|
|
876
|
-
async
|
|
877
|
-
return this.client.
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
// src/models/Triggers.ts
|
|
882
|
-
var Triggers = class {
|
|
883
|
-
client;
|
|
884
|
-
constructor(client) {
|
|
885
|
-
this.client = client;
|
|
1156
|
+
async updateStatus(status, nanoid) {
|
|
1157
|
+
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
886
1158
|
}
|
|
887
1159
|
/**
|
|
888
|
-
*
|
|
889
|
-
* @
|
|
1160
|
+
* Enable an auth config
|
|
1161
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1162
|
+
* @param {RequestOptions} options - Request options
|
|
1163
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
890
1164
|
*/
|
|
891
|
-
async
|
|
892
|
-
return this.client.
|
|
1165
|
+
async enable(nanoid) {
|
|
1166
|
+
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
893
1167
|
}
|
|
894
1168
|
/**
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
* @param {
|
|
898
|
-
* @
|
|
899
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
1169
|
+
* Disable an auth config
|
|
1170
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1171
|
+
* @param {RequestOptions} options - Request options
|
|
1172
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
900
1173
|
*/
|
|
901
|
-
async
|
|
902
|
-
return this.client.
|
|
1174
|
+
async disable(nanoid) {
|
|
1175
|
+
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
903
1176
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
// src/errors/AuthConfigErrors.ts
|
|
1180
|
+
var AuthConfigErrorCodes = {
|
|
1181
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1182
|
+
};
|
|
1183
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1184
|
+
constructor(message, meta) {
|
|
1185
|
+
super(message, {
|
|
1186
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1187
|
+
cause: meta,
|
|
1188
|
+
possibleFixes: [
|
|
1189
|
+
"Check if the auth config exists",
|
|
1190
|
+
"Check if the auth config id is correct",
|
|
1191
|
+
"Check if the auth config is enabled"
|
|
1192
|
+
]
|
|
1193
|
+
});
|
|
1194
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
913
1195
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
// src/types/connectedAccounts.types.ts
|
|
1199
|
+
var import_zod5 = require("zod");
|
|
1200
|
+
var ConnectedAccountStatuses = {
|
|
1201
|
+
ACTIVE: "ACTIVE",
|
|
1202
|
+
INACTIVE: "INACTIVE",
|
|
1203
|
+
PENDING: "DELETED",
|
|
1204
|
+
INITIATED: "INITIATED",
|
|
1205
|
+
EXPIRED: "EXPIRED",
|
|
1206
|
+
FAILED: "FAILED"
|
|
1207
|
+
};
|
|
1208
|
+
var ConnectedAccountStatusSchema = import_zod5.z.enum([
|
|
1209
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
1210
|
+
ConnectedAccountStatuses.INACTIVE,
|
|
1211
|
+
ConnectedAccountStatuses.PENDING,
|
|
1212
|
+
ConnectedAccountStatuses.INITIATED,
|
|
1213
|
+
ConnectedAccountStatuses.EXPIRED,
|
|
1214
|
+
ConnectedAccountStatuses.FAILED
|
|
1215
|
+
]);
|
|
1216
|
+
var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1217
|
+
authConfig: import_zod5.z.object({
|
|
1218
|
+
id: import_zod5.z.string()
|
|
1219
|
+
}),
|
|
1220
|
+
connection: import_zod5.z.object({
|
|
1221
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1222
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1223
|
+
userId: import_zod5.z.string().optional()
|
|
1224
|
+
})
|
|
1225
|
+
});
|
|
1226
|
+
var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1227
|
+
auth_config: import_zod5.z.object({
|
|
1228
|
+
id: import_zod5.z.string()
|
|
1229
|
+
}),
|
|
1230
|
+
connection: import_zod5.z.object({
|
|
1231
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1232
|
+
redirect_uri: import_zod5.z.string().optional(),
|
|
1233
|
+
user_id: import_zod5.z.string().optional()
|
|
1234
|
+
})
|
|
1235
|
+
});
|
|
1236
|
+
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1237
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1238
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1239
|
+
});
|
|
1240
|
+
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
1241
|
+
id: import_zod5.z.string(),
|
|
1242
|
+
status: ConnectedAccountStatusSchema,
|
|
1243
|
+
redirectUrl: import_zod5.z.string().nullable()
|
|
1244
|
+
});
|
|
1245
|
+
var ConnectedAccountAuthSchemes = {
|
|
1246
|
+
OAUTH2: "OAUTH2",
|
|
1247
|
+
OAUTH1: "OAUTH1",
|
|
1248
|
+
OAUTH1A: "OAUTH1A",
|
|
1249
|
+
API_KEY: "API_KEY",
|
|
1250
|
+
BASIC: "BASIC",
|
|
1251
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1252
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1253
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1254
|
+
NO_AUTH: "NO_AUTH",
|
|
1255
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1256
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1257
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1258
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
1259
|
+
};
|
|
1260
|
+
var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
1261
|
+
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1262
|
+
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1263
|
+
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1264
|
+
ConnectedAccountAuthSchemes.API_KEY,
|
|
1265
|
+
ConnectedAccountAuthSchemes.BASIC,
|
|
1266
|
+
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1267
|
+
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1268
|
+
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1269
|
+
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1270
|
+
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1271
|
+
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1272
|
+
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1273
|
+
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1274
|
+
]);
|
|
1275
|
+
var ConnectedAccountAuthConfigSchema = import_zod5.z.object({
|
|
1276
|
+
id: import_zod5.z.string(),
|
|
1277
|
+
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1278
|
+
isComposioManaged: import_zod5.z.boolean(),
|
|
1279
|
+
isDisabled: import_zod5.z.boolean()
|
|
1280
|
+
});
|
|
1281
|
+
var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
1282
|
+
id: import_zod5.z.string(),
|
|
1283
|
+
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1284
|
+
userId: import_zod5.z.string(),
|
|
1285
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1286
|
+
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1287
|
+
status: ConnectedAccountStatusSchema,
|
|
1288
|
+
statusReason: import_zod5.z.string().nullable(),
|
|
1289
|
+
toolkit: import_zod5.z.object({
|
|
1290
|
+
slug: import_zod5.z.string()
|
|
1291
|
+
}),
|
|
1292
|
+
testRequestEndpoint: import_zod5.z.string().optional(),
|
|
1293
|
+
isDisabled: import_zod5.z.boolean(),
|
|
1294
|
+
createdAt: import_zod5.z.string(),
|
|
1295
|
+
updatedAt: import_zod5.z.string()
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
// src/models/ConnectionRequest.ts
|
|
1299
|
+
var import_zod6 = require("zod");
|
|
1300
|
+
|
|
1301
|
+
// src/errors/ConnectionRequestError.ts
|
|
1302
|
+
var ConnectionRequestErrorCodes = {
|
|
1303
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
|
|
1304
|
+
};
|
|
1305
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1306
|
+
constructor(message = "Connection request timed out", meta = {}) {
|
|
1307
|
+
super(message, {
|
|
1308
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1309
|
+
meta
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
// src/models/ConnectionRequest.ts
|
|
1315
|
+
var ConnectionRequest = class {
|
|
1316
|
+
client;
|
|
1317
|
+
connectedAccountId;
|
|
1318
|
+
connectedAccountStatus;
|
|
1319
|
+
redirectUrl;
|
|
1320
|
+
constructor(client, connectedAccountId, connectedAccountStatus, redirectUrl) {
|
|
1321
|
+
this.client = client;
|
|
1322
|
+
this.connectedAccountId = connectedAccountId;
|
|
1323
|
+
this.connectedAccountStatus = connectedAccountStatus;
|
|
1324
|
+
this.redirectUrl = redirectUrl;
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Transform the response from the Composio API to the SDK format
|
|
1328
|
+
* @param response
|
|
918
1329
|
* @returns
|
|
919
1330
|
*/
|
|
920
|
-
async
|
|
921
|
-
|
|
1331
|
+
async transformResponse(response) {
|
|
1332
|
+
try {
|
|
1333
|
+
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1334
|
+
...response,
|
|
1335
|
+
userId: response.user_id,
|
|
1336
|
+
// Add the missing userId property
|
|
1337
|
+
authConfig: {
|
|
1338
|
+
...response.auth_config,
|
|
1339
|
+
authScheme: response.auth_config.auth_scheme,
|
|
1340
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1341
|
+
isDisabled: response.auth_config.is_disabled
|
|
1342
|
+
},
|
|
1343
|
+
statusReason: response.status_reason,
|
|
1344
|
+
isDisabled: response.is_disabled,
|
|
1345
|
+
createdAt: response.created_at,
|
|
1346
|
+
updatedAt: response.updated_at,
|
|
1347
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
1348
|
+
});
|
|
1349
|
+
return parsedResponse;
|
|
1350
|
+
} catch (error) {
|
|
1351
|
+
logger_default.error("Error transforming response", error);
|
|
1352
|
+
if (error instanceof import_zod6.ZodError) {
|
|
1353
|
+
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1354
|
+
}
|
|
1355
|
+
throw error;
|
|
1356
|
+
}
|
|
922
1357
|
}
|
|
923
1358
|
/**
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
* @param {
|
|
927
|
-
* @
|
|
928
|
-
* @param {RequestOptions} options - Request options
|
|
929
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1359
|
+
* Wait for the connection to be established.
|
|
1360
|
+
* The function will poll the Composio API every second until the connection is established or the timeout is reached.
|
|
1361
|
+
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1362
|
+
* @returns
|
|
930
1363
|
*/
|
|
931
|
-
async
|
|
932
|
-
|
|
1364
|
+
async waitForConnection(timeout = 6e4) {
|
|
1365
|
+
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
|
|
1366
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1367
|
+
return Promise.resolve(this.transformResponse(response));
|
|
1368
|
+
}
|
|
1369
|
+
return new Promise((resolve, reject) => {
|
|
1370
|
+
const interval = setInterval(async () => {
|
|
1371
|
+
try {
|
|
1372
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1373
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1374
|
+
clearInterval(interval);
|
|
1375
|
+
resolve(this.transformResponse(response));
|
|
1376
|
+
}
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
clearInterval(interval);
|
|
1379
|
+
reject(error);
|
|
1380
|
+
}
|
|
1381
|
+
}, 1e3);
|
|
1382
|
+
setTimeout(() => {
|
|
1383
|
+
clearInterval(interval);
|
|
1384
|
+
reject(
|
|
1385
|
+
new ConnectionRequestTimeoutError(
|
|
1386
|
+
`Connection request timed out for ${this.connectedAccountId}`
|
|
1387
|
+
)
|
|
1388
|
+
);
|
|
1389
|
+
}, timeout);
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
// src/models/ConnectedAccounts.ts
|
|
1395
|
+
var ConnectedAccounts = class {
|
|
1396
|
+
client;
|
|
1397
|
+
constructor(client) {
|
|
1398
|
+
this.client = client;
|
|
933
1399
|
}
|
|
934
1400
|
/**
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
* @param {
|
|
938
|
-
* @
|
|
939
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1401
|
+
* List all connected accounts
|
|
1402
|
+
* @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
|
|
1403
|
+
* @param {RequestOptions} options - Request options
|
|
1404
|
+
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
940
1405
|
*/
|
|
941
|
-
async
|
|
942
|
-
return this.client.
|
|
1406
|
+
async list(query) {
|
|
1407
|
+
return this.client.connectedAccounts.list(query);
|
|
943
1408
|
}
|
|
944
1409
|
/**
|
|
945
|
-
*
|
|
1410
|
+
* Compound function to create a new connected account.
|
|
1411
|
+
* This function creates a new connected account and returns a connection request.
|
|
1412
|
+
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1413
|
+
* @param {string} userId - User ID of the connected account
|
|
1414
|
+
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1415
|
+
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1416
|
+
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
946
1417
|
*
|
|
947
|
-
* @
|
|
948
|
-
*
|
|
949
|
-
*
|
|
1418
|
+
* @example
|
|
1419
|
+
* const connectionRequest = await composio.createConnectedAccount('user_123', 'auth_config_123', {
|
|
1420
|
+
* data: {
|
|
1421
|
+
* name: 'My Connected Account',
|
|
1422
|
+
* },
|
|
1423
|
+
* });
|
|
1424
|
+
*
|
|
1425
|
+
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
950
1426
|
*/
|
|
951
|
-
async
|
|
952
|
-
|
|
1427
|
+
async initiate(userId, authConfigId, options) {
|
|
1428
|
+
const response = await this.client.connectedAccounts.create({
|
|
1429
|
+
auth_config: {
|
|
1430
|
+
id: authConfigId
|
|
1431
|
+
},
|
|
1432
|
+
connection: {
|
|
1433
|
+
data: options?.data,
|
|
1434
|
+
redirect_uri: options?.redirectUrl,
|
|
1435
|
+
user_id: userId
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
|
|
953
1439
|
}
|
|
954
1440
|
/**
|
|
955
|
-
*
|
|
1441
|
+
* Get a connected account by nanoid
|
|
1442
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1443
|
+
* @param {RequestOptions} options - Request options
|
|
1444
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
|
|
956
1445
|
*/
|
|
1446
|
+
async get(nanoid) {
|
|
1447
|
+
return this.client.connectedAccounts.retrieve(nanoid);
|
|
1448
|
+
}
|
|
957
1449
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1450
|
+
* Delete a connected account
|
|
1451
|
+
* @param {string} nanoid - Unique identifier of the connected account to delete
|
|
961
1452
|
* @param {RequestOptions} options - Request options
|
|
962
|
-
* @returns {Promise<
|
|
1453
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
|
|
963
1454
|
*/
|
|
964
|
-
async
|
|
965
|
-
return this.client.
|
|
1455
|
+
async delete(nanoid) {
|
|
1456
|
+
return this.client.connectedAccounts.delete(nanoid);
|
|
966
1457
|
}
|
|
967
1458
|
/**
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
* @param {
|
|
971
|
-
* @
|
|
972
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1459
|
+
* Refresh a connected account's credentials
|
|
1460
|
+
* @param {string} nanoid - Unique identifier of the connected account to refresh
|
|
1461
|
+
* @param {RequestOptions} options - Request options
|
|
1462
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
|
|
973
1463
|
*/
|
|
974
|
-
async
|
|
975
|
-
return this.client.
|
|
1464
|
+
async refresh(nanoid) {
|
|
1465
|
+
return this.client.connectedAccounts.refresh(nanoid);
|
|
976
1466
|
}
|
|
977
1467
|
/**
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
* @param options
|
|
982
|
-
* @returns
|
|
1468
|
+
* Update the status of a connected account
|
|
1469
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1470
|
+
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
1471
|
+
* @param {RequestOptions} options - Request options
|
|
1472
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
983
1473
|
*/
|
|
984
|
-
async
|
|
985
|
-
return this.client.
|
|
1474
|
+
async updateStatus(nanoid, params) {
|
|
1475
|
+
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
986
1476
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
if (Object.keys(filters).length === 0) return true;
|
|
996
|
-
else {
|
|
997
|
-
return (!filters.appName || data.appName.toLowerCase() === filters.appName.toLowerCase()) && (!filters.triggerId || data.metadata.id.toLowerCase() === filters.triggerId.toLowerCase()) && (!filters.connectionId || data.metadata.connectionId.toLowerCase() === filters.connectionId.toLowerCase()) && (!filters.triggerName || data.metadata.triggerName.toLowerCase() === filters.triggerName.toLowerCase()) && (!filters.entityId || data.metadata.connection.clientUniqueUserId.toLowerCase() === filters.entityId.toLowerCase()) && (!filters.integrationId || data.metadata.connection.integrationId.toLowerCase() === filters.integrationId.toLowerCase());
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
1001
|
-
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1002
|
-
if (shouldSendTrigger(data)) {
|
|
1003
|
-
fn(data);
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1477
|
+
/**
|
|
1478
|
+
* Enable a connected account
|
|
1479
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1480
|
+
* @param {RequestOptions} options - Request options
|
|
1481
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1482
|
+
*/
|
|
1483
|
+
async enable(nanoid) {
|
|
1484
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
1006
1485
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1486
|
+
/**
|
|
1487
|
+
* Disable a connected account
|
|
1488
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1489
|
+
* @param {RequestOptions} options - Request options
|
|
1490
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1491
|
+
*/
|
|
1492
|
+
async disable(nanoid) {
|
|
1493
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
1013
1494
|
}
|
|
1014
1495
|
};
|
|
1015
1496
|
|
|
1016
|
-
// src/models/
|
|
1017
|
-
var
|
|
1018
|
-
FILE_NAME = "core/models/AuthConfigs.ts";
|
|
1497
|
+
// src/models/Toolkits.ts
|
|
1498
|
+
var Toolkits = class {
|
|
1019
1499
|
client;
|
|
1020
1500
|
constructor(client) {
|
|
1021
1501
|
this.client = client;
|
|
1502
|
+
this.authorize = this.authorize.bind(this);
|
|
1022
1503
|
}
|
|
1023
1504
|
/**
|
|
1024
|
-
* List all
|
|
1025
|
-
*
|
|
1026
|
-
* @
|
|
1027
|
-
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
1505
|
+
* List all toolkits available in the Composio SDK.
|
|
1506
|
+
* This method fetches the toolkits from the Composio API.
|
|
1507
|
+
* @returns {Promise<Toolkit[]>} List of toolkits
|
|
1028
1508
|
*/
|
|
1029
|
-
async
|
|
1030
|
-
|
|
1509
|
+
async getToolkits(query) {
|
|
1510
|
+
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
1511
|
+
const result = await this.client.toolkits.list({
|
|
1512
|
+
category: parsedQuery.category,
|
|
1513
|
+
is_local: parsedQuery.isLocal,
|
|
1514
|
+
managed_by: parsedQuery.managedBy,
|
|
1515
|
+
sort_by: parsedQuery.sortBy
|
|
1516
|
+
});
|
|
1517
|
+
const parsedResult = ToolKitListResponseSchema.parse({
|
|
1518
|
+
items: result.items.map((item) => {
|
|
1519
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
1520
|
+
name: item.name,
|
|
1521
|
+
slug: item.slug,
|
|
1522
|
+
meta: item.meta,
|
|
1523
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
1524
|
+
authSchemes: item.auth_schemes,
|
|
1525
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
1526
|
+
noAuth: item.no_auth
|
|
1527
|
+
});
|
|
1528
|
+
return parsedItem;
|
|
1529
|
+
}),
|
|
1530
|
+
nextCursor: result.next_cursor,
|
|
1531
|
+
totalPages: result.total_pages
|
|
1532
|
+
});
|
|
1533
|
+
return parsedResult;
|
|
1031
1534
|
}
|
|
1032
1535
|
/**
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
* @param
|
|
1036
|
-
* @
|
|
1536
|
+
* Fetches a toolkit by its Slug.
|
|
1537
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1538
|
+
* @param slug - The ID of the toolkit to be retrieved
|
|
1539
|
+
* @param options - Request options
|
|
1540
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
|
|
1037
1541
|
*/
|
|
1038
|
-
async
|
|
1039
|
-
|
|
1542
|
+
async getToolkitBySlug(slug) {
|
|
1543
|
+
try {
|
|
1544
|
+
const result = await this.client.toolkits.retrieve(slug);
|
|
1545
|
+
const parsedResult = ToolkitRetrieveResponseSchema.parse({
|
|
1546
|
+
name: result.name,
|
|
1547
|
+
slug: result.slug,
|
|
1548
|
+
meta: {
|
|
1549
|
+
...result.meta,
|
|
1550
|
+
createdAt: result.meta.created_at,
|
|
1551
|
+
updatedAt: result.meta.updated_at,
|
|
1552
|
+
toolsCount: result.meta.tools_count,
|
|
1553
|
+
triggersCount: result.meta.triggers_count
|
|
1554
|
+
// appUrl: result.meta.app_url, @TODO Update the client type to include this
|
|
1555
|
+
},
|
|
1556
|
+
isLocalToolkit: result.is_local_toolkit,
|
|
1557
|
+
composioManagedAuthSchemes: result.composio_managed_auth_schemes,
|
|
1558
|
+
authConfigDetails: result.auth_config_details?.map((authConfig) => ({
|
|
1559
|
+
name: authConfig.name,
|
|
1560
|
+
mode: authConfig.mode,
|
|
1561
|
+
fields: {
|
|
1562
|
+
authConfigCreation: authConfig.fields.auth_config_creation,
|
|
1563
|
+
connectedAccountInitiation: authConfig.fields.connected_account_initiation
|
|
1564
|
+
},
|
|
1565
|
+
proxy: {
|
|
1566
|
+
baseUrl: authConfig.proxy?.base_url
|
|
1567
|
+
}
|
|
1568
|
+
}))
|
|
1569
|
+
});
|
|
1570
|
+
return parsedResult;
|
|
1571
|
+
} catch (error) {
|
|
1572
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1573
|
+
throw new ValidationError(error);
|
|
1574
|
+
}
|
|
1575
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
1576
|
+
slug
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1040
1579
|
}
|
|
1041
1580
|
/**
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
* @param
|
|
1045
|
-
* @returns {Promise<
|
|
1581
|
+
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
1582
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1583
|
+
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
1584
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
1046
1585
|
*/
|
|
1047
|
-
async get(
|
|
1048
|
-
|
|
1586
|
+
async get(arg) {
|
|
1587
|
+
if (typeof arg === "string") {
|
|
1588
|
+
return this.getToolkitBySlug(arg);
|
|
1589
|
+
}
|
|
1590
|
+
return this.getToolkits(arg);
|
|
1049
1591
|
}
|
|
1050
1592
|
/**
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
* @
|
|
1054
|
-
* @param {RequestOptions} options - Request options
|
|
1055
|
-
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
1593
|
+
* Fetches all categories available in the Composio SDK
|
|
1594
|
+
*
|
|
1595
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
|
|
1056
1596
|
*/
|
|
1057
|
-
async
|
|
1058
|
-
|
|
1597
|
+
async listCategories() {
|
|
1598
|
+
const result = await this.client.toolkits.retrieveCategories();
|
|
1599
|
+
const parsedResult = ToolkitRetrieveCategoriesResponseSchema.parse({
|
|
1600
|
+
items: result.items.map((item) => {
|
|
1601
|
+
const parsedItem = ToolkitCategorySchema.parse({
|
|
1602
|
+
id: item.id,
|
|
1603
|
+
name: item.name
|
|
1604
|
+
});
|
|
1605
|
+
return parsedItem;
|
|
1606
|
+
}),
|
|
1607
|
+
nextCursor: result.next_cursor,
|
|
1608
|
+
totalPages: result.total_pages
|
|
1609
|
+
});
|
|
1610
|
+
return parsedResult;
|
|
1059
1611
|
}
|
|
1060
1612
|
/**
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
* @param {
|
|
1064
|
-
* @
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1613
|
+
* Authorizes a user to use a toolkit.
|
|
1614
|
+
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1615
|
+
* @param {string} userId - The user id of the user to authorize
|
|
1616
|
+
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1617
|
+
* @param {string} authConfigId - The id of the auth config to use
|
|
1618
|
+
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
1619
|
+
*/
|
|
1620
|
+
async authorize(userId, toolkitSlug, authConfigId) {
|
|
1621
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1622
|
+
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1623
|
+
let authConfigIdToUse;
|
|
1624
|
+
if (authConfigId) {
|
|
1625
|
+
const authConfig = await composioAuthConfig.get(authConfigId);
|
|
1626
|
+
authConfigIdToUse = authConfig.id;
|
|
1627
|
+
} else {
|
|
1628
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
1629
|
+
const authConfig = await composioAuthConfig.create(toolkitSlug, {
|
|
1630
|
+
type: "use_composio_managed_auth",
|
|
1631
|
+
name: `${toolkit.name} Auth Config`
|
|
1632
|
+
});
|
|
1633
|
+
authConfigIdToUse = authConfig.id;
|
|
1634
|
+
} else {
|
|
1635
|
+
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1636
|
+
toolkitSlug
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
1641
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
// src/utils/pusher.ts
|
|
1646
|
+
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
1647
|
+
var PUSHER_CLUSTER = "mt1";
|
|
1648
|
+
var PusherUtils = class _PusherUtils {
|
|
1649
|
+
static pusherClient;
|
|
1650
|
+
static getPusherClient(baseURL, apiKey) {
|
|
1651
|
+
if (!_PusherUtils.pusherClient) {
|
|
1652
|
+
const PusherClient = require("pusher-js");
|
|
1653
|
+
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
1654
|
+
cluster: PUSHER_CLUSTER,
|
|
1655
|
+
channelAuthorization: {
|
|
1656
|
+
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
1657
|
+
headers: {
|
|
1658
|
+
"x-api-key": apiKey
|
|
1659
|
+
},
|
|
1660
|
+
transport: "ajax"
|
|
1661
|
+
}
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
return _PusherUtils.pusherClient;
|
|
1068
1665
|
}
|
|
1069
1666
|
/**
|
|
1070
|
-
*
|
|
1071
|
-
* @param {string}
|
|
1072
|
-
* @param {string}
|
|
1073
|
-
* @param {
|
|
1074
|
-
* @returns {
|
|
1667
|
+
* Subscribes to a Pusher channel and binds an event to a callback function.
|
|
1668
|
+
* @param {string} channelName - The name of the channel to subscribe to.
|
|
1669
|
+
* @param {string} event - The event to bind to the channel.
|
|
1670
|
+
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
1671
|
+
* @returns {PusherClient} The Pusher client instance.
|
|
1075
1672
|
*/
|
|
1076
|
-
async
|
|
1077
|
-
|
|
1673
|
+
static async subscribe(channelName, event, fn) {
|
|
1674
|
+
try {
|
|
1675
|
+
await _PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
|
|
1676
|
+
} catch (error) {
|
|
1677
|
+
logger_default.error(
|
|
1678
|
+
`Error subscribing to ${channelName} with event ${event}: ${error}`
|
|
1679
|
+
);
|
|
1680
|
+
}
|
|
1078
1681
|
}
|
|
1079
1682
|
/**
|
|
1080
|
-
*
|
|
1081
|
-
* @param {string}
|
|
1082
|
-
* @
|
|
1083
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
1683
|
+
* Unsubscribes from a Pusher channel.
|
|
1684
|
+
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
1685
|
+
* @returns {void}
|
|
1084
1686
|
*/
|
|
1085
|
-
async
|
|
1086
|
-
|
|
1687
|
+
static async unsubscribe(channelName) {
|
|
1688
|
+
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
1087
1689
|
}
|
|
1088
1690
|
/**
|
|
1089
|
-
*
|
|
1090
|
-
* @param {
|
|
1091
|
-
* @param {
|
|
1092
|
-
* @
|
|
1691
|
+
* Binds an event to a channel with support for chunked messages.
|
|
1692
|
+
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
1693
|
+
* @param {string} event - The event to bind to the channel.
|
|
1694
|
+
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
1093
1695
|
*/
|
|
1094
|
-
|
|
1095
|
-
|
|
1696
|
+
static bindWithChunking(channel, event, callback) {
|
|
1697
|
+
channel.bind(event, callback);
|
|
1698
|
+
const events = {};
|
|
1699
|
+
channel.bind("chunked-" + event, (data) => {
|
|
1700
|
+
const typedData = data;
|
|
1701
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
1702
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
1703
|
+
}
|
|
1704
|
+
const ev = events[typedData.id];
|
|
1705
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
1706
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
1707
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
1708
|
+
callback(JSON.parse(ev.chunks.join("")));
|
|
1709
|
+
delete events[typedData.id];
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
1715
|
+
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
1716
|
+
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
1717
|
+
*/
|
|
1718
|
+
static triggerSubscribe(clientId, fn) {
|
|
1719
|
+
const channel = _PusherUtils.pusherClient.subscribe(
|
|
1720
|
+
`private-${clientId}_triggers`
|
|
1721
|
+
);
|
|
1722
|
+
_PusherUtils.bindWithChunking(
|
|
1723
|
+
channel,
|
|
1724
|
+
"trigger_to_client",
|
|
1725
|
+
fn
|
|
1726
|
+
);
|
|
1727
|
+
logger_default.info(
|
|
1728
|
+
`Subscribed to triggers. You should start receiving events now.`
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1731
|
+
static triggerUnsubscribe(clientId) {
|
|
1732
|
+
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
1096
1733
|
}
|
|
1097
1734
|
};
|
|
1098
1735
|
|
|
1099
|
-
// src/
|
|
1100
|
-
var
|
|
1101
|
-
var ConnectedAccountStatuses = {
|
|
1102
|
-
ACTIVE: "ACTIVE",
|
|
1103
|
-
INACTIVE: "INACTIVE",
|
|
1104
|
-
PENDING: "DELETED",
|
|
1105
|
-
INITIATED: "INITIATED",
|
|
1106
|
-
EXPIRED: "EXPIRED",
|
|
1107
|
-
FAILED: "FAILED"
|
|
1108
|
-
};
|
|
1109
|
-
var ConnectedAccountStatusSchema = import_zod3.z.enum([
|
|
1110
|
-
ConnectedAccountStatuses.ACTIVE,
|
|
1111
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1112
|
-
ConnectedAccountStatuses.PENDING,
|
|
1113
|
-
ConnectedAccountStatuses.INITIATED,
|
|
1114
|
-
ConnectedAccountStatuses.EXPIRED,
|
|
1115
|
-
ConnectedAccountStatuses.FAILED
|
|
1116
|
-
]);
|
|
1117
|
-
var CreateConnectedAccountParamsSchema = import_zod3.z.object({
|
|
1118
|
-
authConfig: import_zod3.z.object({
|
|
1119
|
-
id: import_zod3.z.string()
|
|
1120
|
-
}),
|
|
1121
|
-
connection: import_zod3.z.object({
|
|
1122
|
-
data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional(),
|
|
1123
|
-
redirectUrl: import_zod3.z.string().optional(),
|
|
1124
|
-
userId: import_zod3.z.string().optional()
|
|
1125
|
-
})
|
|
1126
|
-
});
|
|
1127
|
-
var DefaultCreateConnectedAccountParamsSchema = import_zod3.z.object({
|
|
1128
|
-
auth_config: import_zod3.z.object({
|
|
1129
|
-
id: import_zod3.z.string()
|
|
1130
|
-
}),
|
|
1131
|
-
connection: import_zod3.z.object({
|
|
1132
|
-
data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional(),
|
|
1133
|
-
redirect_uri: import_zod3.z.string().optional(),
|
|
1134
|
-
user_id: import_zod3.z.string().optional()
|
|
1135
|
-
})
|
|
1136
|
-
});
|
|
1137
|
-
var CreateConnectedAccountOptionsSchema = import_zod3.z.object({
|
|
1138
|
-
redirectUrl: import_zod3.z.string().optional(),
|
|
1139
|
-
data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional()
|
|
1140
|
-
});
|
|
1141
|
-
var CreateConnectedAccountResponseSchema = import_zod3.z.object({
|
|
1142
|
-
id: import_zod3.z.string(),
|
|
1143
|
-
status: ConnectedAccountStatusSchema,
|
|
1144
|
-
redirectUrl: import_zod3.z.string().nullable()
|
|
1145
|
-
});
|
|
1146
|
-
var ConnectedAccountAuthSchemes = {
|
|
1147
|
-
OAUTH2: "OAUTH2",
|
|
1148
|
-
OAUTH1: "OAUTH1",
|
|
1149
|
-
OAUTH1A: "OAUTH1A",
|
|
1150
|
-
API_KEY: "API_KEY",
|
|
1151
|
-
BASIC: "BASIC",
|
|
1152
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1153
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1154
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1155
|
-
NO_AUTH: "NO_AUTH",
|
|
1156
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1157
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1158
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1159
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1160
|
-
};
|
|
1161
|
-
var ConnectedAccountAuthSchemesSchema = import_zod3.z.enum([
|
|
1162
|
-
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1163
|
-
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1164
|
-
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1165
|
-
ConnectedAccountAuthSchemes.API_KEY,
|
|
1166
|
-
ConnectedAccountAuthSchemes.BASIC,
|
|
1167
|
-
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1168
|
-
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1169
|
-
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1170
|
-
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1171
|
-
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1172
|
-
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1173
|
-
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1174
|
-
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1175
|
-
]);
|
|
1176
|
-
var ConnectedAccountAuthConfigSchema = import_zod3.z.object({
|
|
1177
|
-
id: import_zod3.z.string(),
|
|
1178
|
-
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1179
|
-
isComposioManaged: import_zod3.z.boolean(),
|
|
1180
|
-
isDisabled: import_zod3.z.boolean()
|
|
1181
|
-
});
|
|
1182
|
-
var ConnectedAccountRetrieveResponseSchema = import_zod3.z.object({
|
|
1183
|
-
id: import_zod3.z.string(),
|
|
1184
|
-
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1185
|
-
userId: import_zod3.z.string(),
|
|
1186
|
-
data: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
|
|
1187
|
-
params: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
|
|
1188
|
-
status: ConnectedAccountStatusSchema,
|
|
1189
|
-
statusReason: import_zod3.z.string().nullable(),
|
|
1190
|
-
toolkit: import_zod3.z.object({
|
|
1191
|
-
slug: import_zod3.z.string()
|
|
1192
|
-
}),
|
|
1193
|
-
testRequestEndpoint: import_zod3.z.string().optional(),
|
|
1194
|
-
isDisabled: import_zod3.z.boolean(),
|
|
1195
|
-
createdAt: import_zod3.z.string(),
|
|
1196
|
-
updatedAt: import_zod3.z.string()
|
|
1197
|
-
});
|
|
1198
|
-
|
|
1199
|
-
// src/models/ConnectionRequest.ts
|
|
1200
|
-
var import_zod4 = require("zod");
|
|
1201
|
-
var ConnectionRequest = class {
|
|
1736
|
+
// src/models/Session.ts
|
|
1737
|
+
var Session = class {
|
|
1202
1738
|
client;
|
|
1203
|
-
|
|
1204
|
-
connectedAccountStatus;
|
|
1205
|
-
constructor(client, connectedAccountId, connectedAccountStatus) {
|
|
1739
|
+
constructor(client) {
|
|
1206
1740
|
this.client = client;
|
|
1207
|
-
this.connectedAccountId = connectedAccountId;
|
|
1208
|
-
this.connectedAccountStatus = connectedAccountStatus;
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* Transform the response from the Composio API to the SDK format
|
|
1212
|
-
* @param response
|
|
1213
|
-
* @returns
|
|
1214
|
-
*/
|
|
1215
|
-
async transformResponse(response) {
|
|
1216
|
-
try {
|
|
1217
|
-
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1218
|
-
...response,
|
|
1219
|
-
userId: response.user_id,
|
|
1220
|
-
// Add the missing userId property
|
|
1221
|
-
authConfig: {
|
|
1222
|
-
...response.auth_config,
|
|
1223
|
-
authScheme: response.auth_config.auth_scheme,
|
|
1224
|
-
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1225
|
-
isDisabled: response.auth_config.is_disabled
|
|
1226
|
-
},
|
|
1227
|
-
statusReason: response.status_reason,
|
|
1228
|
-
isDisabled: response.is_disabled,
|
|
1229
|
-
createdAt: response.created_at,
|
|
1230
|
-
updatedAt: response.updated_at,
|
|
1231
|
-
testRequestEndpoint: response.test_request_endpoint
|
|
1232
|
-
});
|
|
1233
|
-
return parsedResponse;
|
|
1234
|
-
} catch (error) {
|
|
1235
|
-
logger_default.error("Error transforming response", error);
|
|
1236
|
-
if (error instanceof import_zod4.ZodError) {
|
|
1237
|
-
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1238
|
-
}
|
|
1239
|
-
throw error;
|
|
1240
|
-
}
|
|
1241
1741
|
}
|
|
1242
1742
|
/**
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1246
|
-
* @returns
|
|
1743
|
+
* Get the active session info
|
|
1744
|
+
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
1247
1745
|
*/
|
|
1248
|
-
async
|
|
1249
|
-
|
|
1250
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1251
|
-
return Promise.resolve(this.transformResponse(response));
|
|
1252
|
-
}
|
|
1253
|
-
return new Promise((resolve, reject) => {
|
|
1254
|
-
const interval = setInterval(async () => {
|
|
1255
|
-
try {
|
|
1256
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1257
|
-
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1258
|
-
clearInterval(interval);
|
|
1259
|
-
resolve(this.transformResponse(response));
|
|
1260
|
-
}
|
|
1261
|
-
} catch (error) {
|
|
1262
|
-
clearInterval(interval);
|
|
1263
|
-
reject(error);
|
|
1264
|
-
}
|
|
1265
|
-
}, 1e3);
|
|
1266
|
-
setTimeout(() => {
|
|
1267
|
-
clearInterval(interval);
|
|
1268
|
-
reject(new Error("Connection request timed out"));
|
|
1269
|
-
}, timeout);
|
|
1270
|
-
});
|
|
1746
|
+
async getInfo() {
|
|
1747
|
+
return this.client.auth.session.getInfo();
|
|
1271
1748
|
}
|
|
1272
1749
|
};
|
|
1273
1750
|
|
|
1274
|
-
// src/models/
|
|
1275
|
-
var
|
|
1751
|
+
// src/models/Triggers.ts
|
|
1752
|
+
var Triggers = class {
|
|
1276
1753
|
client;
|
|
1277
1754
|
constructor(client) {
|
|
1278
1755
|
this.client = client;
|
|
1279
1756
|
}
|
|
1280
1757
|
/**
|
|
1281
|
-
*
|
|
1282
|
-
* @
|
|
1283
|
-
* @param {RequestOptions} options - Request options
|
|
1284
|
-
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1758
|
+
* Fetch list of all the active triggers
|
|
1759
|
+
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
1285
1760
|
*/
|
|
1286
|
-
async list(query) {
|
|
1287
|
-
return this.client.
|
|
1761
|
+
async list(query, options) {
|
|
1762
|
+
return this.client.triggerInstances.listActive(query, options);
|
|
1288
1763
|
}
|
|
1289
1764
|
/**
|
|
1290
|
-
* Create a new
|
|
1291
|
-
*
|
|
1292
|
-
* @param {
|
|
1293
|
-
* @
|
|
1765
|
+
* Create a new trigger instance
|
|
1766
|
+
*
|
|
1767
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1768
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1769
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
1294
1770
|
*/
|
|
1295
|
-
async create(
|
|
1296
|
-
return this.client.
|
|
1771
|
+
async create(slug, body, options) {
|
|
1772
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1297
1773
|
}
|
|
1298
1774
|
/**
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1301
|
-
* @param {
|
|
1302
|
-
* @
|
|
1775
|
+
* Update an existing trigger instance
|
|
1776
|
+
*
|
|
1777
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1778
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1779
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1303
1780
|
*/
|
|
1304
|
-
async
|
|
1305
|
-
return this.client.
|
|
1781
|
+
async update(slug, body, options) {
|
|
1782
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1306
1783
|
}
|
|
1307
1784
|
/**
|
|
1308
|
-
* Delete a
|
|
1309
|
-
*
|
|
1310
|
-
* @param {
|
|
1311
|
-
* @returns
|
|
1785
|
+
* Delete a trigger instance
|
|
1786
|
+
*
|
|
1787
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1788
|
+
* @returns
|
|
1312
1789
|
*/
|
|
1313
|
-
async delete(
|
|
1314
|
-
return this.client.
|
|
1790
|
+
async delete(slug) {
|
|
1791
|
+
return this.client.triggerInstances.removeUpsert(slug);
|
|
1315
1792
|
}
|
|
1316
1793
|
/**
|
|
1317
|
-
*
|
|
1318
|
-
*
|
|
1794
|
+
* Update the status of a trigger
|
|
1795
|
+
*
|
|
1796
|
+
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
1797
|
+
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1319
1798
|
* @param {RequestOptions} options - Request options
|
|
1320
|
-
* @returns {Promise<
|
|
1799
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1321
1800
|
*/
|
|
1322
|
-
async
|
|
1323
|
-
return this.client.
|
|
1801
|
+
async updateStatus(status, params, options) {
|
|
1802
|
+
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
1324
1803
|
}
|
|
1325
1804
|
/**
|
|
1326
|
-
*
|
|
1327
|
-
*
|
|
1328
|
-
* @param {
|
|
1329
|
-
* @param {RequestOptions
|
|
1330
|
-
* @returns {Promise<
|
|
1805
|
+
* Disable a trigger instance
|
|
1806
|
+
*
|
|
1807
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1808
|
+
* @param {RequestOptions options - Request options
|
|
1809
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1331
1810
|
*/
|
|
1332
|
-
async
|
|
1333
|
-
return this.client.
|
|
1811
|
+
async disable(slug, options) {
|
|
1812
|
+
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
1334
1813
|
}
|
|
1335
1814
|
/**
|
|
1336
|
-
* Enable a
|
|
1337
|
-
*
|
|
1338
|
-
* @param {
|
|
1339
|
-
* @
|
|
1815
|
+
* Enable a trigger instance
|
|
1816
|
+
*
|
|
1817
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1818
|
+
* @param {RequestOptions options - Request options
|
|
1819
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1340
1820
|
*/
|
|
1341
|
-
async enable(
|
|
1342
|
-
return this.client.
|
|
1821
|
+
async enable(slug, options) {
|
|
1822
|
+
return this.client.triggerInstances.updateStatus("enable", { slug }, options);
|
|
1343
1823
|
}
|
|
1344
1824
|
/**
|
|
1345
|
-
*
|
|
1346
|
-
|
|
1825
|
+
* @TODO Learn about trigger types
|
|
1826
|
+
*/
|
|
1827
|
+
/**
|
|
1828
|
+
* List all the trigger types
|
|
1829
|
+
*
|
|
1830
|
+
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1347
1831
|
* @param {RequestOptions} options - Request options
|
|
1348
|
-
* @returns {Promise<
|
|
1832
|
+
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
1349
1833
|
*/
|
|
1350
|
-
async
|
|
1351
|
-
return this.client.
|
|
1834
|
+
async listTypes(query, options) {
|
|
1835
|
+
return this.client.triggersTypes.list(query, options);
|
|
1352
1836
|
}
|
|
1353
1837
|
/**
|
|
1354
|
-
*
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
1357
|
-
* @param {
|
|
1358
|
-
* @returns {Promise<
|
|
1838
|
+
* Retrieve a trigger type by its slug
|
|
1839
|
+
*
|
|
1840
|
+
* @param {string} slug - The slug of the trigger type
|
|
1841
|
+
* @param {RequestOptions} options - request options
|
|
1842
|
+
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1359
1843
|
*/
|
|
1360
|
-
async
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1844
|
+
async getType(slug, options) {
|
|
1845
|
+
return this.client.triggersTypes.retrieve(slug, options);
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Fetches the list of all the available trigger enums
|
|
1849
|
+
*
|
|
1850
|
+
* This method is used by the CLI where filters are not required.
|
|
1851
|
+
* @param options
|
|
1852
|
+
* @returns
|
|
1853
|
+
*/
|
|
1854
|
+
async listEnum(options) {
|
|
1855
|
+
return this.client.triggersTypes.retrieveEnum(options);
|
|
1856
|
+
}
|
|
1857
|
+
async subscribe(fn, filters = {}) {
|
|
1858
|
+
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
1859
|
+
const session = new Session(this.client);
|
|
1860
|
+
const sessionInfo = await session.getInfo();
|
|
1861
|
+
const clientId = sessionInfo.project?.id;
|
|
1862
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1863
|
+
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
1864
|
+
const shouldSendTrigger = (data) => {
|
|
1865
|
+
if (Object.keys(filters).length === 0) return true;
|
|
1866
|
+
else {
|
|
1867
|
+
return (!filters.appName || data.appName.toLowerCase() === filters.appName.toLowerCase()) && (!filters.triggerId || data.metadata.id.toLowerCase() === filters.triggerId.toLowerCase()) && (!filters.connectionId || data.metadata.connectionId.toLowerCase() === filters.connectionId.toLowerCase()) && (!filters.triggerName || data.metadata.triggerName.toLowerCase() === filters.triggerName.toLowerCase()) && (!filters.entityId || data.metadata.connection.clientUniqueUserId.toLowerCase() === filters.entityId.toLowerCase()) && (!filters.integrationId || data.metadata.connection.integrationId.toLowerCase() === filters.integrationId.toLowerCase());
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
logger_default.debug("Subscribing to triggers", filters);
|
|
1871
|
+
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1872
|
+
if (shouldSendTrigger(data)) {
|
|
1873
|
+
fn(data);
|
|
1369
1874
|
}
|
|
1370
1875
|
});
|
|
1371
|
-
|
|
1876
|
+
}
|
|
1877
|
+
async unsubscribe() {
|
|
1878
|
+
const session = new Session(this.client);
|
|
1879
|
+
const sessionInfo = await session.getInfo();
|
|
1880
|
+
const clientId = sessionInfo.project?.id;
|
|
1881
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1882
|
+
PusherUtils.triggerUnsubscribe(clientId);
|
|
1372
1883
|
}
|
|
1373
1884
|
};
|
|
1374
1885
|
|
|
@@ -1722,8 +2233,8 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1722
2233
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
1723
2234
|
const payload = {
|
|
1724
2235
|
arguments: JSON.parse(tool.function.arguments),
|
|
1725
|
-
connectedAccountId: options
|
|
1726
|
-
customAuthParams: options
|
|
2236
|
+
connectedAccountId: options?.connectedAccountId,
|
|
2237
|
+
customAuthParams: options?.customAuthParams,
|
|
1727
2238
|
userId
|
|
1728
2239
|
};
|
|
1729
2240
|
const result = await this.executeTool(tool.function.name, payload, modifiers);
|
|
@@ -1856,7 +2367,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1856
2367
|
};
|
|
1857
2368
|
|
|
1858
2369
|
// package.json
|
|
1859
|
-
var version = "0.1.
|
|
2370
|
+
var version = "0.1.9-alpha.0";
|
|
1860
2371
|
|
|
1861
2372
|
// src/utils/uuid.ts
|
|
1862
2373
|
var import_uuid = require("uuid");
|
|
@@ -1884,10 +2395,12 @@ var Composio = class {
|
|
|
1884
2395
|
toolkits;
|
|
1885
2396
|
triggers;
|
|
1886
2397
|
toolset;
|
|
2398
|
+
// auth configs
|
|
1887
2399
|
authConfigs;
|
|
2400
|
+
createAuthConfig;
|
|
1888
2401
|
// connected accounts
|
|
1889
2402
|
connectedAccounts;
|
|
1890
|
-
|
|
2403
|
+
initiateConnection;
|
|
1891
2404
|
/**
|
|
1892
2405
|
* @param {Object} config Configuration for the Composio SDK.
|
|
1893
2406
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -1919,10 +2432,9 @@ var Composio = class {
|
|
|
1919
2432
|
this.toolkits = new Toolkits(this.client);
|
|
1920
2433
|
this.triggers = new Triggers(this.client);
|
|
1921
2434
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2435
|
+
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
1922
2436
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
1923
|
-
this.
|
|
1924
|
-
this.connectedAccounts
|
|
1925
|
-
);
|
|
2437
|
+
this.initiateConnection = this.connectedAccounts.initiate.bind(this.connectedAccounts);
|
|
1926
2438
|
if (this.config.allowTracking ?? true) {
|
|
1927
2439
|
this.initializeTelemetry(
|
|
1928
2440
|
{
|
|
@@ -2002,39 +2514,39 @@ var BaseTelemetryTransport = class {
|
|
|
2002
2514
|
};
|
|
2003
2515
|
|
|
2004
2516
|
// src/utils/jsonSchema.ts
|
|
2005
|
-
var
|
|
2517
|
+
var import_zod8 = require("zod");
|
|
2006
2518
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
2007
2519
|
if (!value.type) {
|
|
2008
|
-
return
|
|
2520
|
+
return import_zod8.z.object({});
|
|
2009
2521
|
}
|
|
2010
2522
|
let zodType;
|
|
2011
2523
|
switch (value.type) {
|
|
2012
2524
|
case "string":
|
|
2013
|
-
zodType =
|
|
2525
|
+
zodType = import_zod8.z.string().describe(
|
|
2014
2526
|
(value.description || "") + (value.examples ? `
|
|
2015
2527
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2016
2528
|
);
|
|
2017
2529
|
break;
|
|
2018
2530
|
case "number":
|
|
2019
|
-
zodType =
|
|
2531
|
+
zodType = import_zod8.z.number().describe(
|
|
2020
2532
|
(value.description || "") + (value.examples ? `
|
|
2021
2533
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2022
2534
|
);
|
|
2023
2535
|
break;
|
|
2024
2536
|
case "integer":
|
|
2025
|
-
zodType =
|
|
2537
|
+
zodType = import_zod8.z.number().int().describe(
|
|
2026
2538
|
(value.description || "") + (value.examples ? `
|
|
2027
2539
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2028
2540
|
);
|
|
2029
2541
|
break;
|
|
2030
2542
|
case "boolean":
|
|
2031
|
-
zodType =
|
|
2543
|
+
zodType = import_zod8.z.boolean().describe(
|
|
2032
2544
|
(value.description || "") + (value.examples ? `
|
|
2033
2545
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2034
2546
|
);
|
|
2035
2547
|
break;
|
|
2036
2548
|
case "array":
|
|
2037
|
-
zodType =
|
|
2549
|
+
zodType = import_zod8.z.array(
|
|
2038
2550
|
jsonSchemaPropertiesToTSTypes(
|
|
2039
2551
|
value.items
|
|
2040
2552
|
)
|
|
@@ -2050,7 +2562,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2050
2562
|
);
|
|
2051
2563
|
break;
|
|
2052
2564
|
case "null":
|
|
2053
|
-
zodType =
|
|
2565
|
+
zodType = import_zod8.z.null().describe(value.description || "");
|
|
2054
2566
|
break;
|
|
2055
2567
|
default:
|
|
2056
2568
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
@@ -2061,7 +2573,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2061
2573
|
const properties = jsonSchema.properties;
|
|
2062
2574
|
const requiredFields = jsonSchema.required || [];
|
|
2063
2575
|
if (!properties) {
|
|
2064
|
-
return
|
|
2576
|
+
return import_zod8.z.object({});
|
|
2065
2577
|
}
|
|
2066
2578
|
const zodSchema = {};
|
|
2067
2579
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -2073,7 +2585,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2073
2585
|
schema
|
|
2074
2586
|
)
|
|
2075
2587
|
);
|
|
2076
|
-
zodType =
|
|
2588
|
+
zodType = import_zod8.z.union(anyOfTypes).describe(
|
|
2077
2589
|
(value.description || "") + (value.examples ? `
|
|
2078
2590
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2079
2591
|
);
|
|
@@ -2083,7 +2595,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2083
2595
|
schema
|
|
2084
2596
|
)
|
|
2085
2597
|
);
|
|
2086
|
-
zodType =
|
|
2598
|
+
zodType = import_zod8.z.intersection(
|
|
2087
2599
|
allOfTypes[0],
|
|
2088
2600
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
2089
2601
|
).describe(
|
|
@@ -2107,10 +2619,12 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2107
2619
|
zodSchema[key] = zodType.optional();
|
|
2108
2620
|
}
|
|
2109
2621
|
}
|
|
2110
|
-
return
|
|
2622
|
+
return import_zod8.z.object(zodSchema);
|
|
2111
2623
|
}
|
|
2112
2624
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2113
2625
|
0 && (module.exports = {
|
|
2626
|
+
AuthConfigTypes,
|
|
2627
|
+
AuthSchemeTypes,
|
|
2114
2628
|
BaseAgenticToolset,
|
|
2115
2629
|
BaseNonAgenticToolset,
|
|
2116
2630
|
BaseTelemetryTransport,
|