apps-sdk 1.0.7 → 1.0.9
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/config.js +9 -1
- package/package.json +2 -1
- package/src/libraries/Networking.js +67 -10
- package/src/libraries/Session.js +11 -0
- package/src/libraries/Storage.js +8 -0
- package/types/index.d.ts +8 -2
package/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var ENDPOINTS = {
|
|
2
2
|
INIT : 'https://ap0404.gways.org/v6/init',
|
|
3
3
|
NOTIFICATION_TOKEN: 'https://ap0404.gways.org/user/set_expo_id',
|
|
4
4
|
TRACKING: 'https://ap0404.gways.org/v3/',
|
|
@@ -7,4 +7,12 @@ export const ENDPOINTS = {
|
|
|
7
7
|
SET_ATTRIBUTION: 'https://ap0404.gways.org/user/set_attribution_data',
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export var EVENTS = {}
|
|
11
|
+
|
|
12
|
+
export const EVENT_TYPES = {
|
|
13
|
+
ACTION: 'action',
|
|
14
|
+
SCENE: 'scene',
|
|
15
|
+
OTHER: 'other'
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
export const DEBUG_MODE = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Apps SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@react-native-async-storage/async-storage": "^1.21.0",
|
|
13
13
|
"expo-constants": "^15.4.5",
|
|
14
|
+
"expo-crypto": "^12.8.0",
|
|
14
15
|
"expo-device": "^5.9.3",
|
|
15
16
|
"expo-localization": "^14.8.3",
|
|
16
17
|
"expo-notifications": "^0.23.0",
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import * as config from '../../config';
|
|
2
2
|
import { default as storage } from './Storage';
|
|
3
3
|
import Session from './Session';
|
|
4
|
+
import * as Crypto from 'expo-crypto';
|
|
4
5
|
|
|
5
6
|
class Networking {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.ENCRYPT_KEY = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setEncryptKey() {
|
|
12
|
+
return this.ENCRYPT_KEY;
|
|
13
|
+
}
|
|
6
14
|
|
|
15
|
+
getEncryptKey(value) {
|
|
16
|
+
this.ENCRYPT_KEY = value;
|
|
17
|
+
}
|
|
7
18
|
async trackEvent(wid, event, user_id=null) {
|
|
8
19
|
let data = {
|
|
9
20
|
date : Date.now(),
|
|
@@ -11,7 +22,7 @@ class Networking {
|
|
|
11
22
|
event : event
|
|
12
23
|
};
|
|
13
24
|
|
|
14
|
-
await fetch(config.
|
|
25
|
+
await fetch(config.ENDPOINTS.TRACKING, {
|
|
15
26
|
method: 'POST',
|
|
16
27
|
headers: {
|
|
17
28
|
Accept: 'application/json',
|
|
@@ -32,6 +43,8 @@ class Networking {
|
|
|
32
43
|
let initData = await this.request(config.ENDPOINTS.INIT);
|
|
33
44
|
if (initData) {
|
|
34
45
|
config.DEBUG_MODE && console.debug("initData", initData);
|
|
46
|
+
this.setEndpoints(initData.data.domains);
|
|
47
|
+
this.setEvents(initData.data.attribution);
|
|
35
48
|
}
|
|
36
49
|
} catch (error) {
|
|
37
50
|
console.error(error);
|
|
@@ -42,10 +55,10 @@ class Networking {
|
|
|
42
55
|
getUserID = async () => {
|
|
43
56
|
config.DEBUG_MODE && console.debug("getUserID");
|
|
44
57
|
try {
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
config.DEBUG_MODE && console.debug("new userID",
|
|
48
|
-
return
|
|
58
|
+
let userIDData = await this.request(config.ENDPOINTS.GET_USER_ID);
|
|
59
|
+
if (userIDData && userIDData.success === 1) {
|
|
60
|
+
config.DEBUG_MODE && console.debug("new userID", userIDData.data.external_id);
|
|
61
|
+
return userIDData.data.external_id;
|
|
49
62
|
}
|
|
50
63
|
} catch (error) {
|
|
51
64
|
console.error(error);
|
|
@@ -56,7 +69,7 @@ class Networking {
|
|
|
56
69
|
async setToken(token) {
|
|
57
70
|
try {
|
|
58
71
|
const installID = await storage.getData('install_id');
|
|
59
|
-
const response = await fetch(config.
|
|
72
|
+
const response = await fetch(config.ENDPOINTS.TRACKING.replace('[TOKEN]', token).replace('[INSTALL_ID]', installID));
|
|
60
73
|
const json = await response.json();
|
|
61
74
|
if(json.success){
|
|
62
75
|
return true;
|
|
@@ -67,20 +80,64 @@ class Networking {
|
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
|
|
84
|
+
async request(url, data = {}, encrypt = false) {
|
|
71
85
|
data = { ...Session.sessionData, ...data };
|
|
72
86
|
config.DEBUG_MODE && console.debug("request data: ", url, data);
|
|
73
|
-
|
|
87
|
+
|
|
88
|
+
let headers = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
89
|
+
|
|
90
|
+
if (encrypt) {
|
|
91
|
+
const secretKey = this.ENCRYPT_KEY;
|
|
92
|
+
const encryptedData = await Crypto.digestStringAsync(
|
|
93
|
+
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
94
|
+
JSON.stringify(data),
|
|
95
|
+
{ encoding: Crypto.CryptoEncoding.BASE64 }
|
|
96
|
+
);
|
|
97
|
+
data = { data: encryptedData };
|
|
98
|
+
headers['Content-Type'] = 'application/octet-stream';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
74
102
|
const response = await fetch(url, {
|
|
75
103
|
method: 'POST',
|
|
76
|
-
headers:
|
|
104
|
+
headers: headers,
|
|
77
105
|
body: JSON.stringify(data)
|
|
78
106
|
});
|
|
79
107
|
return await response.json();
|
|
80
|
-
} catch (error){
|
|
108
|
+
} catch (error) {
|
|
81
109
|
console.log(error)
|
|
82
110
|
}
|
|
83
111
|
}
|
|
112
|
+
|
|
113
|
+
setEndpoints(domains) {
|
|
114
|
+
// domains.events && (config.ENDPOINTS.TRACKING = domains.events);
|
|
115
|
+
// domains.audiences && (config.ENDPOINTS.SET_ATTRIBUTION = domains.audiences);
|
|
116
|
+
// domains.notification_token && (config.ENDPOINTS.NOTIFICATION_TOKEN = domains.notification_token);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setEvents(events) {
|
|
120
|
+
events && (config.EVENTS = events);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sendEvent = async (eventType, eventKeyword, eventData={}) => {
|
|
124
|
+
config.DEBUG_MODE && console.debug("sendEvent", eventType, eventKeyword, eventData);
|
|
125
|
+
try {
|
|
126
|
+
let eventResponse = await this.request(config.ENDPOINTS.TRACKING, {
|
|
127
|
+
event_name: eventType,
|
|
128
|
+
action: eventKeyword,
|
|
129
|
+
data: eventData,
|
|
130
|
+
...Session.sessionData,
|
|
131
|
+
});
|
|
132
|
+
if (eventResponse) {
|
|
133
|
+
config.DEBUG_MODE && console.debug("eventResponse", eventResponse);
|
|
134
|
+
return eventResponse;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
84
141
|
}
|
|
85
142
|
|
|
86
143
|
export default new Networking();
|
package/src/libraries/Session.js
CHANGED
|
@@ -122,6 +122,17 @@ class Session {
|
|
|
122
122
|
setUserID = (userID) => {
|
|
123
123
|
this.sessionData.user_id = userID;
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
sendFirstOpen = async () => {
|
|
127
|
+
config.DEBUG_MODE && console.debug("sendFirstOpen");
|
|
128
|
+
try {
|
|
129
|
+
let result = Networking.sendEvent(config.EVENT_TYPES.OTHER, 'first_open');
|
|
130
|
+
config.DEBUG_MODE && console.debug("sendFirstOpen - result: ", result);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error(error);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
export default new Session();
|
package/src/libraries/Storage.js
CHANGED
|
@@ -21,6 +21,14 @@ class Storage {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
async removeData(key){
|
|
25
|
+
try {
|
|
26
|
+
await AsyncStorage.removeItem(key);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error('Storage Error: Removing ' + key);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
async printAllKeys() {
|
|
25
33
|
try {
|
|
26
34
|
const keys = await AsyncStorage.getAllKeys();
|
package/types/index.d.ts
CHANGED
|
@@ -44,16 +44,22 @@ declare module 'apps-sdk' {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export class Networking {
|
|
47
|
+
setEncryptKey(key: string): void;
|
|
48
|
+
getEncryptKey(): string;
|
|
47
49
|
trackEvent(wid: string, event: string, user_id?: string | null): Promise<void>;
|
|
48
50
|
executeInit(): Promise<void>;
|
|
49
51
|
setToken(token: string): Promise<boolean | null>;
|
|
50
52
|
request(url: string, data?: any): Promise<any>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
setEndpoints(endpoints: any): void;
|
|
54
|
+
setEvents(events: any): void;
|
|
55
|
+
sendEvent(eventType: string, eventKeyword:string, eventData?: object): Promise<void>;
|
|
56
|
+
}
|
|
53
57
|
|
|
54
58
|
export class Storage {
|
|
55
59
|
storeData(key: string, value: any): Promise<void>;
|
|
56
60
|
getData(key: string): Promise<any>;
|
|
61
|
+
printAllKeys(): Promise<void>;
|
|
62
|
+
removeData(key: string): Promise<void>;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
export class NotificationsPush {
|