@trycourier/courier-react-native 5.6.17 → 5.7.1

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 (226) hide show
  1. package/README.md +66 -135
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +1 -0
  4. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -0
  5. package/android/src/main/java/com/courierreactnative/CourierPreferencesViewManager.kt +2 -0
  6. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +3 -0
  7. package/android/src/main/java/com/courierreactnative/Utils.kt +11 -1
  8. package/courier-react-native.podspec +1 -1
  9. package/ios/CourierClientModule.swift +1 -0
  10. package/ios/CourierInboxReactNativeManager.swift +8 -0
  11. package/ios/CourierPreferencesReactNativeManager.swift +8 -0
  12. package/ios/CourierReactNativeDelegate.m +1 -1
  13. package/ios/CourierReactNativeEventEmitter.swift +1 -1
  14. package/ios/CourierReactNativeModule.m +1 -0
  15. package/ios/CourierSharedModule.swift +10 -3
  16. package/ios/Utils.swift +10 -0
  17. package/lib/commonjs/Broadcaster.js +5 -5
  18. package/lib/commonjs/Broadcaster.js.map +1 -1
  19. package/lib/commonjs/CourierApiUrls.js +29 -0
  20. package/lib/commonjs/CourierApiUrls.js.map +1 -0
  21. package/lib/commonjs/Modules.js.map +1 -1
  22. package/lib/commonjs/client/BrandClient.js.map +1 -1
  23. package/lib/commonjs/client/ClientModule.js.map +1 -1
  24. package/lib/commonjs/client/CourierClient.js +4 -1
  25. package/lib/commonjs/client/CourierClient.js.map +1 -1
  26. package/lib/commonjs/client/InboxClient.js.map +1 -1
  27. package/lib/commonjs/client/PreferenceClient.js.map +1 -1
  28. package/lib/commonjs/client/TokenClient.js.map +1 -1
  29. package/lib/commonjs/client/TrackingClient.js.map +1 -1
  30. package/lib/commonjs/index.js +22 -2
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  33. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  34. package/lib/commonjs/models/CourierUserPreferences.js +13 -13
  35. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  36. package/lib/commonjs/models/InboxAction.js.map +1 -1
  37. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  38. package/lib/commonjs/utils.js.map +1 -1
  39. package/lib/commonjs/views/CourierInboxView.js +13 -13
  40. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  41. package/lib/commonjs/views/CourierPreferencesView.js +4 -4
  42. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  43. package/lib/module/Broadcaster.js +7 -7
  44. package/lib/module/Broadcaster.js.map +1 -1
  45. package/lib/module/CourierApiUrls.js +20 -0
  46. package/lib/module/CourierApiUrls.js.map +1 -0
  47. package/lib/module/Modules.js +1 -1
  48. package/lib/module/Modules.js.map +1 -1
  49. package/lib/module/client/BrandClient.js +1 -1
  50. package/lib/module/client/BrandClient.js.map +1 -1
  51. package/lib/module/client/ClientModule.js +1 -1
  52. package/lib/module/client/ClientModule.js.map +1 -1
  53. package/lib/module/client/CourierClient.js +10 -7
  54. package/lib/module/client/CourierClient.js.map +1 -1
  55. package/lib/module/client/InboxClient.js +1 -1
  56. package/lib/module/client/InboxClient.js.map +1 -1
  57. package/lib/module/client/PreferenceClient.js +1 -1
  58. package/lib/module/client/PreferenceClient.js.map +1 -1
  59. package/lib/module/client/TokenClient.js +1 -1
  60. package/lib/module/client/TokenClient.js.map +1 -1
  61. package/lib/module/client/TrackingClient.js +1 -1
  62. package/lib/module/client/TrackingClient.js.map +1 -1
  63. package/lib/module/index.js +5 -2
  64. package/lib/module/index.js.map +1 -1
  65. package/lib/module/models/CourierAuthenticationListener.js +1 -1
  66. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  67. package/lib/module/models/CourierInboxListener.js +1 -1
  68. package/lib/module/models/CourierPushListener.js.map +1 -1
  69. package/lib/module/models/CourierUserPreferences.js +13 -13
  70. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  71. package/lib/module/models/InboxAction.js.map +1 -1
  72. package/lib/module/models/InboxMessage.js +1 -1
  73. package/lib/module/models/InboxMessage.js.map +1 -1
  74. package/lib/module/utils.js.map +1 -1
  75. package/lib/module/views/CourierInboxView.js +18 -18
  76. package/lib/module/views/CourierInboxView.js.map +1 -1
  77. package/lib/module/views/CourierPreferencesView.js +7 -7
  78. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  79. package/lib/typescript/src/Broadcaster.d.ts +7 -7
  80. package/lib/typescript/src/Broadcaster.d.ts.map +1 -1
  81. package/lib/typescript/src/CourierApiUrls.d.ts +11 -0
  82. package/lib/typescript/src/CourierApiUrls.d.ts.map +1 -0
  83. package/lib/typescript/src/Modules.d.ts.map +1 -1
  84. package/lib/typescript/src/client/BrandClient.d.ts +1 -1
  85. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -1
  86. package/lib/typescript/src/client/ClientModule.d.ts +1 -1
  87. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -1
  88. package/lib/typescript/src/client/CourierClient.d.ts +9 -6
  89. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -1
  90. package/lib/typescript/src/client/InboxClient.d.ts +1 -1
  91. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -1
  92. package/lib/typescript/src/client/PreferenceClient.d.ts +1 -1
  93. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -1
  94. package/lib/typescript/src/client/TokenClient.d.ts +1 -1
  95. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -1
  96. package/lib/typescript/src/client/TrackingClient.d.ts +1 -1
  97. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -1
  98. package/lib/typescript/src/index.d.ts +6 -2
  99. package/lib/typescript/src/index.d.ts.map +1 -1
  100. package/lib/typescript/src/models/Android_CourierSheet.d.ts +1 -1
  101. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -1
  102. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts +1 -1
  103. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -1
  104. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -1
  105. package/lib/typescript/src/models/CourierButton.d.ts +1 -1
  106. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -1
  107. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -1
  108. package/lib/typescript/src/models/CourierInboxListener.d.ts +1 -1
  109. package/lib/typescript/src/models/CourierInboxMessages.d.ts +1 -1
  110. package/lib/typescript/src/models/CourierInboxTheme.d.ts +4 -3
  111. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -1
  112. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts +2 -2
  113. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -1
  114. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts +7 -6
  115. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -1
  116. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -1
  117. package/lib/typescript/src/models/CourierUserPreferences.d.ts +1 -1
  118. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -1
  119. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
  120. package/lib/typescript/src/models/InboxMessage.d.ts +1 -1
  121. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
  122. package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -1
  123. package/lib/typescript/src/models/InboxMessageSet.d.ts +1 -1
  124. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -1
  125. package/lib/typescript/src/models/iOS_CourierSheet.d.ts +1 -1
  126. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -1
  127. package/lib/typescript/src/utils.d.ts.map +1 -1
  128. package/lib/typescript/src/views/CourierInboxView.d.ts +5 -5
  129. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -1
  130. package/lib/typescript/src/views/CourierPreferencesView.d.ts +3 -3
  131. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -1
  132. package/package.json +8 -4
  133. package/src/Broadcaster.tsx +21 -15
  134. package/src/CourierApiUrls.tsx +30 -0
  135. package/src/Modules.tsx +22 -13
  136. package/src/client/BrandClient.tsx +6 -6
  137. package/src/client/ClientModule.tsx +4 -6
  138. package/src/client/CourierClient.tsx +20 -13
  139. package/src/client/InboxClient.tsx +40 -13
  140. package/src/client/PreferenceClient.tsx +47 -21
  141. package/src/client/TokenClient.tsx +14 -7
  142. package/src/client/TrackingClient.tsx +7 -6
  143. package/src/index.tsx +208 -115
  144. package/src/models/Android_CourierSheet.tsx +5 -5
  145. package/src/models/CourierAuthenticationListener.tsx +5 -9
  146. package/src/models/CourierBrand.tsx +6 -6
  147. package/src/models/CourierButton.tsx +5 -5
  148. package/src/models/CourierDevice.tsx +1 -1
  149. package/src/models/CourierFont.tsx +4 -4
  150. package/src/models/CourierInboxListener.tsx +3 -3
  151. package/src/models/CourierInboxMessages.tsx +2 -2
  152. package/src/models/CourierInboxTheme.tsx +56 -42
  153. package/src/models/CourierInfoViewStyle.tsx +5 -5
  154. package/src/models/CourierPaging.tsx +1 -1
  155. package/src/models/CourierPreferencesTheme.tsx +33 -27
  156. package/src/models/CourierPushListener.tsx +9 -7
  157. package/src/models/CourierPushProvider.tsx +1 -1
  158. package/src/models/CourierTrackingEvent.tsx +6 -6
  159. package/src/models/CourierUserPreferences.tsx +32 -28
  160. package/src/models/InboxAction.tsx +2 -6
  161. package/src/models/InboxMessage.tsx +4 -5
  162. package/src/models/InboxMessageEvent.tsx +7 -1
  163. package/src/models/InboxMessageFeed.tsx +1 -1
  164. package/src/models/InboxMessageSet.tsx +1 -1
  165. package/src/models/iOS_CourierCell.tsx +10 -5
  166. package/src/models/iOS_CourierSheet.tsx +4 -4
  167. package/src/utils.tsx +4 -7
  168. package/src/views/CourierInboxView.tsx +79 -71
  169. package/src/views/CourierPreferencesView.tsx +34 -35
  170. package/lib/example/src/App.js +0 -11
  171. package/lib/example/src/Emitter.js +0 -11
  172. package/lib/example/src/Env.js +0 -6
  173. package/lib/example/src/Home.js +0 -67
  174. package/lib/example/src/Poke.js +0 -75
  175. package/lib/example/src/Tabs.js +0 -36
  176. package/lib/example/src/Utils.js +0 -71
  177. package/lib/example/src/pages/Auth.js +0 -224
  178. package/lib/example/src/pages/Inbox.js +0 -38
  179. package/lib/example/src/pages/Preferences.js +0 -13
  180. package/lib/example/src/pages/PreferencesStack.js +0 -11
  181. package/lib/example/src/pages/Push.js +0 -93
  182. package/lib/example/src/pages/Styles.js +0 -26
  183. package/lib/example/src/pages/Tests.js +0 -1068
  184. package/lib/example/src/pages/inbox/InboxCustom.js +0 -141
  185. package/lib/example/src/pages/inbox/InboxDefault.js +0 -22
  186. package/lib/example/src/pages/inbox/InboxStyled.js +0 -220
  187. package/lib/example/src/pages/preferences/PreferencesCustom.js +0 -91
  188. package/lib/example/src/pages/preferences/PreferencesDefault.js +0 -17
  189. package/lib/example/src/pages/preferences/PreferencesDetail.js +0 -127
  190. package/lib/example/src/pages/preferences/PreferencesStyled.js +0 -110
  191. package/lib/package.json +0 -171
  192. package/lib/src/Broadcaster.js +0 -24
  193. package/lib/src/Modules.js +0 -26
  194. package/lib/src/client/BrandClient.js +0 -17
  195. package/lib/src/client/ClientModule.js +0 -14
  196. package/lib/src/client/CourierClient.js +0 -31
  197. package/lib/src/client/InboxClient.js +0 -99
  198. package/lib/src/client/PreferenceClient.js +0 -63
  199. package/lib/src/client/TokenClient.js +0 -27
  200. package/lib/src/client/TrackingClient.js +0 -17
  201. package/lib/src/index.js +0 -567
  202. package/lib/src/models/Android_CourierSheet.js +0 -1
  203. package/lib/src/models/CourierAuthenticationListener.js +0 -14
  204. package/lib/src/models/CourierBrand.js +0 -1
  205. package/lib/src/models/CourierButton.js +0 -1
  206. package/lib/src/models/CourierDevice.js +0 -1
  207. package/lib/src/models/CourierFont.js +0 -1
  208. package/lib/src/models/CourierInboxListener.js +0 -20
  209. package/lib/src/models/CourierInboxMessages.js +0 -1
  210. package/lib/src/models/CourierInboxTheme.js +0 -1
  211. package/lib/src/models/CourierInfoViewStyle.js +0 -1
  212. package/lib/src/models/CourierPaging.js +0 -1
  213. package/lib/src/models/CourierPreferencesTheme.js +0 -1
  214. package/lib/src/models/CourierPushListener.js +0 -14
  215. package/lib/src/models/CourierPushProvider.js +0 -8
  216. package/lib/src/models/CourierTrackingEvent.js +0 -8
  217. package/lib/src/models/CourierUserPreferences.js +0 -51
  218. package/lib/src/models/InboxAction.js +0 -1
  219. package/lib/src/models/InboxMessage.js +0 -1
  220. package/lib/src/models/InboxMessageFeed.js +0 -1
  221. package/lib/src/models/InboxMessageSet.js +0 -1
  222. package/lib/src/models/iOS_CourierCell.js +0 -1
  223. package/lib/src/models/iOS_CourierSheet.js +0 -1
  224. package/lib/src/utils.js +0 -27
  225. package/lib/src/views/CourierInboxView.js +0 -75
  226. package/lib/src/views/CourierPreferencesView.js +0 -33
package/lib/src/index.js DELETED
@@ -1,567 +0,0 @@
1
- import { Platform, } from 'react-native';
2
- // Imports
3
- import { CourierInboxListener } from './models/CourierInboxListener';
4
- import { CourierPushListener } from './models/CourierPushListener';
5
- import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
6
- import { Modules } from './Modules';
7
- import Broadcaster from './Broadcaster';
8
- import { CourierClient } from './client/CourierClient';
9
- import { Events, CourierUtils } from './utils';
10
- export { CourierClient } from './client/CourierClient';
11
- export { BrandClient } from './client/BrandClient';
12
- // Exports
13
- export { CourierInboxView } from './views/CourierInboxView';
14
- export { CourierPreferencesView } from './views/CourierPreferencesView';
15
- export { CourierInboxListener } from './models/CourierInboxListener';
16
- export { CourierPushListener } from './models/CourierPushListener';
17
- export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
18
- export { CourierUserPreferencesChannel } from './models/CourierUserPreferences';
19
- export { CourierUserPreferencesStatus } from './models/CourierUserPreferences';
20
- export { CourierTrackingEvent } from './models/CourierTrackingEvent';
21
- export { CourierPushProvider } from './models/CourierPushProvider';
22
- export { CourierUtils } from './utils';
23
- class Courier {
24
- // Singleton
25
- static _sharedInstance;
26
- // Listeners
27
- authenticationListeners = new Map();
28
- inboxListeners = new Map();
29
- pushListeners = new Map();
30
- // Broadcasting
31
- systemBroadcaster = new Broadcaster(Modules.System);
32
- sharedBroadcaster = new Broadcaster(Modules.Shared);
33
- pushNotificationClickedEmitter;
34
- pushNotificationDeliveredEmitter;
35
- constructor() {
36
- // Sets the initial SDK values
37
- // will show all foreground notification styles in iOS
38
- Courier.setIOSForegroundPresentationOptions({
39
- options: ['sound', 'badge', 'list', 'banner']
40
- });
41
- // Attach the push notification listeners
42
- this.attachPushNotificationListeners();
43
- }
44
- // Returns the public shared instance
45
- static get shared() {
46
- if (!this._sharedInstance) {
47
- this._sharedInstance = new Courier();
48
- }
49
- return this._sharedInstance;
50
- }
51
- // Debugging
52
- isDebugging = __DEV__;
53
- // Show a log to the console
54
- static log(message) {
55
- if (Courier.shared.isDebugging) {
56
- console.log(message);
57
- }
58
- }
59
- // System (Static)
60
- async attachPushNotificationListeners() {
61
- // Remove existing listeners
62
- // Only allows one subscription to be active
63
- this.pushNotificationClickedEmitter?.remove();
64
- this.pushNotificationDeliveredEmitter?.remove();
65
- // When a push notification is clicked
66
- this.pushNotificationClickedEmitter = await this.systemBroadcaster.addListener(Events.Push.CLICKED, (event) => {
67
- try {
68
- const message = JSON.parse(event);
69
- this.pushListeners.forEach(listener => {
70
- if (listener.onPushNotificationClicked) {
71
- listener.onPushNotificationClicked(message);
72
- }
73
- });
74
- }
75
- catch (error) {
76
- Courier.log(`Error parsing push notification clicked event: ${error}`);
77
- }
78
- });
79
- // When a push notification is delivered
80
- this.pushNotificationDeliveredEmitter = await this.systemBroadcaster.addListener(Events.Push.DELIVERED, (event) => {
81
- try {
82
- const message = JSON.parse(event);
83
- this.pushListeners.forEach(listener => {
84
- if (listener.onPushNotificationDelivered) {
85
- listener.onPushNotificationDelivered(message);
86
- }
87
- });
88
- }
89
- catch (error) {
90
- Courier.log(`Error parsing push notification delivered event: ${error}`);
91
- }
92
- });
93
- }
94
- /**
95
- * Sets the iOS foreground presentation options for push notifications.
96
- * This method only works on iOS devices.
97
- * @param props An object containing an array of iOSForegroundPresentationOptions.
98
- * @returns A string indicating the result of the operation. Returns 'unsupported' on non-iOS platforms.
99
- */
100
- static setIOSForegroundPresentationOptions(props) {
101
- // Only works on iOS
102
- if (Platform.OS !== 'ios')
103
- return 'unsupported';
104
- const normalizedParams = Array.from(new Set(props.options));
105
- return Modules.System.setIOSForegroundPresentationOptions({
106
- options: normalizedParams,
107
- });
108
- }
109
- /**
110
- * Retrieves the current notification permission status.
111
- * @returns A Promise that resolves to a string representing the current notification permission status.
112
- */
113
- static async getNotificationPermissionStatus() {
114
- return await Modules.System.getNotificationPermissionStatus();
115
- }
116
- /**
117
- * Requests permission to send push notifications to the user.
118
- * @returns A Promise that resolves to a string indicating the result of the permission request.
119
- */
120
- static async requestNotificationPermission() {
121
- return await Modules.System.requestNotificationPermission();
122
- }
123
- /**
124
- * Opens the settings page for the current app.
125
- * This can be used to direct users to enable notifications if they've previously denied permission.
126
- */
127
- static openSettingsForApp() {
128
- Modules.System.openSettingsForApp();
129
- }
130
- // Client
131
- /**
132
- * Gets the current CourierClient instance.
133
- * @returns {Promise<CourierClient | undefined>} The current CourierClient instance, or undefined if not initialized.
134
- */
135
- async getClient() {
136
- const client = await Modules.Shared.getClient() ?? undefined;
137
- if (!client) {
138
- return undefined;
139
- }
140
- const clientObj = JSON.parse(client);
141
- return new CourierClient({
142
- userId: clientObj.userId,
143
- showLogs: clientObj.showLogs,
144
- jwt: clientObj.jwt,
145
- clientKey: clientObj.clientKey,
146
- connectionId: clientObj.connectionId,
147
- tenantId: clientObj.tenantId,
148
- });
149
- }
150
- // Authentication
151
- /**
152
- * Gets the current user ID.
153
- * @returns {Promise<string | undefined>} The current user ID, or undefined if not set.
154
- */
155
- async getUserId() {
156
- return await Modules.Shared.getUserId() ?? undefined;
157
- }
158
- /**
159
- * Gets the current tenant ID.
160
- * @returns {Promise<string | undefined>} The current tenant ID, or undefined if not set.
161
- */
162
- async getTenantId() {
163
- return await Modules.Shared.getTenantId() ?? undefined;
164
- }
165
- /**
166
- * Checks if a user is currently signed in.
167
- * @returns {Promise<boolean>} True if a user is signed in, false otherwise.
168
- */
169
- async isUserSignedIn() {
170
- const isSignedIn = await Modules.Shared.getIsUserSignedIn() ?? 'false';
171
- return isSignedIn.toLowerCase() === 'true';
172
- }
173
- /**
174
- * Signs out the current user.
175
- * @returns {Promise<void>} A promise that resolves when the sign out process is complete.
176
- */
177
- async signOut() {
178
- return await Modules.Shared.signOut();
179
- }
180
- /**
181
- * Signs in a user with the provided credentials.
182
- * @param {Object} props - The sign-in properties.
183
- * @param {string} props.accessToken - The access token for authentication.
184
- * @param {string} [props.clientKey] - The client key (optional).
185
- * @param {string} props.userId - The user ID.
186
- * @param {string} [props.tenantId] - The tenant ID (optional).
187
- * @param {boolean} [props.showLogs] - Whether to show debug logs (defaults to __DEV__).
188
- * @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
189
- */
190
- async signIn(props) {
191
- this.isDebugging = props.showLogs ?? __DEV__;
192
- return await Modules.Shared.signIn(props.accessToken, props.clientKey ?? null, props.userId, props.tenantId ?? null, this.isDebugging);
193
- }
194
- /**
195
- * Adds an authentication listener to monitor user changes.
196
- * @param {Object} props - The listener properties.
197
- * @param {function} props.onUserChanged - Callback function triggered when the user changes.
198
- * @returns {CourierAuthenticationListener} The created authentication listener.
199
- */
200
- async addAuthenticationListener(props) {
201
- // Create a listener
202
- const listenerId = `authentication_${CourierUtils.generateUUID()}`;
203
- // Attach the listener
204
- const listener = new CourierAuthenticationListener(listenerId);
205
- listener.onUserChanged = await this.sharedBroadcaster.addListener(listenerId, (event) => props.onUserChanged(event));
206
- const id = await Modules.Shared.addAuthenticationListener(listenerId);
207
- this.authenticationListeners.set(id, listener);
208
- return listener;
209
- }
210
- /**
211
- * Removes a specific authentication listener.
212
- * @param {Object} props - The removal properties.
213
- * @param {string} props.listenerId - The ID of the listener to remove.
214
- * @returns {Promise<string>} A promise that resolves to the ID of the removed listener.
215
- */
216
- async removeAuthenticationListener(props) {
217
- // Remove the native listener
218
- await Modules.Shared.removeAuthenticationListener(props.listenerId);
219
- // Remove the listener
220
- if (this.authenticationListeners.has(props.listenerId)) {
221
- const listener = this.authenticationListeners.get(props.listenerId);
222
- listener?.onUserChanged?.remove();
223
- this.authenticationListeners.delete(props.listenerId);
224
- }
225
- return props.listenerId;
226
- }
227
- /**
228
- * Removes all authentication listeners.
229
- * This method clears all registered authentication listeners, both native and JavaScript.
230
- */
231
- async removeAllAuthenticationListeners() {
232
- // Remove all native listeners
233
- await Modules.Shared.removeAllAuthenticationListeners();
234
- // Iterate through all authentication listeners
235
- this.authenticationListeners.forEach((listener) => {
236
- listener.onUserChanged?.remove();
237
- });
238
- // Clear the map of authentication listeners
239
- this.authenticationListeners.clear();
240
- }
241
- // Push
242
- /**
243
- * Retrieves all push notification tokens.
244
- * @returns {Promise<Map<string, string>>} A promise that resolves to a Map of provider keys to tokens.
245
- */
246
- async getAllTokens() {
247
- const tokensObject = await Modules.Shared.getAllTokens();
248
- const tokensMap = new Map();
249
- for (const [key, value] of Object.entries(tokensObject)) {
250
- tokensMap.set(key, value);
251
- }
252
- return tokensMap;
253
- }
254
- /**
255
- * Retrieves the push notification token for a specific key.
256
- * @param {Object} props - The properties object.
257
- * @param {string} props.key - The key associated with the token.
258
- * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
259
- */
260
- async getToken(props) {
261
- return await Modules.Shared.getToken(props.key);
262
- }
263
- /**
264
- * Retrieves the push notification token for a specific provider.
265
- * @param {Object} props - The properties object.
266
- * @param {CourierPushProvider} props.provider - The push notification provider.
267
- * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
268
- */
269
- async getTokenForProvider(props) {
270
- return await Modules.Shared.getToken(props.provider);
271
- }
272
- /**
273
- * Sets the push notification token for a specific key.
274
- * @param {Object} props - The properties object.
275
- * @param {string} props.key - The key to associate with the token.
276
- * @param {string} props.token - The push notification token.
277
- * @returns {Promise<void>} A promise that resolves when the token is set.
278
- */
279
- async setToken(props) {
280
- return await Modules.Shared.setToken(props.key, props.token);
281
- }
282
- /**
283
- * Sets the push notification token for a specific provider.
284
- * @param {Object} props - The properties object.
285
- * @param {CourierPushProvider} props.provider - The push notification provider.
286
- * @param {string} props.token - The push notification token.
287
- * @returns {Promise<void>} A promise that resolves when the token is set.
288
- */
289
- async setTokenForProvider(props) {
290
- return await Modules.Shared.setToken(props.provider, props.token);
291
- }
292
- /**
293
- * Adds a push notification listener.
294
- * @param {Object} props - The properties object.
295
- * @param {function} [props.onPushNotificationClicked] - Callback function triggered when a push notification is clicked.
296
- * @param {function} [props.onPushNotificationDelivered] - Callback function triggered when a push notification is delivered.
297
- * @returns {CourierPushListener} The created push notification listener.
298
- */
299
- addPushNotificationListener(props) {
300
- const listenerId = `push_${CourierUtils.generateUUID()}`;
301
- const pushListener = new CourierPushListener(listenerId, props.onPushNotificationClicked, props.onPushNotificationDelivered);
302
- // Cache the listener
303
- this.pushListeners.set(listenerId, pushListener);
304
- // When listener is registered
305
- // Attempt to fetch the last message that was clicked
306
- // This is needed for when the app is killed and the
307
- // user launched the app by clicking on a notifications
308
- Modules.System.registerPushNotificationClickedOnKilledState();
309
- return pushListener;
310
- }
311
- /**
312
- * Removes a specific push notification listener.
313
- * @param {Object} props - The properties object.
314
- * @param {string} props.listenerId - The ID of the listener to remove.
315
- * @returns {string} The ID of the removed listener.
316
- */
317
- async removePushNotificationListener(props) {
318
- if (this.pushListeners.has(props.listenerId)) {
319
- this.pushListeners.delete(props.listenerId);
320
- }
321
- return props.listenerId;
322
- }
323
- /**
324
- * Removes all push notification listeners.
325
- */
326
- async removeAllPushNotificationListeners() {
327
- this.pushListeners.forEach((listener) => {
328
- listener.remove();
329
- });
330
- this.pushListeners.clear();
331
- }
332
- // Inbox
333
- /**
334
- * Gets the current pagination limit for inbox messages.
335
- * @returns {Promise<number>} A promise that resolves with the current pagination limit.
336
- */
337
- async getInboxPaginationLimit() {
338
- return await Modules.Shared.getInboxPaginationLimit();
339
- }
340
- /**
341
- * Sets the pagination limit for inbox messages.
342
- * @param {number} limit - The new pagination limit to set.
343
- * @returns {Promise<void>} A promise that resolves when the limit is set.
344
- */
345
- async setInboxPaginationLimit(limit) {
346
- await Modules.Shared.setInboxPaginationLimit(limit);
347
- }
348
- /**
349
- * Opens a specific message in the inbox.
350
- * @param {Object} props - The properties object.
351
- * @param {string} props.messageId - The ID of the message to open.
352
- * @returns {Promise<void>} A promise that resolves when the message is opened.
353
- */
354
- async openMessage(props) {
355
- return await Modules.Shared.openMessage(props.messageId);
356
- }
357
- /**
358
- * Registers a click event for a specific message in the inbox.
359
- * @param {Object} props - The properties object.
360
- * @param {string} props.messageId - The ID of the message that was clicked.
361
- * @returns {Promise<void>} A promise that resolves when the click is registered.
362
- */
363
- async clickMessage(props) {
364
- return await Modules.Shared.clickMessage(props.messageId);
365
- }
366
- /**
367
- * Marks a specific message as read in the inbox.
368
- * @param {Object} props - The properties object.
369
- * @param {string} props.messageId - The ID of the message to mark as read.
370
- * @returns {Promise<void>} A promise that resolves when the message is marked as read.
371
- */
372
- async readMessage(props) {
373
- return await Modules.Shared.readMessage(props.messageId);
374
- }
375
- /**
376
- * Marks a specific message as unread in the inbox.
377
- * @param {Object} props - The properties object.
378
- * @param {string} props.messageId - The ID of the message to mark as unread.
379
- * @returns {Promise<void>} A promise that resolves when the message is marked as unread.
380
- */
381
- async unreadMessage(props) {
382
- return await Modules.Shared.unreadMessage(props.messageId);
383
- }
384
- /**
385
- * Archives a specific message in the inbox.
386
- * @param {Object} props - The properties object.
387
- * @param {string} props.messageId - The ID of the message to archive.
388
- * @returns {Promise<void>} A promise that resolves when the message is archived.
389
- */
390
- async archiveMessage(props) {
391
- return await Modules.Shared.archiveMessage(props.messageId);
392
- }
393
- /**
394
- * Marks all messages in the inbox as read.
395
- * @returns {Promise<void>} A promise that resolves when all messages are marked as read.
396
- */
397
- async readAllInboxMessages() {
398
- return await Modules.Shared.readAllInboxMessages();
399
- }
400
- /**
401
- * Adds a listener for inbox changes.
402
- * @param {Object} props - The properties object.
403
- * @param {Function} [props.onInitialLoad] - Callback function called when the inbox is initially loaded.
404
- * @param {Function} [props.onError] - Callback function called when an error occurs. Receives the error message as a parameter.
405
- * @param {Function} [props.onUnreadCountChanged] - Callback function called when the unread count changes.
406
- * @param {Function} [props.onFeedChanged] - Callback function called when the feed changes.
407
- * @param {Function} [props.onArchiveChanged] - Callback function called when the archive changes.
408
- * @param {Function} [props.onPageAdded] - Callback function called when a new page is added.
409
- * @param {Function} [props.onMessageChanged] - Callback function called when a message changes.
410
- * @param {Function} [props.onMessageAdded] - Callback function called when a new message is added.
411
- * @param {Function} [props.onMessageRemoved] - Callback function called when a message is removed.
412
- * @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
413
- */
414
- async addInboxListener(props) {
415
- const listenerId = `inbox_${CourierUtils.generateUUID()}`;
416
- const listenerIds = {
417
- loading: `inbox_loading_${CourierUtils.generateUUID()}`,
418
- error: `inbox_error_${CourierUtils.generateUUID()}`,
419
- unreadCount: `inbox_unread_count_${CourierUtils.generateUUID()}`,
420
- feed: `inbox_feed_${CourierUtils.generateUUID()}`,
421
- archive: `inbox_archive_${CourierUtils.generateUUID()}`,
422
- pageAdded: `inbox_page_added_${CourierUtils.generateUUID()}`,
423
- messageChanged: `inbox_message_changed_${CourierUtils.generateUUID()}`,
424
- messageAdded: `inbox_message_added_${CourierUtils.generateUUID()}`,
425
- messageRemoved: `inbox_message_removed_${CourierUtils.generateUUID()}`
426
- };
427
- // Create the initial listeners
428
- const listener = new CourierInboxListener(listenerId);
429
- listener.onInitialLoad = await this.sharedBroadcaster.addListener(listenerIds.loading, (event) => {
430
- props.onInitialLoad?.(event);
431
- });
432
- listener.onError = await this.sharedBroadcaster.addListener(listenerIds.error, (event) => {
433
- props.onError?.(event);
434
- });
435
- listener.onUnreadCountChanged = await this.sharedBroadcaster.addListener(listenerIds.unreadCount, (event) => {
436
- props.onUnreadCountChanged?.(event);
437
- });
438
- listener.onFeedChanged = await this.sharedBroadcaster.addListener(listenerIds.feed, (event) => {
439
- const convertedMessages = this.convertMessages(event.messages);
440
- const messageSet = {
441
- messages: convertedMessages,
442
- totalMessageCount: event.totalMessageCount,
443
- canPaginate: event.canPaginate
444
- };
445
- props.onFeedChanged?.(messageSet);
446
- });
447
- listener.onArchiveChanged = await this.sharedBroadcaster.addListener(listenerIds.archive, (event) => {
448
- const convertedMessages = this.convertMessages(event.messages);
449
- const messageSet = {
450
- messages: convertedMessages,
451
- totalMessageCount: event.totalMessageCount,
452
- canPaginate: event.canPaginate
453
- };
454
- props.onArchiveChanged?.(messageSet);
455
- });
456
- listener.onPageAdded = await this.sharedBroadcaster.addListener(listenerIds.pageAdded, (event) => {
457
- const convertedMessages = this.convertMessages(event.messages);
458
- const messageSet = {
459
- messages: convertedMessages,
460
- totalMessageCount: event.totalMessageCount,
461
- canPaginate: event.canPaginate
462
- };
463
- props.onPageAdded?.(event.feed === 'archived' ? 'archived' : 'feed', messageSet);
464
- });
465
- listener.onMessageChanged = await this.sharedBroadcaster.addListener(listenerIds.messageChanged, (event) => {
466
- const convertedMessage = this.convertMessage(event.message);
467
- props.onMessageChanged?.(event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
468
- });
469
- listener.onMessageAdded = await this.sharedBroadcaster.addListener(listenerIds.messageAdded, (event) => {
470
- const convertedMessage = this.convertMessage(event.message);
471
- props.onMessageAdded?.(event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
472
- });
473
- listener.onMessageRemoved = await this.sharedBroadcaster.addListener(listenerIds.messageRemoved, (event) => {
474
- const convertedMessage = this.convertMessage(event.message);
475
- props.onMessageRemoved?.(event.feed === 'archived' ? 'archived' : 'feed', event.index, convertedMessage);
476
- });
477
- // Attach listener to native code
478
- const id = await Modules.Shared.addInboxListener(listenerId, listenerIds.loading, listenerIds.error, listenerIds.unreadCount, listenerIds.feed, listenerIds.archive, listenerIds.pageAdded, listenerIds.messageChanged, listenerIds.messageAdded, listenerIds.messageRemoved);
479
- // Add listener to manager
480
- this.inboxListeners.set(id, listener);
481
- return listener;
482
- }
483
- convertMessages(messages) {
484
- return messages.map(jsonString => {
485
- try {
486
- return JSON.parse(jsonString);
487
- }
488
- catch (error) {
489
- Courier.log(`Error parsing message: ${error}`);
490
- return null;
491
- }
492
- }).filter((message) => message !== null);
493
- }
494
- convertMessage(message) {
495
- try {
496
- return JSON.parse(message);
497
- }
498
- catch (error) {
499
- Courier.log(`Error parsing message: ${error}`);
500
- throw error;
501
- }
502
- }
503
- /**
504
- * Removes a specific inbox listener.
505
- * @param {Object} props - The properties object.
506
- * @param {string} props.listenerId - The ID of the listener to remove.
507
- * @returns {string} The ID of the removed listener.
508
- */
509
- async removeInboxListener(props) {
510
- // Call native code
511
- await Modules.Shared.removeInboxListener(props.listenerId);
512
- // Remove the listener
513
- if (this.inboxListeners.has(props.listenerId)) {
514
- // Remove emitters
515
- const listener = this.inboxListeners.get(props.listenerId);
516
- listener?.onInitialLoad?.remove();
517
- listener?.onError?.remove();
518
- listener?.onUnreadCountChanged?.remove();
519
- listener?.onFeedChanged?.remove();
520
- listener?.onArchiveChanged?.remove();
521
- listener?.onPageAdded?.remove();
522
- listener?.onMessageChanged?.remove();
523
- listener?.onMessageAdded?.remove();
524
- listener?.onMessageRemoved?.remove();
525
- // Remove the listener
526
- this.inboxListeners.delete(props.listenerId);
527
- }
528
- return props.listenerId;
529
- }
530
- /**
531
- * Removes all inbox listeners.
532
- */
533
- async removeAllInboxListeners() {
534
- // Call native code
535
- await Modules.Shared.removeAllInboxListeners();
536
- // Remove all items from inboxListeners
537
- this.inboxListeners.forEach((listener) => {
538
- listener?.onInitialLoad?.remove();
539
- listener?.onError?.remove();
540
- listener?.onUnreadCountChanged?.remove();
541
- listener?.onFeedChanged?.remove();
542
- listener?.onArchiveChanged?.remove();
543
- listener?.onPageAdded?.remove();
544
- listener?.onMessageChanged?.remove();
545
- listener?.onMessageAdded?.remove();
546
- listener?.onMessageRemoved?.remove();
547
- });
548
- this.inboxListeners.clear();
549
- }
550
- /**
551
- * Refreshes the inbox.
552
- * Useful for pull-to-refresh functionality.
553
- * @returns {Promise<void>} A promise that resolves when the inbox is refreshed.
554
- */
555
- async refreshInbox() {
556
- return await Modules.Shared.refreshInbox();
557
- }
558
- /**
559
- * Fetches the next page of inbox messages.
560
- * @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
561
- */
562
- async fetchNextPageOfMessages(props) {
563
- const messages = await Modules.Shared.fetchNextPageOfMessages(props.inboxMessageFeed);
564
- return messages.map((message) => JSON.parse(message));
565
- }
566
- }
567
- export default Courier;
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import Courier from "..";
2
- export class CourierAuthenticationListener {
3
- listenerId;
4
- onUserChanged;
5
- constructor(id) {
6
- this.listenerId = id;
7
- }
8
- async remove() {
9
- // Remove the native inbox listener
10
- await Courier.shared.removeInboxListener({ listenerId: this.listenerId });
11
- // Remove the emitter
12
- this.onUserChanged?.remove();
13
- }
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import Courier from "..";
2
- export class CourierInboxListener {
3
- listenerId;
4
- onInitialLoad;
5
- onError;
6
- onMessagesChanged;
7
- onUnreadCountChanged;
8
- onFeedChanged;
9
- onArchiveChanged;
10
- onPageAdded;
11
- onMessageChanged;
12
- onMessageAdded;
13
- onMessageRemoved;
14
- constructor(id) {
15
- this.listenerId = id;
16
- }
17
- async remove() {
18
- await Courier.shared.removeInboxListener({ listenerId: this.listenerId });
19
- }
20
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- export class CourierPushListener {
2
- listenerId;
3
- onPushNotificationClicked;
4
- onPushNotificationDelivered;
5
- constructor(id, onPushNotificationClicked, onPushNotificationDelivered) {
6
- this.listenerId = id;
7
- this.onPushNotificationClicked = onPushNotificationClicked;
8
- this.onPushNotificationDelivered = onPushNotificationDelivered;
9
- }
10
- remove() {
11
- this.onPushNotificationClicked = undefined;
12
- this.onPushNotificationDelivered = undefined;
13
- }
14
- }
@@ -1,8 +0,0 @@
1
- export var CourierPushProvider;
2
- (function (CourierPushProvider) {
3
- CourierPushProvider["APN"] = "apn";
4
- CourierPushProvider["FIREBASE_FCM"] = "firebase-fcm";
5
- CourierPushProvider["EXPO"] = "expo";
6
- CourierPushProvider["ONE_SIGNAL"] = "onesignal";
7
- CourierPushProvider["PUSHER_BEAMS"] = "pusher-beams";
8
- })(CourierPushProvider || (CourierPushProvider = {}));
@@ -1,8 +0,0 @@
1
- export var CourierTrackingEvent;
2
- (function (CourierTrackingEvent) {
3
- CourierTrackingEvent["Clicked"] = "CLICKED";
4
- CourierTrackingEvent["Delivered"] = "DELIVERED";
5
- CourierTrackingEvent["Opened"] = "OPENED";
6
- CourierTrackingEvent["Read"] = "READ";
7
- CourierTrackingEvent["Unread"] = "UNREAD";
8
- })(CourierTrackingEvent || (CourierTrackingEvent = {}));