Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2409,9 +2409,11 @@ yargs(rawArgs)
async (argv) => {
await applyInsecureStorage(argv.insecureStorage);
const { resolveOptionalApiKey } = await import('./lib/api-key.js');
const { getActiveEnvironment } = await import('./lib/config-store.js');
const { getMigrationsPassthroughArgs, runMigrations } = await import('./commands/migrations.js');
const passthrough = getMigrationsPassthroughArgs(rawArgs);
await runMigrations(passthrough, resolveOptionalApiKey({ apiKey: argv.apiKey }));
const endpoint = getActiveEnvironment()?.endpoint;
await runMigrations(passthrough, resolveOptionalApiKey({ apiKey: argv.apiKey }), endpoint);
},
Comment thread
greptile-apps[bot] marked this conversation as resolved.
)
.command(
Expand Down
11 changes: 11 additions & 0 deletions src/commands/migrations.spec.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ describe('runMigrations', () => {
beforeEach(() => {
vi.clearAllMocks();
delete process.env.WORKOS_SECRET_KEY;
delete process.env.WORKOS_API_URL;
});

it('sets WORKOS_SECRET_KEY from the provided API key', async () => {
Expand DownExpand Up@@ -42,6 +43,16 @@ describe('runMigrations', () => {
expect(mockParseAsync).toHaveBeenCalledWith(args, { from: 'user' });
});

it('sets WORKOS_API_URL when apiBaseUrl is provided', async () => {
await runMigrations(['import', '--csv', 'users.csv'], 'sk_test_123', 'https://api.staging.workos.com');
expect(process.env.WORKOS_API_URL).toBe('https://api.staging.workos.com');
});

it('does not set WORKOS_API_URL when apiBaseUrl is undefined', async () => {
await runMigrations(['import', '--csv', 'users.csv'], 'sk_test_123');
expect(process.env.WORKOS_API_URL).toBeUndefined();
});

it('removes WorkOS global flags from migrations passthrough args', () => {
expect(
getMigrationsPassthroughArgs([
Expand Down
5 changes: 4 additions & 1 deletion src/commands/migrations.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,10 +43,13 @@ export function getMigrationsPassthroughArgs(rawArgs: string[]): string[] {
return passthrough;
}

export async function runMigrations(args: string[], apiKey?: string): Promise<void> {
export async function runMigrations(args: string[], apiKey?: string, apiBaseUrl?: string): Promise<void> {
if (apiKey) {
process.env.WORKOS_SECRET_KEY = apiKey;
}
if (apiBaseUrl) {
process.env.WORKOS_API_URL = apiBaseUrl;
}

const { program } = (await import('@workos/migrations/dist/cli/index.js')) as {
program: {
Expand Down
Loading