@@ -14,7 +14,7 @@ const RNIterableAPI = NativeModules.RNIterableAPI
1414const RNEventEmitter = new NativeEventEmitter ( RNIterableAPI )
1515
1616/**
17- * Enum representing the source of IteraleAction .
17+ * Enum representing the source of IterableAction .
1818*/
1919enum IterableActionSource {
2020 push = 0 ,
@@ -31,7 +31,6 @@ enum IterableLogLevel {
3131 error = 3
3232}
3333
34-
3534/**
3635Iterable Configuration Object. Use this when initializing the API.
3736*/
@@ -42,39 +41,55 @@ class IterableConfig {
4241 * To view your existing integrations, navigate to Settings > Mobile Apps
4342 */
4443 pushIntegrationName ?: string
44+
4545 /**
4646 * When set to true, IterableSDK will automatically register and deregister notification tokens.
4747 */
4848 autoPushRegistration = true
49+
4950 /**
5051 * When set to true, it will check for deferred deep links on first time app launch after installation from the App Store.
5152 */
5253 checkForDeferredDeeplink = false
54+
5355 /**
5456 * How many seconds to wait before showing the next in-app, if there are more than one present
5557 */
5658 inAppDisplayInterval : number = 30.0
59+
5760 /**
5861 * How many seconds to wait before showing the next in-app, if there are more than one present
5962 */
6063 urlHandler ?: ( url : string , context : IterableActionContext ) => boolean
64+
6165 /**
6266 * How to handle IterableActions which are other than 'openUrl'
6367 */
6468 customActionHandler ?: ( action : IterableAction , context : IterableActionContext ) => boolean
69+
6570 /**
6671 * Implement this protocol to override default in-app behavior.
6772 * By default, every single in-app will be shown as soon as it is available.
6873 * If more than 1 in-app is available, we show the first.
6974 */
7075 inAppHandler ?: ( message : IterableInAppMessage ) => IterableInAppShowResponse
7176
77+ /**
78+ * The handler with which your own calls to your backend containing the auth token happen
79+ */
80+ authHandler ?: ( ) => Promise < string | undefined >
81+
7282 /**
7383 * Set the verbosity of Android and iOS project's log system.
7484 * By default, you will be able to see info level logs printed in IDE when running the app.
7585 */
7686 logLevel : IterableLogLevel = IterableLogLevel . info
7787
88+ /**
89+ * Set the amount of time (in seconds) before the current auth token expires to make a call to retrieve a new one
90+ */
91+ expiringAuthTokenRefreshPeriod : number = 60.0
92+
7893 toDict ( ) : any {
7994 return {
8095 "pushIntegrationName" : this . pushIntegrationName ,
@@ -84,7 +99,9 @@ class IterableConfig {
8499 "urlHandlerPresent" : this . urlHandler != undefined ,
85100 "customActionHandlerPresent" : this . customActionHandler != undefined ,
86101 "inAppHandlerPresent" : this . inAppHandler != undefined ,
87- "logLevel" : this . logLevel
102+ "authHandlerPresent" : this . authHandler != undefined ,
103+ "logLevel" : this . logLevel ,
104+ "expiringAuthTokenRefreshPeriod" : this . expiringAuthTokenRefreshPeriod
88105 }
89106 }
90107}
@@ -137,9 +154,6 @@ class IterableAttributionInfo {
137154 }
138155}
139156
140- /**
141- * How many seconds to wait before showing the next in-app, if there are more than one present
142- */
143157class IterableCommerceItem {
144158 id : string
145159 name : string
@@ -158,6 +172,7 @@ enum EventName {
158172 handleUrlCalled = "handleUrlCalled" ,
159173 handleCustomActionCalled = "handleCustomActionCalled" ,
160174 handleInAppCalled = "handleInAppCalled" ,
175+ handleAuthCalled = "handleAuthCalled"
161176}
162177
163178class Iterable {
@@ -190,6 +205,7 @@ class Iterable {
190205 }
191206 )
192207 }
208+
193209 if ( config . customActionHandler ) {
194210 RNEventEmitter . addListener (
195211 EventName . handleCustomActionCalled ,
@@ -200,6 +216,7 @@ class Iterable {
200216 }
201217 )
202218 }
219+
203220 if ( config . inAppHandler ) {
204221 RNEventEmitter . addListener (
205222 EventName . handleInAppCalled ,
@@ -211,6 +228,18 @@ class Iterable {
211228 )
212229 }
213230
231+ if ( config . authHandler ) {
232+ RNEventEmitter . addListener (
233+ EventName . handleAuthCalled ,
234+ ( ) => {
235+ config . authHandler ! ( )
236+ . then ( authToken => {
237+ RNIterableAPI . passAlongAuthToken ( authToken )
238+ } )
239+ }
240+ )
241+ }
242+
214243 // Set version from package.json
215244 const json = require ( '../package.json' )
216245 const version = json [ "version" ] as string
0 commit comments