import * as path from 'path'; import * as bcrypt from 'bcrypt'; export const envPath = path.resolve(process.cwd(), '..', '..', '.env'); export async function hashPassword(password: string) { const saltRounds = 12; return bcrypt.hash(password, saltRounds); } export async function comparePasswordHash( plainPassword: string, passwordHash: string, ): Promise { return bcrypt.compare(plainPassword, passwordHash); } export type RedisConfig = { host: string; port: number; password?: string; }; export function parseRedisUrl(redisUrl: string): RedisConfig { // format - redis[s]://[[username][:password]@][host][:port][/db-number] const { hostname, port, password } = new URL(redisUrl); const portInt = parseInt(port, 10); return { host: hostname, port: portInt, password }; } export function createRetryStrategy() { return function (times: number): number { return Math.max(Math.min(Math.exp(times), 20000), 3000); }; }