@varlet/axle 0.2.18-alpha.1702624592933 → 0.2.18

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.
Files changed (2) hide show
  1. package/es/index.js +19 -14
  2. package/package.json +1 -1
package/es/index.js CHANGED
@@ -343,28 +343,33 @@ import { minimatch as minimatch3 } from "minimatch";
343
343
  import { set, get } from "lodash-es";
344
344
  import { MD5 } from "crypto-js";
345
345
  import { isString } from "@varlet/shared";
346
- function withConfigMd5(config, mappingValue) {
346
+ function withCtxMd5(ctx, mappingValue) {
347
347
  mappingValue.path.forEach((path) => {
348
- const targetValue = get(config, path);
348
+ const targetValue = get(ctx, path);
349
349
  if (targetValue != null) {
350
- set(config, path, MD5(String(targetValue)).toString());
350
+ set(ctx, path, MD5(String(targetValue)).toString());
351
351
  }
352
352
  });
353
353
  }
354
354
  function withMd5(config, mappingValue) {
355
- const { data, headers = {} } = config;
356
- if (isString(data) && data.length > 0 && headers["Content-Type"] === "application/x-www-form-urlencoded") {
357
- config.data = qs2.parse(config.data);
358
- withConfigMd5(config, mappingValue);
359
- config.data = qs2.stringify(config.data);
360
- } else if (isFormData(data)) {
361
- config.data = formDataToObject(data);
362
- withConfigMd5(config, mappingValue);
363
- config.data = objectToFormData(config.data);
355
+ const { data = {}, params = {}, headers = {} } = config;
356
+ const ctx = {
357
+ data: isFormData(data) ? data : JSON.parse(JSON.stringify(data)),
358
+ params: JSON.parse(JSON.stringify(params)),
359
+ headers: JSON.parse(JSON.stringify(headers))
360
+ };
361
+ if (isString(ctx.data) && ctx.data.length > 0 && ctx.headers["Content-Type"] === "application/x-www-form-urlencoded") {
362
+ ctx.data = qs2.parse(ctx.data);
363
+ withCtxMd5(ctx, mappingValue);
364
+ ctx.data = qs2.stringify(ctx.data);
365
+ } else if (isFormData(ctx.data)) {
366
+ ctx.data = formDataToObject(ctx.data);
367
+ withCtxMd5(ctx, mappingValue);
368
+ ctx.data = objectToFormData(ctx.data);
364
369
  } else {
365
- withConfigMd5(config, mappingValue);
370
+ withCtxMd5(ctx, mappingValue);
366
371
  }
367
- return config;
372
+ return __spreadValues(__spreadValues({}, config), ctx);
368
373
  }
369
374
  function requestMd5Interceptor(options = {}) {
370
375
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.2.18-alpha.1702624592933",
3
+ "version": "0.2.18",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "type": "module",
6
6
  "main": "es/index.js",