@composio/core 0.12.0 → 0.13.1

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.
Files changed (147) hide show
  1. package/dist/{BaseProvider-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
  2. package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
  3. package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
  4. package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
  5. package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
  6. package/dist/composio-DfPD7BAi.d.mts +5666 -0
  7. package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
  8. package/dist/customTool.types-D-6YqFdW.d.mts +2826 -0
  9. package/dist/docs/error-consistency.md +97 -0
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
  12. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
  13. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
  14. package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
  15. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
  16. package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
  17. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
  18. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
  19. package/dist/docs/reference/sdk-reference/typescript/session.mdx +252 -0
  20. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -0
  21. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
  22. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
  23. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
  24. package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
  25. package/dist/experimental/index.d.mts +2 -2
  26. package/dist/experimental/index.mjs +1 -1
  27. package/dist/index.d.mts +36 -6
  28. package/dist/index.mjs +455 -123
  29. package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
  30. package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
  31. package/dist/types-CCh8qvui.d.mts +12 -0
  32. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  33. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  34. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  35. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  36. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  37. package/docs/error-consistency.md +97 -0
  38. package/package.json +4 -3
  39. package/src/composio.ts +509 -0
  40. package/src/errors/AuthConfigErrors.ts +23 -0
  41. package/src/errors/ComposioError.ts +408 -0
  42. package/src/errors/ConnectedAccountsErrors.ts +158 -0
  43. package/src/errors/ConnectionRequestErrors.ts +32 -0
  44. package/src/errors/FileModifierErrors.ts +100 -0
  45. package/src/errors/PusherErrors.ts +28 -0
  46. package/src/errors/RemoteFileErrors.ts +62 -0
  47. package/src/errors/SDKErrors.ts +92 -0
  48. package/src/errors/ToolErrors.ts +244 -0
  49. package/src/errors/ToolkitErrors.ts +39 -0
  50. package/src/errors/TriggerErrors.ts +120 -0
  51. package/src/errors/ValidationErrors.ts +99 -0
  52. package/src/errors/index.ts +41 -0
  53. package/src/experimental/index.ts +28 -0
  54. package/src/index.ts +64 -0
  55. package/src/lib/toolRouterConstants.ts +1 -0
  56. package/src/lib/toolRouterParams.ts +306 -0
  57. package/src/lib/toolRouterSessionDelete.ts +30 -0
  58. package/src/models/AuthConfigs.ts +398 -0
  59. package/src/models/AuthScheme.ts +206 -0
  60. package/src/models/ConnectedAccounts.ts +735 -0
  61. package/src/models/ConnectionRequest.ts +150 -0
  62. package/src/models/CustomTool.ts +676 -0
  63. package/src/models/Experimental.ts +202 -0
  64. package/src/models/Files.node.ts +93 -0
  65. package/src/models/Files.workerd.ts +49 -0
  66. package/src/models/MCP.ts +478 -0
  67. package/src/models/RemoteFile.ts +172 -0
  68. package/src/models/SessionContext.ts +147 -0
  69. package/src/models/Sessions.ts +21 -0
  70. package/src/models/ToolRouter.ts +406 -0
  71. package/src/models/ToolRouterSession.ts +839 -0
  72. package/src/models/ToolRouterSessionFileMount.ts +389 -0
  73. package/src/models/Toolkits.ts +412 -0
  74. package/src/models/Tools.ts +1260 -0
  75. package/src/models/Triggers.ts +1381 -0
  76. package/src/models/customToolExecution.ts +118 -0
  77. package/src/models/inlineCustomToolsPayload.ts +17 -0
  78. package/src/models/proxyParamsTransform.ts +26 -0
  79. package/src/provider/BaseProvider.ts +138 -0
  80. package/src/provider/ComposioProvider.ts +29 -0
  81. package/src/provider/OpenAIProvider.ts +547 -0
  82. package/src/services/internal/InternalService.ts +50 -0
  83. package/src/services/internal/InternalService.types.ts +14 -0
  84. package/src/services/pusher/Pusher.ts +230 -0
  85. package/src/services/telemetry/TelemetryService.ts +48 -0
  86. package/src/services/telemetry/TelemetryService.types.ts +67 -0
  87. package/src/telemetry/BatchProcessor.ts +77 -0
  88. package/src/telemetry/README.md +123 -0
  89. package/src/telemetry/Telemetry.ts +356 -0
  90. package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
  91. package/src/types/authConfigs.types.ts +174 -0
  92. package/src/types/composio.types.ts +1 -0
  93. package/src/types/connectedAccountAuthStates.types.ts +852 -0
  94. package/src/types/connectedAccounts.types.ts +395 -0
  95. package/src/types/connectionRequest.types.ts +16 -0
  96. package/src/types/customTool.types.ts +261 -0
  97. package/src/types/files.types.ts +15 -0
  98. package/src/types/mcp.experimental.types.ts +163 -0
  99. package/src/types/mcp.types.ts +362 -0
  100. package/src/types/modifiers.types.ts +663 -0
  101. package/src/types/org.types.ts +0 -0
  102. package/src/types/provider.types.ts +41 -0
  103. package/src/types/pusher.types.ts +18 -0
  104. package/src/types/requestOptions.types.ts +62 -0
  105. package/src/types/telemetry.types.ts +89 -0
  106. package/src/types/tool.types.ts +408 -0
  107. package/src/types/toolRouter.types.ts +774 -0
  108. package/src/types/toolkit.types.ts +130 -0
  109. package/src/types/triggers.types.ts +401 -0
  110. package/src/types/webhookEvents.types.ts +219 -0
  111. package/src/utils/buffer.ts +30 -0
  112. package/src/utils/cancellation.ts +22 -0
  113. package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
  114. package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
  115. package/src/utils/config-defaults/index.ts +1 -0
  116. package/src/utils/config-defaults/types.ts +14 -0
  117. package/src/utils/constants.ts +22 -0
  118. package/src/utils/crypto.ts +34 -0
  119. package/src/utils/env.ts +34 -0
  120. package/src/utils/fileDirs.ts +81 -0
  121. package/src/utils/fileUtils.node.ts +458 -0
  122. package/src/utils/json-schema.ts +1 -0
  123. package/src/utils/jsonSchema.ts +355 -0
  124. package/src/utils/logger.ts +99 -0
  125. package/src/utils/mime.ts +75 -0
  126. package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
  127. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
  128. package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
  129. package/src/utils/pagination.ts +73 -0
  130. package/src/utils/pusher.ts +286 -0
  131. package/src/utils/schemaPropertyKeys.ts +433 -0
  132. package/src/utils/sdk.ts +110 -0
  133. package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
  134. package/src/utils/session.ts +114 -0
  135. package/src/utils/toolArguments.ts +73 -0
  136. package/src/utils/toolkitVersion.ts +26 -0
  137. package/src/utils/transform.ts +42 -0
  138. package/src/utils/transformers/authConfigs.ts +107 -0
  139. package/src/utils/transformers/connectedAccounts.ts +119 -0
  140. package/src/utils/transformers/mcp.ts +164 -0
  141. package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
  142. package/src/utils/transformers/toolkits.ts +100 -0
  143. package/src/utils/transformers/triggers.ts +118 -0
  144. package/src/utils/uploadDirAllowlist.node.ts +178 -0
  145. package/src/utils/uuid.ts +7 -0
  146. package/src/utils/version.ts +58 -0
  147. package/src/utils/zodSchema.ts +90 -0
@@ -0,0 +1,398 @@
1
+ /**
2
+ * @fileoverview Auth configs class for Composio SDK, used to manage authentication configurations.
3
+ *
4
+ * @author Musthaq Ahamad <musthaq@composio.dev>
5
+ * @date 2025-05-05
6
+ * @module AuthConfigs
7
+ */
8
+ import ComposioClient from '@composio/client';
9
+ import {
10
+ AuthConfigDeleteResponse,
11
+ AuthConfigUpdateResponse,
12
+ AuthConfigUpdateStatusResponse,
13
+ } from '@composio/client/resources/auth-configs';
14
+ import {
15
+ AuthConfigListParams,
16
+ AuthConfigListParamsSchema,
17
+ AuthConfigListResponse,
18
+ AuthConfigRetrieveResponse,
19
+ AuthConfigUpdateParams,
20
+ AuthConfigUpdateParamsSchema,
21
+ CreateAuthConfigParams,
22
+ CreateAuthConfigParamsSchema,
23
+ CreateAuthConfigResponse,
24
+ } from '../types/authConfigs.types';
25
+ import { ValidationError } from '../errors/ValidationErrors';
26
+ import { telemetry } from '../telemetry/Telemetry';
27
+ import {
28
+ transformAuthConfigListResponse,
29
+ transformAuthConfigRetrieveResponse,
30
+ transformCreateAuthConfigResponse,
31
+ } from '../utils/transformers/authConfigs';
32
+ import { ComposioRequestOptions } from '../types/requestOptions.types';
33
+ import { withCancellation } from '../utils/cancellation';
34
+ /**
35
+ * AuthConfigs class
36
+ *
37
+ * This class is used to manage authentication configurations in the Composio SDK.
38
+ * Auth configs are used to configure authentication providers and settings.
39
+ */
40
+ export class AuthConfigs {
41
+ private client: ComposioClient;
42
+
43
+ constructor(client: ComposioClient) {
44
+ this.client = client;
45
+ telemetry.instrument(this, 'AuthConfigs');
46
+ }
47
+
48
+ /**
49
+ * Protected getter for the client instance.
50
+ * This is primarily used for testing purposes.
51
+ * @protected
52
+ */
53
+ protected getClient(): ComposioClient {
54
+ return this.client;
55
+ }
56
+
57
+ /**
58
+ * Lists authentication configurations based on provided filter criteria.
59
+ *
60
+ * This method retrieves auth configs from the Composio API, transforms them to the SDK format,
61
+ * and supports filtering by various parameters.
62
+ *
63
+ * @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
64
+ * @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
65
+ * @throws {ValidationError} If the query parameters or response fail validation
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // List all auth configs
70
+ * const allConfigs = await composio.authConfigs.list();
71
+ *
72
+ * // List auth configs for a specific toolkit
73
+ * const githubConfigs = await composio.authConfigs.list({
74
+ * toolkit: 'github'
75
+ * });
76
+ *
77
+ * // Search auth configs by name or id
78
+ * const searchedConfigs = await composio.authConfigs.list({
79
+ * search: 'github',
80
+ * showDisabled: true
81
+ * });
82
+ *
83
+ * // List Composio-managed auth configs
84
+ * const managedConfigs = await composio.authConfigs.list({
85
+ * isComposioManaged: true
86
+ * });
87
+ * ```
88
+ */
89
+ async list(
90
+ query?: AuthConfigListParams,
91
+ requestOptions?: ComposioRequestOptions
92
+ ): Promise<AuthConfigListResponse> {
93
+ const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : undefined;
94
+ const listParams = {
95
+ cursor: parsedQuery?.cursor,
96
+ is_composio_managed: parsedQuery?.isComposioManaged,
97
+ limit: parsedQuery?.limit,
98
+ search: parsedQuery?.search,
99
+ show_disabled: parsedQuery?.showDisabled,
100
+ toolkit_slug: parsedQuery?.toolkit,
101
+ };
102
+ const result = await withCancellation(
103
+ () => this.client.authConfigs.list(listParams, requestOptions),
104
+ requestOptions?.signal
105
+ );
106
+ return transformAuthConfigListResponse(result);
107
+ }
108
+
109
+ /**
110
+ * Create a new auth config
111
+ * @param {string} toolkit - Unique identifier of the toolkit
112
+ * @param {CreateAuthConfigParams} options - Options for creating a new auth config
113
+ * @returns {Promise<CreateAuthConfigResponse>} Created auth config
114
+ *
115
+ * @example
116
+ * const authConfig = await authConfigs.create('my-toolkit', {
117
+ * type: AuthConfigTypes.CUSTOM,
118
+ * name: 'My Custom Auth Config',
119
+ * authScheme: AuthSchemeTypes.API_KEY,
120
+ * credentials: {
121
+ * apiKey: '1234567890',
122
+ * },
123
+ * });
124
+ *
125
+ * @link https://docs.composio.dev/reference/auth-configs/create-auth-config
126
+ */
127
+ async create(
128
+ toolkit: string,
129
+ options: CreateAuthConfigParams = { type: 'use_composio_managed_auth' },
130
+ requestOptions?: ComposioRequestOptions
131
+ ): Promise<CreateAuthConfigResponse> {
132
+ const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
133
+ if (parsedOptions.error) {
134
+ throw new ValidationError('Failed to parse auth config create options', {
135
+ cause: parsedOptions.error,
136
+ });
137
+ }
138
+ const createBody = {
139
+ toolkit: {
140
+ slug: toolkit,
141
+ },
142
+ auth_config:
143
+ parsedOptions.data.type === 'use_custom_auth'
144
+ ? {
145
+ type: parsedOptions.data.type,
146
+ name: parsedOptions.data.name,
147
+ authScheme: parsedOptions.data.authScheme,
148
+ credentials: parsedOptions.data.credentials,
149
+ is_enabled_for_tool_router: parsedOptions.data.isEnabledForToolRouter,
150
+ proxy_config: parsedOptions.data.proxyConfig
151
+ ? {
152
+ proxy_url: parsedOptions.data.proxyConfig.proxyUrl,
153
+ proxy_auth_key: parsedOptions.data.proxyConfig.proxyAuthKey,
154
+ }
155
+ : undefined,
156
+ tool_access_config: parsedOptions.data.toolAccessConfig
157
+ ? {
158
+ tools_for_connected_account_creation:
159
+ parsedOptions.data.toolAccessConfig.toolsForConnectedAccountCreation,
160
+ }
161
+ : undefined,
162
+ }
163
+ : {
164
+ type: parsedOptions.data.type,
165
+ credentials: parsedOptions.data.credentials,
166
+ name: parsedOptions.data.name,
167
+ is_enabled_for_tool_router: parsedOptions.data.isEnabledForToolRouter,
168
+ tool_access_config: parsedOptions.data.toolAccessConfig
169
+ ? {
170
+ tools_for_connected_account_creation:
171
+ parsedOptions.data.toolAccessConfig.toolsForConnectedAccountCreation,
172
+ }
173
+ : undefined,
174
+ },
175
+ };
176
+ const result = await withCancellation(
177
+ () => this.client.authConfigs.create(createBody, requestOptions),
178
+ requestOptions?.signal
179
+ );
180
+ return transformCreateAuthConfigResponse(result);
181
+ }
182
+
183
+ /**
184
+ * Retrieves a specific authentication configuration by its ID.
185
+ *
186
+ * This method fetches detailed information about a single auth config
187
+ * and transforms the response to the SDK's standardized format.
188
+ *
189
+ * @param {string} nanoid - The unique identifier of the auth config to retrieve
190
+ * @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
191
+ * @throws {Error} If the auth config cannot be found or an API error occurs
192
+ * @throws {ValidationError} If the response fails validation
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Get an auth config by ID
197
+ * const authConfig = await composio.authConfigs.get('auth_abc123');
198
+ * console.log(authConfig.name); // e.g., 'GitHub Auth'
199
+ * console.log(authConfig.toolkit.slug); // e.g., 'github'
200
+ * ```
201
+ */
202
+ async get(
203
+ nanoid: string,
204
+ requestOptions?: ComposioRequestOptions
205
+ ): Promise<AuthConfigRetrieveResponse> {
206
+ const result = await withCancellation(
207
+ () => this.client.authConfigs.retrieve(nanoid, requestOptions),
208
+ requestOptions?.signal
209
+ );
210
+ return transformAuthConfigRetrieveResponse(result);
211
+ }
212
+
213
+ /**
214
+ * Updates an existing authentication configuration.
215
+ *
216
+ * This method allows you to modify properties of an auth config such as credentials,
217
+ * scopes, or tool restrictions. The update type (custom or default) determines which
218
+ * fields can be updated.
219
+ *
220
+ * @param {string} nanoid - The unique identifier of the auth config to update
221
+ * @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
222
+ * @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
223
+ * @throws {ValidationError} If the update parameters are invalid
224
+ * @throws {Error} If the auth config cannot be found or updated
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * // Update a custom auth config with new credentials
229
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
230
+ * type: 'custom',
231
+ * credentials: {
232
+ * apiKey: 'new-api-key-value'
233
+ * }
234
+ * });
235
+ *
236
+ * // Update a default auth config with new scopes
237
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
238
+ * type: 'default',
239
+ * scopes: ['read:user', 'repo']
240
+ * });
241
+ * ```
242
+ */
243
+ async update(
244
+ nanoid: string,
245
+ data: AuthConfigUpdateParams,
246
+ requestOptions?: ComposioRequestOptions
247
+ ): Promise<AuthConfigUpdateResponse> {
248
+ const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
249
+ if (parsedData.error) {
250
+ throw new ValidationError('Failed to parse auth config update data', {
251
+ cause: parsedData.error,
252
+ });
253
+ }
254
+ const updateBody =
255
+ parsedData.data.type === 'custom'
256
+ ? {
257
+ type: 'custom' as const,
258
+ credentials: parsedData.data.credentials,
259
+ is_enabled_for_tool_router: parsedData.data.isEnabledForToolRouter,
260
+ tool_access_config: {
261
+ tools_for_connected_account_creation:
262
+ parsedData.data.toolAccessConfig?.toolsForConnectedAccountCreation,
263
+ tools_available_for_execution:
264
+ parsedData.data.toolAccessConfig?.toolsAvailableForExecution ??
265
+ parsedData.data.restrictToFollowingTools,
266
+ },
267
+ }
268
+ : {
269
+ type: 'default' as const,
270
+ scopes: parsedData.data.scopes,
271
+ is_enabled_for_tool_router: parsedData.data.isEnabledForToolRouter,
272
+ tool_access_config: {
273
+ tools_for_connected_account_creation:
274
+ parsedData.data.toolAccessConfig?.toolsForConnectedAccountCreation,
275
+ tools_available_for_execution:
276
+ parsedData.data.toolAccessConfig?.toolsAvailableForExecution ??
277
+ parsedData.data.restrictToFollowingTools,
278
+ },
279
+ };
280
+ return withCancellation(
281
+ () => this.client.authConfigs.update(nanoid, updateBody, requestOptions),
282
+ requestOptions?.signal
283
+ );
284
+ }
285
+
286
+ /**
287
+ * Deletes an authentication configuration.
288
+ *
289
+ * This method permanently removes an auth config from the Composio platform.
290
+ * This action cannot be undone and will prevent any connected accounts that use
291
+ * this auth config from functioning.
292
+ *
293
+ * @param {string} nanoid - The unique identifier of the auth config to delete
294
+ * @returns {Promise<AuthConfigDeleteResponse>} The deletion response
295
+ * @throws {Error} If the auth config doesn't exist or cannot be deleted
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * // Delete an auth config
300
+ * await composio.authConfigs.delete('auth_abc123');
301
+ * ```
302
+ */
303
+ async delete(
304
+ nanoid: string,
305
+ requestOptions?: ComposioRequestOptions
306
+ ): Promise<AuthConfigDeleteResponse> {
307
+ return withCancellation(
308
+ () => this.client.authConfigs.delete(nanoid, undefined, requestOptions),
309
+ requestOptions?.signal
310
+ );
311
+ }
312
+
313
+ /**
314
+ * Updates the status of an authentication configuration.
315
+ *
316
+ * This method allows you to enable or disable an auth config. When disabled,
317
+ * the auth config cannot be used to create new connected accounts or authenticate
318
+ * with third-party services.
319
+ *
320
+ * @param {string} status - The status to set ('ENABLED' or 'DISABLED')
321
+ * @param {string} nanoid - The unique identifier of the auth config
322
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
323
+ * @throws {Error} If the auth config cannot be found or the status cannot be updated
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // Disable an auth config
328
+ * await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
329
+ *
330
+ * // Enable an auth config
331
+ * await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
332
+ * ```
333
+ */
334
+ async updateStatus(
335
+ status: 'ENABLED' | 'DISABLED',
336
+ nanoid: string,
337
+ requestOptions?: ComposioRequestOptions
338
+ ): Promise<AuthConfigUpdateStatusResponse> {
339
+ return withCancellation(
340
+ () => this.client.authConfigs.updateStatus(status, { nanoid }, requestOptions),
341
+ requestOptions?.signal
342
+ );
343
+ }
344
+
345
+ /**
346
+ * Enables an authentication configuration.
347
+ *
348
+ * This is a convenience method that calls updateStatus with 'ENABLED'.
349
+ * When enabled, the auth config can be used to create new connected accounts
350
+ * and authenticate with third-party services.
351
+ *
352
+ * @param {string} nanoid - The unique identifier of the auth config to enable
353
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
354
+ * @throws {Error} If the auth config cannot be found or enabled
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * // Enable an auth config
359
+ * await composio.authConfigs.enable('auth_abc123');
360
+ * ```
361
+ */
362
+ async enable(
363
+ nanoid: string,
364
+ requestOptions?: ComposioRequestOptions
365
+ ): Promise<AuthConfigUpdateStatusResponse> {
366
+ return withCancellation(
367
+ () => this.client.authConfigs.updateStatus('ENABLED', { nanoid }, requestOptions),
368
+ requestOptions?.signal
369
+ );
370
+ }
371
+
372
+ /**
373
+ * Disables an authentication configuration.
374
+ *
375
+ * This is a convenience method that calls updateStatus with 'DISABLED'.
376
+ * When disabled, the auth config cannot be used to create new connected accounts
377
+ * or authenticate with third-party services, but existing connections may continue to work.
378
+ *
379
+ * @param {string} nanoid - The unique identifier of the auth config to disable
380
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
381
+ * @throws {Error} If the auth config cannot be found or disabled
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * // Disable an auth config
386
+ * await composio.authConfigs.disable('auth_abc123');
387
+ * ```
388
+ */
389
+ async disable(
390
+ nanoid: string,
391
+ requestOptions?: ComposioRequestOptions
392
+ ): Promise<AuthConfigUpdateStatusResponse> {
393
+ return withCancellation(
394
+ () => this.client.authConfigs.updateStatus('DISABLED', { nanoid }, requestOptions),
395
+ requestOptions?.signal
396
+ );
397
+ }
398
+ }
@@ -0,0 +1,206 @@
1
+ import { AuthSchemeTypes } from '../types/authConfigs.types';
2
+ import {
3
+ BaseConnectionFields,
4
+ ConnectionData,
5
+ ConnectionStatuses,
6
+ } from '../types/connectedAccountAuthStates.types';
7
+
8
+ export class AuthScheme {
9
+ /**
10
+ * Creates a ConnectionData object for OAuth2 authentication.
11
+ * When `access_token` is provided, status defaults to ACTIVE (token import).
12
+ * When omitted, status defaults to INITIALIZING (redirect-based OAuth flow).
13
+ * Pass an explicit `status` in params to override the auto-detected default.
14
+ * @param params The OAuth2 parameters
15
+ * @returns ConnectionData object
16
+ */
17
+ static OAuth2(
18
+ params: BaseConnectionFields & {
19
+ access_token?: string;
20
+ token_type?: string;
21
+ id_token?: string;
22
+ refresh_token?: string;
23
+ expires_in?: number;
24
+ scope?: string;
25
+ webhook_signature?: string;
26
+ authed_user?: {
27
+ access_token?: string;
28
+ scope?: string;
29
+ };
30
+ code_verifier?: string;
31
+ redirectUrl?: string;
32
+ callback_url?: string;
33
+ finalRedirectUri?: string;
34
+ error?: string;
35
+ error_description?: string;
36
+ expired_at?: string;
37
+ }
38
+ ): ConnectionData {
39
+ const hasToken = !!params.access_token;
40
+ return {
41
+ authScheme: AuthSchemeTypes.OAUTH2,
42
+ val: {
43
+ status: hasToken ? ConnectionStatuses.ACTIVE : ConnectionStatuses.INITIALIZING,
44
+ ...params,
45
+ },
46
+ } as ConnectionData;
47
+ }
48
+
49
+ /**
50
+ * Creates a ConnectionData object for OAuth1 authentication.
51
+ * When both `oauth_token` and `oauth_token_secret` are provided, status defaults to ACTIVE (token import).
52
+ * When either is omitted, status defaults to INITIALIZING (redirect-based OAuth flow).
53
+ * Pass an explicit `status` in params to override the auto-detected default.
54
+ * @param params The OAuth1 parameters
55
+ * @returns ConnectionData object
56
+ */
57
+ static OAuth1(
58
+ params: BaseConnectionFields & {
59
+ oauth_token?: string;
60
+ oauth_token_secret?: string;
61
+ consumer_key?: string;
62
+ redirectUrl?: string;
63
+ callback_url?: string;
64
+ error?: string;
65
+ error_description?: string;
66
+ expired_at?: string;
67
+ }
68
+ ): ConnectionData {
69
+ const hasTokens = !!params.oauth_token && !!params.oauth_token_secret;
70
+ return {
71
+ authScheme: AuthSchemeTypes.OAUTH1,
72
+ val: {
73
+ status: hasTokens ? ConnectionStatuses.ACTIVE : ConnectionStatuses.INITIALIZING,
74
+ ...params,
75
+ },
76
+ } as ConnectionData;
77
+ }
78
+
79
+ /**
80
+ * Creates a ConnectionData object for API Key authentication
81
+ * @param params The API key parameters
82
+ * @returns ConnectionData object
83
+ */
84
+ static APIKey(
85
+ params: BaseConnectionFields & { api_key?: string; generic_api_key?: string }
86
+ ): ConnectionData {
87
+ return {
88
+ authScheme: AuthSchemeTypes.API_KEY,
89
+ val: {
90
+ status: ConnectionStatuses.ACTIVE,
91
+ ...params,
92
+ },
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Creates a ConnectionData object for Basic authentication
98
+ * @param params The basic auth parameters
99
+ * @returns ConnectionData object
100
+ */
101
+ static Basic(
102
+ params: BaseConnectionFields & { username: string; password: string }
103
+ ): ConnectionData {
104
+ return {
105
+ authScheme: AuthSchemeTypes.BASIC,
106
+ val: {
107
+ status: ConnectionStatuses.ACTIVE,
108
+ ...params,
109
+ },
110
+ };
111
+ }
112
+
113
+ /**
114
+ * Creates a ConnectionData object for Bearer Token authentication
115
+ * @param params The bearer token parameters
116
+ * @returns ConnectionData object
117
+ */
118
+ static BearerToken(params: BaseConnectionFields & { token: string }): ConnectionData {
119
+ return {
120
+ authScheme: AuthSchemeTypes.BEARER_TOKEN,
121
+ val: {
122
+ status: ConnectionStatuses.ACTIVE,
123
+ ...params,
124
+ },
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Creates a ConnectionData object for Google Service Account authentication
130
+ * @param params The Google service account parameters
131
+ * @returns ConnectionData object
132
+ */
133
+ static GoogleServiceAccount(
134
+ params: BaseConnectionFields & { credentials_json: string }
135
+ ): ConnectionData {
136
+ return {
137
+ authScheme: AuthSchemeTypes.GOOGLE_SERVICE_ACCOUNT,
138
+ val: {
139
+ status: ConnectionStatuses.ACTIVE,
140
+ ...params,
141
+ },
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Creates a ConnectionData object for No Auth authentication
147
+ * @returns ConnectionData object
148
+ */
149
+ static NoAuth(params?: BaseConnectionFields): ConnectionData {
150
+ return {
151
+ authScheme: AuthSchemeTypes.NO_AUTH,
152
+ val: {
153
+ status: ConnectionStatuses.ACTIVE,
154
+ ...(params ?? {}),
155
+ },
156
+ };
157
+ }
158
+
159
+ /**
160
+ * Creates a ConnectionData object for Basic with JWT authentication
161
+ * @param params The basic with JWT parameters
162
+ * @returns ConnectionData object
163
+ */
164
+ static BasicWithJWT(
165
+ params: BaseConnectionFields & { username: string; password: string }
166
+ ): ConnectionData {
167
+ return {
168
+ authScheme: AuthSchemeTypes.BASIC_WITH_JWT,
169
+ val: {
170
+ status: ConnectionStatuses.ACTIVE,
171
+ ...params,
172
+ },
173
+ };
174
+ }
175
+
176
+ /**
177
+ * Creates a ConnectionData object for Cal.com authentication
178
+ * @returns ConnectionData object
179
+ */
180
+ static CalcomAuth(params?: BaseConnectionFields): ConnectionData {
181
+ return {
182
+ authScheme: AuthSchemeTypes.CALCOM_AUTH,
183
+ val: {
184
+ status: ConnectionStatuses.ACTIVE,
185
+ ...(params ?? {}),
186
+ },
187
+ };
188
+ }
189
+
190
+ /**
191
+ * Creates a ConnectionData object for Bill.com authentication
192
+ * @param params The Bill.com auth parameters
193
+ * @returns ConnectionData object
194
+ */
195
+ static BillcomAuth(
196
+ params: BaseConnectionFields & { sessionId: string; devKey: string }
197
+ ): ConnectionData {
198
+ return {
199
+ authScheme: AuthSchemeTypes.BILLCOM_AUTH,
200
+ val: {
201
+ status: ConnectionStatuses.ACTIVE,
202
+ ...params,
203
+ },
204
+ };
205
+ }
206
+ }