@trycourier/courier-react-native 5.5.0 → 5.5.1

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.
@@ -1,5 +1,5 @@
1
1
  CourierReactNative_kotlinVersion=1.7.0
2
- CourierReactNative_minSdkVersion=21
2
+ CourierReactNative_minSdkVersion=23
3
3
  CourierReactNative_targetSdkVersion=31
4
4
  CourierReactNative_compileSdkVersion=31
5
5
  CourierReactNative_ndkversion=21.4.7075529
@@ -15,7 +15,13 @@ import kotlinx.coroutines.Dispatchers
15
15
  import kotlinx.coroutines.launch
16
16
  import java.util.UUID
17
17
 
18
- class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Client Error", name = "CourierClientModule", reactContext = reactContext) {
18
+ class CourierClientModule(
19
+ reactContext: ReactApplicationContext
20
+ ) : ReactNativeModule(
21
+ tag = "Client Error",
22
+ name = "CourierClientModule",
23
+ reactContext = reactContext
24
+ ) {
19
25
 
20
26
  private var clients: MutableMap<String, CourierClient> = mutableMapOf()
21
27
 
@@ -31,7 +37,6 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
31
37
 
32
38
  @ReactMethod(isBlockingSynchronousMethod = true)
33
39
  fun addClient(options: ReadableMap): String {
34
-
35
40
  val userId = options.getString("userId")
36
41
  val showLogs = if (options.hasKey("showLogs")) options.getBoolean("showLogs") else null
37
42
 
@@ -52,7 +57,6 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
52
57
  clients[uuid] = client
53
58
 
54
59
  return uuid
55
-
56
60
  }
57
61
 
58
62
  @ReactMethod(isBlockingSynchronousMethod = true)
@@ -64,378 +68,369 @@ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeMod
64
68
  // Tokens
65
69
 
66
70
  @ReactMethod
67
- fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
68
-
69
- val client = clients[clientId]
70
- if (client == null) {
71
- promise.rejectMissingClient()
72
- return@launch
73
- }
74
-
75
- if (reactActivity == null) {
76
- promise.rejectMissingContext()
77
- return@launch
71
+ fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise) {
72
+ CoroutineScope(Dispatchers.Main).launch {
73
+ val client = clients[clientId]
74
+ if (client == null) {
75
+ promise.rejectMissingClient()
76
+ return@launch
77
+ }
78
+
79
+ if (reactActivity == null) {
80
+ promise.rejectMissingContext()
81
+ return@launch
82
+ }
83
+
84
+ val courierDevice = device?.let {
85
+ CourierDevice(
86
+ appId = it.getString("appId"),
87
+ adId = it.getString("adId"),
88
+ deviceId = it.getString("deviceId"),
89
+ platform = it.getString("platform"),
90
+ manufacturer = it.getString("manufacturer"),
91
+ model = it.getString("model")
92
+ )
93
+ }
94
+
95
+ try {
96
+ client.tokens.putUserToken(
97
+ token = token,
98
+ provider = provider,
99
+ device = courierDevice ?: CourierDevice.current(reactActivity!!)
100
+ )
101
+ promise.resolve(null)
102
+ } catch (e: Exception) {
103
+ promise.apiError(e)
104
+ }
78
105
  }
79
-
80
- val courierDevice = device?.let {
81
- return@let CourierDevice(
82
- appId = it.getString("appId"),
83
- adId = it.getString("adId"),
84
- deviceId = it.getString("deviceId"),
85
- platform = it.getString("platform"),
86
- manufacturer = it.getString("manufacturer"),
87
- model = it.getString("model")
88
- )
89
- }
90
-
91
- try {
92
- client.tokens.putUserToken(
93
- token = token,
94
- provider = provider,
95
- device = courierDevice ?: CourierDevice.current(reactActivity!!)
96
- )
97
- promise.resolve(null)
98
- } catch (e: Exception) {
99
- promise.apiError(e)
100
- }
101
-
102
106
  }
103
107
 
104
108
  @ReactMethod
105
- fun deleteUserToken(clientId: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
106
-
107
- val client = clients[clientId]
108
- if (client == null) {
109
- promise.rejectMissingClient()
110
- return@launch
111
- }
112
-
113
- try {
114
- client.tokens.deleteUserToken(
115
- token = token,
116
- )
117
- promise.resolve(null)
118
- } catch (e: Exception) {
119
- promise.apiError(e)
109
+ fun deleteUserToken(clientId: String, token: String, promise: Promise) {
110
+ CoroutineScope(Dispatchers.Main).launch {
111
+ val client = clients[clientId]
112
+ if (client == null) {
113
+ promise.rejectMissingClient()
114
+ return@launch
115
+ }
116
+
117
+ try {
118
+ client.tokens.deleteUserToken(token = token)
119
+ promise.resolve(null)
120
+ } catch (e: Exception) {
121
+ promise.apiError(e)
122
+ }
120
123
  }
121
-
122
124
  }
123
125
 
124
126
  // Brands
125
127
 
126
128
  @ReactMethod
127
- fun getBrand(clientId: String, brandId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
128
-
129
- val client = clients[clientId]
130
- if (client == null) {
131
- promise.rejectMissingClient()
132
- return@launch
129
+ fun getBrand(clientId: String, brandId: String, promise: Promise) {
130
+ CoroutineScope(Dispatchers.Main).launch {
131
+ val client = clients[clientId]
132
+ if (client == null) {
133
+ promise.rejectMissingClient()
134
+ return@launch
135
+ }
136
+
137
+ try {
138
+ val brand = client.brands.getBrand(brandId = brandId)
139
+ val json = brand.toJson()
140
+ promise.resolve(json)
141
+ } catch (e: Exception) {
142
+ promise.apiError(e)
143
+ }
133
144
  }
134
-
135
- try {
136
- val brand = client.brands.getBrand(
137
- brandId = brandId
138
- )
139
- val json = brand.toJson()
140
- promise.resolve(json)
141
- } catch (e: Exception) {
142
- promise.apiError(e)
143
- }
144
-
145
145
  }
146
146
 
147
147
  // Inbox
148
148
 
149
149
  @ReactMethod
150
- fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
151
-
152
- val client = clients[clientId]
153
- if (client == null) {
154
- promise.rejectMissingClient()
155
- return@launch
150
+ fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) {
151
+ CoroutineScope(Dispatchers.Main).launch {
152
+ val client = clients[clientId]
153
+ if (client == null) {
154
+ promise.rejectMissingClient()
155
+ return@launch
156
+ }
157
+
158
+ try {
159
+ val res = client.inbox.getMessages(
160
+ paginationLimit = paginationLimit,
161
+ startCursor = startCursor
162
+ )
163
+ val json = res.toJson()
164
+ promise.resolve(json)
165
+ } catch (e: Exception) {
166
+ promise.apiError(e)
167
+ }
156
168
  }
157
-
158
- try {
159
- val res = client.inbox.getMessages(
160
- paginationLimit = paginationLimit,
161
- startCursor = startCursor,
162
- )
163
- val json = res.toJson()
164
- promise.resolve(json)
165
- } catch (e: Exception) {
166
- promise.apiError(e)
167
- }
168
-
169
169
  }
170
170
 
171
171
  @ReactMethod
172
- fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
173
-
174
- val client = clients[clientId]
175
- if (client == null) {
176
- promise.rejectMissingClient()
177
- return@launch
178
- }
179
-
180
- try {
181
- val res = client.inbox.getArchivedMessages(
182
- paginationLimit = paginationLimit,
183
- startCursor = startCursor,
184
- )
185
- val json = res.toJson()
186
- promise.resolve(json)
187
- } catch (e: Exception) {
188
- promise.apiError(e)
172
+ fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) {
173
+ CoroutineScope(Dispatchers.Main).launch {
174
+ val client = clients[clientId]
175
+ if (client == null) {
176
+ promise.rejectMissingClient()
177
+ return@launch
178
+ }
179
+
180
+ try {
181
+ val res = client.inbox.getArchivedMessages(
182
+ paginationLimit = paginationLimit,
183
+ startCursor = startCursor
184
+ )
185
+ val json = res.toJson()
186
+ promise.resolve(json)
187
+ } catch (e: Exception) {
188
+ promise.apiError(e)
189
+ }
189
190
  }
190
-
191
191
  }
192
192
 
193
193
  @ReactMethod
194
- fun getMessageById(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
195
-
196
- val client = clients[clientId]
197
- if (client == null) {
198
- promise.rejectMissingClient()
199
- return@launch
200
- }
201
-
202
- try {
203
- val res = client.inbox.getMessage(
204
- messageId = messageId,
205
- )
206
- val json = res.toJson()
207
- promise.resolve(json)
208
- } catch (e: Exception) {
209
- promise.apiError(e)
194
+ fun getMessageById(clientId: String, messageId: String, promise: Promise) {
195
+ CoroutineScope(Dispatchers.Main).launch {
196
+ val client = clients[clientId]
197
+ if (client == null) {
198
+ promise.rejectMissingClient()
199
+ return@launch
200
+ }
201
+
202
+ try {
203
+ val res = client.inbox.getMessage(messageId = messageId)
204
+ val json = res.toJson()
205
+ promise.resolve(json)
206
+ } catch (e: Exception) {
207
+ promise.apiError(e)
208
+ }
210
209
  }
211
-
212
210
  }
213
211
 
214
212
  @ReactMethod
215
- fun getUnreadMessageCount(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
216
-
217
- val client = clients[clientId]
218
- if (client == null) {
219
- promise.rejectMissingClient()
220
- return@launch
213
+ fun getUnreadMessageCount(clientId: String, promise: Promise) {
214
+ CoroutineScope(Dispatchers.Main).launch {
215
+ val client = clients[clientId]
216
+ if (client == null) {
217
+ promise.rejectMissingClient()
218
+ return@launch
219
+ }
220
+
221
+ try {
222
+ val count = client.inbox.getUnreadMessageCount()
223
+ promise.resolve(count)
224
+ } catch (e: Exception) {
225
+ promise.apiError(e)
226
+ }
221
227
  }
222
-
223
- try {
224
- val count = client.inbox.getUnreadMessageCount()
225
- promise.resolve(count)
226
- } catch (e: Exception) {
227
- promise.apiError(e)
228
- }
229
-
230
228
  }
231
229
 
232
230
  @ReactMethod
233
- fun openMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
234
-
235
- val client = clients[clientId]
236
- if (client == null) {
237
- promise.rejectMissingClient()
238
- return@launch
239
- }
240
-
241
- try {
242
- client.inbox.open(
243
- messageId = messageId,
244
- )
245
- promise.resolve(null)
246
- } catch (e: Exception) {
247
- promise.apiError(e)
231
+ fun openMessage(clientId: String, messageId: String, promise: Promise) {
232
+ CoroutineScope(Dispatchers.Main).launch {
233
+ val client = clients[clientId]
234
+ if (client == null) {
235
+ promise.rejectMissingClient()
236
+ return@launch
237
+ }
238
+
239
+ try {
240
+ client.inbox.open(messageId = messageId)
241
+ promise.resolve(null)
242
+ } catch (e: Exception) {
243
+ promise.apiError(e)
244
+ }
248
245
  }
249
-
250
246
  }
251
247
 
252
248
  @ReactMethod
253
- fun readMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
254
-
255
- val client = clients[clientId]
256
- if (client == null) {
257
- promise.rejectMissingClient()
258
- return@launch
259
- }
260
-
261
- try {
262
- client.inbox.read(
263
- messageId = messageId,
264
- )
265
- promise.resolve(null)
266
- } catch (e: Exception) {
267
- promise.apiError(e)
249
+ fun readMessage(clientId: String, messageId: String, promise: Promise) {
250
+ CoroutineScope(Dispatchers.Main).launch {
251
+ val client = clients[clientId]
252
+ if (client == null) {
253
+ promise.rejectMissingClient()
254
+ return@launch
255
+ }
256
+
257
+ try {
258
+ client.inbox.read(messageId = messageId)
259
+ promise.resolve(null)
260
+ } catch (e: Exception) {
261
+ promise.apiError(e)
262
+ }
268
263
  }
269
-
270
264
  }
271
265
 
272
266
  @ReactMethod
273
- fun unreadMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
274
-
275
- val client = clients[clientId]
276
- if (client == null) {
277
- promise.rejectMissingClient()
278
- return@launch
267
+ fun unreadMessage(clientId: String, messageId: String, promise: Promise) {
268
+ CoroutineScope(Dispatchers.Main).launch {
269
+ val client = clients[clientId]
270
+ if (client == null) {
271
+ promise.rejectMissingClient()
272
+ return@launch
273
+ }
274
+
275
+ try {
276
+ client.inbox.unread(messageId = messageId)
277
+ promise.resolve(null)
278
+ } catch (e: Exception) {
279
+ promise.apiError(e)
280
+ }
279
281
  }
280
-
281
- try {
282
- client.inbox.unread(
283
- messageId = messageId,
284
- )
285
- promise.resolve(null)
286
- } catch (e: Exception) {
287
- promise.apiError(e)
288
- }
289
-
290
282
  }
291
283
 
292
284
  @ReactMethod
293
- fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
294
-
295
- val client = clients[clientId]
296
- if (client == null) {
297
- promise.rejectMissingClient()
298
- return@launch
285
+ fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise) {
286
+ CoroutineScope(Dispatchers.Main).launch {
287
+ val client = clients[clientId]
288
+ if (client == null) {
289
+ promise.rejectMissingClient()
290
+ return@launch
291
+ }
292
+
293
+ try {
294
+ client.inbox.click(
295
+ messageId = messageId,
296
+ trackingId = trackingId
297
+ )
298
+ promise.resolve(null)
299
+ } catch (e: Exception) {
300
+ promise.apiError(e)
301
+ }
299
302
  }
300
-
301
- try {
302
- client.inbox.click(
303
- messageId = messageId,
304
- trackingId = trackingId,
305
- )
306
- promise.resolve(null)
307
- } catch (e: Exception) {
308
- promise.apiError(e)
309
- }
310
-
311
303
  }
312
304
 
313
305
  @ReactMethod
314
- fun archiveMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
315
-
316
- val client = clients[clientId]
317
- if (client == null) {
318
- promise.rejectMissingClient()
319
- return@launch
320
- }
321
-
322
- try {
323
- client.inbox.archive(
324
- messageId = messageId,
325
- )
326
- promise.resolve(null)
327
- } catch (e: Exception) {
328
- promise.apiError(e)
306
+ fun archiveMessage(clientId: String, messageId: String, promise: Promise) {
307
+ CoroutineScope(Dispatchers.Main).launch {
308
+ val client = clients[clientId]
309
+ if (client == null) {
310
+ promise.rejectMissingClient()
311
+ return@launch
312
+ }
313
+
314
+ try {
315
+ client.inbox.archive(messageId = messageId)
316
+ promise.resolve(null)
317
+ } catch (e: Exception) {
318
+ promise.apiError(e)
319
+ }
329
320
  }
330
-
331
321
  }
332
322
 
333
323
  @ReactMethod
334
- fun readAllMessages(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
335
-
336
- val client = clients[clientId]
337
- if (client == null) {
338
- promise.rejectMissingClient()
339
- return@launch
340
- }
341
-
342
- try {
343
- client.inbox.readAll()
344
- promise.resolve(null)
345
- } catch (e: Exception) {
346
- promise.apiError(e)
324
+ fun readAllMessages(clientId: String, promise: Promise) {
325
+ CoroutineScope(Dispatchers.Main).launch {
326
+ val client = clients[clientId]
327
+ if (client == null) {
328
+ promise.rejectMissingClient()
329
+ return@launch
330
+ }
331
+
332
+ try {
333
+ client.inbox.readAll()
334
+ promise.resolve(null)
335
+ } catch (e: Exception) {
336
+ promise.apiError(e)
337
+ }
347
338
  }
348
-
349
339
  }
350
340
 
351
341
  // Preferences
352
342
 
353
343
  @ReactMethod
354
- fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
355
-
356
- val client = clients[clientId]
357
- if (client == null) {
358
- promise.rejectMissingClient()
359
- return@launch
344
+ fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise) {
345
+ CoroutineScope(Dispatchers.Main).launch {
346
+ val client = clients[clientId]
347
+ if (client == null) {
348
+ promise.rejectMissingClient()
349
+ return@launch
350
+ }
351
+
352
+ try {
353
+ val res = client.preferences.getUserPreferences(
354
+ paginationCursor = paginationCursor
355
+ )
356
+ val json = res.toJson()
357
+ promise.resolve(json)
358
+ } catch (e: Exception) {
359
+ promise.apiError(e)
360
+ }
360
361
  }
361
-
362
- try {
363
- val res = client.preferences.getUserPreferences(
364
- paginationCursor = paginationCursor
365
- )
366
- val json = res.toJson()
367
- promise.resolve(json)
368
- } catch (e: Exception) {
369
- promise.apiError(e)
370
- }
371
-
372
362
  }
373
363
 
374
364
  @ReactMethod
375
- fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
376
-
377
- val client = clients[clientId]
378
- if (client == null) {
379
- promise.rejectMissingClient()
380
- return@launch
381
- }
382
-
383
- try {
384
- val res = client.preferences.getUserPreferenceTopic(
385
- topicId = topicId
386
- )
387
- val json = res.toJson()
388
- promise.resolve(json)
389
- } catch (e: Exception) {
390
- promise.apiError(e)
365
+ fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise) {
366
+ CoroutineScope(Dispatchers.Main).launch {
367
+ val client = clients[clientId]
368
+ if (client == null) {
369
+ promise.rejectMissingClient()
370
+ return@launch
371
+ }
372
+
373
+ try {
374
+ val res = client.preferences.getUserPreferenceTopic(topicId = topicId)
375
+ val json = res.toJson()
376
+ promise.resolve(json)
377
+ } catch (e: Exception) {
378
+ promise.apiError(e)
379
+ }
391
380
  }
392
-
393
381
  }
394
382
 
395
383
  @ReactMethod
396
- fun putUserPreferenceTopic(clientId: String, topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
397
-
398
- val client = clients[clientId]
399
- if (client == null) {
400
- promise.rejectMissingClient()
401
- return@launch
402
- }
403
-
404
- try {
405
- client.preferences.putUserPreferenceTopic(
406
- topicId = topicId,
407
- status = CourierPreferenceStatus.fromString(status),
408
- hasCustomRouting = hasCustomRouting,
409
- customRouting = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) },
410
- )
411
- promise.resolve(null)
412
- } catch (e: Exception) {
413
- promise.apiError(e)
384
+ fun putUserPreferenceTopic(
385
+ clientId: String,
386
+ topicId: String,
387
+ status: String,
388
+ hasCustomRouting: Boolean,
389
+ customRouting: ReadableArray,
390
+ promise: Promise
391
+ ) {
392
+ CoroutineScope(Dispatchers.Main).launch {
393
+ val client = clients[clientId]
394
+ if (client == null) {
395
+ promise.rejectMissingClient()
396
+ return@launch
397
+ }
398
+
399
+ try {
400
+ client.preferences.putUserPreferenceTopic(
401
+ topicId = topicId,
402
+ status = CourierPreferenceStatus.fromString(status),
403
+ hasCustomRouting = hasCustomRouting,
404
+ customRouting = customRouting.toArrayList()
405
+ .map { CourierPreferenceChannel.fromString(it as String) }
406
+ )
407
+ promise.resolve(null)
408
+ } catch (e: Exception) {
409
+ promise.apiError(e)
410
+ }
414
411
  }
415
-
416
412
  }
417
413
 
418
414
  // Tracking
419
415
 
420
416
  @ReactMethod
421
- fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
422
-
423
- val client = clients[clientId]
424
- if (client == null) {
425
- promise.rejectMissingClient()
426
- return@launch
417
+ fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise) {
418
+ CoroutineScope(Dispatchers.Main).launch {
419
+ val client = clients[clientId]
420
+ if (client == null) {
421
+ promise.rejectMissingClient()
422
+ return@launch
423
+ }
424
+
425
+ try {
426
+ client.tracking.postTrackingUrl(
427
+ url = url,
428
+ event = CourierTrackingEvent.valueOf(event.uppercase())
429
+ )
430
+ promise.resolve(null)
431
+ } catch (e: Exception) {
432
+ promise.apiError(e)
433
+ }
427
434
  }
428
-
429
- try {
430
- client.tracking.postTrackingUrl(
431
- url = url,
432
- event = CourierTrackingEvent.valueOf(event.uppercase()),
433
- )
434
- promise.resolve(null)
435
- } catch (e: Exception) {
436
- promise.apiError(e)
437
- }
438
-
439
435
  }
440
-
441
436
  }
@@ -34,8 +34,13 @@ import kotlinx.coroutines.CoroutineScope
34
34
  import kotlinx.coroutines.Dispatchers
35
35
  import kotlinx.coroutines.launch
36
36
 
37
-
38
- class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Shared Instance Error", name = "CourierSharedModule", reactContext = reactContext) {
37
+ class CourierSharedModule(
38
+ reactContext: ReactApplicationContext
39
+ ) : ReactNativeModule(
40
+ tag = "Shared Instance Error",
41
+ name = "CourierSharedModule",
42
+ reactContext = reactContext
43
+ ) {
39
44
 
40
45
  // Listeners
41
46
  private var authenticationListeners = mutableMapOf<String, CourierAuthenticationListener>()
@@ -82,26 +87,36 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
82
87
  }
83
88
 
84
89
  @ReactMethod
85
- fun signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, showLogs: Boolean, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
86
- Courier.shared.signIn(
87
- userId = userId,
88
- tenantId = tenantId,
89
- accessToken = accessToken,
90
- clientKey = clientKey,
91
- showLogs = showLogs
92
- )
93
- promise.resolve(null)
90
+ fun signIn(
91
+ accessToken: String,
92
+ clientKey: String?,
93
+ userId: String,
94
+ tenantId: String?,
95
+ showLogs: Boolean,
96
+ promise: Promise
97
+ ) {
98
+ CoroutineScope(Dispatchers.Main).launch {
99
+ Courier.shared.signIn(
100
+ userId = userId,
101
+ tenantId = tenantId,
102
+ accessToken = accessToken,
103
+ clientKey = clientKey,
104
+ showLogs = showLogs
105
+ )
106
+ promise.resolve(null)
107
+ }
94
108
  }
95
109
 
96
110
  @ReactMethod
97
- fun signOut(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
98
- Courier.shared.signOut()
99
- promise.resolve(null)
111
+ fun signOut(promise: Promise) {
112
+ CoroutineScope(Dispatchers.Main).launch {
113
+ Courier.shared.signOut()
114
+ promise.resolve(null)
115
+ }
100
116
  }
101
117
 
102
118
  @ReactMethod
103
119
  fun addAuthenticationListener(listenerId: String, promise: Promise) {
104
-
105
120
  // Create the listener
106
121
  val listener = Courier.shared.addAuthenticationListener { userId ->
107
122
  reactApplicationContext.sendEvent(
@@ -112,24 +127,15 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
112
127
 
113
128
  // Add the listener to the map
114
129
  authenticationListeners[listenerId] = listener
115
-
116
130
  promise.resolve(listenerId)
117
-
118
131
  }
119
132
 
120
133
  @ReactMethod
121
134
  fun removeAuthenticationListener(listenerId: String, promise: Promise) {
122
-
123
135
  val listener = authenticationListeners[listenerId]
124
-
125
- // Disable the listener
126
136
  listener?.remove()
127
-
128
- // Remove the id from the map
129
137
  authenticationListeners.remove(listenerId)
130
-
131
138
  promise.resolve(listenerId)
132
-
133
139
  }
134
140
 
135
141
  @ReactMethod
@@ -142,28 +148,34 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
142
148
  // Push
143
149
 
144
150
  @ReactMethod
145
- fun getAllTokens(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
146
- val tokens = Courier.shared.tokens
147
- val resultMap = Arguments.createMap()
148
- tokens.forEach { (key, value) ->
149
- resultMap.putString(key, value)
151
+ fun getAllTokens(promise: Promise) {
152
+ CoroutineScope(Dispatchers.Main).launch {
153
+ val tokens = Courier.shared.tokens
154
+ val resultMap = Arguments.createMap()
155
+ tokens.forEach { (key, value) ->
156
+ resultMap.putString(key, value)
157
+ }
158
+ promise.resolve(resultMap)
150
159
  }
151
- promise.resolve(resultMap)
152
160
  }
153
161
 
154
162
  @ReactMethod
155
- fun getToken(provider: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
156
- val token = Courier.shared.getToken(provider)
157
- promise.resolve(token)
163
+ fun getToken(provider: String, promise: Promise) {
164
+ CoroutineScope(Dispatchers.Main).launch {
165
+ val token = Courier.shared.getToken(provider)
166
+ promise.resolve(token)
167
+ }
158
168
  }
159
169
 
160
170
  @ReactMethod
161
- fun setToken(provider: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
162
- try {
163
- Courier.shared.setToken(provider, token)
164
- promise.resolve(null)
165
- } catch (e: Exception) {
166
- promise.apiError(e)
171
+ fun setToken(provider: String, token: String, promise: Promise) {
172
+ CoroutineScope(Dispatchers.Main).launch {
173
+ try {
174
+ Courier.shared.setToken(provider, token)
175
+ promise.resolve(null)
176
+ } catch (e: Exception) {
177
+ promise.apiError(e)
178
+ }
167
179
  }
168
180
  }
169
181
 
@@ -181,62 +193,74 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
181
193
  }
182
194
 
183
195
  @ReactMethod
184
- fun openMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
185
- try {
186
- Courier.shared.openMessage(messageId)
187
- promise.resolve(null)
188
- } catch (e: Exception) {
189
- promise.apiError(e)
196
+ fun openMessage(messageId: String, promise: Promise) {
197
+ CoroutineScope(Dispatchers.Main).launch {
198
+ try {
199
+ Courier.shared.openMessage(messageId)
200
+ promise.resolve(null)
201
+ } catch (e: Exception) {
202
+ promise.apiError(e)
203
+ }
190
204
  }
191
205
  }
192
206
 
193
207
  @ReactMethod
194
- fun archiveMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
195
- try {
196
- Courier.shared.archiveMessage(messageId)
197
- promise.resolve(null)
198
- } catch (e: Exception) {
199
- promise.apiError(e)
208
+ fun archiveMessage(messageId: String, promise: Promise) {
209
+ CoroutineScope(Dispatchers.Main).launch {
210
+ try {
211
+ Courier.shared.archiveMessage(messageId)
212
+ promise.resolve(null)
213
+ } catch (e: Exception) {
214
+ promise.apiError(e)
215
+ }
200
216
  }
201
217
  }
202
218
 
203
219
  @ReactMethod
204
- fun clickMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
205
- try {
206
- Courier.shared.clickMessage(messageId)
207
- promise.resolve(null)
208
- } catch (e: Exception) {
209
- promise.apiError(e)
220
+ fun clickMessage(messageId: String, promise: Promise) {
221
+ CoroutineScope(Dispatchers.Main).launch {
222
+ try {
223
+ Courier.shared.clickMessage(messageId)
224
+ promise.resolve(null)
225
+ } catch (e: Exception) {
226
+ promise.apiError(e)
227
+ }
210
228
  }
211
229
  }
212
230
 
213
231
  @ReactMethod
214
- fun readMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
215
- try {
216
- Courier.shared.readMessage(messageId)
217
- promise.resolve(null)
218
- } catch (e: Exception) {
219
- promise.apiError(e)
232
+ fun readMessage(messageId: String, promise: Promise) {
233
+ CoroutineScope(Dispatchers.Main).launch {
234
+ try {
235
+ Courier.shared.readMessage(messageId)
236
+ promise.resolve(null)
237
+ } catch (e: Exception) {
238
+ promise.apiError(e)
239
+ }
220
240
  }
221
241
  }
222
242
 
223
243
  @ReactMethod
224
- fun unreadMessage(messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
225
- try {
226
- Courier.shared.unreadMessage(messageId)
227
- promise.resolve(null)
228
- } catch (e: Exception) {
229
- promise.apiError(e)
244
+ fun unreadMessage(messageId: String, promise: Promise) {
245
+ CoroutineScope(Dispatchers.Main).launch {
246
+ try {
247
+ Courier.shared.unreadMessage(messageId)
248
+ promise.resolve(null)
249
+ } catch (e: Exception) {
250
+ promise.apiError(e)
251
+ }
230
252
  }
231
253
  }
232
254
 
233
255
  @ReactMethod
234
- fun readAllInboxMessages(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
235
- try {
236
- Courier.shared.readAllInboxMessages()
237
- promise.resolve(null)
238
- } catch (e: Exception) {
239
- promise.apiError(e)
256
+ fun readAllInboxMessages(promise: Promise) {
257
+ CoroutineScope(Dispatchers.Main).launch {
258
+ try {
259
+ Courier.shared.readAllInboxMessages()
260
+ promise.resolve(null)
261
+ } catch (e: Exception) {
262
+ promise.apiError(e)
263
+ }
240
264
  }
241
265
  }
242
266
 
@@ -251,76 +275,77 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
251
275
  pageAddedId: String,
252
276
  messageEventId: String,
253
277
  promise: Promise
254
- ) = CoroutineScope(Dispatchers.Main).launch {
255
- val listener = Courier.shared.addInboxListener(
256
- onLoading = { isRefresh ->
257
- reactApplicationContext.sendEvent(
258
- eventName = loadingId,
259
- value = isRefresh
260
- )
261
- },
262
- onError = { e ->
263
- reactApplicationContext.sendEvent(
264
- eventName = errorId,
265
- value = e.message ?: "Courier Inbox Error"
266
- )
267
- },
268
- onUnreadCountChanged = { unreadCount ->
269
- reactApplicationContext.sendEvent(
270
- eventName = unreadCountId,
271
- value = unreadCount
272
- )
273
- },
274
- onTotalCountChanged = { totalCount, feed ->
275
- val json = Arguments.createMap().apply {
276
- putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
277
- putInt("totalCount", totalCount)
278
- }
279
- reactApplicationContext.sendEvent(
280
- eventName = totalCountId,
281
- value = json
282
- )
283
- },
284
- onMessagesChanged = { messages, canPaginate, feed ->
285
- val json = Arguments.createMap().apply {
286
- putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
287
- putArray("messages", messages.map { it.toJson() }.toWritableArray())
288
- putBoolean("canPaginate", canPaginate)
278
+ ) {
279
+ CoroutineScope(Dispatchers.Main).launch {
280
+ val listener = Courier.shared.addInboxListener(
281
+ onLoading = { isRefresh ->
282
+ reactApplicationContext.sendEvent(
283
+ eventName = loadingId,
284
+ value = isRefresh
285
+ )
286
+ },
287
+ onError = { e ->
288
+ reactApplicationContext.sendEvent(
289
+ eventName = errorId,
290
+ value = e.message ?: "Courier Inbox Error"
291
+ )
292
+ },
293
+ onUnreadCountChanged = { unreadCount ->
294
+ reactApplicationContext.sendEvent(
295
+ eventName = unreadCountId,
296
+ value = unreadCount
297
+ )
298
+ },
299
+ onTotalCountChanged = { totalCount, feed ->
300
+ val json = Arguments.createMap().apply {
301
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
302
+ putInt("totalCount", totalCount)
303
+ }
304
+ reactApplicationContext.sendEvent(
305
+ eventName = totalCountId,
306
+ value = json
307
+ )
308
+ },
309
+ onMessagesChanged = { messages, canPaginate, feed ->
310
+ val json = Arguments.createMap().apply {
311
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
312
+ putArray("messages", messages.map { it.toJson() }.toWritableArray())
313
+ putBoolean("canPaginate", canPaginate)
314
+ }
315
+ reactApplicationContext.sendEvent(
316
+ eventName = messagesChangedId,
317
+ value = json
318
+ )
319
+ },
320
+ onPageAdded = { messages, canPaginate, isFirstPage, feed ->
321
+ val json = Arguments.createMap().apply {
322
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
323
+ putArray("messages", messages.map { it.toJson() }.toWritableArray())
324
+ putBoolean("canPaginate", canPaginate)
325
+ putBoolean("isFirstPage", isFirstPage)
326
+ }
327
+ reactApplicationContext.sendEvent(
328
+ eventName = pageAddedId,
329
+ value = json
330
+ )
331
+ },
332
+ onMessageEvent = { message, index, feed, event ->
333
+ val json = Arguments.createMap().apply {
334
+ putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
335
+ putInt("index", index)
336
+ putString("event", event.value)
337
+ putString("message", message.toJson())
338
+ }
339
+ reactApplicationContext.sendEvent(
340
+ eventName = messageEventId,
341
+ value = json
342
+ )
289
343
  }
290
- reactApplicationContext.sendEvent(
291
- eventName = messagesChangedId,
292
- value = json
293
- )
294
- },
295
- onPageAdded = { messages, canPaginate, isFirstPage, feed ->
296
- val json = Arguments.createMap().apply {
297
- putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
298
- putArray("messages", messages.map { it.toJson() }.toWritableArray())
299
- putBoolean("canPaginate", canPaginate)
300
- putBoolean("isFirstPage", isFirstPage)
301
- }
302
- reactApplicationContext.sendEvent(
303
- eventName = pageAddedId,
304
- value = json
305
- )
306
- },
307
- onMessageEvent = { message, index, feed, event ->
308
- val json = Arguments.createMap().apply {
309
- putString("feed", if (feed == InboxMessageFeed.FEED) "feed" else "archive")
310
- putInt("index", index)
311
- putString("event", event.value)
312
- putString("message", message.toJson())
313
- }
314
- reactApplicationContext.sendEvent(
315
- eventName = messageEventId,
316
- value = json
317
- )
318
- }
319
- )
320
-
321
- inboxListeners[listenerId] = listener
344
+ )
322
345
 
323
- promise.resolve(listenerId)
346
+ inboxListeners[listenerId] = listener
347
+ promise.resolve(listenerId)
348
+ }
324
349
  }
325
350
 
326
351
  private fun InboxMessageSet.toJson(): WritableMap? {
@@ -347,19 +372,24 @@ class CourierSharedModule(reactContext: ReactApplicationContext): ReactNativeMod
347
372
  }
348
373
 
349
374
  @ReactMethod
350
- fun refreshInbox(promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
351
- Courier.shared.refreshInbox()
352
- promise.resolve(null)
375
+ fun refreshInbox(promise: Promise) {
376
+ CoroutineScope(Dispatchers.Main).launch {
377
+ Courier.shared.refreshInbox()
378
+ promise.resolve(null)
379
+ }
353
380
  }
354
381
 
355
382
  @ReactMethod
356
- fun fetchNextPageOfMessages(promise: Promise, inboxMessageFeed: String) = CoroutineScope(Dispatchers.Main).launch {
357
- try {
358
- val messageSet = Courier.shared.fetchNextInboxPage(if (inboxMessageFeed == "archived") InboxMessageFeed.ARCHIVE else InboxMessageFeed.FEED)
359
- promise.resolve(messageSet?.toJson())
360
- } catch (e: Exception) {
361
- promise.apiError(e)
383
+ fun fetchNextPageOfMessages(promise: Promise, inboxMessageFeed: String) {
384
+ CoroutineScope(Dispatchers.Main).launch {
385
+ try {
386
+ val messageSet = Courier.shared.fetchNextInboxPage(
387
+ if (inboxMessageFeed == "archived") InboxMessageFeed.ARCHIVE else InboxMessageFeed.FEED
388
+ )
389
+ promise.resolve(messageSet?.toJson())
390
+ } catch (e: Exception) {
391
+ promise.apiError(e)
392
+ }
362
393
  }
363
394
  }
364
-
365
395
  }
@@ -15,7 +15,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
15
15
  import com.google.gson.GsonBuilder
16
16
 
17
17
  internal object Utils {
18
- val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.0")
18
+ val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.1")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -26,7 +26,7 @@
26
26
  if (self) {
27
27
 
28
28
  // Set the user agent
29
- Courier.agent = [CourierAgent reactNativeIOS:@"5.5.0"];
29
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.1"];
30
30
 
31
31
  // Register for remote notifications
32
32
  UIApplication *app = [UIApplication sharedApplication];
@@ -14,7 +14,7 @@ internal class CourierReactNativeEventEmitter: RCTEventEmitter {
14
14
 
15
15
  // Set the user agent
16
16
  // Used to know the platform performing requests
17
- Courier.agent = CourierAgent.reactNativeIOS("5.5.0")
17
+ Courier.agent = CourierAgent.reactNativeIOS("5.5.1")
18
18
 
19
19
  }
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "5.5.0",
3
+ "version": "5.5.1",
4
4
  "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",