newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
6 changed files with 20 additions and 14 deletions
Showing only changes of commit 491052b1ae - Show all commits

11
package-lock.json generated
View File

@ -28,7 +28,6 @@
"devDependencies": { "devDependencies": {
"@owlboard/ts-types": "^0.0.9", "@owlboard/ts-types": "^0.0.9",
"@types/jest": "^29.5.3", "@types/jest": "^29.5.3",
"@types/pino": "^7.0.5",
"eslint": "^8.39.0", "eslint": "^8.39.0",
"jest": "^29.6.2", "jest": "^29.6.2",
"prettier": "^2.8.8", "prettier": "^2.8.8",
@ -2687,16 +2686,6 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz",
"integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==" "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw=="
}, },
"node_modules/@types/pino": {
"version": "7.0.5",
"resolved": "https://registry.npmjs.org/@types/pino/-/pino-7.0.5.tgz",
"integrity": "sha512-wKoab31pknvILkxAF8ss+v9iNyhw5Iu/0jLtRkUD74cNfOOLJNnqfFKAv0r7wVaTQxRZtWrMpGfShwwBjOcgcg==",
"deprecated": "This is a stub types definition. pino provides its own type definitions, so you do not need this installed.",
"dev": true,
"dependencies": {
"pino": "*"
}
},
"node_modules/@types/stack-utils": { "node_modules/@types/stack-utils": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz",

View File

@ -35,7 +35,6 @@
"devDependencies": { "devDependencies": {
"@owlboard/ts-types": "^0.0.9", "@owlboard/ts-types": "^0.0.9",
"@types/jest": "^29.5.3", "@types/jest": "^29.5.3",
"@types/pino": "^7.0.5",
"eslint": "^8.39.0", "eslint": "^8.39.0",
"jest": "^29.6.2", "jest": "^29.6.2",
"prettier": "^2.8.8", "prettier": "^2.8.8",

View File

@ -1,7 +1,11 @@
import { logger } from "./logger.utils";
const htmlShrink = require("html-minifier").minify; const htmlShrink = require("html-minifier").minify;
const juice = require("juice"); const juice = require("juice");
// Inlines styles and minifies the inlined HTML
async function minifyMail(input: string): Promise<string> { async function minifyMail(input: string): Promise<string> {
logger.trace("minifyMail: Minifying mail output")
const inlined: string = juice(input); const inlined: string = juice(input);
return htmlShrink(inlined, { return htmlShrink(inlined, {
removeComments: true, removeComments: true,

View File

@ -1,4 +1,7 @@
import { logger } from "./logger.utils";
export function removeNewlineAndPTag(input: string): string { export function removeNewlineAndPTag(input: string): string {
logger.debug("removeNewlineAndPTag: Cleaning string")
const regex = /[\n\r]|<\/?p[^>]*>/g; const regex = /[\n\r]|<\/?p[^>]*>/g;
return input.replace(regex, function (match) { return input.replace(regex, function (match) {
if (match === "\n" || match === "\r") { if (match === "\n" || match === "\r") {

View File

@ -1,14 +1,19 @@
//const log = require('../utils/log.utils'); //const log = require('../utils/log.utils');
import { logger } from "./logger.utils";
function removeNonAlphanumeric(inputString: string) { function removeNonAlphanumeric(inputString: string) {
logger.debug("removeNonAlphanumeric: Sanitizing string")
return inputString.replace(/[^a-zA-Z0-9]/g, ""); return inputString.replace(/[^a-zA-Z0-9]/g, "");
} }
function removeNonAlpha(inputString: string) { function removeNonAlpha(inputString: string) {
logger.debug("removeNonAlpha: Sanitizing string")
return inputString.replace(/[^a-zA-Z]/g, ""); return inputString.replace(/[^a-zA-Z]/g, "");
} }
function removeNonNumeric(inputString: string) { function removeNonNumeric(inputString: string) {
logger.debug("removeNonNumeric: Sanitizing string")
return inputString.replace(/[^0-9]/g, ""); return inputString.replace(/[^0-9]/g, "");
} }
@ -16,12 +21,14 @@ const cleanApiEndpointTxt = removeNonAlpha;
const cleanApiEndpointNum = removeNonAlphanumeric; const cleanApiEndpointNum = removeNonAlphanumeric;
function cleanNrcc(input: string) { function cleanNrcc(input: string) {
logger.error("DEPRECATED FUNCTION","cleanNrcc: Converting NRCC Data")
// Remove newlines and then <p> tags from input // Remove newlines and then <p> tags from input
const cleanInput = input.replace(/[\n\r]/g, "").replace(/<\/?p[^>]*>/g, ""); const cleanInput = input.replace(/[\n\r]/g, "").replace(/<\/?p[^>]*>/g, "");
return cleanInput; return cleanInput;
} }
function getDomainFromEmail(mail: string) { function getDomainFromEmail(mail: string) {
logger.debug("getDomainFromEmail: Obtaining domain from email address")
// Needs testing // Needs testing
let split = mail.split("@"); let split = mail.split("@");
return split[1].toLowerCase(); return split[1].toLowerCase();

View File

@ -1,10 +1,14 @@
function unixLocal(unix: number) { import { logger } from "./logger.utils";
function unixLocal(unix: number): string {
logger.trace(`unixLocal: Converting time: ${unix}`)
var jsTime = unix * 1000; var jsTime = unix * 1000;
var dt = new Date(jsTime); var dt = new Date(jsTime);
return dt.toLocaleString(); return dt.toLocaleString();
} }
function jsUnix(js: number) { function jsUnix(js: number): number {
logger.trace(`jsUnix: Converting time: ${js}`)
return Math.floor(js / 1000); return Math.floor(js / 1000);
} }