notifly-sdk 3.1.2 → 3.2.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 (64) hide show
  1. package/android/build.gradle +6 -6
  2. package/android/gradle.properties +5 -5
  3. package/android/src/main/AndroidManifest.xml +1 -1
  4. package/android/src/main/java/{com/notiflysdk → tech/notifly/rn}/NotiflySdkModule.kt +52 -14
  5. package/android/src/main/java/{com/notiflysdk → tech/notifly/rn}/NotiflySdkPackage.kt +1 -1
  6. package/android/src/main/java/tech/notifly/rn/NotiflySdkUtils.kt +79 -0
  7. package/android/src/newarch/NotiflySdkSpec.kt +1 -1
  8. package/android/src/oldarch/NotiflySdkSpec.kt +2 -2
  9. package/ios/NotiflySdk.m +1 -5
  10. package/ios/NotiflySdk.swift +3 -8
  11. package/lib/commonjs/{NativeNotiflySdk.js → NativeNotiflyReactNativeSdk.js} +2 -2
  12. package/lib/commonjs/NativeNotiflyReactNativeSdk.js.map +1 -0
  13. package/lib/commonjs/constants.js +12 -0
  14. package/lib/commonjs/constants.js.map +1 -0
  15. package/lib/commonjs/events/EventReceiver.js +60 -0
  16. package/lib/commonjs/events/EventReceiver.js.map +1 -0
  17. package/lib/commonjs/index.js +29 -45
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/types/index.js +17 -0
  20. package/lib/commonjs/types/index.js.map +1 -0
  21. package/lib/commonjs/types/notification.js +14 -0
  22. package/lib/commonjs/types/notification.js.map +1 -0
  23. package/lib/module/NativeNotiflyReactNativeSdk.js +3 -0
  24. package/lib/module/NativeNotiflyReactNativeSdk.js.map +1 -0
  25. package/lib/module/constants.js +5 -0
  26. package/lib/module/constants.js.map +1 -0
  27. package/lib/module/events/EventReceiver.js +53 -0
  28. package/lib/module/events/EventReceiver.js.map +1 -0
  29. package/lib/module/index.js +27 -41
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/module/types/index.js +2 -0
  32. package/lib/module/types/index.js.map +1 -0
  33. package/lib/module/types/notification.js +7 -0
  34. package/lib/module/types/notification.js.map +1 -0
  35. package/lib/typescript/{NativeNotiflySdk.d.ts → NativeNotiflyReactNativeSdk.d.ts} +5 -8
  36. package/lib/typescript/NativeNotiflyReactNativeSdk.d.ts.map +1 -0
  37. package/lib/typescript/constants.d.ts +4 -0
  38. package/lib/typescript/constants.d.ts.map +1 -0
  39. package/lib/typescript/events/EventReceiver.d.ts +11 -0
  40. package/lib/typescript/events/EventReceiver.d.ts.map +1 -0
  41. package/lib/typescript/index.d.ts +6 -16
  42. package/lib/typescript/index.d.ts.map +1 -1
  43. package/lib/typescript/types/index.d.ts +13 -0
  44. package/lib/typescript/types/index.d.ts.map +1 -0
  45. package/lib/typescript/types/notification.d.ts +28 -0
  46. package/lib/typescript/types/notification.d.ts.map +1 -0
  47. package/package.json +5 -5
  48. package/src/{NativeNotiflySdk.ts → NativeNotiflyReactNativeSdk.ts} +5 -10
  49. package/src/constants.ts +3 -0
  50. package/src/events/EventReceiver.ts +67 -0
  51. package/src/index.tsx +59 -56
  52. package/src/types/index.ts +15 -0
  53. package/src/types/notification.ts +40 -0
  54. package/lib/commonjs/NativeNotiflySdk.js.map +0 -1
  55. package/lib/commonjs/types.js +0 -2
  56. package/lib/commonjs/types.js.map +0 -1
  57. package/lib/module/NativeNotiflySdk.js +0 -3
  58. package/lib/module/NativeNotiflySdk.js.map +0 -1
  59. package/lib/module/types.js +0 -2
  60. package/lib/module/types.js.map +0 -1
  61. package/lib/typescript/NativeNotiflySdk.d.ts.map +0 -1
  62. package/lib/typescript/types.d.ts +0 -7
  63. package/lib/typescript/types.d.ts.map +0 -1
  64. package/src/types.ts +0 -7
package/src/index.tsx CHANGED
@@ -1,5 +1,15 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
- import { type UserProperties, type EventProperties } from './types';
2
+ import type {
3
+ InitializeParams,
4
+ EventProperties,
5
+ UserProperties,
6
+ NotificationClickListener,
7
+ OSNotificationClickEvent,
8
+ } from './types';
9
+ import EventReceiver from './events/EventReceiver';
10
+ import { EventNames } from './constants';
11
+
12
+ export type * from './types';
3
13
 
4
14
  const LINKING_ERROR =
5
15
  `The package 'notifly-sdk' doesn't seem to be linked. Make sure: \n\n` +
@@ -10,12 +20,12 @@ const LINKING_ERROR =
10
20
  // @ts-expect-error
11
21
  const isTurboModuleEnabled = global.__turboModuleProxy != null;
12
22
 
13
- const NotiflySdkModule = isTurboModuleEnabled
14
- ? require('./NativeNotiflySdk').default
15
- : NativeModules.NotiflySdk;
23
+ const NotiflyReactNativeSdkModule = isTurboModuleEnabled
24
+ ? require('./NativeNotiflyReactNativeSdk').default
25
+ : NativeModules.NotiflyReactNativeSdk;
16
26
 
17
- const NotiflySdk = NotiflySdkModule
18
- ? NotiflySdkModule
27
+ const NotiflyReactNativeSdk = NotiflyReactNativeSdkModule
28
+ ? NotiflyReactNativeSdkModule
19
29
  : new Proxy(
20
30
  {},
21
31
  {
@@ -25,31 +35,27 @@ const NotiflySdk = NotiflySdkModule
25
35
  }
26
36
  );
27
37
 
28
- export function multiply(a: number, b: number): Promise<number> {
29
- return NotiflySdk.multiply(a, b);
30
- }
38
+ const eventReceiver =
39
+ NotiflyReactNativeSdkModule && Platform.OS === 'android'
40
+ ? new EventReceiver(NotiflyReactNativeSdkModule)
41
+ : null;
31
42
 
32
- export function initialize(
33
- projectId: string,
34
- username: string,
35
- password: string,
36
- useCustomClickHandler: boolean | undefined = undefined
37
- ): Promise<void> {
38
- // @deprecated useCustomClickHandler is deprecated since version 2.3.0
39
- if (typeof useCustomClickHandler !== 'undefined') {
40
- console.warn(
41
- 'Warning: useCustomClickHandler of notifly.initialize is deprecated and will be removed in the next major release.'
42
- );
43
- }
44
- return NotiflySdk.initialize(projectId, username, password);
43
+ let isNativeNotificationClickListenerRegistered = false;
44
+
45
+ export function initialize(params: InitializeParams): Promise<void> {
46
+ return NotiflyReactNativeSdk.initialize(
47
+ params.projectId,
48
+ params.username,
49
+ params.password
50
+ );
45
51
  }
46
52
 
47
- export function setUserId(userId: string | undefined): Promise<void> {
48
- return NotiflySdk.setUserId(userId);
53
+ export function setUserId(userId: string | null | undefined): Promise<void> {
54
+ return NotiflyReactNativeSdk.setUserId(userId);
49
55
  }
50
56
 
51
57
  export function setUserProperties(properties: UserProperties): Promise<void> {
52
- return NotiflySdk.setUserProperties(properties);
58
+ return NotiflyReactNativeSdk.setUserProperties(properties);
53
59
  }
54
60
 
55
61
  export function trackEvent(
@@ -57,7 +63,7 @@ export function trackEvent(
57
63
  eventParams: EventProperties | null | undefined = undefined,
58
64
  segmentationEventParamKeys: string[] | undefined | null = null
59
65
  ): Promise<void> {
60
- return NotiflySdk.trackEvent(
66
+ return NotiflyReactNativeSdk.trackEvent(
61
67
  eventName,
62
68
  eventParams,
63
69
  segmentationEventParamKeys
@@ -67,41 +73,40 @@ export function trackEvent(
67
73
  export function setLogLevel(logLevel: number): Promise<void> {
68
74
  // only implemented on Android
69
75
  if (Platform.OS === 'android') {
70
- return NotiflySdk.setLogLevel(logLevel);
76
+ return NotiflyReactNativeSdk.setLogLevel(logLevel);
77
+ } else {
78
+ console.error(
79
+ '[Notifly React Native SDK] setLogLevel is only supported on Android.'
80
+ );
71
81
  }
72
82
  return Promise.resolve();
73
83
  }
74
84
 
75
- /**
76
- * @deprecated Since version 2.3.0.
77
- */
78
- export function notiflyBackgroundHandler(_remoteMessage: any): Promise<void> {
79
- console.warn(
80
- 'Warning: notifly.notiflyBackgroundHandler(remoteMessage) is deprecated and will be removed in the next major release. You do not need to call this method anymore. remoteMessage is now handled automatically.'
81
- );
82
- return Promise.resolve();
83
- }
84
-
85
- /**
86
- * @deprecated Since version 2.3.0.
87
- */
88
- export function setNotiflyBackgroundMessageHandler(): Promise<void> {
89
- console.warn(
90
- 'Warning: notifly.setNotiflyBackgroundMessageHandler() is deprecated and will be removed in the next major release. You do not need to call this method anymore. remoteMessage is now handled automatically.'
91
- );
92
- return Promise.resolve();
93
- }
94
-
95
85
  export function disableInAppMessage(): Promise<void> {
96
- return NotiflySdk.disableInAppMessage();
86
+ return NotiflyReactNativeSdk.disableInAppMessage();
97
87
  }
98
88
 
99
- export function registerFCMToken(token: string): Promise<void> {
100
- if (Platform.OS === 'android') {
101
- console.warn('Warning: registerFCMToken is only supported on iOS.');
102
- return Promise.resolve();
89
+ export function addNotificationClickListener(
90
+ listener: NotificationClickListener
91
+ ): Promise<void> {
92
+ if (eventReceiver) {
93
+ // only implemented on Android
94
+ eventReceiver.addEventListener<OSNotificationClickEvent>(
95
+ EventNames.NOTIFICATION_CLICKED,
96
+ listener
97
+ );
98
+
99
+ if (!isNativeNotificationClickListenerRegistered) {
100
+ NotiflyReactNativeSdk.addNotificationClickListener();
101
+ isNativeNotificationClickListenerRegistered = true;
102
+ }
103
+ } else {
104
+ console.error(
105
+ '[Notifly React Native SDK] addNotificationClickListener is only supported on Android.'
106
+ );
103
107
  }
104
- return NotiflySdk.registerFCMToken(token);
108
+
109
+ return Promise.resolve();
105
110
  }
106
111
 
107
112
  const notifly = {
@@ -110,10 +115,8 @@ const notifly = {
110
115
  setUserProperties,
111
116
  trackEvent,
112
117
  setLogLevel,
113
- notiflyBackgroundHandler,
114
- setNotiflyBackgroundMessageHandler,
115
118
  disableInAppMessage,
116
- registerFCMToken,
119
+ addNotificationClickListener,
117
120
  };
118
121
 
119
122
  export default notifly;
@@ -0,0 +1,15 @@
1
+ export * from './notification';
2
+
3
+ export interface InitializeParams {
4
+ projectId: string;
5
+ username: string;
6
+ password: string;
7
+ }
8
+
9
+ export interface UserProperties {
10
+ [key: string]: any;
11
+ }
12
+
13
+ export interface EventProperties {
14
+ [key: string]: any;
15
+ }
@@ -0,0 +1,40 @@
1
+ export type NotificationClickListener = (
2
+ event: OSNotificationClickEvent
3
+ ) => void;
4
+
5
+ export enum OSNotificationImportance {
6
+ LOW = 0,
7
+ NORMAL = 1,
8
+ HIGH = 2,
9
+ }
10
+
11
+ export interface OSNotificationClickEvent {
12
+ notification: OSNotification;
13
+ }
14
+
15
+ export interface OSNotification {
16
+ // The Notifly message ID of the notification.
17
+ notiflyMessageId?: string;
18
+ // (Only Android) The Android system notification ID of the notification.
19
+ androidNotificationId?: number;
20
+ // Notifly campaign ID where the notification was sent from.
21
+ campaignId?: string;
22
+ // Notification title
23
+ title?: string;
24
+ // Notification body
25
+ body?: string;
26
+ // (Only Android) Importance of the notification.
27
+ importance?: OSNotificationImportance;
28
+ // URL included in the notification.
29
+ url?: string;
30
+ // URL to the image included in the notification.
31
+ imageUrl?: string;
32
+ // Sent time of the notification in milliseconds since epoch
33
+ sentTime?: number;
34
+ // TTL of the notification in seconds
35
+ ttl?: number;
36
+ // Customized data included in the notification.
37
+ customData?: { [key: string]: any };
38
+ // Raw payload of the notification.
39
+ rawPayload?: { [key: string]: any };
40
+ }
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_default","TurboModuleRegistry","getEnforcing","exports","default"],"sourceRoot":"../../src","sources":["NativeNotiflySdk.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAyBpCC,gCAAmB,CAACC,YAAY,CAAO,YAAY,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAJ,QAAA"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":""}
@@ -1,3 +0,0 @@
1
- import { TurboModuleRegistry } from 'react-native';
2
- export default TurboModuleRegistry.getEnforcing('NotiflySdk');
3
- //# sourceMappingURL=NativeNotiflySdk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeNotiflySdk.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAyBlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,YAAY,CAAC"}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativeNotiflySdk.d.ts","sourceRoot":"","sources":["../../src/NativeNotiflySdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,qBAAqB,EAAE,OAAO,GAAG,SAAS,GACzC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EAC/C,0BAA0B,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,GACtD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,wBAAwB,CAAC,cAAc,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;;AAED,wBAAoE"}
@@ -1,7 +0,0 @@
1
- export interface UserProperties {
2
- [key: string]: any;
3
- }
4
- export interface EventProperties {
5
- [key: string]: any;
6
- }
7
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
package/src/types.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface UserProperties {
2
- [key: string]: any;
3
- }
4
-
5
- export interface EventProperties {
6
- [key: string]: any;
7
- }