@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,253 @@
1
+ import {
2
+ formatConsentString,
3
+ makeFormatPingData,
4
+ makeParseConsentString,
5
+ } from './consent';
6
+
7
+ import { EventNames } from './constants';
8
+ import { MAX_DATE } from '../../constants';
9
+ import { getSupportedApis } from './selectors';
10
+
11
+ /**
12
+ * An object that contains the client callback and metadata.
13
+ * @typedef {Object} EventSubscriber
14
+ * @property {number} version - The version of the API that the subscriber is
15
+ * listening to.
16
+ * @property {function} callback - The callback function that the subscriber
17
+ * provided. The signature should match the API version.
18
+ */
19
+
20
+ /**
21
+ * The listener ID is a number that is used to identify a subscriber. It is both
22
+ * a key in the eventSubscribers map and a property that is given back to the
23
+ * subscriber. It must not change for the lifetime of the subscriber.
24
+ * @typedef {number} ListenerId
25
+ */
26
+
27
+ /**
28
+ * A map of listener IDs to event subscribers.
29
+ * @type {Map<ListenerId, EventSubscriber>}
30
+ */
31
+ const eventSubscribers = new Map();
32
+
33
+ // Allows us to clear the event subscribers in tests
34
+ export const _clearEventSubscribers =
35
+ process.env.NODE_ENV === 'jest' ? () => eventSubscribers.clear() : undefined;
36
+
37
+ const createListenerId = () => {
38
+ let inc = 0;
39
+ let listenerId = MAX_DATE - Date.now();
40
+ do {
41
+ listenerId -= inc++;
42
+ } while (eventSubscribers.has(listenerId));
43
+
44
+ return listenerId;
45
+ };
46
+
47
+ /**
48
+ * Responsible for dispatching events to the subscribers.
49
+ * @param {number} apiVersion - The version of the API as defined by the IAB.
50
+ * @param {object} data - The data to dispatch to the subscribers.
51
+ */
52
+ const makeDispatch = apiVersion =>
53
+ function dispatch(data) {
54
+ eventSubscribers.forEach(({ version, callback }, listenerId) => {
55
+ apiVersion === version &&
56
+ callback({
57
+ ...data,
58
+ listenerId,
59
+ });
60
+ });
61
+ };
62
+
63
+ /**
64
+ * The GPP has its own API but it can also call the older APIs. This function
65
+ * adapts the newer GPP call signature to the older APIs.
66
+ */
67
+ const adaptedApis = new Map();
68
+
69
+ // Allows us to clear the event subscribers in tests
70
+ export const _clearAdaptedApis =
71
+ process.env.NODE_ENV === 'jest' ? () => adaptedApis.clear() : undefined;
72
+
73
+ const getAdaptedApi = (clientApi, api) => {
74
+ // cache the adapted API so that we aren't creating a new function on every call
75
+ const adaptedApi = adaptedApis.get(clientApi);
76
+ if (adaptedApi) {
77
+ return adaptedApi;
78
+ }
79
+
80
+ // If the API is not available, throw an error. If the requested API is the
81
+ // GPP, throw an error (the GPP should never call itself as a sub-API).
82
+ if (!api || clientApi === 'gpp') {
83
+ throw new Error(`API ${clientApi} is not available`);
84
+ }
85
+
86
+ switch (clientApi) {
87
+ // pre-GPP APIs use the signature (command, version, callback, parameter)
88
+ case 'tcfeuv2':
89
+ adaptedApis.set(clientApi, (command, callback, parameter) =>
90
+ api(command, 2, callback, parameter),
91
+ );
92
+ break;
93
+ case 'uspv1':
94
+ adaptedApis.set(clientApi, (command, callback, parameter) =>
95
+ api(command, 1, callback, parameter),
96
+ );
97
+ break;
98
+ default:
99
+ adaptedApis.set(clientApi, api);
100
+ }
101
+
102
+ return adaptedApis.get(clientApi);
103
+ };
104
+
105
+ export default function makeApi(initOptions) {
106
+ const formatPingData = makeFormatPingData(initOptions);
107
+ const parseConsentString = makeParseConsentString(initOptions);
108
+ const makeEventSubscriber = callback => ({
109
+ version: initOptions.version,
110
+ callback,
111
+ });
112
+ const eventListenerReturn = (state, eventName, listenerId, data) => ({
113
+ eventName,
114
+ listenerId,
115
+ data,
116
+ pingData: formatPingData(state),
117
+ });
118
+ const dispatch = makeDispatch(initOptions.version);
119
+
120
+ function bind(store, allApis) {
121
+ const subApiSubscribers = new Map();
122
+ // The GPP spec says that events dispatched from section APIs should be
123
+ // dispatched from the GPP API. To do that, we'll subscribe to the
124
+ // events from the other APIs and re-dispatch them from here.
125
+ const initDispatchAggregator = () => {
126
+ if (subApiSubscribers.size > 0) {
127
+ // We have already initialized the dispatch aggregator
128
+ return;
129
+ }
130
+
131
+ const supportedApis = getSupportedApis(store.getState());
132
+ allApis.forEach((api, section) => {
133
+ if (!supportedApis.includes(section)) {
134
+ return;
135
+ }
136
+
137
+ const subscriber = data => {
138
+ // remove our own listener ID from the data object
139
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
140
+ const { listenerId, ...rest } = data;
141
+
142
+ dispatch({
143
+ // Other APIs don't currently have event names but if
144
+ // they are added this field should be dot-separated,
145
+ // e.g. `${section}.${data.eventName}`
146
+ eventName: section,
147
+ data: rest,
148
+ pingData: formatPingData(store.getState()),
149
+ });
150
+ };
151
+ subApiSubscribers.set(section, subscriber);
152
+ getAdaptedApi(section, api)('addEventListener', subscriber);
153
+ });
154
+ };
155
+
156
+ return function gppApi(command, callback, parameter) {
157
+ const state = store.getState();
158
+
159
+ switch (command) {
160
+ case 'ping': {
161
+ return formatPingData(state);
162
+ }
163
+
164
+ case 'addEventListener': {
165
+ // We wait to initialize the dispatch aggregator until there
166
+ // is at least one client event listener. Saves a little
167
+ // performance and ensures that all APIs are available.
168
+ initDispatchAggregator();
169
+ const listenerId = createListenerId();
170
+
171
+ try {
172
+ if (typeof callback !== 'function') {
173
+ throw new Error('Callback must be a function');
174
+ }
175
+ eventSubscribers.set(listenerId, makeEventSubscriber(callback));
176
+ const returnObject = eventListenerReturn(
177
+ state,
178
+ EventNames.LISTENER_REGISTERED,
179
+ listenerId,
180
+ true,
181
+ );
182
+
183
+ return returnObject;
184
+ } catch {
185
+ eventSubscribers.delete(listenerId);
186
+ return eventListenerReturn(
187
+ state,
188
+ EventNames.LISTENER_REGISTERED,
189
+ 0,
190
+ false,
191
+ );
192
+ }
193
+ }
194
+
195
+ case 'removeEventListener': {
196
+ const listenerId = parseInt(parameter, 10);
197
+ const removed = eventSubscribers.delete(listenerId);
198
+ return eventListenerReturn(
199
+ state,
200
+ EventNames.LISTENER_REMOVED,
201
+ listenerId,
202
+ removed,
203
+ );
204
+ }
205
+
206
+ case 'hasSection': {
207
+ const section = parameter;
208
+ return getSupportedApis(state).includes(`${section}`);
209
+ }
210
+
211
+ /** Note that this command throws if the requested section
212
+ * doesn't exist. The spec does not define what should happen in
213
+ * this case. Returning nothing could be misleading so an error
214
+ * is clearer. */
215
+ case 'getSection': {
216
+ const clientApi = parameter;
217
+ const sectionApi = getAdaptedApi(clientApi, allApis.get(clientApi));
218
+ return sectionApi('getSection');
219
+ }
220
+
221
+ /** Note that as above, this command throws if the requested
222
+ * section does not exist and returns undefined if the field
223
+ * doesn't exist. The spec is again silent on this case. */
224
+ case 'getField': {
225
+ const [clientApi, ...fieldPath] = parameter.split('.');
226
+ const sectionApi = getAdaptedApi(clientApi, allApis.get(clientApi));
227
+ return sectionApi('getField', undefined, fieldPath.join('.'));
228
+ }
229
+
230
+ case 'getGPPData': {
231
+ const gppString = formatConsentString(state);
232
+ return gppString ? parseConsentString(gppString, state) : undefined;
233
+ }
234
+
235
+ default: {
236
+ const mark = command.indexOf('.');
237
+ if (mark < 0) {
238
+ throw new Error(`Invalid command: ${command}`);
239
+ }
240
+ const clientApi = command.substring(0, mark);
241
+ const apiCommand = command.substring(mark + 1);
242
+ const sectionApi = getAdaptedApi(clientApi, allApis.get(clientApi));
243
+ return sectionApi(apiCommand, callback, parameter);
244
+ }
245
+ }
246
+ };
247
+ }
248
+
249
+ return {
250
+ bind,
251
+ dispatch,
252
+ };
253
+ }
@@ -0,0 +1,114 @@
1
+ import { CmpDisplayStatusCodes, CmpStatusCodes, SECTIONS } from './constants';
2
+ import {
3
+ decode as base64Decode,
4
+ encode as base64Encode,
5
+ } from './encoders/CompressedBase64UrlEncoder';
6
+ import {
7
+ doesGDPRApply,
8
+ getConsentString,
9
+ getSupportedApis,
10
+ isBrowsingFrom,
11
+ isUiVisible,
12
+ } from './selectors';
13
+ import {
14
+ decode as fibRangeDecode,
15
+ encode as fibRangeEncode,
16
+ } from './encoders/FibonacciIntegerRangeEncoder';
17
+
18
+ import { CMP_ID } from '../constants';
19
+
20
+ const ERROR_MESSAGE = 'Invalid GPP string';
21
+
22
+ /* A note on the GPP version number: According to the GPP spec, the GPP string's
23
+ * header can only contain an integer version number. However, the API spec for
24
+ * the PingReturn object requires that the GPP version number is in the format
25
+ * Major.Minor (e.g. 1.0). It's not a problem for now but will be interesting if
26
+ * and when they introduce a version 1.1.
27
+ */
28
+ const HEADER_PREFIX = 'DB'; // Section 3 ('D'), GPP v1 ('B')
29
+
30
+ export const isSectionApplicable = (sectionId, state) => {
31
+ switch (sectionId) {
32
+ // case 1 is TCF v1 and is unsupported
33
+ case 2: // TCF EU v2
34
+ return doesGDPRApply(state);
35
+ // cases 3 and 4 are GPP header and integrity sections and are not applicable
36
+ case 5: // TCF CA
37
+ return isBrowsingFrom(state, 'ca');
38
+ case 6: // USPrivacy v1
39
+ // case 7: // US National
40
+ return isBrowsingFrom(state, 'us');
41
+ // We do not implement the GPP US-state spec
42
+ // case 8: // US California
43
+ // return isBrowsingFrom(state, 'us-ca');
44
+ // case 9: // US Virginia
45
+ // return isBrowsingFrom(state, 'us-va');
46
+ // case 10: // US Colorado
47
+ // return isBrowsingFrom(state, 'us-co');
48
+ // case 11: // US Utah
49
+ // return isBrowsingFrom(state, 'us-ut');
50
+ // case 12: // US Connecticut
51
+ // return isBrowsingFrom(state, 'us-ct');
52
+ default:
53
+ return false;
54
+ }
55
+ };
56
+
57
+ export const makeFormatPingData = initOptions => state => ({
58
+ gppVersion: initOptions.version, // '1.0', see note above
59
+ cmpStatus: CmpStatusCodes.LOADED,
60
+ cmpDisplayStatus: isUiVisible(state)
61
+ ? CmpDisplayStatusCodes.VISIBLE
62
+ : CmpDisplayStatusCodes.HIDDEN,
63
+ supportedAPIs: getSupportedApis(state),
64
+ cmpId: CMP_ID,
65
+ });
66
+
67
+ export const makeParseConsentString = initOptions => (gppString, state) => {
68
+ const [header, ...sections] = gppString.split('~');
69
+
70
+ // All GPPv1 strings must start with 'DB'
71
+ if (header.substring(0, 2) !== HEADER_PREFIX) {
72
+ throw new Error(`${ERROR_MESSAGE}: Invalid header`);
73
+ }
74
+
75
+ const expectedSections = fibRangeDecode(base64Decode(header.substring(2)));
76
+
77
+ if (sections.length !== expectedSections.length) {
78
+ throw new Error(
79
+ `${ERROR_MESSAGE}: Number of sections does not match header`,
80
+ );
81
+ }
82
+
83
+ return {
84
+ sectionId: 3,
85
+ gppVersion: 1, // see note above
86
+ sectionList: expectedSections,
87
+ applicableSections: expectedSections.filter(sectionId =>
88
+ isSectionApplicable(sectionId, state),
89
+ ),
90
+ gppString,
91
+ pingData: makeFormatPingData(initOptions)(state),
92
+ };
93
+ };
94
+
95
+ export const formatConsentString = state => {
96
+ const consentStrings = getSupportedApis(state)
97
+ .map(section => ({
98
+ sectionId: SECTIONS[`${section}`],
99
+ consentString: getConsentString(state, section),
100
+ }))
101
+ .filter(({ consentString }) => consentString !== undefined)
102
+ .sort((a, b) => a.sectionId - b.sectionId);
103
+
104
+ const header = `${HEADER_PREFIX}${base64Encode(
105
+ fibRangeEncode(consentStrings.map(({ sectionId }) => sectionId)),
106
+ )}`;
107
+
108
+ const sections = [
109
+ header,
110
+ ...consentStrings.map(({ consentString }) => consentString),
111
+ ];
112
+
113
+ return sections.join('~');
114
+ };
@@ -0,0 +1,49 @@
1
+ // Comment-out the sections that we do not implement as they aren't necessary
2
+ // for functionality.
3
+ export const SECTIONS = {
4
+ // tcfeuv1: 1,
5
+ tcfeuv2: 2,
6
+ // GPP header section is ID 3
7
+ // GPP signal integrity section is ID 4
8
+ tcfcav1: 5,
9
+ uspv1: 6,
10
+ // usnatv1: 7,
11
+ // uscav1: 8,
12
+ // usvav1: 9,
13
+ // uscov1: 10,
14
+ // usutv1: 11,
15
+ // usctv1: 12,
16
+ };
17
+
18
+ /**
19
+ * GPP's defined CMP status codes
20
+ * @enum {string}
21
+ */
22
+ export const CmpStatusCodes = {
23
+ STUB: 'stub',
24
+ LOADED: 'loaded',
25
+ ERROR: 'error',
26
+ };
27
+
28
+ /**
29
+ * GPP's defined CMP display status codes
30
+ * @enum {string}
31
+ */
32
+ export const CmpDisplayStatusCodes = {
33
+ VISIBLE: 'visible',
34
+ HIDDEN: 'hidden',
35
+ DISABLED: 'disabled',
36
+ };
37
+
38
+ /**
39
+ * The GPP API's events
40
+ * @enum {string}
41
+ */
42
+ export const EventNames = {
43
+ LISTENER_REGISTERED: 'listenerRegistered',
44
+ LISTENER_REMOVED: 'listenerRemoved',
45
+ CMP_STATUS_CHANGED: 'cmpStatus',
46
+ CMP_DISPLAY_STATUS_CHANGED: 'cmpDisplayStatus',
47
+ ERROR: 'error',
48
+ SECTION_CHANGED: 'sectionChange',
49
+ };
@@ -0,0 +1,89 @@
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/AbstractBase64UrlEncoder.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 { InvalidBase64UrlError, InvalidBitStringError } from './errors';
23
+ import {
24
+ decode as intDecode,
25
+ encode as intEncode,
26
+ } from './FixedIntegerEncoder';
27
+
28
+ /**
29
+ * Base 64 URL character set. Different from standard Base64 char set in that
30
+ * '+' and '/' are replaced with '-' and '_'.
31
+ */
32
+ const DICT = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
33
+ // prettier-ignore
34
+ const REVERSE_DICT: Record<string,number> = Object.freeze({
35
+ 0: 52, 1: 53, 2: 54, 3: 55, 4: 56, 5: 57, 6: 58, 7: 59, 8: 60, 9: 61, A: 0,
36
+ B: 1, C: 2, D: 3, E: 4, F: 5, G: 6, H: 7, I: 8, J: 9, K: 10, L: 11, M: 12,
37
+ N: 13, O: 14, P: 15, Q: 16, R: 17, S: 18, T: 19, U: 20, V: 21, W: 22, X: 23,
38
+ Y: 24, Z: 25, a: 26, b: 27, c: 28, d: 29, e: 30, f: 31, g: 32, h: 33, i: 34,
39
+ j: 35, k: 36, l: 37, m: 38, n: 39, o: 40, p: 41, q: 42, r: 43, s: 44, t: 45,
40
+ u: 46, v: 47, w: 48, x: 49, y: 50, z: 51, '-': 62, _: 63,
41
+ });
42
+
43
+ export const makeEncode =
44
+ (pad: (str: string) => string) => (bitString: string) => {
45
+ // should only be 0 or 1
46
+ if (!/^[01]*$/.test(bitString)) {
47
+ throw new InvalidBitStringError(bitString);
48
+ }
49
+
50
+ bitString = pad(bitString);
51
+
52
+ let str = '';
53
+
54
+ let index = 0;
55
+ while (index <= bitString.length - 6) {
56
+ const s = bitString.substring(index, index + 6);
57
+ const n = intDecode(s);
58
+ const c = DICT.charAt(n);
59
+ str += c;
60
+
61
+ index += 6;
62
+ }
63
+
64
+ return str;
65
+ };
66
+
67
+ export const decode = (str: string) => {
68
+ // should contain only characters from the base64url set
69
+ if (!/^[A-Za-z0-9\-_]*$/.test(str)) {
70
+ throw new InvalidBase64UrlError(str);
71
+ }
72
+
73
+ let bitString = '';
74
+
75
+ for (let i = 0; i < str.length; i++) {
76
+ const c = str.charAt(i);
77
+
78
+ const n = REVERSE_DICT[`${c}`]!;
79
+ const s = intEncode(n, 6);
80
+ bitString += s;
81
+ }
82
+
83
+ return bitString;
84
+ };
85
+
86
+ export default {
87
+ decode,
88
+ makeEncode,
89
+ };
@@ -0,0 +1,39 @@
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/BooleanEncoder.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
+ /**
23
+ * encode a TCString boolean
24
+ */
25
+ export const encode = (bool: boolean) => {
26
+ return bool ? '1' : '0';
27
+ };
28
+ /**
29
+ * decode a TCString boolean
30
+ */
31
+ export const decode = (bitString: string) => {
32
+ // fewer operations than !!parseInt(value, 2)
33
+ return bitString === '1';
34
+ };
35
+
36
+ export default {
37
+ decode,
38
+ encode,
39
+ };
@@ -0,0 +1,41 @@
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/CompressedBase64UrlEncoder.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, makeEncode } from './AbstractBase64UrlEncoder';
23
+
24
+ const pad = (bitString: string) => {
25
+ while (bitString.length % 8 > 0) {
26
+ bitString += '0';
27
+ }
28
+ while (bitString.length % 6 > 0) {
29
+ bitString += '0';
30
+ }
31
+ return bitString;
32
+ };
33
+
34
+ export const encode = makeEncode(pad);
35
+
36
+ export { decode } from './AbstractBase64UrlEncoder';
37
+
38
+ export default {
39
+ decode,
40
+ encode,
41
+ };
@@ -0,0 +1,46 @@
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/DatetimeEncoder.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 intDecode,
24
+ encode as intEncode,
25
+ } from './FixedIntegerEncoder';
26
+
27
+ export const encode = (date: Date | number, numBits: number = 36) => {
28
+ let deciseconds: number;
29
+ if (date instanceof Date) {
30
+ deciseconds = Math.round(date.getTime() / 100);
31
+ } else {
32
+ deciseconds = date;
33
+ }
34
+ return intEncode(deciseconds, numBits);
35
+ };
36
+
37
+ export const decode = (bitString: string) => {
38
+ const date = new Date(intDecode(bitString) * 100);
39
+
40
+ return date;
41
+ };
42
+
43
+ export default {
44
+ decode,
45
+ encode,
46
+ };