New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@didomi/iabtcf-core

Package Overview
Dependencies
Maintainers
7
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@didomi/iabtcf-core - npm Package Compare versions

Comparing version 1.5.7 to 1.5.8

2

lib/cjs/encoder/field/PurposeRestrictionVectorEncoder.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestrictionVectorEncoder=void 0;var BitLength_js_1=require("../BitLength.js"),BooleanEncoder_js_1=require("./BooleanEncoder.js"),index_js_1=require("../../errors/index.js"),IntEncoder_js_1=require("./IntEncoder.js"),index_js_2=require("../../model/index.js"),PurposeRestrictionVectorEncoder=function(){function e(){}return e.encode=function(e){var n=IntEncoder_js_1.IntEncoder.encode(e.numRestrictions,BitLength_js_1.BitLength.numRestrictions);return e.isEmpty()||e.getRestrictions().forEach((function(t){n+=IntEncoder_js_1.IntEncoder.encode(t.purposeId,BitLength_js_1.BitLength.purposeId),n+=IntEncoder_js_1.IntEncoder.encode(t.restrictionType,BitLength_js_1.BitLength.restrictionType);for(var r=e.getVendors(t),o=r.length,i=0,s=0,d="",_=function(n){var t=r[n];0===s&&(i++,s=t);var _=r[o-1],c=e.gvl.vendorIds;if(n===o-1||r[n+1]>function(e){for(;++e<=_&&!c.has(e););return e}(t)){var B=!(t===s);d+=BooleanEncoder_js_1.BooleanEncoder.encode(B),d+=IntEncoder_js_1.IntEncoder.encode(s,BitLength_js_1.BitLength.vendorId),B&&(d+=IntEncoder_js_1.IntEncoder.encode(t,BitLength_js_1.BitLength.vendorId)),s=0}},c=0;c<o;c++)_(c);n+=IntEncoder_js_1.IntEncoder.encode(i,BitLength_js_1.BitLength.numEntries),n+=d})),n},e.decode=function(e){var n=0,t=new index_js_2.PurposeRestrictionVector,r=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.numRestrictions),BitLength_js_1.BitLength.numRestrictions);n+=BitLength_js_1.BitLength.numRestrictions;for(var o=0;o<r;o++){var i=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.purposeId),BitLength_js_1.BitLength.purposeId);n+=BitLength_js_1.BitLength.purposeId;var s=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.restrictionType),BitLength_js_1.BitLength.restrictionType);n+=BitLength_js_1.BitLength.restrictionType;var d=new index_js_2.PurposeRestriction(i,s),_=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.numEntries),BitLength_js_1.BitLength.numEntries);n+=BitLength_js_1.BitLength.numEntries;for(var c=0;c<_;c++){var B=BooleanEncoder_js_1.BooleanEncoder.decode(e.substr(n,BitLength_js_1.BitLength.anyBoolean));n+=BitLength_js_1.BitLength.anyBoolean;var g=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.vendorId),BitLength_js_1.BitLength.vendorId);if(n+=BitLength_js_1.BitLength.vendorId,B){var h=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.vendorId),BitLength_js_1.BitLength.vendorId);if(n+=BitLength_js_1.BitLength.vendorId,h<g)throw new index_js_1.DecodingError("Invalid RangeEntry: endVendorId ".concat(h," is less than ").concat(g));for(var L=g;L<=h;L++)t.add(L,d)}else t.add(g,d)}}return t.bitLength=n,t},e}();exports.PurposeRestrictionVectorEncoder=PurposeRestrictionVectorEncoder;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestrictionVectorEncoder=void 0;var BitLength_js_1=require("../BitLength.js"),BooleanEncoder_js_1=require("./BooleanEncoder.js"),index_js_1=require("../../errors/index.js"),IntEncoder_js_1=require("./IntEncoder.js"),index_js_2=require("../../model/index.js"),PurposeRestrictionVectorEncoder=function(){function e(){}return e.encode=function(e){var n=IntEncoder_js_1.IntEncoder.encode(e.numRestrictions,BitLength_js_1.BitLength.numRestrictions);if(!e.isEmpty()){var t=Array.from(e.gvl.vendorIds),r=function(e,n){var r=t.indexOf(e);return t.indexOf(n)-r>1};e.getRestrictions().forEach((function(t){n+=IntEncoder_js_1.IntEncoder.encode(t.purposeId,BitLength_js_1.BitLength.purposeId),n+=IntEncoder_js_1.IntEncoder.encode(t.restrictionType,BitLength_js_1.BitLength.restrictionType);for(var o=e.getVendors(t),i=o.length,s=0,d=0,_="",c=0;c<i;c++){var g=o[c];if(0===d&&(s++,d=g),c===i-1||r(g,o[c+1])){var B=!(g===d);_+=BooleanEncoder_js_1.BooleanEncoder.encode(B),_+=IntEncoder_js_1.IntEncoder.encode(d,BitLength_js_1.BitLength.vendorId),B&&(_+=IntEncoder_js_1.IntEncoder.encode(g,BitLength_js_1.BitLength.vendorId)),d=0}}n+=IntEncoder_js_1.IntEncoder.encode(s,BitLength_js_1.BitLength.numEntries),n+=_}))}return n},e.decode=function(e){var n=0,t=new index_js_2.PurposeRestrictionVector,r=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.numRestrictions),BitLength_js_1.BitLength.numRestrictions);n+=BitLength_js_1.BitLength.numRestrictions;for(var o=0;o<r;o++){var i=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.purposeId),BitLength_js_1.BitLength.purposeId);n+=BitLength_js_1.BitLength.purposeId;var s=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.restrictionType),BitLength_js_1.BitLength.restrictionType);n+=BitLength_js_1.BitLength.restrictionType;var d=new index_js_2.PurposeRestriction(i,s),_=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.numEntries),BitLength_js_1.BitLength.numEntries);n+=BitLength_js_1.BitLength.numEntries;for(var c=function(r){var o=BooleanEncoder_js_1.BooleanEncoder.decode(e.substr(n,BitLength_js_1.BitLength.anyBoolean));n+=BitLength_js_1.BitLength.anyBoolean;var i=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.vendorId),BitLength_js_1.BitLength.vendorId);if(n+=BitLength_js_1.BitLength.vendorId,o){var s=IntEncoder_js_1.IntEncoder.decode(e.substr(n,BitLength_js_1.BitLength.vendorId),BitLength_js_1.BitLength.vendorId);if(n+=BitLength_js_1.BitLength.vendorId,s<i)throw new index_js_1.DecodingError("Invalid RangeEntry: endVendorId ".concat(s," is less than ").concat(i));var _=Array.from({length:s-i+1},(function(e,n){return i+n}));t.restrictPurposeToLegalBasis(d,_)}else t.restrictPurposeToLegalBasis(d,[i])},g=0;g<_;g++)c()}return t.bitLength=n,t},e}();exports.PurposeRestrictionVectorEncoder=PurposeRestrictionVectorEncoder;

@@ -1,2 +0,1 @@

export * from './BinarySearchTree.js';
export * from './ConsentLanguages.js';

@@ -3,0 +2,0 @@ export * from './Fields.js';

@@ -1,1 +0,1 @@

"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./BinarySearchTree.js"),exports),__exportStar(require("./ConsentLanguages.js"),exports),__exportStar(require("./Fields.js"),exports),__exportStar(require("./IntMap.js"),exports),__exportStar(require("./KeyMap.js"),exports),__exportStar(require("./PurposeRestriction.js"),exports),__exportStar(require("./PurposeRestrictionVector.js"),exports),__exportStar(require("./DeviceDisclosureStorageAccessType.js"),exports),__exportStar(require("./DeviceDisclosure.js"),exports),__exportStar(require("./RestrictionType.js"),exports),__exportStar(require("./Segment.js"),exports),__exportStar(require("./SegmentIDs.js"),exports),__exportStar(require("./Vector.js"),exports),__exportStar(require("./gvl/index.js"),exports);
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./ConsentLanguages.js"),exports),__exportStar(require("./Fields.js"),exports),__exportStar(require("./IntMap.js"),exports),__exportStar(require("./KeyMap.js"),exports),__exportStar(require("./PurposeRestriction.js"),exports),__exportStar(require("./PurposeRestrictionVector.js"),exports),__exportStar(require("./DeviceDisclosureStorageAccessType.js"),exports),__exportStar(require("./DeviceDisclosure.js"),exports),__exportStar(require("./RestrictionType.js"),exports),__exportStar(require("./Segment.js"),exports),__exportStar(require("./SegmentIDs.js"),exports),__exportStar(require("./Vector.js"),exports),__exportStar(require("./gvl/index.js"),exports);

@@ -14,4 +14,2 @@ import { PurposeRestriction } from './PurposeRestriction.js';

* restriction type.
*
* Using a BST to keep vendors in a sorted order for encoding later
*/

@@ -34,5 +32,6 @@ private map;

* @param {PurposeRestriction} purposeRestriction
* @param {number[]|null|undefined} vendorsIds
* @return {void}
*/
restrictPurposeToLegalBasis(purposeRestriction: PurposeRestriction): void;
restrictPurposeToLegalBasis(purposeRestriction: PurposeRestriction, vendorsIds?: number[]): void;
/**

@@ -39,0 +38,0 @@ * getVendors - returns array of vendor ids optionally narrowed by a given

@@ -1,1 +0,1 @@

"use strict";var __extends=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}}(),__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestrictionVector=void 0;var PurposeRestriction_js_1=require("./PurposeRestriction.js"),BinarySearchTree_js_1=require("./BinarySearchTree.js"),RestrictionType_js_1=require("./RestrictionType.js"),Cloneable_js_1=require("../Cloneable.js"),PurposeRestrictionVector=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.bitLength=0,t.map=new Map,t}return __extends(t,e),t.prototype.has=function(e){return this.map.has(e)},t.prototype.isOkToHave=function(e,t,r){var o,i=!0;if(null===(o=this.gvl)||void 0===o?void 0:o.vendors){var n=this.gvl.vendors[r];if(n)if(e===RestrictionType_js_1.RestrictionType.NOT_ALLOWED)i=n.legIntPurposes.includes(t)||n.purposes.includes(t);else if(n.flexiblePurposes.length)switch(e){case RestrictionType_js_1.RestrictionType.REQUIRE_CONSENT:i=n.flexiblePurposes.includes(t)&&n.legIntPurposes.includes(t);break;case RestrictionType_js_1.RestrictionType.REQUIRE_LI:i=n.flexiblePurposes.includes(t)&&n.purposes.includes(t)}else i=!1;else i=!1}return i},t.prototype.add=function(e,t){if(this.isOkToHave(t.restrictionType,t.purposeId,e)){var r=t.hash;this.has(r)||(this.map.set(r,new BinarySearchTree_js_1.BinarySearchTree),this.bitLength=0),this.map.get(r).add(e)}},t.prototype.restrictPurposeToLegalBasis=function(e){for(var t,r=this.gvl.vendorIds,o=e.hash,i=function(){var e,t,o;try{for(var i=__values(r),n=i.next();!n.done;n=i.next())o=n.value}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}return o}(),n=[],s=0;s<i;s++)n[s]=s+1;for(s=1;s<=i;s++)this.has(o)||(this.map.set(o,BinarySearchTree_js_1.BinarySearchTree.build(n)),this.bitLength=0),null===(t=this.map.get(o))||void 0===t||t.add(s)},t.prototype.getVendors=function(e){var t=[];if(e){var r=e.hash;this.has(r)&&(t=this.map.get(r).get())}else{var o=new Set;this.map.forEach((function(e){e.get().forEach((function(e){o.add(e)}))})),t=Array.from(o)}return t},t.prototype.getRestrictionType=function(e,t){var r;return this.getRestrictions(e).forEach((function(e){e.purposeId===t&&(void 0===r||r>e.restrictionType)&&(r=e.restrictionType)})),r},t.prototype.vendorHasRestriction=function(e,t){for(var r=!1,o=this.getRestrictions(e),i=0;i<o.length&&!r;i++)r=t.isSameAs(o[i]);return r},t.prototype.getMaxVendorId=function(){var e=0;return this.map.forEach((function(t){e=Math.max(t.max(),e)})),e},t.prototype.getRestrictions=function(e){var t=[];return this.map.forEach((function(r,o){e?r.contains(e)&&t.push(PurposeRestriction_js_1.PurposeRestriction.unHash(o)):t.push(PurposeRestriction_js_1.PurposeRestriction.unHash(o))})),t},t.prototype.getPurposes=function(){var e=new Set;return this.map.forEach((function(t,r){e.add(PurposeRestriction_js_1.PurposeRestriction.unHash(r).purposeId)})),Array.from(e)},t.prototype.remove=function(e,t){var r=t.hash,o=this.map.get(r);o&&(o.remove(e),o.isEmpty()&&(this.map.delete(r),this.bitLength=0))},Object.defineProperty(t.prototype,"gvl",{get:function(){return this.gvl_},set:function(e){var t=this;this.gvl_||(this.gvl_=e,this.map.forEach((function(e,r){var o=PurposeRestriction_js_1.PurposeRestriction.unHash(r);e.get().forEach((function(r){t.isOkToHave(o.restrictionType,o.purposeId,r)||e.remove(r)}))})))},enumerable:!1,configurable:!0}),t.prototype.isEmpty=function(){return 0===this.map.size},Object.defineProperty(t.prototype,"numRestrictions",{get:function(){return this.map.size},enumerable:!1,configurable:!0}),t}(Cloneable_js_1.Cloneable);exports.PurposeRestrictionVector=PurposeRestrictionVector;
"use strict";var __extends=this&&this.__extends||function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}}(),__values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],o=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestrictionVector=void 0;var PurposeRestriction_js_1=require("./PurposeRestriction.js"),RestrictionType_js_1=require("./RestrictionType.js"),Cloneable_js_1=require("../Cloneable.js"),PurposeRestrictionVector=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.bitLength=0,e.map=new Map,e}return __extends(e,t),e.prototype.has=function(t){return this.map.has(t)},e.prototype.isOkToHave=function(t,e,r){var o,i=!0;if(null===(o=this.gvl)||void 0===o?void 0:o.vendors){var n=this.gvl.vendors[r];if(n)if(t===RestrictionType_js_1.RestrictionType.NOT_ALLOWED)i=n.legIntPurposes.includes(e)||n.purposes.includes(e);else if(n.flexiblePurposes.length)switch(t){case RestrictionType_js_1.RestrictionType.REQUIRE_CONSENT:i=n.flexiblePurposes.includes(e)&&n.legIntPurposes.includes(e);break;case RestrictionType_js_1.RestrictionType.REQUIRE_LI:i=n.flexiblePurposes.includes(e)&&n.purposes.includes(e)}else i=!1;else i=!1}return i},e.prototype.add=function(t,e){if(this.isOkToHave(e.restrictionType,e.purposeId,t)){var r=e.hash;this.has(r)||(this.map.set(r,new Set),this.bitLength=0),this.map.get(r).add(t)}},e.prototype.restrictPurposeToLegalBasis=function(t,e){var r,o;void 0===e&&(e=Array.from(this.gvl.vendorIds));var i=t.hash;if(this.has(i)){var n=this.map.get(i);try{for(var s=__values(e),a=s.next();!a.done;a=s.next()){var u=a.value;n.add(u)}}catch(t){r={error:t}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}}else this.map.set(i,new Set(e)),this.bitLength=0},e.prototype.getVendors=function(t){var e=[];if(t){var r=t.hash;this.has(r)&&(e=Array.from(this.map.get(r)))}else{var o=new Set;this.map.forEach((function(t){Array.from(t).forEach((function(t){o.add(t)}))})),e=Array.from(o)}return e.sort((function(t,e){return t-e}))},e.prototype.getRestrictionType=function(t,e){var r;return this.getRestrictions(t).forEach((function(t){t.purposeId===e&&(void 0===r||r>t.restrictionType)&&(r=t.restrictionType)})),r},e.prototype.vendorHasRestriction=function(t,e){for(var r=!1,o=this.getRestrictions(t),i=0;i<o.length&&!r;i++)r=e.isSameAs(o[i]);return r},e.prototype.getMaxVendorId=function(){var t=0;return this.map.forEach((function(e){var r=Array.from(e);t=Math.max(r[r.length-1],t)})),t},e.prototype.getRestrictions=function(t){var e=[];return this.map.forEach((function(r,o){t?r.has(t)&&e.push(PurposeRestriction_js_1.PurposeRestriction.unHash(o)):e.push(PurposeRestriction_js_1.PurposeRestriction.unHash(o))})),e},e.prototype.getPurposes=function(){var t=new Set;return this.map.forEach((function(e,r){t.add(PurposeRestriction_js_1.PurposeRestriction.unHash(r).purposeId)})),Array.from(t)},e.prototype.remove=function(t,e){var r=e.hash,o=this.map.get(r);o&&(o.delete(t),0==o.size&&(this.map.delete(r),this.bitLength=0))},Object.defineProperty(e.prototype,"gvl",{get:function(){return this.gvl_},set:function(t){var e=this;this.gvl_||(this.gvl_=t,this.map.forEach((function(t,r){var o=PurposeRestriction_js_1.PurposeRestriction.unHash(r);Array.from(t).forEach((function(r){e.isOkToHave(o.restrictionType,o.purposeId,r)||t.delete(r)}))})))},enumerable:!1,configurable:!0}),e.prototype.isEmpty=function(){return 0===this.map.size},Object.defineProperty(e.prototype,"numRestrictions",{get:function(){return this.map.size},enumerable:!1,configurable:!0}),e}(Cloneable_js_1.Cloneable);exports.PurposeRestrictionVector=PurposeRestrictionVector;

@@ -12,2 +12,9 @@ import { BitLength } from '../BitLength.js';

if (!prVector.isEmpty()) {
const gvlVendorIds = Array.from(prVector.gvl.vendorIds);
const gvlHasVendorBetween = (vendorId, nextVendorId) => {
const firstIndex = gvlVendorIds.indexOf(vendorId);
const nextIndex = gvlVendorIds.indexOf(nextVendorId);
const res = nextIndex - firstIndex;
return res > 1;
};
// create each restriction group

@@ -34,14 +41,6 @@ prVector.getRestrictions().forEach((purpRestriction) => {

}
// 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) => {
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])) {
/**

@@ -99,8 +98,8 @@ * it's a range entry if we've got something other than the start

}
for (let k = 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]);
}

@@ -107,0 +106,0 @@ }

@@ -1,2 +0,1 @@

export * from './BinarySearchTree.js';
export * from './ConsentLanguages.js';

@@ -3,0 +2,0 @@ export * from './Fields.js';

@@ -1,2 +0,1 @@

export * from './BinarySearchTree.js';
export * from './ConsentLanguages.js';

@@ -3,0 +2,0 @@ export * from './Fields.js';

@@ -14,4 +14,2 @@ import { PurposeRestriction } from './PurposeRestriction.js';

* restriction type.
*
* Using a BST to keep vendors in a sorted order for encoding later
*/

@@ -34,5 +32,6 @@ private map;

* @param {PurposeRestriction} purposeRestriction
* @param {number[]|null|undefined} vendorsIds
* @return {void}
*/
restrictPurposeToLegalBasis(purposeRestriction: PurposeRestriction): void;
restrictPurposeToLegalBasis(purposeRestriction: PurposeRestriction, vendorsIds?: number[]): void;
/**

@@ -39,0 +38,0 @@ * getVendors - returns array of vendor ids optionally narrowed by a given

import { PurposeRestriction } from './PurposeRestriction.js';
import { BinarySearchTree } from './BinarySearchTree.js';
import { RestrictionType } from './RestrictionType.js';

@@ -14,4 +13,2 @@ import { Cloneable } from '../Cloneable.js';

* restriction type.
*
* Using a BST to keep vendors in a sorted order for encoding later
*/

@@ -85,3 +82,3 @@ map = new Map();

if (!this.has(hash)) {
this.map.set(hash, new BinarySearchTree());
this.map.set(hash, new Set());
this.bitLength = 0;

@@ -101,31 +98,21 @@ }

* @param {PurposeRestriction} purposeRestriction
* @param {number[]|null|undefined} vendorsIds
* @return {void}
*/
restrictPurposeToLegalBasis(purposeRestriction) {
const vendors = this.gvl.vendorIds;
restrictPurposeToLegalBasis(purposeRestriction, vendorsIds = Array.from(this.gvl.vendorIds)) {
const hash = purposeRestriction.hash;
const lastEntry = (function () {
let value;
for (value of vendors)
;
return value;
})();
/**
* Create an ordered array of vendor IDs from `1` (the minimum value for Vendor ID) to `lastEntry`
*/
const values = [];
for (let i = 0; i < lastEntry; i++) {
values[i] = i + 1;
if (!this.has(hash)) {
this.map.set(hash, new Set(vendorsIds));
this.bitLength = 0;
}
for (let i = 1; i <= lastEntry; i++) {
if (!this.has(hash)) {
this.map.set(hash, BinarySearchTree.build(values)); // use static method `build` to create a `BST` from the ordered array of IDs
this.bitLength = 0;
else {
const currentMap = this.map.get(hash);
for (const vendorId of vendorsIds) {
/**
* Previously I had a check here to remove a duplicate value, but because
* we're using a tree the value is guaranteed to be unique so there is no
* need to add an additional de-duplication here.
*/
currentMap.add(vendorId);
}
/**
* Previously I had a check here to remove a duplicate value, but because
* we're using a tree the value is guaranteed to be unique so there is no
* need to add an additional de-duplication here.
*/
this.map.get(hash)?.add(i);
}

@@ -148,3 +135,3 @@ }

if (this.has(hash)) {
vendorIds = this.map.get(hash).get();
vendorIds = Array.from(this.map.get(hash));
}

@@ -154,4 +141,4 @@ }

const vendorSet = new Set();
this.map.forEach((bst) => {
bst.get().forEach((vendorId) => {
this.map.forEach((vendorIds) => {
Array.from(vendorIds).forEach((vendorId) => {
vendorSet.add(vendorId);

@@ -162,3 +149,3 @@ });

}
return vendorIds;
return vendorIds.sort((a, b) => a - b);
}

@@ -200,25 +187,26 @@ getRestrictionType(vendorId, purposeId) {

getMaxVendorId() {
let retr = 0;
this.map.forEach((bst) => {
retr = Math.max(bst.max(), retr);
let result = 0;
this.map.forEach((purposeRestrictionVendorIds) => {
const vendorIds = Array.from(purposeRestrictionVendorIds);
result = Math.max(vendorIds[vendorIds.length - 1], result);
});
return retr;
return result;
}
getRestrictions(vendorId) {
const retr = [];
this.map.forEach((bst, hash) => {
const result = [];
this.map.forEach((vendorIds, hash) => {
if (vendorId) {
if (bst.contains(vendorId)) {
retr.push(PurposeRestriction.unHash(hash));
if (vendorIds.has(vendorId)) {
result.push(PurposeRestriction.unHash(hash));
}
}
else {
retr.push(PurposeRestriction.unHash(hash));
result.push(PurposeRestriction.unHash(hash));
}
});
return retr;
return result;
}
getPurposes() {
const purposeIds = new Set();
this.map.forEach((bst, hash) => {
this.map.forEach((vendorIds, hash) => {
purposeIds.add(PurposeRestriction.unHash(hash).purposeId);

@@ -237,7 +225,7 @@ });

const hash = purposeRestriction.hash;
const bst = this.map.get(hash);
if (bst) {
bst.remove(vendorId);
const vendorIds = this.map.get(hash);
if (vendorIds) {
vendorIds.delete(vendorId);
// if it's empty let's delete the key so it doesn't show up empty
if (bst.isEmpty()) {
if (vendorIds.size == 0) {
this.map.delete(hash);

@@ -261,8 +249,8 @@ this.bitLength = 0;

*/
this.map.forEach((bst, hash) => {
this.map.forEach((vendorIds, hash) => {
const purposeRestriction = PurposeRestriction.unHash(hash);
const vendors = bst.get();
const vendors = Array.from(vendorIds);
vendors.forEach((vendorId) => {
if (!this.isOkToHave(purposeRestriction.restrictionType, purposeRestriction.purposeId, vendorId)) {
bst.remove(vendorId);
vendorIds.delete(vendorId);
}

@@ -269,0 +257,0 @@ });

{
"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).",

@@ -5,0 +5,0 @@ "author": "Chris Paterson <tcf@chrispaterson.io>",

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