From 636cf38634f75112963388851378d84356effbf6 Mon Sep 17 00:00:00 2001 From: Jon Snyder Date: Mon, 9 Sep 2024 16:34:24 -0600 Subject: [PATCH 1/2] Update the identity component so it can be excluded from a custom build --- src/components/Privacy/configValidators.js | 17 +++++++ src/components/Privacy/index.js | 3 +- src/core/config/createCoreConfigs.js | 3 -- src/core/consent/createConsentStateMachine.js | 3 +- .../Privacy/configValidators.spec.js | 38 +++++++++++++++ .../core/config/createCoreConfigs.spec.js | 46 ------------------- .../consent/createConsentStateMachine.spec.js | 16 +++---- 7 files changed, 66 insertions(+), 60 deletions(-) create mode 100644 src/components/Privacy/configValidators.js create mode 100644 test/unit/specs/components/Privacy/configValidators.spec.js diff --git a/src/components/Privacy/configValidators.js b/src/components/Privacy/configValidators.js new file mode 100644 index 000000000..edb1a4b09 --- /dev/null +++ b/src/components/Privacy/configValidators.js @@ -0,0 +1,17 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ +import { IN, OUT, PENDING } from "../../constants/consentStatus.js"; +import { objectOf, enumOf } from "../../utils/validation/index.js"; + +export default objectOf({ + defaultConsent: enumOf(IN, OUT, PENDING).default(IN), +}); diff --git a/src/components/Privacy/index.js b/src/components/Privacy/index.js index 83a2eabf7..96e28a55d 100644 --- a/src/components/Privacy/index.js +++ b/src/components/Privacy/index.js @@ -24,6 +24,7 @@ import createStoredConsent from "./createStoredConsent.js"; import injectSendSetConsentRequest from "./injectSendSetConsentRequest.js"; import parseConsentCookie from "./parseConsentCookie.js"; import validateSetConsentOptions from "./validateSetConsentOptions.js"; +import configValidators from "./configValidators.js"; const createPrivacy = ({ config, @@ -66,5 +67,5 @@ const createPrivacy = ({ }; createPrivacy.namespace = "Privacy"; - +createPrivacy.configValidators = configValidators; export default createPrivacy; diff --git a/src/core/config/createCoreConfigs.js b/src/core/config/createCoreConfigs.js index 9d9a619a7..a1a0c1e26 100644 --- a/src/core/config/createCoreConfigs.js +++ b/src/core/config/createCoreConfigs.js @@ -14,18 +14,15 @@ import { boolean, string, callback, - enumOf, objectOf, } from "../../utils/validation/index.js"; import { noop, validateConfigOverride } from "../../utils/index.js"; import { EDGE as EDGE_DOMAIN } from "../../constants/domain.js"; import EDGE_BASE_PATH from "../../constants/edgeBasePath.js"; -import { IN, OUT, PENDING } from "../../constants/consentStatus.js"; export default () => objectOf({ debugEnabled: boolean().default(false), - defaultConsent: enumOf(IN, OUT, PENDING).default(IN), datastreamId: string().unique().required(), edgeDomain: string().domain().default(EDGE_DOMAIN), edgeBasePath: string().nonEmpty().default(EDGE_BASE_PATH), diff --git a/src/core/consent/createConsentStateMachine.js b/src/core/consent/createConsentStateMachine.js index c3190b35a..791ebbc7c 100644 --- a/src/core/consent/createConsentStateMachine.js +++ b/src/core/consent/createConsentStateMachine.js @@ -41,8 +41,7 @@ export default ({ logger }) => { } }; - const awaitInitial = () => - Promise.reject(new Error("Consent has not been initialized.")); + const awaitInitial = () => Promise.resolve(); const awaitInDefault = () => Promise.resolve(); const awaitIn = () => Promise.resolve(); const awaitOutDefault = () => diff --git a/test/unit/specs/components/Privacy/configValidators.spec.js b/test/unit/specs/components/Privacy/configValidators.spec.js new file mode 100644 index 000000000..a9e4a2a19 --- /dev/null +++ b/test/unit/specs/components/Privacy/configValidators.spec.js @@ -0,0 +1,38 @@ +import configValidators from "../../../../../src/components/Privacy/configValidators.js"; + +describe("defaultConsent", () => { + it("validates defaultConsent=undefined", () => { + const config = configValidators({}); + expect(config.defaultConsent).toEqual("in"); + }); + it("validates defaultConsent={}", () => { + expect(() => { + configValidators({ + defaultConsent: {}, + }); + }).toThrowError(); + }); + it("validates defaultConsent='in'", () => { + const config = configValidators({ + defaultConsent: "in", + }); + expect(config.defaultConsent).toEqual("in"); + }); + it("validates defaultConsent='pending'", () => { + const config = configValidators({ + defaultConsent: "pending", + }); + expect(config.defaultConsent).toEqual("pending"); + }); + it("validates defaultConsent=123", () => { + expect(() => { + configValidators({ defaultConsent: 123 }); + }).toThrowError(); + }); + it("validates defaultConsent='out'", () => { + const config = configValidators({ + defaultConsent: "out", + }); + expect(config.defaultConsent).toEqual("out"); + }); +}); diff --git a/test/unit/specs/core/config/createCoreConfigs.spec.js b/test/unit/specs/core/config/createCoreConfigs.spec.js index a1a38c081..2c6669964 100644 --- a/test/unit/specs/core/config/createCoreConfigs.spec.js +++ b/test/unit/specs/core/config/createCoreConfigs.spec.js @@ -11,11 +11,6 @@ governing permissions and limitations under the License. */ import createCoreConfigs from "../../../../../src/core/config/createCoreConfigs.js"; -import { - IN, - OUT, - PENDING, -} from "../../../../../src/constants/consentStatus.js"; describe("createCoreConfigs", () => { let validator; @@ -53,47 +48,6 @@ describe("createCoreConfigs", () => { }); }); - describe("defaultConsent", () => { - it("validates defaultConsent=undefined", () => { - const config = validator(baseConfig); - expect(config.defaultConsent).toEqual(IN); - }); - it("validates defaultConsent={}", () => { - expect(() => { - validator({ - defaultConsent: {}, - ...baseConfig, - }); - }).toThrowError(); - }); - it("validates defaultConsent='in'", () => { - const config = validator({ - defaultConsent: IN, - ...baseConfig, - }); - expect(config.defaultConsent).toEqual(IN); - }); - it("validates defaultConsent='pending'", () => { - const config = validator({ - defaultConsent: PENDING, - ...baseConfig, - }); - expect(config.defaultConsent).toEqual(PENDING); - }); - it("validates defaultConsent=123", () => { - expect(() => { - validator({ defaultConsent: 123, ...baseConfig }); - }).toThrowError(); - }); - it("validates defaultConsent='out'", () => { - const config = validator({ - defaultConsent: OUT, - ...baseConfig, - }); - expect(config.defaultConsent).toEqual(OUT); - }); - }); - [ { datastreamId: "asdfasdf", orgId: "" }, { datastreamId: "asdfasdf", orgId: "" }, diff --git a/test/unit/specs/core/consent/createConsentStateMachine.spec.js b/test/unit/specs/core/consent/createConsentStateMachine.spec.js index 5bb81402f..a4de2f745 100644 --- a/test/unit/specs/core/consent/createConsentStateMachine.spec.js +++ b/test/unit/specs/core/consent/createConsentStateMachine.spec.js @@ -96,14 +96,14 @@ describe("createConsentStateMachine", () => { }); }); - it("rejects promises when it is not initialized", () => { - const onRejected = jasmine.createSpy("onRejected"); - return subject - .awaitConsent() - .catch(onRejected) - .then(() => { - expect(onRejected).toHaveBeenCalled(); - }); + // This is what would happen when the privacy component is not included + it("resolves promises when it is not initialized", () => { + const onFulfilled = jasmine.createSpy("onFulfilled"); + subject.awaitConsent().then(onFulfilled); + + return flushPromiseChains().then(() => { + expect(onFulfilled).toHaveBeenCalled(); + }); }); [ From 07a7463134bf64b852a09a23a07a21c05679fe42 Mon Sep 17 00:00:00 2001 From: Jon Snyder Date: Mon, 9 Sep 2024 16:46:47 -0600 Subject: [PATCH 2/2] add eslint ignore for console call --- rollup.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rollup.config.js b/rollup.config.js index 07a7b8c8a..693e5011e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -89,6 +89,7 @@ const bundleSizePlugin = (_options = {}) => { })), ); if (options.reportToConsole) { + // eslint-disable-next-line no-console console.table(sizes); } // check if the output file exists, create it if it does not exist