Skip to content

Commit

Permalink
revert to previously passing commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eastandwestwind committed Oct 17, 2023
1 parent 41f70d8 commit ba694d5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 53 deletions.
4 changes: 2 additions & 2 deletions clients/fides-js/src/components/tcf/TcfOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ConsentMethod,
PrivacyExperience,
} from "../../lib/consent-types";
import { generateTcString } from "../../lib/tcf";
import { generateFidesString } from "../../lib/tcf";
import {
FidesCookie,
transformTcfPreferencesToCookieKeys,
Expand Down Expand Up @@ -186,7 +186,7 @@ const updateCookie = async (
enabledIds: EnabledIds,
experience: PrivacyExperience
): Promise<FidesCookie> => {
const tcString = await generateTcString({
const tcString = await generateFidesString({
tcStringPreferences: enabledIds,
experience,
});
Expand Down
52 changes: 25 additions & 27 deletions clients/fides-js/src/fides-tcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
UserConsentPreference,
} from "./lib/consent-types";

import { generateTcString, initializeCmpApi } from "./lib/tcf";
import { generateFidesString, initializeCmpApi } from "./lib/tcf";
import {
getInitialCookie,
getInitialFides,
Expand All @@ -82,8 +82,8 @@ import {
} from "./lib/tcf/types";
import { TCF_KEY_MAP } from "./lib/tcf/constants";
import {
generateTcStringFromCookieTcfConsent,
transformTcStringToCookieKeys,
generateFidesStringFromCookieTcfConsent,
transformFidesStringToCookieKeys,
} from "./lib/tcf/utils";

declare global {
Expand Down Expand Up @@ -134,27 +134,25 @@ const updateCookie = async (
};

TCF_KEY_MAP.forEach(({ experienceKey, cookieKey, enabledIdsKey }) => {
if (experienceKey) {
tcSavePrefs[cookieKey] = [];
experience[experienceKey]?.forEach((record) => {
const pref: UserConsentPreference = getInitialPreference(record);
// map experience to tcSavePrefs (same as cookie keys)
tcSavePrefs[cookieKey]?.push({
// @ts-ignore
id: record.id,
preference: pref,
});
// add to enabledIds only if user consent is True
if (transformUserPreferenceToBoolean(pref)) {
if (enabledIdsKey) {
enabledIds[enabledIdsKey].push(record.id.toString());
}
}
tcSavePrefs[cookieKey] = [];
experience[experienceKey]?.forEach((record) => {
const pref: UserConsentPreference = getInitialPreference(record);
// map experience to tcSavePrefs (same as cookie keys)
tcSavePrefs[cookieKey]?.push({
// @ts-ignore
id: record.id,
preference: pref,
});
}
// add to enabledIds only if user consent is True
if (transformUserPreferenceToBoolean(pref)) {
if (enabledIdsKey) {
enabledIds[enabledIdsKey].push(record.id.toString());
}
}
});
});

const fidesString = await generateTcString({
const fidesString = await generateFidesString({
experience,
tcStringPreferences: enabledIds,
});
Expand All @@ -168,14 +166,14 @@ const updateCookie = async (
const init = async (config: FidesConfig) => {
const cookie = getInitialCookie(config);
if (config.options.fidesString) {
// If a TC str is explicitly passed in, we override the associated cookie props, which are then used to
// If a fidesString is explicitly passed in, we override the associated cookie props, which are then used to
// override associated props in experience
debugLog(
config.options.debug,
"Explicit TC string detected. Proceeding to override all TCF preferences with given TC string"
"Explicit fidesString detected. Proceeding to override all TCF preferences with given fidesString"
);
cookie.fides_string = config.options.fidesString;
cookie.tcf_consent = transformTcStringToCookieKeys(
cookie.tcf_consent = transformFidesStringToCookieKeys(
config.options.fidesString,
config.options.debug
);
Expand All @@ -185,9 +183,9 @@ const init = async (config: FidesConfig) => {
isPrivacyExperience(config.experience) &&
experienceIsValid(config.experience, config.options)
) {
// This state should not be hit, but just in case: if tc string is missing on cookie but we have tcf consent,
// we should generate tc string so that our CMP API accurately reflects user preference
cookie.fides_string = await generateTcStringFromCookieTcfConsent(
// This state should not be hit, but just in case: if fidesString is missing on cookie but we have tcf consent,
// we should generate fidesString so that our CMP API accurately reflects user preference
cookie.fides_string = await generateFidesStringFromCookieTcfConsent(
config.experience,
cookie.tcf_consent
);
Expand Down
4 changes: 2 additions & 2 deletions clients/fides-js/src/lib/tcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const generateAcString = ({
};

/**
* Generate TC String based on TCF-related info from privacy experience.
* Generate FidesString based on TCF and AC-related info from privacy experience.
* Called when there is either a FidesInitialized or FidesUpdated event
*/
export const generateTcString = async ({
export const generateFidesString = async ({
experience,
tcStringPreferences,
}: {
Expand Down
33 changes: 16 additions & 17 deletions clients/fides-js/src/lib/tcf/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { TCModel, TCString, Vector } from "@iabtechlabtcf/core";
import { PrivacyExperience } from "../consent-types";
import { EnabledIds, TcfCookieConsent, TcfCookieKeyConsent } from "./types";
import { TCF_KEY_MAP } from "./constants";
import { generateTcString } from "../tcf";
import { generateFidesString } from "../tcf";
import { debugLog } from "../consent-utils";

export const transformTcStringToCookieKeys = (
tcString: string,
export const transformFidesStringToCookieKeys = (
fidesString: string,
debug: boolean
): TcfCookieConsent => {
const tcModel: TCModel = TCString.decode(tcString || "");
// Defer: to fully support AC string, we need to split out TC from AC string https://github.com/ethyca/fides/issues/4263
const tcModel: TCModel = TCString.decode(fidesString || "");

const cookieKeys: TcfCookieConsent = {};

Expand All @@ -25,13 +26,13 @@ export const transformTcStringToCookieKeys = (
});
debugLog(
debug,
`Generated cookie.tcf_consent from explicit tc string.`,
`Generated cookie.tcf_consent from explicit fidesString.`,
cookieKeys
);
return cookieKeys;
};

export const generateTcStringFromCookieTcfConsent = async (
export const generateFidesStringFromCookieTcfConsent = async (
experience: PrivacyExperience,
tcfConsent: TcfCookieConsent
): Promise<string> => {
Expand All @@ -46,19 +47,17 @@ export const generateTcStringFromCookieTcfConsent = async (
};

TCF_KEY_MAP.forEach(({ cookieKey, enabledIdsKey }) => {
if (cookieKey) {
const cookieKeyConsent: TcfCookieKeyConsent | undefined =
tcfConsent[cookieKey];
if (cookieKeyConsent) {
Object.keys(cookieKeyConsent).forEach((key: string | number) => {
if (cookieKeyConsent[key] && enabledIdsKey) {
enabledIds[enabledIdsKey].push(key.toString());
}
});
}
const cookieKeyConsent: TcfCookieKeyConsent | undefined =
tcfConsent[cookieKey];
if (cookieKeyConsent) {
Object.keys(cookieKeyConsent).forEach((key: string | number) => {
if (cookieKeyConsent[key] && enabledIdsKey) {
enabledIds[enabledIdsKey].push(key.toString());
}
});
}
});
return generateTcString({
return generateFidesString({
experience,
tcStringPreferences: enabledIds,
});
Expand Down
10 changes: 5 additions & 5 deletions clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,12 +1414,12 @@ describe("Fides-js TCF", () => {
);
});
});
// fixme- wait for when win.__tcfapi exists
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting

cy.window().then((win) => {
win.__tcfapi("addEventListener", 2, cy.stub().as("TCFEvent"));
cy.waitUntilFidesInitialized().then(() => {
cy.window().then((win) => {
win.__tcfapi("addEventListener", 2, cy.stub().as("TCFEvent"));
});
});

// Open the modal
cy.get("#fides-modal-link").click();

Expand Down

0 comments on commit ba694d5

Please sign in to comment.