Skip to content

Commit a857d40

Browse files
committed
fix(config): expose the registration mode through getRegistrationMode
1 parent fddbf7a commit a857d40

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎apps/sim/lib/core/config/deployment-projection.dom.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ vi.unmock('@/lib/core/config/env')
3939
vi.unmock('@/lib/core/config/env-flags')
4040

4141
import {
42+
getRegistrationMode,
4243
isAccessControlEnabled,
4344
isAuditLogsEnabled,
4445
isEmailPasswordAuthEnabled,
@@ -49,7 +50,6 @@ import {
4950
isSelfServeRegistrationClosed,
5051
isSessionPoliciesEnabled,
5152
isSsoEnabled,
52-
registrationMode,
5353
} from '@/lib/core/config/env-flags'
5454

5555
describe('browser enterprise flags', () => {
@@ -69,7 +69,7 @@ describe('browser enterprise flags', () => {
6969

7070
describe('browser registration flags', () => {
7171
it('take the projected registration mode over the browser environment', () => {
72-
expect(registrationMode).toBe('closed-no-email')
72+
expect(getRegistrationMode()).toBe('closed-no-email')
7373
expect(isSelfServeRegistrationClosed).toBe(true)
7474
expect(isEmailSignupAllowed).toBe(false)
7575
expect(isEmailPasswordAuthEnabled).toBe(false)

‎apps/sim/lib/core/config/deployment-shape.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@/lib/api/contracts/workspaces'
99
import { readDeploymentProjection } from '@/lib/core/config/deployment-projection'
1010
import {
11+
getRegistrationMode,
1112
isAccessControlEnabled,
1213
isAuditLogsEnabled,
1314
isAzureConfigured,
@@ -27,7 +28,6 @@ import {
2728
isSessionPoliciesEnabled,
2829
isSsoEnabled,
2930
isUsageMonitoringEnabled,
30-
registrationMode,
3131
} from '@/lib/core/config/env-flags'
3232

3333
/**
@@ -107,7 +107,7 @@ export function resolveDeploymentShape(): DeploymentShape {
107107
chatEnabled: isChatEnabled,
108108
azureConfigured: isAzureConfigured,
109109
cohereConfigured: isCohereConfigured,
110-
registrationMode,
110+
registrationMode: getRegistrationMode(),
111111
features: {
112112
accessControl: isAccessControlEnabled,
113113
auditLogs: isAuditLogsEnabled,

‎apps/sim/lib/core/config/env-flags.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ if (env.EGRESS_ALLOWED_HOSTS || env.EGRESS_ALLOWED_IP_RANGES) {
238238
})
239239
}
240240

241+
const resolvedRegistrationMode: RegistrationMode =
242+
typeof window === 'undefined'
243+
? resolveServerRegistrationMode()
244+
: (readProjectedRegistrationMode() ?? 'open')
245+
241246
/**
242247
* Who may create an account and whether email/password and email OTP work at all
243248
* (`REGISTRATION_MODE`; see `@sim/deployment-config/registration` for the modes).
@@ -248,10 +253,9 @@ if (env.EGRESS_ALLOWED_HOSTS || env.EGRESS_ALLOWED_IP_RANGES) {
248253
* without one (a bare 404 or `global-error` shell) reads `open`, which only affects
249254
* which links render — the server still refuses.
250255
*/
251-
export const registrationMode: RegistrationMode =
252-
typeof window === 'undefined'
253-
? resolveServerRegistrationMode()
254-
: (readProjectedRegistrationMode() ?? 'open')
256+
export function getRegistrationMode(): RegistrationMode {
257+
return resolvedRegistrationMode
258+
}
255259

256260
function resolveServerRegistrationMode(): RegistrationMode {
257261
const { mode, warnings } = resolveRegistrationMode(getEnv)
@@ -272,7 +276,7 @@ function resolveServerRegistrationMode(): RegistrationMode {
272276
return mode
273277
}
274278

275-
const registrationPolicy = getRegistrationPolicy(registrationMode)
279+
const registrationPolicy = getRegistrationPolicy(resolvedRegistrationMode)
276280

277281
/**
278282
* No self-serve account creation by any method, social included (`closed`,

‎packages/testing/src/mocks/env-flags.mock.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export const envFlagsMockFns = {
149149
getBlacklistedProvidersFromEnv: vi.fn<() => string[]>(() => []),
150150
getAllowedMcpDomainsFromEnv: vi.fn<() => string[] | null>(() => null),
151151
getCostMultiplier: vi.fn<() => number>(() => 1),
152+
getRegistrationMode: vi.fn<() => RegistrationMode>(() => envFlagsState.registrationMode),
152153
}
153154

154155
/**
@@ -178,6 +179,9 @@ export function resetEnvFlagsMock(): void {
178179
envFlagsMockFns.getBlacklistedProvidersFromEnv.mockReset().mockImplementation(() => [])
179180
envFlagsMockFns.getAllowedMcpDomainsFromEnv.mockReset().mockImplementation(() => null)
180181
envFlagsMockFns.getCostMultiplier.mockReset().mockImplementation(() => 1)
182+
envFlagsMockFns.getRegistrationMode
183+
.mockReset()
184+
.mockImplementation(() => envFlagsState.registrationMode)
181185
envFlagsMockFns.getEgressAllowedHosts
182186
.mockReset()
183187
.mockImplementation(() =>

0 commit comments

Comments
 (0)