@fetchx/fetcher-adapter-taro 0.1.3 → 0.1.5
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/README.md
CHANGED
|
@@ -8,7 +8,7 @@ exports.default = fetcherAdapterTaro;
|
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _taro = require("@tarojs/taro");
|
|
11
|
-
var
|
|
11
|
+
var _fetcherHelper = require("@fetchx/fetcher-helper");
|
|
12
12
|
var _fetcherCore = require("@fetchx/fetcher-core");
|
|
13
13
|
var _util = require("./util");
|
|
14
14
|
var _excluded = ["method", "signal", "responseType"];
|
|
@@ -32,7 +32,7 @@ function fetcherAdapterTaro(url, headers, body, config) {
|
|
|
32
32
|
name: _fetcherCore.FetcherErrorName.RESPONSE_STATUS,
|
|
33
33
|
message: "Response status ".concat(result.statusCode, "."),
|
|
34
34
|
code: "".concat(result.statusCode),
|
|
35
|
-
responseHeaders: (0,
|
|
35
|
+
responseHeaders: (0, _fetcherHelper.headersNormalize)(result.header),
|
|
36
36
|
responseData: result.data // 401 等状态还是会有 data
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -43,14 +43,14 @@ function fetcherAdapterTaro(url, headers, body, config) {
|
|
|
43
43
|
if (responseType === 'json' && (!result.data || typeof result.data === 'string')) {
|
|
44
44
|
throw (0, _fetcherCore.createFetcherError)(config, {
|
|
45
45
|
name: _fetcherCore.FetcherErrorName.RESPONSE_PARSE,
|
|
46
|
-
responseHeaders: (0,
|
|
46
|
+
responseHeaders: (0, _fetcherHelper.headersNormalize)(result.header),
|
|
47
47
|
responseData: result.data
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
51
|
url: url,
|
|
52
52
|
data: result.data,
|
|
53
|
-
headers: (0,
|
|
53
|
+
headers: (0, _fetcherHelper.headersNormalize)(result.header)
|
|
54
54
|
};
|
|
55
55
|
}, function (err) {
|
|
56
56
|
var originalError = (0, _util.ensureError)(err);
|
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["method", "signal", "responseType"];
|
|
4
4
|
import { request } from '@tarojs/taro';
|
|
5
|
-
import { headersNormalize } from '@fetchx/fetcher-helper
|
|
5
|
+
import { headersNormalize } from '@fetchx/fetcher-helper';
|
|
6
6
|
import { FetcherErrorName, createFetcherError } from '@fetchx/fetcher-core';
|
|
7
7
|
import { toTaroResponseType, ensureError } from './util';
|
|
8
8
|
export default function fetcherAdapterTaro(url, headers, body, config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher-adapter-taro.js","names":["request","headersNormalize","FetcherErrorName","createFetcherError","toTaroResponseType","ensureError","fetcherAdapterTaro","url","headers","body","config","_config$method","method","signal","_config$responseType","responseType","restConfig","_objectWithoutProperties","_excluded","_objectSpread","header","data","undefined","then","result","statusCode","name","RESPONSE_STATUS","message","concat","code","responseHeaders","responseData","RESPONSE_PARSE","err","originalError","NETWORK"],"sources":["../../src/fetcher-adapter-taro.ts"],"sourcesContent":["import Taro, {\n request\n} from '@tarojs/taro';\nimport {\n FetcherHeadersNormalized,\n headersNormalize\n} from '@fetchx/fetcher-helper
|
|
1
|
+
{"version":3,"file":"fetcher-adapter-taro.js","names":["request","headersNormalize","FetcherErrorName","createFetcherError","toTaroResponseType","ensureError","fetcherAdapterTaro","url","headers","body","config","_config$method","method","signal","_config$responseType","responseType","restConfig","_objectWithoutProperties","_excluded","_objectSpread","header","data","undefined","then","result","statusCode","name","RESPONSE_STATUS","message","concat","code","responseHeaders","responseData","RESPONSE_PARSE","err","originalError","NETWORK"],"sources":["../../src/fetcher-adapter-taro.ts"],"sourcesContent":["import Taro, {\n request\n} from '@tarojs/taro';\nimport {\n FetcherHeadersNormalized,\n headersNormalize\n} from '@fetchx/fetcher-helper';\nimport {\n FetcherErrorName,\n FetcherConfig,\n FetcherResponse,\n FetcherBodyNormalized,\n createFetcherError\n} from '@fetchx/fetcher-core';\n\nimport {\n toTaroResponseType,\n ensureError\n} from './util';\n\nexport default function fetcherAdapterTaro<T = unknown>(url: string, headers: FetcherHeadersNormalized, body: FetcherBodyNormalized, config: FetcherConfig): Promise<FetcherResponse<T>> {\n const {\n method = 'GET',\n signal,\n responseType = 'json',\n ...restConfig\n } = config;\n \n return request<T>({\n ...restConfig,\n method: method as Taro.request.Option['method'],\n url,\n header: headers,\n data: body,\n responseType: toTaroResponseType(responseType),\n signal: signal ?? undefined\n }).then(result => {\n if (result.statusCode < 200 || result.statusCode >= 300) {\n throw createFetcherError(config, {\n name: FetcherErrorName.RESPONSE_STATUS,\n message: `Response status ${result.statusCode}.`,\n code: `${result.statusCode}`,\n responseHeaders: headersNormalize(result.header),\n responseData: result.data // 401 等状态还是会有 data\n });\n }\n \n // 若访问的是当前 location 下地址\n // MP data 会是 HTML 串(不论是否 404 地址)\n // H5 data 是 null\n if (responseType === 'json' && (!result.data || typeof result.data === 'string')) {\n throw createFetcherError(config, {\n name: FetcherErrorName.RESPONSE_PARSE,\n responseHeaders: headersNormalize(result.header),\n responseData: result.data\n });\n }\n \n return {\n url,\n data: result.data,\n headers: headersNormalize(result.header)\n };\n }, (err: unknown) => {\n const originalError = ensureError(err);\n \n // 超时的情况下,Taro 内部用的是 AbortController,到这里无法感知是否为超时还是用户手动 abort\n if (originalError.name === 'AbortError') {\n throw originalError;\n }\n \n // MP,无权限接口(包括不存在的)会到这里 { errMsg: 'request:fail url not in domain list', errno: undefined }\n // H5,不存在的接口会报 CORS,得到 NetworkError\n throw createFetcherError(config, {\n name: FetcherErrorName.NETWORK,\n originalError\n });\n });\n}\n"],"mappings":";;;AAAA,SACEA,OAAO,QACF,cAAc;AACrB,S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B,CAAC,CAAC;IACJ;;IAEA;IACA;IACA;IACA,IAAIN,YAAY,KAAK,MAAM,KAAK,CAACS,MAAM,CAACH,IAAI,IAAI,OAAOG,MAAM,CAACH,IAAI,KAAK,QAAQ,CAAC,EAAE;MAChF,MAAMlB,kBAAkB,CAACO,MAAM,EAAE;QAC/BgB,IAAI,EAAExB,gBAAgB,CAAC+B,cAAc;QACrCF,eAAe,EAAE9B,gBAAgB,CAACuB,MAAM,CAACJ,MAAM,CAAC;QAChDY,YAAY,EAAER,MAAM,CAACH;MACvB,CAAC,CAAC;IACJ;IAEA,OAAO;MACLd,GAAG,EAAHA,GAAG;MACHc,IAAI,EAAEG,MAAM,CAACH,IAAI;MACjBb,OAAO,EAAEP,gBAAgB,CAACuB,MAAM,CAACJ,MAAM;IACzC,CAAC;EACH,CAAC,EAAE,UAACc,GAAY,EAAK;IACnB,IAAMC,aAAa,GAAG9B,WAAW,CAAC6B,GAAG,CAAC;;IAEtC;IACA,IAAIC,aAAa,CAACT,IAAI,KAAK,YAAY,EAAE;MACvC,MAAMS,aAAa;IACrB;;IAEA;IACA;IACA,MAAMhC,kBAAkB,CAACO,MAAM,EAAE;MAC/BgB,IAAI,EAAExB,gBAAgB,CAACkC,OAAO;MAC9BD,aAAa,EAAbA;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FetcherHeadersNormalized } from '@fetchx/fetcher-helper
|
|
1
|
+
import { FetcherHeadersNormalized } from '@fetchx/fetcher-helper';
|
|
2
2
|
import { FetcherConfig, FetcherResponse, FetcherBodyNormalized } from '@fetchx/fetcher-core';
|
|
3
3
|
export default function fetcherAdapterTaro<T = unknown>(url: string, headers: FetcherHeadersNormalized, body: FetcherBodyNormalized, config: FetcherConfig): Promise<FetcherResponse<T>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fetchx/fetcher-adapter-taro",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Fetcher adapter for taro.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@tarojs/taro": ">=4.2.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@fetchx/fetcher-core": "^0.1.
|
|
42
|
-
"@fetchx/fetcher-helper
|
|
41
|
+
"@fetchx/fetcher-core": "^0.1.5",
|
|
42
|
+
"@fetchx/fetcher-helper": "^0.1.0",
|
|
43
43
|
"lodash": "^4.18.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"watch": "pnpm build:esm -w",
|
|
52
52
|
"prepublishOnly": "pnpm build:clean && pnpm build"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "98e9e99fb76e274aa7986ef92e099b8627df7d69"
|
|
55
55
|
}
|