Compare commits
No commits in common. "9ab67412433a324c8aec886ae9ead6fea0fd81af" and "0e748d545e3961377807ae5bbef98cd01a64e1d1" have entirely different histories.
9ab6741243
...
0e748d545e
32
package.json
32
package.json
|
@ -1,20 +1,4 @@
|
||||||
{
|
{
|
||||||
"name": "owlboard",
|
|
||||||
"version": "1.2.0-dev",
|
|
||||||
"description": "OwlBoard is an API and PWA for live rail departure board in the UK.",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://git.fjla.uk/owlboard/backend.git"
|
|
||||||
},
|
|
||||||
"license": "GPL-3.0-or-later",
|
|
||||||
"author": "Fred Boniface",
|
|
||||||
"main": "express.js",
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsc",
|
|
||||||
"run": "tsc && node dist/app.js",
|
|
||||||
"start": "node app.js",
|
|
||||||
"test": "jest"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.2.1",
|
"axios": "^1.2.1",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
|
@ -30,6 +14,22 @@
|
||||||
"redis": "^4.6.7",
|
"redis": "^4.6.7",
|
||||||
"zlib": "^1.0.5"
|
"zlib": "^1.0.5"
|
||||||
},
|
},
|
||||||
|
"name": "owlboard",
|
||||||
|
"description": "OwlBoard is an API and PWA for live rail departure board in the UK.",
|
||||||
|
"version": "1.2.0-dev",
|
||||||
|
"main": "express.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node app.js",
|
||||||
|
"run": "tsc && node dist/app.js",
|
||||||
|
"build": "tsc"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.fjla.uk/owlboard/backend.git"
|
||||||
|
},
|
||||||
|
"author": "Fred Boniface",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@owlboard/ts-types": "^0.0.3",
|
"@owlboard/ts-types": "^0.0.3",
|
||||||
"@types/jest": "^29.5.3",
|
"@types/jest": "^29.5.3",
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
export function removeNewlineAndPTag(input: string): string {
|
|
||||||
const regex = /[\n\r]|<\/?p[^>]*>/g;
|
|
||||||
return input.replace(regex, function(match) {
|
|
||||||
if (match === "\n" || match === "\r") {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -20,7 +20,18 @@ function cleanNrcc(input: string) { // Remove newlines and then <p> tags from in
|
||||||
return cleanInput;
|
return cleanInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDomainFromEmail(mail: string) { // Needs testing
|
export function removeNewlineAndPTag(input: string): string {
|
||||||
|
const regex = /[\n\r]|<\/?p[^>]*>/g;
|
||||||
|
return input.replace(regex, function(match) {
|
||||||
|
if (match === "\n" || match === "\r") {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDomainFromEmail(mail: string) { // Needs testing
|
||||||
let split = mail.split('@');
|
let split = mail.split('@');
|
||||||
return split[1];
|
return split[1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import type { StaffLdb, NrccMessage, TrainServices,
|
||||||
ServiceLocation } from '@owlboard/ts-types';
|
ServiceLocation } from '@owlboard/ts-types';
|
||||||
|
|
||||||
import { tz } from 'moment-timezone';
|
import { tz } from 'moment-timezone';
|
||||||
import { removeNewlineAndPTag } from '../../newSanitizer';
|
import { removeNewlineAndPTag } from '../../sanitizer.utils';
|
||||||
|
|
||||||
/// I do not yet have a type defined for any of the input object
|
/// I do not yet have a type defined for any of the input object
|
||||||
export function transform(input: any): StaffLdb | null {
|
export function transform(input: any): StaffLdb | null {
|
||||||
|
@ -14,9 +14,9 @@ export function transform(input: any): StaffLdb | null {
|
||||||
locationName: data?.locationName || "Not Found",
|
locationName: data?.locationName || "Not Found",
|
||||||
stationManagerCode: data?.stationManagerCode || "UK",
|
stationManagerCode: data?.stationManagerCode || "UK",
|
||||||
nrccMessages: transformNrcc(data?.nrccMessages) || undefined,
|
nrccMessages: transformNrcc(data?.nrccMessages) || undefined,
|
||||||
trainServices: transformTrainServices(data?.trainServices) || undefined,
|
trainServices: transformTrainServices(data?.trainServices),
|
||||||
busServices: transformTrainServices(data?.busServices) || undefined,
|
busServices: transformTrainServices(data?.busServices),
|
||||||
ferryServices: transformTrainServices(data?.ferryServices) || undefined
|
ferryServices: transformTrainServices(data?.ferryServices)
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -26,18 +26,15 @@ export function transform(input: any): StaffLdb | null {
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformDateTime(input: string): Date {
|
function transformDateTime(input: string): Date {
|
||||||
console.debug(`staffStation.transformDateTime Input: ${input}`)
|
|
||||||
return new Date(input)
|
return new Date(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformNrcc(input: any): NrccMessage[] {
|
function transformNrcc(input: any): NrccMessage[] {
|
||||||
console.debug(`staffStations.transformNrcc: Running`)
|
|
||||||
let output: NrccMessage[] = []
|
let output: NrccMessage[] = []
|
||||||
let messages = input
|
|
||||||
if (!Array.isArray(input?.message)) {
|
if (!Array.isArray(input?.message)) {
|
||||||
messages = [input?.message]
|
input.message = [input?.message]
|
||||||
}
|
}
|
||||||
for (const item of messages) {
|
for (const item of input?.message) {
|
||||||
let message: NrccMessage = {
|
let message: NrccMessage = {
|
||||||
severity: item?.severity,
|
severity: item?.severity,
|
||||||
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
xhtmlMessage: removeNewlineAndPTag(item?.xhtmlMessage)
|
||||||
|
@ -48,46 +45,37 @@ function transformNrcc(input: any): NrccMessage[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformTrainServices(input: any): TrainServices[] {
|
function transformTrainServices(input: any): TrainServices[] {
|
||||||
console.debug(`staffStation.transformTrainServices running`)
|
let services: any = input.service
|
||||||
let services: any = input?.service
|
|
||||||
let output: TrainServices[] = []
|
let output: TrainServices[] = []
|
||||||
if (services === undefined) {
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
if (!Array.isArray(input.service)) {
|
if (!Array.isArray(input.service)) {
|
||||||
services = [input.service]
|
services = [input.service]
|
||||||
}
|
}
|
||||||
for (const service of services) {
|
const trainServices: TrainServices = {
|
||||||
const trainService: TrainServices = {
|
rid: services?.rid,
|
||||||
rid: service?.rid,
|
uid: services?.uid,
|
||||||
uid: service?.uid,
|
trainid: services?.trainid,
|
||||||
trainid: service?.trainid,
|
operatorCode: services?.operatorCode || 'UK',
|
||||||
operatorCode: service?.operatorCode || 'UK',
|
platform: services?.platform || '',
|
||||||
platform: service?.platform || '-',
|
platformIsHidden: services?.platformIsHidden || '',
|
||||||
platformIsHidden: service?.platformIsHidden,
|
serviceIsSupressed: services?.serviceIsSupressed || '',
|
||||||
serviceIsSupressed: service?.serviceIsSupressed,
|
origin: transformLocation(services?.origin),
|
||||||
origin: transformLocation(service?.origin),
|
destination: transformLocation(services?.destination),
|
||||||
destination: transformLocation(service?.destination),
|
isCancelled: services?.isCancelled || '',
|
||||||
isCancelled: service?.isCancelled,
|
cancelReason: services?.cancelReason,
|
||||||
cancelReason: service?.cancelReason,
|
delayReason: services?.delayReason,
|
||||||
delayReason: service?.delayReason,
|
arrivalType: services?.arrivalType,
|
||||||
arrivalType: service?.arrivalType,
|
departureType: services?.departureType,
|
||||||
departureType: service?.departureType,
|
sta: transformUnspecifiedDateTime(services?.sta),
|
||||||
sta: transformUnspecifiedDateTime(service?.sta),
|
eta: transformUnspecifiedDateTime(services?.eta),
|
||||||
eta: transformUnspecifiedDateTime(service?.eta),
|
ata: transformUnspecifiedDateTime(services?.ata),
|
||||||
ata: transformUnspecifiedDateTime(service?.ata),
|
std: transformUnspecifiedDateTime(services?.std),
|
||||||
std: transformUnspecifiedDateTime(service?.std),
|
etd: transformUnspecifiedDateTime(services?.etd),
|
||||||
etd: transformUnspecifiedDateTime(service?.etd),
|
atd: transformUnspecifiedDateTime(services?.atd),
|
||||||
atd: transformUnspecifiedDateTime(service?.atd),
|
|
||||||
}
|
|
||||||
Object.keys(trainService).forEach(key => trainService[key] === undefined && delete trainService[key]);
|
|
||||||
output.push(trainService)
|
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformLocation(input: any): ServiceLocation[] {
|
function transformLocation(input: any): ServiceLocation[] {
|
||||||
console.debug(`staffStation.transformLocation running`)
|
|
||||||
let output: ServiceLocation[] = []
|
let output: ServiceLocation[] = []
|
||||||
if (!Array.isArray(input)) {
|
if (!Array.isArray(input)) {
|
||||||
input = [input]
|
input = [input]
|
||||||
|
@ -102,11 +90,7 @@ function transformLocation(input: any): ServiceLocation[] {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformUnspecifiedDateTime(input: string): Date | undefined {
|
function transformUnspecifiedDateTime(input: string): Date {
|
||||||
console.debug(`staffStation.transformUnspecifiedDateTime running`)
|
|
||||||
if (!input) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
const date = tz(input, "Europe/London");
|
const date = tz(input, "Europe/London");
|
||||||
return date.toDate()
|
return date.toDate()
|
||||||
}
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
import { removeNewlineAndPTag } from "../../src/utils/newSanitizer";
|
|
||||||
|
|
||||||
describe('newSanitizer', () => {
|
|
||||||
test('Should remove /\n and <p>/</p> elements', () => {
|
|
||||||
const input = "\n<p>This is a string</p>";
|
|
||||||
const expectedOutput = "This is a string"
|
|
||||||
expect(removeNewlineAndPTag(input)).toEqual(expectedOutput);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,31 +1,9 @@
|
||||||
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
|
import { removeNewlineAndPTag } from "../../src/utils/sanitizer.utils";
|
||||||
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
|
|
||||||
|
|
||||||
describe('Sanitize Email', () => {
|
describe('sanitizer', () => {
|
||||||
const inputs = [
|
test('Should remove /\n and <p>/</p> elements', () => {
|
||||||
"this+is+an-_email@example.com",
|
const input = "\n<p>This is a string</p>";
|
||||||
'"unusual email"@example.com',
|
const expectedOutput = "This is a string"
|
||||||
"(brackets)addr@example.com",
|
expect(removeNewlineAndPTag(input)).toEqual(expectedOutput);
|
||||||
"I%Have{Special}%Characters@example.com",
|
});
|
||||||
"Basic.address@example.com",
|
|
||||||
`"very.(),:;<>[]\".VERY.\"very\ \"very\".unusual"@example.com`
|
|
||||||
]
|
|
||||||
const expectedOutput = "example.com"
|
|
||||||
for (const addr of inputs) {
|
|
||||||
test(`Should return only domain: ${addr}`, () => {
|
|
||||||
expect(getDomainFromEmail(addr)).toEqual(expectedOutput);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Remove non-numeric', () => {
|
|
||||||
const inputs = ['abc123','<%43)($£@:}jfkd4']
|
|
||||||
const expectedOutputs = ['123','434']
|
|
||||||
for (const key in inputs) {
|
|
||||||
const input = inputs[key];
|
|
||||||
const desired = expectedOutputs[key];
|
|
||||||
test(`Should return only numbers: ${key}`, () => {
|
|
||||||
expect(removeNonNumeric(input)).toEqual(desired);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const inputs: any[] = [
|
||||||
{
|
{
|
||||||
rid: "202308017159276",
|
rid: "202308017159276",
|
||||||
uid: "G59276",
|
uid: "G59276",
|
||||||
trainid: "1M83",
|
trainuid: "1M83",
|
||||||
sdd: "2023-08-01",
|
sdd: "2023-08-01",
|
||||||
operator: "CrossCountry",
|
operator: "CrossCountry",
|
||||||
operatorCode: "XC",
|
operatorCode: "XC",
|
||||||
|
|
|
@ -13,7 +13,7 @@ export const outputs: any[] = [
|
||||||
{
|
{
|
||||||
rid: "202308017159276",
|
rid: "202308017159276",
|
||||||
uid: "G59276",
|
uid: "G59276",
|
||||||
trainid: "1M83",
|
trainuid: "1M83",
|
||||||
operatorCode: "XC",
|
operatorCode: "XC",
|
||||||
sta: expect.any(Date),
|
sta: expect.any(Date),
|
||||||
ata: expect.any(Date),
|
ata: expect.any(Date),
|
||||||
|
@ -35,8 +35,6 @@ export const outputs: any[] = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
busServices: [],
|
|
||||||
ferryServices: []
|
|
||||||
},
|
},
|
||||||
]
|
]
|
Loading…
Reference in New Issue