@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.
- package/LICENSE +1 -1
- package/README.md +16 -412
- package/android/build.gradle +48 -83
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +10 -10
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +146 -137
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +1 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +43 -0
- package/courier-react-native.podspec +12 -4
- package/ios/CourierReactNative-Bridging-Header.h +0 -1
- package/ios/CourierReactNative.xcodeproj/project.pbxproj +4 -4
- package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/CourierReactNativeModule.m +48 -0
- package/ios/{CourierReactNative.swift → CourierReactNativeModule.swift} +165 -45
- package/ios/CourierReactNativeViewManager.m +15 -0
- package/ios/CourierReactNativeViewManager.swift +348 -0
- package/lib/commonjs/index.js +68 -213
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +26 -0
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js +2 -0
- package/lib/commonjs/models/CourierInboxTheme.js.map +1 -0
- package/lib/commonjs/models/InboxAction.js +2 -0
- package/lib/commonjs/models/InboxAction.js.map +1 -0
- package/lib/commonjs/models/InboxMessage.js +6 -0
- package/lib/commonjs/models/InboxMessage.js.map +1 -0
- package/lib/commonjs/views/CourierInboxView.js +53 -0
- package/lib/commonjs/views/CourierInboxView.js.map +1 -0
- package/lib/module/index.js +62 -212
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +18 -0
- package/lib/module/models/CourierInboxListener.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js +2 -0
- package/lib/module/models/CourierInboxTheme.js.map +1 -0
- package/lib/module/models/InboxAction.js +2 -0
- package/lib/module/models/InboxAction.js.map +1 -0
- package/lib/module/models/InboxMessage.js +2 -0
- package/lib/module/models/InboxMessage.js.map +1 -0
- package/lib/module/views/CourierInboxView.js +45 -0
- package/lib/module/views/CourierInboxView.js.map +1 -0
- package/lib/typescript/index.d.ts +34 -92
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/models/CourierInboxListener.d.ts +9 -0
- package/lib/typescript/models/CourierInboxListener.d.ts.map +1 -0
- package/lib/typescript/models/CourierInboxTheme.d.ts +34 -0
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -0
- package/lib/typescript/models/InboxAction.d.ts +8 -0
- package/lib/typescript/models/InboxAction.d.ts.map +1 -0
- package/lib/typescript/models/InboxMessage.d.ts +18 -0
- package/lib/typescript/models/InboxMessage.d.ts.map +1 -0
- package/lib/typescript/views/CourierInboxView.d.ts +16 -0
- package/lib/typescript/views/CourierInboxView.d.ts.map +1 -0
- package/package.json +61 -44
- package/src/index.tsx +188 -0
- package/src/models/CourierInboxListener.tsx +25 -0
- package/src/models/CourierInboxTheme.tsx +30 -0
- package/src/models/InboxAction.tsx +5 -0
- package/src/models/InboxMessage.tsx +16 -0
- package/src/views/CourierInboxView.tsx +85 -0
- package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -17
- package/android/.idea/jarRepositories.xml +0 -35
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/vcs.xml +0 -6
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/android/local.properties +0 -8
- package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +0 -6
- package/ios/CourierReactNative.m +0 -52
- package/ios/CourierReactNativeDelegate.h +0 -20
- package/ios/CourierReactNativeDelegate.m +0 -125
- package/src/index.ts +0 -337
package/lib/module/index.js
CHANGED
|
@@ -1,53 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/* eslint class-methods-use-this: 0 */
|
|
6
|
-
import { NativeModules, Platform, DeviceEventEmitter, NativeEventEmitter } from 'react-native';
|
|
7
|
-
const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n${Platform.select({
|
|
1
|
+
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import { CourierInboxListener } from './models/CourierInboxListener';
|
|
3
|
+
export { CourierInboxView } from './views/CourierInboxView';
|
|
4
|
+
const LINKING_ERROR = `The package 'courier-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
8
5
|
ios: "- You have run 'pod install'\n",
|
|
9
6
|
default: ''
|
|
10
|
-
})
|
|
11
|
-
const CourierReactNativeModules = NativeModules.
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const CourierReactNativeModules = NativeModules.CourierReactNativeModule ? NativeModules.CourierReactNativeModule : new Proxy({}, {
|
|
12
9
|
get() {
|
|
13
10
|
throw new Error(LINKING_ERROR);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
});
|
|
17
|
-
const CourierEventEmitter = new NativeEventEmitter(NativeModules.
|
|
18
|
-
export let CourierProvider;
|
|
19
|
-
|
|
20
|
-
(function (CourierProvider) {
|
|
21
|
-
CourierProvider["FCM"] = "firebase-fcm";
|
|
22
|
-
CourierProvider["APNS"] = "apn";
|
|
23
|
-
})(CourierProvider || (CourierProvider = {}));
|
|
24
|
-
|
|
13
|
+
const CourierEventEmitter = new NativeEventEmitter(NativeModules.CourierReactNativeModule);
|
|
25
14
|
class Courier {
|
|
26
15
|
constructor() {
|
|
27
|
-
_defineProperty(this, "PUSH_NOTIFICATION_CLICKED", 'pushNotificationClicked');
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "PUSH_NOTIFICATION_DELIVERED", 'pushNotificationDelivered');
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "_isDebugging", false);
|
|
32
|
-
|
|
33
|
-
_defineProperty(this, "debugListener", void 0);
|
|
34
|
-
|
|
35
16
|
// Sets the initial SDK values
|
|
36
17
|
// Defaults to React Native level debugging
|
|
37
18
|
// and will show all foreground notification styles in iOS
|
|
38
19
|
this.setDefaults();
|
|
39
20
|
}
|
|
40
|
-
|
|
41
21
|
async setDefaults() {
|
|
42
22
|
try {
|
|
43
|
-
await Promise.all([this.setIsDebugging(__DEV__)
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
await Promise.all([this.setIsDebugging(__DEV__)
|
|
24
|
+
// this.iOSForegroundPresentationOptions({
|
|
25
|
+
// options: ['sound', 'badge', 'list', 'banner'],
|
|
26
|
+
// }),
|
|
27
|
+
]);
|
|
46
28
|
} catch (error) {
|
|
47
29
|
console.log(error);
|
|
48
30
|
}
|
|
49
31
|
}
|
|
50
|
-
|
|
32
|
+
_isDebugging = false;
|
|
51
33
|
/**
|
|
52
34
|
* Tells native Courier SDKs to show or hide logs.
|
|
53
35
|
* Defaults to the React __DEV__ mode
|
|
@@ -55,33 +37,31 @@ class Courier {
|
|
|
55
37
|
*/
|
|
56
38
|
async setIsDebugging(isDebugging) {
|
|
57
39
|
var _this$debugListener;
|
|
58
|
-
|
|
59
40
|
// Remove the existing listener if needed
|
|
60
|
-
(_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove();
|
|
61
|
-
// listener needs to be registered first to catch the event
|
|
41
|
+
(_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove();
|
|
62
42
|
|
|
43
|
+
// Set a new listener
|
|
44
|
+
// listener needs to be registered first to catch the event
|
|
63
45
|
if (isDebugging) {
|
|
64
46
|
this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
|
|
65
47
|
console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
|
|
66
48
|
});
|
|
67
49
|
}
|
|
68
|
-
|
|
69
50
|
this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging);
|
|
70
51
|
return this._isDebugging;
|
|
71
52
|
}
|
|
72
|
-
|
|
73
53
|
get isDebugging() {
|
|
74
54
|
return this._isDebugging;
|
|
75
55
|
}
|
|
56
|
+
|
|
76
57
|
/**
|
|
77
58
|
* Returns the current user id stored in local native storage
|
|
78
59
|
* @example const userId = await Courier.userId
|
|
79
60
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
61
|
get userId() {
|
|
83
62
|
return CourierReactNativeModules.getUserId();
|
|
84
63
|
}
|
|
64
|
+
|
|
85
65
|
/**
|
|
86
66
|
* Signs user in and persists signin in between sessions
|
|
87
67
|
* using native level storage apis
|
|
@@ -90,6 +70,7 @@ class Courier {
|
|
|
90
70
|
* ```
|
|
91
71
|
*await Courier.signIn({
|
|
92
72
|
accessToken: YOUR_COURIER_GENERATED_JWT,
|
|
73
|
+
clientKey: YOUR_CLIENT_KEY,
|
|
93
74
|
userId: YOUR_USER_ID,
|
|
94
75
|
})
|
|
95
76
|
* ```
|
|
@@ -97,200 +78,69 @@ class Courier {
|
|
|
97
78
|
* that is requested from your backend
|
|
98
79
|
* https://www.courier.com/docs/reference/auth/issue-token/
|
|
99
80
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
signIn(_ref) {
|
|
103
|
-
let {
|
|
104
|
-
accessToken,
|
|
105
|
-
userId
|
|
106
|
-
} = _ref;
|
|
107
|
-
return CourierReactNativeModules.signIn(userId, accessToken);
|
|
81
|
+
signIn(props) {
|
|
82
|
+
return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId);
|
|
108
83
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Logs user out of native level user storage.
|
|
111
|
-
* This will clear the userId, accessToken, and apns / fcm tokens and
|
|
112
|
-
* delete the matching devices apns / fcm tokens for the user in Courier token management
|
|
113
|
-
* @example await Courier.signOut()
|
|
114
|
-
*/
|
|
115
84
|
|
|
116
|
-
|
|
117
|
-
signOut() {
|
|
118
|
-
return CourierReactNativeModules.signOut();
|
|
119
|
-
}
|
|
120
85
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
86
|
+
* TODO
|
|
87
|
+
* @param props
|
|
88
|
+
* @returns
|
|
124
89
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
get apnsToken() {
|
|
128
|
-
if (Platform.OS !== 'ios') return Promise.resolve(undefined);
|
|
129
|
-
return CourierReactNativeModules.getApnsToken();
|
|
90
|
+
readMessage(props) {
|
|
91
|
+
return CourierReactNativeModules.readMessage(props.messageId);
|
|
130
92
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Sets the current Firebase Cloud Messaging (FCM) token
|
|
133
|
-
* using Courier token management apis
|
|
134
|
-
* @example const fcmToken = await Courier.fcmToken
|
|
135
|
-
*/
|
|
136
93
|
|
|
137
|
-
|
|
138
|
-
get fcmToken() {
|
|
139
|
-
return CourierReactNativeModules.getFcmToken();
|
|
140
|
-
}
|
|
141
94
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
95
|
+
* TODO
|
|
96
|
+
* @param props
|
|
97
|
+
* @returns
|
|
145
98
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
setFcmToken(token) {
|
|
149
|
-
return CourierReactNativeModules.setFcmToken(token);
|
|
99
|
+
unreadMessage(props) {
|
|
100
|
+
return CourierReactNativeModules.unreadMessage(props.messageId);
|
|
150
101
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Hits the Courier /send endpoint and sends a test push notification
|
|
153
|
-
* @example
|
|
154
|
-
* ```
|
|
155
|
-
*const messageId = await sendPush({
|
|
156
|
-
authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,
|
|
157
|
-
userId: USER_ID,
|
|
158
|
-
title: 'This is a title',
|
|
159
|
-
body: 'This is a body',
|
|
160
|
-
providers: [CourierProvider.APNS, CourierProvider.FCM],
|
|
161
|
-
});
|
|
162
|
-
* ```
|
|
163
|
-
* @returns promise
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
102
|
|
|
167
|
-
sendPush(_ref2) {
|
|
168
|
-
let {
|
|
169
|
-
authKey,
|
|
170
|
-
userId,
|
|
171
|
-
title,
|
|
172
|
-
body,
|
|
173
|
-
providers
|
|
174
|
-
} = _ref2;
|
|
175
|
-
return CourierReactNativeModules.sendPush(authKey, userId, title, body, providers);
|
|
176
|
-
}
|
|
177
103
|
/**
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
104
|
+
* TODO
|
|
105
|
+
* @param props
|
|
106
|
+
* @returns
|
|
180
107
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
get notificationPermissionStatus() {
|
|
184
|
-
return CourierReactNativeModules.getNotificationPermissionStatus();
|
|
108
|
+
readAllInboxMessages() {
|
|
109
|
+
return CourierReactNativeModules.readAllInboxMessages();
|
|
185
110
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Requests notification permission status at a system level.
|
|
188
|
-
* Returns the string associated with the permission status.
|
|
189
|
-
* Will return the current status and will not present a popup
|
|
190
|
-
* if the user has already been asked for permission.
|
|
191
|
-
* @example const permissionStatus = await Courier.requestNotificationPermission()
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
111
|
|
|
195
|
-
requestNotificationPermission() {
|
|
196
|
-
return CourierReactNativeModules.requestNotificationPermission();
|
|
197
|
-
}
|
|
198
112
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* Defaults to sound, badge, list and/or banner.
|
|
203
|
-
*
|
|
204
|
-
* @example iOSForegroundPresentationOptions({options: ['sound']});
|
|
113
|
+
* TODO
|
|
114
|
+
* @param props
|
|
115
|
+
* @returns
|
|
205
116
|
*/
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
// Only works on iOS
|
|
213
|
-
if (Platform.OS !== 'ios') return Promise.resolve();
|
|
214
|
-
const normalizedParams = Array.from(new Set(options));
|
|
215
|
-
return CourierReactNativeModules.iOSForegroundPresentationOptions({
|
|
216
|
-
options: normalizedParams
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* @example
|
|
221
|
-
*```
|
|
222
|
-
const unsubPushListeners = () => {
|
|
223
|
-
return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({
|
|
224
|
-
onPushNotificationClicked: (push) => {
|
|
225
|
-
...
|
|
226
|
-
},
|
|
227
|
-
onPushNotificationDelivered: (push) => {
|
|
228
|
-
...
|
|
229
|
-
},
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
// To unsubscribe the listeners
|
|
233
|
-
unsubPushListeners()
|
|
234
|
-
*```
|
|
235
|
-
* @returns function that can be used to unsubscribe from registered listeners
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
registerPushNotificationListeners(_ref4) {
|
|
240
|
-
let {
|
|
241
|
-
onPushNotificationClicked,
|
|
242
|
-
onPushNotificationDelivered
|
|
243
|
-
} = _ref4;
|
|
244
|
-
let notificationClickedListener;
|
|
245
|
-
let notificationDeliveredListener; // Android
|
|
246
|
-
|
|
247
|
-
if (Platform.OS === 'android') {
|
|
248
|
-
notificationClickedListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_CLICKED, event => {
|
|
249
|
-
try {
|
|
250
|
-
onPushNotificationClicked(JSON.parse(event));
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.log(error);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
notificationDeliveredListener = DeviceEventEmitter.addListener(this.PUSH_NOTIFICATION_DELIVERED, event => {
|
|
256
|
-
try {
|
|
257
|
-
onPushNotificationDelivered(JSON.parse(event));
|
|
258
|
-
} catch (error) {
|
|
259
|
-
console.log(error);
|
|
260
|
-
}
|
|
117
|
+
addInboxListener(props) {
|
|
118
|
+
// Create the initial listeners
|
|
119
|
+
const inboxListener = new CourierInboxListener();
|
|
120
|
+
if (props.onInitialLoad) {
|
|
121
|
+
inboxListener.onInitialLoad = CourierEventEmitter.addListener('inboxInitialLoad', () => {
|
|
122
|
+
props.onInitialLoad();
|
|
261
123
|
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
onPushNotificationClicked(JSON.parse(event));
|
|
269
|
-
} catch (error) {
|
|
270
|
-
console.log(error);
|
|
271
|
-
}
|
|
124
|
+
}
|
|
125
|
+
if (props.onError) {
|
|
126
|
+
inboxListener.onError = CourierEventEmitter.addListener('inboxError', event => {
|
|
127
|
+
console.log(event);
|
|
128
|
+
props.onError();
|
|
272
129
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
130
|
+
}
|
|
131
|
+
if (props.onMessagesChanged) {
|
|
132
|
+
inboxListener.onMessagesChanged = CourierEventEmitter.addListener('inboxMessagesChanged', event => {
|
|
133
|
+
console.log('onMessagesChanged');
|
|
134
|
+
console.log(event);
|
|
135
|
+
props.onMessagesChanged(event.messages);
|
|
279
136
|
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
|
|
287
|
-
return () => {
|
|
288
|
-
notificationClickedListener.remove();
|
|
289
|
-
notificationDeliveredListener.remove();
|
|
290
|
-
};
|
|
137
|
+
}
|
|
138
|
+
inboxListener.listenerId = CourierReactNativeModules.addInboxListener(null);
|
|
139
|
+
return inboxListener;
|
|
140
|
+
}
|
|
141
|
+
removeInboxListener(props) {
|
|
142
|
+
return CourierReactNativeModules.removeInboxListener(props.listenerId);
|
|
291
143
|
}
|
|
292
|
-
|
|
293
144
|
}
|
|
294
|
-
|
|
295
145
|
export default new Courier();
|
|
296
146
|
//# sourceMappingURL=index.js.map
|
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","debugListener","remove","addListener","event","_isDebugging","setDebugMode","userId","getUserId","signIn","accessToken","signOut","apnsToken","OS","resolve","undefined","getApnsToken","fcmToken","getFcmToken","setFcmToken","token","sendPush","authKey","title","body","providers","notificationPermissionStatus","getNotificationPermissionStatus","requestNotificationPermission","normalizedParams","Array","from","Set","registerPushNotificationListeners","onPushNotificationClicked","onPushNotificationDelivered","notificationClickedListener","notificationDeliveredListener","PUSH_NOTIFICATION_CLICKED","JSON","parse","PUSH_NOTIFICATION_DELIVERED","registerPushNotificationClickedOnKilledState"],"sources":["index.ts"],"sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint class-methods-use-this: 0 */\nimport {\n NativeModules,\n Platform,\n DeviceEventEmitter,\n NativeEventEmitter,\n EmitterSubscription,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \\n\\n${Platform.select(\n { ios: \"- You have run 'pod install'\\n\", default: '' }\n )}- You rebuilt the app after installing the package\\n` +\n `- You are not using Expo managed workflow\\n`;\n\nconst CourierReactNativeModules = NativeModules.CourierReactNative\n ? NativeModules.CourierReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nconst CourierEventEmitter = new NativeEventEmitter(\n NativeModules.CourierReactNative\n);\n\nexport enum CourierProvider {\n FCM = 'firebase-fcm',\n APNS = 'apn',\n}\n\nclass Courier {\n readonly PUSH_NOTIFICATION_CLICKED = 'pushNotificationClicked';\n\n readonly PUSH_NOTIFICATION_DELIVERED = 'pushNotificationDelivered';\n\n public constructor() {\n // Sets the initial SDK values\n // Defaults to React Native level debugging\n // and will show all foreground notification styles in iOS\n this.setDefaults();\n }\n\n private async setDefaults() {\n try {\n await Promise.all([\n this.setIsDebugging(__DEV__),\n this.iOSForegroundPresentationOptions({\n options: ['sound', 'badge', 'list', 'banner'],\n }),\n ]);\n } catch (error) {\n console.log(error);\n }\n }\n\n private _isDebugging = false;\n\n private debugListener: EmitterSubscription | undefined;\n\n /**\n * Tells native Courier SDKs to show or hide logs.\n * Defaults to the React __DEV__ mode\n * @example Courier.setIsDebugging(true)\n */\n public async setIsDebugging(isDebugging: boolean): Promise<boolean> {\n // Remove the existing listener if needed\n this.debugListener?.remove();\n\n // Set a new listener\n // listener needs to be registered first to catch the event\n if (isDebugging) {\n this.debugListener = CourierEventEmitter.addListener(\n 'courierDebugEvent',\n (event) => {\n console.log('\\x1b[36m%s\\x1b[0m', 'COURIER', event);\n }\n );\n }\n\n this._isDebugging = await CourierReactNativeModules.setDebugMode(\n isDebugging\n );\n\n return this._isDebugging;\n }\n\n get isDebugging(): boolean {\n return this._isDebugging;\n }\n\n /**\n * Returns the current user id stored in local native storage\n * @example const userId = await Courier.userId\n */\n get userId(): Promise<string | undefined> {\n return CourierReactNativeModules.getUserId();\n }\n\n /**\n * Signs user in and persists signin in between sessions\n * using native level storage apis\n * \n * @example\n * ```\n *await Courier.signIn({\n accessToken: YOUR_COURIER_GENERATED_JWT,\n userId: YOUR_USER_ID,\n })\n * ```\n * Your access token should be generated using this endpoint\n * that is requested from your backend\n * https://www.courier.com/docs/reference/auth/issue-token/\n */\n public signIn({\n accessToken,\n userId,\n }: {\n accessToken: string;\n userId: string;\n }): Promise<void> {\n return CourierReactNativeModules.signIn(userId, accessToken);\n }\n\n /**\n * Logs user out of native level user storage.\n * This will clear the userId, accessToken, and apns / fcm tokens and\n * delete the matching devices apns / fcm tokens for the user in Courier token management\n * @example await Courier.signOut()\n */\n public signOut(): Promise<void> {\n return CourierReactNativeModules.signOut();\n }\n\n /**\n * Sets the current Apple Push Notification Service (APNS) token\n * using Courier token management apis\n * @example const apnsToken = await Courier.apnsToken\n */\n get apnsToken(): Promise<string | undefined> {\n if (Platform.OS !== 'ios') return Promise.resolve(undefined);\n return CourierReactNativeModules.getApnsToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example const fcmToken = await Courier.fcmToken\n */\n get fcmToken(): Promise<string | undefined> {\n return CourierReactNativeModules.getFcmToken();\n }\n\n /**\n * Sets the current Firebase Cloud Messaging (FCM) token\n * using Courier token management apis\n * @example await setFcmToken('asdf...asdf')\n */\n public setFcmToken(token: string): Promise<void> {\n return CourierReactNativeModules.setFcmToken(token);\n }\n\n /**\n * Hits the Courier /send endpoint and sends a test push notification\n * @example\n * ```\n *const messageId = await sendPush({\n authKey: YOUR_AUTH_KEY_THAT_SHOULD_NOT_STAY_IN_YOUR_PRODUCTION_APP,\n userId: USER_ID,\n title: 'This is a title',\n body: 'This is a body',\n providers: [CourierProvider.APNS, CourierProvider.FCM],\n });\n * ```\n * @returns promise\n */\n public sendPush({\n authKey,\n userId,\n title,\n body,\n providers,\n }: {\n authKey: string;\n userId: string;\n title?: string;\n body?: string;\n providers: CourierProvider[];\n }): Promise<string> {\n return CourierReactNativeModules.sendPush(\n authKey,\n userId,\n title,\n body,\n providers\n );\n }\n\n /**\n * Gets notification permission status at a system level.\n * @example const permissionStatus = await Courier.getNotificationPermissionStatus()\n */\n get notificationPermissionStatus(): Promise<string> {\n return CourierReactNativeModules.getNotificationPermissionStatus();\n }\n\n /**\n * Requests notification permission status at a system level.\n * Returns the string associated with the permission status.\n * Will return the current status and will not present a popup\n * if the user has already been asked for permission.\n * @example const permissionStatus = await Courier.requestNotificationPermission()\n */\n public requestNotificationPermission(): Promise<string> {\n return CourierReactNativeModules.requestNotificationPermission();\n }\n\n /**\n * Sets the push notification presentation style when the app is in the foreground\n * This does not affect how the notification is shown when the app is killed or in the background states\n *\n * Defaults to sound, badge, list and/or banner.\n *\n * @example iOSForegroundPresentationOptions({options: ['sound']});\n */\n public iOSForegroundPresentationOptions({\n options,\n }: {\n options: ('sound' | 'badge' | 'list' | 'banner')[];\n }): Promise<void> {\n // Only works on iOS\n if (Platform.OS !== 'ios') return Promise.resolve();\n\n const normalizedParams = Array.from(new Set(options));\n return CourierReactNativeModules.iOSForegroundPresentationOptions({\n options: normalizedParams,\n });\n }\n\n /**\n * @example \n *```\n const unsubPushListeners = () => {\n return Courier.registerPushNotificationListeners<YOUR_NOTIFICATION_TYPE>({\n onPushNotificationClicked: (push) => {\n ...\n },\n onPushNotificationDelivered: (push) => {\n ...\n },\n })\n }\n\n // To unsubscribe the listeners\n unsubPushListeners()\n *```\n * @returns function that can be used to unsubscribe from registered listeners\n */\n public registerPushNotificationListeners({\n onPushNotificationClicked,\n onPushNotificationDelivered,\n }: {\n onPushNotificationClicked: (_push: any) => void;\n onPushNotificationDelivered: (_push: any) => void;\n }) {\n let notificationClickedListener: EmitterSubscription;\n let notificationDeliveredListener: EmitterSubscription;\n\n // Android\n if (Platform.OS === 'android') {\n notificationClickedListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = DeviceEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // iOS\n if (Platform.OS === 'ios') {\n notificationClickedListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_CLICKED,\n (event: any) => {\n try {\n onPushNotificationClicked(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n\n notificationDeliveredListener = CourierEventEmitter.addListener(\n this.PUSH_NOTIFICATION_DELIVERED,\n (event: any) => {\n try {\n onPushNotificationDelivered(JSON.parse(event));\n } catch (error) {\n console.log(error);\n }\n }\n );\n }\n\n // When listener is registered\n // Attempt to fetch the last message that was clicked\n // This is needed for when the app is killed and the\n // user launched the app by clicking on a notifications\n CourierReactNativeModules.registerPushNotificationClickedOnKilledState();\n\n return () => {\n notificationClickedListener.remove();\n notificationDeliveredListener.remove();\n };\n }\n}\n\nexport default new Courier();\n"],"mappings":";;AAAA;;AACA;AACA,SACEA,aADF,EAEEC,QAFF,EAGEC,kBAHF,EAIEC,kBAJF,QAMO,cANP;AAQA,MAAMC,aAAa,GAChB,4FAA2FH,QAAQ,CAACI,MAAT,CAC1F;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAD0F,CAE1F,sDAFF,GAGC,6CAJH;AAMA,MAAMC,yBAAyB,GAAGR,aAAa,CAACS,kBAAd,GAC9BT,aAAa,CAACS,kBADgB,GAE9B,IAAIC,KAAJ,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P,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR6B,CAAhC;IAUD,CA3BA,CA6BD;;;IACA,IAAIvB,QAAQ,CAACuC,EAAT,KAAgB,KAApB,EAA2B;MACzBuB,2BAA2B,GAAGlD,mBAAmB,CAACiB,WAApB,CAC5B,KAAKmC,yBADuB,EAE3BlC,KAAD,IAAgB;QACd,IAAI;UACF8B,yBAAyB,CAACK,IAAI,CAACC,KAAL,CAAWpC,KAAX,CAAD,CAAzB;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR2B,CAA9B;MAWAwC,6BAA6B,GAAGnD,mBAAmB,CAACiB,WAApB,CAC9B,KAAKsC,2BADyB,EAE7BrC,KAAD,IAAgB;QACd,IAAI;UACF+B,2BAA2B,CAACI,IAAI,CAACC,KAAL,CAAWpC,KAAX,CAAD,CAA3B;QACD,CAFD,CAEE,OAAOP,KAAP,EAAc;UACdC,OAAO,CAACC,GAAR,CAAYF,KAAZ;QACD;MACF,CAR6B,CAAhC;IAUD,CApDA,CAsDD;IACA;IACA;IACA;;;IACAhB,yBAAyB,CAAC6D,4CAA1B;IAEA,OAAO,MAAM;MACXN,2BAA2B,CAAClC,MAA5B;MACAmC,6BAA6B,CAACnC,MAA9B;IACD,CAHD;EAID;;AAzSW;;AA4Sd,eAAe,IAAId,OAAJ,EAAf"}
|
|
1
|
+
{"version":3,"names":["NativeModules","NativeEventEmitter","Platform","CourierInboxListener","CourierInboxView","LINKING_ERROR","select","ios","default","CourierReactNativeModules","CourierReactNativeModule","Proxy","get","Error","CourierEventEmitter","Courier","constructor","setDefaults","Promise","all","setIsDebugging","__DEV__","error","console","log","_isDebugging","isDebugging","_this$debugListener","debugListener","remove","addListener","event","setDebugMode","userId","getUserId","signIn","props","accessToken","clientKey","readMessage","messageId","unreadMessage","readAllInboxMessages","addInboxListener","inboxListener","onInitialLoad","onError","onMessagesChanged","messages","listenerId","removeInboxListener"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SACEA,aAAa,EACbC,kBAAkB,EAElBC,QAAQ,QACH,cAAc;AACrB,SAASC,oBAAoB,QAAQ,+BAA+B;AAGpE,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,MAAMC,aAAa,GAChB,+EAA8E,GAC/EH,QAAQ,CAACI,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,yBAAyB,GAAGT,aAAa,CAACU,wBAAwB,GACpEV,aAAa,CAACU,wBAAwB,GACtC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACR,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,MAAMS,mBAAmB,GAAG,IAAIb,kBAAkB,CAChDD,aAAa,CAACU,wBAChB,CAAC;AAED,MAAMK,OAAO,CAAC;EAELC,WAAWA,CAAA,EAAG;IAEnB;IACA;IACA;IACA,IAAI,CAACC,WAAW,CAAC,CAAC;EACpB;EAEA,MAAcA,WAAWA,CAAA,EAAG;IAC1B,IAAI;MACF,MAAMC,OAAO,CAACC,GAAG,CAAC,CAChB,IAAI,CAACC,cAAc,CAACC,OAAO;MAC3B;MACA;MACA;MAAA,CACD,CAAC;IACJ,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACC,GAAG,CAACF,KAAK,CAAC;IACpB;EACF;EAEQG,YAAY,GAAG,KAAK;EAI5B;AACF;AACA;AACA;AACA;EACE,MAAaL,cAAcA,CAACM,WAAoB,EAAoB;IAAA,IAAAC,mBAAA;IAElE;IACA,CAAAA,mBAAA,OAAI,CAACC,aAAa,cAAAD,mBAAA,uBAAlBA,mBAAA,CAAoBE,MAAM,CAAC,CAAC;;IAE5B;IACA;IACA,IAAIH,WAA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C,CAAC;IAEhD,IAAIiC,KAAK,CAACS,aAAa,EAAE;MACvBD,aAAa,CAACC,aAAa,GAAG/B,mBAAmB,CAACgB,WAAW,CAAC,kBAAkB,EAAE,MAAM;QACtFM,KAAK,CAACS,aAAa,CAAE,CAAC;MACxB,CAAC,CAAC;IACJ;IAEA,IAAIT,KAAK,CAACU,OAAO,EAAE;MACjBF,aAAa,CAACE,OAAO,GAAGhC,mBAAmB,CAACgB,WAAW,CAAC,YAAY,EAAEC,KAAK,IAAI;QAC7ER,OAAO,CAACC,GAAG,CAACO,KAAK,CAAC;QAClBK,KAAK,CAACU,OAAO,CAAE,CAAC;MAClB,CAAC,CAAC;IACJ;IAEA,IAAIV,KAAK,CAACW,iBAAiB,EAAE;MAC3BH,aAAa,CAACG,iBAAiB,GAAGjC,mBAAmB,CAACgB,WAAW,CAAC,sBAAsB,EAAEC,KAAK,IAAI;QACjGR,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;QAChCD,OAAO,CAACC,GAAG,CAACO,KAAK,CAAC;QAClBK,KAAK,CAACW,iBAAiB,CACrBhB,KAAK,CAACiB,QACR,CAAC;MACH,CAAC,CAAC;IACJ;IAEAJ,aAAa,CAACK,UAAU,GAAGxC,yBAAyB,CAACkC,gBAAgB,CAAC,IAAI,CAAC;IAE3E,OAAOC,aAAa;EAEtB;EAEOM,mBAAmBA,CAACd,KAA6B,EAAU;IAChE,OAAO3B,yBAAyB,CAACyC,mBAAmB,CAACd,KAAK,CAACa,UAAU,CAAC;EACxE;AAEF;AAEA,eAAe,IAAIlC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Courier from 'courier-react-native';
|
|
2
|
+
export class CourierInboxListener {
|
|
3
|
+
remove() {
|
|
4
|
+
var _this$onInitialLoad, _this$onError, _this$onMessagesChang;
|
|
5
|
+
// Remove the native inbox listener
|
|
6
|
+
if (this.listenerId) {
|
|
7
|
+
Courier.removeInboxListener({
|
|
8
|
+
listenerId: this.listenerId
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Remove the emitters
|
|
13
|
+
(_this$onInitialLoad = this.onInitialLoad) === null || _this$onInitialLoad === void 0 ? void 0 : _this$onInitialLoad.remove();
|
|
14
|
+
(_this$onError = this.onError) === null || _this$onError === void 0 ? void 0 : _this$onError.remove();
|
|
15
|
+
(_this$onMessagesChang = this.onMessagesChanged) === null || _this$onMessagesChang === void 0 ? void 0 : _this$onMessagesChang.remove();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=CourierInboxListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Courier","CourierInboxListener","remove","_this$onInitialLoad","_this$onError","_this$onMessagesChang","listenerId","removeInboxListener","onInitialLoad","onError","onMessagesChanged"],"sourceRoot":"../../../src","sources":["models/CourierInboxListener.tsx"],"mappings":"AACA,OAAOA,OAAO,MAAM,sBAAsB;AAE1C,OAAO,MAAMC,oBAAoB,CAAC;EAOzBC,MAAMA,CAAA,EAAG;IAAA,IAAAC,mBAAA,EAAAC,aAAA,EAAAC,qBAAA;IAEd;IACA,IAAI,IAAI,CAACC,UAAU,EAAE;MACnBN,OAAO,CAACO,mBAAmB,CAAC;QAAED,UAAU,EAAE,IAAI,CAACA;MAAW,CAAC,CAAC;IAC9D;;IAEA;IACA,CAAAH,mBAAA,OAAI,CAACK,aAAa,cAAAL,mBAAA,uBAAlBA,mBAAA,CAAoBD,MAAM,CAAC,CAAC;IAC5B,CAAAE,aAAA,OAAI,CAACK,OAAO,cAAAL,aAAA,uBAAZA,aAAA,CAAcF,MAAM,CAAC,CAAC;IACtB,CAAAG,qBAAA,OAAI,CAACK,iBAAiB,cAAAL,qBAAA,uBAAtBA,qBAAA,CAAwBH,MAAM,CAAC,CAAC;EAElC;AAEF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["models/CourierInboxTheme.tsx"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["models/InboxAction.tsx"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["models/InboxMessage.tsx"],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Platform, requireNativeComponent, UIManager } from "react-native";
|
|
3
|
+
const ComponentName = 'CourierReactNativeView';
|
|
4
|
+
const LINKING_ERROR = `The package 'courier-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
5
|
+
ios: "- You have run 'pod install'\n",
|
|
6
|
+
default: ''
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const CourierInbox = UIManager.getViewManagerConfig(ComponentName) != null ? requireNativeComponent(ComponentName) : () => {
|
|
9
|
+
throw new Error(LINKING_ERROR);
|
|
10
|
+
};
|
|
11
|
+
export const CourierInboxView = props => {
|
|
12
|
+
const onClickInboxMessageAtIndex = event => {
|
|
13
|
+
// Parse the native event data
|
|
14
|
+
if (props.onClickInboxMessageAtIndex) {
|
|
15
|
+
const index = event.nativeEvent["index"];
|
|
16
|
+
const message = event.nativeEvent["message"];
|
|
17
|
+
props.onClickInboxMessageAtIndex(message, index);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const onClickInboxActionForMessageAtIndex = event => {
|
|
21
|
+
// Parse the native event data
|
|
22
|
+
if (props.onClickInboxActionForMessageAtIndex) {
|
|
23
|
+
const index = event.nativeEvent["index"];
|
|
24
|
+
const action = event.nativeEvent["action"];
|
|
25
|
+
const message = event.nativeEvent["message"];
|
|
26
|
+
props.onClickInboxActionForMessageAtIndex(action, message, index);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const onScrollInbox = event => {
|
|
30
|
+
// Parse the native event data
|
|
31
|
+
if (props.onScrollInbox) {
|
|
32
|
+
const contentOffset = event.nativeEvent["contentOffset"];
|
|
33
|
+
props.onScrollInbox(contentOffset["y"], contentOffset["x"]);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/React.createElement(CourierInbox, {
|
|
37
|
+
lightTheme: props.lightTheme,
|
|
38
|
+
darkTheme: props.darkTheme,
|
|
39
|
+
onClickInboxMessageAtIndex: onClickInboxMessageAtIndex,
|
|
40
|
+
onClickInboxActionForMessageAtIndex: onClickInboxActionForMessageAtIndex,
|
|
41
|
+
onScrollInbox: onScrollInbox,
|
|
42
|
+
style: props.style
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=CourierInboxView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Platform","requireNativeComponent","UIManager","ComponentName","LINKING_ERROR","select","ios","default","CourierInbox","getViewManagerConfig","Error","CourierInboxView","props","onClickInboxMessageAtIndex","event","index","nativeEvent","message","onClickInboxActionForMessageAtIndex","action","onScrollInbox","contentOffset","createElement","lightTheme","darkTheme","style"],"sourceRoot":"../../../src","sources":["views/CourierInboxView.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,EAAEC,sBAAsB,EAAEC,SAAS,QAAmB,cAAc;AAcrF,MAAMC,aAAa,GAAG,wBAAwB;AAE9C,MAAMC,aAAa,GAChB,+EAA8E,GAC/EJ,QAAQ,CAACK,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,YAAY,GAChBN,SAAS,CAACO,oBAAoB,CAACN,aAAa,CAAC,IAAI,IAAI,GACjDF,sBAAsB,CAAwBE,aAAa,CAAC,GAC5D,MAAM;EACJ,MAAM,IAAIO,KAAK,CAACN,aAAa,CAAC;AAChC,CAAC;AAEP,OAA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AGN,CAAC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
import { CourierInboxListener } from './models/CourierInboxListener';
|
|
2
|
+
import { InboxMessage } from './models/InboxMessage';
|
|
3
|
+
export { CourierInboxView } from './views/CourierInboxView';
|
|
5
4
|
declare class Courier {
|
|
6
|
-
readonly PUSH_NOTIFICATION_CLICKED = "pushNotificationClicked";
|
|
7
|
-
readonly PUSH_NOTIFICATION_DELIVERED = "pushNotificationDelivered";
|
|
8
5
|
constructor();
|
|
9
6
|
private setDefaults;
|
|
10
7
|
private _isDebugging;
|
|
@@ -29,6 +26,7 @@ declare class Courier {
|
|
|
29
26
|
* ```
|
|
30
27
|
*await Courier.signIn({
|
|
31
28
|
accessToken: YOUR_COURIER_GENERATED_JWT,
|
|
29
|
+
clientKey: YOUR_CLIENT_KEY,
|
|
32
30
|
userId: YOUR_USER_ID,
|
|
33
31
|
})
|
|
34
32
|
* ```
|
|
@@ -36,103 +34,47 @@ declare class Courier {
|
|
|
36
34
|
* that is requested from your backend
|
|
37
35
|
* https://www.courier.com/docs/reference/auth/issue-token/
|
|
38
36
|
*/
|
|
39
|
-
signIn(
|
|
37
|
+
signIn(props: {
|
|
40
38
|
accessToken: string;
|
|
39
|
+
clientKey?: string;
|
|
41
40
|
userId: string;
|
|
42
41
|
}): Promise<void>;
|
|
43
42
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
|
43
|
+
* TODO
|
|
44
|
+
* @param props
|
|
45
|
+
* @returns
|
|
60
46
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
});
|
|
79
|
-
* ```
|
|
80
|
-
* @returns promise
|
|
81
|
-
*/
|
|
82
|
-
sendPush({ authKey, userId, title, body, providers, }: {
|
|
83
|
-
authKey: string;
|
|
84
|
-
userId: string;
|
|
85
|
-
title?: string;
|
|
86
|
-
body?: string;
|
|
87
|
-
providers: CourierProvider[];
|
|
88
|
-
}): Promise<string>;
|
|
47
|
+
readMessage(props: {
|
|
48
|
+
messageId: string;
|
|
49
|
+
}): Promise<void>;
|
|
89
50
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
51
|
+
* TODO
|
|
52
|
+
* @param props
|
|
53
|
+
* @returns
|
|
92
54
|
*/
|
|
93
|
-
|
|
55
|
+
unreadMessage(props: {
|
|
56
|
+
messageId: string;
|
|
57
|
+
}): Promise<void>;
|
|
94
58
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* if the user has already been asked for permission.
|
|
99
|
-
* @example const permissionStatus = await Courier.requestNotificationPermission()
|
|
59
|
+
* TODO
|
|
60
|
+
* @param props
|
|
61
|
+
* @returns
|
|
100
62
|
*/
|
|
101
|
-
|
|
63
|
+
readAllInboxMessages(): Promise<void>;
|
|
102
64
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* Defaults to sound, badge, list and/or banner.
|
|
107
|
-
*
|
|
108
|
-
* @example iOSForegroundPresentationOptions({options: ['sound']});
|
|
65
|
+
* TODO
|
|
66
|
+
* @param props
|
|
67
|
+
* @returns
|
|
109
68
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
onPushNotificationClicked: (push) => {
|
|
119
|
-
...
|
|
120
|
-
},
|
|
121
|
-
onPushNotificationDelivered: (push) => {
|
|
122
|
-
...
|
|
123
|
-
},
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// To unsubscribe the listeners
|
|
128
|
-
unsubPushListeners()
|
|
129
|
-
*```
|
|
130
|
-
* @returns function that can be used to unsubscribe from registered listeners
|
|
131
|
-
*/
|
|
132
|
-
registerPushNotificationListeners({ onPushNotificationClicked, onPushNotificationDelivered, }: {
|
|
133
|
-
onPushNotificationClicked: (_push: any) => void;
|
|
134
|
-
onPushNotificationDelivered: (_push: any) => void;
|
|
135
|
-
}): () => void;
|
|
69
|
+
addInboxListener(props: {
|
|
70
|
+
onInitialLoad: () => void;
|
|
71
|
+
onError: () => void;
|
|
72
|
+
onMessagesChanged: (messages: InboxMessage[]) => void;
|
|
73
|
+
}): CourierInboxListener;
|
|
74
|
+
removeInboxListener(props: {
|
|
75
|
+
listenerId: string;
|
|
76
|
+
}): string;
|
|
136
77
|
}
|
|
137
78
|
declare const _default: Courier;
|
|
138
79
|
export default _default;
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|