apps-sdk 1.0.10 → 1.0.12
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 +1 -1
- package/src/libraries/Networking.js +29 -2
- package/types/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import * as Crypto from 'expo-crypto';
|
|
|
6
6
|
class Networking {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.ENCRYPT_KEY = null;
|
|
9
|
+
this.DEFAULT_ENCRYPT_VALUE = false;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
setEncryptKey() {
|
|
@@ -15,6 +16,11 @@ class Networking {
|
|
|
15
16
|
getEncryptKey(value) {
|
|
16
17
|
this.ENCRYPT_KEY = value;
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
setDefaultEncryptValue(value) {
|
|
21
|
+
this.DEFAULT_ENCRYPT_VALUE = value;
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
async trackEvent(wid, event, user_id=null) {
|
|
19
25
|
let data = {
|
|
20
26
|
date : Date.now(),
|
|
@@ -81,7 +87,7 @@ class Networking {
|
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
|
|
84
|
-
async request(url, data = {}, encrypt =
|
|
90
|
+
async request(url, data = {}, encrypt = this.DEFAULT_ENCRYPT_VALUE) {
|
|
85
91
|
data = { ...Session.sessionData, ...data };
|
|
86
92
|
config.DEBUG_MODE && console.debug("request data: ", url, data);
|
|
87
93
|
|
|
@@ -104,12 +110,33 @@ class Networking {
|
|
|
104
110
|
headers: headers,
|
|
105
111
|
body: JSON.stringify(data)
|
|
106
112
|
});
|
|
107
|
-
|
|
113
|
+
if (encrypt) {
|
|
114
|
+
return await this.decryptData(await response.json());
|
|
115
|
+
} else {
|
|
116
|
+
return await response.json();
|
|
117
|
+
}
|
|
108
118
|
} catch (error) {
|
|
109
119
|
console.log(error)
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
123
|
+
decryptData = async (data) => {
|
|
124
|
+
if (data && data.data) {
|
|
125
|
+
try {
|
|
126
|
+
const decryptedData = await Crypto.digestStringAsync(
|
|
127
|
+
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
128
|
+
data.data,
|
|
129
|
+
{ encoding: Crypto.CryptoEncoding.BASE64 }
|
|
130
|
+
);
|
|
131
|
+
return JSON.parse(decryptedData);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(error);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return data;
|
|
138
|
+
}
|
|
139
|
+
|
|
113
140
|
setEndpoints(domains) {
|
|
114
141
|
// domains.events && (config.ENDPOINTS.TRACKING = domains.events);
|
|
115
142
|
// domains.audiences && (config.ENDPOINTS.SET_ATTRIBUTION = domains.audiences);
|
package/types/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ declare module 'apps-sdk' {
|
|
|
46
46
|
export class Networking {
|
|
47
47
|
setEncryptKey(key: string): void;
|
|
48
48
|
getEncryptKey(): string;
|
|
49
|
+
setDefaultEncryptValue(value: boolean): void;
|
|
49
50
|
trackEvent(wid: string, event: string, user_id?: string | null): Promise<void>;
|
|
50
51
|
executeInit(): Promise<void>;
|
|
51
52
|
setToken(token: string): Promise<boolean | null>;
|