Skip to content

Commit

Permalink
chore: update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Oct 10, 2023
1 parent 0addd12 commit e561867
Show file tree
Hide file tree
Showing 23 changed files with 8,820 additions and 23,016 deletions.
31,519 changes: 8,663 additions & 22,856 deletions package-lock.json

Large diffs are not rendered by default.

114 changes: 57 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,107 +6,107 @@
"main": "dist/src/index.js",
"dependencies": {
"@koa/router": "^12.0.0",
"@maxmind/geoip2-node": "^3.5.0",
"@maxmind/geoip2-node": "^4.2.0",
"@redocly/openapi-core": "^1.2.0",
"@socket.io/redis-adapter": "^8.1.0",
"@socket.io/redis-adapter": "^8.2.1",
"adm-zip": "^0.5.10",
"any-ascii": "^0.3.2",
"bluebird": "^3.7.2",
"config": "^3.3.9",
"countries-list": "^2.6.1",
"countries-list": "^3.0.5",
"crypto-random-string": "^5.0.0",
"csv-parser": "^3.0.0",
"got": "^12.6.0",
"got": "^12.6.1",
"gunzip-maybe": "^1.4.2",
"http-errors": "^2.0.0",
"ipaddr.js": "^2.0.1",
"joi": "^17.9.1",
"ipaddr.js": "^2.1.0",
"joi": "^17.11.0",
"knex": "^2.5.1",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.0",
"koa-bodyparser": "^4.4.1",
"koa-compress": "^5.1.1",
"koa-conditional-get": "^3.0.0",
"koa-etag": "^4.0.0",
"koa-json": "^2.0.2",
"koa-response-time": "^2.1.0",
"lodash": "^4.17.21",
"lru-cache": "^10.0.0",
"maxmind": "^4.3.10",
"lru-cache": "^10.0.1",
"maxmind": "^4.3.16",
"mysql": "^2.18.1",
"newrelic": "^10.4.1",
"newrelic": "^10.6.2",
"physical-cpu-count": "^2.0.0",
"rate-limiter-flexible": "^2.4.1",
"redis": "^4.6.5",
"rate-limiter-flexible": "^2.4.2",
"redis": "^4.6.10",
"request-ip": "^3.3.0",
"semver": "^7.4.0",
"socket.io": "^4.5.4",
"validator": "^13.9.0",
"winston": "^3.8.2"
"semver": "^7.5.4",
"socket.io": "^4.7.2",
"validator": "^13.11.0",
"winston": "^3.11.0"
},
"devDependencies": {
"@apideck/portman": "^1.22.0",
"@apidevtools/swagger-parser": "^10.1.0",
"@martin-kolarik/eslint-config": "^7.1.6",
"@martin-kolarik/eslint-config": "^7.3.0",
"@redocly/cli": "^1.2.0",
"@stoplight/spectral-cli": "^6.6.0",
"@stoplight/spectral-cli": "^6.11.0",
"@tsconfig/node18-strictest-esm": "^1.0.1",
"@types/adm-zip": "^0.5.0",
"@types/bluebird": "^3.5.38",
"@types/chai": "^4.3.4",
"@types/adm-zip": "^0.5.2",
"@types/bluebird": "^3.5.40",
"@types/chai": "^4.3.7",
"@types/chai-subset": "^1.3.3",
"@types/config": "^3.3.0",
"@types/http-errors": "^2.0.1",
"@types/koa": "^2.13.6",
"@types/koa__router": "^12.0.0",
"@types/config": "^3.3.1",
"@types/http-errors": "^2.0.2",
"@types/koa": "^2.13.9",
"@types/koa__router": "^12.0.1",
"@types/koa-bodyparser": "^4.3.10",
"@types/koa-compress": "^4.0.3",
"@types/koa-conditional-get": "^2.0.0",
"@types/koa-etag": "^3.0.0",
"@types/koa-favicon": "^2.0.21",
"@types/koa-json": "^2.0.20",
"@types/koa-response-time": "^2.1.2",
"@types/koa-compress": "^4.0.4",
"@types/koa-conditional-get": "^2.0.1",
"@types/koa-etag": "^3.0.1",
"@types/koa-favicon": "^2.1.1",
"@types/koa-json": "^2.0.21",
"@types/koa-response-time": "^2.1.3",
"@types/koa-static": "^4.0.2",
"@types/lodash": "^4.14.194",
"@types/mocha": "^10.0.1",
"@types/mock-fs": "^4.13.1",
"@types/newrelic": "^9.4.0",
"@types/node": "^18.15.11",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.2",
"@types/mock-fs": "^4.13.2",
"@types/newrelic": "^9.14.1",
"@types/node": "^18.18.4",
"@types/physical-cpu-count": "^2.0.0",
"@types/request-ip": "^0.0.37",
"@types/semver": "^7.3.13",
"@types/sinon": "^10.0.14",
"@types/supertest": "^2.0.12",
"@types/throng": "^5.0.4",
"@types/validator": "^13.7.15",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@types/request-ip": "^0.0.39",
"@types/semver": "^7.5.3",
"@types/sinon": "^10.0.19",
"@types/supertest": "^2.0.14",
"@types/throng": "^5.0.5",
"@types/validator": "^13.11.2",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"artillery": "^2.0.0-31",
"artillery": "^2.0.0-37",
"better-ajv-errors": "^1.2.0",
"c8": "^7.13.0",
"chai": "^4.3.7",
"eslint": "^8.38.0",
"c8": "^8.0.1",
"chai": "^4.3.10",
"eslint": "^8.51.0",
"husky": "^8.0.3",
"koa-favicon": "^2.1.0",
"koa-static": "^5.0.0",
"lint-staged": "^13.2.1",
"lint-staged": "^14.0.1",
"mocha": "^10.2.0",
"mock-fs": "^5.2.0",
"nock": "^13.3.0",
"rimraf": "^3.0.2",
"sinon": "^15.0.3",
"socket.io-client": "^4.6.1",
"start-server-and-test": "^2.0.0",
"nock": "^13.3.3",
"rimraf": "^5.0.5",
"sinon": "^16.1.0",
"socket.io-client": "^4.7.2",
"start-server-and-test": "^2.0.1",
"supertest": "^6.3.3",
"testdouble": "^3.17.2",
"testdouble": "^3.19.0",
"ts-node": "^10.9.1",
"tsx": "^3.12.6",
"tsx": "^3.13.0",
"typescript": "~4.7.4"
},
"optionalDependencies": {
"bufferutil": "^4.0.7",
"utf-8-validate": "^5.0.10"
"utf-8-validate": "^6.0.3"
},
"scripts": {
"build": "tsc && npm run download:files",
Expand Down
4 changes: 2 additions & 2 deletions src/adoption-code/sender.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import createHttpError from 'http-errors';
import { fetchSockets, ProbeSocket } from '../lib/ws/server.js';
import { fetchSockets, RemoteProbeSocket } from '../lib/ws/server.js';
import type { AdoptionCodeRequest } from './types.js';

export class CodeSender {
Expand All @@ -23,7 +23,7 @@ export class CodeSender {
return sockets.find(socket => socket.data.probe.ipAddress === ip);
}

private sendToSocket (sockets: ProbeSocket, code: string) {
private sendToSocket (sockets: RemoteProbeSocket, code: string) {
sockets.emit('probe:adoption:code', {
code,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/geoip/fake-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ProbeLocation } from '../../probe/types';
import type { ProbeLocation } from '../../probe/types.js';

export const fakeLookup = (): ProbeLocation => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/geoip/providers/maxmind.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import newrelic from 'newrelic';
import { type City, WebServiceClient } from '@maxmind/geoip2-node';
import type { WebServiceClientError } from '@maxmind/geoip2-node/dist/src/types';
import type { WebServiceClientError } from '@maxmind/geoip2-node/dist/src/types.js';
import type { LocationInfo } from '../client.js';
import {
normalizeCityName,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/http/middleware/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createHttpError from 'http-errors';
import newrelic from 'newrelic';
import { scopedLogger } from '../../logger.js';
import type { ExtendedMiddleware } from '../../../types';
import type { ExtendedMiddleware } from '../../../types.js';

const logger = scopedLogger('error-handler-mw');

Expand Down
3 changes: 1 addition & 2 deletions src/lib/location/location.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import geoLists from 'countries-list';
import { countries } from 'countries-list';
import { regions, aliases as regionAliases } from './regions.js';
import { states } from './states.js';
import {
Expand All @@ -9,7 +9,6 @@ import {
import { aliases as networkAliases } from './networks.js';
import { aliases as continentAliases } from './continents.js';

const { countries } = geoLists;
const countryToRegionMap = new Map(_.flatMap(regions, (v, r) => v.map(c => [ c, r ])));

export const getRegionByCountry = (country: string): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { scopedLogger } from './logger.js';
const logger = scopedLogger('metrics');

export class MetricsAgent {
private interval: NodeJS.Timer | undefined;
private interval: NodeJS.Timeout | undefined;

constructor (
private readonly io: SocketServer,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/redis/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineScript } from 'redis';
import type { MeasurementRecord, MeasurementResultMessage } from '../../measurement/types';
import type { MeasurementRecord, MeasurementResultMessage } from '../../measurement/types.js';

type CountScript = {
NUMBER_OF_KEYS: number;
Expand Down
8 changes: 3 additions & 5 deletions src/lib/ws/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Socket } from 'socket.io';
import { getMetricsAgent } from '../metrics.js';
import type { Probe } from '../../probe/types.js';
import { handleMeasurementAck } from '../../measurement/handler/ack.js';
import { handleMeasurementResult } from '../../measurement/handler/result.js';
import { handleMeasurementProgress } from '../../measurement/handler/progress.js';
import { handleStatusUpdate } from '../../probe/handler/status.js';
import { handleDnsUpdate } from '../../probe/handler/dns.js';
import { handleStatsReport } from '../../probe/handler/stats.js';
import { scopedLogger } from '../logger.js';
import { getWsServer, PROBES_NAMESPACE } from './server.js';
import { getWsServer, PROBES_NAMESPACE, ServerSocket } from './server.js';
import { probeMetadata } from './middleware/probe-metadata.js';
import { errorHandler } from './helper/error-handler.js';
import { subscribeWithHandler } from './helper/subscribe-handler.js';
Expand All @@ -20,8 +18,8 @@ const metricsAgent = getMetricsAgent();
io
.of(PROBES_NAMESPACE)
.use(probeMetadata)
.on('connect', errorHandler(async (socket: Socket) => {
const probe = socket.data['probe'] as Probe;
.on('connect', errorHandler(async (socket: ServerSocket) => {
const probe = socket.data.probe;
socket.emit('api:connect:location', probe.location);
logger.info(`ws client ${socket.id} connected from ${probe.location.city}, ${probe.location.country} [${probe.ipAddress} - ${probe.location.network}]`);

Expand Down
4 changes: 3 additions & 1 deletion src/lib/ws/helper/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Socket } from 'socket.io';
import type { ServerSocket } from '../server.js';

import getProbeIp from '../../get-probe-ip.js';
import { scopedLogger } from '../../logger.js';

Expand All @@ -18,7 +20,7 @@ type NextArgument = NextConnectArgument | NextMwArgument;
const isError = (error: unknown): error is Error => Boolean(error as Error['message']);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const errorHandler = (next: NextArgument) => (socket: Socket, mwNext?: (error?: any) => void) => {
export const errorHandler = (next: NextArgument) => (socket: ServerSocket, mwNext?: (error?: any) => void) => {
next(socket, mwNext!).catch((error) => { // eslint-disable-line @typescript-eslint/no-non-null-assertion
const clientIp = getProbeIp(socket) ?? '';
const reason = isError(error) ? error.message : 'unknown';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ws/helper/reconnect-probes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ThrottledFetchSockets } from '../server';
import type { ThrottledFetchSockets } from '../server.js';

const TIME_TO_RECONNECT_PROBES = 2 * 60 * 1000;

Expand Down
8 changes: 4 additions & 4 deletions src/lib/ws/helper/subscribe-handler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Socket } from 'socket.io';
import type { Probe } from '../../../probe/types.js';
import type { ServerSocket } from '../server.js';

import { scopedLogger } from '../../logger.js';

const logger = scopedLogger('ws:handler:error');
const isError = (error: unknown): error is Error => Boolean(error as Error['message']);

type HandlerMethod = (...args: never[]) => Promise<void>;

export const subscribeWithHandler = (socket: Socket, event: string, method: HandlerMethod) => {
export const subscribeWithHandler = (socket: ServerSocket, event: string, method: HandlerMethod) => {
socket.on(event, async (...args) => {
try {
await method(...args as never[]);
} catch (error: unknown) {
const probe = socket.data['probe'] as Probe;
const probe = socket.data.probe;
const clientIp = probe.ipAddress;
const reason = isError(error) ? error.message : 'unknown';

Expand Down
8 changes: 5 additions & 3 deletions src/lib/ws/middleware/probe-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Socket } from 'socket.io';
// eslint-disable-next-line n/no-missing-import
import type { ExtendedError } from 'socket.io/dist/namespace.js';

import type { ServerSocket } from '../server.js';
import { WsError } from '../ws-error.js';
import { buildProbe } from '../../../probe/builder.js';
import { ProbeError } from '../../probe-error.js';
Expand All @@ -9,11 +11,11 @@ import getProbeIp from '../../get-probe-ip.js';

const logger = scopedLogger('probe-metadata');

export const probeMetadata = errorHandler(async (socket: Socket, next: (error?: ExtendedError) => void) => {
export const probeMetadata = errorHandler(async (socket: ServerSocket, next: (error?: ExtendedError) => void) => {
const clientIp = getProbeIp(socket);

try {
socket.data['probe'] = await buildProbe(socket);
socket.data.probe = await buildProbe(socket);
next();
} catch (error: unknown) {
logger.error(error);
Expand Down
13 changes: 8 additions & 5 deletions src/lib/ws/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import config from 'config';
import { type RemoteSocket, Server } from 'socket.io';
import { type RemoteSocket, Server, Socket } from 'socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import type { DefaultEventsMap } from 'socket.io/dist/typed-events';
// eslint-disable-next-line n/no-missing-import
import type { DefaultEventsMap } from 'socket.io/dist/typed-events.js';
import type { Probe } from '../../probe/types.js';
import { getRedisClient } from '../redis/client.js';
import { reconnectProbes } from './helper/reconnect-probes.js';
Expand All @@ -12,7 +13,9 @@ export type SocketData = {
probe: Probe;
};

export type ProbeSocket = RemoteSocket<DefaultEventsMap, SocketData>;
export type RemoteProbeSocket = RemoteSocket<DefaultEventsMap, SocketData>;

export type ServerSocket = Socket<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, SocketData>;

export type WsServer = Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, SocketData>;

Expand All @@ -21,7 +24,7 @@ const TIME_UNTIL_VM_BECOMES_HEALTHY = 8000;
const logger = scopedLogger('ws-server');

let io: WsServer;
let throttledFetchSockets: (options?: LRUOptions) => Promise<ProbeSocket[]>;
let throttledFetchSockets: (options?: LRUOptions) => Promise<RemoteProbeSocket[]>;

export const initWsServer = async () => {
const pubClient = getRedisClient().duplicate();
Expand All @@ -38,7 +41,7 @@ export const initWsServer = async () => {

io.adapter(createAdapter(pubClient, subClient));

throttledFetchSockets = throttle<ProbeSocket[]>(
throttledFetchSockets = throttle<RemoteProbeSocket[]>(
io.of(PROBES_NAMESPACE).fetchSockets.bind(io.of(PROBES_NAMESPACE)),
config.get<number>('ws.fetchSocketsCacheTTL'),
);
Expand Down
3 changes: 1 addition & 2 deletions src/measurement/schema/location-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import anyAscii from 'any-ascii';
import Joi from 'joi';
import config from 'config';

import geoLists from 'countries-list';
import { continents, countries } from 'countries-list';
import { states } from '../../lib/location/states.js';
import { regionNames } from '../../lib/location/regions.js';
import { GLOBAL_DEFAULTS } from './utils.js';

const { continents, countries } = geoLists;
const measurementConfig = config.get<{limits: {global: number; location: number}}>('measurement');

const normalizeValue = (value: string): string => anyAscii(value);
Expand Down
Loading

0 comments on commit e561867

Please sign in to comment.