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

Publisher restriction optimisation #5

Merged
merged 4 commits into from
Sep 4, 2023
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
2 changes: 1 addition & 1 deletion modules/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint": "eslint `find src -name '*.ts'`"
},
"dependencies": {
"@didomi/iabtcf-core": "1.5.6"
"@didomi/iabtcf-core": "1.5.8"
},
"devDependencies": {
"@types/node": "^17.0.18",
Expand Down
4 changes: 2 additions & 2 deletions modules/cmpapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@didomi/iabtcf-cmpapi",
"version": "1.5.6",
"version": "1.5.8",
"description": "Ensures other in-page digital marketing technologies have access to CMP transparency and consent information for the iab. Transparency and Consent Framework (TCF).",
"author": "Chris Paterson <tcf@chrispaterson.io>",
"homepage": "https://iabtcf.com/",
Expand Down Expand Up @@ -28,7 +28,7 @@
"test-cov": "rm -rf coverage; nyc --reporter=html mocha"
},
"peerDependencies": {
"@didomi/iabtcf-core": ">=1.0.0"
"@didomi/iabtcf-core": ">=1.5.8"
},
"devDependencies": {
"@didomi/iabtcf-stub": "1.5.6",
Expand Down
2 changes: 1 addition & 1 deletion modules/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@didomi/iabtcf-core",
"version": "1.5.7",
"version": "1.5.8",
"description": "Ensures consistent encoding and decoding of TC Signals for the iab. Transparency and Consent Framework (TCF).",
"author": "Chris Paterson <tcf@chrispaterson.io>",
"homepage": "https://iabtcf.com/",
Expand Down
38 changes: 18 additions & 20 deletions modules/core/src/encoder/field/PurposeRestrictionVectorEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ export class PurposeRestrictionVectorEncoder {
// if the vector is empty we'll just return a string with just the numRestricitons being 0
if (!prVector.isEmpty()) {

const gvlVendorIds = Array.from(prVector.gvl.vendorIds);

const gvlHasVendorBetween = (vendorId: number, nextVendorId: number): boolean => {

const firstIndex = gvlVendorIds.indexOf(vendorId);
const nextIndex = gvlVendorIds.indexOf(nextVendorId);

const res = nextIndex - firstIndex;

return res > 1;

};

// create each restriction group
prVector.getRestrictions().forEach((purpRestriction: PurposeRestriction): void => {

Expand Down Expand Up @@ -44,23 +57,10 @@ export class PurposeRestrictionVectorEncoder {

}

// we know that `len` is greater than zero because we entered the loop
const lastVendorId = vendors[len - 1];
const gvlVendorIds = prVector.gvl.vendorIds;

const nextGvlVendor = (vendorId: number): number => {

while (++vendorId <= lastVendorId && !gvlVendorIds.has(vendorId)) {
}

return vendorId;

};

/**
* either end of the loop or there are GVL vendor IDs before the next one
*/
if (i === len - 1 || vendors[i + 1] > nextGvlVendor(vendorId)) {
if (i === len - 1 || gvlHasVendorBetween(vendorId, vendors[i + 1])) {

/**
* it's a range entry if we've got something other than the start
Expand Down Expand Up @@ -141,15 +141,13 @@ export class PurposeRestrictionVectorEncoder {

}

for ( let k: number = startOrOnlyVendorId; k <= endVendorId; k++) {

vector.add(k, purposeRestriction);

}
// required to preserve the default behavior (includes also vendors ids that doesn't exist)
const vendorIds = Array.from({length: endVendorId - startOrOnlyVendorId + 1}, (_, index) => startOrOnlyVendorId + index);
vector.restrictPurposeToLegalBasis(purposeRestriction, vendorIds);

} else {

vector.add(startOrOnlyVendorId, purposeRestriction);
vector.restrictPurposeToLegalBasis(purposeRestriction, [startOrOnlyVendorId]);

}

Expand Down
Loading