dicoshot-core 0.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/dist/client/dicoshot.client.d.ts +5 -0
- package/dist/client/dicoshot.client.d.ts.map +1 -0
- package/dist/client/dicoshot.client.impl.d.ts +9 -0
- package/dist/client/dicoshot.client.impl.d.ts.map +1 -0
- package/dist/client/dicoshot.client.impl.js +20 -0
- package/dist/client/dicoshot.client.impl.js.map +1 -0
- package/dist/client/dicoshot.client.js +3 -0
- package/dist/client/dicoshot.client.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/message/discord.message.d.ts +17 -0
- package/dist/message/discord.message.d.ts.map +1 -0
- package/dist/message/discord.message.js +3 -0
- package/dist/message/discord.message.js.map +1 -0
- package/dist/message/message.factory.d.ts +11 -0
- package/dist/message/message.factory.d.ts.map +1 -0
- package/dist/message/message.factory.js +87 -0
- package/dist/message/message.factory.js.map +1 -0
- package/dist/options/dicoshot.options.d.ts +10 -0
- package/dist/options/dicoshot.options.d.ts.map +1 -0
- package/dist/options/dicoshot.options.js +3 -0
- package/dist/options/dicoshot.options.js.map +1 -0
- package/package.json +16 -0
- package/src/client/dicoshot.client.impl.ts +15 -0
- package/src/client/dicoshot.client.ts +5 -0
- package/src/index.ts +5 -0
- package/src/message/discord.message.ts +18 -0
- package/src/message/message.factory.ts +57 -0
- package/src/options/dicoshot.options.ts +9 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.client.d.ts","sourceRoot":"","sources":["../../src/client/dicoshot.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DicoshotOptions } from '../options/dicoshot.options';
|
|
2
|
+
import { DiscordMessage } from '../message/discord.message';
|
|
3
|
+
import { DicoshotClient } from './dicoshot.client';
|
|
4
|
+
export declare class DicoshotClientImpl implements DicoshotClient {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options: DicoshotOptions);
|
|
7
|
+
send(message: DiscordMessage): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=dicoshot.client.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.client.impl.d.ts","sourceRoot":"","sources":["../../src/client/dicoshot.client.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,kBAAmB,YAAW,cAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,eAAe;IAE/C,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAMnD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DicoshotClientImpl = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class DicoshotClientImpl {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async send(message) {
|
|
13
|
+
await axios_1.default.post(this.options.webhookUrl, message, {
|
|
14
|
+
timeout: this.options.timeoutMs ?? 5000,
|
|
15
|
+
headers: { 'Content-Type': 'application/json' },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DicoshotClientImpl = DicoshotClientImpl;
|
|
20
|
+
//# sourceMappingURL=dicoshot.client.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.client.impl.js","sourceRoot":"","sources":["../../src/client/dicoshot.client.impl.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAK1B,MAAa,kBAAkB;IAC7B,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEzD,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,MAAM,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE;YACjD,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI;YACvC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC;CACF;AATD,gDASC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.client.js","sourceRoot":"","sources":["../../src/client/dicoshot.client.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { DicoshotOptions } from './options/dicoshot.options';
|
|
2
|
+
export type { DiscordField, DiscordEmbed, DiscordMessage } from './message/discord.message';
|
|
3
|
+
export { MessageFactory } from './message/message.factory';
|
|
4
|
+
export type { DicoshotClient } from './client/dicoshot.client';
|
|
5
|
+
export { DicoshotClientImpl } from './client/dicoshot.client.impl';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DicoshotClientImpl = exports.MessageFactory = void 0;
|
|
4
|
+
var message_factory_1 = require("./message/message.factory");
|
|
5
|
+
Object.defineProperty(exports, "MessageFactory", { enumerable: true, get: function () { return message_factory_1.MessageFactory; } });
|
|
6
|
+
var dicoshot_client_impl_1 = require("./client/dicoshot.client.impl");
|
|
7
|
+
Object.defineProperty(exports, "DicoshotClientImpl", { enumerable: true, get: function () { return dicoshot_client_impl_1.DicoshotClientImpl; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,6DAA2D;AAAlD,iHAAA,cAAc,OAAA;AAEvB,sEAAmE;AAA1D,0HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface DiscordField {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
inline?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface DiscordEmbed {
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
color?: number;
|
|
10
|
+
fields?: DiscordField[];
|
|
11
|
+
timestamp?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DiscordMessage {
|
|
14
|
+
username?: string;
|
|
15
|
+
embeds?: DiscordEmbed[];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=discord.message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord.message.d.ts","sourceRoot":"","sources":["../../src/message/discord.message.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord.message.js","sourceRoot":"","sources":["../../src/message/discord.message.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DicoshotOptions } from '../options/dicoshot.options';
|
|
2
|
+
import { DiscordMessage } from './discord.message';
|
|
3
|
+
export declare class MessageFactory {
|
|
4
|
+
private readonly options;
|
|
5
|
+
private readonly version;
|
|
6
|
+
private readonly env;
|
|
7
|
+
constructor(options: DicoshotOptions);
|
|
8
|
+
startup(): DiscordMessage;
|
|
9
|
+
shutdown(): DiscordMessage;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=message.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.factory.d.ts","sourceRoot":"","sources":["../../src/message/message.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKnD,qBAAa,cAAc;IAIb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAEA,OAAO,EAAE,eAAe;IAKrD,OAAO,IAAI,cAAc;IAqBzB,QAAQ,IAAI,cAAc;CAmB3B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MessageFactory = void 0;
|
|
37
|
+
const os = __importStar(require("os"));
|
|
38
|
+
const STARTUP_COLOR = 5763719;
|
|
39
|
+
const SHUTDOWN_COLOR = 15548997;
|
|
40
|
+
class MessageFactory {
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
this.version = process.env['npm_package_version'] ?? '0.0.0';
|
|
44
|
+
this.env = process.env['NODE_ENV'] ?? 'development';
|
|
45
|
+
}
|
|
46
|
+
startup() {
|
|
47
|
+
const now = new Date().toISOString();
|
|
48
|
+
return {
|
|
49
|
+
username: this.options.username,
|
|
50
|
+
embeds: [
|
|
51
|
+
{
|
|
52
|
+
title: '🟢 Application Started',
|
|
53
|
+
color: STARTUP_COLOR,
|
|
54
|
+
fields: [
|
|
55
|
+
{ name: 'Service', value: this.options.applicationName ?? 'Unknown', inline: true },
|
|
56
|
+
{ name: 'Environment', value: this.env, inline: true },
|
|
57
|
+
{ name: 'Version', value: this.version, inline: true },
|
|
58
|
+
{ name: 'Hostname', value: os.hostname(), inline: true },
|
|
59
|
+
{ name: 'Time', value: now, inline: false },
|
|
60
|
+
],
|
|
61
|
+
timestamp: now,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
shutdown() {
|
|
67
|
+
const now = new Date().toISOString();
|
|
68
|
+
return {
|
|
69
|
+
username: this.options.username,
|
|
70
|
+
embeds: [
|
|
71
|
+
{
|
|
72
|
+
title: '🔴 Application Stopped',
|
|
73
|
+
color: SHUTDOWN_COLOR,
|
|
74
|
+
fields: [
|
|
75
|
+
{ name: 'Service', value: this.options.applicationName ?? 'Unknown', inline: true },
|
|
76
|
+
{ name: 'Environment', value: this.env, inline: true },
|
|
77
|
+
{ name: 'Hostname', value: os.hostname(), inline: true },
|
|
78
|
+
{ name: 'Time', value: now, inline: false },
|
|
79
|
+
],
|
|
80
|
+
timestamp: now,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.MessageFactory = MessageFactory;
|
|
87
|
+
//# sourceMappingURL=message.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.factory.js","sourceRoot":"","sources":["../../src/message/message.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAIzB,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC,MAAa,cAAc;IAIzB,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,OAAO,CAAC;QAC7D,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,aAAa,CAAC;IACtD,CAAC;IAED,OAAO;QACL,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,MAAM,EAAE;gBACN;oBACE,KAAK,EAAE,wBAAwB;oBAC/B,KAAK,EAAE,aAAa;oBACpB,MAAM,EAAE;wBACN,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE;wBACnF,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;wBACtD,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;wBACtD,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;wBACxD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE;qBAC5C;oBACD,SAAS,EAAE,GAAG;iBACf;aACF;SACF,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,MAAM,EAAE;gBACN;oBACE,KAAK,EAAE,wBAAwB;oBAC/B,KAAK,EAAE,cAAc;oBACrB,MAAM,EAAE;wBACN,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE;wBACnF,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;wBACtD,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;wBACxD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE;qBAC5C;oBACD,SAAS,EAAE,GAAG;iBACf;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAjDD,wCAiDC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface DicoshotOptions {
|
|
2
|
+
webhookUrl: string;
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
notifyOnStartup?: boolean;
|
|
5
|
+
notifyOnShutdown?: boolean;
|
|
6
|
+
applicationName?: string;
|
|
7
|
+
username?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=dicoshot.options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.options.d.ts","sourceRoot":"","sources":["../../src/options/dicoshot.options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.options.js","sourceRoot":"","sources":["../../src/options/dicoshot.options.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dicoshot-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"axios": "^1.7.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"typescript": "^5.4.0",
|
|
14
|
+
"@types/node": "^20.0.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DicoshotOptions } from '../options/dicoshot.options';
|
|
3
|
+
import { DiscordMessage } from '../message/discord.message';
|
|
4
|
+
import { DicoshotClient } from './dicoshot.client';
|
|
5
|
+
|
|
6
|
+
export class DicoshotClientImpl implements DicoshotClient {
|
|
7
|
+
constructor(private readonly options: DicoshotOptions) {}
|
|
8
|
+
|
|
9
|
+
async send(message: DiscordMessage): Promise<void> {
|
|
10
|
+
await axios.post(this.options.webhookUrl, message, {
|
|
11
|
+
timeout: this.options.timeoutMs ?? 5000,
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { DicoshotOptions } from './options/dicoshot.options';
|
|
2
|
+
export type { DiscordField, DiscordEmbed, DiscordMessage } from './message/discord.message';
|
|
3
|
+
export { MessageFactory } from './message/message.factory';
|
|
4
|
+
export type { DicoshotClient } from './client/dicoshot.client';
|
|
5
|
+
export { DicoshotClientImpl } from './client/dicoshot.client.impl';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface DiscordField {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
inline?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface DiscordEmbed {
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
color?: number;
|
|
11
|
+
fields?: DiscordField[];
|
|
12
|
+
timestamp?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DiscordMessage {
|
|
16
|
+
username?: string;
|
|
17
|
+
embeds?: DiscordEmbed[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import { DicoshotOptions } from '../options/dicoshot.options';
|
|
3
|
+
import { DiscordMessage } from './discord.message';
|
|
4
|
+
|
|
5
|
+
const STARTUP_COLOR = 5763719;
|
|
6
|
+
const SHUTDOWN_COLOR = 15548997;
|
|
7
|
+
|
|
8
|
+
export class MessageFactory {
|
|
9
|
+
private readonly version: string;
|
|
10
|
+
private readonly env: string;
|
|
11
|
+
|
|
12
|
+
constructor(private readonly options: DicoshotOptions) {
|
|
13
|
+
this.version = process.env['npm_package_version'] ?? '0.0.0';
|
|
14
|
+
this.env = process.env['NODE_ENV'] ?? 'development';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
startup(): DiscordMessage {
|
|
18
|
+
const now = new Date().toISOString();
|
|
19
|
+
return {
|
|
20
|
+
username: this.options.username,
|
|
21
|
+
embeds: [
|
|
22
|
+
{
|
|
23
|
+
title: '🟢 Application Started',
|
|
24
|
+
color: STARTUP_COLOR,
|
|
25
|
+
fields: [
|
|
26
|
+
{ name: 'Service', value: this.options.applicationName ?? 'Unknown', inline: true },
|
|
27
|
+
{ name: 'Environment', value: this.env, inline: true },
|
|
28
|
+
{ name: 'Version', value: this.version, inline: true },
|
|
29
|
+
{ name: 'Hostname', value: os.hostname(), inline: true },
|
|
30
|
+
{ name: 'Time', value: now, inline: false },
|
|
31
|
+
],
|
|
32
|
+
timestamp: now,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
shutdown(): DiscordMessage {
|
|
39
|
+
const now = new Date().toISOString();
|
|
40
|
+
return {
|
|
41
|
+
username: this.options.username,
|
|
42
|
+
embeds: [
|
|
43
|
+
{
|
|
44
|
+
title: '🔴 Application Stopped',
|
|
45
|
+
color: SHUTDOWN_COLOR,
|
|
46
|
+
fields: [
|
|
47
|
+
{ name: 'Service', value: this.options.applicationName ?? 'Unknown', inline: true },
|
|
48
|
+
{ name: 'Environment', value: this.env, inline: true },
|
|
49
|
+
{ name: 'Hostname', value: os.hostname(), inline: true },
|
|
50
|
+
{ name: 'Time', value: now, inline: false },
|
|
51
|
+
],
|
|
52
|
+
timestamp: now,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"strict": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"outDir": "dist"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"],
|
|
14
|
+
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
|
|
15
|
+
}
|