slack-logs 1.0.14 → 1.1.0
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/README.md +9 -2
- package/dist/index.js +34 -3
- package/dist/index.ts +38 -4
- package/package.json +1 -1
- package/src/index.ts +38 -4
package/README.md
CHANGED
|
@@ -15,9 +15,16 @@ This package provides a simple and efficient way to log messages directly to Sla
|
|
|
15
15
|
### Installation
|
|
16
16
|
|
|
17
17
|
- Install the package using npm:
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm install slack-logs
|
|
21
|
+
```
|
|
22
|
+
|
|
19
23
|
- Or using yarn:
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
yarn add slack-logs
|
|
27
|
+
```
|
|
21
28
|
|
|
22
29
|
### Configuration:
|
|
23
30
|
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.slack = void 0;
|
|
6
|
+
exports.slack = exports.LogColor = exports.LogLevel = void 0;
|
|
7
7
|
const common_variables_1 = require("./constants/common-variables");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
var LogLevel;
|
|
10
|
+
(function (LogLevel) {
|
|
11
|
+
LogLevel["DEFAULT"] = "DEFAULT";
|
|
12
|
+
LogLevel["SUCCESS"] = "SUCCESS";
|
|
13
|
+
LogLevel["INFO"] = "INFO";
|
|
14
|
+
LogLevel["WARN"] = "WARN";
|
|
15
|
+
LogLevel["ERROR"] = "ERROR";
|
|
16
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
17
|
+
var LogColor;
|
|
18
|
+
(function (LogColor) {
|
|
19
|
+
LogColor["DEFAULT"] = "#B4B4B8";
|
|
20
|
+
LogColor["SUCCESS"] = "#65B741";
|
|
21
|
+
LogColor["INFO"] = "#40A2D8";
|
|
22
|
+
LogColor["WARN"] = "#E3651D";
|
|
23
|
+
LogColor["ERROR"] = "#FF0000";
|
|
24
|
+
})(LogColor || (exports.LogColor = LogColor = {}));
|
|
9
25
|
exports.slack = {
|
|
10
26
|
async log(label, data) {
|
|
11
27
|
const messageData = JSON.stringify(data);
|
|
@@ -20,13 +36,20 @@ exports.slack = {
|
|
|
20
36
|
};
|
|
21
37
|
await axiosCall(payload);
|
|
22
38
|
},
|
|
23
|
-
async logBlockMessage(label, objectData) {
|
|
39
|
+
async logBlockMessage(label, objectData, error_type = LogLevel.DEFAULT) {
|
|
24
40
|
if (!isValidSlackWebhookUrl()) {
|
|
25
41
|
// SLACK_WEBHOOK_URL is valid
|
|
26
42
|
console.error("🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨");
|
|
27
43
|
return null;
|
|
28
44
|
}
|
|
45
|
+
console.log(error_type);
|
|
46
|
+
const messageBodyColor = LogColor[error_type];
|
|
29
47
|
const blocks = [];
|
|
48
|
+
const attachments = [];
|
|
49
|
+
const attachmentsBlocks = [];
|
|
50
|
+
blocks.push({
|
|
51
|
+
type: "divider",
|
|
52
|
+
});
|
|
30
53
|
// Label of slack message
|
|
31
54
|
blocks.push({
|
|
32
55
|
type: "header",
|
|
@@ -36,10 +59,13 @@ exports.slack = {
|
|
|
36
59
|
emoji: true,
|
|
37
60
|
},
|
|
38
61
|
});
|
|
62
|
+
blocks.push({
|
|
63
|
+
type: "divider",
|
|
64
|
+
});
|
|
39
65
|
if (objectData?.length) {
|
|
40
66
|
objectData.forEach((element) => {
|
|
41
67
|
let value = JSON.stringify(element.value);
|
|
42
|
-
|
|
68
|
+
attachmentsBlocks.push({
|
|
43
69
|
type: "section",
|
|
44
70
|
text: {
|
|
45
71
|
type: "mrkdwn",
|
|
@@ -48,9 +74,14 @@ exports.slack = {
|
|
|
48
74
|
});
|
|
49
75
|
});
|
|
50
76
|
}
|
|
77
|
+
attachments.push({
|
|
78
|
+
color: messageBodyColor,
|
|
79
|
+
blocks: attachmentsBlocks,
|
|
80
|
+
});
|
|
51
81
|
let payload = {
|
|
52
82
|
text: "Application Error!",
|
|
53
83
|
blocks: blocks,
|
|
84
|
+
attachments: attachments,
|
|
54
85
|
};
|
|
55
86
|
await axiosCall(payload);
|
|
56
87
|
},
|
package/dist/index.ts
CHANGED
|
@@ -8,13 +8,29 @@ interface Slack {
|
|
|
8
8
|
log(label: string, data: any): Promise<null | undefined>;
|
|
9
9
|
logBlockMessage(
|
|
10
10
|
label: string,
|
|
11
|
-
objectData: BlocksInterface[]
|
|
11
|
+
objectData: BlocksInterface[],
|
|
12
|
+
error_type?: LogLevel
|
|
12
13
|
): Promise<null | undefined>;
|
|
13
14
|
}
|
|
14
15
|
interface BlocksInterface {
|
|
15
16
|
title: string;
|
|
16
17
|
value: any;
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
export enum LogLevel {
|
|
21
|
+
DEFAULT = "DEFAULT",
|
|
22
|
+
SUCCESS = "SUCCESS",
|
|
23
|
+
INFO = "INFO",
|
|
24
|
+
WARN = "WARN",
|
|
25
|
+
ERROR = "ERROR",
|
|
26
|
+
}
|
|
27
|
+
export enum LogColor {
|
|
28
|
+
DEFAULT = "#B4B4B8",
|
|
29
|
+
SUCCESS = "#65B741",
|
|
30
|
+
INFO = "#40A2D8",
|
|
31
|
+
WARN = "#E3651D",
|
|
32
|
+
ERROR = "#FF0000",
|
|
33
|
+
}
|
|
18
34
|
export const slack: Slack = {
|
|
19
35
|
async log(label: string, data: any) {
|
|
20
36
|
const messageData = JSON.stringify(data);
|
|
@@ -32,7 +48,11 @@ export const slack: Slack = {
|
|
|
32
48
|
};
|
|
33
49
|
await axiosCall(payload);
|
|
34
50
|
},
|
|
35
|
-
async logBlockMessage(
|
|
51
|
+
async logBlockMessage(
|
|
52
|
+
label: string,
|
|
53
|
+
objectData: BlocksInterface[],
|
|
54
|
+
error_type: LogLevel = LogLevel.DEFAULT
|
|
55
|
+
) {
|
|
36
56
|
if (!isValidSlackWebhookUrl()) {
|
|
37
57
|
// SLACK_WEBHOOK_URL is valid
|
|
38
58
|
console.error(
|
|
@@ -40,9 +60,15 @@ export const slack: Slack = {
|
|
|
40
60
|
);
|
|
41
61
|
return null;
|
|
42
62
|
}
|
|
63
|
+
console.log(error_type);
|
|
64
|
+
const messageBodyColor = LogColor[error_type];
|
|
43
65
|
|
|
44
66
|
const blocks: object[] = [];
|
|
45
|
-
|
|
67
|
+
const attachments: object[] = [];
|
|
68
|
+
const attachmentsBlocks: object[] = [];
|
|
69
|
+
blocks.push({
|
|
70
|
+
type: "divider",
|
|
71
|
+
});
|
|
46
72
|
// Label of slack message
|
|
47
73
|
blocks.push({
|
|
48
74
|
type: "header",
|
|
@@ -52,11 +78,14 @@ export const slack: Slack = {
|
|
|
52
78
|
emoji: true,
|
|
53
79
|
},
|
|
54
80
|
});
|
|
81
|
+
blocks.push({
|
|
82
|
+
type: "divider",
|
|
83
|
+
});
|
|
55
84
|
|
|
56
85
|
if (objectData?.length) {
|
|
57
86
|
objectData.forEach((element) => {
|
|
58
87
|
let value = JSON.stringify(element.value);
|
|
59
|
-
|
|
88
|
+
attachmentsBlocks.push({
|
|
60
89
|
type: "section",
|
|
61
90
|
text: {
|
|
62
91
|
type: "mrkdwn",
|
|
@@ -65,10 +94,15 @@ export const slack: Slack = {
|
|
|
65
94
|
});
|
|
66
95
|
});
|
|
67
96
|
}
|
|
97
|
+
attachments.push({
|
|
98
|
+
color: messageBodyColor,
|
|
99
|
+
blocks: attachmentsBlocks,
|
|
100
|
+
});
|
|
68
101
|
|
|
69
102
|
let payload = {
|
|
70
103
|
text: "Application Error!",
|
|
71
104
|
blocks: blocks,
|
|
105
|
+
attachments: attachments,
|
|
72
106
|
};
|
|
73
107
|
await axiosCall(payload);
|
|
74
108
|
},
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,13 +8,29 @@ interface Slack {
|
|
|
8
8
|
log(label: string, data: any): Promise<null | undefined>;
|
|
9
9
|
logBlockMessage(
|
|
10
10
|
label: string,
|
|
11
|
-
objectData: BlocksInterface[]
|
|
11
|
+
objectData: BlocksInterface[],
|
|
12
|
+
error_type?: LogLevel
|
|
12
13
|
): Promise<null | undefined>;
|
|
13
14
|
}
|
|
14
15
|
interface BlocksInterface {
|
|
15
16
|
title: string;
|
|
16
17
|
value: any;
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
export enum LogLevel {
|
|
21
|
+
DEFAULT = "DEFAULT",
|
|
22
|
+
SUCCESS = "SUCCESS",
|
|
23
|
+
INFO = "INFO",
|
|
24
|
+
WARN = "WARN",
|
|
25
|
+
ERROR = "ERROR",
|
|
26
|
+
}
|
|
27
|
+
export enum LogColor {
|
|
28
|
+
DEFAULT = "#B4B4B8",
|
|
29
|
+
SUCCESS = "#65B741",
|
|
30
|
+
INFO = "#40A2D8",
|
|
31
|
+
WARN = "#E3651D",
|
|
32
|
+
ERROR = "#FF0000",
|
|
33
|
+
}
|
|
18
34
|
export const slack: Slack = {
|
|
19
35
|
async log(label: string, data: any) {
|
|
20
36
|
const messageData = JSON.stringify(data);
|
|
@@ -32,7 +48,11 @@ export const slack: Slack = {
|
|
|
32
48
|
};
|
|
33
49
|
await axiosCall(payload);
|
|
34
50
|
},
|
|
35
|
-
async logBlockMessage(
|
|
51
|
+
async logBlockMessage(
|
|
52
|
+
label: string,
|
|
53
|
+
objectData: BlocksInterface[],
|
|
54
|
+
error_type: LogLevel = LogLevel.DEFAULT
|
|
55
|
+
) {
|
|
36
56
|
if (!isValidSlackWebhookUrl()) {
|
|
37
57
|
// SLACK_WEBHOOK_URL is valid
|
|
38
58
|
console.error(
|
|
@@ -40,9 +60,15 @@ export const slack: Slack = {
|
|
|
40
60
|
);
|
|
41
61
|
return null;
|
|
42
62
|
}
|
|
63
|
+
console.log(error_type);
|
|
64
|
+
const messageBodyColor = LogColor[error_type];
|
|
43
65
|
|
|
44
66
|
const blocks: object[] = [];
|
|
45
|
-
|
|
67
|
+
const attachments: object[] = [];
|
|
68
|
+
const attachmentsBlocks: object[] = [];
|
|
69
|
+
blocks.push({
|
|
70
|
+
type: "divider",
|
|
71
|
+
});
|
|
46
72
|
// Label of slack message
|
|
47
73
|
blocks.push({
|
|
48
74
|
type: "header",
|
|
@@ -52,11 +78,14 @@ export const slack: Slack = {
|
|
|
52
78
|
emoji: true,
|
|
53
79
|
},
|
|
54
80
|
});
|
|
81
|
+
blocks.push({
|
|
82
|
+
type: "divider",
|
|
83
|
+
});
|
|
55
84
|
|
|
56
85
|
if (objectData?.length) {
|
|
57
86
|
objectData.forEach((element) => {
|
|
58
87
|
let value = JSON.stringify(element.value);
|
|
59
|
-
|
|
88
|
+
attachmentsBlocks.push({
|
|
60
89
|
type: "section",
|
|
61
90
|
text: {
|
|
62
91
|
type: "mrkdwn",
|
|
@@ -65,10 +94,15 @@ export const slack: Slack = {
|
|
|
65
94
|
});
|
|
66
95
|
});
|
|
67
96
|
}
|
|
97
|
+
attachments.push({
|
|
98
|
+
color: messageBodyColor,
|
|
99
|
+
blocks: attachmentsBlocks,
|
|
100
|
+
});
|
|
68
101
|
|
|
69
102
|
let payload = {
|
|
70
103
|
text: "Application Error!",
|
|
71
104
|
blocks: blocks,
|
|
105
|
+
attachments: attachments,
|
|
72
106
|
};
|
|
73
107
|
await axiosCall(payload);
|
|
74
108
|
},
|