@trycourier/courier-react-native 2.0.0-beta9 → 2.0.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.
- package/README.md +190 -15
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +8 -18
- package/lib/commonjs/index.js +39 -75
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +39 -75
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/hooks/CourierProvider.d.ts +1 -1
- package/lib/typescript/hooks/CourierProvider.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +30 -73
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/CourierProvider.tsx +1 -1
- package/src/index.tsx +44 -75
package/src/index.tsx
CHANGED
|
@@ -77,7 +77,6 @@ class Courier {
|
|
|
77
77
|
/**
|
|
78
78
|
* Tells native Courier SDKs to show or hide logs.
|
|
79
79
|
* Defaults to the React __DEV__ mode
|
|
80
|
-
* @example Courier.setIsDebugging(true)
|
|
81
80
|
*/
|
|
82
81
|
public setIsDebugging(isDebugging: boolean): boolean {
|
|
83
82
|
|
|
@@ -100,14 +99,15 @@ class Courier {
|
|
|
100
99
|
|
|
101
100
|
}
|
|
102
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Returns the status of debugging
|
|
104
|
+
*/
|
|
103
105
|
get isDebugging(): boolean {
|
|
104
106
|
return this._isDebugging;
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param props
|
|
110
|
-
* @returns
|
|
110
|
+
* Sets the notification presentation options for iOS
|
|
111
111
|
*/
|
|
112
112
|
public iOSForegroundPresentationOptions(props: { options: iOSForegroundPresentationOptions[] }): string {
|
|
113
113
|
|
|
@@ -122,9 +122,7 @@ class Courier {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
* using Courier token management apis
|
|
127
|
-
* @example const apnsToken = await Courier.apnsToken
|
|
125
|
+
* Gets the apns token being used
|
|
128
126
|
*/
|
|
129
127
|
get apnsToken(): string | undefined {
|
|
130
128
|
if (Platform.OS !== 'ios') return undefined;
|
|
@@ -132,47 +130,51 @@ class Courier {
|
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
/**
|
|
135
|
-
*
|
|
136
|
-
* using Courier token management apis
|
|
137
|
-
* @example const fcmToken = await Courier.fcmToken
|
|
133
|
+
* Gets the fcm token being used
|
|
138
134
|
*/
|
|
139
135
|
get fcmToken(): Promise<string | undefined> {
|
|
140
136
|
return CourierReactNativeModules.getFcmToken();
|
|
141
137
|
}
|
|
142
138
|
|
|
143
139
|
/**
|
|
144
|
-
* Sets the
|
|
145
|
-
* using Courier token management apis
|
|
146
|
-
* @example await setFcmToken('asdf...asdf')
|
|
140
|
+
* Sets the fcm token to be used by Courier
|
|
147
141
|
*/
|
|
148
142
|
public setFcmToken(props: { token: string }): Promise<void> {
|
|
149
143
|
return CourierReactNativeModules.setFcmToken(props.token);
|
|
150
144
|
}
|
|
151
145
|
|
|
152
146
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
147
|
+
* Returns the notification permission status
|
|
148
|
+
* Only supported on iOS
|
|
155
149
|
*/
|
|
156
150
|
public getNotificationPermissionStatus(): Promise<string> {
|
|
157
|
-
|
|
151
|
+
|
|
152
|
+
if (Platform.OS === 'ios') {
|
|
153
|
+
return CourierReactNativeModules.getNotificationPermissionStatus();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return Promise.reject('unknown')
|
|
157
|
+
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
* Requests notification
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* if the user has already been asked for permission.
|
|
165
|
-
* @example const permissionStatus = await Courier.requestNotificationPermission()
|
|
161
|
+
* Requests notification permissions
|
|
162
|
+
* This will show a dialog asking the user for permission
|
|
163
|
+
* Only supported on iOS
|
|
166
164
|
*/
|
|
167
165
|
public requestNotificationPermission(): Promise<string> {
|
|
168
|
-
|
|
166
|
+
|
|
167
|
+
if (Platform.OS === 'ios') {
|
|
168
|
+
return CourierReactNativeModules.requestNotificationPermission();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return Promise.reject('unknown')
|
|
172
|
+
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
/**
|
|
172
|
-
*
|
|
173
|
-
|
|
174
|
-
* @returns function that can be used to unsubscribe from registered listeners
|
|
175
|
-
*/
|
|
176
|
+
* Listens to push notification clicked and delivered messages
|
|
177
|
+
*/
|
|
176
178
|
public addPushNotificationListener(props: { onPushNotificationClicked?: (push: any) => void, onPushNotificationDelivered?: (push: any) => void }): CourierPushListener {
|
|
177
179
|
|
|
178
180
|
const pushListener = new CourierPushListener();
|
|
@@ -236,46 +238,29 @@ class Courier {
|
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
+
* Gets the user id that is currently being used
|
|
242
|
+
* This is the user id associated with the http requests the sdk does
|
|
241
243
|
*/
|
|
242
244
|
get userId(): string | undefined {
|
|
243
245
|
return CourierReactNativeModules.getUserId() ?? undefined
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
/**
|
|
247
|
-
*
|
|
248
|
-
* using native level storage apis
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* ```
|
|
252
|
-
*await Courier.signIn({
|
|
253
|
-
accessToken: YOUR_COURIER_GENERATED_JWT,
|
|
254
|
-
clientKey: YOUR_CLIENT_KEY,
|
|
255
|
-
userId: YOUR_USER_ID,
|
|
256
|
-
})
|
|
257
|
-
* ```
|
|
258
|
-
* Your access token should be generated using this endpoint
|
|
259
|
-
* that is requested from your backend
|
|
260
|
-
* https://www.courier.com/docs/reference/auth/issue-token/
|
|
249
|
+
* Registers the auth token, client key and user id the sdk should use for requests
|
|
261
250
|
*/
|
|
262
251
|
public signIn(props: { accessToken: string, clientKey?: string, userId: string }): Promise<void> {
|
|
263
252
|
return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId);
|
|
264
253
|
}
|
|
265
254
|
|
|
266
255
|
/**
|
|
267
|
-
*
|
|
268
|
-
* @param props
|
|
269
|
-
* @returns
|
|
256
|
+
* Removes the current user and credentials from the sdk
|
|
270
257
|
*/
|
|
271
258
|
public signOut(): Promise<void> {
|
|
272
259
|
return CourierReactNativeModules.signOut();
|
|
273
260
|
}
|
|
274
261
|
|
|
275
262
|
/**
|
|
276
|
-
*
|
|
277
|
-
* @param props
|
|
278
|
-
* @returns
|
|
263
|
+
* Listens to authentication changes for the current user
|
|
279
264
|
*/
|
|
280
265
|
public addAuthenticationListener(props: { onUserChanged: (userId?: string) => void }): CourierAuthenticationListener {
|
|
281
266
|
|
|
@@ -292,45 +277,35 @@ class Courier {
|
|
|
292
277
|
}
|
|
293
278
|
|
|
294
279
|
/**
|
|
295
|
-
*
|
|
296
|
-
* @param props
|
|
297
|
-
* @returns
|
|
280
|
+
* Removes an authentication listener
|
|
298
281
|
*/
|
|
299
282
|
public removeAuthenticationListener(props: { listenerId: string }): string {
|
|
300
283
|
return CourierReactNativeModules.removeAuthenticationListener(props.listenerId);
|
|
301
284
|
}
|
|
302
285
|
|
|
303
286
|
/**
|
|
304
|
-
*
|
|
305
|
-
* @param props
|
|
306
|
-
* @returns
|
|
287
|
+
* Reads an inbox message
|
|
307
288
|
*/
|
|
308
289
|
public readMessage(props: { messageId: string }): string {
|
|
309
290
|
return CourierReactNativeModules.readMessage(props.messageId);
|
|
310
291
|
}
|
|
311
292
|
|
|
312
293
|
/**
|
|
313
|
-
*
|
|
314
|
-
* @param props
|
|
315
|
-
* @returns
|
|
294
|
+
* Unreads an inbox message
|
|
316
295
|
*/
|
|
317
296
|
public unreadMessage(props: { messageId: string }): string {
|
|
318
297
|
return CourierReactNativeModules.unreadMessage(props.messageId);
|
|
319
298
|
}
|
|
320
299
|
|
|
321
300
|
/**
|
|
322
|
-
*
|
|
323
|
-
* @param props
|
|
324
|
-
* @returns
|
|
301
|
+
* Reads all the inbox messages
|
|
325
302
|
*/
|
|
326
303
|
public readAllInboxMessages(): Promise<void> {
|
|
327
304
|
return CourierReactNativeModules.readAllInboxMessages();
|
|
328
305
|
}
|
|
329
306
|
|
|
330
307
|
/**
|
|
331
|
-
*
|
|
332
|
-
* @param props
|
|
333
|
-
* @returns
|
|
308
|
+
* Listens to changes for the inbox itself
|
|
334
309
|
*/
|
|
335
310
|
public addInboxListener(props: { onInitialLoad?: () => void, onError?: (error: string) => void, onMessagesChanged?: (messages: InboxMessage[], unreadMessageCount: number, totalMessageCount: number, canPaginate: boolean) => void }): CourierInboxListener {
|
|
336
311
|
|
|
@@ -373,38 +348,32 @@ class Courier {
|
|
|
373
348
|
}
|
|
374
349
|
|
|
375
350
|
/**
|
|
376
|
-
*
|
|
377
|
-
* @param props
|
|
378
|
-
* @returns
|
|
351
|
+
* Removes an inbox listener
|
|
379
352
|
*/
|
|
380
353
|
public removeInboxListener(props: { listenerId: string }): string {
|
|
381
354
|
return CourierReactNativeModules.removeInboxListener(props.listenerId);
|
|
382
355
|
}
|
|
383
356
|
|
|
384
357
|
/**
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
* @returns
|
|
358
|
+
* Refreshes the inbox
|
|
359
|
+
* Useful for pull to refresh
|
|
388
360
|
*/
|
|
389
361
|
public async refreshInbox(): Promise<void> {
|
|
390
362
|
return CourierReactNativeModules.refreshInbox();
|
|
391
363
|
}
|
|
392
364
|
|
|
393
365
|
/**
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* @returns
|
|
366
|
+
* Fetches the next page of inbox messages
|
|
367
|
+
* Returns the fetched inbox messages
|
|
397
368
|
*/
|
|
398
369
|
public async fetchNextPageOfMessages(): Promise<InboxMessage[]> {
|
|
399
370
|
return CourierReactNativeModules.fetchNextPageOfMessages();
|
|
400
371
|
}
|
|
401
372
|
|
|
402
373
|
/**
|
|
403
|
-
*
|
|
374
|
+
* Sets the pagination limit
|
|
404
375
|
* Min = 1
|
|
405
376
|
* Max = 100
|
|
406
|
-
* @param props
|
|
407
|
-
* @returns
|
|
408
377
|
*/
|
|
409
378
|
public setInboxPaginationLimit(props: { limit: number }): void {
|
|
410
379
|
CourierReactNativeModules.setInboxPaginationLimit(props.limit);
|