nettoyage du code

This commit is contained in:
Puechberty Arthur
2026-04-23 23:39:18 +02:00
parent 9c311b75dd
commit 0d55fe5978
160 changed files with 4165 additions and 1237 deletions
+7 -1
View File
@@ -1,5 +1,11 @@
export const BOT_CONTROL_QUEUE = "bot-control";
export const BOT_CONTROL_QUEUE_PREFIX = "discord-saas";
export const BOT_STATUS = ["stopped", "starting", "running", "stopping", "error"] as const;
export const BOT_STATUS = [
"stopped",
"starting",
"running",
"stopping",
"error",
] as const;
export type BotStatus = (typeof BOT_STATUS)[number];
+11 -3
View File
@@ -1,6 +1,10 @@
const sanitizeSegment = (segment: string): string => segment.replace(/[^a-zA-Z0-9:_-]/g, "_");
const sanitizeSegment = (segment: string): string =>
segment.replace(/[^a-zA-Z0-9:_-]/g, "_");
export const tenantRedisKey = (tenantId: string, ...parts: string[]): string => {
export const tenantRedisKey = (
tenantId: string,
...parts: string[]
): string => {
const tail = parts.map(sanitizeSegment).join(":");
return tail.length > 0
? `tenant:${sanitizeSegment(tenantId)}:${tail}`
@@ -11,6 +15,10 @@ export const tenantRateLimitKey = (tenantId: string, scope: string): string => {
return tenantRedisKey(tenantId, "ratelimit", scope);
};
export const tenantBotRedisKey = (tenantId: string, botId: string, ...parts: string[]): string => {
export const tenantBotRedisKey = (
tenantId: string,
botId: string,
...parts: string[]
): string => {
return tenantRedisKey(tenantId, "bot", botId, ...parts);
};
+17 -4
View File
@@ -18,11 +18,17 @@ export const parseTokenEncryptionKey = (base64Key: string): Buffer => {
return key;
};
export const encryptToken = (plainToken: string, key: Buffer): EncryptedToken => {
export const encryptToken = (
plainToken: string,
key: Buffer,
): EncryptedToken => {
const iv = randomBytes(IV_LENGTH);
const cipher = createCipheriv(ALGORITHM, key, iv);
const ciphertext = Buffer.concat([cipher.update(plainToken, "utf8"), cipher.final()]);
const ciphertext = Buffer.concat([
cipher.update(plainToken, "utf8"),
cipher.final(),
]);
const tag = cipher.getAuthTag();
return {
@@ -32,8 +38,15 @@ export const encryptToken = (plainToken: string, key: Buffer): EncryptedToken =>
};
};
export const decryptToken = (encryptedToken: EncryptedToken, key: Buffer): string => {
const decipher = createDecipheriv(ALGORITHM, key, Buffer.from(encryptedToken.iv, "base64"));
export const decryptToken = (
encryptedToken: EncryptedToken,
key: Buffer,
): string => {
const decipher = createDecipheriv(
ALGORITHM,
key,
Buffer.from(encryptedToken.iv, "base64"),
);
decipher.setAuthTag(Buffer.from(encryptedToken.tag, "base64"));
const decrypted = Buffer.concat([
+2 -1
View File
@@ -3,7 +3,8 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist",
"declaration": true
},
"include": ["src/**/*.ts"]
}