From 07c7cdcb47c84406abb68acbf8c204f9265df36e Mon Sep 17 00:00:00 2001 From: Christian Cartes Date: Wed, 22 May 2024 12:15:38 -0500 Subject: [PATCH] fix: Cant set consentLanguage with custom GVL #211, GVL object is being constructed with the gvl json, and setting consentLanguage forces another fetch #405 --- modules/core/src/GVL.ts | 19 ++++++++++--------- .../core/src/model/gvl/GvlCreationOptions.ts | 3 +++ modules/core/src/model/gvl/index.ts | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 modules/core/src/model/gvl/GvlCreationOptions.ts diff --git a/modules/core/src/GVL.ts b/modules/core/src/GVL.ts index 45a6fdf2..e123ded4 100644 --- a/modules/core/src/GVL.ts +++ b/modules/core/src/GVL.ts @@ -1,8 +1,8 @@ -import {Cloneable} from './Cloneable.js'; -import {GVLError} from './errors/index.js'; -import {Json} from './Json.js'; -import {ConsentLanguages, IntMap} from './model/index.js'; -import {ByPurposeVendorMap, Declarations, Feature, IDSetMap, Purpose, Stack, Vendor, VendorList, DataCategory} from './model/gvl/index.js'; +import { Cloneable } from './Cloneable.js'; +import { GVLError } from './errors/index.js'; +import { Json } from './Json.js'; +import { ConsentLanguages, IntMap } from './model/index.js'; +import { ByPurposeVendorMap, Declarations, Feature, IDSetMap, Purpose, Stack, Vendor, VendorList, DataCategory, GvlCreationOption } from './model/gvl/index.js'; export type VersionOrVendorList = string | number | VendorList; type PurposeOrFeature = 'purpose' | 'feature'; @@ -236,8 +236,9 @@ export class GVL extends Cloneable implements VendorList { * [[VendorList]] object or a version number represented as a string or * number to download. If nothing is passed the latest version of the GVL * will be loaded + * @param options - it is an optional object where the default language can be set */ - public constructor(versionOrVendorList?: VersionOrVendorList) { + public constructor(versionOrVendorList?: VersionOrVendorList, options?: GvlCreationOption) { super(); @@ -247,8 +248,8 @@ export class GVL extends Cloneable implements VendorList { */ let url = GVL.baseUrl; - this.lang_ = GVL.DEFAULT_LANGUAGE; - this.cacheLang_ = GVL.DEFAULT_LANGUAGE; + this.lang_ = options?.language || GVL.DEFAULT_LANGUAGE; + this.cacheLang_ = options?.language || GVL.DEFAULT_LANGUAGE; if (this.isVendorList(versionOrVendorList as GVL)) { @@ -689,7 +690,7 @@ export class GVL extends Cloneable implements VendorList { } else { - vendorSet = this['by' + (special ? 'Special' : '' ) + properPurposeOrFeature + 'VendorMap'][String(id)]; + vendorSet = this['by' + (special ? 'Special' : '') + properPurposeOrFeature + 'VendorMap'][String(id)]; } diff --git a/modules/core/src/model/gvl/GvlCreationOptions.ts b/modules/core/src/model/gvl/GvlCreationOptions.ts new file mode 100644 index 00000000..edb073f1 --- /dev/null +++ b/modules/core/src/model/gvl/GvlCreationOptions.ts @@ -0,0 +1,3 @@ +export interface GvlCreationOptions { + language: string; +} diff --git a/modules/core/src/model/gvl/index.ts b/modules/core/src/model/gvl/index.ts index 2ba8d3c1..58cd56f5 100644 --- a/modules/core/src/model/gvl/index.ts +++ b/modules/core/src/model/gvl/index.ts @@ -10,3 +10,4 @@ export * from './Stack.js'; export * from './Vendor.js'; export * from './VendorList.js'; export * from './DataCategory.js'; +export * from './GvlCreationOptions.js';