Skip to content

Commit 6bc1fa7

Browse files
committed
chore: formatting
1 parent 3485fe5 commit 6bc1fa7

8 files changed

Lines changed: 29 additions & 51 deletions

File tree

src/bin.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (!satisfies(process.version, NODE_VERSION_RANGE)) {
3131
import { isNonInteractiveEnvironment } from './utils/environment.js';
3232
import clack from './utils/clack.js';
3333

34-
/** Apply insecure storage flag if set (for both credential-store and config-store) */
34+
/** Apply insecure storage flag if set */
3535
async function applyInsecureStorage(insecureStorage?: boolean): Promise<void> {
3636
if (insecureStorage) {
3737
const { setInsecureStorage } = await import('./lib/credentials.js');
@@ -266,16 +266,11 @@ yargs(hideBin(process.argv))
266266
await runEnvSwitch(argv.name);
267267
},
268268
)
269-
.command(
270-
'list',
271-
'List configured environments',
272-
{},
273-
async (argv) => {
274-
await applyInsecureStorage((argv as any).insecureStorage);
275-
const { runEnvList } = await import('./commands/env.js');
276-
await runEnvList();
277-
},
278-
)
269+
.command('list', 'List configured environments', {}, async (argv) => {
270+
await applyInsecureStorage((argv as any).insecureStorage);
271+
const { runEnvList } = await import('./commands/env.js');
272+
await runEnvList();
273+
})
279274
.demandCommand(1, 'Please specify an env subcommand')
280275
.strict(),
281276
)
@@ -320,8 +315,7 @@ yargs(hideBin(process.argv))
320315
.command(
321316
'get <orgId>',
322317
'Get an organization by ID',
323-
(yargs) =>
324-
yargs.positional('orgId', { type: 'string', demandOption: true, describe: 'Organization ID' }),
318+
(yargs) => yargs.positional('orgId', { type: 'string', demandOption: true, describe: 'Organization ID' }),
325319
async (argv) => {
326320
await applyInsecureStorage(argv.insecureStorage);
327321
const { resolveApiKey, resolveApiBaseUrl } = await import('./lib/api-key.js');
@@ -356,8 +350,7 @@ yargs(hideBin(process.argv))
356350
.command(
357351
'delete <orgId>',
358352
'Delete an organization',
359-
(yargs) =>
360-
yargs.positional('orgId', { type: 'string', demandOption: true, describe: 'Organization ID' }),
353+
(yargs) => yargs.positional('orgId', { type: 'string', demandOption: true, describe: 'Organization ID' }),
361354
async (argv) => {
362355
await applyInsecureStorage(argv.insecureStorage);
363356
const { resolveApiKey, resolveApiBaseUrl } = await import('./lib/api-key.js');

src/commands/env.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ function getOrCreateConfig(): CliConfig {
1616
return getConfig() ?? { environments: {} };
1717
}
1818

19-
export async function runEnvAdd(options: {
20-
name?: string;
21-
apiKey?: string;
22-
endpoint?: string;
23-
}): Promise<void> {
19+
export async function runEnvAdd(options: { name?: string; apiKey?: string; endpoint?: string }): Promise<void> {
2420
let { name, apiKey, endpoint } = options;
2521

2622
if (name && apiKey) {
@@ -58,7 +54,6 @@ export async function runEnvAdd(options: {
5854
if (clack.isCancel(apiKeyResult)) process.exit(0);
5955
apiKey = apiKeyResult;
6056

61-
// Store the type from interactive selection
6257
const config = getOrCreateConfig();
6358
const isFirst = Object.keys(config.environments).length === 0;
6459

@@ -185,10 +180,8 @@ export async function runEnvList(): Promise<void> {
185180

186181
const entries = Object.entries(config.environments);
187182

188-
// Header
189183
const nameW = Math.max(6, ...entries.map(([k]) => k.length)) + 2;
190184
const typeW = 12;
191-
const endpointW = 30;
192185

193186
const header = [
194187
chalk.yellow(' '),
@@ -213,4 +206,3 @@ export async function runEnvList(): Promise<void> {
213206
}
214207
}
215208

216-
export { setInsecureConfigStorage };

src/commands/organization.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ vi.mock('../lib/workos-api.js', () => ({
1919
const { workosRequest } = await import('../lib/workos-api.js');
2020
const mockRequest = vi.mocked(workosRequest);
2121

22-
const { runOrgCreate, runOrgUpdate, runOrgGet, runOrgList, runOrgDelete, parseDomainArgs } = await import(
23-
'./organization.js'
24-
);
22+
const { runOrgCreate, runOrgUpdate, runOrgGet, runOrgList, runOrgDelete, parseDomainArgs } =
23+
await import('./organization.js');
2524

2625
describe('organization commands', () => {
2726
let consoleOutput: string[];
@@ -143,9 +142,7 @@ describe('organization commands', () => {
143142
list_metadata: { before: null, after: null },
144143
});
145144
await runOrgList({}, 'sk_test');
146-
expect(mockRequest).toHaveBeenCalledWith(
147-
expect.objectContaining({ method: 'GET', path: '/organizations' }),
148-
);
145+
expect(mockRequest).toHaveBeenCalledWith(expect.objectContaining({ method: 'GET', path: '/organizations' }));
149146
// Should contain table data
150147
expect(consoleOutput.some((l) => l.includes('FooCorp'))).toBe(true);
151148
});

src/commands/organization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function runOrgUpdate(
8181
name: string,
8282
domain?: string,
8383
state?: string,
84-
apiKey?: string,
84+
apiKey: string,
8585
baseUrl?: string,
8686
): Promise<void> {
8787
const body: Record<string, unknown> = { name };
@@ -93,7 +93,7 @@ export async function runOrgUpdate(
9393
const org = await workosRequest<Organization>({
9494
method: 'PUT',
9595
path: `/organizations/${orgId}`,
96-
apiKey: apiKey!,
96+
apiKey,
9797
baseUrl,
9898
body,
9999
});

src/lib/api-key.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ export function resolveApiKey(options?: ApiKeyOptions): string {
2424
const activeEnv = getActiveEnvironment();
2525
if (activeEnv?.apiKey) return activeEnv.apiKey;
2626

27-
throw new Error(
28-
'No API key configured. Run `workos env add` to configure an environment, or set WORKOS_API_KEY.',
29-
);
27+
throw new Error('No API key configured. Run `workos env add` to configure an environment, or set WORKOS_API_KEY.');
3028
}
3129

3230
export function resolveApiBaseUrl(): string {

src/lib/workos-api.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ describe('workos-api', () => {
120120

121121
it('throws WorkOSApiError on 401', async () => {
122122
mockFetch.mockResolvedValue(mockResponse(401, { message: 'Unauthorized' }, false));
123-
await expect(
124-
workosRequest({ method: 'GET', path: '/organizations', apiKey: 'bad_key' }),
125-
).rejects.toThrow(WorkOSApiError);
123+
await expect(workosRequest({ method: 'GET', path: '/organizations', apiKey: 'bad_key' })).rejects.toThrow(
124+
WorkOSApiError,
125+
);
126126
try {
127127
await workosRequest({ method: 'GET', path: '/organizations', apiKey: 'bad_key' });
128128
} catch (e) {
@@ -132,14 +132,18 @@ describe('workos-api', () => {
132132

133133
it('throws WorkOSApiError on 404', async () => {
134134
mockFetch.mockResolvedValue(mockResponse(404, { message: 'Not Found' }, false));
135-
await expect(
136-
workosRequest({ method: 'GET', path: '/organizations/missing', apiKey: 'sk_test' }),
137-
).rejects.toThrow(WorkOSApiError);
135+
await expect(workosRequest({ method: 'GET', path: '/organizations/missing', apiKey: 'sk_test' })).rejects.toThrow(
136+
WorkOSApiError,
137+
);
138138
});
139139

140140
it('throws WorkOSApiError with validation errors on 422', async () => {
141141
mockFetch.mockResolvedValue(
142-
mockResponse(422, { message: 'Validation failed', code: 'validation_error', errors: [{ message: 'Name required' }] }, false),
142+
mockResponse(
143+
422,
144+
{ message: 'Validation failed', code: 'validation_error', errors: [{ message: 'Name required' }] },
145+
false,
146+
),
143147
);
144148
try {
145149
await workosRequest({ method: 'POST', path: '/organizations', apiKey: 'sk_test', body: {} });
@@ -153,9 +157,9 @@ describe('workos-api', () => {
153157

154158
it('throws on network error', async () => {
155159
mockFetch.mockRejectedValue(new TypeError('fetch failed'));
156-
await expect(
157-
workosRequest({ method: 'GET', path: '/organizations', apiKey: 'sk_test' }),
158-
).rejects.toThrow('Failed to connect to WorkOS API');
160+
await expect(workosRequest({ method: 'GET', path: '/organizations', apiKey: 'sk_test' })).rejects.toThrow(
161+
'Failed to connect to WorkOS API',
162+
);
159163
});
160164
});
161165
});

src/lib/workos-api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* Generic WorkOS API client.
3-
*
43
* Thin fetch wrapper with auth, error parsing, and query param support.
5-
* Reusable for any WorkOS resource endpoint.
64
*/
75

86
const DEFAULT_BASE_URL = 'https://api.workos.com';

src/utils/table.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@ export interface TableColumn {
66
}
77

88
export function formatTable(columns: TableColumn[], rows: string[][]): string {
9-
// Calculate column widths: max of header length, content length, or specified width
109
const widths = columns.map((col, i) => {
1110
const contentMax = rows.reduce((max, row) => Math.max(max, (row[i] || '').length), 0);
1211
return col.width ?? Math.max(col.header.length, contentMax);
1312
});
1413

1514
const lines: string[] = [];
1615

17-
// Header row
1816
const header = columns.map((col, i) => chalk.yellow(col.header.padEnd(widths[i]))).join(' ');
1917
lines.push(header);
2018

21-
// Separator
2219
const totalWidth = widths.reduce((sum, w) => sum + w, 0) + (widths.length - 1) * 2;
2320
lines.push(chalk.dim('─'.repeat(totalWidth)));
2421

25-
// Data rows
2622
for (const row of rows) {
2723
const line = row.map((cell, i) => (cell || '').padEnd(widths[i])).join(' ');
2824
lines.push(line);

0 commit comments

Comments
 (0)