@trycourier/courier-react-native 1.0.9 → 2.0.0-beta0

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 (89) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -412
  3. package/android/build.gradle +48 -83
  4. package/android/src/main/AndroidManifest.xml +0 -1
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +10 -10
  7. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +146 -137
  8. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +1 -3
  9. package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +43 -0
  10. package/courier-react-native.podspec +12 -4
  11. package/ios/CourierReactNative-Bridging-Header.h +0 -1
  12. package/ios/CourierReactNative.xcodeproj/project.pbxproj +4 -4
  13. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  14. package/ios/CourierReactNativeModule.m +48 -0
  15. package/ios/{CourierReactNative.swift → CourierReactNativeModule.swift} +165 -45
  16. package/ios/CourierReactNativeViewManager.m +15 -0
  17. package/ios/CourierReactNativeViewManager.swift +348 -0
  18. package/lib/commonjs/index.js +68 -213
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/models/CourierInboxListener.js +26 -0
  21. package/lib/commonjs/models/CourierInboxListener.js.map +1 -0
  22. package/lib/commonjs/models/CourierInboxTheme.js +2 -0
  23. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -0
  24. package/lib/commonjs/models/InboxAction.js +2 -0
  25. package/lib/commonjs/models/InboxAction.js.map +1 -0
  26. package/lib/commonjs/models/InboxMessage.js +6 -0
  27. package/lib/commonjs/models/InboxMessage.js.map +1 -0
  28. package/lib/commonjs/views/CourierInboxView.js +53 -0
  29. package/lib/commonjs/views/CourierInboxView.js.map +1 -0
  30. package/lib/module/index.js +62 -212
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/models/CourierInboxListener.js +18 -0
  33. package/lib/module/models/CourierInboxListener.js.map +1 -0
  34. package/lib/module/models/CourierInboxTheme.js +2 -0
  35. package/lib/module/models/CourierInboxTheme.js.map +1 -0
  36. package/lib/module/models/InboxAction.js +2 -0
  37. package/lib/module/models/InboxAction.js.map +1 -0
  38. package/lib/module/models/InboxMessage.js +2 -0
  39. package/lib/module/models/InboxMessage.js.map +1 -0
  40. package/lib/module/views/CourierInboxView.js +45 -0
  41. package/lib/module/views/CourierInboxView.js.map +1 -0
  42. package/lib/typescript/index.d.ts +34 -92
  43. package/lib/typescript/index.d.ts.map +1 -0
  44. package/lib/typescript/models/CourierInboxListener.d.ts +9 -0
  45. package/lib/typescript/models/CourierInboxListener.d.ts.map +1 -0
  46. package/lib/typescript/models/CourierInboxTheme.d.ts +34 -0
  47. package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -0
  48. package/lib/typescript/models/InboxAction.d.ts +8 -0
  49. package/lib/typescript/models/InboxAction.d.ts.map +1 -0
  50. package/lib/typescript/models/InboxMessage.d.ts +18 -0
  51. package/lib/typescript/models/InboxMessage.d.ts.map +1 -0
  52. package/lib/typescript/views/CourierInboxView.d.ts +16 -0
  53. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -0
  54. package/package.json +61 -44
  55. package/src/index.tsx +188 -0
  56. package/src/models/CourierInboxListener.tsx +25 -0
  57. package/src/models/CourierInboxTheme.tsx +30 -0
  58. package/src/models/InboxAction.tsx +5 -0
  59. package/src/models/InboxMessage.tsx +16 -0
  60. package/src/views/CourierInboxView.tsx +85 -0
  61. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  62. package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
  63. package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
  64. package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
  65. package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
  66. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  67. package/android/.gradle/7.1/gc.properties +0 -0
  68. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  69. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  70. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  71. package/android/.gradle/checksums/checksums.lock +0 -0
  72. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  73. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  74. package/android/.gradle/vcs-1/gc.properties +0 -0
  75. package/android/.idea/compiler.xml +0 -6
  76. package/android/.idea/gradle.xml +0 -17
  77. package/android/.idea/jarRepositories.xml +0 -35
  78. package/android/.idea/misc.xml +0 -10
  79. package/android/.idea/vcs.xml +0 -6
  80. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  81. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  82. package/android/gradlew +0 -185
  83. package/android/gradlew.bat +0 -89
  84. package/android/local.properties +0 -8
  85. package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +0 -6
  86. package/ios/CourierReactNative.m +0 -52
  87. package/ios/CourierReactNativeDelegate.h +0 -20
  88. package/ios/CourierReactNativeDelegate.m +0 -125
  89. package/src/index.ts +0 -337
package/src/index.ts DELETED
@@ -1,337 +0,0 @@
1
- /* eslint no-underscore-dangle: 0 */
2
- /* eslint class-methods-use-this: 0 */
3
- import {
4
- NativeModules,
5
- Platform,
6
- DeviceEventEmitter,
7
- NativeEventEmitter,
8
- EmitterSubscription,
9
- } from 'react-native';
10
-
11
- const LINKING_ERROR =
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`;
16
-
17
- const CourierReactNativeModules = NativeModules.CourierReactNative
18
- ? NativeModules.CourierReactNative
19
- : new Proxy(
20
- {},
21
- {
22
- get() {
23
- throw new Error(LINKING_ERROR);
24
- },
25
- }
26
- );
27
-
28
- const CourierEventEmitter = new NativeEventEmitter(
29
- NativeModules.CourierReactNative
30
- );
31
-
32
- export enum CourierProvider {
33
- FCM = 'firebase-fcm',
34
- APNS = 'apn',
35
- }
36
-
37
- class Courier {
38
- readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';
39
-
40
- readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';
41
-
42
- public constructor() {
43
- // Sets the initial SDK values
44
- // Defaults to React Native level debugging
45
- // and will show all foreground notification styles in iOS
46
- this.setDefaults();
47
- }
48
-
49
- private async setDefaults() {
50
- try {
51
- await Promise.all([
52
- this.setIsDebugging(__DEV__),
53
- this.iOSForegroundPresentationOptions({
54
- options: ['sound', 'badge', 'list', 'banner'],
55
- }),
56
- ]);
57
- } catch (error) {
58
- console.log(error);
59
- }
60
- }
61
-
62
- private _isDebugging = false;
63
-
64
- private debugListener: EmitterSubscription | undefined;
65
-
66
- /**
67
- * Tells native Courier SDKs to show or hide logs.
68
- * Defaults to the React __DEV__ mode
69
- * @example Courier.setIsDebugging(true)
70
- */
71
- public async setIsDebugging(isDebugging: boolean): Promise<boolean> {
72
- // Remove the existing listener if needed
73
- this.debugListener?.remove();
74
-
75
- // Set a new listener
76
- // listener needs to be registered first to catch the event
77
- if (isDebugging) {
78
- this.debugListener = CourierEventEmitter.addListener(
79
- 'courierDebugEvent',
80
- (event) => {
81
- console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
82
- }
83
- );
84
- }
85
-
86
- this._isDebugging = await CourierReactNativeModules.setDebugMode(
87
- isDebugging
88
- );
89
-
90
- return this._isDebugging;
91
- }
92
-
93
- get isDebugging(): boolean {
94
- return this._isDebugging;
95
- }
96
-
97
- /**
98
- * Returns the current user id stored in local native storage
99
- * @example const userId = await Courier.userId
100
- */
101
- get userId(): Promise<string | undefined> {
102
- return CourierReactNativeModules.getUserId();
103
- }
104
-
105
- /**
106
- * Signs user in and persists signin in between sessions
107
- * using native level storage apis
108
- *
109
- * @example
110
- * ```
111
- *await Courier.signIn({
112
- accessToken: YOUR_COURIER_GENERATED_JWT,
113
- userId: YOUR_USER_ID,
114
- })
115
- * ```
116
- * Your access token should be generated using this endpoint
117
- * that is requested from your backend
118
- * https://www.courier.com/docs/reference/auth/issue-token/
119
- */
120
- public signIn({
121
- accessToken,
122
- userId,
123
- }: {
124
- accessToken: string;
125
- userId: string;
126
- }): Promise<void> {
127
- return CourierReactNativeModules.signIn(userId, accessToken);
128
- }
129
-
130
- /**
131
- * Logs user out of native level user storage.
132
- * This will clear the userId, accessToken, and apns / fcm tokens and
133
- * delete the matching devices apns / fcm tokens for the user in Courier token management
134
- * @example await Courier.signOut()
135
- */
136
- public signOut(): Promise<void> {
137
- return CourierReactNativeModules.signOut();
138
- }
139
-
140
- /**
141
- * Sets the current Apple Push Notification Service (APNS) token
142
- * using Courier token management apis
143
- * @example const apnsToken = await Courier.apnsToken
144
- */
145
- get apnsToken(): Promise<string | undefined> {
146
- if (Platform.OS !== 'ios') return Promise.resolve(undefined);
147
- return CourierReactNativeModules.getApnsToken();
148
- }
149
-
150
- /**
151
- * Sets the current Firebase Cloud Messaging (FCM) token
152
- * using Courier token management apis
153
- * @example const fcmToken = await Courier.fcmToken
154
- */
155
- get fcmToken(): Promise<string | undefined> {
156
- return CourierReactNativeModules.getFcmToken();
157
- }
158
-
159
- /**
160
- * Sets the current Firebase Cloud Messaging (FCM) token
161
- * using Courier token management apis
162
- * @example await setFcmToken('asdf...asdf')
163
- */
164
- public setFcmToken(token: string): Promise<void> {
165
- return CourierReactNativeModules.setFcmToken(token);
166
- }
167
-
168
- /**
169
- * Hits the Courier /send endpoint and sends a test push notification
170
- * @example
171
- * ```
172
- *const messageId = await sendPush({
173
- authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,
174
- userId: USER_ID,
175
- title: 'This is a title',
176
- body: 'This is a body',
177
- providers: [CourierProvider.APNS, CourierProvider.FCM],
178
- });
179
- * ```
180
- * @returns promise
181
- */
182
- public sendPush({
183
- authKey,
184
- userId,
185
- title,
186
- body,
187
- providers,
188
- }: {
189
- authKey: string;
190
- userId: string;
191
- title?: string;
192
- body?: string;
193
- providers: CourierProvider[];
194
- }): Promise<string> {
195
- return CourierReactNativeModules.sendPush(
196
- authKey,
197
- userId,
198
- title,
199
- body,
200
- providers
201
- );
202
- }
203
-
204
- /**
205
- * Gets notification permission status at a system level.
206
- * @example const permissionStatus = await Courier.getNotificationPermissionStatus()
207
- */
208
- get notificationPermissionStatus(): Promise<string> {
209
- return CourierReactNativeModules.getNotificationPermissionStatus();
210
- }
211
-
212
- /**
213
- * Requests notification permission status at a system level.
214
- * Returns the string associated with the permission status.
215
- * Will return the current status and will not present a popup
216
- * if the user has already been asked for permission.
217
- * @example const permissionStatus = await Courier.requestNotificationPermission()
218
- */
219
- public requestNotificationPermission(): Promise<string> {
220
- return CourierReactNativeModules.requestNotificationPermission();
221
- }
222
-
223
- /**
224
- * Sets the push notification presentation style when the app is in the foreground
225
- * This does not affect how the notification is shown when the app is killed or in the background states
226
- *
227
- * Defaults to sound, badge, list and/or banner.
228
- *
229
- * @example iOSForegroundPresentationOptions({options: ['sound']});
230
- */
231
- public iOSForegroundPresentationOptions({
232
- options,
233
- }: {
234
- options: ('sound' | 'badge' | 'list' | 'banner')[];
235
- }): Promise<void> {
236
- // Only works on iOS
237
- if (Platform.OS !== 'ios') return Promise.resolve();
238
-
239
- const normalizedParams = Array.from(new Set(options));
240
- return CourierReactNativeModules.iOSForegroundPresentationOptions({
241
- options: normalizedParams,
242
- });
243
- }
244
-
245
- /**
246
- * @example
247
- *```
248
- const unsubPushListeners = () => {
249
- return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({
250
- onPushNotificationClicked: (push) => {
251
- ...
252
- },
253
- onPushNotificationDelivered: (push) => {
254
- ...
255
- },
256
- })
257
- }
258
-
259
- // To unsubscribe the listeners
260
- unsubPushListeners()
261
- *```
262
- * @returns function that can be used to unsubscribe from registered listeners
263
- */
264
- public registerPushNotificationListeners({
265
- onPushNotificationClicked,
266
- onPushNotificationDelivered,
267
- }: {
268
- onPushNotificationClicked: (_push: any) => void;
269
- onPushNotificationDelivered: (_push: any) => void;
270
- }) {
271
- let notificationClickedListener: EmitterSubscription;
272
- let notificationDeliveredListener: EmitterSubscription;
273
-
274
- // Android
275
- if (Platform.OS === 'android') {
276
- notificationClickedListener = DeviceEventEmitter.addListener(
277
- this.PUSH_NOTIFICATION_CLICKED,
278
- (event: any) => {
279
- try {
280
- onPushNotificationClicked(JSON.parse(event));
281
- } catch (error) {
282
- console.log(error);
283
- }
284
- }
285
- );
286
-
287
- notificationDeliveredListener = DeviceEventEmitter.addListener(
288
- this.PUSH_NOTIFICATION_DELIVERED,
289
- (event: any) => {
290
- try {
291
- onPushNotificationDelivered(JSON.parse(event));
292
- } catch (error) {
293
- console.log(error);
294
- }
295
- }
296
- );
297
- }
298
-
299
- // iOS
300
- if (Platform.OS === 'ios') {
301
- notificationClickedListener = CourierEventEmitter.addListener(
302
- this.PUSH_NOTIFICATION_CLICKED,
303
- (event: any) => {
304
- try {
305
- onPushNotificationClicked(JSON.parse(event));
306
- } catch (error) {
307
- console.log(error);
308
- }
309
- }
310
- );
311
-
312
- notificationDeliveredListener = CourierEventEmitter.addListener(
313
- this.PUSH_NOTIFICATION_DELIVERED,
314
- (event: any) => {
315
- try {
316
- onPushNotificationDelivered(JSON.parse(event));
317
- } catch (error) {
318
- console.log(error);
319
- }
320
- }
321
- );
322
- }
323
-
324
- // When listener is registered
325
- // Attempt to fetch the last message that was clicked
326
- // This is needed for when the app is killed and the
327
- // user launched the app by clicking on a notifications
328
- CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
329
-
330
- return () => {
331
- notificationClickedListener.remove();
332
- notificationDeliveredListener.remove();
333
- };
334
- }
335
- }
336
-
337
- export default new Courier();