Skip to content

Add devMode for NAC widgets#969

Open
rchlfryn wants to merge 7 commits intomainfrom
nac-dev
Open

Add devMode for NAC widgets#969
rchlfryn wants to merge 7 commits intomainfrom
nac-dev

Conversation

@rchlfryn
Copy link
Collaborator

@rchlfryn rchlfryn commented Mar 4, 2026

Summary

  • Add NAC_WIDGET_DEV_MODE environment variable to control the devMode value passed to NAC widget configs
  • When set to "true", overrides the production lock that currently forces devMode to false
  • Falls back to the nacWidgetsConfig global's devMode field when the env var is not set
  • Enables dedicated staging environments to point widgets at the staging base URL without code changes or redeployment

Motivation

Fixes #717

Currently, devMode is always forced to false in production (getNACWidgetsConfig.ts), regardless of the admin panel setting. This makes it impossible to run a staging/preview deployment that uses the NAC staging widget URLs — useful for nwacus/app (AvyApp) development and testing custom data entered in staging.

Changes

  • src/utilities/getNACWidgetsConfig.ts — Check NAC_WIDGET_DEV_MODE env var before falling back to the global config value. Remove the blanket production override so staging deployments can opt in.
  • .env.example — Document the new NAC_WIDGET_DEV_MODE variable.

How it works

Priority order for devMode:

  1. NAC_WIDGET_DEV_MODE env var ("true"true, "false"false)
  2. nacWidgetsConfig.devMode global value from admin panel
  3. Defaults to false

Test plan

  • Verify widgets load normally in local dev with no env var set (devMode respects admin panel)
  • Set NAC_WIDGET_DEV_MODE=true and confirm widgets use the staging base URL
  • Set NAC_WIDGET_DEV_MODE=false and confirm it overrides an admin panel devMode: true
  • Verify production deployment without the env var still defaults to devMode: false
  • Check /api/[center]/nac-config endpoint returns the correct devMode value

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Migration Safety Check

Found 1 potential issue:

20260318_204443_add_dev_mode.ts

Warning (line 6): ALTER keyword detected - review for data loss

sql`ALTER TABLE \`nac_widgets_config\` ADD \`dev_mode\` integer DEFAULT false NOT NULL;`,

Review these patterns and add backup/restore logic if needed. See docs/migration-safety.md for guidance.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Preview deployment: https://nac-dev.preview.avy-fx.org

@rchlfryn
Copy link
Collaborator Author

rchlfryn commented Mar 5, 2026

@busbyk Leaving this as a draft. It is ready fro review but I am curious if you think this is the correct approach based on the issue you wrote.

@rchlfryn rchlfryn marked this pull request as ready for review March 10, 2026 16:28
@rchlfryn
Copy link
Collaborator Author

@busbyk Ready for review

Comment on lines +31 to +37
jest.mock('../../src/services/nac/nac', () => ({
getAvalancheCenterPlatforms: jest.fn(async (centerSlug: string) => {
const centerSlugToUse = centerSlug === 'dvac' ? 'nwac' : centerSlug

return mockCenters[centerSlugToUse] ?? allFalsePlatforms
}),
}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the function we're testing here with a mocked function that's only used in this test doesn't actually test the getAvalancheCenterPlatforms function.

Ideally, we would intercept the API requests and return mocked data using MSW or something similar so that we would be testing the actual implementation of getAvalancheCenterPlatforms.

If you don't want to set up MSW, I suggest removing this test file completely.

Comment on lines +30 to +36
it('forces devMode to false in production even when global config has it enabled', async () => {
Object.defineProperty(process.env, 'NODE_ENV', { value: 'production', configurable: true })
mockConfig.devMode = true

const result = await getNACWidgetsConfig()
expect(result.devMode).toBe(false)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says that nacWidgetsConfig.devMode should be respected when NAC_WIDGET_DEV_MODE is not set.

Comment on lines +19 to +21
// In production, always force devMode off regardless of the admin setting
const devMode =
process.env.NODE_ENV === 'production' ? false : (nacWidgetsConfig?.devMode ?? false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I don't see why we wouldn't respect this in production.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention was we would never want this to be accidentally true in production, but I guess we might want that? I can't think of a use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NAC Widgets devMode

2 participants