Skip to content

Commit

Permalink
Adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
zapo committed Feb 19, 2025
1 parent 2721deb commit c7f89cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
37 changes: 23 additions & 14 deletions lib/core/regs/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,52 @@ type CMPSignals = {
function applicableReg(defaultReg: Regulation | null, cmp: CMPSignals): Regulation | null {
const { gdprApplies, gppSectionIDs } = cmp;

// Respect CMP signaling that a regulation applies
if (gdprApplies === true) {
return "gdpr";
// Prefer TCF signaling over GPP
if (typeof gdprApplies !== "undefined") {
if (gdprApplies) {
return "gdpr";
}

// Override with unknown regulation if CMP indicates the detected
// regulation doesn't apply
return defaultReg === "gdpr" ? null : defaultReg;
}

// Handle GPP signaling
//
// Unknown regulation signal
if (typeof gppSectionIDs === "undefined" || (gppSectionIDs.length === 1 && gppSectionIDs[0] === 0)) {
return defaultReg;
}

if (gpp.euSections.some((s) => gppSectionIDs?.includes(s.SectionID))) {
// GDPR > CAN > US
if (gppSectionIDs.some((sid) => gpp.euSectionIDs.includes(sid))) {
return "gdpr";
}

if (gpp.caSections.some((s) => gppSectionIDs?.includes(s.SectionID))) {
if (gppSectionIDs.some((sid) => gpp.caSectionIDs.includes(sid))) {
return "can";
}

if (gpp.usSections.some((s) => gppSectionIDs?.includes(s.SectionID))) {
if (gppSectionIDs.some((sid) => gpp.usSectionIDs.includes(sid))) {
return "us";
}

const gppUnknown = typeof gppSectionIDs === "undefined" || (gppSectionIDs.length === 1 && gppSectionIDs[0] === 0);

// Override with unknown regulation if CMP indicates the detected
// regulation doesn't apply
switch (defaultReg) {
case "gdpr":
if (gdprApplies === false) {
return null;
}
if (!gppUnknown && !gpp.euSections.some((s) => gppSectionIDs!.includes(s.SectionID))) {
if (!gppSectionIDs.some((sid) => gpp.euSectionIDs.includes(sid))) {
return null;
}
break;
case "can":
if (!gppUnknown && !gpp.caSections.some((s) => gppSectionIDs!.includes(s.SectionID))) {
if (!gppSectionIDs.some((sid) => gpp.caSectionIDs.includes(sid))) {
return null;
}
break;
case "us":
if (!gppUnknown && !gpp.usSections.some((s) => gppSectionIDs!.includes(s.SectionID))) {
if (!gppSectionIDs.some((sid) => gpp.usSectionIDs.includes(sid))) {
return null;
}
break;
Expand Down
38 changes: 19 additions & 19 deletions lib/core/regs/gpp/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import * as ustx from "./ustx";
import * as usut from "./usut";
import * as usva from "./usva";

export const euSections = [tcfeuv2];
export const euSectionIDs = [tcfeuv2.SectionID];

export const caSections = [tcfcav1];
export const caSectionIDs = [tcfcav1.SectionID];

export const usSections = [
usnat,
usca,
usco,
usct,
usde,
usfl,
usia,
usmt,
usne,
usnh,
usnj,
usor,
ustn,
ustx,
usut,
usva,
export const usSectionIDs = [
usnat.SectionID,
usca.SectionID,
usco.SectionID,
usct.SectionID,
usde.SectionID,
usfl.SectionID,
usia.SectionID,
usmt.SectionID,
usne.SectionID,
usnh.SectionID,
usnj.SectionID,
usor.SectionID,
ustn.SectionID,
ustx.SectionID,
usut.SectionID,
usva.SectionID,
];

export {
Expand Down

0 comments on commit c7f89cb

Please sign in to comment.