rudder-sdk-js
rudder-sdk-js copied to clipboard
feat: set server side cookies
PR Description
- added new load option to enable setting cookie from server side
- added new load option to take the base URL to set the cookie to if not same as dataplane url
- If the option is enabled SDK will make a POST request to the API gateway with the cookie name value and settings.
- Whenever a cookie is modified cookie setter method will be called
Linear task (optional)
https://linear.app/rudderstack/issue/SDK-1301/create-a-cookie-setter-provider-for-service
Cross Browser Tests
Please confirm you have tested for the following browsers:
- [ ] Chrome
- [ ] Firefox
- [ ] IE11
Sanity Suite
- [ ] All sanity suite test cases pass locally
Security
- [ ] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
Summary by CodeRabbit
-
New Features
- Added server-side cookie handling capabilities.
- Enhanced analytics tracking with new HTTP post handlers for different endpoints.
- Introduced new configuration options for server-side cookies in analytics setup.
-
Enhancements
- Increased size limits for various analytics modules to accommodate new features.
- Improved error logging related to data server URL validation and cookie setting failures.
-
Bug Fixes
- Fixed syntax in Criteo integration and streamlined configuration assignment in FacebookPixel integration.
-
Documentation
- Updated public-facing configuration examples to demonstrate the use of server-side cookies.
Walkthrough
The updates involve enhancing functionality related to server-side cookie management and data handling in an analytics JavaScript library. New properties and methods support server-side cookies, including configuration validation and HTTP handling. Additionally, the inclusion of workspaceId enhances data source identification, aligning with enhanced security and configuration precision.
Changes
| File Path | Changes |
|---|---|
.../types/LoadOptions.ts, .../utilities/loadOptions.ts |
Added useServerSideCookies and dataServerUrl to handle server-side cookie configurations. |
.../types/Source.ts, .../configManager/ConfigManager.ts |
Introduced workspaceId for better source management. |
.../__fixtures__/msw.handlers.ts |
New HTTP POST handler for server-side cookie requests. |
.../__tests__/components/configManager/ConfigManager.test.ts, .../__tests__/components/userSessionManager/UserSessionManager.test.ts |
Updated tests to include new configurations and methods related to server-side cookies and workspaceId. |
.../src/components/configManager/util/validate.ts, .../src/components/userSessionManager/UserSessionManager.ts |
Added functions and methods for validating and setting server-side cookies, including error handling. |
.../src/components/userSessionManager/types.ts |
Defined new types for managing cookie data. |
ππ In the meadow of code, where the data streams flow,
A rabbit hopped in, with updates in tow.
Server-side cookies, oh so sweet,
Ensuring every byte is neat.
With a hop, skip, and a commendable feat,
Our rabbitβs work is now complete! πΌπͺ ππ
Recent Review Details
Configuration used: CodeRabbit UI Review profile: CHILL
Commits
Files that changed from the base of the PR and between a59c8d0648e3eb076823d0c8835dc422dac0c67d and 0c65220d014a7f165991d7b52ca50e038b069b6c.Files selected for processing (10)
- packages/analytics-js-common/src/types/LoadOptions.ts (1 hunks)
- packages/analytics-js-common/src/types/Source.ts (1 hunks)
- packages/analytics-js/fixtures/msw.handlers.ts (1 hunks)
- packages/analytics-js/tests/components/configManager/ConfigManager.test.ts (1 hunks)
- packages/analytics-js/tests/components/userSessionManager/UserSessionManager.test.ts (3 hunks)
- packages/analytics-js/src/components/configManager/ConfigManager.ts (3 hunks)
- packages/analytics-js/src/components/configManager/util/validate.ts (2 hunks)
- packages/analytics-js/src/components/userSessionManager/UserSessionManager.ts (5 hunks)
- packages/analytics-js/src/components/userSessionManager/types.ts (1 hunks)
- packages/analytics-js/src/components/utilities/loadOptions.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/analytics-js/src/components/userSessionManager/types.ts
Additional Context Used
Learnings (2)
packages/analytics-js/src/components/userSessionManager/UserSessionManager.ts (1)
User: MoumitaM PR: rudderlabs/rudder-sdk-js#1625 File: packages/analytics-js/__tests__/components/userSessionManager/UserSessionManager.test.ts:1374-1385 Timestamp: 2024-02-22T10:46:36.393Z Learning: Multiple cookies with the same name are not possible in web browsers; a newer cookie will overwrite an older one if they share the same name.packages/analytics-js/__tests__/components/userSessionManager/UserSessionManager.test.ts (1)
User: MoumitaM PR: rudderlabs/rudder-sdk-js#1625 File: packages/analytics-js/__tests__/components/userSessionManager/UserSessionManager.test.ts:1374-1385 Timestamp: 2024-02-22T10:46:36.393Z Learning: Multiple cookies with the same name are not possible in web browsers; a newer cookie will overwrite an older one if they share the same name.
Additional comments not posted (12)
packages/analytics-js-common/src/types/Source.ts (1)
21-21: The addition ofworkspaceIdto theSourcetype is correctly implemented.packages/analytics-js/__fixtures__/msw.handlers.ts (1)
80-87: Consider adding cookie headers in the POST handler for/rsaRequestto better simulate the server-side cookie setting feature.packages/analytics-js-common/src/types/LoadOptions.ts (1)
152-153: The addition ofuseServerSideCookiesanddataServerUrlto theLoadOptionstype is correctly implemented.packages/analytics-js/src/components/utilities/loadOptions.ts (1)
60-64: The logic to handle theuseServerSideCookiesflag and validate thedataServerUrlin thenormalizeLoadOptionsfunction is correctly implemented.packages/analytics-js/src/components/configManager/ConfigManager.ts (2)
98-104: The integration ofvalidateAndReturnCookieServerUrlto validatedataServerUrlin theConfigManagerclass is correctly implemented. Ensure that the function behaves as expected during integration tests.
174-174: The addition ofworkspaceIdto thesourceobject in theConfigManagerclass is correctly implemented.packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts (1)
177-177: The addition ofworkspaceIdto theexpectedSourceStateobject in theConfigManagertest suite is correctly implemented.packages/analytics-js/__tests__/components/userSessionManager/UserSessionManager.test.ts (5)
23-24: The addition of imports formsw.serverandHttpClientis appropriate for the new functionalities being tested, such as server-side cookie setting.
89-89: The addition ofdefaultHttpClientto theUserSessionManagerconstructor is crucial for enabling HTTP communication for server-side cookie management. Ensure that all instances ofUserSessionManageracross the project are updated to include this new dependency.
1390-1406: The test cases forsyncValueToStoragemethod correctly handle scenarios whereuseServerSideCookiesis set and not set. This ensures that thesetServerSideCookiemethod is only called when appropriate.
1410-1507: The test cases forsetServerSideCookiemethod are well-implemented. They check the functionality of making external requests for cookie setting, using both the default and a provided server URL. It's important to ensure that the encryption function (encrypt) is correctly implemented and tested since it's mocked here.
1377-1382: The updated test cases forgetExternalAnonymousIdByCookieNamemethod are correctly implemented to handle scenarios where the cookie does not exist and when it does. This ensures robustness in fetching external anonymous IDs.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai generate interesting stats about this repository and render them as a table.@coderabbitai show all the console.log statements in this repository.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
Attention: Patch coverage is 75.80645% with 15 lines in your changes are missing coverage. Please review.
Project coverage is 53.99%. Comparing base (
695b229) to head (0c65220).
Additional details and impacted files
@@ Coverage Diff @@
## develop #1649 +/- ##
===========================================
+ Coverage 53.92% 53.99% +0.06%
===========================================
Files 461 461
Lines 15615 15669 +54
Branches 3101 3112 +11
===========================================
+ Hits 8421 8461 +40
- Misses 5890 5920 +30
+ Partials 1304 1288 -16
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
size-limit report π¦
| Name | Size (Base) | Size (Current) | Size Limit | Status |
|---|---|---|---|---|
| Common Code - No bundling | 15.78 KB | 15.78 KB (0%) | 16.5 KB | β |
| Remote Module Federation Mapping - CDN | 330 B | 330 B (0%) | 512 B | β |
| Remote Module Federated Plugins - CDN | 5.71 KB | 5.71 KB (0%) | 6 KB | β |
| Core ESM - NPM | 7.66 KB | 7.67 KB (+0.12% β²) | 8 KB | β |
| Core CJS - NPM | 22.47 KB | 22.91 KB (+2% β²) | 23 KB | β |
| Core - NPM | 22.56 KB | 23.01 KB (+2.01% β²) | 23 KB | β |
| Core Legacy - CDN | 43 KB | 43.44 KB (+1.04% β²) | 44 KB | β |
| Core - CDN | 22.71 KB | 23.17 KB (+2.03% β²) | 23.5 KB | β |
| Core (legacy build) - CDN - v1.1 | 31.57 KB | 31.57 KB (0%) | 32 KB | β |
| Core - NPM - v1.1 | 31.56 KB | 31.56 KB (0%) | 32 KB | β |
| Service Worker Module | 22.64 KB | 22.64 KB (0%) | 24 KB | β |
| All Integrations (legacy build) - CDN | 98.4 KB | 98.4 KB (0%) | 105 KB | β |
Hello! This PR has been open for 20 days without any activity. Therefore, it's considered as stale and is scheduled to be closed in 10 days. If you're still working on this, please remove the 'Stale' label or add a comment to keep it open. Thanks for your contribution!
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
76.4% Coverage on New Code
0.0% Duplication on New Code
All the previous comments are addressed