@inngageregistry/inngage-react 2.2.4 → 2.2.8
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/ListenToNotifications.js +1 -1
- package/index.js +20 -5
- package/inngageApi.js +1 -0
- package/package.json +1 -1
- package/utils.js +23 -9
package/ListenToNotifications.js
CHANGED
|
@@ -4,7 +4,7 @@ import messaging, { firebase } from '@react-native-firebase/messaging';
|
|
|
4
4
|
import DeviceInfo from 'react-native-device-info'
|
|
5
5
|
import { showAlert, showAlertLink } from './utils'
|
|
6
6
|
import { notificationApi } from './inngageApi'
|
|
7
|
-
import AsyncStorage from '@react-native-
|
|
7
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
|
|
9
9
|
export const linkInApp = (link) => {
|
|
10
10
|
InAppBrowser.open(link, {
|
package/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { firebase } from '@react-native-firebase/messaging';
|
|
2
|
-
import InAppBrowser from 'react-native-inappbrowser-reborn'
|
|
3
2
|
import DeviceInfo from "react-native-device-info";
|
|
4
3
|
import * as RNLocalize from "react-native-localize";
|
|
5
4
|
import { formatDate, subscriptionRequestAdapter, showAlertLink } from "./utils";
|
|
6
5
|
import ListenToNotifications, { linkInApp } from "./ListenToNotifications";
|
|
7
|
-
import { subscription,
|
|
8
|
-
import AsyncStorage from '@react-native-
|
|
6
|
+
import { subscription, eventsApi } from "./inngageApi";
|
|
7
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
8
|
import Carousel, { Pagination } from 'react-native-snap-carousel';
|
|
10
9
|
import React, { useState, useEffect, useRef } from 'react';
|
|
11
10
|
import {
|
|
@@ -471,6 +470,7 @@ const getFirebaseAccess = () => {
|
|
|
471
470
|
const Inngage = {
|
|
472
471
|
// ------------ Get Permission ------------------//
|
|
473
472
|
GetPermission: async (props) => {
|
|
473
|
+
|
|
474
474
|
try {
|
|
475
475
|
LogBox.ignoreLogs(['registerHeadlessTask'])
|
|
476
476
|
} catch (e) { }
|
|
@@ -479,7 +479,7 @@ const Inngage = {
|
|
|
479
479
|
} catch (e) { }
|
|
480
480
|
try {
|
|
481
481
|
AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => backgroundNotificationHandler)
|
|
482
|
-
ListenToNotifications(props);
|
|
482
|
+
ListenToNotifications(props);
|
|
483
483
|
} catch (e) {
|
|
484
484
|
console.error(e);
|
|
485
485
|
return { subscribed: false };
|
|
@@ -494,6 +494,7 @@ const Inngage = {
|
|
|
494
494
|
customFields,
|
|
495
495
|
customData,
|
|
496
496
|
phoneNumber,
|
|
497
|
+
authKey
|
|
497
498
|
} = props;
|
|
498
499
|
const respToken = await getFirebaseAccess()
|
|
499
500
|
|
|
@@ -523,15 +524,29 @@ const Inngage = {
|
|
|
523
524
|
app_installed_in,
|
|
524
525
|
app_updated_in,
|
|
525
526
|
uuid: DeviceInfo.getUniqueId(),
|
|
527
|
+
authKey
|
|
526
528
|
}
|
|
527
529
|
};
|
|
528
530
|
|
|
529
531
|
const request = subscriptionRequestAdapter(rawRequest, customData, customFields)
|
|
530
|
-
|
|
532
|
+
const subscribe = await subscription(request, dev);
|
|
533
|
+
console.log(await subscribe.json())
|
|
534
|
+
return subscribe;
|
|
531
535
|
} catch (e) {
|
|
532
536
|
console.error(e);
|
|
533
537
|
return { subscribed: false };
|
|
534
538
|
}
|
|
539
|
+
},
|
|
540
|
+
SendEvent: async (props) => {
|
|
541
|
+
const { authKey, newEventRequest } = props
|
|
542
|
+
const rawRequest = {
|
|
543
|
+
registerSubscriberRequest: {
|
|
544
|
+
authKey
|
|
545
|
+
},
|
|
546
|
+
newEventRequest
|
|
547
|
+
}
|
|
548
|
+
const subscribe = await eventsApi(rawRequest);
|
|
549
|
+
return subscribe
|
|
535
550
|
}
|
|
536
551
|
}
|
|
537
552
|
|
package/inngageApi.js
CHANGED
|
@@ -2,3 +2,4 @@ import { fetchClient } from './utils'
|
|
|
2
2
|
|
|
3
3
|
export const subscription = (request, dev = false) => fetchClient('POST', request, '/subscription/', !!dev)
|
|
4
4
|
export const notificationApi = (request, dev = false) => fetchClient('POST', request, '/notification/', !!dev)
|
|
5
|
+
export const eventsApi = (request, dev = false) => fetchClient('POST', request, '/events/newEvent/', !!dev)
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -7,20 +7,34 @@ const baseUrlHook = {
|
|
|
7
7
|
[true]: 'https://apid.inngage.com.br/v1',
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const requestConfigFactory = (method, request) =>
|
|
11
|
-
|
|
10
|
+
const requestConfigFactory = (method, request) => {
|
|
11
|
+
|
|
12
|
+
let header = {
|
|
12
13
|
Accept: 'application/json',
|
|
13
14
|
'Content-Type': 'application/json',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (request.registerSubscriberRequest.authKey) {
|
|
18
|
+
header = {
|
|
19
|
+
...header,
|
|
20
|
+
Authorization: request.registerSubscriberRequest.authKey
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let objToSend = {
|
|
25
|
+
method,
|
|
26
|
+
body: JSON.stringify(request),
|
|
27
|
+
headers: header
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return objToSend
|
|
31
|
+
}
|
|
18
32
|
|
|
19
33
|
export const fetchClient = (method, requestBody, path, isDev = false) => {
|
|
20
34
|
return new Promise((resolve) => {
|
|
21
35
|
const url = String(baseUrlHook[isDev]).concat(path)
|
|
22
36
|
const request = requestConfigFactory(method, requestBody)
|
|
23
|
-
|
|
37
|
+
console.log(request)
|
|
24
38
|
fetch(url, request)
|
|
25
39
|
.then(resolve)
|
|
26
40
|
.catch(err => console.log('Fetch Error', err))
|
|
@@ -28,7 +42,7 @@ export const fetchClient = (method, requestBody, path, isDev = false) => {
|
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
export const formatDate = (timestamp) => {
|
|
31
|
-
if(!timestamp) {
|
|
45
|
+
if (!timestamp) {
|
|
32
46
|
return null
|
|
33
47
|
}
|
|
34
48
|
return new Date(timestamp).toISOString()
|
|
@@ -52,7 +66,7 @@ export const showAlertLink = (title, body, appName, link) => {
|
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
export const subscriptionRequestAdapter = (sdkRequest, useCustomData, customData) => {
|
|
55
|
-
if(useCustomData) {
|
|
69
|
+
if (useCustomData) {
|
|
56
70
|
return {
|
|
57
71
|
registerSubscriberRequest: {
|
|
58
72
|
...sdkRequest.registerSubscriberRequest,
|