(
options: GetMothershipBaseURLOptions = {}
)
| 41 | } |
| 42 | |
| 43 | export async function getMothershipBaseURL( |
| 44 | options: GetMothershipBaseURLOptions = {} |
| 45 | ): Promise<string> { |
| 46 | const defaultUrl = getDefaultMothershipBaseURL(options.fallbackUrl) |
| 47 | |
| 48 | const { userId } = options |
| 49 | if (!userId) return defaultUrl |
| 50 | |
| 51 | const [row] = await db |
| 52 | .select({ |
| 53 | role: user.role, |
| 54 | superUserModeEnabled: settings.superUserModeEnabled, |
| 55 | mothershipEnvironment: settings.mothershipEnvironment, |
| 56 | }) |
| 57 | .from(user) |
| 58 | .leftJoin(settings, eq(settings.userId, user.id)) |
| 59 | .where(eq(user.id, userId)) |
| 60 | .limit(1) |
| 61 | |
| 62 | const effectiveSuperUser = row?.role === 'admin' && (row.superUserModeEnabled ?? false) |
| 63 | if (!effectiveSuperUser) return defaultUrl |
| 64 | |
| 65 | const selectedEnvironment = options.environment ?? row.mothershipEnvironment |
| 66 | const parsedEnvironment = mothershipEnvironmentSchema.safeParse(selectedEnvironment) |
| 67 | const environment = parsedEnvironment.success ? parsedEnvironment.data : 'default' |
| 68 | |
| 69 | return getConfiguredEnvironmentUrl(environment) ?? defaultUrl |
| 70 | } |
| 71 | |
| 72 | export function getMothershipSourceEnvHeaders(): Record<string, string> { |
| 73 | const sourceEnv = env.COPILOT_SOURCE_ENV?.trim().toLowerCase() |
no test coverage detected