-
Notifications
You must be signed in to change notification settings - Fork 92
/
index.ts
executable file
·139 lines (90 loc) · 3.44 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env node
/* eslint no-console: 0 */
import {TCString, Vector} from '@iabtcf/core';
const args = process.argv;
let encoded = '';
for (const arg of args) {
if (arg.charAt(0) === 'C') {
encoded = arg;
break;
}
}
global.btoa = (str: string | Buffer): string => {
let buffer;
if (str instanceof Buffer) {
buffer = str;
} else {
buffer = Buffer.from(str.toString(), 'binary');
}
return buffer.toString('base64');
};
global.atob = (str: string): string => {
return Buffer.from(str, 'base64').toString('binary');
};
const print = (key: string | number, value: string | number | boolean | object | undefined, indent = 0): void => {
const indentString = ' '.repeat(indent);
key = '\x1b[33m' + key +'\x1b[0m';
switch (typeof value) {
case 'string':
console.log(`${indentString}${key}: \x1b[32m"${value}"\x1b[0m`);
break;
case 'boolean':
console.log(`${indentString}${key}: \x1b[35m\x1b[1m${value}\x1b[0m`);
break;
case 'object':
if (value instanceof Date) {
console.log(`${indentString}${key}: \x1b[36m${(value as Date).toString()}\x1b[0m`);
} else if (value === null) {
console.log(`${indentString}${key}: '\x1b[1m' + value\x1b[0m`);
} else if (value instanceof Vector) {
console.log(`\x1b[1m${indentString}${key}\x1b[0m`);
value.forEach((bool: boolean, id: number): void => {
print(id, bool, indent + 1);
});
} else {
console.log(`\x1b[1m${indentString}${key}\x1b[0m`);
Object.keys(value).forEach((key: string): void => {
print(key, value[key], indent + 1);
});
}
break;
case 'number':
console.log(`${indentString}${key}: ${value}\x1b[0m`);
break;
}
};
if (encoded) {
print('encoded', encoded);
try {
const tcModel = TCString.decode(encoded);
print('version', tcModel.version);
print('cmpId', tcModel.cmpId);
print('cmpVersion', tcModel.cmpVersion);
print('consentScreen', tcModel.consentScreen);
print('consentLanguage', tcModel.consentLanguage);
print('created', tcModel.created);
print('lastUpdated', tcModel.lastUpdated);
print('policyVersion', tcModel.policyVersion);
print('isServiceSpecific', tcModel.isServiceSpecific);
print('useNonStandardStacks', tcModel.useNonStandardStacks);
print('purposeOneTreatment', tcModel.purposeOneTreatment);
print('publisherCountryCode', tcModel.publisherCountryCode);
print('supportOOB', tcModel.supportOOB);
print('vendorListVersion', tcModel.vendorListVersion);
print('purposeConsents', tcModel.purposeConsents);
print('purposeLegitimateInterest', tcModel.purposeLegitimateInterest);
print('specialFeatureOptIns', tcModel.specialFeatureOptIns);
print('publisherCustomConsents', tcModel.publisherCustomConsents);
print('publisherLegitimateInterest', tcModel.publisherLegitimateInterest);
print('publisherCustomConsents', tcModel.publisherCustomConsents);
print('publisherCustomLegitimateInterest', tcModel.publisherCustomLegitimateInterest);
print('vendorConsents', tcModel.vendorConsents);
print('vendorLegitimateInterest', tcModel.vendorLegitimateInterest);
print('vendorsDisclosed', tcModel.vendorsDisclosed);
print('vendorsAllowed', tcModel.vendorsAllowed);
} catch (err) {
console.error(`Unable to decode TC string: ${err.message}`);
}
} else {
console.error('Please pass a TC string');
}