@inngageregistry/inngage-react 4.0.0-alpha.2 → 4.0.0-beta.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@inngageregistry/inngage-react",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Inngage Plugin for React Native applications for marketing campaign optimization using Push Notification.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.d.ts",
package/src/Inngage.ts CHANGED
@@ -4,18 +4,12 @@ import * as RNLocalize from "react-native-localize";
4
4
  import AsyncStorage from '@react-native-async-storage/async-storage';
5
5
 
6
6
  import { formatDate } from "./utils";
7
- import { InngageNotificationMessage } from "./firebase/notifications_listener";
7
+ import { InngageNotificationMessage, messagingHeadlessTask } from "./firebase/notifications_listener";
8
8
  import { InngageProperties } from './models/inngage_properties';
9
9
 
10
10
  import RNPermissions, { NotificationOption, RESULTS } from 'react-native-permissions';
11
11
 
12
- import ApiService from './services/api_service';
13
-
14
- import {
15
- SUBSCRIBE_REQUEST,
16
- EVENT_REQUEST,
17
- USER_DATA_REQUEST,
18
- } from './models/requests';
12
+ import ApiService from './services/api_services';
19
13
 
20
14
  const API_LEVEL_33 = 33;
21
15
 
@@ -63,7 +57,6 @@ const getFirebaseToken = async () => {
63
57
 
64
58
  interface SubscriptionProps {
65
59
  appToken: string,
66
- enableAlert: boolean,
67
60
  dev?: boolean,
68
61
  friendlyIdentifier?: string,
69
62
  customFields?: any,
@@ -73,10 +66,7 @@ interface SubscriptionProps {
73
66
  }
74
67
 
75
68
  interface SendEventProps {
76
- appToken: string,
77
69
  eventName: string,
78
- identifier?: string,
79
- registration?: string,
80
70
  conversionEvent?: boolean,
81
71
  conversionValue?: number,
82
72
  conversionNotId?: string,
@@ -99,7 +89,7 @@ class Inngage {
99
89
  return Inngage.instance;
100
90
  }
101
91
 
102
- static async notificationListener(firebaseListenCallback?: any) {
92
+ static notificationListener(firebaseListenCallback?: any) {
103
93
  try {
104
94
  InngageNotificationMessage(firebaseListenCallback)
105
95
  } catch (e) {
@@ -156,9 +146,9 @@ class Inngage {
156
146
 
157
147
  static async sendEvent({
158
148
  eventName,
159
- conversionEvent,
160
- conversionValue,
161
- conversionNotId,
149
+ conversionEvent = false,
150
+ conversionValue = 0,
151
+ conversionNotId = "",
162
152
  eventValues,
163
153
  }: SendEventProps) {
164
154
  const inngage = Inngage.getInstance();
@@ -171,7 +161,7 @@ class Inngage {
171
161
  identifier: InngageProperties.identifier,
172
162
  registration,
173
163
  eventName,
174
- conversionEvent: !!conversionEvent,
164
+ conversionEvent,
175
165
  conversionValue,
176
166
  conversionNotId,
177
167
  eventValues,
@@ -1,53 +1,53 @@
1
1
  const baseUrlHook = {
2
- [false as any]: 'https://api.inngage.com.br/v1',
3
- [undefined as any]: 'https://api.inngage.com.br/v1',
4
- [null as any]: 'https://api.inngage.com.br/v1',
5
- [true as any]: 'https://apid.inngage.com.br/v1',
2
+ [false as any]: 'https://api.inngage.com.br/v1',
3
+ [undefined as any]: 'https://api.inngage.com.br/v1',
4
+ [null as any]: 'https://api.inngage.com.br/v1',
5
+ [true as any]: 'https://apid.inngage.com.br/v1',
6
6
  }
7
7
 
8
8
  const requestConfigFactory = (method, request) => {
9
9
 
10
- let header: any = {
11
- Accept: 'application/json',
12
- 'Content-Type': 'application/json',
13
- }
14
- try {
15
- if (request?.registerSubscriberRequest?.authKey) {
16
- header = {
17
- ...header,
18
- Authorization: request.registerSubscriberRequest.authKey
19
- }
10
+ let header: any = {
11
+ Accept: 'application/json',
12
+ 'Content-Type': 'application/json',
13
+ }
14
+ try {
15
+ if (request?.registerSubscriberRequest?.authKey) {
16
+ header = {
17
+ ...header,
18
+ Authorization: request.registerSubscriberRequest.authKey
19
+ }
20
+ }
21
+ } catch (e) {
22
+ console.error(e)
23
+ }
24
+ let objToSend = {
25
+ method,
26
+ body: JSON.stringify(request),
27
+ headers: header
20
28
  }
21
- } catch (e) {
22
- console.error(e)
23
- }
24
- let objToSend = {
25
- method,
26
- body: JSON.stringify(request),
27
- headers: header
28
- }
29
29
 
30
- return objToSend
30
+ return objToSend
31
31
  }
32
32
 
33
33
  export const fetchClient = async (
34
- method: string,
35
- requestBody: any,
36
- path: string,
37
- isDev = false
34
+ method: string,
35
+ requestBody: any,
36
+ path: string,
37
+ isDev = false
38
38
  ): Promise<Response> => {
39
- try {
40
- const url: URL = new URL(`${baseUrlHook[isDev as any]}${path}`);
41
- const request: RequestInit = requestConfigFactory(method, requestBody);
42
- const response: Response = await fetch(url, request);
39
+ try {
40
+ const url: URL = new URL(`${baseUrlHook[isDev as any]}${path}`);
41
+ const request: RequestInit = requestConfigFactory(method, requestBody);
42
+ const response: Response = await fetch(url, request);
43
43
 
44
- if (!response.ok) {
45
- throw new Error(`Network response was not ok (${response.status})`);
46
- }
44
+ if (!response.ok) {
45
+ throw new Error(`Network response was not ok (${response.status})`);
46
+ }
47
47
 
48
- return response;
49
- } catch (error: any) {
50
- console.error('Fetch Error:', error.message);
51
- throw error;
52
- }
48
+ return response;
49
+ } catch (error: any) {
50
+ console.error('Fetch Error:', error.message);
51
+ throw error;
52
+ }
53
53
  };
@@ -1,102 +1,159 @@
1
1
  import * as React from "react";
2
2
  import {
3
- View,
4
- Text,
5
- TouchableOpacity,
6
- ImageBackground,
3
+ StyleSheet,
4
+ Image,
5
+ View,
6
+ Text,
7
+ TouchableOpacity,
8
+ ImageBackground,
9
+ Dimensions,
7
10
  } from "react-native";
8
11
 
9
12
  import AsyncStorage from "@react-native-async-storage/async-storage";
13
+ import Carousel from 'react-native-snap-carousel';
10
14
 
11
15
  import { buildStyles } from "./styles";
12
16
  import { Modal } from "../components/modal";
17
+ import { InngageProperties } from "../models/inngage_properties";
13
18
 
14
19
  interface InAppData {
15
- inapp_message: boolean
16
- title: string
17
- body: string
18
- title_font_color: string
19
- body_font_color: string
20
- background_color: string
21
- btn_left_txt_color: string
22
- btn_left_bg_color: string
23
- btn_right_txt_color: string
24
- btn_right_bg_color: string
25
- background_image: string
26
- btn_left_text: string
27
- btn_left_action_type: string
28
- btn_left_action_link: string
29
- btn_right_text: string
30
- btn_right_action_type: string
31
- btn_right_action_link: string
32
- rick_content: string
33
- inpression: string
34
- bg_img_action_type: string
35
- bg_img_action_link: string
36
- dot_color: string
20
+ inapp_message: boolean
21
+ title: string
22
+ body: string
23
+ title_font_color: string
24
+ body_font_color: string
25
+ background_color: string
26
+ btn_left_txt_color: string
27
+ btn_left_bg_color: string
28
+ btn_right_txt_color: string
29
+ btn_right_bg_color: string
30
+ background_image: string
31
+ btn_left_txt: string
32
+ btn_left_action_type: string
33
+ btn_left_action_link: string
34
+ btn_right_txt: string
35
+ btn_right_action_type: string
36
+ btn_right_action_link: string
37
+ rich_content: string
38
+ inpression: string
39
+ bg_img_action_type: string
40
+ bg_img_action_link: string
41
+ dot_color: string
37
42
  }
38
43
 
39
- export function InAppContainer(): JSX.Element {
40
- const [data, setData] = React.useState<InAppData>();
41
- const [visible, setVisible] = React.useState(false);
42
-
43
- React.useEffect(() => {
44
- const fetchAdditionalData = async () => {
45
- try {
46
- const data = await AsyncStorage.getItem('inapp');
47
- if (data) {
48
- const parsedData = JSON.parse(data);
49
-
50
- setVisible(true);
51
- setData(parsedData);
52
- }
53
- } catch (error) {
54
- console.error('Error retrieving additionalData from AsyncStorage:', error);
55
- }
56
- };
57
-
58
- fetchAdditionalData();
59
- }, []);
60
-
61
- const styles = buildStyles(data);
62
-
63
- const handleDismissInApp = async () => {
64
- await AsyncStorage.removeItem('inapp');
65
- setVisible(false);
66
- }
67
-
68
- if (data != null)
69
- console.log('data in app', data)
70
-
71
- return (
72
- <Modal
73
- renderToHardwareTextureAndroid={true}
74
- transparent={true}
75
- visible={visible}>
76
- <ImageBackground style={styles.content} source={{ uri: data?.background_image }}>
77
- <TouchableOpacity style={styles.closeButton} onPress={handleDismissInApp}>
78
- <Text>X</Text>
79
- </TouchableOpacity>
80
- <View style={styles.messageData}>
81
- <Text style={styles.title}>{data?.title}</Text>
82
- <Text style={styles.body}>{data?.body}</Text>
83
- </View>
84
- <View style={styles.footer}>
85
- <TouchableOpacity
86
- style={styles.buttonLeft}>
87
- <Text style={styles.textButton}>{data?.btn_left_text}</Text>
88
- </TouchableOpacity>
89
- <TouchableOpacity
90
- style={styles.buttonRight}>
91
- <Text style={styles.textButton}>{data?.btn_right_text}</Text>
92
- </TouchableOpacity>
93
- </View>
94
- </ImageBackground>
95
- </Modal>
96
- )
44
+ interface InAppRichContent {
45
+ carousel: boolean
46
+ img1: string
47
+ img2: string
48
+ img3: string
49
+ img4: string
50
+ img5: string
97
51
  }
98
52
 
53
+ interface InAppProps {
54
+ onDismiss: () => void;
55
+ }
99
56
 
100
-
101
-
102
-
57
+ export function InApp({ onDismiss }: InAppProps): JSX.Element {
58
+ const { width: screenWidth } = Dimensions.get('window');
59
+
60
+ const sliderWidth = screenWidth;
61
+ const itemWidth = screenWidth * 0.9;
62
+
63
+ const [data, setData] = React.useState<InAppData>();
64
+ const [richContent, setRichContent] = React.useState<InAppRichContent>();
65
+ const [visible, setVisible] = React.useState(false);
66
+
67
+ React.useEffect(() => {
68
+ const fetchAdditionalData = async () => {
69
+ try {
70
+ console.log('in app message')
71
+ const data = await AsyncStorage.getItem('inapp');
72
+ if (data) {
73
+ const parsedData = JSON.parse(data);
74
+ const richContentData = parsedData.rich_content;
75
+
76
+ setVisible(true);
77
+ setData(parsedData);
78
+ setRichContent(richContentData);
79
+ }
80
+ } catch (error) {
81
+ console.error('Error retrieving additionalData from AsyncStorage:', error);
82
+ }
83
+ };
84
+
85
+ fetchAdditionalData();
86
+ }, []);
87
+
88
+ const styles = buildStyles(data, screenWidth * 0.9);
89
+
90
+ const handleDismissInApp = async () => {
91
+ await AsyncStorage.removeItem('inapp');
92
+ setVisible(false);
93
+ onDismiss();
94
+ }
95
+
96
+ const imageUrls: string[] = [
97
+ richContent?.img1 ?? '',
98
+ richContent?.img2 ?? '',
99
+ richContent?.img3 ?? '',
100
+ richContent?.img4 ?? '',
101
+ richContent?.img5 ?? ''
102
+ ];
103
+
104
+ const stylesCarousel = StyleSheet.create({
105
+ itemContainer: {
106
+ justifyContent: 'center',
107
+ height: 250
108
+ },
109
+ itemImg: {
110
+ height: 250,
111
+ },
112
+ });
113
+
114
+ const _renderItem = ({ item, index }) => {
115
+ return (
116
+ <View style={stylesCarousel.itemContainer}>
117
+ <Image style={[stylesCarousel.itemImg]} source={{ uri: item }} />
118
+ </View>
119
+ )
120
+ }
121
+
122
+ if (InngageProperties.getDebugMode() && data != null) {
123
+ console.log('INNGAGE - Data In App:', data)
124
+ console.log('INNGAGE - Data Rich Content:', richContent)
125
+ }
126
+
127
+ return (
128
+ <Modal
129
+ renderToHardwareTextureAndroid={true}
130
+ transparent={true}
131
+ visible={visible}>
132
+ <ImageBackground style={styles.content} source={{ uri: data?.background_image }}>
133
+ {richContent?.carousel ? <Carousel
134
+ layout={"default"}
135
+ data={imageUrls}
136
+ sliderWidth={sliderWidth}
137
+ itemWidth={itemWidth}
138
+ renderItem={_renderItem} /> : null}
139
+ <TouchableOpacity style={styles.closeButton} onPress={handleDismissInApp}>
140
+ <Text>X</Text>
141
+ </TouchableOpacity>
142
+ <View style={styles.messageData}>
143
+ <Text style={styles.title}>{data?.title}</Text>
144
+ <Text style={styles.body}>{data?.body}</Text>
145
+ </View>
146
+ <View style={styles.footer}>
147
+ {data?.btn_left_txt != null ? <TouchableOpacity
148
+ style={styles.buttonLeft}>
149
+ <Text style={styles.textButton}>{data?.btn_left_txt}</Text>
150
+ </TouchableOpacity> : null}
151
+ {data?.btn_right_txt != null ? <TouchableOpacity
152
+ style={styles.buttonRight}>
153
+ <Text style={styles.textButton}>{data?.btn_right_txt}</Text>
154
+ </TouchableOpacity> : null}
155
+ </View>
156
+ </ImageBackground>
157
+ </Modal>
158
+ )
159
+ }
@@ -1,97 +1,70 @@
1
- import { Platform, PlatformColor, StyleSheet } from "react-native";
1
+ import { PlatformColor, StyleSheet } from "react-native";
2
2
 
3
3
 
4
- export const buildStyles = (data: any) => StyleSheet.create({
4
+ export const buildStyles = (data: any, screen: any) => StyleSheet.create({
5
5
  closeButton: {
6
6
  position: 'absolute',
7
7
  top: 10,
8
8
  right: 10,
9
9
  zIndex: 10,
10
10
  },
11
- content: Platform.select({
12
- android: {
13
- backgroundColor: data?.background_color,
14
- flexDirection: "column",
15
- borderRadius: 3,
16
- padding: 16,
17
- margin: 16,
18
- overflow: "hidden",
19
- elevation: 10,
20
- minWidth: 300,
21
- alignItems: "center"
22
- },
23
- default: {}
24
- }),
25
- messageData: Platform.select({
26
- android: {
27
- marginTop: 12
28
- },
29
- default: {}
30
- }),
11
+ content: {
12
+ backgroundColor: data?.background_color,
13
+ flexDirection: "column",
14
+ borderRadius: 3,
15
+ paddingBottom: 16,
16
+ paddingRight: 16,
17
+ paddingLeft: 16,
18
+ margin: 16,
19
+ overflow: "hidden",
20
+ elevation: 10,
21
+ width: screen,
22
+ alignItems: "center"
23
+ },
24
+ messageData: { marginTop: 12 },
31
25
  footer: {
32
26
  flexDirection: "row",
33
- ...Platform.select({
34
- android: {
35
- alignItems: "center",
36
- justifyContent: "flex-end",
37
- marginTop: 4,
38
- },
39
- default: {},
40
- }),
27
+ alignItems: "center",
28
+ justifyContent: "flex-end",
29
+ marginTop: 4,
30
+ },
31
+ title: {
32
+ color: PlatformColor(
33
+ `@android:color/${"primary_text_light"}`
34
+ ),
35
+ fontWeight: "500",
36
+ fontSize: 18,
37
+ },
38
+ body: {
39
+ color: PlatformColor(
40
+ `@android:color/${"secondary_text_light"}`
41
+ ),
42
+ fontSize: 16,
43
+ marginTop: 10,
44
+ marginBottom: 10,
45
+ },
46
+ buttonLeft: {
47
+ margin: 2,
48
+ flex: 1,
49
+ backgroundColor: data?.btn_left_bg_color,
50
+ justifyContent: "center",
51
+ alignItems: "center",
52
+ },
53
+ buttonRight: {
54
+ margin: 2,
55
+ flex: 1,
56
+ backgroundColor: data?.btn_right_bg_color,
57
+ justifyContent: "center",
58
+ alignItems: "center",
59
+ },
60
+ textButton: {
61
+ color: PlatformColor(
62
+ `@android:color/${"secondary_text_light"}`
63
+ ),
64
+ textAlign: "center",
65
+ backgroundColor: "transparent",
66
+ padding: 8,
67
+ fontSize: 14,
68
+ textTransform: "uppercase",
41
69
  },
42
- title: Platform.select({
43
- android: {
44
- color: PlatformColor(
45
- `@android:color/${"primary_text_light"}`
46
- ),
47
- fontWeight: "500",
48
- fontSize: 18,
49
- },
50
-
51
- default: {},
52
- }),
53
- body: Platform.select({
54
- android: {
55
- color: PlatformColor(
56
- `@android:color/${"secondary_text_light"}`
57
- ),
58
- fontSize: 16,
59
- marginTop: 10,
60
- marginBottom: 10,
61
- },
62
- default: {},
63
- }),
64
- buttonLeft: Platform.select({
65
- android: {
66
- margin: 2,
67
- flex: 1,
68
- backgroundColor: data?.btn_left_bg_color,
69
- justifyContent: "center",
70
- alignItems: "center",
71
- },
72
- default: {},
73
- }),
74
- buttonRight: Platform.select({
75
- android: {
76
- margin: 2,
77
- flex: 1,
78
- backgroundColor: data?.btn_right_bg_color,
79
- justifyContent: "center",
80
- alignItems: "center",
81
- },
82
- default: {},
83
- }),
84
- textButton: Platform.select({
85
- android: {
86
- color: PlatformColor(
87
- `@android:color/${"secondary_text_light"}`
88
- ),
89
- textAlign: "center",
90
- backgroundColor: "transparent",
91
- padding: 8,
92
- fontSize: 14,
93
- textTransform: "uppercase",
94
- },
95
- default: {},
96
- }),
97
70
  })
@@ -1,4 +1,4 @@
1
- import { useEffect } from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
 
3
3
  import AsyncStorage from '@react-native-async-storage/async-storage';
4
4
 
@@ -6,7 +6,48 @@ import messaging from '@react-native-firebase/messaging';
6
6
  import PushNotification, { Importance } from 'react-native-push-notification'
7
7
 
8
8
  import { InngageProperties } from '../models/inngage_properties';
9
- import * as ApiService from '../services/api_service'
9
+ import * as ApiService from '../services/api_services'
10
+ import { AppState } from 'react-native';
11
+
12
+ export const messagingHeadlessTask = () => {
13
+ return messaging().setBackgroundMessageHandler(async remoteMessage => {
14
+ if (InngageProperties.getDebugMode())
15
+ console.log('INNGAGE BACKGROUND AND CLOSED DATA: ', remoteMessage)
16
+
17
+ if (remoteMessage?.data?.additional_data != null) {
18
+ await AsyncStorage.setItem('inapp', remoteMessage?.data?.additional_data);
19
+ }
20
+
21
+ return Promise.resolve();
22
+ });
23
+ }
24
+
25
+ export const useInAppHandler = () => {
26
+ const [showInApp, setShowInApp] = useState(false);
27
+
28
+ useEffect(() => {
29
+ const checkInAppData = async () => {
30
+ const inAppData = await AsyncStorage.getItem('inapp');
31
+ if (inAppData) {
32
+ setShowInApp(true);
33
+ }
34
+ };
35
+
36
+ checkInAppData();
37
+
38
+ const subscription = AppState.addEventListener('change', nextAppState => {
39
+ if (nextAppState === 'active') {
40
+ checkInAppData();
41
+ }
42
+ });
43
+
44
+ return () => {
45
+ subscription.remove();
46
+ };
47
+ }, []);
48
+
49
+ return { showInApp, setShowInApp };
50
+ }
10
51
 
11
52
  export const InngageNotificationMessage = (firebaseListenCallback?: any) => {
12
53
  useEffect(() => {
@@ -61,29 +102,16 @@ export const InngageNotificationMessage = (firebaseListenCallback?: any) => {
61
102
  }, []);
62
103
 
63
104
  useEffect(() => {
64
- const backgroundHandler = async (remoteMessage: any) => {
65
- const notificationData = remoteMessage.data;
66
-
67
- if (InngageProperties.getDebugMode())
68
- console.log('Remote message received in background: ', remoteMessage);
69
-
105
+ messaging().onNotificationOpenedApp(remoteMessage => {
70
106
  if (remoteMessage != null)
71
107
  firebaseListenCallback(remoteMessage.data)
72
108
 
73
- if (notificationData.additional_data != null)
74
- await AsyncStorage.setItem('inapp', notificationData.additional_data);
75
-
76
- messaging().onNotificationOpenedApp(remoteMessage => {
77
- handleNotification(remoteMessage)
78
- })
79
- };
80
-
81
- return messaging().setBackgroundMessageHandler(backgroundHandler);
109
+ handleNotification(remoteMessage)
110
+ })
82
111
  }, []);
83
112
 
84
113
  useEffect(() => {
85
114
  messaging().getInitialNotification().then(async (value) => {
86
-
87
115
  if (value !== null)
88
116
  handleUniqueRemoteMessage(value);
89
117
  });
@@ -92,6 +120,7 @@ export const InngageNotificationMessage = (firebaseListenCallback?: any) => {
92
120
  const handleUniqueRemoteMessage = async (
93
121
  remoteMessage: { messageId?: string }) => {
94
122
  try {
123
+ console.log('oi')
95
124
  const lastRemoteMessageId = await AsyncStorage.getItem('LAST_REMOTE_MESSAGE_ID');
96
125
  const newRemoteMessageId = remoteMessage?.messageId;
97
126
 
@@ -100,7 +129,7 @@ export const InngageNotificationMessage = (firebaseListenCallback?: any) => {
100
129
  handleNotification(remoteMessage)
101
130
  }
102
131
  } catch (e) {
103
- console.log(e);
132
+ console.error(e);
104
133
  }
105
134
  };
106
135
 
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { InAppContainer } from './components/in_app';
1
+ import { InApp } from './components/in_app';
2
2
  import Inngage from './Inngage';
3
3
 
4
4
  //-------------- In-APP Component -------------//
5
- export { InAppContainer };
5
+ export { InApp };
6
6
 
7
7
  //-------------- Inngage Wrapper --------------//
8
8
  export default Inngage;
@@ -0,0 +1,41 @@
1
+ const baseUrlHook = {
2
+ [false as any]: 'https://api.inngage.com.br/v1',
3
+ [undefined as any]: 'https://api.inngage.com.br/v1',
4
+ [null as any]: 'https://api.inngage.com.br/v1',
5
+ [true as any]: 'https://apid.inngage.com.br/v1',
6
+ }
7
+
8
+ const requestConfigFactory = (method, request) => {
9
+
10
+ let header: any = {
11
+ Accept: 'application/json',
12
+ 'Content-Type': 'application/json',
13
+ }
14
+ try {
15
+ if (request?.registerSubscriberRequest?.authKey) {
16
+ header = {
17
+ ...header,
18
+ Authorization: request.registerSubscriberRequest.authKey
19
+ }
20
+ }
21
+ } catch (e) {
22
+ console.error(e)
23
+ }
24
+ let objToSend = {
25
+ method,
26
+ body: JSON.stringify(request),
27
+ headers: header
28
+ }
29
+
30
+ return objToSend
31
+ }
32
+
33
+ export const fetchClient = (method, requestBody, path, isDev = false): Promise<Response> => {
34
+ return new Promise((resolve) => {
35
+ const url = String(baseUrlHook[isDev as any]).concat(path)
36
+ const request = requestConfigFactory(method, requestBody)
37
+ fetch(url, request)
38
+ .then(resolve)
39
+ .catch(err => console.error('Fetch Error', err))
40
+ })
41
+ }
@@ -0,0 +1,23 @@
1
+ import { InngageProperties } from '../models/inngage_properties'
2
+ import { fetchClient } from './handler'
3
+
4
+ export const subscriptionApi = (request, dev = false) => {
5
+ if (InngageProperties.getDebugMode())
6
+ console.log('subscriptionApi', request)
7
+ return fetchClient('POST', request, '/subscription/', !!dev)
8
+ }
9
+ export const notificationApi = (request, dev = false) => {
10
+ if (InngageProperties.getDebugMode())
11
+ console.log('notificationApi', request)
12
+ return fetchClient('POST', request, '/notification/', !!dev)
13
+ }
14
+ export const eventsApi = (request, dev = false) => {
15
+ if (InngageProperties.getDebugMode())
16
+ console.log('eventsApi', request)
17
+ return fetchClient('POST', request, '/events/newEvent/', !!dev)
18
+ }
19
+ export const addUserDataApi = (request, dev = false) => {
20
+ if (InngageProperties.getDebugMode())
21
+ console.log('addUserData', request)
22
+ return fetchClient('POST', request, '/subscription/addCustomField', !!dev)
23
+ }