Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the privacy component so it can be excluded from a custom build #1179

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/components/Privacy/configValidators.js
Original file line number Diff line number Diff line change
@@ -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),
});
3 changes: 2 additions & 1 deletion src/components/Privacy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,5 +67,5 @@ const createPrivacy = ({
};

createPrivacy.namespace = "Privacy";

createPrivacy.configValidators = configValidators;
export default createPrivacy;
3 changes: 0 additions & 3 deletions src/core/config/createCoreConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/core/consent/createConsentStateMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down
38 changes: 38 additions & 0 deletions test/unit/specs/components/Privacy/configValidators.spec.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
46 changes: 0 additions & 46 deletions test/unit/specs/core/config/createCoreConfigs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: "" },
Expand Down
16 changes: 8 additions & 8 deletions test/unit/specs/core/consent/createConsentStateMachine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

[
Expand Down
Loading