@trycourier/courier-react-native 0.1.0

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.
Files changed (47) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +382 -0
  3. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
  6. package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
  7. package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
  8. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  9. package/android/.gradle/7.1/gc.properties +0 -0
  10. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  11. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  12. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  13. package/android/.gradle/checksums/checksums.lock +0 -0
  14. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  15. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  16. package/android/.gradle/vcs-1/gc.properties +0 -0
  17. package/android/.idea/compiler.xml +6 -0
  18. package/android/.idea/gradle.xml +17 -0
  19. package/android/.idea/jarRepositories.xml +35 -0
  20. package/android/.idea/misc.xml +10 -0
  21. package/android/.idea/vcs.xml +6 -0
  22. package/android/build.gradle +149 -0
  23. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  24. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  25. package/android/gradle.properties +5 -0
  26. package/android/gradlew +185 -0
  27. package/android/gradlew.bat +89 -0
  28. package/android/local.properties +8 -0
  29. package/android/src/main/AndroidManifest.xml +4 -0
  30. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +62 -0
  31. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +199 -0
  32. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +19 -0
  33. package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +6 -0
  34. package/courier-react-native.podspec +37 -0
  35. package/ios/CourierReactNative-Bridging-Header.h +3 -0
  36. package/ios/CourierReactNative.m +53 -0
  37. package/ios/CourierReactNative.swift +286 -0
  38. package/ios/CourierReactNative.xcodeproj/project.pbxproj +283 -0
  39. package/ios/CourierReactNativeDelegate.h +20 -0
  40. package/ios/CourierReactNativeDelegate.m +125 -0
  41. package/lib/commonjs/index.js +305 -0
  42. package/lib/commonjs/index.js.map +1 -0
  43. package/lib/module/index.js +295 -0
  44. package/lib/module/index.js.map +1 -0
  45. package/lib/typescript/index.d.ts +140 -0
  46. package/package.json +156 -0
  47. package/src/index.ts +337 -0
@@ -0,0 +1,125 @@
1
+ //
2
+ // CourierReactNativeDelegate.m
3
+ // courier-react-native
4
+ //
5
+ // Created by Michael Miller on 10/7/22.
6
+ //
7
+
8
+ @import Courier_iOS;
9
+ #import "CourierReactNativeDelegate.h"
10
+ #pragma GCC diagnostic ignored "-Wprotocol"
11
+ #pragma clang diagnostic ignored "-Wprotocol"
12
+
13
+ @implementation CourierReactNativeDelegate
14
+
15
+ NSString *iosForegroundNotificationPresentationOptions = @"iosForegroundNotificationPresentationOptions";
16
+ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNone;
17
+
18
+ - (id) init {
19
+
20
+ self = [super init];
21
+
22
+ if (self) {
23
+
24
+ // Register for remote notifications
25
+ UIApplication *app = [UIApplication sharedApplication];
26
+ [app registerForRemoteNotifications];
27
+
28
+ // Register notification center changes
29
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
30
+ center.delegate = self;
31
+
32
+ [[NSNotificationCenter defaultCenter]
33
+ addObserver:self
34
+ selector:@selector(notificationPresentationOptionsUpdate:)
35
+ name:iosForegroundNotificationPresentationOptions
36
+ object:nil
37
+ ];
38
+
39
+ }
40
+
41
+ return(self);
42
+
43
+ }
44
+
45
+ - (void) notificationPresentationOptionsUpdate:(NSNotification *) notification
46
+ {
47
+ if ([[notification name] isEqualToString:iosForegroundNotificationPresentationOptions])
48
+ {
49
+ NSDictionary *userInfo = notification.userInfo;
50
+ notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
51
+ }
52
+ }
53
+
54
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
55
+ {
56
+
57
+ UNNotificationContent *content = notification.request.content;
58
+ NSDictionary *message = content.userInfo;
59
+
60
+ [[Courier shared] trackNotificationWithMessage:message event:CourierPushEventDelivered completionHandler:^(NSError *error)
61
+ {
62
+ if (error != nil) {
63
+ [self log:error];
64
+ }
65
+ }
66
+ ];
67
+
68
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
69
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
70
+
71
+ completionHandler(notificationPresentationOptions);
72
+
73
+ }
74
+
75
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
76
+ {
77
+
78
+ UNNotificationContent *content = response.notification.request.content;
79
+ NSDictionary *message = content.userInfo;
80
+
81
+ [[Courier shared] trackNotificationWithMessage:message event:CourierPushEventClicked completionHandler:^(NSError *error)
82
+ {
83
+ if (error != nil) {
84
+ [self log:error];
85
+ }
86
+ }
87
+ ];
88
+
89
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
90
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
91
+
92
+ dispatch_async(dispatch_get_main_queue(), ^{
93
+ completionHandler();
94
+ });
95
+
96
+ }
97
+
98
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
99
+ {
100
+ [self log:error];
101
+ }
102
+
103
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
104
+ {
105
+
106
+ [[Courier shared]
107
+ setAPNSToken:deviceToken
108
+ onSuccess:^()
109
+ {
110
+ // Empty
111
+ }
112
+ onFailure:^(NSError *error)
113
+ {
114
+ [self log:error];
115
+ }
116
+ ];
117
+
118
+ }
119
+
120
+ - (void)log: (NSError*)error {
121
+ NSString *err = [NSString stringWithFormat:@"%@", error];
122
+ [Courier log:err];
123
+ }
124
+
125
+ @end
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.CourierProvider = void 0;
7
+
8
+ var _reactNative = require("react-native");
9
+
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
+
12
+ const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
13
+ ios: "- You have run 'pod install'\n",
14
+ default: ''
15
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
16
+ const CourierReactNativeModules = _reactNative.NativeModules.CourierReactNative ? _reactNative.NativeModules.CourierReactNative : new Proxy({}, {
17
+ get() {
18
+ throw new Error(LINKING_ERROR);
19
+ }
20
+
21
+ });
22
+ const CourierEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.CourierReactNative);
23
+ let CourierProvider;
24
+ exports.CourierProvider = CourierProvider;
25
+
26
+ (function (CourierProvider) {
27
+ CourierProvider["FCM"] = "firebase-fcm";
28
+ CourierProvider["APNS"] = "apn";
29
+ })(CourierProvider || (exports.CourierProvider = CourierProvider = {}));
30
+
31
+ class Courier {
32
+ constructor() {
33
+ _defineProperty(this, "PUSH_NOTIFICATION_CLICKED", 'pushNotificationClicked');
34
+
35
+ _defineProperty(this, "PUSH_NOTIFICATION_DELIVERED", 'pushNotificationDelivered');
36
+
37
+ _defineProperty(this, "_isDebugging", false);
38
+
39
+ _defineProperty(this, "debugListener", void 0);
40
+
41
+ // Sets the initial SDK values
42
+ // Defaults to React Native level debugging
43
+ // and will show all foreground notification styles in iOS
44
+ this.setDefaults();
45
+ }
46
+
47
+ async setDefaults() {
48
+ try {
49
+ await Promise.all([this.setIsDebugging(__DEV__), this.iOSForegroundPresentationOptions({
50
+ options: ['sound', 'badge', 'list', 'banner']
51
+ })]);
52
+ } catch (error) {
53
+ console.log(error);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Tells native Courier SDKs to show or hide logs.
59
+ * Defaults to the React __DEV__ mode
60
+ * @example Courier.setIsDebugging(true)
61
+ */
62
+ async setIsDebugging(isDebugging) {
63
+ var _this$debugListener;
64
+
65
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging); // Remove the existing listener if needed
66
+
67
+ (_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove(); // Set a new listener
68
+
69
+ if (this._isDebugging) {
70
+ this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
71
+ console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
72
+ });
73
+ }
74
+
75
+ return this._isDebugging;
76
+ }
77
+
78
+ get isDebugging() {
79
+ return this._isDebugging;
80
+ }
81
+ /**
82
+ * Returns the current user id stored in local native storage
83
+ * @example const userId = await Courier.userId
84
+ */
85
+
86
+
87
+ get userId() {
88
+ return CourierReactNativeModules.getUserId();
89
+ }
90
+ /**
91
+ * Signs user in and persists signin in between sessions
92
+ * using native level storage apis
93
+ *
94
+ * @example
95
+ * ```
96
+ *await Courier.signIn({
97
+ accessToken: YOUR_COURIER_GENERATED_JWT,
98
+ userId: YOUR_USER_ID,
99
+ })
100
+ * ```
101
+ * Your access token should be generated using this endpoint
102
+ * that is requested from your backend
103
+ * https://www.courier.com/docs/reference/auth/issue-token/
104
+ */
105
+
106
+
107
+ signIn(_ref) {
108
+ let {
109
+ accessToken,
110
+ userId
111
+ } = _ref;
112
+ return CourierReactNativeModules.signIn(userId, accessToken);
113
+ }
114
+ /**
115
+ * Logs user out of native level user storage.
116
+ * This will clear the userId, accessToken, and apns / fcm tokens and
117
+ * delete the matching devices apns / fcm tokens for the user in Courier token management
118
+ * @example await Courier.signOut()
119
+ */
120
+
121
+
122
+ signOut() {
123
+ return CourierReactNativeModules.signOut();
124
+ }
125
+ /**
126
+ * Sets the current Apple Push Notification Service (APNS) token
127
+ * using Courier token management apis
128
+ * @example const apnsToken = await Courier.apnsToken
129
+ */
130
+
131
+
132
+ get apnsToken() {
133
+ if (_reactNative.Platform.OS !== 'ios') return Promise.resolve(undefined);
134
+ return CourierReactNativeModules.getApnsToken();
135
+ }
136
+ /**
137
+ * Sets the current Firebase Cloud Messaging (FCM) token
138
+ * using Courier token management apis
139
+ * @example const fcmToken = await Courier.fcmToken
140
+ */
141
+
142
+
143
+ get fcmToken() {
144
+ return CourierReactNativeModules.getFcmToken();
145
+ }
146
+ /**
147
+ * Sets the current Firebase Cloud Messaging (FCM) token
148
+ * using Courier token management apis
149
+ * @example await setFcmToken('asdf...asdf')
150
+ */
151
+
152
+
153
+ setFcmToken(token) {
154
+ return CourierReactNativeModules.setFcmToken(token);
155
+ }
156
+ /**
157
+ * Hits the Courier /send endpoint and sends a test push notification
158
+ * @example
159
+ * ```
160
+ *const messageId = await sendPush({
161
+ authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,
162
+ userId: USER_ID,
163
+ title: 'This is a title',
164
+ body: 'This is a body',
165
+ providers: [CourierProvider.APNS, CourierProvider.FCM],
166
+ isProduction: false, // true is production apns, false is sandbox apns
167
+ });
168
+ * ```
169
+ * @returns promise
170
+ */
171
+
172
+
173
+ sendPush(_ref2) {
174
+ let {
175
+ authKey,
176
+ userId,
177
+ title,
178
+ body,
179
+ providers,
180
+ isProduction
181
+ } = _ref2;
182
+ return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers, isProduction);
183
+ }
184
+ /**
185
+ * Gets notification permission status at a system level.
186
+ * @example const permissionStatus = await Courier.getNotificationPermissionStatus()
187
+ */
188
+
189
+
190
+ get notificationPermissionStatus() {
191
+ return CourierReactNativeModules.getNotificationPermissionStatus();
192
+ }
193
+ /**
194
+ * Requests notification permission status at a system level.
195
+ * Returns the string associated with the permission status.
196
+ * Will return the current status and will not present a popup
197
+ * if the user has already been asked for permission.
198
+ * @example const permissionStatus = await Courier.requestNotificationPermission()
199
+ */
200
+
201
+
202
+ requestNotificationPermission() {
203
+ return CourierReactNativeModules.requestNotificationPermission();
204
+ }
205
+ /**
206
+ * Sets the push notification presentation style when the app is in the foreground
207
+ * This does not affect how the notification is shown when the app is killed or in the background states
208
+ *
209
+ * Defaults to sound, badge, list and/or banner.
210
+ *
211
+ * @example iOSForegroundPresentationOptions({options: ['sound']});
212
+ */
213
+
214
+
215
+ iOSForegroundPresentationOptions(_ref3) {
216
+ let {
217
+ options
218
+ } = _ref3;
219
+ // Only works on iOS
220
+ if (_reactNative.Platform.OS !== 'ios') return Promise.resolve();
221
+ const normalizedParams = Array.from(new Set(options));
222
+ return CourierReactNativeModules.iOSForegroundPresentationOptions({
223
+ options: normalizedParams
224
+ });
225
+ }
226
+ /**
227
+ * @example
228
+ *```
229
+ const unsubPushListeners = () => {
230
+ return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({
231
+ onPushNotificationClicked: (push) => {
232
+ ...
233
+ },
234
+ onPushNotificationDelivered: (push) => {
235
+ ...
236
+ },
237
+ })
238
+ }
239
+ // To unsubscribe the listeners
240
+ unsubPushListeners()
241
+ *```
242
+ * @returns function that can be used to unsubscribe from registered listeners
243
+ */
244
+
245
+
246
+ registerPushNotificationListeners(_ref4) {
247
+ let {
248
+ onPushNotificationClicked,
249
+ onPushNotificationDelivered
250
+ } = _ref4;
251
+ let notificationClickedListener;
252
+ let notificationDeliveredListener; // Android
253
+
254
+ if (_reactNative.Platform.OS === 'android') {
255
+ notificationClickedListener = _reactNative.DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, event => {
256
+ try {
257
+ onPushNotificationClicked(JSON.parse(event));
258
+ } catch (error) {
259
+ console.log(error);
260
+ }
261
+ });
262
+ notificationDeliveredListener = _reactNative.DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
263
+ try {
264
+ onPushNotificationDelivered(JSON.parse(event));
265
+ } catch (error) {
266
+ console.log(error);
267
+ }
268
+ });
269
+ } // iOS
270
+
271
+
272
+ if (_reactNative.Platform.OS === 'ios') {
273
+ notificationClickedListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, event => {
274
+ try {
275
+ onPushNotificationClicked(JSON.parse(event));
276
+ } catch (error) {
277
+ console.log(error);
278
+ }
279
+ });
280
+ notificationDeliveredListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
281
+ try {
282
+ onPushNotificationDelivered(JSON.parse(event));
283
+ } catch (error) {
284
+ console.log(error);
285
+ }
286
+ });
287
+ } // When listener is registered
288
+ // Attempt to fetch the last message that was clicked
289
+ // This is needed for when the app is killed and the
290
+ // user launched the app by clicking on a notifications
291
+
292
+
293
+ CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
294
+ return () => {
295
+ notificationClickedListener.remove();
296
+ notificationDeliveredListener.remove();
297
+ };
298
+ }
299
+
300
+ }
301
+
302
+ var _default = new Courier();
303
+
304
+ exports.default = _default;
305
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,M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