@composio/core 0.1.12-alpha.7 → 0.1.12-alpha.9
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 +20 -0
- package/dist/index.cjs +557 -177
- package/dist/index.d.cts +936 -160
- package/dist/index.d.ts +936 -160
- package/dist/index.js +557 -177
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -44,7 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
46
|
// src/composio.ts
|
|
47
|
-
var
|
|
47
|
+
var import_client2 = __toESM(require("@composio/client"), 1);
|
|
48
48
|
|
|
49
49
|
// src/types/tool.types.ts
|
|
50
50
|
var import_zod = require("zod");
|
|
@@ -417,8 +417,8 @@ var CustomTools = class {
|
|
|
417
417
|
});
|
|
418
418
|
}
|
|
419
419
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
420
|
-
|
|
421
|
-
|
|
420
|
+
toolkit_slugs: [toolkitSlug],
|
|
421
|
+
user_ids: [metadata.userId]
|
|
422
422
|
});
|
|
423
423
|
if (!connectedAccounts.items.length) {
|
|
424
424
|
throw new ComposioConnectedAccountNotFoundError(
|
|
@@ -485,7 +485,7 @@ var ValidationErrorCodes = {
|
|
|
485
485
|
};
|
|
486
486
|
var ValidationError = class extends ComposioError {
|
|
487
487
|
zodError;
|
|
488
|
-
constructor(zodError, message = "Input validation failed") {
|
|
488
|
+
constructor(zodError, message = "Input validation failed", meta) {
|
|
489
489
|
let zodErrorInstance;
|
|
490
490
|
if (!(zodError instanceof import_zod2.ZodError)) {
|
|
491
491
|
zodErrorInstance = new import_zod2.ZodError([
|
|
@@ -498,20 +498,16 @@ var ValidationError = class extends ComposioError {
|
|
|
498
498
|
} else {
|
|
499
499
|
zodErrorInstance = zodError;
|
|
500
500
|
}
|
|
501
|
+
const issues = zodErrorInstance.issues.map(
|
|
502
|
+
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
503
|
+
);
|
|
501
504
|
super(message, {
|
|
502
505
|
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
503
|
-
meta
|
|
504
|
-
|
|
505
|
-
zodErrorInstance.issues.map((issue) => ({
|
|
506
|
-
path: issue.path.join("."),
|
|
507
|
-
message: issue.message,
|
|
508
|
-
code: issue.code
|
|
509
|
-
}))
|
|
510
|
-
)
|
|
511
|
-
},
|
|
512
|
-
cause: zodErrorInstance
|
|
506
|
+
meta,
|
|
507
|
+
cause: issues.join("\n")
|
|
513
508
|
});
|
|
514
509
|
this.zodError = zodErrorInstance;
|
|
510
|
+
this.name = "ValidationError";
|
|
515
511
|
}
|
|
516
512
|
};
|
|
517
513
|
|
|
@@ -536,9 +532,15 @@ var Tools = class {
|
|
|
536
532
|
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
537
533
|
}
|
|
538
534
|
/**
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
535
|
+
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
536
|
+
*
|
|
537
|
+
* This method standardizes the property naming convention for tools retrieved from the Composio API,
|
|
538
|
+
* making them more consistent with JavaScript/TypeScript conventions.
|
|
539
|
+
*
|
|
540
|
+
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
541
|
+
* @returns {Tool} The transformed tool with camelCase properties
|
|
542
|
+
*
|
|
543
|
+
* @private
|
|
542
544
|
*/
|
|
543
545
|
transformToolCases(tool) {
|
|
544
546
|
return ToolSchema.parse({
|
|
@@ -548,9 +550,15 @@ var Tools = class {
|
|
|
548
550
|
});
|
|
549
551
|
}
|
|
550
552
|
/**
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
553
|
+
* Transforms tool execution response from snake_case API format to camelCase.
|
|
554
|
+
*
|
|
555
|
+
* This method converts the response received from the Composio API to a standardized format
|
|
556
|
+
* with consistent property naming that follows JavaScript/TypeScript conventions.
|
|
557
|
+
*
|
|
558
|
+
* @param {ComposioToolExecuteResponse} response - The raw API response to transform
|
|
559
|
+
* @returns {ToolExecuteResponse} The transformed response with camelCase properties
|
|
560
|
+
*
|
|
561
|
+
* @private
|
|
554
562
|
*/
|
|
555
563
|
transformToolExecuteResponse(response) {
|
|
556
564
|
return ToolExecuteResponseSchema.parse({
|
|
@@ -635,9 +643,35 @@ var Tools = class {
|
|
|
635
643
|
return null;
|
|
636
644
|
}
|
|
637
645
|
/**
|
|
638
|
-
* Lists all tools available in the Composio SDK
|
|
639
|
-
*
|
|
640
|
-
*
|
|
646
|
+
* Lists all tools available in the Composio SDK including custom tools.
|
|
647
|
+
*
|
|
648
|
+
* This method fetches tools from the Composio API in raw format and combines them with
|
|
649
|
+
* any registered custom tools. The response can be filtered and modified as needed.
|
|
650
|
+
*
|
|
651
|
+
* @param {string} userId - The user ID for whom to fetch the tools
|
|
652
|
+
* @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
|
|
653
|
+
* @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
|
|
654
|
+
* @returns {Promise<ToolList>} List of tools matching the query criteria
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* // Get all tools
|
|
659
|
+
* const tools = await composio.tools.getRawComposioTools('default');
|
|
660
|
+
*
|
|
661
|
+
* // Get tools with filters
|
|
662
|
+
* const githubTools = await composio.tools.getRawComposioTools('default', {
|
|
663
|
+
* toolkits: ['github'],
|
|
664
|
+
* important: true
|
|
665
|
+
* });
|
|
666
|
+
*
|
|
667
|
+
* // Get tools with schema transformation
|
|
668
|
+
* const tools = await composio.tools.getRawComposioTools('default', {},
|
|
669
|
+
* (toolSlug, toolkitSlug, tool) => {
|
|
670
|
+
* // Add custom properties to tool schema
|
|
671
|
+
* return {...tool, customProperty: 'value'};
|
|
672
|
+
* }
|
|
673
|
+
* );
|
|
674
|
+
* ```
|
|
641
675
|
*/
|
|
642
676
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
643
677
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
@@ -704,11 +738,13 @@ var Tools = class {
|
|
|
704
738
|
return modifiedToool;
|
|
705
739
|
}
|
|
706
740
|
/**
|
|
707
|
-
* Get a tool
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
* @param
|
|
711
|
-
* @
|
|
741
|
+
* Get a tool or list of tools based on the provided arguments.
|
|
742
|
+
* This is an implementation method that handles both overloads.
|
|
743
|
+
*
|
|
744
|
+
* @param {string} userId - The user id to get the tool(s) for
|
|
745
|
+
* @param {ToolListParams | string} arg2 - Either a slug string or filters object
|
|
746
|
+
* @param {ProviderOptions<TProvider>} [options] - Optional provider options
|
|
747
|
+
* @returns {Promise<TToolCollection>} The tool collection
|
|
712
748
|
*/
|
|
713
749
|
async get(userId, arg2, options) {
|
|
714
750
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
@@ -818,13 +854,43 @@ var Tools = class {
|
|
|
818
854
|
return result;
|
|
819
855
|
}
|
|
820
856
|
/**
|
|
821
|
-
*
|
|
857
|
+
* Executes a given tool with the provided parameters.
|
|
822
858
|
*
|
|
823
|
-
* This method calls the Composio API to execute the tool and returns the response.
|
|
859
|
+
* This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
|
|
860
|
+
* It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
|
|
824
861
|
*
|
|
825
|
-
* @param {string} slug - The ID of the tool to be executed
|
|
862
|
+
* @param {string} slug - The slug/ID of the tool to be executed
|
|
826
863
|
* @param {ToolExecuteParams} body - The parameters to be passed to the tool
|
|
864
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
|
|
827
865
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
866
|
+
*
|
|
867
|
+
* @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
|
|
868
|
+
* @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
|
|
869
|
+
* @throws {ComposioToolExecutionError} If there is an error during tool execution
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
* ```typescript
|
|
873
|
+
* // Execute a Composio API tool
|
|
874
|
+
* const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
|
|
875
|
+
* userId: 'default',
|
|
876
|
+
* arguments: { userId: 'pg' }
|
|
877
|
+
* });
|
|
878
|
+
*
|
|
879
|
+
* // Execute with modifiers
|
|
880
|
+
* const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
|
|
881
|
+
* userId: 'default',
|
|
882
|
+
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
883
|
+
* }, {
|
|
884
|
+
* beforeToolExecute: (toolSlug, toolkitSlug, params) => {
|
|
885
|
+
* // Modify params before execution
|
|
886
|
+
* return params;
|
|
887
|
+
* },
|
|
888
|
+
* afterToolExecute: (toolSlug, toolkitSlug, result) => {
|
|
889
|
+
* // Transform result after execution
|
|
890
|
+
* return result;
|
|
891
|
+
* }
|
|
892
|
+
* });
|
|
893
|
+
* ```
|
|
828
894
|
*/
|
|
829
895
|
async execute(slug, body, modifiers) {
|
|
830
896
|
if (!this.customTools) {
|
|
@@ -881,9 +947,39 @@ var Tools = class {
|
|
|
881
947
|
return this.client.tools.proxy(body);
|
|
882
948
|
}
|
|
883
949
|
/**
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
950
|
+
* Creates a custom tool that can be used within the Composio SDK.
|
|
951
|
+
*
|
|
952
|
+
* Custom tools allow you to extend the functionality of Composio with your own implementations
|
|
953
|
+
* while keeping a consistent interface for both built-in and custom tools.
|
|
954
|
+
*
|
|
955
|
+
* @param {CustomToolOptions} body - The configuration for the custom tool
|
|
956
|
+
* @returns {Promise<Tool>} The created custom tool
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```typescript
|
|
960
|
+
* const customTool = await composio.tools.createCustomTool({
|
|
961
|
+
* name: 'My Custom Tool',
|
|
962
|
+
* description: 'A custom tool that does something specific',
|
|
963
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
964
|
+
* inputParameters: {
|
|
965
|
+
* param1: {
|
|
966
|
+
* type: 'string',
|
|
967
|
+
* description: 'First parameter',
|
|
968
|
+
* required: true
|
|
969
|
+
* }
|
|
970
|
+
* },
|
|
971
|
+
* outputParameters: {
|
|
972
|
+
* result: {
|
|
973
|
+
* type: 'string',
|
|
974
|
+
* description: 'The result of the operation'
|
|
975
|
+
* }
|
|
976
|
+
* },
|
|
977
|
+
* handler: async (params, context) => {
|
|
978
|
+
* // Custom logic here
|
|
979
|
+
* return { data: { result: 'Success!' } };
|
|
980
|
+
* }
|
|
981
|
+
* });
|
|
982
|
+
* ```
|
|
887
983
|
*/
|
|
888
984
|
async createCustomTool(body) {
|
|
889
985
|
return this.customTools.createTool(body);
|
|
@@ -1041,7 +1137,7 @@ var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
|
1041
1137
|
status: import_zod4.z.enum(["ENABLED", "DISABLED"]),
|
|
1042
1138
|
uuid: import_zod4.z.string(),
|
|
1043
1139
|
authScheme: AuthSchemeEnum.optional(),
|
|
1044
|
-
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.
|
|
1140
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
|
|
1045
1141
|
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1046
1142
|
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1047
1143
|
createdBy: import_zod4.z.string().optional(),
|
|
@@ -1088,6 +1184,18 @@ var AuthConfigs = class {
|
|
|
1088
1184
|
getClient() {
|
|
1089
1185
|
return this.client;
|
|
1090
1186
|
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Transforms an auth config response from API format to SDK format.
|
|
1189
|
+
*
|
|
1190
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1191
|
+
* the data structure to match the SDK's standardized format for auth configurations.
|
|
1192
|
+
*
|
|
1193
|
+
* @param {ComposioAuthConfigRetrieveResponse} authConfig - The raw API response to transform
|
|
1194
|
+
* @returns {AuthConfigRetrieveResponse} The transformed auth config data
|
|
1195
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
1196
|
+
*
|
|
1197
|
+
* @private
|
|
1198
|
+
*/
|
|
1091
1199
|
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1092
1200
|
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1093
1201
|
id: authConfig.id,
|
|
@@ -1113,10 +1221,30 @@ var AuthConfigs = class {
|
|
|
1113
1221
|
return result.data;
|
|
1114
1222
|
}
|
|
1115
1223
|
/**
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1224
|
+
* Lists authentication configurations based on provided filter criteria.
|
|
1225
|
+
*
|
|
1226
|
+
* This method retrieves auth configs from the Composio API, transforms them to the SDK format,
|
|
1227
|
+
* and supports filtering by various parameters.
|
|
1228
|
+
*
|
|
1229
|
+
* @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
|
|
1230
|
+
* @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
|
|
1231
|
+
* @throws {ValidationError} If the query parameters or response fail validation
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```typescript
|
|
1235
|
+
* // List all auth configs
|
|
1236
|
+
* const allConfigs = await composio.authConfigs.list();
|
|
1237
|
+
*
|
|
1238
|
+
* // List auth configs for a specific toolkit
|
|
1239
|
+
* const githubConfigs = await composio.authConfigs.list({
|
|
1240
|
+
* toolkitSlug: 'github'
|
|
1241
|
+
* });
|
|
1242
|
+
*
|
|
1243
|
+
* // List Composio-managed auth configs
|
|
1244
|
+
* const managedConfigs = await composio.authConfigs.list({
|
|
1245
|
+
* isComposioManaged: true
|
|
1246
|
+
* });
|
|
1247
|
+
* ```
|
|
1120
1248
|
*/
|
|
1121
1249
|
async list(query) {
|
|
1122
1250
|
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
@@ -1177,21 +1305,57 @@ var AuthConfigs = class {
|
|
|
1177
1305
|
return parsedResult.data;
|
|
1178
1306
|
}
|
|
1179
1307
|
/**
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1308
|
+
* Retrieves a specific authentication configuration by its ID.
|
|
1309
|
+
*
|
|
1310
|
+
* This method fetches detailed information about a single auth config
|
|
1311
|
+
* and transforms the response to the SDK's standardized format.
|
|
1312
|
+
*
|
|
1313
|
+
* @param {string} nanoid - The unique identifier of the auth config to retrieve
|
|
1314
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
|
|
1315
|
+
* @throws {Error} If the auth config cannot be found or an API error occurs
|
|
1316
|
+
* @throws {ValidationError} If the response fails validation
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1319
|
+
* ```typescript
|
|
1320
|
+
* // Get an auth config by ID
|
|
1321
|
+
* const authConfig = await composio.authConfigs.get('auth_abc123');
|
|
1322
|
+
* console.log(authConfig.name); // e.g., 'GitHub Auth'
|
|
1323
|
+
* console.log(authConfig.toolkit.slug); // e.g., 'github'
|
|
1324
|
+
* ```
|
|
1184
1325
|
*/
|
|
1185
1326
|
async get(nanoid) {
|
|
1186
1327
|
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1187
1328
|
return this.parseAuthConfigRetrieveResponse(result);
|
|
1188
1329
|
}
|
|
1189
1330
|
/**
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
*
|
|
1331
|
+
* Updates an existing authentication configuration.
|
|
1332
|
+
*
|
|
1333
|
+
* This method allows you to modify properties of an auth config such as credentials,
|
|
1334
|
+
* scopes, or tool restrictions. The update type (custom or default) determines which
|
|
1335
|
+
* fields can be updated.
|
|
1336
|
+
*
|
|
1337
|
+
* @param {string} nanoid - The unique identifier of the auth config to update
|
|
1338
|
+
* @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
|
|
1339
|
+
* @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
|
|
1340
|
+
* @throws {ValidationError} If the update parameters are invalid
|
|
1341
|
+
* @throws {Error} If the auth config cannot be found or updated
|
|
1342
|
+
*
|
|
1343
|
+
* @example
|
|
1344
|
+
* ```typescript
|
|
1345
|
+
* // Update a custom auth config with new credentials
|
|
1346
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
1347
|
+
* type: 'custom',
|
|
1348
|
+
* credentials: {
|
|
1349
|
+
* apiKey: 'new-api-key-value'
|
|
1350
|
+
* }
|
|
1351
|
+
* });
|
|
1352
|
+
*
|
|
1353
|
+
* // Update a default auth config with new scopes
|
|
1354
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
1355
|
+
* type: 'default',
|
|
1356
|
+
* scopes: ['read:user', 'repo']
|
|
1357
|
+
* });
|
|
1358
|
+
* ```
|
|
1195
1359
|
*/
|
|
1196
1360
|
async update(nanoid, data) {
|
|
1197
1361
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
@@ -1212,38 +1376,85 @@ var AuthConfigs = class {
|
|
|
1212
1376
|
);
|
|
1213
1377
|
}
|
|
1214
1378
|
/**
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1218
|
-
*
|
|
1379
|
+
* Deletes an authentication configuration.
|
|
1380
|
+
*
|
|
1381
|
+
* This method permanently removes an auth config from the Composio platform.
|
|
1382
|
+
* This action cannot be undone and will prevent any connected accounts that use
|
|
1383
|
+
* this auth config from functioning.
|
|
1384
|
+
*
|
|
1385
|
+
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
1386
|
+
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
1387
|
+
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
1388
|
+
*
|
|
1389
|
+
* @example
|
|
1390
|
+
* ```typescript
|
|
1391
|
+
* // Delete an auth config
|
|
1392
|
+
* await composio.authConfigs.delete('auth_abc123');
|
|
1393
|
+
* ```
|
|
1219
1394
|
*/
|
|
1220
1395
|
async delete(nanoid) {
|
|
1221
1396
|
return this.client.authConfigs.delete(nanoid);
|
|
1222
1397
|
}
|
|
1223
1398
|
/**
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1399
|
+
* Updates the status of an authentication configuration.
|
|
1400
|
+
*
|
|
1401
|
+
* This method allows you to enable or disable an auth config. When disabled,
|
|
1402
|
+
* the auth config cannot be used to create new connected accounts or authenticate
|
|
1403
|
+
* with third-party services.
|
|
1404
|
+
*
|
|
1405
|
+
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
1406
|
+
* @param {string} nanoid - The unique identifier of the auth config
|
|
1407
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1408
|
+
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
1409
|
+
*
|
|
1410
|
+
* @example
|
|
1411
|
+
* ```typescript
|
|
1412
|
+
* // Disable an auth config
|
|
1413
|
+
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
1414
|
+
*
|
|
1415
|
+
* // Enable an auth config
|
|
1416
|
+
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
1417
|
+
* ```
|
|
1229
1418
|
*/
|
|
1230
1419
|
async updateStatus(status, nanoid) {
|
|
1231
1420
|
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1232
1421
|
}
|
|
1233
1422
|
/**
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1423
|
+
* Enables an authentication configuration.
|
|
1424
|
+
*
|
|
1425
|
+
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
1426
|
+
* When enabled, the auth config can be used to create new connected accounts
|
|
1427
|
+
* and authenticate with third-party services.
|
|
1428
|
+
*
|
|
1429
|
+
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
1430
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1431
|
+
* @throws {Error} If the auth config cannot be found or enabled
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```typescript
|
|
1435
|
+
* // Enable an auth config
|
|
1436
|
+
* await composio.authConfigs.enable('auth_abc123');
|
|
1437
|
+
* ```
|
|
1238
1438
|
*/
|
|
1239
1439
|
async enable(nanoid) {
|
|
1240
1440
|
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1241
1441
|
}
|
|
1242
1442
|
/**
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
*
|
|
1246
|
-
*
|
|
1443
|
+
* Disables an authentication configuration.
|
|
1444
|
+
*
|
|
1445
|
+
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
1446
|
+
* When disabled, the auth config cannot be used to create new connected accounts
|
|
1447
|
+
* or authenticate with third-party services, but existing connections may continue to work.
|
|
1448
|
+
*
|
|
1449
|
+
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
1450
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1451
|
+
* @throws {Error} If the auth config cannot be found or disabled
|
|
1452
|
+
*
|
|
1453
|
+
* @example
|
|
1454
|
+
* ```typescript
|
|
1455
|
+
* // Disable an auth config
|
|
1456
|
+
* await composio.authConfigs.disable('auth_abc123');
|
|
1457
|
+
* ```
|
|
1247
1458
|
*/
|
|
1248
1459
|
async disable(nanoid) {
|
|
1249
1460
|
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
@@ -1293,7 +1504,7 @@ var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
|
1293
1504
|
}),
|
|
1294
1505
|
connection: import_zod5.z.object({
|
|
1295
1506
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1296
|
-
|
|
1507
|
+
callbackUrl: import_zod5.z.string().optional(),
|
|
1297
1508
|
userId: import_zod5.z.string().optional()
|
|
1298
1509
|
})
|
|
1299
1510
|
});
|
|
@@ -1303,12 +1514,12 @@ var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
|
1303
1514
|
}),
|
|
1304
1515
|
connection: import_zod5.z.object({
|
|
1305
1516
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1306
|
-
|
|
1517
|
+
callback_url: import_zod5.z.string().optional(),
|
|
1307
1518
|
user_id: import_zod5.z.string().optional()
|
|
1308
1519
|
})
|
|
1309
1520
|
});
|
|
1310
1521
|
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1311
|
-
|
|
1522
|
+
callbackUrl: import_zod5.z.string().optional(),
|
|
1312
1523
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1313
1524
|
});
|
|
1314
1525
|
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
@@ -1357,7 +1568,7 @@ var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
|
1357
1568
|
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1358
1569
|
userId: import_zod5.z.string(),
|
|
1359
1570
|
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1360
|
-
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1571
|
+
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1361
1572
|
status: ConnectedAccountStatusSchema,
|
|
1362
1573
|
statusReason: import_zod5.z.string().nullable(),
|
|
1363
1574
|
toolkit: import_zod5.z.object({
|
|
@@ -1368,8 +1579,24 @@ var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
|
1368
1579
|
createdAt: import_zod5.z.string(),
|
|
1369
1580
|
updatedAt: import_zod5.z.string()
|
|
1370
1581
|
});
|
|
1582
|
+
var ConnectedAccountListParamsSchema = import_zod5.z.object({
|
|
1583
|
+
authConfigIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
1584
|
+
cursor: import_zod5.z.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
1585
|
+
labels: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
1586
|
+
limit: import_zod5.z.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
1587
|
+
orderBy: import_zod5.z.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
1588
|
+
statuses: import_zod5.z.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
1589
|
+
toolkitSlugs: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
1590
|
+
userIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
1591
|
+
});
|
|
1592
|
+
var ConnectedAccountListResponseSchema = import_zod5.z.object({
|
|
1593
|
+
items: import_zod5.z.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
1594
|
+
nextCursor: import_zod5.z.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
1595
|
+
totalPages: import_zod5.z.number().describe("The total number of pages of connected accounts")
|
|
1596
|
+
});
|
|
1371
1597
|
|
|
1372
1598
|
// src/models/ConnectionRequest.ts
|
|
1599
|
+
var import_client = __toESM(require("@composio/client"), 1);
|
|
1373
1600
|
var import_zod6 = require("zod");
|
|
1374
1601
|
|
|
1375
1602
|
// src/errors/ConnectionRequestError.ts
|
|
@@ -1402,16 +1629,23 @@ var ConnectionRequest = class {
|
|
|
1402
1629
|
id;
|
|
1403
1630
|
status;
|
|
1404
1631
|
redirectUrl;
|
|
1405
|
-
constructor(client, connectedAccountId,
|
|
1632
|
+
constructor(client, connectedAccountId, status, redirectUrl) {
|
|
1406
1633
|
this.client = client;
|
|
1407
1634
|
this.id = connectedAccountId;
|
|
1408
|
-
this.status =
|
|
1635
|
+
this.status = status || ConnectedAccountStatuses.INITIATED;
|
|
1409
1636
|
this.redirectUrl = redirectUrl;
|
|
1410
1637
|
}
|
|
1411
1638
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1639
|
+
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
1640
|
+
*
|
|
1641
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1642
|
+
* the data structure to match the SDK's standardized format.
|
|
1643
|
+
*
|
|
1644
|
+
* @param {OriginalConnectedAccountResponse} response - The raw API response to transform
|
|
1645
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The transformed response
|
|
1646
|
+
* @throws {ZodError} If the response fails validation against the expected schema
|
|
1647
|
+
*
|
|
1648
|
+
* @private
|
|
1415
1649
|
*/
|
|
1416
1650
|
async transformResponse(response) {
|
|
1417
1651
|
try {
|
|
@@ -1441,15 +1675,49 @@ var ConnectionRequest = class {
|
|
|
1441
1675
|
}
|
|
1442
1676
|
}
|
|
1443
1677
|
/**
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1447
|
-
*
|
|
1678
|
+
* Waits for the connection request to complete and become active.
|
|
1679
|
+
*
|
|
1680
|
+
* This method continuously polls the Composio API to check the status of the connection request
|
|
1681
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
1682
|
+
*
|
|
1683
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
|
|
1684
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
|
|
1685
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
1686
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
1687
|
+
* @throws {ConnectionRequestTimeoutError} If the connection request does not complete within the timeout period
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```typescript
|
|
1691
|
+
* // Wait for connection with default timeout (60 seconds)
|
|
1692
|
+
* try {
|
|
1693
|
+
* const connection = await connectionRequest.waitForConnection();
|
|
1694
|
+
* console.log('Connection established:', connection.id);
|
|
1695
|
+
* } catch (error) {
|
|
1696
|
+
* console.error('Connection failed:', error.message);
|
|
1697
|
+
* }
|
|
1698
|
+
*
|
|
1699
|
+
* // Wait for connection with custom timeout (2 minutes)
|
|
1700
|
+
* const connection = await connectionRequest.waitForConnection(120000);
|
|
1701
|
+
* ```
|
|
1448
1702
|
*/
|
|
1449
1703
|
async waitForConnection(timeout = 6e4) {
|
|
1450
|
-
|
|
1704
|
+
try {
|
|
1451
1705
|
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
1452
|
-
|
|
1706
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1707
|
+
this.status = ConnectedAccountStatuses.ACTIVE;
|
|
1708
|
+
return this.transformResponse(response);
|
|
1709
|
+
}
|
|
1710
|
+
} catch (error) {
|
|
1711
|
+
if (error instanceof import_client.default.NotFoundError) {
|
|
1712
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
1713
|
+
`Connected account with id ${this.id} not found`,
|
|
1714
|
+
{
|
|
1715
|
+
connectedAccountId: this.id
|
|
1716
|
+
}
|
|
1717
|
+
);
|
|
1718
|
+
} else {
|
|
1719
|
+
throw error;
|
|
1720
|
+
}
|
|
1453
1721
|
}
|
|
1454
1722
|
const terminalErrorStates = [
|
|
1455
1723
|
ConnectedAccountStatuses.FAILED,
|
|
@@ -1461,6 +1729,7 @@ var ConnectionRequest = class {
|
|
|
1461
1729
|
while (Date.now() - start < timeout) {
|
|
1462
1730
|
try {
|
|
1463
1731
|
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
1732
|
+
this.status = response.status;
|
|
1464
1733
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1465
1734
|
return this.transformResponse(response);
|
|
1466
1735
|
}
|
|
@@ -1483,17 +1752,6 @@ var ConnectionRequest = class {
|
|
|
1483
1752
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1484
1753
|
}
|
|
1485
1754
|
};
|
|
1486
|
-
var connectionRequest = (client) => {
|
|
1487
|
-
return {
|
|
1488
|
-
waitForConnection: async (connectedAccountId, timeout = 6e4) => {
|
|
1489
|
-
return new ConnectionRequest(
|
|
1490
|
-
client,
|
|
1491
|
-
connectedAccountId,
|
|
1492
|
-
ConnectedAccountStatuses.INITIATED
|
|
1493
|
-
).waitForConnection(timeout);
|
|
1494
|
-
}
|
|
1495
|
-
};
|
|
1496
|
-
};
|
|
1497
1755
|
|
|
1498
1756
|
// src/models/ConnectedAccounts.ts
|
|
1499
1757
|
var ConnectedAccounts = class {
|
|
@@ -1501,14 +1759,95 @@ var ConnectedAccounts = class {
|
|
|
1501
1759
|
constructor(client) {
|
|
1502
1760
|
this.client = client;
|
|
1503
1761
|
}
|
|
1762
|
+
transformConnectedAccountRetrieveResponse(response) {
|
|
1763
|
+
const result = ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
1764
|
+
...response,
|
|
1765
|
+
userId: response.user_id,
|
|
1766
|
+
// Add the missing userId property
|
|
1767
|
+
authConfig: {
|
|
1768
|
+
...response.auth_config,
|
|
1769
|
+
authScheme: response.auth_config.auth_scheme,
|
|
1770
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1771
|
+
isDisabled: response.auth_config.is_disabled
|
|
1772
|
+
},
|
|
1773
|
+
statusReason: response.status_reason,
|
|
1774
|
+
isDisabled: response.is_disabled,
|
|
1775
|
+
createdAt: response.created_at,
|
|
1776
|
+
updatedAt: response.updated_at,
|
|
1777
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
1778
|
+
});
|
|
1779
|
+
if (!result.success) {
|
|
1780
|
+
throw new ValidationError(result.error);
|
|
1781
|
+
}
|
|
1782
|
+
return result.data;
|
|
1783
|
+
}
|
|
1504
1784
|
/**
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1785
|
+
* Lists all connected accounts based on provided filter criteria.
|
|
1786
|
+
*
|
|
1787
|
+
* This method retrieves connected accounts from the Composio API with optional filtering.
|
|
1788
|
+
*
|
|
1789
|
+
* @param {ConnectedAccountListParams} [query] - Optional query parameters for filtering connected accounts
|
|
1790
|
+
* @returns {Promise<ConnectedAccountListResponse>} A paginated list of connected accounts
|
|
1791
|
+
* @throws {ValidationError} If the query fails validation against the expected schema
|
|
1792
|
+
* @example
|
|
1793
|
+
* ```typescript
|
|
1794
|
+
* // List all connected accounts
|
|
1795
|
+
* const allAccounts = await composio.connectedAccounts.list();
|
|
1796
|
+
*
|
|
1797
|
+
* // List accounts for a specific user
|
|
1798
|
+
* const userAccounts = await composio.connectedAccounts.list({
|
|
1799
|
+
* userIds: ['user123']
|
|
1800
|
+
* });
|
|
1801
|
+
*
|
|
1802
|
+
* // List accounts for a specific toolkit
|
|
1803
|
+
* const githubAccounts = await composio.connectedAccounts.list({
|
|
1804
|
+
* toolkitSlugs: ['github']
|
|
1805
|
+
* });
|
|
1806
|
+
* ```
|
|
1509
1807
|
*/
|
|
1510
1808
|
async list(query) {
|
|
1511
|
-
|
|
1809
|
+
let rawQuery = void 0;
|
|
1810
|
+
if (query) {
|
|
1811
|
+
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
1812
|
+
if (!parsedQuery.success) {
|
|
1813
|
+
throw new ValidationError(parsedQuery.error);
|
|
1814
|
+
}
|
|
1815
|
+
rawQuery = {
|
|
1816
|
+
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
1817
|
+
cursor: parsedQuery.data.cursor,
|
|
1818
|
+
labels: parsedQuery.data.labels,
|
|
1819
|
+
limit: parsedQuery.data.limit,
|
|
1820
|
+
order_by: parsedQuery.data.orderBy,
|
|
1821
|
+
statuses: parsedQuery.data.statuses,
|
|
1822
|
+
toolkit_slugs: parsedQuery.data.toolkitSlugs,
|
|
1823
|
+
user_ids: parsedQuery.data.userIds
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
const result = await this.client.connectedAccounts.list(rawQuery);
|
|
1827
|
+
const parsedResponse = ConnectedAccountListResponseSchema.safeParse({
|
|
1828
|
+
items: result.items.map(this.transformConnectedAccountRetrieveResponse),
|
|
1829
|
+
nextCursor: result.next_cursor,
|
|
1830
|
+
totalPages: result.total_pages
|
|
1831
|
+
});
|
|
1832
|
+
if (!parsedResponse.success) {
|
|
1833
|
+
throw new ValidationError(parsedResponse.error);
|
|
1834
|
+
}
|
|
1835
|
+
return parsedResponse.data;
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Transforms connected account data from API format to SDK format.
|
|
1839
|
+
*
|
|
1840
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1841
|
+
* the data structure to match the SDK's standardized format for connected accounts.
|
|
1842
|
+
*
|
|
1843
|
+
* @param {ConnectedAccountRetrieveResponseRaw} response - The raw API response to transform
|
|
1844
|
+
* @returns {ConnectedAccountRetrieveResponse} The transformed connected account data
|
|
1845
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
1846
|
+
*
|
|
1847
|
+
* @private
|
|
1848
|
+
*/
|
|
1849
|
+
transformConnectedAccountResponse(response) {
|
|
1850
|
+
return this.transformConnectedAccountRetrieveResponse(response);
|
|
1512
1851
|
}
|
|
1513
1852
|
/**
|
|
1514
1853
|
* Compound function to create a new connected account.
|
|
@@ -1535,75 +1874,94 @@ var ConnectedAccounts = class {
|
|
|
1535
1874
|
},
|
|
1536
1875
|
connection: {
|
|
1537
1876
|
data: options?.data,
|
|
1538
|
-
|
|
1877
|
+
callback_url: options?.callbackUrl,
|
|
1539
1878
|
user_id: userId
|
|
1540
1879
|
}
|
|
1541
1880
|
});
|
|
1542
|
-
return new ConnectionRequest(this.client, response.id, response.status, response.
|
|
1881
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_url);
|
|
1543
1882
|
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Waits for a connection request to complete and become active.
|
|
1885
|
+
*
|
|
1886
|
+
* This method continuously polls the Composio API to check the status of a connection
|
|
1887
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
1888
|
+
*
|
|
1889
|
+
* @param {string} connectedAccountId - The ID of the connected account to wait for
|
|
1890
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
|
|
1891
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The finalized connected account data
|
|
1892
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
1893
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
1894
|
+
* @throws {ConnectionRequestTimeoutError} If the connection does not complete within the timeout period
|
|
1895
|
+
*
|
|
1896
|
+
* @example
|
|
1897
|
+
* ```typescript
|
|
1898
|
+
* // Wait for a connection to complete with default timeout
|
|
1899
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
|
|
1900
|
+
*
|
|
1901
|
+
* // Wait with a custom timeout of 2 minutes
|
|
1902
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
|
|
1903
|
+
* ```
|
|
1904
|
+
*/
|
|
1544
1905
|
async waitForConnection(connectedAccountId, timeout = 6e4) {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
connectedAccount = await this.get(connectedAccountId);
|
|
1548
|
-
} catch (error) {
|
|
1549
|
-
logger_default.error(error);
|
|
1550
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
1551
|
-
`Unable to retrieve connected account with Id: ${connectedAccountId}`,
|
|
1552
|
-
{
|
|
1553
|
-
connectedAccountId
|
|
1554
|
-
}
|
|
1555
|
-
);
|
|
1556
|
-
}
|
|
1557
|
-
const connectionRequest2 = new ConnectionRequest(
|
|
1558
|
-
this.client,
|
|
1559
|
-
connectedAccountId,
|
|
1560
|
-
connectedAccount.status
|
|
1561
|
-
);
|
|
1562
|
-
return connectionRequest2.waitForConnection(timeout);
|
|
1906
|
+
const connectionRequest = new ConnectionRequest(this.client, connectedAccountId);
|
|
1907
|
+
return connectionRequest.waitForConnection(timeout);
|
|
1563
1908
|
}
|
|
1564
1909
|
/**
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
1910
|
+
* Retrieves a specific connected account by its ID.
|
|
1911
|
+
*
|
|
1912
|
+
* This method fetches detailed information about a single connected account
|
|
1913
|
+
* and transforms the response to the SDK's standardized format.
|
|
1914
|
+
*
|
|
1915
|
+
* @param {string} nanoid - The unique identifier of the connected account
|
|
1916
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The connected account details
|
|
1917
|
+
* @throws {Error} If the connected account cannot be found or an API error occurs
|
|
1918
|
+
*
|
|
1919
|
+
* @example
|
|
1920
|
+
* ```typescript
|
|
1921
|
+
* // Get a connected account by ID
|
|
1922
|
+
* const account = await composio.connectedAccounts.get('conn_abc123');
|
|
1923
|
+
* console.log(account.status); // e.g., 'ACTIVE'
|
|
1924
|
+
* console.log(account.toolkit.slug); // e.g., 'github'
|
|
1925
|
+
* ```
|
|
1569
1926
|
*/
|
|
1570
1927
|
async get(nanoid) {
|
|
1571
1928
|
const response = await this.client.connectedAccounts.retrieve(nanoid);
|
|
1572
|
-
|
|
1573
|
-
...response,
|
|
1574
|
-
userId: response.user_id,
|
|
1575
|
-
// Add the missing userId property
|
|
1576
|
-
authConfig: {
|
|
1577
|
-
...response.auth_config,
|
|
1578
|
-
authScheme: response.auth_config.auth_scheme,
|
|
1579
|
-
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1580
|
-
isDisabled: response.auth_config.is_disabled
|
|
1581
|
-
},
|
|
1582
|
-
statusReason: response.status_reason,
|
|
1583
|
-
isDisabled: response.is_disabled,
|
|
1584
|
-
createdAt: response.created_at,
|
|
1585
|
-
updatedAt: response.updated_at,
|
|
1586
|
-
testRequestEndpoint: response.test_request_endpoint
|
|
1587
|
-
});
|
|
1588
|
-
if (parsedResult.error) {
|
|
1589
|
-
throw new ValidationError(parsedResult.error);
|
|
1590
|
-
}
|
|
1591
|
-
return parsedResult.data;
|
|
1929
|
+
return this.transformConnectedAccountResponse(response);
|
|
1592
1930
|
}
|
|
1593
1931
|
/**
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1596
|
-
*
|
|
1597
|
-
*
|
|
1932
|
+
* Deletes a connected account.
|
|
1933
|
+
*
|
|
1934
|
+
* This method permanently removes a connected account from the Composio platform.
|
|
1935
|
+
* This action cannot be undone and will revoke any access tokens associated with the account.
|
|
1936
|
+
*
|
|
1937
|
+
* @param {string} nanoid - The unique identifier of the connected account to delete
|
|
1938
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} The deletion response
|
|
1939
|
+
* @throws {Error} If the account doesn't exist or cannot be deleted
|
|
1940
|
+
*
|
|
1941
|
+
* @example
|
|
1942
|
+
* ```typescript
|
|
1943
|
+
* // Delete a connected account
|
|
1944
|
+
* await composio.connectedAccounts.delete('conn_abc123');
|
|
1945
|
+
* ```
|
|
1598
1946
|
*/
|
|
1599
1947
|
async delete(nanoid) {
|
|
1600
1948
|
return this.client.connectedAccounts.delete(nanoid);
|
|
1601
1949
|
}
|
|
1602
1950
|
/**
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1951
|
+
* Refreshes a connected account's authentication credentials.
|
|
1952
|
+
*
|
|
1953
|
+
* This method attempts to refresh OAuth tokens or other credentials associated with
|
|
1954
|
+
* the connected account. This is useful when a token has expired or is about to expire.
|
|
1955
|
+
*
|
|
1956
|
+
* @param {string} nanoid - The unique identifier of the connected account to refresh
|
|
1957
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} The response containing the refreshed account details
|
|
1958
|
+
* @throws {Error} If the account doesn't exist or credentials cannot be refreshed
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* ```typescript
|
|
1962
|
+
* // Refresh a connected account's credentials
|
|
1963
|
+
* const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
|
|
1964
|
+
* ```
|
|
1607
1965
|
*/
|
|
1608
1966
|
async refresh(nanoid) {
|
|
1609
1967
|
return this.client.connectedAccounts.refresh(nanoid);
|
|
@@ -1646,9 +2004,15 @@ var Toolkits = class {
|
|
|
1646
2004
|
this.authorize = this.authorize.bind(this);
|
|
1647
2005
|
}
|
|
1648
2006
|
/**
|
|
1649
|
-
*
|
|
1650
|
-
*
|
|
1651
|
-
*
|
|
2007
|
+
* Retrieves a list of toolkits based on the provided query parameters.
|
|
2008
|
+
*
|
|
2009
|
+
* This method fetches toolkits from the Composio API and transforms the response
|
|
2010
|
+
* from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
|
|
2011
|
+
*
|
|
2012
|
+
* @param {ToolkitListParams} query - The query parameters to filter toolkits
|
|
2013
|
+
* @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
|
|
2014
|
+
*
|
|
2015
|
+
* @private
|
|
1652
2016
|
*/
|
|
1653
2017
|
async getToolkits(query) {
|
|
1654
2018
|
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
@@ -1677,11 +2041,29 @@ var Toolkits = class {
|
|
|
1677
2041
|
return parsedResult;
|
|
1678
2042
|
}
|
|
1679
2043
|
/**
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
* @param
|
|
1683
|
-
* @
|
|
1684
|
-
|
|
2044
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2045
|
+
*
|
|
2046
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2047
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
2048
|
+
*/
|
|
2049
|
+
async get(arg) {
|
|
2050
|
+
if (typeof arg === "string") {
|
|
2051
|
+
return this.getToolkitBySlug(arg);
|
|
2052
|
+
}
|
|
2053
|
+
return this.getToolkits(arg);
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Retrieves a specific toolkit by its slug identifier.
|
|
2057
|
+
*
|
|
2058
|
+
* This method fetches a single toolkit from the Composio API and transforms
|
|
2059
|
+
* the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
|
|
2060
|
+
*
|
|
2061
|
+
* @param {string} slug - The unique slug identifier of the toolkit to retrieve
|
|
2062
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
|
|
2063
|
+
* @throws {ValidationError} If the response cannot be properly parsed
|
|
2064
|
+
* @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
|
|
2065
|
+
*
|
|
2066
|
+
* @private
|
|
1685
2067
|
*/
|
|
1686
2068
|
async getToolkitBySlug(slug) {
|
|
1687
2069
|
try {
|
|
@@ -1722,21 +2104,19 @@ var Toolkits = class {
|
|
|
1722
2104
|
}
|
|
1723
2105
|
}
|
|
1724
2106
|
/**
|
|
1725
|
-
*
|
|
1726
|
-
*
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1729
|
-
*/
|
|
1730
|
-
async get(arg) {
|
|
1731
|
-
if (typeof arg === "string") {
|
|
1732
|
-
return this.getToolkitBySlug(arg);
|
|
1733
|
-
}
|
|
1734
|
-
return this.getToolkits(arg);
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* Fetches all categories available in the Composio SDK
|
|
2107
|
+
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2108
|
+
*
|
|
2109
|
+
* This method fetches the complete list of categories from the Composio API
|
|
2110
|
+
* and transforms the response to use camelCase property naming.
|
|
1738
2111
|
*
|
|
1739
|
-
* @returns {Promise<ToolkitRetrieveCategoriesResponse>}
|
|
2112
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
|
|
2113
|
+
*
|
|
2114
|
+
* @example
|
|
2115
|
+
* ```typescript
|
|
2116
|
+
* // Get all toolkit categories
|
|
2117
|
+
* const categories = await composio.toolkits.listCategories();
|
|
2118
|
+
* console.log(categories.items); // Array of category objects
|
|
2119
|
+
* ```
|
|
1740
2120
|
*/
|
|
1741
2121
|
async listCategories() {
|
|
1742
2122
|
const result = await this.client.toolkits.retrieveCategories();
|
|
@@ -1758,8 +2138,12 @@ var Toolkits = class {
|
|
|
1758
2138
|
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1759
2139
|
* @param {string} userId - The user id of the user to authorize
|
|
1760
2140
|
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1761
|
-
* @param {string} authConfigId - The id of the auth config to use
|
|
1762
2141
|
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
2142
|
+
*
|
|
2143
|
+
* @example
|
|
2144
|
+
* ```typescript
|
|
2145
|
+
* const connectionRequest = await composio.toolkits.authorize(userId, 'github');
|
|
2146
|
+
* ```
|
|
1763
2147
|
*/
|
|
1764
2148
|
async authorize(userId, toolkitSlug) {
|
|
1765
2149
|
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
@@ -2516,7 +2900,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2516
2900
|
};
|
|
2517
2901
|
|
|
2518
2902
|
// package.json
|
|
2519
|
-
var version = "0.1.12-alpha.
|
|
2903
|
+
var version = "0.1.12-alpha.9";
|
|
2520
2904
|
|
|
2521
2905
|
// src/utils/uuid.ts
|
|
2522
2906
|
var import_uuid = require("uuid");
|
|
@@ -2548,7 +2932,6 @@ var Composio = class {
|
|
|
2548
2932
|
authConfigs;
|
|
2549
2933
|
// connected accounts
|
|
2550
2934
|
connectedAccounts;
|
|
2551
|
-
experimental;
|
|
2552
2935
|
/**
|
|
2553
2936
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2554
2937
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2566,7 +2949,7 @@ var Composio = class {
|
|
|
2566
2949
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2567
2950
|
logger_default.info(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2568
2951
|
}
|
|
2569
|
-
this.client = new
|
|
2952
|
+
this.client = new import_client2.default({
|
|
2570
2953
|
apiKey: apiKeyParsed,
|
|
2571
2954
|
baseURL: baseURLParsed
|
|
2572
2955
|
});
|
|
@@ -2580,9 +2963,6 @@ var Composio = class {
|
|
|
2580
2963
|
this.triggers = new Triggers(this.client);
|
|
2581
2964
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2582
2965
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2583
|
-
this.experimental = {
|
|
2584
|
-
connectionRequest: connectionRequest(this.client)
|
|
2585
|
-
};
|
|
2586
2966
|
if (this.config.allowTracking ?? true) {
|
|
2587
2967
|
this.initializeTelemetry(
|
|
2588
2968
|
{
|