summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/core/API.js198
-rw-r--r--build/core/API.js.map1
-rw-r--r--build/core/Authentication.js86
-rw-r--r--build/core/Authentication.js.map1
-rw-r--r--build/core/Autoreport.js86
-rw-r--r--build/core/Autoreport.js.map1
-rw-r--r--build/core/AutoreportBase.js15
-rw-r--r--build/core/AutoreportBase.js.map1
-rw-r--r--build/core/Notification.js51
-rw-r--r--build/core/Notification.js.map1
-rw-r--r--build/index.js33
-rw-r--r--build/index.js.map1
-rw-r--r--build/types/Report.js37
-rw-r--r--build/types/Report.js.map1
-rw-r--r--build/types/UUID.js13
-rw-r--r--build/types/UUID.js.map1
16 files changed, 527 insertions, 0 deletions
diff --git a/build/core/API.js b/build/core/API.js
new file mode 100644
index 0000000..ebe6346
--- /dev/null
+++ b/build/core/API.js
@@ -0,0 +1,198 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ReportEndpoint = void 0;
+const AutoreportBase_1 = __importDefault(require("./AutoreportBase"));
+const Authentication_1 = __importDefault(require("./Authentication"));
+const Report_1 = require("../types/Report");
+const node_fs_1 = require("node:fs");
+const UUID_1 = __importDefault(require("../types/UUID"));
+const Notification_1 = __importDefault(require("./Notification"));
+class APIEndpoint extends AutoreportBase_1.default {
+}
+class ReportEndpoint extends APIEndpoint {
+ static refresh(req, res) {
+ ReportEndpoint.reports = JSON.parse((0, node_fs_1.readFileSync)("./data/reports.json").toString());
+ return res.status(200).json({
+ code: 200,
+ message: "OK."
+ });
+ }
+ static post(req, res) {
+ if ([null, undefined, ""].includes(req.body.service) ||
+ [null, undefined, ""].includes(req.body.time) ||
+ [null, undefined, ""].includes(req.body.severity) ||
+ [null, undefined, "", {}].includes(req.body.error) ||
+ [null, undefined, "", {}].includes(req.body.systemInfo)) {
+ return res.status(400).json({
+ code: 400,
+ message: "Report information is missing."
+ });
+ }
+ if ([null, undefined, ""].includes(req.body.error.message) ||
+ [null, undefined, ""].includes(req.body.error.stacktrace)) {
+ return res.status(400).json({
+ code: 400,
+ message: "Error information is missing."
+ });
+ }
+ if ([null, undefined, ""].includes(req.body.systemInfo.pid) ||
+ [null, undefined, ""].includes(req.body.systemInfo.user) ||
+ [null, undefined, ""].includes(req.body.systemInfo.executable) ||
+ [null, undefined, ""].includes(req.body.systemInfo.memoryUsed) ||
+ [null, undefined, ""].includes(req.body.systemInfo.cpuTimes) ||
+ [null, undefined, ""].includes(req.body.systemInfo.uptime) ||
+ [null, undefined, ""].includes(req.body.systemInfo.systemUptime) ||
+ [null, undefined, ""].includes(req.body.systemInfo.os)) {
+ return res.status(400).json({
+ code: 400,
+ message: "System information is missing."
+ });
+ }
+ let severity = Report_1.ReportSeverity.Medium;
+ switch (req.body.severity.toString().toLowerCase()) {
+ case "low":
+ case "0":
+ severity = Report_1.ReportSeverity.Low;
+ break;
+ case "medium":
+ case "1":
+ severity = Report_1.ReportSeverity.Medium;
+ break;
+ case "high":
+ case "2":
+ severity = Report_1.ReportSeverity.High;
+ break;
+ case "critical":
+ case "3":
+ severity = Report_1.ReportSeverity.Critical;
+ break;
+ case "fatal":
+ case "4":
+ severity = Report_1.ReportSeverity.Fatal;
+ break;
+ default:
+ severity = Report_1.ReportSeverity.Medium;
+ break;
+ }
+ let reportError = {
+ message: req.body.error.message,
+ stacktrace: req.body.error.stacktrace,
+ logs: req.body.error.logs ?? null,
+ potentialFix: null
+ };
+ let systemInfo = req.body.systemInfo;
+ let report = {
+ id: new UUID_1.default(),
+ service: req.body.service,
+ time: new Date(req.body.time),
+ severity,
+ response: Report_1.ReportResponse.None,
+ error: reportError,
+ systemInfo
+ };
+ ReportEndpoint.reports.push(report);
+ (0, node_fs_1.writeFileSync)(AutoreportBase_1.default.getRoot() + "/data/reports.json", JSON.stringify(ReportEndpoint.reports));
+ let notification = new Notification_1.default(report);
+ notification.send().then(() => {
+ res.status(201).json({
+ code: 201,
+ message: "Created."
+ });
+ });
+ }
+ static get(req, res) {
+ if (!Authentication_1.default.checkAuthentication(req))
+ return res.redirect("/oauth2/start");
+ if ([null, undefined, ""].includes(req.query.id)) {
+ return res.status(400).json({
+ code: 400,
+ message: "An ID must be provided."
+ });
+ }
+ if (!ReportEndpoint.reports.some(report => report.id === req.query.id)) {
+ return res.status(404).json({
+ code: 404,
+ message: "Report with that ID does not exist."
+ });
+ }
+ res.status(200).json(ReportEndpoint.reports.find(report => report.id === req.query.id));
+ }
+ static getMany(req, res) {
+ if (!Authentication_1.default.checkAuthentication(req))
+ return res.redirect("/oauth2/start");
+ let page = parseInt(req.query.page ?? 0);
+ let size = parseInt(req.query.size ?? 10);
+ if (isNaN(page)) {
+ return res.status(400).json({
+ code: 400,
+ message: "Page must be a number."
+ });
+ }
+ if (isNaN(size)) {
+ return res.status(400).json({
+ code: 400,
+ message: "Size must be a number."
+ });
+ }
+ // task: split the array into chunks of `size`
+ // good luck <3
+ let reportsRequested = ReportEndpoint.reports.slice((size * page), size);
+ res.status(200).json({
+ reports: reportsRequested,
+ page: page,
+ pageCount: Math.ceil(ReportEndpoint.reports.length / size)
+ });
+ }
+ static patch(req, res) {
+ if (!Authentication_1.default.checkAuthentication(req))
+ return res.redirect("/oauth2/start");
+ if ([null, undefined, ""].includes(req.query.id) ||
+ [null, undefined, ""].includes(req.query.response)) {
+ return res.status(400).json({
+ code: 400,
+ message: "Report infomation is missing."
+ });
+ }
+ if (!ReportEndpoint.reports.some(report => report.id === req.query.id)) {
+ return res.status(404).json({
+ code: 404,
+ message: "That report does not exist."
+ });
+ }
+ let reportIndex = ReportEndpoint.reports.findIndex(report => report.id === req.query.id);
+ let response;
+ switch (req.query.response.toString().toLowerCase()) {
+ case "none":
+ case "0":
+ response = Report_1.ReportResponse.None;
+ break;
+ case "acknowledged":
+ case "1":
+ response = Report_1.ReportResponse.Acknowledged;
+ break;
+ case "ignored":
+ case "2":
+ response = Report_1.ReportResponse.Ignored;
+ break;
+ case "stfu":
+ case "3":
+ response = Report_1.ReportResponse.STFU;
+ break;
+ default:
+ response = Report_1.ReportResponse.None;
+ break;
+ }
+ ReportEndpoint.reports[reportIndex].response = response;
+ (0, node_fs_1.writeFileSync)(AutoreportBase_1.default.getRoot() + "/data/reports.json", JSON.stringify(ReportEndpoint.reports));
+ res.status(200).json({
+ code: 200,
+ message: "Updated."
+ });
+ }
+}
+exports.ReportEndpoint = ReportEndpoint;
+ReportEndpoint.reports = JSON.parse((0, node_fs_1.readFileSync)("./data/reports.json").toString());
+//# sourceMappingURL=API.js.map \ No newline at end of file
diff --git a/build/core/API.js.map b/build/core/API.js.map
new file mode 100644
index 0000000..ad10c58
--- /dev/null
+++ b/build/core/API.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"API.js","sourceRoot":"","sources":["../../src/core/API.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA8C;AAC9C,sEAA8C;AAC9C,4CAAsH;AACtH,qCAAoD;AACpD,yDAAiC;AACjC,kEAA0C;AAE1C,MAAM,WAAY,SAAQ,wBAAc;CAAG;AAE3C,MAAa,cAAe,SAAQ,WAAW;IAGpC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG;QAC1B,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACxB,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,KAAK;SACjB,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG;QACvB,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;YACpD,CAAC,IAAI,EAAE,SAAS,EAAE,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QAAQ,CAAC;QACxD,IAAA,uBAAa,EAAC,wBAAc,CAAC,OAAO,EAAE,GAAG,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAEvG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,UAAU;SACtB,CAAC,CAAC;IACP,CAAC;;AA7ML,wCA8MC;AA7MkB,sBAAO,GAAa,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC"} \ No newline at end of file
diff --git a/build/core/Authentication.js b/build/core/Authentication.js
new file mode 100644
index 0000000..d0606f6
--- /dev/null
+++ b/build/core/Authentication.js
@@ -0,0 +1,86 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const AutoreportBase_1 = __importDefault(require("./AutoreportBase"));
+const axios_1 = __importDefault(require("axios"));
+const node_fs_1 = require("node:fs");
+const crypto_1 = require("crypto");
+class Authentication extends AutoreportBase_1.default {
+ static getToken(token) {
+ let tokens = JSON.parse((0, node_fs_1.readFileSync)(AutoreportBase_1.default.getRoot() + "/data/tokens.json").toString());
+ if (Object.keys(tokens).includes(token) && new Date(tokens[token].date).getTime() - new Date().getTime() <= 31000000) {
+ return tokens[token].info;
+ }
+ else {
+ return false;
+ }
+ }
+ static saveToken(userInfo) {
+ let tokens = JSON.parse((0, node_fs_1.readFileSync)(AutoreportBase_1.default.getRoot() + "/data/tokens.json").toString());
+ let token = (0, crypto_1.randomBytes)(64).toString("base64url");
+ tokens[token] = {
+ date: new Date().getTime(),
+ info: userInfo
+ };
+ (0, node_fs_1.writeFileSync)(AutoreportBase_1.default.getRoot() + "/data/tokens.json", JSON.stringify(tokens));
+ return token;
+ }
+ static startFlow(req, res) {
+ res.redirect(`${AutoreportBase_1.default.config.authentication.server}/api/rest/oauth2/auth?client_id=${AutoreportBase_1.default.config.authentication.id}&response_type=code&redirect_uri=${AutoreportBase_1.default.config.authentication.redirect}&scope=Hub&request_credentials=default&access_type=offline`);
+ }
+ static checkAuthentication(req) {
+ let _cookies = req.headers.cookie ?? "";
+ let _tokens = _cookies.split(";").map(i => i.trim().split("=")).filter(i => i[0] === "AutoreportToken");
+ let __tokens = _tokens[0] ?? [];
+ let token = __tokens[1] ?? null;
+ return !(!token || !this.getToken(token));
+ }
+ static async callback(req, res) {
+ if (!req.query.code) {
+ res.redirect("/");
+ }
+ let token = (await axios_1.default.post(`${AutoreportBase_1.default.config.authentication.server}/api/rest/oauth2/token`, `grant_type=authorization_code&redirect_uri=${encodeURIComponent(AutoreportBase_1.default.config.authentication.redirect)}&code=${req.query.code}`, {
+ headers: {
+ 'Authorization': `Basic ${Buffer.from(`${AutoreportBase_1.default.config.authentication.id}:${AutoreportBase_1.default.config.authentication.secret}`).toString("base64")}`,
+ 'Accept': "application/json",
+ 'Content-Type': "application/x-www-form-urlencoded"
+ }
+ })).data.access_token;
+ let userInfo = (await axios_1.default.get(`${AutoreportBase_1.default.config.authentication.server}/api/rest/users/me`, {
+ headers: {
+ 'Authorization': `Bearer ${token}`,
+ 'Accept': "application/json"
+ }
+ })).data;
+ let userToken = Authentication.saveToken(userInfo);
+ res.cookie('AutoreportToken', userToken, { maxAge: 31000000, httpOnly: true });
+ res.redirect("/");
+ }
+ static testEndpoint(req, res) {
+ if (Authentication.checkAuthentication(req)) {
+ res.send("Authenticated");
+ }
+ else {
+ res.send("NOT authenticated");
+ }
+ }
+ static protectedAPI(req, res, next) {
+ if ([null, undefined, ""].includes(req.get("authorization"))) {
+ return res.status(401).json({
+ code: 401,
+ message: "Please provide an Authorization header."
+ });
+ }
+ if (req.get("authorization") !== AutoreportBase_1.default.config.api.token) {
+ return res.status(403).json({
+ code: 403,
+ message: "You do not have permission to use this endpoint."
+ });
+ }
+ next();
+ }
+}
+exports.default = Authentication;
+//# sourceMappingURL=Authentication.js.map \ No newline at end of file
diff --git a/build/core/Authentication.js.map b/build/core/Authentication.js.map
new file mode 100644
index 0000000..6f7d5a6
--- /dev/null
+++ b/build/core/Authentication.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"Authentication.js","sourceRoot":"","sources":["../../src/core/Authentication.ts"],"names":[],"mappings":";;;;;AAAA,sEAA8C;AAC9C,kDAA0B;AAC1B,qCAAsD;AACtD,mCAAqC;AAErC,MAAqB,cAAe,SAAQ,wBAAc;IAC/C,MAAM,CAAC,QAAQ,CAAC,KAAK;QACxB,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,wBAAc,CAAC,OAAO,EAAE,GAAG,mBAAmB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEjG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,QAAQ,EAAE;YAClH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;SAC7B;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,QAAQ;QAC7B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,wBAAc,CAAC,OAAO,EAAE,GAAG,mBAAmB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjG,IAAI,KAAK,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAElD,MAAM,CAAC,KAAK,CAAC,GAAG;YACZ,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO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CAAC,eAAe,CAAC,CAAC;SAC7B;aAAM;YACH,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;SACjC;IACL,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;QACrC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE;YAC1D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACxB,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,yCAAyC;aACrD,CAAC,CAAC;SACN;QAED,IAAI,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,wBAAc,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE;YAC9D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAE;gBACzB,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,kDAAkD;aAC9D,CAAC,CAAC;SACN;QAED,IAAI,EAAE,CAAC;IACX,CAAC;CACJ;AAvFD,iCAuFC"} \ No newline at end of file
diff --git a/build/core/Autoreport.js b/build/core/Autoreport.js
new file mode 100644
index 0000000..9fa6469
--- /dev/null
+++ b/build/core/Autoreport.js
@@ -0,0 +1,86 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ var desc = Object.getOwnPropertyDescriptor(m, k);
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+ desc = { enumerable: true, get: function() { return m[k]; } };
+ }
+ Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const AutoreportBase_1 = __importDefault(require("./AutoreportBase"));
+const express_1 = __importDefault(require("express"));
+const Authentication_1 = __importDefault(require("./Authentication"));
+const node_fs_1 = require("node:fs");
+const API = __importStar(require("./API"));
+class Autoreport extends AutoreportBase_1.default {
+ constructor() {
+ const app = (0, express_1.default)();
+ app.use(express_1.default.static(AutoreportBase_1.default.getRoot() + "/assets"));
+ app.use(express_1.default.json());
+ app.set('view engine', 'ejs');
+ app.get("/", (req, res) => {
+ if (!Authentication_1.default.checkAuthentication(req))
+ return res.redirect("/oauth2/start");
+ let reports = JSON.parse((0, node_fs_1.readFileSync)("./data/reports.json").toString());
+ res.render("index", { reports });
+ });
+ app.get("/oauth2/start", (req, res) => {
+ Authentication_1.default.startFlow(req, res);
+ });
+ app.get("/oauth2/callback", (req, res) => {
+ Authentication_1.default.callback(req, res);
+ });
+ app.post("/api/reports/refresh", (req, res) => {
+ API.ReportEndpoint.refresh(req, res);
+ });
+ // API methods (public)
+ app.get("/api/report", (req, res) => {
+ API.ReportEndpoint.get(req, res);
+ });
+ app.get("/api/reports", (req, res) => {
+ API.ReportEndpoint.getMany(req, res);
+ });
+ // API methods (private, need privateauth.equestria.dev authentication)
+ app.patch("/api/report", (req, res) => {
+ API.ReportEndpoint.patch(req, res);
+ });
+ // API methods (private, need token authentication)
+ app.post("/api/report", Authentication_1.default.protectedAPI, (req, res) => {
+ API.ReportEndpoint.post(req, res);
+ });
+ app.get("/oauth2/test", (req, res) => {
+ Authentication_1.default.testEndpoint(req, res);
+ });
+ app.listen(34512);
+ // To setup port forwarding:
+ // - Ctrl+Shift+K/Cmd+Shift+K
+ // - "Forward port"
+ // - "34512:34512"
+ // - You can now access it from http://localhost:34512
+ console.log("Listening!");
+ console.log(" - Public URL: http://localhost:34512");
+ console.log(" - OAuth2 test: http://localhost:34512/oauth2/start");
+ super();
+ }
+}
+exports.default = Autoreport;
+//# sourceMappingURL=Autoreport.js.map \ No newline at end of file
diff --git a/build/core/Autoreport.js.map b/build/core/Autoreport.js.map
new file mode 100644
index 0000000..46c479e
--- /dev/null
+++ b/build/core/Autoreport.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"Autoreport.js","sourceRoot":"","sources":["../../src/core/Autoreport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAA8C;AAC9C,sDAA8B;AAC9B,sEAA8C;AAE9C,qCAAqC;AAErC,2CAA6B;AAE7B,MAAqB,UAAW,SAAQ,wBAAc;IAClD;QACI,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QAEtB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,wBAAc,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;QAC9D,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAE9B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACtB,IAAI,CAAC,wBAAc,CAAC,mBAAmB,CAAC,GAAG,CAAC;gBAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;YAEnF,IAAI,OAAO,GAAa,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;YAElF,GAAG,CAAC,MAAM,CAAC,OA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AAE,EAAE;YAC9D,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACjC,wBAAc,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAElB,4BAA4B;QAC5B,6BAA6B;QAC7B,mBAAmB;QACnB,kBAAkB;QAClB,sDAAsD;QAEtD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;QAEpE,KAAK,EAAE,CAAC;IACZ,CAAC;CACJ;AAjED,6BAiEC"} \ No newline at end of file
diff --git a/build/core/AutoreportBase.js b/build/core/AutoreportBase.js
new file mode 100644
index 0000000..17d35e2
--- /dev/null
+++ b/build/core/AutoreportBase.js
@@ -0,0 +1,15 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const yaml_1 = __importDefault(require("yaml"));
+const node_fs_1 = require("node:fs");
+class AutoreportBase {
+ static getRoot() {
+ return __dirname + "/../../";
+ }
+}
+exports.default = AutoreportBase;
+AutoreportBase.config = yaml_1.default.parse((0, node_fs_1.readFileSync)(AutoreportBase.getRoot() + "/config.yml").toString());
+//# sourceMappingURL=AutoreportBase.js.map \ No newline at end of file
diff --git a/build/core/AutoreportBase.js.map b/build/core/AutoreportBase.js.map
new file mode 100644
index 0000000..37f75a5
--- /dev/null
+++ b/build/core/AutoreportBase.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"AutoreportBase.js","sourceRoot":"","sources":["../../src/core/AutoreportBase.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,qCAAuC;AAEvC,MAAqB,cAAc;IACxB,MAAM,CAAC,OAAO;QACjB,OAAO,SAAS,GAAG,SAAS,CAAC;IACjC,CAAC;;AAHL,iCAMC;AADiB,qBAAM,GAAG,cAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,cAAc,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC"} \ No newline at end of file
diff --git a/build/core/Notification.js b/build/core/Notification.js
new file mode 100644
index 0000000..dcb09cf
--- /dev/null
+++ b/build/core/Notification.js
@@ -0,0 +1,51 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const AutoreportBase_1 = __importDefault(require("./AutoreportBase"));
+const Report_1 = require("../types/Report");
+class Notification extends AutoreportBase_1.default {
+ constructor(report) {
+ super();
+ this.service = report.service;
+ this.report = report;
+ }
+ async send() {
+ let message;
+ switch (this.report.severity) {
+ case Report_1.ReportSeverity.Low:
+ message = "Service " + this.service + " has encountered a minor error";
+ break;
+ case Report_1.ReportSeverity.Medium:
+ message = "Service " + this.service + " has encountered an error";
+ break;
+ case Report_1.ReportSeverity.High:
+ message = "Service " + this.service + " has encountered a major error";
+ break;
+ case Report_1.ReportSeverity.Critical:
+ message = "Service " + this.service + " has encountered a critical error";
+ break;
+ case Report_1.ReportSeverity.Fatal:
+ message = "Service " + this.service + " has encountered a fatal error";
+ break;
+ }
+ await fetch("https://" + AutoreportBase_1.default.config.notifications.server, {
+ method: "POST",
+ body: JSON.stringify({
+ topic: AutoreportBase_1.default.config.notifications.topic,
+ message,
+ title: "A service encountered an error",
+ tags: ["crash", "service:" + this.service],
+ priority: 3,
+ actions: [{ "action": "view", "label": "Open report", "url": AutoreportBase_1.default.config.base + "/#/report/" + this.report.id }]
+ }),
+ headers: {
+ "Authorization": "Basic " + Buffer.from(AutoreportBase_1.default.config.notifications.user + ":" + AutoreportBase_1.default.config.notifications.password).toString("base64"),
+ "Content-Type": "application/json"
+ }
+ });
+ }
+}
+exports.default = Notification;
+//# sourceMappingURL=Notification.js.map \ No newline at end of file
diff --git a/build/core/Notification.js.map b/build/core/Notification.js.map
new file mode 100644
index 0000000..2130dc5
--- /dev/null
+++ b/build/core/Notification.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"Notification.js","sourceRoot":"","sources":["../../src/core/Notification.ts"],"names":[],"mappings":";;;;;AAAA,sEAA8C;AAC9C,4CAAuD;AAEvD,MAAqB,YAAa,SAAQ,wBAAc;IAIpD,YAAY,MAAc;QACtB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,IAAI;QACb,IAAI,OAAe,CAAC;QAEpB,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC1B,KAAK,uBAAc,CAAC,GAAG;gBAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,GAAG,gCAAgC,CAAC;gBAAC,MAAM;YACvG,KAAK,uBAAc,CAAC,MAAM;gBAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,GAAG,2BAA2B,CAAC;gBAAC,MAAM;YACrG,KAAK,uBAAc,CAAC,IAAI;gBAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,GAAG,gCAAgC,CAAC;gBAAC,MAAM;YACxG,KAAK,uBAAc,CAAC,QAAQ;gBAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,GAAG,mCAAmC,CAAC;gBAAC,MAAM;YAC/G,KAAK,uBAAc,CAAC,KAAK;gBAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,GAAG,gCAAgC,CAAC;gBAAC,MAAM;SAC5G;QAED,MAAM,KAAK,CAAC,UAAU,GAAG,wBAAc,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACjB,KAAK,EAAE,wBAAc,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK;gBAChD,OAAO;gBACP,KAAK,EAAE,gCAAgC;gBACvC,IAAI,EAAE,CAAE,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC,OAAO,CAAE;gBAC5C,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,wBAAc,CAAC,MAAM,CAAC,IAAI,GAAG,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;aAC7H,CAAC;YACF,OAAO,EAAE;gBACL,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,wBAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,GAAG,GAAG,GAAG,wBAAc,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACzJ,cAAc,EAAE,kBAAkB;aACrC;SACJ,CAAC,CAAA;IACN,CAAC;CACJ;AArCD,+BAqCC"} \ No newline at end of file
diff --git a/build/index.js b/build/index.js
new file mode 100644
index 0000000..bfacbbe
--- /dev/null
+++ b/build/index.js
@@ -0,0 +1,33 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const Autoreport_1 = __importDefault(require("./core/Autoreport"));
+new Autoreport_1.default();
+// you need to add topic "crashes" to ntfy (make sure you select use another server)
+// mhm!
+// done
+// so when we'll test it it should work
+// mhm!
+// don't we need ejs?
+// probably, installing it
+// epic hehe
+// installed
+// is there a module you use to interface with the notifications?
+// it's just HTTP requests
+// okay, so here's the requirements
+// express, superagent, why not axios instead?
+// sure hehe
+// installed all that
+// epic, server time
+// oh wait we need dotenv to store the api token in .env
+// why not just use a config file
+// don't want to push the config file to the repo
+// add it to .gitignore
+// which i currently cannot see
+// because it doesn't exist -c-
+// oh
+// trying to not have a coughing fit while programming rn
+// .c.
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/build/index.js.map b/build/index.js.map
new file mode 100644
index 0000000..c4e4868
--- /dev/null
+++ b/build/index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,mEAA2C;AAE3C,IAAI,oBAAU,EAAE,CAAC;AAEjB,oFAAoF;AACpF,OAAO;AACP,OAAO;AACP,uCAAuC;AACvC,OAAO;AAGP,qBAAqB;AACrB,0BAA0B;AAC1B,YAAY;AACZ,YAAY;AAEZ,iEAAiE;AACjE,0BAA0B;AAC1B,mCAAmC;AACnC,8CAA8C;AAC9C,YAAY;AACZ,qBAAqB;AACrB,oBAAoB;AACpB,wDAAwD;AACxD,iCAAiC;AACjC,iDAAiD;AACjD,uBAAuB;AACvB,+BAA+B;AAC/B,+BAA+B;AAC/B,KAAK;AACL,yDAAyD;AACzD,MAAM"} \ No newline at end of file
diff --git a/build/types/Report.js b/build/types/Report.js
new file mode 100644
index 0000000..727abd5
--- /dev/null
+++ b/build/types/Report.js
@@ -0,0 +1,37 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ProcessState = exports.ReportResponse = exports.ReportSeverity = void 0;
+var ReportSeverity;
+(function (ReportSeverity) {
+ // Low - something went wrong where it shouldn't, but it's not that bad
+ // Medium - something went wrong where it shouldn't, should be looked into
+ // High - something went wrong where it shouldn't, must be looked into
+ // Critical - something went wrong where it really shouldn't of, must be looked into right that moment
+ // Fatal - something went so wrong that the service will not recover without help, must be looked into right that moment
+ ReportSeverity[ReportSeverity["Low"] = 0] = "Low";
+ ReportSeverity[ReportSeverity["Medium"] = 1] = "Medium";
+ ReportSeverity[ReportSeverity["High"] = 2] = "High";
+ ReportSeverity[ReportSeverity["Critical"] = 3] = "Critical";
+ ReportSeverity[ReportSeverity["Fatal"] = 4] = "Fatal";
+})(ReportSeverity = exports.ReportSeverity || (exports.ReportSeverity = {}));
+var ReportResponse;
+(function (ReportResponse) {
+ // None - not been responded to yet
+ // Acknowledged - report has been acknowledged
+ // Ignored - report has been ignored
+ // STFU - "Shut The Fuck Up", we're already aware of this please stop telling us
+ ReportResponse[ReportResponse["None"] = 0] = "None";
+ ReportResponse[ReportResponse["Acknowledged"] = 1] = "Acknowledged";
+ ReportResponse[ReportResponse["Ignored"] = 2] = "Ignored";
+ ReportResponse[ReportResponse["STFU"] = 3] = "STFU";
+})(ReportResponse = exports.ReportResponse || (exports.ReportResponse = {}));
+var ProcessState;
+(function (ProcessState) {
+ ProcessState[ProcessState["Stopped"] = 0] = "Stopped";
+ ProcessState[ProcessState["Running"] = 1] = "Running";
+ ProcessState[ProcessState["Starting"] = 2] = "Starting";
+ ProcessState[ProcessState["Idle"] = 3] = "Idle";
+ ProcessState[ProcessState["Blocked"] = 4] = "Blocked";
+ ProcessState[ProcessState["Stopping"] = 5] = "Stopping";
+})(ProcessState = exports.ProcessState || (exports.ProcessState = {}));
+//# sourceMappingURL=Report.js.map \ No newline at end of file
diff --git a/build/types/Report.js.map b/build/types/Report.js.map
new file mode 100644
index 0000000..6fd7c13
--- /dev/null
+++ b/build/types/Report.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"Report.js","sourceRoot":"","sources":["../../src/types/Report.ts"],"names":[],"mappings":";;;AAkCA,IAAY,cAYX;AAZD,WAAY,cAAc;IACtB,4EAA4E;IAC5E,4EAA4E;IAC5E,0EAA0E;IAC1E,sGAAsG;IACtG,2HAA2H;IAE3H,iDAAG,CAAA;IACH,uDAAM,CAAA;IACN,mDAAI,CAAA;IACJ,2DAAQ,CAAA;IACR,qDAAK,CAAA;AACT,CAAC,EAZW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAYzB;AAED,IAAY,cAUX;AAVD,WAAY,cAAc;IACtB,2CAA2C;IAC3C,8CAA8C;IAC9C,yCAAyC;IACzC,wFAAwF;IAExF,mDAAI,CAAA;IACJ,mEAAY,CAAA;IACZ,yDAAO,CAAA;IACP,mDAAI,CAAA;AACR,CAAC,EAVW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAUzB;AAED,IAAY,YAOX;AAPD,WAAY,YAAY;IACpB,qDAAO,CAAA;IACP,qDAAO,CAAA;IACP,uDAAQ,CAAA;IACR,+CAAI,CAAA;IACJ,qDAAO,CAAA;IACP,uDAAQ,CAAA;AACZ,CAAC,EAPW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAOvB"} \ No newline at end of file
diff --git a/build/types/UUID.js b/build/types/UUID.js
new file mode 100644
index 0000000..4205099
--- /dev/null
+++ b/build/types/UUID.js
@@ -0,0 +1,13 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const uuid_v4_1 = __importDefault(require("uuid-v4"));
+class UUID extends String {
+ constructor() {
+ super((0, uuid_v4_1.default)());
+ }
+}
+exports.default = UUID;
+//# sourceMappingURL=UUID.js.map \ No newline at end of file
diff --git a/build/types/UUID.js.map b/build/types/UUID.js.map
new file mode 100644
index 0000000..cad9716
--- /dev/null
+++ b/build/types/UUID.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"UUID.js","sourceRoot":"","sources":["../../src/types/UUID.ts"],"names":[],"mappings":";;;;;AAAA,sDAA2B;AAE3B,MAAqB,IAAK,SAAQ,MAAM;IACpC;QACI,KAAK,CAAC,IAAA,iBAAI,GAAE,CAAC,CAAC;IAClB,CAAC;CACJ;AAJD,uBAIC"} \ No newline at end of file