Skip to content

Commit a6e6bfa

Browse files
authored
Frontend/feature flags (#1114)
### Requirements List - **New .env variables:** - `VUE_APP_ENV=local` - `VUE_APP_STATSIG_KEY=<get from Statsig account: Settings -> Keys & Environments -> Client API Keys>` - **New dependencies** - `yarn install --ignore-engines` ### Description List - Added new env vars for app environment and Statsig key - Updated the EnvConfig plugin to handle new env vars - Updated README for new env vars + some general env var doc cleanup - Added Statsig package dependencies - Add a Statsig plugin to allow injecting the Statsig client into components - Initialize Statsig client in `main.ts` - Handle Statsig user change in login & logout flows - Don't allow Statsig init to block loading for more than 2 seconds - Add a polling process to periodically refetch the Statsig gate config from the server - Add full examples of feature gate usage to the Styelguide example components - Inject feature checking Statsig client into some models - Updated CSP Lambda with Statsig domains - Fix some existing transient errors in the tests related to the LicenseeList & Sorting components ### Testing List - `yarn test:unit:all` should run without errors or warnings - `yarn serve` should run without errors or warnings - `yarn build` should run without errors or warnings - For API configuration changes: CDK tests added/updated in `backend/compact-connect/tests/unit/test_api.py` - Code review - Testing - On launching the app in the browser, explore the dev tools Network tab to ensure calls to Statsig domains are successful - _Note that Statsig uses a variety of different root domains - seen in the CSP Lambda updates_ - Navigate the app to make sure things are generally stable and there are no indications of regressions or Statsig-related issues - Navigate to the `/Styleguide` page and scroll to the bottom to see the Example Feature Gates section - All of the different flag evaluations should be in the expected Enabled / Disabled state depending on the state of the flag(s) in Statsig - Go to the Statsig web console and update the toggle status of the flag(s) - Back in the Styleguide page, either: - Wait for the Statsig refresh timer in App.ts, then navigate away and back to the Styleguide page, or - Refresh the Styleguide page - Either case should result in the Styleguide flag evaluations being updated to the new state (Enabled / Disabled) Closes #1094 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Integrated feature flags and analytics; added Example Feature Gates to the Style Guide. - App initializes analytics and updates user periodically; clears analytics user on logout. - Added new translations for feature gate labels. - Bug Fixes - Improved sorting to avoid errors when no callback is provided. - Style - Minor UI refinements adding rr-block styling across forms, cards, and confirmation views. - Documentation - Updated environment variable guidance and setup instructions. - Tests - Added tests for feature flags plugin and Example Feature Gates; updated test helpers. - Chores - Updated CI/CD, deployment configs, CSP allowlist, and added analytics dependencies. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3e67b28 commit a6e6bfa

60 files changed

Lines changed: 1076 additions & 168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/check-webroot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ on:
1717
# Allows you to run this workflow manually from the Actions tab
1818
workflow_dispatch:
1919

20+
# Permission can be added at job level or workflow level
21+
permissions:
22+
id-token: write # This is required for requesting the JWT
23+
contents: read # This is required for actions/checkout
24+
2025
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2126
jobs:
2227
CheckWebroot:
@@ -78,6 +83,7 @@ jobs:
7883
env:
7984
NODE_ENV: production
8085
BASE_URL: ${{ env.BASE_URL }}
86+
VUE_APP_ENV: production
8187
VUE_APP_DOMAIN: ${{ env.VUE_APP_DOMAIN }}
8288
VUE_APP_ROBOTS_META: ${{ env.VUE_APP_ROBOTS_META }}
8389
VUE_APP_API_STATE_ROOT: ${{ env.VUE_APP_API_STATE_ROOT }}
@@ -88,5 +94,6 @@ jobs:
8894
VUE_APP_COGNITO_AUTH_DOMAIN_LICENSEE: ${{ env.VUE_APP_COGNITO_AUTH_DOMAIN_LICENSEE }}
8995
VUE_APP_COGNITO_CLIENT_ID_LICENSEE: ${{ env.VUE_APP_COGNITO_CLIENT_ID_LICENSEE }}
9096
VUE_APP_RECAPTCHA_KEY: ${{ env.VUE_APP_RECAPTCHA_KEY }}
97+
VUE_APP_MOCK_API: true
9198
run: yarn build
9299
working-directory: ./webroot

backend/compact-connect-ui-app/cdk.context.beta-example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"region": "us-east-1",
1414
"domain_name": "beta.compactconnect.org",
1515
"recaptcha_public_key": "123-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
16-
"robots_meta": "noindex,nofollow"
16+
"robots_meta": "noindex,nofollow",
17+
"statsig_key": "client-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
18+
"app_env": "beta"
1719
}
1820
}
1921
}

backend/compact-connect-ui-app/cdk.context.prod-example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"region": "us-east-1",
1414
"domain_name": "compactconnect.org",
1515
"robots_meta": "index,follow",
16-
"recaptcha_public_key": "123-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih"
16+
"recaptcha_public_key": "123-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
17+
"statsig_key": "client-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
18+
"app_env": "production"
1719
}
1820
}
1921
}

backend/compact-connect-ui-app/cdk.context.sandbox-example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"region": "us-east-1",
1111
"domain_name": "justin.compactconnect.org",
1212
"recaptcha_public_key": "123-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
13-
"robots_meta": "noindex,nofollow"
13+
"robots_meta": "noindex,nofollow",
14+
"statsig_key": "client-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
15+
"app_env": "local"
1416
}
1517
}
1618
}

backend/compact-connect-ui-app/cdk.context.test-example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"region": "us-east-1",
1414
"domain_name": "test.compactconnect.org",
1515
"recaptcha_public_key": "123-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
16-
"robots_meta": "noindex,nofollow"
16+
"robots_meta": "noindex,nofollow",
17+
"statsig_key": "client-KFEUsjehfuejILDVUKkRnAF9SSzb8o9uv5lY7Ih",
18+
"app_env": "csg-test"
1719
}
1820
}
1921
}

backend/compact-connect-ui-app/lambdas/nodejs/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _[back to top](#ingest-event-reporter-lambda)_
2222
---
2323
## Local development
2424
- **Linting**
25-
- `yarn run lint`
25+
- `yarn lint`
2626
- Lints all code in all the Lambda function
2727
- **Running an individual Lambda**
2828
- The easiest way to execute the Lambda is to run the tests ([see below](#tests))
@@ -33,7 +33,6 @@ _[back to top](#ingest-event-reporter-lambda)_
3333
---
3434
## Testing
3535
This project uses `jest` and `aws-sdk-client-mock` for approachable unit testing. The code in this folder can be tested by running:
36-
- `yarn install`
37-
- `yarn test`
36+
- `yarn test:csg`
3837

3938
or by using the utility scripts located at `backend/bin`.

backend/compact-connect-ui-app/lambdas/nodejs/cloudfront-csp/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ const setCspHeader = (headers = {}) => {
243243
domains.cognitoProvider,
244244
cognitoIdpUrl,
245245
'https://www.google.com/recaptcha/',
246+
// Begin Statsig domains
247+
'https://api.statsig.com/',
248+
'https://featuregates.org/',
249+
'https://statsigapi.net/',
250+
'https://events.statsigapi.net/',
251+
'https://api.statsigcdn.com/',
252+
'https://featureassets.org/',
253+
'https://assetsconfigcdn.org/',
254+
'https://prodregistryv2.org/',
255+
'https://cloudflare-dns.com/',
256+
'https://beyondwickedmapping.org/',
257+
// End Statsig domains
246258
]),
247259
].join(' ')}`,
248260
}];

backend/compact-connect-ui-app/lambdas/nodejs/cloudfront-csp/test/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ const buildCspHeaders = (environment) => {
156156
cognitoProviderUrl,
157157
cognitoIdpUrl,
158158
'https://www.google.com/recaptcha/',
159+
// Begin Statsig domains
160+
'https://api.statsig.com/',
161+
'https://featuregates.org/',
162+
'https://statsigapi.net/',
163+
'https://events.statsigapi.net/',
164+
'https://api.statsigcdn.com/',
165+
'https://featureassets.org/',
166+
'https://assetsconfigcdn.org/',
167+
'https://prodregistryv2.org/',
168+
'https://cloudflare-dns.com/',
169+
'https://beyondwickedmapping.org/',
170+
// End Statsig domains
159171
].join(' ');
160172

161173
return `${[

backend/compact-connect-ui-app/stacks/frontend_deployment_stack/deployment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def __init__(
3131
# Get environment-specific values from context
3232
recaptcha_public_key = environment_context['recaptcha_public_key']
3333
robots_meta = environment_context['robots_meta']
34+
statsig_client_key = environment_context['statsig_key']
35+
app_env = environment_context['app_env']
3436

3537
super().__init__(
3638
scope,
@@ -56,6 +58,7 @@ def __init__(
5658
image=DockerImage('public.ecr.aws/lts/ubuntu:22.04_stable'),
5759
environment={
5860
'BASE_URL': '/',
61+
'VUE_APP_ENV': app_env,
5962
'VUE_APP_DOMAIN': f'{HTTPS_PREFIX}{persistent_stack_app_config_values.ui_domain_name}',
6063
'VUE_APP_ROBOTS_META': robots_meta,
6164
'VUE_APP_API_STATE_ROOT': f'{HTTPS_PREFIX}{persistent_stack_app_config_values.api_domain_name}',
@@ -67,6 +70,7 @@ def __init__(
6770
'VUE_APP_COGNITO_AUTH_DOMAIN_LICENSEE': f'{HTTPS_PREFIX}{provider_users_stack_app_config_values.provider_cognito_domain}{COGNITO_AUTH_DOMAIN_SUFFIX}',
6871
'VUE_APP_COGNITO_CLIENT_ID_LICENSEE': provider_users_stack_app_config_values.provider_cognito_client_id,
6972
'VUE_APP_RECAPTCHA_KEY': recaptcha_public_key,
73+
'VUE_APP_STATSIG_KEY': statsig_client_key,
7074
},
7175
entrypoint=['bash'],
7276
command=['bin/build.sh'],

backend/compact-connect-ui-app/tests/resources/snapshots/BetaFrontend-FrontendDeploymentStack-UI_DISTRIBUTION.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{
4040
"EventType": "viewer-response",
4141
"LambdaFunctionARN": {
42-
"Ref": "CSPFunctionCurrentVersionB61A66115988ea1180930366a7af32c8681342bd"
42+
"Ref": "CSPFunctionCurrentVersionB61A6611c49f5a41519db73b59488deeb4e8a5bc"
4343
}
4444
}
4545
],

0 commit comments

Comments
 (0)