@trycourier/courier-react-native 2.0.2 → 2.1.0

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 (62) hide show
  1. package/README.md +37 -8
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +50 -0
  4. package/android/src/main/java/com/courierreactnative/Extensions.kt +51 -3
  5. package/courier-react-native.podspec +1 -1
  6. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +3 -0
  7. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/xcuserdata/mike.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  8. package/ios/CourierReactNativeModule.m +27 -0
  9. package/ios/CourierReactNativeModule.swift +51 -15
  10. package/ios/CourierReactNativeViewManager.swift +0 -123
  11. package/ios/Utils.swift +199 -0
  12. package/lib/commonjs/hooks/CourierProvider.js +8 -12
  13. package/lib/commonjs/hooks/CourierProvider.js.map +1 -1
  14. package/lib/commonjs/index.js +35 -0
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/models/CourierPaging.js +2 -0
  17. package/lib/commonjs/models/CourierPaging.js.map +1 -0
  18. package/lib/commonjs/models/CourierUserPreferences.js +6 -0
  19. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -0
  20. package/lib/commonjs/models/CourierUserPreferencesChannel.js +17 -0
  21. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +1 -0
  22. package/lib/commonjs/models/CourierUserPreferencesStatus.js +15 -0
  23. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +1 -0
  24. package/lib/commonjs/models/CourierUserPreferencesTopic.js +6 -0
  25. package/lib/commonjs/models/CourierUserPreferencesTopic.js.map +1 -0
  26. package/lib/module/hooks/CourierProvider.js +8 -12
  27. package/lib/module/hooks/CourierProvider.js.map +1 -1
  28. package/lib/module/index.js +23 -0
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/models/CourierPaging.js +2 -0
  31. package/lib/module/models/CourierPaging.js.map +1 -0
  32. package/lib/module/models/CourierUserPreferences.js +2 -0
  33. package/lib/module/models/CourierUserPreferences.js.map +1 -0
  34. package/lib/module/models/CourierUserPreferencesChannel.js +10 -0
  35. package/lib/module/models/CourierUserPreferencesChannel.js.map +1 -0
  36. package/lib/module/models/CourierUserPreferencesStatus.js +8 -0
  37. package/lib/module/models/CourierUserPreferencesStatus.js.map +1 -0
  38. package/lib/module/models/CourierUserPreferencesTopic.js +2 -0
  39. package/lib/module/models/CourierUserPreferencesTopic.js.map +1 -0
  40. package/lib/typescript/index.d.ts +27 -0
  41. package/lib/typescript/index.d.ts.map +1 -1
  42. package/lib/typescript/models/CourierPaging.d.ts +5 -0
  43. package/lib/typescript/models/CourierPaging.d.ts.map +1 -0
  44. package/lib/typescript/models/CourierUserPreferences.d.ts +7 -0
  45. package/lib/typescript/models/CourierUserPreferences.d.ts.map +1 -0
  46. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +9 -0
  47. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +1 -0
  48. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +7 -0
  49. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +1 -0
  50. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +11 -0
  51. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -0
  52. package/lib/typescript/views/CourierInboxView.d.ts +3 -3
  53. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -1
  54. package/package.json +4 -2
  55. package/src/hooks/CourierProvider.tsx +9 -9
  56. package/src/index.tsx +27 -0
  57. package/src/models/CourierPaging.tsx +4 -0
  58. package/src/models/CourierUserPreferences.tsx +7 -0
  59. package/src/models/CourierUserPreferencesChannel.tsx +8 -0
  60. package/src/models/CourierUserPreferencesStatus.tsx +6 -0
  61. package/src/models/CourierUserPreferencesTopic.tsx +11 -0
  62. package/src/views/CourierInboxView.tsx +3 -3
@@ -0,0 +1,7 @@
1
+ import { CourierPaging } from "./CourierPaging";
2
+ import { CourierUserPreferencesTopic } from "./CourierUserPreferencesTopic";
3
+ export interface CourierUserPreferences {
4
+ items?: CourierUserPreferencesTopic[];
5
+ paging?: CourierPaging;
6
+ }
7
+ //# sourceMappingURL=CourierUserPreferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CourierUserPreferences.d.ts","sourceRoot":"","sources":["../../../src/models/CourierUserPreferences.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,2BAA2B,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB"}
@@ -0,0 +1,9 @@
1
+ export declare enum CourierUserPreferencesChannel {
2
+ DirectMessage = "direct_message",
3
+ Email = "email",
4
+ Push = "push",
5
+ SMS = "sms",
6
+ Webhook = "webhook",
7
+ Unknown = "unknown"
8
+ }
9
+ //# sourceMappingURL=CourierUserPreferencesChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CourierUserPreferencesChannel.d.ts","sourceRoot":"","sources":["../../../src/models/CourierUserPreferencesChannel.tsx"],"names":[],"mappings":"AAAA,oBAAY,6BAA6B;IACvC,aAAa,mBAAmB;IAChC,KAAK,UAAU;IACf,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB"}
@@ -0,0 +1,7 @@
1
+ export declare enum CourierUserPreferencesStatus {
2
+ OptedIn = "OPTED_IN",
3
+ OptedOut = "OPTED_OUT",
4
+ Required = "REQUIRED",
5
+ Unknown = "UNKNOWN"
6
+ }
7
+ //# sourceMappingURL=CourierUserPreferencesStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CourierUserPreferencesStatus.d.ts","sourceRoot":"","sources":["../../../src/models/CourierUserPreferencesStatus.tsx"],"names":[],"mappings":"AAAA,oBAAY,4BAA4B;IACtC,OAAO,aAAa;IACpB,QAAQ,cAAc;IACtB,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB"}
@@ -0,0 +1,11 @@
1
+ import { CourierUserPreferencesChannel } from "./CourierUserPreferencesChannel";
2
+ import { CourierUserPreferencesStatus } from "./CourierUserPreferencesStatus";
3
+ export interface CourierUserPreferencesTopic {
4
+ defaultStatus?: string;
5
+ hasCustomRouting?: string;
6
+ customRouting?: CourierUserPreferencesChannel[];
7
+ status?: CourierUserPreferencesStatus;
8
+ topicId?: string;
9
+ topicName?: string;
10
+ }
11
+ //# sourceMappingURL=CourierUserPreferencesTopic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CourierUserPreferencesTopic.d.ts","sourceRoot":"","sources":["../../../src/models/CourierUserPreferencesTopic.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,MAAM,WAAW,2BAA2B;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,6BAA6B,EAAE,CAAC;IAChD,MAAM,CAAC,EAAE,4BAA4B,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  import { 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";
3
+ import CourierInboxTheme from "../models/CourierInboxTheme";
4
+ import { InboxAction } from "../models/InboxAction";
5
+ import { InboxMessage } from "../models/InboxMessage";
6
6
  type CourierInboxViewProps = {
7
7
  theme?: {
8
8
  light?: CourierInboxTheme;
@@ -1 +1 @@
1
- {"version":3,"file":"CourierInboxView.d.ts","sourceRoot":"","sources":["../../../src/views/CourierInboxView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAA+C,SAAS,EAA2C,MAAM,cAAc,CAAC;AAC/H,OAAO,iBAAiB,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,KAAK,qBAAqB,GAAG;IAC3B,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,iBAAiB,CAAC;QAC1B,IAAI,CAAC,EAAE,iBAAiB,CAAA;KACzB,CAAC;IACF,0BAA0B,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5E,mCAAmC,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1G,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAiBF,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,sBAiG5D,CAAA"}
1
+ {"version":3,"file":"CourierInboxView.d.ts","sourceRoot":"","sources":["../../../src/views/CourierInboxView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAA+C,SAAS,EAA2C,MAAM,cAAc,CAAC;AAC/H,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,KAAK,qBAAqB,GAAG;IAC3B,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,iBAAiB,CAAC;QAC1B,IAAI,CAAC,EAAE,iBAAiB,CAAA;KACzB,CAAC;IACF,0BAA0B,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5E,mCAAmC,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1G,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAiBF,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,sBAiG5D,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Inbox & Push Notifications for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -36,7 +36,9 @@
36
36
  "build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
37
37
  "build:ios": "cd example/ios && xcodebuild -workspace CourierReactNativeExample.xcworkspace -scheme CourierReactNativeExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
38
38
  "bootstrap": "yarn example && yarn install && yarn example pods",
39
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
40
+ "linkPackage": "yarn link && yarn example link @trycourier/courier-react-native && yarn example setupEnv",
41
+ "setup": "sh setup.sh"
40
42
  },
41
43
  "keywords": [
42
44
  "react-native",
@@ -82,12 +82,6 @@ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children })
82
82
  const userId = Courier.shared.userId;
83
83
  auth_setUserId(userId);
84
84
 
85
- // Permissions
86
- syncNotificationPermissions();
87
-
88
- // Push tokens
89
- syncTokens();
90
-
91
85
  }, []);
92
86
 
93
87
  useEffect(() => {
@@ -114,6 +108,12 @@ export const CourierProvider: React.FC<{ children: ReactNode }> = ({ children })
114
108
 
115
109
  const startPush = () => {
116
110
 
111
+ // Permissions
112
+ syncNotificationPermissions();
113
+
114
+ // Push tokens
115
+ syncTokens();
116
+
117
117
  if (!pushListener) {
118
118
 
119
119
  pushListener = Courier.shared.addPushNotificationListener({
@@ -321,7 +321,7 @@ export const useCourierPush = (props: UseCourierPushProps = {}): CourierPushCont
321
321
  // Set the presentation options
322
322
  const options = props.iOSForegroundPresentationOptions;
323
323
  if (options) {
324
- context.push?.iOSForegroundPresentationOptions(options);
324
+ context.push.iOSForegroundPresentationOptions(options);
325
325
  }
326
326
 
327
327
  context.push.start();
@@ -346,10 +346,10 @@ export const useCourierInbox = (props: UseCourierInboxProps = {}): CourierInboxC
346
346
  // Set the initial pagination limit if needed
347
347
  const limit = props.paginationLimit;
348
348
  if (limit) {
349
- context.inbox?.setPaginationLimit(limit);
349
+ context.inbox.setPaginationLimit(limit);
350
350
  }
351
351
 
352
- context.inbox?.start();
352
+ context.inbox.start();
353
353
 
354
354
  return context.inbox;
355
355
 
package/src/index.tsx CHANGED
@@ -11,6 +11,10 @@ import { CourierInboxListener } from './models/CourierInboxListener';
11
11
  import { CourierPushListener } from './models/CourierPushListener';
12
12
  import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
13
13
  import { InboxMessage } from './models/InboxMessage';
14
+ import { CourierUserPreferences } from './models/CourierUserPreferences';
15
+ import { CourierUserPreferencesTopic } from './models/CourierUserPreferencesTopic';
16
+ import { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
17
+ import { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
14
18
 
15
19
  // Exports
16
20
  export { CourierInboxView } from './views/CourierInboxView';
@@ -18,6 +22,8 @@ export { CourierProvider, useCourierAuth, useCourierPush, useCourierInbox } from
18
22
  export { CourierInboxListener } from './models/CourierInboxListener';
19
23
  export { CourierPushListener } from './models/CourierPushListener';
20
24
  export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
25
+ export { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
26
+ export { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
21
27
  export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
22
28
 
23
29
  const LINKING_ERROR =
@@ -379,6 +385,27 @@ class Courier {
379
385
  CourierReactNativeModules.setInboxPaginationLimit(props.limit);
380
386
  }
381
387
 
388
+ /**
389
+ * Get all available preferences
390
+ */
391
+ public async getUserPreferences(props?: { paginationCursor: string }): Promise<CourierUserPreferences> {
392
+ return CourierReactNativeModules.getUserPreferences(props?.paginationCursor ?? "");
393
+ }
394
+
395
+ /**
396
+ * Get individual preferences topic
397
+ */
398
+ public async getUserPreferencesTopic(props: { topicId: string }): Promise<CourierUserPreferencesTopic> {
399
+ return CourierReactNativeModules.getUserPreferencesTopic(props.topicId);
400
+ }
401
+
402
+ /**
403
+ * Update individual preferences topic
404
+ */
405
+ public async putUserPreferencesTopic(props: { topicId: string, status: CourierUserPreferencesStatus, hasCustomRouting: boolean, customRouting: CourierUserPreferencesChannel[] }): Promise<void> {
406
+ return CourierReactNativeModules.putUserPreferencesTopic(props.topicId, props.status, props.hasCustomRouting, props.customRouting);
407
+ }
408
+
382
409
  }
383
410
 
384
411
  export default Courier;
@@ -0,0 +1,4 @@
1
+ export interface CourierPaging {
2
+ cursor?: string;
3
+ more: boolean;
4
+ }
@@ -0,0 +1,7 @@
1
+ import { CourierPaging } from "./CourierPaging";
2
+ import { CourierUserPreferencesTopic } from "./CourierUserPreferencesTopic";
3
+
4
+ export interface CourierUserPreferences {
5
+ items?: CourierUserPreferencesTopic[];
6
+ paging?: CourierPaging;
7
+ }
@@ -0,0 +1,8 @@
1
+ export enum CourierUserPreferencesChannel {
2
+ DirectMessage = 'direct_message',
3
+ Email = 'email',
4
+ Push = 'push',
5
+ SMS = 'sms',
6
+ Webhook = 'webhook',
7
+ Unknown = 'unknown'
8
+ }
@@ -0,0 +1,6 @@
1
+ export enum CourierUserPreferencesStatus {
2
+ OptedIn = "OPTED_IN",
3
+ OptedOut = "OPTED_OUT",
4
+ Required = "REQUIRED",
5
+ Unknown = "UNKNOWN"
6
+ }
@@ -0,0 +1,11 @@
1
+ import { CourierUserPreferencesChannel } from "./CourierUserPreferencesChannel";
2
+ import { CourierUserPreferencesStatus } from "./CourierUserPreferencesStatus";
3
+
4
+ export interface CourierUserPreferencesTopic {
5
+ defaultStatus?: string;
6
+ hasCustomRouting?: string;
7
+ customRouting?: CourierUserPreferencesChannel[];
8
+ status?: CourierUserPreferencesStatus;
9
+ topicId?: string;
10
+ topicName?: string;
11
+ }
@@ -1,8 +1,8 @@
1
1
  import React, { useEffect } from "react";
2
2
  import { Platform, requireNativeComponent, UIManager, ViewStyle, DeviceEventEmitter, EmitterSubscription } from "react-native";
3
- import CourierInboxTheme from "src/models/CourierInboxTheme";
4
- import { InboxAction } from "src/models/InboxAction";
5
- import { InboxMessage } from "src/models/InboxMessage";
3
+ import CourierInboxTheme from "../models/CourierInboxTheme";
4
+ import { InboxAction } from "../models/InboxAction";
5
+ import { InboxMessage } from "../models/InboxMessage";
6
6
 
7
7
  type CourierInboxViewProps = {
8
8
  theme?: {