@pubtech-ai/core 1.6.0

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.
Files changed (237) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +527 -0
  3. package/lib/cjs/Cloneable.d.ts +27 -0
  4. package/lib/cjs/Cloneable.js +1 -0
  5. package/lib/cjs/GVL.d.ts +295 -0
  6. package/lib/cjs/GVL.js +1 -0
  7. package/lib/cjs/Json.d.ts +20 -0
  8. package/lib/cjs/Json.js +1 -0
  9. package/lib/cjs/TCModel.d.ts +337 -0
  10. package/lib/cjs/TCModel.js +1 -0
  11. package/lib/cjs/TCString.d.ts +27 -0
  12. package/lib/cjs/TCString.js +1 -0
  13. package/lib/cjs/encoder/Base64Url.d.ts +29 -0
  14. package/lib/cjs/encoder/Base64Url.js +1 -0
  15. package/lib/cjs/encoder/BitLength.d.ts +32 -0
  16. package/lib/cjs/encoder/BitLength.js +1 -0
  17. package/lib/cjs/encoder/EncodingOptions.d.ts +6 -0
  18. package/lib/cjs/encoder/EncodingOptions.js +1 -0
  19. package/lib/cjs/encoder/SegmentEncoder.d.ts +8 -0
  20. package/lib/cjs/encoder/SegmentEncoder.js +1 -0
  21. package/lib/cjs/encoder/SemanticPreEncoder.d.ts +6 -0
  22. package/lib/cjs/encoder/SemanticPreEncoder.js +1 -0
  23. package/lib/cjs/encoder/field/BooleanEncoder.d.ts +4 -0
  24. package/lib/cjs/encoder/field/BooleanEncoder.js +1 -0
  25. package/lib/cjs/encoder/field/DateEncoder.d.ts +4 -0
  26. package/lib/cjs/encoder/field/DateEncoder.js +1 -0
  27. package/lib/cjs/encoder/field/FieldEncoderMap.d.ts +1 -0
  28. package/lib/cjs/encoder/field/FieldEncoderMap.js +1 -0
  29. package/lib/cjs/encoder/field/FixedVectorEncoder.d.ts +5 -0
  30. package/lib/cjs/encoder/field/FixedVectorEncoder.js +1 -0
  31. package/lib/cjs/encoder/field/IntEncoder.d.ts +4 -0
  32. package/lib/cjs/encoder/field/IntEncoder.js +1 -0
  33. package/lib/cjs/encoder/field/LangEncoder.d.ts +4 -0
  34. package/lib/cjs/encoder/field/LangEncoder.js +1 -0
  35. package/lib/cjs/encoder/field/PurposeRestrictionVectorEncoder.d.ts +5 -0
  36. package/lib/cjs/encoder/field/PurposeRestrictionVectorEncoder.js +1 -0
  37. package/lib/cjs/encoder/field/VectorEncodingType.d.ts +4 -0
  38. package/lib/cjs/encoder/field/VectorEncodingType.js +1 -0
  39. package/lib/cjs/encoder/field/VendorVectorEncoder.d.ts +6 -0
  40. package/lib/cjs/encoder/field/VendorVectorEncoder.js +1 -0
  41. package/lib/cjs/encoder/field/index.d.ts +9 -0
  42. package/lib/cjs/encoder/field/index.js +1 -0
  43. package/lib/cjs/encoder/index.d.ts +7 -0
  44. package/lib/cjs/encoder/index.js +1 -0
  45. package/lib/cjs/encoder/sequence/FieldSequence.d.ts +5 -0
  46. package/lib/cjs/encoder/sequence/FieldSequence.js +1 -0
  47. package/lib/cjs/encoder/sequence/SegmentSequence.d.ts +9 -0
  48. package/lib/cjs/encoder/sequence/SegmentSequence.js +1 -0
  49. package/lib/cjs/encoder/sequence/SequenceVersionMap.d.ts +7 -0
  50. package/lib/cjs/encoder/sequence/SequenceVersionMap.js +1 -0
  51. package/lib/cjs/encoder/sequence/index.d.ts +3 -0
  52. package/lib/cjs/encoder/sequence/index.js +1 -0
  53. package/lib/cjs/errors/DecodingError.d.ts +15 -0
  54. package/lib/cjs/errors/DecodingError.js +1 -0
  55. package/lib/cjs/errors/EncodingError.d.ts +15 -0
  56. package/lib/cjs/errors/EncodingError.js +1 -0
  57. package/lib/cjs/errors/GVLError.d.ts +15 -0
  58. package/lib/cjs/errors/GVLError.js +1 -0
  59. package/lib/cjs/errors/TCModelError.d.ts +16 -0
  60. package/lib/cjs/errors/TCModelError.js +1 -0
  61. package/lib/cjs/errors/index.d.ts +4 -0
  62. package/lib/cjs/errors/index.js +1 -0
  63. package/lib/cjs/index.d.ts +8 -0
  64. package/lib/cjs/index.js +1 -0
  65. package/lib/cjs/model/BinarySearchTree.d.ts +30 -0
  66. package/lib/cjs/model/BinarySearchTree.js +1 -0
  67. package/lib/cjs/model/ConsentLanguages.d.ts +6 -0
  68. package/lib/cjs/model/ConsentLanguages.js +1 -0
  69. package/lib/cjs/model/DeviceDisclosure.d.ts +9 -0
  70. package/lib/cjs/model/DeviceDisclosure.js +1 -0
  71. package/lib/cjs/model/DeviceDisclosureStorageAccessType.d.ts +5 -0
  72. package/lib/cjs/model/DeviceDisclosureStorageAccessType.js +1 -0
  73. package/lib/cjs/model/Fields.d.ts +29 -0
  74. package/lib/cjs/model/Fields.js +1 -0
  75. package/lib/cjs/model/IntMap.d.ts +13 -0
  76. package/lib/cjs/model/IntMap.js +1 -0
  77. package/lib/cjs/model/KeyMap.d.ts +12 -0
  78. package/lib/cjs/model/KeyMap.js +1 -0
  79. package/lib/cjs/model/PurposeRestriction.d.ts +33 -0
  80. package/lib/cjs/model/PurposeRestriction.js +1 -0
  81. package/lib/cjs/model/PurposeRestrictionVector.d.ts +100 -0
  82. package/lib/cjs/model/PurposeRestrictionVector.js +1 -0
  83. package/lib/cjs/model/RestrictionType.d.ts +19 -0
  84. package/lib/cjs/model/RestrictionType.js +1 -0
  85. package/lib/cjs/model/Segment.d.ts +6 -0
  86. package/lib/cjs/model/Segment.js +1 -0
  87. package/lib/cjs/model/SegmentIDs.d.ts +12 -0
  88. package/lib/cjs/model/SegmentIDs.js +1 -0
  89. package/lib/cjs/model/Vector.d.ts +72 -0
  90. package/lib/cjs/model/Vector.js +1 -0
  91. package/lib/cjs/model/gvl/ByPurposeVendorMap.d.ts +7 -0
  92. package/lib/cjs/model/gvl/ByPurposeVendorMap.js +1 -0
  93. package/lib/cjs/model/gvl/DataCategory.d.ts +4 -0
  94. package/lib/cjs/model/gvl/DataCategory.js +1 -0
  95. package/lib/cjs/model/gvl/DataRetention.d.ts +6 -0
  96. package/lib/cjs/model/gvl/DataRetention.js +1 -0
  97. package/lib/cjs/model/gvl/Declarations.d.ts +13 -0
  98. package/lib/cjs/model/gvl/Declarations.js +1 -0
  99. package/lib/cjs/model/gvl/Feature.d.ts +5 -0
  100. package/lib/cjs/model/gvl/Feature.js +1 -0
  101. package/lib/cjs/model/gvl/GVLMapItem.d.ts +4 -0
  102. package/lib/cjs/model/gvl/GVLMapItem.js +1 -0
  103. package/lib/cjs/model/gvl/IDSetMap.d.ts +2 -0
  104. package/lib/cjs/model/gvl/IDSetMap.js +1 -0
  105. package/lib/cjs/model/gvl/Purpose.d.ts +5 -0
  106. package/lib/cjs/model/gvl/Purpose.js +1 -0
  107. package/lib/cjs/model/gvl/Stack.d.ts +6 -0
  108. package/lib/cjs/model/gvl/Stack.js +1 -0
  109. package/lib/cjs/model/gvl/Vendor.d.ts +24 -0
  110. package/lib/cjs/model/gvl/Vendor.js +1 -0
  111. package/lib/cjs/model/gvl/VendorList.d.ts +10 -0
  112. package/lib/cjs/model/gvl/VendorList.js +1 -0
  113. package/lib/cjs/model/gvl/VendorUrl.d.ts +5 -0
  114. package/lib/cjs/model/gvl/VendorUrl.js +1 -0
  115. package/lib/cjs/model/gvl/index.d.ts +10 -0
  116. package/lib/cjs/model/gvl/index.js +1 -0
  117. package/lib/cjs/model/index.d.ts +14 -0
  118. package/lib/cjs/model/index.js +1 -0
  119. package/lib/cjs/package.json +3 -0
  120. package/lib/mjs/Cloneable.d.ts +27 -0
  121. package/lib/mjs/Cloneable.js +76 -0
  122. package/lib/mjs/GVL.d.ts +295 -0
  123. package/lib/mjs/GVL.js +591 -0
  124. package/lib/mjs/Json.d.ts +20 -0
  125. package/lib/mjs/Json.js +74 -0
  126. package/lib/mjs/TCModel.d.ts +337 -0
  127. package/lib/mjs/TCModel.js +512 -0
  128. package/lib/mjs/TCString.d.ts +27 -0
  129. package/lib/mjs/TCString.js +71 -0
  130. package/lib/mjs/encoder/Base64Url.d.ts +29 -0
  131. package/lib/mjs/encoder/Base64Url.js +80 -0
  132. package/lib/mjs/encoder/BitLength.d.ts +32 -0
  133. package/lib/mjs/encoder/BitLength.js +32 -0
  134. package/lib/mjs/encoder/EncodingOptions.d.ts +6 -0
  135. package/lib/mjs/encoder/EncodingOptions.js +1 -0
  136. package/lib/mjs/encoder/SegmentEncoder.d.ts +8 -0
  137. package/lib/mjs/encoder/SegmentEncoder.js +106 -0
  138. package/lib/mjs/encoder/SemanticPreEncoder.d.ts +6 -0
  139. package/lib/mjs/encoder/SemanticPreEncoder.js +133 -0
  140. package/lib/mjs/encoder/field/BooleanEncoder.d.ts +4 -0
  141. package/lib/mjs/encoder/field/BooleanEncoder.js +9 -0
  142. package/lib/mjs/encoder/field/DateEncoder.d.ts +4 -0
  143. package/lib/mjs/encoder/field/DateEncoder.js +15 -0
  144. package/lib/mjs/encoder/field/FieldEncoderMap.d.ts +1 -0
  145. package/lib/mjs/encoder/field/FieldEncoderMap.js +39 -0
  146. package/lib/mjs/encoder/field/FixedVectorEncoder.d.ts +5 -0
  147. package/lib/mjs/encoder/field/FixedVectorEncoder.js +25 -0
  148. package/lib/mjs/encoder/field/IntEncoder.d.ts +4 -0
  149. package/lib/mjs/encoder/field/IntEncoder.js +25 -0
  150. package/lib/mjs/encoder/field/LangEncoder.d.ts +4 -0
  151. package/lib/mjs/encoder/field/LangEncoder.js +36 -0
  152. package/lib/mjs/encoder/field/PurposeRestrictionVectorEncoder.d.ts +5 -0
  153. package/lib/mjs/encoder/field/PurposeRestrictionVectorEncoder.js +109 -0
  154. package/lib/mjs/encoder/field/VectorEncodingType.d.ts +4 -0
  155. package/lib/mjs/encoder/field/VectorEncodingType.js +5 -0
  156. package/lib/mjs/encoder/field/VendorVectorEncoder.d.ts +6 -0
  157. package/lib/mjs/encoder/field/VendorVectorEncoder.js +156 -0
  158. package/lib/mjs/encoder/field/index.d.ts +9 -0
  159. package/lib/mjs/encoder/field/index.js +9 -0
  160. package/lib/mjs/encoder/index.d.ts +7 -0
  161. package/lib/mjs/encoder/index.js +7 -0
  162. package/lib/mjs/encoder/sequence/FieldSequence.d.ts +5 -0
  163. package/lib/mjs/encoder/sequence/FieldSequence.js +53 -0
  164. package/lib/mjs/encoder/sequence/SegmentSequence.d.ts +9 -0
  165. package/lib/mjs/encoder/sequence/SegmentSequence.js +52 -0
  166. package/lib/mjs/encoder/sequence/SequenceVersionMap.d.ts +7 -0
  167. package/lib/mjs/encoder/sequence/SequenceVersionMap.js +1 -0
  168. package/lib/mjs/encoder/sequence/index.d.ts +3 -0
  169. package/lib/mjs/encoder/sequence/index.js +4 -0
  170. package/lib/mjs/errors/DecodingError.d.ts +15 -0
  171. package/lib/mjs/errors/DecodingError.js +18 -0
  172. package/lib/mjs/errors/EncodingError.d.ts +15 -0
  173. package/lib/mjs/errors/EncodingError.js +18 -0
  174. package/lib/mjs/errors/GVLError.d.ts +15 -0
  175. package/lib/mjs/errors/GVLError.js +18 -0
  176. package/lib/mjs/errors/TCModelError.d.ts +16 -0
  177. package/lib/mjs/errors/TCModelError.js +19 -0
  178. package/lib/mjs/errors/index.d.ts +4 -0
  179. package/lib/mjs/errors/index.js +4 -0
  180. package/lib/mjs/index.d.ts +8 -0
  181. package/lib/mjs/index.js +9 -0
  182. package/lib/mjs/model/BinarySearchTree.d.ts +30 -0
  183. package/lib/mjs/model/BinarySearchTree.js +267 -0
  184. package/lib/mjs/model/ConsentLanguages.d.ts +6 -0
  185. package/lib/mjs/model/ConsentLanguages.js +42 -0
  186. package/lib/mjs/model/DeviceDisclosure.d.ts +9 -0
  187. package/lib/mjs/model/DeviceDisclosure.js +1 -0
  188. package/lib/mjs/model/DeviceDisclosureStorageAccessType.d.ts +5 -0
  189. package/lib/mjs/model/DeviceDisclosureStorageAccessType.js +6 -0
  190. package/lib/mjs/model/Fields.d.ts +29 -0
  191. package/lib/mjs/model/Fields.js +29 -0
  192. package/lib/mjs/model/IntMap.d.ts +13 -0
  193. package/lib/mjs/model/IntMap.js +1 -0
  194. package/lib/mjs/model/KeyMap.d.ts +12 -0
  195. package/lib/mjs/model/KeyMap.js +1 -0
  196. package/lib/mjs/model/PurposeRestriction.d.ts +33 -0
  197. package/lib/mjs/model/PurposeRestriction.js +69 -0
  198. package/lib/mjs/model/PurposeRestrictionVector.d.ts +100 -0
  199. package/lib/mjs/model/PurposeRestrictionVector.js +286 -0
  200. package/lib/mjs/model/RestrictionType.d.ts +19 -0
  201. package/lib/mjs/model/RestrictionType.js +20 -0
  202. package/lib/mjs/model/Segment.d.ts +6 -0
  203. package/lib/mjs/model/Segment.js +7 -0
  204. package/lib/mjs/model/SegmentIDs.d.ts +12 -0
  205. package/lib/mjs/model/SegmentIDs.js +21 -0
  206. package/lib/mjs/model/Vector.d.ts +72 -0
  207. package/lib/mjs/model/Vector.js +161 -0
  208. package/lib/mjs/model/gvl/ByPurposeVendorMap.d.ts +7 -0
  209. package/lib/mjs/model/gvl/ByPurposeVendorMap.js +1 -0
  210. package/lib/mjs/model/gvl/DataCategory.d.ts +4 -0
  211. package/lib/mjs/model/gvl/DataCategory.js +1 -0
  212. package/lib/mjs/model/gvl/DataRetention.d.ts +6 -0
  213. package/lib/mjs/model/gvl/DataRetention.js +1 -0
  214. package/lib/mjs/model/gvl/Declarations.d.ts +13 -0
  215. package/lib/mjs/model/gvl/Declarations.js +1 -0
  216. package/lib/mjs/model/gvl/Feature.d.ts +5 -0
  217. package/lib/mjs/model/gvl/Feature.js +2 -0
  218. package/lib/mjs/model/gvl/GVLMapItem.d.ts +4 -0
  219. package/lib/mjs/model/gvl/GVLMapItem.js +1 -0
  220. package/lib/mjs/model/gvl/IDSetMap.d.ts +2 -0
  221. package/lib/mjs/model/gvl/IDSetMap.js +1 -0
  222. package/lib/mjs/model/gvl/Purpose.d.ts +5 -0
  223. package/lib/mjs/model/gvl/Purpose.js +1 -0
  224. package/lib/mjs/model/gvl/Stack.d.ts +6 -0
  225. package/lib/mjs/model/gvl/Stack.js +1 -0
  226. package/lib/mjs/model/gvl/Vendor.d.ts +24 -0
  227. package/lib/mjs/model/gvl/Vendor.js +1 -0
  228. package/lib/mjs/model/gvl/VendorList.d.ts +10 -0
  229. package/lib/mjs/model/gvl/VendorList.js +1 -0
  230. package/lib/mjs/model/gvl/VendorUrl.d.ts +5 -0
  231. package/lib/mjs/model/gvl/VendorUrl.js +1 -0
  232. package/lib/mjs/model/gvl/index.d.ts +10 -0
  233. package/lib/mjs/model/gvl/index.js +11 -0
  234. package/lib/mjs/model/index.d.ts +14 -0
  235. package/lib/mjs/model/index.js +14 -0
  236. package/lib/mjs/package.json +3 -0
  237. package/package.json +95 -0
@@ -0,0 +1,30 @@
1
+ import { Cloneable } from '../Cloneable.js';
2
+ interface TreeNode {
3
+ value: number;
4
+ right: TreeNode | null;
5
+ left: TreeNode | null;
6
+ }
7
+ declare type TreeNodeMaybe = TreeNode | null;
8
+ export declare class BinarySearchTree extends Cloneable<BinarySearchTree> {
9
+ private root;
10
+ getRoot(): TreeNodeMaybe;
11
+ isEmpty(): boolean;
12
+ add(value: number): void;
13
+ /**
14
+ * performs Morris in-order traversal
15
+ * @return {number[]} sorted array
16
+ */
17
+ get(): number[];
18
+ contains(value: number): boolean;
19
+ min(current?: TreeNodeMaybe): number;
20
+ max(current?: TreeNodeMaybe): number;
21
+ remove(value: number, current?: TreeNodeMaybe): void;
22
+ /**
23
+ * Build Binary Search Tree from the ordered number array.
24
+ * The depth of the tree will be the `log2` of the array length.
25
+ * @param {number[]} values number array in ascending order
26
+ * @return {BinarySearchTree} Binary Search Tree
27
+ */
28
+ static build(values?: number[]): BinarySearchTree | null;
29
+ }
30
+ export {};
@@ -0,0 +1,267 @@
1
+ import { Cloneable } from '../Cloneable.js';
2
+ export class BinarySearchTree extends Cloneable {
3
+ root = null;
4
+ getRoot() {
5
+ return this.root;
6
+ }
7
+ isEmpty() {
8
+ // if root is undefined or null then by definition this is empty
9
+ return !(this.root);
10
+ }
11
+ add(value) {
12
+ // create new node object
13
+ const node = {
14
+ value: value,
15
+ left: null,
16
+ right: null,
17
+ };
18
+ let current;
19
+ // first item?
20
+ if (this.isEmpty()) {
21
+ this.root = node;
22
+ }
23
+ else {
24
+ // start at the root
25
+ current = this.root;
26
+ // infinite loop, figure out where to put it
27
+ while (true) {
28
+ // if the value is less than current value; go left
29
+ if (value < current.value) {
30
+ // if it's empty, we can insert
31
+ if (current.left === null) {
32
+ // insert on the left
33
+ current.left = node;
34
+ // our work is done here
35
+ break;
36
+ }
37
+ else {
38
+ /**
39
+ * if there's something there already, we'll reset the pointer and
40
+ * wait for the next loop to do something ie. keep traversing
41
+ */
42
+ current = current.left;
43
+ }
44
+ }
45
+ else if (value > current.value) {
46
+ // if the value is greater than our current value; go right
47
+ if (current.right === null) {
48
+ // there's nothing to the right, so put it here
49
+ current.right = node;
50
+ break;
51
+ }
52
+ else {
53
+ /**
54
+ * if there's something there already, we'll reset the pointer and
55
+ * wait for the next loop to do something ie. keep traversing
56
+ */
57
+ current = current.right;
58
+ }
59
+ }
60
+ else {
61
+ /**
62
+ * If it's neither greater than the right or less than the right then
63
+ * it is equal to the current nodes value. In that case we won't do
64
+ * anything with it because we will only insert unique values.
65
+ */
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ /**
72
+ * performs Morris in-order traversal
73
+ * @return {number[]} sorted array
74
+ */
75
+ get() {
76
+ const retr = [];
77
+ let current = this.root;
78
+ while (current) {
79
+ if (!current.left) {
80
+ retr.push(current.value); // if there is no left child, visit current node
81
+ current = current.right; // then we go the right branch
82
+ }
83
+ else {
84
+ // find the right most leaf of root.left node.
85
+ let pre = current.left;
86
+ // when pre.right == null, it means we go to the right most leaf
87
+ // when pre.right == current, it means the right most leaf has been visited in the last round
88
+ while (pre.right && pre.right != current) {
89
+ pre = pre.right;
90
+ }
91
+ // this means the pre.right has been set, it's time to go to current node
92
+ if (pre.right == current) {
93
+ pre.right = null;
94
+ // means the current node is pointed by left right most child
95
+ // the left branch has been visited, it's time to push the current node
96
+ retr.push(current.value);
97
+ current = current.right;
98
+ }
99
+ else {
100
+ // the fist time to visit the pre node, make its right child point to current node
101
+ pre.right = current;
102
+ current = current.left;
103
+ }
104
+ }
105
+ }
106
+ return retr;
107
+ }
108
+ contains(value) {
109
+ let retr = false;
110
+ let current = this.root;
111
+ while (current) {
112
+ if (current.value === value) {
113
+ retr = true;
114
+ break;
115
+ }
116
+ else if (value > current.value) {
117
+ current = current.right;
118
+ }
119
+ else if (value < current.value) {
120
+ current = current.left;
121
+ }
122
+ }
123
+ return retr;
124
+ }
125
+ min(current = this.root) {
126
+ let retr;
127
+ while (current) {
128
+ if (current.left) {
129
+ current = current.left;
130
+ }
131
+ else {
132
+ retr = current.value;
133
+ current = null;
134
+ }
135
+ }
136
+ return retr;
137
+ }
138
+ max(current = this.root) {
139
+ let retr;
140
+ while (current) {
141
+ if (current.right) {
142
+ current = current.right;
143
+ }
144
+ else {
145
+ retr = current.value;
146
+ current = null;
147
+ }
148
+ }
149
+ return retr;
150
+ }
151
+ remove(value, current = this.root) {
152
+ // we start at the root, so the parent is null
153
+ let parent = null;
154
+ let parentSide = 'left';
155
+ while (current) {
156
+ if (value < current.value) {
157
+ // set our parent to the current value
158
+ parent = current;
159
+ // value is less than current value, so go left
160
+ current = current.left;
161
+ parentSide = 'left';
162
+ }
163
+ else if (value > current.value) {
164
+ // set our parent to the current value
165
+ parent = current;
166
+ // value is greater than current value, so go right
167
+ current = current.right;
168
+ parentSide = 'right';
169
+ }
170
+ else {
171
+ /**
172
+ * if it's neither greater than or less than, then it's equal so BINGO!
173
+ * we've found it
174
+ *
175
+ * If we have children, we've got to figure out what to do with
176
+ * them once we are no longer around... Woah, code is like real
177
+ * life...
178
+ *
179
+ * There are three cases we care about when it comes to this removal
180
+ * process:
181
+ *
182
+ * 1. No children -- If not children we just delete an do nothing
183
+ * else, no harm no foul.
184
+ *
185
+ * 2. One child -- Just link the parent's link to current to the
186
+ * child.
187
+ *
188
+ * 3. Two children -- Find the minimum value from the right subtree
189
+ * replace us with the minimum value and of course remove that
190
+ * minimum value from the right stubtree
191
+ */
192
+ if (!current.left && !current.right) {
193
+ // case 1 there are no children easy peasy lemon squeezy
194
+ if (parent) {
195
+ parent[parentSide] = null;
196
+ }
197
+ else {
198
+ this.root = null;
199
+ }
200
+ }
201
+ else if (!current.left) {
202
+ // no left side only right, so link right
203
+ if (parent) {
204
+ parent[parentSide] = current.right;
205
+ }
206
+ else {
207
+ this.root = current.right;
208
+ }
209
+ }
210
+ else if (!current.right) {
211
+ // no right side only left, so link left
212
+ if (parent) {
213
+ parent[parentSide] = current.left;
214
+ }
215
+ else {
216
+ this.root = current.left;
217
+ }
218
+ }
219
+ else {
220
+ /**
221
+ * case 3 just like real life, if you delete a parent the more kids
222
+ * that parent has the more complicated things get... in this case we
223
+ * have two children. We're gonna have to figure out who goes where.
224
+ */
225
+ const minVal = this.min(current.right);
226
+ // little bit of recursion...
227
+ this.remove(minVal, current.right);
228
+ current.value = minVal;
229
+ }
230
+ current = null;
231
+ }
232
+ }
233
+ }
234
+ /**
235
+ * Build Binary Search Tree from the ordered number array.
236
+ * The depth of the tree will be the `log2` of the array length.
237
+ * @param {number[]} values number array in ascending order
238
+ * @return {BinarySearchTree} Binary Search Tree
239
+ */
240
+ static build(values) {
241
+ if (!values || values.length === 0) {
242
+ return null;
243
+ }
244
+ else if (values.length === 1) {
245
+ const tree = new BinarySearchTree();
246
+ tree.add(values[0]);
247
+ return tree;
248
+ }
249
+ else {
250
+ const rootIndex = values.length >> 1;
251
+ const tree = new BinarySearchTree();
252
+ tree.add(values[rootIndex]);
253
+ const root = tree.getRoot();
254
+ if (root) {
255
+ if (rootIndex + 1 < values.length) {
256
+ const rightTree = BinarySearchTree.build(values.slice(rootIndex + 1));
257
+ root.right = rightTree ? rightTree.getRoot() : null;
258
+ }
259
+ if (rootIndex - 1 > 0) {
260
+ const leftTree = BinarySearchTree.build(values.slice(0, rootIndex - 1));
261
+ root.left = leftTree ? leftTree.getRoot() : null;
262
+ }
263
+ }
264
+ return tree;
265
+ }
266
+ }
267
+ }
@@ -0,0 +1,6 @@
1
+ export declare class ConsentLanguages {
2
+ private static readonly langSet;
3
+ has(key: string): boolean;
4
+ forEach(callback: (key: string) => void): void;
5
+ get size(): number;
6
+ }
@@ -0,0 +1,42 @@
1
+ export class ConsentLanguages {
2
+ static langSet = new Set([
3
+ 'BG',
4
+ 'CA',
5
+ 'CS',
6
+ 'DA',
7
+ 'DE',
8
+ 'EL',
9
+ 'EN',
10
+ 'ES',
11
+ 'ET',
12
+ 'FI',
13
+ 'FR',
14
+ 'HR',
15
+ 'HU',
16
+ 'IT',
17
+ 'JA',
18
+ 'LT',
19
+ 'LV',
20
+ 'MT',
21
+ 'NL',
22
+ 'NO',
23
+ 'PL',
24
+ 'PT',
25
+ 'RO',
26
+ 'RU',
27
+ 'SK',
28
+ 'SL',
29
+ 'SV',
30
+ 'TR',
31
+ 'ZH',
32
+ ]);
33
+ has(key) {
34
+ return ConsentLanguages.langSet.has(key);
35
+ }
36
+ forEach(callback) {
37
+ ConsentLanguages.langSet.forEach(callback);
38
+ }
39
+ get size() {
40
+ return ConsentLanguages.langSet.size;
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ import { DeviceDisclosureStorageAccessType } from './DeviceDisclosureStorageAccessType.js';
2
+ export interface DeviceDisclosure {
3
+ domain?: string;
4
+ cookieRefresh?: boolean;
5
+ identifier: string;
6
+ maxAgeSeconds: number | null;
7
+ purposes: number[];
8
+ type: DeviceDisclosureStorageAccessType;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare enum DeviceDisclosureStorageAccessType {
2
+ COOKIE = "cookie",
3
+ WEB = "web",
4
+ APP = "app"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var DeviceDisclosureStorageAccessType;
2
+ (function (DeviceDisclosureStorageAccessType) {
3
+ DeviceDisclosureStorageAccessType["COOKIE"] = "cookie";
4
+ DeviceDisclosureStorageAccessType["WEB"] = "web";
5
+ DeviceDisclosureStorageAccessType["APP"] = "app";
6
+ })(DeviceDisclosureStorageAccessType || (DeviceDisclosureStorageAccessType = {}));
@@ -0,0 +1,29 @@
1
+ export declare class Fields {
2
+ static readonly cmpId: 'cmpId';
3
+ static readonly cmpVersion: 'cmpVersion';
4
+ static readonly consentLanguage: 'consentLanguage';
5
+ static readonly consentScreen: 'consentScreen';
6
+ static readonly created: 'created';
7
+ static readonly supportOOB: 'supportOOB';
8
+ static readonly isServiceSpecific: 'isServiceSpecific';
9
+ static readonly lastUpdated: 'lastUpdated';
10
+ static readonly numCustomPurposes: 'numCustomPurposes';
11
+ static readonly policyVersion: 'policyVersion';
12
+ static readonly publisherCountryCode: 'publisherCountryCode';
13
+ static readonly publisherCustomConsents: 'publisherCustomConsents';
14
+ static readonly publisherCustomLegitimateInterests: 'publisherCustomLegitimateInterests';
15
+ static readonly publisherLegitimateInterests: 'publisherLegitimateInterests';
16
+ static readonly publisherConsents: 'publisherConsents';
17
+ static readonly publisherRestrictions: 'publisherRestrictions';
18
+ static readonly purposeConsents: 'purposeConsents';
19
+ static readonly purposeLegitimateInterests: 'purposeLegitimateInterests';
20
+ static readonly purposeOneTreatment: 'purposeOneTreatment';
21
+ static readonly specialFeatureOptins: 'specialFeatureOptins';
22
+ static readonly useNonStandardStacks: 'useNonStandardStacks';
23
+ static readonly vendorConsents: 'vendorConsents';
24
+ static readonly vendorLegitimateInterests: 'vendorLegitimateInterests';
25
+ static readonly vendorListVersion: 'vendorListVersion';
26
+ static readonly vendorsAllowed: 'vendorsAllowed';
27
+ static readonly vendorsDisclosed: 'vendorsDisclosed';
28
+ static readonly version: 'version';
29
+ }
@@ -0,0 +1,29 @@
1
+ export class Fields {
2
+ static cmpId = 'cmpId';
3
+ static cmpVersion = 'cmpVersion';
4
+ static consentLanguage = 'consentLanguage';
5
+ static consentScreen = 'consentScreen';
6
+ static created = 'created';
7
+ static supportOOB = 'supportOOB';
8
+ static isServiceSpecific = 'isServiceSpecific';
9
+ static lastUpdated = 'lastUpdated';
10
+ static numCustomPurposes = 'numCustomPurposes';
11
+ static policyVersion = 'policyVersion';
12
+ static publisherCountryCode = 'publisherCountryCode';
13
+ static publisherCustomConsents = 'publisherCustomConsents';
14
+ static publisherCustomLegitimateInterests = 'publisherCustomLegitimateInterests';
15
+ static publisherLegitimateInterests = 'publisherLegitimateInterests';
16
+ static publisherConsents = 'publisherConsents';
17
+ static publisherRestrictions = 'publisherRestrictions';
18
+ static purposeConsents = 'purposeConsents';
19
+ static purposeLegitimateInterests = 'purposeLegitimateInterests';
20
+ static purposeOneTreatment = 'purposeOneTreatment';
21
+ static specialFeatureOptins = 'specialFeatureOptins';
22
+ static useNonStandardStacks = 'useNonStandardStacks';
23
+ static vendorConsents = 'vendorConsents';
24
+ static vendorLegitimateInterests = 'vendorLegitimateInterests';
25
+ static vendorListVersion = 'vendorListVersion';
26
+ static vendorsAllowed = 'vendorsAllowed';
27
+ static vendorsDisclosed = 'vendorsDisclosed';
28
+ static version = 'version';
29
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * IntMap - A map of abstract type (defined by implementer) that is keyed by an
3
+ * integer string id. Example `IntMap<number>`:
4
+ * ```
5
+ * const myIntMapOfNumbers: IntMap<number> = {
6
+ * "1":2,
7
+ * "3":4,
8
+ * };
9
+ * ```
10
+ */
11
+ export interface IntMap<T> {
12
+ [id: string]: T;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * KeyMap - A map of abstract type (defined by implementer) that is keyed by an
3
+ * integer string id. Example `KeyMap<number>`:
4
+ * ```
5
+ * const myKeyMapOfNumbers: KeyMap<number> = {
6
+ * "1":2,
7
+ * "3":4,
8
+ * };
9
+ * ```
10
+ */
11
+ import { IntMap } from './IntMap.js';
12
+ export declare type KeyMap<T> = IntMap<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { Cloneable } from '../Cloneable.js';
2
+ import { RestrictionType } from './RestrictionType.js';
3
+ export declare class PurposeRestriction extends Cloneable<PurposeRestriction> {
4
+ static hashSeparator: string;
5
+ private purposeId_;
6
+ restrictionType: RestrictionType;
7
+ /**
8
+ * constructor
9
+ *
10
+ * @param {number} purposeId? - may optionally pass the purposeId into the
11
+ * constructor
12
+ * @param {RestrictionType} restrictionType? - may
13
+ * optionally pass the restrictionType into the constructor
14
+ * @return {undefined}
15
+ */
16
+ constructor(purposeId?: number, restrictionType?: RestrictionType);
17
+ static unHash(hash: string): PurposeRestriction;
18
+ get hash(): string;
19
+ /**
20
+ * @return {number} The purpose Id associated with a publisher
21
+ * purpose-by-vendor restriction that resulted in a different consent or LI
22
+ * status than the consent or LI purposes allowed lists.
23
+ */
24
+ get purposeId(): number;
25
+ /**
26
+ * @param {number} idNum - The purpose Id associated with a publisher
27
+ * purpose-by-vendor restriction that resulted in a different consent or LI
28
+ * status than the consent or LI purposes allowed lists.
29
+ */
30
+ set purposeId(idNum: number);
31
+ isValid(): boolean;
32
+ isSameAs(otherPR: PurposeRestriction): boolean;
33
+ }
@@ -0,0 +1,69 @@
1
+ import { Cloneable } from '../Cloneable.js';
2
+ import { TCModelError } from '../errors/index.js';
3
+ import { RestrictionType } from './RestrictionType.js';
4
+ export class PurposeRestriction extends Cloneable {
5
+ static hashSeparator = '-';
6
+ purposeId_;
7
+ restrictionType;
8
+ /**
9
+ * constructor
10
+ *
11
+ * @param {number} purposeId? - may optionally pass the purposeId into the
12
+ * constructor
13
+ * @param {RestrictionType} restrictionType? - may
14
+ * optionally pass the restrictionType into the constructor
15
+ * @return {undefined}
16
+ */
17
+ constructor(purposeId, restrictionType) {
18
+ super();
19
+ if (purposeId !== undefined) {
20
+ this.purposeId = purposeId;
21
+ }
22
+ if (restrictionType !== undefined) {
23
+ this.restrictionType = restrictionType;
24
+ }
25
+ }
26
+ static unHash(hash) {
27
+ const splitUp = hash.split(this.hashSeparator);
28
+ const purpRestriction = new PurposeRestriction();
29
+ if (splitUp.length !== 2) {
30
+ throw new TCModelError('hash', hash);
31
+ }
32
+ purpRestriction.purposeId = parseInt(splitUp[0], 10);
33
+ purpRestriction.restrictionType = parseInt(splitUp[1], 10);
34
+ return purpRestriction;
35
+ }
36
+ get hash() {
37
+ if (!this.isValid()) {
38
+ throw new Error('cannot hash invalid PurposeRestriction');
39
+ }
40
+ return `${this.purposeId}${PurposeRestriction.hashSeparator}${this.restrictionType}`;
41
+ }
42
+ /**
43
+ * @return {number} The purpose Id associated with a publisher
44
+ * purpose-by-vendor restriction that resulted in a different consent or LI
45
+ * status than the consent or LI purposes allowed lists.
46
+ */
47
+ get purposeId() {
48
+ return this.purposeId_;
49
+ }
50
+ /**
51
+ * @param {number} idNum - The purpose Id associated with a publisher
52
+ * purpose-by-vendor restriction that resulted in a different consent or LI
53
+ * status than the consent or LI purposes allowed lists.
54
+ */
55
+ set purposeId(idNum) {
56
+ this.purposeId_ = idNum;
57
+ }
58
+ isValid() {
59
+ return (Number.isInteger(this.purposeId) &&
60
+ this.purposeId > 0 &&
61
+ (this.restrictionType === RestrictionType.NOT_ALLOWED ||
62
+ this.restrictionType === RestrictionType.REQUIRE_CONSENT ||
63
+ this.restrictionType === RestrictionType.REQUIRE_LI));
64
+ }
65
+ isSameAs(otherPR) {
66
+ return (this.purposeId === otherPR.purposeId &&
67
+ this.restrictionType === otherPR.restrictionType);
68
+ }
69
+ }
@@ -0,0 +1,100 @@
1
+ import { PurposeRestriction } from './PurposeRestriction.js';
2
+ import { RestrictionType } from './RestrictionType.js';
3
+ import { GVL } from '../GVL.js';
4
+ import { Cloneable } from '../Cloneable.js';
5
+ export declare class PurposeRestrictionVector extends Cloneable<PurposeRestrictionVector> {
6
+ /**
7
+ * if this originatd from an encoded string we'll need a place to store the
8
+ * bit length; it can be set and got from here
9
+ */
10
+ bitLength: number;
11
+ /**
12
+ * a map indexed by a string which will be a 'hash' of the purpose and
13
+ * restriction type.
14
+ *
15
+ * Using a BST to keep vendors in a sorted order for encoding later
16
+ */
17
+ private map;
18
+ private gvl_;
19
+ private has;
20
+ private isOkToHave;
21
+ /**
22
+ * add - adds a given Vendor ID under a given Purpose Restriction
23
+ *
24
+ * @param {number} vendorId
25
+ * @param {PurposeRestriction} purposeRestriction
26
+ * @return {void}
27
+ */
28
+ add(vendorId: number, purposeRestriction: PurposeRestriction): void;
29
+ /**
30
+ * restrictPurposeToLegalBasis - adds all Vendors under a given Purpose Restriction
31
+ *
32
+ * @param {PurposeRestriction} purposeRestriction
33
+ * @return {void}
34
+ */
35
+ restrictPurposeToLegalBasis(purposeRestriction: PurposeRestriction): void;
36
+ /**
37
+ * getVendors - returns array of vendor ids optionally narrowed by a given
38
+ * Purpose Restriction. If no purpose restriction is passed then all vendor
39
+ * ids will be returned. One can expect this result to be a unique set of
40
+ * ids no duplicates.
41
+ *
42
+ * @param {PurposeRestriction} [purposeRestriction] - optionally passed to
43
+ * get only Vendor IDs restricted under the given Purpose Restriction
44
+ * @return {number[]} - Unique ID set of vendors
45
+ */
46
+ getVendors(purposeRestriction?: PurposeRestriction): number[];
47
+ getRestrictionType(vendorId: number, purposeId: number): RestrictionType | undefined;
48
+ /**
49
+ * vendorHasRestriction - determines whether a given Vendor ID is under a
50
+ * given Purpose Restriction
51
+ *
52
+ * @param {number} vendorId
53
+ * @param {PurposeRestriction} purposeRestriction
54
+ * @return {boolean} - true if the give Vendor ID is under the given Purpose
55
+ * Restriction
56
+ */
57
+ vendorHasRestriction(vendorId: number, purposeRestriction: PurposeRestriction): boolean;
58
+ /**
59
+ * getMaxVendorId - gets the Maximum Vendor ID regardless of Purpose
60
+ * Restriction
61
+ *
62
+ * @return {number} - maximum Vendor ID
63
+ */
64
+ getMaxVendorId(): number;
65
+ getRestrictions(vendorId?: number): PurposeRestriction[];
66
+ getPurposes(): number[];
67
+ /**
68
+ * remove - removes Vendor ID from a Purpose Restriction
69
+ *
70
+ * @param {number} vendorId
71
+ * @param {PurposeRestriction} purposeRestriction
72
+ * @return {void}
73
+ */
74
+ remove(vendorId: number, purposeRestriction: PurposeRestriction): void;
75
+ /**
76
+ * Essential for being able to determine whether we can actually set a
77
+ * purpose restriction since they have to have a flexible legal basis
78
+ *
79
+ * @param {GVL} value - the GVL instance
80
+ */
81
+ set gvl(value: GVL);
82
+ /**
83
+ * gvl returns local copy of the GVL these restrictions apply to
84
+ *
85
+ * @return {GVL}
86
+ */
87
+ get gvl(): GVL;
88
+ /**
89
+ * isEmpty - whether or not this vector has any restrictions in it
90
+ *
91
+ * @return {boolean}
92
+ */
93
+ isEmpty(): boolean;
94
+ /**
95
+ * numRestrictions - returns the number of Purpose Restrictions.
96
+ *
97
+ * @return {number}
98
+ */
99
+ get numRestrictions(): number;
100
+ }