swiftyper-node 1.0.7 → 1.0.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/lib/SwiftyperResource.js +18 -4
- package/package.json +1 -1
package/lib/SwiftyperResource.js
CHANGED
|
@@ -195,7 +195,7 @@ SwiftyperResource.prototype = {
|
|
|
195
195
|
_makeHeaders(contentLength, method, userSuppliedHeaders) {
|
|
196
196
|
const defaultHeaders = {
|
|
197
197
|
Accept: 'application/json',
|
|
198
|
-
'Content-Type': 'application/
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
199
|
'Content-Length': contentLength,
|
|
200
200
|
};
|
|
201
201
|
|
|
@@ -305,15 +305,29 @@ SwiftyperResource.prototype = {
|
|
|
305
305
|
req.end();
|
|
306
306
|
};
|
|
307
307
|
|
|
308
|
+
const transformRequestData = (data) => {
|
|
309
|
+
if (typeof data === 'boolean') {
|
|
310
|
+
return data.toString();
|
|
311
|
+
} else if (Array.isArray(data)) {
|
|
312
|
+
return data.map(transformRequestData);
|
|
313
|
+
} else if (typeof data === 'object' && data !== null) {
|
|
314
|
+
return Object.fromEntries(
|
|
315
|
+
Object.entries(data).map(([key, value]) => [key, transformRequestData(value)])
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return data;
|
|
320
|
+
}
|
|
321
|
+
|
|
308
322
|
const prepareAndMakeRequest = (error, data) => {
|
|
309
323
|
if (error) {
|
|
310
324
|
return callback(error);
|
|
311
325
|
}
|
|
312
326
|
|
|
313
|
-
requestData = data;
|
|
327
|
+
requestData = JSON.stringify(transformRequestData(data));
|
|
314
328
|
|
|
315
329
|
const headers = this._makeHeaders(
|
|
316
|
-
requestData
|
|
330
|
+
Buffer.byteLength(requestData, 'utf-8'),
|
|
317
331
|
method,
|
|
318
332
|
options.headers,
|
|
319
333
|
options.settings
|
|
@@ -330,7 +344,7 @@ SwiftyperResource.prototype = {
|
|
|
330
344
|
prepareAndMakeRequest
|
|
331
345
|
);
|
|
332
346
|
} else {
|
|
333
|
-
prepareAndMakeRequest(null,
|
|
347
|
+
prepareAndMakeRequest(null, data);
|
|
334
348
|
}
|
|
335
349
|
},
|
|
336
350
|
};
|