@osano/osano-cmp-react-native 0.9.0 → 0.11.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 (317) hide show
  1. package/lib/commonjs/components/Button.js +27 -12
  2. package/lib/commonjs/components/Button.js.map +1 -1
  3. package/lib/commonjs/locale/af.json +324 -321
  4. package/lib/commonjs/locale/ar.json +324 -321
  5. package/lib/commonjs/locale/bg.json +324 -321
  6. package/lib/commonjs/locale/ca.json +324 -321
  7. package/lib/commonjs/locale/cs.json +324 -321
  8. package/lib/commonjs/locale/da.json +324 -321
  9. package/lib/commonjs/locale/de-at.json +324 -321
  10. package/lib/commonjs/locale/de.json +324 -321
  11. package/lib/commonjs/locale/el.json +324 -321
  12. package/lib/commonjs/locale/en-au.json +324 -321
  13. package/lib/commonjs/locale/en-ca.json +324 -321
  14. package/lib/commonjs/locale/en-gb.json +324 -321
  15. package/lib/commonjs/locale/en.json +324 -321
  16. package/lib/commonjs/locale/es-mx.json +324 -321
  17. package/lib/commonjs/locale/es.json +324 -321
  18. package/lib/commonjs/locale/et.json +324 -321
  19. package/lib/commonjs/locale/fa.json +324 -321
  20. package/lib/commonjs/locale/fi.json +324 -321
  21. package/lib/commonjs/locale/fr-ca.json +324 -321
  22. package/lib/commonjs/locale/fr.json +324 -321
  23. package/lib/commonjs/locale/gd.json +324 -321
  24. package/lib/commonjs/locale/he.json +324 -321
  25. package/lib/commonjs/locale/hi.json +324 -321
  26. package/lib/commonjs/locale/hr.json +324 -321
  27. package/lib/commonjs/locale/hu.json +324 -321
  28. package/lib/commonjs/locale/hy.json +324 -321
  29. package/lib/commonjs/locale/id.json +324 -321
  30. package/lib/commonjs/locale/is.json +324 -321
  31. package/lib/commonjs/locale/it.json +324 -321
  32. package/lib/commonjs/locale/ja.json +324 -321
  33. package/lib/commonjs/locale/kk.json +324 -321
  34. package/lib/commonjs/locale/ko.json +324 -321
  35. package/lib/commonjs/locale/lt.json +324 -321
  36. package/lib/commonjs/locale/lv.json +324 -321
  37. package/lib/commonjs/locale/mi.json +324 -321
  38. package/lib/commonjs/locale/ms.json +324 -321
  39. package/lib/commonjs/locale/nb.json +324 -321
  40. package/lib/commonjs/locale/nl-be.json +324 -321
  41. package/lib/commonjs/locale/nl.json +324 -321
  42. package/lib/commonjs/locale/nn.json +324 -321
  43. package/lib/commonjs/locale/no.json +324 -321
  44. package/lib/commonjs/locale/pl.json +324 -321
  45. package/lib/commonjs/locale/pt-br.json +324 -321
  46. package/lib/commonjs/locale/pt.json +324 -321
  47. package/lib/commonjs/locale/ro.json +324 -321
  48. package/lib/commonjs/locale/ru.json +324 -321
  49. package/lib/commonjs/locale/sk.json +324 -321
  50. package/lib/commonjs/locale/sl.json +324 -321
  51. package/lib/commonjs/locale/sq.json +324 -321
  52. package/lib/commonjs/locale/sr.json +324 -321
  53. package/lib/commonjs/locale/sv.json +324 -321
  54. package/lib/commonjs/locale/th.json +324 -321
  55. package/lib/commonjs/locale/tl.json +324 -321
  56. package/lib/commonjs/locale/tr.json +324 -321
  57. package/lib/commonjs/locale/uk.json +324 -321
  58. package/lib/commonjs/locale/vi.json +324 -321
  59. package/lib/commonjs/locale/zh-hk.json +324 -321
  60. package/lib/commonjs/locale/zh-tw.json +324 -321
  61. package/lib/commonjs/locale/zh.json +324 -321
  62. package/lib/commonjs/locale/zu.json +324 -321
  63. package/lib/commonjs/views/Dialog/Message.js +2 -2
  64. package/lib/commonjs/views/Dialog/Message.js.map +1 -1
  65. package/lib/commonjs/views/Dialog/index.js +1 -0
  66. package/lib/commonjs/views/Dialog/index.js.map +1 -1
  67. package/lib/commonjs/views/Drawer/index.js +1 -0
  68. package/lib/commonjs/views/Drawer/index.js.map +1 -1
  69. package/lib/module/components/Button.js +27 -12
  70. package/lib/module/components/Button.js.map +1 -1
  71. package/lib/module/locale/af.json +324 -321
  72. package/lib/module/locale/ar.json +324 -321
  73. package/lib/module/locale/bg.json +324 -321
  74. package/lib/module/locale/ca.json +324 -321
  75. package/lib/module/locale/cs.json +324 -321
  76. package/lib/module/locale/da.json +324 -321
  77. package/lib/module/locale/de-at.json +324 -321
  78. package/lib/module/locale/de.json +324 -321
  79. package/lib/module/locale/el.json +324 -321
  80. package/lib/module/locale/en-au.json +324 -321
  81. package/lib/module/locale/en-ca.json +324 -321
  82. package/lib/module/locale/en-gb.json +324 -321
  83. package/lib/module/locale/en.json +324 -321
  84. package/lib/module/locale/es-mx.json +324 -321
  85. package/lib/module/locale/es.json +324 -321
  86. package/lib/module/locale/et.json +324 -321
  87. package/lib/module/locale/fa.json +324 -321
  88. package/lib/module/locale/fi.json +324 -321
  89. package/lib/module/locale/fr-ca.json +324 -321
  90. package/lib/module/locale/fr.json +324 -321
  91. package/lib/module/locale/gd.json +324 -321
  92. package/lib/module/locale/he.json +324 -321
  93. package/lib/module/locale/hi.json +324 -321
  94. package/lib/module/locale/hr.json +324 -321
  95. package/lib/module/locale/hu.json +324 -321
  96. package/lib/module/locale/hy.json +324 -321
  97. package/lib/module/locale/id.json +324 -321
  98. package/lib/module/locale/is.json +324 -321
  99. package/lib/module/locale/it.json +324 -321
  100. package/lib/module/locale/ja.json +324 -321
  101. package/lib/module/locale/kk.json +324 -321
  102. package/lib/module/locale/ko.json +324 -321
  103. package/lib/module/locale/lt.json +324 -321
  104. package/lib/module/locale/lv.json +324 -321
  105. package/lib/module/locale/mi.json +324 -321
  106. package/lib/module/locale/ms.json +324 -321
  107. package/lib/module/locale/nb.json +324 -321
  108. package/lib/module/locale/nl-be.json +324 -321
  109. package/lib/module/locale/nl.json +324 -321
  110. package/lib/module/locale/nn.json +324 -321
  111. package/lib/module/locale/no.json +324 -321
  112. package/lib/module/locale/pl.json +324 -321
  113. package/lib/module/locale/pt-br.json +324 -321
  114. package/lib/module/locale/pt.json +324 -321
  115. package/lib/module/locale/ro.json +324 -321
  116. package/lib/module/locale/ru.json +324 -321
  117. package/lib/module/locale/sk.json +324 -321
  118. package/lib/module/locale/sl.json +324 -321
  119. package/lib/module/locale/sq.json +324 -321
  120. package/lib/module/locale/sr.json +324 -321
  121. package/lib/module/locale/sv.json +324 -321
  122. package/lib/module/locale/th.json +324 -321
  123. package/lib/module/locale/tl.json +324 -321
  124. package/lib/module/locale/tr.json +324 -321
  125. package/lib/module/locale/uk.json +324 -321
  126. package/lib/module/locale/vi.json +324 -321
  127. package/lib/module/locale/zh-hk.json +324 -321
  128. package/lib/module/locale/zh-tw.json +324 -321
  129. package/lib/module/locale/zh.json +324 -321
  130. package/lib/module/locale/zu.json +324 -321
  131. package/lib/module/views/Dialog/Message.js +2 -2
  132. package/lib/module/views/Dialog/Message.js.map +1 -1
  133. package/lib/module/views/Dialog/index.js +1 -0
  134. package/lib/module/views/Dialog/index.js.map +1 -1
  135. package/lib/module/views/Drawer/index.js +1 -0
  136. package/lib/module/views/Drawer/index.js.map +1 -1
  137. package/lib/typescript/lib/commonjs/components/Button.d.ts.map +1 -1
  138. package/lib/typescript/lib/commonjs/views/Dialog/index.d.ts.map +1 -1
  139. package/lib/typescript/lib/commonjs/views/Drawer/index.d.ts.map +1 -1
  140. package/lib/typescript/lib/module/components/Button.d.ts.map +1 -1
  141. package/lib/typescript/lib/module/views/Dialog/index.d.ts.map +1 -1
  142. package/lib/typescript/lib/module/views/Drawer/index.d.ts.map +1 -1
  143. package/lib/typescript/src/components/Button.d.ts.map +1 -1
  144. package/lib/typescript/src/iab/gpp/api.d.ts +28 -0
  145. package/lib/typescript/src/iab/gpp/api.d.ts.map +1 -0
  146. package/lib/typescript/src/iab/gpp/consent.d.ts +24 -0
  147. package/lib/typescript/src/iab/gpp/consent.d.ts.map +1 -0
  148. package/lib/typescript/src/iab/gpp/constants.d.ts +37 -0
  149. package/lib/typescript/src/iab/gpp/constants.d.ts.map +1 -0
  150. package/lib/typescript/src/iab/gpp/encoders/AbstractBase64UrlEncoder.d.ts +28 -0
  151. package/lib/typescript/src/iab/gpp/encoders/AbstractBase64UrlEncoder.d.ts.map +1 -0
  152. package/lib/typescript/src/iab/gpp/encoders/BooleanEncoder.d.ts +34 -0
  153. package/lib/typescript/src/iab/gpp/encoders/BooleanEncoder.d.ts.map +1 -0
  154. package/lib/typescript/src/iab/gpp/encoders/CompressedBase64UrlEncoder.d.ts +28 -0
  155. package/lib/typescript/src/iab/gpp/encoders/CompressedBase64UrlEncoder.d.ts.map +1 -0
  156. package/lib/typescript/src/iab/gpp/encoders/DatetimeEncoder.d.ts +28 -0
  157. package/lib/typescript/src/iab/gpp/encoders/DatetimeEncoder.d.ts.map +1 -0
  158. package/lib/typescript/src/iab/gpp/encoders/EncodableOptimizedFixedRange.d.ts +16 -0
  159. package/lib/typescript/src/iab/gpp/encoders/EncodableOptimizedFixedRange.d.ts.map +1 -0
  160. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerEncoder.d.ts +28 -0
  161. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerEncoder.d.ts.map +1 -0
  162. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.d.ts +28 -0
  163. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.d.ts.map +1 -0
  164. package/lib/typescript/src/iab/gpp/encoders/FixedBitfieldEncoder.d.ts +28 -0
  165. package/lib/typescript/src/iab/gpp/encoders/FixedBitfieldEncoder.d.ts.map +1 -0
  166. package/lib/typescript/src/iab/gpp/encoders/FixedIdBitMapEncoder.d.ts +6 -0
  167. package/lib/typescript/src/iab/gpp/encoders/FixedIdBitMapEncoder.d.ts.map +1 -0
  168. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerEncoder.d.ts +28 -0
  169. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerEncoder.d.ts.map +1 -0
  170. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerListEncoder.d.ts +28 -0
  171. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerListEncoder.d.ts.map +1 -0
  172. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerRangeEncoder.d.ts +28 -0
  173. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerRangeEncoder.d.ts.map +1 -0
  174. package/lib/typescript/src/iab/gpp/encoders/FixedStringEncoder.d.ts +26 -0
  175. package/lib/typescript/src/iab/gpp/encoders/FixedStringEncoder.d.ts.map +1 -0
  176. package/lib/typescript/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.d.ts +28 -0
  177. package/lib/typescript/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.d.ts.map +1 -0
  178. package/lib/typescript/src/iab/gpp/encoders/errors.d.ts +19 -0
  179. package/lib/typescript/src/iab/gpp/encoders/errors.d.ts.map +1 -0
  180. package/lib/typescript/src/iab/gpp/encoders/index.d.ts +16 -0
  181. package/lib/typescript/src/iab/gpp/encoders/index.d.ts.map +1 -0
  182. package/lib/typescript/src/iab/gpp/encoders/types.d.ts +5 -0
  183. package/lib/typescript/src/iab/gpp/encoders/types.d.ts.map +1 -0
  184. package/lib/typescript/src/iab/gpp/index.d.ts +10 -0
  185. package/lib/typescript/src/iab/gpp/index.d.ts.map +1 -0
  186. package/lib/typescript/src/iab/gpp/reducer.d.ts +6 -0
  187. package/lib/typescript/src/iab/gpp/reducer.d.ts.map +1 -0
  188. package/lib/typescript/src/iab/gpp/selectors.d.ts +6 -0
  189. package/lib/typescript/src/iab/gpp/selectors.d.ts.map +1 -0
  190. package/lib/typescript/src/iab/gpp/types.d.ts +3 -0
  191. package/lib/typescript/src/iab/gpp/types.d.ts.map +1 -0
  192. package/lib/typescript/src/iab/gpp/v1/constants.d.ts +9 -0
  193. package/lib/typescript/src/iab/gpp/v1/constants.d.ts.map +1 -0
  194. package/lib/typescript/src/iab/gpp/v1/index.d.ts +19 -0
  195. package/lib/typescript/src/iab/gpp/v1/index.d.ts.map +1 -0
  196. package/lib/typescript/src/iab/usp/api.d.ts +4 -0
  197. package/lib/typescript/src/iab/usp/api.d.ts.map +1 -0
  198. package/lib/typescript/src/iab/usp/consent.d.ts +13 -0
  199. package/lib/typescript/src/iab/usp/consent.d.ts.map +1 -0
  200. package/lib/typescript/src/iab/usp/constants.d.ts +77 -0
  201. package/lib/typescript/src/iab/usp/constants.d.ts.map +1 -0
  202. package/lib/typescript/src/iab/usp/index.d.ts +10 -0
  203. package/lib/typescript/src/iab/usp/index.d.ts.map +1 -0
  204. package/lib/typescript/src/iab/usp/reducer.d.ts +13 -0
  205. package/lib/typescript/src/iab/usp/reducer.d.ts.map +1 -0
  206. package/lib/typescript/src/iab/usp/selectors.d.ts +9 -0
  207. package/lib/typescript/src/iab/usp/selectors.d.ts.map +1 -0
  208. package/lib/typescript/src/iab/usp/types.d.ts +5 -0
  209. package/lib/typescript/src/iab/usp/types.d.ts.map +1 -0
  210. package/lib/typescript/src/iab/usp/v1/constants.d.ts +9 -0
  211. package/lib/typescript/src/iab/usp/v1/constants.d.ts.map +1 -0
  212. package/lib/typescript/src/iab/usp/v1/index.d.ts +16 -0
  213. package/lib/typescript/src/iab/usp/v1/index.d.ts.map +1 -0
  214. package/lib/typescript/src/views/Dialog/Message.d.ts.map +1 -1
  215. package/lib/typescript/src/views/Dialog/index.d.ts.map +1 -1
  216. package/lib/typescript/src/views/Drawer/index.d.ts.map +1 -1
  217. package/package.json +2 -6
  218. package/src/components/Button.tsx +22 -12
  219. package/src/iab/gpp/api.js +253 -0
  220. package/src/iab/gpp/consent.js +114 -0
  221. package/src/iab/gpp/constants.js +49 -0
  222. package/src/iab/gpp/encoders/AbstractBase64UrlEncoder.ts +89 -0
  223. package/src/iab/gpp/encoders/BooleanEncoder.ts +39 -0
  224. package/src/iab/gpp/encoders/CompressedBase64UrlEncoder.ts +41 -0
  225. package/src/iab/gpp/encoders/DatetimeEncoder.ts +46 -0
  226. package/src/iab/gpp/encoders/EncodableOptimizedFixedRange.ts +213 -0
  227. package/src/iab/gpp/encoders/FibonacciIntegerEncoder.ts +81 -0
  228. package/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.ts +122 -0
  229. package/src/iab/gpp/encoders/FixedBitfieldEncoder.ts +59 -0
  230. package/src/iab/gpp/encoders/FixedIdBitMapEncoder.ts +30 -0
  231. package/src/iab/gpp/encoders/FixedIntegerEncoder.ts +61 -0
  232. package/src/iab/gpp/encoders/FixedIntegerListEncoder.ts +87 -0
  233. package/src/iab/gpp/encoders/FixedIntegerRangeEncoder.ts +102 -0
  234. package/src/iab/gpp/encoders/FixedStringEncoder.ts +74 -0
  235. package/src/iab/gpp/encoders/LICENSE-IABTechLab +176 -0
  236. package/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.ts +38 -0
  237. package/src/iab/gpp/encoders/errors.ts +41 -0
  238. package/src/iab/gpp/encoders/index.ts +15 -0
  239. package/src/iab/gpp/encoders/types.ts +5 -0
  240. package/src/iab/gpp/index.js +9 -0
  241. package/src/iab/gpp/reducer.js +7 -0
  242. package/src/iab/gpp/selectors.js +21 -0
  243. package/src/iab/gpp/types.ts +3 -0
  244. package/src/iab/gpp/v1/constants.js +7 -0
  245. package/src/iab/gpp/v1/index.js +73 -0
  246. package/src/iab/usp/api.js +56 -0
  247. package/src/iab/usp/consent.js +150 -0
  248. package/src/iab/usp/constants.js +40 -0
  249. package/src/iab/usp/index.js +9 -0
  250. package/src/iab/usp/reducer.js +107 -0
  251. package/src/iab/usp/selectors.js +31 -0
  252. package/src/iab/usp/types.ts +4 -0
  253. package/src/iab/usp/v1/constants.js +10 -0
  254. package/src/iab/usp/v1/index.js +54 -0
  255. package/src/locale/af.json +324 -321
  256. package/src/locale/ar.json +324 -321
  257. package/src/locale/bg.json +324 -321
  258. package/src/locale/ca.json +324 -321
  259. package/src/locale/cs.json +324 -321
  260. package/src/locale/da.json +324 -321
  261. package/src/locale/de-at.json +324 -321
  262. package/src/locale/de.json +324 -321
  263. package/src/locale/el.json +324 -321
  264. package/src/locale/en-au.json +324 -321
  265. package/src/locale/en-ca.json +324 -321
  266. package/src/locale/en-gb.json +324 -321
  267. package/src/locale/en.json +324 -321
  268. package/src/locale/es-mx.json +324 -321
  269. package/src/locale/es.json +324 -321
  270. package/src/locale/et.json +324 -321
  271. package/src/locale/fa.json +324 -321
  272. package/src/locale/fi.json +324 -321
  273. package/src/locale/fr-ca.json +324 -321
  274. package/src/locale/fr.json +324 -321
  275. package/src/locale/gd.json +324 -321
  276. package/src/locale/he.json +324 -321
  277. package/src/locale/hi.json +324 -321
  278. package/src/locale/hr.json +324 -321
  279. package/src/locale/hu.json +324 -321
  280. package/src/locale/hy.json +324 -321
  281. package/src/locale/id.json +324 -321
  282. package/src/locale/is.json +324 -321
  283. package/src/locale/it.json +324 -321
  284. package/src/locale/ja.json +324 -321
  285. package/src/locale/kk.json +324 -321
  286. package/src/locale/ko.json +324 -321
  287. package/src/locale/lt.json +324 -321
  288. package/src/locale/lv.json +324 -321
  289. package/src/locale/mi.json +324 -321
  290. package/src/locale/ms.json +324 -321
  291. package/src/locale/nb.json +324 -321
  292. package/src/locale/nl-be.json +324 -321
  293. package/src/locale/nl.json +324 -321
  294. package/src/locale/nn.json +324 -321
  295. package/src/locale/no.json +324 -321
  296. package/src/locale/pl.json +324 -321
  297. package/src/locale/pt-br.json +324 -321
  298. package/src/locale/pt.json +324 -321
  299. package/src/locale/ro.json +324 -321
  300. package/src/locale/ru.json +324 -321
  301. package/src/locale/sk.json +324 -321
  302. package/src/locale/sl.json +324 -321
  303. package/src/locale/sq.json +324 -321
  304. package/src/locale/sr.json +324 -321
  305. package/src/locale/sv.json +324 -321
  306. package/src/locale/th.json +324 -321
  307. package/src/locale/tl.json +324 -321
  308. package/src/locale/tr.json +324 -321
  309. package/src/locale/uk.json +324 -321
  310. package/src/locale/vi.json +324 -321
  311. package/src/locale/zh-hk.json +324 -321
  312. package/src/locale/zh-tw.json +324 -321
  313. package/src/locale/zh.json +324 -321
  314. package/src/locale/zu.json +324 -321
  315. package/src/views/Dialog/Message.tsx +2 -1
  316. package/src/views/Dialog/index.tsx +1 -0
  317. package/src/views/Drawer/index.tsx +1 -0
@@ -0,0 +1,213 @@
1
+ // This is our own implementation but is analogous to
2
+ // https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/EncodableOptimizedFixedRange.ts
3
+
4
+ import BooleanEncoder from './BooleanEncoder';
5
+ import { default as FixedIdBitMapEncoder } from './FixedIdBitMapEncoder';
6
+ import IntEncoder from './FixedIntegerEncoder';
7
+
8
+ export const BitLength = {
9
+ encodingType: 1,
10
+ maxId: 16,
11
+ numEntries: 12,
12
+ singleOrRange: 1,
13
+ vendorId: 16,
14
+ };
15
+
16
+ const HEADER_LENGTH = BitLength.maxId + BitLength.encodingType;
17
+ const RANGE_MINIMUM_LENGTH =
18
+ BitLength.vendorId + BitLength.singleOrRange + BitLength.numEntries;
19
+
20
+ const ENCODING_TYPE = {
21
+ FIELD: 0,
22
+ RANGE: 1,
23
+ };
24
+
25
+ const buildRangeEncoding = (ranges: (number | string)[][]) => {
26
+ // describe the number of entries to follow
27
+ const numEntries = ranges.length;
28
+ let rangeString = IntEncoder.encode(numEntries, BitLength.numEntries);
29
+
30
+ // each range
31
+ ranges.forEach((range /*: number[]*/) => {
32
+ // is this range a single?
33
+ const single = range.length === 1;
34
+
35
+ // first is the indicator of whether this is a single id or range (two)
36
+ // 0 is single and range is 1
37
+ rangeString += BooleanEncoder.encode(!single);
38
+
39
+ // second is the first (or only) vendorId
40
+ rangeString += IntEncoder.encode(`${range[0]}`, BitLength.vendorId);
41
+
42
+ if (!single) {
43
+ // add the second id if it exists
44
+ rangeString += IntEncoder.encode(`${range[1]}`, BitLength.vendorId);
45
+ }
46
+ });
47
+
48
+ return rangeString;
49
+ };
50
+
51
+ const encode = (value: Record<number, boolean>) => {
52
+ // Filter out any falsey values and convert the keys to numbers
53
+ const vendorIds = Object.entries(value)
54
+ .filter(([, v]) => !!v)
55
+ .map(([id]) => {
56
+ const parsedId = parseInt(id, 10);
57
+ if (isNaN(parsedId) || parsedId < 1 || /^\d+$/.test(id) === false) {
58
+ throw new Error(`Invalid vendor ID: ${id}`);
59
+ }
60
+ return parsedId;
61
+ });
62
+ const vendorSet = new Set(vendorIds);
63
+ const maxId = Math.max(0, ...vendorIds);
64
+ // collectors for range encoding
65
+ const ranges = []; // : number[][]
66
+ let range = []; // : number[]
67
+
68
+ // bit field will be just the encoded value of the ID corresponding to the
69
+ // position in the bit field
70
+ let bitField = '';
71
+ // A range is a minimum of 29 bits, so if the max vendor ID in this value
72
+ // is less than that then we know that a bitfield encoding will be shorter
73
+ // than any range encoding.
74
+ let rangeIsSmaller = maxId > RANGE_MINIMUM_LENGTH;
75
+
76
+ const bitFieldLength = HEADER_LENGTH + maxId;
77
+
78
+ // grows as we add to the range
79
+ let rangeLength = HEADER_LENGTH + BitLength.numEntries;
80
+
81
+ for (let vendorId = 1; vendorId <= maxId; vendorId++) {
82
+ const vendorIsOn = vendorSet.has(vendorId);
83
+
84
+ // build our bitfield no matter what
85
+ bitField += BooleanEncoder.encode(vendorIsOn);
86
+
87
+ // For each vendor ID up to maxId, we're re-evaluating whether the range
88
+ // grows larger than the bitfield. If it does, we'll abandon building
89
+ // the range
90
+ rangeIsSmaller = rangeIsSmaller && rangeLength < bitFieldLength;
91
+ if (rangeIsSmaller && vendorIsOn) {
92
+ const isEndOfRange = !vendorSet.has(vendorId + 1);
93
+ if (isEndOfRange) {
94
+ range.push(vendorId);
95
+
96
+ // add to the range length the additional vendorId
97
+ rangeLength += BitLength.vendorId;
98
+
99
+ // store the array in our bigger array
100
+ ranges.push(range);
101
+
102
+ // clear the array for the next range
103
+ range = [];
104
+ } else if (range.length === 0) {
105
+ // this is the first value for this range
106
+ range.push(vendorId);
107
+
108
+ // update our count with new range overhead
109
+ rangeLength += BitLength.singleOrRange;
110
+ rangeLength += BitLength.vendorId;
111
+ }
112
+ }
113
+ }
114
+
115
+ rangeIsSmaller = rangeIsSmaller && rangeLength < bitFieldLength;
116
+
117
+ // since both encodings need the maxId, start with that
118
+ const encodedMaxId = IntEncoder.encode(maxId, BitLength.maxId);
119
+ return (
120
+ encodedMaxId +
121
+ (rangeIsSmaller
122
+ ? ENCODING_TYPE.RANGE.toString() + buildRangeEncoding(ranges)
123
+ : ENCODING_TYPE.FIELD.toString() + bitField)
124
+ );
125
+ };
126
+
127
+ const decode = (bitString: string) => {
128
+ if (!bitString) {
129
+ return { bitLength: 0, value: {} };
130
+ }
131
+ let index = 0;
132
+
133
+ const maxId = IntEncoder.decode(
134
+ bitString.substr(index, BitLength.maxId),
135
+ BitLength.maxId,
136
+ );
137
+ index += BitLength.maxId;
138
+ const encodingType = IntEncoder.decode(
139
+ bitString.charAt(index),
140
+ BitLength.encodingType,
141
+ );
142
+ index += BitLength.encodingType;
143
+
144
+ /**
145
+ * Range is handled in batches so we'll need a different decoding scheme
146
+ */
147
+ if (encodingType === ENCODING_TYPE.RANGE) {
148
+ const vendorIds = new Set();
149
+
150
+ const numEntries = IntEncoder.decode(
151
+ bitString.substr(index, BitLength.numEntries),
152
+ BitLength.numEntries,
153
+ );
154
+
155
+ index += BitLength.numEntries;
156
+
157
+ // loop through each group of entries
158
+ for (let i = 0; i < numEntries; i++) {
159
+ // Ranges can represent a single id or a range of ids.
160
+ const isIdRange = BooleanEncoder.decode(bitString.charAt(index));
161
+
162
+ index += BitLength.singleOrRange;
163
+
164
+ /**
165
+ * regardless of whether or not it's a single entry or range, the next
166
+ * set of bits is a vendor ID
167
+ */
168
+ const firstId = IntEncoder.decode(
169
+ bitString.substr(index, BitLength.vendorId),
170
+ BitLength.vendorId,
171
+ );
172
+
173
+ index += BitLength.vendorId;
174
+
175
+ // if it's a range, the next set of bits is the second id
176
+ if (isIdRange) {
177
+ const secondId = IntEncoder.decode(
178
+ bitString.substr(index, BitLength.vendorId),
179
+ BitLength.vendorId,
180
+ );
181
+
182
+ index += BitLength.vendorId;
183
+
184
+ // we'll need to set or unset all the vendor ids between the first and second
185
+ for (let j = firstId; j <= secondId; j++) {
186
+ vendorIds.add(j);
187
+ }
188
+ } else {
189
+ vendorIds.add(firstId);
190
+ }
191
+ }
192
+
193
+ const decodedValue: Record<number, boolean> = {};
194
+ for (let vendorId = 1; vendorId <= maxId; vendorId++) {
195
+ decodedValue[vendorId] = vendorIds.has(vendorId);
196
+ }
197
+ return { bitLength: index, value: decodedValue };
198
+ }
199
+
200
+ // Bitfield decoding
201
+ const bitField = bitString.substr(index, maxId);
202
+
203
+ index += maxId;
204
+ return {
205
+ bitLength: index,
206
+ value: FixedIdBitMapEncoder.decode(bitField, maxId),
207
+ };
208
+ };
209
+
210
+ export default {
211
+ decode,
212
+ encode,
213
+ };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Adapted from IABTechLab's GPP JavaScript Reference Implementation
3
+ *
4
+ * https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/encoder/FibonacciIntegerEncoder.ts
5
+ *
6
+ * @license
7
+ * Copyright 2023 IABTechLab
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
+ * use this file except in compliance with the License. You may obtain a copy of
11
+ * the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations under
19
+ * the License.
20
+ */
21
+
22
+ export const encode = (value: number) => {
23
+ const fib = [];
24
+ if (value >= 1) {
25
+ fib.push(1);
26
+
27
+ if (value >= 2) {
28
+ fib.push(2);
29
+
30
+ let i = 2;
31
+ while (value >= fib[i - 1]! + fib[i - 2]!) {
32
+ fib.push(fib[i - 1]! + fib[i - 2]!);
33
+ i++;
34
+ }
35
+ }
36
+ }
37
+
38
+ let bitString = '1';
39
+ for (let i = fib.length - 1; i >= 0; i--) {
40
+ const f = fib[i]!;
41
+ if (value >= f) {
42
+ bitString = '1' + bitString;
43
+ value -= f;
44
+ } else {
45
+ bitString = '0' + bitString;
46
+ }
47
+ }
48
+
49
+ return bitString;
50
+ };
51
+
52
+ export const decode = (bitString: string) => {
53
+ if (!/^[01]*11$/.test(bitString)) {
54
+ throw new Error('Invalid bit string');
55
+ }
56
+
57
+ let value = 0;
58
+
59
+ const fib: number[] = [];
60
+ for (let i = 0; i < bitString.length - 1; i++) {
61
+ if (i === 0) {
62
+ fib.push(1);
63
+ } else if (i === 1) {
64
+ fib.push(2);
65
+ } else {
66
+ fib.push(fib[i - 1]! + fib[i - 2]!);
67
+ }
68
+ }
69
+
70
+ for (let i = 0; i < bitString.length - 1; i++) {
71
+ if (bitString.charAt(i) === '1') {
72
+ value += fib[i]!;
73
+ }
74
+ }
75
+ return value;
76
+ };
77
+
78
+ export default {
79
+ decode,
80
+ encode,
81
+ };
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Adapted from IABTechLab's GPP JavaScript Reference Implementation
3
+ *
4
+ * https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/encoder/FibonacciIntegerRangeEncoder.ts
5
+ *
6
+ * @license
7
+ * Copyright 2023 IABTechLab
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
+ * use this file except in compliance with the License. You may obtain a copy of
11
+ * the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations under
19
+ * the License.
20
+ */
21
+
22
+ import {
23
+ decode as fibIntDecode,
24
+ encode as fibIntEncode,
25
+ } from './FibonacciIntegerEncoder';
26
+ import {
27
+ decode as intDecode,
28
+ encode as intEncode,
29
+ } from './FixedIntegerEncoder';
30
+
31
+ import { decode as boolDecode } from './BooleanEncoder';
32
+
33
+ export const encode = (value: number[]) => {
34
+ value = value.sort((n1, n2) => n1 - n2);
35
+
36
+ const groups = [];
37
+
38
+ let offset = 0;
39
+ let groupStartIndex = 0;
40
+ while (groupStartIndex < value.length) {
41
+ let groupEndIndex = groupStartIndex;
42
+ while (
43
+ groupEndIndex < value.length - 1 &&
44
+ value[groupEndIndex]! + 1 === value[groupEndIndex + 1]
45
+ ) {
46
+ groupEndIndex++;
47
+ }
48
+
49
+ groups.push(value.slice(groupStartIndex, groupEndIndex + 1));
50
+
51
+ groupStartIndex = groupEndIndex + 1;
52
+ }
53
+
54
+ let bitString = intEncode(groups.length, 12);
55
+ for (let i = 0; i < groups.length; i++) {
56
+ const group = groups[i]!;
57
+ if (group.length > 0) {
58
+ const startInt = group[0]!;
59
+ if (groups.length === 1) {
60
+ const v = startInt - offset;
61
+ offset = startInt;
62
+ bitString += '0' + fibIntEncode(v);
63
+ } else {
64
+ const startVal = startInt - offset;
65
+ offset = startInt;
66
+ const endInt = group[group.length - 1]!;
67
+ const endVal = endInt - offset;
68
+ offset = endInt;
69
+ bitString += '1' + fibIntEncode(startVal) + fibIntEncode(endVal);
70
+ }
71
+ }
72
+ }
73
+ return bitString;
74
+ };
75
+
76
+ export const decode = (bitString: string) => {
77
+ if (!/^[01]{12,}$/.test(bitString)) {
78
+ throw new Error('invalid bit string');
79
+ }
80
+
81
+ const value = [];
82
+ const count = intDecode(bitString.substring(0, 12));
83
+
84
+ let offset = 0;
85
+ let startIndex = 12;
86
+ for (let i = 0; i < count; i++) {
87
+ const group = boolDecode(bitString.substring(startIndex, startIndex + 1));
88
+ startIndex++;
89
+
90
+ if (group === true) {
91
+ let index = bitString.indexOf('11', startIndex);
92
+ const start =
93
+ fibIntDecode(bitString.substring(startIndex, index + 2)) + offset;
94
+ offset = start;
95
+ startIndex = index + 2;
96
+
97
+ index = bitString.indexOf('11', startIndex);
98
+ const end =
99
+ fibIntDecode(bitString.substring(startIndex, index + 2)) + offset;
100
+ offset = end;
101
+ startIndex = index + 2;
102
+
103
+ for (let j = start; j <= end; j++) {
104
+ value.push(j);
105
+ }
106
+ } else {
107
+ const index = bitString.indexOf('11', startIndex);
108
+ const val =
109
+ fibIntDecode(bitString.substring(startIndex, index + 2)) + offset;
110
+ offset = val;
111
+ value.push(val);
112
+ startIndex = index + 2;
113
+ }
114
+ }
115
+
116
+ return value;
117
+ };
118
+
119
+ export default {
120
+ decode,
121
+ encode,
122
+ };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Adapted from IABTechLab's GPP JavaScript Reference Implementation
3
+ *
4
+ * https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/encoder/FixedBitfieldEncoder.ts
5
+ *
6
+ * @license
7
+ * Copyright 2023 IABTechLab
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
+ * use this file except in compliance with the License. You may obtain a copy of
11
+ * the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations under
19
+ * the License.
20
+ */
21
+
22
+ import { decode as boolDecode, encode as boolEncode } from './BooleanEncoder';
23
+
24
+ import { InvalidBitStringError } from './errors';
25
+
26
+ export const encode = (value: boolean[], bitStringLength: number) => {
27
+ let bitString = '';
28
+ for (let i = 0; i < value.length; i++) {
29
+ bitString += boolEncode(value[i]!);
30
+ }
31
+
32
+ // String.prototype.padEnd causes CoreJS to include a polyfill for it.
33
+ bitString =
34
+ bitString.length >= bitStringLength
35
+ ? bitString
36
+ : bitString + '0'.repeat(bitStringLength - bitString.length);
37
+
38
+ return bitString;
39
+ };
40
+
41
+ export const decode = (
42
+ bitString: string,
43
+ numBits: number = bitString.length,
44
+ ) => {
45
+ if (!/^[01]*$/.test(bitString)) {
46
+ throw new InvalidBitStringError(bitString);
47
+ }
48
+
49
+ const value = [];
50
+ for (let i = 0; i < numBits; i++) {
51
+ value.push(boolDecode(bitString.substring(i, i + 1)));
52
+ }
53
+ return value;
54
+ };
55
+
56
+ export default {
57
+ decode,
58
+ encode,
59
+ };
@@ -0,0 +1,30 @@
1
+ // This encoder is used to encode and decode ID-to-bit/boolean maps to and from
2
+ // fixed bitfields.It doesn't exactly have an equivalent in the GPP reference
3
+ // implementation but the EncodableFixedBitfield class is similar.
4
+ // https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/EncodableFixedBitfield.ts.
5
+ // The functional difference is that it encodes from and decodes to an array of
6
+ // booleans whereas this encoder encodes from and decodes to an object of
7
+ // ID-to-boolean mappings.
8
+
9
+ import FixedBitfieldEncoder from './FixedBitfieldEncoder';
10
+
11
+ export default {
12
+ encode: (value: Record<number, boolean>, numBits: number) =>
13
+ FixedBitfieldEncoder.encode(
14
+ Object.entries(value || {}).reduce((acc, [key, bit]) => {
15
+ const id = parseInt(key, 10);
16
+ acc[id - 1] = bit;
17
+ return acc;
18
+ }, [] as boolean[]),
19
+ numBits,
20
+ ),
21
+
22
+ decode: (bitString: string, numBits: number) =>
23
+ FixedBitfieldEncoder.decode(bitString, numBits).reduce(
24
+ (acc, value, index) => {
25
+ acc[index + 1] = value;
26
+ return acc;
27
+ },
28
+ {} as Record<number, boolean>,
29
+ ),
30
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Adapted from IABTechLab's GPP JavaScript Reference Implementation
3
+ *
4
+ * https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/encoder/FixedIntegerEncoder.ts
5
+ *
6
+ * @license
7
+ * Copyright 2023 IABTechLab
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
+ * use this file except in compliance with the License. You may obtain a copy of
11
+ * the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations under
19
+ * the License.
20
+ */
21
+
22
+ import { InvalidSizeError } from './errors';
23
+
24
+ // We use browser native functions to encode/decode integers to/from bit strings
25
+ // instead of the more verbose method in the reference implementation
26
+
27
+ export const encode = (int: number | string, numBits: number) => {
28
+ let bitString;
29
+
30
+ if (typeof int === 'string') {
31
+ int = parseInt(int, 10);
32
+ }
33
+
34
+ bitString = int.toString(2);
35
+
36
+ if (bitString.length > numBits || int < 0) {
37
+ throw new InvalidSizeError(int, numBits);
38
+ }
39
+
40
+ // Pad the string if not filling all bits
41
+ if (bitString.length < numBits) {
42
+ // pad left
43
+ bitString = '0'.repeat(numBits - bitString.length) + bitString;
44
+ }
45
+
46
+ return bitString;
47
+ };
48
+
49
+ export const decode = (bitString: string, numBits?: number) => {
50
+ if (!bitString) {
51
+ // Handle falsy values
52
+ return 0;
53
+ }
54
+
55
+ return parseInt(bitString.slice(0, numBits), 2);
56
+ };
57
+
58
+ export default {
59
+ decode,
60
+ encode,
61
+ };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Adapted from IABTechLab's GPP JavaScript Reference Implementation
3
+ *
4
+ * https://github.com/IABTechLab/iabgpp-es/blob/42060d7ac2b6d0ee70fc1b5bcd33fc447bf5123c/modules/cmpapi/src/encoder/datatype/encoder/FixedIntegerListEncoder.ts
5
+ *
6
+ * @license
7
+ * Copyright 2023 IABTechLab
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
+ * use this file except in compliance with the License. You may obtain a copy of
11
+ * the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations under
19
+ * the License.
20
+ */
21
+
22
+ import { BitStringParametersMatchError, InvalidBitStringError } from './errors';
23
+ import {
24
+ decode as intDecode,
25
+ encode as intEncode,
26
+ } from './FixedIntegerEncoder';
27
+
28
+ export const encode = (
29
+ value: number[],
30
+ elementBitStringLength: number,
31
+ numElements: number,
32
+ ) => {
33
+ let bitString = '';
34
+ for (let i = 0; i < value.length; i++) {
35
+ bitString += intEncode(value[i]!, elementBitStringLength);
36
+ }
37
+
38
+ while (bitString.length < elementBitStringLength * numElements) {
39
+ bitString += '0';
40
+ }
41
+
42
+ return bitString;
43
+ };
44
+
45
+ export const decode = (
46
+ bitString: string,
47
+ elementBitStringLength: number,
48
+ numElements: number,
49
+ ) => {
50
+ if (!/^[01]*$/.test(bitString)) {
51
+ throw new InvalidBitStringError(bitString);
52
+ }
53
+
54
+ if (
55
+ bitString.length > elementBitStringLength * numElements ||
56
+ bitString.length % elementBitStringLength !== 0
57
+ ) {
58
+ throw new BitStringParametersMatchError(bitString, {
59
+ elementBitStringLength,
60
+ numElements,
61
+ });
62
+ }
63
+
64
+ while (bitString.length < elementBitStringLength * numElements) {
65
+ bitString += '0';
66
+ }
67
+
68
+ if (bitString.length > elementBitStringLength * numElements) {
69
+ bitString = bitString.substring(0, elementBitStringLength * numElements);
70
+ }
71
+
72
+ const value = [];
73
+ for (let i = 0; i < bitString.length; i += elementBitStringLength) {
74
+ value.push(intDecode(bitString.substring(i, i + elementBitStringLength)));
75
+ }
76
+
77
+ while (value.length < numElements) {
78
+ value.push(0);
79
+ }
80
+
81
+ return value;
82
+ };
83
+
84
+ export default {
85
+ decode,
86
+ encode,
87
+ };