Skip to content

Commit 5246008

Browse files
committed
improvement(config): one resolver for projected server switches, plus audit follow-ups
- env-flags: the five server-only switches share resolveServerSwitch instead of five copies of the server/projection branch. - deployment-shape: isSameDeploymentShape compares every top-level field, so a new shape field cannot be missed and its reseed silently dropped; covered by a test that flips each switch. - Docs: drop the stale NEXT_PUBLIC pairs sentence in authentication, fix the Slack trigger variable count and wording, and point the upgrade note at the right reference. - Contract comment and a test mock message describe current behavior.
1 parent 2fbc5f3 commit 5246008

10 files changed

Lines changed: 61 additions & 56 deletions

File tree

‎apps/docs/content/docs/integrations/slack.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Sim requests these scopes when someone connects a Slack account. For a self-host
7878
| `reactions:write` | Add emoji reactions to messages |
7979
| `reactions:read` | View emoji reactions on messages |
8080

81-
Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes:
81+
Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable it only after Slack approves the app for these scopes:
8282

8383
| Scope | Description |
8484
| ----- | ----------- |

‎apps/docs/content/docs/platform/self-hosting/authentication.mdx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ Requests use a shared anonymous session.
193193
| `DISABLE_PUBLIC_API=true` | Disable the public API globally. |
194194
| `ADMIN_API_KEY` | Enables Admin API GitOps operations and organization provisioning. |
195195

196-
Set both server and `NEXT_PUBLIC_` flags where a pair is listed. The server flag enforces the restriction; its counterpart controls the UI.
197-
198196
## Verify authentication
199197

200198
Sign out and sign back in at the public origin, then open a workflow in two browser windows and confirm edits propagate. Test each enabled login method. If verification is required, create a test account and confirm the message arrives and the verification succeeds. Use [Verify your install](/platform/self-hosting/verify) for deployment checks.

‎apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ Webhook triggers receive callbacks from the provider and must be able to verify
479479
| `SLACK_SIGNING_SECRET` | Verifying Slack event and slash-command signatures |
480480
| `SLACK_EXTENDED_SCOPES` | Enabling the native Sim-app trigger and its broader Slack scope set |
481481

482-
When enabling the native Sim Slack trigger, configure all three variables together. Enable the extended-scope flags only after Slack approves the app for `assistant:write`, `app_mentions:read`, and `im:history`; otherwise Slack rejects OAuth authorization. Slack OAuth actions can use `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` without enabling the native trigger or supplying a signing secret.
482+
When enabling the native Sim Slack trigger, configure both variables together. Enable `SLACK_EXTENDED_SCOPES` only after Slack approves the app for `assistant:write`, `app_mentions:read`, and `im:history`; otherwise Slack rejects OAuth authorization. Slack OAuth actions can use `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` without enabling the native trigger or supplying a signing secret.
483483

484484
Your deployment must also be reachable from the provider's servers for webhook triggers to fire — a Sim instance on a private network can use polling triggers but not webhook triggers. Polling triggers additionally require the scheduler; see [Background Jobs](/platform/self-hosting/background-jobs).
485485

‎apps/docs/content/docs/platform/self-hosting/upgrades.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Check the changes for every release between your current version and the target
7575
|---|---|
7676
| **Redis is required.** Sim refuses to start without `REDIS_URL`; there is no PostgreSQL or in-memory fallback. | Keep the bundled Redis, or point `REDIS_URL` at a managed instance before upgrading. App and realtime must reach the same Redis. See [Redis](/platform/self-hosting/redis). |
7777
| **`REGISTRATION_MODE` replaces `DISABLE_REGISTRATION`, `DISABLE_EMAIL_SIGNUP`, and `EMAIL_PASSWORD_SIGNUP_ENABLED`** (and its `NEXT_PUBLIC_` twin). The old variables are still honored as deprecated aliases, and the most restrictive setting wins. `NEXT_PUBLIC_EMAIL_PASSWORD_SIGNUP_ENABLED=false` now also disables email/password sign-in on the server. | Move to `REGISTRATION_MODE`. See [Control registration and sign-in](/platform/self-hosting/authentication#controlling-who-can-sign-up). |
78-
| **Enterprise `NEXT_PUBLIC_*` flags and `NEXT_PUBLIC_SANDBOXES_ENABLED` are no longer read, nor are `NEXT_PUBLIC_BILLING_ENABLED`, `NEXT_PUBLIC_E2B_ENABLED`, `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES`, `NEXT_PUBLIC_DISABLE_INVITATIONS`, and `NEXT_PUBLIC_DISABLE_PUBLIC_API`.** The browser reads the server's resolved settings. | Set the server variable for each feature (`BILLING_ENABLED`, `E2B_ENABLED`, `SLACK_EXTENDED_SCOPES`, `DISABLE_INVITATIONS`, `DISABLE_PUBLIC_API`, …). See the [feature flag reference](/platform/enterprise/self-hosted#feature-flag-reference). |
78+
| **Enterprise `NEXT_PUBLIC_*` flags and `NEXT_PUBLIC_SANDBOXES_ENABLED` are no longer read, nor are `NEXT_PUBLIC_BILLING_ENABLED`, `NEXT_PUBLIC_E2B_ENABLED`, `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES`, `NEXT_PUBLIC_DISABLE_INVITATIONS`, and `NEXT_PUBLIC_DISABLE_PUBLIC_API`.** The browser reads the server's resolved settings. | Set the server variable of the same name without the `NEXT_PUBLIC_` prefix (`BILLING_ENABLED`, `E2B_ENABLED`, `DISABLE_INVITATIONS`, …). The enterprise flags are listed in the [feature flag reference](/platform/enterprise/self-hosted#feature-flag-reference). |
7979
| **`ALLOW_PRIVATE_DATABASE_HOSTS` was removed.** The app logs an error at startup if it is still set. | Name your database, cache, and mail hosts in the egress allowlists. See [Upgrading from an earlier release](/platform/self-hosting/security#upgrading-from-an-earlier-release). |
8080
| **White-labeling was removed.** `NEXT_PUBLIC_BRAND_*`, `NEXT_PUBLIC_CUSTOM_CSS_URL`, `NEXT_PUBLIC_SUPPORT_EMAIL`, `NEXT_PUBLIC_DOCUMENTATION_URL`, `NEXT_PUBLIC_TERMS_URL`, `NEXT_PUBLIC_PRIVACY_URL`, `WHITELABELING_ENABLED`, and `NEXT_PUBLIC_WHITELABELING_ENABLED` are ignored. | Remove them at your convenience; leaving them set is harmless. |
8181
| **`docker-compose.ollama.yml` is now an overlay on `docker-compose.prod.yml`.** | A stack started from the previous standalone file needs its project name carried over, or it starts on an empty database. See [Migrating from the previous Ollama stack](/platform/self-hosting/docker#migrating-from-the-previous-ollama-stack). |

‎apps/sim/lib/api/contracts/workspaces.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const deploymentShapeSchema = z.object({
274274
*/
275275
registrationMode: z.enum(REGISTRATION_MODES).optional(),
276276
/**
277-
* Server-only switches the browser used to read from `NEXT_PUBLIC_*` twins. Optional
277+
* Server-only switches, resolved on the server and projected for the browser. Optional
278278
* for rolling compatibility with app versions that predate projecting them; readers
279279
* treat absent as `false`.
280280
*/

‎apps/sim/lib/billing/core/organization-activity.integration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const databaseUrl = readTestDatabaseUrl()
1010
vi.mock('@sim/db', () => ({ dbReplica: { execute, select } }))
1111
vi.mock('@/lib/core/config/redis', () => ({
1212
getRedisClient: () => {
13-
throw new Error('Redis is not used by this suite; the usage cache reads the ledger')
13+
throw new Error('Redis is unavailable in this suite; the usage cache falls back to the ledger')
1414
},
1515
}))
1616

‎apps/sim/lib/core/config/deployment-shape.dom.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ describe('seeded server shape', () => {
141141
expect(apiKeyFieldShown('custom/model')).toBe(true)
142142
})
143143

144+
it('takes a reseed that changes any top-level switch', () => {
145+
const switches = (Object.keys(HOSTED) as (keyof DeploymentShape)[]).filter(
146+
(key) => typeof HOSTED[key] === 'boolean'
147+
)
148+
expect(switches.length).toBeGreaterThan(0)
149+
for (const key of switches) {
150+
seedDeploymentShape(HOSTED)
151+
const changed = { ...HOSTED, [key]: !HOSTED[key] }
152+
seedDeploymentShape(changed)
153+
expect(getDeploymentShape(), key).toBe(changed)
154+
}
155+
})
156+
157+
it('keeps the current seed for an equal shape', () => {
158+
seedDeploymentShape(HOSTED)
159+
seedDeploymentShape({ ...HOSTED, features: { ...HOSTED.features } })
160+
161+
expect(getDeploymentShape()).toBe(HOSTED)
162+
})
163+
144164
it('is ignored when the server predates deployment projection', () => {
145165
seedDeploymentShape(undefined)
146166

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,9 @@ export function resolveDeploymentShape(): DeploymentShape {
137137

138138
function isSameDeploymentShape(seeded: DeploymentShape | null, next: DeploymentShape): boolean {
139139
if (seeded === null) return false
140-
if (
141-
seeded.hosted !== next.hosted ||
142-
seeded.billingEnabled !== next.billingEnabled ||
143-
seeded.chatEnabled !== next.chatEnabled ||
144-
seeded.azureConfigured !== next.azureConfigured ||
145-
seeded.cohereConfigured !== next.cohereConfigured ||
146-
seeded.registrationMode !== next.registrationMode ||
147-
seeded.e2bEnabled !== next.e2bEnabled ||
148-
seeded.slackExtendedScopes !== next.slackExtendedScopes ||
149-
seeded.invitationsDisabled !== next.invitationsDisabled ||
150-
seeded.publicApiDisabled !== next.publicApiDisabled
151-
) {
152-
return false
140+
const keys = new Set([...Object.keys(seeded), ...Object.keys(next)]) as Set<keyof DeploymentShape>
141+
for (const key of keys) {
142+
if (key !== 'features' && seeded[key] !== next[key]) return false
153143
}
154144
const featureKeys = Object.keys(next.features) as (keyof DeploymentFeatures)[]
155145
return featureKeys.every((key) => seeded.features[key] === next.features[key])

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

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,23 @@ export const isCopilotToolPermissionsEnabled = isTruthy(env.COPILOT_TOOL_PERMISS
121121
export const isMothershipBenchmarkEnabled = isTruthy(env.MOTHERSHIP_BENCHMARK_ENABLED)
122122

123123
/**
124-
* Is billing enforcement enabled.
125-
*
126-
* Server code reads `BILLING_ENABLED`. The browser never sees that variable and
127-
* takes the server's answer from the deployment-shape projection on `<html>`
128-
* (`./deployment-projection`); a document without one reads it as off.
124+
* A server-only switch: `serverValue` on the server; in the browser, which never
125+
* sees server variables, the server's answer from the deployment-shape projection
126+
* on `<html>` (`./deployment-projection`), off on a document without one.
127+
*/
128+
function resolveServerSwitch(
129+
serverValue: Parameters<typeof isTruthy>[0],
130+
projectedKey: string
131+
): boolean {
132+
return typeof window === 'undefined'
133+
? isTruthy(serverValue)
134+
: (readProjectedBoolean(projectedKey) ?? false)
135+
}
136+
137+
/**
138+
* Is billing enforcement enabled (`BILLING_ENABLED`).
129139
*/
130-
export const isBillingEnabled =
131-
typeof window === 'undefined'
132-
? isTruthy(env.BILLING_ENABLED)
133-
: (readProjectedBoolean('billingEnabled') ?? false)
140+
export const isBillingEnabled = resolveServerSwitch(env.BILLING_ENABLED, 'billingEnabled')
134141

135142
/**
136143
* Is email verification enabled
@@ -296,15 +303,14 @@ export const isAppConfigEnabled =
296303
* off there until review lands; a self-hosted deployment pointing at its own
297304
* (unlisted) Slack app can opt in.
298305
*
299-
* Server code reads `SLACK_EXTENDED_SCOPES`; the browser reads the server's answer
300-
* from the deployment-shape projection (see {@link isBillingEnabled}). The server
301-
* value decides the grant; the browser value only decides what the credential
302-
* pickers advertise and treat as missing.
306+
* Read from `SLACK_EXTENDED_SCOPES`. The server value decides the grant; the
307+
* browser value only decides what the credential pickers advertise and treat as
308+
* missing.
303309
*/
304-
export const isSlackExtendedScopesEnabled =
305-
typeof window === 'undefined'
306-
? isTruthy(env.SLACK_EXTENDED_SCOPES)
307-
: (readProjectedBoolean('slackExtendedScopes') ?? false)
310+
export const isSlackExtendedScopesEnabled = resolveServerSwitch(
311+
env.SLACK_EXTENDED_SCOPES,
312+
'slackExtendedScopes'
313+
)
308314

309315
/**
310316
* Is Trigger.dev enabled for async job processing
@@ -553,33 +559,24 @@ export const isAzureConfigured = isTruthy(getEnv('NEXT_PUBLIC_AZURE_CONFIGURED')
553559
export const isCohereConfigured = isTruthy(getEnv('NEXT_PUBLIC_COHERE_CONFIGURED'))
554560

555561
/**
556-
* Are workspace invitations disabled for every user (`DISABLE_INVITATIONS`). The
557-
* browser reads the server's answer from the deployment-shape projection.
562+
* Are workspace invitations disabled for every user (`DISABLE_INVITATIONS`).
558563
*/
559-
export const isInvitationsDisabled =
560-
typeof window === 'undefined'
561-
? isTruthy(env.DISABLE_INVITATIONS)
562-
: (readProjectedBoolean('invitationsDisabled') ?? false)
564+
export const isInvitationsDisabled = resolveServerSwitch(
565+
env.DISABLE_INVITATIONS,
566+
'invitationsDisabled'
567+
)
563568

564569
/**
565570
* Is public API access disabled for every workspace (`DISABLE_PUBLIC_API`): the
566-
* public API toggle is hidden and public API access is blocked. The browser reads
567-
* the server's answer from the deployment-shape projection.
571+
* public API toggle is hidden and public API access is blocked.
568572
*/
569-
export const isPublicApiDisabled =
570-
typeof window === 'undefined'
571-
? isTruthy(env.DISABLE_PUBLIC_API)
572-
: (readProjectedBoolean('publicApiDisabled') ?? false)
573+
export const isPublicApiDisabled = resolveServerSwitch(env.DISABLE_PUBLIC_API, 'publicApiDisabled')
573574

574575
/**
575576
* Is the E2B code-execution provider switched on (`E2B_ENABLED`). Pi's cloud modes
576-
* run in an E2B sandbox and stay hidden without it. The browser reads the server's
577-
* answer from the deployment-shape projection.
577+
* run in an E2B sandbox and stay hidden without it.
578578
*/
579-
export const isE2bEnabled =
580-
typeof window === 'undefined'
581-
? isTruthy(env.E2B_ENABLED)
582-
: (readProjectedBoolean('e2bEnabled') ?? false)
579+
export const isE2bEnabled = resolveServerSwitch(env.E2B_ENABLED, 'e2bEnabled')
583580

584581
/**
585582
* Is Google OAuth login disabled

‎scripts/generate-docs.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4937,7 +4937,7 @@ async function buildOAuthScopesSection(
49374937

49384938
if (gatedScopes.length) {
49394939
section +=
4940-
'Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes:\n\n'
4940+
'Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable it only after Slack approves the app for these scopes:\n\n'
49414941
section += scopeTable(gatedScopes, describe)
49424942
}
49434943

0 commit comments

Comments
 (0)