@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,295 @@
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
+
3
+ /* eslint-disable */
4
+ 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` + Platform.select({
6
+ ios: "- You have run 'pod install'\n",
7
+ default: ''
8
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
9
+ const CourierReactNativeModules = NativeModules.CourierReactNative ? NativeModules.CourierReactNative : new Proxy({}, {
10
+ get() {
11
+ throw new Error(LINKING_ERROR);
12
+ }
13
+
14
+ });
15
+ const CourierEventEmitter = new NativeEventEmitter(NativeModules.CourierReactNative);
16
+ export let CourierProvider;
17
+
18
+ (function (CourierProvider) {
19
+ CourierProvider["FCM"] = "firebase-fcm";
20
+ CourierProvider["APNS"] = "apn";
21
+ })(CourierProvider || (CourierProvider = {}));
22
+
23
+ class Courier {
24
+ constructor() {
25
+ _defineProperty(this, "PUSH_NOTIFICATION_CLICKED", 'pushNotificationClicked');
26
+
27
+ _defineProperty(this, "PUSH_NOTIFICATION_DELIVERED", 'pushNotificationDelivered');
28
+
29
+ _defineProperty(this, "_isDebugging", false);
30
+
31
+ _defineProperty(this, "debugListener", void 0);
32
+
33
+ // Sets the initial SDK values
34
+ // Defaults to React Native level debugging
35
+ // and will show all foreground notification styles in iOS
36
+ this.setDefaults();
37
+ }
38
+
39
+ async setDefaults() {
40
+ try {
41
+ await Promise.all([this.setIsDebugging(__DEV__), this.iOSForegroundPresentationOptions({
42
+ options: ['sound', 'badge', 'list', 'banner']
43
+ })]);
44
+ } catch (error) {
45
+ console.log(error);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Tells native Courier SDKs to show or hide logs.
51
+ * Defaults to the React __DEV__ mode
52
+ * @example Courier.setIsDebugging(true)
53
+ */
54
+ async setIsDebugging(isDebugging) {
55
+ var _this$debugListener;
56
+
57
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging); // Remove the existing listener if needed
58
+
59
+ (_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove(); // Set a new listener
60
+
61
+ if (this._isDebugging) {
62
+ this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
63
+ console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
64
+ });
65
+ }
66
+
67
+ return this._isDebugging;
68
+ }
69
+
70
+ get isDebugging() {
71
+ return this._isDebugging;
72
+ }
73
+ /**
74
+ * Returns the current user id stored in local native storage
75
+ * @example const userId = await Courier.userId
76
+ */
77
+
78
+
79
+ get userId() {
80
+ return CourierReactNativeModules.getUserId();
81
+ }
82
+ /**
83
+ * Signs user in and persists signin in between sessions
84
+ * using native level storage apis
85
+ *
86
+ * @example
87
+ * ```
88
+ *await Courier.signIn({
89
+ accessToken: YOUR_COURIER_GENERATED_JWT,
90
+ userId: YOUR_USER_ID,
91
+ })
92
+ * ```
93
+ * Your access token should be generated using this endpoint
94
+ * that is requested from your backend
95
+ * https://www.courier.com/docs/reference/auth/issue-token/
96
+ */
97
+
98
+
99
+ signIn(_ref) {
100
+ let {
101
+ accessToken,
102
+ userId
103
+ } = _ref;
104
+ return CourierReactNativeModules.signIn(userId, accessToken);
105
+ }
106
+ /**
107
+ * Logs user out of native level user storage.
108
+ * This will clear the userId, accessToken, and apns / fcm tokens and
109
+ * delete the matching devices apns / fcm tokens for the user in Courier token management
110
+ * @example await Courier.signOut()
111
+ */
112
+
113
+
114
+ signOut() {
115
+ return CourierReactNativeModules.signOut();
116
+ }
117
+ /**
118
+ * Sets the current Apple Push Notification Service (APNS) token
119
+ * using Courier token management apis
120
+ * @example const apnsToken = await Courier.apnsToken
121
+ */
122
+
123
+
124
+ get apnsToken() {
125
+ if (Platform.OS !== 'ios') return Promise.resolve(undefined);
126
+ return CourierReactNativeModules.getApnsToken();
127
+ }
128
+ /**
129
+ * Sets the current Firebase Cloud Messaging (FCM) token
130
+ * using Courier token management apis
131
+ * @example const fcmToken = await Courier.fcmToken
132
+ */
133
+
134
+
135
+ get fcmToken() {
136
+ return CourierReactNativeModules.getFcmToken();
137
+ }
138
+ /**
139
+ * Sets the current Firebase Cloud Messaging (FCM) token
140
+ * using Courier token management apis
141
+ * @example await setFcmToken('asdf...asdf')
142
+ */
143
+
144
+
145
+ setFcmToken(token) {
146
+ return CourierReactNativeModules.setFcmToken(token);
147
+ }
148
+ /**
149
+ * Hits the Courier /send endpoint and sends a test push notification
150
+ * @example
151
+ * ```
152
+ *const messageId = await sendPush({
153
+ authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,
154
+ userId: USER_ID,
155
+ title: 'This is a title',
156
+ body: 'This is a body',
157
+ providers: [CourierProvider.APNS, CourierProvider.FCM],
158
+ isProduction: false, // true is production apns, false is sandbox apns
159
+ });
160
+ * ```
161
+ * @returns promise
162
+ */
163
+
164
+
165
+ sendPush(_ref2) {
166
+ let {
167
+ authKey,
168
+ userId,
169
+ title,
170
+ body,
171
+ providers,
172
+ isProduction
173
+ } = _ref2;
174
+ return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers, isProduction);
175
+ }
176
+ /**
177
+ * Gets notification permission status at a system level.
178
+ * @example const permissionStatus = await Courier.getNotificationPermissionStatus()
179
+ */
180
+
181
+
182
+ get notificationPermissionStatus() {
183
+ return CourierReactNativeModules.getNotificationPermissionStatus();
184
+ }
185
+ /**
186
+ * Requests notification permission status at a system level.
187
+ * Returns the string associated with the permission status.
188
+ * Will return the current status and will not present a popup
189
+ * if the user has already been asked for permission.
190
+ * @example const permissionStatus = await Courier.requestNotificationPermission()
191
+ */
192
+
193
+
194
+ requestNotificationPermission() {
195
+ return CourierReactNativeModules.requestNotificationPermission();
196
+ }
197
+ /**
198
+ * Sets the push notification presentation style when the app is in the foreground
199
+ * This does not affect how the notification is shown when the app is killed or in the background states
200
+ *
201
+ * Defaults to sound, badge, list and/or banner.
202
+ *
203
+ * @example iOSForegroundPresentationOptions({options: ['sound']});
204
+ */
205
+
206
+
207
+ iOSForegroundPresentationOptions(_ref3) {
208
+ let {
209
+ options
210
+ } = _ref3;
211
+ // Only works on iOS
212
+ if (Platform.OS !== 'ios') return Promise.resolve();
213
+ const normalizedParams = Array.from(new Set(options));
214
+ return CourierReactNativeModules.iOSForegroundPresentationOptions({
215
+ options: normalizedParams
216
+ });
217
+ }
218
+ /**
219
+ * @example
220
+ *```
221
+ const unsubPushListeners = () => {
222
+ return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({
223
+ onPushNotificationClicked: (push) => {
224
+ ...
225
+ },
226
+ onPushNotificationDelivered: (push) => {
227
+ ...
228
+ },
229
+ })
230
+ }
231
+ // To unsubscribe the listeners
232
+ unsubPushListeners()
233
+ *```
234
+ * @returns function that can be used to unsubscribe from registered listeners
235
+ */
236
+
237
+
238
+ registerPushNotificationListeners(_ref4) {
239
+ let {
240
+ onPushNotificationClicked,
241
+ onPushNotificationDelivered
242
+ } = _ref4;
243
+ let notificationClickedListener;
244
+ let notificationDeliveredListener; // Android
245
+
246
+ if (Platform.OS === 'android') {
247
+ notificationClickedListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, event => {
248
+ try {
249
+ onPushNotificationClicked(JSON.parse(event));
250
+ } catch (error) {
251
+ console.log(error);
252
+ }
253
+ });
254
+ notificationDeliveredListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
255
+ try {
256
+ onPushNotificationDelivered(JSON.parse(event));
257
+ } catch (error) {
258
+ console.log(error);
259
+ }
260
+ });
261
+ } // iOS
262
+
263
+
264
+ if (Platform.OS === 'ios') {
265
+ notificationClickedListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, event => {
266
+ try {
267
+ onPushNotificationClicked(JSON.parse(event));
268
+ } catch (error) {
269
+ console.log(error);
270
+ }
271
+ });
272
+ notificationDeliveredListener = CourierEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
273
+ try {
274
+ onPushNotificationDelivered(JSON.parse(event));
275
+ } catch (error) {
276
+ console.log(error);
277
+ }
278
+ });
279
+ } // When listener is registered
280
+ // Attempt to fetch the last message that was clicked
281
+ // This is needed for when the app is killed and the
282
+ // user launched the app by clicking on a notifications
283
+
284
+
285
+ CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
286
+ return () => {
287
+ notificationClickedListener.remove();
288
+ notificationDeliveredListener.remove();
289
+ };
290
+ }
291
+
292
+ }
293
+
294
+ export default new Courier();
295
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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 declare class Courier {
6
+ readonly PUSH_NOTIFICATION_CLICKED = "pushNotificationClicked";
7
+ readonly PUSH_NOTIFICATION_DELIVERED = "pushNotificationDelivered";
8
+ constructor();
9
+ private setDefaults;
10
+ private _isDebugging;
11
+ private debugListener;
12
+ /**
13
+ * Tells native Courier SDKs to show or hide logs.
14
+ * Defaults to the React __DEV__ mode
15
+ * @example Courier.setIsDebugging(true)
16
+ */
17
+ setIsDebugging(isDebugging: boolean): Promise<boolean>;
18
+ get isDebugging(): boolean;
19
+ /**
20
+ * Returns the current user id stored in local native storage
21
+ * @example const userId = await Courier.userId
22
+ */
23
+ get userId(): Promise<string | undefined>;
24
+ /**
25
+ * Signs user in and persists signin in between sessions
26
+ * using native level storage apis
27
+ *
28
+ * @example
29
+ * ```
30
+ *await Courier.signIn({
31
+ accessToken: YOUR_COURIER_GENERATED_JWT,
32
+ userId: YOUR_USER_ID,
33
+ })
34
+ * ```
35
+ * Your access token should be generated using this endpoint
36
+ * that is requested from your backend
37
+ * https://www.courier.com/docs/reference/auth/issue-token/
38
+ */
39
+ signIn({ accessToken, userId, }: {
40
+ accessToken: string;
41
+ userId: string;
42
+ }): Promise<void>;
43
+ /**
44
+ * Logs user out of native level user storage.
45
+ * This will clear the userId, accessToken, and apns / fcm tokens and
46
+ * delete the matching devices apns / fcm tokens for the user in Courier token management
47
+ * @example await Courier.signOut()
48
+ */
49
+ signOut(): Promise<void>;
50
+ /**
51
+ * Sets the current Apple Push Notification Service (APNS) token
52
+ * using Courier token management apis
53
+ * @example const apnsToken = await Courier.apnsToken
54
+ */
55
+ get apnsToken(): Promise<string | undefined>;
56
+ /**
57
+ * Sets the current Firebase Cloud Messaging (FCM) token
58
+ * using Courier token management apis
59
+ * @example const fcmToken = await Courier.fcmToken
60
+ */
61
+ get fcmToken(): Promise<string | undefined>;
62
+ /**
63
+ * Sets the current Firebase Cloud Messaging (FCM) token
64
+ * using Courier token management apis
65
+ * @example await setFcmToken('asdf...asdf')
66
+ */
67
+ setFcmToken(token: string): Promise<void>;
68
+ /**
69
+ * Hits the Courier /send endpoint and sends a test push notification
70
+ * @example
71
+ * ```
72
+ *const messageId = await sendPush({
73
+ authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,
74
+ userId: USER_ID,
75
+ title: 'This is a title',
76
+ body: 'This is a body',
77
+ providers: [CourierProvider.APNS, CourierProvider.FCM],
78
+ isProduction: false, // true is production apns, false is sandbox apns
79
+ });
80
+ * ```
81
+ * @returns promise
82
+ */
83
+ sendPush({ authKey, userId, title, body, providers, isProduction, }: {
84
+ authKey: string;
85
+ userId: string;
86
+ title?: string;
87
+ body?: string;
88
+ providers: CourierProvider[];
89
+ isProduction: boolean;
90
+ }): Promise<string>;
91
+ /**
92
+ * Gets notification permission status at a system level.
93
+ * @example const permissionStatus = await Courier.getNotificationPermissionStatus()
94
+ */
95
+ get notificationPermissionStatus(): Promise<string>;
96
+ /**
97
+ * Requests notification permission status at a system level.
98
+ * Returns the string associated with the permission status.
99
+ * Will return the current status and will not present a popup
100
+ * if the user has already been asked for permission.
101
+ * @example const permissionStatus = await Courier.requestNotificationPermission()
102
+ */
103
+ requestNotificationPermission(): Promise<string>;
104
+ /**
105
+ * Sets the push notification presentation style when the app is in the foreground
106
+ * This does not affect how the notification is shown when the app is killed or in the background states
107
+ *
108
+ * Defaults to sound, badge, list and/or banner.
109
+ *
110
+ * @example iOSForegroundPresentationOptions({options: ['sound']});
111
+ */
112
+ iOSForegroundPresentationOptions({ options, }: {
113
+ options: ('sound' | 'badge' | 'list' | 'banner')[];
114
+ }): Promise<void>;
115
+ /**
116
+ * @example
117
+ *```
118
+ const unsubPushListeners = () => {
119
+ return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({
120
+ onPushNotificationClicked: (push) => {
121
+ ...
122
+ },
123
+ onPushNotificationDelivered: (push) => {
124
+ ...
125
+ },
126
+ })
127
+ }
128
+
129
+ // To unsubscribe the listeners
130
+ unsubPushListeners()
131
+ *```
132
+ * @returns function that can be used to unsubscribe from registered listeners
133
+ */
134
+ registerPushNotificationListeners({ onPushNotificationClicked, onPushNotificationDelivered, }: {
135
+ onPushNotificationClicked: (push: any) => void;
136
+ onPushNotificationDelivered: (push: any) => void;
137
+ }): () => void;
138
+ }
139
+ declare const _default: Courier;
140
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,156 @@
1
+ {
2
+ "name": "@trycourier/courier-react-native",
3
+ "version": "0.1.0",
4
+ "description": "test",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "courier-react-native.podspec",
17
+ "!lib/typescript/example",
18
+ "!android/build",
19
+ "!ios/build",
20
+ "!**/__tests__",
21
+ "!**/__fixtures__",
22
+ "!**/__mocks__"
23
+ ],
24
+ "scripts": {
25
+ "test": "jest",
26
+ "typescript": "tsc --noEmit",
27
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
28
+ "prepare": "bob build",
29
+ "release": "release-it",
30
+ "example": "yarn --cwd example",
31
+ "bootstrap": "yarn example && yarn && yarn example pods",
32
+ "linkPackage": "yarn link && yarn example link @trycourier/courier-react-native && yarn example setupEnv",
33
+ "setup": "sh setup.sh"
34
+ },
35
+ "keywords": [
36
+ "react-native",
37
+ "ios",
38
+ "android"
39
+ ],
40
+ "repository": "https://github.com/trycourier/courier-react-native",
41
+ "author": "FahadAminShovon <shovonfahad991@gmail.com> (https://github.com/FahadAminShovon)",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/trycourier/courier-react-native/issues"
45
+ },
46
+ "homepage": "https://github.com/trycourier/courier-react-native#readme",
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "devDependencies": {
51
+ "@arkweid/lefthook": "^0.7.7",
52
+ "@babel/eslint-parser": "^7.18.2",
53
+ "@commitlint/config-conventional": "^17.0.2",
54
+ "@react-native-community/eslint-config": "^3.0.2",
55
+ "@release-it/conventional-changelog": "^5.0.0",
56
+ "@types/jest": "^28.1.2",
57
+ "@types/react": "~17.0.21",
58
+ "@types/react-native": "0.68.0",
59
+ "commitlint": "^17.0.2",
60
+ "eslint": "^8.4.1",
61
+ "eslint-config-prettier": "^8.5.0",
62
+ "eslint-plugin-prettier": "^4.0.0",
63
+ "jest": "^28.1.1",
64
+ "pod-install": "^0.1.0",
65
+ "prettier": "^2.0.5",
66
+ "react": "17.0.2",
67
+ "react-native": "0.68.2",
68
+ "react-native-builder-bob": "^0.18.3",
69
+ "release-it": "^15.0.0",
70
+ "typescript": "^4.5.2"
71
+ },
72
+ "resolutions": {
73
+ "@types/react": "17.0.21"
74
+ },
75
+ "peerDependencies": {
76
+ "react": "*",
77
+ "react-native": "*"
78
+ },
79
+ "jest": {
80
+ "preset": "react-native",
81
+ "modulePathIgnorePatterns": [
82
+ "<rootDir>/example/node_modules",
83
+ "<rootDir>/lib/"
84
+ ],
85
+ "setupFiles": [
86
+ "./src/__mocks__/native-module-bridge.js"
87
+ ]
88
+ },
89
+ "commitlint": {
90
+ "extends": [
91
+ "@commitlint/config-conventional"
92
+ ]
93
+ },
94
+ "release-it": {
95
+ "git": {
96
+ "commitMessage": "chore: release ${version}",
97
+ "tagName": "v${version}"
98
+ },
99
+ "npm": {
100
+ "publish": true
101
+ },
102
+ "github": {
103
+ "release": true
104
+ },
105
+ "plugins": {
106
+ "@release-it/conventional-changelog": {
107
+ "preset": "angular"
108
+ }
109
+ }
110
+ },
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
+ "eslintIgnore": [
132
+ "node_modules/",
133
+ "lib/"
134
+ ],
135
+ "prettier": {
136
+ "quoteProps": "consistent",
137
+ "singleQuote": true,
138
+ "tabWidth": 2,
139
+ "trailingComma": "es5",
140
+ "useTabs": false
141
+ },
142
+ "react-native-builder-bob": {
143
+ "source": "src",
144
+ "output": "lib",
145
+ "targets": [
146
+ "commonjs",
147
+ "module",
148
+ [
149
+ "typescript",
150
+ {
151
+ "project": "tsconfig.build.json"
152
+ }
153
+ ]
154
+ ]
155
+ }
156
+ }