@abyss-project/console 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +34 -0
- package/README.md +2 -0
- package/USAGE_EXAMPLES.md +257 -0
- package/dist/api/application-cron-task.admin.api.d.ts +10 -0
- package/dist/api/application-cron-task.admin.api.js +40 -0
- package/dist/api/application-cron-task.api.d.ts +10 -0
- package/dist/api/application-cron-task.api.js +40 -0
- package/dist/api/application-event.admin.api.d.ts +4 -0
- package/dist/api/application-event.admin.api.js +16 -0
- package/dist/api/application-event.api.d.ts +8 -0
- package/dist/api/application-event.api.js +32 -0
- package/dist/api/application-log.admin.api.d.ts +3 -0
- package/dist/api/application-log.admin.api.js +12 -0
- package/dist/api/application-log.api.d.ts +4 -0
- package/dist/api/application-log.api.js +16 -0
- package/dist/api/application-sentinel.admin.api.d.ts +9 -0
- package/dist/api/application-sentinel.admin.api.js +36 -0
- package/dist/api/application-sentinel.api.d.ts +10 -0
- package/dist/api/application-sentinel.api.js +40 -0
- package/dist/api/application-stats.admin.api.d.ts +3 -0
- package/dist/api/application-stats.admin.api.js +12 -0
- package/dist/api/application-stats.api.d.ts +4 -0
- package/dist/api/application-stats.api.js +16 -0
- package/dist/api/application-webhook-history.admin.api.d.ts +3 -0
- package/dist/api/application-webhook-history.admin.api.js +12 -0
- package/dist/api/application-webhook-history.api.d.ts +3 -0
- package/dist/api/application-webhook-history.api.js +12 -0
- package/dist/api/application-webhook.admin.api.d.ts +7 -0
- package/dist/api/application-webhook.admin.api.js +28 -0
- package/dist/api/application-webhook.api.d.ts +7 -0
- package/dist/api/application-webhook.api.js +28 -0
- package/dist/api/application.admin.api.d.ts +7 -0
- package/dist/api/application.admin.api.js +28 -0
- package/dist/api/application.api.d.ts +10 -0
- package/dist/api/application.api.js +40 -0
- package/dist/api/domain-verification.admin.api.d.ts +2 -0
- package/dist/api/domain-verification.admin.api.js +9 -0
- package/dist/api/domain-verification.api.d.ts +7 -0
- package/dist/api/domain-verification.api.js +28 -0
- package/dist/api/hourly-metrics.api.d.ts +2 -0
- package/dist/api/hourly-metrics.api.js +8 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +21 -0
- package/dist/api/infrastructure.admin.api.d.ts +3 -0
- package/dist/api/infrastructure.admin.api.js +12 -0
- package/dist/api/metrics.api.d.ts +4 -0
- package/dist/api/metrics.api.js +16 -0
- package/dist/api/monitor.api.d.ts +2 -0
- package/dist/api/monitor.api.js +8 -0
- package/dist/api/report.admin.api.d.ts +2 -0
- package/dist/api/report.admin.api.js +9 -0
- package/dist/api/workflow.admin.api.d.ts +8 -0
- package/dist/api/workflow.admin.api.js +34 -0
- package/dist/api/workflow.api.d.ts +15 -0
- package/dist/api/workflow.api.js +62 -0
- package/dist/frameworks/express/decorators.d.ts +52 -0
- package/dist/frameworks/express/decorators.js +163 -0
- package/dist/frameworks/express/index.d.ts +17 -0
- package/dist/frameworks/express/index.js +173 -0
- package/dist/frameworks/express/metadata.d.ts +9 -0
- package/dist/frameworks/express/metadata.js +12 -0
- package/dist/frameworks/index.d.ts +1 -0
- package/dist/frameworks/index.js +17 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +163 -0
- package/dist/middlewares/context.middleware.d.ts +12 -0
- package/dist/middlewares/context.middleware.js +39 -0
- package/dist/middlewares/index.d.ts +3 -0
- package/dist/middlewares/index.js +19 -0
- package/dist/middlewares/logger-endpoint.middleware.d.ts +5 -0
- package/dist/middlewares/logger-endpoint.middleware.js +86 -0
- package/dist/middlewares/logger-setup.middleware.d.ts +5 -0
- package/dist/middlewares/logger-setup.middleware.js +16 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +17 -0
- package/dist/models/logger.model.d.ts +61 -0
- package/dist/models/logger.model.js +201 -0
- package/dist/models/stats-publisher.model.d.ts +20 -0
- package/dist/models/stats-publisher.model.js +113 -0
- package/dist/types/dto/domain-verification.dto.d.ts +19 -0
- package/dist/types/dto/domain-verification.dto.js +2 -0
- package/dist/types/dto/index.d.ts +1 -0
- package/dist/types/dto/index.js +17 -0
- package/dist/types/enum/api-error.enum.d.ts +20 -0
- package/dist/types/enum/api-error.enum.js +25 -0
- package/dist/types/enum/api-method.enum.d.ts +7 -0
- package/dist/types/enum/api-method.enum.js +11 -0
- package/dist/types/enum/application-alert-type.enum.d.ts +5 -0
- package/dist/types/enum/application-alert-type.enum.js +9 -0
- package/dist/types/enum/application-sentinel-type.enum.d.ts +5 -0
- package/dist/types/enum/application-sentinel-type.enum.js +9 -0
- package/dist/types/enum/application-stats-type.enum.d.ts +5 -0
- package/dist/types/enum/application-stats-type.enum.js +9 -0
- package/dist/types/enum/application-webhook-scope.enum.d.ts +4 -0
- package/dist/types/enum/application-webhook-scope.enum.js +8 -0
- package/dist/types/enum/index.d.ts +1 -0
- package/dist/types/enum/index.js +17 -0
- package/dist/types/enum/log-level.enum.d.ts +6 -0
- package/dist/types/enum/log-level.enum.js +10 -0
- package/dist/types/enum/log-scenario.enum.d.ts +5 -0
- package/dist/types/enum/log-scenario.enum.js +9 -0
- package/dist/types/enum/time-period.enum.d.ts +0 -0
- package/dist/types/enum/time-period.enum.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/interface/api/index.d.ts +13 -0
- package/dist/types/interface/api/index.js +29 -0
- package/dist/types/interface/api/requests/application-cron-task.admin.request.d.ts +50 -0
- package/dist/types/interface/api/requests/application-cron-task.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-cron-task.request.d.ts +61 -0
- package/dist/types/interface/api/requests/application-cron-task.request.js +2 -0
- package/dist/types/interface/api/requests/application-event.admin.request.d.ts +16 -0
- package/dist/types/interface/api/requests/application-event.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-event.request.d.ts +50 -0
- package/dist/types/interface/api/requests/application-event.request.js +2 -0
- package/dist/types/interface/api/requests/application-log.admin.request.d.ts +19 -0
- package/dist/types/interface/api/requests/application-log.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-log.request.d.ts +59 -0
- package/dist/types/interface/api/requests/application-log.request.js +2 -0
- package/dist/types/interface/api/requests/application-sentinel.admin.request.d.ts +52 -0
- package/dist/types/interface/api/requests/application-sentinel.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-sentinel.request.d.ts +71 -0
- package/dist/types/interface/api/requests/application-sentinel.request.js +2 -0
- package/dist/types/interface/api/requests/application-stats.admin.request.d.ts +13 -0
- package/dist/types/interface/api/requests/application-stats.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-stats.request.d.ts +31 -0
- package/dist/types/interface/api/requests/application-stats.request.js +2 -0
- package/dist/types/interface/api/requests/application-webhook-history.admin.request.d.ts +16 -0
- package/dist/types/interface/api/requests/application-webhook-history.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-webhook-history.request.d.ts +21 -0
- package/dist/types/interface/api/requests/application-webhook-history.request.js +2 -0
- package/dist/types/interface/api/requests/application-webhook.admin.request.d.ts +39 -0
- package/dist/types/interface/api/requests/application-webhook.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application-webhook.request.d.ts +45 -0
- package/dist/types/interface/api/requests/application-webhook.request.js +2 -0
- package/dist/types/interface/api/requests/application.admin.request.d.ts +23 -0
- package/dist/types/interface/api/requests/application.admin.request.js +2 -0
- package/dist/types/interface/api/requests/application.request.d.ts +64 -0
- package/dist/types/interface/api/requests/application.request.js +2 -0
- package/dist/types/interface/api/requests/domain-verification.admin.request.d.ts +5 -0
- package/dist/types/interface/api/requests/domain-verification.admin.request.js +2 -0
- package/dist/types/interface/api/requests/domain-verification.request.d.ts +29 -0
- package/dist/types/interface/api/requests/domain-verification.request.js +2 -0
- package/dist/types/interface/api/requests/hourly-metrics.request.d.ts +10 -0
- package/dist/types/interface/api/requests/hourly-metrics.request.js +2 -0
- package/dist/types/interface/api/requests/infrastructure.admin.request.d.ts +4 -0
- package/dist/types/interface/api/requests/infrastructure.admin.request.js +2 -0
- package/dist/types/interface/api/requests/metrics.admin.request.d.ts +14 -0
- package/dist/types/interface/api/requests/metrics.admin.request.js +2 -0
- package/dist/types/interface/api/requests/metrics.request.d.ts +23 -0
- package/dist/types/interface/api/requests/metrics.request.js +2 -0
- package/dist/types/interface/api/requests/report.admin.request.d.ts +6 -0
- package/dist/types/interface/api/requests/report.admin.request.js +2 -0
- package/dist/types/interface/api/requests/workflow.admin.request.d.ts +35 -0
- package/dist/types/interface/api/requests/workflow.admin.request.js +2 -0
- package/dist/types/interface/api/requests/workflow.request.d.ts +114 -0
- package/dist/types/interface/api/requests/workflow.request.js +2 -0
- package/dist/types/interface/api/responses/application-cron-task.admin.response.d.ts +30 -0
- package/dist/types/interface/api/responses/application-cron-task.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-cron-task.response.d.ts +30 -0
- package/dist/types/interface/api/responses/application-cron-task.response.js +2 -0
- package/dist/types/interface/api/responses/application-event.admin.response.d.ts +9 -0
- package/dist/types/interface/api/responses/application-event.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-event.response.d.ts +33 -0
- package/dist/types/interface/api/responses/application-event.response.js +2 -0
- package/dist/types/interface/api/responses/application-log.admin.response.d.ts +10 -0
- package/dist/types/interface/api/responses/application-log.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-log.response.d.ts +10 -0
- package/dist/types/interface/api/responses/application-log.response.js +2 -0
- package/dist/types/interface/api/responses/application-sentinel.admin.response.d.ts +26 -0
- package/dist/types/interface/api/responses/application-sentinel.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-sentinel.response.d.ts +33 -0
- package/dist/types/interface/api/responses/application-sentinel.response.js +2 -0
- package/dist/types/interface/api/responses/application-stats.admin.response.d.ts +6 -0
- package/dist/types/interface/api/responses/application-stats.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-stats.response.d.ts +10 -0
- package/dist/types/interface/api/responses/application-stats.response.js +2 -0
- package/dist/types/interface/api/responses/application-webhook-history.admin.response.d.ts +7 -0
- package/dist/types/interface/api/responses/application-webhook-history.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-webhook-history.response.d.ts +7 -0
- package/dist/types/interface/api/responses/application-webhook-history.response.js +2 -0
- package/dist/types/interface/api/responses/application-webhook.admin.response.d.ts +21 -0
- package/dist/types/interface/api/responses/application-webhook.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application-webhook.response.d.ts +21 -0
- package/dist/types/interface/api/responses/application-webhook.response.js +2 -0
- package/dist/types/interface/api/responses/application.admin.response.d.ts +34 -0
- package/dist/types/interface/api/responses/application.admin.response.js +2 -0
- package/dist/types/interface/api/responses/application.response.d.ts +130 -0
- package/dist/types/interface/api/responses/application.response.js +2 -0
- package/dist/types/interface/api/responses/domain-verification.admin.response.d.ts +6 -0
- package/dist/types/interface/api/responses/domain-verification.admin.response.js +2 -0
- package/dist/types/interface/api/responses/domain-verification.response.d.ts +29 -0
- package/dist/types/interface/api/responses/domain-verification.response.js +2 -0
- package/dist/types/interface/api/responses/hourly-metrics.response.d.ts +70 -0
- package/dist/types/interface/api/responses/hourly-metrics.response.js +2 -0
- package/dist/types/interface/api/responses/infrastructure.admin.response.d.ts +18 -0
- package/dist/types/interface/api/responses/infrastructure.admin.response.js +2 -0
- package/dist/types/interface/api/responses/metrics.admin.response.d.ts +19 -0
- package/dist/types/interface/api/responses/metrics.admin.response.js +2 -0
- package/dist/types/interface/api/responses/metrics.response.d.ts +29 -0
- package/dist/types/interface/api/responses/metrics.response.js +2 -0
- package/dist/types/interface/api/responses/monitor.response.d.ts +7 -0
- package/dist/types/interface/api/responses/monitor.response.js +2 -0
- package/dist/types/interface/api/responses/report.admin.response.d.ts +87 -0
- package/dist/types/interface/api/responses/report.admin.response.js +2 -0
- package/dist/types/interface/api/responses/workflow.admin.response.d.ts +24 -0
- package/dist/types/interface/api/responses/workflow.admin.response.js +2 -0
- package/dist/types/interface/api/responses/workflow.response.d.ts +54 -0
- package/dist/types/interface/api/responses/workflow.response.js +2 -0
- package/dist/types/interface/api/type-message/api-error.d.ts +8 -0
- package/dist/types/interface/api/type-message/api-error.js +2 -0
- package/dist/types/interface/api/type-message/base-order.d.ts +4 -0
- package/dist/types/interface/api/type-message/base-order.js +2 -0
- package/dist/types/interface/api/type-message/base-paginate.d.ts +10 -0
- package/dist/types/interface/api/type-message/base-paginate.js +2 -0
- package/dist/types/interface/api/type-message/response.d.ts +5 -0
- package/dist/types/interface/api/type-message/response.js +2 -0
- package/dist/types/interface/dto/application-sentinel-configuration.dto.d.ts +68 -0
- package/dist/types/interface/dto/application-sentinel-configuration.dto.js +4 -0
- package/dist/types/interface/dto/index.d.ts +2 -0
- package/dist/types/interface/dto/index.js +18 -0
- package/dist/types/interface/dto/webhook.dto.d.ts +27 -0
- package/dist/types/interface/dto/webhook.dto.js +2 -0
- package/dist/types/interface/index.d.ts +6 -0
- package/dist/types/interface/index.js +22 -0
- package/dist/types/interface/models/application-cron-task-history.model.d.ts +17 -0
- package/dist/types/interface/models/application-cron-task-history.model.js +2 -0
- package/dist/types/interface/models/application-cron-task.model.d.ts +14 -0
- package/dist/types/interface/models/application-cron-task.model.js +2 -0
- package/dist/types/interface/models/application-event.model.d.ts +19 -0
- package/dist/types/interface/models/application-event.model.js +2 -0
- package/dist/types/interface/models/application-hourly-metrics.model.d.ts +14 -0
- package/dist/types/interface/models/application-hourly-metrics.model.js +2 -0
- package/dist/types/interface/models/application-lifetime-metrics.model.d.ts +8 -0
- package/dist/types/interface/models/application-lifetime-metrics.model.js +2 -0
- package/dist/types/interface/models/application-log-endpoint.model.d.ts +20 -0
- package/dist/types/interface/models/application-log-endpoint.model.js +2 -0
- package/dist/types/interface/models/application-log.model.d.ts +23 -0
- package/dist/types/interface/models/application-log.model.js +2 -0
- package/dist/types/interface/models/application-sentinel-history.model.d.ts +16 -0
- package/dist/types/interface/models/application-sentinel-history.model.js +2 -0
- package/dist/types/interface/models/application-sentinel.model.d.ts +20 -0
- package/dist/types/interface/models/application-sentinel.model.js +2 -0
- package/dist/types/interface/models/application-stats.model.d.ts +14 -0
- package/dist/types/interface/models/application-stats.model.js +2 -0
- package/dist/types/interface/models/application-webhook-history.model.d.ts +22 -0
- package/dist/types/interface/models/application-webhook-history.model.js +2 -0
- package/dist/types/interface/models/application-webhook.model.d.ts +32 -0
- package/dist/types/interface/models/application-webhook.model.js +3 -0
- package/dist/types/interface/models/application.model.d.ts +19 -0
- package/dist/types/interface/models/application.model.js +2 -0
- package/dist/types/interface/models/domain-verification.model.d.ts +42 -0
- package/dist/types/interface/models/domain-verification.model.js +14 -0
- package/dist/types/interface/models/partition-optimization-history.model.d.ts +11 -0
- package/dist/types/interface/models/partition-optimization-history.model.js +2 -0
- package/dist/types/interface/models/project.model.d.ts +11 -0
- package/dist/types/interface/models/project.model.js +2 -0
- package/dist/types/interface/models/workflow-execution-step.model.d.ts +59 -0
- package/dist/types/interface/models/workflow-execution-step.model.js +12 -0
- package/dist/types/interface/models/workflow-execution.model.d.ts +76 -0
- package/dist/types/interface/models/workflow-execution.model.js +13 -0
- package/dist/types/interface/models/workflow-step.model.d.ts +106 -0
- package/dist/types/interface/models/workflow-step.model.js +44 -0
- package/dist/types/interface/models/workflow.model.d.ts +90 -0
- package/dist/types/interface/models/workflow.model.js +24 -0
- package/dist/typing-examples.d.ts +1 -0
- package/dist/typing-examples.js +48 -0
- package/dist/utils/alert.utils.d.ts +35 -0
- package/dist/utils/alert.utils.js +138 -0
- package/dist/utils/discord-webhook-log-formatter.utils.d.ts +48 -0
- package/dist/utils/discord-webhook-log-formatter.utils.js +332 -0
- package/dist/utils/error.utils.d.ts +15 -0
- package/dist/utils/error.utils.js +24 -0
- package/dist/utils/import.utils.d.ts +1 -0
- package/dist/utils/import.utils.js +7 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/json.utils.d.ts +1 -0
- package/dist/utils/json.utils.js +13 -0
- package/dist/utils/non-blocking-promise.utils.d.ts +2 -0
- package/dist/utils/non-blocking-promise.utils.js +11 -0
- package/package.json +49 -0
- package/tsconfig.json +105 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestContext = exports.createRequestContext = exports.contextMiddleware = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
let asyncHooks;
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
asyncHooks = require('async_hooks');
|
|
8
|
+
}
|
|
9
|
+
const store = new Map();
|
|
10
|
+
const asyncHook = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.createHook({
|
|
11
|
+
init: (asyncId, _, triggerAsyncId) => {
|
|
12
|
+
const existingEntry = store.get(triggerAsyncId);
|
|
13
|
+
if (existingEntry) {
|
|
14
|
+
store.set(asyncId, existingEntry);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
destroy: (asyncId) => {
|
|
18
|
+
if (store.has(asyncId)) {
|
|
19
|
+
store.delete(asyncId);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
asyncHook === null || asyncHook === void 0 ? void 0 : asyncHook.enable();
|
|
24
|
+
const contextMiddleware = (req, res, next) => {
|
|
25
|
+
const data = { headers: req.headers };
|
|
26
|
+
(0, exports.createRequestContext)(data);
|
|
27
|
+
next();
|
|
28
|
+
};
|
|
29
|
+
exports.contextMiddleware = contextMiddleware;
|
|
30
|
+
const createRequestContext = (data, requestId = (0, uuid_1.v4)()) => {
|
|
31
|
+
const requestInfo = { requestId, data };
|
|
32
|
+
store.set(asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.executionAsyncId(), requestInfo);
|
|
33
|
+
return requestInfo;
|
|
34
|
+
};
|
|
35
|
+
exports.createRequestContext = createRequestContext;
|
|
36
|
+
const getRequestContext = () => {
|
|
37
|
+
return store.get(asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.executionAsyncId());
|
|
38
|
+
};
|
|
39
|
+
exports.getRequestContext = getRequestContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context.middleware"), exports);
|
|
18
|
+
__exportStar(require("./logger-endpoint.middleware"), exports);
|
|
19
|
+
__exportStar(require("./logger-setup.middleware"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express-serve-static-core';
|
|
2
|
+
import { Logger } from '../models';
|
|
3
|
+
import { IMonitorLocals } from '../types';
|
|
4
|
+
export declare const CONTROLLER_FILE_ENDS_WITH: string;
|
|
5
|
+
export declare const loggerEndpointMiddleware: (logger: Logger, req: Request, res: Response<unknown, IMonitorLocals>, next: NextFunction, callback?: ((req: Request, res: Response<unknown, IMonitorLocals>, next: NextFunction) => Promise<void>) | undefined) => Promise<void>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loggerEndpointMiddleware = exports.CONTROLLER_FILE_ENDS_WITH = void 0;
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const context_middleware_1 = require("./context.middleware");
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const net_1 = __importDefault(require("net"));
|
|
11
|
+
const import_utils_1 = require("../utils/import.utils");
|
|
12
|
+
exports.CONTROLLER_FILE_ENDS_WITH = `.controller${(0, import_utils_1.extensionFileToImport)()}`;
|
|
13
|
+
const loggerEndpointMiddleware = async (logger, req, res, next, callback) => {
|
|
14
|
+
res.locals.timer = {
|
|
15
|
+
start: new Date(),
|
|
16
|
+
startTime: process.hrtime(),
|
|
17
|
+
};
|
|
18
|
+
const requestId = (0, context_middleware_1.getRequestContext)().requestId;
|
|
19
|
+
res.on('close', async () => {
|
|
20
|
+
var _a;
|
|
21
|
+
try {
|
|
22
|
+
res.locals.timer.durationToClose = getDurationInMilliseconds(res.locals.timer.startTime);
|
|
23
|
+
if (!res.locals.shouldNotPublishLog) {
|
|
24
|
+
const ips = [];
|
|
25
|
+
const forwardedFor = req.headers['x-forwarded-for'];
|
|
26
|
+
if (forwardedFor) {
|
|
27
|
+
if (Array.isArray(forwardedFor)) {
|
|
28
|
+
ips.push(...forwardedFor);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ips.push(forwardedFor);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (req.socket.remoteAddress) {
|
|
35
|
+
ips.push(req.socket.remoteAddress);
|
|
36
|
+
}
|
|
37
|
+
if (req.ip) {
|
|
38
|
+
ips.push(req.ip);
|
|
39
|
+
}
|
|
40
|
+
await logger.log('', {
|
|
41
|
+
requestId,
|
|
42
|
+
context: 'API',
|
|
43
|
+
applicationLogEndpoint: {
|
|
44
|
+
responseHttpCode: res.statusCode,
|
|
45
|
+
responseTime: Math.round(res.locals.timer.durationToClose),
|
|
46
|
+
ip: (0, lodash_1.uniq)(ips).filter(net_1.default.isIP),
|
|
47
|
+
endpoint: res.locals.path || ((_a = req.route) === null || _a === void 0 ? void 0 : _a.path) || req.path,
|
|
48
|
+
controller: res.locals.controller || 'Unknown Controller',
|
|
49
|
+
method: types_1.APIMethod[req.method.toUpperCase()],
|
|
50
|
+
requestParams: req.params,
|
|
51
|
+
requestQuery: req.query,
|
|
52
|
+
requestBody: res.locals.shouldNotSaveRequestBody
|
|
53
|
+
? null
|
|
54
|
+
: req.body
|
|
55
|
+
? JSON.parse(JSON.stringify(req.body))
|
|
56
|
+
: null,
|
|
57
|
+
responseBody: res.locals.shouldNotSaveResponseBody
|
|
58
|
+
? null
|
|
59
|
+
: res.locals.responseBody
|
|
60
|
+
? JSON.parse(JSON.stringify(res.locals.responseBody))
|
|
61
|
+
: null,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
if (callback) {
|
|
67
|
+
await callback(req, res, next);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.error(error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
next();
|
|
79
|
+
};
|
|
80
|
+
exports.loggerEndpointMiddleware = loggerEndpointMiddleware;
|
|
81
|
+
const getDurationInMilliseconds = (start) => {
|
|
82
|
+
const NS_PER_SEC = 1e9;
|
|
83
|
+
const NS_TO_MS = 1e6;
|
|
84
|
+
const diff = process.hrtime(start);
|
|
85
|
+
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
|
|
86
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loggerSetupMiddleware = void 0;
|
|
4
|
+
const loggerSetupMiddleware = async (req, res, next) => {
|
|
5
|
+
const originalJson = res.json;
|
|
6
|
+
const originalSend = res.send;
|
|
7
|
+
res.send = function (...args) {
|
|
8
|
+
return originalSend.apply(res, args);
|
|
9
|
+
};
|
|
10
|
+
res.json = function (...args) {
|
|
11
|
+
res.locals.responseBody = args[0];
|
|
12
|
+
return originalJson.apply(res, args);
|
|
13
|
+
};
|
|
14
|
+
next();
|
|
15
|
+
};
|
|
16
|
+
exports.loggerSetupMiddleware = loggerSetupMiddleware;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger.model';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger.model"), exports);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { APIMethod, ICreateApplicationLogBody, LogLevel } from '../types';
|
|
2
|
+
export type LogData = ICreateApplicationLogBody;
|
|
3
|
+
export type PayloadLog = {
|
|
4
|
+
context?: string | null;
|
|
5
|
+
scenario?: string | null;
|
|
6
|
+
requestId?: string | null;
|
|
7
|
+
data?: Record<string, unknown> | null;
|
|
8
|
+
applicationLogEndpoint?: {
|
|
9
|
+
controller: string;
|
|
10
|
+
endpoint: string;
|
|
11
|
+
ip: string[];
|
|
12
|
+
method: APIMethod;
|
|
13
|
+
responseTime: number;
|
|
14
|
+
responseHttpCode: number;
|
|
15
|
+
requestParams?: Record<string, string> | null;
|
|
16
|
+
requestQuery?: Record<string, string | string[]> | null;
|
|
17
|
+
requestBody?: Record<string, unknown> | string | null;
|
|
18
|
+
responseBody?: Record<string, unknown> | string | null;
|
|
19
|
+
};
|
|
20
|
+
applicationEvent?: {
|
|
21
|
+
event: string;
|
|
22
|
+
level: LogLevel;
|
|
23
|
+
message?: string | null;
|
|
24
|
+
data?: Record<string, unknown> | null;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
type Options = {
|
|
28
|
+
shouldSaveStack?: boolean;
|
|
29
|
+
customerConsoleLogger?: (data: LogData) => void;
|
|
30
|
+
compact?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type PayloadSendLog = PayloadLog & {
|
|
33
|
+
level: LogLevel;
|
|
34
|
+
message: string;
|
|
35
|
+
stack?: string;
|
|
36
|
+
};
|
|
37
|
+
type PayloadConstructor = {
|
|
38
|
+
shouldDisableConsoleLogging?: boolean;
|
|
39
|
+
shouldDisableConsoleResponseBodyLogging?: boolean;
|
|
40
|
+
shouldDisableRemoteLogging?: boolean;
|
|
41
|
+
customConsoleLogger?: (data: LogData) => void;
|
|
42
|
+
customPublishLog?: (payload: LogData, options?: Options) => Promise<void>;
|
|
43
|
+
processId?: string;
|
|
44
|
+
};
|
|
45
|
+
export declare class Logger {
|
|
46
|
+
private shouldDisableConsoleLogging;
|
|
47
|
+
private shouldDisableRemoteLogging;
|
|
48
|
+
private shouldDisableConsoleResponseBodyLogging;
|
|
49
|
+
private customConsoleLogger?;
|
|
50
|
+
private customPublishLog?;
|
|
51
|
+
private processId;
|
|
52
|
+
constructor(payload: PayloadConstructor);
|
|
53
|
+
log(message: string, payload?: PayloadLog, options?: Options): Promise<void>;
|
|
54
|
+
debug(message: string, payload?: PayloadLog, options?: Omit<Options, 'shouldSaveStack'>): Promise<void>;
|
|
55
|
+
error(message: string | Error, payload?: PayloadLog, options?: Options): Promise<void>;
|
|
56
|
+
info(message: string, payload?: PayloadLog, options?: Options): Promise<void>;
|
|
57
|
+
warn(message: string, payload?: PayloadLog, options?: Options): Promise<void>;
|
|
58
|
+
private publishLog;
|
|
59
|
+
private console;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Logger = void 0;
|
|
7
|
+
const api_1 = require("../api");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
10
|
+
const __1 = require("..");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const alert_utils_1 = require("../utils/alert.utils");
|
|
13
|
+
const MAXIMUM_BODY_SIZE = 1024 * 1024 * 1024;
|
|
14
|
+
const MAXIMUM_FIELD_LENGTH = 255;
|
|
15
|
+
let chalk;
|
|
16
|
+
if (typeof window === 'undefined') {
|
|
17
|
+
chalk = require('chalk');
|
|
18
|
+
}
|
|
19
|
+
const INFO_LEVEL = {
|
|
20
|
+
ERROR: chalk === null || chalk === void 0 ? void 0 : chalk.red('ERROR'),
|
|
21
|
+
WARN: chalk === null || chalk === void 0 ? void 0 : chalk.bgYellow.black('WARN'),
|
|
22
|
+
INFO: chalk === null || chalk === void 0 ? void 0 : chalk.blueBright('INFO'),
|
|
23
|
+
DEBUG: chalk === null || chalk === void 0 ? void 0 : chalk.grey('DEBUG'),
|
|
24
|
+
LOG: chalk === null || chalk === void 0 ? void 0 : chalk.grey('LOG'),
|
|
25
|
+
};
|
|
26
|
+
class Logger {
|
|
27
|
+
constructor(payload) {
|
|
28
|
+
this.shouldDisableRemoteLogging = payload.shouldDisableRemoteLogging || false;
|
|
29
|
+
this.shouldDisableConsoleLogging = payload.shouldDisableConsoleLogging || false;
|
|
30
|
+
this.shouldDisableConsoleResponseBodyLogging =
|
|
31
|
+
payload.shouldDisableConsoleResponseBodyLogging || false;
|
|
32
|
+
this.processId = payload.processId || process.pid.toString();
|
|
33
|
+
this.customConsoleLogger = payload.customConsoleLogger;
|
|
34
|
+
this.customPublishLog = payload.customPublishLog;
|
|
35
|
+
}
|
|
36
|
+
async log(message, payload = {}, options) {
|
|
37
|
+
this.publishLog({ ...payload, message, level: types_1.LogLevel.LOG }, options);
|
|
38
|
+
}
|
|
39
|
+
async debug(message, payload = {}, options) {
|
|
40
|
+
this.publishLog({ ...payload, message, stack: new Error().stack, level: types_1.LogLevel.LOG }, options);
|
|
41
|
+
}
|
|
42
|
+
async error(message, payload = {}, options) {
|
|
43
|
+
if (message instanceof Error) {
|
|
44
|
+
this.publishLog({
|
|
45
|
+
...payload,
|
|
46
|
+
message: `${message.name} ${message.message}`,
|
|
47
|
+
stack: message.stack,
|
|
48
|
+
level: types_1.LogLevel.ERROR,
|
|
49
|
+
data: {
|
|
50
|
+
...payload.data,
|
|
51
|
+
errorName: message.name,
|
|
52
|
+
},
|
|
53
|
+
}, options);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.publishLog({ ...payload, message, level: types_1.LogLevel.ERROR }, options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async info(message, payload = {}, options) {
|
|
60
|
+
this.publishLog({ ...payload, message, level: types_1.LogLevel.INFO }, options);
|
|
61
|
+
}
|
|
62
|
+
async warn(message, payload = {}, options) {
|
|
63
|
+
this.publishLog({ ...payload, message, level: types_1.LogLevel.WARN }, options);
|
|
64
|
+
}
|
|
65
|
+
async publishLog(payload, options) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const log = {
|
|
68
|
+
...payload,
|
|
69
|
+
dateValue: new Date(),
|
|
70
|
+
processId: this.processId,
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
this.console(log, options === null || options === void 0 ? void 0 : options.customerConsoleLogger);
|
|
74
|
+
if (this.customPublishLog) {
|
|
75
|
+
await this.customPublishLog(log, options);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const { applicationId, secretPublishToken } = __1.AbyssMonitorCore.getConfig();
|
|
79
|
+
if (!this.shouldDisableRemoteLogging && applicationId && secretPublishToken) {
|
|
80
|
+
const size = Buffer.byteLength(JSON.stringify(log));
|
|
81
|
+
const body = log;
|
|
82
|
+
let isBodyTruncated = false;
|
|
83
|
+
if (size >= MAXIMUM_BODY_SIZE) {
|
|
84
|
+
isBodyTruncated = true;
|
|
85
|
+
if ((_a = body.applicationLogEndpoint) === null || _a === void 0 ? void 0 : _a.requestBody) {
|
|
86
|
+
body.applicationLogEndpoint.requestBody = 'Payload Too Large';
|
|
87
|
+
}
|
|
88
|
+
if ((_b = body.applicationLogEndpoint) === null || _b === void 0 ? void 0 : _b.responseBody) {
|
|
89
|
+
body.applicationLogEndpoint.responseBody = 'Payload Too Large';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const newSize = Buffer.byteLength(JSON.stringify(body));
|
|
93
|
+
if (newSize >= MAXIMUM_BODY_SIZE) {
|
|
94
|
+
this.warn(`Unable to save log because payload is too big (more than 1Mo even after removing responseBody and requestBody)`, {
|
|
95
|
+
requestId: body.requestId
|
|
96
|
+
? (0, lodash_1.truncate)(body.requestId, { length: MAXIMUM_FIELD_LENGTH })
|
|
97
|
+
: undefined,
|
|
98
|
+
context: body.context
|
|
99
|
+
? (0, lodash_1.truncate)(body.context, { length: MAXIMUM_FIELD_LENGTH })
|
|
100
|
+
: undefined,
|
|
101
|
+
scenario: body.scenario
|
|
102
|
+
? (0, lodash_1.truncate)(body.scenario, { length: MAXIMUM_FIELD_LENGTH })
|
|
103
|
+
: undefined,
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const applicationLog = await (0, api_1.createApplicationLog)({ applicationId }, { token: secretPublishToken }, body);
|
|
108
|
+
(0, __1.nonBlockingPromise)((async () => {
|
|
109
|
+
(0, alert_utils_1.sendLogAlert)({
|
|
110
|
+
...payload,
|
|
111
|
+
logData: log,
|
|
112
|
+
logger: this,
|
|
113
|
+
applicationLogId: applicationLog.data.applicationLog.id || '',
|
|
114
|
+
compact: options === null || options === void 0 ? void 0 : options.compact,
|
|
115
|
+
});
|
|
116
|
+
})(), this);
|
|
117
|
+
if (isBodyTruncated) {
|
|
118
|
+
this.warn(`Endpoint log ${applicationLog.data.applicationLog.id} has been truncated (requestBody & responseBody) because payload was too big (more than 1Mo)`, {
|
|
119
|
+
requestId: body.requestId
|
|
120
|
+
? (0, lodash_1.truncate)(body.requestId, { length: MAXIMUM_FIELD_LENGTH })
|
|
121
|
+
: undefined,
|
|
122
|
+
context: body.context
|
|
123
|
+
? (0, lodash_1.truncate)(body.context, { length: MAXIMUM_FIELD_LENGTH })
|
|
124
|
+
: undefined,
|
|
125
|
+
scenario: body.scenario
|
|
126
|
+
? (0, lodash_1.truncate)(body.scenario, { length: MAXIMUM_FIELD_LENGTH })
|
|
127
|
+
: undefined,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(`Unable to publish log. Error: ${error}`);
|
|
135
|
+
(0, alert_utils_1.sendLogAlert)({
|
|
136
|
+
...payload,
|
|
137
|
+
logData: log,
|
|
138
|
+
logger: this,
|
|
139
|
+
author: 'AbyssMonitor Logger',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
console(data, customConsoleLogger) {
|
|
144
|
+
if (this.shouldDisableConsoleLogging) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (customConsoleLogger) {
|
|
148
|
+
customConsoleLogger(data);
|
|
149
|
+
}
|
|
150
|
+
else if (this.customConsoleLogger) {
|
|
151
|
+
this.customConsoleLogger(data);
|
|
152
|
+
}
|
|
153
|
+
else if (data.applicationLogEndpoint) {
|
|
154
|
+
let message = `${chalk.grey((0, dayjs_1.default)().format('DD/MM/YYYY HH:mm:ss'))} | ${chalk.bgBlueBright(' API ')} | `;
|
|
155
|
+
message += `${chalk.grey(data.requestId)} | ${chalk.greenBright(types_1.APIMethod[data.applicationLogEndpoint.method])} | ${data.applicationLogEndpoint.controller} ${data.applicationLogEndpoint.endpoint} | `;
|
|
156
|
+
if (data.applicationLogEndpoint.responseHttpCode >= 100 &&
|
|
157
|
+
data.applicationLogEndpoint.responseHttpCode <= 199) {
|
|
158
|
+
message += `${chalk.blue(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
159
|
+
}
|
|
160
|
+
else if (data.applicationLogEndpoint.responseHttpCode >= 200 &&
|
|
161
|
+
data.applicationLogEndpoint.responseHttpCode <= 299) {
|
|
162
|
+
message += `${chalk.green(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
163
|
+
}
|
|
164
|
+
else if (data.applicationLogEndpoint.responseHttpCode >= 300 &&
|
|
165
|
+
data.applicationLogEndpoint.responseHttpCode <= 399) {
|
|
166
|
+
message += `${chalk.magenta(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
167
|
+
}
|
|
168
|
+
else if (data.applicationLogEndpoint.responseHttpCode >= 400 &&
|
|
169
|
+
data.applicationLogEndpoint.responseHttpCode <= 499) {
|
|
170
|
+
message += `${chalk.yellow(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
171
|
+
}
|
|
172
|
+
else if (data.applicationLogEndpoint.responseHttpCode >= 500 &&
|
|
173
|
+
data.applicationLogEndpoint.responseHttpCode <= 599) {
|
|
174
|
+
message += `${chalk.red(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
message += `${chalk.bgCyanBright.black(data.applicationLogEndpoint.responseHttpCode)}`;
|
|
178
|
+
}
|
|
179
|
+
if (data.applicationLogEndpoint.responseTime < 50) {
|
|
180
|
+
message += ` | ${chalk.greenBright(data.applicationLogEndpoint.responseTime, 'ms')} | `;
|
|
181
|
+
}
|
|
182
|
+
else if (data.applicationLogEndpoint.responseTime < 150) {
|
|
183
|
+
message += ` | ${chalk.yellow(data.applicationLogEndpoint.responseTime, 'ms')} | `;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
message += ` | ${chalk.red(data.applicationLogEndpoint.responseTime, 'ms')} | `;
|
|
187
|
+
}
|
|
188
|
+
message += `${(data.applicationLogEndpoint.ip || []).join(' ')} | `;
|
|
189
|
+
if (!this.shouldDisableConsoleResponseBodyLogging &&
|
|
190
|
+
(data.applicationLogEndpoint.responseHttpCode < 200 ||
|
|
191
|
+
data.applicationLogEndpoint.responseHttpCode > 399)) {
|
|
192
|
+
message += `${JSON.stringify(data.applicationLogEndpoint.responseBody)}`;
|
|
193
|
+
}
|
|
194
|
+
console.log(message);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(`${chalk.grey((0, dayjs_1.default)().format('DD/MM/YYYY HH:mm:ss'))} | ${INFO_LEVEL[types_1.LogLevel[data.level]]} | ${data.processId}${data.requestId ? ` | ${data.requestId}` : ''}${data.context ? ` | ${data.context}` : ''} | ${data.message || data.stack} `);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Logger, ApplicationStatsType } from '..';
|
|
3
|
+
type StartOptions = {
|
|
4
|
+
interval?: number;
|
|
5
|
+
customCallback?: (values: {
|
|
6
|
+
type: ApplicationStatsType;
|
|
7
|
+
dateValue: Date;
|
|
8
|
+
processId: string;
|
|
9
|
+
value: number;
|
|
10
|
+
percentValue: number;
|
|
11
|
+
}[]) => Promise<void>;
|
|
12
|
+
logger?: Logger;
|
|
13
|
+
processId?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class StatsPublisher {
|
|
16
|
+
static interval: NodeJS.Timeout | null;
|
|
17
|
+
static start(options?: StartOptions): void;
|
|
18
|
+
static stop(): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StatsPublisher = void 0;
|
|
7
|
+
const axios_1 = require("axios");
|
|
8
|
+
const __1 = require("..");
|
|
9
|
+
const node_os_utils_1 = __importDefault(require("node-os-utils"));
|
|
10
|
+
const INTERVAL_BETWEEN_STATS_PUBLISH = 30000;
|
|
11
|
+
class StatsPublisher {
|
|
12
|
+
static start(options) {
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const si = require('systeminformation');
|
|
17
|
+
const checkDiskSpace = require('check-disk-space').default;
|
|
18
|
+
const interval = setInterval(async () => {
|
|
19
|
+
var _a, _b, _c, _d, _e;
|
|
20
|
+
try {
|
|
21
|
+
const devices = await si.blockDevices();
|
|
22
|
+
const dateValue = new Date();
|
|
23
|
+
const [cpuUsage, cpuSpeed, cpu, { usedMemMb, totalMemMb }, ...devicesSpace] = await Promise.all([
|
|
24
|
+
node_os_utils_1.default.cpu.usage(),
|
|
25
|
+
si.cpuCurrentSpeed(),
|
|
26
|
+
si.cpu(),
|
|
27
|
+
node_os_utils_1.default.mem.used(),
|
|
28
|
+
...devices.map((device) => checkDiskSpace(device.mount)),
|
|
29
|
+
]);
|
|
30
|
+
const totalDisk = devicesSpace.reduce((acc, drive) => acc + drive.size, 0);
|
|
31
|
+
const totalDiskFree = devicesSpace.reduce((acc, drive) => acc + drive.free, 0);
|
|
32
|
+
const totalDiskUSage = totalDisk - totalDiskFree;
|
|
33
|
+
const totalDiskUSagePerCent = (totalDiskUSage / totalDisk) * 100 || 0;
|
|
34
|
+
const payload = {
|
|
35
|
+
cpuUsage: (cpuSpeed.avg * (cpu.cores || 1) * 1000 * 1000 * 1000 * cpuUsage) / 100,
|
|
36
|
+
cpuPercentUsage: cpuUsage,
|
|
37
|
+
ramUsage: usedMemMb * 1024 * 1024,
|
|
38
|
+
ramPercentUsage: ((usedMemMb * 1024 * 1024) / (totalMemMb * 1024 * 1024)) * 100,
|
|
39
|
+
diskUsage: totalDiskUSage,
|
|
40
|
+
diskPercentUsage: totalDiskUSagePerCent,
|
|
41
|
+
};
|
|
42
|
+
const stats = [
|
|
43
|
+
{
|
|
44
|
+
type: __1.ApplicationStatsType.CPU_USAGE,
|
|
45
|
+
dateValue,
|
|
46
|
+
value: payload.cpuUsage,
|
|
47
|
+
percentValue: payload.cpuPercentUsage,
|
|
48
|
+
processId: (options === null || options === void 0 ? void 0 : options.processId) || process.pid.toString(),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: __1.ApplicationStatsType.RAM_USAGE,
|
|
52
|
+
dateValue,
|
|
53
|
+
value: payload.ramUsage,
|
|
54
|
+
percentValue: payload.ramPercentUsage,
|
|
55
|
+
processId: (options === null || options === void 0 ? void 0 : options.processId) || process.pid.toString(),
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: __1.ApplicationStatsType.DISK_USAGE,
|
|
59
|
+
dateValue,
|
|
60
|
+
value: payload.diskUsage,
|
|
61
|
+
percentValue: payload.diskPercentUsage,
|
|
62
|
+
processId: (options === null || options === void 0 ? void 0 : options.processId) || process.pid.toString(),
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
if (options === null || options === void 0 ? void 0 : options.customCallback) {
|
|
66
|
+
await options.customCallback(stats);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const applicationId = __1.AbyssMonitorCore.getConfig().applicationId;
|
|
70
|
+
const secretPublishToken = __1.AbyssMonitorCore.getConfig().secretPublishToken;
|
|
71
|
+
if (!applicationId) {
|
|
72
|
+
(_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.warn(`No applicationId provided on AbyssMonitorCore. Skipping publish stats`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!secretPublishToken) {
|
|
76
|
+
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.warn(`No secretPublishToken provided on AbyssMonitorCore. Skipping publish stats`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await (0, __1.createApplicationStats)({ applicationId }, { token: secretPublishToken }, { stats: stats });
|
|
80
|
+
await (0, __1.sendStatsAlert)({
|
|
81
|
+
...payload,
|
|
82
|
+
logger: options === null || options === void 0 ? void 0 : options.logger,
|
|
83
|
+
statsData: {
|
|
84
|
+
cpu: { percentValue: payload.cpuPercentUsage, value: payload.cpuUsage },
|
|
85
|
+
ram: { percentValue: payload.ramPercentUsage, value: payload.ramUsage },
|
|
86
|
+
disk: { percentValue: payload.diskPercentUsage, value: payload.diskUsage },
|
|
87
|
+
},
|
|
88
|
+
processId: (options === null || options === void 0 ? void 0 : options.processId) || process.pid.toString(),
|
|
89
|
+
dateValue,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.log(error);
|
|
95
|
+
(_c = options === null || options === void 0 ? void 0 : options.logger) === null || _c === void 0 ? void 0 : _c.error(`Failed to publish stats. Error ${error}`, { data: { error } });
|
|
96
|
+
if ((0, axios_1.isAxiosError)(error) && ((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) === 401) {
|
|
97
|
+
(_e = options === null || options === void 0 ? void 0 : options.logger) === null || _e === void 0 ? void 0 : _e.warn(`Unauthorized to publish stats, disabling stats publisher.`);
|
|
98
|
+
this.stop();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, (options === null || options === void 0 ? void 0 : options.interval) && (options === null || options === void 0 ? void 0 : options.interval) >= INTERVAL_BETWEEN_STATS_PUBLISH
|
|
102
|
+
? options === null || options === void 0 ? void 0 : options.interval
|
|
103
|
+
: INTERVAL_BETWEEN_STATS_PUBLISH);
|
|
104
|
+
StatsPublisher.interval = interval;
|
|
105
|
+
}
|
|
106
|
+
static stop() {
|
|
107
|
+
if (StatsPublisher.interval) {
|
|
108
|
+
clearInterval(StatsPublisher.interval);
|
|
109
|
+
}
|
|
110
|
+
StatsPublisher.interval = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.StatsPublisher = StatsPublisher;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VerificationMethod, VerificationStatus } from '../interface/models/domain-verification.model';
|
|
2
|
+
export interface DomainVerificationResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
status: VerificationStatus;
|
|
5
|
+
method?: VerificationMethod;
|
|
6
|
+
message?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
verifiedAt?: Date;
|
|
9
|
+
details?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export interface DnsVerificationResult extends DomainVerificationResult {
|
|
12
|
+
txtRecords?: string[];
|
|
13
|
+
foundToken?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface HttpVerificationResult extends DomainVerificationResult {
|
|
16
|
+
fileContent?: string;
|
|
17
|
+
statusCode?: number;
|
|
18
|
+
redirectCount?: number;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './domain-verification.dto';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./domain-verification.dto"), exports);
|