Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix upload/download

haxzie4c53ab0c054c
diff --git a/ts/examples/connected-accounts/src/magic-flow-demo.ts b/ts/examples/connected-accounts/src/magic-flow-demo.ts
index 47e8dbf88..03f434fe2 100644
--- a/ts/examples/connected-accounts/src/magic-flow-demo.ts
+++ b/ts/examples/connected-accounts/src/magic-flow-demo.ts
@@ -24,6 +24,8 @@ console.log(`Redirect the user to ${redirectUrl}`);
// Wait for the user to connect the account / singin to GitHub
const connectedAccount = await connectionRequest.waitForConnection();
+console.log(`Connected account created: ${JSON.stringify(connectedAccount, null, 2)}`);
+
// ------------------------------------------------------------
// 2. Get the GitHub tools
// ------------------------------------------------------------
@@ -47,3 +49,5 @@ const response = await openai.chat.completions.create({
tools: tools,
tool_choice: 'auto',
});
+
+console.log(`Response: ${JSON.stringify(response, null, 2)}`);
diff --git a/ts/examples/tools/src/index.ts b/ts/examples/tools/src/index.ts
index e2bb271cc..944e6d079 100644
--- a/ts/examples/tools/src/index.ts
+++ b/ts/examples/tools/src/index.ts
@@ -25,23 +25,28 @@ const composio = new Composio({
*/
async function main() {
try {
- console.log('πŸš€ Starting Tools Example...');
-
- const tools = await composio.tools.getRawComposioTools({
- tools: ['GOOGLEDRIVE_UPLOAD_FILE'],
- });
-
- console.log(JSON.stringify(tools, null, 2));
+ console.log('πŸš€ Starting Upload file Example...');
+ console.log('πŸ”„ Uploading file...');
const result = await composio.tools.execute('GOOGLEDRIVE_UPLOAD_FILE', {
arguments: {
file_to_upload: path.join(__dirname, 'image.png'),
},
userId: 'default',
});
-
+ console.log('βœ… File uploaded successfully...');
console.log(JSON.stringify(result, null, 2));
-
+
+ console.log('πŸ”„ Downloading file...');
+ const result2 = await composio.tools.execute('GOOGLEDRIVE_DOWNLOAD_FILE', {
+ arguments: {
+ file_id: (result.data.response_data as unknown as { id: string }).id,
+ },
+ userId: 'default',
+ });
+ console.log('βœ… File downloaded successfully...');
+ console.log(JSON.stringify(result2, null, 2));
+
} catch (error) {
console.error('❌ Error running example:', error);
}
diff --git a/ts/packages/core/src/models/Toolkits.ts b/ts/packages/core/src/models/Toolkits.ts
index 2027400be..af1e25977 100644
--- a/ts/packages/core/src/models/Toolkits.ts
+++ b/ts/packages/core/src/models/Toolkits.ts
@@ -380,20 +380,6 @@ export class Toolkits {
const authConfig = await composioAuthConfig.list({
toolkit: toolkitSlug,
});
- if (authConfig.items?.length === 0) {
- throw new ComposioAuthConfigNotFoundError(
- `No auth configs found for toolkit ${toolkitSlug}`,
- {
- meta: {
- toolkitSlug,
- },
- possibleFixes: [
- `Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`,
- ],
- }
- );
- }
-
// pick the first auth config
authConfigIdToUse = authConfig.items[0]?.id;
@@ -401,20 +387,40 @@ export class Toolkits {
if (!authConfigIdToUse) {
// create authConfig using composioManagedAuthSchemes
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
- const authConfig = await composioAuthConfig.create(toolkitSlug, {
- type: 'use_composio_managed_auth',
- name: `${toolkit.name} Auth Config`,
- });
- authConfigIdToUse = authConfig.id;
+ try {
+ const authConfig = await composioAuthConfig.create(toolkitSlug, {
+ type: 'use_composio_managed_auth',
+ name: `${toolkit.name} Auth Config`,
+ });
+ authConfigIdToUse = authConfig.id;
+ } catch (error) {
+ if (error instanceof ComposioClient.APIError && error.status === 400) {
+ throw new ComposioAuthConfigNotFoundError(
+ `No Default auth config found for toolkit ${toolkitSlug}`,
+ {
+ meta: {
+ toolkitSlug,
+ },
+ cause: error,
+ possibleFixes: [
+ `Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`,
+ ],
+ }
+ );
+ }
+ throw error;
+ }
} else {
- throw new ComposioAuthConfigNotFoundError('No auth config found for toolkit', {
- meta: {
- toolkitSlug,
- },
- });
+ throw new ComposioAuthConfigNotFoundError(
+ `No auth configs found for toolkit ${toolkitSlug}`,
+ {
+ meta: {
+ toolkitSlug,
+ },
+ }
+ );
}
}
-
// create the auth config
const composioConnectedAccount = new ConnectedAccounts(this.client);
return await composioConnectedAccount.initiate(userId, authConfigIdToUse, {
diff --git a/ts/packages/core/src/utils/modifiers/FileToolModifier.ts b/ts/packages/core/src/utils/modifiers/FileToolModifier.ts
index 3e718d98c..bc9c052a9 100644
--- a/ts/packages/core/src/utils/modifiers/FileToolModifier.ts
+++ b/ts/packages/core/src/utils/modifiers/FileToolModifier.ts
@@ -21,19 +21,173 @@ const transformProperties = (properties: JSONSchemaProperty): JSONSchemaProperty
const newProperties: JSONSchemaProperty = {};
for (const [key, property] of Object.entries(properties) as [string, JSONSchemaProperty][]) {
- if (!property.file_uploadable) {
+ if (property.file_uploadable) {
+ // Transform file-uploadable property
+ newProperties[key] = {
+ title: property.title,
+ description: property.description,
+ format: 'path',
+ type: 'string',
+ file_uploadable: true,
+ };
+ } else if (property.type === 'object' && property.properties) {
+ // Recursively transform nested properties
+ newProperties[key] = {
+ ...property,
+ properties: transformProperties(property.properties),
+ };
+ } else {
+ // Copy the property as-is
newProperties[key] = property;
- continue;
}
- newProperties[key] = {
- ...property,
- format: 'path',
- };
}
return newProperties;
};
+/**
+ * Recursively walks a runtime value and its matching JSON-Schema node,
+ * uploading any string path whose schema node has `file_uploadable: true`.
+ * The function returns a **new** value with all substitutions applied;
+ * nothing is mutated in-place.
+ */
+const hydrateFiles = async (
+ value: unknown,
+ schema: JSONSchemaProperty | undefined,
+ ctx: {
+ toolSlug: string;
+ toolkitSlug: string;
+ client: ComposioClient;
+ }
+): Promise<unknown> => {
+ // ──────────────────────────────────────────────────────────────────────────
+ // 1. Direct file upload
+ // ──────────────────────────────────────────────────────────────────────────
+ if (schema?.file_uploadable) {
+ // Upload only if the runtime value is a string (i.e., a local path)
+ if (typeof value !== 'string') return value;
+
+ logger.debug(`Uploading file "${value}"`);
+ return getFileDataAfterUploadingToS3({
+ path: value,
+ toolSlug: ctx.toolSlug,
+ toolkitSlug: ctx.toolkitSlug,
+ client: ctx.client,
+ });
+ }
+
+ // ──────────────────────────────────────────────────────────────────────────
+ // 2. Object β†’ traverse each property
+ // ──────────────────────────────────────────────────────────────────────────
+ if (schema?.type === 'object' && schema.properties && isPlainObject(value)) {
+ const transformed: Record<string, unknown> = {};
+
+ for (const [k, v] of Object.entries(value)) {
+ transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
+ }
+ return transformed;
+ }
+
+ // ──────────────────────────────────────────────────────────────────────────
+ // 3. Array β†’ traverse each item
+ // ──────────────────────────────────────────────────────────────────────────
+ if (schema?.type === 'array' && schema.items && Array.isArray(value)) {
+ // `items` can be a single schema or an array of schemas; we handle both.
+ const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
+
+ return Promise.all(
+ value.map(item => hydrateFiles(item, itemSchema as JSONSchemaProperty, ctx))
+ );
+ }
+
+ // ──────────────────────────────────────────────────────────────────────────
+ // 4. Primitive or schema-less branch β†’ return unchanged
+ // ──────────────────────────────────────────────────────────────────────────
+ return value;
+};
+
+/**
+ * Recursively walks an arbitrary value and its matching JSON-Schema node.
+ * Whenever it encounters an object that represents a file reference
+ * (i.e. has an `s3url`), it downloads the file and returns a replacement:
+ * {
+ * uri: "<local-path>",
+ * file_downloaded: true | false,
+ * s3url: "<original S3 URL>",
+ * mimeType: "<detected-or-fallback-mime-type>"
+ * }
+ *
+ * The function is side-effect-free: it never mutates the input value.
+ */
+/**
+ * Walk a value (object, array, primitive).
+ * Wherever an object contains a string `s3url`, download the file and
+ * return a replacement object:
+ * {
+ * uri: "<local path>",
+ * file_downloaded: true|false,
+ * s3url: "<original url>",
+ * mimeType: "<detected-or-fallback>"
+ * }
+ */
+const hydrateDownloads = async (value: unknown, ctx: { toolSlug: string }): Promise<unknown> => {
+ // ─────────────────────────────── 1. direct S3 ref ─────────────────────────
+ if (isPlainObject(value) && typeof value.s3url === 'string') {
+ const { s3url, mimetype } = value as {
+ s3url: string;
+ mimetype?: string;
+ };
+
+ try {
+ logger.debug(`Downloading from S3: ${s3url}`);
+
+ const dl = await downloadFileFromS3({
+ toolSlug: ctx.toolSlug,
+ s3Url: s3url,
+ mimeType: mimetype ?? 'application/octet-stream',
+ });
+
+ logger.debug(`Downloaded β†’ ${dl.filePath}`);
+
+ return {
+ uri: dl.filePath,
+ file_downloaded: true,
+ s3url,
+ mimeType: dl.mimeType,
+ };
+ } catch (err) {
+ logger.error(`Download failed: ${s3url}`, { cause: err });
+ return {
+ uri: '',
+ file_downloaded: false,
+ s3url,
+ mimeType: mimetype ?? 'application/octet-stream',
+ };
+ }
+ }
+
+ // ─────────────────────────────── 2. object branch ─────────────────────────
+ if (isPlainObject(value)) {
+ const pairs = await Promise.all(
+ Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)])
+ );
+ return Object.fromEntries(pairs);
+ }
+
+ // ─────────────────────────────── 3. array branch ──────────────────────────
+ if (Array.isArray(value)) {
+ return Promise.all(value.map(item => hydrateDownloads(item, ctx)));
+ }
+
+ // ─────────────────────────────── 4. primitive ─────────────────────────────
+ return value; // leave unchanged
+};
+
+// Small helper to recognise plain objects
+function isPlainObject(val: unknown): val is Record<string, unknown> {
+ return typeof val === 'object' && val !== null && !Array.isArray(val);
+}
+
export class FileToolModifier {
private client: ComposioClient;
@@ -78,35 +232,30 @@ export class FileToolModifier {
*/
async fileUploadModifier(
tool: Tool,
- options: { toolSlug: string; toolkitSlug: string; params: ToolExecuteParams }
- ): Promise<ToolExecuteParams> {
- const { arguments: args } = options.params;
- if (!args) {
- return options.params;
+ options: {
+ toolSlug: string;
+ toolkitSlug?: string;
+ params: ToolExecuteParams;
}
- // Check if the arguments is an object
- for (const key of Object.keys(args)) {
- // Check if the key ends with _schema_parsed_file and is a string
- const toolProperty = tool.inputParameters?.properties?.[key];
-
- if (toolProperty?.file_uploadable) {
- logger.debug(`Processing file upload for: ${key}`);
- try {
- const fileData = await getFileDataAfterUploadingToS3({
- path: args[key] as string,
- toolSlug: options.toolSlug,
- toolkitSlug: options.toolkitSlug ?? 'unknown',
- client: this.client,
- });
- args[key] = fileData;
- } catch (error) {
- throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
- cause: error,
- });
- }
- }
+ ): Promise<ToolExecuteParams> {
+ const { params, toolSlug, toolkitSlug = 'unknown' } = options;
+ const { arguments: args } = params;
+
+ if (!args || typeof args !== 'object') return params;
+
+ // Recursively transform the arguments tree without mutating the caller’s copy
+ try {
+ const newArgs = await hydrateFiles(args, tool.inputParameters, {
+ toolSlug,
+ toolkitSlug,
+ client: this.client,
+ });
+ return { ...params, arguments: newArgs as ToolExecuteParams['arguments'] };
+ } catch (error) {
+ throw new ComposioFileUploadError('Failed to upload file', {
+ cause: error,
+ });
}
- return options.params;
}
/**
@@ -120,47 +269,18 @@ export class FileToolModifier {
* @returns The result with the file download URL included.
*/
async fileDownloadModifier(
- tool: Tool,
+ _tool: Tool, // no longer needed for the traversal itself
options: {
toolSlug: string;
- toolkitSlug: string;
+ toolkitSlug: string; // kept for API parity, unused here
result: ToolExecuteResponse;
}
): Promise<ToolExecuteResponse> {
- for (const [key, value] of Object.entries(options.result?.data)) {
- const fileData = value as { s3url?: string; mimetype?: string };
-
- if (!fileData?.s3url) continue;
-
- logger.debug(`Downloading file from S3: ${fileData.s3url}`);
-
- try {
- const downloadedFile = await downloadFileFromS3({
- toolSlug: options.toolSlug,
- s3Url: fileData.s3url,
- mimeType: fileData.mimetype || 'application/txt',
- });
-
- logger.debug(`Downloaded file from S3: ${downloadedFile.filePath}`);
-
- options.result.data[key] = {
- uri: downloadedFile.filePath,
- file_downloaded: true,
- s3url: fileData.s3url,
- mimeType: downloadedFile.mimeType,
- };
- } catch (error) {
- logger.error(`Failed to download file from S3: ${fileData.s3url}`, {
- cause: error,
- });
- options.result.data[key] = {
- uri: '',
- file_downloaded: false,
- s3url: fileData.s3url,
- mimeType: fileData.mimetype || 'application/txt',
- };
- }
- }
- return options.result;
+ const { result, toolSlug } = options;
+
+ // Walk result.data without mutating the original
+ const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
+
+ return { ...result, data: dataWithDownloads as typeof result.data };
}
}
diff --git a/ts/packages/core/test/models/toolkits.test.ts b/ts/packages/core/test/models/toolkits.test.ts
index 909e8864a..88c9b6fcb 100644
--- a/ts/packages/core/test/models/toolkits.test.ts
+++ b/ts/packages/core/test/models/toolkits.test.ts
@@ -221,219 +221,229 @@ describe('Toolkits', () => {
});
describe('authorize', () => {
- it('should create auth config and initiate connection request when no auth config exists', async () => {
- const userId = 'user_123';
- const toolkitSlug = 'test-toolkit';
- const options = {
- callbackUrl: 'https://example.com/callback',
- };
-
- // Mock toolkit response
- mockClient.toolkits.retrieve.mockResolvedValueOnce({
- slug: toolkitSlug,
- name: 'Test Toolkit',
- meta: {
- created_at: new Date().toISOString(),
- updated_at: new Date().toISOString(),
- tools_count: 1,
- triggers_count: 0,
- },
- is_local_toolkit: false,
- auth_config_details: [
- {
- name: 'oauth2',
- mode: 'oauth2',
- fields: {
- auth_config_creation: {
- optional: [],
- required: [],
- },
- connected_account_initiation: {
- optional: [],
- required: [],
- },
+ const userId = 'user_123';
+ const toolkitSlug = 'test-toolkit';
+ const mockToolkitResponse = {
+ slug: toolkitSlug,
+ name: 'Test Toolkit',
+ meta: {
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString(),
+ tools_count: 1,
+ triggers_count: 0,
+ },
+ is_local_toolkit: false,
+ auth_config_details: [
+ {
+ name: 'oauth2',
+ mode: 'OAUTH2',
+ fields: {
+ auth_config_creation: {
+ optional: [],
+ required: [],
+ },
+ connected_account_initiation: {
+ optional: [],
+ required: [],
},
},
- ],
- });
+ },
+ ],
+ };
+
+ it('should create auth config and initiate connection when no auth config exists', async () => {
+ // Mock toolkit retrieval
+ mockClient.toolkits.retrieve.mockResolvedValueOnce(mockToolkitResponse);
- // Mock auth config list response
+ // Mock empty auth config list
mockClient.authConfigs.list.mockResolvedValueOnce({
items: [],
- next_cursor: 'next-cursor',
+ next_cursor: null,
total_pages: 1,
});
- // Mock auth config create response
+ // Mock auth config creation
mockClient.authConfigs.create.mockResolvedValueOnce({
toolkit: {
slug: toolkitSlug,
},
auth_config: {
id: 'auth_config_123',
- auth_scheme: 'oauth2',
+ auth_scheme: 'OAUTH2',
is_composio_managed: true,
is_disabled: false,
+ name: 'Test Toolkit Auth Config',
+ no_of_connections: 0,
+ status: 'ENABLED',
+ uuid: 'uuid-1',
toolkit: {
- slug: toolkitSlug,
logo: 'https://example.com/logo.png',
+ slug: toolkitSlug,
},
},
});
- // Mock connected accounts list response
+ // Mock connected accounts list
mockClient.connectedAccounts.list.mockResolvedValueOnce({
items: [],
next_cursor: null,
total_pages: 1,
});
- // Mock connected account create response
+ // Mock connection initiation
mockClient.connectedAccounts.create.mockResolvedValueOnce({
id: 'conn_123',
connectionData: {
val: {
- authScheme: 'OAUTH2',
status: 'INITIALIZING',
redirectUrl: 'https://auth.example.com/connect',
+ authScheme: 'OAUTH2',
},
},
});
const connectionRequest = await toolkits.authorize(userId, toolkitSlug);
+ // Verify the flow
+ expect(mockClient.toolkits.retrieve).toHaveBeenCalledWith(toolkitSlug);
+ expect(mockClient.authConfigs.list).toHaveBeenCalledWith({
+ toolkit_slug: toolkitSlug,
+ });
expect(mockClient.authConfigs.create).toHaveBeenCalledWith({
- toolkit: { slug: toolkitSlug },
+ toolkit: {
+ slug: toolkitSlug,
+ },
auth_config: {
type: 'use_composio_managed_auth',
name: 'Test Toolkit Auth Config',
},
});
-
+ expect(mockClient.connectedAccounts.create).toHaveBeenCalledWith({
+ auth_config: {
+ id: 'auth_config_123',
+ },
+ connection: {
+ user_id: userId,
+ },
+ });
expect(connectionRequest).toBeInstanceOf(ConnectionRequest);
+ expect(connectionRequest.redirectUrl).toBe('https://auth.example.com/connect');
});
- it('should use existing auth config to initiate connection request', async () => {
- const userId = 'user_123';
- const toolkitSlug = 'test-toolkit';
- const options = {
- callbackUrl: 'https://example.com/callback',
- };
-
- // Mock toolkit response
- mockClient.toolkits.retrieve.mockResolvedValueOnce({
- slug: toolkitSlug,
- name: 'Test Toolkit',
- meta: {
- created_at: new Date().toISOString(),
- updated_at: new Date().toISOString(),
- tools_count: 1,
- triggers_count: 0,
- },
- is_local_toolkit: false,
- auth_config_details: [
- {
- name: 'oauth2',
- mode: 'OAUTH2',
- fields: {
- auth_config_creation: {
- optional: [],
- required: [],
- },
- connected_account_initiation: {
- optional: [],
- required: [],
- },
- },
- },
- ],
- });
+ it('should use existing auth config to initiate connection', async () => {
+ // Mock toolkit retrieval
+ mockClient.toolkits.retrieve.mockResolvedValueOnce(mockToolkitResponse);
- // Mock auth config list response
+ // Mock existing auth config
mockClient.authConfigs.list.mockResolvedValueOnce({
items: [
{
- id: 'auth_config_123',
+ id: 'existing_auth_123',
auth_scheme: 'OAUTH2',
is_composio_managed: true,
is_disabled: false,
- name: 'Test Toolkit Auth Config',
- no_of_connections: 0,
+ name: 'Existing Auth Config',
+ no_of_connections: 1,
status: 'ENABLED',
+ uuid: 'uuid-1',
toolkit: {
logo: 'https://example.com/logo.png',
slug: toolkitSlug,
},
- uuid: 'uuid-1',
- credentials: {},
- expected_input_fields: [],
- created_by: 'user-1',
- created_at: new Date().toISOString(),
- last_updated_at: new Date().toISOString(),
},
],
next_cursor: null,
total_pages: 1,
});
- // Mock connected accounts list response
+ // Mock connected accounts list
mockClient.connectedAccounts.list.mockResolvedValueOnce({
items: [],
next_cursor: null,
total_pages: 1,
});
- // Mock connected account create response
+ // Mock connection initiation
mockClient.connectedAccounts.create.mockResolvedValueOnce({
id: 'conn_123',
connectionData: {
val: {
- authScheme: AuthSchemeTypes.OAUTH2,
status: 'INITIALIZING',
redirectUrl: 'https://auth.example.com/connect',
+ authScheme: 'OAUTH2',
},
},
});
const connectionRequest = await toolkits.authorize(userId, toolkitSlug);
+ // Verify the flow
+ expect(mockClient.toolkits.retrieve).toHaveBeenCalledWith(toolkitSlug);
+ expect(mockClient.authConfigs.list).toHaveBeenCalledWith({
+ toolkit_slug: toolkitSlug,
+ });
expect(mockClient.authConfigs.create).not.toHaveBeenCalled();
+ expect(mockClient.connectedAccounts.create).toHaveBeenCalledWith({
+ auth_config: {
+ id: 'existing_auth_123',
+ },
+ connection: {
+ user_id: userId,
+ },
+ });
expect(connectionRequest).toBeInstanceOf(ConnectionRequest);
+ expect(connectionRequest.redirectUrl).toBe('https://auth.example.com/connect');
});
it('should throw ComposioAuthConfigNotFoundError when toolkit has no auth config details', async () => {
// Mock toolkit retrieval with no auth config details
- mockClient.toolkits.retrieve.mockResolvedValue({
- name: 'Test Toolkit',
- slug: 'test-toolkit',
- meta: {
- created_at: new Date().toISOString(),
- updated_at: new Date().toISOString(),
- tools_count: 1,
- triggers_count: 0,
- },
- is_local_toolkit: false,
- auth_config_details: [],
+ mockClient.toolkits.retrieve.mockResolvedValueOnce({
+ ...mockToolkitResponse,
+ auth_config_details: [], // Empty auth config details
+ });
+
+ // Mock empty auth config list
+ mockClient.authConfigs.list.mockResolvedValueOnce({
+ items: [],
+ next_cursor: null,
+ total_pages: 1,
});
+ const promise = toolkits.authorize(userId, toolkitSlug);
+
+ await expect(promise).rejects.toThrow(ComposioAuthConfigNotFoundError);
+ await expect(promise).rejects.toThrow(`No auth configs found for toolkit ${toolkitSlug}`);
+ expect(mockClient.authConfigs.create).not.toHaveBeenCalled();
+ expect(mockClient.connectedAccounts.create).not.toHaveBeenCalled();
+ });
+
+ it('should throw ComposioAuthConfigNotFoundError when auth config creation fails', async () => {
+ // Mock toolkit retrieval
+ mockClient.toolkits.retrieve.mockResolvedValueOnce(mockToolkitResponse);
+
// Mock empty auth config list
- mockClient.authConfigs.list.mockResolvedValue({
+ mockClient.authConfigs.list.mockResolvedValueOnce({
items: [],
next_cursor: null,
total_pages: 1,
});
- // Mock the error to be thrown
- mockClient.authConfigs.create.mockRejectedValue(
- new ComposioAuthConfigNotFoundError('No auth config found for toolkit')
+ // Mock auth config creation failure with ComposioClient.APIError
+ const apiError = new ComposioClient.APIError(
+ 400,
+ 'Bad Request',
+ 'Bad Request',
+ new Headers()
);
+ mockClient.authConfigs.create.mockRejectedValueOnce(apiError);
- const promise = toolkits.authorize('user-123', 'test-toolkit');
+ const promise = toolkits.authorize(userId, toolkitSlug);
await expect(promise).rejects.toThrow(ComposioAuthConfigNotFoundError);
- await expect(promise).rejects.toThrow('No auth config found for toolkit');
- expect(mockClient.authConfigs.create).not.toHaveBeenCalled();
- expect(mockClient.connectedAccounts.initiate).not.toHaveBeenCalled();
+ await expect(promise).rejects.toThrow(
+ `No Default auth config found for toolkit ${toolkitSlug}`
+ );
+ expect(mockClient.connectedAccounts.create).not.toHaveBeenCalled();
});
it('should throw ComposioToolkitNotFoundError when toolkit does not exist', async () => {
@@ -446,7 +456,7 @@ describe('Toolkits', () => {
await expect(promise).rejects.toThrow("Couldn't fetch Toolkit with slug: non-existent");
expect(mockClient.authConfigs.list).not.toHaveBeenCalled();
expect(mockClient.authConfigs.create).not.toHaveBeenCalled();
- expect(mockClient.connectedAccounts.initiate).not.toHaveBeenCalled();
+ expect(mockClient.connectedAccounts.create).not.toHaveBeenCalled();
});
});