@trycourier/courier-react-native 1.0.8 → 1.0.9
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 +15 -19
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -2
- package/courier-react-native.podspec +1 -1
- package/ios/CourierReactNative.m +0 -1
- package/ios/CourierReactNative.swift +2 -3
- package/lib/commonjs/index.js +2 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +2 -4
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -3
- package/package.json +1 -1
- package/src/index.ts +1 -5
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Courier React Native Overview
|
|
2
2
|
|
|
3
3
|
```ts
|
|
4
|
-
import Courier, { CourierProvider } from '@trycourier/courier-react-native'
|
|
4
|
+
import Courier, { CourierProvider } from '@trycourier/courier-react-native';
|
|
5
5
|
|
|
6
6
|
await Courier.setIsDebugging(true);
|
|
7
7
|
|
|
@@ -19,7 +19,8 @@ await Courier.iOSForegroundPresentationOptions({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const currentPermissionStatus = await Courier.notificationPermissionStatus;
|
|
22
|
-
const requestNotificationPermission =
|
|
22
|
+
const requestNotificationPermission =
|
|
23
|
+
await Courier.requestNotificationPermission();
|
|
23
24
|
|
|
24
25
|
await Courier.setFcmToken('asdf...');
|
|
25
26
|
|
|
@@ -40,7 +41,6 @@ const messageId = await Courier.sendPush({
|
|
|
40
41
|
userId: 'example_user_id',
|
|
41
42
|
title: 'Hey! 👋',
|
|
42
43
|
body: 'Courier is awesome!!',
|
|
43
|
-
isProduction: false,
|
|
44
44
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
45
45
|
});
|
|
46
46
|
```
|
|
@@ -49,11 +49,10 @@ const messageId = await Courier.sendPush({
|
|
|
49
49
|
|
|
50
50
|
# Requirements & Support
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
| Operating System | Min SDK | Compile SDK | Firebase Cloud Messaging | Apple Push Notification Service | Expo | OneSignal | Courier Inbox | Courier Toast |
|
|
54
|
-
|
|
|
55
|
-
| `iOS`
|
|
56
|
-
| `Android`
|
|
53
|
+
| :--------------- | ------: | ----------: | -----------------------: | ------------------------------: | ---: | --------: | ------------: | ------------: |
|
|
54
|
+
| `iOS` | `13` | — | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
55
|
+
| `Android` | `21` | `32` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
57
56
|
|
|
58
57
|
> Most of this SDK depends on a Courier account: [`Create a Courier account here`](https://app.courier.com/signup)
|
|
59
58
|
|
|
@@ -175,7 +174,7 @@ allprojects {
|
|
|
175
174
|
```
|
|
176
175
|
|
|
177
176
|
3. Update your `yourApp/android/build.gradle` to support the following SDK versions
|
|
178
|
-
|
|
177
|
+
- This is needed to support newer Android Notification APIs
|
|
179
178
|
|
|
180
179
|
```groovy
|
|
181
180
|
buildscript {
|
|
@@ -190,7 +189,7 @@ buildscript {
|
|
|
190
189
|
}
|
|
191
190
|
```
|
|
192
191
|
|
|
193
|
-
4. Add the `google-services` dependency to your `yourApp/android/build.gradle` file:
|
|
192
|
+
4. Add the `google-services` dependency to your `yourApp/android/build.gradle` file:
|
|
194
193
|
|
|
195
194
|
```groovy
|
|
196
195
|
buildscript {
|
|
@@ -233,7 +232,7 @@ import com.google.firebase.messaging.RemoteMessage;
|
|
|
233
232
|
// This is safe. `CourierService` will automatically handle token refreshes.
|
|
234
233
|
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
|
|
235
234
|
public class YourExampleService extends CourierService {
|
|
236
|
-
|
|
235
|
+
|
|
237
236
|
@Override
|
|
238
237
|
public void showNotification(@NonNull RemoteMessage message) {
|
|
239
238
|
super.showNotification(message);
|
|
@@ -254,7 +253,7 @@ public class YourExampleService extends CourierService {
|
|
|
254
253
|
);
|
|
255
254
|
|
|
256
255
|
}
|
|
257
|
-
|
|
256
|
+
|
|
258
257
|
}
|
|
259
258
|
```
|
|
260
259
|
|
|
@@ -357,7 +356,8 @@ console.log(notificationPermission);
|
|
|
357
356
|
|
|
358
357
|
// Notification permissions must be `authorized` on iOS to receive pushes
|
|
359
358
|
|
|
360
|
-
const requestedNotificationPermission =
|
|
359
|
+
const requestedNotificationPermission =
|
|
360
|
+
await Courier.requestNotificationPermission();
|
|
361
361
|
console.log(requestedNotificationPermission);
|
|
362
362
|
|
|
363
363
|
// This is how iOS will show the notification when the app is in the foreground
|
|
@@ -367,22 +367,19 @@ await Courier.iOSForegroundPresentationOptions({
|
|
|
367
367
|
options: ['badge', 'banner', 'list', 'sound'],
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
-
|
|
371
370
|
// This function returns an unsubscribe function
|
|
372
371
|
// Call `unsibscribe();` to stop listening to notifications
|
|
373
372
|
// Recommended to call the function while component mounts and unsubscribe when the component unmounts
|
|
374
373
|
const unsubscribe = Courier.registerPushNotificationListeners({
|
|
375
|
-
|
|
376
374
|
// Will be called if the app is in the foreground and a push notification arrives
|
|
377
375
|
onPushNotificationClicked(push) {
|
|
378
|
-
console.log(push.title)
|
|
376
|
+
console.log(push.title);
|
|
379
377
|
},
|
|
380
378
|
|
|
381
379
|
// Will be called when a user clicks a push notification
|
|
382
380
|
onPushNotificationDelivered(push) {
|
|
383
|
-
console.log(push.title)
|
|
384
|
-
}
|
|
385
|
-
|
|
381
|
+
console.log(push.title);
|
|
382
|
+
},
|
|
386
383
|
});
|
|
387
384
|
|
|
388
385
|
// Sends a test push
|
|
@@ -391,7 +388,6 @@ const messageId = await Courier.sendPush({
|
|
|
391
388
|
userId: 'example_user',
|
|
392
389
|
title: 'Chirp Chrip!',
|
|
393
390
|
body: 'Hello from Courier 🐣',
|
|
394
|
-
isProduction: false, // This only affects APNS pushes. false == sandbox / true == production
|
|
395
391
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
396
392
|
});
|
|
397
393
|
```
|
package/android/build.gradle
CHANGED
|
@@ -104,7 +104,6 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
104
104
|
title: String,
|
|
105
105
|
body: String,
|
|
106
106
|
providers: ReadableArray,
|
|
107
|
-
isProduction: Boolean,
|
|
108
107
|
promise: Promise
|
|
109
108
|
) {
|
|
110
109
|
Courier.shared.sendPush(
|
|
@@ -113,7 +112,6 @@ class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
113
112
|
title = title,
|
|
114
113
|
body = body,
|
|
115
114
|
providers = providers.toCourierProviders(),
|
|
116
|
-
isProduction = isProduction,
|
|
117
115
|
onSuccess = { messageId ->
|
|
118
116
|
promise.resolve(messageId)
|
|
119
117
|
},
|
|
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
19
|
s.dependency "React-Core"
|
|
20
|
-
s.dependency 'Courier-iOS', '1.1.
|
|
20
|
+
s.dependency 'Courier-iOS', '1.1.2'
|
|
21
21
|
s.swift_version = '5.6'
|
|
22
22
|
|
|
23
23
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
package/ios/CourierReactNative.m
CHANGED
|
@@ -34,7 +34,6 @@ RCT_EXTERN_METHOD(sendPush: (NSString*)authKey
|
|
|
34
34
|
withTitle:(NSString*)title
|
|
35
35
|
withBody:(NSString*)body
|
|
36
36
|
withProviders:(NSArray*)providers
|
|
37
|
-
withIsProduction:(BOOL)isProduction
|
|
38
37
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
39
38
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
40
39
|
|
|
@@ -197,8 +197,8 @@ class CourierReactNative: RCTEventEmitter {
|
|
|
197
197
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
@objc(sendPush: withUserId: withTitle: withBody: withProviders:
|
|
201
|
-
func sendPush(authKey: NSString, userId: NSString, title: NSString, body: NSString, providers: NSArray,
|
|
200
|
+
@objc(sendPush: withUserId: withTitle: withBody: withProviders: withResolver: withRejecter:)
|
|
201
|
+
func sendPush(authKey: NSString, userId: NSString, title: NSString, body: NSString, providers: NSArray, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
202
202
|
|
|
203
203
|
guard let courierProviders = providers as? [String] else {
|
|
204
204
|
reject("No provider supported", CourierReactNative.COURIER_ERROR_TAG, nil)
|
|
@@ -210,7 +210,6 @@ class CourierReactNative: RCTEventEmitter {
|
|
|
210
210
|
userId: userId as String,
|
|
211
211
|
title: title as String,
|
|
212
212
|
message: body as String,
|
|
213
|
-
isProduction: isProduction,
|
|
214
213
|
providers: courierProviders,
|
|
215
214
|
onSuccess: { requestId in
|
|
216
215
|
resolve(requestId)
|
package/lib/commonjs/index.js
CHANGED
|
@@ -164,7 +164,6 @@ class Courier {
|
|
|
164
164
|
title: 'This is a title',
|
|
165
165
|
body: 'This is a body',
|
|
166
166
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
167
|
-
isProduction: false, // true is production apns, false is sandbox apns
|
|
168
167
|
});
|
|
169
168
|
* ```
|
|
170
169
|
* @returns promise
|
|
@@ -177,10 +176,9 @@ class Courier {
|
|
|
177
176
|
userId,
|
|
178
177
|
title,
|
|
179
178
|
body,
|
|
180
|
-
providers
|
|
181
|
-
isProduction
|
|
179
|
+
providers
|
|
182
180
|
} = _ref2;
|
|
183
|
-
return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers
|
|
181
|
+
return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers);
|
|
184
182
|
}
|
|
185
183
|
/**
|
|
186
184
|
* Gets notification permission status at a system level.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","CourierReactNativeModules","NativeModules","CourierReactNative","Proxy","get","Error","CourierEventEmitter","NativeEventEmitter","CourierProvider","Courier","constructor","setDefaults","Promise","all","setIsDebugging","__DEV__","iOSForegroundPresentationOptions","options","error","console","log","isDebugging","debugListener","remove","addListener","event","_isDebugging","setDebugMode","userId","getUserId","signIn","accessToken","signOut","apnsToken","OS","resolve","undefined","getApnsToken","fcmToken","getFcmToken","setFcmToken","token","sendPush","authKey","title","body","providers","isProduction","notificationPermissionStatus","getNotificationPermissionStatus","requestNotificationPermission","normalizedParams","Array","from","Set","registerPushNotificationListeners","onPushNotificationClicked","onPushNotificationDelivered","notificationClickedListener","notificationDeliveredListener","DeviceEventEmitter","PUSH_NOTIFICATION_CLICKED","JSON","parse","PUSH_NOTIFICATION_DELIVERED","registerPushNotificationClickedOnKilledState"],"sources":["index.ts"],"sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint class-methods-use-this: 0 */\nimport {\n NativeModules,\n Platform,\n DeviceEventEmitter,\n NativeEventEmitter,\n EmitterSubscription,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \\n\\n${Platform.select(\n { ios: \"- You have run 'pod install'\\n\", default: '' }\n )}- You rebuilt the app after installing the package\\n` +\n `- You are not using Expo managed workflow\\n`;\n\nconst CourierReactNativeModules = NativeModules.CourierReactNative\n ? NativeModules.CourierReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nconst CourierEventEmitter = new NativeEventEmitter(\n NativeModules.CourierReactNative\n);\n\nexport enum CourierProvider {\n FCM = 'firebase-fcm',\n APNS = 'apn',\n}\n\nclass Courier {\n readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';\n\n readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';\n\n public constructor() {\n // Sets the initial SDK values\n // Defaults to React Native level debugging\n // and will show all foreground notification styles in iOS\n this.setDefaults();\n }\n\n private async setDefaults() {\n try {\n await Promise.all([\n this.setIsDebugging(__DEV__),\n this.iOSForegroundPresentationOptions({\n options: ['sound', 'badge', 'list', 'banner'],\n }),\n ]);\n } catch (error) {\n console.log(error);\n }\n }\n\n private _isDebugging = false;\n\n private debugListener: EmitterSubscription | undefined;\n\n /**\n * Tells native Courier SDKs to show or hide logs.\n * Defaults to the React __DEV__ mode\n * @example Courier.setIsDebugging(true)\n */\n public async setIsDebugging(isDebugging: boolean): Promise<boolean> {\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n // listener needs to be registered first to catch the event\n if (isDebugging) {\n this.debugListener = CourierEventEmitter.addListener(\n 'courierDebugEvent',\n (event) => {\n console.log('\\x1b[36m%s\\x1b[0m', 'COURIER', event);\n }\n );\n }\n\n this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n return this._isDebugging;\n }\n\n get isDebugging(): boolean {\n return this._isDebugging;\n }\n\n /**\n * Returns the current user id stored in local native storage\n * @example const userId = await Courier.userId\n */\n get userId(): Promise<string | undefined> {\n return CourierReactNativeModules.getUserId();\n }\n\n /**\n * Signs user in and persists signin in between sessions\n * using native level storage apis\n * \n * @example\n * ```\n *await Courier.signIn({\n accessToken: YOUR_COURIER_GENERATED_JWT,\n userId: YOUR_USER_ID,\n })\n * ```\n * Your access token should be generated using this endpoint\n * that is requested from your backend\n * https://www.courier.com/docs/reference/auth/issue-token/\n */\n public signIn({\n accessToken,\n userId,\n }: {\n accessToken: string;\n userId: string;\n }): Promise<void> {\n return CourierReactNativeModules.signIn(userId, accessToken);\n }\n\n /**\n * Logs user out of native level user storage.\n * This will clear the userId, accessToken, and apns / fcm tokens and\n * delete the matching devices apns / fcm tokens for the user in Courier token management\n * @example await Courier.signOut()\n */\n public signOut(): Promise<void> {\n return CourierReactNativeModules.signOut();\n }\n\n /**\n * Sets the current Apple Push Notification Service (APNS) token\n * using Courier token management apis\n * @example const apnsToken = await Courier.apnsToken\n */\n get apnsToken(): Promise<string | undefined> {\n if (Platform.OS !== 'ios') return Promise.resolve(undefined);\n return CourierReactNativeModules.getApnsToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example const fcmToken = await Courier.fcmToken\n */\n get fcmToken(): Promise<string | undefined> {\n return CourierReactNativeModules.getFcmToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example await setFcmToken('asdf...asdf')\n */\n public setFcmToken(token: string): Promise<void> {\n return CourierReactNativeModules.setFcmToken(token);\n }\n\n /**\n * Hits the Courier /send endpoint and sends a test push notification\n * @example\n * ```\n *const messageId = await sendPush({\n authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,\n userId: USER_ID,\n title: 'This is a title',\n body: 'This is a body',\n providers: [CourierProvider.APNS, CourierProvider.FCM],\n isProduction: false, // true is production apns, false is sandbox apns\n });\n * ```\n * @returns promise\n */\n public sendPush({\n authKey,\n userId,\n title,\n body,\n providers,\n isProduction,\n }: {\n authKey: string;\n userId: string;\n title?: string;\n body?: string;\n providers: CourierProvider[];\n isProduction: boolean;\n }): Promise<string> {\n return CourierReactNativeModules.sendPush(\n authKey,\n userId,\n title,\n body,\n providers,\n isProduction\n );\n }\n\n /**\n * Gets notification permission status at a system level.\n * @example const permissionStatus = await Courier.getNotificationPermissionStatus()\n */\n get notificationPermissionStatus(): Promise<string> {\n return CourierReactNativeModules.getNotificationPermissionStatus();\n }\n\n /**\n * Requests notification permission status at a system level.\n * Returns the string associated with the permission status.\n * Will return the current status and will not present a popup\n * if the user has already been asked for permission.\n * @example const permissionStatus = await Courier.requestNotificationPermission()\n */\n public requestNotificationPermission(): Promise<string> {\n return CourierReactNativeModules.requestNotificationPermission();\n }\n\n /**\n * Sets the push notification presentation style when the app is in the foreground\n * This does not affect how the notification is shown when the app is killed or in the background states\n *\n * Defaults to sound, badge, list and/or banner.\n *\n * @example iOSForegroundPresentationOptions({options: ['sound']});\n */\n public iOSForegroundPresentationOptions({\n options,\n }: {\n options: ('sound' | 'badge' | 'list' | 'banner')[];\n }): Promise<void> {\n // Only works on iOS\n if (Platform.OS !== 'ios') return Promise.resolve();\n\n const normalizedParams = Array.from(new Set(options));\n return CourierReactNativeModules.iOSForegroundPresentationOptions({\n options: normalizedParams,\n });\n }\n\n /**\n * @example \n *```\n const unsubPushListeners = () => {\n return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({\n onPushNotificationClicked: (push) => {\n ...\n },\n onPushNotificationDelivered: (push) => {\n ...\n },\n })\n }\n\n // To unsubscribe the listeners\n unsubPushListeners()\n *```\n * @returns function that can be used to unsubscribe from registered listeners\n */\n public registerPushNotificationListeners({\n onPushNotificationClicked,\n onPushNotificationDelivered,\n }: {\n onPushNotificationClicked: (_push: any) => void;\n onPushNotificationDelivered: (_push: any) => void;\n }) {\n let notificationClickedListener: EmitterSubscription;\n let notificationDeliveredListener: EmitterSubscription;\n\n // Android\n if (Platform.OS === 'android') {\n notificationClickedListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // iOS\n if (Platform.OS === 'ios') {\n notificationClickedListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // When listener is registered\n // Attempt to fetch the last message that was clicked\n // This is needed for when the app is killed and the\n // user launched the app by clicking on a notifications\n CourierReactNativeModules.registerPushNotificationClickedOnKilledState();\n\n return () => {\n notificationClickedListener.remove();\n notificationDeliveredListener.remove();\n };\n }\n}\n\nexport default new Courier();\n"],"mappings":";;;;;;;AAEA;;;;AAQA,MAAMA,aAAa,GAChB,4FAA2FC,qBAAA,CAASC,MAAT,CAC1F;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAD0F,CAE1F,sDAFF,GAGC,6CAJH;AAMA,MAAMC,yBAAyB,GAAGC,0BAAA,CAAcC,kBAAd,GAC9BD,0BAAA,CAAcC,kBADgB,GAE9B,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAFJ;AAWA,MAAMW,mBAAmB,GAAG,IAAIC,+BAAJ,CAC1BN,0BAAA,CAAcC,kBADY,CAA5B;IAIYM,e;;;WAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;AAKZ,MAAMC,OAAN,CAAc;EAKLC,WAAW,GAAG;IAAA,mDAJgB,yBAIhB;;IAAA,qDAFkB,2BAElB;;IAAA,sCAoBE,KApBF;;IAAA;;IACnB;IACA;IACA;IACA,KAAKC,WAAL;EACD;;EAEwB,MAAXA,WAAW,GAAG;IAC1B,IAAI;MACF,MAAMC,OAAO,CAACC,GAAR,CAAY,CAChB,KAAKC,cAAL,CAAoBC,OAApB,CADgB,EAEhB,KAAKC,gCAAL,CAAsC;QACpCC,OAAO,EAAE,CAAC,OAAD,EAAU,OAAV,EAAmB,MAAnB,EAA2B,QAA3B;MAD2B,CAAtC,CAFgB,CAAZ,CAAN;IAMD,CAPD,CAOE,OAAOC,KAAP,EAAc;MACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;IACD;EACF;;EAMD;AACF;AACA;AACA;AACA;EAC6B,MAAdJ,cAAc,CAACO,WAAD,EAAyC;IAAA;;IAClE;IACA,4BAA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AoC,6BAA6B,CAACpC,MAA9B;IACD,CAHD;EAID;;AA7SW;;eAgTC,IAAId,OAAJ,E"}
|
|
1
|
+
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","CourierReactNativeModules","NativeModules","CourierReactNative","Proxy","get","Error","CourierEventEmitter","NativeEventEmitter","CourierProvider","Courier","constructor","setDefaults","Promise","all","setIsDebugging","__DEV__","iOSForegroundPresentationOptions","options","error","console","log","isDebugging","debugListener","remove","addListener","event","_isDebugging","setDebugMode","userId","getUserId","signIn","accessToken","signOut","apnsToken","OS","resolve","undefined","getApnsToken","fcmToken","getFcmToken","setFcmToken","token","sendPush","authKey","title","body","providers","notificationPermissionStatus","getNotificationPermissionStatus","requestNotificationPermission","normalizedParams","Array","from","Set","registerPushNotificationListeners","onPushNotificationClicked","onPushNotificationDelivered","notificationClickedListener","notificationDeliveredListener","DeviceEventEmitter","PUSH_NOTIFICATION_CLICKED","JSON","parse","PUSH_NOTIFICATION_DELIVERED","registerPushNotificationClickedOnKilledState"],"sources":["index.ts"],"sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint class-methods-use-this: 0 */\nimport {\n NativeModules,\n Platform,\n DeviceEventEmitter,\n NativeEventEmitter,\n EmitterSubscription,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \\n\\n${Platform.select(\n { ios: \"- You have run 'pod install'\\n\", default: '' }\n )}- You rebuilt the app after installing the package\\n` +\n `- You are not using Expo managed workflow\\n`;\n\nconst CourierReactNativeModules = NativeModules.CourierReactNative\n ? NativeModules.CourierReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nconst CourierEventEmitter = new NativeEventEmitter(\n NativeModules.CourierReactNative\n);\n\nexport enum CourierProvider {\n FCM = 'firebase-fcm',\n APNS = 'apn',\n}\n\nclass Courier {\n readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';\n\n readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';\n\n public constructor() {\n // Sets the initial SDK values\n // Defaults to React Native level debugging\n // and will show all foreground notification styles in iOS\n this.setDefaults();\n }\n\n private async setDefaults() {\n try {\n await Promise.all([\n this.setIsDebugging(__DEV__),\n this.iOSForegroundPresentationOptions({\n options: ['sound', 'badge', 'list', 'banner'],\n }),\n ]);\n } catch (error) {\n console.log(error);\n }\n }\n\n private _isDebugging = false;\n\n private debugListener: EmitterSubscription | undefined;\n\n /**\n * Tells native Courier SDKs to show or hide logs.\n * Defaults to the React __DEV__ mode\n * @example Courier.setIsDebugging(true)\n */\n public async setIsDebugging(isDebugging: boolean): Promise<boolean> {\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n // listener needs to be registered first to catch the event\n if (isDebugging) {\n this.debugListener = CourierEventEmitter.addListener(\n 'courierDebugEvent',\n (event) => {\n console.log('\\x1b[36m%s\\x1b[0m', 'COURIER', event);\n }\n );\n }\n\n this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n return this._isDebugging;\n }\n\n get isDebugging(): boolean {\n return this._isDebugging;\n }\n\n /**\n * Returns the current user id stored in local native storage\n * @example const userId = await Courier.userId\n */\n get userId(): Promise<string | undefined> {\n return CourierReactNativeModules.getUserId();\n }\n\n /**\n * Signs user in and persists signin in between sessions\n * using native level storage apis\n * \n * @example\n * ```\n *await Courier.signIn({\n accessToken: YOUR_COURIER_GENERATED_JWT,\n userId: YOUR_USER_ID,\n })\n * ```\n * Your access token should be generated using this endpoint\n * that is requested from your backend\n * https://www.courier.com/docs/reference/auth/issue-token/\n */\n public signIn({\n accessToken,\n userId,\n }: {\n accessToken: string;\n userId: string;\n }): Promise<void> {\n return CourierReactNativeModules.signIn(userId, accessToken);\n }\n\n /**\n * Logs user out of native level user storage.\n * This will clear the userId, accessToken, and apns / fcm tokens and\n * delete the matching devices apns / fcm tokens for the user in Courier token management\n * @example await Courier.signOut()\n */\n public signOut(): Promise<void> {\n return CourierReactNativeModules.signOut();\n }\n\n /**\n * Sets the current Apple Push Notification Service (APNS) token\n * using Courier token management apis\n * @example const apnsToken = await Courier.apnsToken\n */\n get apnsToken(): Promise<string | undefined> {\n if (Platform.OS !== 'ios') return Promise.resolve(undefined);\n return CourierReactNativeModules.getApnsToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example const fcmToken = await Courier.fcmToken\n */\n get fcmToken(): Promise<string | undefined> {\n return CourierReactNativeModules.getFcmToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example await setFcmToken('asdf...asdf')\n */\n public setFcmToken(token: string): Promise<void> {\n return CourierReactNativeModules.setFcmToken(token);\n }\n\n /**\n * Hits the Courier /send endpoint and sends a test push notification\n * @example\n * ```\n *const messageId = await sendPush({\n authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,\n userId: USER_ID,\n title: 'This is a title',\n body: 'This is a body',\n providers: [CourierProvider.APNS, CourierProvider.FCM],\n });\n * ```\n * @returns promise\n */\n public sendPush({\n authKey,\n userId,\n title,\n body,\n providers,\n }: {\n authKey: string;\n userId: string;\n title?: string;\n body?: string;\n providers: CourierProvider[];\n }): Promise<string> {\n return CourierReactNativeModules.sendPush(\n authKey,\n userId,\n title,\n body,\n providers\n );\n }\n\n /**\n * Gets notification permission status at a system level.\n * @example const permissionStatus = await Courier.getNotificationPermissionStatus()\n */\n get notificationPermissionStatus(): Promise<string> {\n return CourierReactNativeModules.getNotificationPermissionStatus();\n }\n\n /**\n * Requests notification permission status at a system level.\n * Returns the string associated with the permission status.\n * Will return the current status and will not present a popup\n * if the user has already been asked for permission.\n * @example const permissionStatus = await Courier.requestNotificationPermission()\n */\n public requestNotificationPermission(): Promise<string> {\n return CourierReactNativeModules.requestNotificationPermission();\n }\n\n /**\n * Sets the push notification presentation style when the app is in the foreground\n * This does not affect how the notification is shown when the app is killed or in the background states\n *\n * Defaults to sound, badge, list and/or banner.\n *\n * @example iOSForegroundPresentationOptions({options: ['sound']});\n */\n public iOSForegroundPresentationOptions({\n options,\n }: {\n options: ('sound' | 'badge' | 'list' | 'banner')[];\n }): Promise<void> {\n // Only works on iOS\n if (Platform.OS !== 'ios') return Promise.resolve();\n\n const normalizedParams = Array.from(new Set(options));\n return CourierReactNativeModules.iOSForegroundPresentationOptions({\n options: normalizedParams,\n });\n }\n\n /**\n * @example \n *```\n const unsubPushListeners = () => {\n return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({\n onPushNotificationClicked: (push) => {\n ...\n },\n onPushNotificationDelivered: (push) => {\n ...\n },\n })\n }\n\n // To unsubscribe the listeners\n unsubPushListeners()\n *```\n * @returns function that can be used to unsubscribe from registered listeners\n */\n public registerPushNotificationListeners({\n onPushNotificationClicked,\n onPushNotificationDelivered,\n }: {\n onPushNotificationClicked: (_push: any) => void;\n onPushNotificationDelivered: (_push: any) => void;\n }) {\n let notificationClickedListener: EmitterSubscription;\n let notificationDeliveredListener: EmitterSubscription;\n\n // Android\n if (Platform.OS === 'android') {\n notificationClickedListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // iOS\n if (Platform.OS === 'ios') {\n notificationClickedListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // When listener is registered\n // Attempt to fetch the last message that was clicked\n // This is needed for when the app is killed and the\n // user launched the app by clicking on a notifications\n CourierReactNativeModules.registerPushNotificationClickedOnKilledState();\n\n return () => {\n notificationClickedListener.remove();\n notificationDeliveredListener.remove();\n };\n }\n}\n\nexport default new Courier();\n"],"mappings":";;;;;;;AAEA;;;;AAQA,MAAMA,aAAa,GAChB,4FAA2FC,qBAAA,CAASC,MAAT,CAC1F;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAD0F,CAE1F,sDAFF,GAGC,6CAJH;AAMA,MAAMC,yBAAyB,GAAGC,0BAAA,CAAcC,kBAAd,GAC9BD,0BAAA,CAAcC,kBADgB,GAE9B,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAFJ;AAWA,MAAMW,mBAAmB,GAAG,IAAIC,+BAAJ,CAC1BN,0BAAA,CAAcC,kBADY,CAA5B;IAIYM,e;;;WAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;AAKZ,MAAMC,OAAN,CAAc;EAKLC,WAAW,GAAG;IAAA,mDAJgB,yBAIhB;;IAAA,qDAFkB,2BAElB;;IAAA,sCAoBE,KApBF;;IAAA;;IACnB;IACA;IACA;IACA,KAAKC,WAAL;EACD;;EAEwB,MAAXA,WAAW,GAAG;IAC1B,IAAI;MACF,MAAMC,OAAO,CAACC,GAAR,CAAY,CAChB,KAAKC,cAAL,CAAoBC,OAApB,CADgB,EAEhB,KAAKC,gCAAL,CAAsC;QACpCC,OAAO,EAAE,CAAC,OAAD,EAAU,OAAV,EAAmB,MAAnB,EAA2B,QAA3B;MAD2B,CAAtC,CAFgB,CAAZ,CAAN;IAMD,CAPD,CAOE,OAAOC,KAAP,EAAc;MACdC,O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DD;IACA;IACA;IACA;;;IACAlB,yBAAyB,CAACgE,4CAA1B;IAEA,OAAO,MAAM;MACXP,2BAA2B,CAAClC,MAA5B;MACAmC,6BAA6B,CAACnC,MAA9B;IACD,CAHD;EAID;;AAzSW;;eA4SC,IAAId,OAAJ,E"}
|
package/lib/module/index.js
CHANGED
|
@@ -158,7 +158,6 @@ class Courier {
|
|
|
158
158
|
title: 'This is a title',
|
|
159
159
|
body: 'This is a body',
|
|
160
160
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
161
|
-
isProduction: false, // true is production apns, false is sandbox apns
|
|
162
161
|
});
|
|
163
162
|
* ```
|
|
164
163
|
* @returns promise
|
|
@@ -171,10 +170,9 @@ class Courier {
|
|
|
171
170
|
userId,
|
|
172
171
|
title,
|
|
173
172
|
body,
|
|
174
|
-
providers
|
|
175
|
-
isProduction
|
|
173
|
+
providers
|
|
176
174
|
} = _ref2;
|
|
177
|
-
return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers
|
|
175
|
+
return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers);
|
|
178
176
|
}
|
|
179
177
|
/**
|
|
180
178
|
* Gets notification permission status at a system level.
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","DeviceEventEmitter","NativeEventEmitter","LINKING_ERROR","select","ios","default","CourierReactNativeModules","CourierReactNative","Proxy","get","Error","CourierEventEmitter","CourierProvider","Courier","constructor","setDefaults","Promise","all","setIsDebugging","__DEV__","iOSForegroundPresentationOptions","options","error","console","log","isDebugging","debugListener","remove","addListener","event","_isDebugging","setDebugMode","userId","getUserId","signIn","accessToken","signOut","apnsToken","OS","resolve","undefined","getApnsToken","fcmToken","getFcmToken","setFcmToken","token","sendPush","authKey","title","body","providers","isProduction","notificationPermissionStatus","getNotificationPermissionStatus","requestNotificationPermission","normalizedParams","Array","from","Set","registerPushNotificationListeners","onPushNotificationClicked","onPushNotificationDelivered","notificationClickedListener","notificationDeliveredListener","PUSH_NOTIFICATION_CLICKED","JSON","parse","PUSH_NOTIFICATION_DELIVERED","registerPushNotificationClickedOnKilledState"],"sources":["index.ts"],"sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint class-methods-use-this: 0 */\nimport {\n NativeModules,\n Platform,\n DeviceEventEmitter,\n NativeEventEmitter,\n EmitterSubscription,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \\n\\n${Platform.select(\n { ios: \"- You have run 'pod install'\\n\", default: '' }\n )}- You rebuilt the app after installing the package\\n` +\n `- You are not using Expo managed workflow\\n`;\n\nconst CourierReactNativeModules = NativeModules.CourierReactNative\n ? NativeModules.CourierReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nconst CourierEventEmitter = new NativeEventEmitter(\n NativeModules.CourierReactNative\n);\n\nexport enum CourierProvider {\n FCM = 'firebase-fcm',\n APNS = 'apn',\n}\n\nclass Courier {\n readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';\n\n readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';\n\n public constructor() {\n // Sets the initial SDK values\n // Defaults to React Native level debugging\n // and will show all foreground notification styles in iOS\n this.setDefaults();\n }\n\n private async setDefaults() {\n try {\n await Promise.all([\n this.setIsDebugging(__DEV__),\n this.iOSForegroundPresentationOptions({\n options: ['sound', 'badge', 'list', 'banner'],\n }),\n ]);\n } catch (error) {\n console.log(error);\n }\n }\n\n private _isDebugging = false;\n\n private debugListener: EmitterSubscription | undefined;\n\n /**\n * Tells native Courier SDKs to show or hide logs.\n * Defaults to the React __DEV__ mode\n * @example Courier.setIsDebugging(true)\n */\n public async setIsDebugging(isDebugging: boolean): Promise<boolean> {\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n // listener needs to be registered first to catch the event\n if (isDebugging) {\n this.debugListener = CourierEventEmitter.addListener(\n 'courierDebugEvent',\n (event) => {\n console.log('\\x1b[36m%s\\x1b[0m', 'COURIER', event);\n }\n );\n }\n\n this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n return this._isDebugging;\n }\n\n get isDebugging(): boolean {\n return this._isDebugging;\n }\n\n /**\n * Returns the current user id stored in local native storage\n * @example const userId = await Courier.userId\n */\n get userId(): Promise<string | undefined> {\n return CourierReactNativeModules.getUserId();\n }\n\n /**\n * Signs user in and persists signin in between sessions\n * using native level storage apis\n * \n * @example\n * ```\n *await Courier.signIn({\n accessToken: YOUR_COURIER_GENERATED_JWT,\n userId: YOUR_USER_ID,\n })\n * ```\n * Your access token should be generated using this endpoint\n * that is requested from your backend\n * https://www.courier.com/docs/reference/auth/issue-token/\n */\n public signIn({\n accessToken,\n userId,\n }: {\n accessToken: string;\n userId: string;\n }): Promise<void> {\n return CourierReactNativeModules.signIn(userId, accessToken);\n }\n\n /**\n * Logs user out of native level user storage.\n * This will clear the userId, accessToken, and apns / fcm tokens and\n * delete the matching devices apns / fcm tokens for the user in Courier token management\n * @example await Courier.signOut()\n */\n public signOut(): Promise<void> {\n return CourierReactNativeModules.signOut();\n }\n\n /**\n * Sets the current Apple Push Notification Service (APNS) token\n * using Courier token management apis\n * @example const apnsToken = await Courier.apnsToken\n */\n get apnsToken(): Promise<string | undefined> {\n if (Platform.OS !== 'ios') return Promise.resolve(undefined);\n return CourierReactNativeModules.getApnsToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example const fcmToken = await Courier.fcmToken\n */\n get fcmToken(): Promise<string | undefined> {\n return CourierReactNativeModules.getFcmToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example await setFcmToken('asdf...asdf')\n */\n public setFcmToken(token: string): Promise<void> {\n return CourierReactNativeModules.setFcmToken(token);\n }\n\n /**\n * Hits the Courier /send endpoint and sends a test push notification\n * @example\n * ```\n *const messageId = await sendPush({\n authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,\n userId: USER_ID,\n title: 'This is a title',\n body: 'This is a body',\n providers: [CourierProvider.APNS, CourierProvider.FCM],\n isProduction: false, // true is production apns, false is sandbox apns\n });\n * ```\n * @returns promise\n */\n public sendPush({\n authKey,\n userId,\n title,\n body,\n providers,\n isProduction,\n }: {\n authKey: string;\n userId: string;\n title?: string;\n body?: string;\n providers: CourierProvider[];\n isProduction: boolean;\n }): Promise<string> {\n return CourierReactNativeModules.sendPush(\n authKey,\n userId,\n title,\n body,\n providers,\n isProduction\n );\n }\n\n /**\n * Gets notification permission status at a system level.\n * @example const permissionStatus = await Courier.getNotificationPermissionStatus()\n */\n get notificationPermissionStatus(): Promise<string> {\n return CourierReactNativeModules.getNotificationPermissionStatus();\n }\n\n /**\n * Requests notification permission status at a system level.\n * Returns the string associated with the permission status.\n * Will return the current status and will not present a popup\n * if the user has already been asked for permission.\n * @example const permissionStatus = await Courier.requestNotificationPermission()\n */\n public requestNotificationPermission(): Promise<string> {\n return CourierReactNativeModules.requestNotificationPermission();\n }\n\n /**\n * Sets the push notification presentation style when the app is in the foreground\n * This does not affect how the notification is shown when the app is killed or in the background states\n *\n * Defaults to sound, badge, list and/or banner.\n *\n * @example iOSForegroundPresentationOptions({options: ['sound']});\n */\n public iOSForegroundPresentationOptions({\n options,\n }: {\n options: ('sound' | 'badge' | 'list' | 'banner')[];\n }): Promise<void> {\n // Only works on iOS\n if (Platform.OS !== 'ios') return Promise.resolve();\n\n const normalizedParams = Array.from(new Set(options));\n return CourierReactNativeModules.iOSForegroundPresentationOptions({\n options: normalizedParams,\n });\n }\n\n /**\n * @example \n *```\n const unsubPushListeners = () => {\n return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({\n onPushNotificationClicked: (push) => {\n ...\n },\n onPushNotificationDelivered: (push) => {\n ...\n },\n })\n }\n\n // To unsubscribe the listeners\n unsubPushListeners()\n *```\n * @returns function that can be used to unsubscribe from registered listeners\n */\n public registerPushNotificationListeners({\n onPushNotificationClicked,\n onPushNotificationDelivered,\n }: {\n onPushNotificationClicked: (_push: any) => void;\n onPushNotificationDelivered: (_push: any) => void;\n }) {\n let notificationClickedListener: EmitterSubscription;\n let notificationDeliveredListener: EmitterSubscription;\n\n // Android\n if (Platform.OS === 'android') {\n notificationClickedListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // iOS\n if (Platform.OS === 'ios') {\n notificationClickedListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // When listener is registered\n // Attempt to fetch the last message that was clicked\n // This is needed for when the app is killed and the\n // user launched the app by clicking on a notifications\n CourierReactNativeModules.registerPushNotificationClickedOnKilledState();\n\n return () => {\n notificationClickedListener.remove();\n notificationDeliveredListener.remove();\n };\n }\n}\n\nexport default new Courier();\n"],"mappings":";;AAAA;;AACA;AACA,SACEA,aADF,EAEEC,QAFF,EAGEC,kBAHF,EAIEC,kBAJF,QAMO,cANP;AAQA,MAAMC,aAAa,GAChB,4FAA2FH,QAAQ,CAACI,MAAT,CAC1F;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAD0F,CAE1F,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,CAC9B,KAAKuC,2BADyB,EAE7BtC,KAAD,IAAgB;QACd,IAAI;UACFgC,2BAA2B,CAACI,IAAI,CAACC,KAAL,CAAWrC,KAAX,CAAD,CAA3B;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR6B,CAAhC;IAUD,CA3BA,CA6BD;;;IACA,IAAIvB,QAAQ,CAACuC,EAAT,KAAgB,KAApB,EAA2B;MACzBwB,2BAA2B,GAAGnD,mBAAmB,CAACiB,WAApB,CAC5B,KAAKoC,yBADuB,EAE3BnC,KAAD,IAAgB;QACd,IAAI;UACF+B,yBAAyB,CAACK,IAAI,CAACC,KAAL,CAAWrC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAyC,6BAA6B,GAAGpD,mBAAmB,CAACiB,WAApB,CAC9B,KAAKuC,2BADyB,EAE7BtC,KAAD,IAAgB;QACd,IAAI;UACFgC,2BAA2B,CAACI,IAAI,CAACC,KAAL,CAAWrC,KAAX,CAAD,CAA3B;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR6B,CAAhC;IAUD,CApDA,CAsDD;IACA;IACA;IACA;;;IACAhB,yBAAyB,CAAC8D,4CAA1B;IAEA,OAAO,MAAM;MACXN,2BAA2B,CAACnC,MAA5B;MACAoC,6BAA6B,CAACpC,MAA9B;IACD,CAHD;EAID;;AA7SW;;AAgTd,eAAe,IAAId,OAAJ,EAAf"}
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","DeviceEventEmitter","NativeEventEmitter","LINKING_ERROR","select","ios","default","CourierReactNativeModules","CourierReactNative","Proxy","get","Error","CourierEventEmitter","CourierProvider","Courier","constructor","setDefaults","Promise","all","setIsDebugging","__DEV__","iOSForegroundPresentationOptions","options","error","console","log","isDebugging","debugListener","remove","addListener","event","_isDebugging","setDebugMode","userId","getUserId","signIn","accessToken","signOut","apnsToken","OS","resolve","undefined","getApnsToken","fcmToken","getFcmToken","setFcmToken","token","sendPush","authKey","title","body","providers","notificationPermissionStatus","getNotificationPermissionStatus","requestNotificationPermission","normalizedParams","Array","from","Set","registerPushNotificationListeners","onPushNotificationClicked","onPushNotificationDelivered","notificationClickedListener","notificationDeliveredListener","PUSH_NOTIFICATION_CLICKED","JSON","parse","PUSH_NOTIFICATION_DELIVERED","registerPushNotificationClickedOnKilledState"],"sources":["index.ts"],"sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint class-methods-use-this: 0 */\nimport {\n NativeModules,\n Platform,\n DeviceEventEmitter,\n NativeEventEmitter,\n EmitterSubscription,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \\n\\n${Platform.select(\n { ios: \"- You have run 'pod install'\\n\", default: '' }\n )}- You rebuilt the app after installing the package\\n` +\n `- You are not using Expo managed workflow\\n`;\n\nconst CourierReactNativeModules = NativeModules.CourierReactNative\n ? NativeModules.CourierReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nconst CourierEventEmitter = new NativeEventEmitter(\n NativeModules.CourierReactNative\n);\n\nexport enum CourierProvider {\n FCM = 'firebase-fcm',\n APNS = 'apn',\n}\n\nclass Courier {\n readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';\n\n readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';\n\n public constructor() {\n // Sets the initial SDK values\n // Defaults to React Native level debugging\n // and will show all foreground notification styles in iOS\n this.setDefaults();\n }\n\n private async setDefaults() {\n try {\n await Promise.all([\n this.setIsDebugging(__DEV__),\n this.iOSForegroundPresentationOptions({\n options: ['sound', 'badge', 'list', 'banner'],\n }),\n ]);\n } catch (error) {\n console.log(error);\n }\n }\n\n private _isDebugging = false;\n\n private debugListener: EmitterSubscription | undefined;\n\n /**\n * Tells native Courier SDKs to show or hide logs.\n * Defaults to the React __DEV__ mode\n * @example Courier.setIsDebugging(true)\n */\n public async setIsDebugging(isDebugging: boolean): Promise<boolean> {\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n // listener needs to be registered first to catch the event\n if (isDebugging) {\n this.debugListener = CourierEventEmitter.addListener(\n 'courierDebugEvent',\n (event) => {\n console.log('\\x1b[36m%s\\x1b[0m', 'COURIER', event);\n }\n );\n }\n\n this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n return this._isDebugging;\n }\n\n get isDebugging(): boolean {\n return this._isDebugging;\n }\n\n /**\n * Returns the current user id stored in local native storage\n * @example const userId = await Courier.userId\n */\n get userId(): Promise<string | undefined> {\n return CourierReactNativeModules.getUserId();\n }\n\n /**\n * Signs user in and persists signin in between sessions\n * using native level storage apis\n * \n * @example\n * ```\n *await Courier.signIn({\n accessToken: YOUR_COURIER_GENERATED_JWT,\n userId: YOUR_USER_ID,\n })\n * ```\n * Your access token should be generated using this endpoint\n * that is requested from your backend\n * https://www.courier.com/docs/reference/auth/issue-token/\n */\n public signIn({\n accessToken,\n userId,\n }: {\n accessToken: string;\n userId: string;\n }): Promise<void> {\n return CourierReactNativeModules.signIn(userId, accessToken);\n }\n\n /**\n * Logs user out of native level user storage.\n * This will clear the userId, accessToken, and apns / fcm tokens and\n * delete the matching devices apns / fcm tokens for the user in Courier token management\n * @example await Courier.signOut()\n */\n public signOut(): Promise<void> {\n return CourierReactNativeModules.signOut();\n }\n\n /**\n * Sets the current Apple Push Notification Service (APNS) token\n * using Courier token management apis\n * @example const apnsToken = await Courier.apnsToken\n */\n get apnsToken(): Promise<string | undefined> {\n if (Platform.OS !== 'ios') return Promise.resolve(undefined);\n return CourierReactNativeModules.getApnsToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example const fcmToken = await Courier.fcmToken\n */\n get fcmToken(): Promise<string | undefined> {\n return CourierReactNativeModules.getFcmToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example await setFcmToken('asdf...asdf')\n */\n public setFcmToken(token: string): Promise<void> {\n return CourierReactNativeModules.setFcmToken(token);\n }\n\n /**\n * Hits the Courier /send endpoint and sends a test push notification\n * @example\n * ```\n *const messageId = await sendPush({\n authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,\n userId: USER_ID,\n title: 'This is a title',\n body: 'This is a body',\n providers: [CourierProvider.APNS, CourierProvider.FCM],\n });\n * ```\n * @returns promise\n */\n public sendPush({\n authKey,\n userId,\n title,\n body,\n providers,\n }: {\n authKey: string;\n userId: string;\n title?: string;\n body?: string;\n providers: CourierProvider[];\n }): Promise<string> {\n return CourierReactNativeModules.sendPush(\n authKey,\n userId,\n title,\n body,\n providers\n );\n }\n\n /**\n * Gets notification permission status at a system level.\n * @example const permissionStatus = await Courier.getNotificationPermissionStatus()\n */\n get notificationPermissionStatus(): Promise<string> {\n return CourierReactNativeModules.getNotificationPermissionStatus();\n }\n\n /**\n * Requests notification permission status at a system level.\n * Returns the string associated with the permission status.\n * Will return the current status and will not present a popup\n * if the user has already been asked for permission.\n * @example const permissionStatus = await Courier.requestNotificationPermission()\n */\n public requestNotificationPermission(): Promise<string> {\n return CourierReactNativeModules.requestNotificationPermission();\n }\n\n /**\n * Sets the push notification presentation style when the app is in the foreground\n * This does not affect how the notification is shown when the app is killed or in the background states\n *\n * Defaults to sound, badge, list and/or banner.\n *\n * @example iOSForegroundPresentationOptions({options: ['sound']});\n */\n public iOSForegroundPresentationOptions({\n options,\n }: {\n options: ('sound' | 'badge' | 'list' | 'banner')[];\n }): Promise<void> {\n // Only works on iOS\n if (Platform.OS !== 'ios') return Promise.resolve();\n\n const normalizedParams = Array.from(new Set(options));\n return CourierReactNativeModules.iOSForegroundPresentationOptions({\n options: normalizedParams,\n });\n }\n\n /**\n * @example \n *```\n const unsubPushListeners = () => {\n return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({\n onPushNotificationClicked: (push) => {\n ...\n },\n onPushNotificationDelivered: (push) => {\n ...\n },\n })\n }\n\n // To unsubscribe the listeners\n unsubPushListeners()\n *```\n * @returns function that can be used to unsubscribe from registered listeners\n */\n public registerPushNotificationListeners({\n onPushNotificationClicked,\n onPushNotificationDelivered,\n }: {\n onPushNotificationClicked: (_push: any) => void;\n onPushNotificationDelivered: (_push: any) => void;\n }) {\n let notificationClickedListener: EmitterSubscription;\n let notificationDeliveredListener: EmitterSubscription;\n\n // Android\n if (Platform.OS === 'android') {\n notificationClickedListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // iOS\n if (Platform.OS === 'ios') {\n notificationClickedListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // When listener is registered\n // Attempt to fetch the last message that was clicked\n // This is needed for when the app is killed and the\n // user launched the app by clicking on a notifications\n CourierReactNativeModules.registerPushNotificationClickedOnKilledState();\n\n return () => {\n notificationClickedListener.remove();\n notificationDeliveredListener.remove();\n };\n }\n}\n\nexport default new Courier();\n"],"mappings":";;AAAA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-75,18 +75,16 @@ declare class Courier {
|
|
|
75
75
|
title: 'This is a title',
|
|
76
76
|
body: 'This is a body',
|
|
77
77
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
78
|
-
isProduction: false, // true is production apns, false is sandbox apns
|
|
79
78
|
});
|
|
80
79
|
* ```
|
|
81
80
|
* @returns promise
|
|
82
81
|
*/
|
|
83
|
-
sendPush({ authKey, userId, title, body, providers,
|
|
82
|
+
sendPush({ authKey, userId, title, body, providers, }: {
|
|
84
83
|
authKey: string;
|
|
85
84
|
userId: string;
|
|
86
85
|
title?: string;
|
|
87
86
|
body?: string;
|
|
88
87
|
providers: CourierProvider[];
|
|
89
|
-
isProduction: boolean;
|
|
90
88
|
}): Promise<string>;
|
|
91
89
|
/**
|
|
92
90
|
* Gets notification permission status at a system level.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -175,7 +175,6 @@ class Courier {
|
|
|
175
175
|
title: 'This is a title',
|
|
176
176
|
body: 'This is a body',
|
|
177
177
|
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
178
|
-
isProduction: false, // true is production apns, false is sandbox apns
|
|
179
178
|
});
|
|
180
179
|
* ```
|
|
181
180
|
* @returns promise
|
|
@@ -186,22 +185,19 @@ class Courier {
|
|
|
186
185
|
title,
|
|
187
186
|
body,
|
|
188
187
|
providers,
|
|
189
|
-
isProduction,
|
|
190
188
|
}: {
|
|
191
189
|
authKey: string;
|
|
192
190
|
userId: string;
|
|
193
191
|
title?: string;
|
|
194
192
|
body?: string;
|
|
195
193
|
providers: CourierProvider[];
|
|
196
|
-
isProduction: boolean;
|
|
197
194
|
}): Promise<string> {
|
|
198
195
|
return CourierReactNativeModules.sendPush(
|
|
199
196
|
authKey,
|
|
200
197
|
userId,
|
|
201
198
|
title,
|
|
202
199
|
body,
|
|
203
|
-
providers
|
|
204
|
-
isProduction
|
|
200
|
+
providers
|
|
205
201
|
);
|
|
206
202
|
}
|
|
207
203
|
|