UNPKG

10 kBTypeScriptView Raw
1/**
2 * This exposes the native AppConsent module as a JS module.
3 *
4 * @packageDocumentation
5 */
6
7import { NativeModules, Platform } from 'react-native';
8
9const LINKING_ERROR =
10 `The package 'appconsent-clear-reactnative' doesn't seem to be linked. Make sure: \n\n` +
11 Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
12 '- You rebuilt the app after installing the package\n' +
13 '- You are not using Expo managed workflow\n';
14
15const appConsent = NativeModules.AppconsentClearReactnative
16 ? NativeModules.AppconsentClearReactnative
17 : new Proxy(
18 {},
19 {
20 get() {
21 throw new Error(LINKING_ERROR);
22 },
23 }
24 );
25
26/**
27 * This is the main entry point to interact with AppConsent API.
28 *
29 * @example
30 * import AppConsent from 'appconsent-clear-reactnative';
31 */
32export default appConsent as AppConsent;
33
34/**
35 * This is the main interface to interact with AppConsent API, it exposes typescript declarations to access Native libraries features.
36 *
37 * @example
38 * import AppConsent from 'appconsent-clear-reactnative';
39 */
40export interface AppConsent {
41 /**
42 * This initializes AppConsent.
43 * @remarks
44 * This method is <b>ASYNCHRONOUS!</b><br />
45 * You must call the method with <b>await</b>.<br />
46 * To ensure proper operation, put the call to this method in a <b>try/catch</b>.<br />
47 * This method doesn't have a <b>Promise<T></b> signature<br />
48 * So it can't be used as such (<i>promiseMethod.then().catch()</i>)
49 *
50 * @param appKey - Your AppKey
51 * @param forceApplyGDPR - force behavior as in a GDPR subject country<br />
52 * false, let the CMP check whether the user is subject to the GDPR of its region.<br />
53 * true, it considers the user to be subject to GDPR
54 * @param forceATT - force ATT handling (iOS only)
55 *
56 * @category General Use
57 */
58 configureWith(
59 appKey: string,
60 forceApplyGDPR: boolean,
61 forceATT: boolean
62 ): void;
63
64 /**
65 * To display AppConsent by modal on top of your view.
66 *
67 * @remarks
68 * To be notified when the user has entered his consent, don't forget to register with the callback.
69 *
70 * @see {@link AppConsent.consentGiven}
71 * @param force - false, displays the introduction screen as a modal only if necessary (subject to GDPR, consent not entered, consent period exceeded, etc.).<br />
72 * true, forces the display of the configuration screen (allowing users to enter/modify their consent)
73 *
74 * @category General Use
75 */
76 present(force: boolean): void;
77
78 /**
79 * Check if consent must be updated (new gvl version, new consentables…)
80 *
81 * @example
82 * AppConsent.checkForUpdate()
83 * .then((isNeedToUpdate: boolean) => {
84 * console.log('isNeedToUpdate => ' + isNeedToUpdate);
85 * // CMP needs to be displayed again to your users
86 * AppConsent.present(false);
87 * }).catch((err: any) => console.log(err));
88 *
89 * @category Advanced Use
90 */
91 checkForUpdate(): Promise<boolean>;
92
93 /**
94 * Check if device is GDPR country.
95 *
96 * @returns true if the device is in a country subject to GDPR, false otherwise.
97 *
98 * @category Advanced Use
99 */
100 isGDPRCountry(): Promise<boolean>;
101
102 /**
103 * Check if user gave consent
104 *
105 * @example
106 * AppConsent.consentAlreadyGiven()
107 * .then( success =>
108 * console.log("đŸ”¥ consentAlreadyGiven => " + success)
109 * )
110 *
111 * @returns true if consent is given, false otherwise.
112 *
113 * @category Advanced Use
114 */
115 consentAlreadyGiven(): Promise<boolean>;
116
117 /**
118 * Callback when user give its consent.
119 *
120 * @example
121 * AppConsent.consentGiven()
122 * .then((success: boolean) => console.log('consentGiven => ' + success))
123 * .catch((err: any) => console.log(err));
124 *
125 * @returns true if user saved their consent preferences.
126 *
127 * @category Advanced Use
128 */
129 consentGiven(): Promise<boolean>;
130
131 /**
132 * Clear consents on NSUserDefaults, DefaultSharedPreference, but not on server.
133 *
134 * @category Advanced Use
135 */
136 clearConsent(): void;
137
138 /**
139 *
140 * @param extraId
141 * @returns true if consentable with extraId is allowed, false otherwise.
142 *
143 * @category Advanced Use
144 */
145 extraConsentableAllowed(extraId: string): Promise<boolean>;
146
147 /**
148 *
149 * @param extraId
150 * @returns true if consentable with extraId is allowed, false otherwise.
151 *
152 * @category Advanced Use
153 */
154 extraVendorAllowed(extraId: string): Promise<boolean>;
155
156 /**
157 * Check if floating purpose is allowed.
158 *
159 * @remarks
160 * NOTE:
161 * You need to call checkForUpdate method before calling this method to stay up to date.
162 *
163 * @see {@link AppConsent.checkForUpdate}
164 *
165 * @param extraId
166 *
167 * @category Advanced Use
168 */
169 extraFloatingPurposeAllowed(extraId: string): Promise<boolean>;
170
171 /**
172 * Set consentables status with an iabId.
173 *
174 * @remarks
175 * CAUTION:
176 * Key must be an iabId, not an objectId.
177 * Value must be an Integer: 0 (pending), 1 (allowed), -1 (denied)
178 *
179 * NOTE:
180 * This method doesn’t send request to the server.
181 *
182 * @param values
183 *
184 * @category Advanced Use
185 */
186 setConsentableConsent(values: {}): Promise<boolean>;
187
188 /**
189 * Set consentables status with extraId.
190 *
191 * @remarks
192 * CAUTION:
193 * Key must be an extraId, not an objectId.
194 * Value must be an Integer: 0 (pending), 1 (allowed), -1 (denied)
195 *
196 * NOTE:
197 * This method doesn’t send request to the server.
198 *
199 * @param values
200 *
201 * @category Advanced Use
202 */
203 setExtraConsentableConsent(values: {}): Promise<boolean>;
204
205 // EXTERNAL IDS
206
207 /**
208 * Retrieve external ids from cache.
209 *
210 * @remarks
211 * NOTE: this only returns the external ids present in the local storage, without checking them out from the backend, external ids are only synchronized after a call to present() or checkForUpdate().
212 *
213 * @returns String representation of all the external Ids in User Preferences
214 * in the following form :
215 * [:] for an empty value
216 * ["key1": "value1", "key2": "value2"] for a key/value data set
217 *
218 * @category External Ids
219 */
220 getExternalIds(): Promise<string>;
221
222 /**
223 * Store a set of external id allong the consent, the ids are synchornised with the consents upon calling present() or checkForUpdate(), so this should be called before calling present() or checkForUpdate().
224 *
225 * @remarks
226 * NOTE: this overrides previously set ExternalIds in the local storage, but the change won't be synchronized with our backend untill a call to present() or checkForUpdate() is made.
227 *
228 * @returns true
229 *
230 * @param ids
231 *
232 * @category External Ids
233 */
234 setExternalIds(ids: {}): Promise<boolean>;
235
236 /**
237 * Send the external ids you have stored with setExternalIds to the server.
238 *
239 * @remarks
240 * NOTE: the external ids are also saved automatically when calling present(), whether or not the notice is presented, or when calling checkForUpdate().
241 * Saving ExternalIds with this method doesn't work unless there has been a previous consent registered with present(), so in most cases it is preferable to simply rely on present() or checkForUpdate() to save the ExternalIds.
242 *
243 * @example
244 * AppConsent.setExternalIds({ myCustomID: 'xyz' })
245 * .then((success: boolean) =>
246 * console.log('đŸ”¥ setExternalIds => ' + success)
247 * )
248 * .catch((err: any) => console.log(err))
249 *
250 * @returns true
251 *
252 * @category External Ids
253 */
254 saveExternalIds(): Promise<boolean>;
255
256 // IOS ONLY
257
258 /**
259 * @remarks
260 * This is only supported on iOS targets.
261 *
262 * @returns forceATT
263 *
264 * @category iOS App Tracking Transparency
265 */
266 getForceATT(): Promise<boolean>;
267
268 /**
269 * Check if your device supports App Tracking Transparency.
270 *
271 * @remarks
272 * This is only supported on iOS targets.
273 *
274 * @returns true if available, false otherwise.
275 *
276 * @category iOS App Tracking Transparency
277 */
278 appTrackingIsAvailable(): Promise<boolean>;
279
280 /**
281 * Check if App Tracking Transparency has been given.
282 *
283 * @remarks
284 * This is only supported on iOS targets.
285 *
286 * @returns 0 (not given), 1 (given), 2 (not supported)
287 *
288 * @category iOS App Tracking Transparency
289 */
290 appTrackingAuthorizationGiven(): Promise<number>;
291
292 /**
293 * Check status of App Tracking Transparency.
294 *
295 * @remarks
296 * This is only supported on iOS targets.
297 *
298 * @returns 0 (failure), 1 (success), 2 (not supported)
299 *
300 * @category iOS App Tracking Transparency
301 */
302 appTrackingAuthorizationStatus(): Promise<number>;
303
304 // DEPRECATED
305
306 /**
307 * @returns true if consentable with objectId is allowed, false otherwise.
308 *
309 * @deprecated
310 * @category Advanced Use
311 */
312 consentableAllowedByObjectId(id: string): Promise<boolean>;
313
314 /**
315 * @param iabId
316 * @param type - 0: purpose, 1: feature, 2: specialFeature, 3: specialPurpose
317 * @returns true if consentable with iabId is allowed, false otherwise.
318 *
319 * @deprecated
320 * @category Advanced Use
321 */
322 consentableAllowedByIABId(iabId: string, type: number): Promise<boolean>;
323
324 /**
325 * @returns true if consentable with iabId is allowed, false otherwise.
326 *
327 * @deprecated
328 * @category Advanced Use
329 */
330 vendorAllowedByIABId(iabId: string): Promise<boolean>;
331
332 /**
333 * @returns true if consentable with iabId is allowed, false otherwise.
334 *
335 * @deprecated
336 * @category Advanced Use
337 */
338 stackAllowedByIABId(iabId: string): Promise<boolean>;
339
340 /**
341 * @returns the configured AppKey.
342 *
343 * @deprecated
344 * @category Advanced Use
345 */
346 getAppKey(): Promise<string>;
347
348 /**
349 * @returns forceApplyGDPR
350 *
351 * @deprecated
352 * @category Advanced Use
353 */
354 getForceApplyGDPR(): Promise<boolean>;
355
356 /**
357 *
358 * @deprecated
359 * @category Advanced Use
360 */
361 getName(): string;
362
363 /**
364 *
365 * @deprecated
366 * @category Advanced Use
367 */
368 getConstants(): any;
369}