@stepzen/fetch 0.23.0-beta.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021, 2022 StepZen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@stepzen/fetch`
2
+
3
+ StepZen wrapper for the [`node-fetch`](https://www.npmjs.com/package/node-fetch) npm package that implements the `fetch()` API for NodeJS.
4
+
5
+ The main reason to create this wrapper is create a workaround for an issue affecting a small part of StepZen CLI users where some CLI calls would stall due to an incorrectly terminated TCP transmission. See https://github.com/steprz/stepzen-cli/issues/934 for more details.
6
+
7
+ This package would be obsolete either when the ISP issue with TCP configuration is fixed, or when the CLI can assume it runs on NodeJS 19 or newer. In Node 19 the default http(s) agent config changes to add the `Connection: keep-alive` HTTP header, and that seems to prevent the issue.
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { RequestInfo, RequestInit, Response } from 'node-fetch';
2
+ declare const fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>;
3
+ export default fetch;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AAe7D,QAAA,MAAM,KAAK,QACJ,WAAW,SACT,WAAW,KACjB,QAAQ,QAAQ,CAclB,CAAA;AAED,eAAe,KAAK,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const http = require("http");
4
+ const https = require("https");
5
+ const node_fetch_1 = require("node-fetch");
6
+ // workaround for https://github.com/steprz/stepzen-cli/issues/934
7
+ const httpAgent = new http.Agent({
8
+ keepAlive: true,
9
+ scheduling: 'lifo',
10
+ timeout: 5000,
11
+ });
12
+ const httpsAgent = new https.Agent({
13
+ keepAlive: true,
14
+ scheduling: 'lifo',
15
+ timeout: 5000,
16
+ });
17
+ const fetch = async (url, init) => {
18
+ let urlstr;
19
+ if (typeof url === 'string') {
20
+ urlstr = url;
21
+ }
22
+ else if ('href' in url) {
23
+ urlstr = url.href;
24
+ }
25
+ else {
26
+ urlstr = url.url;
27
+ }
28
+ return (0, node_fetch_1.default)(url, {
29
+ agent: urlstr.startsWith('https:') ? httpsAgent : httpAgent,
30
+ ...init,
31
+ });
32
+ };
33
+ exports.default = fetch;
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAA4B;AAC5B,+BAA8B;AAC9B,2CAA+B;AAG/B,kEAAkE;AAClE,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;IAC/B,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI;CACd,CAAC,CAAA;AAEF,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;IACjC,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI;CACd,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,KAAK,EACjB,GAAgB,EAChB,IAAkB,EACC,EAAE;IACrB,IAAI,MAAM,CAAA;IACV,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,GAAG,GAAG,CAAA;KACb;SAAM,IAAI,MAAM,IAAI,GAAG,EAAE;QACxB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAA;KAClB;SAAM;QACL,MAAM,GAAG,GAAG,CAAC,GAAG,CAAA;KACjB;IAED,OAAO,IAAA,oBAAM,EAAC,GAAG,EAAE;QACjB,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QAC3D,GAAG,IAAI;KACR,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,kBAAe,KAAK,CAAA"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@stepzen/fetch",
3
+ "description": "StepZen implementation of the fetch() API for NodeJS",
4
+ "version": "0.23.0-beta.0",
5
+ "author": "StepZen Ltd",
6
+ "license": "MIT",
7
+ "files": [
8
+ "lib/**/*",
9
+ "src/**/*"
10
+ ],
11
+ "main": "lib/index.js",
12
+ "types": "lib/index.d.ts",
13
+ "engines": {
14
+ "node": ">=14.0.1",
15
+ "npm": ">=6.14"
16
+ },
17
+ "scripts": {
18
+ "clean": "rm -rf lib tsconfig.tsbuildinfo",
19
+ "build": "../../node_modules/.bin/tsc -b",
20
+ "test": "npm run build && nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
21
+ "test:single": "npm run build && mocha",
22
+ "posttest": "prettier . --check"
23
+ },
24
+ "dependencies": {
25
+ "debug": "^4.3.4",
26
+ "node-fetch": "^2.6.7"
27
+ },
28
+ "devDependencies": {
29
+ "@types/debug": "^4.1.7",
30
+ "@types/mocha": "^9.1.1",
31
+ "@types/node-fetch": "^2.6.2",
32
+ "chai": "^4.3.4",
33
+ "fancy-test": "^1.4.10",
34
+ "mocha": "^9.0.1",
35
+ "mock-fs": "^4.13.0",
36
+ "nyc": "^14.1.1",
37
+ "prettier": "^2.7.1",
38
+ "ts-node": "^10.8.2"
39
+ }
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,38 @@
1
+ import * as http from 'http'
2
+ import * as https from 'https'
3
+ import fetch0 from 'node-fetch'
4
+ import {RequestInfo, RequestInit, Response} from 'node-fetch'
5
+
6
+ // workaround for https://github.com/steprz/stepzen-cli/issues/934
7
+ const httpAgent = new http.Agent({
8
+ keepAlive: true,
9
+ scheduling: 'lifo',
10
+ timeout: 5000,
11
+ })
12
+
13
+ const httpsAgent = new https.Agent({
14
+ keepAlive: true,
15
+ scheduling: 'lifo',
16
+ timeout: 5000,
17
+ })
18
+
19
+ const fetch = async (
20
+ url: RequestInfo,
21
+ init?: RequestInit,
22
+ ): Promise<Response> => {
23
+ let urlstr
24
+ if (typeof url === 'string') {
25
+ urlstr = url
26
+ } else if ('href' in url) {
27
+ urlstr = url.href
28
+ } else {
29
+ urlstr = url.url
30
+ }
31
+
32
+ return fetch0(url, {
33
+ agent: urlstr.startsWith('https:') ? httpsAgent : httpAgent,
34
+ ...init,
35
+ })
36
+ }
37
+
38
+ export default fetch