Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/ads-personalised-consent

Package Overview
Dependencies
Maintainers
9
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/ads-personalised-consent - npm Package Compare versions

Comparing version 5.0.0-beta.7 to 5.0.0-beta.8

14

dist/ads-personalised-consent.js

@@ -22,4 +22,4 @@ import { fetchLegislation } from '@financial-times/privacy-legislation-client';

static legislationPolicy = {
CCPA: 'ccpa',
GDPR: 'gdpr'
CCPA: "ccpa",
GDPR: "gdpr"
};

@@ -99,5 +99,5 @@ /**

this.consentCookie = {
behavioral: consentCookie.includes('behaviouraladsOnsite:on'),
demographic: consentCookie.includes('demographicadsOnsite:on'),
programmatic: consentCookie.includes('programmaticadsOnsite:on')
behavioral: consentCookie.includes("behaviouraladsOnsite:on"),
demographic: consentCookie.includes("demographicadsOnsite:on"),
programmatic: consentCookie.includes("programmaticadsOnsite:on")
};

@@ -149,3 +149,3 @@ }

}
/**
/**
* getLegislation method returns the legislation policies which the user is subject to

@@ -168,3 +168,3 @@ * @returns {PersonalisedConsentTyping.Legislation}

}
/**
/**
* getGpcValue method returns the globalPrivacyControl value in user's browser

@@ -171,0 +171,0 @@ * @returns {boolean}

@@ -14,3 +14,3 @@ {

},
"version": "5.0.0-beta.7"
"version": "5.0.0-beta.8"
}
/** @typedef {import("$typings/personalised-consent")} PersonalisedConsentTyping */
import { fetchLegislation } from '@financial-times/privacy-legislation-client';
import { fetchLegislation } from "@financial-times/privacy-legislation-client";

@@ -21,4 +21,4 @@ /** @type {PersonalisedConsentTyping.PersonalisedConsent} */

static legislationPolicy = {
CCPA: 'ccpa',
GDPR: 'gdpr',
CCPA: "ccpa",
GDPR: "gdpr",
};

@@ -84,10 +84,10 @@

demographic: false,
programmatic: false
programmatic: false,
};
} else {
const consentCookie = decodeURIComponent(match[1]);
this.consentCookie = {
behavioral: consentCookie.includes('behaviouraladsOnsite:on'),
demographic: consentCookie.includes('demographicadsOnsite:on'),
programmatic: consentCookie.includes('programmaticadsOnsite:on')
this.consentCookie = {
behavioral: consentCookie.includes("behaviouraladsOnsite:on"),
demographic: consentCookie.includes("demographicadsOnsite:on"),
programmatic: consentCookie.includes("programmaticadsOnsite:on"),
};

@@ -116,3 +116,3 @@ }

}
/**

@@ -133,6 +133,6 @@ * isAllowed method returns whether behavioral, demographic and programmatic ads is allowed or not

programmatic: !isCcpaAndGpc && this.consentCookie.programmatic,
}
};
}
/**
/**
* getLegislation method returns the legislation policies which the user is subject to

@@ -153,3 +153,3 @@ * @returns {PersonalisedConsentTyping.Legislation}

/**
/**
* getGpcValue method returns the globalPrivacyControl value in user's browser

@@ -180,7 +180,4 @@ * @returns {boolean}

return pc;
}
};
export {
PersonalisedConsent,
getPersonalisedConsent,
};
export { PersonalisedConsent, getPersonalisedConsent };

@@ -7,17 +7,17 @@ /** @typedef {import("$typings/personalised-consent")} PersonalisedConsentTyping */

/* eslint-disable no-console */
import { getPersonalisedConsent } from '../src';
import * as legislationClient from '@financial-times/privacy-legislation-client';
import { getPersonalisedConsent } from "../src";
import * as legislationClient from "@financial-times/privacy-legislation-client";
// legislation policy and region values
const LEGISLATION = {
CCPA: new Set(['ccpa', 'gdpr']),
OTHER: new Set(['gdpr']),
CCPA: new Set(["ccpa", "gdpr"]),
OTHER: new Set(["gdpr"]),
ERROR: undefined,
};
const REGION = {
USCA: 'US-CA',
OTHER: 'GB',
USCA: "US-CA",
OTHER: "GB",
ERROR: undefined,
};
// consent info values (for consent cookie and personalisd consent)
// consent info values (for consent cookie and personalisd consent)
const CONSENT_INFO = {

@@ -49,18 +49,20 @@ ENABLE_ALL: {

Promise.reject({
err: 'Cannot retrieve legislation',
err: "Cannot retrieve legislation",
});
// mock cookies for 'FTConsent'
const NO_COOKIES = '';
const ENABLE_ALL_COOKIES = 'FTConsent=behaviouraladsOnsite%3Aon%2CdemographicadsOnsite%3Aon%2CprogrammaticadsOnsite%3Aon';
const DISABLE_ALL_COOKIES = 'FTConsent=behaviouraladsOnsite%3Aoff%2CdemographicadsOnsite%3Aoff%2CprogrammaticadsOnsite%3Aoff';
const NO_COOKIES = "";
const ENABLE_ALL_COOKIES =
"FTConsent=behaviouraladsOnsite%3Aon%2CdemographicadsOnsite%3Aon%2CprogrammaticadsOnsite%3Aon";
const DISABLE_ALL_COOKIES =
"FTConsent=behaviouraladsOnsite%3Aoff%2CdemographicadsOnsite%3Aoff%2CprogrammaticadsOnsite%3Aoff";
// deleteAllCookies function delete all cookies in document.cookie by making them expired
function deleteAllCookies() {
const cookies = document.cookie.split(';');
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
const eqPos = cookie.indexOf('=');
const name = eqPos > -1 ? cookie.substring(0, eqPos) : cookie;
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
const cookie = cookies[i];
const eqPos = cookie.indexOf("=");
const name = eqPos > -1 ? cookie.substring(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

@@ -95,6 +97,5 @@ }

const spy = jest.spyOn(legislationClient, 'fetchLegislation');
const spy = jest.spyOn(legislationClient, "fetchLegislation");
describe('Allow personalised ads', () => {
describe("Allow personalised ads", () => {
beforeEach(() => {

@@ -105,7 +106,8 @@ deleteAllCookies();

test('Should allow personalised ads when legislation client API throws error, GPC disabled and enable cookies', async () => {
test("Should allow personalised ads when legislation client API throws error, GPC disabled and enable cookies", async () => {
spy.mockImplementation(mockFetchLegislationError);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.ENABLE_ALL);

@@ -118,7 +120,8 @@ expect(legislation).toBe(LEGISLATION.ERROR);

test('Should allow personalised ads when not subject to CCPA, GPC disabled and enable cookies', async () => {
test("Should allow personalised ads when not subject to CCPA, GPC disabled and enable cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.ENABLE_ALL);

@@ -132,7 +135,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should allow personalised ads when not subject to CCPA, GPC enabled and enable cookies', async () => {
test("Should allow personalised ads when not subject to CCPA, GPC enabled and enable cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = true;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.ENABLE_ALL);

@@ -146,7 +150,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should allow personalised ads when subject to CCPA, GPC disabled and enable cookies', async () => {
test("Should allow personalised ads when subject to CCPA, GPC disabled and enable cookies", async () => {
spy.mockImplementation(mockFetchLegislationCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.ENABLE_ALL);

@@ -159,9 +164,6 @@ expect(legislation).toBe(LEGISLATION.CCPA);

});
});
describe('Disallow personalised ads', () => {
describe('Legislation client API throws error and GPC enabled', () => {
describe("Disallow personalised ads", () => {
describe("Legislation client API throws error and GPC enabled", () => {
beforeEach(() => {

@@ -173,6 +175,7 @@ deleteAllCookies();

test('Should disallow personalised ads when legislation client API throws error, GPC enabled and no cookies', async () => {
test("Should disallow personalised ads when legislation client API throws error, GPC enabled and no cookies", async () => {
document.cookie = NO_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -185,6 +188,7 @@ expect(legislation).toBe(LEGISLATION.ERROR);

test('Should disallow personalised ads when legislation client API throws error, GPC enabled and enable cookies', async () => {
test("Should disallow personalised ads when legislation client API throws error, GPC enabled and enable cookies", async () => {
document.cookie = ENABLE_ALL_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -197,6 +201,7 @@ expect(legislation).toBe(LEGISLATION.ERROR);

test('Should disallow personalised ads when legislation client API throws error, GPC enabled and disable cookies', async () => {
test("Should disallow personalised ads when legislation client API throws error, GPC enabled and disable cookies", async () => {
document.cookie = DISABLE_ALL_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -208,7 +213,5 @@ expect(legislation).toBe(LEGISLATION.ERROR);

});
});
describe('Subject to CCPA and GPC enabled', () => {
describe("Subject to CCPA and GPC enabled", () => {
beforeEach(() => {

@@ -220,6 +223,7 @@ deleteAllCookies();

test('Should disallow personalised ads when subject to CCPA, GPC enabled and no cookies', async () => {
test("Should disallow personalised ads when subject to CCPA, GPC enabled and no cookies", async () => {
document.cookie = NO_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -233,6 +237,7 @@ expect(legislation).toBe(LEGISLATION.CCPA);

test('Should disallow personalised ads when subject to CCPA, GPC enabled and enable cookies', async () => {
test("Should disallow personalised ads when subject to CCPA, GPC enabled and enable cookies", async () => {
document.cookie = ENABLE_ALL_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -246,6 +251,7 @@ expect(legislation).toBe(LEGISLATION.CCPA);

test('Should disallow personalised ads when subject to CCPA, GPC enabled and disable cookies', async () => {
test("Should disallow personalised ads when subject to CCPA, GPC enabled and disable cookies", async () => {
document.cookie = DISABLE_ALL_COOKIES;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -258,7 +264,5 @@ expect(legislation).toBe(LEGISLATION.CCPA);

});
});
describe('No cookies', () => {
describe("No cookies", () => {
beforeEach(() => {

@@ -269,7 +273,8 @@ deleteAllCookies();

test('Should disallow personalised ads when not subject to CCPA, GPC disabled and no cookies', async () => {
test("Should disallow personalised ads when not subject to CCPA, GPC disabled and no cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -283,7 +288,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should disallow personalised ads when not subject to CCPA, GPC enabled and no cookies', async () => {
test("Should disallow personalised ads when not subject to CCPA, GPC enabled and no cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = true;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -297,7 +303,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should disallow personalised ads when subject to CCPA, GPC disabled and no cookies', async () => {
test("Should disallow personalised ads when subject to CCPA, GPC disabled and no cookies", async () => {
spy.mockImplementation(mockFetchLegislationCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -310,7 +317,5 @@ expect(legislation).toBe(LEGISLATION.CCPA);

});
});
describe('Disable cookies', () => {
describe("Disable cookies", () => {
beforeEach(() => {

@@ -321,7 +326,8 @@ deleteAllCookies();

test('Should disallow personalised ads when not subject to CCPA, GPC disabled and disable cookies', async () => {
test("Should disallow personalised ads when not subject to CCPA, GPC disabled and disable cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -335,7 +341,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should disallow personalised ads when not subject to CCPA, GPC enabled and disable cookies', async () => {
test("Should disallow personalised ads when not subject to CCPA, GPC enabled and disable cookies", async () => {
spy.mockImplementation(mockFetchLegislationNotCcpa);
navigator.globalPrivacyControl = true;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -349,7 +356,8 @@ expect(legislation).toBe(LEGISLATION.OTHER);

test('Should disallow personalised ads when subject to CCPA, GPC disabled and disable cookies', async () => {
test("Should disallow personalised ads when subject to CCPA, GPC disabled and disable cookies", async () => {
spy.mockImplementation(mockFetchLegislationCcpa);
navigator.globalPrivacyControl = false;
const pc = await getPersonalisedConsent();
const { legislation, region, gpcValue, consentCookie, personalisedConsent } = getAllPrivacyProperties(pc);
const { legislation, region, gpcValue, consentCookie, personalisedConsent } =
getAllPrivacyProperties(pc);
expect(personalisedConsent).toEqual(CONSENT_INFO.DISABLE_ALL);

@@ -362,5 +370,3 @@ expect(legislation).toBe(LEGISLATION.CCPA);

});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc