Skip to content

Open-source status page, incident response and uptime monitoring

1.1 KB
Raw Blame
import { resolveDashboardUrl } from "@openstatus/services/incident";

import { env } from "@/env";

/**
 * Slack credentials and derived settings, resolved once when the route is
 * built and carried on the request context.
 *
 * Handlers read this instead of `env` directly so tests can construct a route
 * with explicit config. Mutating `process.env` per-test is not viable: every
 * test in a file shares it, so one case's settings leak into the next.
 */
export type SlackConfig = {
  signingSecret?: string;
  clientId?: string;
  clientSecret?: string;
  redirectUri?: string;
  aiGatewayApiKey?: string;
  dashboardUrl: string;
};

export type SlackEnv = {
  Variables: {
    slackBody: unknown;
    event: Record<string, unknown>;
    slackConfig: SlackConfig;
  };
};

export function slackConfigFromEnv(): SlackConfig {
  return {
    signingSecret: env.SLACK_SIGNING_SECRET,
    clientId: env.SLACK_CLIENT_ID,
    clientSecret: env.SLACK_CLIENT_SECRET,
    redirectUri: env.SLACK_REDIRECT_URI,
    aiGatewayApiKey: env.AI_GATEWAY_API_KEY,
    dashboardUrl: resolveDashboardUrl({
      nodeEnv: env.NODE_ENV,
      override: env.DASHBOARD_URL,
    }),
  };
}