@pubtech-ai/core 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
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)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestriction=void 0;var Cloneable_js_1=require("../Cloneable.js"),index_js_1=require("../errors/index.js"),RestrictionType_js_1=require("./RestrictionType.js"),PurposeRestriction=function(e){function t(t,r){var o=e.call(this)||this;return void 0!==t&&(o.purposeId=t),void 0!==r&&(o.restrictionType=r),o}return __extends(t,e),t.unHash=function(e){var r=e.split(this.hashSeparator),o=new t;if(2!==r.length)throw new index_js_1.TCModelError("hash",e);return o.purposeId=parseInt(r[0],10),o.restrictionType=parseInt(r[1],10),o},Object.defineProperty(t.prototype,"hash",{get:function(){if(!this.isValid())throw new Error("cannot hash invalid PurposeRestriction");return"".concat(this.purposeId).concat(t.hashSeparator).concat(this.restrictionType)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"purposeId",{get:function(){return this.purposeId_},set:function(e){this.purposeId_=e},enumerable:!1,configurable:!0}),t.prototype.isValid=function(){return Number.isInteger(this.purposeId)&&this.purposeId>0&&(this.restrictionType===RestrictionType_js_1.RestrictionType.NOT_ALLOWED||this.restrictionType===RestrictionType_js_1.RestrictionType.REQUIRE_CONSENT||this.restrictionType===RestrictionType_js_1.RestrictionType.REQUIRE_LI)},t.prototype.isSameAs=function(e){return this.purposeId===e.purposeId&&this.restrictionType===e.restrictionType},t.hashSeparator="-",t}(Cloneable_js_1.Cloneable);exports.PurposeRestriction=PurposeRestriction;
|
|
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)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.PurposeRestriction=void 0;var Cloneable_js_1=require("../Cloneable.js"),index_js_1=require("../errors/index.js"),RestrictionType_js_1=require("./RestrictionType.js"),unhashCacheResults={},PurposeRestriction=function(e){function t(t,r){var o=e.call(this)||this;return void 0!==t&&(o.purposeId=t),void 0!==r&&(o.restrictionType=r),o}return __extends(t,e),t.unHash=function(e){if(unhashCacheResults[e])return unhashCacheResults[e];var r=e.split(this.hashSeparator),o=new t;if(2!==r.length)throw new index_js_1.TCModelError("hash",e);return o.purposeId=parseInt(r[0],10),o.restrictionType=parseInt(r[1],10),unhashCacheResults[e]=o,o},Object.defineProperty(t.prototype,"hash",{get:function(){if(!this.isValid())throw new Error("cannot hash invalid PurposeRestriction");return"".concat(this.purposeId).concat(t.hashSeparator).concat(this.restrictionType)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"purposeId",{get:function(){return this.purposeId_},set:function(e){this.purposeId_=e},enumerable:!1,configurable:!0}),t.prototype.isValid=function(){return Number.isInteger(this.purposeId)&&this.purposeId>0&&(this.restrictionType===RestrictionType_js_1.RestrictionType.NOT_ALLOWED||this.restrictionType===RestrictionType_js_1.RestrictionType.REQUIRE_CONSENT||this.restrictionType===RestrictionType_js_1.RestrictionType.REQUIRE_LI)},t.prototype.isSameAs=function(e){return this.purposeId===e.purposeId&&this.restrictionType===e.restrictionType},t.hashSeparator="-",t}(Cloneable_js_1.Cloneable);exports.PurposeRestriction=PurposeRestriction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cloneable } from '../Cloneable.js';
|
|
2
2
|
import { TCModelError } from '../errors/index.js';
|
|
3
3
|
import { RestrictionType } from './RestrictionType.js';
|
|
4
|
+
const unhashCacheResults = {};
|
|
4
5
|
export class PurposeRestriction extends Cloneable {
|
|
5
6
|
static hashSeparator = '-';
|
|
6
7
|
purposeId_;
|
|
@@ -24,6 +25,9 @@ export class PurposeRestriction extends Cloneable {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
static unHash(hash) {
|
|
28
|
+
if (unhashCacheResults[hash]) {
|
|
29
|
+
return unhashCacheResults[hash];
|
|
30
|
+
}
|
|
27
31
|
const splitUp = hash.split(this.hashSeparator);
|
|
28
32
|
const purpRestriction = new PurposeRestriction();
|
|
29
33
|
if (splitUp.length !== 2) {
|
|
@@ -31,6 +35,7 @@ export class PurposeRestriction extends Cloneable {
|
|
|
31
35
|
}
|
|
32
36
|
purpRestriction.purposeId = parseInt(splitUp[0], 10);
|
|
33
37
|
purpRestriction.restrictionType = parseInt(splitUp[1], 10);
|
|
38
|
+
unhashCacheResults[hash] = purpRestriction;
|
|
34
39
|
return purpRestriction;
|
|
35
40
|
}
|
|
36
41
|
get hash() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubtech-ai/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Ensures consistent encoding and decoding of TC Signals for the iab. Transparency and Consent Framework (TCF).",
|
|
5
5
|
"author": "Mayank Mishra <mayank@iabtechlab.com>",
|
|
6
6
|
"homepage": "https://iabtcf.com/",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test-cov": "rm -rf coverage; nyc --reporter=html mocha"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@pubtech-ai/testing": "2.
|
|
31
|
+
"@pubtech-ai/testing": "2.6.0",
|
|
32
32
|
"@istanbuljs/nyc-config-typescript": "^0.1.3",
|
|
33
33
|
"@types/sinon": "^10.0.11",
|
|
34
34
|
"@types/sinon-chai": "3.2.8",
|