UJS: Refactored core package to be platform agnostic#1524
Conversation
🦋 Changeset detectedLatest commit: aa36211 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
| Filename | Overview |
|---|---|
| packages/core/src/core/network/requestMethods/injectSendBeaconRequest.js | Removed logger dependency and replaced logger.info with bare console.info, causing the fallback message to print unconditionally in production rather than only when debug mode is enabled. |
| packages/core/src/utils/request/createGetAssuranceValidationTokenParams.js | Migrated clientId persistence to async storage; the storage.getItem().then() chain is missing a .catch(), which will produce an unhandled promise rejection if a non-browser storage backend rejects. |
| packages/core/src/core/createLogController.js | Debug persistence migrated from sync sessionStorage.getItem to an async storage.getItem promise with a !debugSetByUser guard to prevent the async restore from overwriting a synchronously-set query-string value; .catch(() => {}) is present. |
| packages/core/src/core/index.js | Central wiring point — createPlatformServices() now called before logger construction and platformServices threaded into every component creator; cookieJar, injectStorage, and getMonitors direct references removed. |
| packages/core/src/components/RulesEngine/createEventRegistry.js | Safe defaults added for eventRegistry/eventRegistrySize; setStorage made async and save reassignment moved after await restore to close the prior race window. |
| packages/core/src/components/Consent/createConsentHashStore.js | isNew() and save() made async using Promise.all; callers updated to await them correctly. |
| packages/browser/src/services/createBrowserGlobalsService.js | Added getLocationHash, getPageLocation, isPageSsl, and getWindowContext so core components no longer reference window/document directly. |
| packages/core/src/components/Identity/index.js | Removed direct window references for isPageSsl, locationSearch, locationHash, and ECID visitor service; all replaced with platformServices equivalents. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[createExecuteCommand] -->|calls| B[createPlatformServices]
B --> C[createBrowserNetworkService]
B --> D[createBrowserStorageService]
B --> E[createBrowserCookieService]
B --> F[createBrowserGlobalsService]
B --> G[createBrowserLegacyService]
A -->|passes storage.session to| H[createLogController]
H -->|async getItem| D
A -->|passes storage.persistent to| I[createGetAssuranceValidationTokenParams]
I -->|async getItem no catch| D
A -->|platformServices threaded through| J[Component Creators]
J --> K[RulesEngine createEventRegistry]
J --> L[Consent createConsentHashStore]
J --> M[Identity createComponent]
C -->|sendBeacon fallback| Q[injectSendBeaconRequest console.info always-on]
style I fill:#ffcccc
style Q fill:#ffcccc
Reviews (4): Last reviewed commit: "Address debugSetByUser overwrite bug" | Re-trigger Greptile
jonsnyder
left a comment
There was a problem hiding this comment.
I'm a bit concerned that we are going to introduce a ton of regressions with this migration. One way to mitigate that risk is with automated testing at the SDK level. If we can develop a set of tests, and then run it against an old SDK version without failures, we can be more certain that this migration isn't creating problems. We could have AI create a bunch of tests, or we could do some random testing to generate a test set.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
carterworks
left a comment
There was a problem hiding this comment.
two small things. good job on the tests
…v dependency; relocate DOM utils into utils/dom/
…network services; move browser-specific utilities for network to browser package
Changed Packages
Description
Moved platform-specific implementation details (ie 'window' and 'document' that are specific to browser implementation, as well as upstream dependencies that use these artifacts) to the browser's platform services. C
Related Issue
(Related to Universal JavaScript migration)
Motivation and Context
Node package for WebSDK will have failures when encountering references to browser resources.
Screenshots (if appropriate):
N/A
Documentation
(All UJS should be documented together)
Types of changes
Checklist: