@osano/osano-cmp-react-native 0.8.0 → 0.10.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 (42) 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 +13 -9
  12. package/src/services/consent.ts +135 -41
  13. package/lib/typescript/webdriverio-appium/common/commonCommands.d.ts +0 -21
  14. package/lib/typescript/webdriverio-appium/common/commonCommands.d.ts.map +0 -1
  15. package/lib/typescript/webdriverio-appium/config/wdio.conf.android.d.cts +0 -3
  16. package/lib/typescript/webdriverio-appium/config/wdio.conf.android.d.cts.map +0 -1
  17. package/lib/typescript/webdriverio-appium/config/wdio.conf.d.cts +0 -21
  18. package/lib/typescript/webdriverio-appium/config/wdio.conf.d.cts.map +0 -1
  19. package/lib/typescript/webdriverio-appium/config/wdio.conf.ios.d.cts +0 -3
  20. package/lib/typescript/webdriverio-appium/config/wdio.conf.ios.d.cts.map +0 -1
  21. package/lib/typescript/webdriverio-appium/test/android/six-drawer.d.ts +0 -2
  22. package/lib/typescript/webdriverio-appium/test/android/six-drawer.d.ts.map +0 -1
  23. package/lib/typescript/webdriverio-appium/test/ios/one.d.ts +0 -2
  24. package/lib/typescript/webdriverio-appium/test/ios/one.d.ts.map +0 -1
  25. package/lib/typescript/webdriverio-appium/test/ios/six.d.ts +0 -2
  26. package/lib/typescript/webdriverio-appium/test/ios/six.d.ts.map +0 -1
  27. package/lib/typescript/webdriverio-appium/test/ios/three.d.ts +0 -2
  28. package/lib/typescript/webdriverio-appium/test/ios/three.d.ts.map +0 -1
  29. package/lib/typescript/webdriverio-appium/test/ios/two-iab.d.ts +0 -2
  30. package/lib/typescript/webdriverio-appium/test/ios/two-iab.d.ts.map +0 -1
  31. package/lib/typescript/webdriverio-appium/test/ios/two.d.ts +0 -2
  32. package/lib/typescript/webdriverio-appium/test/ios/two.d.ts.map +0 -1
  33. package/lib/typescript/webdriverio-appium/test/one.d.ts +0 -2
  34. package/lib/typescript/webdriverio-appium/test/one.d.ts.map +0 -1
  35. package/lib/typescript/webdriverio-appium/test/six-iab.d.ts +0 -2
  36. package/lib/typescript/webdriverio-appium/test/six-iab.d.ts.map +0 -1
  37. package/lib/typescript/webdriverio-appium/test/three.d.ts +0 -2
  38. package/lib/typescript/webdriverio-appium/test/three.d.ts.map +0 -1
  39. package/lib/typescript/webdriverio-appium/test/two-iab.d.ts +0 -2
  40. package/lib/typescript/webdriverio-appium/test/two-iab.d.ts.map +0 -1
  41. package/lib/typescript/webdriverio-appium/test/two.d.ts +0 -2
  42. package/lib/typescript/webdriverio-appium/test/two.d.ts.map +0 -1
@@ -3,16 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.recordConsent = exports.fetchConsent = exports.fetchConfig = exports.clearConsent = void 0;
6
+ exports.fetchConsent = exports.fetchConfig = exports.clearConsent = void 0;
7
+ exports.hashExtUsrData = hashExtUsrData;
8
+ exports.recordConsent = void 0;
7
9
  var _constants = require("../constants");
8
- var _reactNative = require("react-native");
10
+ var _OsanoCmp = require("../native/OsanoCmp");
9
11
  var _API = _interopRequireDefault(require("../utils/API"));
12
+ var _reactNative = require("react-native");
13
+ var _textEncoding = require("text-encoding");
10
14
  var _utils = require("../utils");
11
- var _OsanoCmp = require("../native/OsanoCmp");
15
+ var _jsSha = require("js-sha512");
12
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- // @ts-nocheck
14
- // file deepcode ignore DuplicateCaseBody: <please specify a reason of ignoring this>
15
-
17
+ const Buffer = require('buffer').Buffer;
16
18
  const {
17
19
  CONSENT_URI,
18
20
  LOOKUPS_URI,
@@ -34,7 +36,8 @@ function createConsentPayload(cmp, consent) {
34
36
  }).filter(([, value]) => value !== undefined));
35
37
  }
36
38
  function createConsentRecordPayload(cmp, consent) {
37
- const consentedCategories = consent ?? cmp.consent;
39
+ const consentedCategories = consent ?? cmp.consent ?? [];
40
+ const hashedExtUsrData = hashExtUsrData(cmp.customerId, cmp.configId, cmp.extUsrData);
38
41
  return Object.fromEntries(Object.entries({
39
42
  osnoCustomerId: cmp.customerId,
40
43
  osnoConfigId: cmp.configId,
@@ -42,7 +45,7 @@ function createConsentRecordPayload(cmp, consent) {
42
45
  consentingDomain: cmp.consentingDomain,
43
46
  consentingPlatform: `${_reactNative.Platform.OS}.react-native`,
44
47
  userConsentId: cmp.deviceId,
45
- extUsrData: cmp.extUsrData
48
+ extUsrData: hashedExtUsrData
46
49
  }).filter(([, value]) => value !== undefined));
47
50
  }
48
51
  const STORAGE_KEY = 'osano_consentmanager';
@@ -56,7 +59,9 @@ const storeConsent = async (cmp, consent) => {
56
59
  switch (_reactNative.Platform.OS) {
57
60
  case 'ios':
58
61
  case 'android':
59
- (0, _OsanoCmp.setStorage)(`${STORAGE_KEY}_${cmp.configId}`, JSON.stringify(cmp.consent)).then(resConsent).catch(reject);
62
+ (0, _OsanoCmp.setStorage)(`${STORAGE_KEY}_last_recorded_consent_date`, JSON.stringify(new Date())).then(() => {
63
+ (0, _OsanoCmp.setStorage)(`${STORAGE_KEY}_${cmp.configId}`, JSON.stringify(cmp.consent)).then(resConsent).catch(reject);
64
+ }).catch(reject);
60
65
  break;
61
66
  }
62
67
  });
@@ -74,7 +79,6 @@ const clearConsent = async cmp => {
74
79
  (0, _OsanoCmp.clearStorage)(`${STORAGE_KEY}_${cmp.configId}`).then(resConsent);
75
80
  break;
76
81
  default:
77
- window.localStorage.removeItem(`${STORAGE_KEY}_${cmp.configId}`);
78
82
  break;
79
83
  }
80
84
  });
@@ -104,11 +108,29 @@ const retrieveConsent = async cmp => {
104
108
  });
105
109
  break;
106
110
  default:
107
- try {
108
- resConsent(window.localStorage.getItem(`${STORAGE_KEY}_${cmp.configId}`));
109
- } catch (e) {
110
- clearConsent(cmp).then(resolve);
111
- }
111
+ break;
112
+ }
113
+ });
114
+ };
115
+ const retrieveLastConsentTimestamp = async () => {
116
+ return new Promise(resolve => {
117
+ const resValue = consentJson => {
118
+ if (consentJson) {
119
+ const timestamp = JSON.parse(consentJson);
120
+ resolve(timestamp);
121
+ return timestamp;
122
+ } else {
123
+ resolve('');
124
+ return '';
125
+ }
126
+ };
127
+ switch (_reactNative.Platform.OS) {
128
+ case 'ios':
129
+ case 'android':
130
+ (0, _OsanoCmp.getStorage)(`${STORAGE_KEY}_last_recorded_consent_date`).then(resValue);
131
+ break;
132
+ default:
133
+ // nothing
112
134
  break;
113
135
  }
114
136
  });
@@ -123,24 +145,65 @@ const recordConsent = (cmp, consent) => {
123
145
  });
124
146
  };
125
147
  exports.recordConsent = recordConsent;
126
- const fetchConsent = cmp => {
148
+ function hashExtUsrData(customerId, configId, extUsrData) {
149
+ if (extUsrData === '' || customerId === '' || configId === '') {
150
+ return '';
151
+ } else {
152
+ try {
153
+ const encoder = new _textEncoding.TextEncoder();
154
+ const data = encoder.encode(`${customerId}/${configId}/${extUsrData}`);
155
+ const hash = _jsSha.sha512.arrayBuffer(data);
156
+ const base64 = Buffer.from(hash).toString('base64');
157
+ const hashUrlSafe = base64.replace(/\+/g, '-').replace(/\//g, '_');
158
+ return hashUrlSafe;
159
+ } catch (error) {
160
+ // something went wrong
161
+ return '';
162
+ }
163
+ }
164
+ }
165
+ const fetchConsent = async cmp => {
127
166
  const {
128
167
  customerId,
129
168
  configId,
130
- extUsrData: userData
169
+ extUsrData
131
170
  } = cmp;
132
- return retrieveConsent(cmp).catch(() => {
133
- // Consent not found
134
- return _API.default.get(`${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${userData}/consent`).then(response => {
135
- const {
136
- consent
137
- } = response;
171
+ try {
172
+ const consent = await retrieveConsent(cmp);
173
+ const hashedUserData = hashExtUsrData(customerId, configId, extUsrData);
174
+
175
+ // No user data or remote consent disabled
176
+ if (hashedUserData === '' || cmp.config.remoteConsent === false) {
138
177
  return consent;
139
- }).then(consent => storeConsent(cmp, consent)).catch(() => {
140
- // Consent not found or network/server error
141
- return retrieveConsent(cmp);
142
- });
143
- });
178
+ }
179
+ const response = await _API.default.get(`${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${hashedUserData}/consent`);
180
+ const {
181
+ consented,
182
+ lastConsentTimestamp
183
+ } = response;
184
+ if (!consented || !lastConsentTimestamp) {
185
+ // No remote consent found, use local consent
186
+ await storeConsent(cmp, consent);
187
+ return consent;
188
+ }
189
+ const internalTimestamp = await retrieveLastConsentTimestamp();
190
+ try {
191
+ if (new Date(lastConsentTimestamp) > new Date(internalTimestamp) || internalTimestamp === '') {
192
+ // Remote consent is newer or we haven't recorded any consent yet. Store remote consent.
193
+ const remoteConsentCategories = consented.map(category => _constants.ConsentCategory[category]);
194
+ await storeConsent(cmp, remoteConsentCategories);
195
+ return remoteConsentCategories;
196
+ }
197
+ } catch (error) {
198
+ // Error parsing timestamp
199
+ }
200
+ return consent;
201
+ } catch (error) {
202
+ console.error('Error fetching consent:', error);
203
+ // Consent not found or network/server error.
204
+ const consent = await retrieveConsent(cmp);
205
+ return consent;
206
+ }
144
207
  };
145
208
  exports.fetchConsent = fetchConsent;
146
209
  const fetchConfig = (customerId, configId) => {
@@ -1 +1 @@
1
- {"version":3,"names":["_constants","require","_reactNative","_API","_interopRequireDefault","_utils","_OsanoCmp","e","__esModule","default","CONSENT_URI","LOOKUPS_URI","OSANO_ORIGIN","env","overrideConfig","variant","createConsentPayload","cmp","consent","Object","fromEntries","entries","customerId","configId","consented","consentingDomain","consentingPlatform","Platform","OS","deviceId","extUsrData","filter","value","undefined","createConsentRecordPayload","consentedCategories","osnoCustomerId","osnoConfigId","join","userConsentId","STORAGE_KEY","storeConsent","Promise","resolve","reject","resConsent","setStorage","JSON","stringify","then","catch","clearConsent","ConsentCategory","ESSENTIAL","clearStorage","window","localStorage","removeItem","exports","retrieveConsent","consentJson","parse","length","Error","getStorage","getItem","recordConsent","payload","API","post","referrer","consentCategories","error","fetchConsent","userData","get","response","fetchConfig","headers","json","merge","country","region","gdprApplies"],"sourceRoot":"../../../src","sources":["services/consent.ts"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,MAAA,GAAAJ,OAAA;AAKA,IAAAK,SAAA,GAAAL,OAAA;AAA0E,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAb1E;AACA;;AAcA,MAAM;EAAEG,WAAW;EAAEC,WAAW;EAAEC;AAAa,CAAC,GAAGC,cAAG;AAEtD,MAAMC,cAA+B,GAAG;EACvC;EACAC,OAAO,EAAE;AACV,CAAC;AAsBD,SAASC,oBAAoBA,CAC5BC,GAAmB,EACnBC,OAA+B,EACd;EACjB,OAAOC,MAAM,CAACC,WAAW,CACxBD,MAAM,CAACE,OAAO,CAAC;IACdC,UAAU,EAAEL,GAAG,CAACK,UAAU;IAC1BC,QAAQ,EAAEN,GAAG,CAACM,QAAQ;IACtBC,SAAS,EAAEN,OAAO,IAAID,GAAG,CAACC,OAAO;IACjCO,gBAAgB,EAAER,GAAG,CAACQ,gBAAgB;IACtCC,kBAAkB,EAAE,GAAGC,qBAAQ,CAACC,EAAE,eAAe;IACjDC,QAAQ,EAAEZ,GAAG,CAACY,QAAQ;IACtBC,UAAU,EAAEb,GAAG,CAACa;EACjB,CAAC,CAAC,CAACC,MAAM,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IACtD,CAAC,EACD7D,cACD,CAAC;EACF,CAAC,CAAC,CACDoC,KAAK,CAAC,MAAM;IACZ;IACA,OAAO,IAAI;EACZ,CAAC,CAAC;AACJ,CAAC;AAACQ,OAAA,CAAAmB,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {"version":3,"names":["_constants","require","_OsanoCmp","_API","_interopRequireDefault","_reactNative","_textEncoding","_utils","_jsSha","e","__esModule","default","Buffer","CONSENT_URI","LOOKUPS_URI","OSANO_ORIGIN","env","overrideConfig","variant","createConsentPayload","cmp","consent","Object","fromEntries","entries","customerId","configId","consented","consentingDomain","consentingPlatform","Platform","OS","deviceId","extUsrData","filter","value","undefined","createConsentRecordPayload","consentedCategories","hashedExtUsrData","hashExtUsrData","osnoCustomerId","osnoConfigId","join","userConsentId","STORAGE_KEY","storeConsent","Promise","resolve","reject","resConsent","setStorage","JSON","stringify","Date","then","catch","clearConsent","ConsentCategory","ESSENTIAL","clearStorage","exports","retrieveConsent","consentJson","parse","length","Error","getStorage","retrieveLastConsentTimestamp","resValue","timestamp","recordConsent","payload","API","post","referrer","consentCategories","error","encoder","TextEncoder","data","encode","hash","sha512","arrayBuffer","base64","from","toString","hashUrlSafe","replace","fetchConsent","hashedUserData","config","remoteConsent","response","get","lastConsentTimestamp","internalTimestamp","remoteConsentCategories","map","category","ConsentCategoryType","console","fetchConfig","headers","json","merge","country","region","gdprApplies"],"sourceRoot":"../../../src","sources":["services/consent.ts"],"mappings":";;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAAmC,SAAAG,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD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,IAAI;MACPE,OAAO,EAAEH,OAAO,CAACT,GAAG,CAAC,iBAAiB,CAAC;MACvCa,MAAM,EAAEJ,OAAO,CAACT,GAAG,CAAC,gBAAgB,CAAC;MACrC7E,OAAO,EAAEsF,OAAO,CAACT,GAAG,CAAC,iBAAiB,CAAC;MACvCc,WAAW,EAAEL,OAAO,CAACT,GAAG,CAAC,sBAAsB,CAAC,KAAK;IACtD,CAAC,EACD9E,cACD,CAAC;EACF,CAAC,CAAC,CACDuC,KAAK,CAAC,MAAM;IACZ;IACA,OAAO,IAAI;EACZ,CAAC,CAAC;AACJ,CAAC;AAACK,OAAA,CAAA0C,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1,11 +1,12 @@
1
- // @ts-nocheck
2
- // file deepcode ignore DuplicateCaseBody: <please specify a reason of ignoring this>
3
- import { env } from '../constants';
4
- import { Platform } from 'react-native';
1
+ import { ConsentCategory, ConsentCategory as ConsentCategoryType } from '../constants';
2
+ import { clearStorage, getStorage, setStorage } from '../native/OsanoCmp';
5
3
  import API from '../utils/API';
4
+ import { Platform } from 'react-native';
5
+ import { TextEncoder } from 'text-encoding';
6
+ import { env } from '../constants';
6
7
  import { merge } from '../utils';
7
- import { ConsentCategory } from '../constants';
8
- import { clearStorage, getStorage, setStorage } from '../native/OsanoCmp';
8
+ import { sha512 } from 'js-sha512';
9
+ const Buffer = require('buffer').Buffer;
9
10
  const {
10
11
  CONSENT_URI,
11
12
  LOOKUPS_URI,
@@ -27,7 +28,8 @@ function createConsentPayload(cmp, consent) {
27
28
  }).filter(([, value]) => value !== undefined));
28
29
  }
29
30
  function createConsentRecordPayload(cmp, consent) {
30
- const consentedCategories = consent ?? cmp.consent;
31
+ const consentedCategories = consent ?? cmp.consent ?? [];
32
+ const hashedExtUsrData = hashExtUsrData(cmp.customerId, cmp.configId, cmp.extUsrData);
31
33
  return Object.fromEntries(Object.entries({
32
34
  osnoCustomerId: cmp.customerId,
33
35
  osnoConfigId: cmp.configId,
@@ -35,7 +37,7 @@ function createConsentRecordPayload(cmp, consent) {
35
37
  consentingDomain: cmp.consentingDomain,
36
38
  consentingPlatform: `${Platform.OS}.react-native`,
37
39
  userConsentId: cmp.deviceId,
38
- extUsrData: cmp.extUsrData
40
+ extUsrData: hashedExtUsrData
39
41
  }).filter(([, value]) => value !== undefined));
40
42
  }
41
43
  const STORAGE_KEY = 'osano_consentmanager';
@@ -49,7 +51,9 @@ const storeConsent = async (cmp, consent) => {
49
51
  switch (Platform.OS) {
50
52
  case 'ios':
51
53
  case 'android':
52
- setStorage(`${STORAGE_KEY}_${cmp.configId}`, JSON.stringify(cmp.consent)).then(resConsent).catch(reject);
54
+ setStorage(`${STORAGE_KEY}_last_recorded_consent_date`, JSON.stringify(new Date())).then(() => {
55
+ setStorage(`${STORAGE_KEY}_${cmp.configId}`, JSON.stringify(cmp.consent)).then(resConsent).catch(reject);
56
+ }).catch(reject);
53
57
  break;
54
58
  }
55
59
  });
@@ -67,7 +71,6 @@ export const clearConsent = async cmp => {
67
71
  clearStorage(`${STORAGE_KEY}_${cmp.configId}`).then(resConsent);
68
72
  break;
69
73
  default:
70
- window.localStorage.removeItem(`${STORAGE_KEY}_${cmp.configId}`);
71
74
  break;
72
75
  }
73
76
  });
@@ -96,11 +99,29 @@ const retrieveConsent = async cmp => {
96
99
  });
97
100
  break;
98
101
  default:
99
- try {
100
- resConsent(window.localStorage.getItem(`${STORAGE_KEY}_${cmp.configId}`));
101
- } catch (e) {
102
- clearConsent(cmp).then(resolve);
103
- }
102
+ break;
103
+ }
104
+ });
105
+ };
106
+ const retrieveLastConsentTimestamp = async () => {
107
+ return new Promise(resolve => {
108
+ const resValue = consentJson => {
109
+ if (consentJson) {
110
+ const timestamp = JSON.parse(consentJson);
111
+ resolve(timestamp);
112
+ return timestamp;
113
+ } else {
114
+ resolve('');
115
+ return '';
116
+ }
117
+ };
118
+ switch (Platform.OS) {
119
+ case 'ios':
120
+ case 'android':
121
+ getStorage(`${STORAGE_KEY}_last_recorded_consent_date`).then(resValue);
122
+ break;
123
+ default:
124
+ // nothing
104
125
  break;
105
126
  }
106
127
  });
@@ -114,24 +135,65 @@ export const recordConsent = (cmp, consent) => {
114
135
  throw error;
115
136
  });
116
137
  };
117
- export const fetchConsent = cmp => {
138
+ export function hashExtUsrData(customerId, configId, extUsrData) {
139
+ if (extUsrData === '' || customerId === '' || configId === '') {
140
+ return '';
141
+ } else {
142
+ try {
143
+ const encoder = new TextEncoder();
144
+ const data = encoder.encode(`${customerId}/${configId}/${extUsrData}`);
145
+ const hash = sha512.arrayBuffer(data);
146
+ const base64 = Buffer.from(hash).toString('base64');
147
+ const hashUrlSafe = base64.replace(/\+/g, '-').replace(/\//g, '_');
148
+ return hashUrlSafe;
149
+ } catch (error) {
150
+ // something went wrong
151
+ return '';
152
+ }
153
+ }
154
+ }
155
+ export const fetchConsent = async cmp => {
118
156
  const {
119
157
  customerId,
120
158
  configId,
121
- extUsrData: userData
159
+ extUsrData
122
160
  } = cmp;
123
- return retrieveConsent(cmp).catch(() => {
124
- // Consent not found
125
- return API.get(`${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${userData}/consent`).then(response => {
126
- const {
127
- consent
128
- } = response;
161
+ try {
162
+ const consent = await retrieveConsent(cmp);
163
+ const hashedUserData = hashExtUsrData(customerId, configId, extUsrData);
164
+
165
+ // No user data or remote consent disabled
166
+ if (hashedUserData === '' || cmp.config.remoteConsent === false) {
129
167
  return consent;
130
- }).then(consent => storeConsent(cmp, consent)).catch(() => {
131
- // Consent not found or network/server error
132
- return retrieveConsent(cmp);
133
- });
134
- });
168
+ }
169
+ const response = await API.get(`${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${hashedUserData}/consent`);
170
+ const {
171
+ consented,
172
+ lastConsentTimestamp
173
+ } = response;
174
+ if (!consented || !lastConsentTimestamp) {
175
+ // No remote consent found, use local consent
176
+ await storeConsent(cmp, consent);
177
+ return consent;
178
+ }
179
+ const internalTimestamp = await retrieveLastConsentTimestamp();
180
+ try {
181
+ if (new Date(lastConsentTimestamp) > new Date(internalTimestamp) || internalTimestamp === '') {
182
+ // Remote consent is newer or we haven't recorded any consent yet. Store remote consent.
183
+ const remoteConsentCategories = consented.map(category => ConsentCategoryType[category]);
184
+ await storeConsent(cmp, remoteConsentCategories);
185
+ return remoteConsentCategories;
186
+ }
187
+ } catch (error) {
188
+ // Error parsing timestamp
189
+ }
190
+ return consent;
191
+ } catch (error) {
192
+ console.error('Error fetching consent:', error);
193
+ // Consent not found or network/server error.
194
+ const consent = await retrieveConsent(cmp);
195
+ return consent;
196
+ }
135
197
  };
136
198
  export const fetchConfig = (customerId, configId) => {
137
199
  return API.get(`${OSANO_ORIGIN}/${customerId}/${configId}/config.json`, true).then(response => {
@@ -1 +1 @@
1
- {"version":3,"names":["env","Platform","API","merge","ConsentCategory","clearStorage","getStorage","setStorage","CONSENT_URI","LOOKUPS_URI","OSANO_ORIGIN","overrideConfig","variant","createConsentPayload","cmp","consent","Object","fromEntries","entries","customerId","configId","consented","consentingDomain","consentingPlatform","OS","deviceId","extUsrData","filter","value","undefined","createConsentRecordPayload","consentedCategories","osnoCustomerId","osnoConfigId","join","userConsentId","STORAGE_KEY","storeConsent","Promise","resolve","reject","resConsent","JSON","stringify","then","catch","clearConsent","ESSENTIAL","window","localStorage","removeItem","retrieveConsent","consentJson","parse","length","Error","getItem","e","recordConsent","payload","post","referrer","consentCategories","error","fetchConsent","userData","get","response","fetchConfig","headers","json","country","region","gdprApplies"],"sourceRoot":"../../../src","sources":["services/consent.ts"],"mappings":"AAAA;AACA;AACA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,QAAQ,QAAQ,cAAc;AAEvC,OAAOC,GAAG,MAAM,cAAc;AAG9B,SAASC,KAAK,QAAQ,UAAU;AAChC,SAECC,eAAe,QACT,cAAc;AACrB,SAASC,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAQ,oBAAoB;AAEzE,MAAM;EAAEC,WAAW;EAAEC,WAAW;EAAEC;AAA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,cAAc,EAAE,IAAI,CAAC,CAC3EwB,IAAI,CAAEuB,QAAQ,IAAK;IACnB,MAAM;MAAEE,OAAO;MAAEC;IAAK,CAAC,GAAGH,QAGzB;IACD,OAAOhE,KAAK,CACX;MACC,GAAGmE,IAAI;MACPC,OAAO,EAAEF,OAAO,CAACH,GAAG,CAAC,iBAAiB,CAAC;MACvCM,MAAM,EAAEH,OAAO,CAACH,GAAG,CAAC,gBAAgB,CAAC;MACrCtD,OAAO,EAAEyD,OAAO,CAACH,GAAG,CAAC,iBAAiB,CAAC;MACvCO,WAAW,EAAEJ,OAAO,CAACH,GAAG,CAAC,sBAAsB,CAAC,KAAK;IACtD,CAAC,EACDvD,cACD,CAAC;EACF,CAAC,CAAC,CACDkC,KAAK,CAAC,MAAM;IACZ;IACA,OAAO,IAAI;EACZ,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["ConsentCategory","ConsentCategoryType","clearStorage","getStorage","setStorage","API","Platform","TextEncoder","env","merge","sha512","Buffer","require","CONSENT_URI","LOOKUPS_URI","OSANO_ORIGIN","overrideConfig","variant","createConsentPayload","cmp","consent","Object","fromEntries","entries","customerId","configId","consented","consentingDomain","consentingPlatform","OS","deviceId","extUsrData","filter","value","undefined","createConsentRecordPayload","consentedCategories","hashedExtUsrData","hashExtUsrData","osnoCustomerId","osnoConfigId","join","userConsentId","STORAGE_KEY","storeConsent","Promise","resolve","reject","resConsent","JSON","stringify","Date","then","catch","clearConsent","ESSENTIAL","retrieveConsent","consentJson","parse","length","Error","retrieveLastConsentTimestamp","resValue","timestamp","recordConsent","payload","post","referrer","consentCategories","error","encoder","data","encode","hash","arrayBuffer","base64","from","toString","hashUrlSafe","replace","fetchConsent","hashedUserData","config","remoteConsent","response","get","lastConsentTimestamp","internalTimestamp","remoteConsentCategories","map","category","console","fetchConfig","headers","json","country","region","gdprApplies"],"sourceRoot":"../../../src","sources":["services/consent.ts"],"mappings":"AAAA,SACCA,eAAe,EACfA,eAAe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AI,CAAEgC,QAAQ,IAAK;IACnB,MAAM;MAAES,OAAO;MAAEC;IAAK,CAAC,GAAGV,QAGzB;IACD,OAAO3E,KAAK,CACX;MACC,GAAGqF,IAAI;MACPC,OAAO,EAAEF,OAAO,CAACR,GAAG,CAAC,iBAAiB,CAAC;MACvCW,MAAM,EAAEH,OAAO,CAACR,GAAG,CAAC,gBAAgB,CAAC;MACrCpE,OAAO,EAAE4E,OAAO,CAACR,GAAG,CAAC,iBAAiB,CAAC;MACvCY,WAAW,EAAEJ,OAAO,CAACR,GAAG,CAAC,sBAAsB,CAAC,KAAK;IACtD,CAAC,EACDrE,cACD,CAAC;EACF,CAAC,CAAC,CACDqC,KAAK,CAAC,MAAM;IACZ;IACA,OAAO,IAAI;EACZ,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  export const __esModule: boolean;
2
+ export function hashExtUsrData(customerId: any, configId: any, extUsrData: any): string;
2
3
  export function clearConsent(cmp: any): Promise<any>;
3
4
  export function recordConsent(cmp: any, consent: any): any;
4
5
  export function fetchConsent(cmp: any): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../commonjs/services/consent.js"],"names":[],"mappings":";AA+DA,qDAiBC;AAmCD,2DAQC;AAED,qDAkBC;AAED,iEAiBC"}
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../commonjs/services/consent.js"],"names":[],"mappings":";AAmJA,wFAgBC;AA/FD,qDAgBC;AAqDD,2DAQC;AAmBD,qDA0CC;AAED,iEAiBC"}
@@ -1,3 +1,4 @@
1
+ export function hashExtUsrData(customerId: any, configId: any, extUsrData: any): string;
1
2
  export function clearConsent(cmp: any): Promise<any>;
2
3
  export function recordConsent(cmp: any, consent: any): Promise<any>;
3
4
  export function fetchConsent(cmp: any): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../module/services/consent.js"],"names":[],"mappings":"AAwDO,qDAiBN;AAkCM,oEAQN;AACM,qDAkBN;AACM,0EAiBN"}
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../module/services/consent.js"],"names":[],"mappings":"AAyIA,wFAgBC;AA7FM,qDAgBN;AAoDM,oEAQN;AAkBM,qDA0CN;AACM,0EAiBN"}
@@ -1,6 +1,6 @@
1
+ import { ConsentCategory, ConsentCategory as ConsentCategoryType } from '../constants';
1
2
  import type { Config } from '../types/consent-config';
2
3
  import type { ConsentManager } from '../ConsentManager';
3
- import { type ConsentCategory as ConsentCategoryType } from '../constants';
4
4
  export type ConsentPayload = {
5
5
  customerId: string;
6
6
  configId: string;
@@ -19,8 +19,14 @@ export type ConsentRecordPayload = {
19
19
  userConsentId: string;
20
20
  extUsrData?: string;
21
21
  };
22
- export declare const clearConsent: (cmp: ConsentManager) => Promise<ConsentCategoryType[]>;
23
- export declare const recordConsent: (cmp: ConsentManager, consent?: ConsentCategoryType[]) => Promise<ConsentCategoryType[]>;
24
- export declare const fetchConsent: (cmp: ConsentManager) => Promise<ConsentCategoryType[]>;
22
+ export type ConsentLookupResponseType = {
23
+ consented: string[];
24
+ lastConsentTimestamp: string;
25
+ userConsentId: string;
26
+ };
27
+ export declare const clearConsent: (cmp: ConsentManager) => Promise<ConsentCategory[]>;
28
+ export declare const recordConsent: (cmp: ConsentManager, consent?: ConsentCategoryType[]) => Promise<ConsentCategory[]>;
29
+ export declare function hashExtUsrData(customerId: string, configId: string, extUsrData: string): string;
30
+ export declare const fetchConsent: (cmp: ConsentManager) => Promise<ConsentCategory[]>;
25
31
  export declare const fetchConfig: (customerId: string, configId: string) => Promise<Config | null>;
26
32
  //# sourceMappingURL=consent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../../../../src/services/consent.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KA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;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACvC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;CACtB,CAAC;AA2EF,eAAO,MAAM,YAAY,QAAe,cAAc,+BAgBrD,CAAC;AAyDF,eAAO,MAAM,aAAa,QACpB,cAAc,YACT,mBAAmB,EAAE,+BAY/B,CAAC;AAEF,wBAAgB,cAAc,CAC7B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GAChB,MAAM,CAgBR;AAED,eAAO,MAAM,YAAY,QAAe,cAAc,+BAmDrD,CAAC;AAEF,eAAO,MAAM,WAAW,eAAgB,MAAM,YAAY,MAAM,2BAsB/D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osano/osano-cmp-react-native",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Package and example for the react-native Osano CMP SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -23,11 +23,15 @@
23
23
  "!**/__tests__",
24
24
  "!**/__fixtures__",
25
25
  "!**/__mocks__",
26
- "!**/.*"
26
+ "!**/.*",
27
+ "!lib/typescript/webdriverio-appium/**",
28
+ "!lib/typescript/webdriverio-appium/common/**",
29
+ "!lib/typescript/webdriverio-appium/config/**",
30
+ "!lib/typescript/webdriverio-appium/test/**"
27
31
  ],
28
32
  "scripts": {
29
33
  "example": "yarn workspace osano-cmp-sdk-example",
30
- "test": "jest ./src/__tests__/index.test.ts",
34
+ "test": "jest src/services/__tests__/consent.test.ts src/__tests__/index.test.tsx",
31
35
  "typecheck": "tsc --noEmit",
32
36
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
37
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
@@ -65,17 +69,20 @@
65
69
  "@docusaurus/module-type-aliases": "3.5.2",
66
70
  "@docusaurus/preset-classic": "3.5.2",
67
71
  "@mdx-js/react": "^3.0.1",
72
+ "@testing-library/react-native": "^12.8.1",
68
73
  "@types/jest": "^29.5.5",
69
74
  "@types/react": "^18.2.44",
75
+ "@types/react-test-renderer": "^18.3.0",
76
+ "@types/text-encoding": "^0.0.39",
70
77
  "commitlint": "^17.0.2",
71
78
  "del-cli": "^5.1.0",
72
79
  "jest": "^29.7.0",
73
80
  "prettier": "^3.0.3",
74
81
  "prism-react-renderer": "^2.4.0",
75
82
  "react": "18.3.1",
76
- "react-dom": "18.3.1",
77
83
  "react-native": "0.74.4",
78
84
  "react-native-builder-bob": "^0.23.2",
85
+ "react-test-renderer": "^18.3.1",
79
86
  "release-it": "^17.6.0",
80
87
  "turbo": "^1.10.7",
81
88
  "typescript": "^5.2.2"
@@ -131,12 +138,9 @@
131
138
  ]
132
139
  },
133
140
  "dependencies": {
134
- "@testing-library/react-native": "^12.5.0",
135
- "@types/react-test-renderer": "^18.3.0",
136
- "react": "*",
137
- "react-dom": "^17.0.2",
141
+ "js-sha512": "^0.9.0",
138
142
  "react-native-picker-modal-view": "^1.3.2",
139
143
  "react-native-svg": "^15.1.0",
140
- "react-test-renderer": "^18.3.1"
144
+ "text-encoding": "^0.7.0"
141
145
  }
142
146
  }
@@ -1,17 +1,19 @@
1
- // @ts-nocheck
2
- // file deepcode ignore DuplicateCaseBody: <please specify a reason of ignoring this>
3
- import { env } from '../constants';
4
- import { Platform } from 'react-native';
1
+ import {
2
+ ConsentCategory,
3
+ ConsentCategory as ConsentCategoryType,
4
+ } from '../constants';
5
+ import { clearStorage, getStorage, setStorage } from '../native/OsanoCmp';
5
6
 
6
7
  import API from '../utils/API';
7
8
  import type { Config } from '../types/consent-config';
8
9
  import type { ConsentManager } from '../ConsentManager';
10
+ import { Platform } from 'react-native';
11
+ import { TextEncoder } from 'text-encoding';
12
+ import { env } from '../constants';
9
13
  import { merge } from '../utils';
10
- import {
11
- type ConsentCategory as ConsentCategoryType,
12
- ConsentCategory,
13
- } from '../constants';
14
- import { clearStorage, getStorage, setStorage } from '../native/OsanoCmp';
14
+ import { sha512 } from 'js-sha512';
15
+
16
+ const Buffer = require('buffer').Buffer;
15
17
 
16
18
  const { CONSENT_URI, LOOKUPS_URI, OSANO_ORIGIN } = env;
17
19
 
@@ -40,6 +42,12 @@ export type ConsentRecordPayload = {
40
42
  extUsrData?: string;
41
43
  };
42
44
 
45
+ export type ConsentLookupResponseType = {
46
+ consented: string[];
47
+ lastConsentTimestamp: string;
48
+ userConsentId: string;
49
+ };
50
+
43
51
  function createConsentPayload(
44
52
  cmp: ConsentManager,
45
53
  consent?: ConsentCategoryType[],
@@ -60,8 +68,13 @@ function createConsentPayload(
60
68
  function createConsentRecordPayload(
61
69
  cmp: ConsentManager,
62
70
  consent?: ConsentCategoryType[],
63
- ): ConsentRecordPayload{
64
- const consentedCategories = consent ?? cmp.consent
71
+ ): ConsentRecordPayload {
72
+ const consentedCategories = consent ?? cmp.consent ?? [];
73
+ const hashedExtUsrData = hashExtUsrData(
74
+ cmp.customerId,
75
+ cmp.configId,
76
+ cmp.extUsrData,
77
+ );
65
78
  return Object.fromEntries(
66
79
  Object.entries({
67
80
  osnoCustomerId: cmp.customerId,
@@ -70,7 +83,7 @@ function createConsentRecordPayload(
70
83
  consentingDomain: cmp.consentingDomain,
71
84
  consentingPlatform: `${Platform.OS}.react-native`,
72
85
  userConsentId: cmp.deviceId,
73
- extUsrData: cmp.extUsrData,
86
+ extUsrData: hashedExtUsrData,
74
87
  }).filter(([, value]) => value !== undefined),
75
88
  ) as ConsentRecordPayload;
76
89
  }
@@ -91,10 +104,17 @@ const storeConsent = async (
91
104
  case 'ios':
92
105
  case 'android':
93
106
  setStorage(
94
- `${STORAGE_KEY}_${cmp.configId}`,
95
- JSON.stringify(cmp.consent),
107
+ `${STORAGE_KEY}_last_recorded_consent_date`,
108
+ JSON.stringify(new Date()),
96
109
  )
97
- .then(resConsent)
110
+ .then(() => {
111
+ setStorage(
112
+ `${STORAGE_KEY}_${cmp.configId}`,
113
+ JSON.stringify(cmp.consent),
114
+ )
115
+ .then(resConsent)
116
+ .catch(reject);
117
+ })
98
118
  .catch(reject);
99
119
  break;
100
120
  }
@@ -114,7 +134,6 @@ export const clearConsent = async (cmp: ConsentManager) => {
114
134
  clearStorage(`${STORAGE_KEY}_${cmp.configId}`).then(resConsent);
115
135
  break;
116
136
  default:
117
- window.localStorage.removeItem(`${STORAGE_KEY}_${cmp.configId}`);
118
137
  break;
119
138
  }
120
139
  });
@@ -146,13 +165,30 @@ const retrieveConsent = async (cmp: ConsentManager) => {
146
165
  });
147
166
  break;
148
167
  default:
149
- try {
150
- resConsent(
151
- window.localStorage.getItem(`${STORAGE_KEY}_${cmp.configId}`),
152
- );
153
- } catch (e) {
154
- clearConsent(cmp).then(resolve);
155
- }
168
+ break;
169
+ }
170
+ });
171
+ };
172
+
173
+ const retrieveLastConsentTimestamp = async () => {
174
+ return new Promise<string>((resolve) => {
175
+ const resValue = (consentJson: string | null | undefined) => {
176
+ if (consentJson) {
177
+ const timestamp = JSON.parse(consentJson);
178
+ resolve(timestamp);
179
+ return timestamp;
180
+ } else {
181
+ resolve('');
182
+ return '';
183
+ }
184
+ };
185
+ switch (Platform.OS) {
186
+ case 'ios':
187
+ case 'android':
188
+ getStorage(`${STORAGE_KEY}_last_recorded_consent_date`).then(resValue);
189
+ break;
190
+ default:
191
+ // nothing
156
192
  break;
157
193
  }
158
194
  });
@@ -163,7 +199,9 @@ export const recordConsent = (
163
199
  consent?: ConsentCategoryType[],
164
200
  ) => {
165
201
  const payload = createConsentRecordPayload(cmp, consent);
166
- return API.post(`${CONSENT_URI}/record`, payload, {referrer: cmp.consentingDomain})
202
+ return API.post(`${CONSENT_URI}/record`, payload, {
203
+ referrer: cmp.consentingDomain,
204
+ })
167
205
  .then(() => consent ?? cmp.consent)
168
206
  .then((consentCategories) => storeConsent(cmp, consentCategories))
169
207
  .catch((error) => {
@@ -172,23 +210,79 @@ export const recordConsent = (
172
210
  });
173
211
  };
174
212
 
175
- export const fetchConsent = (cmp: ConsentManager) => {
176
- const { customerId, configId, extUsrData: userData } = cmp;
177
- return retrieveConsent(cmp).catch(() => {
178
- // Consent not found
179
- return API.get(
180
- `${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${userData}/consent`,
181
- )
182
- .then((response) => {
183
- const { consent } = response as { consent: ConsentCategoryType[] };
184
- return consent;
185
- })
186
- .then((consent) => storeConsent(cmp, consent))
187
- .catch(() => {
188
- // Consent not found or network/server error
189
- return retrieveConsent(cmp);
190
- });
191
- });
213
+ export function hashExtUsrData(
214
+ customerId: string,
215
+ configId: string,
216
+ extUsrData: string,
217
+ ): string {
218
+ if (extUsrData === '' || customerId === '' || configId === '') {
219
+ return '';
220
+ } else {
221
+ try {
222
+ const encoder = new TextEncoder();
223
+ const data = encoder.encode(`${customerId}/${configId}/${extUsrData}`);
224
+ const hash = sha512.arrayBuffer(data);
225
+ const base64 = Buffer.from(hash).toString('base64');
226
+ const hashUrlSafe = base64.replace(/\+/g, '-').replace(/\//g, '_');
227
+ return hashUrlSafe;
228
+ } catch (error) {
229
+ // something went wrong
230
+ return '';
231
+ }
232
+ }
233
+ }
234
+
235
+ export const fetchConsent = async (cmp: ConsentManager) => {
236
+ const { customerId, configId, extUsrData } = cmp;
237
+
238
+ try {
239
+ const consent = await retrieveConsent(cmp);
240
+
241
+ const hashedUserData = hashExtUsrData(customerId, configId, extUsrData);
242
+
243
+ // No user data or remote consent disabled
244
+ if (hashedUserData === '' || cmp.config.remoteConsent === false) {
245
+ return consent;
246
+ }
247
+
248
+ const response = await API.get(
249
+ `${LOOKUPS_URI}/customer/${customerId}/config/${configId}/user/${hashedUserData}/consent`,
250
+ );
251
+
252
+ const { consented, lastConsentTimestamp } =
253
+ response as ConsentLookupResponseType;
254
+
255
+ if (!consented || !lastConsentTimestamp) {
256
+ // No remote consent found, use local consent
257
+ await storeConsent(cmp, consent);
258
+ return consent;
259
+ }
260
+
261
+ const internalTimestamp = await retrieveLastConsentTimestamp();
262
+ try {
263
+ if (
264
+ new Date(lastConsentTimestamp) > new Date(internalTimestamp) ||
265
+ internalTimestamp === ''
266
+ ) {
267
+ // Remote consent is newer or we haven't recorded any consent yet. Store remote consent.
268
+ const remoteConsentCategories = consented.map(
269
+ (category) =>
270
+ ConsentCategoryType[category as keyof typeof ConsentCategoryType],
271
+ );
272
+ await storeConsent(cmp, remoteConsentCategories);
273
+ return remoteConsentCategories;
274
+ }
275
+ } catch (error) {
276
+ // Error parsing timestamp
277
+ }
278
+
279
+ return consent;
280
+ } catch (error) {
281
+ console.error('Error fetching consent:', error);
282
+ // Consent not found or network/server error.
283
+ const consent = await retrieveConsent(cmp);
284
+ return consent;
285
+ }
192
286
  };
193
287
 
194
288
  export const fetchConfig = (customerId: string, configId: string) => {
@@ -1,21 +0,0 @@
1
- export function clickElement(ele: any): Promise<void>;
2
- export function enableIAB(): Promise<void>;
3
- export function updateConfig(settings: any): Promise<void>;
4
- export function updateFlavor(flavor: any): Promise<void>;
5
- export function validateConsentIab(consentProvided: any, consentExpected: any): Promise<void>;
6
- export function validateConsent(consentProvided: any, consentExpected: any): Promise<void>;
7
- export function clearConsent(): Promise<void>;
8
- export function provideConsent(consent: any, bannerText: any, closeButtonExists: any): Promise<void>;
9
- export function toggleFLC(iabEnabled: any): Promise<void>;
10
- export function toggleDrawer(iabEnabled: any): Promise<void>;
11
- export const bannerFlavorOne: "This website utilizes technologies such as cookies to enable essential site functionality, as well as for analytics, personalization, and targeted advertising. To learn more, view the following link:";
12
- export const bannerFlavorTwo: "This website utilizes technologies such as cookies to enable essential site functionality, as well as for analytics, personalization, and targeted advertising. You may change your settings at any time or accept the default settings. You may close this banner to continue with only essential cookies.";
13
- export const bannerFlavorTwoIab: "We and our 8 IAB TCF partners store and access information on your device for the following purposes: advertising and content measurement, audience research, and services development, personalised advertising, personalised content. \n\n\nPersonal data may be processed to do the following: use precise geolocation data and actively scan device characteristics for identification. \n\n\nOur third party IAB TCF partners may store and access information on your device such as IP address and device characteristics. Our IAB TCF Partners may process this personal data on the basis of legitimate interest, or with your consent. You may change or withdraw your preferences at any time by clicking on the cookie icon or link; however, as a consequence, you may not see relevant ads or personalized content. You may change your settings at any time or accept the default settings. You may close this banner to continue with only essential cookies.";
14
- export const bannerFlavorThree: "This website utilizes technologies such as cookies to enable essential site functionality, as well as for analytics, personalization, and targeted advertising.";
15
- export const bannerFlavorSix: "To improve your experience, we (and our partners) store and/or access information on your terminal (cookie or equivalent) with your consent for all our websites and applications, on your connected terminals.";
16
- export const bannerFlavorSixCont: "• Measure the audience of the advertising on our website, without profiling • Display personalized ads based on your navigation and your profile • Personalize our editorial content based on your navigation • Allow you to share content on social networks or platforms present on our website • Send you advertising based on your location";
17
- export const platform: string | undefined;
18
- export const showConsentVariantButton: "//XCUIElementTypeButton[@name=\"Show Consent Variant\"]" | "~Show Consent Variant";
19
- export const closeBannerButton: "//XCUIElementTypeStaticText[@name=\"✕\"]" | "//com.horcrux.svg.SvgView";
20
- export const closeDrawerButton: "-ios predicate string:name == \"✕\" AND label == \"✕\" AND type == \"XCUIElementTypeButton\"" | "android=new UiSelector().className(\"android.view.ViewGroup\").instance(40)";
21
- //# sourceMappingURL=commonCommands.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commonCommands.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/common/commonCommands.js"],"names":[],"mappings":"AA0BA,sDAGC;AAED,2CAMC;AAED,2DAgBC;AAED,yDASC;AAED,8FAkBC;AAED,2FAsBC;AAED,8CAOC;AAED,qGAaC;AAED,0DAeC;AAED,6DAqBC;AA/JD,wOAAyO;AACzO,4UAA6U;AAC7U,i9BAAk9B;AACl9B,kMAAmM;AACnM,gPAAgP;AAChP,oXAAqX;AACrX,0CAA6C;AAC7C,2HAA+I;AAC/I,yGAA6H;AAC7H,+MAA6N"}
@@ -1,3 +0,0 @@
1
- export { config };
2
- import { config } from "./wdio.conf.cjs";
3
- //# sourceMappingURL=wdio.conf.android.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wdio.conf.android.d.cts","sourceRoot":"","sources":["../../../../webdriverio-appium/config/wdio.conf.android.cjs"],"names":[],"mappings":""}
@@ -1,21 +0,0 @@
1
- export namespace config {
2
- let runner: string;
3
- let port: number;
4
- let specs: string[];
5
- let exclude: never[];
6
- let maxInstances: number;
7
- let capabilities: never[];
8
- let logLevel: string;
9
- let bail: number;
10
- let waitforTimeout: number;
11
- let connectionRetryTimeout: number;
12
- let connectionRetryCount: number;
13
- let services: string[];
14
- let framework: string;
15
- let reporters: string[];
16
- namespace mochaOpts {
17
- let ui: string;
18
- let timeout: number;
19
- }
20
- }
21
- //# sourceMappingURL=wdio.conf.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wdio.conf.d.cts","sourceRoot":"","sources":["../../../../webdriverio-appium/config/wdio.conf.cjs"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export { config };
2
- import { config } from "./wdio.conf.cjs";
3
- //# sourceMappingURL=wdio.conf.ios.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wdio.conf.ios.d.cts","sourceRoot":"","sources":["../../../../webdriverio-appium/config/wdio.conf.ios.cjs"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=six-drawer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"six-drawer.d.ts","sourceRoot":"","sources":["../../../../../webdriverio-appium/test/android/six-drawer.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=one.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"one.d.ts","sourceRoot":"","sources":["../../../../../webdriverio-appium/test/ios/one.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=six.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"six.d.ts","sourceRoot":"","sources":["../../../../../webdriverio-appium/test/ios/six.js"],"names":[],"mappings":""}
@@ -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/ios/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/ios/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/ios/two.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=one.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"one.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/test/one.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=six-iab.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"six-iab.d.ts","sourceRoot":"","sources":["../../../../webdriverio-appium/test/six-iab.js"],"names":[],"mappings":""}
@@ -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":""}