slack-logs 1.1.2 → 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 +12 -13
- package/dist/index.ts +12 -12
- package/package.json +1 -1
- package/src/index.ts +12 -12
- 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) {
|
|
@@ -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,26 +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 (!
|
|
92
|
-
|
|
93
|
-
typeof
|
|
91
|
+
if (!SLACK_WEBHOOK_URL ||
|
|
92
|
+
SLACK_WEBHOOK_URL == null ||
|
|
93
|
+
typeof SLACK_WEBHOOK_URL == "undefined") {
|
|
94
94
|
return false;
|
|
95
95
|
}
|
|
96
96
|
// Check if SLACK_WEBHOOK_URL starts with "https://"
|
|
97
|
-
return
|
|
97
|
+
return SLACK_WEBHOOK_URL.startsWith("https://");
|
|
98
98
|
}
|
|
99
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;
|
|
100
104
|
return await axios_1.default
|
|
101
|
-
.post(
|
|
105
|
+
.post(SLACK_WEBHOOK_URL, JSON.stringify(payload), {
|
|
102
106
|
headers: { "Content-Type": "application/json" },
|
|
103
|
-
})
|
|
104
|
-
.then((response) => {
|
|
105
|
-
if (common_variables_1.SLACK_DEBUGGER) {
|
|
106
|
-
console.log("✅ Log message sent to Slack successfully");
|
|
107
|
-
}
|
|
108
107
|
})
|
|
109
108
|
.catch((error) => {
|
|
110
|
-
console.error("🚨 Error sending log message to Slack:"
|
|
109
|
+
console.error("🚨 Error sending log message to Slack: Webhook URL might be updated!");
|
|
111
110
|
});
|
|
112
111
|
}
|
package/dist/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SLACK_DEBUGGER,
|
|
3
|
-
SLACK_WEBHOOK_URL,
|
|
4
|
-
} from "./constants/common-variables";
|
|
5
1
|
import axios from "axios";
|
|
6
2
|
|
|
7
3
|
interface Slack {
|
|
@@ -56,7 +52,7 @@ export const slack: Slack = {
|
|
|
56
52
|
if (!isValidSlackWebhookUrl()) {
|
|
57
53
|
// SLACK_WEBHOOK_URL is valid
|
|
58
54
|
console.error(
|
|
59
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
55
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨",
|
|
60
56
|
);
|
|
61
57
|
return null;
|
|
62
58
|
}
|
|
@@ -100,7 +96,7 @@ export const slack: Slack = {
|
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
let payload = {
|
|
103
|
-
text:
|
|
99
|
+
text: label,
|
|
104
100
|
blocks: blocks,
|
|
105
101
|
attachments: attachments,
|
|
106
102
|
};
|
|
@@ -109,6 +105,7 @@ export const slack: Slack = {
|
|
|
109
105
|
};
|
|
110
106
|
|
|
111
107
|
function isValidSlackWebhookUrl(): boolean {
|
|
108
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
112
109
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
113
110
|
if (
|
|
114
111
|
!SLACK_WEBHOOK_URL ||
|
|
@@ -123,16 +120,19 @@ function isValidSlackWebhookUrl(): boolean {
|
|
|
123
120
|
}
|
|
124
121
|
|
|
125
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;
|
|
126
129
|
return await axios
|
|
127
130
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
128
131
|
headers: { "Content-Type": "application/json" },
|
|
129
132
|
})
|
|
130
|
-
.then((response) => {
|
|
131
|
-
if (SLACK_DEBUGGER) {
|
|
132
|
-
console.log("✅ Log message sent to Slack successfully");
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
133
|
.catch((error) => {
|
|
136
|
-
console.error(
|
|
134
|
+
console.error(
|
|
135
|
+
"🚨 Error sending log message to Slack: Webhook URL might be updated!"
|
|
136
|
+
);
|
|
137
137
|
});
|
|
138
138
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SLACK_DEBUGGER,
|
|
3
|
-
SLACK_WEBHOOK_URL,
|
|
4
|
-
} from "./constants/common-variables";
|
|
5
1
|
import axios from "axios";
|
|
6
2
|
|
|
7
3
|
interface Slack {
|
|
@@ -56,7 +52,7 @@ export const slack: Slack = {
|
|
|
56
52
|
if (!isValidSlackWebhookUrl()) {
|
|
57
53
|
// SLACK_WEBHOOK_URL is valid
|
|
58
54
|
console.error(
|
|
59
|
-
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨"
|
|
55
|
+
"🚨 Invalid Slack webhook URL. Kindly check 'SLACK_WEBHOOK_URL' in your .env file! 🚨",
|
|
60
56
|
);
|
|
61
57
|
return null;
|
|
62
58
|
}
|
|
@@ -100,7 +96,7 @@ export const slack: Slack = {
|
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
let payload = {
|
|
103
|
-
text:
|
|
99
|
+
text: label,
|
|
104
100
|
blocks: blocks,
|
|
105
101
|
attachments: attachments,
|
|
106
102
|
};
|
|
@@ -109,6 +105,7 @@ export const slack: Slack = {
|
|
|
109
105
|
};
|
|
110
106
|
|
|
111
107
|
function isValidSlackWebhookUrl(): boolean {
|
|
108
|
+
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
|
|
112
109
|
// Check if SLACK_WEBHOOK_URL is not null or undefined
|
|
113
110
|
if (
|
|
114
111
|
!SLACK_WEBHOOK_URL ||
|
|
@@ -123,16 +120,19 @@ function isValidSlackWebhookUrl(): boolean {
|
|
|
123
120
|
}
|
|
124
121
|
|
|
125
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;
|
|
126
129
|
return await axios
|
|
127
130
|
.post(SLACK_WEBHOOK_URL as string, JSON.stringify(payload), {
|
|
128
131
|
headers: { "Content-Type": "application/json" },
|
|
129
132
|
})
|
|
130
|
-
.then((response) => {
|
|
131
|
-
if (SLACK_DEBUGGER) {
|
|
132
|
-
console.log("✅ Log message sent to Slack successfully");
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
133
|
.catch((error) => {
|
|
136
|
-
console.error(
|
|
134
|
+
console.error(
|
|
135
|
+
"🚨 Error sending log message to Slack: Webhook URL might be updated!"
|
|
136
|
+
);
|
|
137
137
|
});
|
|
138
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;
|