mynth-logger 2.0.9 → 2.0.10
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.
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
check-latest: true
|
|
22
22
|
|
|
23
23
|
- name: Update npm
|
|
24
|
-
run: npm install -g npm@
|
|
24
|
+
run: npm install -g npm@"<11"
|
|
25
25
|
|
|
26
26
|
- name: Install dependencies
|
|
27
27
|
run: npm ci --include dev
|
|
@@ -43,7 +43,7 @@ jobs:
|
|
|
43
43
|
check-latest: true
|
|
44
44
|
|
|
45
45
|
- name: Update npm
|
|
46
|
-
run: npm install -g npm@
|
|
46
|
+
run: npm install -g npm@"<11"
|
|
47
47
|
|
|
48
48
|
- name: Install dependencies
|
|
49
49
|
run: npm ci --include dev
|
|
@@ -66,7 +66,7 @@ jobs:
|
|
|
66
66
|
check-latest: true
|
|
67
67
|
|
|
68
68
|
- name: Update npm
|
|
69
|
-
run: npm install -g npm@
|
|
69
|
+
run: npm install -g npm@"<11"
|
|
70
70
|
|
|
71
71
|
- name: Install dependencies
|
|
72
72
|
run: npm install --include dev
|
|
@@ -2,23 +2,47 @@ import { format } from "../format.js";
|
|
|
2
2
|
import { type } from "arktype";
|
|
3
3
|
import got from "got";
|
|
4
4
|
const Discord = type({
|
|
5
|
-
discord:
|
|
5
|
+
discord: "true",
|
|
6
6
|
color: "string",
|
|
7
7
|
title: "string",
|
|
8
|
-
webhookUrl: "string",
|
|
8
|
+
"webhookUrl?": "string.url",
|
|
9
|
+
});
|
|
10
|
+
const ConfigureDiscord = type({
|
|
11
|
+
discord: "true",
|
|
12
|
+
setWebhookUrl: "string.url",
|
|
9
13
|
});
|
|
10
14
|
const NullDiscord = { discord: false };
|
|
11
15
|
const Reporter = {
|
|
16
|
+
webhookUrl: "",
|
|
12
17
|
log: (logObj) => {
|
|
18
|
+
if (configureDiscord(logObj.args)) {
|
|
19
|
+
logObj.args = ["Set Discord webhook URL"];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
13
22
|
const [discord, args] = getDiscord(logObj.args);
|
|
14
23
|
if (!discord.discord)
|
|
15
24
|
return;
|
|
16
|
-
|
|
25
|
+
const webhookUrl = discord.webhookUrl || Reporter.webhookUrl;
|
|
26
|
+
if (!webhookUrl) {
|
|
27
|
+
console.error("Discord webhook URL is missing");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
sendToDiscord(format(args), discord, webhookUrl);
|
|
17
31
|
// Filter Discord data before the other reporters
|
|
18
32
|
// process the message
|
|
19
33
|
logObj.args = args;
|
|
20
34
|
},
|
|
21
35
|
};
|
|
36
|
+
const configureDiscord = (args) => {
|
|
37
|
+
for (const arg of args) {
|
|
38
|
+
const config = ConfigureDiscord(arg);
|
|
39
|
+
if (!(config instanceof type.errors)) {
|
|
40
|
+
Reporter.webhookUrl = config.setWebhookUrl;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
22
46
|
const getDiscord = (args) => {
|
|
23
47
|
for (let i = 0; i < args.length; i++) {
|
|
24
48
|
const discord = Discord(args[i]);
|
|
@@ -28,7 +52,7 @@ const getDiscord = (args) => {
|
|
|
28
52
|
}
|
|
29
53
|
return [NullDiscord, args];
|
|
30
54
|
};
|
|
31
|
-
const sendToDiscord = async (description, options) => {
|
|
55
|
+
const sendToDiscord = async (description, options, webhookUrl) => {
|
|
32
56
|
const data = {
|
|
33
57
|
json: {
|
|
34
58
|
embeds: [
|
|
@@ -42,7 +66,7 @@ const sendToDiscord = async (description, options) => {
|
|
|
42
66
|
retry: { limit: 5 },
|
|
43
67
|
};
|
|
44
68
|
try {
|
|
45
|
-
await got.post(
|
|
69
|
+
await got.post(webhookUrl, data);
|
|
46
70
|
}
|
|
47
71
|
catch (error) {
|
|
48
72
|
console.error("Unable to send message to Discord", error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mynth-logger",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Package to format logs for mynth microservices.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "git@github.com-mynth:MynthAI/mynth-logger.git"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"arktype": "^2.0.
|
|
25
|
+
"arktype": "^2.0.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@ungap/structured-clone": "^1.2.0",
|
package/src/reporters/discord.ts
CHANGED
|
@@ -4,10 +4,15 @@ import { type } from "arktype";
|
|
|
4
4
|
import got from "got";
|
|
5
5
|
|
|
6
6
|
const Discord = type({
|
|
7
|
-
discord:
|
|
7
|
+
discord: "true",
|
|
8
8
|
color: "string",
|
|
9
9
|
title: "string",
|
|
10
|
-
webhookUrl: "string",
|
|
10
|
+
"webhookUrl?": "string.url",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const ConfigureDiscord = type({
|
|
14
|
+
discord: "true",
|
|
15
|
+
setWebhookUrl: "string.url",
|
|
11
16
|
});
|
|
12
17
|
|
|
13
18
|
type Discord = typeof Discord.infer;
|
|
@@ -17,11 +22,24 @@ const NullDiscord = { discord: false } as const;
|
|
|
17
22
|
type NullDiscord = typeof NullDiscord;
|
|
18
23
|
|
|
19
24
|
const Reporter = {
|
|
25
|
+
webhookUrl: "",
|
|
20
26
|
log: (logObj: LogObject) => {
|
|
27
|
+
if (configureDiscord(logObj.args)) {
|
|
28
|
+
logObj.args = ["Set Discord webhook URL"];
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
const [discord, args] = getDiscord(logObj.args);
|
|
22
33
|
if (!discord.discord) return;
|
|
23
34
|
|
|
24
|
-
|
|
35
|
+
const webhookUrl = discord.webhookUrl || Reporter.webhookUrl;
|
|
36
|
+
|
|
37
|
+
if (!webhookUrl) {
|
|
38
|
+
console.error("Discord webhook URL is missing");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
sendToDiscord(format(args), discord, webhookUrl);
|
|
25
43
|
|
|
26
44
|
// Filter Discord data before the other reporters
|
|
27
45
|
// process the message
|
|
@@ -29,6 +47,19 @@ const Reporter = {
|
|
|
29
47
|
},
|
|
30
48
|
};
|
|
31
49
|
|
|
50
|
+
const configureDiscord = (args: unknown[]): boolean => {
|
|
51
|
+
for (const arg of args) {
|
|
52
|
+
const config = ConfigureDiscord(arg);
|
|
53
|
+
|
|
54
|
+
if (!(config instanceof type.errors)) {
|
|
55
|
+
Reporter.webhookUrl = config.setWebhookUrl;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
|
|
32
63
|
const getDiscord = (args: unknown[]): [Discord | NullDiscord, unknown[]] => {
|
|
33
64
|
for (let i = 0; i < args.length; i++) {
|
|
34
65
|
const discord = Discord(args[i]);
|
|
@@ -40,7 +71,11 @@ const getDiscord = (args: unknown[]): [Discord | NullDiscord, unknown[]] => {
|
|
|
40
71
|
return [NullDiscord, args];
|
|
41
72
|
};
|
|
42
73
|
|
|
43
|
-
const sendToDiscord = async (
|
|
74
|
+
const sendToDiscord = async (
|
|
75
|
+
description: string,
|
|
76
|
+
options: Discord,
|
|
77
|
+
webhookUrl: string
|
|
78
|
+
) => {
|
|
44
79
|
const data = {
|
|
45
80
|
json: {
|
|
46
81
|
embeds: [
|
|
@@ -55,7 +90,7 @@ const sendToDiscord = async (description: string, options: Discord) => {
|
|
|
55
90
|
};
|
|
56
91
|
|
|
57
92
|
try {
|
|
58
|
-
await got.post(
|
|
93
|
+
await got.post(webhookUrl, data);
|
|
59
94
|
} catch (error) {
|
|
60
95
|
console.error("Unable to send message to Discord", error);
|
|
61
96
|
}
|