@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,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
index_1.AbyssConsoleCore.setConfig({
|
|
5
|
+
token: 'user-token',
|
|
6
|
+
baseURL: 'https://console-api.abyss-project.fr/api/',
|
|
7
|
+
});
|
|
8
|
+
index_1.AbyssConsoleCore.sdk.workflow.create({ name: 'Mon workflow' });
|
|
9
|
+
index_1.AbyssConsoleCore.sdk.workflow.paginate({ page: 1 });
|
|
10
|
+
index_1.AbyssConsoleCore.sdk.domainVerification.list();
|
|
11
|
+
index_1.AbyssConsoleCore.setConfig({
|
|
12
|
+
adminToken: 'admin-token',
|
|
13
|
+
baseURL: 'https://console-api.abyss-project.fr/api/',
|
|
14
|
+
admin: true,
|
|
15
|
+
});
|
|
16
|
+
index_1.AbyssConsoleCore.sdk.workflow.create({ name: 'Mon workflow' });
|
|
17
|
+
index_1.AbyssConsoleCore.sdk.workflow.paginate({ page: 1 });
|
|
18
|
+
index_1.AbyssConsoleCore.sdk.workflow.admin.paginate({ page: 1 });
|
|
19
|
+
index_1.AbyssConsoleCore.sdk.workflow.admin.trigger('workflow-id', { input: {} });
|
|
20
|
+
index_1.AbyssConsoleCore.sdk.domainVerification.admin.runCron();
|
|
21
|
+
index_1.AbyssConsoleCore.setConfig({ admin: false });
|
|
22
|
+
const sdk = index_1.AbyssConsoleCore.sdk;
|
|
23
|
+
const result = sdk.workflow.admin;
|
|
24
|
+
class WorkflowService {
|
|
25
|
+
constructor(isAdmin) {
|
|
26
|
+
index_1.AbyssConsoleCore.setConfig({
|
|
27
|
+
token: isAdmin ? undefined : 'user-token',
|
|
28
|
+
adminToken: isAdmin ? 'admin-token' : undefined,
|
|
29
|
+
admin: isAdmin,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async listWorkflows() {
|
|
33
|
+
const config = index_1.AbyssConsoleCore.getConfig();
|
|
34
|
+
if (config.admin) {
|
|
35
|
+
return await index_1.AbyssConsoleCore.sdk.workflow.admin.paginate({ page: 1 });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return await index_1.AbyssConsoleCore.sdk.workflow.paginate({ page: 1 });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function hasAdminMethods(sdk) {
|
|
43
|
+
return index_1.AbyssConsoleCore.getConfig().admin === true;
|
|
44
|
+
}
|
|
45
|
+
const currentSdk = index_1.AbyssConsoleCore.sdk;
|
|
46
|
+
if (hasAdminMethods(currentSdk)) {
|
|
47
|
+
currentSdk.workflow.admin.paginate({ page: 1 });
|
|
48
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LogData, Logger } from '..';
|
|
2
|
+
type BaseSendAlertParams = {
|
|
3
|
+
author?: string;
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
};
|
|
6
|
+
export type ParamsSendLogAlert = {
|
|
7
|
+
logData: LogData;
|
|
8
|
+
applicationLogId?: string | null;
|
|
9
|
+
webhookUrl?: string;
|
|
10
|
+
compact?: boolean;
|
|
11
|
+
} & BaseSendAlertParams;
|
|
12
|
+
export type PayloadSendStatsAlert = {
|
|
13
|
+
statsData: {
|
|
14
|
+
cpu?: {
|
|
15
|
+
value?: number | null;
|
|
16
|
+
percentValue?: number | null;
|
|
17
|
+
};
|
|
18
|
+
ram?: {
|
|
19
|
+
value?: number | null;
|
|
20
|
+
percentValue?: number | null;
|
|
21
|
+
};
|
|
22
|
+
disk?: {
|
|
23
|
+
value?: number | null;
|
|
24
|
+
percentValue?: number | null;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
processId: string;
|
|
28
|
+
dateValue: Date;
|
|
29
|
+
};
|
|
30
|
+
export type ParamsSendStatsAlert = {
|
|
31
|
+
webhookUrl?: string;
|
|
32
|
+
} & BaseSendAlertParams & PayloadSendStatsAlert;
|
|
33
|
+
export declare const sendLogAlert: (params: ParamsSendLogAlert) => Promise<void>;
|
|
34
|
+
export declare const sendStatsAlert: (params: ParamsSendStatsAlert) => Promise<void>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.sendStatsAlert = exports.sendLogAlert = void 0;
|
|
30
|
+
const __1 = require("..");
|
|
31
|
+
const json_utils_1 = require("./json.utils");
|
|
32
|
+
const axios_1 = __importDefault(require("axios"));
|
|
33
|
+
const axios_rate_limit_1 = __importDefault(require("axios-rate-limit"));
|
|
34
|
+
const axios_retry_1 = __importStar(require("axios-retry"));
|
|
35
|
+
const webhookClients = new Map();
|
|
36
|
+
const MAX_REQUEST_PER_MINUTE = 30;
|
|
37
|
+
const RATE_LIMIT_PERIOD_IN_MS = 60 * 1000;
|
|
38
|
+
const APPLICATION_LOG_ID_QUERY_PARAMS = 'application_log_id';
|
|
39
|
+
const sendLogAlert = async (params) => {
|
|
40
|
+
const webhookUrl = params.webhookUrl ||
|
|
41
|
+
(await __1.AbyssMonitorCore.getConfig().getWebhookUrl({
|
|
42
|
+
type: __1.ApplicationAlertType.LOG,
|
|
43
|
+
payload: params,
|
|
44
|
+
}));
|
|
45
|
+
if (!webhookUrl) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (params.logData.applicationLogEndpoint) {
|
|
49
|
+
await sendAlert({
|
|
50
|
+
logger: params.logger,
|
|
51
|
+
body: (0, __1.generateDiscordApiLogMessageContent)({
|
|
52
|
+
...params.logData,
|
|
53
|
+
author: params.author || __1.AbyssMonitorCore.getConfig().applicationName,
|
|
54
|
+
dashboardLogUrl: `${__1.AbyssMonitorCore.getConfig().baseClientURL}dashboard/project/${__1.AbyssMonitorCore.getConfig().projectId}/application/${__1.AbyssMonitorCore.getConfig().applicationId}/monitor/log?${params.applicationLogId
|
|
55
|
+
? `${APPLICATION_LOG_ID_QUERY_PARAMS}=${params.applicationLogId}`
|
|
56
|
+
: ''}`,
|
|
57
|
+
dateValue: params.logData.dateValue,
|
|
58
|
+
}),
|
|
59
|
+
webhookUrl,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await sendAlert({
|
|
64
|
+
logger: params.logger,
|
|
65
|
+
body: (0, __1.generateDiscordAlertLogMessageContent)({
|
|
66
|
+
title: params.logData.title,
|
|
67
|
+
level: params.logData.level,
|
|
68
|
+
author: params.author || __1.AbyssMonitorCore.getConfig().applicationName,
|
|
69
|
+
message: params.logData.message,
|
|
70
|
+
context: params.logData.context,
|
|
71
|
+
scenario: params.logData.scenario,
|
|
72
|
+
stack: params.logData.stack,
|
|
73
|
+
processId: params.logData.processId,
|
|
74
|
+
requestId: params.logData.requestId,
|
|
75
|
+
dashboardLogUrl: `${__1.AbyssMonitorCore.getConfig().baseClientURL}dashboard/project/${__1.AbyssMonitorCore.getConfig().projectId}/application/${__1.AbyssMonitorCore.getConfig().applicationId}/monitor/log?${APPLICATION_LOG_ID_QUERY_PARAMS}=${params.applicationLogId}`,
|
|
76
|
+
dateValue: params.logData.dateValue,
|
|
77
|
+
}, { compact: params.compact }),
|
|
78
|
+
webhookUrl,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.sendLogAlert = sendLogAlert;
|
|
83
|
+
const sendStatsAlert = async (params) => {
|
|
84
|
+
const webhookUrl = params.webhookUrl ||
|
|
85
|
+
(await __1.AbyssMonitorCore.getConfig().getWebhookUrl({
|
|
86
|
+
type: __1.ApplicationAlertType.STATS,
|
|
87
|
+
payload: params,
|
|
88
|
+
}));
|
|
89
|
+
if (!webhookUrl) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
await sendAlert({
|
|
93
|
+
logger: params.logger,
|
|
94
|
+
body: (0, __1.generateDiscordStatsMessageContent)({
|
|
95
|
+
...params,
|
|
96
|
+
dashboardStatsUrl: `${__1.AbyssMonitorCore.getConfig().baseClientURL}dashboard/project/${__1.AbyssMonitorCore.getConfig().projectId}/application/${__1.AbyssMonitorCore.getConfig().applicationId}/monitor/stats`,
|
|
97
|
+
author: params.author || __1.AbyssMonitorCore.getConfig().applicationName,
|
|
98
|
+
}),
|
|
99
|
+
webhookUrl,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.sendStatsAlert = sendStatsAlert;
|
|
103
|
+
const sendAlert = async (params) => {
|
|
104
|
+
const webhookUrls = Array.isArray(params.webhookUrl) ? params.webhookUrl : [params.webhookUrl];
|
|
105
|
+
await Promise.allSettled(webhookUrls.map(async (webhookUrl) => {
|
|
106
|
+
var _a;
|
|
107
|
+
try {
|
|
108
|
+
const webhookClient = findOrCreateWebhookClient(webhookUrl);
|
|
109
|
+
await webhookClient.post('', params.body);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
(_a = params.logger) === null || _a === void 0 ? void 0 : _a.error(`Unable to deliver alert to ${params.webhookUrl}. Error: ${error}`, {
|
|
113
|
+
data: (0, json_utils_1.isValidJson)(params.body) ? params.body : undefined,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
};
|
|
118
|
+
const findOrCreateWebhookClient = (webhookUrl) => {
|
|
119
|
+
const existingWebhookClient = webhookClients.get(webhookUrl);
|
|
120
|
+
if (existingWebhookClient) {
|
|
121
|
+
return existingWebhookClient;
|
|
122
|
+
}
|
|
123
|
+
const webhookClient = (0, axios_rate_limit_1.default)(axios_1.default.create({ baseURL: webhookUrl }), {
|
|
124
|
+
maxRequests: MAX_REQUEST_PER_MINUTE,
|
|
125
|
+
perMilliseconds: RATE_LIMIT_PERIOD_IN_MS,
|
|
126
|
+
});
|
|
127
|
+
(0, axios_retry_1.default)(webhookClient, {
|
|
128
|
+
retries: __1.NUMBER_RETRY_API,
|
|
129
|
+
retryDelay: (retryCount) => retryCount * __1.BASE_DELAY_BETWEEN_RETRY,
|
|
130
|
+
retryCondition: (error) => {
|
|
131
|
+
var _a;
|
|
132
|
+
return (0, axios_retry_1.isNetworkOrIdempotentRequestError)(error) ||
|
|
133
|
+
__1.RETRY_CODES.includes(((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) || 502);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
webhookClients.set(webhookUrl, webhookClient);
|
|
137
|
+
return webhookClient;
|
|
138
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WebhookMessageCreateOptions } from 'discord.js';
|
|
2
|
+
import { IApplicationCronTask, IApplicationCronTaskHistory } from '../types';
|
|
3
|
+
import { LogData } from '../models';
|
|
4
|
+
import { PayloadSendStatsAlert } from './alert.utils';
|
|
5
|
+
export declare const MAX_DESCRIPTION_LENGTH = 4096;
|
|
6
|
+
export declare const MAX_FIELD_NAME_LENGTH = 256;
|
|
7
|
+
export declare const MAX_FIELD_VALUE_LENGTH = 1024;
|
|
8
|
+
export declare const MAX_FOOTER_LENGTH = 2048;
|
|
9
|
+
export declare const MAX_TITLE_LENGTH = 256;
|
|
10
|
+
export declare const MAX_AUTHOR_NAME_LENGTH = 256;
|
|
11
|
+
export declare const HIGHLIGHT = "```";
|
|
12
|
+
export declare enum DISCORD_EMBED_COLORS {
|
|
13
|
+
red = 16711680,
|
|
14
|
+
green = 4961603,
|
|
15
|
+
blue = 52479,
|
|
16
|
+
orange = 16753920,
|
|
17
|
+
grey = 8421504
|
|
18
|
+
}
|
|
19
|
+
export declare const DATE_FORMAT = "DD/MM/YYYY HH:mm:ss";
|
|
20
|
+
export declare const dateFormatted: (date?: Date) => string;
|
|
21
|
+
export declare const generateDiscordHighlightBlock: (content: string) => string;
|
|
22
|
+
export declare const generateDiscordHighlightBlockWithColor: (color: keyof typeof DISCORD_EMBED_COLORS, message: string) => string;
|
|
23
|
+
export declare const getBlockColorByResultCode: (resultCode: number) => keyof typeof DISCORD_EMBED_COLORS;
|
|
24
|
+
export declare const getAPIEmbedColor: (color: keyof typeof DISCORD_EMBED_COLORS) => DISCORD_EMBED_COLORS;
|
|
25
|
+
export type ParamsGenerateDiscordAlertLogMessageContent = {
|
|
26
|
+
dashboardLogUrl: string;
|
|
27
|
+
author: string;
|
|
28
|
+
} & LogData;
|
|
29
|
+
export declare const generateDiscordAlertLogMessageContent: (params: ParamsGenerateDiscordAlertLogMessageContent, options?: {
|
|
30
|
+
compact?: boolean;
|
|
31
|
+
}) => WebhookMessageCreateOptions;
|
|
32
|
+
export type ParamsGenerateDiscordApiLogMessageContent = {
|
|
33
|
+
dashboardLogUrl: string;
|
|
34
|
+
author: string;
|
|
35
|
+
} & LogData;
|
|
36
|
+
export declare const generateDiscordApiLogMessageContent: (params: ParamsGenerateDiscordApiLogMessageContent) => WebhookMessageCreateOptions;
|
|
37
|
+
type ParamsGenerateDiscordStatsMessageContent = {
|
|
38
|
+
dashboardStatsUrl: string;
|
|
39
|
+
author: string;
|
|
40
|
+
} & PayloadSendStatsAlert;
|
|
41
|
+
export declare const generateDiscordStatsMessageContent: (params: ParamsGenerateDiscordStatsMessageContent) => WebhookMessageCreateOptions;
|
|
42
|
+
type ParamsGenerateDiscordCronTaskHistoryMessageContent = {
|
|
43
|
+
applicationCronTaskHistory: IApplicationCronTaskHistory;
|
|
44
|
+
applicationCronTask: IApplicationCronTask;
|
|
45
|
+
dashboardCronTaskHistoryUrl: string;
|
|
46
|
+
};
|
|
47
|
+
export declare const generateDiscordCronTaskHistoryMessageContent: (params: ParamsGenerateDiscordCronTaskHistoryMessageContent) => WebhookMessageCreateOptions;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,332 @@
|
|
|
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.generateDiscordCronTaskHistoryMessageContent = exports.generateDiscordStatsMessageContent = exports.generateDiscordApiLogMessageContent = exports.generateDiscordAlertLogMessageContent = exports.getAPIEmbedColor = exports.getBlockColorByResultCode = exports.generateDiscordHighlightBlockWithColor = exports.generateDiscordHighlightBlock = exports.dateFormatted = exports.DATE_FORMAT = exports.DISCORD_EMBED_COLORS = exports.HIGHLIGHT = exports.MAX_AUTHOR_NAME_LENGTH = exports.MAX_TITLE_LENGTH = exports.MAX_FOOTER_LENGTH = exports.MAX_FIELD_VALUE_LENGTH = exports.MAX_FIELD_NAME_LENGTH = exports.MAX_DESCRIPTION_LENGTH = void 0;
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
10
|
+
exports.MAX_DESCRIPTION_LENGTH = 4096;
|
|
11
|
+
exports.MAX_FIELD_NAME_LENGTH = 256;
|
|
12
|
+
exports.MAX_FIELD_VALUE_LENGTH = 1024;
|
|
13
|
+
exports.MAX_FOOTER_LENGTH = 2048;
|
|
14
|
+
exports.MAX_TITLE_LENGTH = 256;
|
|
15
|
+
exports.MAX_AUTHOR_NAME_LENGTH = 256;
|
|
16
|
+
const truncate = (text, maxLength) => {
|
|
17
|
+
if (text.length <= maxLength) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return text.substring(0, maxLength - 3) + '...';
|
|
21
|
+
};
|
|
22
|
+
exports.HIGHLIGHT = '```';
|
|
23
|
+
var DISCORD_EMBED_COLORS;
|
|
24
|
+
(function (DISCORD_EMBED_COLORS) {
|
|
25
|
+
DISCORD_EMBED_COLORS[DISCORD_EMBED_COLORS["red"] = 16711680] = "red";
|
|
26
|
+
DISCORD_EMBED_COLORS[DISCORD_EMBED_COLORS["green"] = 4961603] = "green";
|
|
27
|
+
DISCORD_EMBED_COLORS[DISCORD_EMBED_COLORS["blue"] = 52479] = "blue";
|
|
28
|
+
DISCORD_EMBED_COLORS[DISCORD_EMBED_COLORS["orange"] = 16753920] = "orange";
|
|
29
|
+
DISCORD_EMBED_COLORS[DISCORD_EMBED_COLORS["grey"] = 8421504] = "grey";
|
|
30
|
+
})(DISCORD_EMBED_COLORS || (exports.DISCORD_EMBED_COLORS = DISCORD_EMBED_COLORS = {}));
|
|
31
|
+
const COLOR_FOR_LOG_LEVEL = {
|
|
32
|
+
[types_1.LogLevel.ERROR]: DISCORD_EMBED_COLORS.red,
|
|
33
|
+
[types_1.LogLevel.INFO]: DISCORD_EMBED_COLORS.blue,
|
|
34
|
+
[types_1.LogLevel.LOG]: DISCORD_EMBED_COLORS.grey,
|
|
35
|
+
[types_1.LogLevel.WARN]: DISCORD_EMBED_COLORS.orange,
|
|
36
|
+
};
|
|
37
|
+
exports.DATE_FORMAT = 'DD/MM/YYYY HH:mm:ss';
|
|
38
|
+
const dateFormatted = (date = new Date()) => {
|
|
39
|
+
return (0, dayjs_1.default)(date).format(exports.DATE_FORMAT);
|
|
40
|
+
};
|
|
41
|
+
exports.dateFormatted = dateFormatted;
|
|
42
|
+
const generateDiscordHighlightBlock = (content) => {
|
|
43
|
+
return `${exports.HIGHLIGHT}\n${content}\n${exports.HIGHLIGHT}`;
|
|
44
|
+
};
|
|
45
|
+
exports.generateDiscordHighlightBlock = generateDiscordHighlightBlock;
|
|
46
|
+
const generateDiscordHighlightBlockWithColor = (color, message) => {
|
|
47
|
+
if (color === 'green') {
|
|
48
|
+
return `${exports.HIGHLIGHT}diff\n+ ${message}\n${exports.HIGHLIGHT}`;
|
|
49
|
+
}
|
|
50
|
+
else if (color === 'red') {
|
|
51
|
+
return `${exports.HIGHLIGHT}diff\n- ${message}\n${exports.HIGHLIGHT}`;
|
|
52
|
+
}
|
|
53
|
+
else if (color === 'orange') {
|
|
54
|
+
return `${exports.HIGHLIGHT}fix\n${message}\n${exports.HIGHLIGHT}`;
|
|
55
|
+
}
|
|
56
|
+
else if (color === 'blue') {
|
|
57
|
+
return `${exports.HIGHLIGHT}ini\n[${message}]\n${exports.HIGHLIGHT}`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return `${exports.HIGHLIGHT}${message}${exports.HIGHLIGHT}`;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.generateDiscordHighlightBlockWithColor = generateDiscordHighlightBlockWithColor;
|
|
64
|
+
const getBlockColorByResultCode = (resultCode) => {
|
|
65
|
+
if (resultCode >= 100 && resultCode <= 199) {
|
|
66
|
+
return 'blue';
|
|
67
|
+
}
|
|
68
|
+
else if (resultCode >= 200 && resultCode <= 299) {
|
|
69
|
+
return 'green';
|
|
70
|
+
}
|
|
71
|
+
else if (resultCode >= 300 && resultCode <= 399) {
|
|
72
|
+
return 'grey';
|
|
73
|
+
}
|
|
74
|
+
else if (resultCode >= 400 && resultCode <= 499) {
|
|
75
|
+
return 'orange';
|
|
76
|
+
}
|
|
77
|
+
else if (resultCode >= 500 && resultCode <= 599) {
|
|
78
|
+
return 'red';
|
|
79
|
+
}
|
|
80
|
+
return 'grey';
|
|
81
|
+
};
|
|
82
|
+
exports.getBlockColorByResultCode = getBlockColorByResultCode;
|
|
83
|
+
const getAPIEmbedColor = (color) => {
|
|
84
|
+
if (['blue', 'green'].includes(color)) {
|
|
85
|
+
return DISCORD_EMBED_COLORS.green;
|
|
86
|
+
}
|
|
87
|
+
else if (['orange'].includes(color)) {
|
|
88
|
+
return DISCORD_EMBED_COLORS.orange;
|
|
89
|
+
}
|
|
90
|
+
else if (['red'].includes(color)) {
|
|
91
|
+
return DISCORD_EMBED_COLORS.red;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return DISCORD_EMBED_COLORS.grey;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.getAPIEmbedColor = getAPIEmbedColor;
|
|
98
|
+
const generateDiscordAlertLogMessageContent = (params, options) => {
|
|
99
|
+
if (params.applicationLogEndpoint) {
|
|
100
|
+
return (0, exports.generateDiscordApiLogMessageContent)(params);
|
|
101
|
+
}
|
|
102
|
+
if ((options === null || options === void 0 ? void 0 : options.compact) && params.level === types_1.LogLevel.INFO) {
|
|
103
|
+
return {
|
|
104
|
+
content: `**[${params.author}]** ${types_1.LogLevel[params.level]} - ${params.message}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
embeds: [
|
|
109
|
+
{
|
|
110
|
+
color: COLOR_FOR_LOG_LEVEL[params.level],
|
|
111
|
+
author: {
|
|
112
|
+
name: truncate(`${params.author} - ${types_1.LogLevel[params.level]}`, exports.MAX_AUTHOR_NAME_LENGTH),
|
|
113
|
+
},
|
|
114
|
+
...(params.title || params.level === types_1.LogLevel.ERROR
|
|
115
|
+
? {
|
|
116
|
+
title: truncate(`${params.title ? params.title : 'Not named Error'}`, exports.MAX_TITLE_LENGTH),
|
|
117
|
+
}
|
|
118
|
+
: {}),
|
|
119
|
+
description: truncate(`${params.message} ${params.stack ? params.stack : ''}`, exports.MAX_DESCRIPTION_LENGTH),
|
|
120
|
+
fields: [
|
|
121
|
+
{
|
|
122
|
+
name: truncate(`Context`, exports.MAX_FIELD_NAME_LENGTH),
|
|
123
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.context || 'No Context'), exports.MAX_FIELD_VALUE_LENGTH),
|
|
124
|
+
inline: true,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: truncate(`Scenario`, exports.MAX_FIELD_NAME_LENGTH),
|
|
128
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.scenario || 'No Scenario'), exports.MAX_FIELD_VALUE_LENGTH),
|
|
129
|
+
inline: true,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
footer: {
|
|
133
|
+
text: truncate(`${(0, exports.dateFormatted)(params.dateValue)} - ${params.processId} - ${params.requestId || 'No Request id'} - [See Log](${params.dashboardLogUrl})`, exports.MAX_FOOTER_LENGTH),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
exports.generateDiscordAlertLogMessageContent = generateDiscordAlertLogMessageContent;
|
|
140
|
+
const generateDiscordApiLogMessageContent = (params) => {
|
|
141
|
+
if (!params.applicationLogEndpoint) {
|
|
142
|
+
return (0, exports.generateDiscordAlertLogMessageContent)(params);
|
|
143
|
+
}
|
|
144
|
+
const color = (0, exports.getBlockColorByResultCode)(params.applicationLogEndpoint.responseHttpCode);
|
|
145
|
+
let durationColor;
|
|
146
|
+
if (params.applicationLogEndpoint.responseTime < 100) {
|
|
147
|
+
durationColor = 'green';
|
|
148
|
+
}
|
|
149
|
+
else if (params.applicationLogEndpoint.responseTime < 250) {
|
|
150
|
+
durationColor = 'orange';
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
durationColor = 'red';
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
embeds: [
|
|
157
|
+
{
|
|
158
|
+
color: (0, exports.getAPIEmbedColor)(color),
|
|
159
|
+
author: {
|
|
160
|
+
name: truncate(`${params.author} - API`, exports.MAX_AUTHOR_NAME_LENGTH),
|
|
161
|
+
},
|
|
162
|
+
fields: [
|
|
163
|
+
{
|
|
164
|
+
name: truncate(`Request ID`, exports.MAX_FIELD_NAME_LENGTH),
|
|
165
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.requestId || ''), exports.MAX_FIELD_VALUE_LENGTH),
|
|
166
|
+
inline: true,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: truncate(`Process ID`, exports.MAX_FIELD_NAME_LENGTH),
|
|
170
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.processId), exports.MAX_FIELD_VALUE_LENGTH),
|
|
171
|
+
inline: true,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: truncate(`Authentication`, exports.MAX_FIELD_NAME_LENGTH),
|
|
175
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.applicationLogEndpoint.authentication || 'None'), exports.MAX_FIELD_VALUE_LENGTH),
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: truncate(`Method`, exports.MAX_FIELD_NAME_LENGTH),
|
|
179
|
+
value: truncate(`${(0, exports.generateDiscordHighlightBlockWithColor)('blue', types_1.APIMethod[params.applicationLogEndpoint.method].toUpperCase())}`, exports.MAX_FIELD_VALUE_LENGTH),
|
|
180
|
+
inline: true,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: truncate(`Response HTTP Code`, exports.MAX_FIELD_NAME_LENGTH),
|
|
184
|
+
value: truncate((0, exports.generateDiscordHighlightBlockWithColor)(color, params.applicationLogEndpoint.responseHttpCode.toString()), exports.MAX_FIELD_VALUE_LENGTH),
|
|
185
|
+
inline: true,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: truncate(`Duration`, exports.MAX_FIELD_NAME_LENGTH),
|
|
189
|
+
value: truncate((0, exports.generateDiscordHighlightBlockWithColor)(durationColor, `${params.applicationLogEndpoint.responseTime}ms`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
190
|
+
inline: true,
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: truncate(`Controller`, exports.MAX_FIELD_NAME_LENGTH),
|
|
194
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)((0, lodash_1.upperFirst)(params.applicationLogEndpoint.controller || 'Unknown Controller')), exports.MAX_FIELD_VALUE_LENGTH),
|
|
195
|
+
inline: true,
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: truncate(`Endpoint`, exports.MAX_FIELD_NAME_LENGTH),
|
|
199
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.applicationLogEndpoint.endpoint), exports.MAX_FIELD_VALUE_LENGTH),
|
|
200
|
+
inline: true,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: truncate(`Client IPs`, exports.MAX_FIELD_NAME_LENGTH),
|
|
204
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(params.applicationLogEndpoint.ip.join('\n')), exports.MAX_FIELD_VALUE_LENGTH),
|
|
205
|
+
},
|
|
206
|
+
...(params.applicationLogEndpoint.responseHttpCode < 200 ||
|
|
207
|
+
params.applicationLogEndpoint.responseHttpCode > 399
|
|
208
|
+
? [
|
|
209
|
+
{
|
|
210
|
+
name: truncate(`Error`, exports.MAX_FIELD_NAME_LENGTH),
|
|
211
|
+
value: truncate(`${JSON.stringify(params.applicationLogEndpoint.responseBody)}`, exports.MAX_FIELD_VALUE_LENGTH),
|
|
212
|
+
},
|
|
213
|
+
]
|
|
214
|
+
: []),
|
|
215
|
+
],
|
|
216
|
+
footer: {
|
|
217
|
+
text: truncate(`${(0, exports.dateFormatted)(params.dateValue)} - ${params.processId} - ${params.requestId || 'No Request id'} - [See Log](${params.dashboardLogUrl})`, exports.MAX_FOOTER_LENGTH),
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
exports.generateDiscordApiLogMessageContent = generateDiscordApiLogMessageContent;
|
|
224
|
+
const generateDiscordStatsMessageContent = (params) => {
|
|
225
|
+
return {
|
|
226
|
+
embeds: [
|
|
227
|
+
{
|
|
228
|
+
color: (0, exports.getAPIEmbedColor)('orange'),
|
|
229
|
+
title: truncate(`${params.author} - Performance Alert`, exports.MAX_TITLE_LENGTH),
|
|
230
|
+
fields: [
|
|
231
|
+
...(params.statsData.cpu &&
|
|
232
|
+
(params.statsData.cpu.value || params.statsData.cpu.percentValue)
|
|
233
|
+
? [
|
|
234
|
+
{
|
|
235
|
+
name: truncate('CPU Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
236
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.cpu.value
|
|
237
|
+
? `${(params.statsData.cpu.value / 1000 / 1000 / 1000).toFixed(2)} Ghz`
|
|
238
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
239
|
+
inline: true,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: truncate('CPU Percent Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
243
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.cpu.percentValue
|
|
244
|
+
? `${params.statsData.cpu.percentValue.toFixed(2)}%`
|
|
245
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
246
|
+
inline: true,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: truncate('\n', exports.MAX_FIELD_NAME_LENGTH),
|
|
250
|
+
value: truncate('\n', exports.MAX_FIELD_VALUE_LENGTH),
|
|
251
|
+
inline: true,
|
|
252
|
+
},
|
|
253
|
+
]
|
|
254
|
+
: []),
|
|
255
|
+
...(params.statsData.ram &&
|
|
256
|
+
(params.statsData.ram.value || params.statsData.ram.percentValue)
|
|
257
|
+
? [
|
|
258
|
+
{
|
|
259
|
+
name: truncate('Memory Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
260
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.ram.value
|
|
261
|
+
? `${(params.statsData.ram.value / 1024 / 1024 / 1024).toFixed(2)} Go`
|
|
262
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
263
|
+
inline: true,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: truncate('Memory Percent Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
267
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.ram.percentValue
|
|
268
|
+
? `${params.statsData.ram.percentValue.toFixed(2)}%`
|
|
269
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
270
|
+
inline: true,
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: truncate('\n', exports.MAX_FIELD_NAME_LENGTH),
|
|
274
|
+
value: truncate('\n', exports.MAX_FIELD_VALUE_LENGTH),
|
|
275
|
+
inline: true,
|
|
276
|
+
},
|
|
277
|
+
]
|
|
278
|
+
: []),
|
|
279
|
+
...(params.statsData.disk &&
|
|
280
|
+
(params.statsData.disk.value || params.statsData.disk.percentValue)
|
|
281
|
+
? [
|
|
282
|
+
{
|
|
283
|
+
name: truncate('Disk Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
284
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.disk.value
|
|
285
|
+
? `${(params.statsData.disk.value / 1024 / 1024 / 1024).toFixed(2)}`
|
|
286
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
287
|
+
inline: true,
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: truncate('Disk Percent Usage', exports.MAX_FIELD_NAME_LENGTH),
|
|
291
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.statsData.disk.percentValue
|
|
292
|
+
? `${params.statsData.disk.percentValue.toFixed(2)}%`
|
|
293
|
+
: 'Unknown'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
294
|
+
inline: true,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: truncate('\n', exports.MAX_FIELD_NAME_LENGTH),
|
|
298
|
+
value: truncate('\n', exports.MAX_FIELD_VALUE_LENGTH),
|
|
299
|
+
inline: true,
|
|
300
|
+
},
|
|
301
|
+
]
|
|
302
|
+
: []),
|
|
303
|
+
],
|
|
304
|
+
footer: {
|
|
305
|
+
text: truncate(`${(0, exports.dateFormatted)(params.dateValue)} - ${params.processId} - [See Stats](${params.dashboardStatsUrl})`, exports.MAX_FOOTER_LENGTH),
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
exports.generateDiscordStatsMessageContent = generateDiscordStatsMessageContent;
|
|
312
|
+
const generateDiscordCronTaskHistoryMessageContent = (params) => {
|
|
313
|
+
return {
|
|
314
|
+
embeds: [
|
|
315
|
+
{
|
|
316
|
+
color: (0, exports.getAPIEmbedColor)(params.applicationCronTaskHistory.hasFailed ? 'red' : 'green'),
|
|
317
|
+
title: truncate(`CronTask ${params.applicationCronTask.name}`, exports.MAX_TITLE_LENGTH),
|
|
318
|
+
fields: [
|
|
319
|
+
{
|
|
320
|
+
name: truncate('Status', exports.MAX_FIELD_NAME_LENGTH),
|
|
321
|
+
value: truncate((0, exports.generateDiscordHighlightBlock)(`${params.applicationCronTaskHistory.hasFailed ? 'FAILED' : 'SUCCEEDED'}`), exports.MAX_FIELD_VALUE_LENGTH),
|
|
322
|
+
inline: true,
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
footer: {
|
|
326
|
+
text: truncate(`${(0, exports.dateFormatted)(params.applicationCronTaskHistory.startDate)} - ${params.applicationCronTaskHistory.requestId || 'No Request id'} - [See CronTask history](${params.dashboardCronTaskHistoryUrl})`, exports.MAX_FOOTER_LENGTH),
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
exports.generateDiscordCronTaskHistoryMessageContent = generateDiscordCronTaskHistoryMessageContent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Code, ErrorType } from '../types';
|
|
2
|
+
type ErrorParams = {
|
|
3
|
+
code: Code;
|
|
4
|
+
type: ErrorType;
|
|
5
|
+
message?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class ServiceException extends Error {
|
|
8
|
+
private readonly code;
|
|
9
|
+
private readonly type;
|
|
10
|
+
getCode(): Code;
|
|
11
|
+
getType(): ErrorType;
|
|
12
|
+
constructor(params: ErrorParams);
|
|
13
|
+
}
|
|
14
|
+
export declare const handleError: (error: Error | ErrorParams, _params?: ErrorParams) => Error;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleError = exports.ServiceException = void 0;
|
|
4
|
+
class ServiceException extends Error {
|
|
5
|
+
getCode() {
|
|
6
|
+
return this.code;
|
|
7
|
+
}
|
|
8
|
+
getType() {
|
|
9
|
+
return this.type;
|
|
10
|
+
}
|
|
11
|
+
constructor(params) {
|
|
12
|
+
super(params.message);
|
|
13
|
+
this.code = params.code;
|
|
14
|
+
this.type = params.type;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ServiceException = ServiceException;
|
|
18
|
+
const handleError = (error, _params) => {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
return new ServiceException(error);
|
|
23
|
+
};
|
|
24
|
+
exports.handleError = handleError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extensionFileToImport: () => ".ts" | ".js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extensionFileToImport = void 0;
|
|
4
|
+
const extensionFileToImport = () => {
|
|
5
|
+
return process.env.NODE_ENV === 'DEVELOPMENT' ? '.ts' : '.js';
|
|
6
|
+
};
|
|
7
|
+
exports.extensionFileToImport = extensionFileToImport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error.utils';
|