react-native-netmera 1.4.8 → 1.5.0-alpha01

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.
@@ -16,8 +16,8 @@ android {
16
16
  }
17
17
 
18
18
  dependencies {
19
- implementation 'com.netmera:nmcore:3.9.10'
20
- implementation 'com.netmera:nmfcm:3.9.3'
19
+ implementation 'com.netmera:nmcore:3.9.12'
20
+ implementation 'com.netmera:nmfcm:3.9.4'
21
21
  implementation 'com.netmera:nmhms:3.9.5'
22
22
  implementation 'com.facebook.react:react-native:+'
23
23
  }
@@ -3,12 +3,19 @@ package com.netmera.reactnativesdk;
3
3
  import android.content.ContentValues;
4
4
  import android.content.Context;
5
5
 
6
+ import androidx.startup.AppInitializer;
7
+
6
8
  import com.netmera.Netmera;
7
9
  import com.netmera.NetmeraConfiguration;
10
+ import com.netmera.NMInitializer;
11
+ import com.netmera.NMMainModule;
12
+ import com.netmera.nmfcm.NMFCMProviderInitializer;
13
+ import com.netmera.nmhms.NMHMSProviderInitializer;
8
14
 
9
15
  public class RNNetmera {
10
16
 
11
17
  public static void initNetmera(RNNetmeraConfiguration netmeraConfiguration) {
18
+ checkNetmeraComponent(netmeraConfiguration.context);
12
19
  Netmera.init(netmeraConfiguration.getNetmeraConfiguration());
13
20
  setNetmeraHeaders();
14
21
  }
@@ -16,7 +23,15 @@ public class RNNetmera {
16
23
  static void setNetmeraHeaders() {
17
24
  ContentValues headerValues = new ContentValues();
18
25
  headerValues.put("X-netmera-framework", "react");
19
- headerValues.put("X-netmera-frameworkV", "1.4.8");
26
+ headerValues.put("X-netmera-frameworkV", "1.5.0-alpha");
20
27
  Netmera.setNetmeraHeaders(headerValues);
21
28
  }
29
+
30
+ private static void checkNetmeraComponent(Context context) {
31
+ if (NMMainModule.context == null) {
32
+ NMInitializer.initializeComponents(context);
33
+ AppInitializer.getInstance(context).initializeComponent(NMFCMProviderInitializer.class);
34
+ AppInitializer.getInstance(context).initializeComponent(NMHMSProviderInitializer.class);
35
+ }
36
+ }
22
37
  }
@@ -92,6 +92,16 @@ public class RNNetmeraModule extends ReactContextBaseJavaModule {
92
92
  Netmera.setBaseUrl(baseUrl);
93
93
  }
94
94
 
95
+ @ReactMethod(isBlockingSynchronousMethod = true)
96
+ public Boolean areNotificationsEnabled() {
97
+ return Netmera.areNotificationsEnabled();
98
+ }
99
+
100
+ @ReactMethod
101
+ public void requestPushNotificationAuthorization() {
102
+ Netmera.requestNotificationPermissions(reactContext.getCurrentActivity());
103
+ }
104
+
95
105
  @ReactMethod
96
106
  public void requestPermissionsForLocation() {
97
107
  Netmera.requestPermissionsForLocation();
package/index.ts ADDED
@@ -0,0 +1,28 @@
1
+ import Netmera from "./src/Netmera";
2
+ import NetmeraEvent from "./src/models/NetmeraEvent";
3
+ import NetmeraUser, {
4
+ NMUserGender,
5
+ NMUserMaritalStatus,
6
+ } from "./src/models/NetmeraUser";
7
+ import NetmeraCategory from "./src/models/NetmeraCategory";
8
+ import NetmeraCategoryFilter from "./src/models/NetmeraCategoryFilter";
9
+ import NetmeraPushInbox from "./src/models/NetmeraInbox";
10
+ import NetmeraInboxFilter from "./src/models/NetmeraInboxFilter";
11
+ import NMInboxStatusCountFilter from "./src/models/NMInboxStatusCountFilter";
12
+ import NMCategoryPreference from "./src/models/NMCategoryPreference";
13
+ import { NMInboxStatus } from "./src/models/NMInboxStatus";
14
+
15
+ export {
16
+ Netmera,
17
+ NetmeraEvent,
18
+ NetmeraUser,
19
+ NMUserGender,
20
+ NMUserMaritalStatus,
21
+ NetmeraPushInbox,
22
+ NetmeraInboxFilter,
23
+ NMInboxStatus,
24
+ NMInboxStatusCountFilter,
25
+ NetmeraCategory,
26
+ NetmeraCategoryFilter,
27
+ NMCategoryPreference,
28
+ };
package/ios/RNNetmera.m CHANGED
@@ -46,7 +46,7 @@ NSString *const ERROR_MESSAGE_SET_CATEGORY_PREFERENCE = @"Error occurred while s
46
46
 
47
47
  + (void)setNetmeraHeaders {
48
48
  [Netmera setFramework:@"react"];
49
- [Netmera setFrameworkVersion:@"1.4.8"];
49
+ [Netmera setFrameworkVersion:@"1.5.0-alpha"];
50
50
  }
51
51
 
52
52
  + (void)setPushDelegate:(NSObject<NetmeraPushDelegate> *)delegate {
@@ -91,6 +91,10 @@ RCT_EXPORT_METHOD(requestPushNotificationAuthorization) {
91
91
  [Netmera requestPushNotificationAuthorizationForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound];
92
92
  }
93
93
 
94
+ RCT_EXPORT_METHOD(areNotificationsEnabled:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
95
+ resolve(@([Netmera isEnabledReceivingPushNotifications]));
96
+ }
97
+
94
98
  RCT_EXPORT_METHOD(requestPermissionsForLocation) {
95
99
  [Netmera requestLocationAuthorization];
96
100
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "react-native-netmera",
3
- "version": "1.4.8",
3
+ "version": "1.5.0-alpha01",
4
4
  "description": "Netmera React Native SDK",
5
- "main": "index.js",
5
+ "main": "index.ts",
6
6
  "author": "netmera",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -13,5 +13,15 @@
13
13
  "android",
14
14
  "netmera"
15
15
  ],
16
- "license": ""
16
+ "license": "",
17
+ "devDependencies": {
18
+ "@tsconfig/react-native": "^2.0.3",
19
+ "@types/jest": "^29.5.0",
20
+ "@types/react": "^18.0.30",
21
+ "@types/react-native": "^0.71.5",
22
+ "@types/react-test-renderer": "^18.0.0",
23
+ "eslint": "^8.39.0",
24
+ "prettier": "^2.8.7",
25
+ "typescript": "^5.0.2"
26
+ }
17
27
  }
package/src/Netmera.ts ADDED
@@ -0,0 +1,257 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ import {
6
+ AppRegistry,
7
+ NativeEventEmitter,
8
+ NativeModules,
9
+ NativeModulesStatic,
10
+ Platform,
11
+ } from "react-native";
12
+ import NetmeraUser from "./models/NetmeraUser";
13
+ import NetmeraEvent from "./models/NetmeraEvent";
14
+ import NetmeraInboxFilter from "./models/NetmeraInboxFilter";
15
+ import NetmeraPushInbox from "./models/NetmeraInbox";
16
+ import NetmeraCategoryFilter from "./models/NetmeraCategoryFilter";
17
+ import NetmeraCategory from "./models/NetmeraCategory";
18
+ import NMInboxStatusCountFilter from "./models/NMInboxStatusCountFilter";
19
+ import NMCategoryPreference from "./models/NMCategoryPreference";
20
+ import { NMInboxStatus } from "./models/NMInboxStatus";
21
+
22
+ const { RNNetmera, RNNetmeraRCTEventEmitter }: NativeModulesStatic =
23
+ NativeModules;
24
+ const netmeraRCTEventEmitter: NativeEventEmitter = new NativeEventEmitter(
25
+ RNNetmeraRCTEventEmitter
26
+ );
27
+
28
+ export default class Netmera {
29
+ static initBroadcastReceiver = (
30
+ onPushRegister?: (message: string) => Promise<void>,
31
+ onPushReceive?: (message: string) => Promise<void>,
32
+ onPushOpen?: (message: string) => Promise<void>,
33
+ onPushDismiss?: (message: string) => Promise<void>,
34
+ onPushButtonClicked?: (message: string) => Promise<void>,
35
+ onCarouselObjectSelected?: (message: string) => Promise<void>
36
+ ) => {
37
+ if (onPushRegister) {
38
+ if (Platform.OS === "android") {
39
+ AppRegistry.registerHeadlessTask(
40
+ "onPushRegister",
41
+ () => onPushRegister
42
+ );
43
+ } else {
44
+ netmeraRCTEventEmitter.addListener("onPushRegister", onPushRegister);
45
+ }
46
+ }
47
+ if (onPushReceive) {
48
+ if (Platform.OS === "android") {
49
+ AppRegistry.registerHeadlessTask("onPushReceive", () => onPushReceive);
50
+ } else {
51
+ netmeraRCTEventEmitter.addListener("onPushReceive", onPushReceive);
52
+ }
53
+ }
54
+ if (onPushOpen) {
55
+ if (Platform.OS === "android") {
56
+ AppRegistry.registerHeadlessTask("onPushOpen", () => onPushOpen);
57
+ } else {
58
+ netmeraRCTEventEmitter.addListener("onPushOpen", onPushOpen);
59
+ }
60
+ }
61
+ if (onPushDismiss) {
62
+ if (Platform.OS === "android") {
63
+ AppRegistry.registerHeadlessTask("onPushDismiss", () => onPushDismiss);
64
+ } else {
65
+ netmeraRCTEventEmitter.addListener("onPushDismiss", onPushDismiss);
66
+ }
67
+ }
68
+ if (onPushButtonClicked) {
69
+ if (Platform.OS === "android") {
70
+ AppRegistry.registerHeadlessTask(
71
+ "onPushButtonClicked",
72
+ () => onPushButtonClicked
73
+ );
74
+ }
75
+ }
76
+ if (onCarouselObjectSelected) {
77
+ if (Platform.OS === "android") {
78
+ AppRegistry.registerHeadlessTask(
79
+ "onCarouselObjectSelected",
80
+ () => onCarouselObjectSelected
81
+ );
82
+ }
83
+ }
84
+ };
85
+
86
+ static currentExternalId = async (): Promise<string> => {
87
+ return RNNetmera.currentExternalId();
88
+ };
89
+
90
+ static setBaseUrl = (baseUrl: string) => {
91
+ RNNetmera.setBaseUrl(baseUrl);
92
+ };
93
+
94
+ static areNotificationsEnabled = async (): Promise<boolean> => {
95
+ return RNNetmera.areNotificationsEnabled();
96
+ };
97
+
98
+ static requestPushNotificationAuthorization = () => {
99
+ RNNetmera.requestPushNotificationAuthorization();
100
+ };
101
+
102
+ static requestPermissionsForLocation = () => {
103
+ RNNetmera.requestPermissionsForLocation();
104
+ };
105
+
106
+ static setNetmeraMaxActiveRegions = (maxActiveRegions: number) => {
107
+ RNNetmera.setNetmeraMaxActiveRegions(maxActiveRegions);
108
+ };
109
+
110
+ static enablePopupPresentation = () => {
111
+ RNNetmera.enablePopupPresentation();
112
+ };
113
+
114
+ static disablePopupPresentation = () => {
115
+ RNNetmera.disablePopupPresentation();
116
+ };
117
+
118
+ static isPushEnabled = async (): Promise<boolean> => {
119
+ return RNNetmera.isPushEnabled();
120
+ };
121
+
122
+ static enablePush = () => {
123
+ RNNetmera.enablePush();
124
+ };
125
+
126
+ static disablePush = () => {
127
+ RNNetmera.disablePush();
128
+ };
129
+
130
+ static turnOffSendingEventAndUserUpdate = (turnOff: boolean) => {
131
+ if (Platform.OS === "android") {
132
+ RNNetmera.turnOffSendingEventAndUserUpdate(turnOff);
133
+ }
134
+ };
135
+
136
+ static fetchInbox = (
137
+ netmeraInboxFilter: NetmeraInboxFilter
138
+ ): Promise<Array<NetmeraPushInbox>> => {
139
+ return RNNetmera.fetchInbox(netmeraInboxFilter);
140
+ };
141
+
142
+ static fetchNextPage = (): Promise<Array<NetmeraPushInbox>> => {
143
+ return RNNetmera.fetchNextPage();
144
+ };
145
+
146
+ static countForStatus = (status: number = NMInboxStatus.STATUS_UNREAD) => {
147
+ return RNNetmera.countForStatus(status);
148
+ };
149
+
150
+ static inboxUpdateStatus = (
151
+ fromIndex: number,
152
+ toIndex: number,
153
+ status: number = NMInboxStatus.STATUS_UNREAD
154
+ ) => {
155
+ return RNNetmera.inboxUpdateStatus(fromIndex, toIndex, status);
156
+ };
157
+
158
+ static fetchCategory = (
159
+ categoryFilter: NetmeraCategoryFilter
160
+ ): Promise<Array<NetmeraCategory>> => {
161
+ return RNNetmera.fetchCategory(categoryFilter);
162
+ };
163
+
164
+ static fetchNextCategoryPage = (): Promise<Array<NetmeraCategory>> => {
165
+ return RNNetmera.fetchNextCategoryPage();
166
+ };
167
+
168
+ static sendEvent = (event: NetmeraEvent) => {
169
+ RNNetmera.sendEvent(event);
170
+ };
171
+
172
+ static updateUser = (user: NetmeraUser) => {
173
+ RNNetmera.updateUser(user);
174
+ };
175
+
176
+ static updateAll = (inboxStatus: number) => {
177
+ return RNNetmera.updateAll(inboxStatus);
178
+ };
179
+
180
+ static handlePushObject = (pushId: string) => {
181
+ RNNetmera.handlePushObject(pushId);
182
+ };
183
+
184
+ static handleInteractiveAction = (pushId: string) => {
185
+ RNNetmera.handleInteractiveAction(pushId);
186
+ };
187
+
188
+ static setApiKey = (apiKey: string) => {
189
+ RNNetmera.setApiKey(apiKey);
190
+ };
191
+
192
+ static handleLastMessage = (categoryName: string) => {
193
+ RNNetmera.handleLastMessage(categoryName);
194
+ };
195
+
196
+ static updateStatusByCategories = (
197
+ fromIndex: number,
198
+ toIndex: number,
199
+ status: number = NMInboxStatus.STATUS_UNREAD
200
+ ) => {
201
+ return RNNetmera.updateStatusByCategories(fromIndex, toIndex, status);
202
+ };
203
+
204
+ static getInboxCountForStatus = (
205
+ nmInboxStatusCountFilter: NMInboxStatusCountFilter
206
+ ) => {
207
+ return RNNetmera.getInboxCountForStatus(nmInboxStatusCountFilter);
208
+ };
209
+
210
+ static getUserCategoryPreferenceList = (): Promise<
211
+ Array<NMCategoryPreference>
212
+ > => {
213
+ return RNNetmera.getUserCategoryPreferenceList();
214
+ };
215
+
216
+ static setUserCategoryPreference = (
217
+ categoryId: number,
218
+ categoryEnabled: boolean
219
+ ) => {
220
+ return RNNetmera.setUserCategoryPreference(categoryId, categoryEnabled);
221
+ };
222
+
223
+ static onNetmeraFirebasePushMessageReceived = (
224
+ from?: string,
225
+ data?: { [key: string]: string }
226
+ ) => {
227
+ if (Platform.OS === "android" && data) {
228
+ data["google.c.sender.id"] = from ?? "";
229
+ RNNetmera.onNetmeraPushMessageReceived(data);
230
+ }
231
+ };
232
+
233
+ static onNetmeraHuaweiPushMessageReceived = (
234
+ from?: string,
235
+ data?: { [key: string]: string }
236
+ ) => {
237
+ if (Platform.OS === "android" && data) {
238
+ data["_nm"] = JSON.stringify(data["_nm"]);
239
+ data["from"] = from ?? "";
240
+ RNNetmera.onNetmeraPushMessageReceived(data);
241
+ }
242
+ };
243
+
244
+ static onNetmeraNewToken = (pushToken: string) => {
245
+ if (Platform.OS === "android") {
246
+ RNNetmera.onNetmeraNewToken(pushToken);
247
+ }
248
+ };
249
+
250
+ static isNetmeraRemoteMessage(data?: { [key: string]: string }): boolean {
251
+ return (
252
+ Platform.OS === "android" &&
253
+ data != undefined &&
254
+ data.hasOwnProperty("_nm")
255
+ );
256
+ }
257
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NMCategoryPreference {
6
+ categoryId?: number;
7
+ categoryName?: string;
8
+ optInStatus?: boolean;
9
+ }
@@ -0,0 +1,7 @@
1
+ export enum NMInboxStatus {
2
+ STATUS_READ = 1,
3
+ STATUS_UNREAD = 2,
4
+ STATUS_READ_OR_UNREAD = 3,
5
+ STATUS_DELETED = 4,
6
+ STATUS_ALL = 7,
7
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NMInboxStatusCountFilter {
6
+ status?: number;
7
+ categoryList?: number[];
8
+ includeExpired?: boolean;
9
+
10
+ set nmInboxStatus(nmInboxStatus: number) {
11
+ this.status = nmInboxStatus;
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ import NetmeraPushInbox from "./NetmeraInbox";
6
+
7
+ export default class NetmeraCategory {
8
+ categoryName?: string;
9
+ categoryStatus?: string;
10
+ lastMessage?: NetmeraPushInbox;
11
+ readCount?: number;
12
+ deletedCount?: number;
13
+ unreadCount?: number;
14
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NetmeraCategoryFilter {
6
+ pageSize?: number;
7
+ status?: number;
8
+ includeExpiredObjects?: boolean;
9
+ }
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default abstract class NetmeraEvent {
6
+ abstract code: string;
7
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NetmeraPushInbox {
6
+ title?: string;
7
+ subtitle?: string;
8
+ body?: string;
9
+ pushType?: number;
10
+ pushId?: string;
11
+ pushInstanceId?: string;
12
+ sendDate?: string;
13
+ inboxStatus?: number;
14
+ deepLink?: string;
15
+ webPage?: string;
16
+ externalId?: string;
17
+ customJson?: Map<any, any>;
18
+ pushAction?: Map<any, any>;
19
+ carousel?: any[];
20
+ mediaAttachmentURL?: string;
21
+ category?: string;
22
+ categories?: any[];
23
+ interactiveActions?: any[];
24
+ expireTime?: string;
25
+ }
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NetmeraInboxFilter {
6
+ pageSize?: number;
7
+ status?: number;
8
+ categories?: string[];
9
+ includeExpiredObjects?: boolean;
10
+ }
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Copyright (c) 2023 Netmera Research.
3
+ */
4
+
5
+ export default class NetmeraUser {
6
+ private pa?: string;
7
+ private pb?: string;
8
+ private pc?: string[];
9
+ private pd?: number;
10
+ private pe?: number;
11
+ private pf?: number;
12
+ private pg?: number;
13
+ private ph?: string;
14
+ private pi?: string;
15
+ private pj?: string;
16
+ private pk?: string;
17
+ private pl?: string;
18
+ private pm?: string;
19
+ private pn?: string;
20
+ private po?: string;
21
+ userId?: string;
22
+ msisdn?: string;
23
+ email?: string;
24
+
25
+ set name(value: string) {
26
+ this.pa = value;
27
+ }
28
+
29
+ set surname(value: string) {
30
+ this.pb = value;
31
+ }
32
+
33
+ set externalSegments(value: string[]) {
34
+ this.pc = value;
35
+ }
36
+
37
+ set gender(value: number) {
38
+ this.pd = value;
39
+ }
40
+
41
+ set dateOfBirth(value: number) {
42
+ this.pe = value;
43
+ }
44
+
45
+ set maritalStatus(value: number) {
46
+ this.pf = value;
47
+ }
48
+
49
+ set childCount(value: number) {
50
+ this.pg = value;
51
+ }
52
+
53
+ set country(value: string) {
54
+ this.ph = value;
55
+ }
56
+
57
+ set state(value: string) {
58
+ this.pi = value;
59
+ }
60
+
61
+ set city(value: string) {
62
+ this.pj = value;
63
+ }
64
+
65
+ set district(value: string) {
66
+ this.pk = value;
67
+ }
68
+
69
+ set occupation(value: string) {
70
+ this.pl = value;
71
+ }
72
+
73
+ set industry(value: string) {
74
+ this.pm = value;
75
+ }
76
+
77
+ set favoriteTeam(value: string) {
78
+ this.pn = value;
79
+ }
80
+
81
+ set language(value: string) {
82
+ this.po = value;
83
+ }
84
+ }
85
+
86
+ export enum NMUserGender {
87
+ MALE = 0,
88
+ FEMALE = 1,
89
+ NOT_SPECIFIED = 2,
90
+ }
91
+
92
+ export enum NMUserMaritalStatus {
93
+ SINGLE = 0,
94
+ MARRIED = 1,
95
+ NOT_SPECIFIED = 2,
96
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@tsconfig/react-native/tsconfig.json"
3
+ }
package/index.js DELETED
@@ -1,19 +0,0 @@
1
- import Netmera from "./src/Netmera";
2
- import NetmeraUser from "./src/NetmeraUser";
3
- import {
4
- NetmeraCategory,
5
- NetmeraCategoryFilter,
6
- NetmeraInboxFilter,
7
- NetmeraPushInbox,
8
- NMInboxStatus
9
- } from "./src/NetmeraInbox";
10
-
11
- module.exports = {
12
- Netmera,
13
- NetmeraUser,
14
- NetmeraInboxFilter,
15
- NetmeraCategoryFilter,
16
- NetmeraPushInbox,
17
- NetmeraCategory,
18
- NMInboxStatus,
19
- };