From 754c93f59f3d2005e98eac48cfbbba2b582b16d0 Mon Sep 17 00:00:00 2001 From: Sebastian Sangervasi <2236777+ssangervasi@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:29:26 -0800 Subject: [PATCH] pc/consent: Restructure consent src dir to make modle/browser distinction clearer (#1904) --- clients/privacy-center/.gitignore | 3 +++ .../privacy-center/packages/fides-consent/README.md | 2 +- .../packages/fides-consent/package.json | 2 +- .../packages/fides-consent/rollup.config.js | 8 ++++---- .../packages/fides-consent/src/fides-consent.ts | 12 ++++++++++++ .../packages/fides-consent/src/index.ts | 7 ------- .../packages/fides-consent/src/{ => lib}/cookie.ts | 1 - .../packages/fides-consent/src/lib/index.ts | 6 ++++++ 8 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 clients/privacy-center/packages/fides-consent/src/fides-consent.ts delete mode 100644 clients/privacy-center/packages/fides-consent/src/index.ts rename clients/privacy-center/packages/fides-consent/src/{ => lib}/cookie.ts (97%) create mode 100644 clients/privacy-center/packages/fides-consent/src/lib/index.ts diff --git a/clients/privacy-center/.gitignore b/clients/privacy-center/.gitignore index f98e120312..a8c4b0219a 100644 --- a/clients/privacy-center/.gitignore +++ b/clients/privacy-center/.gitignore @@ -82,6 +82,9 @@ typings/ # The consent script is a build artifact. public/fides-consent.js +# Fix conflict with root .gitignore Python rule. +!lib + # Nuxt.js build / generate output .nuxt dist diff --git a/clients/privacy-center/packages/fides-consent/README.md b/clients/privacy-center/packages/fides-consent/README.md index e971ced010..d89b4a8cd3 100644 --- a/clients/privacy-center/packages/fides-consent/README.md +++ b/clients/privacy-center/packages/fides-consent/README.md @@ -27,7 +27,7 @@ In this example, `data_sharing` is a cookie key that has been [configured in the ## fides-consent.mjs & fides-consent.d.ts -This package also exports its cookie utilities (`cookie.ts`) as a module the Privacy Center can import. This ensures the Privacy Center uses the exact same logic for reading & writing cookie data. This module is only used locally for convenience and is not published. +This package also exports its library (`src/lib`) as a module the Privacy Center can import. This ensures the Privacy Center uses the exact same logic for reading & writing cookie data. This module is only used locally for convenience and is not published. Note that this module does _not_ define the `Fides.consent` global, as that is unnecessary when using modules. diff --git a/clients/privacy-center/packages/fides-consent/package.json b/clients/privacy-center/packages/fides-consent/package.json index 6ccd24c51a..077a6167a5 100644 --- a/clients/privacy-center/packages/fides-consent/package.json +++ b/clients/privacy-center/packages/fides-consent/package.json @@ -2,7 +2,7 @@ "name": "fides-consent", "version": "0.0.1", "description": "Fides consent script", - "source": "src/index.ts", + "source": "src/lib/index.ts", "license": "Apache-2.0", "publishConfig": { "access": "public" diff --git a/clients/privacy-center/packages/fides-consent/rollup.config.js b/clients/privacy-center/packages/fides-consent/rollup.config.js index bebf6a916e..ba5e483144 100644 --- a/clients/privacy-center/packages/fides-consent/rollup.config.js +++ b/clients/privacy-center/packages/fides-consent/rollup.config.js @@ -7,11 +7,11 @@ const name = require("./package.json").name; export default [ { - input: `src/index.ts`, + input: `src/${name}.ts`, plugins: [ nodeResolve(), esbuild({ - minify: process.env.NODE_ENV === "development", + minify: process.env.NODE_ENV !== "development", }), copy({ // Automatically add the built script to the privacy center's static files for testing: @@ -31,7 +31,7 @@ export default [ ], }, { - input: `src/cookie.ts`, + input: `src/lib/index.ts`, plugins: [nodeResolve(), esbuild()], output: [ { @@ -43,7 +43,7 @@ export default [ ], }, { - input: `src/cookie.ts`, + input: `src/lib/index.ts`, plugins: [dts()], output: [ { diff --git a/clients/privacy-center/packages/fides-consent/src/fides-consent.ts b/clients/privacy-center/packages/fides-consent/src/fides-consent.ts new file mode 100644 index 0000000000..59bb251914 --- /dev/null +++ b/clients/privacy-center/packages/fides-consent/src/fides-consent.ts @@ -0,0 +1,12 @@ +/** + * This script defines the browser script entrypoint for Fides consent logic. It is distributed + * as `fides-consent.js` and is accessed from the `Fides` global variable. + */ + +import { getConsentCookie } from "./lib/cookie"; + +const Fides = { + consent: getConsentCookie(), +}; + +export default Fides; diff --git a/clients/privacy-center/packages/fides-consent/src/index.ts b/clients/privacy-center/packages/fides-consent/src/index.ts deleted file mode 100644 index f434ffffcf..0000000000 --- a/clients/privacy-center/packages/fides-consent/src/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { getConsentCookie } from "./cookie"; - -const Fides = { - consent: getConsentCookie(), -}; - -export default Fides; diff --git a/clients/privacy-center/packages/fides-consent/src/cookie.ts b/clients/privacy-center/packages/fides-consent/src/lib/cookie.ts similarity index 97% rename from clients/privacy-center/packages/fides-consent/src/cookie.ts rename to clients/privacy-center/packages/fides-consent/src/lib/cookie.ts index 7ef3e55705..6ce4800c08 100644 --- a/clients/privacy-center/packages/fides-consent/src/cookie.ts +++ b/clients/privacy-center/packages/fides-consent/src/lib/cookie.ts @@ -1,4 +1,3 @@ -// import config from "config/config.json"; import { getCookie, setCookie, Types } from "typescript-cookie"; /** diff --git a/clients/privacy-center/packages/fides-consent/src/lib/index.ts b/clients/privacy-center/packages/fides-consent/src/lib/index.ts new file mode 100644 index 0000000000..63000829c7 --- /dev/null +++ b/clients/privacy-center/packages/fides-consent/src/lib/index.ts @@ -0,0 +1,6 @@ +/** + * This module defines the library of features are exported as a module. This library + * is then bundled into `fides-consent.js` and imported by Privacy Center app, so that + * both can share the same consent logic. + */ +export * from "./cookie";