feat: allow env variables to overwrite smtp config

Fixes #3
This commit is contained in:
Anselm Stordeur
2019-01-09 17:53:53 +01:00
parent cdbbb0ae1f
commit 3d82c94577
4 changed files with 199 additions and 84 deletions

49
src/common.ts Normal file
View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* A recursive partial object
*
* Copied from https://stackoverflow.com/a/51365037
*/
export type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ?
Array<RecursivePartial<U>> :
T[P] extends object ? RecursivePartial<T[P]> : T[P];
};
/**
* Deletes all properties that are undefined from an object
* @param obj
*/
export function deleteUndefinedProperties(obj: any) {
// return atomic data types and arrays (recursion anchor)
if (typeof obj !== 'object' || Array.isArray(obj)) {
return obj;
}
// check each key
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'undefined') {
// delete undefined keys
delete obj[key];
} else {
// check recursive
obj[key] = deleteUndefinedProperties(obj[key]);
}
});
return obj;
}