From 170338b6fdc004f4c4a421ca896f13dbab22937c Mon Sep 17 00:00:00 2001 From: dal Date: Wed, 9 Jul 2025 15:33:23 -0600 Subject: [PATCH] change server url --- apps/server/.env.example | 2 +- apps/server/env.d.ts | 2 +- apps/server/scripts/validate-env.js | 4 ++-- apps/server/src/api/v2/slack/channels.int.test.ts | 1 - apps/server/src/api/v2/slack/handler.int.test.ts | 2 -- .../api/v2/slack/services/slack-oauth-service.int.test.ts | 4 +--- .../src/api/v2/slack/services/slack-oauth-service.test.ts | 4 ++-- .../server/src/api/v2/slack/services/slack-oauth-service.ts | 6 +++--- 8 files changed, 10 insertions(+), 15 deletions(-) diff --git a/apps/server/.env.example b/apps/server/.env.example index 344f71976..fe66b4c12 100644 --- a/apps/server/.env.example +++ b/apps/server/.env.example @@ -11,5 +11,5 @@ TRIGGER_SECRET_KEY= SLACK_INTEGRATION_ENABLED=false SLACK_CLIENT_ID="" SLACK_CLIENT_SECRET="" -SLACK_REDIRECT_URI="http://localhost:3000/api/v2/slack/auth/callback" +SERVER_URL="http://localhost:3002" SLACK_APP_SUPPORT_URL= \ No newline at end of file diff --git a/apps/server/env.d.ts b/apps/server/env.d.ts index 356aefcd0..343209e5a 100644 --- a/apps/server/env.d.ts +++ b/apps/server/env.d.ts @@ -12,8 +12,8 @@ declare global { SLACK_INTEGRATION_ENABLED: string; SLACK_CLIENT_ID: string; SLACK_CLIENT_SECRET: string; - SLACK_REDIRECT_URI: string; SLACK_APP_SUPPORT_URL: string; + SERVER_URL: string; NODE_ENV?: 'development' | 'production' | 'test'; } } diff --git a/apps/server/scripts/validate-env.js b/apps/server/scripts/validate-env.js index fc5469f91..0e094c004 100644 --- a/apps/server/scripts/validate-env.js +++ b/apps/server/scripts/validate-env.js @@ -26,9 +26,9 @@ const env = { const slackEnv = { SLACK_CLIENT_ID: process.env.SLACK_CLIENT_ID, SLACK_CLIENT_SECRET: process.env.SLACK_CLIENT_SECRET, - SLACK_REDIRECT_URI: process.env.SLACK_REDIRECT_URI, SLACK_INTEGRATION_ENABLED: process.env.SLACK_INTEGRATION_ENABLED || 'false', SLACK_APP_SUPPORT_URL: process.env.SLACK_APP_SUPPORT_URL, + SERVER_URL: process.env.SERVER_URL, }; let hasErrors = false; @@ -50,8 +50,8 @@ if (slackEnv.SLACK_INTEGRATION_ENABLED === 'true') { const requiredSlackVars = [ 'SLACK_CLIENT_ID', 'SLACK_CLIENT_SECRET', - 'SLACK_REDIRECT_URI', 'SLACK_APP_SUPPORT_URL', + 'SERVER_URL', ]; for (const envKey of requiredSlackVars) { diff --git a/apps/server/src/api/v2/slack/channels.int.test.ts b/apps/server/src/api/v2/slack/channels.int.test.ts index 361ccff53..09db44a10 100644 --- a/apps/server/src/api/v2/slack/channels.int.test.ts +++ b/apps/server/src/api/v2/slack/channels.int.test.ts @@ -11,7 +11,6 @@ const skipIfNoEnv = !process.env.DATABASE_URL || !process.env.SLACK_CLIENT_ID || !process.env.SLACK_CLIENT_SECRET || - !process.env.SLACK_REDIRECT_URI || !process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY || !process.env.SLACK_TEST_ACCESS_TOKEN; // Additional env var for testing channels diff --git a/apps/server/src/api/v2/slack/handler.int.test.ts b/apps/server/src/api/v2/slack/handler.int.test.ts index 93607ccc5..424848f81 100644 --- a/apps/server/src/api/v2/slack/handler.int.test.ts +++ b/apps/server/src/api/v2/slack/handler.int.test.ts @@ -12,7 +12,6 @@ const skipIfNoEnv = !process.env.DATABASE_URL || !process.env.SLACK_CLIENT_ID || !process.env.SLACK_CLIENT_SECRET || - !process.env.SLACK_REDIRECT_URI || !process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY; @@ -80,7 +79,6 @@ describe.skipIf(skipIfNoEnv)('SlackHandler Integration Tests', () => { // Ensure all required env vars are set for the service process.env.SLACK_CLIENT_ID = process.env.SLACK_CLIENT_ID || 'test-client-id'; process.env.SLACK_CLIENT_SECRET = process.env.SLACK_CLIENT_SECRET || 'test-client-secret'; - process.env.SLACK_REDIRECT_URI = process.env.SLACK_REDIRECT_URI || 'https://test.com/callback'; // Create unique test organization and user const { organizationId, userId } = await createTestOrgAndUser(); diff --git a/apps/server/src/api/v2/slack/services/slack-oauth-service.int.test.ts b/apps/server/src/api/v2/slack/services/slack-oauth-service.int.test.ts index c97b150c9..488ae08cf 100644 --- a/apps/server/src/api/v2/slack/services/slack-oauth-service.int.test.ts +++ b/apps/server/src/api/v2/slack/services/slack-oauth-service.int.test.ts @@ -9,7 +9,6 @@ const skipIfNoEnv = !process.env.DATABASE_URL || !process.env.SLACK_CLIENT_ID || !process.env.SLACK_CLIENT_SECRET || - !process.env.SLACK_REDIRECT_URI || !process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY; @@ -99,8 +98,7 @@ describe.skipIf(skipIfNoEnv)('SlackOAuthService Integration Tests', () => { // Set test environment variables process.env.SLACK_CLIENT_ID = process.env.SLACK_CLIENT_ID || 'test-client-id'; process.env.SLACK_CLIENT_SECRET = process.env.SLACK_CLIENT_SECRET || 'test-client-secret'; - process.env.SLACK_REDIRECT_URI = - process.env.SLACK_REDIRECT_URI || 'https://test.com/callback'; + process.env.SERVER_URL = process.env.SERVER_URL || 'https://test.com'; const { SlackOAuthService } = await import('./slack-oauth-service'); service = new SlackOAuthService(); } diff --git a/apps/server/src/api/v2/slack/services/slack-oauth-service.test.ts b/apps/server/src/api/v2/slack/services/slack-oauth-service.test.ts index e935c764e..781638fab 100644 --- a/apps/server/src/api/v2/slack/services/slack-oauth-service.test.ts +++ b/apps/server/src/api/v2/slack/services/slack-oauth-service.test.ts @@ -13,7 +13,7 @@ vi.mock('@buster/slack', () => ({ // Mock environment variables before importing vi.stubEnv('SLACK_CLIENT_ID', 'test-client-id'); vi.stubEnv('SLACK_CLIENT_SECRET', 'test-client-secret'); -vi.stubEnv('SLACK_REDIRECT_URI', 'https://test.com/callback'); +vi.stubEnv('SERVER_URL', 'https://test.com'); vi.stubEnv('SLACK_INTEGRATION_ENABLED', 'true'); // Import after mocking env vars @@ -27,7 +27,7 @@ describe('SlackOAuthService', () => { // Reset env vars to defaults vi.stubEnv('SLACK_CLIENT_ID', 'test-client-id'); vi.stubEnv('SLACK_CLIENT_SECRET', 'test-client-secret'); - vi.stubEnv('SLACK_REDIRECT_URI', 'https://test.com/callback'); + vi.stubEnv('SERVER_URL', 'https://test.com'); vi.stubEnv('SLACK_INTEGRATION_ENABLED', 'true'); service = new SlackOAuthService(); }); diff --git a/apps/server/src/api/v2/slack/services/slack-oauth-service.ts b/apps/server/src/api/v2/slack/services/slack-oauth-service.ts index 3983fe8a6..9dcf88291 100644 --- a/apps/server/src/api/v2/slack/services/slack-oauth-service.ts +++ b/apps/server/src/api/v2/slack/services/slack-oauth-service.ts @@ -7,7 +7,7 @@ import { oauthStateStorage, tokenStorage } from './token-storage'; const SlackEnvSchema = z.object({ SLACK_CLIENT_ID: z.string().min(1), SLACK_CLIENT_SECRET: z.string().min(1), - SLACK_REDIRECT_URI: z.string().url(), + SERVER_URL: z.string().url(), SLACK_INTEGRATION_ENABLED: z .string() .transform((val) => val === 'true') @@ -39,7 +39,7 @@ export class SlackOAuthService { { clientId: this.env.SLACK_CLIENT_ID, clientSecret: this.env.SLACK_CLIENT_SECRET, - redirectUri: this.env.SLACK_REDIRECT_URI, + redirectUri: `${this.env.SERVER_URL}/api/v2/slack/auth/callback`, scopes: [ 'channels:history', 'channels:read', @@ -60,7 +60,7 @@ export class SlackOAuthService { environment: { hasClientId: !!process.env.SLACK_CLIENT_ID, hasClientSecret: !!process.env.SLACK_CLIENT_SECRET, - hasRedirectUri: !!process.env.SLACK_REDIRECT_URI, + hasServerUrl: !!process.env.SERVER_URL, integrationEnabled: process.env.SLACK_INTEGRATION_ENABLED, }, });