@pubtech-ai/core 2.5.0 → 2.7.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";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TCString=void 0;var index_js_1=require("./encoder/index.js"),index_js_2=require("./model/index.js"),IntEncoder_js_1=require("./encoder/field/IntEncoder.js"),TCModel_js_1=require("./TCModel.js"),TCString=function(){function e(){}return e.encode=function(e,n){var r,t="";return e=index_js_1.SemanticPreEncoder.process(e,n),(r=Array.isArray(null==n?void 0:n.segments)?n.segments:new index_js_1.SegmentSequence(e,n)[""+e.version]).forEach((function(n,d){var s="";d<r.length-1&&(s="."),t+=index_js_1.SegmentEncoder.encode(e,n)+s})),t},e.decode=function(e,n){var r=e.split("."),t=r.length;n||(n=new TCModel_js_1.TCModel);for(var d=0;d<t;d++){var s=r[d],i=index_js_1.Base64Url.decode(s.charAt(0)).substr(0,index_js_1.BitLength.segmentType),o=index_js_2.SegmentIDs.ID_TO_KEY[IntEncoder_js_1.IntEncoder.decode(i,index_js_1.BitLength.segmentType).toString()];index_js_1.SegmentEncoder.decode(s,n,o)}return n},e}();exports.TCString=TCString;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TCString=void 0;var index_js_1=require("./encoder/index.js"),index_js_2=require("./model/index.js"),IntEncoder_js_1=require("./encoder/field/IntEncoder.js"),TCModel_js_1=require("./TCModel.js"),decodeCachedResults={},TCString=function(){function e(){}return e.encode=function(e,n){var d,r="";return e=index_js_1.SemanticPreEncoder.process(e,n),(d=Array.isArray(null==n?void 0:n.segments)?n.segments:new index_js_1.SegmentSequence(e,n)[""+e.version]).forEach((function(n,s){var t="";s<d.length-1&&(t="."),r+=index_js_1.SegmentEncoder.encode(e,n)+t})),r},e.decode=function(e,n){if(decodeCachedResults[e])return decodeCachedResults[e].clone();decodeCachedResults={};var d=e.split("."),r=d.length;n||(n=new TCModel_js_1.TCModel);for(var s=0;s<r;s++){var t=d[s],o=index_js_1.Base64Url.decode(t.charAt(0)).substr(0,index_js_1.BitLength.segmentType),c=index_js_2.SegmentIDs.ID_TO_KEY[IntEncoder_js_1.IntEncoder.decode(o,index_js_1.BitLength.segmentType).toString()];index_js_1.SegmentEncoder.decode(t,n,c)}return decodeCachedResults[e]=n,n},e}();exports.TCString=TCString;
@@ -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;
@@ -2,6 +2,7 @@ import { Base64Url, BitLength, SegmentEncoder, SegmentSequence, SemanticPreEncod
2
2
  import { SegmentIDs } from './model/index.js';
3
3
  import { IntEncoder } from './encoder/field/IntEncoder.js';
4
4
  import { TCModel } from './TCModel.js';
5
+ let decodeCachedResults = {};
5
6
  /**
6
7
  * Main class for encoding and decoding a
7
8
  * TCF Transparency and Consent String
@@ -47,6 +48,10 @@ export class TCString {
47
48
  * @return {TCModel} - Returns populated TCModel
48
49
  */
49
50
  static decode(encodedTCString, tcModel) {
51
+ if (decodeCachedResults[encodedTCString]) {
52
+ return decodeCachedResults[encodedTCString].clone();
53
+ }
54
+ decodeCachedResults = {};
50
55
  const segments = encodedTCString.split('.');
51
56
  const len = segments.length;
52
57
  if (!tcModel) {
@@ -66,6 +71,7 @@ export class TCString {
66
71
  const segment = SegmentIDs.ID_TO_KEY[IntEncoder.decode(segTypeBits, BitLength.segmentType).toString()];
67
72
  SegmentEncoder.decode(segString, tcModel, segment);
68
73
  }
74
+ decodeCachedResults[encodedTCString] = tcModel;
69
75
  return tcModel;
70
76
  }
71
77
  }
@@ -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.5.0",
3
+ "version": "2.7.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.5.0",
31
+ "@pubtech-ai/testing": "2.7.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",