reteno-react-native-sdk 2.2.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,26 +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
- export type NotificationGroupingRule =
153
- | { payloadKey: string; groupId?: never }
154
- | { groupId: string; payloadKey?: never };
155
-
156
146
  export type InAppCustomData = {
157
- customData?: Record<string, any>;
147
+ customData?: Record<string, unknown>;
158
148
  inapp_id?: string;
159
149
  inapp_source?: 'DISPLAY_RULES' | 'PUSH_NOTIFICATION';
160
150
  url?: string;
161
151
  };
162
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
+
163
161
  export type RecommendationsPayload = {
164
162
  recomVariantId: string;
165
163
  productIds: string[];
166
164
  categoryId: string;
167
- 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[];
168
170
  fields: string[];
169
171
  };
170
172
 
@@ -183,13 +185,19 @@ export type RecommendationEventPayload = {
183
185
  export type InboxMessage = {
184
186
  id: string;
185
187
  title: string;
186
- 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;
187
195
  imageURL?: string;
188
196
  linkURL?: string;
189
197
  isNew: boolean;
190
198
  content?: string;
191
- // Only on Android
192
199
  category?: string;
200
+ // Only on Android — the iOS native SDK has no equivalent concept.
193
201
  status?: AppInboxStatus;
194
202
  };
195
203
 
@@ -203,15 +211,51 @@ export type UnreadMessagesCountErrorData = {
203
211
  error?: string | null;
204
212
  };
205
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
+
206
245
  export type PushButton = {
207
246
  actionId: string;
247
+ /** Raw string as forwarded by the native SDK (commonly JSON-encoded) — not parsed here. */
208
248
  customData: string | null;
209
249
  actionLink: string | null;
210
- userInfo: any;
250
+ userInfo: RetenoPushPayload;
211
251
  };
212
252
 
213
- const RetenoSdk = NativeModules.RetenoSdk
214
- ? NativeModules.RetenoSdk
253
+ export type RetenoPushButtonClickedEvent = PushButton;
254
+
255
+ const nativeRetenoSdk = NativeRetenoSdk ?? NativeModules.RetenoSdk;
256
+
257
+ const RetenoSdk = nativeRetenoSdk
258
+ ? nativeRetenoSdk
215
259
  : new Proxy(
216
260
  {},
217
261
  {
@@ -221,6 +265,88 @@ const RetenoSdk = NativeModules.RetenoSdk
221
265
  }
222
266
  );
223
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
+
224
350
  export function initialize(
225
351
  input: string | InitializeOptions
226
352
  ): Promise<boolean> {
@@ -254,19 +380,34 @@ export function setUserAttributes(
254
380
  !payload.externalUserId ||
255
381
  (payload.externalUserId && payload.externalUserId.length === 0)
256
382
  ) {
257
- throw new Error('Missing argument: "externalUserId"');
383
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
258
384
  }
259
385
  return RetenoSdk.setUserAttributes(payload);
260
386
  }
261
387
 
262
- export function getInitialNotification(): Promise<any> {
388
+ export function getInitialNotification(): Promise<RetenoInitialNotification | null> {
263
389
  return RetenoSdk.getInitialNotification();
264
390
  }
265
391
 
266
- 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>(
267
401
  payload: RecommendationsPayload
268
- ): Promise<any> {
269
- 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
+ });
270
411
  }
271
412
 
272
413
  export function logRecommendationEvent(
@@ -275,10 +416,56 @@ export function logRecommendationEvent(
275
416
  return RetenoSdk.logRecommendationEvent(payload);
276
417
  }
277
418
 
278
- const eventEmitter =
279
- Platform.OS === 'android'
280
- ? DeviceEventEmitter
281
- : 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
+ }
282
469
 
283
470
  /**
284
471
  * Initialize event handler. Call this after setting up all event listeners.
@@ -340,30 +527,28 @@ export function getAutoOpenLinks(): Promise<boolean> {
340
527
  }
341
528
 
342
529
  export function setOnRetenoPushReceivedListener(
343
- listener: (event: any) => void
530
+ listener: (event: RetenoPushReceivedEvent) => void
344
531
  ) {
345
- return eventEmitter.addListener('reteno-push-received', listener);
532
+ return addEventListener('pushReceived', listener);
346
533
  }
347
534
 
348
- export function setOnRetenoPushClickedListener(listener: (event: any) => void) {
349
- return eventEmitter.addListener('reteno-push-clicked', listener);
535
+ export function setOnRetenoPushClickedListener(
536
+ listener: (event: RetenoPushClickedEvent) => void
537
+ ) {
538
+ return addEventListener('pushClicked', listener);
350
539
  }
351
540
 
352
541
  /**
353
542
  * iOS Only
354
543
  */
355
544
  export function setOnRetenoPushButtonClickedListener(
356
- listener: (event: PushButton) => void
545
+ listener: (event: RetenoPushButtonClickedEvent) => void
357
546
  ) {
358
- if (Platform.OS === 'ios') {
359
- return eventEmitter.addListener('reteno-push-button-clicked', listener);
360
- }
361
-
362
- return undefined;
547
+ return addEventListener('pushButtonClicked', listener);
363
548
  }
364
549
 
365
550
  export function setInAppLifecycleCallback() {
366
- RetenoSdk.setInAppLifecycleCallback();
551
+ return RetenoSdk.setInAppLifecycleCallback();
367
552
  }
368
553
 
369
554
  /**
@@ -371,69 +556,43 @@ export function setInAppLifecycleCallback() {
371
556
  */
372
557
  export function removeInAppLifecycleCallback() {
373
558
  if (Platform.OS === 'android') {
374
- RetenoSdk.removeInAppLifecycleCallback();
559
+ return RetenoSdk.removeInAppLifecycleCallback();
375
560
  }
561
+ return Promise.resolve(undefined);
376
562
  }
377
563
 
378
564
  export function beforeInAppDisplayHandler(
379
565
  callback: (data: InAppDisplayData) => void
380
566
  ) {
381
- return eventEmitter.addListener('reteno-before-in-app-display', (data) => {
382
- if (callback && typeof callback === 'function') {
383
- callback(data);
384
- }
385
- });
567
+ return addEventListener('beforeInAppDisplay', callback);
386
568
  }
387
569
 
388
570
  export function onInAppDisplayHandler(
389
571
  callback: (data: InAppDisplayData) => void
390
572
  ) {
391
- return eventEmitter.addListener('reteno-on-in-app-display', (data) => {
392
- if (callback && typeof callback === 'function') {
393
- callback(data);
394
- }
395
- });
573
+ return addEventListener('inAppDisplay', callback);
396
574
  }
397
575
 
398
576
  export function beforeInAppCloseHandler(
399
577
  callback: (data: InAppCloseData) => void
400
578
  ) {
401
- return eventEmitter.addListener('reteno-before-in-app-close', (data) => {
402
- if (callback && typeof callback === 'function') {
403
- callback(data);
404
- }
405
- });
579
+ return addEventListener('beforeInAppClose', callback);
406
580
  }
407
581
 
408
582
  export function afterInAppCloseHandler(
409
583
  callback: (data: InAppCloseData) => void
410
584
  ) {
411
- return eventEmitter.addListener('reteno-after-in-app-close', (data) => {
412
- if (callback && typeof callback === 'function') {
413
- callback(data);
414
- }
415
- });
585
+ return addEventListener('afterInAppClose', callback);
416
586
  }
417
587
 
418
588
  export function onInAppErrorHandler(callback: (data: InAppErrorData) => void) {
419
- return eventEmitter.addListener('reteno-on-in-app-error', (data) => {
420
- if (callback && typeof callback === 'function') {
421
- callback(data);
422
- }
423
- });
589
+ return addEventListener('inAppError', callback);
424
590
  }
425
591
 
426
592
  export function addInAppMessageCustomDataHandler(
427
- callback: (data: InAppCustomData) => void
593
+ callback: (data: RetenoInAppCustomDataEvent) => void
428
594
  ) {
429
- return eventEmitter.addListener(
430
- 'reteno-in-app-custom-data-received',
431
- (data) => {
432
- if (callback && typeof callback === 'function') {
433
- callback(data);
434
- }
435
- }
436
- );
595
+ return addEventListener('inAppCustomData', callback);
437
596
  }
438
597
 
439
598
  /**
@@ -501,7 +660,7 @@ export function setMultiAccountUserAttributes(
501
660
  payload: SetMultiAccountUserAttributesPayload
502
661
  ): Promise<void> {
503
662
  if (!payload.externalUserId) {
504
- throw new Error('Missing argument: "externalUserId"');
663
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
505
664
  }
506
665
  return RetenoSdk.setMultiAccountUserAttributes(payload);
507
666
  }
@@ -512,19 +671,14 @@ export function setMultiAccountUserAttributes(
512
671
  * Call this function to send all accumulated events
513
672
  */
514
673
  export function forcePushData(): Promise<void> {
515
- if (Platform.OS === 'ios') {
516
- // 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
517
- return logEvent('', new Date().toISOString(), [], true);
518
- } else return RetenoSdk.forcePushData();
674
+ return RetenoSdk.forcePushData();
519
675
  }
520
676
  /**
521
677
  * Send log screen view event
522
678
  * @param screenName name of the screen
523
679
  */
524
- export function logScreenView(screenName: string) {
525
- return logEvent(CustomEventTypes.screenView, new Date().toISOString(), [
526
- { name: CustomEventTypes.screenView, value: screenName },
527
- ]);
680
+ export function logScreenView(screenName: string): Promise<void> {
681
+ return RetenoSdk.logScreenView(screenName);
528
682
  }
529
683
 
530
684
  /**
@@ -564,11 +718,7 @@ export function unsubscribeAllMessagesCountChanged(): Promise<void> {
564
718
  export function unreadMessagesCountHandler(
565
719
  callback: (data: UnreadMessagesCountData) => void
566
720
  ) {
567
- return eventEmitter.addListener('reteno-unread-messages-count', (data) => {
568
- if (callback && typeof callback === 'function') {
569
- callback(data);
570
- }
571
- });
721
+ return addEventListener('unreadMessagesCountChanged', callback);
572
722
  }
573
723
 
574
724
  /**
@@ -577,18 +727,7 @@ export function unreadMessagesCountHandler(
577
727
  export function unreadMessagesCountErrorHandler(
578
728
  callback: (data: UnreadMessagesCountErrorData) => void
579
729
  ) {
580
- if (Platform.OS === 'android') {
581
- return eventEmitter.addListener(
582
- 'reteno-unread-messages-count-error',
583
- (data) => {
584
- if (callback && typeof callback === 'function') {
585
- callback(data);
586
- }
587
- }
588
- );
589
- }
590
-
591
- return undefined;
730
+ return addEventListener('unreadMessagesCountError', callback);
592
731
  }
593
732
 
594
733
  export function markAsOpened(
@@ -599,13 +738,6 @@ export function markAsOpened(
599
738
  status: messageIds?.length ? 'OPENED' : '',
600
739
  };
601
740
 
602
- if (Platform.OS === 'android') {
603
- return RetenoSdk.markAsOpened(messageIds?.[0]).then(
604
- () => response,
605
- (error: any) => Promise.reject(error)
606
- );
607
- }
608
-
609
741
  return RetenoSdk.markAsOpened(messageIds).then(
610
742
  () => response,
611
743
  (error: any) => Promise.reject(error)
@@ -842,12 +974,9 @@ export function logEcomEventSearchRequest(
842
974
  * Listen for push notification dismissed (swiped away) events.
843
975
  */
844
976
  export function setOnRetenoPushDismissedListener(
845
- listener: (event: any) => void
846
- ): ReturnType<typeof eventEmitter.addListener> | undefined {
847
- if (Platform.OS === 'android') {
848
- return eventEmitter.addListener('reteno-push-dismissed', listener);
849
- }
850
- return undefined;
977
+ listener: (event: RetenoPushDismissedEvent) => void
978
+ ): RetenoSubscription {
979
+ return addEventListener('pushDismissed', listener);
851
980
  }
852
981
 
853
982
  /**
@@ -855,42 +984,90 @@ export function setOnRetenoPushDismissedListener(
855
984
  * Listen for custom push data events (silent/data-only push messages).
856
985
  */
857
986
  export function setOnRetenoCustomPushDataListener(
858
- listener: (event: any) => void
859
- ): ReturnType<typeof eventEmitter.addListener> | undefined {
860
- if (Platform.OS === 'android') {
861
- return eventEmitter.addListener('reteno-custom-push-received', listener);
862
- }
863
- return undefined;
987
+ listener: (event: RetenoCustomPushDataEvent) => void
988
+ ): RetenoSubscription {
989
+ return addEventListener('customPushData', listener);
864
990
  }
865
991
 
866
992
  /**
867
- * Android Only
993
+ * Android Only.
868
994
  * Request notification permission. Returns true if granted, false otherwise.
869
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.)
870
999
  */
871
1000
  export function requestNotificationPermission(): Promise<boolean> {
872
1001
  if (Platform.OS === 'android') {
873
1002
  return RetenoSdk.requestNotificationPermission();
874
1003
  }
875
- return Promise.resolve(false);
1004
+ return Promise.reject(
1005
+ new Error('requestNotificationPermission() is not supported on iOS')
1006
+ );
876
1007
  }
877
1008
 
878
1009
  /**
879
- * Android Only
1010
+ * Android Only.
880
1011
  * Get current notification permission status.
881
1012
  * Returns 'ALLOWED', 'DENIED', or 'PERMANENTLY_DENIED'.
882
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.)
883
1017
  */
884
1018
  export function getNotificationPermissionStatus(): Promise<NotificationPermissionStatus> {
885
1019
  if (Platform.OS === 'android') {
886
1020
  return RetenoSdk.getNotificationPermissionStatus();
887
1021
  }
888
- return Promise.resolve('ALLOWED' as NotificationPermissionStatus);
1022
+ return Promise.reject(
1023
+ new Error('getNotificationPermissionStatus() is not supported on iOS')
1024
+ );
1025
+ }
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);
889
1051
  }
890
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
+
891
1065
  /**
892
1066
  * Android only. Groups notifications by a push payload value or a constant ID.
893
1067
  * Pass `null` to disable grouping.
1068
+ *
1069
+ * `showSummary` requires Android 6.0 (API 23) or higher; on older versions the
1070
+ * promise still resolves successfully, but no summary notification is created.
894
1071
  */
895
1072
  export function setNotificationGroupingRule(
896
1073
  rule: NotificationGroupingRule | null
@@ -922,33 +1099,90 @@ export function setNotificationGroupingRule(
922
1099
  );
923
1100
  }
924
1101
 
925
- return RetenoSdk.setNotificationGroupingRule(
926
- payloadKey ? { payloadKey } : { groupId }
927
- );
928
- }
929
-
930
- /**
931
- * Android Only
932
- * Pause or resume push-triggered in-app messages specifically.
933
- * Introduced in Android SDK 2.9.0.
934
- */
935
- export function pausePushInAppMessages(isPaused: boolean): Promise<void> {
936
- if (Platform.OS === 'android') {
937
- return RetenoSdk.pausePushInAppMessages(isPaused);
1102
+ if (rule.showSummary !== undefined && typeof rule.showSummary !== 'boolean') {
1103
+ return Promise.reject(
1104
+ new Error('Invalid argument: showSummary must be a boolean')
1105
+ );
938
1106
  }
939
- return Promise.resolve(undefined);
940
- }
941
1107
 
942
- /**
943
- * Android Only
944
- * Set the behaviour for push-triggered in-app messages when paused.
945
- * Introduced in Android SDK 2.9.0.
946
- */
947
- export function setPushInAppMessagesPauseBehaviour(
948
- behaviour: InAppPauseBehaviour
949
- ): Promise<void> {
950
- if (Platform.OS === 'android') {
951
- return RetenoSdk.setPushInAppMessagesPauseBehaviour(behaviour);
1108
+ const normalizedRule: Record<string, unknown> = payloadKey
1109
+ ? { payloadKey }
1110
+ : { groupId };
1111
+ if (rule.showSummary === true) {
1112
+ normalizedRule.showSummary = true;
952
1113
  }
953
- return Promise.resolve(undefined);
1114
+ return RetenoSdk.setNotificationGroupingRule(normalizedRule);
954
1115
  }
1116
+
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;