fix: migrate deprecated APIs and patch vulnerable dependencies
Use current Mongoose, NATS, React, and ESLint APIs. Upgrade Vite and other affected dependencies, restrict the compatibility plugin to resolved module IDs, and keep qs unchanged.
This commit is contained in:
1 parent
5882585f69
commit
9d7c888b0a
14 files changed
+952
-900
No files matched your search
@@ -1,10 +1,11 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
export default defineConfig(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
|
||||
@@ -35,19 +35,20 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@lolympus/contracts": "workspace:*",
|
||||
"@nats-io/jetstream": "^3.4.0",
|
||||
"@nats-io/transport-node": "^3.4.0",
|
||||
"@nestjs/common": "^11.1.28",
|
||||
"@nestjs/config": "^4.0.4",
|
||||
"@nestjs/core": "^11.1.28",
|
||||
"@nestjs/platform-express": "^11.1.28",
|
||||
"@nestjs/platform-socket.io": "^11.1.28",
|
||||
"@nestjs/swagger": "^11.4.6",
|
||||
"@nestjs/swagger": "^11.4.8",
|
||||
"@nestjs/websockets": "^11.1.28",
|
||||
"@socket.io/redis-adapter": "^8.3.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.15.1",
|
||||
"jose": "^6.2.2",
|
||||
"mongoose": "9.11.4",
|
||||
"nats": "^2.29.3",
|
||||
"mongoose": "9.12.1",
|
||||
"newrelic": "^14.3.3",
|
||||
"redis": "^5.12.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
@@ -56,8 +57,7 @@
|
||||
"temporal-polyfill": "^0.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
@@ -65,7 +65,7 @@
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^26.1.1",
|
||||
"@types/supertest": "^7.0.0",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint": "^10.14.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^17.0.0",
|
||||
|
||||
@@ -1895,7 +1895,7 @@ describe('AuctionService', () => {
|
||||
expect(findOneAndUpdate).toHaveBeenCalledWith(
|
||||
{ matchId, 'chatMessages.id': { $ne: appended.message.id } },
|
||||
{ $push: { chatMessages: { $each: [appended.message], $slice: -200 } } },
|
||||
{ new: true },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -706,7 +706,7 @@ export class AuctionService {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ new: true },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
if (auction) return { auction, message, created: true };
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { connect } from 'nats';
|
||||
import type { NatsConnection } from 'nats';
|
||||
import { connect, type NatsConnection } from '@nats-io/transport-node';
|
||||
import { SecretModule } from '../secret/secret.module';
|
||||
import { SecretService } from '../secret/secret.service';
|
||||
import { NATS_CLIENT } from './nats.constants';
|
||||
|
||||
@@ -2,20 +2,21 @@ import { Inject, Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
|
||||
import {
|
||||
AckPolicy,
|
||||
DeliverPolicy,
|
||||
nanos,
|
||||
jetstream,
|
||||
jetstreamManager,
|
||||
ReplayPolicy,
|
||||
RetentionPolicy,
|
||||
StorageType,
|
||||
StringCodec,
|
||||
} from 'nats';
|
||||
import type {
|
||||
ConsumerMessages,
|
||||
JsMsg,
|
||||
Msg,
|
||||
NatsConnection,
|
||||
PubAck,
|
||||
Subscription,
|
||||
} from 'nats';
|
||||
type ConsumerMessages,
|
||||
type JsMsg,
|
||||
type PubAck,
|
||||
} from '@nats-io/jetstream';
|
||||
import {
|
||||
nanos,
|
||||
type Msg,
|
||||
type NatsConnection,
|
||||
type Subscription,
|
||||
} from '@nats-io/transport-node';
|
||||
import { NATS_CLIENT } from './nats.constants';
|
||||
|
||||
export type NatsMessageHandler<T = unknown> = (
|
||||
@@ -64,7 +65,6 @@ const JET_STREAM_CONSUMER_RESTART_DELAY_MILLISECONDS = 1_000;
|
||||
@Injectable()
|
||||
export class NatsService implements OnModuleDestroy {
|
||||
private readonly logger = new Logger(NatsService.name);
|
||||
private readonly stringCodec = StringCodec();
|
||||
private readonly subscriptions = new Set<Subscription>();
|
||||
private readonly jetStreamConsumers = new Set<ConsumerMessages>();
|
||||
private isDestroying = false;
|
||||
@@ -108,10 +108,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
}
|
||||
|
||||
public async publish<T = unknown>(subject: string, data: T): Promise<void> {
|
||||
this.natsClient.publish(
|
||||
subject,
|
||||
this.stringCodec.encode(JSON.stringify(data)),
|
||||
);
|
||||
this.natsClient.publish(subject, JSON.stringify(data));
|
||||
await this.natsClient.flush();
|
||||
}
|
||||
|
||||
@@ -133,19 +130,16 @@ export class NatsService implements OnModuleDestroy {
|
||||
data: T,
|
||||
options?: { messageId?: string; timeoutMs?: number },
|
||||
): Promise<PubAck> {
|
||||
const ack = await this.natsClient
|
||||
.jetstream()
|
||||
.publish(subject, this.stringCodec.encode(JSON.stringify(data)), {
|
||||
msgID: options?.messageId,
|
||||
timeout: options?.timeoutMs ?? 5000,
|
||||
});
|
||||
return ack;
|
||||
return jetstream(this.natsClient).publish(subject, JSON.stringify(data), {
|
||||
msgID: options?.messageId,
|
||||
timeout: options?.timeoutMs ?? 5000,
|
||||
});
|
||||
}
|
||||
|
||||
public async ensureJetStreamStream(
|
||||
options: JetStreamStreamOptions,
|
||||
): Promise<void> {
|
||||
const manager = await this.natsClient.jetstreamManager();
|
||||
const manager = await jetstreamManager(this.natsClient);
|
||||
const config = {
|
||||
name: options.name,
|
||||
subjects: options.subjects,
|
||||
@@ -173,7 +167,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
public async ensureJetStreamConsumer(
|
||||
options: JetStreamConsumerOptions,
|
||||
): Promise<void> {
|
||||
const manager = await this.natsClient.jetstreamManager();
|
||||
const manager = await jetstreamManager(this.natsClient);
|
||||
const config = {
|
||||
durable_name: options.durable,
|
||||
name: options.durable,
|
||||
@@ -206,9 +200,10 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
while (!this.isDestroying) {
|
||||
try {
|
||||
const consumer = await this.natsClient
|
||||
.jetstream()
|
||||
.consumers.get(options.stream, options.durable);
|
||||
const consumer = await jetstream(this.natsClient).consumers.get(
|
||||
options.stream,
|
||||
options.durable,
|
||||
);
|
||||
const messages = await consumer.consume({
|
||||
max_messages: options.maxMessages ?? 10,
|
||||
expires: options.expiresMs ?? 30000,
|
||||
@@ -263,8 +258,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
let data: T;
|
||||
try {
|
||||
const decoded = this.stringCodec.decode(msg.data);
|
||||
data = JSON.parse(decoded) as T;
|
||||
data = msg.json<T>();
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Failed to decode NATS message on subject="${msg.subject}": ${
|
||||
@@ -292,7 +286,7 @@ export class NatsService implements OnModuleDestroy {
|
||||
): Promise<void> {
|
||||
let data: T;
|
||||
try {
|
||||
data = JSON.parse(msg.string()) as T;
|
||||
data = msg.json<T>();
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Terminating undecodable JetStream message subject="${msg.subject}" stream="${options.stream}": ${
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os from 'node:os';
|
||||
import mongoose from 'mongoose';
|
||||
import { AuctionService } from '../src/modules/auction/auction.service';
|
||||
import { AuctionDurabilityScheduler } from '../src/modules/auction/auction-durability.scheduler';
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
} from '../src/modules/global/database/schema';
|
||||
|
||||
let connection: mongoose.Connection;
|
||||
let models: Record<string, mongoose.Model<any>>;
|
||||
let models: ReturnType<typeof createModels>;
|
||||
const redis = {
|
||||
acquireTokenLock: async () => true,
|
||||
releaseTokenLock: async () => true,
|
||||
@@ -27,19 +28,8 @@ const redis = {
|
||||
}),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
if (
|
||||
process.env.MONGO_TEST_ISOLATED !== '1' ||
|
||||
!process.env.MONGO_TEST_URL?.startsWith('mongodb://127.0.0.1:')
|
||||
)
|
||||
throw new Error('Use test:mongodb with an isolated local replica set.');
|
||||
connection = await mongoose
|
||||
.createConnection(process.env.MONGO_TEST_URL, {
|
||||
autoIndex: false,
|
||||
autoCreate: false,
|
||||
})
|
||||
.asPromise();
|
||||
models = {
|
||||
function createModels(connection: mongoose.Connection) {
|
||||
return {
|
||||
match: connection.model('match', MatchSchema),
|
||||
auction: connection.model('auction', AuctionSchema),
|
||||
auctionHistory: connection.model(
|
||||
@@ -56,12 +46,29 @@ beforeAll(async () => {
|
||||
AuctionBidRecordSchema,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
if (
|
||||
process.env.MONGO_TEST_ISOLATED !== '1' ||
|
||||
!process.env.MONGO_TEST_URL?.startsWith('mongodb://127.0.0.1:')
|
||||
)
|
||||
throw new Error('Use test:mongodb with an isolated local replica set.');
|
||||
connection = await mongoose
|
||||
.createConnection(process.env.MONGO_TEST_URL, {
|
||||
autoIndex: false,
|
||||
autoCreate: false,
|
||||
// NODE-7832: the driver's default OS adapter breaks the Jest handshake.
|
||||
runtimeAdapters: { os },
|
||||
})
|
||||
.asPromise();
|
||||
models = createModels(connection);
|
||||
await Promise.all(
|
||||
Object.values(models).map((model) => model.createCollection()),
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await Promise.all(Object.values(models).map((model) => model.deleteMany({})));
|
||||
await Promise.all(Object.values(models).map((model) => model.deleteMany()));
|
||||
});
|
||||
afterEach(() => jest.restoreAllMocks());
|
||||
afterAll(async () => {
|
||||
@@ -84,7 +91,6 @@ async function fixture(reserved: boolean) {
|
||||
participants: [],
|
||||
tournamentCodeIds: reserved ? [codeId] : [],
|
||||
gameSchedule: [],
|
||||
__v: 0,
|
||||
});
|
||||
await models.auction.collection.insertOne({
|
||||
_id: auctionId,
|
||||
@@ -104,7 +110,7 @@ async function fixture(reserved: boolean) {
|
||||
matchId,
|
||||
});
|
||||
const database = {
|
||||
getModel: async (name: string) => models[name],
|
||||
getModel: async (name: keyof typeof models) => models[name],
|
||||
createSession: () => connection.startSession(),
|
||||
};
|
||||
const codes = new TournamentCodeService(database as never, redis as never);
|
||||
@@ -611,10 +617,7 @@ it('reads an uncommitted Match in the provided session when cancelling polling b
|
||||
{ session },
|
||||
);
|
||||
expect(await models.match.findById(created._id)).toBeNull();
|
||||
await f.results.cancelPolling(
|
||||
created._id as mongoose.Types.ObjectId,
|
||||
session,
|
||||
);
|
||||
await f.results.cancelPolling(created._id, session);
|
||||
expect(
|
||||
await models.match.findById(created._id).session(session),
|
||||
).not.toBeNull();
|
||||
|
||||
@@ -324,7 +324,13 @@ describe('Community Hash response cache', () => {
|
||||
|
||||
it('does not share an old in-flight detail request after invalidation or overwrite the fresh response', async () => {
|
||||
const service = new CommunityStatsService(
|
||||
{} as never,
|
||||
{
|
||||
getModel: async () => ({
|
||||
findOne: () => ({
|
||||
select: () => ({ lean: () => ({ exec: async () => null }) }),
|
||||
}),
|
||||
}),
|
||||
} as never,
|
||||
cache,
|
||||
{} as never,
|
||||
{} as never,
|
||||
|
||||
Reference in new issue
Block a user