@trycourier/courier-react-native 3.2.1 → 4.0.4

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 (251) hide show
  1. package/android/build.gradle +4 -1
  2. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
  3. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
  5. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +321 -0
  6. package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
  7. package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
  8. package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
  9. package/courier-react-native.podspec +1 -1
  10. package/ios/CourierClientModule.swift +450 -0
  11. package/ios/CourierInboxReactNativeManager.swift +17 -9
  12. package/ios/CourierReactNativeDelegate.m +18 -35
  13. package/ios/CourierReactNativeEventEmitter.swift +25 -0
  14. package/ios/CourierReactNativeModule.m +192 -23
  15. package/ios/CourierSharedModule.swift +425 -0
  16. package/ios/CourierSystemModule.swift +147 -0
  17. package/ios/Utils.swift +103 -115
  18. package/lib/commonjs/Broadcaster.js +30 -0
  19. package/lib/commonjs/Broadcaster.js.map +1 -0
  20. package/lib/commonjs/Modules.js +25 -0
  21. package/lib/commonjs/Modules.js.map +1 -0
  22. package/lib/commonjs/client/BrandClient.js +25 -0
  23. package/lib/commonjs/client/BrandClient.js.map +1 -0
  24. package/lib/commonjs/client/ClientModule.js +21 -0
  25. package/lib/commonjs/client/ClientModule.js.map +1 -0
  26. package/lib/commonjs/client/CourierClient.js +33 -0
  27. package/lib/commonjs/client/CourierClient.js.map +1 -0
  28. package/lib/commonjs/client/InboxClient.js +116 -0
  29. package/lib/commonjs/client/InboxClient.js.map +1 -0
  30. package/lib/commonjs/client/PreferenceClient.js +73 -0
  31. package/lib/commonjs/client/PreferenceClient.js.map +1 -0
  32. package/lib/commonjs/client/TokenClient.js +36 -0
  33. package/lib/commonjs/client/TokenClient.js.map +1 -0
  34. package/lib/commonjs/client/TrackingClient.js +25 -0
  35. package/lib/commonjs/client/TrackingClient.js.map +1 -0
  36. package/lib/commonjs/index.js +418 -186
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
  39. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  40. package/lib/commonjs/models/CourierBrand.js +2 -0
  41. package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  42. package/lib/commonjs/models/CourierButton.js.map +1 -1
  43. package/lib/commonjs/models/CourierDevice.js +2 -0
  44. package/lib/commonjs/models/CourierDevice.js.map +1 -0
  45. package/lib/commonjs/models/CourierFont.js.map +1 -1
  46. package/lib/commonjs/models/CourierInboxListener.js +2 -2
  47. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  48. package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
  49. package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
  50. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
  51. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
  52. package/lib/commonjs/models/CourierPaging.js.map +1 -1
  53. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
  54. package/lib/commonjs/models/CourierPushListener.js +7 -3
  55. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  56. package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
  57. package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
  58. package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
  59. package/lib/commonjs/models/CourierUserPreferences.js +54 -0
  60. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  61. package/lib/commonjs/models/InboxAction.js.map +1 -1
  62. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  63. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
  64. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
  65. package/lib/commonjs/utils.js +9 -17
  66. package/lib/commonjs/utils.js.map +1 -1
  67. package/lib/commonjs/views/CourierInboxView.js +3 -3
  68. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  69. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  70. package/lib/module/Broadcaster.js +23 -0
  71. package/lib/module/Broadcaster.js.map +1 -0
  72. package/lib/module/Modules.js +18 -0
  73. package/lib/module/Modules.js.map +1 -0
  74. package/lib/module/client/BrandClient.js +18 -0
  75. package/lib/module/client/BrandClient.js.map +1 -0
  76. package/lib/module/client/ClientModule.js +14 -0
  77. package/lib/module/client/ClientModule.js.map +1 -0
  78. package/lib/module/client/CourierClient.js +26 -0
  79. package/lib/module/client/CourierClient.js.map +1 -0
  80. package/lib/module/client/InboxClient.js +109 -0
  81. package/lib/module/client/InboxClient.js.map +1 -0
  82. package/lib/module/client/PreferenceClient.js +66 -0
  83. package/lib/module/client/PreferenceClient.js.map +1 -0
  84. package/lib/module/client/TokenClient.js +29 -0
  85. package/lib/module/client/TokenClient.js.map +1 -0
  86. package/lib/module/client/TrackingClient.js +18 -0
  87. package/lib/module/client/TrackingClient.js.map +1 -0
  88. package/lib/module/index.js +383 -185
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/models/Android_CourierSheet.js.map +1 -1
  91. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  92. package/lib/module/models/CourierBrand.js +2 -0
  93. package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  94. package/lib/module/models/CourierButton.js.map +1 -1
  95. package/lib/module/models/CourierDevice.js +2 -0
  96. package/lib/module/models/CourierDevice.js.map +1 -0
  97. package/lib/module/models/CourierFont.js.map +1 -1
  98. package/lib/module/models/CourierInboxListener.js +1 -1
  99. package/lib/module/models/CourierInboxListener.js.map +1 -1
  100. package/lib/module/models/CourierInboxMessages.js +2 -0
  101. package/lib/module/models/CourierInboxMessages.js.map +1 -0
  102. package/lib/module/models/CourierInboxTheme.js.map +1 -1
  103. package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
  104. package/lib/module/models/CourierPaging.js.map +1 -1
  105. package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
  106. package/lib/module/models/CourierPushListener.js +7 -3
  107. package/lib/module/models/CourierPushListener.js.map +1 -1
  108. package/lib/module/models/CourierPushProvider.js.map +1 -1
  109. package/lib/module/models/CourierTrackingEvent.js +9 -0
  110. package/lib/module/models/CourierTrackingEvent.js.map +1 -0
  111. package/lib/module/models/CourierUserPreferences.js +53 -1
  112. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  113. package/lib/module/models/InboxAction.js.map +1 -1
  114. package/lib/module/models/InboxMessage.js.map +1 -1
  115. package/lib/module/models/iOS_CourierCell.js.map +1 -1
  116. package/lib/module/models/iOS_CourierSheet.js.map +1 -1
  117. package/lib/module/utils.js +7 -16
  118. package/lib/module/utils.js.map +1 -1
  119. package/lib/module/views/CourierInboxView.js +3 -3
  120. package/lib/module/views/CourierInboxView.js.map +1 -1
  121. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  122. package/lib/typescript/src/Broadcaster.d.ts +14 -0
  123. package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
  124. package/lib/typescript/src/Modules.d.ts +8 -0
  125. package/lib/typescript/src/Modules.d.ts.map +1 -0
  126. package/lib/typescript/src/client/BrandClient.d.ts +15 -0
  127. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
  128. package/lib/typescript/src/client/ClientModule.d.ts +8 -0
  129. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
  130. package/lib/typescript/src/client/CourierClient.d.ts +31 -0
  131. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
  132. package/lib/typescript/src/client/InboxClient.d.ts +94 -0
  133. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
  134. package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
  135. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
  136. package/lib/typescript/src/client/TokenClient.d.ts +28 -0
  137. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
  138. package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
  139. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
  140. package/lib/typescript/src/index.d.ts +300 -0
  141. package/lib/typescript/src/index.d.ts.map +1 -0
  142. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
  143. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
  144. package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
  145. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
  146. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
  147. package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
  148. package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
  149. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
  150. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
  151. package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
  152. package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
  153. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
  154. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
  155. package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
  156. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
  157. package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
  158. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
  159. package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
  160. package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
  161. package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
  162. package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
  163. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
  164. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
  165. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
  166. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
  167. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
  168. package/lib/typescript/src/utils.d.ts +14 -0
  169. package/lib/typescript/src/utils.d.ts.map +1 -0
  170. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
  171. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
  172. package/package.json +3 -3
  173. package/src/Broadcaster.tsx +32 -0
  174. package/src/Modules.tsx +28 -0
  175. package/src/client/BrandClient.tsx +23 -0
  176. package/src/client/ClientModule.tsx +21 -0
  177. package/src/client/CourierClient.tsx +49 -0
  178. package/src/client/InboxClient.tsx +114 -0
  179. package/src/client/PreferenceClient.tsx +77 -0
  180. package/src/client/TokenClient.tsx +34 -0
  181. package/src/client/TrackingClient.tsx +23 -0
  182. package/src/index.tsx +398 -205
  183. package/src/models/CourierBrand.tsx +24 -0
  184. package/src/models/CourierDevice.tsx +8 -0
  185. package/src/models/CourierInboxListener.tsx +1 -1
  186. package/src/models/CourierInboxMessages.tsx +28 -0
  187. package/src/models/CourierPushListener.tsx +11 -6
  188. package/src/models/CourierTrackingEvent.tsx +7 -0
  189. package/src/models/CourierUserPreferences.tsx +70 -3
  190. package/src/utils.tsx +7 -23
  191. package/src/views/CourierInboxView.tsx +3 -3
  192. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
  193. package/ios/CourierReactNativeModule.swift +0 -524
  194. package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
  195. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
  196. package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
  197. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
  198. package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
  199. package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
  200. package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
  201. package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
  202. package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
  203. package/lib/typescript/index.d.ts +0 -199
  204. package/lib/typescript/index.d.ts.map +0 -1
  205. package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
  206. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
  207. package/lib/typescript/models/CourierButton.d.ts.map +0 -1
  208. package/lib/typescript/models/CourierFont.d.ts.map +0 -1
  209. package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
  210. package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
  211. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
  212. package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
  213. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
  214. package/lib/typescript/models/CourierPushListener.d.ts +0 -7
  215. package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
  216. package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
  217. package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
  218. package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
  219. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
  220. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
  221. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
  222. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
  223. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
  224. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
  225. package/lib/typescript/models/InboxAction.d.ts.map +0 -1
  226. package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
  227. package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
  228. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
  229. package/lib/typescript/utils.d.ts +0 -21
  230. package/lib/typescript/utils.d.ts.map +0 -1
  231. package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
  232. package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
  233. package/src/models/CourierUserPreferencesChannel.tsx +0 -8
  234. package/src/models/CourierUserPreferencesStatus.tsx +0 -6
  235. package/src/models/CourierUserPreferencesTopic.tsx +0 -13
  236. /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
  237. /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
  238. /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
  239. /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
  240. /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
  241. /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
  242. /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
  243. /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
  244. /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
  245. /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
  246. /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
  247. /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
  248. /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
  249. /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
  250. /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
  251. /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "3.2.1",
4
- "description": "Inbox & Push Notifications for React Native",
3
+ "version": "4.0.4",
4
+ "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
- "types": "lib/typescript/index.d.ts",
7
+ "types": "lib/typescript/src/index.d.ts",
8
8
  "react-native": "src/index",
9
9
  "source": "src/index",
10
10
  "files": [
@@ -0,0 +1,32 @@
1
+ import { NativeModule } from "react-native";
2
+ import { NativeEventEmitter, EmitterSubscription, Platform, DeviceEventEmitter } from "react-native";
3
+
4
+ export default class Broadcaster {
5
+
6
+ private emitter: NativeEventEmitter;
7
+
8
+ constructor(module: NativeModule) {
9
+ this.emitter = new NativeEventEmitter(module);
10
+ }
11
+
12
+ /**
13
+ * Creates an event listener for the native function
14
+ * @param key Key for the listener
15
+ * @param callback Value returned for the listener callback
16
+ * @returns Subscription
17
+ */
18
+ addListener(id: string, callback: (value: any) => void): EmitterSubscription | undefined {
19
+
20
+ if (Platform.OS === 'android') {
21
+ return DeviceEventEmitter.addListener(id, (event: any) => callback(event));
22
+ }
23
+
24
+ if (Platform.OS === 'ios') {
25
+ return this.emitter.addListener(id, (event: any) => callback(event));
26
+ }
27
+
28
+ return undefined;
29
+
30
+ }
31
+
32
+ }
@@ -0,0 +1,28 @@
1
+ import { NativeModules, Platform } from "react-native";
2
+
3
+ export class Modules {
4
+
5
+ static readonly LINKING_ERROR =
6
+ `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
7
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
8
+ '- You rebuilt the app after installing the package\n' +
9
+ '- You are not using Expo Go\n';
10
+
11
+ static readonly Client = Modules.getNativeModule(NativeModules.CourierClientModule);
12
+ static readonly Shared = Modules.getNativeModule(NativeModules.CourierSharedModule);
13
+ static readonly System = Modules.getNativeModule(NativeModules.CourierSystemModule);
14
+
15
+ static getNativeModule<T>(nativeModule: T | undefined): T {
16
+ return nativeModule
17
+ ? nativeModule
18
+ : new Proxy(
19
+ {},
20
+ {
21
+ get() {
22
+ throw new Error(Modules.LINKING_ERROR);
23
+ },
24
+ }
25
+ ) as T;
26
+ }
27
+
28
+ }
@@ -0,0 +1,23 @@
1
+ import { Modules } from "../Modules";
2
+ import { CourierBrandResponse } from "..";
3
+
4
+ export class BrandClient {
5
+
6
+ readonly clientId: string;
7
+
8
+ constructor(clientId: string) {
9
+ this.clientId = clientId;
10
+ }
11
+
12
+ /**
13
+ * Retrieves brand information for a specific brand ID.
14
+ * @param props - The properties for getting the brand.
15
+ * @param props.brandId - The ID of the brand to retrieve.
16
+ * @returns A promise that resolves with the CourierBrandResponse containing brand information.
17
+ */
18
+ public async getBrand(props: { brandId: string }): Promise<CourierBrandResponse> {
19
+ const json = await Modules.Client.getBrand(this.clientId, props.brandId);
20
+ return JSON.parse(json);
21
+ }
22
+
23
+ }
@@ -0,0 +1,21 @@
1
+ import { Modules } from "../Modules";
2
+ import { CourierClientOptions } from "./CourierClient";
3
+
4
+ export abstract class ClientModule {
5
+
6
+ readonly clientId: string;
7
+
8
+ // Constructor to create a low level CourierClient
9
+ constructor(options: CourierClientOptions) {
10
+ this.clientId = this.add(options);
11
+ }
12
+
13
+ private add(options: CourierClientOptions): string {
14
+ return Modules.Client.addClient(options);
15
+ }
16
+
17
+ public remove(): string {
18
+ return Modules.Client.removeClient(this.clientId);
19
+ }
20
+
21
+ }
@@ -0,0 +1,49 @@
1
+ import { BrandClient } from "..";
2
+ import { ClientModule } from "./ClientModule";
3
+ import { InboxClient } from "./InboxClient";
4
+ import { PreferenceClient } from "./PreferenceClient";
5
+ import { TokenClient } from "./TokenClient";
6
+ import { TrackingClient } from "./TrackingClient";
7
+
8
+ export interface CourierClientOptions {
9
+ userId: string;
10
+ showLogs: boolean;
11
+ jwt?: string;
12
+ clientKey?: string;
13
+ connectionId?: string;
14
+ tenantId?: string;
15
+ }
16
+
17
+ export class CourierClient extends ClientModule {
18
+
19
+ public readonly options: CourierClientOptions;
20
+ public readonly tokens: TokenClient;
21
+ public readonly brands: BrandClient;
22
+ public readonly inbox: InboxClient;
23
+ public readonly preferences: PreferenceClient;
24
+ public readonly tracking: TrackingClient;
25
+
26
+ constructor(props: { userId: string, jwt?: string, clientKey?: string, connectionId?: string, tenantId?: string, showLogs?: boolean }) {
27
+
28
+ const options = {
29
+ userId: props.userId,
30
+ showLogs: props.showLogs ?? __DEV__,
31
+ jwt: props.jwt,
32
+ clientKey: props.clientKey,
33
+ connectionId: props.clientKey,
34
+ tenantId: props.tenantId,
35
+ };
36
+
37
+ super(options);
38
+
39
+ this.options = options
40
+
41
+ this.tokens = new TokenClient(this.clientId);
42
+ this.brands = new BrandClient(this.clientId);
43
+ this.inbox = new InboxClient(this.clientId);
44
+ this.preferences = new PreferenceClient(this.clientId);
45
+ this.tracking = new TrackingClient(this.clientId);
46
+
47
+ }
48
+
49
+ }
@@ -0,0 +1,114 @@
1
+ import { Modules } from "../Modules";
2
+ import { CourierGetInboxMessageResponse, CourierGetInboxMessagesResponse } from "../models/CourierInboxMessages";
3
+
4
+ export class InboxClient {
5
+
6
+ readonly clientId: string;
7
+
8
+ constructor(clientId: string) {
9
+ this.clientId = clientId;
10
+ }
11
+
12
+ /**
13
+ * Retrieves messages from the inbox.
14
+ * @param props - The properties for getting messages.
15
+ * @param props.paginationLimit - Optional. The number of messages to retrieve per page. Defaults to 24.
16
+ * @param props.startCursor - Optional. The cursor to start retrieving messages from.
17
+ * @returns A promise that resolves with the CourierGetInboxMessagesResponse containing the messages.
18
+ */
19
+ public async getMessages(props: { paginationLimit?: number, startCursor?: string }): Promise<CourierGetInboxMessagesResponse> {
20
+ const json = await Modules.Client.getMessages(this.clientId, props.paginationLimit ?? 24, props.startCursor);
21
+ return JSON.parse(json);
22
+ }
23
+
24
+ /**
25
+ * Retrieves archived messages from the inbox.
26
+ * @param props - The properties for getting archived messages.
27
+ * @param props.paginationLimit - Optional. The number of messages to retrieve per page. Defaults to 24.
28
+ * @param props.startCursor - Optional. The cursor to start retrieving messages from.
29
+ * @returns A promise that resolves with the CourierGetInboxMessagesResponse containing the archived messages.
30
+ */
31
+ public async getArchivedMessages(props: { paginationLimit?: number, startCursor?: string }): Promise<CourierGetInboxMessagesResponse> {
32
+ const json = await Modules.Client.getArchivedMessages(this.clientId, props.paginationLimit ?? 24, props.startCursor);
33
+ return JSON.parse(json);
34
+ }
35
+
36
+ /**
37
+ * Retrieves a specific message by its ID.
38
+ * @param props - The properties for getting the message.
39
+ * @param props.messageId - The ID of the message to retrieve.
40
+ * @returns A promise that resolves with the CourierGetInboxMessageResponse containing the message.
41
+ */
42
+ public async getMessageById(props: { messageId: String }): Promise<CourierGetInboxMessageResponse> {
43
+ const json = await Modules.Client.getMessageById(this.clientId, props.messageId);
44
+ return JSON.parse(json);
45
+ }
46
+
47
+ /**
48
+ * Retrieves the count of unread messages in the inbox.
49
+ * @returns A promise that resolves with the number of unread messages.
50
+ */
51
+ public async getUnreadMessageCount(): Promise<number> {
52
+ return await Modules.Client.getUnreadMessageCount(this.clientId);
53
+ }
54
+
55
+ /**
56
+ * Marks a message as opened.
57
+ * @param props - The properties for opening the message.
58
+ * @param props.messageId - The ID of the message to mark as opened.
59
+ * @returns A promise that resolves with a number indicating the operation result.
60
+ */
61
+ public async open(props: { messageId: String }): Promise<number> {
62
+ return await Modules.Client.openMessage(this.clientId, props.messageId);
63
+ }
64
+
65
+ /**
66
+ * Marks a message as read.
67
+ * @param props - The properties for reading the message.
68
+ * @param props.messageId - The ID of the message to mark as read.
69
+ * @returns A promise that resolves with a number indicating the operation result.
70
+ */
71
+ public async read(props: { messageId: String }): Promise<number> {
72
+ return await Modules.Client.readMessage(this.clientId, props.messageId);
73
+ }
74
+
75
+ /**
76
+ * Marks a message as unread.
77
+ * @param props - The properties for marking the message as unread.
78
+ * @param props.messageId - The ID of the message to mark as unread.
79
+ * @returns A promise that resolves with a number indicating the operation result.
80
+ */
81
+ public async unread(props: { messageId: String }): Promise<number> {
82
+ return await Modules.Client.unreadMessage(this.clientId, props.messageId);
83
+ }
84
+
85
+ /**
86
+ * Records a click event for a message.
87
+ * @param props - The properties for clicking the message.
88
+ * @param props.messageId - The ID of the message that was clicked.
89
+ * @param props.trackingId - The tracking ID associated with the click event.
90
+ * @returns A promise that resolves with a number indicating the operation result.
91
+ */
92
+ public async click(props: { messageId: String, trackingId: string }): Promise<number> {
93
+ return await Modules.Client.clickMessage(this.clientId, props.messageId, props.trackingId);
94
+ }
95
+
96
+ /**
97
+ * Archives a message.
98
+ * @param props - The properties for archiving the message.
99
+ * @param props.messageId - The ID of the message to archive.
100
+ * @returns A promise that resolves with a number indicating the operation result.
101
+ */
102
+ public async archive(props: { messageId: String }): Promise<number> {
103
+ return await Modules.Client.archiveMessage(this.clientId, props.messageId);
104
+ }
105
+
106
+ /**
107
+ * Marks all messages as read.
108
+ * @returns A promise that resolves with a number indicating the operation result.
109
+ */
110
+ public async readAll(): Promise<number> {
111
+ return await Modules.Client.readAllMessages(this.clientId);
112
+ }
113
+
114
+ }
@@ -0,0 +1,77 @@
1
+ import { Modules } from "../Modules";
2
+ import { CourierUserPreferences, CourierUserPreferencesChannel, CourierUserPreferencesStatus, CourierUserPreferencesTopic } from "../models/CourierUserPreferences";
3
+
4
+ export class PreferenceClient {
5
+
6
+ readonly clientId: string;
7
+
8
+ constructor(clientId: string) {
9
+ this.clientId = clientId;
10
+ }
11
+
12
+ /**
13
+ * Retrieves user preferences.
14
+ * @param props - Optional properties for pagination.
15
+ * @param props.paginationCursor - Optional cursor for pagination.
16
+ * @returns A promise that resolves with CourierUserPreferences containing user preference items and paging information.
17
+ */
18
+ public async getUserPreferences(props?: { paginationCursor?: string }): Promise<CourierUserPreferences> {
19
+
20
+ const json = await Modules.Client.getUserPreferences(this.clientId, props?.paginationCursor);
21
+
22
+ const rawData = JSON.parse(json);
23
+
24
+ return {
25
+ items: rawData.items.map((item: any) => ({
26
+ defaultStatus: item.default_status as CourierUserPreferencesStatus,
27
+ hasCustomRouting: item.has_custom_routing,
28
+ customRouting: item.custom_routing.map((channel: string) => channel as CourierUserPreferencesChannel),
29
+ status: item.status as CourierUserPreferencesStatus,
30
+ topicId: item.topic_id,
31
+ topicName: item.topic_name,
32
+ sectionName: item.section_name,
33
+ sectionId: item.section_id
34
+ })),
35
+ paging: rawData.paging
36
+ };
37
+
38
+ }
39
+
40
+ /**
41
+ * Retrieves user preference for a specific topic.
42
+ * @param props - Properties for getting the user preference topic.
43
+ * @param props.topicId - The ID of the topic to retrieve preferences for.
44
+ * @returns A promise that resolves with CourierUserPreferencesTopic containing the topic preference details.
45
+ */
46
+ public async getUserPreferenceTopic(props: { topicId: string }): Promise<CourierUserPreferencesTopic> {
47
+ const json = await Modules.Client.getUserPreferenceTopic(this.clientId, props.topicId);
48
+ const rawData = JSON.parse(json);
49
+
50
+ const convertedTopic: CourierUserPreferencesTopic = {
51
+ defaultStatus: rawData.default_status as CourierUserPreferencesStatus,
52
+ hasCustomRouting: rawData.has_custom_routing,
53
+ customRouting: rawData.custom_routing.map((channel: string) => channel as CourierUserPreferencesChannel),
54
+ status: rawData.status as CourierUserPreferencesStatus,
55
+ topicId: rawData.topic_id,
56
+ topicName: rawData.topic_name,
57
+ sectionName: rawData.section_name,
58
+ sectionId: rawData.section_id
59
+ };
60
+
61
+ return convertedTopic;
62
+ }
63
+
64
+ /**
65
+ * Updates user preference for a specific topic.
66
+ * @param props - Properties for updating the user preference topic.
67
+ * @param props.topicId - The ID of the topic to update preferences for.
68
+ * @param props.status - The new status for the topic preference.
69
+ * @param props.hasCustomRouting - Whether the topic has custom routing.
70
+ * @param props.customRouting - Array of custom routing channels.
71
+ * @returns A promise that resolves when the update is complete.
72
+ */
73
+ public async putUserPreferenceTopic(props: { topicId: string, status: CourierUserPreferencesStatus, hasCustomRouting: boolean, customRouting: CourierUserPreferencesChannel[] }): Promise<void> {
74
+ await Modules.Client.putUserPreferenceTopic(this.clientId, props.topicId, props.status, props.hasCustomRouting, props.customRouting);
75
+ }
76
+
77
+ }
@@ -0,0 +1,34 @@
1
+ import { CourierDevice } from "..";
2
+ import { Modules } from "../Modules";
3
+
4
+ export class TokenClient {
5
+
6
+ readonly clientId: string;
7
+
8
+ constructor(clientId: string) {
9
+ this.clientId = clientId;
10
+ }
11
+
12
+ /**
13
+ * Stores a user token for a specific provider.
14
+ * @param props - The properties for storing the user token.
15
+ * @param props.token - The token to be stored.
16
+ * @param props.provider - The provider associated with the token.
17
+ * @param props.device - Optional device information.
18
+ * @returns A promise that resolves when the token is successfully stored.
19
+ */
20
+ public async putUserToken(props: { token: string, provider: string, device?: CourierDevice }): Promise<void> {
21
+ await Modules.Client.putUserToken(this.clientId, props.token, props.provider, props.device);
22
+ }
23
+
24
+ /**
25
+ * Deletes a user token.
26
+ * @param props - The properties for deleting the user token.
27
+ * @param props.token - The token to be deleted.
28
+ * @returns A promise that resolves when the token is successfully deleted.
29
+ */
30
+ public async deleteUserToken(props: { token: string }): Promise<void> {
31
+ await Modules.Client.deleteUserToken(this.clientId, props.token);
32
+ }
33
+
34
+ }
@@ -0,0 +1,23 @@
1
+ import { CourierTrackingEvent } from "..";
2
+ import { Modules } from "../Modules";
3
+
4
+ export class TrackingClient {
5
+
6
+ readonly clientId: string;
7
+
8
+ constructor(clientId: string) {
9
+ this.clientId = clientId;
10
+ }
11
+
12
+ /**
13
+ * Posts a tracking URL with associated event data.
14
+ * @param props - The properties for posting the tracking URL.
15
+ * @param props.url - The tracking URL to be posted.
16
+ * @param props.event - The CourierTrackingEvent associated with the URL.
17
+ * @returns A promise that resolves when the tracking URL is successfully posted.
18
+ */
19
+ public async postTrackingUrl(props: { url: string, event: CourierTrackingEvent }): Promise<void> {
20
+ await Modules.Client.postTrackingUrl(this.clientId, props.url, props.event);
21
+ }
22
+
23
+ }