@trycourier/courier-react-native 1.0.7 → 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 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 = await Courier.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` | `13` | — | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
56
- | `Android` | `21` | `32` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
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
- - This is needed to support newer Android Notification APIs
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 = await Courier.requestNotificationPermission();
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
  ```
@@ -136,7 +136,7 @@ dependencies {
136
136
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
137
137
 
138
138
  // Courier Core SDK
139
- api 'com.github.trycourier:courier-android:1.1.1'
139
+ api 'com.github.trycourier:courier-android:1.1.9'
140
140
 
141
141
  }
142
142
 
@@ -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.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.
@@ -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
 
@@ -8,7 +8,7 @@ class CourierReactNative: RCTEventEmitter {
8
8
  internal static let COURIER_PUSH_NOTIFICATION_DELIVERED_EVENT = "pushNotificationDelivered"
9
9
  private static let COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT = "courierDebugEvent"
10
10
 
11
- private var isDebugListenerRegistered = false
11
+ private var hasListeners = false
12
12
 
13
13
  private var lastClickedMessage: [AnyHashable: Any]? = nil
14
14
  private var notificationCenter: NotificationCenter {
@@ -24,14 +24,29 @@ class CourierReactNative: RCTEventEmitter {
24
24
  // Used to know the platform performing requests
25
25
  Courier.agent = CourierAgent.react_native_ios
26
26
 
27
- // Reset Debugger
28
- Courier.shared.isDebugging = false
29
-
30
27
  // Attach the listeners
31
28
  attachObservers()
32
29
 
33
30
  }
34
31
 
32
+ override func startObserving() {
33
+
34
+ hasListeners = true
35
+
36
+ // setup listeners
37
+ Courier.shared.logListener = { log in
38
+ self.sendEvent(withName: CourierReactNative.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT, body: log)
39
+ }
40
+
41
+ }
42
+
43
+ override func stopObserving() {
44
+
45
+ hasListeners = false
46
+ // perform actions after listener is removed
47
+
48
+ }
49
+
35
50
  private func attachObservers() {
36
51
 
37
52
  notificationCenter.addObserver(
@@ -182,8 +197,8 @@ class CourierReactNative: RCTEventEmitter {
182
197
 
183
198
  }
184
199
 
185
- @objc(sendPush: withUserId: withTitle: withBody: withProviders: withIsProduction: withResolver: withRejecter:)
186
- func sendPush(authKey: NSString, userId: NSString, title: NSString, body: NSString, providers: NSArray, isProduction: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
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) {
187
202
 
188
203
  guard let courierProviders = providers as? [String] else {
189
204
  reject("No provider supported", CourierReactNative.COURIER_ERROR_TAG, nil)
@@ -195,7 +210,6 @@ class CourierReactNative: RCTEventEmitter {
195
210
  userId: userId as String,
196
211
  title: title as String,
197
212
  message: body as String,
198
- isProduction: isProduction,
199
213
  providers: courierProviders,
200
214
  onSuccess: { requestId in
201
215
  resolve(requestId)
@@ -221,15 +235,7 @@ class CourierReactNative: RCTEventEmitter {
221
235
 
222
236
  @objc(setDebugMode: withResolver: withRejecter:)
223
237
  func setDebugMode(isDebugging: Bool,resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
224
-
225
- // Send notification to react native side
226
- if (isDebugging && !isDebugListenerRegistered) {
227
- isDebugListenerRegistered = true
228
- Courier.shared.logListener = { log in
229
- self.sendEvent(withName: CourierReactNative.COURIER_PUSH_NOTIFICATION_DEBUG_LOG_EVENT, body: log)
230
- }
231
- }
232
-
238
+
233
239
  Courier.shared.isDebugging = isDebugging
234
240
  resolve(Courier.shared.isDebugging)
235
241
 
@@ -62,16 +62,17 @@ class Courier {
62
62
  async setIsDebugging(isDebugging) {
63
63
  var _this$debugListener;
64
64
 
65
- this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging); // Remove the existing listener if needed
66
-
65
+ // Remove the existing listener if needed
67
66
  (_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove(); // Set a new listener
67
+ // listener needs to be registered first to catch the event
68
68
 
69
- if (this._isDebugging) {
69
+ if (isDebugging) {
70
70
  this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
71
71
  console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
72
72
  });
73
73
  }
74
74
 
75
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging);
75
76
  return this._isDebugging;
76
77
  }
77
78
 
@@ -163,7 +164,6 @@ class Courier {
163
164
  title: 'This is a title',
164
165
  body: 'This is a body',
165
166
  providers: [CourierProvider.APNS, CourierProvider.FCM],
166
- isProduction: false, // true is production apns, false is sandbox apns
167
167
  });
168
168
  * ```
169
169
  * @returns promise
@@ -176,10 +176,9 @@ class Courier {
176
176
  userId,
177
177
  title,
178
178
  body,
179
- providers,
180
- isProduction
179
+ providers
181
180
  } = _ref2;
182
- return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers, isProduction);
181
+ return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers);
183
182
  }
184
183
  /**
185
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","_isDebugging","setDebugMode","debugListener","remove","addListener","event","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 this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n if (this._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 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,yBA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,IAAI,CAACC,KAAL,CAAWpC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOT,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAyC,6BAA6B,GAAGrD,mBAAmB,CAACoB,WAApB,CAC9B,KAAKsC,2BADyB,EAE7BrC,KAAD,IAAgB;QACd,IAAI;UACF8B,2BAA2B,CAACK,IAAI,CAACC,KAAL,CAAWpC,KAAX,CAAD,CAA3B;QACD,CAFD,CAEE,OAAOT,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR6B,CAAhC;IAUD,CApDA,CAsDD;IACA;IACA;IACA;;;IACAlB,yBAAyB,CAACiE,4CAA1B;IAEA,OAAO,MAAM;MACXP,2BAA2B,CAACjC,MAA5B;MACAkC,6BAA6B,CAAClC,MAA9B;IACD,CAHD;EAID;;AA5SW;;eA+SC,IAAIhB,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,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AAmB,CAACkB,WAApB,CAC5B,KAAKoC,yBADuB,EAE3BnC,KAAD,IAAgB;QACd,IAAI;UACF8B,yBAAyB,CAACM,IAAI,CAACC,KAAL,CAAWrC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAwC,6BAA6B,GAAGpD,mBAAmB,CAACkB,WAApB,CAC9B,KAAKuC,2BADyB,EAE7BtC,KAAD,IAAgB;QACd,IAAI;UACF+B,2BAA2B,CAACK,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;;;IACAlB,yBAAyB,CAACgE,4CAA1B;IAEA,OAAO,MAAM;MACXP,2BAA2B,CAAClC,MAA5B;MACAmC,6BAA6B,CAACnC,MAA9B;IACD,CAHD;EAID;;AAzSW;;eA4SC,IAAId,OAAJ,E"}
@@ -56,16 +56,17 @@ class Courier {
56
56
  async setIsDebugging(isDebugging) {
57
57
  var _this$debugListener;
58
58
 
59
- this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging); // Remove the existing listener if needed
60
-
59
+ // Remove the existing listener if needed
61
60
  (_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove(); // Set a new listener
61
+ // listener needs to be registered first to catch the event
62
62
 
63
- if (this._isDebugging) {
63
+ if (isDebugging) {
64
64
  this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
65
65
  console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
66
66
  });
67
67
  }
68
68
 
69
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging);
69
70
  return this._isDebugging;
70
71
  }
71
72
 
@@ -157,7 +158,6 @@ class Courier {
157
158
  title: 'This is a title',
158
159
  body: 'This is a body',
159
160
  providers: [CourierProvider.APNS, CourierProvider.FCM],
160
- isProduction: false, // true is production apns, false is sandbox apns
161
161
  });
162
162
  * ```
163
163
  * @returns promise
@@ -170,10 +170,9 @@ class Courier {
170
170
  userId,
171
171
  title,
172
172
  body,
173
- providers,
174
- isProduction
173
+ providers
175
174
  } = _ref2;
176
- return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers, isProduction);
175
+ return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers);
177
176
  }
178
177
  /**
179
178
  * Gets notification permission status at a system level.
@@ -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","_isDebugging","setDebugMode","debugListener","remove","addListener","event","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 this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n if (this._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 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,sDAFF,GAGC,6CAJH;AAMA,MAAMC,yBAAyB,GAAGR,aAAa,CAACS,kBAAd,GAC9BT,aAAa,CAACS,kBADgB,GAE9B,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUR,aAAV,CAAN;EACD;;AAHH,CAFF,CAFJ;AAWA,MAAMS,mBAAmB,GAAG,IAAIV,kBAAJ,CAC1BH,aAAa,CAACS,kBADY,CAA5B;AAIA,WAAYK,eAAZ;;WAAYA,e;EAAAA,e;EAAAA,e;GAAAA,e,KAAAA,e;;AAKZ,MAAMC,OAAN,CAAc;EAKLC,WAAW,GAAG;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F6B,yBAAyB,CAACK,IAAI,CAACC,KAAL,CAAWnC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOT,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAyC,6BAA6B,GAAGpD,mBAAmB,CAACmB,WAApB,CAC9B,KAAKqC,2BADyB,EAE7BpC,KAAD,IAAgB;QACd,IAAI;UACF8B,2BAA2B,CAACI,IAAI,CAACC,KAAL,CAAWnC,KAAX,CAAD,CAA3B;QACD,CAFD,CAEE,OAAOT,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,CAACjC,MAA5B;MACAkC,6BAA6B,CAAClC,MAA9B;IACD,CAHD;EAID;;AA5SW;;AA+Sd,eAAe,IAAIhB,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;;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,sDAFF,GAGC,6CAJH;AAMA,MAAMC,yBAAyB,GAAGR,aAAa,CAACS,kBAAd,GAC9BT,aAAa,CAACS,kBADgB,GAE9B,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUR,aAAV,CAAN;EACD;;A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BA,CA6BD;;;IACA,IAAIvB,QAAQ,CAACuC,EAAT,KAAgB,KAApB,EAA2B;MACzBuB,2BAA2B,GAAGlD,mBAAmB,CAACiB,WAApB,CAC5B,KAAKmC,yBADuB,EAE3BlC,KAAD,IAAgB;QACd,IAAI;UACF8B,yBAAyB,CAACK,IAAI,CAACC,KAAL,CAAWpC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAwC,6BAA6B,GAAGnD,mBAAmB,CAACiB,WAApB,CAC9B,KAAKsC,2BADyB,EAE7BrC,KAAD,IAAgB;QACd,IAAI;UACF+B,2BAA2B,CAACI,IAAI,CAACC,KAAL,CAAWpC,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,CAAC6D,4CAA1B;IAEA,OAAO,MAAM;MACXN,2BAA2B,CAAClC,MAA5B;MACAmC,6BAA6B,CAACnC,MAA9B;IACD,CAHD;EAID;;AAzSW;;AA4Sd,eAAe,IAAId,OAAJ,EAAf"}
@@ -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, isProduction, }: {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ts CHANGED
@@ -69,15 +69,12 @@ class Courier {
69
69
  * @example Courier.setIsDebugging(true)
70
70
  */
71
71
  public async setIsDebugging(isDebugging: boolean): Promise<boolean> {
72
- this._isDebugging = await CourierReactNativeModules.setDebugMode(
73
- isDebugging
74
- );
75
-
76
72
  // Remove the existing listener if needed
77
73
  this.debugListener?.remove();
78
74
 
79
75
  // Set a new listener
80
- if (this._isDebugging) {
76
+ // listener needs to be registered first to catch the event
77
+ if (isDebugging) {
81
78
  this.debugListener = CourierEventEmitter.addListener(
82
79
  'courierDebugEvent',
83
80
  (event) => {
@@ -86,6 +83,10 @@ class Courier {
86
83
  );
87
84
  }
88
85
 
86
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(
87
+ isDebugging
88
+ );
89
+
89
90
  return this._isDebugging;
90
91
  }
91
92
 
@@ -174,7 +175,6 @@ class Courier {
174
175
  title: 'This is a title',
175
176
  body: 'This is a body',
176
177
  providers: [CourierProvider.APNS, CourierProvider.FCM],
177
- isProduction: false, // true is production apns, false is sandbox apns
178
178
  });
179
179
  * ```
180
180
  * @returns promise
@@ -185,22 +185,19 @@ class Courier {
185
185
  title,
186
186
  body,
187
187
  providers,
188
- isProduction,
189
188
  }: {
190
189
  authKey: string;
191
190
  userId: string;
192
191
  title?: string;
193
192
  body?: string;
194
193
  providers: CourierProvider[];
195
- isProduction: boolean;
196
194
  }): Promise<string> {
197
195
  return CourierReactNativeModules.sendPush(
198
196
  authKey,
199
197
  userId,
200
198
  title,
201
199
  body,
202
- providers,
203
- isProduction
200
+ providers
204
201
  );
205
202
  }
206
203