slack-logs 1.1.1 → 1.1.3
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 +70 -0
- package/dist/index.js +5 -7
- package/dist/index.ts +10 -29
- package/package.json +1 -1
- package/src/index.ts +10 -29
package/README.md
CHANGED
|
@@ -88,6 +88,76 @@ slack.logBlockMessage("Validation Message!", payload, LogLevel.WARN);
|
|
|
88
88
|
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
## Sample code with output:
|
|
92
|
+
|
|
93
|
+
#### Sample 1:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
import { slack } from "slack-logs";.
|
|
97
|
+
|
|
98
|
+
slack.log("Data Log with bold", "Here is *BOLD* message");
|
|
99
|
+
slack.log("Highlight Log", "`Message`");
|
|
100
|
+
slack.log("Emoji :rocket: Log", "Yeah :female-technologist::skin-tone-2:");
|
|
101
|
+
slack.log("Object Log", {id:"123", value:"Lorem Impulse"});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+

|
|
105
|
+
|
|
106
|
+
#### Sample 2:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
import { LogLevel, slack } from "slack-logs";.
|
|
110
|
+
|
|
111
|
+
const payload = [
|
|
112
|
+
{ title: "Title 1", value: "1234" },
|
|
113
|
+
{ title: "Title 2", value: 123 },
|
|
114
|
+
{ title: "Title 3", value: { id: 12 } },
|
|
115
|
+
{ title: "Title 4", value: [{ id: 12 }] },
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
slack.logBlockMessage("Custom Logs!", payload);
|
|
119
|
+
slack.logBlockMessage("Some Information Logs!", payload, LogLevel.INFO);
|
|
120
|
+
slack.logBlockMessage("Critical Alert!", payload, LogLevel.ERROR);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+

|
|
124
|
+
|
|
125
|
+
#### Sample 3:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
import { LogLevel, slack } from "slack-logs";.
|
|
129
|
+
|
|
130
|
+
const payload = [
|
|
131
|
+
{ title: "Event Name", value: "directMessage" },
|
|
132
|
+
{
|
|
133
|
+
title: "`to_user` Validation",
|
|
134
|
+
value: "Message 'to_user' is required! Current value is null",
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
slack.logBlockMessage(`Validation failure on "development" server`, payload, LogLevel.WARN);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+

|
|
142
|
+
|
|
143
|
+
#### Sample 3:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
import { LogLevel, slack } from "slack-logs";.
|
|
147
|
+
|
|
148
|
+
const title =
|
|
149
|
+
":rotating_light: Error processing message failure on 'local' server :rotating_light:";
|
|
150
|
+
|
|
151
|
+
const payload = [
|
|
152
|
+
{ title: "Event Name", value: "directMessage" },
|
|
153
|
+
{ title: "`error`", value: {} },
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
slack.logBlockMessage(title, payload, LogLevel.ERROR);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+

|
|
160
|
+
|
|
91
161
|
### Contributing
|
|
92
162
|
|
|
93
163
|
Contributions are welcome! If you have a feature request, bug report, or a pull request, please open an issue or submit a PR on the GitHub repository
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,7 @@ exports.slack = {
|
|
|
63
63
|
type: "divider",
|
|
64
64
|
});
|
|
65
65
|
if (objectData?.length) {
|
|
66
|
-
objectData.forEach(
|
|
66
|
+
objectData.forEach(element => {
|
|
67
67
|
let value = JSON.stringify(element.value);
|
|
68
68
|
attachmentsBlocks.push({
|
|
69
69
|
type: "section",
|
|
@@ -88,9 +88,7 @@ exports.slack = {
|
|
|
88
88
|
};
|
|
89
89
|
function isValidSlackWebhookUrl() {
|
|
90
90
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
91
|
-
if (!common_variables_1.SLACK_WEBHOOK_URL ||
|
|
92
|
-
common_variables_1.SLACK_WEBHOOK_URL == null ||
|
|
93
|
-
typeof common_variables_1.SLACK_WEBHOOK_URL == "undefined") {
|
|
91
|
+
if (!common_variables_1.SLACK_WEBHOOK_URL || common_variables_1.SLACK_WEBHOOK_URL == null || typeof common_variables_1.SLACK_WEBHOOK_URL == "undefined") {
|
|
94
92
|
return false;
|
|
95
93
|
}
|
|
96
94
|
// Check if SLACK_WEBHOOK_URL starts with "https://"
|
|
@@ -101,12 +99,12 @@ async function axiosCall(payload) {
|
|
|
101
99
|
.post(common_variables_1.SLACK_WEBHOOK_URL, JSON.stringify(payload), {
|
|
102
100
|
headers: { "Content-Type": "application/json" },
|
|
103
101
|
})
|
|
104
|
-
.then(
|
|
102
|
+
.then(response => {
|
|
105
103
|
if (common_variables_1.SLACK_DEBUGGER) {
|
|
106
104
|
console.log("✅ Log message sent to Slack successfully");
|
|
107
105
|
}
|
|
108
106
|
})
|
|
109
|
-
.catch(
|
|
110
|
-
console.error("🚨 Error sending log message to Slack:"
|
|
107
|
+
.catch(error => {
|
|
108
|
+
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
111
109
|
});
|
|
112
110
|
}
|
package/dist/index.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SLACK_DEBUGGER,
|
|
3
|
-
SLACK_WEBHOOK_URL,
|
|
4
|
-
} from "./constants/common-variables";
|
|
1
|
+
import { SLACK_DEBUGGER, SLACK_WEBHOOK_URL } from "./constants/common-variables";
|
|
5
2
|
import axios from "axios";
|
|
6
3
|
|
|
7
4
|
interface Slack {
|
|
8
5
|
log(label: string, data: any): Promise<null | undefined>;
|
|
9
|
-
logBlockMessage(
|
|
10
|
-
label: string,
|
|
11
|
-
objectData: BlocksInterface[],
|
|
12
|
-
error_type?: LogLevel
|
|
13
|
-
): Promise<null | undefined>;
|
|
6
|
+
logBlockMessage(label: string, objectData: BlocksInterface[], error_type?: LogLevel): Promise<null | undefined>;
|
|
14
7
|
}
|
|
15
8
|
interface BlocksInterface {
|
|
16
9
|
title: string;
|
|
@@ -36,9 +29,7 @@ export const slack: Slack = {
|
|
|
36
29
|
const messageData = JSON.stringify(data);
|
|
37
30
|
if (!isValidSlackWebhookUrl()) {
|
|
38
31
|
// SLACK_WEBHOOK_URL is valid
|
|
39
|
-
console.error(
|
|
40
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
41
|
-
);
|
|
32
|
+
console.error("🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨");
|
|
42
33
|
return null;
|
|
43
34
|
}
|
|
44
35
|
|
|
@@ -48,16 +39,10 @@ export const slack: Slack = {
|
|
|
48
39
|
};
|
|
49
40
|
await axiosCall(payload);
|
|
50
41
|
},
|
|
51
|
-
async logBlockMessage(
|
|
52
|
-
label: string,
|
|
53
|
-
objectData: BlocksInterface[],
|
|
54
|
-
error_type: LogLevel = LogLevel.DEFAULT
|
|
55
|
-
) {
|
|
42
|
+
async logBlockMessage(label: string, objectData: BlocksInterface[], error_type: LogLevel = LogLevel.DEFAULT) {
|
|
56
43
|
if (!isValidSlackWebhookUrl()) {
|
|
57
44
|
// SLACK_WEBHOOK_URL is valid
|
|
58
|
-
console.error(
|
|
59
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
60
|
-
);
|
|
45
|
+
console.error("🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨");
|
|
61
46
|
return null;
|
|
62
47
|
}
|
|
63
48
|
console.log(error_type);
|
|
@@ -83,7 +68,7 @@ export const slack: Slack = {
|
|
|
83
68
|
});
|
|
84
69
|
|
|
85
70
|
if (objectData?.length) {
|
|
86
|
-
objectData.forEach(
|
|
71
|
+
objectData.forEach(element => {
|
|
87
72
|
let value = JSON.stringify(element.value);
|
|
88
73
|
attachmentsBlocks.push({
|
|
89
74
|
type: "section",
|
|
@@ -110,11 +95,7 @@ export const slack: Slack = {
|
|
|
110
95
|
|
|
111
96
|
function isValidSlackWebhookUrl(): boolean {
|
|
112
97
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
113
|
-
if (
|
|
114
|
-
!SLACK_WEBHOOK_URL ||
|
|
115
|
-
SLACK_WEBHOOK_URL == null ||
|
|
116
|
-
typeof SLACK_WEBHOOK_URL == "undefined"
|
|
117
|
-
) {
|
|
98
|
+
if (!SLACK_WEBHOOK_URL || SLACK_WEBHOOK_URL == null || typeof SLACK_WEBHOOK_URL == "undefined") {
|
|
118
99
|
return false;
|
|
119
100
|
}
|
|
120
101
|
|
|
@@ -127,12 +108,12 @@ async function axiosCall(payload: any) {
|
|
|
127
108
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
128
109
|
headers: { "Content-Type": "application/json" },
|
|
129
110
|
})
|
|
130
|
-
.then(
|
|
111
|
+
.then(response => {
|
|
131
112
|
if (SLACK_DEBUGGER) {
|
|
132
113
|
console.log("✅ Log message sent to Slack successfully");
|
|
133
114
|
}
|
|
134
115
|
})
|
|
135
|
-
.catch(
|
|
136
|
-
console.error("🚨 Error sending log message to Slack:"
|
|
116
|
+
.catch(error => {
|
|
117
|
+
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
137
118
|
});
|
|
138
119
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SLACK_DEBUGGER,
|
|
3
|
-
SLACK_WEBHOOK_URL,
|
|
4
|
-
} from "./constants/common-variables";
|
|
1
|
+
import { SLACK_DEBUGGER, SLACK_WEBHOOK_URL } from "./constants/common-variables";
|
|
5
2
|
import axios from "axios";
|
|
6
3
|
|
|
7
4
|
interface Slack {
|
|
8
5
|
log(label: string, data: any): Promise<null | undefined>;
|
|
9
|
-
logBlockMessage(
|
|
10
|
-
label: string,
|
|
11
|
-
objectData: BlocksInterface[],
|
|
12
|
-
error_type?: LogLevel
|
|
13
|
-
): Promise<null | undefined>;
|
|
6
|
+
logBlockMessage(label: string, objectData: BlocksInterface[], error_type?: LogLevel): Promise<null | undefined>;
|
|
14
7
|
}
|
|
15
8
|
interface BlocksInterface {
|
|
16
9
|
title: string;
|
|
@@ -36,9 +29,7 @@ export const slack: Slack = {
|
|
|
36
29
|
const messageData = JSON.stringify(data);
|
|
37
30
|
if (!isValidSlackWebhookUrl()) {
|
|
38
31
|
// SLACK_WEBHOOK_URL is valid
|
|
39
|
-
console.error(
|
|
40
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
41
|
-
);
|
|
32
|
+
console.error("🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨");
|
|
42
33
|
return null;
|
|
43
34
|
}
|
|
44
35
|
|
|
@@ -48,16 +39,10 @@ export const slack: Slack = {
|
|
|
48
39
|
};
|
|
49
40
|
await axiosCall(payload);
|
|
50
41
|
},
|
|
51
|
-
async logBlockMessage(
|
|
52
|
-
label: string,
|
|
53
|
-
objectData: BlocksInterface[],
|
|
54
|
-
error_type: LogLevel = LogLevel.DEFAULT
|
|
55
|
-
) {
|
|
42
|
+
async logBlockMessage(label: string, objectData: BlocksInterface[], error_type: LogLevel = LogLevel.DEFAULT) {
|
|
56
43
|
if (!isValidSlackWebhookUrl()) {
|
|
57
44
|
// SLACK_WEBHOOK_URL is valid
|
|
58
|
-
console.error(
|
|
59
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
60
|
-
);
|
|
45
|
+
console.error("🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨");
|
|
61
46
|
return null;
|
|
62
47
|
}
|
|
63
48
|
console.log(error_type);
|
|
@@ -83,7 +68,7 @@ export const slack: Slack = {
|
|
|
83
68
|
});
|
|
84
69
|
|
|
85
70
|
if (objectData?.length) {
|
|
86
|
-
objectData.forEach(
|
|
71
|
+
objectData.forEach(element => {
|
|
87
72
|
let value = JSON.stringify(element.value);
|
|
88
73
|
attachmentsBlocks.push({
|
|
89
74
|
type: "section",
|
|
@@ -110,11 +95,7 @@ export const slack: Slack = {
|
|
|
110
95
|
|
|
111
96
|
function isValidSlackWebhookUrl(): boolean {
|
|
112
97
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
113
|
-
if (
|
|
114
|
-
!SLACK_WEBHOOK_URL ||
|
|
115
|
-
SLACK_WEBHOOK_URL == null ||
|
|
116
|
-
typeof SLACK_WEBHOOK_URL == "undefined"
|
|
117
|
-
) {
|
|
98
|
+
if (!SLACK_WEBHOOK_URL || SLACK_WEBHOOK_URL == null || typeof SLACK_WEBHOOK_URL == "undefined") {
|
|
118
99
|
return false;
|
|
119
100
|
}
|
|
120
101
|
|
|
@@ -127,12 +108,12 @@ async function axiosCall(payload: any) {
|
|
|
127
108
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
128
109
|
headers: { "Content-Type": "application/json" },
|
|
129
110
|
})
|
|
130
|
-
.then(
|
|
111
|
+
.then(response => {
|
|
131
112
|
if (SLACK_DEBUGGER) {
|
|
132
113
|
console.log("✅ Log message sent to Slack successfully");
|
|
133
114
|
}
|
|
134
115
|
})
|
|
135
|
-
.catch(
|
|
136
|
-
console.error("🚨 Error sending log message to Slack:"
|
|
116
|
+
.catch(error => {
|
|
117
|
+
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
137
118
|
});
|
|
138
119
|
}
|