Skip to content

ENG-2694: Add fides_external_id option to FidesJS SDK to provide a custom ID on preferences#7094

Merged
NevilleS merged 16 commits intomainfrom
ns-fides-js-external-id
Feb 14, 2026
Merged

ENG-2694: Add fides_external_id option to FidesJS SDK to provide a custom ID on preferences#7094
NevilleS merged 16 commits intomainfrom
ns-fides-js-external-id

Conversation

@NevilleS
Copy link
Copy Markdown
Contributor

@NevilleS NevilleS commented Dec 9, 2025

Ticket ENG-2694

Description Of Changes

Add support for an optional fides_external_id in FidesJS so customers can pass a custom user ID that is sent with privacy-preferences and notices-served API calls and stored in the consent cookie. The option can be set via init options, overrides (query param, cookie, window), and in the Privacy Center via FIDES_EXTERNAL_ID env and the /fides.js API.

Fides.setIdentity() helper: Customers can set identity after init via Fides.setIdentity({ external_id: "user-123" }). Only external_id is supported; reserved keys (e.g. fides_user_device_id) and verified keys (email, phone_number) throw. Empty or whitespace-only external_id throws (omit the key to leave identity unchanged). Values are trimmed before saving. Init treats empty/whitespace fides_external_id as not set, consistent with setIdentity. Identity key constants are centralized in cookie.ts (FIDES_* prefixed).

Code Changes

  • Add fidesExternalId to FidesJS type definitions, consent constants (override validation), and init defaults
  • Persist and read external_id in cookie identity in getOrMakeFidesCookie / makeFidesCookie / makeDefaultIdentity
  • Add FIDES_EXTERNAL_ID to Privacy Center settings, env loading, and fides.js API config
  • Document fides_external_id in FidesOptions docs and add Cypress tests for external_id in consent banner flows
  • setIdentity: Add Fides.setIdentity(identity) in consent-types, set-identity module (validation, trim, empty/whitespace reject), init-utils wiring; JSDoc and generated Fides.md; unit tests (incl. empty string, whitespace-only, trim); Cypress tests (setIdentity then save, validation errors, empty string, GPC edge case)
  • Init/cookie alignment: makeDefaultIdentity and getOrMakeFidesCookie treat empty/whitespace fidesExternalId as not set; use ?? for device-id fallback; FidesOptions docs note empty/whitespace behavior

Steps to Confirm

  1. Load a page with FidesJS and fides_external_id set via override or init; confirm privacy-preferences and notices-served requests include the id and the consent cookie stores it.
  2. After init, call Fides.setIdentity({ external_id: "user-456" }) then save preferences; confirm the id is in the API request. Call setIdentity({ external_id: "" }) and confirm it throws; omit the key and confirm identity is unchanged.

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Dec 9, 2025

Deployment failed with the following error:

You must set up Two-Factor Authentication before accessing this team.

View Documentation: https://vercel.com/docs/two-factor-authentication

Copy link
Copy Markdown
Contributor Author

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

some changes needed to tidy this up

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Feb 14, 2026 3:57pm
fides-privacy-center Ignored Ignored Feb 14, 2026 3:57pm

Request Review

Copy link
Copy Markdown
Contributor Author

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

missed one more unneeded change

@NevilleS NevilleS force-pushed the ns-fides-js-external-id branch from 911b7c9 to 132262d Compare February 12, 2026 22:41
Neville Samuell and others added 2 commits February 12, 2026 17:55
- Add fidesExternalId to type definitions, override support, and init defaults
- Document fides_external_id and add test mock default
- Implement cookie storage and persistence for external_id
- Add FIDES_EXTERNAL_ID env/API support in Privacy Center
- Add Cypress tests for external_id in consent banner
- Revert Privacy Center notice-driven component usage per review

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@NevilleS NevilleS force-pushed the ns-fides-js-external-id branch from 4132479 to b3f2b06 Compare February 12, 2026 22:55
Copy link
Copy Markdown
Contributor Author

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Self review notes

Neville Samuell and others added 2 commits February 12, 2026 18:03
@NevilleS NevilleS marked this pull request as ready for review February 12, 2026 23:11
@NevilleS NevilleS requested a review from a team as a code owner February 12, 2026 23:11
@NevilleS NevilleS requested review from gilluminate and speaker-ender and removed request for a team and speaker-ender February 12, 2026 23:11
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 12, 2026

Greptile Overview

Greptile Summary

Added support for fides_external_id option in FidesJS SDK, allowing customers to provide a custom user ID that is included in privacy-preferences and notices-served API calls and stored in the consent cookie.

Key changes:

  • Added fidesExternalId field to FidesInitOptions interface and Identity type as optional fields
  • Implemented makeDefaultIdentity() helper function to generate identity objects with optional external_id
  • Updated makeFidesCookie() and getOrMakeFidesCookie() to accept and handle fidesExternalId parameter
  • Added logic to preserve existing external_id from cookies when not explicitly provided, and update it when a new value is provided
  • Added override validation for fides_external_id with regex /.+/ requiring non-empty strings
  • Comprehensive test coverage including edge cases (undefined identity, empty strings, preservation of existing values)
  • Added Cypress e2e tests verifying external_id is sent correctly in API calls
  • Updated documentation with clear examples of usage

Implementation notes:

  • The external_id is only set when fidesExternalId is a non-null, non-undefined value (empty strings are rejected)
  • When fidesExternalId is not provided, existing external_id values from the cookie are preserved
  • The fides_user_device_id continues to be generated and included alongside external_id to maintain per-device tracking

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean, well-tested, and follows existing patterns in the codebase. The feature adds optional functionality without breaking existing behavior. Test coverage is comprehensive including edge cases, and the logic properly handles null/undefined values to prevent data corruption.
  • No files require special attention

Important Files Changed

Filename Overview
clients/fides-js/src/lib/consent-types.ts Added fidesExternalId field to FidesInitOptions and Identity type; clean type additions with proper optional handling
clients/fides-js/src/lib/cookie.ts Implemented external_id handling in cookie operations; logic properly handles setting and preserving external_id
clients/fides-js/src/lib/consent-constants.ts Added validation config for fides_external_id override with appropriate regex requiring non-empty values
clients/fides-js/tests/lib/cookie.test.ts Comprehensive test coverage for external_id functionality including edge cases like undefined identity and empty strings
clients/privacy-center/cypress/e2e/fides-js/consent-banner.cy.ts Added Cypress e2e tests verifying external_id is correctly sent in privacy-preferences and notices-served API calls

Last reviewed commit: 3899a21

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

11 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Contributor

@gilluminate gilluminate left a comment

Choose a reason for hiding this comment

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

Looks good! tested locally and it works well. Just one clarification question and good to go!

Neville Samuell and others added 6 commits February 13, 2026 08:52
Co-authored-by: Jason Gill <jason.gill@ethyca.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…nt-constants override

Co-authored-by: Cursor <cursoragent@cursor.com>
…y fides_external_id; cookie use ??

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	clients/fides-js/src/lib/cookie.ts
@NevilleS
Copy link
Copy Markdown
Contributor Author

Updated the PR description to include the Fides.setIdentity() helper and related behavior (empty/whitespace validation, trim, init alignment, identity constants).

@NevilleS NevilleS changed the title Add fides_external_id option to FidesJS SDK to provide a custom ID on preferences ENG-2694: Add fides_external_id option to FidesJS SDK to provide a custom ID on preferences Feb 13, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@gilluminate gilluminate self-requested a review February 13, 2026 18:41
Copy link
Copy Markdown
Contributor

@gilluminate gilluminate left a comment

Choose a reason for hiding this comment

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

Approved with nit-picks. No blockers though. 👍

cursoragent and others added 2 commits February 14, 2026 14:29
…_OPTION_KEY_EXTERNAL_ID

- Add normalizeIdentityValue() to centralize null/undefined/empty/whitespace handling
- Refactor makeDefaultIdentity, getOrMakeFidesCookie, and setIdentity to use it
- Use FIDES_IDENTITY_OPTION_KEY_EXTERNAL_ID in consent-constants override config
- Add unit tests for normalizeIdentityValue
- Update setIdentity error message for whitespace-only rejection

Co-authored-by: Neville Samuell <NevilleS@users.noreply.github.com>
Co-authored-by: Neville Samuell <NevilleS@users.noreply.github.com>
cursoragent and others added 2 commits February 14, 2026 14:42
Importing from cookie into consent-constants causes Cypress suite failures.
The constant was not used anywhere in the codebase.

Co-authored-by: Neville Samuell <NevilleS@users.noreply.github.com>
Co-authored-by: Neville Samuell <NevilleS@users.noreply.github.com>
@NevilleS NevilleS added this pull request to the merge queue Feb 14, 2026
Merged via the queue into main with commit dbdf817 Feb 14, 2026
40 of 41 checks passed
@NevilleS NevilleS deleted the ns-fides-js-external-id branch February 14, 2026 17:21
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.

3 participants