Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime config and JWT support #843

Merged
merged 11 commits into from
Jun 21, 2021
Merged

Runtime config and JWT support #843

merged 11 commits into from
Jun 21, 2021

Conversation

cea2aj
Copy link
Member

@cea2aj cea2aj commented Jun 18, 2021

Add Runtime Config and JWT support

cea2aj and others added 10 commits June 1, 2021 12:37
Add JWT support which is enabled when useJWT is true in global config

For iframe experiences, add iframe-jwt.js (along with prod and staging versions) which provide an `initAnswersFrameJWT` function. The answers experience will load once `initAnswersFrameJWT` is called.

For non-iframe experiences, `initAnswersJWT` must be called rather than `initAnswersFrameJWT`

The next PR will ensure that the apiKey from the jambo injected data will not appear in the output of any builds.

This PR does not include JWT overlay support.

J=SLAP-1118
TEST=manual

Test iframe-jwt.js and see that the page doesn't load until initAnswersFrame is ran. Test supplying valid and invalid tokens. Test navigating between pages and refreshing the page. Test that if the answers experience with `useJWT=true` is loaded directly (not through the iframe), and error message appears in the console. Smoke test the non-iframe experience and the the overlay integration with `useJWT=false`.  Test JWT locally and on SGS. Test in a cross-domain manner with a local test site which points to an answers experience on SGS which is running this branch. On SGS, test iframe-jwt-prod.js and iframe-jwt-staging.js

Test JWT on non-iframe experiences.
Remove the apiKey from the build output when useJWT=true

The apiKey needs to be removed in the templatedataformatter and in the JAMBO_INJECTED_DATA that weback puts in the bundles.

J=J=SLAP-1118
TEST=manual, auto

When useJWT is true, run a build and search for the apiKey and confirm that it does not appear anywhere in the build output. Test this with JAMBO_INJECTED_DATA which contains apiKeys. Smoke test the JWT integration and the standard integration. Add unit test.
Support runtime config and update the JWT support to use it

This PR allows the parent to set arbitrary config for iframed Answers experiences with the `setRuntimeConfig` function. Data attributes on the '#answers-container' div are also loaded into the RuntimeConfig when the iframe is created. Inside the experience, the runtime config is available at the `RuntimeConfig` object on the window.

The experience can be setup to allow be manually initialized rather than initialized automatically . To do this, the hitchhiker must set `"manuallyInitialize": true` inside global_config. With that option enabled, the experience must be started with `initAnswersExperienceFrame(config)` for iframe experiences or with `initAnswersExperience(config)` for non-iframe experiences.

The manual initialization also allows the experience to be started with a JWT token. To use JWT, 'initializeManually' and 'useJWT' should be set in global_config. The 'useJWT' option simply ensures that any api key that may have been injected does not appear anywhere in the build output. The experience can then be started with `initAnswersExperienceFrame({ token: 'jwt-token-here' });` or with `initAnswersExperience({ token: 'jwt-token-here' });` for non-iframe experiences.

J=SLAP-1315
TEST=manual

Test JWT support with iframe and non-iframe experiences. Test supplying custom config and seeing it available within the iframe. Note that the config is set even before the cards render with initial searches set. Test navigating pages within the iframe and seeing the config maintained. Set data attributes and see them get set within the iframe.
Update the public interface of the runtime config in accordance with the product spec

- All new functionality on the window is namespaced to AnswersExperience or AnswersExperienceFrame for iframe integrations
- These namespaces each have an init function and a runtime config object
- The runtime config object has public set get, and a getAll methods
- The 'initAnswersExperience' boolean has been moved out the runtime config. This change lead me to create the iframe message queue to prevent messages from being sent and lost before the iframe has initialized
- I also removed the lastUpdated logic. It was created for an older design where the entire runtime config object was being updated at once, but it's no longer necessary since the runtime config is now updated one key value pair at a time.
- Remove the data attributes feature since we currently can't guarantee the run config will be set by the time answers initializes

J=SLAP-1362
TEST=manual

On both iframe and non-iframe experiences test initializing the experience with custom config. Test using the runtime config data models. Test that calling set on the parent runtime config will update the runtime config within the iframe. Test initialization with JWT.
Use link targets from runtime config, and default to "_top" if it is not specified

Update all targets which include card title links, CTAS, phone links, RTF links, and direct answer links

J=SLAP-1349
TEST=manual

Load the test site, change the runtime config link target and see different link target behavior. Test title links, CTAs, phone links, RTF links, and direct answer links
Ensure that the page initializes upon page navigation when initializeManually=true

This functionality broke during a recent re-factor when I moved the initAnswersExperience boolean out of the runtimeConfig and into the top-level of the message. Since this data was previously inside the runtimeConfig, it would persist and the experience would receive the message to re-initialize during page navigation. After moving that data outside of the runtimeConfig, the page would no longer receive that message and would fail to re-initialize. To fix this, I ensure that the parent indicates to the iframe that it needs to re-initialize.

J=none
TEST=manual

Load an iframe test site with manuallyInitialize=true, and call the init function. See that the experience now initializes when navigating verticals within the iframe.
…842)

Resolve conflicts to allow feature/jwt-support to merge into develop
@coveralls
Copy link

coveralls commented Jun 21, 2021

Coverage Status

Coverage increased (+0.2%) to 5.877% when pulling c063198 on feature/jwt-support-merge into 357ad3b on develop.

@cea2aj cea2aj merged commit 4910fe5 into develop Jun 21, 2021
@cea2aj cea2aj deleted the feature/jwt-support-merge branch June 21, 2021 03:08
@cea2aj cea2aj mentioned this pull request Jun 23, 2021
cea2aj added a commit that referenced this pull request Jun 23, 2021
## Version 1.22.0
### Changes
- Code coverage reports are now generated automatically for the Theme. (#759)
- A number of dependencies were updated in accordance with Dependabot's suggestions. (#780)
- The build time in `Development` mode was reduced significantly. (#782, #829) Build times in 
`Production` mode were also decreased. (#783, #825)
- Two new cards supporting videos were added: `product-prominentvideo` and `multilang-product-prominentvideo`. These cards
work with either YouTube or Vimeo content. (#794)
- The process for formatting hours was made more efficient, resulting in faster renders for cards with hours. (#784)
- Any SDK branch can now be specified in the `global_config.sdkVersion` attribute. (#791)
- Unused CSS was removed from the Theme. (#793, #798)
- To reduce flashing related to the SDK Component lifecycle, placeholder skeletons were added for the `SearchBar` and
`Navigation` components. (#797)
- Additional acceptance tests were added for the `VerticalFullPageMap` and Percy snapshots are now generated for all
cards. (#830, #820)
- Multi-language tests were added for the Theme. (#826)
- The `documentsearch-standard` card now supports rich text featured snippets. (#838)
- A new concept, `RuntimeConfig` was added. This allows configuration, computed at run-time, to be injected into the
Theme and SDK. This new concept enables JWT integrations as well. (#843)
### Bug Fixes
- A number of changes were made to make the Theme's visual regression tests more reliable. (#764, #765, #766, #778)
- Corrected how the CTA URLs for the `menuitem-standard` and `multilang-menuitem-standard` cards are computed. (#787)
- The Google Streetview person icon is now visible when using the `VerticalFullPageMap` layout. (#801)
- The size of the cluster and result pins are now configurable. (#807)
- A double encoding error for `verticalUrl` was fixed. (#836)
- The `Opens At` open status message is now properly translated in all languages. (#834)
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.

2 participants