@ceramicnetwork/common 1.9.0 → 1.10.0-rc.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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 1.10.0-rc.0 (2021-12-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add client side timeout to http-requests ([a33356c](https://github.com/ceramicnetwork/js-ceramic/commit/a33356c8a518252af9d81d1136411725c429cc3b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.9.0](https://github.com/ceramicnetwork/js-ceramic/compare/@ceramicnetwork/common@1.9.0-rc.2...@ceramicnetwork/common@1.9.0) (2021-12-06)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @ceramicnetwork/common
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":"AAKA,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,SAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAgC/E"}
|
package/lib/utils/http-utils.js
CHANGED
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fetchJson = void 0;
|
|
7
7
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
8
|
+
const abort_controller_1 = __importDefault(require("abort-controller"));
|
|
9
|
+
const DEFAULT_FETCH_TIMEOUT = 60 * 1000 * 3;
|
|
8
10
|
async function fetchJson(url, opts = {}) {
|
|
9
11
|
if (opts.body) {
|
|
10
12
|
Object.assign(opts, {
|
|
@@ -12,7 +14,22 @@ async function fetchJson(url, opts = {}) {
|
|
|
12
14
|
headers: { 'Content-Type': 'application/json' },
|
|
13
15
|
});
|
|
14
16
|
}
|
|
15
|
-
const
|
|
17
|
+
const timeoutLength = opts.timeout || DEFAULT_FETCH_TIMEOUT;
|
|
18
|
+
const controller = new abort_controller_1.default();
|
|
19
|
+
const timeout = setTimeout(() => {
|
|
20
|
+
controller.abort();
|
|
21
|
+
}, timeoutLength);
|
|
22
|
+
Object.assign(opts, {
|
|
23
|
+
signal: controller.signal,
|
|
24
|
+
});
|
|
25
|
+
const res = await cross_fetch_1.default(url, opts)
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
if (err.name == 'AbortError') {
|
|
28
|
+
throw new Error(`Http request timed out after ${timeoutLength} ms`);
|
|
29
|
+
}
|
|
30
|
+
throw err;
|
|
31
|
+
})
|
|
32
|
+
.finally(() => timeout && clearTimeout(timeout));
|
|
16
33
|
if (!res.ok) {
|
|
17
34
|
const text = await res.text();
|
|
18
35
|
throw new Error(`HTTP request to '${url}' failed with status '${res.statusText}': ${text}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA+B;
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA+B;AAE/B,wEAA8C;AAE9C,MAAM,qBAAqB,GAAG,EAAE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,CAAA;AACnB,CAAC;AAhCD,8BAgCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ceramicnetwork/common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0-rc.0",
|
|
4
4
|
"description": "Ceramic common types and utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ceramic",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ceramicnetwork/streamid": "^1.3.5",
|
|
35
35
|
"@overnightjs/logger": "^1.2.0",
|
|
36
|
+
"abort-controller": "^3.0.0",
|
|
36
37
|
"caip": "~1.0.0",
|
|
37
38
|
"cids": "~1.1.6",
|
|
38
39
|
"cross-fetch": "^3.1.4",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"testEnvironment": "node",
|
|
59
60
|
"resolver": "jest-resolver-enhanced"
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "0f464c11ea6d167ee139110c807cb6da1344e65c"
|
|
62
63
|
}
|