@trycourier/courier-react-native 1.0.5 → 1.0.6
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/android/build.gradle +1 -1
- package/courier-react-native.podspec +1 -1
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +5 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/package.json +26 -36
- package/src/index.ts +10 -7
package/android/build.gradle
CHANGED
|
@@ -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.
|
|
20
|
+
s.dependency 'Courier-iOS', '1.1.1'
|
|
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/lib/commonjs/index.js
CHANGED
|
@@ -9,10 +9,10 @@ var _reactNative = require("react-native");
|
|
|
9
9
|
|
|
10
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
11
|
|
|
12
|
-
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n
|
|
12
|
+
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n${_reactNative.Platform.select({
|
|
13
13
|
ios: "- You have run 'pod install'\n",
|
|
14
14
|
default: ''
|
|
15
|
-
})
|
|
15
|
+
})}- You rebuilt the app after installing the package\n` + `- You are not using Expo managed workflow\n`;
|
|
16
16
|
const CourierReactNativeModules = _reactNative.NativeModules.CourierReactNative ? _reactNative.NativeModules.CourierReactNative : new Proxy({}, {
|
|
17
17
|
get() {
|
|
18
18
|
throw new Error(LINKING_ERROR);
|
|
@@ -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-disable */\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` +\n Platform.select({ 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 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 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":";;;;;;;AACA;;;;AAQA,MAAMA,aAAa,GAChB,2FAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;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;EAILC,WAAW,GAAG;IAAA,mDAHgB,yBAGhB;;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;;EAKD;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A;IACA;;;IACAlB,yBAAyB,CAACiE,4CAA1B;IAEA,OAAO,MAAM;MACXP,2BAA2B,CAACjC,MAA5B;MACAkC,6BAA6B,CAAClC,MAA9B;IACD,CAHD;EAID;;AA1SW;;eA6SC,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","_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,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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B,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"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
|
-
/* eslint-
|
|
3
|
+
/* eslint no-underscore-dangle: 0 */
|
|
4
|
+
|
|
5
|
+
/* eslint class-methods-use-this: 0 */
|
|
4
6
|
import { NativeModules, Platform, DeviceEventEmitter, NativeEventEmitter } from 'react-native';
|
|
5
|
-
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n
|
|
7
|
+
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n${Platform.select({
|
|
6
8
|
ios: "- You have run 'pod install'\n",
|
|
7
9
|
default: ''
|
|
8
|
-
})
|
|
10
|
+
})}- You rebuilt the app after installing the package\n` + `- You are not using Expo managed workflow\n`;
|
|
9
11
|
const CourierReactNativeModules = NativeModules.CourierReactNative ? NativeModules.CourierReactNative : new Proxy({}, {
|
|
10
12
|
get() {
|
|
11
13
|
throw new Error(LINKING_ERROR);
|
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","_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-disable */\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` +\n Platform.select({ 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 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 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,SACEA,aADF,EAEEC,QAFF,EAGEC,kBAHF,EAIEC,kBAJF,QAMO,cANP;AAQA,MAAMC,aAAa,GAChB,2FAAD,GACAH,QAAQ,CAACI,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;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;EAILC,WAAW,GAAG;IAAA,mDAHgB,yBAGhB;;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;;EAKD;AACF;AACA;AACA;AACA;EAC6B,MAAdJ,cAAc,CAACO,WAAD,EAAy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M;MACXN,2BAA2B,CAACjC,MAA5B;MACAkC,6BAA6B,CAAClC,MAA9B;IACD,CAHD;EAID;;AA1SW;;AA6Sd,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","_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;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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AgB;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"}
|
|
@@ -132,8 +132,8 @@ declare class Courier {
|
|
|
132
132
|
* @returns function that can be used to unsubscribe from registered listeners
|
|
133
133
|
*/
|
|
134
134
|
registerPushNotificationListeners({ onPushNotificationClicked, onPushNotificationDelivered, }: {
|
|
135
|
-
onPushNotificationClicked: (
|
|
136
|
-
onPushNotificationDelivered: (
|
|
135
|
+
onPushNotificationClicked: (_push: any) => void;
|
|
136
|
+
onPushNotificationDelivered: (_push: any) => void;
|
|
137
137
|
}): () => void;
|
|
138
138
|
}
|
|
139
139
|
declare const _default: Courier;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier-react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "test",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -48,26 +48,33 @@
|
|
|
48
48
|
"registry": "https://registry.npmjs.org/"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@arkweid/lefthook": "^0.7.7",
|
|
52
51
|
"@babel/eslint-parser": "^7.18.2",
|
|
53
52
|
"@commitlint/config-conventional": "^17.0.2",
|
|
54
|
-
"@react-native-community/eslint-config": "^3.0
|
|
53
|
+
"@react-native-community/eslint-config": "^3.2.0",
|
|
55
54
|
"@release-it/conventional-changelog": "^5.0.0",
|
|
56
55
|
"@types/jest": "^28.1.2",
|
|
57
56
|
"@types/react": "~17.0.21",
|
|
58
57
|
"@types/react-native": "0.68.0",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
58
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
59
|
+
"commitizen": "^4.2.5",
|
|
60
|
+
"commitlint": "^17.2.0",
|
|
61
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
62
|
+
"eslint": "^8.27.0",
|
|
63
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
61
64
|
"eslint-config-prettier": "^8.5.0",
|
|
62
|
-
"eslint-plugin-
|
|
65
|
+
"eslint-plugin-import": "^2.26.0",
|
|
66
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
67
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
68
|
+
"eslint-plugin-react": "^7.31.10",
|
|
63
69
|
"jest": "^28.1.1",
|
|
70
|
+
"lefthook": "^1.2.0",
|
|
64
71
|
"pod-install": "^0.1.0",
|
|
65
|
-
"prettier": "^2.
|
|
72
|
+
"prettier": "^2.7.1",
|
|
66
73
|
"react": "17.0.2",
|
|
67
74
|
"react-native": "0.68.2",
|
|
68
75
|
"react-native-builder-bob": "^0.18.3",
|
|
69
76
|
"release-it": "^15.0.0",
|
|
70
|
-
"typescript": "^4.
|
|
77
|
+
"typescript": "^4.8.4"
|
|
71
78
|
},
|
|
72
79
|
"resolutions": {
|
|
73
80
|
"@types/react": "17.0.21"
|
|
@@ -108,37 +115,14 @@
|
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
117
|
},
|
|
111
|
-
"eslintConfig": {
|
|
112
|
-
"root": true,
|
|
113
|
-
"parser": "@babel/eslint-parser",
|
|
114
|
-
"extends": [
|
|
115
|
-
"@react-native-community",
|
|
116
|
-
"prettier"
|
|
117
|
-
],
|
|
118
|
-
"rules": {
|
|
119
|
-
"prettier/prettier": [
|
|
120
|
-
"error",
|
|
121
|
-
{
|
|
122
|
-
"quoteProps": "consistent",
|
|
123
|
-
"singleQuote": true,
|
|
124
|
-
"tabWidth": 2,
|
|
125
|
-
"trailingComma": "es5",
|
|
126
|
-
"useTabs": false
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
118
|
"eslintIgnore": [
|
|
132
119
|
"node_modules/",
|
|
133
|
-
"lib/"
|
|
120
|
+
"lib/",
|
|
121
|
+
"**/babel.config.**",
|
|
122
|
+
"**/metro.config.**",
|
|
123
|
+
"**/react-native.config.**",
|
|
124
|
+
"**/scripts/**"
|
|
134
125
|
],
|
|
135
|
-
"prettier": {
|
|
136
|
-
"quoteProps": "consistent",
|
|
137
|
-
"singleQuote": true,
|
|
138
|
-
"tabWidth": 2,
|
|
139
|
-
"trailingComma": "es5",
|
|
140
|
-
"useTabs": false
|
|
141
|
-
},
|
|
142
126
|
"react-native-builder-bob": {
|
|
143
127
|
"source": "src",
|
|
144
128
|
"output": "lib",
|
|
@@ -152,5 +136,11 @@
|
|
|
152
136
|
}
|
|
153
137
|
]
|
|
154
138
|
]
|
|
139
|
+
},
|
|
140
|
+
"dependencies": {},
|
|
141
|
+
"config": {
|
|
142
|
+
"commitizen": {
|
|
143
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
144
|
+
}
|
|
155
145
|
}
|
|
156
146
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/* eslint-
|
|
1
|
+
/* eslint no-underscore-dangle: 0 */
|
|
2
|
+
/* eslint class-methods-use-this: 0 */
|
|
2
3
|
import {
|
|
3
4
|
NativeModules,
|
|
4
5
|
Platform,
|
|
@@ -8,10 +9,10 @@ import {
|
|
|
8
9
|
} from 'react-native';
|
|
9
10
|
|
|
10
11
|
const LINKING_ERROR =
|
|
11
|
-
`The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
`The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n${Platform.select(
|
|
13
|
+
{ ios: "- You have run 'pod install'\n", default: '' }
|
|
14
|
+
)}- You rebuilt the app after installing the package\n` +
|
|
15
|
+
`- You are not using Expo managed workflow\n`;
|
|
15
16
|
|
|
16
17
|
const CourierReactNativeModules = NativeModules.CourierReactNative
|
|
17
18
|
? NativeModules.CourierReactNative
|
|
@@ -35,6 +36,7 @@ export enum CourierProvider {
|
|
|
35
36
|
|
|
36
37
|
class Courier {
|
|
37
38
|
readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';
|
|
39
|
+
|
|
38
40
|
readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';
|
|
39
41
|
|
|
40
42
|
public constructor() {
|
|
@@ -58,6 +60,7 @@ class Courier {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
private _isDebugging = false;
|
|
63
|
+
|
|
61
64
|
private debugListener: EmitterSubscription | undefined;
|
|
62
65
|
|
|
63
66
|
/**
|
|
@@ -265,8 +268,8 @@ class Courier {
|
|
|
265
268
|
onPushNotificationClicked,
|
|
266
269
|
onPushNotificationDelivered,
|
|
267
270
|
}: {
|
|
268
|
-
onPushNotificationClicked: (
|
|
269
|
-
onPushNotificationDelivered: (
|
|
271
|
+
onPushNotificationClicked: (_push: any) => void;
|
|
272
|
+
onPushNotificationDelivered: (_push: any) => void;
|
|
270
273
|
}) {
|
|
271
274
|
let notificationClickedListener: EmitterSubscription;
|
|
272
275
|
let notificationDeliveredListener: EmitterSubscription;
|