@devries-cameron20 / composio Mirror · read-only / commits / 558c2054c
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 08:30 UTC

refactor(cli): move the `auth-configs` commands into the directory shape (#4990)

This PR: - moves `dev auth-configs list`, `info` and `create` from `auth-configs/commands/` to `auth-configs/<name>/auth-configs.<name>.{cmd,handler,format}.ts`, splitting the group's `format.ts` into one formatter per command; `auth-configs/commands/` is gone - turns `create`'s mutable request building into two pure functions, `parseScopes` and `buildAuthConfigCreateRequest` (an `Option.match` on `--auth-scheme`); `list` picks the next-step ID with `Array.head` instead of a truthiness check - moves the three suites to their mirrored paths and adds a handler test per command: stdout JSON, exit codes (0 on a missing `<id>` or bad `--custom-credentials`, 1 on an API failure), no request before validation, the `--limit` clamp, and a table for the create request shapes - adds `AuthConfigsHandlerTest` (`test/__utils__/layers/auth-configs.ts`) and `makeAuthConfigItem` for those tests - part of the CLI command-layout series (legacy-shape cleanup before U10); no user-visible change, so no CHANGELOG entry ## Context Verified: `pnpm --filter @composio/cli test` (190 files, 2060 passed; `validate:command-tests` still at 2 exemptions), CLI `typecheck`, `lint:effect`, oxlint, prettier, root `pnpm typecheck`; handler tests also pass with `CI=true` (ID redaction on). Binary smoke against an `origin/next` build: `--help` for `dev`, `dev auth-configs` and each subcommand, plus logged-out `list`, `info`, `info ac_x`, `create`, `create --toolkit gmail` and `list --limit abc`, have byte-identical stdout and stderr and the same exit codes.

Alberto Schiabel committed Oct 20, 2026 at 18:59 UTC 558c2054cb2eb4cc54796ba7abd14ec92764153a
21 files changed +809 -293
ts/packages/cli/src/commands/auth-configs/auth-configs.cmd.ts
+3 -3
@@ -1,8 +1,8 @@
1 import { requireLogin } from 'src/effects/require-auth';
2 import { Command } from 'effect/cli';
3 -import { authConfigsCmd$List } from './commands/auth-configs.list.cmd';
4 -import { authConfigsCmd$Info } from './commands/auth-configs.info.cmd';
5 -import { authConfigsCmd$Create } from './commands/auth-configs.create.cmd';
3 +import { authConfigsCmd$List } from './list/auth-configs.list.cmd';
4 +import { authConfigsCmd$Info } from './info/auth-configs.info.cmd';
5 +import { authConfigsCmd$Create } from './create/auth-configs.create.cmd';
6
7 /**
8 * CLI entry point for auth config management commands.
ts/packages/cli/src/commands/auth-configs/commands/auth-configs.create.cmd.ts deleted
-146
@@ -1,146 +0,0 @@
1 -import { Effect, Option, Result } from 'effect';
2 -import { Argument, Command, Flag } from 'effect/cli';
3 -import type { AuthConfigCreateParams } from '@composio/client/resources/auth-configs';
4 -import { parseJsonRecord } from 'src/utils/parse-json';
5 -import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 -import { TerminalUI } from 'src/services/terminal-ui';
7 -import { handleClientApiError } from 'src/effects/handle-http-error';
8 -import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
9 -import { redact } from 'src/ui/redact';
10 -import { formatAuthConfigCreated } from '../format';
11 -
12 -const name = Argument.String('name').pipe(
13 - Argument.withDescription('Display name for the auth config'),
14 - Argument.optional
15 -);
16 -
17 -const toolkit = Flag.String('toolkit').pipe(Flag.withDescription('Toolkit slug (e.g. "gmail")'));
18 -
19 -const authScheme = Flag.String('auth-scheme').pipe(
20 - Flag.withDescription(
21 - 'Auth scheme (e.g. OAUTH2, API_KEY, BEARER_TOKEN). If omitted, uses Composio managed defaults.'
22 - ),
23 - Flag.optional
24 -);
25 -
26 -const scopes = Flag.String('scopes').pipe(
27 - Flag.withDescription('Comma-separated scopes (OAuth only, e.g. "send_email,read_email")'),
28 - Flag.optional
29 -);
30 -
31 -const customCredentials = Flag.String('custom-credentials').pipe(
32 - Flag.withDescription('Custom credentials as JSON string (for white-labeling)'),
33 - Flag.optional
34 -);
35 -
36 -/**
37 - * Create a new auth config.
38 - *
39 - * @example
40 - * ```bash
41 - * # Composio-managed defaults
42 - * composio dev auth-configs create "my-gmail-config" --toolkit "gmail"
43 - *
44 - * # Custom auth with specific scheme
45 - * composio dev auth-configs create "custom-gmail" --toolkit "gmail" --auth-scheme "OAUTH2" --scopes "send_email"
46 - *
47 - * # White-labeling with custom credentials
48 - * composio dev auth-configs create "custom-gmail" --toolkit "gmail" --auth-scheme "OAUTH2" --custom-credentials '{"client_id":"...","client_secret":"..."}'
49 - * ```
50 - */
51 -export const authConfigsCmd$Create = Command.make(
52 - 'create',
53 - { name, toolkit, authScheme, scopes, customCredentials },
54 - ({ name, toolkit, authScheme, scopes, customCredentials }) =>
55 - Effect.gen(function* () {
56 - const ui = yield* TerminalUI;
57 - const repo = yield* ComposioToolkitsRepository;
58 -
59 - // Parse custom credentials JSON if provided
60 - let parsedCustomCredentials: Record<string, unknown> | undefined;
61 - if (Option.isSome(customCredentials)) {
62 - const parsed = parseJsonRecord(customCredentials.value);
63 - if (Result.isFailure(parsed)) {
64 - yield* ui.log.error('Invalid JSON in --custom-credentials. Please provide valid JSON.');
65 - yield* ui.log.step(
66 - 'Example:\n> composio dev auth-configs create "name" --toolkit "gmail" --custom-credentials \'{"client_id":"...","client_secret":"..."}\''
67 - );
68 - return;
69 - }
70 - parsedCustomCredentials = parsed.success;
71 - }
72 -
73 - // Parse scopes into array
74 - const scopesList = Option.getOrUndefined(
75 - Option.map(scopes, value =>
76 - value
77 - .split(',')
78 - .map(s => s.trim())
79 - .filter(Boolean)
80 - )
81 - );
82 -
83 - // Build create params based on whether auth scheme is provided
84 - const nameValue = Option.getOrUndefined(name);
85 - let params: AuthConfigCreateParams;
86 -
87 - if (Option.isSome(authScheme)) {
88 - // Custom credentials must be nested under `credentials` for the API to accept them.
89 - params = {
90 - toolkit: { slug: toolkit },
91 - auth_config: {
92 - type: 'use_custom_auth' as const,
93 - authScheme: authScheme.value as AuthConfigCreateParams.UnionMember1['authScheme'],
94 - name: nameValue,
95 - credentials:
96 - parsedCustomCredentials || scopesList
97 - ? {
98 - ...(parsedCustomCredentials ?? {}),
99 - ...(scopesList ? { scopes: scopesList } : {}),
100 - }
101 - : undefined,
102 - },
103 - };
104 - } else {
105 - // Composio managed mode
106 - params = {
107 - toolkit: { slug: toolkit },
108 - auth_config: {
109 - type: 'use_composio_managed_auth' as const,
110 - name: nameValue,
111 - credentials: scopesList ? { scopes: scopesList } : undefined,
112 - },
113 - };
114 - }
115 -
116 - const resultOpt = yield* ui
117 - .withSpinner('Creating auth config...', repo.createAuthConfig(params))
118 - .pipe(
119 - Effect.asSome,
120 - Effect.catchTag(
121 - CLIENT_API_ERROR_TAGS,
122 - handleClientApiError(ui, {
123 - fallbackMessage: 'Failed to create auth config.',
124 - hint: `Check available auth schemes for "${toolkit}":\n> composio dev toolkits info "${toolkit}"`,
125 - fallbackValue: Option.none(),
126 - })
127 - )
128 - );
129 -
130 - if (Option.isNone(resultOpt)) {
131 - return;
132 - }
133 -
134 - const result = resultOpt.value;
135 -
136 - yield* ui.log.success('Auth config created.');
137 - yield* ui.note(formatAuthConfigCreated(result), 'New Auth Config');
138 -
139 - const redactedId = redact({ value: result.auth_config.id, prefix: 'ac_' });
140 -
141 - // Next step hint
142 - yield* ui.log.step(`To view details:\n> composio dev auth-configs info "${redactedId}"`);
143 -
144 - yield* ui.output(JSON.stringify(result, null, 2));
145 - })
146 -).pipe(Command.withDescription('Create a new auth config.'));
ts/packages/cli/src/commands/auth-configs/commands/auth-configs.list.cmd.ts deleted
-80
@@ -1,80 +0,0 @@
1 -import { Effect, Option } from 'effect';
2 -import { Command, Flag } from 'effect/cli';
3 -import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { clampLimit } from 'src/ui/clamp-limit';
6 -import { redact } from 'src/ui/redact';
7 -import { formatAuthConfigsTable, formatAuthConfigsJson } from '../format';
8 -
9 -const toolkits = Flag.String('toolkits').pipe(
10 - Flag.withDescription('Filter by toolkit slugs, comma-separated (e.g. "gmail" or "gmail,slack")'),
11 - Flag.optional
12 -);
13 -
14 -const query = Flag.String('query').pipe(
15 - Flag.withDescription('Search by auth config name'),
16 - Flag.optional
17 -);
18 -
19 -const limit = Flag.Int('limit').pipe(
20 - Flag.withDefault(30),
21 - Flag.withDescription('Number of results per page (1-1000)')
22 -);
23 -
24 -/**
25 - * List auth configs with optional filters.
26 - *
27 - * @example
28 - * ```bash
29 - * composio dev auth-configs list
30 - * composio dev auth-configs list --toolkits "gmail"
31 - * composio dev auth-configs list --query "my config" --limit 10
32 - * ```
33 - */
34 -export const authConfigsCmd$List = Command.make(
35 - 'list',
36 - { toolkits, query, limit },
37 - ({ toolkits, query, limit }) =>
38 - Effect.gen(function* () {
39 - const ui = yield* TerminalUI;
40 - const repo = yield* ComposioToolkitsRepository;
41 -
42 - const result = yield* ui.withSpinner(
43 - 'Fetching auth configs...',
44 - repo.listAuthConfigs({
45 - search: Option.getOrUndefined(query),
46 - toolkit_slug: Option.getOrUndefined(toolkits),
47 - limit: clampLimit(limit),
48 - })
49 - );
50 -
51 - if (result.items.length === 0) {
52 - const hint = Option.match(toolkits, {
53 - onNone: () => 'No auth configs found. Try broadening your search.',
54 - onSome: toolkit =>
55 - `No auth configs found for toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`,
56 - });
57 - yield* ui.log.warn(hint);
58 - return;
59 - }
60 -
61 - const showing = result.items.length;
62 - const total = result.total_items;
63 -
64 - yield* ui.log.info(
65 - `Listing ${showing} of ${total} auth configs\n\n${formatAuthConfigsTable(result.items)}`
66 - );
67 -
68 - // Next step hint
69 - const firstId = result.items[0]?.id;
70 - const redactedId = redact({ value: firstId, prefix: 'ac_' });
71 -
72 - if (firstId) {
73 - yield* ui.log.step(
74 - `To view details of an auth config:\n> composio dev auth-configs info "${redactedId}"`
75 - );
76 - }
77 -
78 - yield* ui.output(formatAuthConfigsJson(result.items));
79 - })
80 -).pipe(Command.withDescription('List auth configs.'));
ts/packages/cli/src/commands/auth-configs/create/auth-configs.create.cmd.ts new
+47
@@ -0,0 +1,47 @@
1 +import { Argument, Command, Flag } from 'effect/cli';
2 +import { runAuthConfigsCreate } from './auth-configs.create.handler';
3 +
4 +const name = Argument.String('name').pipe(
5 + Argument.withDescription('Display name for the auth config'),
6 + Argument.optional
7 +);
8 +
9 +const toolkit = Flag.String('toolkit').pipe(Flag.withDescription('Toolkit slug (e.g. "gmail")'));
10 +
11 +const authScheme = Flag.String('auth-scheme').pipe(
12 + Flag.withDescription(
13 + 'Auth scheme (e.g. OAUTH2, API_KEY, BEARER_TOKEN). If omitted, uses Composio managed defaults.'
14 + ),
15 + Flag.optional
16 +);
17 +
18 +const scopes = Flag.String('scopes').pipe(
19 + Flag.withDescription('Comma-separated scopes (OAuth only, e.g. "send_email,read_email")'),
20 + Flag.optional
21 +);
22 +
23 +const customCredentials = Flag.String('custom-credentials').pipe(
24 + Flag.withDescription('Custom credentials as JSON string (for white-labeling)'),
25 + Flag.optional
26 +);
27 +
28 +/**
29 + * Create a new auth config.
30 + *
31 + * @example
32 + * ```bash
33 + * # Composio-managed defaults
34 + * composio dev auth-configs create "my-gmail-config" --toolkit "gmail"
35 + *
36 + * # Custom auth with specific scheme
37 + * composio dev auth-configs create "custom-gmail" --toolkit "gmail" --auth-scheme "OAUTH2" --scopes "send_email"
38 + *
39 + * # White-labeling with custom credentials
40 + * composio dev auth-configs create "custom-gmail" --toolkit "gmail" --auth-scheme "OAUTH2" --custom-credentials '{"client_id":"...","client_secret":"..."}'
41 + * ```
42 + */
43 +export const authConfigsCmd$Create = Command.make(
44 + 'create',
45 + { name, toolkit, authScheme, scopes, customCredentials },
46 + runAuthConfigsCreate
47 +).pipe(Command.withDescription('Create a new auth config.'));
ts/packages/cli/src/commands/auth-configs/create/auth-configs.create.format.ts new
+19
@@ -0,0 +1,19 @@
1 +import type { AuthConfigCreateResponse } from '@composio/client/resources/auth-configs';
2 +import { bold } from 'src/ui/colors';
3 +import { redact } from 'src/ui/redact';
4 +
5 +/**
6 + * Format a create auth config response for interactive display.
7 + */
8 +export function formatAuthConfigCreated(result: AuthConfigCreateResponse): string {
9 + const lines: string[] = [];
10 +
11 + lines.push(`${bold('Id:')} ${redact({ value: result.auth_config.id, prefix: 'ac_' })}`);
12 + lines.push(`${bold('Auth Scheme:')} ${result.auth_config.auth_scheme}`);
13 + lines.push(`${bold('Toolkit:')} ${result.toolkit.slug}`);
14 + lines.push(
15 + `${bold('Composio Managed:')} ${result.auth_config.is_composio_managed ? 'Yes' : 'No'}`
16 + );
17 +
18 + return lines.join('\n');
19 +}
ts/packages/cli/src/commands/auth-configs/create/auth-configs.create.handler.ts new
+136
@@ -0,0 +1,136 @@
1 +import type { AuthConfigCreateParams as AuthConfigCreateRequest } from '@composio/client/resources/auth-configs';
2 +import { Effect, Option, Result } from 'effect';
3 +import { handleClientApiError } from 'src/effects/handle-http-error';
4 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 +import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
6 +import { TerminalUI } from 'src/services/terminal-ui';
7 +import { redact } from 'src/ui/redact';
8 +import { parseJsonRecord } from 'src/utils/parse-json';
9 +import { formatAuthConfigCreated } from './auth-configs.create.format';
10 +
11 +export type AuthConfigsCreateParams = {
12 + readonly name: Option.Option<string>;
13 + readonly toolkit: string;
14 + readonly authScheme: Option.Option<string>;
15 + readonly scopes: Option.Option<string>;
16 + readonly customCredentials: Option.Option<string>;
17 +};
18 +
19 +/** `--custom-credentials` as a record, `undefined` when the flag is absent. */
20 +const parseCustomCredentials = (customCredentials: Option.Option<string>) =>
21 + Option.match(customCredentials, {
22 + onNone: () => Result.succeed(undefined),
23 + onSome: parseJsonRecord,
24 + });
25 +
26 +/** `--scopes` split on commas with blanks dropped, `undefined` when the flag is absent. */
27 +export const parseScopes = (scopes: Option.Option<string>): Array<string> | undefined =>
28 + Option.getOrUndefined(
29 + Option.map(scopes, value =>
30 + value
31 + .split(',')
32 + .map(s => s.trim())
33 + .filter(Boolean)
34 + )
35 + );
36 +
37 +/**
38 + * The create request: Composio-managed auth without `--auth-scheme`, custom auth with it. Custom
39 + * credentials and scopes go under `credentials`, the only place the API accepts them; managed
40 + * auth carries only the scopes.
41 + */
42 +export const buildAuthConfigCreateRequest = (input: {
43 + readonly name: string | undefined;
44 + readonly toolkit: string;
45 + readonly authScheme: Option.Option<string>;
46 + readonly scopes: Array<string> | undefined;
47 + readonly customCredentials: Record<string, unknown> | undefined;
48 +}): AuthConfigCreateRequest =>
49 + Option.match(input.authScheme, {
50 + onNone: () => ({
51 + toolkit: { slug: input.toolkit },
52 + auth_config: {
53 + type: 'use_composio_managed_auth' as const,
54 + name: input.name,
55 + credentials: input.scopes ? { scopes: input.scopes } : undefined,
56 + },
57 + }),
58 + onSome: authScheme => ({
59 + toolkit: { slug: input.toolkit },
60 + auth_config: {
61 + type: 'use_custom_auth' as const,
62 + // The API validates the scheme and answers an unknown one with its own error and hint.
63 + authScheme: authScheme as AuthConfigCreateRequest.UnionMember1['authScheme'],
64 + name: input.name,
65 + credentials:
66 + input.customCredentials || input.scopes
67 + ? {
68 + ...(input.customCredentials ?? {}),
69 + ...(input.scopes ? { scopes: input.scopes } : {}),
70 + }
71 + : undefined,
72 + },
73 + }),
74 + });
75 +
76 +/**
77 + * Create an auth config: the summary on stderr, the API response as JSON on stdout. Invalid
78 + * `--custom-credentials` JSON is reported before any request and exits 0; an API failure is
79 + * reported with a hint and exits 1.
80 + */
81 +export const runAuthConfigsCreate = ({
82 + name,
83 + toolkit,
84 + authScheme,
85 + scopes,
86 + customCredentials,
87 +}: AuthConfigsCreateParams) =>
88 + Effect.gen(function* () {
89 + const ui = yield* TerminalUI;
90 + const repo = yield* ComposioToolkitsRepository;
91 +
92 + const parsedCustomCredentials = parseCustomCredentials(customCredentials);
93 + if (Result.isFailure(parsedCustomCredentials)) {
94 + yield* ui.log.error('Invalid JSON in --custom-credentials. Please provide valid JSON.');
95 + yield* ui.log.step(
96 + 'Example:\n> composio dev auth-configs create "name" --toolkit "gmail" --custom-credentials \'{"client_id":"...","client_secret":"..."}\''
97 + );
98 + return;
99 + }
100 +
101 + const request = buildAuthConfigCreateRequest({
102 + name: Option.getOrUndefined(name),
103 + toolkit,
104 + authScheme,
105 + scopes: parseScopes(scopes),
106 + customCredentials: parsedCustomCredentials.success,
107 + });
108 +
109 + const resultOpt = yield* ui
110 + .withSpinner('Creating auth config...', repo.createAuthConfig(request))
111 + .pipe(
112 + Effect.asSome,
113 + Effect.catchTag(
114 + CLIENT_API_ERROR_TAGS,
115 + handleClientApiError(ui, {
116 + fallbackMessage: 'Failed to create auth config.',
117 + hint: `Check available auth schemes for "${toolkit}":\n> composio dev toolkits info "${toolkit}"`,
118 + fallbackValue: Option.none(),
119 + })
120 + )
121 + );
122 +
123 + if (Option.isNone(resultOpt)) {
124 + return;
125 + }
126 +
127 + const result = resultOpt.value;
128 +
129 + yield* ui.log.success('Auth config created.');
130 + yield* ui.note(formatAuthConfigCreated(result), 'New Auth Config');
131 +
132 + const redactedId = redact({ value: result.auth_config.id, prefix: 'ac_' });
133 + yield* ui.log.step(`To view details:\n> composio dev auth-configs info "${redactedId}"`);
134 +
135 + yield* ui.output(JSON.stringify(result, null, 2));
136 + });
ts/packages/cli/src/commands/auth-configs/info/auth-configs.info.cmd.ts new
+19
@@ -0,0 +1,19 @@
1 +import { Argument, Command } from 'effect/cli';
2 +import { runAuthConfigsInfo } from './auth-configs.info.handler';
3 +
4 +const id = Argument.String('id').pipe(
5 + Argument.withDescription('Auth config ID (nanoid)'),
6 + Argument.optional
7 +);
8 +
9 +/**
10 + * View details of a specific auth config.
11 + *
12 + * @example
13 + * ```bash
14 + * composio dev auth-configs info "ac_1232323"
15 + * ```
16 + */
17 +export const authConfigsCmd$Info = Command.make('info', { id }, runAuthConfigsInfo).pipe(
18 + Command.withDescription('View details of a specific auth config.')
19 +);
ts/packages/cli/src/commands/auth-configs/info/auth-configs.info.format.ts new
+26
@@ -0,0 +1,26 @@
1 +import type { AuthConfigItem } from 'src/models/auth-configs';
2 +import { bold } from 'src/ui/colors';
3 +import { redact } from 'src/ui/redact';
4 +
5 +/**
6 + * Format a single auth config for interactive display.
7 + */
8 +export function formatAuthConfigInfo(item: AuthConfigItem): string {
9 + const lines: string[] = [];
10 +
11 + lines.push(`${bold('Id:')} ${redact({ value: item.id, prefix: 'ac_' })}`);
12 + lines.push(`${bold('Name:')} ${item.name}`);
13 + lines.push(`${bold('Toolkit:')} ${item.toolkit.slug}`);
14 + lines.push(`${bold('Auth Scheme:')} ${item.auth_scheme || '(none)'}`);
15 + lines.push(`${bold('Type:')} ${item.type}`);
16 + lines.push(`${bold('Status:')} ${item.status}`);
17 + lines.push(`${bold('Composio Managed:')} ${item.is_composio_managed ? 'Yes' : 'No'}`);
18 + lines.push(`${bold('Tool Router:')} ${item.is_enabled_for_tool_router ? 'Enabled' : 'Disabled'}`);
19 + lines.push(`${bold('Connected Accounts:')} ${item.no_of_connections}`);
20 +
21 + if (item.created_at) {
22 + lines.push(`${bold('Created:')} ${item.created_at}`);
23 + }
24 +
25 + return lines.join('\n');
26 +}
ts/packages/cli/src/commands/auth-configs/info/auth-configs.info.handler.ts renamed
+10 -18
@@ -1,30 +1,23 @@
1 import { Effect, Option } from 'effect';
2 -import { Argument, Command } from 'effect/cli';
3 -import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 -import { TerminalUI } from 'src/services/terminal-ui';
2 import { handleClientApiError } from 'src/effects/handle-http-error';
3 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
7 -import { formatAuthConfigInfo } from '../format';
5 +import { TerminalUI } from 'src/services/terminal-ui';
6 +import { formatAuthConfigInfo } from './auth-configs.info.format';
7
9 -const id = Argument.String('id').pipe(
10 - Argument.withDescription('Auth config ID (nanoid)'),
11 - Argument.optional
12 -);
8 +export type AuthConfigsInfoParams = {
9 + readonly id: Option.Option<string>;
10 +};
11
12 /**
15 - * View details of a specific auth config.
16 - *
17 - * @example
18 - * ```bash
19 - * composio dev auth-configs info "ac_1232323"
20 - * ```
13 + * Show one auth config: the details on stderr, the JSON on stdout. A missing `<id>` warns and
14 + * exits 0; an API failure is reported with a hint and exits 1.
15 */
22 -export const authConfigsCmd$Info = Command.make('info', { id }, ({ id }) =>
16 +export const runAuthConfigsInfo = ({ id }: AuthConfigsInfoParams) =>
17 Effect.gen(function* () {
18 const ui = yield* TerminalUI;
19 const repo = yield* ComposioToolkitsRepository;
20
27 - // Missing ID guard
21 if (Option.isNone(id)) {
22 yield* ui.log.warn('Missing required argument: <id>');
23 yield* ui.log.step(
@@ -59,5 +52,4 @@ export const authConfigsCmd$Info = Command.make('info', { id }, ({ id }) =>
52 yield* ui.note(formatAuthConfigInfo(item), `Auth Config: ${item.name}`);
53
54 yield* ui.output(JSON.stringify(item, null, 2));
62 - })
63 -).pipe(Command.withDescription('View details of a specific auth config.'));
55 + });
ts/packages/cli/src/commands/auth-configs/list/auth-configs.list.cmd.ts new
+33
@@ -0,0 +1,33 @@
1 +import { Command, Flag } from 'effect/cli';
2 +import { runAuthConfigsList } from './auth-configs.list.handler';
3 +
4 +const toolkits = Flag.String('toolkits').pipe(
5 + Flag.withDescription('Filter by toolkit slugs, comma-separated (e.g. "gmail" or "gmail,slack")'),
6 + Flag.optional
7 +);
8 +
9 +const query = Flag.String('query').pipe(
10 + Flag.withDescription('Search by auth config name'),
11 + Flag.optional
12 +);
13 +
14 +const limit = Flag.Int('limit').pipe(
15 + Flag.withDefault(30),
16 + Flag.withDescription('Number of results per page (1-1000)')
17 +);
18 +
19 +/**
20 + * List auth configs with optional filters.
21 + *
22 + * @example
23 + * ```bash
24 + * composio dev auth-configs list
25 + * composio dev auth-configs list --toolkits "gmail"
26 + * composio dev auth-configs list --query "my config" --limit 10
27 + * ```
28 + */
29 +export const authConfigsCmd$List = Command.make(
30 + 'list',
31 + { toolkits, query, limit },
32 + runAuthConfigsList
33 +).pipe(Command.withDescription('List auth configs.'));
ts/packages/cli/src/commands/auth-configs/list/auth-configs.list.format.ts renamed
-40
@@ -1,5 +1,4 @@
1 import type { AuthConfigItem } from 'src/models/auth-configs';
2 -import type { AuthConfigCreateResponse } from '@composio/client/resources/auth-configs';
2 import { bold, gray } from 'src/ui/colors';
3 import { redact } from 'src/ui/redact';
4 import { truncate } from 'src/ui/truncate';
@@ -43,42 +42,3 @@ export function formatAuthConfigsJson(items: ReadonlyArray<AuthConfigItem>): str
42 2
43 );
44 }
46 -
47 -/**
48 - * Format a single auth config for interactive display.
49 - */
50 -export function formatAuthConfigInfo(item: AuthConfigItem): string {
51 - const lines: string[] = [];
52 -
53 - lines.push(`${bold('Id:')} ${redact({ value: item.id, prefix: 'ac_' })}`);
54 - lines.push(`${bold('Name:')} ${item.name}`);
55 - lines.push(`${bold('Toolkit:')} ${item.toolkit.slug}`);
56 - lines.push(`${bold('Auth Scheme:')} ${item.auth_scheme || '(none)'}`);
57 - lines.push(`${bold('Type:')} ${item.type}`);
58 - lines.push(`${bold('Status:')} ${item.status}`);
59 - lines.push(`${bold('Composio Managed:')} ${item.is_composio_managed ? 'Yes' : 'No'}`);
60 - lines.push(`${bold('Tool Router:')} ${item.is_enabled_for_tool_router ? 'Enabled' : 'Disabled'}`);
61 - lines.push(`${bold('Connected Accounts:')} ${item.no_of_connections}`);
62 -
63 - if (item.created_at) {
64 - lines.push(`${bold('Created:')} ${item.created_at}`);
65 - }
66 -
67 - return lines.join('\n');
68 -}
69 -
70 -/**
71 - * Format a create auth config response for interactive display.
72 - */
73 -export function formatAuthConfigCreated(result: AuthConfigCreateResponse): string {
74 - const lines: string[] = [];
75 -
76 - lines.push(`${bold('Id:')} ${redact({ value: result.auth_config.id, prefix: 'ac_' })}`);
77 - lines.push(`${bold('Auth Scheme:')} ${result.auth_config.auth_scheme}`);
78 - lines.push(`${bold('Toolkit:')} ${result.toolkit.slug}`);
79 - lines.push(
80 - `${bold('Composio Managed:')} ${result.auth_config.is_composio_managed ? 'Yes' : 'No'}`
81 - );
82 -
83 - return lines.join('\n');
84 -}
ts/packages/cli/src/commands/auth-configs/list/auth-configs.list.handler.ts new
+61
@@ -0,0 +1,61 @@
1 +import { Array as Arr, Effect, Option, String } from 'effect';
2 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
3 +import { TerminalUI } from 'src/services/terminal-ui';
4 +import { clampLimit } from 'src/ui/clamp-limit';
5 +import { redact } from 'src/ui/redact';
6 +import { formatAuthConfigsJson, formatAuthConfigsTable } from './auth-configs.list.format';
7 +
8 +export type AuthConfigsListParams = {
9 + readonly toolkits: Option.Option<string>;
10 + readonly query: Option.Option<string>;
11 + readonly limit: number;
12 +};
13 +
14 +/**
15 + * List auth configs, filtered by toolkit and name: the table on stderr, the JSON on stdout.
16 + */
17 +export const runAuthConfigsList = ({ toolkits, query, limit }: AuthConfigsListParams) =>
18 + Effect.gen(function* () {
19 + const ui = yield* TerminalUI;
20 + const repo = yield* ComposioToolkitsRepository;
21 +
22 + const result = yield* ui.withSpinner(
23 + 'Fetching auth configs...',
24 + repo.listAuthConfigs({
25 + search: Option.getOrUndefined(query),
26 + toolkit_slug: Option.getOrUndefined(toolkits),
27 + limit: clampLimit(limit),
28 + })
29 + );
30 +
31 + if (result.items.length === 0) {
32 + const hint = Option.match(toolkits, {
33 + onNone: () => 'No auth configs found. Try broadening your search.',
34 + onSome: toolkit =>
35 + `No auth configs found for toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`,
36 + });
37 + yield* ui.log.warn(hint);
38 + return;
39 + }
40 +
41 + const showing = result.items.length;
42 + const total = result.total_items;
43 +
44 + yield* ui.log.info(
45 + `Listing ${showing} of ${total} auth configs\n\n${formatAuthConfigsTable(result.items)}`
46 + );
47 +
48 + const firstId = Arr.head(result.items).pipe(
49 + Option.map(item => item.id),
50 + Option.filter(String.isNonEmpty)
51 + );
52 + yield* Option.match(firstId, {
53 + onNone: () => Effect.void,
54 + onSome: id =>
55 + ui.log.step(
56 + `To view details of an auth config:\n> composio dev auth-configs info "${redact({ value: id, prefix: 'ac_' })}"`
57 + ),
58 + });
59 +
60 + yield* ui.output(formatAuthConfigsJson(result.items));
61 + });
ts/packages/cli/test/__utils__/layers/auth-configs.ts new
+58
@@ -0,0 +1,58 @@
1 +import { Console, Effect, Layer } from 'effect';
2 +import {
3 + ComposioToolkitsRepository,
4 + type ComposioToolkitsRepositoryShape,
5 +} from 'src/services/composio-clients';
6 +import { TerminalUI } from 'src/services/terminal-ui';
7 +import * as MockConsole from '../services/mock-console';
8 +import { recordingNodeProcess } from '../services/node-process-test';
9 +import { makeToolkitsRepositoryStub } from '../services/toolkits-repository-stub';
10 +import {
11 + authConfigRepositoryMethods,
12 + resolveAuthConfigsTestData,
13 + type AuthConfigsTestData,
14 +} from './connected-accounts';
15 +import { terminalUITestImpl } from '../services/terminal-ui-test';
16 +
17 +/** What an `auth-configs` handler test serves. */
18 +export interface AuthConfigsHandlerFixture {
19 + /** The auth configs the repository answers from, as `TestLive` serves them. */
20 + readonly authConfigsData?: AuthConfigsTestData;
21 + /** Repository methods that answer differently, such as a failing request. */
22 + readonly repository?: Partial<ComposioToolkitsRepositoryShape>;
23 +}
24 +
25 +/**
26 + * What an `auth-configs` handler needs without argv or `TestLive`: a headless terminal whose
27 + * stdout payloads land in `outputs` (decoration goes to `MockConsole`), a `NodeProcess` that
28 + * records the exit code, and a repository serving only the auth-config methods. Any other
29 + * repository method dies.
30 + */
31 +export const AuthConfigsHandlerTest = (fixture: AuthConfigsHandlerFixture = {}) => {
32 + const outputs: Array<string> = [];
33 + const proc = recordingNodeProcess();
34 + const layer = Layer.mergeAll(
35 + Layer.effect(Console.Console, MockConsole.make),
36 + Layer.succeed(
37 + TerminalUI,
38 + TerminalUI.of({
39 + ...terminalUITestImpl,
40 + output: data =>
41 + Effect.sync(() => {
42 + outputs.push(data);
43 + }),
44 + })
45 + ),
46 + proc.layer,
47 + Layer.succeed(
48 + ComposioToolkitsRepository,
49 + makeToolkitsRepositoryStub({
50 + // Only the auth-config methods: a stray connected-account request dies instead of
51 + // answering a catchable API error, so a test fails loudly at the change site.
52 + ...authConfigRepositoryMethods(resolveAuthConfigsTestData(fixture.authConfigsData)),
53 + ...fixture.repository,
54 + })
55 + )
56 + );
57 + return { layer, outputs, exitCode: proc.exitCode };
58 +};
ts/packages/cli/test/__utils__/layers/connected-accounts.ts
+26 -6
@@ -78,6 +78,16 @@ const findById = <A extends { readonly id: string }>(
78 notFound
79 );
80
81 +/**
82 + * The repository's auth-config methods.
83 + */
84 +export type AuthConfigRepositoryMethod = 'listAuthConfigs' | 'getAuthConfig' | 'createAuthConfig';
85 +
86 +export type AuthConfigRepositoryMethods = Pick<
87 + ComposioToolkitsRepositoryShape,
88 + AuthConfigRepositoryMethod
89 +>;
90 +
91 /**
92 * The repository methods this family serves.
93 */
@@ -90,13 +100,12 @@ export type ConnectedAccountRepositoryMethods = Pick<
100 >;
101
102 /**
93 - * The repository's auth-config and connected-account methods, answering from
94 - * the test data the way the API would.
103 + * The repository's auth-config methods, answering from the test data the way
104 + * the API would.
105 */
96 -export const connectedAccountRepositoryMethods = (
97 - authConfigsData: ResolvedAuthConfigsTestData,
98 - connectedAccountsData: ResolvedConnectedAccountsTestData
99 -): ConnectedAccountRepositoryMethods => ({
106 +export const authConfigRepositoryMethods = (
107 + authConfigsData: ResolvedAuthConfigsTestData
108 +): AuthConfigRepositoryMethods => ({
109 listAuthConfigs: (params: {
110 search?: string;
111 toolkit_slug?: string;
@@ -143,6 +152,17 @@ export const connectedAccountRepositoryMethods = (
152 }
153 );
154 },
155 +});
156 +
157 +/**
158 + * The repository's auth-config and connected-account methods, answering from
159 + * the test data the way the API would.
160 + */
161 +export const connectedAccountRepositoryMethods = (
162 + authConfigsData: ResolvedAuthConfigsTestData,
163 + connectedAccountsData: ResolvedConnectedAccountsTestData
164 +): ConnectedAccountRepositoryMethods => ({
165 + ...authConfigRepositoryMethods(authConfigsData),
166 getConnectedAccount: (nanoid: string) =>
167 findById(connectedAccountsData.items, nanoid, () =>
168 notFoundError(`Connected account "${nanoid}" not found`, {
ts/packages/cli/test/__utils__/models/auth-configs.ts new
+20
@@ -0,0 +1,20 @@
1 +import type { AuthConfigItem } from 'src/models/auth-configs';
2 +
3 +/**
4 + * An enabled, Composio-managed Gmail auth config. Suites override only the
5 + * fields their scenario is about.
6 + */
7 +export const makeAuthConfigItem = (overrides: Partial<AuthConfigItem> = {}): AuthConfigItem => ({
8 + id: 'ac_gmail_default',
9 + name: 'Gmail Default',
10 + no_of_connections: 5,
11 + status: 'ENABLED',
12 + type: 'default',
13 + uuid: 'uuid-1',
14 + toolkit: { logo: '', slug: 'gmail' },
15 + auth_scheme: 'OAUTH2',
16 + is_composio_managed: true,
17 + is_enabled_for_tool_router: true,
18 + created_at: '2026-01-01T00:00:00Z',
19 + ...overrides,
20 +});
ts/packages/cli/test/src/commands/auth-configs/create/auth-configs.create.cmd.test.ts renamed
ts/packages/cli/test/src/commands/auth-configs/create/auth-configs.create.handler.test.ts new
+169
@@ -0,0 +1,169 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Effect, Option } from 'effect';
3 +import {
4 + buildAuthConfigCreateRequest,
5 + parseScopes,
6 + runAuthConfigsCreate,
7 + type AuthConfigsCreateParams,
8 +} from 'src/commands/auth-configs/create/auth-configs.create.handler';
9 +import { MockConsole } from 'test/__utils__';
10 +import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs';
11 +import { notFoundError } from 'test/__utils__/layers/not-found';
12 +
13 +const params: AuthConfigsCreateParams = {
14 + name: Option.none(),
15 + toolkit: 'gmail',
16 + authScheme: Option.none(),
17 + scopes: Option.none(),
18 + customCredentials: Option.none(),
19 +};
20 +
21 +const createResponse = {
22 + auth_config: { id: 'ac_created', auth_scheme: 'OAUTH2', is_composio_managed: false },
23 + toolkit: { slug: 'gmail' },
24 +};
25 +
26 +describe('parseScopes', () => {
27 + it.each([
28 + { name: 'no flag', input: Option.none<string>(), expected: undefined },
29 + { name: 'one scope', input: Option.some('send_email'), expected: ['send_email'] },
30 + {
31 + name: 'padded scopes and blanks',
32 + input: Option.some(' send_email, ,read_email ,'),
33 + expected: ['send_email', 'read_email'],
34 + },
35 + // An empty flag still sends an empty list, as before the move.
36 + { name: 'an empty flag', input: Option.some(''), expected: [] },
37 + ])('[Given] $name [Then] returns $expected', ({ input, expected }) => {
38 + expect(parseScopes(input)).toEqual(expected);
39 + });
40 +});
41 +
42 +describe('buildAuthConfigCreateRequest', () => {
43 + const base = {
44 + name: undefined,
45 + toolkit: 'gmail',
46 + authScheme: Option.none<string>(),
47 + scopes: undefined,
48 + customCredentials: undefined,
49 + };
50 +
51 + it.each([
52 + {
53 + name: 'no scheme',
54 + input: { ...base, name: 'mine' },
55 + expected: {
56 + toolkit: { slug: 'gmail' },
57 + auth_config: { type: 'use_composio_managed_auth', name: 'mine', credentials: undefined },
58 + },
59 + },
60 + {
61 + name: 'no scheme with scopes and custom credentials',
62 + input: { ...base, scopes: ['send_email'], customCredentials: { client_id: 'ignored' } },
63 + expected: {
64 + toolkit: { slug: 'gmail' },
65 + auth_config: {
66 + type: 'use_composio_managed_auth',
67 + name: undefined,
68 + credentials: { scopes: ['send_email'] },
69 + },
70 + },
71 + },
72 + {
73 + name: 'a scheme alone',
74 + input: { ...base, authScheme: Option.some('API_KEY') },
75 + expected: {
76 + toolkit: { slug: 'gmail' },
77 + auth_config: {
78 + type: 'use_custom_auth',
79 + authScheme: 'API_KEY',
80 + name: undefined,
81 + credentials: undefined,
82 + },
83 + },
84 + },
85 + {
86 + name: 'a scheme with custom credentials and scopes',
87 + input: {
88 + ...base,
89 + authScheme: Option.some('OAUTH2'),
90 + scopes: ['send_email'],
91 + customCredentials: { client_id: 'id', scopes: ['overridden'] },
92 + },
93 + expected: {
94 + toolkit: { slug: 'gmail' },
95 + auth_config: {
96 + type: 'use_custom_auth',
97 + authScheme: 'OAUTH2',
98 + name: undefined,
99 + credentials: { client_id: 'id', scopes: ['send_email'] },
100 + },
101 + },
102 + },
103 + ])('[Given] $name [Then] builds the matching request', ({ input, expected }) => {
104 + expect(buildAuthConfigCreateRequest(input)).toStrictEqual(expected);
105 + });
106 +});
107 +
108 +describe('runAuthConfigsCreate', () => {
109 + it.effect('[Given] a successful create [Then] prints the API response JSON to stdout', () => {
110 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
111 + authConfigsData: { createResponse },
112 + });
113 + return Effect.gen(function* () {
114 + yield* runAuthConfigsCreate(params);
115 +
116 + expect(outputs).toEqual([JSON.stringify(createResponse, null, 2)]);
117 + const decoration = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
118 + expect(decoration).toContain('Auth config created.');
119 + expect(decoration).toContain('[New Auth Config]');
120 + expect(exitCode()).toBeUndefined();
121 + }).pipe(Effect.provide(layer));
122 + });
123 +
124 + it.effect.each([
125 + { name: 'malformed JSON', customCredentials: '{invalid json}' },
126 + { name: 'a JSON array', customCredentials: '["client_id"]' },
127 + ])(
128 + '[Given] $name in --custom-credentials [Then] reports it, sends no request, and exits 0',
129 + ({ customCredentials }) => {
130 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
131 + repository: { createAuthConfig: () => Effect.die('createAuthConfig must not be called') },
132 + });
133 + return Effect.gen(function* () {
134 + yield* runAuthConfigsCreate({
135 + ...params,
136 + authScheme: Option.some('OAUTH2'),
137 + customCredentials: Option.some(customCredentials),
138 + });
139 +
140 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([
141 + 'Invalid JSON in --custom-credentials. Please provide valid JSON.',
142 + ]);
143 + expect(outputs).toEqual([]);
144 + expect(exitCode()).toBeUndefined();
145 + }).pipe(Effect.provide(layer));
146 + }
147 + );
148 +
149 + it.effect('[Given] the API rejects the create [Then] hints at the toolkit and exits 1', () => {
150 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
151 + repository: {
152 + createAuthConfig: () => Effect.fail(notFoundError('Toolkit not found')),
153 + },
154 + });
155 + return Effect.gen(function* () {
156 + yield* runAuthConfigsCreate({ ...params, toolkit: 'nope' });
157 +
158 + const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join(
159 + '\n'
160 + );
161 + expect(stderr).toContain('Failed to create auth config.');
162 + expect(stderr).toContain(
163 + 'Check available auth schemes for "nope":\n> composio dev toolkits info "nope"'
164 + );
165 + expect(outputs).toEqual([]);
166 + expect(exitCode()).toBe(1);
167 + }).pipe(Effect.provide(layer));
168 + });
169 +});
ts/packages/cli/test/src/commands/auth-configs/info/auth-configs.info.cmd.test.ts renamed
ts/packages/cli/test/src/commands/auth-configs/info/auth-configs.info.handler.test.ts new
+63
@@ -0,0 +1,63 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Effect, Option } from 'effect';
3 +import { runAuthConfigsInfo } from 'src/commands/auth-configs/info/auth-configs.info.handler';
4 +import { MockConsole } from 'test/__utils__';
5 +import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs';
6 +import { makeAuthConfigItem } from 'test/__utils__/models/auth-configs';
7 +
8 +const gmail = makeAuthConfigItem();
9 +
10 +describe('runAuthConfigsInfo', () => {
11 + it.effect('[Given] a known ID [Then] prints the auth config JSON to stdout', () => {
12 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
13 + authConfigsData: { items: [gmail] },
14 + });
15 + return Effect.gen(function* () {
16 + yield* runAuthConfigsInfo({ id: Option.some('ac_gmail_default') });
17 +
18 + expect(outputs).toEqual([JSON.stringify(gmail, null, 2)]);
19 + const decoration = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
20 + expect(decoration).toContain('[Auth Config: Gmail Default]');
21 + expect(decoration).toContain('Tool Router: Enabled');
22 + expect(exitCode()).toBeUndefined();
23 + }).pipe(Effect.provide(layer));
24 + });
25 +
26 + it.effect('[Given] no ID [Then] warns, sends no request, and exits 0', () => {
27 + // The stub repository dies on any call, so reaching the API fails the test.
28 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
29 + repository: { getAuthConfig: () => Effect.die('getAuthConfig must not be called') },
30 + });
31 + return Effect.gen(function* () {
32 + yield* runAuthConfigsInfo({ id: Option.none() });
33 +
34 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([
35 + 'Missing required argument: <id>',
36 + ]);
37 + expect(outputs).toEqual([]);
38 + expect(exitCode()).toBeUndefined();
39 + }).pipe(Effect.provide(layer));
40 + });
41 +
42 + it.effect(
43 + '[Given] an unknown ID [Then] reports the API error with the list hint and exits 1',
44 + () => {
45 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
46 + authConfigsData: { items: [gmail] },
47 + });
48 + return Effect.gen(function* () {
49 + yield* runAuthConfigsInfo({ id: Option.some('ac_missing') });
50 +
51 + const stderr = (yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).join(
52 + '\n'
53 + );
54 + expect(stderr).toContain('Auth config "ac_missing" not found.');
55 + expect(stderr).toContain(
56 + 'Browse available auth configs:\n> composio dev auth-configs list'
57 + );
58 + expect(outputs).toEqual([]);
59 + expect(exitCode()).toBe(1);
60 + }).pipe(Effect.provide(layer));
61 + }
62 + );
63 +});
ts/packages/cli/test/src/commands/auth-configs/list/auth-configs.list.cmd.test.ts renamed
ts/packages/cli/test/src/commands/auth-configs/list/auth-configs.list.handler.test.ts new
+119
@@ -0,0 +1,119 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Effect, Option } from 'effect';
3 +import { runAuthConfigsList } from 'src/commands/auth-configs/list/auth-configs.list.handler';
4 +import { redact } from 'src/ui/redact';
5 +import { MockConsole } from 'test/__utils__';
6 +import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs';
7 +import { makeAuthConfigItem } from 'test/__utils__/models/auth-configs';
8 +
9 +const gmail = makeAuthConfigItem();
10 +const slack = makeAuthConfigItem({
11 + id: 'ac_slack_custom',
12 + name: 'Slack Custom',
13 + toolkit: { logo: '', slug: 'slack' },
14 + auth_scheme: 'API_KEY',
15 + type: 'custom',
16 + is_composio_managed: false,
17 +});
18 +
19 +const params = {
20 + toolkits: Option.none<string>(),
21 + query: Option.none<string>(),
22 + limit: 30,
23 +};
24 +
25 +describe('runAuthConfigsList', () => {
26 + it.effect('[Given] auth configs [Then] prints their summary JSON to stdout', () => {
27 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
28 + authConfigsData: { items: [gmail, slack] },
29 + });
30 + return Effect.gen(function* () {
31 + yield* runAuthConfigsList(params);
32 +
33 + expect(outputs.map(data => JSON.parse(data))).toEqual([
34 + [
35 + {
36 + id: 'ac_gmail_default',
37 + name: 'Gmail Default',
38 + toolkit_slug: 'gmail',
39 + auth_scheme: 'OAUTH2',
40 + type: 'default',
41 + status: 'ENABLED',
42 + no_of_connections: 5,
43 + is_composio_managed: true,
44 + },
45 + {
46 + id: 'ac_slack_custom',
47 + name: 'Slack Custom',
48 + toolkit_slug: 'slack',
49 + auth_scheme: 'API_KEY',
50 + type: 'custom',
51 + status: 'ENABLED',
52 + no_of_connections: 5,
53 + is_composio_managed: false,
54 + },
55 + ],
56 + ]);
57 + const decoration = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
58 + expect(decoration).toContain('Listing 2 of 2 auth configs');
59 + expect(decoration).toContain(
60 + `To view details of an auth config:\n> composio dev auth-configs info "${redact({ value: 'ac_gmail_default', prefix: 'ac_' })}"`
61 + );
62 + expect(exitCode()).toBeUndefined();
63 + }).pipe(Effect.provide(layer));
64 + });
65 +
66 + it.effect('[Given] a limit above 1000 [Then] asks the API for at most 1000', () => {
67 + const limits: Array<number | undefined> = [];
68 + const { layer } = AuthConfigsHandlerTest({
69 + repository: {
70 + listAuthConfigs: params =>
71 + Effect.sync(() => {
72 + limits.push(params.limit);
73 + return {
74 + items: [],
75 + total_items: 0,
76 + total_pages: 0,
77 + current_page: 1,
78 + next_cursor: null,
79 + };
80 + }),
81 + },
82 + });
83 + return Effect.gen(function* () {
84 + yield* runAuthConfigsList({ ...params, limit: 5000 });
85 +
86 + expect(limits).toEqual([1000]);
87 + }).pipe(Effect.provide(layer));
88 + });
89 +
90 + it.effect.each([
91 + {
92 + name: 'no toolkit filter',
93 + toolkits: Option.none<string>(),
94 + warning: 'No auth configs found. Try broadening your search.',
95 + },
96 + {
97 + name: 'a toolkit filter',
98 + toolkits: Option.some('notion'),
99 + warning:
100 + 'No auth configs found for toolkit "notion". Verify the toolkit slug with:\n> composio dev toolkits list',
101 + },
102 + ])(
103 + '[Given] no matches and $name [Then] warns and prints nothing to stdout',
104 + ({ toolkits, warning }) => {
105 + const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
106 + authConfigsData: { items: [gmail] },
107 + });
108 + return Effect.gen(function* () {
109 + yield* runAuthConfigsList({ ...params, toolkits, query: Option.some('nothing-matches') });
110 +
111 + expect(yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true })).toEqual([
112 + warning,
113 + ]);
114 + expect(outputs).toEqual([]);
115 + expect(exitCode()).toBeUndefined();
116 + }).pipe(Effect.provide(layer));
117 + }
118 + );
119 +});