-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GPP/TCF cmpapi integration to respect device access in EU/CA/US (#…
…152)
- Loading branch information
Showing
47 changed files
with
1,600 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getConfig } from "./config"; | ||
import globalConsent from "./core/regs/consent"; | ||
|
||
describe("getConfig", () => { | ||
it("returns the default config when no overrides are provided", () => { | ||
expect(getConfig({ host: "host", site: "site" })).toEqual({ | ||
host: "host", | ||
site: "site", | ||
cookies: true, | ||
initPassport: true, | ||
consent: { deviceAccess: true, reg: null }, | ||
}); | ||
}); | ||
|
||
it("allows overriding all properties", () => { | ||
expect( | ||
getConfig({ | ||
host: "host", | ||
site: "site", | ||
cookies: false, | ||
initPassport: false, | ||
consent: { static: { deviceAccess: true, reg: "us" } }, | ||
}) | ||
).toEqual({ | ||
host: "host", | ||
site: "site", | ||
cookies: false, | ||
initPassport: false, | ||
consent: { deviceAccess: true, reg: "us" }, | ||
}); | ||
}); | ||
|
||
it("infers regulation and gathers consent when using cmpapi", () => { | ||
const spy = jest.spyOn(Intl, "DateTimeFormat").mockImplementation(() => ({ | ||
resolvedOptions: () => ({ | ||
timeZone: "America/New_York", | ||
}), | ||
})); | ||
|
||
const config = getConfig({ | ||
host: "host", | ||
site: "site", | ||
consent: { cmpapi: {} }, | ||
}); | ||
expect(config.consent).toEqual({ deviceAccess: true, reg: "us" }); | ||
|
||
spy.mockRestore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,53 @@ | ||
type OptableConfig = { | ||
import { getConsent, Consent, inferRegulation } from "./core/regs/consent"; | ||
|
||
type CMPApiConfig = { | ||
// An optional vendor ID from GVL (global vendor list) when interpretting TCF/GPP EU consent, | ||
// when not passed, defaults to publisher consent. | ||
tcfeuVendorID?: number; | ||
}; | ||
|
||
type InitConsent = { | ||
// A "cmpapi" configuration indicating that consent should be gathered from CMP apis. | ||
cmpapi?: CMPApiConfig; | ||
// A "static" consent object already collected by the publisher | ||
static?: Consent; | ||
}; | ||
|
||
type InitConfig = { | ||
host: string; | ||
site: string; | ||
cookies?: boolean; | ||
initPassport?: boolean; | ||
consent?: InitConsent; | ||
}; | ||
|
||
type ResolvedConfig = Required<Omit<InitConfig, "consent">> & { | ||
consent: Consent; | ||
}; | ||
|
||
const DCN_DEFAULTS = { | ||
cookies: true, | ||
initPassport: true, | ||
consent: { deviceAccess: true, reg: null }, | ||
}; | ||
|
||
function getConfig(config: OptableConfig): Required<OptableConfig> { | ||
return { ...DCN_DEFAULTS, ...config }; | ||
function getConfig(init: InitConfig): ResolvedConfig { | ||
const config: ResolvedConfig = { | ||
host: init.host, | ||
site: init.site, | ||
cookies: init.cookies ?? DCN_DEFAULTS.cookies, | ||
initPassport: init.initPassport ?? DCN_DEFAULTS.initPassport, | ||
consent: DCN_DEFAULTS.consent, | ||
}; | ||
|
||
if (init.consent?.static) { | ||
config.consent = init.consent.static; | ||
} else if (init.consent?.cmpapi) { | ||
config.consent = getConsent(inferRegulation(), init.consent.cmpapi); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
export { OptableConfig, getConfig }; | ||
export default OptableConfig; | ||
export type { InitConsent, CMPApiConfig, InitConfig, ResolvedConfig }; | ||
export { getConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.