From c7748aef463865bbd478af36b938a751b0d80a16 Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Tue, 29 Oct 2024 16:47:06 -0600 Subject: [PATCH 1/3] versioning support for Fides --- clients/admin-ui/package.json | 6 ++++-- clients/fides-js/package.json | 5 +++-- clients/package-lock.json | 9 +++++---- clients/privacy-center/package.json | 7 ++++--- clients/privacy-center/pages/api/fides-js.ts | 4 ++++ clients/turbo.json | 3 +++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/clients/admin-ui/package.json b/clients/admin-ui/package.json index 5f8a201c7a..68e0d2a101 100644 --- a/clients/admin-ui/package.json +++ b/clients/admin-ui/package.json @@ -1,6 +1,7 @@ { "name": "admin-ui", "private": true, + "version": "2.48.0", "scripts": { "analyze": "cross-env ANALYZE=true next build", "analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build", @@ -26,7 +27,8 @@ "start": "next start", "test": "jest --watchAll", "test:ci": "jest", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "version": "npm version --allow-same-version=true --no-git-tag-version" }, "dependencies": { "@ant-design/cssinjs": "^1.21.0", @@ -41,7 +43,7 @@ "date-fns": "^2.29.3", "date-fns-tz": "^2.0.0", "eslint-plugin-tailwindcss": "^3.17.4", - "fides-js": "^0.0.1", + "fides-js": "^2", "fidesui": "*", "file-saver": "^2.0.5", "formik": "^2.4.6", diff --git a/clients/fides-js/package.json b/clients/fides-js/package.json index 72a284f6d1..d67eb4b61e 100644 --- a/clients/fides-js/package.json +++ b/clients/fides-js/package.json @@ -1,6 +1,6 @@ { "name": "fides-js", - "version": "0.0.1", + "version": "2.48.0", "description": "FidesJS: JavaScript SDK for Fides", "license": "Apache-2.0", "main": "./dist/fides.js", @@ -23,7 +23,8 @@ "lint:fix": "eslint . --fix", "test": "jest --watchAll", "test:ci": "jest", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "version": "npm version --allow-same-version=true --no-git-tag-version" }, "repository": { "type": "git", diff --git a/clients/package-lock.json b/clients/package-lock.json index 4579089a0d..79ee7c0a69 100644 --- a/clients/package-lock.json +++ b/clients/package-lock.json @@ -15,6 +15,7 @@ } }, "admin-ui": { + "version": "2.48.0", "dependencies": { "@ant-design/cssinjs": "^1.21.0", "@fontsource/inter": "^4.5.15", @@ -28,7 +29,7 @@ "date-fns": "^2.29.3", "date-fns-tz": "^2.0.0", "eslint-plugin-tailwindcss": "^3.17.4", - "fides-js": "^0.0.1", + "fides-js": "^2", "fidesui": "*", "file-saver": "^2.0.5", "formik": "^2.4.6", @@ -671,7 +672,7 @@ } }, "fides-js": { - "version": "0.0.1", + "version": "2.48.0", "license": "Apache-2.0", "dependencies": { "@iabgpp/cmpapi": "^3.1.0", @@ -26117,7 +26118,7 @@ "integrity": "sha512-jEA1znR7b4C/NnaycInCU6h/d15ZzCd1jmsruqOKnZP6WXQSMH3W2GL+OXbkruslU4h+Tzuos0HdswzRUk/Vgg==" }, "privacy-center": { - "version": "2.13.0", + "version": "2.48.0", "dependencies": { "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", @@ -26126,7 +26127,7 @@ "@reduxjs/toolkit": "^1.9.3", "@types/react-dom": "^18.3.0", "cache-control-parser": "^2.0.4", - "fides-js": "*", + "fides-js": "^2", "fidesui": "*", "formik": "^2.2.9", "framer-motion": "^11.2.12", diff --git a/clients/privacy-center/package.json b/clients/privacy-center/package.json index 4bbdf25c43..e33e3a88d3 100644 --- a/clients/privacy-center/package.json +++ b/clients/privacy-center/package.json @@ -1,6 +1,6 @@ { "name": "privacy-center", - "version": "2.13.0", + "version": "2.48.0", "private": true, "scripts": { "dev": "next dev -p 3001", @@ -22,7 +22,8 @@ "analyze": "cross-env ANALYZE=true next build", "analyze:server": "cross-env BUNDLE_ANALYZE=server next build", "analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build", - "openapi:generate": "openapi --input http://localhost:8080/openapi.json --output ./types/api --exportCore false --exportServices false --indent 2 && prettier --write ." + "openapi:generate": "openapi --input http://localhost:8080/openapi.json --output ./types/api --exportCore false --exportServices false --indent 2 && prettier --write .", + "version": "npm version --allow-same-version=true --no-git-tag-version" }, "dependencies": { "@emotion/react": "^11.10.6", @@ -32,7 +33,7 @@ "@reduxjs/toolkit": "^1.9.3", "@types/react-dom": "^18.3.0", "cache-control-parser": "^2.0.4", - "fides-js": "*", + "fides-js": "^2", "fidesui": "*", "formik": "^2.2.9", "framer-motion": "^11.2.12", diff --git a/clients/privacy-center/pages/api/fides-js.ts b/clients/privacy-center/pages/api/fides-js.ts index 6d5a9c7f7f..e4fb5ed389 100644 --- a/clients/privacy-center/pages/api/fides-js.ts +++ b/clients/privacy-center/pages/api/fides-js.ts @@ -21,6 +21,8 @@ import { import { LOCATION_HEADERS, lookupGeolocation } from "~/common/geolocation"; import { safeLookupPropertyId } from "~/common/property-id"; +import * as npmPackage from "../../package.json"; + // one hour, how long the client should cache fides.js for const FIDES_JS_MAX_AGE_SECONDS = 60 * 60; // one hour, how long until the custom-fides.css is refreshed @@ -111,6 +113,7 @@ export default async function handler( // Load the configured consent options (data uses, defaults, etc.) from environment const environment = await loadPrivacyCenterEnvironment(); const serverSettings = await loadServerSettings(); + const { version } = npmPackage; let options: ConsentOption[] = []; if (environment.config?.consent?.page.consentOptions) { @@ -314,6 +317,7 @@ export default async function handler( : "" } window.Fides.config = ${fidesConfigJSON}; + window.Fides.version = "${version}"; ${skipInitialization ? "" : `window.Fides.init();`} ${ environment.settings.DEBUG && skipInitialization diff --git a/clients/turbo.json b/clients/turbo.json index e58fa4abfe..dc931412a1 100644 --- a/clients/turbo.json +++ b/clients/turbo.json @@ -74,6 +74,9 @@ }, "openapi:generate-dictionary": { "dependsOn": [] + }, + "version": { + "dependsOn": [] } } } From 611f4c2503903831fc19f3dc18b94dfa5f509350 Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Thu, 31 Oct 2024 16:17:08 -0600 Subject: [PATCH 2/3] add version to FidesJS at build time instead of runtime --- CHANGELOG.md | 1 + clients/fides-js/docs/interfaces/Fides.md | 9 ++++++++ clients/fides-js/package.json | 1 + clients/fides-js/rollup.config.mjs | 20 +++++++++++++++++ clients/fides-js/src/docs/fides.ts | 6 +++++ clients/fides-js/src/fides-tcf.ts | 1 + clients/fides-js/src/fides.ts | 1 + clients/package-lock.json | 23 ++++++++++++++++++++ clients/privacy-center/pages/api/fides-js.ts | 4 ---- 9 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e52e6930e9..d338982b6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The types of changes are: ### Added - Added DataHub integration config [#5401](https://github.com/ethyca/fides/pull/5401) - Added keepalive settings to the Redshift integration [#5433](https://github.com/ethyca/fides/pull/5433) +- Added current version to the window.Fides object [#5435](https://github.com/ethyca/fides/pull/5435) ### Developer Experience - Added Carbon Icons to FidesUI [#5416](https://github.com/ethyca/fides/pull/5416) diff --git a/clients/fides-js/docs/interfaces/Fides.md b/clients/fides-js/docs/interfaces/Fides.md index 88b9bad308..6005498c2d 100644 --- a/clients/fides-js/docs/interfaces/Fides.md +++ b/clients/fides-js/docs/interfaces/Fides.md @@ -343,3 +343,12 @@ preferences) or in the case when the previous consent is no longer valid. #### Returns `boolean` + +*** + +### version? + +> `optional` **version**: `string` + +Returns the current version of FidesJS. This can be useful for debugging +purposes, or for checking the version of FidesJS that is currently running. diff --git a/clients/fides-js/package.json b/clients/fides-js/package.json index d67eb4b61e..2a8b6f0451 100644 --- a/clients/fides-js/package.json +++ b/clients/fides-js/package.json @@ -46,6 +46,7 @@ "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.2", + "@rollup/plugin-replace": "^6.0.1", "@rollup/plugin-strip": "^3.0.4", "@types/base-64": "^1.0.2", "@types/jest": "^29.5.12", diff --git a/clients/fides-js/rollup.config.mjs b/clients/fides-js/rollup.config.mjs index b582803f51..dc50f7b0f7 100644 --- a/clients/fides-js/rollup.config.mjs +++ b/clients/fides-js/rollup.config.mjs @@ -9,6 +9,8 @@ import postcss from "rollup-plugin-postcss"; import commonjs from "@rollup/plugin-commonjs"; import { visualizer } from "rollup-plugin-visualizer"; import strip from "@rollup/plugin-strip"; +import replace from "@rollup/plugin-replace"; +import pkg from "./package.json" assert { type: "json" }; const NAME = "fides"; const IS_DEV = process.env.NODE_ENV === "development"; @@ -19,6 +21,19 @@ const GZIP_SIZE_WARN_KB = 35; // log a warning if bundle size exceeds this const GZIP_SIZE_TCF_ERROR_KB = 85; const GZIP_SIZE_TCF_WARN_KB = 75; +let PACKAGE_VERSION = "0.0.0"; +try { + PACKAGE_VERSION = pkg.version; + if (!PACKAGE_VERSION) { + throw new Error("No version found in package.json"); + } + console.log( + `Starting FidesJS build and tagging with current version (Fides.version=${PACKAGE_VERSION})...`, + ); +} catch (e) { + console.error("🚨 Failed to get package version, defaulting to 0.0.0"); +} + const preactAliases = { entries: [ { find: "react", replacement: "preact/compat" }, @@ -93,6 +108,11 @@ const fidesScriptPlugins = ({ name, gzipWarnSizeKb, gzipErrorSizeKb }) => [ visualizer({ filename: `bundle-size-stats/${name}-stats.html`, }), + replace({ + __FIDES_JS_VERSION_NUMBER__: PACKAGE_VERSION, + preventAssignment: true, + include: ["src/fides.ts", "src/fides-tcf.ts"], + }), ]; const SCRIPTS = [ diff --git a/clients/fides-js/src/docs/fides.ts b/clients/fides-js/src/docs/fides.ts index 00f49fd5e5..1889c281e9 100644 --- a/clients/fides-js/src/docs/fides.ts +++ b/clients/fides-js/src/docs/fides.ts @@ -263,6 +263,12 @@ export interface Fides { */ shouldShowExperience: () => boolean; + /** + * Returns the current version of FidesJS. This can be useful for debugging + * purposes, or for checking the version of FidesJS that is currently running. + */ + version?: string; + /** * NOTE: The properties below are all marked @internal, despite being exported * on the global Fides object. This is because they are mostly implementation diff --git a/clients/fides-js/src/fides-tcf.ts b/clients/fides-js/src/fides-tcf.ts index e8c95fcfd0..e24a9ee8dc 100644 --- a/clients/fides-js/src/fides-tcf.ts +++ b/clients/fides-js/src/fides-tcf.ts @@ -70,6 +70,7 @@ declare global { const updateWindowFides = (fidesGlobal: FidesGlobal) => { if (typeof window !== "undefined") { window.Fides = fidesGlobal; + window.Fides.version = "__FIDES_JS_VERSION_NUMBER__"; } }; diff --git a/clients/fides-js/src/fides.ts b/clients/fides-js/src/fides.ts index 6d44eb446c..ffce41f52d 100644 --- a/clients/fides-js/src/fides.ts +++ b/clients/fides-js/src/fides.ts @@ -53,6 +53,7 @@ declare global { const updateWindowFides = (fidesGlobal: FidesGlobal) => { if (typeof window !== "undefined") { window.Fides = fidesGlobal; + window.Fides.version = "__FIDES_JS_VERSION_NUMBER__"; } }; diff --git a/clients/package-lock.json b/clients/package-lock.json index 79ee7c0a69..28cc4128f0 100644 --- a/clients/package-lock.json +++ b/clients/package-lock.json @@ -689,6 +689,7 @@ "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.2", + "@rollup/plugin-replace": "^6.0.1", "@rollup/plugin-strip": "^3.0.4", "@types/base-64": "^1.0.2", "@types/jest": "^29.5.12", @@ -5511,6 +5512,28 @@ } } }, + "node_modules/@rollup/plugin-replace": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-6.0.1.tgz", + "integrity": "sha512-2sPh9b73dj5IxuMmDAsQWVFT7mR+yoHweBaXG2W/R8vQ+IWZlnaI7BR7J6EguVQUp1hd8Z7XuozpDjEKQAAC2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-strip": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@rollup/plugin-strip/-/plugin-strip-3.0.4.tgz", diff --git a/clients/privacy-center/pages/api/fides-js.ts b/clients/privacy-center/pages/api/fides-js.ts index e4fb5ed389..6d5a9c7f7f 100644 --- a/clients/privacy-center/pages/api/fides-js.ts +++ b/clients/privacy-center/pages/api/fides-js.ts @@ -21,8 +21,6 @@ import { import { LOCATION_HEADERS, lookupGeolocation } from "~/common/geolocation"; import { safeLookupPropertyId } from "~/common/property-id"; -import * as npmPackage from "../../package.json"; - // one hour, how long the client should cache fides.js for const FIDES_JS_MAX_AGE_SECONDS = 60 * 60; // one hour, how long until the custom-fides.css is refreshed @@ -113,7 +111,6 @@ export default async function handler( // Load the configured consent options (data uses, defaults, etc.) from environment const environment = await loadPrivacyCenterEnvironment(); const serverSettings = await loadServerSettings(); - const { version } = npmPackage; let options: ConsentOption[] = []; if (environment.config?.consent?.page.consentOptions) { @@ -317,7 +314,6 @@ export default async function handler( : "" } window.Fides.config = ${fidesConfigJSON}; - window.Fides.version = "${version}"; ${skipInitialization ? "" : `window.Fides.init();`} ${ environment.settings.DEBUG && skipInitialization From 76341ace66eb0c4066c98bb3fc4a32bdb29907f1 Mon Sep 17 00:00:00 2001 From: Jason Gill Date: Mon, 4 Nov 2024 17:43:30 -0700 Subject: [PATCH 3/3] add health api endpoint with versions as response --- clients/privacy-center/pages/api/health.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 clients/privacy-center/pages/api/health.ts diff --git a/clients/privacy-center/pages/api/health.ts b/clients/privacy-center/pages/api/health.ts new file mode 100644 index 0000000000..4d8c195080 --- /dev/null +++ b/clients/privacy-center/pages/api/health.ts @@ -0,0 +1,16 @@ +/* eslint-disable jsdoc/no-missing-syntax */ +import * as fidesJSPackage from "fides-js/package.json"; +import { NextApiRequest, NextApiResponse } from "next"; + +import * as privacyCenterPackage from "../../package.json"; + +export default function handler(req: NextApiRequest, res: NextApiResponse) { + try { + res.status(200).json({ + core_fides_version: fidesJSPackage.version, + privacy_center_version: privacyCenterPackage.version, + }); + } catch (error) { + res.status(500).json({ error: "failed to get health check" }); + } +}