Skip to content

Commit

Permalink
fix: 🐛 Upgrade dependencies of ethlogger
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot authored and atoulme committed Aug 26, 2022
1 parent 9645f09 commit 93c0f94
Show file tree
Hide file tree
Showing 9 changed files with 1,713 additions and 724 deletions.
4 changes: 3 additions & 1 deletion jest.config.json
Expand Up @@ -2,7 +2,9 @@
"roots": ["<rootDir>/"],
"collectCoverageFrom": ["src/*.ts", "src/**/*.ts"],
"transform": {
"^.+\\.ts?$": "ts-jest"
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js)$": "babel-jest"
},
"transformIgnorePatterns": [],
"testMatch": ["<rootDir>/**/?(*.)(spec|test).(ts|js)?(x)"]
}
32 changes: 16 additions & 16 deletions package.json
Expand Up @@ -13,22 +13,22 @@
"registry": "https://npm.pkg.github.com/"
},
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2.2.2",
"@types/node-fetch": "^2.5.4",
"@oclif/command": "^1.8.16",
"@oclif/config": "^1.18.3",
"@oclif/plugin-help": "^5.1.12",
"@types/node-fetch": "^2.6.2",
"abort-controller": "^3.0.0",
"agentkeepalive": "^4.1.0",
"bl": "^4.0.0",
"debug": "^4.1.1",
"ethers": "^5.5.1",
"fs-extra": "^8.1.0",
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"node-fetch": "^2.6.0",
"tslib": "^1"
"agentkeepalive": "^4.2.1",
"bl": "^5.0.0",
"debug": "^4.3.4",
"ethers": "^5.7.0",
"fs-extra": "^10.1.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"tslib": "^2.4.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
Expand Down Expand Up @@ -58,7 +58,7 @@
"ts-jest": "^24.2.0",
"ts-node": "^8.5.4",
"typescript": "^3.7.3",
"typescript-json-schema": "^0.41.0"
"typescript-json-schema": "^0.42.0"
},
"engines": {
"node": ">=12.0.0"
Expand Down
5 changes: 4 additions & 1 deletion src/balancewatcher.ts
Expand Up @@ -279,6 +279,9 @@ export class BalanceWatcher implements ManagedResource {

let outputMessages = Array<OutputMessage>();
if (receipt != null && receipt.logs != null) {
const isDefined = (addr: string | undefined): addr is string => {
return !!addr;
};
const addresses = receipt.logs
?.map(log => {
if (this.config.contractAddress == log.address) {
Expand All @@ -290,7 +293,7 @@ export class BalanceWatcher implements ManagedResource {
}
})
.flat()
.filter(a => a !== undefined);
.filter(isDefined);
if (addresses.length > 0) {
this.counters.transfersProcessed++;
outputMessages = await this.abortHandle.race(
Expand Down
2 changes: 1 addition & 1 deletion src/cliflags.ts
@@ -1,7 +1,7 @@
import { flags } from '@oclif/command';
import { StartBlock } from './blockwatcher';

export const CLI_FLAGS = {
export const CLI_FLAGS: flags.Input<any> = {
version: flags.version({ char: 'v' }),
help: flags.help({ char: 'h' }),
debug: flags.boolean({
Expand Down
14 changes: 7 additions & 7 deletions src/config.ts
Expand Up @@ -6,7 +6,7 @@ import { CLI_FLAGS } from './cliflags';
import { createModuleDebug } from './utils/debug';
import { durationStringToMs } from './utils/parse';
import { exponentialBackoff, linearBackoff, WaitTime } from './utils/retry';
import { safeLoad } from 'js-yaml';
import { load } from 'js-yaml';
import { removeEmtpyValues, deepMerge, isEmpty } from './utils/obj';

const { debug, warn, error } = createModuleDebug('config');
Expand Down Expand Up @@ -652,7 +652,7 @@ export async function loadConfigFile(
if (detectedType === 'json') {
return JSON.parse(fileContents);
} else if (detectedType === 'yaml') {
return safeLoad(fileContents, { filename: fileName });
return load(fileContents, { filename: fileName });
}

return {};
Expand Down Expand Up @@ -751,13 +751,13 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal
}

const required = <T>(flag: keyof CliFlags, configValue: T | undefined): T => {
const val: T = flags[flag];
const val: T = flags[flag.toString()];
if (val == null) {
if (configValue == null) {
if (dryRun) {
error('Missing required option --%s', flag);
} else {
throw new ConfigError(`Missing required option --${flag}`);
throw new ConfigError(`Missing required option --${flag.toString()}`);
}
} else {
return configValue;
Expand Down Expand Up @@ -786,8 +786,8 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal
): HecConfig | undefined => {
const result = removeEmtpyValues({
defaultFields: defaults?.defaultFields,
defaultMetadata: flags[indexFlag]
? Object.assign({}, defaults?.defaultMetadata, { index: flags[indexFlag] })
defaultMetadata: flags[indexFlag.toString()]
? Object.assign({}, defaults?.defaultMetadata, { index: flags[indexFlag.toString()] })
: defaults?.defaultMetadata,
flushTime: parseDuration(defaults?.flushTime),
gzip: defaults?.gzip,
Expand All @@ -799,7 +799,7 @@ export async function loadEthloggerConfig(flags: CliFlags, dryRun: boolean = fal
requestKeepAlive: defaults?.requestKeepAlive,
retryWaitTime: waitTimeFromConfig(defaults?.retryWaitTime as WaitTimeConfig),
timeout: parseDuration(defaults?.timeout),
token: flags[tokenFlag] ?? defaults?.token,
token: flags[tokenFlag.toString()] ?? defaults?.token,
url: defaults?.url,
userAgent: defaults?.userAgent,
validateCertificate: defaults?.validateCertificate,
Expand Down
5 changes: 4 additions & 1 deletion src/eth/http.ts
Expand Up @@ -98,6 +98,8 @@ export class HttpTransport implements EthereumTransport {
this.counters.requests++;
this.aggregates.batchSize.push(Array.isArray(request) ? request.length : 1);
try {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), this.config.timeout);
const response = await fetch(this.url, {
method: 'POST',
headers: {
Expand All @@ -106,8 +108,9 @@ export class HttpTransport implements EthereumTransport {
},
body,
agent: this.httpAgent,
timeout: this.config.timeout,
signal: controller.signal,
});
clearTimeout(id);
if (!response.ok) {
let responseBody: any = null;
try {
Expand Down
19 changes: 11 additions & 8 deletions src/hec.ts
Expand Up @@ -2,7 +2,6 @@ import AbortController from 'abort-controller';
import { default as HttpAgent, HttpOptions, HttpsAgent } from 'agentkeepalive';
import BufferList from 'bl';
import fetch from 'node-fetch';
import { AbortSignal } from 'node-fetch/externals';
import { createGzip } from 'zlib';
import { HecConfig } from './config';
import { sleep } from './utils/async';
Expand Down Expand Up @@ -324,14 +323,17 @@ export class HecClient {

debug('Checking if HEC is available at %s', url.href);
try {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), this.config.timeout);
const res = await fetch(url.href, {
method: 'GET',
headers: {
'User-Agent': this.config.userAgent,
},
agent: this.httpAgent,
timeout: this.config.timeout,
signal: controller.signal,
});
clearTimeout(id);
debug('HEC responded to availability check with HTTP status %d', res.status);
if (!isSuccessfulStatus(res.status)) {
throw new Error(`HTTP Status ${res.status}`);
Expand Down Expand Up @@ -390,7 +392,7 @@ export class HecClient {

const abortController = new AbortController();
const flushHandle = new FlushHandle(abortController);
const flushCompletePromise = this.sendToHec(queue, abortController.signal);
const flushCompletePromise = this.sendToHec(queue, abortController);
flushHandle.promise = flushCompletePromise;
this.activeFlushing.add(flushHandle);

Expand All @@ -400,7 +402,7 @@ export class HecClient {
return flushCompletePromise;
};

private async sendToHec(msgs: SerializedHecMsg[], abortSignal: AbortSignal): Promise<void> {
private async sendToHec(msgs: SerializedHecMsg[], abortController: AbortController): Promise<void> {
const startTime = Date.now();
debug('Flushing HEC queue with %s messages', msgs.length);
const rawBody = new BufferList(msgs);
Expand Down Expand Up @@ -428,14 +430,15 @@ export class HecClient {
attempt++;
try {
const requestStart = Date.now();
const id = setTimeout(() => abortController.abort(), this.config.timeout);
const response = await fetch(this.config.url, {
method: 'POST',
headers,
body: body.duplicate(),
agent: this.httpAgent,
signal: abortSignal,
timeout: this.config.timeout,
signal: abortController.signal,
});
clearTimeout(id);
this.aggregates.requestDuration.push(Date.now() - requestStart);

if (!isSuccessfulStatus(response.status)) {
Expand Down Expand Up @@ -465,14 +468,14 @@ export class HecClient {
this.counters.errorCount++;
debug('Failed to send batch to HEC (attempt %s)', attempt, e);
error('Failed to send batch to HEC (attempt %s): %s', attempt, e.toString());
if (abortSignal.aborted) {
if (abortController.signal.aborted) {
throw new Error('Aborted');
}
if (attempt <= this.config.maxRetries) {
const retryDelay = resolveWaitTime(this.config.retryWaitTime, attempt);
debug(`Retrying to send batch to HEC in %d ms`, retryDelay);
await sleep(retryDelay);
if (abortSignal.aborted) {
if (abortController.signal.aborted) {
throw new Error('Aborted');
}
this.counters.retryCount++;
Expand Down
1 change: 1 addition & 0 deletions test/nftwatcher.test.ts
Expand Up @@ -57,6 +57,7 @@ class RecorderFetchTransport implements FetchTransport {
export class ReplayFetchTransport implements FetchTransport {
constructor(private records: Record[]) {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async fetch(url: RequestInfo, init?: RequestInit | undefined): Promise<Response> {
const requestJson = JSON.stringify({ url: url });
const reqMatches = (r: Record) => JSON.stringify({ url: r.request }) === requestJson;
Expand Down

0 comments on commit 93c0f94

Please sign in to comment.