From 491052b1ae893b89d419b609ac49ed7b14dbe327 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 26 Sep 2023 19:48:08 +0100 Subject: [PATCH] Add additional logging Signed-off-by: Fred Boniface --- package-lock.json | 11 ----------- package.json | 1 - src/utils/minify.utils.ts | 4 ++++ src/utils/newSanitizer.ts | 3 +++ src/utils/sanitizer.utils.ts | 7 +++++++ src/utils/timeConvert.utils.ts | 8 ++++++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4250fe0..cbb6043 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "devDependencies": { "@owlboard/ts-types": "^0.0.9", "@types/jest": "^29.5.3", - "@types/pino": "^7.0.5", "eslint": "^8.39.0", "jest": "^29.6.2", "prettier": "^2.8.8", @@ -2687,16 +2686,6 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", "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": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", diff --git a/package.json b/package.json index 6df13f4..e64fd46 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "devDependencies": { "@owlboard/ts-types": "^0.0.9", "@types/jest": "^29.5.3", - "@types/pino": "^7.0.5", "eslint": "^8.39.0", "jest": "^29.6.2", "prettier": "^2.8.8", diff --git a/src/utils/minify.utils.ts b/src/utils/minify.utils.ts index e9b37ba..83c7821 100644 --- a/src/utils/minify.utils.ts +++ b/src/utils/minify.utils.ts @@ -1,7 +1,11 @@ +import { logger } from "./logger.utils"; + const htmlShrink = require("html-minifier").minify; const juice = require("juice"); +// Inlines styles and minifies the inlined HTML async function minifyMail(input: string): Promise { + logger.trace("minifyMail: Minifying mail output") const inlined: string = juice(input); return htmlShrink(inlined, { removeComments: true, diff --git a/src/utils/newSanitizer.ts b/src/utils/newSanitizer.ts index 5f9714d..4597856 100644 --- a/src/utils/newSanitizer.ts +++ b/src/utils/newSanitizer.ts @@ -1,4 +1,7 @@ +import { logger } from "./logger.utils"; + export function removeNewlineAndPTag(input: string): string { + logger.debug("removeNewlineAndPTag: Cleaning string") const regex = /[\n\r]|<\/?p[^>]*>/g; return input.replace(regex, function (match) { if (match === "\n" || match === "\r") { diff --git a/src/utils/sanitizer.utils.ts b/src/utils/sanitizer.utils.ts index 9619536..604fc8a 100644 --- a/src/utils/sanitizer.utils.ts +++ b/src/utils/sanitizer.utils.ts @@ -1,14 +1,19 @@ //const log = require('../utils/log.utils'); +import { logger } from "./logger.utils"; + function removeNonAlphanumeric(inputString: string) { + logger.debug("removeNonAlphanumeric: Sanitizing string") return inputString.replace(/[^a-zA-Z0-9]/g, ""); } function removeNonAlpha(inputString: string) { + logger.debug("removeNonAlpha: Sanitizing string") return inputString.replace(/[^a-zA-Z]/g, ""); } function removeNonNumeric(inputString: string) { + logger.debug("removeNonNumeric: Sanitizing string") return inputString.replace(/[^0-9]/g, ""); } @@ -16,12 +21,14 @@ const cleanApiEndpointTxt = removeNonAlpha; const cleanApiEndpointNum = removeNonAlphanumeric; function cleanNrcc(input: string) { + logger.error("DEPRECATED FUNCTION","cleanNrcc: Converting NRCC Data") // Remove newlines and then

tags from input const cleanInput = input.replace(/[\n\r]/g, "").replace(/<\/?p[^>]*>/g, ""); return cleanInput; } function getDomainFromEmail(mail: string) { + logger.debug("getDomainFromEmail: Obtaining domain from email address") // Needs testing let split = mail.split("@"); return split[1].toLowerCase(); diff --git a/src/utils/timeConvert.utils.ts b/src/utils/timeConvert.utils.ts index 12f510a..68c6d6d 100644 --- a/src/utils/timeConvert.utils.ts +++ b/src/utils/timeConvert.utils.ts @@ -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 dt = new Date(jsTime); return dt.toLocaleString(); } -function jsUnix(js: number) { +function jsUnix(js: number): number { + logger.trace(`jsUnix: Converting time: ${js}`) return Math.floor(js / 1000); }