1- import {
2- Linking ,
3- NativeEventEmitter ,
4- Platform ,
5- } from 'react-native' ;
1+ import { Linking , NativeEventEmitter , Platform } from 'react-native' ;
62
73import { buildInfo } from '../../itblBuildInfo' ;
84
@@ -13,7 +9,8 @@ import { IterableInAppMessage } from '../../inApp/classes/IterableInAppMessage';
139import { IterableInAppCloseSource } from '../../inApp/enums/IterableInAppCloseSource' ;
1410import { IterableInAppDeleteSource } from '../../inApp/enums/IterableInAppDeleteSource' ;
1511import { IterableInAppLocation } from '../../inApp/enums/IterableInAppLocation' ;
16- import { IterableAuthResponseResult , IterableEventName } from '../enums' ;
12+ import { IterableAuthResponseResult } from '../enums/IterableAuthResponseResult' ;
13+ import { IterableEventName } from '../enums/IterableEventName' ;
1714
1815// Add this type-only import to avoid circular dependency
1916import type { IterableInAppManager } from '../../inApp/classes/IterableInAppManager' ;
@@ -25,6 +22,7 @@ import { IterableAuthResponse } from './IterableAuthResponse';
2522import type { IterableCommerceItem } from './IterableCommerceItem' ;
2623import { IterableConfig } from './IterableConfig' ;
2724import { IterableLogger } from './IterableLogger' ;
25+ import type { IterableAuthFailure } from '../types/IterableAuthFailure' ;
2826
2927const RNEventEmitter = new NativeEventEmitter ( RNIterableAPI ) ;
3028
@@ -79,8 +77,11 @@ export class Iterable {
7977 // Lazy initialization to avoid circular dependency
8078 if ( ! this . _inAppManager ) {
8179 // Import here to avoid circular dependency at module level
82- // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
83- const { IterableInAppManager } = require ( '../../inApp/classes/IterableInAppManager' ) ;
80+
81+ const {
82+ IterableInAppManager,
83+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
84+ } = require ( '../../inApp/classes/IterableInAppManager' ) ;
8485 this . _inAppManager = new IterableInAppManager ( ) ;
8586 }
8687 return this . _inAppManager ;
@@ -357,7 +358,13 @@ export class Iterable {
357358 Iterable ?. logger ?. log ( 'getAttributionInfo' ) ;
358359
359360 return RNIterableAPI . getAttributionInfo ( ) . then (
360- ( dict : { campaignId : number ; templateId : number ; messageId : string } | null ) => {
361+ (
362+ dict : {
363+ campaignId : number ;
364+ templateId : number ;
365+ messageId : string ;
366+ } | null
367+ ) => {
361368 if ( dict ) {
362369 return new IterableAttributionInfo (
363370 dict . campaignId as number ,
@@ -398,7 +405,11 @@ export class Iterable {
398405 static setAttributionInfo ( attributionInfo ?: IterableAttributionInfo ) {
399406 Iterable ?. logger ?. log ( 'setAttributionInfo' ) ;
400407
401- RNIterableAPI . setAttributionInfo ( attributionInfo as unknown as { [ key : string ] : string | number | boolean ; } | null ) ;
408+ RNIterableAPI . setAttributionInfo (
409+ attributionInfo as unknown as {
410+ [ key : string ] : string | number | boolean ;
411+ } | null
412+ ) ;
402413 }
403414
404415 /**
@@ -477,7 +488,9 @@ export class Iterable {
477488 static updateCart ( items : IterableCommerceItem [ ] ) {
478489 Iterable ?. logger ?. log ( 'updateCart' ) ;
479490
480- RNIterableAPI . updateCart ( items as unknown as { [ key : string ] : string | number | boolean } [ ] ) ;
491+ RNIterableAPI . updateCart (
492+ items as unknown as { [ key : string ] : string | number | boolean } [ ]
493+ ) ;
481494 }
482495
483496 /**
@@ -529,7 +542,11 @@ export class Iterable {
529542 ) {
530543 Iterable ?. logger ?. log ( 'trackPurchase' ) ;
531544
532- RNIterableAPI . trackPurchase ( total , items as unknown as { [ key : string ] : string | number | boolean } [ ] , dataFields as { [ key : string ] : string | number | boolean } | undefined ) ;
545+ RNIterableAPI . trackPurchase (
546+ total ,
547+ items as unknown as { [ key : string ] : string | number | boolean } [ ] ,
548+ dataFields as { [ key : string ] : string | number | boolean } | undefined
549+ ) ;
533550 }
534551
535552 /**
@@ -698,7 +715,10 @@ export class Iterable {
698715 static trackEvent ( name : string , dataFields ?: unknown ) {
699716 Iterable ?. logger ?. log ( 'trackEvent' ) ;
700717
701- RNIterableAPI . trackEvent ( name , dataFields as { [ key : string ] : string | number | boolean } | undefined ) ;
718+ RNIterableAPI . trackEvent (
719+ name ,
720+ dataFields as { [ key : string ] : string | number | boolean } | undefined
721+ ) ;
702722 }
703723
704724 /**
@@ -746,7 +766,10 @@ export class Iterable {
746766 ) {
747767 Iterable ?. logger ?. log ( 'updateUser' ) ;
748768
749- RNIterableAPI . updateUser ( dataFields as { [ key : string ] : string | number | boolean } , mergeNestedObjects ) ;
769+ RNIterableAPI . updateUser (
770+ dataFields as { [ key : string ] : string | number | boolean } ,
771+ mergeNestedObjects
772+ ) ;
750773 }
751774
752775 /**
@@ -911,34 +934,45 @@ export class Iterable {
911934 }
912935
913936 /**
914- * Sets up event handlers for various Iterable events .
937+ * A callback function that is called when an authentication failure occurs .
915938 *
916- * This method performs the following actions:
917- * - Removes all existing listeners to avoid duplicate listeners.
918- * - Adds listeners for URL handling, custom actions, in-app messages, and authentication.
939+ * @param authFailure - The auth failure details
919940 *
920- * Event Handlers:
921- * - `handleUrlCalled`: Invokes the URL handler if configured, with a delay on Android to allow the activity to wake up.
922- * - `handleCustomActionCalled`: Invokes the custom action handler if configured.
923- * - `handleInAppCalled`: Invokes the in-app handler if configured and sets the in-app show response.
924- * - `handleAuthCalled`: Invokes the authentication handler if configured and handles the promise result.
925- * - `handleAuthSuccessCalled`: Sets the authentication response callback to success.
926- * - `handleAuthFailureCalled`: Sets the authentication response callback to failure.
941+ * @example
942+ * ```typescript
943+ * Iterable.onAuthFailure({
944+ * userKey: '1234567890',
945+ * failedAuthToken: '1234567890',
946+ * failedRequestTime: 1234567890,
947+ * failureReason: IterableAuthFailureReason.AUTH_TOKEN_EXPIRED,
948+ * });
949+ * ```
950+ */
951+ static onAuthFailure ( authFailure : IterableAuthFailure ) {
952+ Iterable ?. logger ?. log ( 'onAuthFailure' ) ;
953+
954+ RNIterableAPI . onAuthFailure ( authFailure ) ;
955+ }
956+
957+ /**
958+ * Pause the authentication retry mechanism.
927959 *
928- * Helper Functions:
929- * - `callUrlHandler`: Calls the URL handler and attempts to open the URL if the handler returns false.
960+ * @param pauseRetry - Whether to pause the authentication retry mechanism
930961 *
931- * @internal
962+ * @example
963+ * ```typescript
964+ * Iterable.pauseAuthRetries(true);
965+ * ```
932966 */
933- private static setupEventHandlers ( ) {
934- //Remove all listeners to avoid duplicate listeners
935- RNEventEmitter . removeAllListeners ( IterableEventName . handleUrlCalled ) ;
936- RNEventEmitter . removeAllListeners ( IterableEventName . handleInAppCalled ) ;
937- RNEventEmitter . removeAllListeners (
938- IterableEventName . handleCustomActionCalled
939- ) ;
940- RNEventEmitter . removeAllListeners ( IterableEventName . handleAuthCalled ) ;
967+ static pauseAuthRetries ( pauseRetry : boolean ) {
968+ Iterable ?. logger ?. log ( 'pauseAuthRetries' ) ;
969+
970+ RNIterableAPI . pauseAuthRetries ( pauseRetry ) ;
971+ }
941972
973+ /** * @internal
974+ */
975+ private static setupEventHandlers ( ) {
942976 if ( Iterable . savedConfig . urlHandler ) {
943977 RNEventEmitter . addListener ( IterableEventName . handleUrlCalled , ( dict ) => {
944978 const url = dict . url ;
0 commit comments