feat(sync): harden the Hiboutik sync, share rate limits across instances, update dependencies (#4)

This commit is contained in:
2026-11-08 13:45:08 +00:00
parent 04960379e8
commit d07c4df52d
62 changed files with 1546 additions and 639 deletions

View File

@@ -1,20 +1,25 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { Injectable, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from './generated/client';
import { PrismaPg } from '@prisma/adapter-pg';
/** Prisma client shared by the whole app (global PrismaModule), connected to `DATABASE_URL` through the pg driver adapter. */
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
export class PrismaService extends PrismaClient implements OnModuleInit, OnApplicationShutdown {
constructor() {
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
super({ adapter });
// 'minimal': by default, error messages print the query arguments (emails, names, addresses...), which end up in the logs
super({ adapter, errorFormat: 'minimal' });
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
/**
* Last shutdown hook (after `onModuleDestroy` and `beforeApplicationShutdown`, once the HTTP server is closed):
* a synchronization still running is waited for in `beforeApplicationShutdown` and keeps the database until then.
*/
async onApplicationShutdown() {
await this.$disconnect();
}
}