From f2562daef2ba4f173764d565e8d6bf94f2a0ff6c Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Tue, 18 Jun 2024 15:18:05 -0600 Subject: [PATCH 1/9] reduce file size of returned `fides.js` --- clients/privacy-center/pages/api/fides-js.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clients/privacy-center/pages/api/fides-js.ts b/clients/privacy-center/pages/api/fides-js.ts index a5e639b0ff..4e79926855 100644 --- a/clients/privacy-center/pages/api/fides-js.ts +++ b/clients/privacy-center/pages/api/fides-js.ts @@ -293,12 +293,11 @@ export default async function handler( isTestMode // let end-to-end tests set the config and initialize as needed ? "" : ` - var fidesConfig = ${fidesConfigJSON}; window.Fides.config = ${fidesConfigJSON}; - ${skipInitialization ? "" : `window.Fides.init(fidesConfig);`} + ${skipInitialization ? "" : `window.Fides.init();`} ${ environment.settings.DEBUG && skipInitialization - ? `console.log("fides.js initialization skipped. Call window.Fides.init() manually.");` + ? `console.log("Fides initialization skipped. Call window.Fides.init() manually.");` : "" }` } From 4d2d75eaac2baab2d17cdd3eaea133ceff91ebf3 Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Tue, 18 Jun 2024 16:39:15 -0600 Subject: [PATCH 2/9] fix Cypress tests --- clients/privacy-center/cypress/e2e/fides-js.cy.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clients/privacy-center/cypress/e2e/fides-js.cy.ts b/clients/privacy-center/cypress/e2e/fides-js.cy.ts index a2dcc25b51..b82792b34b 100644 --- a/clients/privacy-center/cypress/e2e/fides-js.cy.ts +++ b/clients/privacy-center/cypress/e2e/fides-js.cy.ts @@ -15,10 +15,10 @@ describe("fides.js API route", () => { .to.match(/^\s+\(function/, "should be an IIFE") .to.match(/\}\)\(\);\s+$/, "should be an IIFE"); expect(response.body) - .to.match(/var fidesConfig = \{/, "should bundle Fides.init") - .to.match(/Fides.init\(fidesConfig\);/, "should bundle Fides.init"); + .to.match(/window.Fides.config = \{/, "should bundle Fides.init") + .to.match(/Fides.init\(\);/, "should call Fides.init"); const matches = response.body.match( - /var fidesConfig = (?\{.*?\});/ + /window.Fides.config = (?\{.*?\});/ ); expect(matches).to.have.nested.property("groups.json"); expect(JSON.parse(matches.groups.json)) @@ -44,9 +44,9 @@ describe("fides.js API route", () => { describe("when pre-fetching geolocation", () => { it("returns geolocation if provided as a '?geolocation' query param", () => { cy.request("/fides.js?geolocation=US-CA").then((response) => { - expect(response.body).to.match(/var fidesConfig = \{/); + expect(response.body).to.match(/window.Fides.config = \{/); const matches = response.body.match( - /var fidesConfig = (?\{.*?\});/ + /window.Fides.config = (?\{.*?\});/ ); expect(JSON.parse(matches.groups.json)) .to.have.nested.property("geolocation") @@ -66,9 +66,9 @@ describe("fides.js API route", () => { "CloudFront-Viewer-Country-Region": "IDF", }, }).then((response) => { - expect(response.body).to.match(/var fidesConfig = \{/); + expect(response.body).to.match(/window.Fides.config = \{/); const matches = response.body.match( - /var fidesConfig = (?\{.*?\});/ + /window.Fides.config = (?\{.*?\});/ ); expect(JSON.parse(matches.groups.json)) .to.have.nested.property("geolocation") From d8d6716ad90f6bf95b541fcddd518374af247bae Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Wed, 19 Jun 2024 14:01:52 -0600 Subject: [PATCH 3/9] pass along `gppEnabled` and update related tests --- clients/fides-js/src/fides-tcf.ts | 1 + clients/fides-js/src/fides.ts | 1 + clients/fides-js/src/lib/consent-types.ts | 3 +++ .../privacy-center/cypress/e2e/fides-js.cy.ts | 5 ++++ clients/privacy-center/pages/api/fides-js.ts | 27 ++++++++----------- .../public/fides-js-components-demo.html | 10 +++---- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/clients/fides-js/src/fides-tcf.ts b/clients/fides-js/src/fides-tcf.ts index aa1dc05ab4..e39569fbda 100644 --- a/clients/fides-js/src/fides-tcf.ts +++ b/clients/fides-js/src/fides-tcf.ts @@ -235,6 +235,7 @@ const _Fides: FidesGlobal = { fidesApiUrl: "", serverSideFidesApiUrl: "", tcfEnabled: true, + gppEnabled: false, fidesEmbed: false, fidesDisableSaveApi: false, fidesDisableNoticesServedApi: false, diff --git a/clients/fides-js/src/fides.ts b/clients/fides-js/src/fides.ts index 795c7225de..dbc3daf62f 100644 --- a/clients/fides-js/src/fides.ts +++ b/clients/fides-js/src/fides.ts @@ -173,6 +173,7 @@ const _Fides: FidesGlobal = { fidesApiUrl: "", serverSideFidesApiUrl: "", tcfEnabled: false, + gppEnabled: false, fidesEmbed: false, fidesDisableSaveApi: false, fidesDisableNoticesServedApi: false, diff --git a/clients/fides-js/src/lib/consent-types.ts b/clients/fides-js/src/lib/consent-types.ts index 2e02d2514a..98e7d0b6a6 100644 --- a/clients/fides-js/src/lib/consent-types.ts +++ b/clients/fides-js/src/lib/consent-types.ts @@ -78,6 +78,9 @@ export interface FidesInitOptions { // Whether we should show the TCF modal tcfEnabled: boolean; + // Whether to include the GPP extension + gppEnabled: boolean; + // Whether we should "embed" the fides.js overlay UI (ie. “Layer 2”) into a web page instead of as a pop-up // overlay, and never render the banner (ie. “Layer 1”). fidesEmbed: boolean; diff --git a/clients/privacy-center/cypress/e2e/fides-js.cy.ts b/clients/privacy-center/cypress/e2e/fides-js.cy.ts index b82792b34b..94d215c57b 100644 --- a/clients/privacy-center/cypress/e2e/fides-js.cy.ts +++ b/clients/privacy-center/cypress/e2e/fides-js.cy.ts @@ -208,6 +208,11 @@ describe("fides.js API route", () => { expect(response.body).not.to.match(/window.Fides.init(fidesConfig)/); }); }); + it("does not initialize GPP", () => { + cy.request("/fides.js?initialize=false&gpp=true").then((response) => { + expect(response.body).not.to.match(/window.__gpp/); + }); + }); }); }); diff --git a/clients/privacy-center/pages/api/fides-js.ts b/clients/privacy-center/pages/api/fides-js.ts index 4e79926855..b380078859 100644 --- a/clients/privacy-center/pages/api/fides-js.ts +++ b/clients/privacy-center/pages/api/fides-js.ts @@ -167,11 +167,9 @@ export default async function handler( } } - // These query params are used for testing purposes only, and should not be used - // in production. They allow for the config to be injected by the test framework - // and delay the initialization of fides.js until the test framework is ready. - const { e2e: e2eQuery, tcf: tcfQuery } = req.query; - const isTestMode = e2eQuery === "true"; + // This query param is used for testing purposes only, and should not be used + // in production. + const { tcf: tcfQuery } = req.query; // We determine server-side whether or not to send the TCF bundle, which is based // on whether or not the experience is marked as TCF. This means for TCF, we *must* @@ -209,6 +207,7 @@ export default async function handler( privacyCenterUrl: environment.settings.PRIVACY_CENTER_URL, fidesApiUrl: environment.settings.FIDES_API_URL, tcfEnabled, + gppEnabled, serverSideFidesApiUrl: environment.settings.SERVER_SIDE_FIDES_API_URL || environment.settings.FIDES_API_URL, @@ -289,17 +288,13 @@ export default async function handler( document.head.append(style); ` : "" - }${ - isTestMode // let end-to-end tests set the config and initialize as needed - ? "" - : ` - window.Fides.config = ${fidesConfigJSON}; - ${skipInitialization ? "" : `window.Fides.init();`} - ${ - environment.settings.DEBUG && skipInitialization - ? `console.log("Fides initialization skipped. Call window.Fides.init() manually.");` - : "" - }` + } + window.Fides.config = ${fidesConfigJSON}; + ${skipInitialization ? "" : `window.Fides.init();`} + ${ + environment.settings.DEBUG && skipInitialization + ? `console.log("Fides initialization skipped. Call window.Fides.init() manually.");` + : "" } })(); `; diff --git a/clients/privacy-center/public/fides-js-components-demo.html b/clients/privacy-center/public/fides-js-components-demo.html index 4a6632e84a..e5ec433b0d 100644 --- a/clients/privacy-center/public/fides-js-components-demo.html +++ b/clients/privacy-center/public/fides-js-components-demo.html @@ -12,18 +12,18 @@