Compare commits
12 Commits
e9b0101095
...
v0.0.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b515c608f | |||
| d8869b103b | |||
| 1dba774abc | |||
| 505d7cea5d | |||
| 1ff5e5032f | |||
| 5fa70da90c | |||
| 0459cd788a | |||
| 7d7d991122 | |||
| 2721bb2a3b | |||
| 4424c742d2 | |||
| 6d8499bfb8 | |||
| 9edafc9d28 |
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,5 +1,46 @@
|
|||||||
# All Changes to LST can be found below.
|
# All Changes to LST can be found below.
|
||||||
|
|
||||||
|
## [0.0.2-alpha.10](https://git.tuffraid.net/cowch/lst_v3/compare/v0.0.2-alpha.9...v0.0.2-alpha.10) (2026-05-08)
|
||||||
|
|
||||||
|
|
||||||
|
### 🌟 Enhancements
|
||||||
|
|
||||||
|
* **analytics:** added in backend anaylitics ([9edafc9](https://git.tuffraid.net/cowch/lst_v3/commits/9edafc9d2810f339d197c10dfc6a037b3352d81f))
|
||||||
|
* **api hits:** added in api hits for monitoring ([2721bb2](https://git.tuffraid.net/cowch/lst_v3/commits/2721bb2a3bf1f829591d26a0716f74c4f7fc0c79))
|
||||||
|
* **scanner:** added in lanechecks ([87803ee](https://git.tuffraid.net/cowch/lst_v3/commits/87803eed43069b73de3f66e6524bb45da9c46334))
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug fixes
|
||||||
|
|
||||||
|
* **scan user:** typo ([d8869b1](https://git.tuffraid.net/cowch/lst_v3/commits/d8869b103b80e4208b3928a370a9524ef33d25cd))
|
||||||
|
* **schema:** typo in add_date ([7d7d991](https://git.tuffraid.net/cowch/lst_v3/commits/7d7d9911223905d6767b87d2471b6607a90f1ea7))
|
||||||
|
* **spelling:** corrected the spelling on the file ([0459cd7](https://git.tuffraid.net/cowch/lst_v3/commits/0459cd788aaad6ac54a67e23f798ce5e5a437394))
|
||||||
|
|
||||||
|
|
||||||
|
### 📝 Chore
|
||||||
|
|
||||||
|
* **file:** name changes.. spelled wrong ([5fa70da](https://git.tuffraid.net/cowch/lst_v3/commits/5fa70da90ca290ee45088e9c8eb06ba48a6677af))
|
||||||
|
* **server:** removed a console log that shouldnt be there ([1dba774](https://git.tuffraid.net/cowch/lst_v3/commits/1dba774abc54bf20850c3f26d49926e86d59712d))
|
||||||
|
|
||||||
|
|
||||||
|
### 🛠️ Code Refactor
|
||||||
|
|
||||||
|
* **analyitics:** finished analyitics as a base ([4424c74](https://git.tuffraid.net/cowch/lst_v3/commits/4424c742d24dc230b2bc1782e33535184c378cf0))
|
||||||
|
* **scan:** bump in build and style update ([505d7ce](https://git.tuffraid.net/cowch/lst_v3/commits/505d7cea5d2f52fc4a3ec1edff1878be703c4034))
|
||||||
|
* **scanner:** added toasts in to make it look better ([edb3668](https://git.tuffraid.net/cowch/lst_v3/commits/edb366854825f4c24ab5d77cf88759465d067f00))
|
||||||
|
|
||||||
|
|
||||||
|
### 📝 Testing Code
|
||||||
|
|
||||||
|
* **scanusers:** added in scan users as test ([1ff5e50](https://git.tuffraid.net/cowch/lst_v3/commits/1ff5e5032f9c8bf81f972dc99d6c86ba8d3936c6))
|
||||||
|
|
||||||
|
|
||||||
|
### 📈 Project changes
|
||||||
|
|
||||||
|
* **template:** bug in getting the template to work correctly ([e9b0101](https://git.tuffraid.net/cowch/lst_v3/commits/e9b01010954624aed738cd6e4b82fccbba195cc4))
|
||||||
|
* **templates:** added in templates for the repo to make it more easy to manage and add in new ideas ([ca885fb](https://git.tuffraid.net/cowch/lst_v3/commits/ca885fb01a3c8bc22694c2e05269c43fcd4de70e))
|
||||||
|
* **templates:** force useage ([6d8499b](https://git.tuffraid.net/cowch/lst_v3/commits/6d8499bfb85f7b9131b1ec7b31a17c4256d0f0cf))
|
||||||
|
|
||||||
## [0.0.2-alpha.9](https://git.tuffraid.net/cowch/lst_v3/compare/v0.0.2-alpha.8...v0.0.2-alpha.9) (2026-05-06)
|
## [0.0.2-alpha.9](https://git.tuffraid.net/cowch/lst_v3/compare/v0.0.2-alpha.8...v0.0.2-alpha.9) (2026-05-06)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import build from "./admin.build.js";
|
import build from "./admin.build.js";
|
||||||
import update from "./admin.updateServer.js";
|
import update from "./admin.updateServer.js";
|
||||||
|
|
||||||
export const setupAdminRoutes = (baseUrl: string, app: Express) => {
|
export const setupAdminRoutes = (baseUrl: string, app: Express) => {
|
||||||
//stats will be like this as we dont need to change this
|
//stats will be like this as we dont need to change this
|
||||||
app.use(`${baseUrl}/api/admin/build`, requireAuth, build);
|
app.use(`${baseUrl}/api/admin/build`, requireAuth, routeHitMiddleware, build);
|
||||||
app.use(`${baseUrl}/api/admin/build`, requireAuth, update);
|
app.use(
|
||||||
|
`${baseUrl}/api/admin/build`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
update,
|
||||||
|
);
|
||||||
|
|
||||||
// all other system should be under /api/system/*
|
// all other system should be under /api/system/*
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
|||||||
import { toNodeHandler } from "better-auth/node";
|
import { toNodeHandler } from "better-auth/node";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
|
import { umamiConfig } from "./configs/umami.config.js";
|
||||||
import { createLogger } from "./logger/logger.controller.js";
|
import { createLogger } from "./logger/logger.controller.js";
|
||||||
import { setupRoutes } from "./routeHandler.routes.js";
|
import { setupRoutes } from "./routeHandler.routes.js";
|
||||||
import { auth } from "./utils/auth.utils.js";
|
import { auth } from "./utils/auth.utils.js";
|
||||||
@@ -33,6 +34,22 @@ const createApp = async () => {
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
setupRoutes(baseUrl, app);
|
setupRoutes(baseUrl, app);
|
||||||
|
|
||||||
|
app.get(`${baseUrl}/api/lst-config.js`, (_, res) => {
|
||||||
|
res.type("application/javascript");
|
||||||
|
res.setHeader("Cache-Control", "no-store");
|
||||||
|
|
||||||
|
res.send(`
|
||||||
|
window.LST_CONFIG = {
|
||||||
|
appName: ${JSON.stringify(umamiConfig.appName ?? "LST")},
|
||||||
|
site: ${JSON.stringify(umamiConfig.site ?? "unknown")},
|
||||||
|
server: ${JSON.stringify(umamiConfig.server ?? "unknown")},
|
||||||
|
appVersion: ${JSON.stringify(umamiConfig.appVersion ?? "dev")},
|
||||||
|
umamiHost: ${JSON.stringify(umamiConfig.umamiHost ?? "")},
|
||||||
|
umamiWebsiteId: ${JSON.stringify(umamiConfig.umamiWebsiteId ?? "")}
|
||||||
|
};
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
`${baseUrl}/app`,
|
`${baseUrl}/app`,
|
||||||
express.static(join(__dirname, "../frontend/dist")),
|
express.static(join(__dirname, "../frontend/dist")),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import login from "./login.route.js";
|
import login from "./login.route.js";
|
||||||
import register from "./register.route.js";
|
import register from "./register.route.js";
|
||||||
|
|
||||||
export const setupAuthRoutes = (baseUrl: string, app: Express) => {
|
export const setupAuthRoutes = (baseUrl: string, app: Express) => {
|
||||||
//setup all the routes
|
//setup all the routes
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
app.use(`${baseUrl}/api/authentication/login`, login);
|
app.use(`${baseUrl}/api/authentication/login`, login);
|
||||||
app.use(`${baseUrl}/api/authentication/register`, register);
|
app.use(`${baseUrl}/api/authentication/register`, register);
|
||||||
};
|
};
|
||||||
|
|||||||
21
backend/configs/umami.config.ts
Normal file
21
backend/configs/umami.config.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export type UmamiRuntimeConfig = {
|
||||||
|
appName: string;
|
||||||
|
site: string;
|
||||||
|
server: string;
|
||||||
|
appVersion: string;
|
||||||
|
umamiHost: string;
|
||||||
|
umamiWebsiteId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const umamiConfig: UmamiRuntimeConfig = {
|
||||||
|
appName: process.env.APP_NAME ?? "LST",
|
||||||
|
site: process.env.URL ?? "unknown",
|
||||||
|
server: process.env.PROD_PLANT_TOKEN ?? "unknown", // could also be server name based on our setup.
|
||||||
|
appVersion: process.env.NODE_ENV ?? "dev",
|
||||||
|
umamiHost: process.env.UMAMI_HOST ?? "",
|
||||||
|
umamiWebsiteId: process.env.UMAMI_WEBSITE_ID ?? "",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function isUmamiEnabled() {
|
||||||
|
return Boolean(umamiConfig.umamiHost && umamiConfig.umamiWebsiteId);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||||
import { datamartData } from "./datamartData.utlis.js";
|
import { datamartData } from "./datamartData.utlis.js";
|
||||||
import runQuery from "./getDatamart.route.js";
|
import runQuery from "./getDatamart.route.js";
|
||||||
@@ -30,7 +30,7 @@ export const setupDatamartRoutes = (baseUrl: string, app: Express) => {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
//setup all the routes
|
//setup all the routes
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
app.use(`${baseUrl}/api/datamart`, runQuery);
|
app.use(`${baseUrl}/api/datamart`, runQuery);
|
||||||
|
|
||||||
// just sending a get on datamart will return all the queries that we can call.
|
// just sending a get on datamart will return all the queries that we can call.
|
||||||
|
|||||||
21
backend/db/schema/analytics.schema.ts
Normal file
21
backend/db/schema/analytics.schema.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { integer, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
|
export const analytics = pgTable("analytics", {
|
||||||
|
id: uuid("id").defaultRandom().primaryKey(),
|
||||||
|
|
||||||
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||||
|
|
||||||
|
method: text("method").notNull(),
|
||||||
|
routePattern: text("route_pattern").notNull(),
|
||||||
|
actualPath: text("actual_path").notNull(),
|
||||||
|
|
||||||
|
statusCode: integer("status_code").notNull(),
|
||||||
|
durationMs: integer("duration_ms").notNull(),
|
||||||
|
|
||||||
|
module: text("module"),
|
||||||
|
userId: text("user_id"),
|
||||||
|
userEmail: text("user_email"),
|
||||||
|
|
||||||
|
ipAddress: text("ip_address"),
|
||||||
|
userAgent: text("user_agent"),
|
||||||
|
});
|
||||||
33
backend/db/schema/dailyAnalytics.schema.ts
Normal file
33
backend/db/schema/dailyAnalytics.schema.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
date,
|
||||||
|
integer,
|
||||||
|
pgTable,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
uuid,
|
||||||
|
} from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
|
export const analyticsDaily = pgTable("analytics_daily", {
|
||||||
|
id: uuid("id").defaultRandom().primaryKey(),
|
||||||
|
|
||||||
|
businessDate: date("business_date").notNull(),
|
||||||
|
|
||||||
|
method: text("method").notNull(),
|
||||||
|
routePattern: text("route_pattern").notNull(),
|
||||||
|
module: text("module").notNull(),
|
||||||
|
|
||||||
|
totalHits: integer("total_hits").notNull(),
|
||||||
|
uniqueUsers: integer("unique_users").notNull(),
|
||||||
|
|
||||||
|
successCount: integer("success_count").notNull(),
|
||||||
|
errorCount: integer("error_count").notNull(),
|
||||||
|
|
||||||
|
avgDurationMs: integer("avg_duration_ms").notNull(),
|
||||||
|
maxDurationMs: integer("max_duration_ms").notNull(),
|
||||||
|
|
||||||
|
firstHitAt: timestamp("first_hit_at").notNull(),
|
||||||
|
lastHitAt: timestamp("last_hit_at").notNull(),
|
||||||
|
|
||||||
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||||
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||||
|
});
|
||||||
@@ -12,7 +12,7 @@ export const scanLog = pgTable("scan_log", {
|
|||||||
runningNumber: text("running_number").default("0"),
|
runningNumber: text("running_number").default("0"),
|
||||||
status: text("status"),
|
status: text("status"),
|
||||||
lines: jsonb("lines").default([]),
|
lines: jsonb("lines").default([]),
|
||||||
add_Date: timestamp("add_Date").defaultNow(),
|
add_Date: timestamp("add_date").defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const scanLogSchema = createSelectSchema(scanLog);
|
export const scanLogSchema = createSelectSchema(scanLog);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type Express, Router } from "express";
|
import { type Express, Router } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import restart from "./gpSqlRestart.route.js";
|
import restart from "./gpSqlRestart.route.js";
|
||||||
import start from "./gpSqlStart.route.js";
|
import start from "./gpSqlStart.route.js";
|
||||||
import stop from "./gpSqlStop.route.js";
|
import stop from "./gpSqlStop.route.js";
|
||||||
@@ -8,6 +9,7 @@ export const setupGPSqlRoutes = (baseUrl: string, app: Express) => {
|
|||||||
// Apply auth to entire router
|
// Apply auth to entire router
|
||||||
const router = Router();
|
const router = Router();
|
||||||
router.use(requireAuth);
|
router.use(requireAuth);
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
|
|
||||||
router.use(start);
|
router.use(start);
|
||||||
router.use(stop);
|
router.use(stop);
|
||||||
|
|||||||
83
backend/middleware/routeHit.middleware.ts
Normal file
83
backend/middleware/routeHit.middleware.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
// routeHit.middleware.ts
|
||||||
|
|
||||||
|
import type { NextFunction, Request, Response } from "express";
|
||||||
|
import {
|
||||||
|
createRouteHit,
|
||||||
|
shouldIgnoreRoute,
|
||||||
|
} from "../utils/analyticRouteHits.utils.js";
|
||||||
|
|
||||||
|
export function routeHitMiddleware(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction,
|
||||||
|
) {
|
||||||
|
const start = performance.now();
|
||||||
|
|
||||||
|
res.on("finish", () => {
|
||||||
|
const actualPath = getActualPath(req);
|
||||||
|
|
||||||
|
if (shouldIgnoreRoute(actualPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const durationMs = Math.round(performance.now() - start);
|
||||||
|
|
||||||
|
const routePattern = getRoutePattern(req) as string;
|
||||||
|
const module = getModuleName(req);
|
||||||
|
|
||||||
|
void createRouteHit({
|
||||||
|
method: req.method,
|
||||||
|
routePattern,
|
||||||
|
actualPath,
|
||||||
|
statusCode: res.statusCode,
|
||||||
|
durationMs,
|
||||||
|
module,
|
||||||
|
|
||||||
|
// adjust these names to your Better Auth/session shape
|
||||||
|
userId: req.user?.id ?? null,
|
||||||
|
userEmail: req.user?.email ?? null,
|
||||||
|
|
||||||
|
ipAddress: req.ip ?? null,
|
||||||
|
userAgent: req.get("user-agent") ?? null,
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error("Failed to save route hit", err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getActualPath(req: Request) {
|
||||||
|
return req.originalUrl.split("?")[0] ?? req.path ?? "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRoutePattern(req: Request) {
|
||||||
|
const baseUrl = req.baseUrl || "";
|
||||||
|
const routePath = req.route?.path;
|
||||||
|
|
||||||
|
if (typeof routePath === "string") {
|
||||||
|
return `${baseUrl}${routePath}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getActualPath(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getModuleName(req: Request) {
|
||||||
|
const path = req.originalUrl.split("?")[0];
|
||||||
|
|
||||||
|
if (path?.includes("/printers")) return "printers";
|
||||||
|
if (path?.includes("/releases")) return "releases";
|
||||||
|
if (path?.includes("/quality")) return "quality";
|
||||||
|
if (path?.includes("/scanner")) return "scanner";
|
||||||
|
if (path?.includes("/settings")) return "settings";
|
||||||
|
if (path?.includes("/users")) return "users";
|
||||||
|
if (path?.includes("/mobile")) return "mobile";
|
||||||
|
if (path?.includes("/servers")) return "servers";
|
||||||
|
if (path?.includes("/logistics")) return "servers";
|
||||||
|
if (path?.includes("/ocp")) return "ocp";
|
||||||
|
if (path?.includes("/auth")) return "auth";
|
||||||
|
if (path?.includes("/datamart")) return "datamart";
|
||||||
|
if (path?.includes("/opendock")) return "opendock";
|
||||||
|
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import downloads from "./donwloadApps.route.js";
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
|
import downloads from "./downloadApps.route.js";
|
||||||
import lanes from "./laneCheck.js";
|
import lanes from "./laneCheck.js";
|
||||||
import authPin from "./mobileAuth.route.js";
|
import authPin from "./mobileAuth.route.js";
|
||||||
import newPin from "./mobilePin.route.js";
|
import newPin from "./mobilePin.route.js";
|
||||||
@@ -8,6 +9,9 @@ import version from "./version.route.js";
|
|||||||
|
|
||||||
export const setupMobileRoutes = (baseUrl: string, app: Express) => {
|
export const setupMobileRoutes = (baseUrl: string, app: Express) => {
|
||||||
//stats will be like this as we dont need to change this
|
//stats will be like this as we dont need to change this
|
||||||
|
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
|
|
||||||
app.use(`${baseUrl}/api/mobile/version`, version);
|
app.use(`${baseUrl}/api/mobile/version`, version);
|
||||||
app.use(`${baseUrl}/api/mobile/apk`, downloads);
|
app.use(`${baseUrl}/api/mobile/apk`, downloads);
|
||||||
app.use(`${baseUrl}/api/mobile/logs`, logs);
|
app.use(`${baseUrl}/api/mobile/logs`, logs);
|
||||||
|
|||||||
@@ -162,6 +162,14 @@ r.post("/user", async (req, res) => {
|
|||||||
r.get("/user", requireAuth, async (_, res) => {
|
r.get("/user", requireAuth, async (_, res) => {
|
||||||
const { data, error } = await tryCatch(db.select().from(scanUser));
|
const { data, error } = await tryCatch(db.select().from(scanUser));
|
||||||
|
|
||||||
|
// await trackLstEvent({
|
||||||
|
// eventName: "mobile_get_users",
|
||||||
|
// url: "/mobile/users",
|
||||||
|
// eventData: {
|
||||||
|
// module: "mobile",
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return apiReturn(res, {
|
return apiReturn(res, {
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { db } from "../db/db.controller.js";
|
||||||
|
import { settings } from "../db/schema/settings.schema.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -10,6 +12,15 @@ const appJsonPath = path.join(projectRoot, "app.json");
|
|||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
||||||
|
const mobileSettings = await db
|
||||||
|
.select()
|
||||||
|
.from(settings)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(settings.moduleName, "mobile"),
|
||||||
|
eq(settings.settingType, "standard"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const raw = fs.readFileSync(appJsonPath, "utf-8");
|
const raw = fs.readFileSync(appJsonPath, "utf-8");
|
||||||
const config = JSON.parse(raw);
|
const config = JSON.parse(raw);
|
||||||
@@ -22,6 +33,7 @@ router.get("/", async (req, res) => {
|
|||||||
versionCode: exp.android?.versionCode,
|
versionCode: exp.android?.versionCode,
|
||||||
minSupportedVersionCode: exp?.android?.minSupportedVersionCode ?? 0,
|
minSupportedVersionCode: exp?.android?.minSupportedVersionCode ?? 0,
|
||||||
downloadUrl: `${baseUrl}/lst/api/mobile/apk/latest`,
|
downloadUrl: `${baseUrl}/lst/api/mobile/apk/latest`,
|
||||||
|
settings: mobileSettings,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import manual from "./notification.manualTrigger.js";
|
import manual from "./notification.manualTrigger.js";
|
||||||
import getNotifications from "./notification.route.js";
|
import getNotifications from "./notification.route.js";
|
||||||
import updateNote from "./notification.update.route.js";
|
import updateNote from "./notification.update.route.js";
|
||||||
@@ -10,13 +11,48 @@ import updateSub from "./notificationSub.update.route.js";
|
|||||||
|
|
||||||
export const setupNotificationRoutes = (baseUrl: string, app: Express) => {
|
export const setupNotificationRoutes = (baseUrl: string, app: Express) => {
|
||||||
//stats will be like this as we dont need to change this
|
//stats will be like this as we dont need to change this
|
||||||
app.use(`${baseUrl}/api/notification`, requireAuth, getNotifications);
|
app.use(
|
||||||
app.use(`${baseUrl}/api/notification`, requireAuth, updateNote);
|
`${baseUrl}/api/notification`,
|
||||||
app.use(`${baseUrl}/api/notification/manual`, requireAuth, manual);
|
requireAuth,
|
||||||
app.use(`${baseUrl}/api/notification/sub`, requireAuth, subs);
|
routeHitMiddleware,
|
||||||
app.use(`${baseUrl}/api/notification/sub`, requireAuth, newSub);
|
getNotifications,
|
||||||
app.use(`${baseUrl}/api/notification/sub`, requireAuth, updateSub);
|
);
|
||||||
app.use(`${baseUrl}/api/notification/sub`, requireAuth, deleteSub);
|
app.use(
|
||||||
|
`${baseUrl}/api/notification`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
updateNote,
|
||||||
|
);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/notification/manual`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
manual,
|
||||||
|
);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/notification/sub`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
subs,
|
||||||
|
);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/notification/sub`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
newSub,
|
||||||
|
);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/notification/sub`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
updateSub,
|
||||||
|
);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/notification/sub`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
deleteSub,
|
||||||
|
);
|
||||||
|
|
||||||
// all other system should be under /api/system/*
|
// all other system should be under /api/system/*
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { type Express, Router } from "express";
|
import { type Express, Router } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
import { featureCheck } from "../middleware/featureActive.middleware.js";
|
import { featureCheck } from "../middleware/featureActive.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import listener from "./ocp.printer.listener.js";
|
import listener from "./ocp.printer.listener.js";
|
||||||
import update from "./ocp.printer.update.js";
|
import update from "./ocp.printer.update.js";
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ export const setupOCPRoutes = (baseUrl: string, app: Express) => {
|
|||||||
// auth routes below here
|
// auth routes below here
|
||||||
router.use(requireAuth);
|
router.use(requireAuth);
|
||||||
|
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
|
|
||||||
router.use(update);
|
router.use(update);
|
||||||
//router.use("");
|
//router.use("");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { type Express, Router } from "express";
|
import { type Express, Router } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
import { featureCheck } from "../middleware/featureActive.middleware.js";
|
import { featureCheck } from "../middleware/featureActive.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import getApt from "./opendockGetRelease.route.js";
|
import getApt from "./opendockGetRelease.route.js";
|
||||||
|
|
||||||
export const setupOpendockRoutes = (baseUrl: string, app: Express) => {
|
export const setupOpendockRoutes = (baseUrl: string, app: Express) => {
|
||||||
@@ -13,6 +14,7 @@ export const setupOpendockRoutes = (baseUrl: string, app: Express) => {
|
|||||||
|
|
||||||
// we need to make sure we are authenticated to see the releases
|
// we need to make sure we are authenticated to see the releases
|
||||||
router.use(requireAuth);
|
router.use(requireAuth);
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
|
|
||||||
router.use(getApt);
|
router.use(getApt);
|
||||||
app.use(`${baseUrl}/api/opendock`, router);
|
app.use(`${baseUrl}/api/opendock`, router);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type Express, Router } from "express";
|
import { type Express, Router } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import restart from "./prodSqlRestart.route.js";
|
import restart from "./prodSqlRestart.route.js";
|
||||||
import start from "./prodSqlStart.route.js";
|
import start from "./prodSqlStart.route.js";
|
||||||
import stop from "./prodSqlStop.route.js";
|
import stop from "./prodSqlStop.route.js";
|
||||||
@@ -8,6 +9,7 @@ export const setupProdSqlRoutes = (baseUrl: string, app: Express) => {
|
|||||||
// Apply auth to entire router
|
// Apply auth to entire router
|
||||||
const router = Router();
|
const router = Router();
|
||||||
router.use(requireAuth);
|
router.use(requireAuth);
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
|
|
||||||
router.use(start);
|
router.use(start);
|
||||||
router.use(stop);
|
router.use(stop);
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ import { setupSocketIORoutes } from "./socket.io/serverSetup.js";
|
|||||||
import { serversChecks } from "./system/serverData.controller.js";
|
import { serversChecks } from "./system/serverData.controller.js";
|
||||||
import { baseSettingValidationCheck } from "./system/settingsBase.controller.js";
|
import { baseSettingValidationCheck } from "./system/settingsBase.controller.js";
|
||||||
import { startTCPServer } from "./tcpServer/tcp.server.js";
|
import { startTCPServer } from "./tcpServer/tcp.server.js";
|
||||||
|
import {
|
||||||
|
aggregateRouteHitsForBusinessDay,
|
||||||
|
cleanupOldRouteHits,
|
||||||
|
runRouteHitAnalyticsCron,
|
||||||
|
} from "./utils/analyticRouteHits.utils.js";
|
||||||
import { createCronJob } from "./utils/croner.utils.js";
|
import { createCronJob } from "./utils/croner.utils.js";
|
||||||
import { sendEmail } from "./utils/sendEmail.utils.js";
|
import { sendEmail } from "./utils/sendEmail.utils.js";
|
||||||
|
|
||||||
@@ -68,10 +73,16 @@ const start = async () => {
|
|||||||
createCronJob("logsCleanup", "0 15 5 * * *", () => dbCleanup("logs", 120));
|
createCronJob("logsCleanup", "0 15 5 * * *", () => dbCleanup("logs", 120));
|
||||||
historicalSchedule();
|
historicalSchedule();
|
||||||
|
|
||||||
|
createCronJob("aggregateHits", "0 0 7 * * *", async () =>
|
||||||
|
runRouteHitAnalyticsCron(),
|
||||||
|
);
|
||||||
|
|
||||||
|
createCronJob("cleanHitsUp", "0 0 7 * * *", () => cleanupOldRouteHits());
|
||||||
// one shots only needed to run on server startups
|
// one shots only needed to run on server startups
|
||||||
createNotifications();
|
createNotifications();
|
||||||
startNotifications();
|
startNotifications();
|
||||||
serversChecks();
|
serversChecks();
|
||||||
|
aggregateRouteHitsForBusinessDay();
|
||||||
}, 5 * 1000);
|
}, 5 * 1000);
|
||||||
|
|
||||||
process.on("uncaughtException", async (err) => {
|
process.on("uncaughtException", async (err) => {
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ const newSettings: NewSetting[] = [
|
|||||||
roles: ["admin"],
|
roles: ["admin"],
|
||||||
seedVersion: 1,
|
seedVersion: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "mobile",
|
||||||
|
value: "0",
|
||||||
|
active: false,
|
||||||
|
description: "LST Android Mobile app",
|
||||||
|
moduleName: "mobile",
|
||||||
|
settingType: "feature",
|
||||||
|
roles: ["admin"],
|
||||||
|
seedVersion: 1,
|
||||||
|
},
|
||||||
|
|
||||||
// standard settings
|
// standard settings
|
||||||
{
|
{
|
||||||
@@ -304,6 +314,38 @@ const newSettings: NewSetting[] = [
|
|||||||
roles: ["admin"],
|
roles: ["admin"],
|
||||||
seedVersion: 1,
|
seedVersion: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "laneCheck",
|
||||||
|
value: "0",
|
||||||
|
active: false,
|
||||||
|
description:
|
||||||
|
"Allows the driver to scan a lane and see what is in the lane and details about each pallet.",
|
||||||
|
moduleName: "mobile",
|
||||||
|
settingType: "standard",
|
||||||
|
roles: ["admin"],
|
||||||
|
seedVersion: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dockScan",
|
||||||
|
value: "0",
|
||||||
|
active: false,
|
||||||
|
description:
|
||||||
|
"Enables dock door scanning, must have a dock scanner setup for this to work.",
|
||||||
|
moduleName: "mobile",
|
||||||
|
settingType: "standard",
|
||||||
|
roles: ["admin"],
|
||||||
|
seedVersion: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "cycleCounting",
|
||||||
|
value: "0",
|
||||||
|
active: false,
|
||||||
|
description: "Enables a cycle count to be triggered from the scanner.",
|
||||||
|
moduleName: "mobile",
|
||||||
|
settingType: "standard",
|
||||||
|
roles: ["admin"],
|
||||||
|
seedVersion: 1,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const baseSettingValidationCheck = async () => {
|
export const baseSettingValidationCheck = async () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import getServers from "./serverData.route.js";
|
import getServers from "./serverData.route.js";
|
||||||
import getSettings from "./settings.route.js";
|
import getSettings from "./settings.route.js";
|
||||||
import updSetting from "./settingsUpdate.route.js";
|
import updSetting from "./settingsUpdate.route.js";
|
||||||
@@ -7,6 +8,7 @@ import stats from "./stats.route.js";
|
|||||||
|
|
||||||
export const setupSystemRoutes = (baseUrl: string, app: Express) => {
|
export const setupSystemRoutes = (baseUrl: string, app: Express) => {
|
||||||
//stats will be like this as we dont need to change this
|
//stats will be like this as we dont need to change this
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
app.use(`${baseUrl}/api/stats`, stats);
|
app.use(`${baseUrl}/api/stats`, stats);
|
||||||
app.use(`${baseUrl}/api/settings`, getSettings);
|
app.use(`${baseUrl}/api/settings`, getSettings);
|
||||||
app.use(`${baseUrl}/api/servers`, getServers);
|
app.use(`${baseUrl}/api/servers`, getServers);
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import { requireAuth } from "../middleware/auth.middleware.js";
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import restart from "./tcpRestart.route.js";
|
import restart from "./tcpRestart.route.js";
|
||||||
import start from "./tcpStart.route.js";
|
import start from "./tcpStart.route.js";
|
||||||
import stop from "./tcpStop.route.js";
|
import stop from "./tcpStop.route.js";
|
||||||
|
|
||||||
export const setupTCPRoutes = (baseUrl: string, app: Express) => {
|
export const setupTCPRoutes = (baseUrl: string, app: Express) => {
|
||||||
//stats will be like this as we dont need to change this
|
//stats will be like this as we dont need to change this
|
||||||
app.use(`${baseUrl}/api/tcp/start`, requireAuth, start);
|
|
||||||
app.use(`${baseUrl}/api/tcp/stop`, requireAuth, stop);
|
app.use(`${baseUrl}/api/tcp/start`, requireAuth, routeHitMiddleware, start);
|
||||||
app.use(`${baseUrl}/api/tcp/restart`, requireAuth, restart);
|
app.use(`${baseUrl}/api/tcp/stop`, requireAuth, routeHitMiddleware, stop);
|
||||||
|
app.use(
|
||||||
|
`${baseUrl}/api/tcp/restart`,
|
||||||
|
requireAuth,
|
||||||
|
routeHitMiddleware,
|
||||||
|
restart,
|
||||||
|
);
|
||||||
|
|
||||||
// all other system should be under /api/system/*
|
// all other system should be under /api/system/*
|
||||||
};
|
};
|
||||||
|
|||||||
141
backend/utils/analyticRouteHits.utils.ts
Normal file
141
backend/utils/analyticRouteHits.utils.ts
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import { and, count, countDistinct, gte, lt, sql } from "drizzle-orm";
|
||||||
|
import { db } from "../db/db.controller.js";
|
||||||
|
import { analytics } from "../db/schema/analytics.schema.js";
|
||||||
|
import { analyticsDaily } from "../db/schema/dailyAnalytics.schema.js";
|
||||||
|
|
||||||
|
export const ignoredRoutePrefixes = [
|
||||||
|
"/health",
|
||||||
|
"/favicon.ico",
|
||||||
|
"/socket.io",
|
||||||
|
"/lst/api/ws",
|
||||||
|
"/lst-config.js",
|
||||||
|
];
|
||||||
|
|
||||||
|
export function shouldIgnoreRoute(path: string) {
|
||||||
|
return ignoredRoutePrefixes.some((prefix) => path.startsWith(prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateRouteHitInput = {
|
||||||
|
method: string;
|
||||||
|
routePattern: string;
|
||||||
|
actualPath: string;
|
||||||
|
statusCode: number;
|
||||||
|
durationMs: number;
|
||||||
|
module?: string | null;
|
||||||
|
userId?: string | null;
|
||||||
|
userEmail?: string | null;
|
||||||
|
ipAddress?: string | null;
|
||||||
|
userAgent?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function createRouteHit(input: CreateRouteHitInput) {
|
||||||
|
await db.insert(analytics).values(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPreviousBusinessDayWindow(date = new Date()) {
|
||||||
|
const end = new Date(date);
|
||||||
|
end.setHours(7, 0, 0, 0);
|
||||||
|
|
||||||
|
const start = new Date(end);
|
||||||
|
start.setDate(start.getDate() - 1);
|
||||||
|
|
||||||
|
const businessDate = start.toISOString().slice(0, 10);
|
||||||
|
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
businessDate,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function runRouteHitAnalyticsCron(): Promise<void> {
|
||||||
|
const result = await aggregateRouteHitsForBusinessDay();
|
||||||
|
|
||||||
|
await cleanupOldRouteHits();
|
||||||
|
|
||||||
|
console.log("Route hit analytics aggregated", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function aggregateRouteHitsForBusinessDay() {
|
||||||
|
const { start, end, businessDate } = getPreviousBusinessDayWindow();
|
||||||
|
|
||||||
|
const rows = await db
|
||||||
|
.select({
|
||||||
|
businessDate: sql<string>`${businessDate}`,
|
||||||
|
method: analytics.method,
|
||||||
|
routePattern: analytics.routePattern,
|
||||||
|
module: sql<string>`COALESCE(${analytics.module}, 'unknown')`,
|
||||||
|
|
||||||
|
totalHits: count(),
|
||||||
|
uniqueUsers: countDistinct(analytics.userId),
|
||||||
|
|
||||||
|
successCount: sql<number>`
|
||||||
|
COUNT(*) FILTER (WHERE ${analytics.statusCode} < 400)
|
||||||
|
`,
|
||||||
|
errorCount: sql<number>`
|
||||||
|
COUNT(*) FILTER (WHERE ${analytics.statusCode} >= 400)
|
||||||
|
`,
|
||||||
|
|
||||||
|
avgDurationMs: sql<number>`
|
||||||
|
COALESCE(ROUND(AVG(${analytics.durationMs})), 0)
|
||||||
|
`,
|
||||||
|
maxDurationMs: sql<number>`
|
||||||
|
COALESCE(MAX(${analytics.durationMs}), 0)
|
||||||
|
`,
|
||||||
|
|
||||||
|
firstHitAt: sql<Date>`
|
||||||
|
COALESCE(MIN(${analytics.createdAt}), NOW())
|
||||||
|
`,
|
||||||
|
lastHitAt: sql<Date>`
|
||||||
|
COALESCE(MAX(${analytics.createdAt}), NOW())
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
.from(analytics)
|
||||||
|
.where(and(gte(analytics.createdAt, start), lt(analytics.createdAt, end)))
|
||||||
|
.groupBy(
|
||||||
|
analytics.method,
|
||||||
|
analytics.routePattern,
|
||||||
|
sql`COALESCE(${analytics.module}, 'unknown')`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rows.length === 0) {
|
||||||
|
return {
|
||||||
|
businessDate,
|
||||||
|
inserted: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.insert(analyticsDaily)
|
||||||
|
.values(rows)
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [
|
||||||
|
analyticsDaily.businessDate,
|
||||||
|
analyticsDaily.method,
|
||||||
|
analyticsDaily.routePattern,
|
||||||
|
analyticsDaily.module,
|
||||||
|
],
|
||||||
|
set: {
|
||||||
|
totalHits: sql`excluded.total_hits`,
|
||||||
|
uniqueUsers: sql`excluded.unique_users`,
|
||||||
|
successCount: sql`excluded.success_count`,
|
||||||
|
errorCount: sql`excluded.error_count`,
|
||||||
|
avgDurationMs: sql`excluded.avg_duration_ms`,
|
||||||
|
maxDurationMs: sql`excluded.max_duration_ms`,
|
||||||
|
firstHitAt: sql`excluded.first_hit_at`,
|
||||||
|
lastHitAt: sql`excluded.last_hit_at`,
|
||||||
|
updatedAt: sql`now()`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
businessDate,
|
||||||
|
inserted: rows.length,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function cleanupOldRouteHits() {
|
||||||
|
await db
|
||||||
|
.delete(analytics)
|
||||||
|
.where(lt(analytics.createdAt, sql`now() - interval '4 days'`));
|
||||||
|
}
|
||||||
61
backend/utils/umami.utils.ts
Normal file
61
backend/utils/umami.utils.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { isUmamiEnabled, umamiConfig } from "../configs/umami.config.js";
|
||||||
|
|
||||||
|
type TrackLstEventInput = {
|
||||||
|
eventName: string;
|
||||||
|
eventData?: Record<string, unknown>;
|
||||||
|
url?: string;
|
||||||
|
hostname?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function trackLstEvent({
|
||||||
|
eventName,
|
||||||
|
eventData,
|
||||||
|
url = "/backend",
|
||||||
|
hostname = umamiConfig.server,
|
||||||
|
}: TrackLstEventInput): Promise<void> {
|
||||||
|
if (!isUmamiEnabled()) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fetch(`${umamiConfig.umamiHost}/api/send`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": "LST-Backend",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
type: "event",
|
||||||
|
payload: {
|
||||||
|
website: umamiConfig.umamiWebsiteId,
|
||||||
|
name: eventName,
|
||||||
|
url,
|
||||||
|
hostname,
|
||||||
|
language: "en-US",
|
||||||
|
screen: "backend",
|
||||||
|
data: {
|
||||||
|
app: umamiConfig.appName,
|
||||||
|
site: umamiConfig.site,
|
||||||
|
server: umamiConfig.server,
|
||||||
|
appVersion: umamiConfig.appVersion,
|
||||||
|
source: "backend",
|
||||||
|
...eventData,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to send Umami backend event", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
await trackLstEvent({
|
||||||
|
eventName: "label_print_completed",
|
||||||
|
url: "/backend/printers",
|
||||||
|
eventData: {
|
||||||
|
module: "printers",
|
||||||
|
printerName,
|
||||||
|
labelType,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
|
import { routeHitMiddleware } from "../middleware/routeHit.middleware.js";
|
||||||
import getActiveJobs from "./cronerActiveJobs.route.js";
|
import getActiveJobs from "./cronerActiveJobs.route.js";
|
||||||
import jobStatusChange from "./cronerStatusChange.route.js";
|
import jobStatusChange from "./cronerStatusChange.route.js";
|
||||||
export const setupUtilsRoutes = (baseUrl: string, app: Express) => {
|
export const setupUtilsRoutes = (baseUrl: string, app: Express) => {
|
||||||
|
app.use(routeHitMiddleware);
|
||||||
app.use(`${baseUrl}/api/utils/croner`, getActiveJobs);
|
app.use(`${baseUrl}/api/utils/croner`, getActiveJobs);
|
||||||
app.use(`${baseUrl}/api/utils/croner`, jobStatusChange);
|
app.use(`${baseUrl}/api/utils/croner`, jobStatusChange);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,15 @@
|
|||||||
<title>Logistics Support Tool</title>
|
<title>Logistics Support Tool</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<script>
|
||||||
|
const configScript = document.createElement("script");
|
||||||
|
configScript.src = `${window.location.origin}/lst/api/lst-config.js`;
|
||||||
|
configScript.defer = false;
|
||||||
|
document.head.appendChild(configScript);
|
||||||
|
</script>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
<script defer src="https://stats.tuffraid.net/script.js" data-website-id="49bc2489-3930-4358-a13d-1cc609336572"></script>
|
||||||
|
|
||||||
<script type="module" src="/src/main.tsx"></script>
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
25
frontend/src/lib/queries/getScanUsers.ts
Normal file
25
frontend/src/lib/queries/getScanUsers.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { keepPreviousData, queryOptions } from "@tanstack/react-query";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export function getScanUsers() {
|
||||||
|
return queryOptions({
|
||||||
|
queryKey: ["getScanUsers"],
|
||||||
|
queryFn: () => fetch(),
|
||||||
|
staleTime: 5000,
|
||||||
|
refetchOnWindowFocus: true,
|
||||||
|
placeholderData: keepPreviousData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetch = async () => {
|
||||||
|
if (window.location.hostname === "localhost") {
|
||||||
|
await new Promise((res) => setTimeout(res, 1500));
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.get("/lst/api/mobile/auth/user", {
|
||||||
|
withCredentials: true,
|
||||||
|
timeout: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
|
return data.data;
|
||||||
|
};
|
||||||
65
frontend/src/lib/umami.utils.ts
Normal file
65
frontend/src/lib/umami.utils.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
type RuntimeConfig = {
|
||||||
|
appName: string;
|
||||||
|
site: string;
|
||||||
|
server: string;
|
||||||
|
appVersion: string;
|
||||||
|
umamiHost: string;
|
||||||
|
umamiWebsiteId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
LST_CONFIG?: RuntimeConfig;
|
||||||
|
umami?: {
|
||||||
|
track: (eventName: string, eventData?: Record<string, unknown>) => void;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const runtimeConfig: RuntimeConfig = {
|
||||||
|
appName: window.LST_CONFIG?.appName ?? "LST",
|
||||||
|
site: window.LST_CONFIG?.site ?? "unknown",
|
||||||
|
server: window.LST_CONFIG?.server ?? "unknown",
|
||||||
|
appVersion: window.LST_CONFIG?.appVersion ?? "dev",
|
||||||
|
umamiHost: window.LST_CONFIG?.umamiHost ?? "",
|
||||||
|
umamiWebsiteId: window.LST_CONFIG?.umamiWebsiteId ?? "",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function loadUmami() {
|
||||||
|
if (!runtimeConfig.umamiHost) return;
|
||||||
|
if (!runtimeConfig.umamiWebsiteId) return;
|
||||||
|
if (document.querySelector("script[data-website-id]")) return;
|
||||||
|
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.defer = true;
|
||||||
|
script.src = `${runtimeConfig.umamiHost}/script.js`;
|
||||||
|
script.setAttribute("data-website-id", runtimeConfig.umamiWebsiteId);
|
||||||
|
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackLstEvent(
|
||||||
|
eventName: string,
|
||||||
|
eventData?: Record<string, unknown>,
|
||||||
|
) {
|
||||||
|
window.umami?.track(eventName, {
|
||||||
|
app: runtimeConfig.appName,
|
||||||
|
site: runtimeConfig.site,
|
||||||
|
server: runtimeConfig.server,
|
||||||
|
appVersion: runtimeConfig.appVersion,
|
||||||
|
...eventData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
event type
|
||||||
|
|
||||||
|
trackLstEvent("exampleClick", {
|
||||||
|
module: "example",
|
||||||
|
action: "test_click",
|
||||||
|
label: "Example Button",
|
||||||
|
page: window.location.pathname,
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -4,6 +4,7 @@ import ReactDOM from "react-dom/client";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { createRouter, RouterProvider } from "@tanstack/react-router";
|
import { createRouter, RouterProvider } from "@tanstack/react-router";
|
||||||
import socket from "./lib/socket.io";
|
import socket from "./lib/socket.io";
|
||||||
|
import { loadUmami } from "./lib/umami.utils";
|
||||||
// Import the generated route tree
|
// Import the generated route tree
|
||||||
import { routeTree } from "./routeTree.gen";
|
import { routeTree } from "./routeTree.gen";
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ declare module "@tanstack/react-router" {
|
|||||||
// Render the app
|
// Render the app
|
||||||
const rootElement = document.getElementById("root")!;
|
const rootElement = document.getElementById("root")!;
|
||||||
if (!rootElement.innerHTML) {
|
if (!rootElement.innerHTML) {
|
||||||
|
loadUmami();
|
||||||
const root = ReactDOM.createRoot(rootElement);
|
const root = ReactDOM.createRoot(rootElement);
|
||||||
root.render(
|
root.render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import { getScanUsers } from "../../lib/queries/getScanUsers";
|
||||||
|
|
||||||
export const Route = createFileRoute('/admin/scanUsers')({
|
export const Route = createFileRoute("/admin/scanUsers")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
})
|
});
|
||||||
|
|
||||||
|
const ScanUserTable = () => {
|
||||||
|
const { data } = useSuspenseQuery(getScanUsers());
|
||||||
|
console.log(data);
|
||||||
|
return <div>Hello "/admin/scanUsers"!</div>;
|
||||||
|
};
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return <div>Hello "/admin/scanUsers"!</div>
|
return <ScanUserTable />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ function RouteComponent() {
|
|||||||
|
|
||||||
const columnHelper = createColumnHelper<any>();
|
const columnHelper = createColumnHelper<any>();
|
||||||
|
|
||||||
console.log(window.location);
|
|
||||||
const logColumns = [
|
const logColumns = [
|
||||||
columnHelper.accessor("timestamp", {
|
columnHelper.accessor("timestamp", {
|
||||||
header: ({ column }) => (
|
header: ({ column }) => (
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createFileRoute } from "@tanstack/react-router";
|
|||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
|
||||||
import { useSession } from "../lib/auth-client";
|
import { useSession } from "../lib/auth-client";
|
||||||
|
import { trackLstEvent } from "../lib/umami.utils";
|
||||||
|
|
||||||
export const Route = createFileRoute("/")({
|
export const Route = createFileRoute("/")({
|
||||||
validateSearch: z.object({
|
validateSearch: z.object({
|
||||||
@@ -27,6 +28,16 @@ function Index() {
|
|||||||
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//test tracking
|
||||||
|
const click = () => {
|
||||||
|
trackLstEvent("silly_click", {
|
||||||
|
module: "silly",
|
||||||
|
action: "click",
|
||||||
|
label: "rick rolled",
|
||||||
|
page: window.location.pathname,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center m-10 flex-col">
|
<div className="flex justify-center m-10 flex-col">
|
||||||
<h3 className="w-2xl text-3xl">Welcome Lst - V3</h3>
|
<h3 className="w-2xl text-3xl">Welcome Lst - V3</h3>
|
||||||
@@ -43,7 +54,8 @@ function Index() {
|
|||||||
<b>
|
<b>
|
||||||
<strong>Click</strong>
|
<strong>Click</strong>
|
||||||
</b>
|
</b>
|
||||||
</a>
|
</a>{" "}
|
||||||
|
<button onClick={click}>
|
||||||
<a
|
<a
|
||||||
href={`https://www.youtube.com/watch?v=dQw4w9WgXcQ`}
|
href={`https://www.youtube.com/watch?v=dQw4w9WgXcQ`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -53,6 +65,7 @@ function Index() {
|
|||||||
<strong> Here</strong>
|
<strong> Here</strong>
|
||||||
</b>
|
</b>
|
||||||
</a>
|
</a>
|
||||||
|
</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"foregroundImage": "./assets/adaptive-icon-white.png",
|
"foregroundImage": "./assets/adaptive-icon-white.png",
|
||||||
"backgroundColor": "#ffffff"
|
"backgroundColor": "#ffffff"
|
||||||
},
|
},
|
||||||
"versionCode": 31,
|
"versionCode": 32,
|
||||||
"minSupportedVersionCode": 26,
|
"minSupportedVersionCode": 26,
|
||||||
"predictiveBackGestureEnabled": false,
|
"predictiveBackGestureEnabled": false,
|
||||||
"package": "net.alpla.lst.mobile"
|
"package": "net.alpla.lst.mobile"
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { Redirect, Tabs } from "expo-router";
|
import { Redirect, Tabs } from "expo-router";
|
||||||
import { Container, Home, Logs, Rows4, Settings } from "lucide-react-native";
|
import {
|
||||||
|
Boxes,
|
||||||
|
Container,
|
||||||
|
Home,
|
||||||
|
Logs,
|
||||||
|
Rows4,
|
||||||
|
Settings,
|
||||||
|
} from "lucide-react-native";
|
||||||
import { useAppStore } from "../../hooks/useAppStore";
|
import { useAppStore } from "../../hooks/useAppStore";
|
||||||
import { useMobileAuthStore } from "../../hooks/useMobileAuth";
|
import { useMobileAuthStore } from "../../hooks/useMobileAuth";
|
||||||
|
|
||||||
@@ -51,11 +58,18 @@ export default function TabsLayout() {
|
|||||||
// },
|
// },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Tabs.Screen
|
||||||
|
name="ppoo"
|
||||||
|
options={{
|
||||||
|
title: "PPOO",
|
||||||
|
href: isNormalScanner ? null : "/(tabs)/ppoo",
|
||||||
|
tabBarIcon: ({ color, size }) => <Boxes size={size} color={color} />,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="laneCheck"
|
name="laneCheck"
|
||||||
options={{
|
options={{
|
||||||
title: "Lane Check",
|
title: "Lane Check",
|
||||||
|
|
||||||
href: isNormalScanner ? null : "/(tabs)/laneCheck",
|
href: isNormalScanner ? null : "/(tabs)/laneCheck",
|
||||||
tabBarIcon: ({ color, size }) => <Rows4 size={size} color={color} />,
|
tabBarIcon: ({ color, size }) => <Rows4 size={size} color={color} />,
|
||||||
}}
|
}}
|
||||||
|
|||||||
18
lstMobile/src/app/(tabs)/ppoo.tsx
Normal file
18
lstMobile/src/app/(tabs)/ppoo.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Text, View } from "react-native";
|
||||||
|
import { Button } from "../../components/ui/button";
|
||||||
|
|
||||||
|
export default function PPOO() {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
//justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
marginTop: 50,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text>Ppo checks</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ export function GlobalFooter() {
|
|||||||
{!hasUpdate && shouldUpdate && (
|
{!hasUpdate && shouldUpdate && (
|
||||||
<View className="bg-[#FDBA74]">
|
<View className="bg-[#FDBA74]">
|
||||||
<Link href={"/updateScreen"}>
|
<Link href={"/updateScreen"}>
|
||||||
<Text className="h-[32] font-medium text-lg text-wrap text-center">
|
<Text className="h-[16] font-medium text-base text-wrap text-center">
|
||||||
There is an update click me for instructions
|
There is an update click me for instructions
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
14
migrations/0048_little_amazoness.sql
Normal file
14
migrations/0048_little_amazoness.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE "analytics" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||||
|
"method" text NOT NULL,
|
||||||
|
"route_pattern" text NOT NULL,
|
||||||
|
"actual_path" text NOT NULL,
|
||||||
|
"status_code" integer NOT NULL,
|
||||||
|
"duration_ms" integer NOT NULL,
|
||||||
|
"module" text,
|
||||||
|
"user_id" text,
|
||||||
|
"user_email" text,
|
||||||
|
"ip_address" text,
|
||||||
|
"user_agent" text
|
||||||
|
);
|
||||||
1
migrations/0049_futuristic_silk_fever.sql
Normal file
1
migrations/0049_futuristic_silk_fever.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "scan_log" RENAME COLUMN "add_Date" TO "add_date";
|
||||||
17
migrations/0050_concerned_vivisector.sql
Normal file
17
migrations/0050_concerned_vivisector.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE "analytics_daily" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"business_date" date NOT NULL,
|
||||||
|
"method" text NOT NULL,
|
||||||
|
"route_pattern" text NOT NULL,
|
||||||
|
"module" text NOT NULL,
|
||||||
|
"total_hits" integer NOT NULL,
|
||||||
|
"unique_users" integer NOT NULL,
|
||||||
|
"success_count" integer NOT NULL,
|
||||||
|
"error_count" integer NOT NULL,
|
||||||
|
"avg_duration_ms" integer NOT NULL,
|
||||||
|
"max_duration_ms" integer NOT NULL,
|
||||||
|
"first_hit_at" timestamp NOT NULL,
|
||||||
|
"last_hit_at" timestamp NOT NULL,
|
||||||
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
2243
migrations/meta/0048_snapshot.json
Normal file
2243
migrations/meta/0048_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
2243
migrations/meta/0049_snapshot.json
Normal file
2243
migrations/meta/0049_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
2349
migrations/meta/0050_snapshot.json
Normal file
2349
migrations/meta/0050_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -337,6 +337,27 @@
|
|||||||
"when": 1778068577325,
|
"when": 1778068577325,
|
||||||
"tag": "0047_spotty_queen_noir",
|
"tag": "0047_spotty_queen_noir",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 48,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1778165976086,
|
||||||
|
"tag": "0048_little_amazoness",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 49,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1778166074209,
|
||||||
|
"tag": "0049_futuristic_silk_fever",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 50,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1778169641819,
|
||||||
|
"tag": "0050_concerned_vivisector",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "lst_v3",
|
"name": "lst_v3",
|
||||||
"version": "0.0.2-alpha.9",
|
"version": "0.0.2-alpha.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "lst_v3",
|
"name": "lst_v3",
|
||||||
"version": "0.0.2-alpha.9",
|
"version": "0.0.2-alpha.10",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dotenvx/dotenvx": "^1.57.0",
|
"@dotenvx/dotenvx": "^1.57.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lst_v3",
|
"name": "lst_v3",
|
||||||
"version": "0.0.2-alpha.9",
|
"version": "0.0.2-alpha.10",
|
||||||
"description": "The tool that supports us in our everyday alplaprod",
|
"description": "The tool that supports us in our everyday alplaprod",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ function Update-Server {
|
|||||||
"CLIENT_SECRET" = "zsJeyjMN2yDDqfyzSsh96OtlA2714F5d"
|
"CLIENT_SECRET" = "zsJeyjMN2yDDqfyzSsh96OtlA2714F5d"
|
||||||
"CLIENT_SCOPES" = "openid profile email groups"
|
"CLIENT_SCOPES" = "openid profile email groups"
|
||||||
"DISCOVERY_URL" = "https://auth.tuffraid.net/oidc/.well-known/openid-configuration"
|
"DISCOVERY_URL" = "https://auth.tuffraid.net/oidc/.well-known/openid-configuration"
|
||||||
|
"UMAMI_HOST" = "https://stats.tuffraid.net"
|
||||||
|
"UMAMI_WEBSITE_ID" = "49bc2489-3930-4358-a13d-1cc609336572"
|
||||||
}
|
}
|
||||||
|
|
||||||
$linesToAppend = @()
|
$linesToAppend = @()
|
||||||
|
|||||||
Reference in New Issue
Block a user