Skip to content

Commit

Permalink
GVL 2.2 [InteractiveAdvertisingBureau#396 - from forked] (#6)
Browse files Browse the repository at this point in the history
* add optional fields

* schema version for GVL: v2 and v2.2

* add tests

* fix GVL path

* update v2.2 GVL to the latest version in testing

* v1.5.7

* Assigned new package name iabtechlabtcf

* corrected package version

* v1.5.7

* v1.5.7

* v1.5.7

* Update to support TCF v2.2 (issue InteractiveAdvertisingBureau#388). Also fixed an error in the test script"

---------

Co-authored-by: Sergei Sevriugin <sevriugin@gmail.com>
Co-authored-by: Nitish Shelage <nitish.shelage@aitglobalinc.com>
Co-authored-by: Heinz Baumann <heinz_baumann1@hotmail.com>
  • Loading branch information
4 people authored Jul 21, 2023
1 parent 55b2ca8 commit ba47cf4
Show file tree
Hide file tree
Showing 96 changed files with 21,061 additions and 30 deletions.
2 changes: 1 addition & 1 deletion modules/cmpapi/test/command/GetVendorListCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('command->GetVendorListCommand', (): void => {
const version = makeRandomInt(1, 22);
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const json = JSON.parse(fs.readFileSync(__dirname + `/../../../testing/lib/mjs/vendorlist/vendor-list-v${version}.json`).toString());
const json = JSON.parse(fs.readFileSync(__dirname + `/../../../testing/lib/mjs/vendorlist/v2/vendor-list-v${version}.json`).toString());
const stringified = JSON.stringify(json);

new GetVendorListCommand((gvl: VendorList, success: boolean): void => {
Expand Down
10 changes: 9 additions & 1 deletion modules/core/src/GVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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} from './model/gvl/index.js';
import {ByPurposeVendorMap, Declarations, Feature, IDSetMap, Purpose, Stack, Vendor, VendorList, DataCategory} from './model/gvl/index.js';

export type VersionOrVendorList = string | number | VendorList;
type PurposeOrFeature = 'purpose' | 'feature';
Expand Down Expand Up @@ -221,6 +221,11 @@ export class GVL extends Cloneable<GVL> implements VendorList {
*/
public stacks: IntMap<Stack>;

/**
* @param {IntMap<DataCategory>} a collection of [[DataCategory]]s
*/
public dataCategories?: IntMap<DataCategory>;

private lang_: string;

private isLatest = false;
Expand Down Expand Up @@ -365,6 +370,7 @@ export class GVL extends Cloneable<GVL> implements VendorList {
features: this.features,
specialFeatures: this.specialFeatures,
stacks: this.stacks,
dataCategories: this.dataCategories,
});

}
Expand Down Expand Up @@ -404,6 +410,7 @@ export class GVL extends Cloneable<GVL> implements VendorList {
features: this.features,
specialFeatures: this.specialFeatures,
stacks: this.stacks,
dataCategories: this.dataCategories,
vendors: this.fullVendorList,
}));

Expand Down Expand Up @@ -493,6 +500,7 @@ export class GVL extends Cloneable<GVL> implements VendorList {
this.features = gvlObject.features;
this.specialFeatures = gvlObject.specialFeatures;
this.stacks = gvlObject.stacks;
this.dataCategories = gvlObject.dataCategories;

if (this.isVendorList(gvlObject)) {

Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/model/gvl/DataCategory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {GVLMapItem} from './GVLMapItem.js';

export interface DataCategory extends GVLMapItem {
description: string;
}
7 changes: 7 additions & 0 deletions modules/core/src/model/gvl/DataRetention.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {IntMap} from '../IntMap.js';

export interface DataRetention {
stdRetention?: number;
purposes: IntMap<number>;
specialPurposes: IntMap<number>;
}
2 changes: 2 additions & 0 deletions modules/core/src/model/gvl/Declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {IntMap} from '../IntMap.js';
import {Feature} from './Feature.js';
import {Purpose} from './Purpose.js';
import {Stack} from './Stack.js';
import {DataCategory} from './DataCategory.js';

export interface Declarations {
purposes: IntMap<Purpose>;
specialPurposes: IntMap<Purpose>;
features: IntMap<Feature>;
specialFeatures: IntMap<Feature>;
stacks: IntMap<Stack>;
dataCategories?: IntMap<DataCategory>;
}
5 changes: 5 additions & 0 deletions modules/core/src/model/gvl/Vendor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {GVLMapItem} from './GVLMapItem.js';
import {DataRetention} from './DataRetention.js';
import {VendorUrl} from './VendorUrl.js';

export interface Vendor extends GVLMapItem {
purposes: number[];
Expand All @@ -17,4 +19,7 @@ export interface Vendor extends GVLMapItem {
overflow?: {
httpGetLimit: 32 | 128;
};
dataRetention?: DataRetention;
urls?: VendorUrl[];
dataDeclaration?: number[];
}
5 changes: 5 additions & 0 deletions modules/core/src/model/gvl/VendorUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface VendorUrl {
langId: string;
privacy: string;
legIntClaim: string;
}
1 change: 1 addition & 0 deletions modules/core/src/model/gvl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './Purpose.js';
export * from './Stack.js';
export * from './Vendor.js';
export * from './VendorList.js';
export * from './DataCategory.js';
36 changes: 28 additions & 8 deletions modules/core/test/GVL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ import {XMLHttpTestTools} from '@iabtechlabtcf/testing';
import {Json} from '../src/Json';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/vendor-list-v24.json');
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/vendor-list-v24.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const translationJson = require('@iabtechlabtcf/testing/lib/vendorlist/purposes-fr.json');
const translationJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/purposes-fr.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlistJson22 = require('@iabtechlabtcf/testing/lib/vendorlist/v2.2/vendor-list.json');

describe('GVL', (): void => {

const assertPopulated = (gvl: GVL): void => {
const assertPopulated = (gvl: GVL, json = vendorlistJson): void => {

Object.keys(vendorlistJson).forEach((key: string): void => {
Object.keys(json).forEach((key: string): void => {

const msg = `assertPopulated(): gvl.${key}]`;

if (key === 'lastUpdated') {

expect((gvl[key] as Date).getTime(), msg)
.to.equal((new Date(vendorlistJson.lastUpdated).getTime()));
.to.equal((new Date(json.lastUpdated).getTime()));

} else if (typeof vendorlistJson[key] === 'object') {
} else if (typeof json[key] === 'object') {

expect(gvl[key], msg).to.deep.equal(vendorlistJson[key]);
expect(gvl[key], msg).to.deep.equal(json[key]);

} else {

expect(gvl[key], msg).to.equal(vendorlistJson[key]);
expect(gvl[key], msg).to.equal(json[key]);

}

Expand Down Expand Up @@ -117,6 +119,14 @@ describe('GVL', (): void => {

});

it('should propogate all values with passed in json for version 2.2', (): void => {

const gvl: GVL = new GVL(vendorlistJson22);

assertPopulated(gvl, vendorlistJson22);

});

it('should clone all values', (): void => {

const gvl: GVL = new GVL(vendorlistJson);
Expand All @@ -127,6 +137,16 @@ describe('GVL', (): void => {

});

it('should clone all values for version 2.2', (): void => {

const gvl: GVL = new GVL(vendorlistJson22);
const clone: GVL = gvl.clone();

assertPopulated(gvl, vendorlistJson22);
assertPopulated(clone, vendorlistJson22);

});

it('should produce a clone with the same language as the original gvl using its language cache', async (): Promise<void> => {

const fetchStub = sinon.stub(Json, 'fetch');
Expand Down
10 changes: 5 additions & 5 deletions modules/core/test/ReportedIssues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Issues Reported', (): void => {
const CONSENTSCREEN = makeRandomInt(1, 63);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlist = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/vendor-list.json').toString());
const vendorlist = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/v2/vendor-list.json').toString());

GVL.baseUrl = 'http://mydomain.com/cmp/vendorlist';

Expand Down Expand Up @@ -99,10 +99,10 @@ describe('Issues Reported', (): void => {

const language = 'fr';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const translationJson = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/purposes-fr.json').toString());
const translationJson = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/v2/purposes-fr.json').toString());

// eslint-disable-next-line @typescript-eslint/no-var-requires
const gvl = new GVL(JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/vendor-list.json').toString()));
const gvl = new GVL(JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/v2/vendor-list.json').toString()));
const {tcfPolicyVersion, gvlSpecificationVersion} = gvl;

expect(tcfPolicyVersion, 'tcfPolicyVersion').to.equal(2);
Expand All @@ -127,7 +127,7 @@ describe('Issues Reported', (): void => {
const ENGLISH = 'EN';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const gvl = new GVL(JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/vendor-list.json').toString()));
const gvl = new GVL(JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/v2/vendor-list.json').toString()));
const tcModel = new TCModel(gvl);

expect(tcModel.consentLanguage, 'consentLanguage').to.equal(ENGLISH);
Expand All @@ -141,7 +141,7 @@ describe('Issues Reported', (): void => {
it('117 TCString.encode writes all vendors as disclosed even after GVL.narrowVendorsTo([...])', async (): Promise<void> => {

// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlist = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/vendor-list.json').toString());
const vendorlist = JSON.parse(fs.readFileSync(__dirname + '/../../testing/lib/mjs/vendorlist/v2/vendor-list.json').toString());

const tcModel = new TCModel(new GVL(vendorlist));
tcModel.cmpId = makeRandomInt(2, 100);
Expand Down
4 changes: 2 additions & 2 deletions modules/core/test/TCModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('TCModel', (): void => {

describe(fieldName, (): void => {

const gvl: GVL = new GVL(require('@iabtechlabtcf/testing/lib/vendorlist/vendor-list.json'));
const gvl: GVL = new GVL(require('@iabtechlabtcf/testing/lib/vendorlist/v2/vendor-list.json'));

it(`should create an instance of ${instanceName} as ${fieldName} on init`, (): void => {

Expand Down Expand Up @@ -220,7 +220,7 @@ describe('TCModel', (): void => {

const runSetAllAndUnsetAll = (): void => {

const gvl: GVL = new GVL(require('@iabtechlabtcf/testing/lib/vendorlist/vendor-list.json'));
const gvl: GVL = new GVL(require('@iabtechlabtcf/testing/lib/vendorlist/v2/vendor-list.json'));

const loopGVLMap = (gvlKey: string, cb ): void => {

Expand Down
8 changes: 4 additions & 4 deletions modules/core/test/model/PurposeRestrictionVector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function run(): void {
const restrictionType: number = RestrictionType.NOT_ALLOWED;
const purpRestriction = new PurposeRestriction(purposeId, restrictionType);
// eslint-disable-next-line
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/purpose-restriction-vendor-list.json');
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/purpose-restriction-vendor-list.json');
const vendorIds = Object.keys(vendorlistJson.vendors);
let chosenVendorId = 0;

Expand Down Expand Up @@ -217,7 +217,7 @@ export function run(): void {
const restrictionType: number = RestrictionType.REQUIRE_CONSENT;
const purpRestriction = new PurposeRestriction(purposeId, restrictionType);
// eslint-disable-next-line
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/purpose-restriction-vendor-list.json');
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/purpose-restriction-vendor-list.json');
const vendorIds = Object.keys(vendorlistJson.vendors);
let chosenVendorId = 0;

Expand Down Expand Up @@ -254,7 +254,7 @@ export function run(): void {
const restrictionType: number = RestrictionType.REQUIRE_LI;
const purpRestriction = new PurposeRestriction(purposeId, restrictionType);
// eslint-disable-next-line
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/purpose-restriction-vendor-list.json');
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/purpose-restriction-vendor-list.json');
const vendorIds = Object.keys(vendorlistJson.vendors);
let chosenVendorId = 0;

Expand Down Expand Up @@ -291,7 +291,7 @@ export function run(): void {
const restrictionType: number = RestrictionType.NOT_ALLOWED;
const purpRestriction = new PurposeRestriction(purposeId, restrictionType);
// eslint-disable-next-line
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/purpose-restriction-vendor-list.json');
const vendorlistJson = require('@iabtechlabtcf/testing/lib/vendorlist/v2/purpose-restriction-vendor-list.json');
const vendorIds = Object.keys(vendorlistJson.vendors);
let chosenVendorId = 0;

Expand Down
33 changes: 33 additions & 0 deletions modules/core/test/model/gvl/DataCategory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {expect} from 'chai';
import {DataCategory} from '../../../src/model/gvl/DataCategory';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlistJson = require('@iabtcf/testing/lib/vendorlist/v2.2/vendor-list.json');

export function run(): void {

describe('DataCategory', (): void => {

it('must be present in GVL 2.2', (): void => {

const {dataCategories, gvlSpecificationVersion} = vendorlistJson;

expect(gvlSpecificationVersion).to.equal(3);

Object.keys(dataCategories).forEach((key: string): void => {

const dataCategory = dataCategories[key] as DataCategory;

expect(dataCategory.id).to.equal(key);

expect(dataCategory.name).to.be.a('string');

expect(dataCategory.description).to.be.a('string');

});

});

});

}
37 changes: 37 additions & 0 deletions modules/core/test/model/gvl/Vendor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {expect} from 'chai';
import {Vendor} from '../../../src/model/gvl/Vendor';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const vendorlistJson = require('@iabtcf/testing/lib/vendorlist/v2.2/vendor-list.json');

export function run(): void {

describe('Vendor', (): void => {

it('must contain new fields in GVL 2.2', (): void => {

const {vendors, gvlSpecificationVersion} = vendorlistJson;

expect(gvlSpecificationVersion).to.equal(3);

Object.keys(vendors).forEach((key: string): void => {

const vendor = vendors[key] as Vendor;

expect(vendor.id).to.equal(key);

const {dataRetention, urls, dataDeclaration} = vendor;

expect(dataRetention).to.be.a('object');

expect(urls).to.be.a('object');

expect(dataDeclaration).to.be.a('object');

});

});

});

}
3 changes: 2 additions & 1 deletion modules/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"import": "./lib/mjs/index.js",
"require": "./lib/cjs/index.js"
},
"./lib/vendorlist/*.json": "./lib/mjs/vendorlist/*.json"
"./lib/vendorlist/v2/*.json": "./lib/mjs/vendorlist/v2/*.json",
"./lib/vendorlist/v2.2/*.json": "./lib/mjs/vendorlist/v2.2/*.json"
},
"types": "lib/mjs/index.d.ts",
"files": [
Expand Down
8 changes: 4 additions & 4 deletions modules/testing/src/GVLFactory.cts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import {GVL} from '@iabtechlabtcf/core';

export class GVLFactory {

public static getVersion(version: number): GVL {
public static getVersion(version: number, schema = "v2"): GVL {

return new GVL(require(`./vendorlist/vendor-list-v${version}.json`));
return new GVL(require(`./vendorlist/${schema}/vendor-list-v${version}.json`));

}

public static getLatest(): GVL {
public static getLatest(schema = "v2"): GVL {

return new GVL(require('./vendorlist/vendor-list.json'));
return new GVL(require(`./vendorlist/${schema}/vendor-list.json`));

}

Expand Down
8 changes: 4 additions & 4 deletions modules/testing/src/GVLFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const __dirname = path.dirname(__filename);

export class GVLFactory {

public static getVersion(version: number): GVL {
public static getVersion(version: number, schema = 'v2'): GVL {

const json = JSON.parse(fs.readFileSync(__dirname + `/vendorlist/vendor-list-v${version}.json`).toString());
const json = JSON.parse(fs.readFileSync(__dirname + `/vendorlist/${schema}/vendor-list-v${version}.json`).toString());
return new GVL(json);

}

public static getLatest(): GVL {
public static getLatest(schema = 'v2'): GVL {

const json = JSON.parse(fs.readFileSync(__dirname + '/vendorlist/vendor-list.json').toString());
const json = JSON.parse(fs.readFileSync(__dirname + `/vendorlist/${schema}/vendor-list.json`).toString());
return new GVL(json);

}
Expand Down
Loading

0 comments on commit ba47cf4

Please sign in to comment.