@pubtech-ai/core 1.6.1 → 1.6.3

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
@@ -170,6 +170,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
170
170
  */
171
171
  dataCategories?: IntMap<DataCategory>;
172
172
  private lang_;
173
+ private cacheLang_;
173
174
  private isLatest;
174
175
  /**
175
176
  * @param {VersionOrVendorList} [versionOrVendorList] - can be either a
@@ -181,7 +182,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
181
182
  /**
182
183
  * emptyLanguageCache
183
184
  *
184
- * @param {string} [lang] - Optional ISO 639-1 langauge code to remove from
185
+ * @param {string} [lang] - Optional language code to remove from
185
186
  * the cache. Should be one of the languages in GVL.consentLanguages set.
186
187
  * If not then the whole cache will be deleted.
187
188
  * @return {boolean} - true if anything was deleted from the cache
@@ -209,7 +210,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
209
210
  * changeLanguage - retrieves the purpose language translation and sets the
210
211
  * internal language variable
211
212
  *
212
- * @param {string} lang - ISO 639-1 langauge code to change language to
213
+ * @param {string} lang - language code to change language to
213
214
  * @return {Promise<void | GVLError>} - returns the `readyPromise` and
214
215
  * resolves when this GVL is populated with the data from the language file.
215
216
  */
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(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){i.label=o[1];break}if(6===o[0]&&i.label<s[1]){i.label=s[1],s=o;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(o);break}s[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=s=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};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.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 void 0===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.lang_)||t.LANGUAGE_CACHE.set(this.lang_,{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 JSON.parse(JSON.stringify({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;return __generator(this,(function(a){switch(a.label){case 0:if(r=e.toUpperCase(),!t.consentLanguages.has(r))return[3,6];if(r===this.lang_)return[3,5];if(this.lang_=r,!t.LANGUAGE_CACHE.has(r))return[3,1];for(s in n=t.LANGUAGE_CACHE.get(r))n.hasOwnProperty(s)&&(this[s]=n[s]);return[3,5];case 1:o=t.baseUrl+t.languageFilename.replace("[LANG]",e),a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.fetchJson(o)];case 3:return a.sent(),this.cacheLanguage(),[3,5];case 4:throw i=a.sent(),new index_js_1.GVLError("unable to load language: "+i.message);case 5:return[3,7];case 6:throw new index_js_1.GVLError("unsupported language ".concat(e));case 7: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(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)}}(),__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(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]<s[3])){i.label=o[1];break}if(6===o[0]&&i.label<s[1]){i.label=s[1],s=o;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(o);break}s[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=s=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};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 JSON.parse(JSON.stringify({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===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]",e),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(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.SemanticPreEncoder=void 0;var index_js_1=require("../errors/index.js"),index_js_2=require("../model/index.js"),SemanticPreEncoder=function(){function e(){}return e.process=function(e,r){var s=e.gvl;if(!s)throw new index_js_1.EncodingError("Unable to encode TCModel without a GVL");if(!s.isReady)throw new index_js_1.EncodingError("Unable to encode TCModel tcModel.gvl.readyPromise is not resolved");(e=e.clone()).consentLanguage=s.language.toUpperCase(),(null==r?void 0:r.version)>0&&(null==r?void 0:r.version)<=this.processor.length?e.version=r.version:e.version=this.processor.length;var n=e.version-1;if(!this.processor[n])throw new index_js_1.EncodingError("Invalid version: ".concat(e.version));return this.processor[n](e,s)},e.processor=[function(e){return e},function(e,r){e.publisherRestrictions.gvl=r,e.purposeLegitimateInterests.unset([1,3,4,5,6]);var s=new Map;return s.set("legIntPurposes",e.vendorLegitimateInterests),s.set("purposes",e.vendorConsents),s.forEach((function(s,n){s.forEach((function(o,t){if(o){var i=r.vendors[t];if(!i||i.deletedDate)s.unset(t);else if(0===i[n].length)if("legIntPurposes"===n&&0===i.purposes.length&&0===i.legIntPurposes.length&&i.specialPurposes.length>0);else if(e.isServiceSpecific)if(0===i.flexiblePurposes.length)s.unset(t);else{for(var c=e.publisherRestrictions.getRestrictions(t),l=!1,d=0,u=c.length;d<u&&!l;d++)l=c[d].restrictionType===index_js_2.RestrictionType.REQUIRE_CONSENT&&"purposes"===n||c[d].restrictionType===index_js_2.RestrictionType.REQUIRE_LI&&"legIntPurposes"===n;l||s.unset(t)}else s.unset(t)}}))})),e.vendorsDisclosed.set(r.vendors),e}],e}();exports.SemanticPreEncoder=SemanticPreEncoder;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SemanticPreEncoder=void 0;var index_js_1=require("../errors/index.js"),index_js_2=require("../model/index.js"),SemanticPreEncoder=function(){function e(){}return e.process=function(e,s){var r=e.gvl;if(!r)throw new index_js_1.EncodingError("Unable to encode TCModel without a GVL");if(!r.isReady)throw new index_js_1.EncodingError("Unable to encode TCModel tcModel.gvl.readyPromise is not resolved");(e=e.clone()).consentLanguage=r.language.slice(0,2).toUpperCase(),(null==s?void 0:s.version)>0&&(null==s?void 0:s.version)<=this.processor.length?e.version=s.version:e.version=this.processor.length;var n=e.version-1;if(!this.processor[n])throw new index_js_1.EncodingError("Invalid version: ".concat(e.version));return this.processor[n](e,r)},e.processor=[function(e){return e},function(e,s){e.publisherRestrictions.gvl=s,e.purposeLegitimateInterests.unset([1,3,4,5,6]);var r=new Map;return r.set("legIntPurposes",e.vendorLegitimateInterests),r.set("purposes",e.vendorConsents),r.forEach((function(r,n){r.forEach((function(o,i){if(o){var t=s.vendors[i];if(!t||t.deletedDate)r.unset(i);else if(0===t[n].length)if("legIntPurposes"===n&&0===t.purposes.length&&0===t.legIntPurposes.length&&t.specialPurposes.length>0);else if(e.isServiceSpecific)if(0===t.flexiblePurposes.length)r.unset(i);else{for(var c=e.publisherRestrictions.getRestrictions(i),l=!1,d=0,u=c.length;d<u&&!l;d++)l=c[d].restrictionType===index_js_2.RestrictionType.REQUIRE_CONSENT&&"purposes"===n||c[d].restrictionType===index_js_2.RestrictionType.REQUIRE_LI&&"legIntPurposes"===n;l||r.unset(i)}else r.unset(i)}}))})),e.vendorsDisclosed.set(s.vendors),e}],e}();exports.SemanticPreEncoder=SemanticPreEncoder;
@@ -1,6 +1,7 @@
1
1
  export declare class ConsentLanguages {
2
2
  private static readonly langSet;
3
3
  has(key: string): boolean;
4
+ parseLanguage(lang: string): string;
4
5
  forEach(callback: (key: string) => void): void;
5
6
  get size(): number;
6
7
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConsentLanguages=void 0;var ConsentLanguages=function(){function e(){}return e.prototype.has=function(n){return e.langSet.has(n)},e.prototype.forEach=function(n){e.langSet.forEach(n)},Object.defineProperty(e.prototype,"size",{get:function(){return e.langSet.size},enumerable:!1,configurable:!0}),e.langSet=new Set(["BG","CA","CS","DA","DE","EL","EN","ES","ET","FI","FR","HR","HU","IT","JA","LT","LV","MT","NL","NO","PL","PT","RO","RU","SK","SL","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];try{for(var a=__values(e.langSet),u=a.next();!u.done;u=a.next()){var i=u.value;if(i==o)return o;if(i==t)return i}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=a.return)&&r.call(a)}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-CYRL","SR-LATN","SV","TR","ZH"]),e}();exports.ConsentLanguages=ConsentLanguages;
@@ -2,5 +2,5 @@ import { GVLMapItem } from './GVLMapItem.js';
2
2
  export interface Feature extends GVLMapItem {
3
3
  description: string;
4
4
  descriptionLegal: string;
5
- illustrations: string[];
5
+ illustrations?: string[];
6
6
  }
@@ -2,5 +2,5 @@ import { GVLMapItem } from './GVLMapItem.js';
2
2
  export interface Purpose extends GVLMapItem {
3
3
  description: string;
4
4
  descriptionLegal: string;
5
- illustrations: string[];
5
+ illustrations?: string[];
6
6
  }
package/lib/mjs/GVL.d.ts CHANGED
@@ -170,6 +170,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
170
170
  */
171
171
  dataCategories?: IntMap<DataCategory>;
172
172
  private lang_;
173
+ private cacheLang_;
173
174
  private isLatest;
174
175
  /**
175
176
  * @param {VersionOrVendorList} [versionOrVendorList] - can be either a
@@ -181,7 +182,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
181
182
  /**
182
183
  * emptyLanguageCache
183
184
  *
184
- * @param {string} [lang] - Optional ISO 639-1 langauge code to remove from
185
+ * @param {string} [lang] - Optional language code to remove from
185
186
  * the cache. Should be one of the languages in GVL.consentLanguages set.
186
187
  * If not then the whole cache will be deleted.
187
188
  * @return {boolean} - true if anything was deleted from the cache
@@ -209,7 +210,7 @@ export declare class GVL extends Cloneable<GVL> implements VendorList {
209
210
  * changeLanguage - retrieves the purpose language translation and sets the
210
211
  * internal language variable
211
212
  *
212
- * @param {string} lang - ISO 639-1 langauge code to change language to
213
+ * @param {string} lang - language code to change language to
213
214
  * @return {Promise<void | GVLError>} - returns the `readyPromise` and
214
215
  * resolves when this GVL is populated with the data from the language file.
215
216
  */
package/lib/mjs/GVL.js CHANGED
@@ -182,6 +182,7 @@ export class GVL extends Cloneable {
182
182
  */
183
183
  dataCategories;
184
184
  lang_;
185
+ cacheLang_;
185
186
  isLatest = false;
186
187
  /**
187
188
  * @param {VersionOrVendorList} [versionOrVendorList] - can be either a
@@ -197,6 +198,7 @@ export class GVL extends Cloneable {
197
198
  */
198
199
  let url = GVL.baseUrl;
199
200
  this.lang_ = GVL.DEFAULT_LANGUAGE;
201
+ this.cacheLang_ = GVL.DEFAULT_LANGUAGE;
200
202
  if (this.isVendorList(versionOrVendorList)) {
201
203
  this.populate(versionOrVendorList);
202
204
  this.readyPromise = Promise.resolve();
@@ -239,22 +241,22 @@ export class GVL extends Cloneable {
239
241
  /**
240
242
  * emptyLanguageCache
241
243
  *
242
- * @param {string} [lang] - Optional ISO 639-1 langauge code to remove from
244
+ * @param {string} [lang] - Optional language code to remove from
243
245
  * the cache. Should be one of the languages in GVL.consentLanguages set.
244
246
  * If not then the whole cache will be deleted.
245
247
  * @return {boolean} - true if anything was deleted from the cache
246
248
  */
247
249
  static emptyLanguageCache(lang) {
248
- let retr = false;
249
- if (lang === undefined && GVL.LANGUAGE_CACHE.size > 0) {
250
+ let result = false;
251
+ if (lang == null && GVL.LANGUAGE_CACHE.size > 0) {
250
252
  GVL.LANGUAGE_CACHE = new Map();
251
- retr = true;
253
+ result = true;
252
254
  }
253
255
  else if (typeof lang === 'string' && this.consentLanguages.has(lang.toUpperCase())) {
254
256
  GVL.LANGUAGE_CACHE.delete(lang.toUpperCase());
255
- retr = true;
257
+ result = true;
256
258
  }
257
- return retr;
259
+ return result;
258
260
  }
259
261
  /**
260
262
  * emptyCache
@@ -276,8 +278,8 @@ export class GVL extends Cloneable {
276
278
  return retr;
277
279
  }
278
280
  cacheLanguage() {
279
- if (!GVL.LANGUAGE_CACHE.has(this.lang_)) {
280
- GVL.LANGUAGE_CACHE.set(this.lang_, {
281
+ if (!GVL.LANGUAGE_CACHE.has(this.cacheLang_)) {
282
+ GVL.LANGUAGE_CACHE.set(this.cacheLang_, {
281
283
  purposes: this.purposes,
282
284
  specialPurposes: this.specialPurposes,
283
285
  features: this.features,
@@ -321,39 +323,42 @@ export class GVL extends Cloneable {
321
323
  * changeLanguage - retrieves the purpose language translation and sets the
322
324
  * internal language variable
323
325
  *
324
- * @param {string} lang - ISO 639-1 langauge code to change language to
326
+ * @param {string} lang - language code to change language to
325
327
  * @return {Promise<void | GVLError>} - returns the `readyPromise` and
326
328
  * resolves when this GVL is populated with the data from the language file.
327
329
  */
328
330
  async changeLanguage(lang) {
329
- const langUpper = lang.toUpperCase();
330
- if (GVL.consentLanguages.has(langUpper)) {
331
- if (langUpper !== this.lang_) {
332
- this.lang_ = langUpper;
333
- if (GVL.LANGUAGE_CACHE.has(langUpper)) {
334
- const cached = GVL.LANGUAGE_CACHE.get(langUpper);
335
- for (const prop in cached) {
336
- if (cached.hasOwnProperty(prop)) {
337
- this[prop] = cached[prop];
338
- }
331
+ let parsedLanguage = lang;
332
+ try {
333
+ parsedLanguage = GVL.consentLanguages.parseLanguage(lang);
334
+ }
335
+ catch (e) {
336
+ throw new GVLError('Error during parsing the language: ' + e.message);
337
+ }
338
+ const cacheLang = lang.toUpperCase();
339
+ if (parsedLanguage !== this.lang_) {
340
+ this.lang_ = parsedLanguage;
341
+ if (GVL.LANGUAGE_CACHE.has(cacheLang)) {
342
+ const cached = GVL.LANGUAGE_CACHE.get(cacheLang);
343
+ for (const prop in cached) {
344
+ if (cached.hasOwnProperty(prop)) {
345
+ this[prop] = cached[prop];
339
346
  }
340
347
  }
341
- else {
342
- // load Language specified
343
- const url = GVL.baseUrl + GVL.languageFilename.replace('[LANG]', lang);
344
- try {
345
- await this.fetchJson(url);
346
- this.cacheLanguage();
347
- }
348
- catch (err) {
349
- throw new GVLError('unable to load language: ' + err.message);
350
- }
348
+ }
349
+ else {
350
+ // load Language specified
351
+ const url = GVL.baseUrl + GVL.languageFilename.replace('[LANG]', lang);
352
+ try {
353
+ await this.fetchJson(url);
354
+ this.cacheLang_ = cacheLang;
355
+ this.cacheLanguage();
356
+ }
357
+ catch (err) {
358
+ throw new GVLError('unable to load language: ' + err.message);
351
359
  }
352
360
  }
353
361
  }
354
- else {
355
- throw new GVLError(`unsupported language ${lang}`);
356
- }
357
362
  }
358
363
  get language() {
359
364
  return this.lang_;
@@ -114,7 +114,7 @@ export class SemanticPreEncoder {
114
114
  throw new EncodingError('Unable to encode TCModel tcModel.gvl.readyPromise is not resolved');
115
115
  }
116
116
  tcModel = tcModel.clone();
117
- tcModel.consentLanguage = gvl.language.toUpperCase();
117
+ tcModel.consentLanguage = gvl.language.slice(0, 2).toUpperCase();
118
118
  if (options?.version > 0 && options?.version <= this.processor.length) {
119
119
  tcModel.version = options.version;
120
120
  }
@@ -1,6 +1,7 @@
1
1
  export declare class ConsentLanguages {
2
2
  private static readonly langSet;
3
3
  has(key: string): boolean;
4
+ parseLanguage(lang: string): string;
4
5
  forEach(callback: (key: string) => void): void;
5
6
  get size(): number;
6
7
  }
@@ -1,6 +1,8 @@
1
1
  export class ConsentLanguages {
2
2
  static langSet = new Set([
3
+ 'AR',
3
4
  'BG',
5
+ 'BS',
4
6
  'CA',
5
7
  'CS',
6
8
  'DA',
@@ -9,8 +11,10 @@ export class ConsentLanguages {
9
11
  'EN',
10
12
  'ES',
11
13
  'ET',
14
+ 'EU',
12
15
  'FI',
13
16
  'FR',
17
+ 'GL',
14
18
  'HR',
15
19
  'HU',
16
20
  'IT',
@@ -21,11 +25,14 @@ export class ConsentLanguages {
21
25
  'NL',
22
26
  'NO',
23
27
  'PL',
24
- 'PT',
28
+ 'PT-BR',
29
+ 'PT-PT',
25
30
  'RO',
26
31
  'RU',
27
32
  'SK',
28
33
  'SL',
34
+ 'SR-CYRL',
35
+ 'SR-LATN',
29
36
  'SV',
30
37
  'TR',
31
38
  'ZH',
@@ -33,6 +40,19 @@ export class ConsentLanguages {
33
40
  has(key) {
34
41
  return ConsentLanguages.langSet.has(key);
35
42
  }
43
+ parseLanguage(lang) {
44
+ lang = lang.toUpperCase();
45
+ const primaryLanguage = lang.split('-')[0];
46
+ for (const supportedLang of ConsentLanguages.langSet) {
47
+ if (supportedLang == primaryLanguage) {
48
+ return primaryLanguage;
49
+ }
50
+ if (supportedLang == lang) {
51
+ return supportedLang;
52
+ }
53
+ }
54
+ throw new Error(`unsupported language ${lang}`);
55
+ }
36
56
  forEach(callback) {
37
57
  ConsentLanguages.langSet.forEach(callback);
38
58
  }
@@ -2,5 +2,5 @@ import { GVLMapItem } from './GVLMapItem.js';
2
2
  export interface Feature extends GVLMapItem {
3
3
  description: string;
4
4
  descriptionLegal: string;
5
- illustrations: string[];
5
+ illustrations?: string[];
6
6
  }
@@ -2,5 +2,5 @@ import { GVLMapItem } from './GVLMapItem.js';
2
2
  export interface Purpose extends GVLMapItem {
3
3
  description: string;
4
4
  descriptionLegal: string;
5
- illustrations: string[];
5
+ illustrations?: string[];
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubtech-ai/core",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
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": "1.6.1",
31
+ "@pubtech-ai/testing": "1.6.3",
32
32
  "@istanbuljs/nyc-config-typescript": "^0.1.3",
33
33
  "@types/sinon": "^10.0.11",
34
34
  "@types/sinon-chai": "3.2.8",