apps-sdk 1.0.140 → 1.0.142

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.140",
3
+ "version": "1.0.142",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -80,39 +80,37 @@ class Networking {
80
80
  }
81
81
  }
82
82
 
83
- async request(url, data = {}, encrypt = this.DEFAULT_ENCRYPT_VALUE) {
84
- data = { ...Session.sessionData, ...data };
85
- let dataConsoleLog = JSON.parse(JSON.stringify(data));
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 mergedPayload = { ...Session.sessionData, ...payload };
91
+ data.delete('payload');
92
+ data.append('payload', JSON.stringify(mergedPayload));
93
+ headers = {'Content-Type': 'multipart/form-data'};
94
+ } else {
95
+ data = JSON.stringify({ ...Session.sessionData, ...data });
96
+ }
97
+
98
+ let dataConsoleLog = isFormData ? data : JSON.parse(data);
86
99
  if (dataConsoleLog && dataConsoleLog.img) {
87
100
  dataConsoleLog.img = dataConsoleLog.img.substring(0, 50) + '...';
88
101
  }
89
102
  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
- }
103
+ config.DEBUG_MODE && console.debug("request headers: ", headers);
102
104
 
103
105
  try {
104
106
  const response = await fetch(url, {
105
107
  method: 'POST',
106
108
  headers: headers,
107
- body: JSON.stringify(data)
109
+ body: data
108
110
  });
109
- if (encrypt) {
110
- return await this.decryptData(await response.json());
111
- } else {
112
- return await response.json();
113
- }
111
+ return await response.json();
114
112
  } catch (error) {
115
- console.log(error)
113
+ console.log(error);
116
114
  }
117
115
  }
118
116