Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { promisify } = require('util');
// Inline promisify shim — avoids requiring Node's `util` module so this file
// can be bundled for browsers without a polyfill. If the codegen template
// is regenerated, restore this shim.
function promisify(fn) {
return (...args) => new Promise((resolve, reject) => {
fn(...args, (err, result) => (err ? reject(err) : resolve(result)));
});
}
const GrpcError = require('@dashevo/grpc-common/lib/server/error/GrpcError');

const { CoreClient } = require('./core_pb_service');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const { PlatformClient } = require('./platform_pb_service');
const { promisify } = require('util');

// Inline promisify shim — avoids requiring Node's `util` module so this file
// can be bundled for browsers without a polyfill. If the codegen template
// is regenerated, restore this shim.
function promisify(fn) {
return (...args) => new Promise((resolve, reject) => {
fn(...args, (err, result) => (err ? reject(err) : resolve(result)));
});
}

class PlatformPromiseClient {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sample = require('lodash/sample');
const sample = (arr) => arr[Math.floor(Math.random() * arr.length)];
const networks = require('@dashevo/dashcore-lib/lib/networks');

class ListDAPIAddressProvider {
Expand Down
2 changes: 0 additions & 2 deletions packages/js-dapi-client/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('../polyfills/fetch-polyfill');

const DAPIClient = require('./DAPIClient');

const NotFoundError = require('./transport/GrpcTransport/errors/NotFoundError');
Expand Down
105 changes: 29 additions & 76 deletions packages/js-dapi-client/lib/logger/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,33 @@
const util = require('util');
const winston = require('winston');
const LOG_LEVEL = (typeof process !== 'undefined' && process.env && process.env.LOG_LEVEL) || 'silent';

// TODO: Refactor to use params instead on envs

const LOG_LEVEL = process.env.LOG_LEVEL || 'silent';
const LOG_TO_FILE = process.env.LOG_WALLET_TO_FILE || 'false';

// Log levels:
// error 0
// warn 1
// info 2 (default)
// verbose 3
// debug 4
// silly 5

const loggers = {};

const createLogger = (formats = [], id = '') => {
const format = winston.format.combine(
{
transform: (info) => {
const args = info[Symbol.for('splat')];
const result = { ...info };
if (args) {
result.message = util.format(info.message, ...args);
}
return result;
},
},
...formats,
winston.format.colorize(),
winston.format.printf(({
level, message,
}) => `${level}: ${message}`),
);

const transports = [
new winston.transports.Console({
format,
silent: LOG_LEVEL === 'silent',
}),
];

if (LOG_TO_FILE === 'true' && typeof window === 'undefined') {
transports.push(
new winston.transports.File({
filename: `wallet${id !== '' ? `_${id}` : ''}`,
format,
silent: LOG_LEVEL === 'silent',
}),
);
}

return winston.createLogger({
level: LOG_LEVEL,
transports,
});
const LEVELS = {
silent: -1, error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5,
};

const logger = createLogger();

logger.getForId = (id) => {
if (!loggers[id]) {
const format = {
transform: (info) => {
const message = `[DAPIClient: ${id}] ${info.message}`;
return { ...info, message };
},
};

loggers[id] = createLogger([format], id);
}

return loggers[id];
};

logger.verbose(`Logger uses "${LOG_LEVEL}" level`, { level: LOG_LEVEL });
const cache = {};

function build(level = LOG_LEVEL, prefix = '') {
const threshold = LEVELS[level] != null ? LEVELS[level] : LEVELS.silent;
const noop = () => {};
const fmt = prefix ? (...a) => [prefix, ...a] : (...a) => a;

const logger = {
error: threshold >= 0 ? (...a) => console.error(...fmt(...a)) : noop,

Check warning on line 15 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 15 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
warn: threshold >= 1 ? (...a) => console.warn(...fmt(...a)) : noop,

Check warning on line 16 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 16 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
info: threshold >= 2 ? (...a) => console.info(...fmt(...a)) : noop,

Check warning on line 17 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 17 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
verbose: threshold >= 3 ? (...a) => console.debug(...fmt(...a)) : noop,

Check warning on line 18 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 18 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
debug: threshold >= 4 ? (...a) => console.debug(...fmt(...a)) : noop,

Check warning on line 19 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 19 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
silly: threshold >= 5 ? (...a) => console.debug(...fmt(...a)) : noop,

Check warning on line 20 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement

Check warning on line 20 in packages/js-dapi-client/lib/logger/index.js

View workflow job for this annotation

GitHub Actions / JS packages (@dashevo/dapi-client) / Linting

Unexpected console statement
getForId(id, overrideLevel) {
const effective = overrideLevel || level;
const key = `${id}\0${effective}`;
if (!cache[key]) {
cache[key] = build(effective, `[DAPIClient: ${id}]`);
}
return cache[key];
},
};
return logger;
}

module.exports = logger;
module.exports = build();
3 changes: 0 additions & 3 deletions packages/js-dapi-client/lib/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require('../../polyfills/fetch-polyfill');
require('setimmediate');

const { expect, use } = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const https = require('https');
const JsonRpcError = require('./errors/JsonRpcError');
const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
/**
Expand Down Expand Up @@ -47,17 +46,6 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
Object.assign(requestOptions, { signal: controller.signal });
}

// For NodeJS Client
if (typeof process !== 'undefined'
&& process.versions != null
&& process.versions.node != null
&& protocol === 'https'
&& selfSigned) {
requestOptions.agent = new https.Agent({
rejectUnauthorized: false,
});
}
// eslint-disable-next-line
const response = await fetch(url, requestOptions);

if (typeof requestTimeoutId !== 'undefined') {
Expand Down
11 changes: 4 additions & 7 deletions packages/js-dapi-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@
"@dashevo/dashcore-lib": "~0.22.0",
"@dashevo/grpc-common": "workspace:*",
"@dashevo/wasm-dpp": "workspace:*",
"bs58": "^4.0.1",
"cbor": "^8.0.0",
"google-protobuf": "^3.12.2",
"lodash": "^4.17.23",
"node-fetch": "^2.6.7",
"node-inspect-extracted": "^1.0.8",
"wasm-x11-hash": "~0.0.2",
"winston": "^3.2.1"
"wasm-x11-hash": "~0.0.2"
},
"devDependencies": {
"@babel/core": "^7.26.10",
Expand Down Expand Up @@ -76,10 +71,12 @@
"webpack": "^5.104.0",
"webpack-cli": "^4.9.1"
},
"engines": {
"node": ">=18.18"
},
"files": [
"docs",
"lib",
"polyfills",
"dist"
],
"scripts": {
Expand Down
10 changes: 0 additions & 10 deletions packages/js-dapi-client/polyfills/fetch-polyfill.js

This file was deleted.

5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,6 @@ __metadata:
assert-browserify: "npm:^2.0.0"
babel-loader: "npm:^9.1.3"
browserify-zlib: "npm:^0.2.0"
bs58: "npm:^4.0.1"
buffer: "npm:^6.0.3"
cbor: "npm:^8.0.0"
chai: "npm:^4.3.10"
Expand All @@ -1542,10 +1541,7 @@ __metadata:
karma-mocha: "npm:^2.0.1"
karma-mocha-reporter: "npm:^2.2.5"
karma-webpack: "npm:^5.0.0"
lodash: "npm:^4.17.23"
mocha: "npm:^11.1.0"
node-fetch: "npm:^2.6.7"
node-inspect-extracted: "npm:^1.0.8"
nyc: "npm:^15.1.0"
os-browserify: "npm:^0.3.0"
path-browserify: "npm:^1.0.1"
Expand All @@ -1560,7 +1556,6 @@ __metadata:
wasm-x11-hash: "npm:~0.0.2"
webpack: "npm:^5.104.0"
webpack-cli: "npm:^4.9.1"
winston: "npm:^3.2.1"
languageName: unknown
linkType: soft

Expand Down
Loading