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

Update fides.js API options and improve automated tests #4314

Merged
merged 24 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f72cfff
Rename FidesPreferenceToggled -> FidesUIChanged
NevilleS Oct 20, 2023
3bc9461
Format
NevilleS Oct 20, 2023
e288b64
Fix some lint warnings
NevilleS Oct 20, 2023
0fa918f
Finish renaming to FidesUIChanged
NevilleS Oct 22, 2023
df91340
Add placeholder CHANGELOG
NevilleS Oct 22, 2023
b55181d
Minor cleanup of user preferences specs
NevilleS Oct 22, 2023
003800d
Update comments for consistency
NevilleS Oct 22, 2023
331006d
Fix TCF prefs specs: use fides_string in cookie, properly stub experi…
NevilleS Oct 22, 2023
45ebfb0
Reuse cookie definition on all user preferences specs
NevilleS Oct 22, 2023
a80ede6
Add test case comments for understanding, assert on expected TC strin…
NevilleS Oct 22, 2023
3704696
Reorder precedence in comment (for clarity)
NevilleS Oct 22, 2023
f6ddcb5
Add comments to getOverrideFidesOptions
NevilleS Oct 22, 2023
952c6c2
Rename from window.config.fides -> window.config.tc_info (for now)
NevilleS Oct 22, 2023
62c026e
Formatting
NevilleS Oct 22, 2023
70407fc
Formatting
NevilleS Oct 22, 2023
f390866
Fix broken spec
NevilleS Oct 22, 2023
4a0966e
Update CHANGELOG
NevilleS Oct 22, 2023
2cb808f
Fix lint error
NevilleS Oct 22, 2023
3748862
Update CHANGELOG.md
NevilleS Oct 23, 2023
209ccaf
Update TODO comment
NevilleS Oct 23, 2023
0448459
Update TODOs to link to follow-up issue
NevilleS Oct 23, 2023
d880de1
Merge branch 'main' of github.com:ethyca/fides into PROD-1234-ns-upda…
NevilleS Oct 23, 2023
c718fb2
Add FidesCookie type declaration for safety
NevilleS Oct 23, 2023
846ed0b
Merge branch 'main' of github.com:ethyca/fides into PROD-1234-ns-upda…
NevilleS Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The types of changes are:
- Cleans up CSS for fidesEmbed mode [#4306](https://github.com/ethyca/fides/pull/4306)

### Added
- Added a `FidesPreferenceToggled` event to Fides.js to track when user preferences change without being saved [#4253](https://github.com/ethyca/fides/pull/4253)
- Added a `FidesUIChanged` event to Fides.js to track when user preferences change without being saved [](?) and [#4253](https://github.com/ethyca/fides/pull/4253)
- Add AC Systems to the TCF Overlay under Vendor Consents section [#4266](https://github.com/ethyca/fides/pull/4266/)

### Changed
Expand Down
6 changes: 1 addition & 5 deletions clients/fides-js/src/components/notices/NoticeOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ const NoticeOverlay: FunctionComponent<OverlayProps> = ({
enabledNoticeKeys={draftEnabledNoticeKeys}
onChange={(updatedKeys) => {
setDraftEnabledNoticeKeys(updatedKeys);
dispatchFidesEvent(
"FidesPreferenceToggled",
cookie,
options.debug
);
dispatchFidesEvent("FidesUIChanged", cookie, options.debug);
}}
/>
</div>
Expand Down
6 changes: 1 addition & 5 deletions clients/fides-js/src/components/tcf/TcfOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,7 @@ const TcfOverlay: FunctionComponent<OverlayProps> = ({
enabledIds={draftIds}
onChange={(updatedIds) => {
setDraftIds(updatedIds);
dispatchFidesEvent(
"FidesPreferenceToggled",
cookie,
options.debug
);
dispatchFidesEvent("FidesUIChanged", cookie, options.debug);
}}
activeTabIndex={activeTabIndex}
onTabChange={setActiveTabIndex}
Expand Down
3 changes: 2 additions & 1 deletion clients/fides-js/src/fides-tcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ declare global {
parameter?: number | string
) => void;
config: {
fides: OverrideOptions;
// TODO: make configurable!
tc_info: OverrideOptions;
NevilleS marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion clients/fides-js/src/fides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ declare global {
interface Window {
Fides: Fides;
config: {
fides: OverrideOptions;
// TODO: make this configurable!
tc_info: OverrideOptions;
};
}
}
Expand Down
8 changes: 4 additions & 4 deletions clients/fides-js/src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import { debugLog } from "./consent-utils";
* - FidesInitialized: dispatched when initialization is complete, from Fides.init()
* - FidesUpdated: dispatched when preferences are updated, from updateConsentPreferences() or Fides.init()
* - FidesUIShown: dispatched when either the banner or modal is shown to the user
* - FidesUIChanged: dispatched when preferences are changed but not saved, i.e. "dirty".
* - FidesModalClosed: dispatched when the modal is closed
* - FidesPreferenceToggled: dispatched when preferences are toggled but not saved, i.e. "dirty".
*/
export type FidesEventType =
| "FidesInitialized"
| "FidesUpdated"
| "FidesUIShown"
| "FidesModalClosed"
| "FidesPreferenceToggled";
| "FidesUIChanged"
| "FidesModalClosed";

// Bonus points: update the WindowEventMap interface with our custom event types
declare global {
interface WindowEventMap {
FidesInitialized: FidesEvent;
FidesUpdated: FidesEvent;
FidesUIShown: FidesEvent;
FidesUIChanged: FidesEvent;
FidesModalClosed: FidesEvent;
FidesPreferenceToggled: FidesEvent;
}
}

Expand Down
24 changes: 18 additions & 6 deletions clients/fides-js/src/lib/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,33 @@ const automaticallyApplyGPCPreferences = ({

/**
* Gets and validates Fides override options provided through URL query params, cookie or window obj.
*
* If the same override option is provided in multiple ways, load the value in this order:
* 1) query param (top priority)
* 2) window obj (second priority)
* 3) cookie value (last priority)
eastandwestwind marked this conversation as resolved.
Show resolved Hide resolved
*/
export const getOverrideFidesOptions = (): Partial<FidesOptionOverrides> => {
const overrideOptions: Partial<FidesOptionOverrides> = {};
if (typeof window !== "undefined") {
const params = new URLSearchParams(document.location.search);
// Grab query params if provided in the URL (e.g. "?fides_string=123...")
const queryParams = new URLSearchParams(window.location.search);
NevilleS marked this conversation as resolved.
Show resolved Hide resolved
// Grab global window object if provided (e.g. window.config.tc_info = { fides_string: "123..." })
// TODO: make this configurable (window.config.tc_info, window.my_config, etc.) and default to window.fides_config
const windowObj = window.config?.tc_info;
NevilleS marked this conversation as resolved.
Show resolved Hide resolved

// Look for each of the override options in all three locations: query params, window object, cookie
FIDES_OVERRIDE_OPTIONS_VALIDATOR_MAP.forEach(
({ fidesOption, fidesOptionType, fidesOverrideKey, validationRegex }) => {
// look for override options on URL query params, window obj, and cookie
const queryParamOverride: string | null = params.get(fidesOverrideKey);
const windowObjOverride: string | boolean | undefined = window.config
?.fides
? window.config?.fides[fidesOverrideKey]
const queryParamOverride: string | null =
queryParams.get(fidesOverrideKey);
const windowObjOverride: string | boolean | undefined = windowObj
? windowObj[fidesOverrideKey]
: undefined;
const cookieOverride: string | undefined =
getCookieByName(fidesOverrideKey);

// Load the override option value, respecting the order of precedence (query params > window object > cookie)
const value = queryParamOverride || windowObjOverride || cookieOverride;
if (value && validationRegex.test(value.toString())) {
// coerce to expected type in FidesOptions
Expand Down
Loading
Loading