@pubtech-ai/core 2.8.1 → 2.9.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.
package/lib/cjs/GVL.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Cloneable } from './Cloneable.js';
2
2
  import { GVLError } from './errors/index.js';
3
- import { ConsentLanguages, IntMap } from './model/index.js';
3
+ import { ConsentLanguages, GvlCreationOptions, IntMap } from './model/index.js';
4
4
  import { Feature, Purpose, Stack, Vendor, VendorList, DataCategory } from './model/gvl/index.js';
5
5
  export type VersionOrVendorList = string | number | VendorList;
6
6
  /**
@@ -177,8 +177,9 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
177
177
  * [[VendorList]] object or a version number represented as a string or
178
178
  * number to download. If nothing is passed the latest version of the GVL
179
179
  * will be loaded
180
+ * @param {GvlCreationOptions} [options] - it is an optional object where the default language can be set
180
181
  */
181
- constructor(versionOrVendorList?: VersionOrVendorList);
182
+ constructor(versionOrVendorList?: VersionOrVendorList, options?: GvlCreationOptions);
182
183
  /**
183
184
  * emptyLanguageCache
184
185
  *
@@ -206,6 +207,20 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
206
207
  * functionality and methods of this class.
207
208
  */
208
209
  getJson(): VendorList;
210
+ private cloneSpecialFeatures;
211
+ private cloneFeatures;
212
+ private cloneStacks;
213
+ private cloneDataCategories;
214
+ private cloneSpecialPurposes;
215
+ private clonePurposes;
216
+ private static clonePurpose;
217
+ private static cloneFeature;
218
+ private static cloneDataCategory;
219
+ private static cloneStack;
220
+ private static cloneDataRetention;
221
+ private static cloneVendorUrls;
222
+ private static cloneVendor;
223
+ private cloneVendors;
209
224
  /**
210
225
  * changeLanguage - retrieves the purpose language translation and sets the
211
226
  * internal language variable
package/lib/cjs/GVL.js CHANGED
@@ -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 n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),__awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(s,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,s,o,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GVL=void 0;var Cloneable_js_1=require("./Cloneable.js"),index_js_1=require("./errors/index.js"),Json_js_1=require("./Json.js"),index_js_2=require("./model/index.js"),GVL=function(e){function t(r){var n=e.call(this)||this;n.isReady_=!1,n.isLatest=!1;var s=t.baseUrl;if(n.lang_=t.DEFAULT_LANGUAGE,n.cacheLang_=t.DEFAULT_LANGUAGE,n.isVendorList(r))n.populate(r),n.readyPromise=Promise.resolve();else{if(!s)throw new index_js_1.GVLError("must specify GVL.baseUrl before loading GVL json");if(r>0){var o=r;t.CACHE.has(o)?(n.populate(t.CACHE.get(o)),n.readyPromise=Promise.resolve()):(s+=t.versionedFilename.replace("[VERSION]",String(o)),n.readyPromise=n.fetchJson(s))}else t.CACHE.has(t.LATEST_CACHE_KEY)?(n.populate(t.CACHE.get(t.LATEST_CACHE_KEY)),n.readyPromise=Promise.resolve()):(n.isLatest=!0,n.readyPromise=n.fetchJson(s+t.latestFilename))}return n}return __extends(t,e),Object.defineProperty(t,"baseUrl",{get:function(){return this.baseUrl_},set:function(e){if(/^https?:\/\/vendorlist\.consensu\.org\//.test(e))throw new index_js_1.GVLError("Invalid baseUrl! You may not pull directly from vendorlist.consensu.org and must provide your own cache");e.length>0&&"/"!==e[e.length-1]&&(e+="/"),this.baseUrl_=e},enumerable:!1,configurable:!0}),t.emptyLanguageCache=function(e){var r=!1;return null==e&&t.LANGUAGE_CACHE.size>0?(t.LANGUAGE_CACHE=new Map,r=!0):"string"==typeof e&&this.consentLanguages.has(e.toUpperCase())&&(t.LANGUAGE_CACHE.delete(e.toUpperCase()),r=!0),r},t.emptyCache=function(e){var r=!1;return Number.isInteger(e)&&e>=0?(t.CACHE.delete(e),r=!0):void 0===e&&(t.CACHE=new Map,r=!0),r},t.prototype.cacheLanguage=function(){t.LANGUAGE_CACHE.has(this.cacheLang_)||t.LANGUAGE_CACHE.set(this.cacheLang_,{purposes:this.purposes,specialPurposes:this.specialPurposes,features:this.features,specialFeatures:this.specialFeatures,stacks:this.stacks,dataCategories:this.dataCategories})},t.prototype.fetchJson=function(e){return __awaiter(this,void 0,void 0,(function(){var t,r;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=this.populate,[4,Json_js_1.Json.fetch(e)];case 1:return t.apply(this,[n.sent()]),[3,3];case 2:throw r=n.sent(),new index_js_1.GVLError(r.message);case 3:return[2]}}))}))},t.prototype.getJson=function(){return{gvlSpecificationVersion:this.gvlSpecificationVersion,vendorListVersion:this.vendorListVersion,tcfPolicyVersion:this.tcfPolicyVersion,lastUpdated:this.lastUpdated,purposes:this.purposes,specialPurposes:this.specialPurposes,features:this.features,specialFeatures:this.specialFeatures,stacks:this.stacks,dataCategories:this.dataCategories,vendors:this.fullVendorList}},t.prototype.changeLanguage=function(e){return __awaiter(this,void 0,void 0,(function(){var r,n,s,o,i,a;return __generator(this,(function(u){switch(u.label){case 0:r=e;try{r=t.consentLanguages.parseLanguage(e)}catch(e){throw new index_js_1.GVLError("Error during parsing the language: "+e.message)}if(n=e.toUpperCase(),r.toLowerCase()===t.DEFAULT_LANGUAGE.toLowerCase()&&!t.LANGUAGE_CACHE.has(n))return[2];if(r===this.lang_)return[3,5];if(this.lang_=r,!t.LANGUAGE_CACHE.has(n))return[3,1];for(o in s=t.LANGUAGE_CACHE.get(n))s.hasOwnProperty(o)&&(this[o]=s[o]);return[3,5];case 1:i=t.baseUrl+t.languageFilename.replace("[LANG]",this.lang_.toLowerCase()),u.label=2;case 2:return u.trys.push([2,4,,5]),[4,this.fetchJson(i)];case 3:return u.sent(),this.cacheLang_=n,this.cacheLanguage(),[3,5];case 4:throw a=u.sent(),new index_js_1.GVLError("unable to load language: "+a.message);case 5:return[2]}}))}))},Object.defineProperty(t.prototype,"language",{get:function(){return this.lang_},enumerable:!1,configurable:!0}),t.prototype.isVendorList=function(e){return void 0!==e&&void 0!==e.vendors},t.prototype.populate=function(e){this.purposes=e.purposes,this.specialPurposes=e.specialPurposes,this.features=e.features,this.specialFeatures=e.specialFeatures,this.stacks=e.stacks,this.dataCategories=e.dataCategories,this.isVendorList(e)&&(this.gvlSpecificationVersion=e.gvlSpecificationVersion,this.tcfPolicyVersion=e.tcfPolicyVersion,this.vendorListVersion=e.vendorListVersion,this.lastUpdated=e.lastUpdated,"string"==typeof this.lastUpdated&&(this.lastUpdated=new Date(this.lastUpdated)),this.vendors_=e.vendors,this.fullVendorList=e.vendors,this.mapVendors(),this.isReady_=!0,this.isLatest&&t.CACHE.set(t.LATEST_CACHE_KEY,this.getJson()),t.CACHE.has(this.vendorListVersion)||t.CACHE.set(this.vendorListVersion,this.getJson())),this.cacheLanguage()},t.prototype.mapVendors=function(e){var t=this;this.byPurposeVendorMap={},this.bySpecialPurposeVendorMap={},this.byFeatureVendorMap={},this.bySpecialFeatureVendorMap={},Object.keys(this.purposes).forEach((function(e){t.byPurposeVendorMap[e]={legInt:new Set,consent:new Set,flexible:new Set}})),Object.keys(this.specialPurposes).forEach((function(e){t.bySpecialPurposeVendorMap[e]=new Set})),Object.keys(this.features).forEach((function(e){t.byFeatureVendorMap[e]=new Set})),Object.keys(this.specialFeatures).forEach((function(e){t.bySpecialFeatureVendorMap[e]=new Set})),Array.isArray(e)||(e=Object.keys(this.fullVendorList).map((function(e){return+e}))),this.vendorIds=new Set(e),this.vendors_=e.reduce((function(e,r){var n=t.vendors_[String(r)];return n&&void 0===n.deletedDate&&(n.purposes.forEach((function(e){t.byPurposeVendorMap[String(e)].consent.add(r)})),n.specialPurposes.forEach((function(e){t.bySpecialPurposeVendorMap[String(e)].add(r)})),n.legIntPurposes.forEach((function(e){t.byPurposeVendorMap[String(e)].legInt.add(r)})),n.flexiblePurposes&&n.flexiblePurposes.forEach((function(e){t.byPurposeVendorMap[String(e)].flexible.add(r)})),n.features.forEach((function(e){t.byFeatureVendorMap[String(e)].add(r)})),n.specialFeatures.forEach((function(e){t.bySpecialFeatureVendorMap[String(e)].add(r)})),e[r]=n),e}),{})},t.prototype.getFilteredVendors=function(e,t,r,n){var s=this,o=e.charAt(0).toUpperCase()+e.slice(1),i={};return("purpose"===e&&r?this["by"+o+"VendorMap"][String(t)][r]:this["by"+(n?"Special":"")+o+"VendorMap"][String(t)]).forEach((function(e){i[String(e)]=s.vendors[String(e)]})),i},t.prototype.getVendorsWithConsentPurpose=function(e){return this.getFilteredVendors("purpose",e,"consent")},t.prototype.getVendorsWithLegIntPurpose=function(e){return this.getFilteredVendors("purpose",e,"legInt")},t.prototype.getVendorsWithFlexiblePurpose=function(e){return this.getFilteredVendors("purpose",e,"flexible")},t.prototype.getVendorsWithSpecialPurpose=function(e){return this.getFilteredVendors("purpose",e,void 0,!0)},t.prototype.getVendorsWithFeature=function(e){return this.getFilteredVendors("feature",e)},t.prototype.getVendorsWithSpecialFeature=function(e){return this.getFilteredVendors("feature",e,void 0,!0)},Object.defineProperty(t.prototype,"vendors",{get:function(){return this.vendors_},enumerable:!1,configurable:!0}),t.prototype.narrowVendorsTo=function(e){this.mapVendors(e)},Object.defineProperty(t.prototype,"isReady",{get:function(){return this.isReady_},enumerable:!1,configurable:!0}),t.prototype.clone=function(){var e=new t(JSON.parse(JSON.stringify(this.getJson())));return this.lang_!==t.DEFAULT_LANGUAGE&&e.changeLanguage(this.lang_),e},t.isInstanceOf=function(e){return"object"==typeof e&&"function"==typeof e.narrowVendorsTo},t.LANGUAGE_CACHE=new Map,t.CACHE=new Map,t.LATEST_CACHE_KEY=0,t.DEFAULT_LANGUAGE="EN",t.consentLanguages=new index_js_2.ConsentLanguages,t.latestFilename="vendor-list.json",t.versionedFilename="archives/vendor-list-v[VERSION].json",t.languageFilename="purposes-[LANG].json",t}(Cloneable_js_1.Cloneable);exports.GVL=GVL;
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 n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(s,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,s,o,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GVL=void 0;var Cloneable_js_1=require("./Cloneable.js"),index_js_1=require("./errors/index.js"),Json_js_1=require("./Json.js"),index_js_2=require("./model/index.js"),GVL=function(e){function t(r,n){var s=e.call(this)||this;s.isReady_=!1,s.isLatest=!1;var o=t.baseUrl,i=null==n?void 0:n.language;if(i)try{i=t.consentLanguages.parseLanguage(i)}catch(e){throw new index_js_1.GVLError("Error during parsing the language: "+e.message)}if(s.lang_=i||t.DEFAULT_LANGUAGE,s.cacheLang_=i||t.DEFAULT_LANGUAGE,s.isVendorList(r))s.populate(r),s.readyPromise=Promise.resolve();else{if(!o)throw new index_js_1.GVLError("must specify GVL.baseUrl before loading GVL json");if(r>0){var a=r;t.CACHE.has(a)?(s.populate(t.CACHE.get(a)),s.readyPromise=Promise.resolve()):(o+=t.versionedFilename.replace("[VERSION]",String(a)),s.readyPromise=s.fetchJson(o))}else t.CACHE.has(t.LATEST_CACHE_KEY)?(s.populate(t.CACHE.get(t.LATEST_CACHE_KEY)),s.readyPromise=Promise.resolve()):(s.isLatest=!0,s.readyPromise=s.fetchJson(o+t.latestFilename))}return s}return __extends(t,e),Object.defineProperty(t,"baseUrl",{get:function(){return this.baseUrl_},set:function(e){if(/^https?:\/\/vendorlist\.consensu\.org\//.test(e))throw new index_js_1.GVLError("Invalid baseUrl! You may not pull directly from vendorlist.consensu.org and must provide your own cache");e.length>0&&"/"!==e[e.length-1]&&(e+="/"),this.baseUrl_=e},enumerable:!1,configurable:!0}),t.emptyLanguageCache=function(e){var r=!1;return null==e&&t.LANGUAGE_CACHE.size>0?(t.LANGUAGE_CACHE=new Map,r=!0):"string"==typeof e&&this.consentLanguages.has(e.toUpperCase())&&(t.LANGUAGE_CACHE.delete(e.toUpperCase()),r=!0),r},t.emptyCache=function(e){var r=!1;return Number.isInteger(e)&&e>=0?(t.CACHE.delete(e),r=!0):void 0===e&&(t.CACHE=new Map,r=!0),r},t.prototype.cacheLanguage=function(){t.LANGUAGE_CACHE.has(this.cacheLang_)||t.LANGUAGE_CACHE.set(this.cacheLang_,{purposes:this.purposes,specialPurposes:this.specialPurposes,features:this.features,specialFeatures:this.specialFeatures,stacks:this.stacks,dataCategories:this.dataCategories})},t.prototype.fetchJson=function(e){return __awaiter(this,void 0,void 0,(function(){var t,r;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=this.populate,[4,Json_js_1.Json.fetch(e)];case 1:return t.apply(this,[n.sent()]),[3,3];case 2:throw r=n.sent(),new index_js_1.GVLError(r.message);case 3:return[2]}}))}))},t.prototype.getJson=function(){return{gvlSpecificationVersion:this.gvlSpecificationVersion,vendorListVersion:this.vendorListVersion,tcfPolicyVersion:this.tcfPolicyVersion,lastUpdated:this.lastUpdated,purposes:this.purposes,specialPurposes:this.specialPurposes,features:this.features,specialFeatures:this.specialFeatures,stacks:this.stacks,dataCategories:this.dataCategories,vendors:this.fullVendorList}},t.prototype.cloneSpecialFeatures=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.specialFeatures)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.cloneFeature(this.specialFeatures[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.cloneFeatures=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.features)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.cloneFeature(this.features[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.cloneStacks=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.stacks)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.cloneStack(this.stacks[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.cloneDataCategories=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.dataCategories)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.cloneDataCategory(this.dataCategories[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.cloneSpecialPurposes=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.specialPurposes)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.clonePurpose(this.specialPurposes[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.clonePurposes=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.purposes)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.clonePurpose(this.purposes[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.clonePurpose=function(e){return __assign(__assign({id:e.id,name:e.name,description:e.description},e.descriptionLegal?{descriptionLegal:e.descriptionLegal}:{}),e.illustrations?{illustrations:Array.from(e.illustrations)}:{})},t.cloneFeature=function(e){return __assign(__assign({id:e.id,name:e.name,description:e.description},e.descriptionLegal?{descriptionLegal:e.descriptionLegal}:{}),e.illustrations?{illustrations:Array.from(e.illustrations)}:{})},t.cloneDataCategory=function(e){return{id:e.id,name:e.name,description:e.description}},t.cloneStack=function(e){return{id:e.id,name:e.name,description:e.description,purposes:Array.from(e.purposes),specialFeatures:Array.from(e.specialFeatures)}},t.cloneDataRetention=function(e){return __assign(__assign({},"number"==typeof e.stdRetention?{stdRetention:e.stdRetention}:{}),{purposes:__assign({},e.purposes),specialPurposes:__assign({},e.specialPurposes)})},t.cloneVendorUrls=function(e){return e.map((function(e){return __assign({langId:e.langId,privacy:e.privacy},e.legIntClaim?{legIntClaim:e.legIntClaim}:{})}))},t.cloneVendor=function(e){return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({id:e.id,name:e.name,purposes:Array.from(e.purposes),legIntPurposes:Array.from(e.legIntPurposes),flexiblePurposes:Array.from(e.flexiblePurposes),specialPurposes:Array.from(e.specialPurposes),features:Array.from(e.features),specialFeatures:Array.from(e.specialFeatures)},e.overflow?{overflow:{httpGetLimit:e.overflow.httpGetLimit}}:{}),"number"==typeof e.cookieMaxAgeSeconds||null===e.cookieMaxAgeSeconds?{cookieMaxAgeSeconds:e.cookieMaxAgeSeconds}:{}),void 0!==e.usesCookies?{usesCookies:e.usesCookies}:{}),e.policyUrl?{policyUrl:e.policyUrl}:{}),void 0!==e.cookieRefresh?{cookieRefresh:e.cookieRefresh}:{}),void 0!==e.usesNonCookieAccess?{usesNonCookieAccess:e.usesNonCookieAccess}:{}),e.dataRetention?{dataRetention:this.cloneDataRetention(e.dataRetention)}:{}),e.urls?{urls:this.cloneVendorUrls(e.urls)}:{}),e.dataDeclaration?{dataDeclaration:Array.from(e.dataDeclaration)}:{}),e.deviceStorageDisclosureUrl?{deviceStorageDisclosureUrl:e.deviceStorageDisclosureUrl}:{}),e.deletedDate?{deletedDate:e.deletedDate}:{})},t.prototype.cloneVendors=function(){var e,r,n={};try{for(var s=__values(Object.keys(this.fullVendorList)),o=s.next();!o.done;o=s.next()){var i=o.value;n[i]=t.cloneVendor(this.fullVendorList[i])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return n},t.prototype.changeLanguage=function(e){return __awaiter(this,void 0,void 0,(function(){var r,n,s,o,i,a;return __generator(this,(function(u){switch(u.label){case 0:r=e;try{r=t.consentLanguages.parseLanguage(e)}catch(e){throw new index_js_1.GVLError("Error during parsing the language: "+e.message)}if(n=e.toUpperCase(),r.toLowerCase()===t.DEFAULT_LANGUAGE.toLowerCase()&&!t.LANGUAGE_CACHE.has(n))return[2];if(r===this.lang_)return[3,5];if(this.lang_=r,!t.LANGUAGE_CACHE.has(n))return[3,1];for(o in s=t.LANGUAGE_CACHE.get(n))s.hasOwnProperty(o)&&(this[o]=s[o]);return[3,5];case 1:i=t.baseUrl+t.languageFilename.replace("[LANG]",this.lang_.toLowerCase()),u.label=2;case 2:return u.trys.push([2,4,,5]),[4,this.fetchJson(i)];case 3:return u.sent(),this.cacheLang_=n,this.cacheLanguage(),[3,5];case 4:throw a=u.sent(),new index_js_1.GVLError("unable to load language: "+a.message);case 5:return[2]}}))}))},Object.defineProperty(t.prototype,"language",{get:function(){return this.lang_},enumerable:!1,configurable:!0}),t.prototype.isVendorList=function(e){return void 0!==e&&void 0!==e.vendors},t.prototype.populate=function(e){this.purposes=e.purposes,this.specialPurposes=e.specialPurposes,this.features=e.features,this.specialFeatures=e.specialFeatures,this.stacks=e.stacks,this.dataCategories=e.dataCategories,this.isVendorList(e)&&(this.gvlSpecificationVersion=e.gvlSpecificationVersion,this.tcfPolicyVersion=e.tcfPolicyVersion,this.vendorListVersion=e.vendorListVersion,this.lastUpdated=e.lastUpdated,"string"==typeof this.lastUpdated&&(this.lastUpdated=new Date(this.lastUpdated)),this.vendors_=e.vendors,this.fullVendorList=e.vendors,this.mapVendors(),this.isReady_=!0,this.isLatest&&t.CACHE.set(t.LATEST_CACHE_KEY,this.getJson()),t.CACHE.has(this.vendorListVersion)||t.CACHE.set(this.vendorListVersion,this.getJson())),this.cacheLanguage()},t.prototype.mapVendors=function(e){var t=this;this.byPurposeVendorMap={},this.bySpecialPurposeVendorMap={},this.byFeatureVendorMap={},this.bySpecialFeatureVendorMap={},Object.keys(this.purposes).forEach((function(e){t.byPurposeVendorMap[e]={legInt:new Set,consent:new Set,flexible:new Set}})),Object.keys(this.specialPurposes).forEach((function(e){t.bySpecialPurposeVendorMap[e]=new Set})),Object.keys(this.features).forEach((function(e){t.byFeatureVendorMap[e]=new Set})),Object.keys(this.specialFeatures).forEach((function(e){t.bySpecialFeatureVendorMap[e]=new Set})),Array.isArray(e)||(e=Object.keys(this.fullVendorList).map((function(e){return+e}))),this.vendorIds=new Set(e),this.vendors_=e.reduce((function(e,r){var n=t.vendors_[String(r)];return n&&void 0===n.deletedDate&&(n.purposes.forEach((function(e){t.byPurposeVendorMap[String(e)].consent.add(r)})),n.specialPurposes.forEach((function(e){t.bySpecialPurposeVendorMap[String(e)].add(r)})),n.legIntPurposes.forEach((function(e){t.byPurposeVendorMap[String(e)].legInt.add(r)})),n.flexiblePurposes&&n.flexiblePurposes.forEach((function(e){t.byPurposeVendorMap[String(e)].flexible.add(r)})),n.features.forEach((function(e){t.byFeatureVendorMap[String(e)].add(r)})),n.specialFeatures.forEach((function(e){t.bySpecialFeatureVendorMap[String(e)].add(r)})),e[r]=n),e}),{})},t.prototype.getFilteredVendors=function(e,t,r,n){var s=this,o=e.charAt(0).toUpperCase()+e.slice(1),i={};return("purpose"===e&&r?this["by"+o+"VendorMap"][String(t)][r]:this["by"+(n?"Special":"")+o+"VendorMap"][String(t)]).forEach((function(e){i[String(e)]=s.vendors[String(e)]})),i},t.prototype.getVendorsWithConsentPurpose=function(e){return this.getFilteredVendors("purpose",e,"consent")},t.prototype.getVendorsWithLegIntPurpose=function(e){return this.getFilteredVendors("purpose",e,"legInt")},t.prototype.getVendorsWithFlexiblePurpose=function(e){return this.getFilteredVendors("purpose",e,"flexible")},t.prototype.getVendorsWithSpecialPurpose=function(e){return this.getFilteredVendors("purpose",e,void 0,!0)},t.prototype.getVendorsWithFeature=function(e){return this.getFilteredVendors("feature",e)},t.prototype.getVendorsWithSpecialFeature=function(e){return this.getFilteredVendors("feature",e,void 0,!0)},Object.defineProperty(t.prototype,"vendors",{get:function(){return this.vendors_},enumerable:!1,configurable:!0}),t.prototype.narrowVendorsTo=function(e){this.mapVendors(e)},Object.defineProperty(t.prototype,"isReady",{get:function(){return this.isReady_},enumerable:!1,configurable:!0}),t.prototype.clone=function(){var e=new t(JSON.parse(JSON.stringify(this.getJson())));return this.lang_!==t.DEFAULT_LANGUAGE&&e.changeLanguage(this.lang_),e},t.isInstanceOf=function(e){return"object"==typeof e&&"function"==typeof e.narrowVendorsTo},t.LANGUAGE_CACHE=new Map,t.CACHE=new Map,t.LATEST_CACHE_KEY=0,t.DEFAULT_LANGUAGE="EN",t.consentLanguages=new index_js_2.ConsentLanguages,t.latestFilename="vendor-list.json",t.versionedFilename="archives/vendor-list-v[VERSION].json",t.languageFilename="purposes-[LANG].json",t}(Cloneable_js_1.Cloneable);exports.GVL=GVL;
@@ -1 +1 @@
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);if(!e.isEmpty()){var t=Array.from(e.gvl.vendorIds),r=function(e,n){var r=t.indexOf(e);if(t.indexOf(n)-r>0){var o=t.indexOf(e+1);return{nextVendorId:t[o],index:t[r+1]}}return{nextVendorId:e,index:e}},o=new Map;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);var i=e.getVendorsSet(t),s=0,d="";if(o.has(i)){var _=o.get(i);s=_.numEntries,d=_.rangeField}else{for(var c=Array.from(i).sort((function(e,n){return e-n})),g=c.length,B=0,h=0;h<g;h++){var L=c[h];0===B&&(s++,B=L);var j=h===g-1;if(!j){var u=r(L,c[g-1]),a=u.nextVendorId,E=u.index;c[h+1]>a?j=!0:E>h&&E<g&&(h=E)}if(j){var I=!(L===B);d+=BooleanEncoder_js_1.BooleanEncoder.encode(I),d+=IntEncoder_js_1.IntEncoder.encode(B,BitLength_js_1.BitLength.vendorId),I&&(d+=IntEncoder_js_1.IntEncoder.encode(L,BitLength_js_1.BitLength.vendorId)),B=0}}o.set(i,{numEntries:s,rangeField:d})}n+=IntEncoder_js_1.IntEncoder.encode(s,BitLength_js_1.BitLength.numEntries),n+=d}))}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=0;c<_;c++){var g=BooleanEncoder_js_1.BooleanEncoder.decode(e.substr(n,BitLength_js_1.BitLength.anyBoolean));n+=BitLength_js_1.BitLength.anyBoolean;var B=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,g){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<B)throw new index_js_1.DecodingError("Invalid RangeEntry: endVendorId ".concat(h," is less than ").concat(B));for(var L=B;L<=h;L++)t.add(L,d)}else t.add(B,d)}}return t.bitLength=n,t},e}();exports.PurposeRestrictionVectorEncoder=PurposeRestrictionVectorEncoder;
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);if(!e.isEmpty()){var t=Array.from(e.gvl.vendorIds),r=function(e,n){var r=t.indexOf(e);if(t.indexOf(n)-r>0){var o=t.indexOf(e+1);return{nextVendorId:t[o],index:t[r+1]}}return{nextVendorId:e,index:e}},o=new Map;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);var i=e.getVendorsSet(t),s=0,d="";if(o.has(i)){var _=o.get(i);s=_.numEntries,d=_.rangeField}else{for(var c=Array.from(i).sort((function(e,n){return e-n})),g=c.length,B=0,h=0;h<g;h++){var L=c[h];0===B&&(s++,B=L);var j=h===g-1;if(!j){var u=r(L,c[g-1]),a=u.nextVendorId,E=u.index;c[h+1]>a?j=!0:E>h&&E<g&&(h=E)}if(L==h-1&&g==h+1&&(j=!0),j){var I=!(L===B);d+=BooleanEncoder_js_1.BooleanEncoder.encode(I),d+=IntEncoder_js_1.IntEncoder.encode(B,BitLength_js_1.BitLength.vendorId),I&&(d+=IntEncoder_js_1.IntEncoder.encode(L,BitLength_js_1.BitLength.vendorId)),B=0}}o.set(i,{numEntries:s,rangeField:d})}n+=IntEncoder_js_1.IntEncoder.encode(s,BitLength_js_1.BitLength.numEntries),n+=d}))}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=0;c<_;c++){var g=BooleanEncoder_js_1.BooleanEncoder.decode(e.substr(n,BitLength_js_1.BitLength.anyBoolean));n+=BitLength_js_1.BitLength.anyBoolean;var B=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,g){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<B)throw new index_js_1.DecodingError("Invalid RangeEntry: endVendorId ".concat(h," is less than ").concat(B));for(var L=B;L<=h;L++)t.add(L,d)}else t.add(B,d)}}return t.bitLength=n,t},e}();exports.PurposeRestrictionVectorEncoder=PurposeRestrictionVectorEncoder;
@@ -1 +1 @@
1
- "use strict";var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConsentLanguages=void 0;var ConsentLanguages=function(){function e(){}return e.prototype.has=function(t){return e.langSet.has(t)},e.prototype.parseLanguage=function(t){var n,r,o=(t=t.toUpperCase()).split("-")[0];if(t.length>=2&&2==o.length){if(e.langSet.has(t))return t;if(e.langSet.has(o))return o;var a=o+"-"+o;if(e.langSet.has(a))return a;try{for(var u=__values(e.langSet),i=u.next();!i.done;i=u.next()){var l=i.value;if(-1!==l.indexOf(t)||-1!==l.indexOf(o))return l}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}throw new Error("unsupported language ".concat(t))},e.prototype.forEach=function(t){e.langSet.forEach(t)},Object.defineProperty(e.prototype,"size",{get:function(){return e.langSet.size},enumerable:!1,configurable:!0}),e.langSet=new Set(["AR","BG","BS","CA","CS","DA","DE","EL","EN","ES","ET","EU","FI","FR","GL","HR","HU","IT","JA","LT","LV","MT","NL","NO","PL","PT-BR","PT-PT","RO","RU","SK","SL","SR-LATN","SR-CYRL","SV","TR","ZH"]),e}();exports.ConsentLanguages=ConsentLanguages;
1
+ "use strict";var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConsentLanguages=void 0;var ConsentLanguages=function(){function e(){}return e.prototype.has=function(t){return e.langSet.has(t)},e.prototype.parseLanguage=function(t){var n,r,o=(t=t.toUpperCase()).split("-")[0];if(t.length>=2&&2==o.length){if(e.langSet.has(t))return t;if(e.langSet.has(o))return o;var a=o+"-"+o;if(e.langSet.has(a))return a;try{for(var u=__values(e.langSet),i=u.next();!i.done;i=u.next()){var l=i.value;if(-1!==l.indexOf(t)||-1!==l.indexOf(o))return l}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}throw new Error("unsupported language ".concat(t))},e.prototype.forEach=function(t){e.langSet.forEach(t)},Object.defineProperty(e.prototype,"size",{get:function(){return e.langSet.size},enumerable:!1,configurable:!0}),e.langSet=new Set(["AR","BG","BS","CA","CS","CY","DA","DE","EL","EN","ES","ET","EU","FI","FR","GL","HE","HR","HU","ID","IT","JA","KO","LT","LV","MK","MS","MT","NL","NO","PL","PT-BR","PT-PT","RO","RU","SK","SL","SR-LATN","SR-CYRL","SV","TL","TR","UK","ZH"]),e}();exports.ConsentLanguages=ConsentLanguages;
@@ -0,0 +1,3 @@
1
+ export interface GvlCreationOptions {
2
+ language: string;
3
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -8,3 +8,4 @@ export * from './Stack.js';
8
8
  export * from './Vendor.js';
9
9
  export * from './VendorList.js';
10
10
  export * from './DataCategory.js';
11
+ export * from './GvlCreationOptions.js';
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var a=Object.getOwnPropertyDescriptor(r,t);a&&!("get"in a?!r.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,a)}: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("./ByPurposeVendorMap.js"),exports),__exportStar(require("./Declarations.js"),exports),__exportStar(require("./Feature.js"),exports),__exportStar(require("./GVLMapItem.js"),exports),__exportStar(require("./IDSetMap.js"),exports),__exportStar(require("./Purpose.js"),exports),__exportStar(require("./Stack.js"),exports),__exportStar(require("./Vendor.js"),exports),__exportStar(require("./VendorList.js"),exports),__exportStar(require("./DataCategory.js"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}: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("./ByPurposeVendorMap.js"),exports),__exportStar(require("./Declarations.js"),exports),__exportStar(require("./Feature.js"),exports),__exportStar(require("./GVLMapItem.js"),exports),__exportStar(require("./IDSetMap.js"),exports),__exportStar(require("./Purpose.js"),exports),__exportStar(require("./Stack.js"),exports),__exportStar(require("./Vendor.js"),exports),__exportStar(require("./VendorList.js"),exports),__exportStar(require("./DataCategory.js"),exports),__exportStar(require("./GvlCreationOptions.js"),exports);
package/lib/mjs/GVL.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Cloneable } from './Cloneable.js';
2
2
  import { GVLError } from './errors/index.js';
3
- import { ConsentLanguages, IntMap } from './model/index.js';
3
+ import { ConsentLanguages, GvlCreationOptions, IntMap } from './model/index.js';
4
4
  import { Feature, Purpose, Stack, Vendor, VendorList, DataCategory } from './model/gvl/index.js';
5
5
  export type VersionOrVendorList = string | number | VendorList;
6
6
  /**
@@ -177,8 +177,9 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
177
177
  * [[VendorList]] object or a version number represented as a string or
178
178
  * number to download. If nothing is passed the latest version of the GVL
179
179
  * will be loaded
180
+ * @param {GvlCreationOptions} [options] - it is an optional object where the default language can be set
180
181
  */
181
- constructor(versionOrVendorList?: VersionOrVendorList);
182
+ constructor(versionOrVendorList?: VersionOrVendorList, options?: GvlCreationOptions);
182
183
  /**
183
184
  * emptyLanguageCache
184
185
  *
@@ -206,6 +207,20 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
206
207
  * functionality and methods of this class.
207
208
  */
208
209
  getJson(): VendorList;
210
+ private cloneSpecialFeatures;
211
+ private cloneFeatures;
212
+ private cloneStacks;
213
+ private cloneDataCategories;
214
+ private cloneSpecialPurposes;
215
+ private clonePurposes;
216
+ private static clonePurpose;
217
+ private static cloneFeature;
218
+ private static cloneDataCategory;
219
+ private static cloneStack;
220
+ private static cloneDataRetention;
221
+ private static cloneVendorUrls;
222
+ private static cloneVendor;
223
+ private cloneVendors;
209
224
  /**
210
225
  * changeLanguage - retrieves the purpose language translation and sets the
211
226
  * internal language variable
package/lib/mjs/GVL.js CHANGED
@@ -189,16 +189,26 @@ export class GVL extends Cloneable {
189
189
  * [[VendorList]] object or a version number represented as a string or
190
190
  * number to download. If nothing is passed the latest version of the GVL
191
191
  * will be loaded
192
+ * @param {GvlCreationOptions} [options] - it is an optional object where the default language can be set
192
193
  */
193
- constructor(versionOrVendorList) {
194
+ constructor(versionOrVendorList, options) {
194
195
  super();
195
196
  /**
196
197
  * should have been configured before and instance was created and will
197
198
  * persist through the app
198
199
  */
199
200
  let url = GVL.baseUrl;
200
- this.lang_ = GVL.DEFAULT_LANGUAGE;
201
- this.cacheLang_ = GVL.DEFAULT_LANGUAGE;
201
+ let parsedLanguage = options?.language;
202
+ if (parsedLanguage) {
203
+ try {
204
+ parsedLanguage = GVL.consentLanguages.parseLanguage(parsedLanguage);
205
+ }
206
+ catch (e) {
207
+ throw new GVLError('Error during parsing the language: ' + e.message);
208
+ }
209
+ }
210
+ this.lang_ = parsedLanguage || GVL.DEFAULT_LANGUAGE;
211
+ this.cacheLang_ = parsedLanguage || GVL.DEFAULT_LANGUAGE;
202
212
  if (this.isVendorList(versionOrVendorList)) {
203
213
  this.populate(versionOrVendorList);
204
214
  this.readyPromise = Promise.resolve();
@@ -319,6 +329,126 @@ export class GVL extends Cloneable {
319
329
  vendors: this.fullVendorList,
320
330
  };
321
331
  }
332
+ cloneSpecialFeatures() {
333
+ const features = {};
334
+ for (const featureId of Object.keys(this.specialFeatures)) {
335
+ features[featureId] = GVL.cloneFeature(this.specialFeatures[featureId]);
336
+ }
337
+ return features;
338
+ }
339
+ cloneFeatures() {
340
+ const features = {};
341
+ for (const featureId of Object.keys(this.features)) {
342
+ features[featureId] = GVL.cloneFeature(this.features[featureId]);
343
+ }
344
+ return features;
345
+ }
346
+ cloneStacks() {
347
+ const stacks = {};
348
+ for (const stackId of Object.keys(this.stacks)) {
349
+ stacks[stackId] = GVL.cloneStack(this.stacks[stackId]);
350
+ }
351
+ return stacks;
352
+ }
353
+ cloneDataCategories() {
354
+ const dataCategories = {};
355
+ for (const dataCategoryId of Object.keys(this.dataCategories)) {
356
+ dataCategories[dataCategoryId] = GVL.cloneDataCategory(this.dataCategories[dataCategoryId]);
357
+ }
358
+ return dataCategories;
359
+ }
360
+ cloneSpecialPurposes() {
361
+ const purposes = {};
362
+ for (const purposeId of Object.keys(this.specialPurposes)) {
363
+ purposes[purposeId] = GVL.clonePurpose(this.specialPurposes[purposeId]);
364
+ }
365
+ return purposes;
366
+ }
367
+ clonePurposes() {
368
+ const purposes = {};
369
+ for (const purposeId of Object.keys(this.purposes)) {
370
+ purposes[purposeId] = GVL.clonePurpose(this.purposes[purposeId]);
371
+ }
372
+ return purposes;
373
+ }
374
+ static clonePurpose(purpose) {
375
+ return {
376
+ id: purpose.id,
377
+ name: purpose.name,
378
+ description: purpose.description,
379
+ ...(purpose.descriptionLegal ? { descriptionLegal: purpose.descriptionLegal } : {}),
380
+ ...(purpose.illustrations ? { illustrations: Array.from(purpose.illustrations) } : {}),
381
+ };
382
+ }
383
+ static cloneFeature(feature) {
384
+ return {
385
+ id: feature.id,
386
+ name: feature.name,
387
+ description: feature.description,
388
+ ...(feature.descriptionLegal ? { descriptionLegal: feature.descriptionLegal } : {}),
389
+ ...(feature.illustrations ? { illustrations: Array.from(feature.illustrations) } : {}),
390
+ };
391
+ }
392
+ static cloneDataCategory(dataCategory) {
393
+ return {
394
+ id: dataCategory.id,
395
+ name: dataCategory.name,
396
+ description: dataCategory.description,
397
+ };
398
+ }
399
+ static cloneStack(stack) {
400
+ return {
401
+ id: stack.id,
402
+ name: stack.name,
403
+ description: stack.description,
404
+ purposes: Array.from(stack.purposes),
405
+ specialFeatures: Array.from(stack.specialFeatures),
406
+ };
407
+ }
408
+ static cloneDataRetention(dataRetention) {
409
+ return {
410
+ ...(typeof dataRetention.stdRetention === 'number' ? { stdRetention: dataRetention.stdRetention } : {}),
411
+ purposes: { ...dataRetention.purposes },
412
+ specialPurposes: { ...dataRetention.specialPurposes },
413
+ };
414
+ }
415
+ static cloneVendorUrls(urls) {
416
+ return urls.map((url) => ({
417
+ langId: url.langId,
418
+ privacy: url.privacy,
419
+ ...(url.legIntClaim ? { legIntClaim: url.legIntClaim } : {}),
420
+ }));
421
+ }
422
+ static cloneVendor(vendor) {
423
+ return {
424
+ id: vendor.id,
425
+ name: vendor.name,
426
+ purposes: Array.from(vendor.purposes),
427
+ legIntPurposes: Array.from(vendor.legIntPurposes),
428
+ flexiblePurposes: Array.from(vendor.flexiblePurposes),
429
+ specialPurposes: Array.from(vendor.specialPurposes),
430
+ features: Array.from(vendor.features),
431
+ specialFeatures: Array.from(vendor.specialFeatures),
432
+ ...(vendor.overflow ? { overflow: { httpGetLimit: vendor.overflow.httpGetLimit } } : {}),
433
+ ...(typeof vendor.cookieMaxAgeSeconds === 'number' || vendor.cookieMaxAgeSeconds === null ? { cookieMaxAgeSeconds: vendor.cookieMaxAgeSeconds } : {}),
434
+ ...(vendor.usesCookies !== undefined ? { usesCookies: vendor.usesCookies } : {}),
435
+ ...(vendor.policyUrl ? { policyUrl: vendor.policyUrl } : {}),
436
+ ...(vendor.cookieRefresh !== undefined ? { cookieRefresh: vendor.cookieRefresh } : {}),
437
+ ...(vendor.usesNonCookieAccess !== undefined ? { usesNonCookieAccess: vendor.usesNonCookieAccess } : {}),
438
+ ...(vendor.dataRetention ? { dataRetention: this.cloneDataRetention(vendor.dataRetention) } : {}),
439
+ ...(vendor.urls ? { urls: this.cloneVendorUrls(vendor.urls) } : {}),
440
+ ...(vendor.dataDeclaration ? { dataDeclaration: Array.from(vendor.dataDeclaration) } : {}),
441
+ ...(vendor.deviceStorageDisclosureUrl ? { deviceStorageDisclosureUrl: vendor.deviceStorageDisclosureUrl } : {}),
442
+ ...(vendor.deletedDate ? { deletedDate: vendor.deletedDate } : {}),
443
+ };
444
+ }
445
+ cloneVendors() {
446
+ const vendors = {};
447
+ for (const vendorId of Object.keys(this.fullVendorList)) {
448
+ vendors[vendorId] = GVL.cloneVendor(this.fullVendorList[vendorId]);
449
+ }
450
+ return vendors;
451
+ }
322
452
  /**
323
453
  * changeLanguage - retrieves the purpose language translation and sets the
324
454
  * internal language variable
@@ -64,6 +64,12 @@ export class PurposeRestrictionVectorEncoder {
64
64
  i = index;
65
65
  }
66
66
  }
67
+ /**
68
+ * @todo require to write a test to cover this part.
69
+ */
70
+ if (vendorId == i - 1 && len == i + 1) {
71
+ isRangeEncodeRequired = true;
72
+ }
67
73
  /**
68
74
  * either end of the loop or there are GVL vendor IDs before the next one
69
75
  */
@@ -5,6 +5,7 @@ export class ConsentLanguages {
5
5
  'BS',
6
6
  'CA',
7
7
  'CS',
8
+ 'CY',
8
9
  'DA',
9
10
  'DE',
10
11
  'EL',
@@ -15,12 +16,17 @@ export class ConsentLanguages {
15
16
  'FI',
16
17
  'FR',
17
18
  'GL',
19
+ 'HE',
18
20
  'HR',
19
21
  'HU',
22
+ 'ID',
20
23
  'IT',
21
24
  'JA',
25
+ 'KO',
22
26
  'LT',
23
27
  'LV',
28
+ 'MK',
29
+ 'MS',
24
30
  'MT',
25
31
  'NL',
26
32
  'NO',
@@ -34,7 +40,9 @@ export class ConsentLanguages {
34
40
  'SR-LATN',
35
41
  'SR-CYRL',
36
42
  'SV',
43
+ 'TL',
37
44
  'TR',
45
+ 'UK',
38
46
  'ZH',
39
47
  ]);
40
48
  has(key) {
@@ -1,2 +1 @@
1
- ;
2
1
  export {};
@@ -0,0 +1,3 @@
1
+ export interface GvlCreationOptions {
2
+ language: string;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -8,3 +8,4 @@ export * from './Stack.js';
8
8
  export * from './Vendor.js';
9
9
  export * from './VendorList.js';
10
10
  export * from './DataCategory.js';
11
+ export * from './GvlCreationOptions.js';
@@ -9,3 +9,4 @@ export * from './Stack.js';
9
9
  export * from './Vendor.js';
10
10
  export * from './VendorList.js';
11
11
  export * from './DataCategory.js';
12
+ export * from './GvlCreationOptions.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubtech-ai/core",
3
- "version": "2.8.1",
3
+ "version": "2.9.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/",
@@ -25,10 +25,11 @@
25
25
  "debug": "ndb mocha --no-timeouts",
26
26
  "serve:cov": "npx http-server ./coverage/",
27
27
  "test": "mocha",
28
- "test-cov": "rm -rf coverage; nyc --reporter=html mocha"
28
+ "test-cov": "rm -rf coverage; nyc --reporter=html mocha",
29
+ "test-ci": "mocha --reporter mocha-junit-reporter"
29
30
  },
30
31
  "devDependencies": {
31
- "@pubtech-ai/testing": "2.8.1",
32
+ "@pubtech-ai/testing": "2.9.0",
32
33
  "@istanbuljs/nyc-config-typescript": "^0.1.3",
33
34
  "@types/sinon": "^10.0.11",
34
35
  "@types/sinon-chai": "3.2.8",