@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 +41 -42
- package/src/Inngage.ts +178 -193
- package/src/components/Inapp.tsx +318 -318
- package/src/components/styles.ts +97 -97
- package/src/index.d.ts +1 -1
- package/src/index.ts +8 -8
- package/src/notificationsListener.ts +190 -190
- package/src/services/handler.ts +42 -42
- package/src/services/inngage.ts +17 -17
- package/src/utils.ts +51 -51
- package/tsconfig.json +24 -24
package/package.json
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@inngageregistry/inngage-react",
|
|
3
|
-
"version": "3.0.
|
|
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-
|
|
23
|
-
"@react-native-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"react-native-
|
|
27
|
-
"react-native-
|
|
28
|
-
"react-native-
|
|
29
|
-
"react-native-
|
|
30
|
-
"react-native-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/react": "^
|
|
36
|
-
"@types/react-native": "^
|
|
37
|
-
"@types/react-native-
|
|
38
|
-
"@types/react-
|
|
39
|
-
"
|
|
40
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|