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

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 +53 -0
  15. package/ios/{CourierReactNative.swift → CourierReactNativeModule.swift} +178 -45
  16. package/ios/CourierReactNativeViewManager.m +15 -0
  17. package/ios/CourierReactNativeViewManager.swift +348 -0
  18. package/lib/commonjs/index.js +86 -210
  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 +80 -209
  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 +46 -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 +213 -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.tsx ADDED
@@ -0,0 +1,213 @@
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EmitterSubscription,
5
+ Platform,
6
+ } from 'react-native';
7
+
8
+ import { CourierInboxListener } from './models/CourierInboxListener';
9
+ import { InboxMessage } from './models/InboxMessage';
10
+ export { CourierInboxView } from './views/CourierInboxView';
11
+
12
+ const LINKING_ERROR =
13
+ `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
14
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
15
+ '- You rebuilt the app after installing the package\n' +
16
+ '- You are not using Expo Go\n';
17
+
18
+ const CourierReactNativeModules = NativeModules.CourierReactNativeModule
19
+ ? NativeModules.CourierReactNativeModule
20
+ : new Proxy(
21
+ {},
22
+ {
23
+ get() {
24
+ throw new Error(LINKING_ERROR);
25
+ },
26
+ }
27
+ );
28
+
29
+ const CourierEventEmitter = new NativeEventEmitter(
30
+ NativeModules.CourierReactNativeModule
31
+ );
32
+
33
+ class Courier {
34
+
35
+ private static _sharedInstance: Courier;
36
+ private _isDebugging = false;
37
+ private debugListener: EmitterSubscription | undefined;
38
+
39
+ public constructor() {
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
+ // Returns the public shared instance
48
+ public static get shared(): Courier {
49
+
50
+ if (!this._sharedInstance) {
51
+ this._sharedInstance = new Courier();
52
+ }
53
+
54
+ return this._sharedInstance;
55
+
56
+ }
57
+
58
+ private async setDefaults() {
59
+ try {
60
+ await Promise.all([
61
+ this.setIsDebugging(__DEV__),
62
+ // this.iOSForegroundPresentationOptions({
63
+ // options: ['sound', 'badge', 'list', 'banner'],
64
+ // }),
65
+ ]);
66
+ } catch (error) {
67
+ console.log(error);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Tells native Courier SDKs to show or hide logs.
73
+ * Defaults to the React __DEV__ mode
74
+ * @example Courier.setIsDebugging(true)
75
+ */
76
+ public async setIsDebugging(isDebugging: boolean): Promise<boolean> {
77
+
78
+ // Remove the existing listener if needed
79
+ this.debugListener?.remove();
80
+
81
+ // Set a new listener
82
+ // listener needs to be registered first to catch the event
83
+ if (isDebugging) {
84
+ this.debugListener = CourierEventEmitter.addListener('courierDebugEvent', event => {
85
+ console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
86
+ });
87
+ }
88
+
89
+ this._isDebugging = await CourierReactNativeModules.setDebugMode(isDebugging);
90
+
91
+ return this._isDebugging;
92
+
93
+ }
94
+
95
+ get isDebugging(): boolean {
96
+ return this._isDebugging;
97
+ }
98
+
99
+ /**
100
+ * Returns the current user id stored in local native storage
101
+ * @example const userId = await Courier.userId
102
+ */
103
+ get userId(): Promise<string | undefined> {
104
+ return CourierReactNativeModules.getUserId();
105
+ }
106
+
107
+ /**
108
+ * Signs user in and persists signin in between sessions
109
+ * using native level storage apis
110
+ *
111
+ * @example
112
+ * ```
113
+ *await Courier.signIn({
114
+ accessToken: YOUR_COURIER_GENERATED_JWT,
115
+ clientKey: YOUR_CLIENT_KEY,
116
+ userId: YOUR_USER_ID,
117
+ })
118
+ * ```
119
+ * Your access token should be generated using this endpoint
120
+ * that is requested from your backend
121
+ * https://www.courier.com/docs/reference/auth/issue-token/
122
+ */
123
+ public signIn(props: { accessToken: string, clientKey?: string, userId: string }): Promise<void> {
124
+ return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId);
125
+ }
126
+
127
+ /**
128
+ * TODO
129
+ * @param props
130
+ * @returns
131
+ */
132
+ public readMessage(props: { messageId: string }): Promise<void> {
133
+ return CourierReactNativeModules.readMessage(props.messageId);
134
+ }
135
+
136
+ /**
137
+ * TODO
138
+ * @param props
139
+ * @returns
140
+ */
141
+ public unreadMessage(props: { messageId: string }): Promise<void> {
142
+ return CourierReactNativeModules.unreadMessage(props.messageId);
143
+ }
144
+
145
+ /**
146
+ * TODO
147
+ * @param props
148
+ * @returns
149
+ */
150
+ public readAllInboxMessages(): Promise<void> {
151
+ return CourierReactNativeModules.readAllInboxMessages();
152
+ }
153
+
154
+ /**
155
+ * TODO
156
+ * @param props
157
+ * @returns
158
+ */
159
+ public addInboxListener(props: { onInitialLoad?: () => void, onError?: (error: string) => void, onMessagesChanged?: (messages: InboxMessage[], unreadMessageCount: number, totalMessageCount: number, canPaginate: boolean) => void }): CourierInboxListener {
160
+
161
+ // Create the initial listeners
162
+ const inboxListener = new CourierInboxListener();
163
+
164
+ if (props.onInitialLoad) {
165
+ inboxListener.onInitialLoad = CourierEventEmitter.addListener('inboxInitialLoad', () => {
166
+ props.onInitialLoad!()
167
+ });
168
+ }
169
+
170
+ if (props.onError) {
171
+ inboxListener.onError = CourierEventEmitter.addListener('inboxError', event => {
172
+ props.onError!(event)
173
+ });
174
+ }
175
+
176
+ if (props.onMessagesChanged) {
177
+ inboxListener.onMessagesChanged = CourierEventEmitter.addListener('inboxMessagesChanged', event => {
178
+ props.onMessagesChanged!(
179
+ event.messages,
180
+ event.unreadMessageCount,
181
+ event.totalMessageCount,
182
+ event.canPaginate,
183
+ )
184
+ });
185
+ }
186
+
187
+ inboxListener.listenerId = CourierReactNativeModules.addInboxListener(null);
188
+
189
+ return inboxListener;
190
+
191
+ }
192
+
193
+ /**
194
+ * TODO
195
+ * @param props
196
+ * @returns
197
+ */
198
+ public removeInboxListener(props: { listenerId: string }): string {
199
+ return CourierReactNativeModules.removeInboxListener(props.listenerId);
200
+ }
201
+
202
+ /**
203
+ * TODO
204
+ * @param props
205
+ * @returns
206
+ */
207
+ public async refreshInbox(): Promise<void> {
208
+ return CourierReactNativeModules.refreshInbox();
209
+ }
210
+
211
+ }
212
+
213
+ export default Courier;
@@ -0,0 +1,25 @@
1
+ import { EmitterSubscription } from "react-native";
2
+ import Courier from "@trycourier/courier-react-native";
3
+
4
+ export class CourierInboxListener {
5
+
6
+ public listenerId?: string
7
+ public onInitialLoad?: EmitterSubscription
8
+ public onError?: EmitterSubscription
9
+ public onMessagesChanged?: EmitterSubscription
10
+
11
+ public remove() {
12
+
13
+ // Remove the native inbox listener
14
+ if (this.listenerId) {
15
+ Courier.shared.removeInboxListener({ listenerId: this.listenerId });
16
+ }
17
+
18
+ // Remove the emitters
19
+ this.onInitialLoad?.remove();
20
+ this.onError?.remove();
21
+ this.onMessagesChanged?.remove();
22
+
23
+ }
24
+
25
+ }
@@ -0,0 +1,30 @@
1
+ export interface CourierInboxFont {
2
+ family?: string
3
+ size?: number
4
+ color?: string
5
+ }
6
+
7
+ export interface CourierInboxButtonStyles {
8
+ font?: CourierInboxFont
9
+ backgroundColor?: string
10
+ cornerRadius?: number
11
+ }
12
+
13
+ export default interface CourierInboxTheme {
14
+ unreadIndicatorBarColor?: string
15
+ loadingIndicatorColor?: string
16
+ titleFont?: CourierInboxFont
17
+ timeFont?: CourierInboxFont
18
+ bodyFont?: CourierInboxFont
19
+ detailTitleFont?: CourierInboxFont
20
+ buttonStyles?: CourierInboxButtonStyles
21
+ iOS?: {
22
+ messageAnimationStyle?: 'fade' | 'right' | 'left' | 'top' | 'bottom' | 'none' | 'middle' | 'automatic',
23
+ cellStyles?: {
24
+ separatorStyle?: 'none' | 'singleLine' | 'singleLineEtched',
25
+ separatorInsets?: { top?: number, left?: number, bottom?: number, right?: number },
26
+ separatorColor?: string,
27
+ selectionStyle?: 'none' | 'blue' | 'gray' | 'default'
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,5 @@
1
+ export interface InboxAction {
2
+ content?: string | null;
3
+ href?: string | null;
4
+ data?: { [key: string]: any } | null;
5
+ }
@@ -0,0 +1,16 @@
1
+ import { InboxAction } from "./InboxAction";
2
+
3
+ export interface InboxMessage {
4
+ messageId: string;
5
+ title?: string | null;
6
+ body?: string | null;
7
+ preview?: string | null;
8
+ created?: string | null;
9
+ actions?: InboxAction[] | null;
10
+ data?: { [key: string]: any } | null;
11
+ read?: boolean | null;
12
+ opened?: boolean | null;
13
+ archived?: boolean | null
14
+ subtitle?: string | null;
15
+ time?: string;
16
+ }
@@ -0,0 +1,85 @@
1
+ import React from "react";
2
+ import { Platform, requireNativeComponent, UIManager, ViewStyle } from "react-native";
3
+ import CourierInboxTheme from "src/models/CourierInboxTheme";
4
+ import { InboxAction } from "src/models/InboxAction";
5
+ import { InboxMessage } from "src/models/InboxMessage";
6
+
7
+ type CourierInboxViewProps = {
8
+ lightTheme?: CourierInboxTheme;
9
+ darkTheme?: CourierInboxTheme;
10
+ onClickInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
11
+ onClickInboxActionForMessageAtIndex?: (action: InboxAction, message: InboxMessage, index: number) => void;
12
+ onScrollInbox?: (offsetY: number, offsetX: number) => void;
13
+ style?: ViewStyle;
14
+ };
15
+
16
+ const ComponentName = 'CourierReactNativeView';
17
+
18
+ const LINKING_ERROR =
19
+ `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
20
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
21
+ '- You rebuilt the app after installing the package\n' +
22
+ '- You are not using Expo Go\n';
23
+
24
+ const CourierInbox =
25
+ UIManager.getViewManagerConfig(ComponentName) != null
26
+ ? requireNativeComponent<CourierInboxViewProps>(ComponentName)
27
+ : () => {
28
+ throw new Error(LINKING_ERROR);
29
+ };
30
+
31
+ export const CourierInboxView = (props: CourierInboxViewProps) => {
32
+
33
+ const onClickInboxMessageAtIndex = (event: any) => {
34
+
35
+ // Parse the native event data
36
+ if (props.onClickInboxMessageAtIndex) {
37
+
38
+ const index = event.nativeEvent["index"]
39
+ const message = event.nativeEvent["message"] as InboxMessage
40
+
41
+ props.onClickInboxMessageAtIndex(message, index)
42
+
43
+ }
44
+
45
+ }
46
+
47
+ const onClickInboxActionForMessageAtIndex = (event: any) => {
48
+
49
+ // Parse the native event data
50
+ if (props.onClickInboxActionForMessageAtIndex) {
51
+
52
+ const index = event.nativeEvent["index"]
53
+ const action = event.nativeEvent["action"] as InboxAction
54
+ const message = event.nativeEvent["message"] as InboxMessage
55
+
56
+ props.onClickInboxActionForMessageAtIndex(action, message, index)
57
+
58
+ }
59
+
60
+ }
61
+
62
+ const onScrollInbox = (event: any) => {
63
+
64
+ // Parse the native event data
65
+ if (props.onScrollInbox) {
66
+
67
+ const contentOffset = event.nativeEvent["contentOffset"]
68
+ props.onScrollInbox(contentOffset["y"], contentOffset["x"])
69
+
70
+ }
71
+
72
+ }
73
+
74
+ return (
75
+ <CourierInbox
76
+ lightTheme={props.lightTheme}
77
+ darkTheme={props.darkTheme}
78
+ onClickInboxMessageAtIndex={onClickInboxMessageAtIndex}
79
+ onClickInboxActionForMessageAtIndex={onClickInboxActionForMessageAtIndex}
80
+ onScrollInbox={onScrollInbox}
81
+ style={props.style}
82
+ />
83
+ )
84
+
85
+ }
File without changes
@@ -1,2 +0,0 @@
1
- #Thu Oct 27 14:07:59 EDT 2022
2
- gradle.version=7.1
File without changes
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="CompilerConfiguration">
4
- <bytecodeTargetLevel target="11" />
5
- </component>
6
- </project>
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="GradleSettings">
4
- <option name="linkedExternalProjectsSettings">
5
- <GradleProjectSettings>
6
- <option name="testRunner" value="GRADLE" />
7
- <option name="distributionType" value="DEFAULT_WRAPPED" />
8
- <option name="externalProjectPath" value="$PROJECT_DIR$" />
9
- <option name="modules">
10
- <set>
11
- <option value="$PROJECT_DIR$" />
12
- </set>
13
- </option>
14
- </GradleProjectSettings>
15
- </option>
16
- </component>
17
- </project>
@@ -1,35 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="RemoteRepositoriesConfiguration">
4
- <remote-repository>
5
- <option name="id" value="central" />
6
- <option name="name" value="Maven Central repository" />
7
- <option name="url" value="https://repo1.maven.org/maven2" />
8
- </remote-repository>
9
- <remote-repository>
10
- <option name="id" value="jboss.community" />
11
- <option name="name" value="JBoss Community repository" />
12
- <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
13
- </remote-repository>
14
- <remote-repository>
15
- <option name="id" value="MavenRepo" />
16
- <option name="name" value="MavenRepo" />
17
- <option name="url" value="https://repo.maven.apache.org/maven2/" />
18
- </remote-repository>
19
- <remote-repository>
20
- <option name="id" value="React Native sources" />
21
- <option name="name" value="React Native sources" />
22
- <option name="url" value="file:$PROJECT_DIR$/../node_modules/react-native/android/" />
23
- </remote-repository>
24
- <remote-repository>
25
- <option name="id" value="maven" />
26
- <option name="name" value="maven" />
27
- <option name="url" value="https://jitpack.io" />
28
- </remote-repository>
29
- <remote-repository>
30
- <option name="id" value="Google" />
31
- <option name="name" value="Google" />
32
- <option name="url" value="https://dl.google.com/dl/android/maven2/" />
33
- </remote-repository>
34
- </component>
35
- </project>
@@ -1,10 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ExternalStorageConfigurationManager" enabled="true" />
4
- <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
5
- <output url="file://$PROJECT_DIR$/build/classes" />
6
- </component>
7
- <component name="ProjectType">
8
- <option name="id" value="Android" />
9
- </component>
10
- </project>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
- </component>
6
- </project>
@@ -1,5 +0,0 @@
1
- distributionBase=GRADLE_USER_HOME
2
- distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4
- zipStoreBase=GRADLE_USER_HOME
5
- zipStorePath=wrapper/dists