apps-sdk 1.0.140 → 1.0.141
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 +21 -22
package/package.json
CHANGED
|
@@ -80,39 +80,38 @@ class Networking {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
async request(url, data = {}
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
async request(url, data = {}) {
|
|
84
|
+
let headers = {'Accept': 'application/json', 'Content-Type': 'application/json'};
|
|
85
|
+
const isFormData = data instanceof FormData;
|
|
86
|
+
|
|
87
|
+
if (isFormData) {
|
|
88
|
+
const payloadString = data.get('payload');
|
|
89
|
+
const payload = payloadString ? JSON.parse(payloadString) : {};
|
|
90
|
+
const sessionData = Session.sessionData;
|
|
91
|
+
sessionData.payload = payload;
|
|
92
|
+
data.delete('payload');
|
|
93
|
+
data.append('payload', JSON.stringify(sessionData));
|
|
94
|
+
headers = {'Content-Type': 'multipart/form-data'};
|
|
95
|
+
} else {
|
|
96
|
+
data = JSON.stringify({ ...Session.sessionData, ...data });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let dataConsoleLog = isFormData ? data : JSON.parse(data);
|
|
86
100
|
if (dataConsoleLog && dataConsoleLog.img) {
|
|
87
101
|
dataConsoleLog.img = dataConsoleLog.img.substring(0, 50) + '...';
|
|
88
102
|
}
|
|
89
103
|
config.DEBUG_MODE && console.debug("request data: ", url, dataConsoleLog);
|
|
90
|
-
|
|
91
|
-
let headers = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
92
|
-
|
|
93
|
-
if (encrypt) {
|
|
94
|
-
const secretKey = CryptoES.enc.Utf8.parse(this.ENCRYPT_KEY); // ensure key is 32 bytes
|
|
95
|
-
const iv = CryptoES.lib.WordArray.random(128/8);
|
|
96
|
-
const cipherParams = CryptoES.AES.encrypt(JSON.stringify(data), secretKey, { iv: iv, mode: CryptoES.mode.CBC, padding: CryptoES.pad.Pkcs7 });
|
|
97
|
-
const base64IV = CryptoES.enc.Base64.stringify(iv);
|
|
98
|
-
const base64Ciphertext = cipherParams.ciphertext.toString(CryptoES.enc.Base64);
|
|
99
|
-
data = { data: base64IV + '$' + base64Ciphertext };
|
|
100
|
-
headers['Content-Type'] = 'application/octet-stream; charset=utf-8';
|
|
101
|
-
}
|
|
104
|
+
config.DEBUG_MODE && console.debug("request headers: ", headers);
|
|
102
105
|
|
|
103
106
|
try {
|
|
104
107
|
const response = await fetch(url, {
|
|
105
108
|
method: 'POST',
|
|
106
109
|
headers: headers,
|
|
107
|
-
body:
|
|
110
|
+
body: data
|
|
108
111
|
});
|
|
109
|
-
|
|
110
|
-
return await this.decryptData(await response.json());
|
|
111
|
-
} else {
|
|
112
|
-
return await response.json();
|
|
113
|
-
}
|
|
112
|
+
return await response.json();
|
|
114
113
|
} catch (error) {
|
|
115
|
-
console.log(error)
|
|
114
|
+
console.log(error);
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
117
|
|