@inngageregistry/inngage-react 4.0.0-beta.1 → 4.0.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.
- package/README.md +61 -40
- package/dist/Inngage.d.ts +28 -0
- package/dist/Inngage.js +149 -0
- package/dist/api/api.d.ts +4 -0
- package/{src/api/api.ts → dist/api/api.js} +22 -28
- package/dist/api/handler.d.ts +1 -0
- package/dist/api/handler.js +44 -0
- package/dist/components/in_app.d.ts +6 -0
- package/dist/components/in_app.js +92 -0
- package/dist/components/modal.d.ts +26 -0
- package/dist/components/modal.js +158 -0
- package/dist/components/styles.d.ts +88 -0
- package/dist/components/styles.js +86 -0
- package/dist/firebase/notifications_listener.d.ts +6 -0
- package/dist/firebase/notifications_listener.js +170 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/models/inngage_properties.d.ts +11 -0
- package/dist/models/inngage_properties.js +13 -0
- package/dist/models/requests.d.ts +40 -0
- package/{src/models/requests.ts → dist/models/requests.js} +40 -42
- package/dist/services/api_services.d.ts +7 -0
- package/{src/services/api_services.ts → dist/services/api_services.js} +25 -30
- package/dist/services/handler.d.ts +1 -0
- package/dist/services/handler.js +38 -0
- package/dist/services/inngage.d.ts +4 -0
- package/dist/services/inngage.js +22 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +25 -0
- package/package.json +79 -40
- package/.editorconfig +0 -6
- package/src/Inngage.ts +0 -193
- package/src/api/handler.ts +0 -53
- package/src/components/in_app.tsx +0 -159
- package/src/components/modal.tsx +0 -221
- package/src/components/styles.ts +0 -70
- package/src/firebase/notifications_listener.ts +0 -146
- package/src/index.ts +0 -8
- package/src/models/inngage_properties.ts +0 -13
- package/src/services/handler.ts +0 -41
- package/src/services/inngage.ts +0 -23
- package/src/utils.ts +0 -35
- package/tsconfig.json +0 -27
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export declare const buildStyles: (data: any, screen: any) => {
|
|
2
|
+
closeButton: {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
justifyContent: "center";
|
|
6
|
+
alignItems: "center";
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
borderRadius: number;
|
|
9
|
+
shadowOffset: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
shadowOpacity: number;
|
|
14
|
+
shadowRadius: number;
|
|
15
|
+
position: "absolute";
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
zIndex: number;
|
|
19
|
+
};
|
|
20
|
+
textButton: {
|
|
21
|
+
color: string;
|
|
22
|
+
fontSize: number;
|
|
23
|
+
fontWeight: "bold";
|
|
24
|
+
};
|
|
25
|
+
content: {
|
|
26
|
+
backgroundColor: any;
|
|
27
|
+
flexDirection: "column";
|
|
28
|
+
borderRadius: number;
|
|
29
|
+
paddingBottom: number;
|
|
30
|
+
paddingRight: number;
|
|
31
|
+
paddingLeft: number;
|
|
32
|
+
margin: number;
|
|
33
|
+
overflow: "hidden";
|
|
34
|
+
elevation: number;
|
|
35
|
+
width: any;
|
|
36
|
+
alignItems: "center";
|
|
37
|
+
};
|
|
38
|
+
messageData: {
|
|
39
|
+
marginTop: number;
|
|
40
|
+
alignItems: "center";
|
|
41
|
+
justifyContent: "center";
|
|
42
|
+
};
|
|
43
|
+
footer: {
|
|
44
|
+
flexDirection: "row";
|
|
45
|
+
alignItems: "center";
|
|
46
|
+
justifyContent: "flex-end";
|
|
47
|
+
marginTop: number;
|
|
48
|
+
};
|
|
49
|
+
title: {
|
|
50
|
+
color: any;
|
|
51
|
+
fontWeight: "500";
|
|
52
|
+
fontSize: number;
|
|
53
|
+
};
|
|
54
|
+
body: {
|
|
55
|
+
color: any;
|
|
56
|
+
fontSize: number;
|
|
57
|
+
marginTop: number;
|
|
58
|
+
marginBottom: number;
|
|
59
|
+
};
|
|
60
|
+
buttonLeft: {
|
|
61
|
+
margin: number;
|
|
62
|
+
flex: number;
|
|
63
|
+
backgroundColor: any;
|
|
64
|
+
justifyContent: "center";
|
|
65
|
+
alignItems: "center";
|
|
66
|
+
};
|
|
67
|
+
buttonRight: {
|
|
68
|
+
margin: number;
|
|
69
|
+
flex: number;
|
|
70
|
+
backgroundColor: any;
|
|
71
|
+
justifyContent: "center";
|
|
72
|
+
alignItems: "center";
|
|
73
|
+
};
|
|
74
|
+
textButtonLeft: {
|
|
75
|
+
color: any;
|
|
76
|
+
textAlign: "center";
|
|
77
|
+
backgroundColor: string;
|
|
78
|
+
padding: number;
|
|
79
|
+
fontSize: number;
|
|
80
|
+
};
|
|
81
|
+
textButtonRight: {
|
|
82
|
+
color: any;
|
|
83
|
+
textAlign: "center";
|
|
84
|
+
backgroundColor: string;
|
|
85
|
+
padding: number;
|
|
86
|
+
fontSize: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
export const buildStyles = (data, screen) => StyleSheet.create({
|
|
3
|
+
closeButton: {
|
|
4
|
+
width: 30,
|
|
5
|
+
height: 30,
|
|
6
|
+
justifyContent: 'center',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
backgroundColor: 'transparent',
|
|
9
|
+
borderRadius: 25,
|
|
10
|
+
shadowOffset: { width: 0, height: 2 },
|
|
11
|
+
shadowOpacity: 0.2,
|
|
12
|
+
shadowRadius: 4,
|
|
13
|
+
position: 'absolute',
|
|
14
|
+
top: 10,
|
|
15
|
+
right: 10,
|
|
16
|
+
zIndex: 10,
|
|
17
|
+
},
|
|
18
|
+
textButton: {
|
|
19
|
+
color: '#000',
|
|
20
|
+
fontSize: 16,
|
|
21
|
+
fontWeight: 'bold',
|
|
22
|
+
},
|
|
23
|
+
content: {
|
|
24
|
+
backgroundColor: data?.background_color,
|
|
25
|
+
flexDirection: "column",
|
|
26
|
+
borderRadius: 20,
|
|
27
|
+
paddingBottom: 16,
|
|
28
|
+
paddingRight: 16,
|
|
29
|
+
paddingLeft: 16,
|
|
30
|
+
margin: 16,
|
|
31
|
+
overflow: "hidden",
|
|
32
|
+
elevation: 10,
|
|
33
|
+
width: screen,
|
|
34
|
+
alignItems: "center"
|
|
35
|
+
},
|
|
36
|
+
messageData: {
|
|
37
|
+
marginTop: 12,
|
|
38
|
+
alignItems: "center",
|
|
39
|
+
justifyContent: "center",
|
|
40
|
+
},
|
|
41
|
+
footer: {
|
|
42
|
+
flexDirection: "row",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
justifyContent: "flex-end",
|
|
45
|
+
marginTop: 4,
|
|
46
|
+
},
|
|
47
|
+
title: {
|
|
48
|
+
color: data?.title_font_color,
|
|
49
|
+
fontWeight: "500",
|
|
50
|
+
fontSize: 18,
|
|
51
|
+
},
|
|
52
|
+
body: {
|
|
53
|
+
color: data?.body_font_color,
|
|
54
|
+
fontSize: 16,
|
|
55
|
+
marginTop: 10,
|
|
56
|
+
marginBottom: 10,
|
|
57
|
+
},
|
|
58
|
+
buttonLeft: {
|
|
59
|
+
margin: 2,
|
|
60
|
+
flex: 1,
|
|
61
|
+
backgroundColor: data?.btn_left_bg_color,
|
|
62
|
+
justifyContent: "center",
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
},
|
|
65
|
+
buttonRight: {
|
|
66
|
+
margin: 2,
|
|
67
|
+
flex: 1,
|
|
68
|
+
backgroundColor: data?.btn_right_bg_color,
|
|
69
|
+
justifyContent: "center",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
},
|
|
72
|
+
textButtonLeft: {
|
|
73
|
+
color: data?.btn_left_txt_color,
|
|
74
|
+
textAlign: "center",
|
|
75
|
+
backgroundColor: "transparent",
|
|
76
|
+
padding: 8,
|
|
77
|
+
fontSize: 14,
|
|
78
|
+
},
|
|
79
|
+
textButtonRight: {
|
|
80
|
+
color: data?.btn_right_txt_color,
|
|
81
|
+
textAlign: "center",
|
|
82
|
+
backgroundColor: "transparent",
|
|
83
|
+
padding: 8,
|
|
84
|
+
fontSize: 14,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const messagingHeadlessTask: () => void;
|
|
2
|
+
export declare const useInAppHandler: () => {
|
|
3
|
+
showInApp: boolean;
|
|
4
|
+
setShowInApp: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const InngageNotificationMessage: (firebaseListenCallback?: (data: Record<string, string>) => void) => void;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AppState, Linking, Platform } from 'react-native';
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { getApp } from '@react-native-firebase/app';
|
|
5
|
+
import { getMessaging, setBackgroundMessageHandler, onMessage, onNotificationOpenedApp, getInitialNotification, } from '@react-native-firebase/messaging';
|
|
6
|
+
import InAppBrowser from 'react-native-inappbrowser-reborn';
|
|
7
|
+
import { InngageProperties } from '../models/inngage_properties';
|
|
8
|
+
import * as ApiService from '../services/api_services';
|
|
9
|
+
import notifee, { EventType } from '@notifee/react-native';
|
|
10
|
+
const ANDROID_CHANNEL_ID = 'inngage_default';
|
|
11
|
+
async function ensureAndroidChannel() {
|
|
12
|
+
if (!notifee || Platform.OS !== 'android')
|
|
13
|
+
return;
|
|
14
|
+
await notifee.createChannel({ id: ANDROID_CHANNEL_ID, name: 'Inngage' });
|
|
15
|
+
}
|
|
16
|
+
const toStringValue = (v) => typeof v === 'string' ? v : JSON.stringify(v ?? '');
|
|
17
|
+
const app = getApp();
|
|
18
|
+
const messagingInstance = getMessaging(app);
|
|
19
|
+
export const messagingHeadlessTask = () => {
|
|
20
|
+
return setBackgroundMessageHandler(messagingInstance, async (remoteMessage) => {
|
|
21
|
+
if (InngageProperties.getDebugMode()) {
|
|
22
|
+
console.log('INNGAGE BACKGROUND AND CLOSED DATA: ', remoteMessage);
|
|
23
|
+
}
|
|
24
|
+
const additional = remoteMessage?.data?.additional_data;
|
|
25
|
+
if (additional != null) {
|
|
26
|
+
await AsyncStorage.setItem('inapp', toStringValue(additional));
|
|
27
|
+
}
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export const useInAppHandler = () => {
|
|
32
|
+
const [showInApp, setShowInApp] = useState(false);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const checkInAppData = async () => {
|
|
35
|
+
const inAppData = await AsyncStorage.getItem('inapp');
|
|
36
|
+
if (inAppData)
|
|
37
|
+
setShowInApp(true);
|
|
38
|
+
};
|
|
39
|
+
checkInAppData();
|
|
40
|
+
const subscription = AppState.addEventListener('change', (next) => {
|
|
41
|
+
if (next === 'active')
|
|
42
|
+
checkInAppData();
|
|
43
|
+
});
|
|
44
|
+
return () => subscription.remove();
|
|
45
|
+
}, []);
|
|
46
|
+
return { showInApp, setShowInApp };
|
|
47
|
+
};
|
|
48
|
+
export const InngageNotificationMessage = (firebaseListenCallback) => {
|
|
49
|
+
const [notificationMessage, setNotificationMessage] = useState(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const handleMessage = async (remoteMessage) => {
|
|
52
|
+
const notificationData = remoteMessage.data ?? {};
|
|
53
|
+
if (notificationData.additional_data != null) {
|
|
54
|
+
await AsyncStorage.setItem('inapp', toStringValue(notificationData.additional_data));
|
|
55
|
+
}
|
|
56
|
+
if (notifee) {
|
|
57
|
+
const title = remoteMessage.notification?.title ?? notificationData.title ?? '';
|
|
58
|
+
const body = remoteMessage.notification?.body ?? notificationData.body ?? '';
|
|
59
|
+
await notifee.displayNotification({
|
|
60
|
+
title,
|
|
61
|
+
body,
|
|
62
|
+
android: Platform.OS === 'android' ? { channelId: ANDROID_CHANNEL_ID } : undefined,
|
|
63
|
+
ios: Platform.OS === 'ios'
|
|
64
|
+
? { foregroundPresentationOptions: { banner: true, list: true, sound: true } }
|
|
65
|
+
: undefined,
|
|
66
|
+
});
|
|
67
|
+
return notifee.onForegroundEvent(({ type, detail }) => {
|
|
68
|
+
switch (type) {
|
|
69
|
+
case EventType.DISMISSED:
|
|
70
|
+
if (InngageProperties.getDebugMode()) {
|
|
71
|
+
console.log('User dismissed notification', detail.notification);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case EventType.PRESS:
|
|
75
|
+
handleNotification(remoteMessage);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (InngageProperties.getDebugMode()) {
|
|
82
|
+
console.log('[SDK] Notifee não instalado; mensagem em foreground: ', remoteMessage);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (InngageProperties.getDebugMode()) {
|
|
86
|
+
console.log('Remote message received in foreground: ', remoteMessage);
|
|
87
|
+
}
|
|
88
|
+
if (firebaseListenCallback && remoteMessage) {
|
|
89
|
+
firebaseListenCallback(notificationData);
|
|
90
|
+
}
|
|
91
|
+
setNotificationMessage(remoteMessage);
|
|
92
|
+
};
|
|
93
|
+
ensureAndroidChannel().catch(() => { });
|
|
94
|
+
const unsubscribe = onMessage(messagingInstance, handleMessage);
|
|
95
|
+
return unsubscribe;
|
|
96
|
+
}, [firebaseListenCallback]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const unsubscribe = onNotificationOpenedApp(messagingInstance, (remoteMessage) => {
|
|
99
|
+
if (!remoteMessage)
|
|
100
|
+
return;
|
|
101
|
+
firebaseListenCallback?.(remoteMessage.data ?? {});
|
|
102
|
+
handleNotification(remoteMessage);
|
|
103
|
+
});
|
|
104
|
+
return unsubscribe;
|
|
105
|
+
}, [firebaseListenCallback]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
let mounted = true;
|
|
108
|
+
getInitialNotification(messagingInstance)
|
|
109
|
+
.then(async (value) => {
|
|
110
|
+
if (!mounted || !value)
|
|
111
|
+
return;
|
|
112
|
+
await handleUniqueRemoteMessage(value);
|
|
113
|
+
})
|
|
114
|
+
.catch((e) => console.error(e));
|
|
115
|
+
return () => {
|
|
116
|
+
mounted = false;
|
|
117
|
+
};
|
|
118
|
+
}, []);
|
|
119
|
+
const handleUniqueRemoteMessage = async (remoteMessage) => {
|
|
120
|
+
try {
|
|
121
|
+
const lastId = await AsyncStorage.getItem('LAST_REMOTE_MESSAGE_ID');
|
|
122
|
+
const newId = remoteMessage?.messageId;
|
|
123
|
+
if (newId && lastId !== newId) {
|
|
124
|
+
await AsyncStorage.setItem('LAST_REMOTE_MESSAGE_ID', newId);
|
|
125
|
+
handleNotification(remoteMessage);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.error(e);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
async function handleNotification(remoteMessage) {
|
|
133
|
+
const data = remoteMessage?.data ?? {};
|
|
134
|
+
const notId = data?.notId;
|
|
135
|
+
const request = {
|
|
136
|
+
notificationRequest: {
|
|
137
|
+
app_token: InngageProperties.appToken,
|
|
138
|
+
id: notId,
|
|
139
|
+
notId: notId
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const url = data?.url;
|
|
143
|
+
const type = data?.type;
|
|
144
|
+
if (url) {
|
|
145
|
+
if (type === 'inapp') {
|
|
146
|
+
try {
|
|
147
|
+
if (await InAppBrowser.isAvailable()) {
|
|
148
|
+
await InAppBrowser.open(url, {
|
|
149
|
+
dismissButtonStyle: 'close',
|
|
150
|
+
preferredBarTintColor: '#453AA4',
|
|
151
|
+
preferredControlTintColor: 'white',
|
|
152
|
+
enableDefaultShare: true,
|
|
153
|
+
enableBarCollapsing: true,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
Linking.openURL(url);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.error(error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (type === 'deep') {
|
|
165
|
+
Linking.openURL(url).catch((err) => console.error('Erro ao abrir o link:', err));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
await ApiService.sendNotification(request);
|
|
169
|
+
}
|
|
170
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InApp } from './components/in_app';
|
|
2
|
+
import { useInAppHandler, messagingHeadlessTask } from './firebase/notifications_listener';
|
|
3
|
+
import Inngage from './Inngage';
|
|
4
|
+
export { InApp };
|
|
5
|
+
export { useInAppHandler, messagingHeadlessTask };
|
|
6
|
+
export default Inngage;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InApp } from './components/in_app';
|
|
2
|
+
import { useInAppHandler, messagingHeadlessTask } from './firebase/notifications_listener';
|
|
3
|
+
import Inngage from './Inngage';
|
|
4
|
+
export { InApp };
|
|
5
|
+
export { useInAppHandler, messagingHeadlessTask };
|
|
6
|
+
export default Inngage;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class InngageProperties {
|
|
2
|
+
static identifier: string;
|
|
3
|
+
static appToken: string;
|
|
4
|
+
static phoneNumber: string;
|
|
5
|
+
static email: string;
|
|
6
|
+
static customFields: any;
|
|
7
|
+
static blockDeepLink: boolean;
|
|
8
|
+
static debugMode: boolean;
|
|
9
|
+
static firebaseToken: string;
|
|
10
|
+
static getDebugMode(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class InngageProperties {
|
|
2
|
+
static getDebugMode() {
|
|
3
|
+
return InngageProperties.debugMode;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
InngageProperties.identifier = '';
|
|
7
|
+
InngageProperties.appToken = '';
|
|
8
|
+
InngageProperties.phoneNumber = '';
|
|
9
|
+
InngageProperties.email = '';
|
|
10
|
+
InngageProperties.customFields = {};
|
|
11
|
+
InngageProperties.blockDeepLink = false;
|
|
12
|
+
InngageProperties.debugMode = false;
|
|
13
|
+
InngageProperties.firebaseToken = '';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const SUBSCRIBE_REQUEST: {
|
|
2
|
+
registerSubscriberRequest: {
|
|
3
|
+
appToken: string;
|
|
4
|
+
identifier: string;
|
|
5
|
+
registration: string;
|
|
6
|
+
platform: string;
|
|
7
|
+
sdk: string;
|
|
8
|
+
deviceModel: string;
|
|
9
|
+
deviceManufacturer: string;
|
|
10
|
+
osLocale: string;
|
|
11
|
+
osLanguage: string;
|
|
12
|
+
osVersion: string;
|
|
13
|
+
appVersion: string;
|
|
14
|
+
appInstalledIn: string;
|
|
15
|
+
appUpdatedIn: string;
|
|
16
|
+
uuid: string;
|
|
17
|
+
phoneNumber: string;
|
|
18
|
+
email: string;
|
|
19
|
+
customFields: {};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare const EVENT_REQUEST: {
|
|
23
|
+
newEventRequest: {
|
|
24
|
+
appToken: string;
|
|
25
|
+
identifier: string;
|
|
26
|
+
registration: string;
|
|
27
|
+
eventName: string;
|
|
28
|
+
conversionEvent: boolean;
|
|
29
|
+
conversionValue: number;
|
|
30
|
+
conversionNotId: string;
|
|
31
|
+
eventValues: {};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare const USER_DATA_REQUEST: {
|
|
35
|
+
fieldsRequest: {
|
|
36
|
+
appToken: string;
|
|
37
|
+
identifier: string;
|
|
38
|
+
customField: {};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
export const SUBSCRIBE_REQUEST = {
|
|
2
|
-
registerSubscriberRequest: {
|
|
3
|
-
appToken: '',
|
|
4
|
-
identifier: '',
|
|
5
|
-
registration: '',
|
|
6
|
-
platform: '',
|
|
7
|
-
sdk: '',
|
|
8
|
-
deviceModel: '',
|
|
9
|
-
deviceManufacturer: '',
|
|
10
|
-
osLocale: '',
|
|
11
|
-
osLanguage: '',
|
|
12
|
-
osVersion: '',
|
|
13
|
-
appVersion: '',
|
|
14
|
-
appInstalledIn: '',
|
|
15
|
-
appUpdatedIn: '',
|
|
16
|
-
uuid: '',
|
|
17
|
-
phoneNumber: '',
|
|
18
|
-
email: '',
|
|
19
|
-
customFields: {},
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
};
|
|
1
|
+
export const SUBSCRIBE_REQUEST = {
|
|
2
|
+
registerSubscriberRequest: {
|
|
3
|
+
appToken: '',
|
|
4
|
+
identifier: '',
|
|
5
|
+
registration: '',
|
|
6
|
+
platform: '',
|
|
7
|
+
sdk: '',
|
|
8
|
+
deviceModel: '',
|
|
9
|
+
deviceManufacturer: '',
|
|
10
|
+
osLocale: '',
|
|
11
|
+
osLanguage: '',
|
|
12
|
+
osVersion: '',
|
|
13
|
+
appVersion: '',
|
|
14
|
+
appInstalledIn: '',
|
|
15
|
+
appUpdatedIn: '',
|
|
16
|
+
uuid: '',
|
|
17
|
+
phoneNumber: '',
|
|
18
|
+
email: '',
|
|
19
|
+
customFields: {},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const EVENT_REQUEST = {
|
|
23
|
+
newEventRequest: {
|
|
24
|
+
appToken: '',
|
|
25
|
+
identifier: '',
|
|
26
|
+
registration: '',
|
|
27
|
+
eventName: '',
|
|
28
|
+
conversionEvent: false,
|
|
29
|
+
conversionValue: 0,
|
|
30
|
+
conversionNotId: '',
|
|
31
|
+
eventValues: {},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const USER_DATA_REQUEST = {
|
|
35
|
+
fieldsRequest: {
|
|
36
|
+
appToken: '',
|
|
37
|
+
identifier: '',
|
|
38
|
+
customField: {},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare class ApiService {
|
|
2
|
+
subscribe(request: any): Promise<Response>;
|
|
3
|
+
sendEvent(request: any, dev?: boolean): Promise<Response>;
|
|
4
|
+
addUserData(request: any, dev?: boolean): Promise<Response>;
|
|
5
|
+
}
|
|
6
|
+
export declare function sendNotification(request: any, dev?: boolean): Promise<Response>;
|
|
7
|
+
export default ApiService;
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
import { InngageProperties } from '../models/inngage_properties';
|
|
2
|
-
import { subscriptionApi, notificationApi, eventsApi, addUserDataApi } from '../api/api';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log('INNGAGE PAYLOAD NOTIFICATION: ', request)
|
|
27
|
-
return notificationApi(request);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default ApiService;
|
|
1
|
+
import { InngageProperties } from '../models/inngage_properties';
|
|
2
|
+
import { subscriptionApi, notificationApi, eventsApi, addUserDataApi } from '../api/api';
|
|
3
|
+
class ApiService {
|
|
4
|
+
async subscribe(request) {
|
|
5
|
+
if (InngageProperties.getDebugMode())
|
|
6
|
+
console.log('INNGAGE PAYLOAD SUBSCRIPTION: ', request);
|
|
7
|
+
return subscriptionApi(request);
|
|
8
|
+
}
|
|
9
|
+
async sendEvent(request, dev = false) {
|
|
10
|
+
if (InngageProperties.getDebugMode())
|
|
11
|
+
console.log('INNGAGE PAYLOAD EVENT: ', request);
|
|
12
|
+
return eventsApi(request);
|
|
13
|
+
}
|
|
14
|
+
async addUserData(request, dev = false) {
|
|
15
|
+
if (InngageProperties.getDebugMode())
|
|
16
|
+
console.log('INNGAGE PAYLOAD ADDUSERDATA: ', request);
|
|
17
|
+
return addUserDataApi(request);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function sendNotification(request, dev = false) {
|
|
21
|
+
if (InngageProperties.getDebugMode())
|
|
22
|
+
console.log('INNGAGE PAYLOAD NOTIFICATION: ', request);
|
|
23
|
+
return notificationApi(request);
|
|
24
|
+
}
|
|
25
|
+
export default ApiService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchClient: (method: any, requestBody: any, path: any, isDev?: boolean) => Promise<Response>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const baseUrlHook = {
|
|
2
|
+
[false]: 'https://api.inngage.com.br/v1',
|
|
3
|
+
[undefined]: 'https://api.inngage.com.br/v1',
|
|
4
|
+
[null]: 'https://api.inngage.com.br/v1',
|
|
5
|
+
[true]: 'https://apid.inngage.com.br/v1',
|
|
6
|
+
};
|
|
7
|
+
const requestConfigFactory = (method, request) => {
|
|
8
|
+
let header = {
|
|
9
|
+
Accept: 'application/json',
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
};
|
|
12
|
+
try {
|
|
13
|
+
if (request?.registerSubscriberRequest?.authKey) {
|
|
14
|
+
header = {
|
|
15
|
+
...header,
|
|
16
|
+
Authorization: request.registerSubscriberRequest.authKey
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
}
|
|
23
|
+
let objToSend = {
|
|
24
|
+
method,
|
|
25
|
+
body: JSON.stringify(request),
|
|
26
|
+
headers: header
|
|
27
|
+
};
|
|
28
|
+
return objToSend;
|
|
29
|
+
};
|
|
30
|
+
export const fetchClient = (method, requestBody, path, isDev = false) => {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const url = String(baseUrlHook[isDev]).concat(path);
|
|
33
|
+
const request = requestConfigFactory(method, requestBody);
|
|
34
|
+
fetch(url, request)
|
|
35
|
+
.then(resolve)
|
|
36
|
+
.catch(err => console.error('Fetch Error', err));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const subscriptionApi: (request: any, dev?: boolean) => Promise<Response>;
|
|
2
|
+
export declare const notificationApi: (request: any, dev?: boolean) => Promise<Response>;
|
|
3
|
+
export declare const eventsApi: (request: any, dev?: boolean) => Promise<Response>;
|
|
4
|
+
export declare const addUserDataApi: (request: any, dev?: boolean) => Promise<Response>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InngageProperties } from '../models/inngage_properties';
|
|
2
|
+
import { fetchClient } from './handler';
|
|
3
|
+
export const subscriptionApi = (request, dev = false) => {
|
|
4
|
+
if (InngageProperties.getDebugMode())
|
|
5
|
+
console.log('subscriptionApi', request);
|
|
6
|
+
return fetchClient('POST', request, '/subscription/', !!dev);
|
|
7
|
+
};
|
|
8
|
+
export const notificationApi = (request, dev = false) => {
|
|
9
|
+
if (InngageProperties.getDebugMode())
|
|
10
|
+
console.log('notificationApi', request);
|
|
11
|
+
return fetchClient('POST', request, '/notification/', !!dev);
|
|
12
|
+
};
|
|
13
|
+
export const eventsApi = (request, dev = false) => {
|
|
14
|
+
if (InngageProperties.getDebugMode())
|
|
15
|
+
console.log('eventsApi', request);
|
|
16
|
+
return fetchClient('POST', request, '/events/newEvent/', !!dev);
|
|
17
|
+
};
|
|
18
|
+
export const addUserDataApi = (request, dev = false) => {
|
|
19
|
+
if (InngageProperties.getDebugMode())
|
|
20
|
+
console.log('addUserData', request);
|
|
21
|
+
return fetchClient('POST', request, '/subscription/addCustomField', !!dev);
|
|
22
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const formatDate: (timestamp: any) => string | null;
|
|
2
|
+
export declare const showAlert: (title: string, body: string) => void;
|
|
3
|
+
export declare const showAlertLink: (title: string, body: string, appName: string, link: string) => Promise<unknown>;
|
|
4
|
+
export declare const isEmpty: (obj: any) => boolean;
|