@cloudpss/fetch 0.4.18 → 0.4.20
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 +1 -1
- package/dist/index-browser.d.ts +5 -5
- package/dist/index-browser.js +7 -7
- package/dist/index-browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/index-browser.ts +7 -7
- package/src/index.ts +8 -20
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# @cloudpss/fetch
|
|
2
2
|
|
|
3
|
-
Provides `fetch` for node.js,
|
|
3
|
+
Provides `fetch` for node.js, a simple wrapper of [node-fetch](https://github.com/node-fetch/node-fetch).
|
package/dist/index-browser.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const _fetch: typeof fetch;
|
|
2
|
+
declare const _Headers: {
|
|
3
3
|
new (init?: HeadersInit | undefined): Headers;
|
|
4
4
|
prototype: Headers;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
declare const _Response: {
|
|
7
7
|
new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): Response;
|
|
8
8
|
prototype: Response;
|
|
9
9
|
error(): Response;
|
|
10
10
|
redirect(url: string | URL, status?: number | undefined): Response;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
declare const _Request: {
|
|
13
13
|
new (input: RequestInfo | URL, init?: RequestInit | undefined): Request;
|
|
14
14
|
prototype: Request;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export { _fetch as fetch, _Headers as Headers, _Response as Response, _Request as Request };
|
|
17
17
|
export default fetch;
|
package/dist/index-browser.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
if (typeof
|
|
2
|
-
throw new TypeError(`fetch is not defined on the global object, you should load polyfill of
|
|
1
|
+
if (typeof fetch != 'function') {
|
|
2
|
+
throw new TypeError(`fetch is not defined on the global object, you should load polyfill of fetch.`);
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
4
|
+
const _fetch = fetch;
|
|
5
|
+
const _Headers = Headers;
|
|
6
|
+
const _Response = Response;
|
|
7
|
+
const _Request = Request;
|
|
8
|
+
export { _fetch as fetch, _Headers as Headers, _Response as Response, _Request as Request };
|
|
9
9
|
export default fetch;
|
|
10
10
|
//# sourceMappingURL=index-browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.js","sourceRoot":"","sources":["../src/index-browser.ts"],"names":[],"mappings":"AAAA,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"index-browser.js","sourceRoot":"","sources":["../src/index-browser.ts"],"names":[],"mappings":"AAAA,IAAI,OAAO,KAAK,IAAI,UAAU,EAAE;IAC5B,MAAM,IAAI,SAAS,CAAC,+EAA+E,CAAC,CAAC;CACxG;AAED,MAAM,MAAM,GAAG,KAAK,CAAC;AACrB,MAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,QAAQ,IAAI,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,QAAQ,IAAI,OAAO,EAAE,CAAC;AAE5F,eAAe,KAAK,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import ProxyAgent from 'proxy-agent';
|
|
2
1
|
import nodeFetch, { Headers as NodeHeaders, Response as NodeResponse, Request as NodeRequest } from 'node-fetch';
|
|
2
|
+
import { agent } from '@cloudpss/proxy-agent';
|
|
3
3
|
/** 生成 fetch */
|
|
4
4
|
function makeFetch() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
!!process.env['ALL_PROXY'] ||
|
|
10
|
-
!!process.env['all_proxy'];
|
|
11
|
-
if (hasProxy) {
|
|
12
|
-
const agent = new ProxyAgent();
|
|
13
|
-
return [
|
|
14
|
-
function fetch(url, init) {
|
|
15
|
-
return nodeFetch(url, { ...init, agent });
|
|
16
|
-
},
|
|
17
|
-
agent,
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return [nodeFetch, undefined];
|
|
5
|
+
if (agent) {
|
|
6
|
+
return function fetch(url, init) {
|
|
7
|
+
return nodeFetch(url, { ...init, agent });
|
|
8
|
+
};
|
|
22
9
|
}
|
|
10
|
+
return nodeFetch;
|
|
23
11
|
}
|
|
24
|
-
export const
|
|
12
|
+
export const fetch = makeFetch();
|
|
25
13
|
export const Headers = NodeHeaders;
|
|
26
14
|
export const Response = NodeResponse;
|
|
27
15
|
export const Request = NodeRequest;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAE,OAAO,IAAI,WAAW,EAAE,QAAQ,IAAI,YAAY,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACjH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,eAAe;AACf,SAAS,SAAS;IACd,IAAI,KAAK,EAAE;QACP,OAAO,SAAS,KAAK,CAAC,GAAsB,EAAE,IAAkB;YAC5D,OAAO,SAAS,CAAC,GAAsB,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAqB,CAAsB,CAAC;QACzG,CAAC,CAAC;KACL;IACD,OAAO,SAAyB,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;AACjC,MAAM,CAAC,MAAM,OAAO,GAAG,WAAmD,CAAC;AAC3E,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAqD,CAAC;AAC9E,MAAM,CAAC,MAAM,OAAO,GAAG,WAAmD,CAAC;AAE3E,eAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/fetch",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.20",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"main": "dist/index.js",
|
|
8
9
|
"module": "dist/index.js",
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"clean": "rimraf dist"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
24
|
+
"@cloudpss/proxy-agent": "~0.4.20",
|
|
25
|
+
"node-fetch": "^3.3.1"
|
|
25
26
|
}
|
|
26
27
|
}
|
package/src/index-browser.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
if (typeof
|
|
2
|
-
throw new TypeError(`fetch is not defined on the global object, you should load polyfill of
|
|
1
|
+
if (typeof fetch != 'function') {
|
|
2
|
+
throw new TypeError(`fetch is not defined on the global object, you should load polyfill of fetch.`);
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
5
|
+
const _fetch = fetch;
|
|
6
|
+
const _Headers = Headers;
|
|
7
|
+
const _Response = Response;
|
|
8
|
+
const _Request = Request;
|
|
9
|
+
export { _fetch as fetch, _Headers as Headers, _Response as Response, _Request as Request };
|
|
10
10
|
|
|
11
11
|
export default fetch;
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import ProxyAgent from 'proxy-agent';
|
|
2
1
|
import type { RequestInfo as NodeRequestInfo, RequestInit as NodeRequestInit } from 'node-fetch';
|
|
3
2
|
import nodeFetch, { Headers as NodeHeaders, Response as NodeResponse, Request as NodeRequest } from 'node-fetch';
|
|
3
|
+
import { agent } from '@cloudpss/proxy-agent';
|
|
4
4
|
|
|
5
5
|
/** 生成 fetch */
|
|
6
|
-
function makeFetch():
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
!!process.env['https_proxy'] ||
|
|
12
|
-
!!process.env['ALL_PROXY'] ||
|
|
13
|
-
!!process.env['all_proxy'];
|
|
14
|
-
if (hasProxy) {
|
|
15
|
-
const agent = new ProxyAgent();
|
|
16
|
-
return [
|
|
17
|
-
function fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
18
|
-
return nodeFetch(url as NodeRequestInfo, { ...init, agent } as NodeRequestInit) as Promise<Response>;
|
|
19
|
-
},
|
|
20
|
-
agent,
|
|
21
|
-
];
|
|
22
|
-
} else {
|
|
23
|
-
return [nodeFetch as typeof globalThis.fetch, undefined];
|
|
6
|
+
function makeFetch(): typeof globalThis.fetch {
|
|
7
|
+
if (agent) {
|
|
8
|
+
return function fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
9
|
+
return nodeFetch(url as NodeRequestInfo, { ...init, agent } as NodeRequestInit) as Promise<Response>;
|
|
10
|
+
};
|
|
24
11
|
}
|
|
12
|
+
return nodeFetch as typeof fetch;
|
|
25
13
|
}
|
|
26
14
|
|
|
27
|
-
export const
|
|
15
|
+
export const fetch = makeFetch();
|
|
28
16
|
export const Headers = NodeHeaders as unknown as typeof globalThis.Headers;
|
|
29
17
|
export const Response = NodeResponse as unknown as typeof globalThis.Response;
|
|
30
18
|
export const Request = NodeRequest as unknown as typeof globalThis.Request;
|