-
Notifications
You must be signed in to change notification settings - Fork 92
/
GetVendorListCommand.ts
80 lines (47 loc) · 1.35 KB
/
GetVendorListCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {GVL, TCModel} from '@iabtcf/core';
import {Command} from './Command';
import {VendorListCallback} from '../types';
import {CmpApiModel} from '../CmpApiModel';
/**
* Gets a version of the Global Vendors List
*/
export class GetVendorListCommand extends Command {
protected success(): void {
let gvl: GVL;
const callback = this.callback as VendorListCallback;
if (!this.param) {
const tcModel = CmpApiModel.tcModel as TCModel;
if (tcModel.gvl) {
callback(tcModel.gvl.getJson(), true);
} else {
tcModel.gvl = new GVL(tcModel.vendorListVersion);
tcModel.gvl.readyPromise.then(() => {
callback(tcModel.gvl.getJson(), true);
}, this.fail).catch(this.fail);
}
} else {
gvl = new GVL(this.param);
const woops = (): void => {
this.fail();
};
gvl.readyPromise.then(() => {
callback(gvl.getJson(), true);
}, woops).catch(woops);
}
}
protected isValid(): boolean {
let retr = true;
if (this.param !== undefined) {
if (typeof this.param === 'string' || typeof this.param === 'number') {
retr = (
Number.isInteger(+this.param) &&
+this.param > 0 ||
this.param === 'LATEST'
);
} else {
retr = false;
}
}
return retr;
}
}