@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.
Files changed (43) hide show
  1. package/README.md +61 -40
  2. package/dist/Inngage.d.ts +28 -0
  3. package/dist/Inngage.js +149 -0
  4. package/dist/api/api.d.ts +4 -0
  5. package/{src/api/api.ts → dist/api/api.js} +22 -28
  6. package/dist/api/handler.d.ts +1 -0
  7. package/dist/api/handler.js +44 -0
  8. package/dist/components/in_app.d.ts +6 -0
  9. package/dist/components/in_app.js +92 -0
  10. package/dist/components/modal.d.ts +26 -0
  11. package/dist/components/modal.js +158 -0
  12. package/dist/components/styles.d.ts +88 -0
  13. package/dist/components/styles.js +86 -0
  14. package/dist/firebase/notifications_listener.d.ts +6 -0
  15. package/dist/firebase/notifications_listener.js +170 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +6 -0
  18. package/dist/models/inngage_properties.d.ts +11 -0
  19. package/dist/models/inngage_properties.js +13 -0
  20. package/dist/models/requests.d.ts +40 -0
  21. package/{src/models/requests.ts → dist/models/requests.js} +40 -42
  22. package/dist/services/api_services.d.ts +7 -0
  23. package/{src/services/api_services.ts → dist/services/api_services.js} +25 -30
  24. package/dist/services/handler.d.ts +1 -0
  25. package/dist/services/handler.js +38 -0
  26. package/dist/services/inngage.d.ts +4 -0
  27. package/dist/services/inngage.js +22 -0
  28. package/dist/utils.d.ts +4 -0
  29. package/dist/utils.js +25 -0
  30. package/package.json +79 -40
  31. package/.editorconfig +0 -6
  32. package/src/Inngage.ts +0 -193
  33. package/src/api/handler.ts +0 -53
  34. package/src/components/in_app.tsx +0 -159
  35. package/src/components/modal.tsx +0 -221
  36. package/src/components/styles.ts +0 -70
  37. package/src/firebase/notifications_listener.ts +0 -146
  38. package/src/index.ts +0 -8
  39. package/src/models/inngage_properties.ts +0 -13
  40. package/src/services/handler.ts +0 -41
  41. package/src/services/inngage.ts +0 -23
  42. package/src/utils.ts +0 -35
  43. package/tsconfig.json +0 -27
@@ -1,221 +0,0 @@
1
- import * as React from "react";
2
- import {
3
- Animated, Easing,
4
- Modal as ReactNativeModal,
5
- ModalProps as ReactNativeModalProps,
6
- Platform,
7
- StyleProp,
8
- StyleSheet,
9
- TouchableWithoutFeedback,
10
- ViewStyle
11
- } from "react-native";
12
- import { Component } from "react";
13
-
14
- const MODAL_ANIM_DURATION = 300;
15
- const MODAL_BACKDROP_OPACITY = 0.3;
16
-
17
- const CONTENT_ANIMATION_IN = Platform.select({
18
- ios: {
19
- opacity: {
20
- inputRange: [0, 1],
21
- outputRange: [0, 1],
22
- },
23
- scale: {
24
- inputRange: [0, 0.5, 1],
25
- outputRange: [1.2, 1.1, 1],
26
- },
27
- },
28
- android: {
29
- opacity: {
30
- inputRange: [0, 0.5, 1],
31
- outputRange: [0, 1, 1],
32
- },
33
- scale: {
34
- inputRange: [0, 1],
35
- outputRange: [0.3, 1],
36
- },
37
- },
38
- default: {
39
- opacity: {
40
- inputRange: [0, 0.5, 1],
41
- outputRange: [0, 1, 1],
42
- },
43
- scale: {
44
- inputRange: [0, 1],
45
- outputRange: [0.3, 1],
46
- },
47
- },
48
- });
49
-
50
- const CONTENT_ANIMATION_OUT = Platform.select({
51
- default: {
52
- opacity: {
53
- inputRange: [0, 1],
54
- outputRange: [0, 1],
55
- },
56
- },
57
- });
58
-
59
- export interface ModalProps extends ReactNativeModalProps {
60
- onBackdropPress?: () => void;
61
- onHide?: () => void;
62
- visible?: boolean;
63
- contentStyle?: StyleProp<ViewStyle>;
64
- useNativeDriver?: boolean;
65
- }
66
-
67
- interface ModalState {
68
- visible: boolean;
69
- currentAnimation: "none" | "in" | "out";
70
- }
71
-
72
- export class Modal extends Component<ModalProps, ModalState> {
73
- static defaultProps: Partial<ModalProps> = {
74
- onBackdropPress: () => null,
75
- onHide: () => null,
76
- visible: false,
77
- useNativeDriver: false,
78
- };
79
-
80
- state: ModalState = {
81
- visible: Boolean(this.props.visible),
82
- currentAnimation: "none",
83
- };
84
-
85
- animVal = new Animated.Value(0);
86
- _isMounted = false;
87
-
88
- componentDidMount() {
89
- this._isMounted = true;
90
- if (this.state.visible) {
91
- this.show();
92
- }
93
- }
94
-
95
- componentWillUnmount() {
96
- this._isMounted = false;
97
- }
98
-
99
- componentDidUpdate(prevProps: ModalProps) {
100
- if (this.props.visible && !prevProps.visible) {
101
- this.show();
102
- } else if (!this.props.visible && prevProps.visible) {
103
- this.hide();
104
- }
105
- }
106
-
107
- show = () => {
108
- this.setState({ visible: true, currentAnimation: "in" }, () => {
109
- Animated.timing(this.animVal, {
110
- easing: Easing.inOut(Easing.quad),
111
- useNativeDriver: Boolean(this.props.useNativeDriver),
112
- duration: MODAL_ANIM_DURATION,
113
- toValue: 1,
114
- }).start(() => {
115
- this.setState({ currentAnimation: "none" });
116
- });
117
- });
118
- };
119
-
120
- hide = () => {
121
- this.setState({ currentAnimation: "out" }, () => {
122
- Animated.timing(this.animVal, {
123
- easing: Easing.inOut(Easing.quad),
124
- useNativeDriver: Boolean(this.props.useNativeDriver),
125
- duration: MODAL_ANIM_DURATION,
126
- toValue: 0,
127
- }).start(() => {
128
- if (this._isMounted) {
129
- this.setState({ currentAnimation: "none" });
130
- this.setState({ visible: false }, this.props.onHide);
131
- }
132
- });
133
- });
134
- };
135
-
136
- render() {
137
- const {
138
- children,
139
- onBackdropPress,
140
- contentStyle,
141
- ...otherProps
142
- } = this.props;
143
- const { currentAnimation, visible } = this.state;
144
-
145
- const backdropAnimatedStyle = {
146
- opacity: this.animVal.interpolate({
147
- inputRange: [0, 1],
148
- outputRange: [0, MODAL_BACKDROP_OPACITY],
149
- }),
150
- };
151
-
152
- const contentAnimatedStyle =
153
- currentAnimation === "in"
154
- ? {
155
- opacity: this.animVal.interpolate({
156
- inputRange: CONTENT_ANIMATION_IN.opacity.inputRange,
157
- outputRange: CONTENT_ANIMATION_IN.opacity.outputRange,
158
- extrapolate: "clamp",
159
- }),
160
- transform: [
161
- {
162
- scale: this.animVal.interpolate({
163
- inputRange: CONTENT_ANIMATION_IN.scale.inputRange,
164
- outputRange: CONTENT_ANIMATION_IN.scale.outputRange,
165
- extrapolate: "clamp",
166
- }),
167
- },
168
- ],
169
- }
170
- : {
171
- opacity: this.animVal.interpolate({
172
- inputRange: CONTENT_ANIMATION_OUT.opacity.inputRange,
173
- outputRange: CONTENT_ANIMATION_OUT.opacity.outputRange,
174
- extrapolate: "clamp",
175
- }),
176
- };
177
-
178
- return (
179
- <ReactNativeModal
180
- transparent
181
- animationType="none"
182
- {...otherProps}
183
- visible={visible}
184
- >
185
- <TouchableWithoutFeedback onPress={onBackdropPress}>
186
- <Animated.View style={[styles.backdrop, backdropAnimatedStyle]} />
187
- </TouchableWithoutFeedback>
188
- {visible && (
189
- <Animated.View
190
- style={[styles.content, contentAnimatedStyle, contentStyle]}
191
- pointerEvents="box-none"
192
- needsOffscreenAlphaCompositing={["in", "out"].includes(
193
- currentAnimation
194
- )}
195
- >
196
- {children}
197
- </Animated.View>
198
- )}
199
- </ReactNativeModal>
200
- );
201
- }
202
- }
203
-
204
- const styles = StyleSheet.create({
205
- backdrop: {
206
- position: "absolute",
207
- top: 0,
208
- bottom: 0,
209
- left: 0,
210
- right: 0,
211
- backgroundColor: "black",
212
- opacity: 0,
213
- },
214
- content: {
215
- flex: 1,
216
- alignItems: "center",
217
- justifyContent: "center",
218
- },
219
- });
220
-
221
- export default Modal;
@@ -1,70 +0,0 @@
1
- import { PlatformColor, StyleSheet } from "react-native";
2
-
3
-
4
- export const buildStyles = (data: any, screen: any) => StyleSheet.create({
5
- closeButton: {
6
- position: 'absolute',
7
- top: 10,
8
- right: 10,
9
- zIndex: 10,
10
- },
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 },
25
- footer: {
26
- flexDirection: "row",
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",
69
- },
70
- })
@@ -1,146 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- import AsyncStorage from '@react-native-async-storage/async-storage';
4
-
5
- import messaging from '@react-native-firebase/messaging';
6
- import PushNotification, { Importance } from 'react-native-push-notification'
7
-
8
- import { InngageProperties } from '../models/inngage_properties';
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
- }
51
-
52
- export const InngageNotificationMessage = (firebaseListenCallback?: any) => {
53
- useEffect(() => {
54
- PushNotification.configure({
55
- onNotification: function (data: any) {
56
- if (data.foreground) {
57
- handleNotification(data)
58
- }
59
- },
60
- popInitialNotification: true,
61
- requestPermissions: true
62
- })
63
- PushNotification.createChannel({
64
- channelId: 'channel_id',
65
- channelName: 'default',
66
- importance: Importance.HIGH,
67
- playSound: true,
68
- soundName: 'default',
69
- vibrate: true
70
- }, (created: any) => {
71
- if (created) {
72
- console.log('Channel created');
73
- }
74
- });
75
- })
76
- useEffect(() => {
77
- const handleMessage = async (remoteMessage: any) => {
78
- const notificationData = remoteMessage.data;
79
-
80
- if (InngageProperties.getDebugMode())
81
- console.log('Remote message received in foreground: ', remoteMessage);
82
-
83
- if (firebaseListenCallback != null && remoteMessage != null)
84
- firebaseListenCallback(notificationData)
85
-
86
- PushNotification.localNotification({
87
- autoCancel: true,
88
- bigPictureUrl: remoteMessage.notification?.android?.imageUrl,
89
- largeIconUrl: remoteMessage.notification?.android?.imageUrl,
90
- title: notificationData?.title,
91
- message: notificationData?.body,
92
- vibration: 300,
93
- channelId: "channel_id",
94
- });
95
-
96
- if (notificationData.additional_data != null)
97
- await AsyncStorage.setItem('inapp', notificationData.additional_data);
98
-
99
- };
100
-
101
- return messaging().onMessage(handleMessage);
102
- }, []);
103
-
104
- useEffect(() => {
105
- messaging().onNotificationOpenedApp(remoteMessage => {
106
- if (remoteMessage != null)
107
- firebaseListenCallback(remoteMessage.data)
108
-
109
- handleNotification(remoteMessage)
110
- })
111
- }, []);
112
-
113
- useEffect(() => {
114
- messaging().getInitialNotification().then(async (value) => {
115
- if (value !== null)
116
- handleUniqueRemoteMessage(value);
117
- });
118
- }, [])
119
-
120
- const handleUniqueRemoteMessage = async (
121
- remoteMessage: { messageId?: string }) => {
122
- try {
123
- console.log('oi')
124
- const lastRemoteMessageId = await AsyncStorage.getItem('LAST_REMOTE_MESSAGE_ID');
125
- const newRemoteMessageId = remoteMessage?.messageId;
126
-
127
- if (newRemoteMessageId && lastRemoteMessageId !== newRemoteMessageId) {
128
- await AsyncStorage.setItem('LAST_REMOTE_MESSAGE_ID', newRemoteMessageId);
129
- handleNotification(remoteMessage)
130
- }
131
- } catch (e) {
132
- console.error(e);
133
- }
134
- };
135
-
136
- async function handleNotification(remoteMessage) {
137
- const notId = remoteMessage.data?.notId;
138
- const request = {
139
- notificationRequest: {
140
- id: notId,
141
- app_token: InngageProperties.appToken,
142
- }
143
- };
144
- await ApiService.sendNotification(request);
145
- }
146
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import { InApp } from './components/in_app';
2
- import Inngage from './Inngage';
3
-
4
- //-------------- In-APP Component -------------//
5
- export { InApp };
6
-
7
- //-------------- Inngage Wrapper --------------//
8
- export default Inngage;
@@ -1,13 +0,0 @@
1
- export 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 = false;
8
- static debugMode: boolean = false;
9
- static firebaseToken: string = '';
10
- static getDebugMode(): boolean {
11
- return InngageProperties.debugMode;
12
- }
13
- }
@@ -1,41 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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
- }
package/src/utils.ts DELETED
@@ -1,35 +0,0 @@
1
- import { Alert } from 'react-native'
2
-
3
- export const formatDate = (timestamp) => {
4
- if (!timestamp) {
5
- return null
6
- }
7
- return new Date(timestamp).toISOString()
8
- }
9
-
10
- export const showAlert = (title: string, body: string) => {
11
- Alert.alert(title, body, [{ text: 'OK', onPress: () => console.log('OK Pressed') }], {
12
- cancelable: false,
13
- })
14
- }
15
-
16
- export const showAlertLink = (title: string, body: string, appName: string, link: string) => {
17
- return new Promise((resolve) => {
18
- Alert.alert(
19
- title,
20
- `${body}\n\n${link}`,
21
- [{ text: 'NO', onPress: () => resolve(false) }, { text: 'OK', onPress: () => resolve(true) }],
22
- { cancelable: false },
23
- )
24
- })
25
- }
26
-
27
- export const isEmpty = (obj: any) => {
28
- for (var prop in obj) {
29
- if (obj.hasOwnProperty(prop)) {
30
- return false;
31
- }
32
- }
33
-
34
- return JSON.stringify(obj) === JSON.stringify({});
35
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "es6",
5
- "declaration": true,
6
- "outDir": "./build",
7
- "strict": true,
8
- "jsx": "react-native",
9
- "esModuleInterop": true,
10
- "allowSyntheticDefaultImports": true,
11
- "skipLibCheck": true,
12
- "moduleResolution": "node",
13
- "noImplicitAny": false,
14
- "lib": [
15
- "dom",
16
- "es2015"
17
- ]
18
- },
19
- "include": [
20
- "**/*"
21
- ],
22
- "exclude": [
23
- "node_modules",
24
- "**/__tests__/*",
25
- "build"
26
- ]
27
- }