ibm-cloud-sdk-core 5.4.15 → 5.4.17
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/es/lib/helper.js +33 -5
- package/es/lib/request-wrapper.js +1 -1
- package/lib/helper.js +33 -5
- package/lib/request-wrapper.js +1 -1
- package/package.json +1 -1
package/es/lib/helper.js
CHANGED
|
@@ -311,14 +311,42 @@ export function isJsonMimeType(mimeType) {
|
|
|
311
311
|
return !!mimeType && /^application\/json(\s*;.*)?$/i.test(mimeType);
|
|
312
312
|
}
|
|
313
313
|
const isObj = (val) => val && typeof val === 'object' && !Array.isArray(val);
|
|
314
|
+
/**
|
|
315
|
+
* Deep clone a value (object, array, or primitive)
|
|
316
|
+
* @param value - The value to clone
|
|
317
|
+
* @returns A deep clone of the value
|
|
318
|
+
*/
|
|
319
|
+
function deepClone(value) {
|
|
320
|
+
if (value == null) {
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
// Handle arrays - create a new array with cloned elements
|
|
324
|
+
if (Array.isArray(value)) {
|
|
325
|
+
return value.map((item) => deepClone(item));
|
|
326
|
+
}
|
|
327
|
+
// Handle objects - create a new object with cloned properties
|
|
328
|
+
if (typeof value === 'object') {
|
|
329
|
+
const cloned = {};
|
|
330
|
+
Object.keys(value).forEach((key) => {
|
|
331
|
+
cloned[key] = deepClone(value[key]);
|
|
332
|
+
});
|
|
333
|
+
return cloned;
|
|
334
|
+
}
|
|
335
|
+
// Handle primitives (string, number, boolean, etc.)
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
314
338
|
export function deepMerge(target, source) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
339
|
+
// Handle null/undefined inputs by treating them as empty objects
|
|
340
|
+
const safeTarget = target || {};
|
|
341
|
+
const safeSource = source || {};
|
|
342
|
+
const result = Object.assign({}, safeTarget);
|
|
343
|
+
Object.keys(safeSource).forEach((key) => {
|
|
344
|
+
if (isObj(safeTarget[key]) && isObj(safeSource[key])) {
|
|
345
|
+
result[key] = deepMerge(safeTarget[key], safeSource[key]);
|
|
319
346
|
}
|
|
320
347
|
else {
|
|
321
|
-
|
|
348
|
+
// Clone the source value to prevent mutation of the original
|
|
349
|
+
result[key] = deepClone(safeSource[key]);
|
|
322
350
|
}
|
|
323
351
|
});
|
|
324
352
|
return result;
|
|
@@ -190,7 +190,7 @@ export class RequestWrapper {
|
|
|
190
190
|
*/
|
|
191
191
|
sendRequest(parameters) {
|
|
192
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
const options = deepMerge(parameters.defaultOptions
|
|
193
|
+
const options = deepMerge(parameters.defaultOptions, parameters.options);
|
|
194
194
|
const { path, body, form, formData, qs, method, serviceUrl, axiosOptions } = options;
|
|
195
195
|
let { headers, url } = options;
|
|
196
196
|
const multipartForm = new FormData();
|
package/lib/helper.js
CHANGED
|
@@ -395,14 +395,42 @@ function isJsonMimeType(mimeType) {
|
|
|
395
395
|
}
|
|
396
396
|
exports.isJsonMimeType = isJsonMimeType;
|
|
397
397
|
var isObj = function (val) { return val && typeof val === 'object' && !Array.isArray(val); };
|
|
398
|
+
/**
|
|
399
|
+
* Deep clone a value (object, array, or primitive)
|
|
400
|
+
* @param value - The value to clone
|
|
401
|
+
* @returns A deep clone of the value
|
|
402
|
+
*/
|
|
403
|
+
function deepClone(value) {
|
|
404
|
+
if (value == null) {
|
|
405
|
+
return value;
|
|
406
|
+
}
|
|
407
|
+
// Handle arrays - create a new array with cloned elements
|
|
408
|
+
if (Array.isArray(value)) {
|
|
409
|
+
return value.map(function (item) { return deepClone(item); });
|
|
410
|
+
}
|
|
411
|
+
// Handle objects - create a new object with cloned properties
|
|
412
|
+
if (typeof value === 'object') {
|
|
413
|
+
var cloned_1 = {};
|
|
414
|
+
Object.keys(value).forEach(function (key) {
|
|
415
|
+
cloned_1[key] = deepClone(value[key]);
|
|
416
|
+
});
|
|
417
|
+
return cloned_1;
|
|
418
|
+
}
|
|
419
|
+
// Handle primitives (string, number, boolean, etc.)
|
|
420
|
+
return value;
|
|
421
|
+
}
|
|
398
422
|
function deepMerge(target, source) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
423
|
+
// Handle null/undefined inputs by treating them as empty objects
|
|
424
|
+
var safeTarget = target || {};
|
|
425
|
+
var safeSource = source || {};
|
|
426
|
+
var result = __assign({}, safeTarget);
|
|
427
|
+
Object.keys(safeSource).forEach(function (key) {
|
|
428
|
+
if (isObj(safeTarget[key]) && isObj(safeSource[key])) {
|
|
429
|
+
result[key] = deepMerge(safeTarget[key], safeSource[key]);
|
|
403
430
|
}
|
|
404
431
|
else {
|
|
405
|
-
|
|
432
|
+
// Clone the source value to prevent mutation of the original
|
|
433
|
+
result[key] = deepClone(safeSource[key]);
|
|
406
434
|
}
|
|
407
435
|
});
|
|
408
436
|
return result;
|
package/lib/request-wrapper.js
CHANGED
|
@@ -263,7 +263,7 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
263
263
|
return __generator(this, function (_c) {
|
|
264
264
|
switch (_c.label) {
|
|
265
265
|
case 0:
|
|
266
|
-
options = (0, helper_1.deepMerge)(parameters.defaultOptions
|
|
266
|
+
options = (0, helper_1.deepMerge)(parameters.defaultOptions, parameters.options);
|
|
267
267
|
path = options.path, body = options.body, form = options.form, formData = options.formData, qs = options.qs, method = options.method, serviceUrl = options.serviceUrl, axiosOptions = options.axiosOptions;
|
|
268
268
|
headers = options.headers, url = options.url;
|
|
269
269
|
multipartForm = new form_data_1.default();
|