@inngageregistry/inngage-react 4.0.0-beta.2 → 4.0.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/README.md +60 -60
- package/dist/Inngage.d.ts +28 -0
- package/dist/Inngage.js +161 -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_config.d.ts +3 -0
- package/dist/firebase/notifications_config.js +30 -0
- package/dist/firebase/notifications_listener.d.ts +8 -0
- package/dist/firebase/notifications_listener.js +202 -0
- package/{src/index.ts → dist/index.d.ts} +6 -11
- 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 +5 -0
- package/dist/utils.js +26 -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 -192
- package/src/components/modal.tsx +0 -221
- package/src/components/styles.ts +0 -88
- package/src/firebase/notifications_listener.ts +0 -182
- 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
|
@@ -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,5 @@
|
|
|
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;
|
|
5
|
+
export declare const toStringValue: (v: unknown) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Alert } from 'react-native';
|
|
2
|
+
export const formatDate = (timestamp) => {
|
|
3
|
+
if (!timestamp) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
return new Date(timestamp).toISOString();
|
|
7
|
+
};
|
|
8
|
+
export const showAlert = (title, body) => {
|
|
9
|
+
Alert.alert(title, body, [{ text: 'OK', onPress: () => console.log('OK Pressed') }], {
|
|
10
|
+
cancelable: false,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const showAlertLink = (title, body, appName, link) => {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
Alert.alert(title, `${body}\n\n${link}`, [{ text: 'NO', onPress: () => resolve(false) }, { text: 'OK', onPress: () => resolve(true) }], { cancelable: false });
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export const isEmpty = (obj) => {
|
|
19
|
+
for (var prop in obj) {
|
|
20
|
+
if (obj.hasOwnProperty(prop)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(obj) === JSON.stringify({});
|
|
25
|
+
};
|
|
26
|
+
export const toStringValue = (v) => typeof v === 'string' ? v : JSON.stringify(v ?? '');
|
package/package.json
CHANGED
|
@@ -1,41 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@inngageregistry/inngage-react",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "Inngage Plugin for React Native applications for marketing campaign optimization using Push Notification.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@inngageregistry/inngage-react",
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "Inngage Plugin for React Native applications for marketing campaign optimization using Push Notification.",
|
|
5
|
+
"author": "Inngage Developer",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/inngage/inngage-react.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/inngage/inngage-react/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/inngage/inngage-react#readme",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"react-native": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"react-native": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"scripts": {
|
|
30
|
+
"clean": "rimraf dist",
|
|
31
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
32
|
+
"prepare": "npm run build",
|
|
33
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@notifee/react-native": ">=7 <10",
|
|
38
|
+
"@react-native-async-storage/async-storage": ">=2.1.0 <3",
|
|
39
|
+
"@react-native-firebase/app": ">=20.0.0 <24",
|
|
40
|
+
"@react-native-firebase/messaging": ">=20.0.0 <24",
|
|
41
|
+
"react": ">=18.2.0 <20",
|
|
42
|
+
"react-native": ">=0.72.0 <0.83.0",
|
|
43
|
+
"react-native-device-info": ">=10.0.0 <15",
|
|
44
|
+
"react-native-inappbrowser-reborn": ">=3.0.0 <4",
|
|
45
|
+
"react-native-localize": ">=3.0.0 <4",
|
|
46
|
+
"react-native-permissions": ">=5.0.0 <6"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@react-native-async-storage/async-storage": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@react-native-firebase/app": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@react-native-firebase/messaging": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"react-native-device-info": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"react-native-inappbrowser-reborn": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"react-native-localize": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"react-native-permissions": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"@notifee/react-native": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/react": "^19.2.2",
|
|
76
|
+
"@types/react-test-renderer": "^19.0.0",
|
|
77
|
+
"rimraf": "^6.0.0",
|
|
78
|
+
"typescript": "^5.6.0"
|
|
79
|
+
}
|
|
41
80
|
}
|
package/.editorconfig
DELETED
package/src/Inngage.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { firebase } from '@react-native-firebase/messaging';
|
|
2
|
-
import DeviceInfo from "react-native-device-info";
|
|
3
|
-
import * as RNLocalize from "react-native-localize";
|
|
4
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
5
|
-
|
|
6
|
-
import { formatDate } from "./utils";
|
|
7
|
-
import { InngageNotificationMessage, messagingHeadlessTask } from "./firebase/notifications_listener";
|
|
8
|
-
import { InngageProperties } from './models/inngage_properties';
|
|
9
|
-
|
|
10
|
-
import RNPermissions, { NotificationOption, RESULTS } from 'react-native-permissions';
|
|
11
|
-
|
|
12
|
-
import ApiService from './services/api_services';
|
|
13
|
-
|
|
14
|
-
const API_LEVEL_33 = 33;
|
|
15
|
-
|
|
16
|
-
// --- Get Firebase Access ------/
|
|
17
|
-
const getFirebaseAccess = async () => {
|
|
18
|
-
return await handleNotificationsPermission();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const handleNotificationsPermission = async () => {
|
|
22
|
-
const options: NotificationOption[] = ['alert', 'badge', 'sound'];
|
|
23
|
-
const apiLevel = await DeviceInfo.getApiLevel();
|
|
24
|
-
|
|
25
|
-
const permissionGranted =
|
|
26
|
-
apiLevel >= API_LEVEL_33
|
|
27
|
-
? (await RNPermissions.requestNotifications(options)).status === RESULTS.GRANTED
|
|
28
|
-
: (await firebase.messaging().requestPermission()) ===
|
|
29
|
-
firebase.messaging.AuthorizationStatus.AUTHORIZED ||
|
|
30
|
-
firebase.messaging.AuthorizationStatus.PROVISIONAL;
|
|
31
|
-
|
|
32
|
-
if (permissionGranted) {
|
|
33
|
-
return await getFirebaseToken();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
throw new Error('Notification permission not granted');
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getFirebaseToken = async () => {
|
|
40
|
-
let fcmToken = await AsyncStorage.getItem('fcmToken');
|
|
41
|
-
|
|
42
|
-
if (!fcmToken) {
|
|
43
|
-
if (!firebase.messaging().isDeviceRegisteredForRemoteMessages) {
|
|
44
|
-
await firebase.messaging().registerDeviceForRemoteMessages?.();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const newFcmToken = await firebase.messaging().getToken?.();
|
|
48
|
-
|
|
49
|
-
if (newFcmToken) {
|
|
50
|
-
await AsyncStorage.setItem('fcmToken', newFcmToken);
|
|
51
|
-
return newFcmToken;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return fcmToken || null;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
interface SubscriptionProps {
|
|
59
|
-
appToken: string,
|
|
60
|
-
dev?: boolean,
|
|
61
|
-
friendlyIdentifier?: string,
|
|
62
|
-
customFields?: any,
|
|
63
|
-
customData?: any,
|
|
64
|
-
phoneNumber?: string,
|
|
65
|
-
email?: string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface SendEventProps {
|
|
69
|
-
eventName: string,
|
|
70
|
-
conversionEvent?: boolean,
|
|
71
|
-
conversionValue?: number,
|
|
72
|
-
conversionNotId?: string,
|
|
73
|
-
eventValues?: any
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
class Inngage {
|
|
77
|
-
private static instance: Inngage;
|
|
78
|
-
private apiService: ApiService;
|
|
79
|
-
|
|
80
|
-
constructor() {
|
|
81
|
-
this.apiService = new ApiService();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static getInstance(): Inngage {
|
|
85
|
-
if (!Inngage.instance) {
|
|
86
|
-
Inngage.instance = new Inngage();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return Inngage.instance;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static notificationListener(firebaseListenCallback?: any) {
|
|
93
|
-
try {
|
|
94
|
-
InngageNotificationMessage(firebaseListenCallback)
|
|
95
|
-
} catch (e) {
|
|
96
|
-
console.log(e)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static async subscribe({
|
|
101
|
-
appToken,
|
|
102
|
-
friendlyIdentifier,
|
|
103
|
-
customFields,
|
|
104
|
-
phoneNumber,
|
|
105
|
-
email,
|
|
106
|
-
}: SubscriptionProps) {
|
|
107
|
-
const inngage = Inngage.getInstance();
|
|
108
|
-
|
|
109
|
-
InngageProperties.appToken = appToken;
|
|
110
|
-
InngageProperties.identifier = friendlyIdentifier!;
|
|
111
|
-
|
|
112
|
-
const respToken = await getFirebaseAccess();
|
|
113
|
-
|
|
114
|
-
const { countryCode: osLocale, languageCode: osLanguage } = RNLocalize.getLocales()[0] || {};
|
|
115
|
-
const deviceManufacturer = await DeviceInfo.getManufacturer();
|
|
116
|
-
const installTime = await DeviceInfo.getFirstInstallTime();
|
|
117
|
-
const lastUpdateTime = await DeviceInfo.getLastUpdateTime();
|
|
118
|
-
const uuid = await DeviceInfo.getUniqueId();
|
|
119
|
-
const appInstalledIn = formatDate(installTime);
|
|
120
|
-
const appUpdatedIn = formatDate(lastUpdateTime);
|
|
121
|
-
|
|
122
|
-
const subscription = {
|
|
123
|
-
registerSubscriberRequest: {
|
|
124
|
-
app_token: appToken,
|
|
125
|
-
identifier: friendlyIdentifier,
|
|
126
|
-
registration: respToken,
|
|
127
|
-
platform: DeviceInfo.getSystemName(),
|
|
128
|
-
sdk: DeviceInfo.getBuildNumber(),
|
|
129
|
-
deviceModel: DeviceInfo.getModel(),
|
|
130
|
-
deviceManufacturer,
|
|
131
|
-
osLocale,
|
|
132
|
-
osLanguage,
|
|
133
|
-
os_version: DeviceInfo.getReadableVersion(),
|
|
134
|
-
app_version: DeviceInfo.getBuildNumber(),
|
|
135
|
-
appInstalledIn,
|
|
136
|
-
appUpdatedIn,
|
|
137
|
-
uuid,
|
|
138
|
-
phone_Number: phoneNumber,
|
|
139
|
-
email: email,
|
|
140
|
-
customFields: customFields,
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return inngage.apiService.subscribe(subscription);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
static async sendEvent({
|
|
148
|
-
eventName,
|
|
149
|
-
conversionEvent = false,
|
|
150
|
-
conversionValue = 0,
|
|
151
|
-
conversionNotId = "",
|
|
152
|
-
eventValues,
|
|
153
|
-
}: SendEventProps) {
|
|
154
|
-
const inngage = Inngage.getInstance();
|
|
155
|
-
|
|
156
|
-
const registration = await getFirebaseAccess();
|
|
157
|
-
|
|
158
|
-
const request = {
|
|
159
|
-
newEventRequest: {
|
|
160
|
-
appToken: InngageProperties.appToken,
|
|
161
|
-
identifier: InngageProperties.identifier,
|
|
162
|
-
registration,
|
|
163
|
-
eventName,
|
|
164
|
-
conversionEvent,
|
|
165
|
-
conversionValue,
|
|
166
|
-
conversionNotId,
|
|
167
|
-
eventValues,
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
return inngage.apiService.sendEvent(request);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
static async addUserData(customFields: any): Promise<any> {
|
|
175
|
-
const inngage = Inngage.getInstance();
|
|
176
|
-
|
|
177
|
-
const request = {
|
|
178
|
-
fieldsRequest: {
|
|
179
|
-
appToken: InngageProperties.appToken,
|
|
180
|
-
identifier: InngageProperties.identifier,
|
|
181
|
-
customField: customFields,
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
return inngage.apiService.addUserData(request);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
static setDebugMode(value: boolean) {
|
|
189
|
-
InngageProperties.debugMode = value;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default Inngage;
|
package/src/api/handler.ts
DELETED
|
@@ -1,53 +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 = async (
|
|
34
|
-
method: string,
|
|
35
|
-
requestBody: any,
|
|
36
|
-
path: string,
|
|
37
|
-
isDev = false
|
|
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);
|
|
43
|
-
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
throw new Error(`Network response was not ok (${response.status})`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return response;
|
|
49
|
-
} catch (error: any) {
|
|
50
|
-
console.error('Fetch Error:', error.message);
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|