@dashevo/dapi-client 3.1.0-dev.5 → 3.1.0-dev.6
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/lib/dapiAddressProvider/ListDAPIAddressProvider.js +1 -1
- package/lib/index.js +0 -2
- package/lib/logger/index.js +38 -76
- package/lib/test/bootstrap.js +0 -3
- package/lib/test/karma/bootstrap.js +0 -3
- package/lib/transport/JsonRpcTransport/requestJsonRpc.js +17 -6
- package/package.json +10 -13
- package/polyfills/fetch-polyfill.js +0 -10
package/lib/index.js
CHANGED
package/lib/logger/index.js
CHANGED
|
@@ -1,80 +1,42 @@
|
|
|
1
|
-
const
|
|
2
|
-
const winston = require('winston');
|
|
1
|
+
const LOG_LEVEL = (typeof process !== 'undefined' && process.env && process.env.LOG_LEVEL) || 'silent';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const LOG_LEVEL = process.env.LOG_LEVEL || 'silent';
|
|
7
|
-
const LOG_TO_FILE = process.env.LOG_WALLET_TO_FILE || 'false';
|
|
8
|
-
|
|
9
|
-
// Log levels:
|
|
10
|
-
// error 0
|
|
11
|
-
// warn 1
|
|
12
|
-
// info 2 (default)
|
|
13
|
-
// verbose 3
|
|
14
|
-
// debug 4
|
|
15
|
-
// silly 5
|
|
16
|
-
|
|
17
|
-
const loggers = {};
|
|
18
|
-
|
|
19
|
-
const createLogger = (formats = [], id = '') => {
|
|
20
|
-
const format = winston.format.combine(
|
|
21
|
-
{
|
|
22
|
-
transform: (info) => {
|
|
23
|
-
const args = info[Symbol.for('splat')];
|
|
24
|
-
const result = { ...info };
|
|
25
|
-
if (args) {
|
|
26
|
-
result.message = util.format(info.message, ...args);
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
...formats,
|
|
32
|
-
winston.format.colorize(),
|
|
33
|
-
winston.format.printf(({
|
|
34
|
-
level, message,
|
|
35
|
-
}) => `${level}: ${message}`),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const transports = [
|
|
39
|
-
new winston.transports.Console({
|
|
40
|
-
format,
|
|
41
|
-
silent: LOG_LEVEL === 'silent',
|
|
42
|
-
}),
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
if (LOG_TO_FILE === 'true' && typeof window === 'undefined') {
|
|
46
|
-
transports.push(
|
|
47
|
-
new winston.transports.File({
|
|
48
|
-
filename: `wallet${id !== '' ? `_${id}` : ''}`,
|
|
49
|
-
format,
|
|
50
|
-
silent: LOG_LEVEL === 'silent',
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return winston.createLogger({
|
|
56
|
-
level: LOG_LEVEL,
|
|
57
|
-
transports,
|
|
58
|
-
});
|
|
3
|
+
const LEVELS = {
|
|
4
|
+
silent: -1, error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5,
|
|
59
5
|
};
|
|
60
6
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
7
|
+
const cache = {};
|
|
8
|
+
|
|
9
|
+
function build(level = LOG_LEVEL, prefix = '') {
|
|
10
|
+
const threshold = LEVELS[level] != null ? LEVELS[level] : LEVELS.silent;
|
|
11
|
+
const noop = () => {};
|
|
12
|
+
// Preserve printf-style interpolation (%s/%d/%o/...): when there is a
|
|
13
|
+
// prefix and the first argument is the format string, merge the prefix
|
|
14
|
+
// into it. Otherwise hand the prefix to console.* as a leading argument.
|
|
15
|
+
const fmt = prefix
|
|
16
|
+
? (...a) => {
|
|
17
|
+
if (a.length === 0) return [prefix];
|
|
18
|
+
const [first, ...rest] = a;
|
|
19
|
+
return typeof first === 'string' ? [`${prefix} ${first}`, ...rest] : [prefix, first, ...rest];
|
|
20
|
+
}
|
|
21
|
+
: (...a) => a;
|
|
22
|
+
|
|
23
|
+
const logger = {
|
|
24
|
+
error: threshold >= 0 ? (...a) => console.error(...fmt(...a)) : noop,
|
|
25
|
+
warn: threshold >= 1 ? (...a) => console.warn(...fmt(...a)) : noop,
|
|
26
|
+
info: threshold >= 2 ? (...a) => console.info(...fmt(...a)) : noop,
|
|
27
|
+
verbose: threshold >= 3 ? (...a) => console.debug(...fmt(...a)) : noop,
|
|
28
|
+
debug: threshold >= 4 ? (...a) => console.debug(...fmt(...a)) : noop,
|
|
29
|
+
silly: threshold >= 5 ? (...a) => console.debug(...fmt(...a)) : noop,
|
|
30
|
+
getForId(id, overrideLevel) {
|
|
31
|
+
const effective = overrideLevel || level;
|
|
32
|
+
const key = `${id}\0${effective}`;
|
|
33
|
+
if (!cache[key]) {
|
|
34
|
+
cache[key] = build(effective, `[DAPIClient: ${id}]`);
|
|
35
|
+
}
|
|
36
|
+
return cache[key];
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return logger;
|
|
40
|
+
}
|
|
79
41
|
|
|
80
|
-
module.exports =
|
|
42
|
+
module.exports = build();
|
package/lib/test/bootstrap.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
const https = require('https');
|
|
2
1
|
const JsonRpcError = require('./errors/JsonRpcError');
|
|
3
2
|
const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
|
|
3
|
+
|
|
4
|
+
// Lazily-created undici Agent that disables TLS verification, shared across
|
|
5
|
+
// all self-signed requests. A per-request Agent would leak its socket pool
|
|
6
|
+
// since nothing destroys it after the fetch completes.
|
|
7
|
+
let sharedSelfSignedAgent;
|
|
4
8
|
/**
|
|
5
9
|
* @typedef {requestJsonRpc}
|
|
6
10
|
* @param {string} protocol
|
|
@@ -47,17 +51,24 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
|
|
|
47
51
|
Object.assign(requestOptions, { signal: controller.signal });
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
//
|
|
54
|
+
// Self-signed HTTPS: Node 18+ built-in fetch is backed by undici, which
|
|
55
|
+
// accepts a `dispatcher` for per-request TLS settings. Browsers can't
|
|
56
|
+
// bypass TLS verification, so the flag is a no-op there. eval('require')
|
|
57
|
+
// hides undici from bundler static analysis so it isn't pulled into
|
|
58
|
+
// browser bundles.
|
|
51
59
|
if (typeof process !== 'undefined'
|
|
52
60
|
&& process.versions != null
|
|
53
61
|
&& process.versions.node != null
|
|
54
62
|
&& protocol === 'https'
|
|
55
63
|
&& selfSigned) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
if (!sharedSelfSignedAgent) {
|
|
65
|
+
// eslint-disable-next-line no-eval, global-require
|
|
66
|
+
const { Agent } = eval('require')('undici');
|
|
67
|
+
sharedSelfSignedAgent = new Agent({ connect: { rejectUnauthorized: false } });
|
|
68
|
+
}
|
|
69
|
+
requestOptions.dispatcher = sharedSelfSignedAgent;
|
|
59
70
|
}
|
|
60
|
-
|
|
71
|
+
|
|
61
72
|
const response = await fetch(url, requestOptions);
|
|
62
73
|
|
|
63
74
|
if (typeof requestTimeoutId !== 'undefined') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "3.1.0-dev.
|
|
3
|
+
"version": "3.1.0-dev.6",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,19 +26,15 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "3.1.0-dev.
|
|
30
|
-
"@dashevo/dash-spv": "4.1.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "3.1.0-dev.6",
|
|
30
|
+
"@dashevo/dash-spv": "4.1.0-dev.6",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.22.0",
|
|
32
|
-
"@dashevo/grpc-common": "3.1.0-dev.
|
|
33
|
-
"@dashevo/wasm-dpp": "3.1.0-dev.
|
|
34
|
-
"bs58": "^4.0.1",
|
|
32
|
+
"@dashevo/grpc-common": "3.1.0-dev.6",
|
|
33
|
+
"@dashevo/wasm-dpp": "3.1.0-dev.6",
|
|
35
34
|
"cbor": "^8.0.0",
|
|
36
35
|
"google-protobuf": "^3.12.2",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"node-inspect-extracted": "^1.0.8",
|
|
40
|
-
"wasm-x11-hash": "~0.0.2",
|
|
41
|
-
"winston": "^3.2.1"
|
|
36
|
+
"undici": "^6.0.0",
|
|
37
|
+
"wasm-x11-hash": "~0.0.2"
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
40
|
"@babel/core": "^7.26.10",
|
|
@@ -66,7 +62,6 @@
|
|
|
66
62
|
"os-browserify": "^0.3.0",
|
|
67
63
|
"path-browserify": "^1.0.1",
|
|
68
64
|
"process": "^0.11.10",
|
|
69
|
-
"setimmediate": "^1.0.5",
|
|
70
65
|
"sinon": "^18.0.1",
|
|
71
66
|
"sinon-chai": "^3.7.0",
|
|
72
67
|
"stream-browserify": "^3.0.0",
|
|
@@ -76,10 +71,12 @@
|
|
|
76
71
|
"webpack": "^5.104.0",
|
|
77
72
|
"webpack-cli": "^4.9.1"
|
|
78
73
|
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18.18"
|
|
76
|
+
},
|
|
79
77
|
"files": [
|
|
80
78
|
"docs",
|
|
81
79
|
"lib",
|
|
82
|
-
"polyfills",
|
|
83
80
|
"dist"
|
|
84
81
|
],
|
|
85
82
|
"scripts": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
const { default: fetch, Headers, Request, Response } = require('node-fetch');
|
|
4
|
-
|
|
5
|
-
if (typeof window === 'undefined') {
|
|
6
|
-
globalThis.fetch = fetch;
|
|
7
|
-
globalThis.Headers = Headers;
|
|
8
|
-
globalThis.Request = Request;
|
|
9
|
-
globalThis.Response = Response;
|
|
10
|
-
}
|