reteno-react-native-sdk 2.3.0 → 3.0.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.
package/src/index.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import {
2
- DeviceEventEmitter,
2
+ EmitterSubscription,
3
3
  NativeEventEmitter,
4
4
  NativeModules,
5
5
  Platform,
6
6
  } from 'react-native';
7
+ import NativeRetenoSdk from './NativeRetenoSdk';
7
8
 
8
9
  const LINKING_ERROR =
9
10
  `The package 'reteno-react-native-sdk' doesn't seem to be linked. Make sure: \n\n` +
@@ -54,9 +55,9 @@ export type AnonymousUserAttributes = Pick<
54
55
 
55
56
  export type User = {
56
57
  userAttributes?: UserAttributes | null;
57
- subscriptionKeys?: String[] | null;
58
- groupNamesInclude?: String[] | null;
59
- groupNamesExclude?: String[] | null;
58
+ subscriptionKeys?: string[] | null;
59
+ groupNamesInclude?: string[] | null;
60
+ groupNamesExclude?: string[] | null;
60
61
  };
61
62
 
62
63
  export type SetUserAttributesPayload = {
@@ -64,10 +65,7 @@ export type SetUserAttributesPayload = {
64
65
  user: User;
65
66
  };
66
67
 
67
- export type SetMultiAccountUserAttributesPayload = {
68
- externalUserId: string;
69
- user: User;
70
- };
68
+ export type SetMultiAccountUserAttributesPayload = SetUserAttributesPayload;
71
69
 
72
70
  export type CustomEventParameter = {
73
71
  name: string;
@@ -145,29 +143,30 @@ export type NotificationPermissionStatus =
145
143
  | 'DENIED'
146
144
  | 'PERMANENTLY_DENIED';
147
145
 
148
- /**
149
- * Android notification grouping rule. The rule is stored natively and restored
150
- * before React Native starts, so it is also applied to background notifications.
151
- *
152
- * `showSummary` requires Android 6.0 (API 23) or higher. On older versions it is
153
- * silently ignored - grouping still applies, but no summary notification is shown.
154
- */
155
- export type NotificationGroupingRule =
156
- | { payloadKey: string; groupId?: never; showSummary?: boolean }
157
- | { groupId: string; payloadKey?: never; showSummary?: boolean };
158
-
159
146
  export type InAppCustomData = {
160
- customData?: Record<string, any>;
147
+ customData?: Record<string, unknown>;
161
148
  inapp_id?: string;
162
149
  inapp_source?: 'DISPLAY_RULES' | 'PUSH_NOTIFICATION';
163
150
  url?: string;
164
151
  };
165
152
 
153
+ /** Alias for {@link InAppCustomData}, named to match the other typed event payloads. */
154
+ export type RetenoInAppCustomDataEvent = InAppCustomData;
155
+
156
+ export type RecomFilter = {
157
+ name: string;
158
+ values: string[];
159
+ };
160
+
166
161
  export type RecommendationsPayload = {
167
162
  recomVariantId: string;
168
163
  productIds: string[];
169
164
  categoryId: string;
170
- filters?: { [key: string]: any }[];
165
+ /**
166
+ * Android currently ignores this field (the bridge never reads it from the payload,
167
+ * see `RetenoSdkModule.getRecommendations`) — only iOS applies filters today.
168
+ */
169
+ filters?: RecomFilter[];
171
170
  fields: string[];
172
171
  };
173
172
 
@@ -186,13 +185,19 @@ export type RecommendationEventPayload = {
186
185
  export type InboxMessage = {
187
186
  id: string;
188
187
  title: string;
189
- createdDate: string;
188
+ /**
189
+ * Format differs by platform (pre-existing, not introduced here): Android sends the raw
190
+ * date string from the API as-is; iOS sends a Unix timestamp in seconds
191
+ * (`Date.timeIntervalSince1970`) as a number. Normalizing this to one shape across
192
+ * platforms is a bridge change, tracked separately — not done as part of this typing pass.
193
+ */
194
+ createdDate: string | number;
190
195
  imageURL?: string;
191
196
  linkURL?: string;
192
197
  isNew: boolean;
193
198
  content?: string;
194
- // Only on Android
195
199
  category?: string;
200
+ // Only on Android — the iOS native SDK has no equivalent concept.
196
201
  status?: AppInboxStatus;
197
202
  };
198
203
 
@@ -206,15 +211,51 @@ export type UnreadMessagesCountErrorData = {
206
211
  error?: string | null;
207
212
  };
208
213
 
214
+ /**
215
+ * Raw native push payload, forwarded as-is from FCM/APNs. The `es_*` keys below are set by
216
+ * Reteno on every Reteno-originated push and are confirmed present on both native SDKs
217
+ * (iOS: `RetenoUserNotification.swift`; Android: `RetenoSdkPush/Constants.kt`). Everything
218
+ * else is app- or campaign-specific and intentionally left open via the index signature —
219
+ * do not assume a fixed shape beyond these.
220
+ */
221
+ export type RetenoPushPayload = {
222
+ /** Correlates this push back to a Reteno interaction (opens/clicks reporting). */
223
+ es_interaction_id?: string;
224
+ /** Wrapped/tracked deep link. */
225
+ es_link?: string;
226
+ /** Original, unwrapped deep link. */
227
+ es_link_raw?: string;
228
+ /** Main notification image URL. */
229
+ es_notification_image?: string;
230
+ /** JSON-encoded carousel image URLs. */
231
+ es_notification_images?: string;
232
+ /** JSON-encoded action buttons definition. */
233
+ es_buttons?: string;
234
+ /** Present when this push also carries a push-triggered in-app message. */
235
+ es_inapp?: string;
236
+ [key: string]: unknown;
237
+ };
238
+
239
+ export type RetenoPushReceivedEvent = RetenoPushPayload;
240
+ export type RetenoPushClickedEvent = RetenoPushPayload;
241
+ export type RetenoPushDismissedEvent = RetenoPushPayload;
242
+ export type RetenoCustomPushDataEvent = RetenoPushPayload;
243
+ export type RetenoInitialNotification = RetenoPushPayload;
244
+
209
245
  export type PushButton = {
210
246
  actionId: string;
247
+ /** Raw string as forwarded by the native SDK (commonly JSON-encoded) — not parsed here. */
211
248
  customData: string | null;
212
249
  actionLink: string | null;
213
- userInfo: any;
250
+ userInfo: RetenoPushPayload;
214
251
  };
215
252
 
216
- const RetenoSdk = NativeModules.RetenoSdk
217
- ? NativeModules.RetenoSdk
253
+ export type RetenoPushButtonClickedEvent = PushButton;
254
+
255
+ const nativeRetenoSdk = NativeRetenoSdk ?? NativeModules.RetenoSdk;
256
+
257
+ const RetenoSdk = nativeRetenoSdk
258
+ ? nativeRetenoSdk
218
259
  : new Proxy(
219
260
  {},
220
261
  {
@@ -224,6 +265,88 @@ const RetenoSdk = NativeModules.RetenoSdk
224
265
  }
225
266
  );
226
267
 
268
+ export type RetenoEventPayloadMap = {
269
+ pushReceived: RetenoPushReceivedEvent;
270
+ pushClicked: RetenoPushClickedEvent;
271
+ pushButtonClicked: RetenoPushButtonClickedEvent;
272
+ pushDismissed: RetenoPushDismissedEvent;
273
+ customPushData: RetenoCustomPushDataEvent;
274
+ beforeInAppDisplay: InAppDisplayData;
275
+ inAppDisplay: InAppDisplayData;
276
+ beforeInAppClose: InAppCloseData;
277
+ afterInAppClose: InAppCloseData;
278
+ inAppError: InAppErrorData;
279
+ inAppCustomData: RetenoInAppCustomDataEvent;
280
+ unreadMessagesCountChanged: UnreadMessagesCountData;
281
+ unreadMessagesCountError: UnreadMessagesCountErrorData;
282
+ };
283
+
284
+ export type RetenoEventType = keyof RetenoEventPayloadMap;
285
+
286
+ export type RetenoEventListener<T extends RetenoEventType> = (
287
+ event: RetenoEventPayloadMap[T]
288
+ ) => void;
289
+
290
+ export type RetenoSubscription = {
291
+ remove(): void;
292
+ };
293
+
294
+ const RETENO_NATIVE_EVENTS: Record<RetenoEventType, string> = {
295
+ pushReceived: 'reteno-push-received',
296
+ pushClicked: 'reteno-push-clicked',
297
+ pushButtonClicked: 'reteno-push-button-clicked',
298
+ pushDismissed: 'reteno-push-dismissed',
299
+ customPushData: 'reteno-custom-push-received',
300
+ beforeInAppDisplay: 'reteno-before-in-app-display',
301
+ inAppDisplay: 'reteno-on-in-app-display',
302
+ beforeInAppClose: 'reteno-before-in-app-close',
303
+ afterInAppClose: 'reteno-after-in-app-close',
304
+ inAppError: 'reteno-on-in-app-error',
305
+ inAppCustomData: 'reteno-in-app-custom-data-received',
306
+ unreadMessagesCountChanged: 'reteno-unread-messages-count',
307
+ unreadMessagesCountError: 'reteno-unread-messages-count-error',
308
+ };
309
+
310
+ const PLATFORM_EVENT_SUPPORT: Partial<
311
+ Record<RetenoEventType, 'ios' | 'android'>
312
+ > = {
313
+ pushButtonClicked: 'ios',
314
+ pushDismissed: 'android',
315
+ customPushData: 'android',
316
+ unreadMessagesCountError: 'android',
317
+ };
318
+
319
+ const eventEmitter = new NativeEventEmitter(RetenoSdk);
320
+
321
+ const eventSubscriptions = new Map<
322
+ RetenoEventType,
323
+ Map<RetenoEventListener<RetenoEventType>, RetenoSubscription>
324
+ >();
325
+
326
+ const noopSubscription: RetenoSubscription = {
327
+ remove: () => undefined,
328
+ };
329
+
330
+ function warnUnsupportedEvent(
331
+ eventName: RetenoEventType,
332
+ supportedPlatform: string
333
+ ) {
334
+ const isDev =
335
+ typeof globalThis !== 'undefined' &&
336
+ Boolean((globalThis as { __DEV__?: boolean }).__DEV__);
337
+
338
+ if (isDev) {
339
+ console.warn(
340
+ `Reteno event "${eventName}" is only supported on ${supportedPlatform}. Returning a no-op subscription.`
341
+ );
342
+ }
343
+ }
344
+
345
+ function isEventSupportedOnCurrentPlatform(eventName: RetenoEventType) {
346
+ const supportedPlatform = PLATFORM_EVENT_SUPPORT[eventName];
347
+ return !supportedPlatform || Platform.OS === supportedPlatform;
348
+ }
349
+
227
350
  export function initialize(
228
351
  input: string | InitializeOptions
229
352
  ): Promise<boolean> {
@@ -257,19 +380,34 @@ export function setUserAttributes(
257
380
  !payload.externalUserId ||
258
381
  (payload.externalUserId && payload.externalUserId.length === 0)
259
382
  ) {
260
- throw new Error('Missing argument: "externalUserId"');
383
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
261
384
  }
262
385
  return RetenoSdk.setUserAttributes(payload);
263
386
  }
264
387
 
265
- export function getInitialNotification(): Promise<any> {
388
+ export function getInitialNotification(): Promise<RetenoInitialNotification | null> {
266
389
  return RetenoSdk.getInitialNotification();
267
390
  }
268
391
 
269
- export function getRecommendations(
392
+ /**
393
+ * Recommendation item shape depends on the `fields` requested in `payload.fields`,
394
+ * so it's intentionally left open rather than a fixed structure.
395
+ */
396
+ export type RetenoRecommendationItem = {
397
+ [key: string]: unknown;
398
+ };
399
+
400
+ export function getRecommendations<T extends object = RetenoRecommendationItem>(
270
401
  payload: RecommendationsPayload
271
- ): Promise<any> {
272
- return RetenoSdk.getRecommendations(payload);
402
+ ): Promise<T[]> {
403
+ // The iOS bridge reads `filters` via a single `guard let` chain alongside the required
404
+ // fields, so an absent key fails that guard and rejects the whole call with "Invalid
405
+ // payload" — even though `filters` is optional in this API. Always send an array so the
406
+ // optional JS type matches what the native side actually requires.
407
+ return RetenoSdk.getRecommendations({
408
+ ...payload,
409
+ filters: payload.filters ?? [],
410
+ });
273
411
  }
274
412
 
275
413
  export function logRecommendationEvent(
@@ -278,10 +416,56 @@ export function logRecommendationEvent(
278
416
  return RetenoSdk.logRecommendationEvent(payload);
279
417
  }
280
418
 
281
- const eventEmitter =
282
- Platform.OS === 'android'
283
- ? DeviceEventEmitter
284
- : new NativeEventEmitter(RetenoSdk);
419
+ export function addEventListener<T extends RetenoEventType>(
420
+ eventName: T,
421
+ listener: RetenoEventListener<T>
422
+ ): RetenoSubscription {
423
+ const supportedPlatform = PLATFORM_EVENT_SUPPORT[eventName];
424
+ if (!isEventSupportedOnCurrentPlatform(eventName)) {
425
+ warnUnsupportedEvent(eventName, supportedPlatform ?? 'this platform');
426
+ return noopSubscription;
427
+ }
428
+
429
+ const eventListeners =
430
+ eventSubscriptions.get(eventName) ??
431
+ new Map<RetenoEventListener<RetenoEventType>, RetenoSubscription>();
432
+ eventSubscriptions.set(eventName, eventListeners);
433
+
434
+ const registeredListener = listener as RetenoEventListener<RetenoEventType>;
435
+ const existingSubscription = eventListeners.get(registeredListener);
436
+ if (existingSubscription) {
437
+ return existingSubscription;
438
+ }
439
+
440
+ const nativeSubscription: EmitterSubscription = eventEmitter.addListener(
441
+ RETENO_NATIVE_EVENTS[eventName],
442
+ (event) => listener(event as RetenoEventPayloadMap[T])
443
+ );
444
+
445
+ const subscription: RetenoSubscription = {
446
+ remove: () => {
447
+ nativeSubscription.remove();
448
+ eventListeners.delete(registeredListener);
449
+ if (eventListeners.size === 0) {
450
+ eventSubscriptions.delete(eventName);
451
+ }
452
+ },
453
+ };
454
+
455
+ eventListeners.set(registeredListener, subscription);
456
+ return subscription;
457
+ }
458
+
459
+ export function removeEventListener<T extends RetenoEventType>(
460
+ eventName: T,
461
+ listener: RetenoEventListener<T>
462
+ ): void {
463
+ const registeredListener = listener as RetenoEventListener<RetenoEventType>;
464
+ const subscription = eventSubscriptions
465
+ .get(eventName)
466
+ ?.get(registeredListener);
467
+ subscription?.remove();
468
+ }
285
469
 
286
470
  /**
287
471
  * Initialize event handler. Call this after setting up all event listeners.
@@ -343,30 +527,28 @@ export function getAutoOpenLinks(): Promise<boolean> {
343
527
  }
344
528
 
345
529
  export function setOnRetenoPushReceivedListener(
346
- listener: (event: any) => void
530
+ listener: (event: RetenoPushReceivedEvent) => void
347
531
  ) {
348
- return eventEmitter.addListener('reteno-push-received', listener);
532
+ return addEventListener('pushReceived', listener);
349
533
  }
350
534
 
351
- export function setOnRetenoPushClickedListener(listener: (event: any) => void) {
352
- return eventEmitter.addListener('reteno-push-clicked', listener);
535
+ export function setOnRetenoPushClickedListener(
536
+ listener: (event: RetenoPushClickedEvent) => void
537
+ ) {
538
+ return addEventListener('pushClicked', listener);
353
539
  }
354
540
 
355
541
  /**
356
542
  * iOS Only
357
543
  */
358
544
  export function setOnRetenoPushButtonClickedListener(
359
- listener: (event: PushButton) => void
545
+ listener: (event: RetenoPushButtonClickedEvent) => void
360
546
  ) {
361
- if (Platform.OS === 'ios') {
362
- return eventEmitter.addListener('reteno-push-button-clicked', listener);
363
- }
364
-
365
- return undefined;
547
+ return addEventListener('pushButtonClicked', listener);
366
548
  }
367
549
 
368
550
  export function setInAppLifecycleCallback() {
369
- RetenoSdk.setInAppLifecycleCallback();
551
+ return RetenoSdk.setInAppLifecycleCallback();
370
552
  }
371
553
 
372
554
  /**
@@ -374,69 +556,43 @@ export function setInAppLifecycleCallback() {
374
556
  */
375
557
  export function removeInAppLifecycleCallback() {
376
558
  if (Platform.OS === 'android') {
377
- RetenoSdk.removeInAppLifecycleCallback();
559
+ return RetenoSdk.removeInAppLifecycleCallback();
378
560
  }
561
+ return Promise.resolve(undefined);
379
562
  }
380
563
 
381
564
  export function beforeInAppDisplayHandler(
382
565
  callback: (data: InAppDisplayData) => void
383
566
  ) {
384
- return eventEmitter.addListener('reteno-before-in-app-display', (data) => {
385
- if (callback && typeof callback === 'function') {
386
- callback(data);
387
- }
388
- });
567
+ return addEventListener('beforeInAppDisplay', callback);
389
568
  }
390
569
 
391
570
  export function onInAppDisplayHandler(
392
571
  callback: (data: InAppDisplayData) => void
393
572
  ) {
394
- return eventEmitter.addListener('reteno-on-in-app-display', (data) => {
395
- if (callback && typeof callback === 'function') {
396
- callback(data);
397
- }
398
- });
573
+ return addEventListener('inAppDisplay', callback);
399
574
  }
400
575
 
401
576
  export function beforeInAppCloseHandler(
402
577
  callback: (data: InAppCloseData) => void
403
578
  ) {
404
- return eventEmitter.addListener('reteno-before-in-app-close', (data) => {
405
- if (callback && typeof callback === 'function') {
406
- callback(data);
407
- }
408
- });
579
+ return addEventListener('beforeInAppClose', callback);
409
580
  }
410
581
 
411
582
  export function afterInAppCloseHandler(
412
583
  callback: (data: InAppCloseData) => void
413
584
  ) {
414
- return eventEmitter.addListener('reteno-after-in-app-close', (data) => {
415
- if (callback && typeof callback === 'function') {
416
- callback(data);
417
- }
418
- });
585
+ return addEventListener('afterInAppClose', callback);
419
586
  }
420
587
 
421
588
  export function onInAppErrorHandler(callback: (data: InAppErrorData) => void) {
422
- return eventEmitter.addListener('reteno-on-in-app-error', (data) => {
423
- if (callback && typeof callback === 'function') {
424
- callback(data);
425
- }
426
- });
589
+ return addEventListener('inAppError', callback);
427
590
  }
428
591
 
429
592
  export function addInAppMessageCustomDataHandler(
430
- callback: (data: InAppCustomData) => void
593
+ callback: (data: RetenoInAppCustomDataEvent) => void
431
594
  ) {
432
- return eventEmitter.addListener(
433
- 'reteno-in-app-custom-data-received',
434
- (data) => {
435
- if (callback && typeof callback === 'function') {
436
- callback(data);
437
- }
438
- }
439
- );
595
+ return addEventListener('inAppCustomData', callback);
440
596
  }
441
597
 
442
598
  /**
@@ -504,7 +660,7 @@ export function setMultiAccountUserAttributes(
504
660
  payload: SetMultiAccountUserAttributesPayload
505
661
  ): Promise<void> {
506
662
  if (!payload.externalUserId) {
507
- throw new Error('Missing argument: "externalUserId"');
663
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
508
664
  }
509
665
  return RetenoSdk.setMultiAccountUserAttributes(payload);
510
666
  }
@@ -515,19 +671,14 @@ export function setMultiAccountUserAttributes(
515
671
  * Call this function to send all accumulated events
516
672
  */
517
673
  export function forcePushData(): Promise<void> {
518
- if (Platform.OS === 'ios') {
519
- // for ios we have to use this hack, because there isn't separate forcePush function as on android, sending an event with forcePush flag does the same thing
520
- return logEvent('', new Date().toISOString(), [], true);
521
- } else return RetenoSdk.forcePushData();
674
+ return RetenoSdk.forcePushData();
522
675
  }
523
676
  /**
524
677
  * Send log screen view event
525
678
  * @param screenName name of the screen
526
679
  */
527
- export function logScreenView(screenName: string) {
528
- return logEvent(CustomEventTypes.screenView, new Date().toISOString(), [
529
- { name: CustomEventTypes.screenView, value: screenName },
530
- ]);
680
+ export function logScreenView(screenName: string): Promise<void> {
681
+ return RetenoSdk.logScreenView(screenName);
531
682
  }
532
683
 
533
684
  /**
@@ -567,11 +718,7 @@ export function unsubscribeAllMessagesCountChanged(): Promise<void> {
567
718
  export function unreadMessagesCountHandler(
568
719
  callback: (data: UnreadMessagesCountData) => void
569
720
  ) {
570
- return eventEmitter.addListener('reteno-unread-messages-count', (data) => {
571
- if (callback && typeof callback === 'function') {
572
- callback(data);
573
- }
574
- });
721
+ return addEventListener('unreadMessagesCountChanged', callback);
575
722
  }
576
723
 
577
724
  /**
@@ -580,18 +727,7 @@ export function unreadMessagesCountHandler(
580
727
  export function unreadMessagesCountErrorHandler(
581
728
  callback: (data: UnreadMessagesCountErrorData) => void
582
729
  ) {
583
- if (Platform.OS === 'android') {
584
- return eventEmitter.addListener(
585
- 'reteno-unread-messages-count-error',
586
- (data) => {
587
- if (callback && typeof callback === 'function') {
588
- callback(data);
589
- }
590
- }
591
- );
592
- }
593
-
594
- return undefined;
730
+ return addEventListener('unreadMessagesCountError', callback);
595
731
  }
596
732
 
597
733
  export function markAsOpened(
@@ -602,13 +738,6 @@ export function markAsOpened(
602
738
  status: messageIds?.length ? 'OPENED' : '',
603
739
  };
604
740
 
605
- if (Platform.OS === 'android') {
606
- return RetenoSdk.markAsOpened(messageIds?.[0]).then(
607
- () => response,
608
- (error: any) => Promise.reject(error)
609
- );
610
- }
611
-
612
741
  return RetenoSdk.markAsOpened(messageIds).then(
613
742
  () => response,
614
743
  (error: any) => Promise.reject(error)
@@ -845,12 +974,9 @@ export function logEcomEventSearchRequest(
845
974
  * Listen for push notification dismissed (swiped away) events.
846
975
  */
847
976
  export function setOnRetenoPushDismissedListener(
848
- listener: (event: any) => void
849
- ): ReturnType<typeof eventEmitter.addListener> | undefined {
850
- if (Platform.OS === 'android') {
851
- return eventEmitter.addListener('reteno-push-dismissed', listener);
852
- }
853
- return undefined;
977
+ listener: (event: RetenoPushDismissedEvent) => void
978
+ ): RetenoSubscription {
979
+ return addEventListener('pushDismissed', listener);
854
980
  }
855
981
 
856
982
  /**
@@ -858,39 +984,84 @@ export function setOnRetenoPushDismissedListener(
858
984
  * Listen for custom push data events (silent/data-only push messages).
859
985
  */
860
986
  export function setOnRetenoCustomPushDataListener(
861
- listener: (event: any) => void
862
- ): ReturnType<typeof eventEmitter.addListener> | undefined {
863
- if (Platform.OS === 'android') {
864
- return eventEmitter.addListener('reteno-custom-push-received', listener);
865
- }
866
- return undefined;
987
+ listener: (event: RetenoCustomPushDataEvent) => void
988
+ ): RetenoSubscription {
989
+ return addEventListener('customPushData', listener);
867
990
  }
868
991
 
869
992
  /**
870
- * Android Only
993
+ * Android Only.
871
994
  * Request notification permission. Returns true if granted, false otherwise.
872
995
  * Uses the new RetenoNotifications API introduced in SDK 2.9.0.
996
+ *
997
+ * On iOS the promise rejects — this method is not supported there. (Previously it
998
+ * silently resolved to `false`, which looked like a real "denied" result.)
873
999
  */
874
1000
  export function requestNotificationPermission(): Promise<boolean> {
875
1001
  if (Platform.OS === 'android') {
876
1002
  return RetenoSdk.requestNotificationPermission();
877
1003
  }
878
- return Promise.resolve(false);
1004
+ return Promise.reject(
1005
+ new Error('requestNotificationPermission() is not supported on iOS')
1006
+ );
879
1007
  }
880
1008
 
881
1009
  /**
882
- * Android Only
1010
+ * Android Only.
883
1011
  * Get current notification permission status.
884
1012
  * Returns 'ALLOWED', 'DENIED', or 'PERMANENTLY_DENIED'.
885
1013
  * Uses the new RetenoNotifications API introduced in SDK 2.9.0.
1014
+ *
1015
+ * On iOS the promise rejects — this method is not supported there. (Previously it
1016
+ * silently resolved to `'ALLOWED'`, which looked like a real permission read.)
886
1017
  */
887
1018
  export function getNotificationPermissionStatus(): Promise<NotificationPermissionStatus> {
888
1019
  if (Platform.OS === 'android') {
889
1020
  return RetenoSdk.getNotificationPermissionStatus();
890
1021
  }
891
- return Promise.resolve('ALLOWED' as NotificationPermissionStatus);
1022
+ return Promise.reject(
1023
+ new Error('getNotificationPermissionStatus() is not supported on iOS')
1024
+ );
892
1025
  }
893
1026
 
1027
+ /**
1028
+ * Android Only
1029
+ * Pause or resume push-triggered in-app messages specifically.
1030
+ * Introduced in Android SDK 2.9.0.
1031
+ */
1032
+ export function pausePushInAppMessages(isPaused: boolean): Promise<void> {
1033
+ if (Platform.OS === 'android') {
1034
+ return RetenoSdk.pausePushInAppMessages(isPaused);
1035
+ }
1036
+ return Promise.resolve(undefined);
1037
+ }
1038
+
1039
+ /**
1040
+ * Android Only
1041
+ * Set the behaviour for push-triggered in-app messages when paused.
1042
+ * Introduced in Android SDK 2.9.0.
1043
+ */
1044
+ export function setPushInAppMessagesPauseBehaviour(
1045
+ behaviour: InAppPauseBehaviour
1046
+ ): Promise<void> {
1047
+ if (Platform.OS === 'android') {
1048
+ return RetenoSdk.setPushInAppMessagesPauseBehaviour(behaviour);
1049
+ }
1050
+ return Promise.resolve(undefined);
1051
+ }
1052
+
1053
+ /**
1054
+ * Android only. Groups notifications by a push payload value or a constant ID.
1055
+ * The rule is persisted natively and restored before the app starts, so it is
1056
+ * also applied to notifications received while the app is not running.
1057
+ *
1058
+ * `showSummary` requires Android 6.0 (API 23) or higher. On older versions it is
1059
+ * silently ignored - grouping still applies, but no summary notification is shown.
1060
+ */
1061
+ export type NotificationGroupingRule =
1062
+ | { payloadKey: string; groupId?: never; showSummary?: boolean }
1063
+ | { groupId: string; payloadKey?: never; showSummary?: boolean };
1064
+
894
1065
  /**
895
1066
  * Android only. Groups notifications by a push payload value or a constant ID.
896
1067
  * Pass `null` to disable grouping.
@@ -927,6 +1098,7 @@ export function setNotificationGroupingRule(
927
1098
  )
928
1099
  );
929
1100
  }
1101
+
930
1102
  if (rule.showSummary !== undefined && typeof rule.showSummary !== 'boolean') {
931
1103
  return Promise.reject(
932
1104
  new Error('Invalid argument: showSummary must be a boolean')
@@ -942,28 +1114,75 @@ export function setNotificationGroupingRule(
942
1114
  return RetenoSdk.setNotificationGroupingRule(normalizedRule);
943
1115
  }
944
1116
 
945
- /**
946
- * Android Only
947
- * Pause or resume push-triggered in-app messages specifically.
948
- * Introduced in Android SDK 2.9.0.
949
- */
950
- export function pausePushInAppMessages(isPaused: boolean): Promise<void> {
951
- if (Platform.OS === 'android') {
952
- return RetenoSdk.pausePushInAppMessages(isPaused);
953
- }
954
- return Promise.resolve(undefined);
955
- }
956
-
957
- /**
958
- * Android Only
959
- * Set the behaviour for push-triggered in-app messages when paused.
960
- * Introduced in Android SDK 2.9.0.
961
- */
962
- export function setPushInAppMessagesPauseBehaviour(
963
- behaviour: InAppPauseBehaviour
964
- ): Promise<void> {
965
- if (Platform.OS === 'android') {
966
- return RetenoSdk.setPushInAppMessagesPauseBehaviour(behaviour);
967
- }
968
- return Promise.resolve(undefined);
969
- }
1117
+ export const user = {
1118
+ setAttributes: setUserAttributes,
1119
+ setMultiAccountAttributes: setMultiAccountUserAttributes,
1120
+ setAnonymousAttributes: setAnonymousUserAttributes,
1121
+ } as const;
1122
+
1123
+ export const push = {
1124
+ setDeviceToken,
1125
+ registerForRemoteNotifications,
1126
+ getInitialNotification,
1127
+ setOnReceivedListener: setOnRetenoPushReceivedListener,
1128
+ setOnClickedListener: setOnRetenoPushClickedListener,
1129
+ setOnButtonClickedListener: setOnRetenoPushButtonClickedListener,
1130
+ setOnDismissedListener: setOnRetenoPushDismissedListener,
1131
+ setOnCustomDataListener: setOnRetenoCustomPushDataListener,
1132
+ requestNotificationPermission,
1133
+ getNotificationPermissionStatus,
1134
+ updatePermissionStatusAndroid: updatePushPermissionStatusAndroid,
1135
+ pauseTriggeredInAppMessages: pausePushInAppMessages,
1136
+ setTriggeredInAppMessagesPauseBehaviour: setPushInAppMessagesPauseBehaviour,
1137
+ setGroupingRule: setNotificationGroupingRule,
1138
+ } as const;
1139
+
1140
+ export const events = {
1141
+ addEventListener,
1142
+ removeEventListener,
1143
+ initializeEventHandler,
1144
+ } as const;
1145
+
1146
+ export const inApp = {
1147
+ setLifecycleCallback: setInAppLifecycleCallback,
1148
+ removeLifecycleCallback: removeInAppLifecycleCallback,
1149
+ beforeDisplay: beforeInAppDisplayHandler,
1150
+ onDisplay: onInAppDisplayHandler,
1151
+ beforeClose: beforeInAppCloseHandler,
1152
+ afterClose: afterInAppCloseHandler,
1153
+ onError: onInAppErrorHandler,
1154
+ onCustomData: addInAppMessageCustomDataHandler,
1155
+ pauseMessages: pauseInAppMessages,
1156
+ setPauseBehaviour: setInAppMessagesPauseBehaviour,
1157
+ setAutoOpenLinks,
1158
+ getAutoOpenLinks,
1159
+ } as const;
1160
+
1161
+ export const inbox = {
1162
+ getMessages: getAppInboxMessages,
1163
+ markAsOpened,
1164
+ markAllAsOpened,
1165
+ getMessagesCount: getAppInboxMessagesCount,
1166
+ subscribeUnreadCount: onUnreadMessagesCountChanged,
1167
+ unsubscribeUnreadCount: unsubscribeMessagesCountChanged,
1168
+ unsubscribeAllUnreadCount: unsubscribeAllMessagesCountChanged,
1169
+ onUnreadCountChanged: unreadMessagesCountHandler,
1170
+ onUnreadCountError: unreadMessagesCountErrorHandler,
1171
+ } as const;
1172
+
1173
+ export const recommendations = {
1174
+ get: getRecommendations,
1175
+ logEvent: logRecommendationEvent,
1176
+ } as const;
1177
+
1178
+ export const ecommerce = {
1179
+ productViewed: logEcomEventProductViewed,
1180
+ productCategoryViewed: logEcomEventProductCategoryViewed,
1181
+ productAddedToWishlist: logEcomEventProductAddedToWishlist,
1182
+ cartUpdated: logEcomEventCartUpdated,
1183
+ orderCreated: logEcomEventOrderCreated,
1184
+ orderUpdated: logEcomEventOrderUpdated,
1185
+ orderDelivered: logEcomEventOrderDelivered,
1186
+ orderCancelled: logEcomEventOrderCancelled,
1187
+ searchRequest: logEcomEventSearchRequest,
1188
+ } as const;