1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

chore: remove compiler warnings from create-config (#6459)

## About the changes
Some changes to fix compiler errors in create-config
This commit is contained in:
Gastón Fournier 2024-03-07 11:44:59 +01:00 committed by GitHub
parent ec6c439c09
commit 2cd80d31f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,6 +53,8 @@ import { validateOrigins } from './util/validateOrigin';
const safeToUpper = (s?: string) => (s ? s.toUpperCase() : s); const safeToUpper = (s?: string) => (s ? s.toUpperCase() : s);
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export function authTypeFromString( export function authTypeFromString(
s?: string, s?: string,
defaultType: IAuthType = IAuthType.OPEN_SOURCE, defaultType: IAuthType = IAuthType.OPEN_SOURCE,
@ -179,35 +181,39 @@ const dateHandlingCallback = (connection, callback) => {
}); });
}; };
const defaultDbOptions: IDBOption = { const defaultDbOptions: WithOptional<IDBOption, 'user' | 'password' | 'host'> =
user: process.env.DATABASE_USERNAME, {
password: process.env.DATABASE_PASSWORD, user: process.env.DATABASE_USERNAME,
host: process.env.DATABASE_HOST, password: process.env.DATABASE_PASSWORD,
port: parseEnvVarNumber(process.env.DATABASE_PORT, 5432), host: process.env.DATABASE_HOST,
database: process.env.DATABASE_NAME || 'unleash', port: parseEnvVarNumber(process.env.DATABASE_PORT, 5432),
ssl: database: process.env.DATABASE_NAME || 'unleash',
process.env.DATABASE_SSL != null ssl:
? JSON.parse(process.env.DATABASE_SSL) process.env.DATABASE_SSL != null
: { rejectUnauthorized: false }, ? JSON.parse(process.env.DATABASE_SSL)
driver: 'postgres', : { rejectUnauthorized: false },
version: process.env.DATABASE_VERSION, driver: 'postgres',
acquireConnectionTimeout: secondsToMilliseconds(30), version: process.env.DATABASE_VERSION,
pool: { acquireConnectionTimeout: secondsToMilliseconds(30),
min: parseEnvVarNumber(process.env.DATABASE_POOL_MIN, 0), pool: {
max: parseEnvVarNumber(process.env.DATABASE_POOL_MAX, 4), min: parseEnvVarNumber(process.env.DATABASE_POOL_MIN, 0),
idleTimeoutMillis: parseEnvVarNumber( max: parseEnvVarNumber(process.env.DATABASE_POOL_MAX, 4),
process.env.DATABASE_POOL_IDLE_TIMEOUT_MS, idleTimeoutMillis: parseEnvVarNumber(
secondsToMilliseconds(30), process.env.DATABASE_POOL_IDLE_TIMEOUT_MS,
), secondsToMilliseconds(30),
...(parseEnvVarBoolean(process.env.ALLOW_NON_STANDARD_DB_DATES, false) ),
? { afterCreate: dateHandlingCallback } ...(parseEnvVarBoolean(
: {}), process.env.ALLOW_NON_STANDARD_DB_DATES,
propagateCreateError: false, false,
}, )
schema: process.env.DATABASE_SCHEMA || 'public', ? { afterCreate: dateHandlingCallback }
disableMigration: false, : {}),
applicationName: process.env.DATABASE_APPLICATION_NAME || 'unleash', propagateCreateError: false,
}; },
schema: process.env.DATABASE_SCHEMA || 'public',
disableMigration: false,
applicationName: process.env.DATABASE_APPLICATION_NAME || 'unleash',
};
const defaultSessionOption: ISessionOption = { const defaultSessionOption: ISessionOption = {
ttlHours: parseEnvVarNumber(process.env.SESSION_TTL_HOURS, 48), ttlHours: parseEnvVarNumber(process.env.SESSION_TTL_HOURS, 48),
@ -271,7 +277,7 @@ const defaultAuthentication: IAuthOption = {
initApiTokens: [], initApiTokens: [],
}; };
const defaultImport: IImportOption = { const defaultImport: WithOptional<IImportOption, 'file'> = {
file: process.env.IMPORT_FILE, file: process.env.IMPORT_FILE,
dropBeforeImport: parseEnvVarBoolean( dropBeforeImport: parseEnvVarBoolean(
process.env.IMPORT_DROP_BEFORE_IMPORT, process.env.IMPORT_DROP_BEFORE_IMPORT,
@ -291,7 +297,6 @@ const defaultEmail: IEmailOption = {
const dbPort = (dbConfig: Partial<IDBOption>): Partial<IDBOption> => { const dbPort = (dbConfig: Partial<IDBOption>): Partial<IDBOption> => {
if (typeof dbConfig.port === 'string') { if (typeof dbConfig.port === 'string') {
// eslint-disable-next-line no-param-reassign
dbConfig.port = Number.parseInt(dbConfig.port, 10); dbConfig.port = Number.parseInt(dbConfig.port, 10);
} }
return dbConfig; return dbConfig;
@ -300,7 +305,6 @@ const dbPort = (dbConfig: Partial<IDBOption>): Partial<IDBOption> => {
const removeUndefinedKeys = (o: object): object => const removeUndefinedKeys = (o: object): object =>
Object.keys(o).reduce((a, key) => { Object.keys(o).reduce((a, key) => {
if (o[key] !== undefined) { if (o[key] !== undefined) {
// eslint-disable-next-line no-param-reassign
a[key] = o[key]; a[key] = o[key];
return a; return a;
} }
@ -316,7 +320,6 @@ const formatServerOptions = (
}; };
} }
/* eslint-disable-next-line */
return { return {
...serverOptions, ...serverOptions,
baseUriPath: formatBaseUri( baseUriPath: formatBaseUri(
@ -467,7 +470,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
]); ]);
const logLevel = const logLevel =
options.logLevel || LogLevel[process.env.LOG_LEVEL] || LogLevel.error; options.logLevel || LogLevel[process.env.LOG_LEVEL ?? LogLevel.error];
const getLogger = options.getLogger || getDefaultLogProvider(logLevel); const getLogger = options.getLogger || getDefaultLogProvider(logLevel);
validateLogProvider(getLogger); validateLogProvider(getLogger);
@ -488,9 +491,9 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
const authentication: IAuthOption = mergeAll([ const authentication: IAuthOption = mergeAll([
defaultAuthentication, defaultAuthentication,
options.authentication (options.authentication
? removeUndefinedKeys(options.authentication) ? removeUndefinedKeys(options.authentication)
: options.authentication, : options.authentication) || {},
{ initApiTokens: initApiTokens }, { initApiTokens: initApiTokens },
]); ]);
@ -512,7 +515,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
if (server.pipe) { if (server.pipe) {
listen = { path: server.pipe }; listen = { path: server.pipe };
} else { } else {
listen = { host: server.host || undefined, port: server.port }; listen = { host: server.host || undefined, port: server.port ?? 4242 };
} }
const frontendApi = options.frontendApi || { const frontendApi = options.frontendApi || {