@osano/osano-cmp-react-native 0.8.0 → 0.9.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 (148) hide show
  1. package/lib/commonjs/services/consent.js +91 -28
  2. package/lib/commonjs/services/consent.js.map +1 -1
  3. package/lib/module/services/consent.js +90 -28
  4. package/lib/module/services/consent.js.map +1 -1
  5. package/lib/typescript/lib/commonjs/services/consent.d.ts +1 -0
  6. package/lib/typescript/lib/commonjs/services/consent.d.ts.map +1 -1
  7. package/lib/typescript/lib/module/services/consent.d.ts +1 -0
  8. package/lib/typescript/lib/module/services/consent.d.ts.map +1 -1
  9. package/lib/typescript/src/services/consent.d.ts +10 -4
  10. package/lib/typescript/src/services/consent.d.ts.map +1 -1
  11. package/package.json +17 -9
  12. package/src/services/consent.ts +135 -41
  13. package/lib/typescript/src/iab/gpp/api.d.ts +0 -28
  14. package/lib/typescript/src/iab/gpp/api.d.ts.map +0 -1
  15. package/lib/typescript/src/iab/gpp/consent.d.ts +0 -24
  16. package/lib/typescript/src/iab/gpp/consent.d.ts.map +0 -1
  17. package/lib/typescript/src/iab/gpp/constants.d.ts +0 -37
  18. package/lib/typescript/src/iab/gpp/constants.d.ts.map +0 -1
  19. package/lib/typescript/src/iab/gpp/encoders/AbstractBase64UrlEncoder.d.ts +0 -28
  20. package/lib/typescript/src/iab/gpp/encoders/AbstractBase64UrlEncoder.d.ts.map +0 -1
  21. package/lib/typescript/src/iab/gpp/encoders/BooleanEncoder.d.ts +0 -34
  22. package/lib/typescript/src/iab/gpp/encoders/BooleanEncoder.d.ts.map +0 -1
  23. package/lib/typescript/src/iab/gpp/encoders/CompressedBase64UrlEncoder.d.ts +0 -28
  24. package/lib/typescript/src/iab/gpp/encoders/CompressedBase64UrlEncoder.d.ts.map +0 -1
  25. package/lib/typescript/src/iab/gpp/encoders/DatetimeEncoder.d.ts +0 -28
  26. package/lib/typescript/src/iab/gpp/encoders/DatetimeEncoder.d.ts.map +0 -1
  27. package/lib/typescript/src/iab/gpp/encoders/EncodableOptimizedFixedRange.d.ts +0 -16
  28. package/lib/typescript/src/iab/gpp/encoders/EncodableOptimizedFixedRange.d.ts.map +0 -1
  29. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerEncoder.d.ts +0 -28
  30. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerEncoder.d.ts.map +0 -1
  31. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.d.ts +0 -28
  32. package/lib/typescript/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.d.ts.map +0 -1
  33. package/lib/typescript/src/iab/gpp/encoders/FixedBitfieldEncoder.d.ts +0 -28
  34. package/lib/typescript/src/iab/gpp/encoders/FixedBitfieldEncoder.d.ts.map +0 -1
  35. package/lib/typescript/src/iab/gpp/encoders/FixedIdBitMapEncoder.d.ts +0 -6
  36. package/lib/typescript/src/iab/gpp/encoders/FixedIdBitMapEncoder.d.ts.map +0 -1
  37. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerEncoder.d.ts +0 -28
  38. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerEncoder.d.ts.map +0 -1
  39. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerListEncoder.d.ts +0 -28
  40. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerListEncoder.d.ts.map +0 -1
  41. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerRangeEncoder.d.ts +0 -28
  42. package/lib/typescript/src/iab/gpp/encoders/FixedIntegerRangeEncoder.d.ts.map +0 -1
  43. package/lib/typescript/src/iab/gpp/encoders/FixedStringEncoder.d.ts +0 -26
  44. package/lib/typescript/src/iab/gpp/encoders/FixedStringEncoder.d.ts.map +0 -1
  45. package/lib/typescript/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.d.ts +0 -28
  46. package/lib/typescript/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.d.ts.map +0 -1
  47. package/lib/typescript/src/iab/gpp/encoders/errors.d.ts +0 -19
  48. package/lib/typescript/src/iab/gpp/encoders/errors.d.ts.map +0 -1
  49. package/lib/typescript/src/iab/gpp/encoders/index.d.ts +0 -16
  50. package/lib/typescript/src/iab/gpp/encoders/index.d.ts.map +0 -1
  51. package/lib/typescript/src/iab/gpp/encoders/types.d.ts +0 -5
  52. package/lib/typescript/src/iab/gpp/encoders/types.d.ts.map +0 -1
  53. package/lib/typescript/src/iab/gpp/index.d.ts +0 -10
  54. package/lib/typescript/src/iab/gpp/index.d.ts.map +0 -1
  55. package/lib/typescript/src/iab/gpp/reducer.d.ts +0 -6
  56. package/lib/typescript/src/iab/gpp/reducer.d.ts.map +0 -1
  57. package/lib/typescript/src/iab/gpp/selectors.d.ts +0 -6
  58. package/lib/typescript/src/iab/gpp/selectors.d.ts.map +0 -1
  59. package/lib/typescript/src/iab/gpp/types.d.ts +0 -3
  60. package/lib/typescript/src/iab/gpp/types.d.ts.map +0 -1
  61. package/lib/typescript/src/iab/gpp/v1/constants.d.ts +0 -9
  62. package/lib/typescript/src/iab/gpp/v1/constants.d.ts.map +0 -1
  63. package/lib/typescript/src/iab/gpp/v1/index.d.ts +0 -19
  64. package/lib/typescript/src/iab/gpp/v1/index.d.ts.map +0 -1
  65. package/lib/typescript/src/iab/usp/api.d.ts +0 -4
  66. package/lib/typescript/src/iab/usp/api.d.ts.map +0 -1
  67. package/lib/typescript/src/iab/usp/consent.d.ts +0 -13
  68. package/lib/typescript/src/iab/usp/consent.d.ts.map +0 -1
  69. package/lib/typescript/src/iab/usp/constants.d.ts +0 -77
  70. package/lib/typescript/src/iab/usp/constants.d.ts.map +0 -1
  71. package/lib/typescript/src/iab/usp/index.d.ts +0 -10
  72. package/lib/typescript/src/iab/usp/index.d.ts.map +0 -1
  73. package/lib/typescript/src/iab/usp/reducer.d.ts +0 -13
  74. package/lib/typescript/src/iab/usp/reducer.d.ts.map +0 -1
  75. package/lib/typescript/src/iab/usp/selectors.d.ts +0 -9
  76. package/lib/typescript/src/iab/usp/selectors.d.ts.map +0 -1
  77. package/lib/typescript/src/iab/usp/types.d.ts +0 -5
  78. package/lib/typescript/src/iab/usp/types.d.ts.map +0 -1
  79. package/lib/typescript/src/iab/usp/v1/constants.d.ts +0 -9
  80. package/lib/typescript/src/iab/usp/v1/constants.d.ts.map +0 -1
  81. package/lib/typescript/src/iab/usp/v1/index.d.ts +0 -16
  82. package/lib/typescript/src/iab/usp/v1/index.d.ts.map +0 -1
  83. package/lib/typescript/webdriverio-appium/common/commonCommands.d.ts +0 -21
  84. package/lib/typescript/webdriverio-appium/common/commonCommands.d.ts.map +0 -1
  85. package/lib/typescript/webdriverio-appium/config/wdio.conf.android.d.cts +0 -3
  86. package/lib/typescript/webdriverio-appium/config/wdio.conf.android.d.cts.map +0 -1
  87. package/lib/typescript/webdriverio-appium/config/wdio.conf.d.cts +0 -21
  88. package/lib/typescript/webdriverio-appium/config/wdio.conf.d.cts.map +0 -1
  89. package/lib/typescript/webdriverio-appium/config/wdio.conf.ios.d.cts +0 -3
  90. package/lib/typescript/webdriverio-appium/config/wdio.conf.ios.d.cts.map +0 -1
  91. package/lib/typescript/webdriverio-appium/test/android/six-drawer.d.ts +0 -2
  92. package/lib/typescript/webdriverio-appium/test/android/six-drawer.d.ts.map +0 -1
  93. package/lib/typescript/webdriverio-appium/test/ios/one.d.ts +0 -2
  94. package/lib/typescript/webdriverio-appium/test/ios/one.d.ts.map +0 -1
  95. package/lib/typescript/webdriverio-appium/test/ios/six.d.ts +0 -2
  96. package/lib/typescript/webdriverio-appium/test/ios/six.d.ts.map +0 -1
  97. package/lib/typescript/webdriverio-appium/test/ios/three.d.ts +0 -2
  98. package/lib/typescript/webdriverio-appium/test/ios/three.d.ts.map +0 -1
  99. package/lib/typescript/webdriverio-appium/test/ios/two-iab.d.ts +0 -2
  100. package/lib/typescript/webdriverio-appium/test/ios/two-iab.d.ts.map +0 -1
  101. package/lib/typescript/webdriverio-appium/test/ios/two.d.ts +0 -2
  102. package/lib/typescript/webdriverio-appium/test/ios/two.d.ts.map +0 -1
  103. package/lib/typescript/webdriverio-appium/test/one.d.ts +0 -2
  104. package/lib/typescript/webdriverio-appium/test/one.d.ts.map +0 -1
  105. package/lib/typescript/webdriverio-appium/test/six-iab.d.ts +0 -2
  106. package/lib/typescript/webdriverio-appium/test/six-iab.d.ts.map +0 -1
  107. package/lib/typescript/webdriverio-appium/test/three.d.ts +0 -2
  108. package/lib/typescript/webdriverio-appium/test/three.d.ts.map +0 -1
  109. package/lib/typescript/webdriverio-appium/test/two-iab.d.ts +0 -2
  110. package/lib/typescript/webdriverio-appium/test/two-iab.d.ts.map +0 -1
  111. package/lib/typescript/webdriverio-appium/test/two.d.ts +0 -2
  112. package/lib/typescript/webdriverio-appium/test/two.d.ts.map +0 -1
  113. package/src/iab/gpp/api.js +0 -253
  114. package/src/iab/gpp/consent.js +0 -114
  115. package/src/iab/gpp/constants.js +0 -49
  116. package/src/iab/gpp/encoders/AbstractBase64UrlEncoder.ts +0 -89
  117. package/src/iab/gpp/encoders/BooleanEncoder.ts +0 -39
  118. package/src/iab/gpp/encoders/CompressedBase64UrlEncoder.ts +0 -41
  119. package/src/iab/gpp/encoders/DatetimeEncoder.ts +0 -46
  120. package/src/iab/gpp/encoders/EncodableOptimizedFixedRange.ts +0 -213
  121. package/src/iab/gpp/encoders/FibonacciIntegerEncoder.ts +0 -81
  122. package/src/iab/gpp/encoders/FibonacciIntegerRangeEncoder.ts +0 -122
  123. package/src/iab/gpp/encoders/FixedBitfieldEncoder.ts +0 -59
  124. package/src/iab/gpp/encoders/FixedIdBitMapEncoder.ts +0 -30
  125. package/src/iab/gpp/encoders/FixedIntegerEncoder.ts +0 -61
  126. package/src/iab/gpp/encoders/FixedIntegerListEncoder.ts +0 -87
  127. package/src/iab/gpp/encoders/FixedIntegerRangeEncoder.ts +0 -102
  128. package/src/iab/gpp/encoders/FixedStringEncoder.ts +0 -74
  129. package/src/iab/gpp/encoders/LICENSE-IABTechLab +0 -176
  130. package/src/iab/gpp/encoders/TraditionalBase64UrlEncoder.ts +0 -38
  131. package/src/iab/gpp/encoders/errors.ts +0 -41
  132. package/src/iab/gpp/encoders/index.ts +0 -15
  133. package/src/iab/gpp/encoders/types.ts +0 -5
  134. package/src/iab/gpp/index.js +0 -9
  135. package/src/iab/gpp/reducer.js +0 -7
  136. package/src/iab/gpp/selectors.js +0 -21
  137. package/src/iab/gpp/types.ts +0 -3
  138. package/src/iab/gpp/v1/constants.js +0 -7
  139. package/src/iab/gpp/v1/index.js +0 -73
  140. package/src/iab/usp/api.js +0 -56
  141. package/src/iab/usp/consent.js +0 -150
  142. package/src/iab/usp/constants.js +0 -40
  143. package/src/iab/usp/index.js +0 -9
  144. package/src/iab/usp/reducer.js +0 -107
  145. package/src/iab/usp/selectors.js +0 -31
  146. package/src/iab/usp/types.ts +0 -4
  147. package/src/iab/usp/v1/constants.js +0 -10
  148. package/src/iab/usp/v1/index.js +0 -54
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=three.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"three.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/test/three.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=two-iab.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"two-iab.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/test/two-iab.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=two.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"two.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/test/two.js"],"names":[],"mappings":""}
@@ -1,253 +0,0 @@
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
- }
@@ -1,114 +0,0 @@
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
- };
@@ -1,49 +0,0 @@
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
- };
@@ -1,89 +0,0 @@
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
- };
@@ -1,39 +0,0 @@
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
- };
@@ -1,41 +0,0 @@
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
- };
@@ -1,46 +0,0 @@
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
- };