diff --git a/app/app.d.ts b/app/app.d.ts new file mode 100644 index 0000000..6078ebc --- /dev/null +++ b/app/app.d.ts @@ -0,0 +1 @@ +export declare const app: import("express-serve-static-core").Express; diff --git a/app.js b/app/app.js similarity index 67% rename from app.js rename to app/app.js index b15aa95..20bbd09 100644 --- a/app.js +++ b/app/app.js @@ -1,22 +1,18 @@ -import http from 'node:http'; import path from 'node:path'; import FasterUrlBuilder from '@cityssm/faster-url-builder'; -import { secondsToMillis } from '@cityssm/to-millis'; import cookieParser from 'cookie-parser'; import Debug from 'debug'; -import { asyncExitHook } from 'exit-hook'; import express from 'express'; import session from 'express-session'; import createError from 'http-errors'; -import schedule from 'node-schedule'; import FileStore from 'session-file-store'; -import { initializeUserDatabase } from './database/helpers.userDatabase.js'; -import { sessionCheckHandler } from './handlers/session.js'; -import * as configFunctions from './helpers/functions.config.js'; -import router_dashboard from './routers/dashboard.js'; -import router_login from './routers/login.js'; -import { version } from './version.js'; -const debug = Debug('faster-web-helper:app'); +import { initializeUserDatabase } from '../database/helpers.userDatabase.js'; +import { sessionCheckHandler } from '../handlers/session.js'; +import * as configFunctions from '../helpers/config.functions.js'; +import router_dashboard from '../routers/dashboard.js'; +import router_login from '../routers/login.js'; +import { version } from '../version.js'; +const debug = Debug(`faster-web-helper:app:${process.pid}`); /* * Initialize databases */ @@ -24,7 +20,7 @@ initializeUserDatabase(); /* * Initialize app */ -const app = express(); +export const app = express(); app.set('views', path.join('views')); app.set('view engine', 'ejs'); app.use((request, _response, next) => { @@ -108,27 +104,14 @@ app.get(`${urlPrefix}/logout`, (request, response) => { /* * Initialize modules */ -const options = { - app -}; -const promises = []; if (configFunctions.getConfigProperty('modules.autocomplete.isEnabled')) { - const initializeAutocompleteModule = await import('./modules/autocomplete/initializeAutocompleteModule.js'); - promises.push(initializeAutocompleteModule.default(options)); + const initializeAutocompleteModule = await import('../modules/autocomplete/initializeAutocompleteModule.js'); + initializeAutocompleteModule.initializeAutocompleteAppHandlers(app); } if (configFunctions.getConfigProperty('modules.inventoryScanner.isEnabled')) { - const initializeInventoryScannerModule = await import('./modules/inventoryScanner/initialize.js'); - initializeInventoryScannerModule.default(options); + const initializeInventoryScannerModule = await import('../modules/inventoryScanner/initializeInventoryScanner.js'); + initializeInventoryScannerModule.initializeInventoryScannerAppHandlers(app); } -if (configFunctions.getConfigProperty('modules.worktechUpdate.isEnabled')) { - const initializeWorktechUpdateModule = await import('./modules/worktechUpdate/initialize.js'); - initializeWorktechUpdateModule.default(options); -} -if (configFunctions.getConfigProperty('modules.tempFolderCleanup.isEnabled')) { - const initializeTempFolderCleanupModule = await import('./modules/tempFolderCleanup/initializeTempFolderCleanupModule.js'); - initializeTempFolderCleanupModule.default(options); -} -await Promise.all(promises); /* * Error handling */ @@ -146,17 +129,3 @@ app.use((error, request, response) => { response.status(error.status || 500); response.render('error'); }); -/* - * Initialize server - */ -const httpPort = configFunctions.getConfigProperty('webServer.httpPort'); -// eslint-disable-next-line @typescript-eslint/no-misused-promises -const httpServer = http.createServer(app); -httpServer.listen(httpPort); -debug(`HTTP listening on ${httpPort.toString()}`); -asyncExitHook(async () => { - await schedule.gracefulShutdown(); - httpServer.close(); -}, { - wait: secondsToMillis(1) -}); diff --git a/app.ts b/app/app.ts similarity index 68% rename from app.ts rename to app/app.ts index 1d436c1..23b1624 100644 --- a/app.ts +++ b/app/app.ts @@ -1,26 +1,21 @@ -import http from 'node:http' import path from 'node:path' import FasterUrlBuilder from '@cityssm/faster-url-builder' -import { secondsToMillis } from '@cityssm/to-millis' import cookieParser from 'cookie-parser' import Debug from 'debug' -import { asyncExitHook } from 'exit-hook' import express from 'express' import session from 'express-session' import createError from 'http-errors' -import schedule from 'node-schedule' import FileStore from 'session-file-store' -import { initializeUserDatabase } from './database/helpers.userDatabase.js' -import { sessionCheckHandler } from './handlers/session.js' -import * as configFunctions from './helpers/functions.config.js' -import type { ModuleInitializerOptions } from './modules/types.js' -import router_dashboard from './routers/dashboard.js' -import router_login from './routers/login.js' -import { version } from './version.js' +import { initializeUserDatabase } from '../database/helpers.userDatabase.js' +import { sessionCheckHandler } from '../handlers/session.js' +import * as configFunctions from '../helpers/config.functions.js' +import router_dashboard from '../routers/dashboard.js' +import router_login from '../routers/login.js' +import { version } from '../version.js' -const debug = Debug('faster-web-helper:app') +const debug = Debug(`faster-web-helper:app:${process.pid}`) /* * Initialize databases @@ -32,7 +27,7 @@ initializeUserDatabase() * Initialize app */ -const app = express() +export const app = express() app.set('views', path.join('views')) app.set('view engine', 'ejs') @@ -177,42 +172,20 @@ app.get(`${urlPrefix}/logout`, (request, response) => { * Initialize modules */ -const options: ModuleInitializerOptions = { - app -} - -const promises: Array> = [] - if (configFunctions.getConfigProperty('modules.autocomplete.isEnabled')) { const initializeAutocompleteModule = await import( - './modules/autocomplete/initializeAutocompleteModule.js' + '../modules/autocomplete/initializeAutocompleteModule.js' ) - promises.push(initializeAutocompleteModule.default(options)) + initializeAutocompleteModule.initializeAutocompleteAppHandlers(app) } if (configFunctions.getConfigProperty('modules.inventoryScanner.isEnabled')) { const initializeInventoryScannerModule = await import( - './modules/inventoryScanner/initialize.js' - ) - initializeInventoryScannerModule.default(options) -} - -if (configFunctions.getConfigProperty('modules.worktechUpdate.isEnabled')) { - const initializeWorktechUpdateModule = await import( - './modules/worktechUpdate/initialize.js' + '../modules/inventoryScanner/initializeInventoryScanner.js' ) - initializeWorktechUpdateModule.default(options) + initializeInventoryScannerModule.initializeInventoryScannerAppHandlers(app) } -if (configFunctions.getConfigProperty('modules.tempFolderCleanup.isEnabled')) { - const initializeTempFolderCleanupModule = await import( - './modules/tempFolderCleanup/initializeTempFolderCleanupModule.js' - ) - initializeTempFolderCleanupModule.default(options) -} - -await Promise.all(promises) - /* * Error handling */ @@ -239,25 +212,3 @@ app.use( response.render('error') } ) - -/* - * Initialize server - */ - -const httpPort = configFunctions.getConfigProperty('webServer.httpPort') - -// eslint-disable-next-line @typescript-eslint/no-misused-promises -const httpServer = http.createServer(app) - -httpServer.listen(httpPort) -debug(`HTTP listening on ${httpPort.toString()}`) - -asyncExitHook( - async () => { - await schedule.gracefulShutdown() - httpServer.close() - }, - { - wait: secondsToMillis(1) - } -) diff --git a/app.d.ts b/app/appProcess.d.ts similarity index 100% rename from app.d.ts rename to app/appProcess.d.ts diff --git a/app/appProcess.js b/app/appProcess.js new file mode 100644 index 0000000..a64ead2 --- /dev/null +++ b/app/appProcess.js @@ -0,0 +1,54 @@ +// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair +/* eslint-disable unicorn/no-process-exit */ +import http from 'node:http'; +import Debug from 'debug'; +import exitHook from 'exit-hook'; +import { getConfigProperty } from '../helpers/config.functions.js'; +import { app } from './app.js'; +const debug = Debug(`faster-web-helper:appProcess:${process.pid}`); +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': { + debug('Requires elevated privileges'); + process.exit(1); + // break; + } + // eslint-disable-next-line no-fallthrough + case 'EADDRINUSE': { + debug('Port is already in use.'); + process.exit(1); + // break; + } + // eslint-disable-next-line no-fallthrough + default: { + throw error; + } + } +} +function onListening(server) { + const addr = server.address(); + if (addr !== null) { + const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}`; + debug(`HTTP Listening on ${bind}`); + } +} +/* + * Initialize HTTP + */ +process.title = `Faster Web Helper (Worker)`; +const httpPort = getConfigProperty('webServer.httpPort'); +// eslint-disable-next-line @typescript-eslint/no-misused-promises +const httpServer = http.createServer(app); +httpServer.listen(httpPort); +httpServer.on('error', onError); +httpServer.on('listening', () => { + onListening(httpServer); +}); +exitHook(() => { + debug('Closing HTTP'); + httpServer.close(); +}); diff --git a/app/appProcess.ts b/app/appProcess.ts new file mode 100644 index 0000000..ddbe780 --- /dev/null +++ b/app/appProcess.ts @@ -0,0 +1,78 @@ +// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair +/* eslint-disable unicorn/no-process-exit */ + +import http from 'node:http' + +import Debug from 'debug' +import exitHook from 'exit-hook' + +import { getConfigProperty } from '../helpers/config.functions.js' + +import { app } from './app.js' + +const debug = Debug(`faster-web-helper:appProcess:${process.pid}`) + +interface ServerError extends Error { + syscall: string + code: string +} + +function onError(error: ServerError): void { + if (error.syscall !== 'listen') { + throw error + } + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': { + debug('Requires elevated privileges') + process.exit(1) + // break; + } + + // eslint-disable-next-line no-fallthrough + case 'EADDRINUSE': { + debug('Port is already in use.') + process.exit(1) + // break; + } + + // eslint-disable-next-line no-fallthrough + default: { + throw error + } + } +} + +function onListening(server: http.Server): void { + const addr = server.address() + + if (addr !== null) { + const bind = + typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}` + debug(`HTTP Listening on ${bind}`) + } +} + +/* + * Initialize HTTP + */ + +process.title = `Faster Web Helper (Worker)` + +const httpPort = getConfigProperty('webServer.httpPort') + +// eslint-disable-next-line @typescript-eslint/no-misused-promises +const httpServer = http.createServer(app) + +httpServer.listen(httpPort) + +httpServer.on('error', onError) +httpServer.on('listening', () => { + onListening(httpServer) +}) + +exitHook(() => { + debug('Closing HTTP') + httpServer.close() +}) \ No newline at end of file diff --git a/database/createUser.js b/database/createUser.js index e6d4f73..70238e8 100644 --- a/database/createUser.js +++ b/database/createUser.js @@ -1,5 +1,5 @@ import sqlite from 'better-sqlite3'; -import { generateKeyGuid } from '../helpers/functions.user.js'; +import { generateKeyGuid } from '../helpers/users.functions.js'; import { databasePath } from './helpers.userDatabase.js'; export default function createUser(user) { const rightNow = Date.now(); diff --git a/database/createUser.ts b/database/createUser.ts index 4c21591..77e2dec 100644 --- a/database/createUser.ts +++ b/database/createUser.ts @@ -1,6 +1,6 @@ import sqlite from 'better-sqlite3' -import { generateKeyGuid } from '../helpers/functions.user.js' +import { generateKeyGuid } from '../helpers/users.functions.js' import { databasePath } from './helpers.userDatabase.js' diff --git a/eslint.config.js b/eslint.config.js index 05c0bad..414b95d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -20,7 +20,8 @@ export const config = tseslint.config(...configWebApp, { '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/no-unsafe-member-access': 'off' + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-type-assertion': 'off' } }); export default config; diff --git a/eslint.config.ts b/eslint.config.ts index 2ca4d60..b00428c 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,31 +1,29 @@ import { configWebApp, cspellWords, tseslint } from 'eslint-config-cityssm' -export const config = tseslint.config( - ...configWebApp, - { - rules: { - '@cspell/spellchecker': [ - 'warn', - { - cspell: { - words: [ - ...cspellWords, - 'autoincrement', - 'fasterwebcloud', - 'fontawesome', - 'resave', - 'unvalidated', - 'worktech' - ] - } +export const config = tseslint.config(...configWebApp, { + rules: { + '@cspell/spellchecker': [ + 'warn', + { + cspell: { + words: [ + ...cspellWords, + 'autoincrement', + 'fasterwebcloud', + 'fontawesome', + 'resave', + 'unvalidated', + 'worktech' + ] } - ], - '@typescript-eslint/no-unsafe-assignment': 'off', - '@typescript-eslint/no-unsafe-argument': 'off', - '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/no-unsafe-member-access': 'off' - } + } + ], + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-type-assertion': 'off' } -) +}) export default config diff --git a/handlers/session.js b/handlers/session.js index 5aa3089..516f5c7 100644 --- a/handlers/session.js +++ b/handlers/session.js @@ -1,4 +1,4 @@ -import { getConfigProperty } from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/config.functions.js'; const urlPrefix = getConfigProperty('webServer.urlPrefix'); const sessionCookieName = getConfigProperty('webServer.session.cookieName'); // Redirect logged in users diff --git a/handlers/session.ts b/handlers/session.ts index c15a522..c77aef9 100644 --- a/handlers/session.ts +++ b/handlers/session.ts @@ -1,6 +1,6 @@ import type { NextFunction, Request, Response } from 'express' -import { getConfigProperty } from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/config.functions.js' const urlPrefix = getConfigProperty('webServer.urlPrefix') diff --git a/helpers/functions.config.d.ts b/helpers/config.functions.d.ts similarity index 100% rename from helpers/functions.config.d.ts rename to helpers/config.functions.d.ts diff --git a/helpers/functions.config.js b/helpers/config.functions.js similarity index 100% rename from helpers/functions.config.js rename to helpers/config.functions.js diff --git a/helpers/functions.config.ts b/helpers/config.functions.ts similarity index 100% rename from helpers/functions.config.ts rename to helpers/config.functions.ts diff --git a/helpers/helpers.faster.d.ts b/helpers/fasterWeb.helpers.d.ts similarity index 100% rename from helpers/helpers.faster.d.ts rename to helpers/fasterWeb.helpers.d.ts diff --git a/helpers/helpers.faster.js b/helpers/fasterWeb.helpers.js similarity index 84% rename from helpers/helpers.faster.js rename to helpers/fasterWeb.helpers.js index 077631f..e4230fb 100644 --- a/helpers/helpers.faster.js +++ b/helpers/fasterWeb.helpers.js @@ -1,5 +1,5 @@ import hasPackage from '@cityssm/has-package'; -import { getConfigProperty } from './functions.config.js'; +import { getConfigProperty } from './config.functions.js'; const fasterApiPackageExists = await hasPackage('@cityssm/faster-api'); const fasterWebConfig = getConfigProperty('fasterWeb'); export const hasFasterApi = fasterApiPackageExists && diff --git a/helpers/helpers.faster.ts b/helpers/fasterWeb.helpers.ts similarity index 84% rename from helpers/helpers.faster.ts rename to helpers/fasterWeb.helpers.ts index 6ca6b1d..724c39c 100644 --- a/helpers/helpers.faster.ts +++ b/helpers/fasterWeb.helpers.ts @@ -1,6 +1,6 @@ import hasPackage from '@cityssm/has-package' -import { getConfigProperty } from './functions.config.js' +import { getConfigProperty } from './config.functions.js' const fasterApiPackageExists = await hasPackage('@cityssm/faster-api') const fasterWebConfig = getConfigProperty('fasterWeb') diff --git a/helpers/functions.filesystem.d.ts b/helpers/filesystem.functions.d.ts similarity index 100% rename from helpers/functions.filesystem.d.ts rename to helpers/filesystem.functions.d.ts diff --git a/helpers/functions.filesystem.js b/helpers/filesystem.functions.js similarity index 100% rename from helpers/functions.filesystem.js rename to helpers/filesystem.functions.js diff --git a/helpers/functions.filesystem.ts b/helpers/filesystem.functions.ts similarity index 100% rename from helpers/functions.filesystem.ts rename to helpers/filesystem.functions.ts diff --git a/helpers/functions.sftp.d.ts b/helpers/sftp.functions.d.ts similarity index 100% rename from helpers/functions.sftp.d.ts rename to helpers/sftp.functions.d.ts diff --git a/helpers/functions.sftp.js b/helpers/sftp.functions.js similarity index 96% rename from helpers/functions.sftp.js rename to helpers/sftp.functions.js index 3e026ab..3cba10f 100644 --- a/helpers/functions.sftp.js +++ b/helpers/sftp.functions.js @@ -3,8 +3,8 @@ import os from 'node:os'; import path from 'node:path'; import { Client } from 'basic-ftp'; import Debug from 'debug'; -import { getConfigProperty } from './functions.config.js'; -import { doesFileExist, ensureTempFolderExists, tempFolderPath } from './functions.filesystem.js'; +import { getConfigProperty } from './config.functions.js'; +import { doesFileExist, ensureTempFolderExists, tempFolderPath } from './filesystem.functions.js'; const debug = Debug('faster-web-helper:functions.sftp'); export async function downloadFilesToTemp(ftpPath) { await ensureTempFolderExists(); diff --git a/helpers/functions.sftp.ts b/helpers/sftp.functions.ts similarity index 96% rename from helpers/functions.sftp.ts rename to helpers/sftp.functions.ts index 909089d..24fceac 100644 --- a/helpers/functions.sftp.ts +++ b/helpers/sftp.functions.ts @@ -7,12 +7,12 @@ import Debug from 'debug' import type { ConfigFtpPath } from '../types/configHelperTypes.js' -import { getConfigProperty } from './functions.config.js' +import { getConfigProperty } from './config.functions.js' import { doesFileExist, ensureTempFolderExists, tempFolderPath -} from './functions.filesystem.js' +} from './filesystem.functions.js' const debug = Debug('faster-web-helper:functions.sftp') diff --git a/helpers/functions.task.d.ts b/helpers/tasks.functions.d.ts similarity index 100% rename from helpers/functions.task.d.ts rename to helpers/tasks.functions.d.ts diff --git a/helpers/functions.task.js b/helpers/tasks.functions.js similarity index 100% rename from helpers/functions.task.js rename to helpers/tasks.functions.js diff --git a/helpers/functions.task.ts b/helpers/tasks.functions.ts similarity index 100% rename from helpers/functions.task.ts rename to helpers/tasks.functions.ts diff --git a/helpers/functions.user.d.ts b/helpers/users.functions.d.ts similarity index 100% rename from helpers/functions.user.d.ts rename to helpers/users.functions.d.ts diff --git a/helpers/functions.user.js b/helpers/users.functions.js similarity index 92% rename from helpers/functions.user.js rename to helpers/users.functions.js index 12268f4..fac0e60 100644 --- a/helpers/functions.user.js +++ b/helpers/users.functions.js @@ -1,8 +1,8 @@ import { randomUUID } from 'node:crypto'; import { ADWebAuthAuthenticator, ActiveDirectoryAuthenticator, PlainTextAuthenticator } from '@cityssm/authentication-helper'; import Debug from 'debug'; -import { getConfigProperty } from './functions.config.js'; -const debug = Debug('faster-web-helper:functions.user'); +import { getConfigProperty } from './config.functions.js'; +const debug = Debug('faster-web-helper:users.functions'); // eslint-disable-next-line @typescript-eslint/init-declarations let authenticator; const authenticationConfig = getConfigProperty('login.authentication'); diff --git a/helpers/functions.user.ts b/helpers/users.functions.ts similarity index 92% rename from helpers/functions.user.ts rename to helpers/users.functions.ts index c2faa0e..3987c58 100644 --- a/helpers/functions.user.ts +++ b/helpers/users.functions.ts @@ -8,9 +8,9 @@ import { } from '@cityssm/authentication-helper' import Debug from 'debug' -import { getConfigProperty } from './functions.config.js' +import { getConfigProperty } from './config.functions.js' -const debug = Debug('faster-web-helper:functions.user') +const debug = Debug('faster-web-helper:users.functions') // eslint-disable-next-line @typescript-eslint/init-declarations let authenticator: BaseAuthenticator | undefined diff --git a/modules/types.js b/index.d.ts similarity index 100% rename from modules/types.js rename to index.d.ts diff --git a/index.js b/index.js new file mode 100644 index 0000000..d62f4cc --- /dev/null +++ b/index.js @@ -0,0 +1,78 @@ +import cluster from 'node:cluster'; +import os from 'node:os'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { secondsToMillis } from '@cityssm/to-millis'; +import Debug from 'debug'; +import { asyncExitHook } from 'exit-hook'; +import schedule from 'node-schedule'; +import { getConfigProperty } from './helpers/config.functions.js'; +const debug = Debug(`lot-occupancy-system:www:${process.pid}`); +const directoryName = path.dirname(fileURLToPath(import.meta.url)); +process.title = `Faster Web Helper (Primary)`; +debug(`Primary pid: ${process.pid}`); +debug(`Primary title: ${process.title}`); +async function initializeModuleTasks() { + const promises = []; + if (getConfigProperty('modules.autocomplete.isEnabled')) { + const initializeAutocompleteModule = await import('./modules/autocomplete/initializeAutocompleteModule.js'); + promises.push(initializeAutocompleteModule.initializeAutocompleteTasks()); + } + if (getConfigProperty('modules.inventoryScanner.isEnabled')) { + const initializeInventoryScannerModule = await import('./modules/inventoryScanner/initializeInventoryScanner.js'); + initializeInventoryScannerModule.initializeInventoryScannerTasks(); + } + if (getConfigProperty('modules.tempFolderCleanup.isEnabled')) { + const initializeTempFolderCleanupModule = await import('./modules/tempFolderCleanup/initializeTempFolderCleanupModule.js'); + initializeTempFolderCleanupModule.initializeTempFolderCleanupTask(); + } + if (getConfigProperty('modules.worktechUpdate.isEnabled')) { + const initializeWorktechUpdateModule = await import('./modules/worktechUpdate/initializeWorktechUpdate.js'); + initializeWorktechUpdateModule.initializeWorktechUpdateTasks(); + } + await Promise.all(promises); +} +function initializeAppWorkers() { + const processCount = Math.min(os.cpus().length, 2); + debug(`Launching ${processCount} web app processes`); + const clusterSettings = { + exec: `${directoryName}/app/appProcess.js` + }; + cluster.setupPrimary(clusterSettings); + const activeWorkers = new Map(); + for (let index = 0; index < processCount; index += 1) { + const worker = cluster.fork(); + activeWorkers.set(worker.process.pid ?? 0, worker); + } + cluster.on('message', (worker, message) => { + for (const [pid, activeWorker] of activeWorkers.entries()) { + if (pid === message.pid) { + continue; + } + debug(`Relaying message to worker: ${pid}`); + activeWorker.send(message); + } + }); + cluster.on('exit', (worker) => { + debug(`Worker ${(worker.process.pid ?? 0).toString()} has been killed`); + activeWorkers.delete(worker.process.pid ?? 0); + debug('Starting another worker'); + cluster.fork(); + }); +} +await initializeModuleTasks(); +initializeAppWorkers(); +if (process.env.STARTUP_TEST === 'true') { + const killSeconds = 10; + debug(`Killing processes in ${killSeconds} seconds...`); + setTimeout(() => { + debug('Killing processes'); + // eslint-disable-next-line unicorn/no-process-exit + process.exit(0); + }, secondsToMillis(killSeconds)); +} +asyncExitHook(async () => { + await schedule.gracefulShutdown(); +}, { + wait: secondsToMillis(1) +}); diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..8e377b7 --- /dev/null +++ b/index.ts @@ -0,0 +1,118 @@ +import cluster, { type Worker } from 'node:cluster' +import os from 'node:os' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +import { secondsToMillis } from '@cityssm/to-millis' +import Debug from 'debug' +import { asyncExitHook } from 'exit-hook' +import schedule from 'node-schedule' + +import { getConfigProperty } from './helpers/config.functions.js' +import type { WorkerMessage } from './types/applicationTypes.js' + +const debug = Debug(`lot-occupancy-system:www:${process.pid}`) + +const directoryName = path.dirname(fileURLToPath(import.meta.url)) + +process.title = `Faster Web Helper (Primary)` + +debug(`Primary pid: ${process.pid}`) +debug(`Primary title: ${process.title}`) + +async function initializeModuleTasks(): Promise { + const promises: Array> = [] + + if (getConfigProperty('modules.autocomplete.isEnabled')) { + const initializeAutocompleteModule = await import( + './modules/autocomplete/initializeAutocompleteModule.js' + ) + promises.push(initializeAutocompleteModule.initializeAutocompleteTasks()) + } + + if (getConfigProperty('modules.inventoryScanner.isEnabled')) { + const initializeInventoryScannerModule = await import( + './modules/inventoryScanner/initializeInventoryScanner.js' + ) + initializeInventoryScannerModule.initializeInventoryScannerTasks() + } + + if (getConfigProperty('modules.tempFolderCleanup.isEnabled')) { + const initializeTempFolderCleanupModule = await import( + './modules/tempFolderCleanup/initializeTempFolderCleanupModule.js' + ) + initializeTempFolderCleanupModule.initializeTempFolderCleanupTask() + } + + if (getConfigProperty('modules.worktechUpdate.isEnabled')) { + const initializeWorktechUpdateModule = await import( + './modules/worktechUpdate/initializeWorktechUpdate.js' + ) + initializeWorktechUpdateModule.initializeWorktechUpdateTasks() + } + + await Promise.all(promises) +} + +function initializeAppWorkers(): void { + const processCount = Math.min(os.cpus().length, 2) + + debug(`Launching ${processCount} web app processes`) + + const clusterSettings = { + exec: `${directoryName}/app/appProcess.js` + } + + cluster.setupPrimary(clusterSettings) + + const activeWorkers = new Map() + + for (let index = 0; index < processCount; index += 1) { + const worker = cluster.fork() + activeWorkers.set(worker.process.pid ?? 0, worker) + } + + cluster.on('message', (worker, message: WorkerMessage) => { + for (const [pid, activeWorker] of activeWorkers.entries()) { + if (pid === message.pid) { + continue + } + + debug(`Relaying message to worker: ${pid}`) + activeWorker.send(message) + } + }) + + cluster.on('exit', (worker) => { + debug(`Worker ${(worker.process.pid ?? 0).toString()} has been killed`) + activeWorkers.delete(worker.process.pid ?? 0) + + debug('Starting another worker') + cluster.fork() + }) +} + +await initializeModuleTasks() +initializeAppWorkers() + +if (process.env.STARTUP_TEST === 'true') { + const killSeconds = 10 + + debug(`Killing processes in ${killSeconds} seconds...`) + + setTimeout(() => { + debug('Killing processes') + + // eslint-disable-next-line unicorn/no-process-exit + process.exit(0) + }, secondsToMillis(killSeconds)) +} + +asyncExitHook( + async () => { + await schedule.gracefulShutdown() + }, + { + wait: secondsToMillis(1) + } +) diff --git a/modules/autocomplete/initializeAutocompleteModule.d.ts b/modules/autocomplete/initializeAutocompleteModule.d.ts index 44e2d4a..643c273 100644 --- a/modules/autocomplete/initializeAutocompleteModule.d.ts +++ b/modules/autocomplete/initializeAutocompleteModule.d.ts @@ -1,2 +1,3 @@ -import type { ModuleInitializerOptions } from '../types.js'; -export default function initializeAutocompleteModule(options: ModuleInitializerOptions): Promise; +import express from 'express'; +export declare function initializeAutocompleteAppHandlers(app: express.Application): void; +export declare function initializeAutocompleteTasks(): Promise; diff --git a/modules/autocomplete/initializeAutocompleteModule.js b/modules/autocomplete/initializeAutocompleteModule.js index 26162d9..d5e193e 100644 --- a/modules/autocomplete/initializeAutocompleteModule.js +++ b/modules/autocomplete/initializeAutocompleteModule.js @@ -5,22 +5,17 @@ import Debug from 'debug'; import exitHook from 'exit-hook'; import express from 'express'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/config.functions.js'; import { moduleName } from './helpers/moduleHelpers.js'; import runUpdateAssetNumbersTask, { taskName as updateAssetNumbersTaskName } from './tasks/updateAssetNumbersTask.js'; import runUpdateItemNumbersTask, { taskName as updateItemNumbersTaskName } from './tasks/updateItemNumbersTask.js'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`); const assetNumbersConfig = getConfigProperty('modules.autocomplete.reports.w114'); const itemNumbersConfig = getConfigProperty('modules.autocomplete.reports.w200'); -export default async function initializeAutocompleteModule(options) { - debug(`Initializing "${moduleName}"...`); - /* - * Set up static server - */ - options.app.use(`${getConfigProperty('webServer.urlPrefix')}/autocomplete`, express.static(path.join('public', 'autocomplete'))); - /* - * Run startup tasks - */ +export function initializeAutocompleteAppHandlers(app) { + app.use(`${getConfigProperty('webServer.urlPrefix')}/autocomplete`, express.static(path.join('public', 'autocomplete'))); +} +export async function initializeAutocompleteTasks() { if (getConfigProperty('modules.autocomplete.runOnStartup')) { debug(`Running "${updateItemNumbersTaskName}" on startup...`); if (assetNumbersConfig !== undefined) { @@ -56,5 +51,4 @@ export default async function initializeAutocompleteModule(options) { updateItemNumbersJob.cancel(); } }); - debug(`"${moduleName}" initialized.`); } diff --git a/modules/autocomplete/initializeAutocompleteModule.ts b/modules/autocomplete/initializeAutocompleteModule.ts index aada969..4fb5409 100644 --- a/modules/autocomplete/initializeAutocompleteModule.ts +++ b/modules/autocomplete/initializeAutocompleteModule.ts @@ -7,8 +7,7 @@ import exitHook from 'exit-hook' import express from 'express' import schedule from 'node-schedule' -import { getConfigProperty } from '../../helpers/functions.config.js' -import type { ModuleInitializerOptions } from '../types.js' +import { getConfigProperty } from '../../helpers/config.functions.js' import { moduleName } from './helpers/moduleHelpers.js' import runUpdateAssetNumbersTask, { @@ -25,24 +24,15 @@ const assetNumbersConfig = getConfigProperty( ) const itemNumbersConfig = getConfigProperty('modules.autocomplete.reports.w200') -export default async function initializeAutocompleteModule( - options: ModuleInitializerOptions -): Promise { - debug(`Initializing "${moduleName}"...`) - - /* - * Set up static server - */ - - options.app.use( +export function initializeAutocompleteAppHandlers(app: express.Application): void { + app.use( `${getConfigProperty('webServer.urlPrefix')}/autocomplete`, express.static(path.join('public', 'autocomplete')) ) +} - /* - * Run startup tasks - */ - +export async function initializeAutocompleteTasks( +): Promise { if (getConfigProperty('modules.autocomplete.runOnStartup')) { debug(`Running "${updateItemNumbersTaskName}" on startup...`) @@ -108,6 +98,4 @@ export default async function initializeAutocompleteModule( updateItemNumbersJob.cancel() } }) - - debug(`"${moduleName}" initialized.`) } diff --git a/modules/autocomplete/tasks/updateAssetNumbersTask.js b/modules/autocomplete/tasks/updateAssetNumbersTask.js index 16af86e..d516053 100644 --- a/modules/autocomplete/tasks/updateAssetNumbersTask.js +++ b/modules/autocomplete/tasks/updateAssetNumbersTask.js @@ -3,8 +3,8 @@ import { parseW114ExcelReport } from '@cityssm/faster-report-parser/xlsx'; import { dateStringToDate } from '@cityssm/utils-datetime'; import camelCase from 'camelcase'; import Debug from 'debug'; -import { getConfigProperty } from '../../../helpers/functions.config.js'; -import { downloadFilesToTemp } from '../../../helpers/functions.sftp.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; +import { downloadFilesToTemp } from '../../../helpers/sftp.functions.js'; import { moduleName } from '../helpers/moduleHelpers.js'; export const taskName = 'Update Asset Numbers Task'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}`); diff --git a/modules/autocomplete/tasks/updateAssetNumbersTask.ts b/modules/autocomplete/tasks/updateAssetNumbersTask.ts index 2adf29d..812d7df 100644 --- a/modules/autocomplete/tasks/updateAssetNumbersTask.ts +++ b/modules/autocomplete/tasks/updateAssetNumbersTask.ts @@ -5,8 +5,8 @@ import { dateStringToDate } from '@cityssm/utils-datetime' import camelCase from 'camelcase' import Debug from 'debug' -import { getConfigProperty } from '../../../helpers/functions.config.js' -import { downloadFilesToTemp } from '../../../helpers/functions.sftp.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' +import { downloadFilesToTemp } from '../../../helpers/sftp.functions.js' import type { ConfigFileSuffixXlsx, ConfigScheduledFtpReport diff --git a/modules/autocomplete/tasks/updateItemNumbersTask.js b/modules/autocomplete/tasks/updateItemNumbersTask.js index 4be031f..e8d5dfc 100644 --- a/modules/autocomplete/tasks/updateItemNumbersTask.js +++ b/modules/autocomplete/tasks/updateItemNumbersTask.js @@ -3,8 +3,8 @@ import { parseW200ExcelReport } from '@cityssm/faster-report-parser/xlsx'; import { dateStringToDate } from '@cityssm/utils-datetime'; import camelCase from 'camelcase'; import Debug from 'debug'; -import { getConfigProperty } from '../../../helpers/functions.config.js'; -import { downloadFilesToTemp } from '../../../helpers/functions.sftp.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; +import { downloadFilesToTemp } from '../../../helpers/sftp.functions.js'; import { moduleName } from '../helpers/moduleHelpers.js'; export const taskName = 'Update Item Numbers Task'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}`); diff --git a/modules/autocomplete/tasks/updateItemNumbersTask.ts b/modules/autocomplete/tasks/updateItemNumbersTask.ts index ce35d0f..98521cd 100644 --- a/modules/autocomplete/tasks/updateItemNumbersTask.ts +++ b/modules/autocomplete/tasks/updateItemNumbersTask.ts @@ -5,8 +5,8 @@ import { dateStringToDate } from '@cityssm/utils-datetime' import camelCase from 'camelcase' import Debug from 'debug' -import { getConfigProperty } from '../../../helpers/functions.config.js' -import { downloadFilesToTemp } from '../../../helpers/functions.sftp.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' +import { downloadFilesToTemp } from '../../../helpers/sftp.functions.js' import type { ConfigFileSuffixXlsx, ConfigScheduledFtpReport diff --git a/modules/inventoryScanner/database/helpers.database.js b/modules/inventoryScanner/database/helpers.database.js index e160033..764347f 100644 --- a/modules/inventoryScanner/database/helpers.database.js +++ b/modules/inventoryScanner/database/helpers.database.js @@ -62,6 +62,7 @@ const createStatements = [ )` ]; export function initializeInventoryScannerDatabase() { + debug(`Checking for ${databasePath}`); let success = false; const database = sqlite(databasePath); const row = database diff --git a/modules/inventoryScanner/database/helpers.database.ts b/modules/inventoryScanner/database/helpers.database.ts index c8a58d1..955a577 100644 --- a/modules/inventoryScanner/database/helpers.database.ts +++ b/modules/inventoryScanner/database/helpers.database.ts @@ -74,6 +74,8 @@ const createStatements = [ ] export function initializeInventoryScannerDatabase(): boolean { + debug(`Checking for ${databasePath}`) + let success = false const database = sqlite(databasePath) diff --git a/modules/inventoryScanner/helpers/sync/faster.d.ts b/modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.d.ts similarity index 100% rename from modules/inventoryScanner/helpers/sync/faster.d.ts rename to modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.d.ts diff --git a/modules/inventoryScanner/helpers/sync/faster.js b/modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.js similarity index 85% rename from modules/inventoryScanner/helpers/sync/faster.js rename to modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.js index a9df234..8fa9f93 100644 --- a/modules/inventoryScanner/helpers/sync/faster.js +++ b/modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.js @@ -5,14 +5,17 @@ import path from 'node:path'; import { dateIntegerToDate } from '@cityssm/utils-datetime'; import camelcase from 'camelcase'; import Debug from 'debug'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; -import { ensureTempFolderExists, tempFolderPath } from '../../../../helpers/functions.filesystem.js'; -import { uploadFile } from '../../../../helpers/functions.sftp.js'; -import { hasFasterApi } from '../../../../helpers/helpers.faster.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; +import { hasFasterApi } from '../../../../helpers/fasterWeb.helpers.js'; +import { ensureTempFolderExists, tempFolderPath } from '../../../../helpers/filesystem.functions.js'; +import { uploadFile } from '../../../../helpers/sftp.functions.js'; import { updateScannerRecordSyncFields } from '../../database/updateScannerRecordSyncFields.js'; import { moduleName } from '../module.js'; import { updateMultipleScannerRecords } from './syncHelpers.js'; const debug = Debug(`faster-web-helper:${camelcase(moduleName)}:syncFaster`); +const exportFileNamePrefix = getConfigProperty( +// eslint-disable-next-line no-secrets/no-secrets +'modules.inventoryScanner.fasterSync.exportFileNamePrefix'); function recordToExportDataLine(record) { // A - "RDC" const dataPieces = ['RDC']; @@ -67,25 +70,32 @@ function recordToExportDataLine(record) { } function getExportFileName() { const rightNow = new Date(); - const timezone = (rightNow.getTimezoneOffset() / 60) * 100; - const timezoneString = timezone > 0 - ? '-' + timezone.toString().padStart(4, '0') - : '+' + Math.abs(timezone).toString().padStart(4, '0'); + /* + * Date + */ const dateString = rightNow.getFullYear().toString() + '-' + (rightNow.getMonth() + 1).toString().padStart(2, '0') + '-' + - rightNow.getDate().toString().padStart(2, '0') + - '_' + - rightNow.getHours().toString().padStart(2, '0') + + rightNow.getDate().toString().padStart(2, '0'); + /* + * Time + */ + const timeString = rightNow.getHours().toString().padStart(2, '0') + rightNow.getMinutes().toString().padStart(2, '0') + - rightNow.getSeconds().toString().padStart(2, '0') + - timezoneString; - const fileName = getConfigProperty( - // eslint-disable-next-line no-secrets/no-secrets - 'modules.inventoryScanner.fasterSync.exportFileNamePrefix') + - dateString + - '.csv'; + rightNow.getSeconds().toString().padStart(2, '0'); + /* + * Timezone + */ + const timezone = (rightNow.getTimezoneOffset() / 60) * 100; + const timezoneString = timezone > 0 + ? `-${timezone.toString().padStart(4, '0')}` + : `+${Math.abs(timezone).toString().padStart(4, '0')}`; + /* + * Full date string + */ + const fullDateString = dateString + '_' + timeString + timezoneString; + const fileName = exportFileNamePrefix + fullDateString + '.csv'; return fileName; } export async function syncScannerRecordsWithFaster(records) { diff --git a/modules/inventoryScanner/helpers/sync/faster.ts b/modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.ts similarity index 86% rename from modules/inventoryScanner/helpers/sync/faster.ts rename to modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.ts index b8d524f..32d0a55 100644 --- a/modules/inventoryScanner/helpers/sync/faster.ts +++ b/modules/inventoryScanner/helpers/sync/fasterWeb.syncHelpers.ts @@ -8,13 +8,13 @@ import { dateIntegerToDate } from '@cityssm/utils-datetime' import camelcase from 'camelcase' import Debug from 'debug' -import { getConfigProperty } from '../../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' +import { hasFasterApi } from '../../../../helpers/fasterWeb.helpers.js' import { ensureTempFolderExists, tempFolderPath -} from '../../../../helpers/functions.filesystem.js' -import { uploadFile } from '../../../../helpers/functions.sftp.js' -import { hasFasterApi } from '../../../../helpers/helpers.faster.js' +} from '../../../../helpers/filesystem.functions.js' +import { uploadFile } from '../../../../helpers/sftp.functions.js' import { updateScannerRecordSyncFields } from '../../database/updateScannerRecordSyncFields.js' import type { InventoryScannerRecord } from '../../types.js' import { moduleName } from '../module.js' @@ -23,6 +23,11 @@ import { updateMultipleScannerRecords } from './syncHelpers.js' const debug = Debug(`faster-web-helper:${camelcase(moduleName)}:syncFaster`) +const exportFileNamePrefix = getConfigProperty( + // eslint-disable-next-line no-secrets/no-secrets + 'modules.inventoryScanner.fasterSync.exportFileNamePrefix' +) + function recordToExportDataLine(record: InventoryScannerRecord): string { // A - "RDC" const dataPieces = ['RDC'] @@ -111,32 +116,44 @@ function recordToExportDataLine(record: InventoryScannerRecord): string { function getExportFileName(): string { const rightNow = new Date() - const timezone = (rightNow.getTimezoneOffset() / 60) * 100 - - const timezoneString = - timezone > 0 - ? '-' + timezone.toString().padStart(4, '0') - : '+' + Math.abs(timezone).toString().padStart(4, '0') + /* + * Date + */ const dateString = rightNow.getFullYear().toString() + '-' + (rightNow.getMonth() + 1).toString().padStart(2, '0') + '-' + - rightNow.getDate().toString().padStart(2, '0') + - '_' + + rightNow.getDate().toString().padStart(2, '0') + + /* + * Time + */ + + const timeString = rightNow.getHours().toString().padStart(2, '0') + rightNow.getMinutes().toString().padStart(2, '0') + - rightNow.getSeconds().toString().padStart(2, '0') + - timezoneString - - const fileName = - getConfigProperty( - // eslint-disable-next-line no-secrets/no-secrets - 'modules.inventoryScanner.fasterSync.exportFileNamePrefix' - ) + - dateString + - '.csv' + rightNow.getSeconds().toString().padStart(2, '0') + + /* + * Timezone + */ + + const timezone = (rightNow.getTimezoneOffset() / 60) * 100 + + const timezoneString = + timezone > 0 + ? `-${timezone.toString().padStart(4, '0')}` + : `+${Math.abs(timezone).toString().padStart(4, '0')}` + + /* + * Full date string + */ + + const fullDateString = dateString + '_' + timeString + timezoneString + + const fileName = exportFileNamePrefix + fullDateString + '.csv' return fileName } diff --git a/modules/inventoryScanner/helpers/sync/worktech.d.ts b/modules/inventoryScanner/helpers/sync/worktech.syncHelpers.d.ts similarity index 100% rename from modules/inventoryScanner/helpers/sync/worktech.d.ts rename to modules/inventoryScanner/helpers/sync/worktech.syncHelpers.d.ts diff --git a/modules/inventoryScanner/helpers/sync/worktech.js b/modules/inventoryScanner/helpers/sync/worktech.syncHelpers.js similarity index 96% rename from modules/inventoryScanner/helpers/sync/worktech.js rename to modules/inventoryScanner/helpers/sync/worktech.syncHelpers.js index 77e1e54..164c7ab 100644 --- a/modules/inventoryScanner/helpers/sync/worktech.js +++ b/modules/inventoryScanner/helpers/sync/worktech.syncHelpers.js @@ -2,7 +2,7 @@ import { dateToString, dateToTimePeriodString } from '@cityssm/utils-datetime'; import { WorkTechAPI } from '@cityssm/worktech-api'; import camelcase from 'camelcase'; import Debug from 'debug'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; import { moduleName } from '../module.js'; import { updateMultipleScannerRecords } from './syncHelpers.js'; const debug = Debug(`faster-web-helper:${camelcase(moduleName)}:syncWorktech`); diff --git a/modules/inventoryScanner/helpers/sync/worktech.ts b/modules/inventoryScanner/helpers/sync/worktech.syncHelpers.ts similarity index 96% rename from modules/inventoryScanner/helpers/sync/worktech.ts rename to modules/inventoryScanner/helpers/sync/worktech.syncHelpers.ts index 574fce4..fd5f884 100644 --- a/modules/inventoryScanner/helpers/sync/worktech.ts +++ b/modules/inventoryScanner/helpers/sync/worktech.syncHelpers.ts @@ -6,7 +6,7 @@ import { import camelcase from 'camelcase' import Debug from 'debug' -import { getConfigProperty } from '../../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' import type { InventoryScannerRecord } from '../../types.js' import { moduleName } from '../module.js' diff --git a/modules/inventoryScanner/helpers/workOrders.js b/modules/inventoryScanner/helpers/workOrders.js index fed957e..9689e41 100644 --- a/modules/inventoryScanner/helpers/workOrders.js +++ b/modules/inventoryScanner/helpers/workOrders.js @@ -1,6 +1,6 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair /* eslint-disable no-secrets/no-secrets */ -import { getConfigProperty } from '../../../helpers/functions.config.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; export function getWorkOrderTypeFromWorkOrderNumber(workOrderNumber) { if (getConfigProperty('modules.inventoryScanner.workOrders.acceptWorkTech') && getConfigProperty('modules.inventoryScanner.workOrders.workTechRegex').test(workOrderNumber)) { diff --git a/modules/inventoryScanner/helpers/workOrders.ts b/modules/inventoryScanner/helpers/workOrders.ts index 6287ba7..4cf2e95 100644 --- a/modules/inventoryScanner/helpers/workOrders.ts +++ b/modules/inventoryScanner/helpers/workOrders.ts @@ -1,7 +1,7 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair /* eslint-disable no-secrets/no-secrets */ -import { getConfigProperty } from '../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' import type { InventoryScannerRecord, WorkOrderType } from '../types.js' export function getWorkOrderTypeFromWorkOrderNumber( diff --git a/modules/inventoryScanner/initialize.d.ts b/modules/inventoryScanner/initialize.d.ts deleted file mode 100644 index bda1874..0000000 --- a/modules/inventoryScanner/initialize.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ModuleInitializerOptions } from '../types.js'; -export default function initializeInventoryScannerModules(options: ModuleInitializerOptions): void; diff --git a/modules/inventoryScanner/initializeInventoryScanner.d.ts b/modules/inventoryScanner/initializeInventoryScanner.d.ts new file mode 100644 index 0000000..80cbe79 --- /dev/null +++ b/modules/inventoryScanner/initializeInventoryScanner.d.ts @@ -0,0 +1,3 @@ +import type express from 'express'; +export declare function initializeInventoryScannerTasks(): void; +export declare function initializeInventoryScannerAppHandlers(app: express.Application): void; diff --git a/modules/inventoryScanner/initialize.js b/modules/inventoryScanner/initializeInventoryScanner.js similarity index 85% rename from modules/inventoryScanner/initialize.js rename to modules/inventoryScanner/initializeInventoryScanner.js index 58d9747..61bfe99 100644 --- a/modules/inventoryScanner/initialize.js +++ b/modules/inventoryScanner/initializeInventoryScanner.js @@ -3,23 +3,16 @@ import { isLocal } from '@cityssm/is-private-network-address'; import camelCase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; -import { getConfigProperty } from '../../helpers/functions.config.js'; -import { hasFasterApi } from '../../helpers/helpers.faster.js'; +import { getConfigProperty } from '../../helpers/config.functions.js'; +import { hasFasterApi } from '../../helpers/fasterWeb.helpers.js'; import { initializeInventoryScannerDatabase } from './database/helpers.database.js'; import router from './handlers/router.js'; import scannerRouter from './handlers/router.scanner.js'; import { moduleName } from './helpers/module.js'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`); const urlPrefix = getConfigProperty('webServer.urlPrefix'); -export default function initializeInventoryScannerModules(options) { - debug(`Initializing "${moduleName}"...`); - /* - * Ensure the local database is available. - */ +export function initializeInventoryScannerTasks() { initializeInventoryScannerDatabase(); - /* - * Initialize tasks - */ const childProcesses = []; const itemValidationConfig = getConfigProperty('modules.inventoryScanner.items.validation'); if (itemValidationConfig !== undefined) { @@ -66,10 +59,20 @@ export default function initializeInventoryScannerModules(options) { if (hasFasterApi) { childProcesses.push(fork('./modules/inventoryScanner/tasks/outstandingItemRequests.js')); } + /* + * Set up exit hook + */ + exitHook(() => { + for (const validationProcess of childProcesses) { + validationProcess.kill(); + } + }); +} +export function initializeInventoryScannerAppHandlers(app) { /* * Initialize router for admin interface */ - options.app.use(`${urlPrefix}/modules/inventoryScanner`, (request, response, nextFunction) => { + app.use(`${urlPrefix}/modules/inventoryScanner`, (request, response, nextFunction) => { if ((request.session.user?.settings.inventoryScanner_hasAccess ?? 'false') === 'true') { nextFunction(); @@ -80,7 +83,7 @@ export default function initializeInventoryScannerModules(options) { /* * Initialize router for scanner */ - options.app.use(`${urlPrefix}/apps/inventoryScanner`, (request, response, nextFunction) => { + app.use(`${urlPrefix}/apps/inventoryScanner`, (request, response, nextFunction) => { const requestIp = request.ip ?? ''; const requestIpRegex = getConfigProperty('modules.inventoryScanner.scannerIpAddressRegex'); if (isLocal(requestIp) || requestIpRegex.test(requestIp)) { @@ -92,13 +95,4 @@ export default function initializeInventoryScannerModules(options) { requestIp }); }, scannerRouter); - /* - * Set up exit hook - */ - exitHook(() => { - for (const validationProcess of childProcesses) { - validationProcess.kill(); - } - }); - debug(`"${moduleName}" initialized.`); } diff --git a/modules/inventoryScanner/initialize.ts b/modules/inventoryScanner/initializeInventoryScanner.ts similarity index 87% rename from modules/inventoryScanner/initialize.ts rename to modules/inventoryScanner/initializeInventoryScanner.ts index e0c4507..e529da6 100644 --- a/modules/inventoryScanner/initialize.ts +++ b/modules/inventoryScanner/initializeInventoryScanner.ts @@ -4,10 +4,10 @@ import { isLocal } from '@cityssm/is-private-network-address' import camelCase from 'camelcase' import Debug from 'debug' import exitHook from 'exit-hook' +import type express from 'express' -import { getConfigProperty } from '../../helpers/functions.config.js' -import { hasFasterApi } from '../../helpers/helpers.faster.js' -import type { ModuleInitializerOptions } from '../types.js' +import { getConfigProperty } from '../../helpers/config.functions.js' +import { hasFasterApi } from '../../helpers/fasterWeb.helpers.js' import { initializeInventoryScannerDatabase } from './database/helpers.database.js' import router from './handlers/router.js' @@ -18,21 +18,10 @@ const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`) const urlPrefix = getConfigProperty('webServer.urlPrefix') -export default function initializeInventoryScannerModules( - options: ModuleInitializerOptions -): void { - debug(`Initializing "${moduleName}"...`) - - /* - * Ensure the local database is available. - */ +export function initializeInventoryScannerTasks(): void { initializeInventoryScannerDatabase() - /* - * Initialize tasks - */ - const childProcesses: ChildProcess[] = [] const itemValidationConfig = getConfigProperty( @@ -101,11 +90,25 @@ export default function initializeInventoryScannerModules( ) } + /* + * Set up exit hook + */ + + exitHook(() => { + for (const validationProcess of childProcesses) { + validationProcess.kill() + } + }) +} + +export function initializeInventoryScannerAppHandlers( + app: express.Application +): void { /* * Initialize router for admin interface */ - options.app.use( + app.use( `${urlPrefix}/modules/inventoryScanner`, (request, response, nextFunction) => { if ( @@ -125,7 +128,7 @@ export default function initializeInventoryScannerModules( * Initialize router for scanner */ - options.app.use( + app.use( `${urlPrefix}/apps/inventoryScanner`, (request, response, nextFunction) => { const requestIp = request.ip ?? '' @@ -146,16 +149,4 @@ export default function initializeInventoryScannerModules( }, scannerRouter ) - - /* - * Set up exit hook - */ - - exitHook(() => { - for (const validationProcess of childProcesses) { - validationProcess.kill() - } - }) - - debug(`"${moduleName}" initialized.`) } diff --git a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js index 0c95be6..3e826a6 100644 --- a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js +++ b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js @@ -3,7 +3,7 @@ import camelcase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; import { getItemValidationRecordsByItemNumber } from '../../database/getItemValidationRecords.js'; import getScannerRecords from '../../database/getScannerRecords.js'; import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js'; diff --git a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts index 69dadf6..b3146da 100644 --- a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts +++ b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts @@ -4,7 +4,7 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' import { getItemValidationRecordsByItemNumber } from '../../database/getItemValidationRecords.js' import getScannerRecords from '../../database/getScannerRecords.js' import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js' diff --git a/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.js b/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.js index ce42985..0aefe69 100644 --- a/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.js +++ b/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.js @@ -4,8 +4,8 @@ import camelCase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js'; import createOrUpdateItemValidation from '../../database/createOrUpdateItemValidation.js'; import deleteExpiredItemValidationRecords from '../../database/deleteExpiredItemValidationRecords.js'; import getMaxItemValidationRecordUpdateMillis from '../../database/getMaxItemValidationRecordUpdateMillis.js'; diff --git a/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.ts b/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.ts index b5fadf1..1d72723 100644 --- a/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.ts +++ b/modules/inventoryScanner/tasks/itemValidation/dynamicsGp.ts @@ -5,8 +5,8 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../../helpers/functions.config.js' -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js' import type { ConfigItemValidationDynamicsGP } from '../../configTypes.js' import createOrUpdateItemValidation from '../../database/createOrUpdateItemValidation.js' import deleteExpiredItemValidationRecords from '../../database/deleteExpiredItemValidationRecords.js' diff --git a/modules/inventoryScanner/tasks/outstandingItemRequests.js b/modules/inventoryScanner/tasks/outstandingItemRequests.js index 77ebf75..2d9cf07 100644 --- a/modules/inventoryScanner/tasks/outstandingItemRequests.js +++ b/modules/inventoryScanner/tasks/outstandingItemRequests.js @@ -4,7 +4,7 @@ import camelcase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../helpers/functions.config.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; import getSetting from '../database/getSetting.js'; import updateSetting from '../database/updateSetting.js'; import { moduleName } from '../helpers/module.js'; diff --git a/modules/inventoryScanner/tasks/outstandingItemRequests.ts b/modules/inventoryScanner/tasks/outstandingItemRequests.ts index 381d5c1..dc795ac 100644 --- a/modules/inventoryScanner/tasks/outstandingItemRequests.ts +++ b/modules/inventoryScanner/tasks/outstandingItemRequests.ts @@ -5,7 +5,7 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' import getSetting from '../database/getSetting.js' import updateSetting from '../database/updateSetting.js' import { moduleName } from '../helpers/module.js' diff --git a/modules/inventoryScanner/tasks/syncScannerRecords.js b/modules/inventoryScanner/tasks/syncScannerRecords.js index b01e9e5..6c19909 100644 --- a/modules/inventoryScanner/tasks/syncScannerRecords.js +++ b/modules/inventoryScanner/tasks/syncScannerRecords.js @@ -2,8 +2,8 @@ import camelcase from 'camelcase'; import Debug from 'debug'; import getScannerRecords from '../database/getScannerRecords.js'; import { moduleName } from '../helpers/module.js'; -import { syncScannerRecordsWithFaster } from '../helpers/sync/faster.js'; -import { syncScannerRecordsWithWorktech } from '../helpers/sync/worktech.js'; +import { syncScannerRecordsWithFaster } from '../helpers/sync/fasterWeb.syncHelpers.js'; +import { syncScannerRecordsWithWorktech } from '../helpers/sync/worktech.syncHelpers.js'; import { sortScannerRecordsByWorkOrderType } from '../helpers/workOrders.js'; export const taskName = 'Sync Scanner Records'; const debug = Debug(`faster-web-helper:${camelcase(moduleName)}:${camelcase(taskName)}`); diff --git a/modules/inventoryScanner/tasks/syncScannerRecords.ts b/modules/inventoryScanner/tasks/syncScannerRecords.ts index d6f308b..1aa0bd8 100644 --- a/modules/inventoryScanner/tasks/syncScannerRecords.ts +++ b/modules/inventoryScanner/tasks/syncScannerRecords.ts @@ -3,8 +3,8 @@ import Debug from 'debug' import getScannerRecords from '../database/getScannerRecords.js' import { moduleName } from '../helpers/module.js' -import { syncScannerRecordsWithFaster } from '../helpers/sync/faster.js' -import { syncScannerRecordsWithWorktech } from '../helpers/sync/worktech.js' +import { syncScannerRecordsWithFaster } from '../helpers/sync/fasterWeb.syncHelpers.js' +import { syncScannerRecordsWithWorktech } from '../helpers/sync/worktech.syncHelpers.js' import { sortScannerRecordsByWorkOrderType } from '../helpers/workOrders.js' export const taskName = 'Sync Scanner Records' diff --git a/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.js b/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.js index 3a4ed0e..35f6405 100644 --- a/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.js +++ b/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.js @@ -4,8 +4,8 @@ import camelcase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js'; import createOrUpdateWorkOrderValidation from '../../database/createOrUpdateWorkOrderValidation.js'; import deleteWorkOrderValidation from '../../database/deleteWorkOrderValidation.js'; import getMaxWorkOrderValidationRecordUpdateMillis from '../../database/getMaxWorkOrderValidationRecordUpdateMillis.js'; diff --git a/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.ts b/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.ts index 1a5512b..3618b07 100644 --- a/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.ts +++ b/modules/inventoryScanner/tasks/workOrderValidation/fasterApi.ts @@ -5,8 +5,8 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../../helpers/functions.config.js' -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js' import createOrUpdateWorkOrderValidation from '../../database/createOrUpdateWorkOrderValidation.js' import deleteWorkOrderValidation from '../../database/deleteWorkOrderValidation.js' import getMaxWorkOrderValidationRecordUpdateMillis from '../../database/getMaxWorkOrderValidationRecordUpdateMillis.js' diff --git a/modules/inventoryScanner/tasks/workOrderValidation/worktech.js b/modules/inventoryScanner/tasks/workOrderValidation/worktech.js index b09b0ad..4fb081a 100644 --- a/modules/inventoryScanner/tasks/workOrderValidation/worktech.js +++ b/modules/inventoryScanner/tasks/workOrderValidation/worktech.js @@ -6,8 +6,8 @@ import camelcase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../../helpers/functions.config.js'; -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js'; +import { getConfigProperty } from '../../../../helpers/config.functions.js'; +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js'; import createOrUpdateWorkOrderValidation from '../../database/createOrUpdateWorkOrderValidation.js'; import getMaxWorkOrderValidationRecordUpdateMillis from '../../database/getMaxWorkOrderValidationRecordUpdateMillis.js'; import getScannerRecords from '../../database/getScannerRecords.js'; diff --git a/modules/inventoryScanner/tasks/workOrderValidation/worktech.ts b/modules/inventoryScanner/tasks/workOrderValidation/worktech.ts index 20cc112..47a7d2e 100644 --- a/modules/inventoryScanner/tasks/workOrderValidation/worktech.ts +++ b/modules/inventoryScanner/tasks/workOrderValidation/worktech.ts @@ -8,8 +8,8 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../../helpers/functions.config.js' -import { getScheduledTaskMinutes } from '../../../../helpers/functions.task.js' +import { getConfigProperty } from '../../../../helpers/config.functions.js' +import { getScheduledTaskMinutes } from '../../../../helpers/tasks.functions.js' import createOrUpdateWorkOrderValidation from '../../database/createOrUpdateWorkOrderValidation.js' import getMaxWorkOrderValidationRecordUpdateMillis from '../../database/getMaxWorkOrderValidationRecordUpdateMillis.js' import getScannerRecords from '../../database/getScannerRecords.js' diff --git a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.d.ts b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.d.ts index 06d3245..85efb16 100644 --- a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.d.ts +++ b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.d.ts @@ -1,2 +1 @@ -import type { ModuleInitializerOptions } from '../types.js'; -export default function initializeTempFolderCleanupModule(options?: ModuleInitializerOptions): void; +export declare function initializeTempFolderCleanupTask(): void; diff --git a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.js b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.js index ed2f1e6..ff04d4c 100644 --- a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.js +++ b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.js @@ -3,11 +3,11 @@ import camelCase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/config.functions.js'; import { moduleName } from './helpers/moduleHelpers.js'; import runTempFolderCleanupTask, { taskName as tempFolderCleanupTaskName } from './tasks/tempFolderCleanupTask.js'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`); -export default function initializeTempFolderCleanupModule(options) { +export function initializeTempFolderCleanupTask() { debug(`Initializing "${moduleName}"...`); const tempFolderCleanupJob = schedule.scheduleJob(tempFolderCleanupTaskName, getConfigProperty('modules.tempFolderCleanup.schedule'), runTempFolderCleanupTask); const tempFolderCleanupFirstRunDate = new Date(tempFolderCleanupJob.nextInvocation().getTime()); diff --git a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.ts b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.ts index 403abc0..44d2af5 100644 --- a/modules/tempFolderCleanup/initializeTempFolderCleanupModule.ts +++ b/modules/tempFolderCleanup/initializeTempFolderCleanupModule.ts @@ -4,8 +4,7 @@ import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../helpers/functions.config.js' -import type { ModuleInitializerOptions } from '../types.js' +import { getConfigProperty } from '../../helpers/config.functions.js' import { moduleName } from './helpers/moduleHelpers.js' import runTempFolderCleanupTask, { @@ -14,9 +13,7 @@ import runTempFolderCleanupTask, { const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`) -export default function initializeTempFolderCleanupModule( - options?: ModuleInitializerOptions -): void { +export function initializeTempFolderCleanupTask(): void { debug(`Initializing "${moduleName}"...`) const tempFolderCleanupJob = schedule.scheduleJob( diff --git a/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.js b/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.js index d0c4b5d..331e643 100644 --- a/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.js +++ b/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.js @@ -5,8 +5,8 @@ import path from 'node:path'; import { daysToMillis } from '@cityssm/to-millis'; import camelCase from 'camelcase'; import Debug from 'debug'; -import { getConfigProperty } from '../../../helpers/functions.config.js'; -import { ensureTempFolderExists, tempFolderPath } from '../../../helpers/functions.filesystem.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; +import { ensureTempFolderExists, tempFolderPath } from '../../../helpers/filesystem.functions.js'; import { moduleName } from '../helpers/moduleHelpers.js'; export const taskName = 'Cleanup Database Task'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}`); diff --git a/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.ts b/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.ts index 1cc4f80..f74a7f2 100644 --- a/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.ts +++ b/modules/tempFolderCleanup/tasks/tempFolderCleanupTask.ts @@ -8,11 +8,11 @@ import { daysToMillis } from '@cityssm/to-millis' import camelCase from 'camelcase' import Debug from 'debug' -import { getConfigProperty } from '../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' import { ensureTempFolderExists, tempFolderPath -} from '../../../helpers/functions.filesystem.js' +} from '../../../helpers/filesystem.functions.js' import { moduleName } from '../helpers/moduleHelpers.js' export const taskName = 'Cleanup Database Task' diff --git a/modules/types.d.ts b/modules/types.d.ts deleted file mode 100644 index 05354e6..0000000 --- a/modules/types.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type express from 'express'; -export interface ModuleInitializerOptions { - app: express.Express; -} diff --git a/modules/types.ts b/modules/types.ts deleted file mode 100644 index fa13968..0000000 --- a/modules/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type express from 'express' - -export interface ModuleInitializerOptions { - app: express.Express -} \ No newline at end of file diff --git a/modules/worktechUpdate/initialize.d.ts b/modules/worktechUpdate/initialize.d.ts deleted file mode 100644 index c65b6bf..0000000 --- a/modules/worktechUpdate/initialize.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ModuleInitializerOptions } from '../types.js'; -export default function initializeWorktechUpdateModule(_options?: ModuleInitializerOptions): void; diff --git a/modules/worktechUpdate/initializeWorktechUpdate.d.ts b/modules/worktechUpdate/initializeWorktechUpdate.d.ts new file mode 100644 index 0000000..d45ce8c --- /dev/null +++ b/modules/worktechUpdate/initializeWorktechUpdate.d.ts @@ -0,0 +1 @@ +export declare function initializeWorktechUpdateTasks(): void; diff --git a/modules/worktechUpdate/initialize.js b/modules/worktechUpdate/initializeWorktechUpdate.js similarity index 85% rename from modules/worktechUpdate/initialize.js rename to modules/worktechUpdate/initializeWorktechUpdate.js index 1b6bdfa..e67a0aa 100644 --- a/modules/worktechUpdate/initialize.js +++ b/modules/worktechUpdate/initializeWorktechUpdate.js @@ -2,11 +2,11 @@ import { fork } from 'node:child_process'; import camelCase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; -import { getConfigProperty } from '../../helpers/functions.config.js'; -import { hasFasterApi } from '../../helpers/helpers.faster.js'; +import { getConfigProperty } from '../../helpers/config.functions.js'; +import { hasFasterApi } from '../../helpers/fasterWeb.helpers.js'; import { moduleName } from './helpers/moduleHelpers.js'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`); -export default function initializeWorktechUpdateModule(_options) { +export function initializeWorktechUpdateTasks() { debug(`Initializing "${moduleName}"...`); if (getConfigProperty('worktech') === undefined) { debug('WorkTech configuration is not set up. Skipping module initialization.'); diff --git a/modules/worktechUpdate/initialize.ts b/modules/worktechUpdate/initializeWorktechUpdate.ts similarity index 79% rename from modules/worktechUpdate/initialize.ts rename to modules/worktechUpdate/initializeWorktechUpdate.ts index c355751..0368251 100644 --- a/modules/worktechUpdate/initialize.ts +++ b/modules/worktechUpdate/initializeWorktechUpdate.ts @@ -4,17 +4,14 @@ import camelCase from 'camelcase' import Debug from 'debug' import exitHook from 'exit-hook' -import { getConfigProperty } from '../../helpers/functions.config.js' -import { hasFasterApi } from '../../helpers/helpers.faster.js' -import type { ModuleInitializerOptions } from '../types.js' +import { getConfigProperty } from '../../helpers/config.functions.js' +import { hasFasterApi } from '../../helpers/fasterWeb.helpers.js' import { moduleName } from './helpers/moduleHelpers.js' const debug = Debug(`faster-web-helper:${camelCase(moduleName)}`) -export default function initializeWorktechUpdateModule( - _options?: ModuleInitializerOptions -): void { +export function initializeWorktechUpdateTasks(): void { debug(`Initializing "${moduleName}"...`) if (getConfigProperty('worktech') === undefined) { diff --git a/modules/worktechUpdate/tasks/activeEquipmentTask.js b/modules/worktechUpdate/tasks/activeEquipmentTask.js index df023d1..2fab873 100644 --- a/modules/worktechUpdate/tasks/activeEquipmentTask.js +++ b/modules/worktechUpdate/tasks/activeEquipmentTask.js @@ -4,20 +4,25 @@ import camelCase from 'camelcase'; import Debug from 'debug'; import exitHook from 'exit-hook'; import schedule from 'node-schedule'; -import { getConfigProperty } from '../../../helpers/functions.config.js'; -import { getScheduledTaskMinutes } from '../../../helpers/functions.task.js'; +import { getConfigProperty } from '../../../helpers/config.functions.js'; +import { getScheduledTaskMinutes } from '../../../helpers/tasks.functions.js'; import { moduleName } from '../helpers/moduleHelpers.js'; export const taskName = 'Active Equipment Task'; const debug = Debug(`faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}`); const fasterWebConfig = getConfigProperty('fasterWeb'); -const worktech = new WorkTechAPI(getConfigProperty('worktech')); +const worktechConfig = getConfigProperty('worktech'); async function runActiveEquipmentTask() { if (fasterWebConfig.apiUserName === undefined || fasterWebConfig.apiPassword === undefined) { - debug('Missing API user configuration.'); + debug('Missing FASTER API user configuration.'); + return; + } + if (worktechConfig === undefined) { + debug('Missing Worktech configuration.'); return; } debug(`Running "${taskName}"...`); + const worktech = new WorkTechAPI(worktechConfig); /* * Call FASTER API */ diff --git a/modules/worktechUpdate/tasks/activeEquipmentTask.ts b/modules/worktechUpdate/tasks/activeEquipmentTask.ts index c7a8a34..fdb65d9 100644 --- a/modules/worktechUpdate/tasks/activeEquipmentTask.ts +++ b/modules/worktechUpdate/tasks/activeEquipmentTask.ts @@ -1,40 +1,47 @@ import { FasterApi } from '@cityssm/faster-api' -import type { mssqlTypes } from '@cityssm/mssql-multi-pool' import { WorkTechAPI } from '@cityssm/worktech-api' import camelCase from 'camelcase' import Debug from 'debug' import exitHook from 'exit-hook' import schedule from 'node-schedule' -import { getConfigProperty } from '../../../helpers/functions.config.js' -import { getScheduledTaskMinutes } from '../../../helpers/functions.task.js' +import { getConfigProperty } from '../../../helpers/config.functions.js' +import { getScheduledTaskMinutes } from '../../../helpers/tasks.functions.js' import { moduleName } from '../helpers/moduleHelpers.js' export const taskName = 'Active Equipment Task' -const debug = Debug(`faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}`) +const debug = Debug( + `faster-web-helper:${camelCase(moduleName)}:${camelCase(taskName)}` +) const fasterWebConfig = getConfigProperty('fasterWeb') - -const worktech = new WorkTechAPI(getConfigProperty('worktech') as mssqlTypes.config) +const worktechConfig = getConfigProperty('worktech') async function runActiveEquipmentTask(): Promise { - if ( fasterWebConfig.apiUserName === undefined || fasterWebConfig.apiPassword === undefined ) { - debug('Missing API user configuration.') + debug('Missing FASTER API user configuration.') + return + } + + if (worktechConfig === undefined) { + debug('Missing Worktech configuration.') return } debug(`Running "${taskName}"...`) + const worktech = new WorkTechAPI(worktechConfig) + /* * Call FASTER API */ - const fasterApi = new FasterApi(fasterWebConfig.tenantOrBaseUrl, + const fasterApi = new FasterApi( + fasterWebConfig.tenantOrBaseUrl, fasterWebConfig.apiUserName, fasterWebConfig.apiPassword ) @@ -49,13 +56,15 @@ async function runActiveEquipmentTask(): Promise { debug(`Syncing ${fasterAssetsResponse.response.results.length} asset(s)...`) for (const fasterAsset of fasterAssetsResponse.response.results) { - const worktechEquipment = await worktech.getEquipmentByEquipmentId(fasterAsset.assetNumber) + const worktechEquipment = await worktech.getEquipmentByEquipmentId( + fasterAsset.assetNumber + ) if (worktechEquipment === undefined) { // add equipment } } - + debug(`Finished "${taskName}".`) } diff --git a/package-lock.json b/package-lock.json index fe81b82..286fbaa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@cityssm/bulma-webapp-js": "^1.5.0", "@cityssm/configurator": "^0.1.0", "@cityssm/dynamics-gp": "^1.0.5", - "@cityssm/faster-api": "github:cityssm/node-faster-api#v1.3.0", "@cityssm/faster-report-exporter": "^0.3.2", "@cityssm/faster-report-parser": "^0.3.0", "@cityssm/faster-url-builder": "^1.0.0", @@ -23,12 +22,12 @@ "@cityssm/mssql-multi-pool": "^4.1.0", "@cityssm/to-millis": "^1.0.0", "@cityssm/utils-datetime": "^1.3.0", - "@cityssm/worktech-api": "^0.5.0", + "@cityssm/worktech-api": "^0.7.0", "@fortawesome/fontawesome-free": "^6.7.2", "@types/nodemailer": "^6.4.17", "basic-ftp": "^5.0.5", "better-sqlite3": "^11.7.0", - "bulma": "^1.0.2", + "bulma": "^1.0.3", "camelcase": "^8.0.0", "cookie-parser": "^1.4.7", "debug": "^4.4.0", @@ -46,12 +45,12 @@ "@types/debug": "^4.1.12", "@types/express": "^5.0.0", "@types/express-session": "^1.18.1", - "@types/node": "^22.10.2", + "@types/node": "^22.10.3", "@types/node-schedule": "^2.1.7", "@types/session-file-store": "^1.2.5", "cypress": "^13.17.0", "cypress-axe": "^1.5.0", - "eslint-config-cityssm": "^18.1.2", + "eslint-config-cityssm": "^18.3.0", "nodemon": "^3.1.9", "prettier-config-cityssm": "^1.0.0" }, @@ -2324,13 +2323,15 @@ } }, "node_modules/@cityssm/worktech-api": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/@cityssm/worktech-api/-/worktech-api-0.5.0.tgz", - "integrity": "sha512-QQlovngVv9NR65AjkIoewVyt9+97SDnL03DcfpWftyZYxI4m37pz90cEwV7M+pbDelE0aF6e4IrNy8g9lYXkWg==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cityssm/worktech-api/-/worktech-api-0.7.0.tgz", + "integrity": "sha512-Ux0kHCYkOjG6wUGdWSgvv7JTAVOcQl0fE4kVM/ScZKGTr2m9N0HCSud30D7x69WF3dz5tPkh7P9WxxauTqVv+g==", "license": "MIT", "dependencies": { "@cityssm/mssql-multi-pool": "^4.1.0", + "@cityssm/to-millis": "^1.0.0", "@cityssm/utils-datetime": "^1.3.0", + "debug": "^4.4.0", "node-cache": "^5.1.2" } }, @@ -3580,9 +3581,9 @@ } }, "node_modules/@types/node": { - "version": "22.10.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz", - "integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==", + "version": "22.10.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.3.tgz", + "integrity": "sha512-DifAyw4BkrufCILvD3ucnuN8eydUfc/C1GlyrnI+LK6543w5/L3VeVgf05o3B4fqSXP1dKYLOZsKfutpxPzZrw==", "license": "MIT", "dependencies": { "undici-types": "~6.20.0" @@ -3706,17 +3707,17 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.18.2.tgz", - "integrity": "sha512-adig4SzPLjeQ0Tm+jvsozSGiCliI2ajeURDGHjZ2llnA+A67HihCQ+a3amtPhUakd1GlwHxSRvzOZktbEvhPPg==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.19.0.tgz", + "integrity": "sha512-NggSaEZCdSrFddbctrVjkVZvFC6KGfKfNK0CU7mNK/iKHGKbzT4Wmgm08dKpcZECBu9f5FypndoMyRHkdqfT1Q==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.18.2", - "@typescript-eslint/type-utils": "8.18.2", - "@typescript-eslint/utils": "8.18.2", - "@typescript-eslint/visitor-keys": "8.18.2", + "@typescript-eslint/scope-manager": "8.19.0", + "@typescript-eslint/type-utils": "8.19.0", + "@typescript-eslint/utils": "8.19.0", + "@typescript-eslint/visitor-keys": "8.19.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -3736,16 +3737,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.18.2.tgz", - "integrity": "sha512-y7tcq4StgxQD4mDr9+Jb26dZ+HTZ/SkfqpXSiqeUXZHxOUyjWDKsmwKhJ0/tApR08DgOhrFAoAhyB80/p3ViuA==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.19.0.tgz", + "integrity": "sha512-6M8taKyOETY1TKHp0x8ndycipTVgmp4xtg5QpEZzXxDhNvvHOJi5rLRkLr8SK3jTgD5l4fTlvBiRdfsuWydxBw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.18.2", - "@typescript-eslint/types": "8.18.2", - "@typescript-eslint/typescript-estree": "8.18.2", - "@typescript-eslint/visitor-keys": "8.18.2", + "@typescript-eslint/scope-manager": "8.19.0", + "@typescript-eslint/types": "8.19.0", + "@typescript-eslint/typescript-estree": "8.19.0", + "@typescript-eslint/visitor-keys": "8.19.0", "debug": "^4.3.4" }, "engines": { @@ -3761,14 +3762,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.18.2.tgz", - "integrity": "sha512-YJFSfbd0CJjy14r/EvWapYgV4R5CHzptssoag2M7y3Ra7XNta6GPAJPPP5KGB9j14viYXyrzRO5GkX7CRfo8/g==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.19.0.tgz", + "integrity": "sha512-hkoJiKQS3GQ13TSMEiuNmSCvhz7ujyqD1x3ShbaETATHrck+9RaDdUbt+osXaUuns9OFwrDTTrjtwsU8gJyyRA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.18.2", - "@typescript-eslint/visitor-keys": "8.18.2" + "@typescript-eslint/types": "8.19.0", + "@typescript-eslint/visitor-keys": "8.19.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3779,14 +3780,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.18.2.tgz", - "integrity": "sha512-AB/Wr1Lz31bzHfGm/jgbFR0VB0SML/hd2P1yxzKDM48YmP7vbyJNHRExUE/wZsQj2wUCvbWH8poNHFuxLqCTnA==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.19.0.tgz", + "integrity": "sha512-TZs0I0OSbd5Aza4qAMpp1cdCYVnER94IziudE3JU328YUHgWu9gwiwhag+fuLeJ2LkWLXI+F/182TbG+JaBdTg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "8.18.2", - "@typescript-eslint/utils": "8.18.2", + "@typescript-eslint/typescript-estree": "8.19.0", + "@typescript-eslint/utils": "8.19.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -3803,9 +3804,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.18.2.tgz", - "integrity": "sha512-Z/zblEPp8cIvmEn6+tPDIHUbRu/0z5lqZ+NvolL5SvXWT5rQy7+Nch83M0++XzO0XrWRFWECgOAyE8bsJTl1GQ==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.19.0.tgz", + "integrity": "sha512-8XQ4Ss7G9WX8oaYvD4OOLCjIQYgRQxO+qCiR2V2s2GxI9AUpo7riNwo6jDhKtTcaJjT8PY54j2Yb33kWtSJsmA==", "dev": true, "license": "MIT", "engines": { @@ -3817,14 +3818,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.18.2.tgz", - "integrity": "sha512-WXAVt595HjpmlfH4crSdM/1bcsqh+1weFRWIa9XMTx/XHZ9TCKMcr725tLYqWOgzKdeDrqVHxFotrvWcEsk2Tg==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.19.0.tgz", + "integrity": "sha512-WW9PpDaLIFW9LCbucMSdYUuGeFUz1OkWYS/5fwZwTA+l2RwlWFdJvReQqMUMBw4yJWJOfqd7An9uwut2Oj8sLw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.18.2", - "@typescript-eslint/visitor-keys": "8.18.2", + "@typescript-eslint/types": "8.19.0", + "@typescript-eslint/visitor-keys": "8.19.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -3870,16 +3871,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.18.2.tgz", - "integrity": "sha512-Cr4A0H7DtVIPkauj4sTSXVl+VBWewE9/o40KcF3TV9aqDEOWoXF3/+oRXNby3DYzZeCATvbdksYsGZzplwnK/Q==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.19.0.tgz", + "integrity": "sha512-PTBG+0oEMPH9jCZlfg07LCB2nYI0I317yyvXGfxnvGvw4SHIOuRnQ3kadyyXY6tGdChusIHIbM5zfIbp4M6tCg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.18.2", - "@typescript-eslint/types": "8.18.2", - "@typescript-eslint/typescript-estree": "8.18.2" + "@typescript-eslint/scope-manager": "8.19.0", + "@typescript-eslint/types": "8.19.0", + "@typescript-eslint/typescript-estree": "8.19.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3894,13 +3895,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.18.2.tgz", - "integrity": "sha512-zORcwn4C3trOWiCqFQP1x6G3xTRyZ1LYydnj51cRnJ6hxBlr/cKPckk+PKPUw/fXmvfKTcw7bwY3w9izgx5jZw==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.19.0.tgz", + "integrity": "sha512-mCFtBbFBJDCNCWUl5y6sZSCHXw1DEFEk3c/M3nRK2a4XUB8StGFtmcEMizdjKuBzB6e/smJAAWYug3VrdLMr1w==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.18.2", + "@typescript-eslint/types": "8.19.0", "eslint-visitor-keys": "^4.2.0" }, "engines": { @@ -4858,9 +4859,9 @@ } }, "node_modules/bulma": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bulma/-/bulma-1.0.2.tgz", - "integrity": "sha512-D7GnDuF6seb6HkcnRMM9E739QpEY9chDzzeFrHMyEns/EXyDJuQ0XA0KxbBl/B2NTsKSoDomW61jFGFaAxhK5A==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/bulma/-/bulma-1.0.3.tgz", + "integrity": "sha512-9eVXBrXwlU337XUXBjIIq7i88A+tRbJYAjXQjT/21lwam+5tpvKF0R7dCesre9N+HV9c6pzCNEPKrtgvBBes2g==", "license": "MIT" }, "node_modules/bytes": { @@ -6363,9 +6364,9 @@ } }, "node_modules/eslint-config-cityssm": { - "version": "18.1.2", - "resolved": "https://registry.npmjs.org/eslint-config-cityssm/-/eslint-config-cityssm-18.1.2.tgz", - "integrity": "sha512-v76ZCVUFnIRHdQvDJ6m64IXqAA87BwuwwkaCHybgzOHkNiWvIkpGhI7vwKHuudPlMn0P6/CRhugWJN/si31rkA==", + "version": "18.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-cityssm/-/eslint-config-cityssm-18.3.0.tgz", + "integrity": "sha512-1ATCjCoP9ZTLxkxUdxn3yb1xNmGGGdxvgqQ8BP+qKvXEwLRTr7CQQ6frnb49YbWvTzi8HhqLIPqxfb9XymSGAg==", "dev": true, "license": "Unlicense", "dependencies": { @@ -6373,7 +6374,7 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1", "@eslint/js": "9.17.0", "eslint": "9.17.0", - "eslint-config-love": "^112.0.0", + "eslint-config-love": "^114.0.0", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jsdoc": "^50.6.1", "eslint-plugin-n": "^17.15.1", @@ -6386,13 +6387,13 @@ "eslint-plugin-unicorn": "^56.0.1", "eslint-plugin-woke": "github:cityssm/eslint-plugin-woke", "eslint-plugin-write-good-comments": "^0.2.0", - "typescript-eslint": "^8.18.1" + "typescript-eslint": "^8.19.0" } }, "node_modules/eslint-config-love": { - "version": "112.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-love/-/eslint-config-love-112.0.0.tgz", - "integrity": "sha512-fips6u8TIzw8LO9z0qF+lu2pjVm5zsvBh0hkCxZrBUD/OxOSqLYit2vW/u80v2v3lQfFpg5igO9qon+wTDaEcA==", + "version": "114.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-love/-/eslint-config-love-114.0.0.tgz", + "integrity": "sha512-PScXVLQge1nucu1GZUGmYaGNZrSlI4d09W4a16GtZA2Ht/Hx2V3f7znBRiAFzqJ4yAcWuDAmXiyrbMmNYEeslA==", "dev": true, "funding": [ { @@ -12393,15 +12394,15 @@ } }, "node_modules/typescript-eslint": { - "version": "8.18.2", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.18.2.tgz", - "integrity": "sha512-KuXezG6jHkvC3MvizeXgupZzaG5wjhU3yE8E7e6viOvAvD9xAWYp8/vy0WULTGe9DYDWcQu7aW03YIV3mSitrQ==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.19.0.tgz", + "integrity": "sha512-Ni8sUkVWYK4KAcTtPjQ/UTiRk6jcsuDhPpxULapUDi8A/l8TSBk+t1GtJA1RsCzIJg0q6+J7bf35AwQigENWRQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.18.2", - "@typescript-eslint/parser": "8.18.2", - "@typescript-eslint/utils": "8.18.2" + "@typescript-eslint/eslint-plugin": "8.19.0", + "@typescript-eslint/parser": "8.19.0", + "@typescript-eslint/utils": "8.19.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index c028c4e..f6c39e6 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "node": ">=18.0.0" }, "scripts": { - "start": "cross-env NODE_ENV=production node ./app.js", - "dev": "cross-env NODE_ENV=dev DEBUG=faster-web-helper:*,faster-report-parser:* nodemon ./app.js", + "start": "cross-env NODE_ENV=production node ./index.js", + "dev": "cross-env NODE_ENV=dev DEBUG=faster-web-helper:*,faster-report-parser:* nodemon ./index.js", "cy:open": "cypress open --config-file cypress.config.ts", "cy:run": "cypress run --config-file cypress.config.ts", "test": "cross-env NODE_ENV=dev DEBUG=faster-web-helper:*,faster-report-parser:* node --test", @@ -36,12 +36,12 @@ "@cityssm/mssql-multi-pool": "^4.1.0", "@cityssm/to-millis": "^1.0.0", "@cityssm/utils-datetime": "^1.3.0", - "@cityssm/worktech-api": "^0.5.0", + "@cityssm/worktech-api": "^0.7.0", "@fortawesome/fontawesome-free": "^6.7.2", "@types/nodemailer": "^6.4.17", "basic-ftp": "^5.0.5", "better-sqlite3": "^11.7.0", - "bulma": "^1.0.2", + "bulma": "^1.0.3", "camelcase": "^8.0.0", "cookie-parser": "^1.4.7", "debug": "^4.4.0", @@ -59,12 +59,12 @@ "@types/debug": "^4.1.12", "@types/express": "^5.0.0", "@types/express-session": "^1.18.1", - "@types/node": "^22.10.2", + "@types/node": "^22.10.3", "@types/node-schedule": "^2.1.7", "@types/session-file-store": "^1.2.5", "cypress": "^13.17.0", "cypress-axe": "^1.5.0", - "eslint-config-cityssm": "^18.1.2", + "eslint-config-cityssm": "^18.3.0", "nodemon": "^3.1.9", "prettier-config-cityssm": "^1.0.0" }, diff --git a/routers/login.js b/routers/login.js index b7183e4..eb782bd 100644 --- a/routers/login.js +++ b/routers/login.js @@ -3,8 +3,8 @@ import { Router } from 'express'; import createUser from '../database/createUser.js'; import { getUserByUserName } from '../database/getUser.js'; -import { getConfigProperty } from '../helpers/functions.config.js'; -import { authenticate } from '../helpers/functions.user.js'; +import { getConfigProperty } from '../helpers/config.functions.js'; +import { authenticate } from '../helpers/users.functions.js'; export const router = Router(); function getSafeRedirectURL(possibleRedirectURL = '') { const urlPrefix = getConfigProperty('webServer.urlPrefix'); diff --git a/routers/login.ts b/routers/login.ts index 39a2bc8..b9009a4 100644 --- a/routers/login.ts +++ b/routers/login.ts @@ -5,8 +5,8 @@ import { Router } from 'express' import createUser from '../database/createUser.js' import { getUserByUserName } from '../database/getUser.js' -import { getConfigProperty } from '../helpers/functions.config.js' -import { authenticate } from '../helpers/functions.user.js' +import { getConfigProperty } from '../helpers/config.functions.js' +import { authenticate } from '../helpers/users.functions.js' export const router = Router() diff --git a/types/applicationTypes.d.ts b/types/applicationTypes.d.ts new file mode 100644 index 0000000..9ac449a --- /dev/null +++ b/types/applicationTypes.d.ts @@ -0,0 +1,5 @@ +export interface WorkerMessage { + messageType: string; + timeMillis: number; + pid: number; +} diff --git a/types/applicationTypes.js b/types/applicationTypes.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/types/applicationTypes.js @@ -0,0 +1 @@ +export {}; diff --git a/types/applicationTypes.ts b/types/applicationTypes.ts new file mode 100644 index 0000000..608b481 --- /dev/null +++ b/types/applicationTypes.ts @@ -0,0 +1,5 @@ +export interface WorkerMessage { + messageType: string + timeMillis: number + pid: number +} \ No newline at end of file