slack-logs 1.1.3 → 1.2.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/dist/index.js +13 -12
- package/dist/index.ts +34 -15
- package/package.json +1 -1
- package/src/index.ts +34 -15
- package/tsconfig.json +12 -12
- package/dist/constants/common-variables.js +0 -7
- package/dist/constants/common-variables.ts +0 -4
- package/src/constants/common-variables.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.slack = exports.LogColor = exports.LogLevel = void 0;
|
|
7
|
-
const common_variables_1 = require("./constants/common-variables");
|
|
8
7
|
const axios_1 = __importDefault(require("axios"));
|
|
9
8
|
var LogLevel;
|
|
10
9
|
(function (LogLevel) {
|
|
@@ -63,7 +62,7 @@ exports.slack = {
|
|
|
63
62
|
type: "divider",
|
|
64
63
|
});
|
|
65
64
|
if (objectData?.length) {
|
|
66
|
-
objectData.forEach(element => {
|
|
65
|
+
objectData.forEach((element) => {
|
|
67
66
|
let value = JSON.stringify(element.value);
|
|
68
67
|
attachmentsBlocks.push({
|
|
69
68
|
type: "section",
|
|
@@ -79,7 +78,7 @@ exports.slack = {
|
|
|
79
78
|
blocks: attachmentsBlocks,
|
|
80
79
|
});
|
|
81
80
|
let payload = {
|
|
82
|
-
text:
|
|
81
|
+
text: label,
|
|
83
82
|
blocks: blocks,
|
|
84
83
|
attachments: attachments,
|
|
85
84
|
};
|
|
@@ -87,24 +86,26 @@ exports.slack = {
|
|
|
87
86
|
},
|
|
88
87
|
};
|
|
89
88
|
function isValidSlackWebhookUrl() {
|
|
89
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
90
90
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
91
|
-
if (!
|
|
91
|
+
if (!SLACK_WEBHOOK_URL ||
|
|
92
|
+
SLACK_WEBHOOK_URL == null ||
|
|
93
|
+
typeof SLACK_WEBHOOK_URL == "undefined") {
|
|
92
94
|
return false;
|
|
93
95
|
}
|
|
94
96
|
// Check if SLACK_WEBHOOK_URL starts with "https://"
|
|
95
|
-
return
|
|
97
|
+
return SLACK_WEBHOOK_URL.startsWith("https://");
|
|
96
98
|
}
|
|
97
99
|
async function axiosCall(payload) {
|
|
100
|
+
const DISABLE_SLACK_LOGS = process?.env?.DISABLE_SLACK_LOGS === "false";
|
|
101
|
+
if (DISABLE_SLACK_LOGS)
|
|
102
|
+
return false;
|
|
103
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
98
104
|
return await axios_1.default
|
|
99
|
-
.post(
|
|
105
|
+
.post(SLACK_WEBHOOK_URL, JSON.stringify(payload), {
|
|
100
106
|
headers: { "Content-Type": "application/json" },
|
|
101
107
|
})
|
|
102
|
-
.
|
|
103
|
-
if (common_variables_1.SLACK_DEBUGGER) {
|
|
104
|
-
console.log("✅ Log message sent to Slack successfully");
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.catch(error => {
|
|
108
|
+
.catch((error) => {
|
|
108
109
|
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
109
110
|
});
|
|
110
111
|
}
|
package/dist/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { SLACK_DEBUGGER, SLACK_WEBHOOK_URL } from "./constants/common-variables";
|
|
2
1
|
import axios from "axios";
|
|
3
2
|
|
|
4
3
|
interface Slack {
|
|
5
4
|
log(label: string, data: any): Promise<null | undefined>;
|
|
6
|
-
logBlockMessage(
|
|
5
|
+
logBlockMessage(
|
|
6
|
+
label: string,
|
|
7
|
+
objectData: BlocksInterface[],
|
|
8
|
+
error_type?: LogLevel
|
|
9
|
+
): Promise<null | undefined>;
|
|
7
10
|
}
|
|
8
11
|
interface BlocksInterface {
|
|
9
12
|
title: string;
|
|
@@ -29,7 +32,9 @@ export const slack: Slack = {
|
|
|
29
32
|
const messageData = JSON.stringify(data);
|
|
30
33
|
if (!isValidSlackWebhookUrl()) {
|
|
31
34
|
// SLACK_WEBHOOK_URL is valid
|
|
32
|
-
console.error(
|
|
35
|
+
console.error(
|
|
36
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
37
|
+
);
|
|
33
38
|
return null;
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -39,10 +44,16 @@ export const slack: Slack = {
|
|
|
39
44
|
};
|
|
40
45
|
await axiosCall(payload);
|
|
41
46
|
},
|
|
42
|
-
async logBlockMessage(
|
|
47
|
+
async logBlockMessage(
|
|
48
|
+
label: string,
|
|
49
|
+
objectData: BlocksInterface[],
|
|
50
|
+
error_type: LogLevel = LogLevel.DEFAULT
|
|
51
|
+
) {
|
|
43
52
|
if (!isValidSlackWebhookUrl()) {
|
|
44
53
|
// SLACK_WEBHOOK_URL is valid
|
|
45
|
-
console.error(
|
|
54
|
+
console.error(
|
|
55
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨",
|
|
56
|
+
);
|
|
46
57
|
return null;
|
|
47
58
|
}
|
|
48
59
|
console.log(error_type);
|
|
@@ -68,7 +79,7 @@ export const slack: Slack = {
|
|
|
68
79
|
});
|
|
69
80
|
|
|
70
81
|
if (objectData?.length) {
|
|
71
|
-
objectData.forEach(element => {
|
|
82
|
+
objectData.forEach((element) => {
|
|
72
83
|
let value = JSON.stringify(element.value);
|
|
73
84
|
attachmentsBlocks.push({
|
|
74
85
|
type: "section",
|
|
@@ -85,7 +96,7 @@ export const slack: Slack = {
|
|
|
85
96
|
});
|
|
86
97
|
|
|
87
98
|
let payload = {
|
|
88
|
-
text:
|
|
99
|
+
text: label,
|
|
89
100
|
blocks: blocks,
|
|
90
101
|
attachments: attachments,
|
|
91
102
|
};
|
|
@@ -94,8 +105,13 @@ export const slack: Slack = {
|
|
|
94
105
|
};
|
|
95
106
|
|
|
96
107
|
function isValidSlackWebhookUrl(): boolean {
|
|
108
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
97
109
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
98
|
-
if (
|
|
110
|
+
if (
|
|
111
|
+
!SLACK_WEBHOOK_URL ||
|
|
112
|
+
SLACK_WEBHOOK_URL == null ||
|
|
113
|
+
typeof SLACK_WEBHOOK_URL == "undefined"
|
|
114
|
+
) {
|
|
99
115
|
return false;
|
|
100
116
|
}
|
|
101
117
|
|
|
@@ -104,16 +120,19 @@ function isValidSlackWebhookUrl(): boolean {
|
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
async function axiosCall(payload: any) {
|
|
123
|
+
const DISABLE_SLACK_LOGS: boolean =
|
|
124
|
+
process?.env?.DISABLE_SLACK_LOGS === "false";
|
|
125
|
+
|
|
126
|
+
if (DISABLE_SLACK_LOGS) return false;
|
|
127
|
+
|
|
128
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
107
129
|
return await axios
|
|
108
130
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
109
131
|
headers: { "Content-Type": "application/json" },
|
|
110
132
|
})
|
|
111
|
-
.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
116
|
-
.catch(error => {
|
|
117
|
-
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
console.error(
|
|
135
|
+
"🚨 Error sending log message to Slack: Webhook URL might be updated!"
|
|
136
|
+
);
|
|
118
137
|
});
|
|
119
138
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { SLACK_DEBUGGER, SLACK_WEBHOOK_URL } from "./constants/common-variables";
|
|
2
1
|
import axios from "axios";
|
|
3
2
|
|
|
4
3
|
interface Slack {
|
|
5
4
|
log(label: string, data: any): Promise<null | undefined>;
|
|
6
|
-
logBlockMessage(
|
|
5
|
+
logBlockMessage(
|
|
6
|
+
label: string,
|
|
7
|
+
objectData: BlocksInterface[],
|
|
8
|
+
error_type?: LogLevel
|
|
9
|
+
): Promise<null | undefined>;
|
|
7
10
|
}
|
|
8
11
|
interface BlocksInterface {
|
|
9
12
|
title: string;
|
|
@@ -29,7 +32,9 @@ export const slack: Slack = {
|
|
|
29
32
|
const messageData = JSON.stringify(data);
|
|
30
33
|
if (!isValidSlackWebhookUrl()) {
|
|
31
34
|
// SLACK_WEBHOOK_URL is valid
|
|
32
|
-
console.error(
|
|
35
|
+
console.error(
|
|
36
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
37
|
+
);
|
|
33
38
|
return null;
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -39,10 +44,16 @@ export const slack: Slack = {
|
|
|
39
44
|
};
|
|
40
45
|
await axiosCall(payload);
|
|
41
46
|
},
|
|
42
|
-
async logBlockMessage(
|
|
47
|
+
async logBlockMessage(
|
|
48
|
+
label: string,
|
|
49
|
+
objectData: BlocksInterface[],
|
|
50
|
+
error_type: LogLevel = LogLevel.DEFAULT
|
|
51
|
+
) {
|
|
43
52
|
if (!isValidSlackWebhookUrl()) {
|
|
44
53
|
// SLACK_WEBHOOK_URL is valid
|
|
45
|
-
console.error(
|
|
54
|
+
console.error(
|
|
55
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨",
|
|
56
|
+
);
|
|
46
57
|
return null;
|
|
47
58
|
}
|
|
48
59
|
console.log(error_type);
|
|
@@ -68,7 +79,7 @@ export const slack: Slack = {
|
|
|
68
79
|
});
|
|
69
80
|
|
|
70
81
|
if (objectData?.length) {
|
|
71
|
-
objectData.forEach(element => {
|
|
82
|
+
objectData.forEach((element) => {
|
|
72
83
|
let value = JSON.stringify(element.value);
|
|
73
84
|
attachmentsBlocks.push({
|
|
74
85
|
type: "section",
|
|
@@ -85,7 +96,7 @@ export const slack: Slack = {
|
|
|
85
96
|
});
|
|
86
97
|
|
|
87
98
|
let payload = {
|
|
88
|
-
text:
|
|
99
|
+
text: label,
|
|
89
100
|
blocks: blocks,
|
|
90
101
|
attachments: attachments,
|
|
91
102
|
};
|
|
@@ -94,8 +105,13 @@ export const slack: Slack = {
|
|
|
94
105
|
};
|
|
95
106
|
|
|
96
107
|
function isValidSlackWebhookUrl(): boolean {
|
|
108
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
97
109
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
98
|
-
if (
|
|
110
|
+
if (
|
|
111
|
+
!SLACK_WEBHOOK_URL ||
|
|
112
|
+
SLACK_WEBHOOK_URL == null ||
|
|
113
|
+
typeof SLACK_WEBHOOK_URL == "undefined"
|
|
114
|
+
) {
|
|
99
115
|
return false;
|
|
100
116
|
}
|
|
101
117
|
|
|
@@ -104,16 +120,19 @@ function isValidSlackWebhookUrl(): boolean {
|
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
async function axiosCall(payload: any) {
|
|
123
|
+
const DISABLE_SLACK_LOGS: boolean =
|
|
124
|
+
process?.env?.DISABLE_SLACK_LOGS === "false";
|
|
125
|
+
|
|
126
|
+
if (DISABLE_SLACK_LOGS) return false;
|
|
127
|
+
|
|
128
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
107
129
|
return await axios
|
|
108
130
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
109
131
|
headers: { "Content-Type": "application/json" },
|
|
110
132
|
})
|
|
111
|
-
.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
116
|
-
.catch(error => {
|
|
117
|
-
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
console.error(
|
|
135
|
+
"🚨 Error sending log message to Slack: Webhook URL might be updated!"
|
|
136
|
+
);
|
|
118
137
|
});
|
|
119
138
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./dist",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "CommonJS",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true
|
|
11
|
+
},
|
|
12
|
+
"exclude": ["node_modules", "dist"]
|
|
13
|
+
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SLACK_DEBUGGER = exports.SLACK_WEBHOOK_URL = void 0;
|
|
4
|
-
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
5
|
-
exports.SLACK_WEBHOOK_URL = SLACK_WEBHOOK_URL;
|
|
6
|
-
const SLACK_DEBUGGER = process?.env?.SLACK_DEBUGGER === "true";
|
|
7
|
-
exports.SLACK_DEBUGGER = SLACK_DEBUGGER;
|