@inngageregistry/inngage-react 3.0.2 → 3.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.
package/package.json CHANGED
@@ -1,42 +1,41 @@
1
- {
2
- "name": "@inngageregistry/inngage-react",
3
- "version": "3.0.2",
4
- "description": "Inngage react integration",
5
- "main": "src/index.ts",
6
- "types": "src/index.d.ts",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "npx tsc"
10
- },
11
- "author": "Inngage Developer",
12
- "license": "ISC",
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/inngage/inngage-react.git"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/inngage/inngage-react/issues"
19
- },
20
- "homepage": "https://github.com/inngage/inngage-react#readme",
21
- "dependencies": {
22
- "@react-native-async-storage/async-storage": "^1.16.1",
23
- "@react-native-community/push-notification-ios": "^1.10.1",
24
- "@react-native-firebase/app": "^14.11.0",
25
- "@react-native-firebase/messaging": "^14.11.0",
26
- "react-native-advertising-id": "^1.0.11",
27
- "react-native-device-info": "^8.4.9",
28
- "react-native-inappbrowser-reborn": "^3.6.3",
29
- "react-native-localize": "^2.2.2",
30
- "react-native-push-notification": "^8.1.1",
31
- "react-native-snap-carousel": "^3.9.1"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^27.4.0",
35
- "@types/react": "^17.0.38",
36
- "@types/react-native": "^0.66.15",
37
- "@types/react-native-push-notification": "^8.1.0",
38
- "@types/react-native-snap-carousel": "^3.8.5",
39
- "@types/react-test-renderer": "^17.0.1",
40
- "typescript": "^4.5.5"
41
- }
42
- }
1
+ {
2
+ "name": "@inngageregistry/inngage-react",
3
+ "version": "3.0.4",
4
+ "description": "Inngage react integration",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "npx tsc"
10
+ },
11
+ "author": "Inngage Developer",
12
+ "license": "ISC",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/inngage/inngage-react.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/inngage/inngage-react/issues"
19
+ },
20
+ "homepage": "https://github.com/inngage/inngage-react#readme",
21
+ "dependencies": {
22
+ "@react-native-firebase/app": "^17.4.2",
23
+ "@react-native-firebase/messaging": "^17.4.2",
24
+ "react-native-localize": "^2.2.6",
25
+ "react-native-snap-carousel": "^3.9.1",
26
+ "@react-native-async-storage/async-storage": "^1.18.1",
27
+ "react-native-inappbrowser-reborn": "^3.7.0",
28
+ "@react-native-community/push-notification-ios": "^1.11.0",
29
+ "react-native-push-notification": "^8.1.1",
30
+ "react-native-device-info": "^10.6.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^29.5.1",
34
+ "@types/react": "^18.2.0",
35
+ "@types/react-native": "^0.71.6",
36
+ "@types/react-native-push-notification": "^8.1.1",
37
+ "@types/react-native-snap-carousel": "^3.8.5",
38
+ "@types/react-test-renderer": "^18.0.0",
39
+ "typescript": "^5.0.4"
40
+ }
41
+ }
package/src/Inngage.ts CHANGED
@@ -1,193 +1,178 @@
1
- import {
2
- Platform,
3
- LogBox,
4
- AppRegistry,
5
- } from "react-native";
6
-
7
- import { firebase } from '@react-native-firebase/messaging';
8
- import DeviceInfo from "react-native-device-info";
9
- import * as RNLocalize from "react-native-localize";
10
- import AsyncStorage from '@react-native-async-storage/async-storage';
11
-
12
- import { formatDate, subscriptionRequestAdapter } from "./utils";
13
- import notificationsListener, { notificationsListenerProps } from "./notificationsListener";
14
- import { subscriptionApi, eventsApi } from "./services/inngage";
15
- import RNAdvertisingId from 'react-native-advertising-id';
16
-
17
- // --- handle background message ------/
18
- const backgroundNotificationHandler = async remoteMessage => {
19
- var messageArray: any = [];
20
- console.log("Remote message:", JSON.stringify(remoteMessage));
21
-
22
- console.log('Called backgroundNotificationHandler');
23
-
24
- const currentMessages = await AsyncStorage.getItem('messages');
25
- if (currentMessages !== null) {
26
- messageArray = JSON.parse(currentMessages);
27
- }
28
- messageArray.push(remoteMessage);
29
-
30
- await AsyncStorage.setItem('messages', JSON.stringify(messageArray));
31
- };
32
-
33
- // --- Get Firebase Access ------/
34
- const getFirebaseAccess = () => {
35
- let firebaseToken = 'W7SAl94Jk6l3w95W9wCgmv3zZ99V5FReNUytdgJUFUvpvZoqXf72'
36
- return new Promise(async (resolve) => {
37
- DeviceInfo.isEmulator().then(isEmulator => {
38
- if (isEmulator && Platform.OS === "ios") {
39
- return resolve(firebaseToken)
40
- }
41
- })
42
- try {
43
- if (!firebase.messaging().isDeviceRegisteredForRemoteMessages)
44
- await firebase.messaging().registerDeviceForRemoteMessages();
45
-
46
- const permission = await firebase.messaging().hasPermission();
47
- if (permission === firebase.messaging.AuthorizationStatus.NOT_DETERMINED) {
48
- try {
49
- await firebase.messaging().requestPermission();
50
- } catch (e) {
51
- console.error(e)
52
- return resolve(firebaseToken);
53
- }
54
- }
55
- try {
56
- firebaseToken = await firebase.messaging().getToken();
57
- } catch (error) {
58
- console.error(error)
59
- return resolve(firebaseToken)
60
- }
61
- return resolve(firebaseToken)
62
- } catch (err) {
63
- console.error(err)
64
- return resolve(firebaseToken)
65
- }
66
- });
67
- };
68
-
69
- interface SubscriptionProps {
70
- appToken: string,
71
- enableAlert: boolean,
72
- authKey: string,
73
- dev?: boolean,
74
- friendlyIdentifier?: string,
75
- customFields?: any,
76
- customData?: any,
77
- phoneNumber?: string
78
- }
79
-
80
- interface SendEventProps {
81
- newEventRequest: {
82
- app_token: string,
83
- identifier: string,
84
- event_name: string,
85
- conversion_event: boolean,
86
- conversion_value: number,
87
- conversion_notid: string,
88
- event_values: {
89
- nome_promo: string,
90
- categoria: string,
91
- foto_promo: string,
92
- redirect_link: string
93
- }
94
- },
95
- authKey: string
96
- }
97
- const Inngage = {
98
- // ------------ Register Notification Listener ------------//
99
- RegisterNotificationListener: async (props: notificationsListenerProps) => {
100
-
101
- try {
102
- LogBox.ignoreLogs(['registerHeadlessTask'])
103
- } catch (e) { }
104
- try {
105
- console.ignoredYellowBox = ['registerHeadlessTask'];
106
- } catch (e) { }
107
- try {
108
- AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => backgroundNotificationHandler)
109
- notificationsListener({ ...props });
110
- } catch (e) {
111
- console.error(e);
112
- return { subscribed: false };
113
- }
114
- },
115
- Subscribe: async ({
116
- appToken,
117
- dev,
118
- friendlyIdentifier,
119
- customFields,
120
- customData,
121
- phoneNumber,
122
- authKey
123
- }: SubscriptionProps) => {
124
- try {
125
- const respToken = await getFirebaseAccess()
126
-
127
- const locales = RNLocalize.getLocales();
128
-
129
- const os_language = locales && locales.length ? locales[0].languageCode : ''
130
- const device_manufacturer = await DeviceInfo.getManufacturer();
131
- const installTime = await DeviceInfo.getFirstInstallTime();
132
- const lastUpdateTime = await DeviceInfo.getLastUpdateTime();
133
- const app_installed_in = formatDate(installTime);
134
- const app_updated_in = formatDate(lastUpdateTime);
135
- const androidId = DeviceInfo.getAndroidId();
136
- var advertiserId = "Unknown"
137
- var idFa = "Unknown"
138
- try{
139
- const rnAdvertisingId = await RNAdvertisingId.getAdvertisingId();
140
- advertiserId = rnAdvertisingId.advertisingId;
141
- idFa = rnAdvertisingId.advertisingId;
142
- }catch(e){
143
-
144
- }
145
-
146
-
147
- const rawRequest = {
148
- registerSubscriberRequest: {
149
- app_token: appToken,
150
- identifier: friendlyIdentifier,
151
- registration: respToken,
152
- phone_Number: phoneNumber,
153
- platform: DeviceInfo.getSystemName(),
154
- sdk: DeviceInfo.getBuildNumber(),
155
- device_model: DeviceInfo.getModel(),
156
- device_manufacturer,
157
- os_locale: RNLocalize.getCountry(),
158
- os_language,
159
- os_version: DeviceInfo.getReadableVersion(),
160
- app_version: DeviceInfo.getBuildNumber(),
161
- app_installed_in,
162
- app_updated_in,
163
- uuid: DeviceInfo.getUniqueId(),
164
- advertiser_id:advertiserId,
165
- android_id:androidId,
166
- idfa:idFa,
167
- authKey,
168
- }
169
- };
170
-
171
- const request = subscriptionRequestAdapter(rawRequest, customData, customFields)
172
- const subscribe = await subscriptionApi(request, dev);
173
- console.log(await subscribe.json())
174
- return subscribe;
175
- } catch (e) {
176
- console.error(e);
177
- return { subscribed: false };
178
- }
179
- },
180
- SendEvent: async (props: SendEventProps) => {
181
- const { authKey, newEventRequest } = props
182
- const rawRequest = {
183
- registerSubscriberRequest: {
184
- authKey
185
- },
186
- newEventRequest
187
- }
188
- const subscribe = await eventsApi(rawRequest);
189
- return subscribe
190
- }
191
- }
192
-
193
- export default Inngage;
1
+ import {
2
+ Platform,
3
+ LogBox,
4
+ AppRegistry,
5
+ } from "react-native";
6
+
7
+ import { firebase } from '@react-native-firebase/messaging';
8
+ import DeviceInfo from "react-native-device-info";
9
+ import * as RNLocalize from "react-native-localize";
10
+ import AsyncStorage from '@react-native-async-storage/async-storage';
11
+
12
+ import { formatDate, subscriptionRequestAdapter } from "./utils";
13
+ import notificationsListener, { notificationsListenerProps } from "./notificationsListener";
14
+ import { subscriptionApi, eventsApi } from "./services/inngage";
15
+
16
+ // --- handle background message ------/
17
+ const backgroundNotificationHandler = async remoteMessage => {
18
+ var messageArray: any = [];
19
+ console.log("Remote message:", JSON.stringify(remoteMessage));
20
+
21
+ console.log('Called backgroundNotificationHandler');
22
+
23
+ const currentMessages = await AsyncStorage.getItem('messages');
24
+ if (currentMessages !== null) {
25
+ messageArray = JSON.parse(currentMessages);
26
+ }
27
+ messageArray.push(remoteMessage);
28
+
29
+ await AsyncStorage.setItem('messages', JSON.stringify(messageArray));
30
+ };
31
+
32
+ // --- Get Firebase Access ------/
33
+ const getFirebaseAccess = () => {
34
+ let firebaseToken = 'W7SAl94Jk6l3w95W9wCgmv3zZ99V5FReNUytdgJUFUvpvZoqXf72'
35
+ return new Promise(async (resolve) => {
36
+ DeviceInfo.isEmulator().then(isEmulator => {
37
+ if (isEmulator && Platform.OS === "ios") {
38
+ return resolve(firebaseToken)
39
+ }
40
+ })
41
+ try {
42
+ if (!firebase.messaging().isDeviceRegisteredForRemoteMessages)
43
+ await firebase.messaging().registerDeviceForRemoteMessages();
44
+
45
+ const permission = await firebase.messaging().hasPermission();
46
+ if (permission === firebase.messaging.AuthorizationStatus.NOT_DETERMINED) {
47
+ try {
48
+ await firebase.messaging().requestPermission();
49
+ } catch (e) {
50
+ console.error(e)
51
+ return resolve(firebaseToken);
52
+ }
53
+ }
54
+ try {
55
+ firebaseToken = await firebase.messaging().getToken();
56
+ } catch (error) {
57
+ console.error(error)
58
+ return resolve(firebaseToken)
59
+ }
60
+ return resolve(firebaseToken)
61
+ } catch (err) {
62
+ console.error(err)
63
+ return resolve(firebaseToken)
64
+ }
65
+ });
66
+ };
67
+
68
+ interface SubscriptionProps {
69
+ appToken: string,
70
+ enableAlert: boolean,
71
+ authKey: string,
72
+ dev?: boolean,
73
+ friendlyIdentifier?: string,
74
+ customFields?: any,
75
+ customData?: any,
76
+ phoneNumber?: string
77
+ }
78
+
79
+ interface SendEventProps {
80
+ newEventRequest: {
81
+ app_token: string,
82
+ identifier: string,
83
+ event_name: string,
84
+ conversion_event: boolean,
85
+ conversion_value: number,
86
+ conversion_notid: string,
87
+ event_values: {
88
+ nome_promo: string,
89
+ categoria: string,
90
+ foto_promo: string,
91
+ redirect_link: string
92
+ }
93
+ },
94
+ authKey: string
95
+ }
96
+ const Inngage = {
97
+ // ------------ Register Notification Listener ------------//
98
+ RegisterNotificationListener: async (props: notificationsListenerProps) => {
99
+
100
+ try {
101
+ LogBox.ignoreLogs(['registerHeadlessTask'])
102
+ } catch (e) { }
103
+ try {
104
+ console.ignoredYellowBox = ['registerHeadlessTask'];
105
+ } catch (e) { }
106
+ try {
107
+ AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => backgroundNotificationHandler)
108
+ notificationsListener({ ...props });
109
+ } catch (e) {
110
+ console.error(e);
111
+ return { subscribed: false };
112
+ }
113
+ },
114
+ Subscribe: async ({
115
+ appToken,
116
+ dev,
117
+ friendlyIdentifier,
118
+ customFields,
119
+ customData,
120
+ phoneNumber,
121
+ authKey
122
+ }: SubscriptionProps) => {
123
+ try {
124
+ const respToken = await getFirebaseAccess()
125
+
126
+ const locales = RNLocalize.getLocales();
127
+
128
+ const os_language = locales && locales.length ? locales[0].languageCode : ''
129
+ const device_manufacturer = await DeviceInfo.getManufacturer();
130
+ const installTime = await DeviceInfo.getFirstInstallTime();
131
+ const lastUpdateTime = await DeviceInfo.getLastUpdateTime();
132
+ const app_installed_in = formatDate(installTime);
133
+ const app_updated_in = formatDate(lastUpdateTime);
134
+
135
+ const rawRequest = {
136
+ registerSubscriberRequest: {
137
+ app_token: appToken,
138
+ identifier: friendlyIdentifier,
139
+ registration: respToken,
140
+ phone_Number: phoneNumber,
141
+ platform: DeviceInfo.getSystemName(),
142
+ sdk: DeviceInfo.getBuildNumber(),
143
+ device_model: DeviceInfo.getModel(),
144
+ device_manufacturer,
145
+ os_locale: RNLocalize.getCountry(),
146
+ os_language,
147
+ os_version: DeviceInfo.getReadableVersion(),
148
+ app_version: DeviceInfo.getBuildNumber(),
149
+ app_installed_in,
150
+ app_updated_in,
151
+ uuid: DeviceInfo.getUniqueId(),
152
+ authKey
153
+ }
154
+ };
155
+
156
+ const request = subscriptionRequestAdapter(rawRequest, customData, customFields)
157
+ const subscribe = await subscriptionApi(request, dev);
158
+ console.log(await subscribe.json())
159
+ return subscribe;
160
+ } catch (e) {
161
+ console.error(e);
162
+ return { subscribed: false };
163
+ }
164
+ },
165
+ SendEvent: async (props: SendEventProps) => {
166
+ const { authKey, newEventRequest } = props
167
+ const rawRequest = {
168
+ registerSubscriberRequest: {
169
+ authKey
170
+ },
171
+ newEventRequest
172
+ }
173
+ const subscribe = await eventsApi(rawRequest);
174
+ return subscribe
175
+ }
176
+ }
177
+
178
+ export default Inngage;