dicoshot-core 0.1.0 → 0.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.
@@ -1,5 +1,6 @@
1
1
  import { DiscordMessage } from '../message/discord.message';
2
2
  export interface DicoshotClient {
3
3
  send(message: DiscordMessage): Promise<void>;
4
+ sendTo(url: string, message: DiscordMessage): Promise<void>;
4
5
  }
5
6
  //# sourceMappingURL=dicoshot.client.d.ts.map
@@ -1 +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"}
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;IAC7C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D"}
@@ -1,9 +1,14 @@
1
- import { DicoshotOptions } from '../options/dicoshot.options';
2
1
  import { DiscordMessage } from '../message/discord.message';
2
+ import { DicoshotOptions } from '../options/dicoshot.options';
3
3
  import { DicoshotClient } from './dicoshot.client';
4
4
  export declare class DicoshotClientImpl implements DicoshotClient {
5
5
  private readonly options;
6
6
  constructor(options: DicoshotOptions);
7
7
  send(message: DiscordMessage): Promise<void>;
8
+ sendTo(url: string, message: DiscordMessage): Promise<void>;
9
+ private resolveRetry;
10
+ private resolveRetryOptions;
11
+ private resolveDelay;
12
+ private delay;
8
13
  }
9
14
  //# sourceMappingURL=dicoshot.client.impl.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"dicoshot.client.impl.d.ts","sourceRoot":"","sources":["../../src/client/dicoshot.client.impl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAgB,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKnD,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;IAK5C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjE,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,KAAK;CAGd"}
@@ -5,15 +5,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DicoshotClientImpl = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const DEFAULT_RETRY_ATTEMPTS = 2;
9
+ const DEFAULT_RETRY_BACKOFF_MS = 500;
8
10
  class DicoshotClientImpl {
9
11
  constructor(options) {
10
12
  this.options = options;
11
13
  }
12
14
  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
- });
15
+ if (!this.options.webhookUrl)
16
+ return;
17
+ await this.sendTo(this.options.webhookUrl, message);
18
+ }
19
+ async sendTo(url, message) {
20
+ const { attempts, backoffMs } = this.resolveRetry();
21
+ for (let attempt = 0;; attempt++) {
22
+ try {
23
+ await axios_1.default.post(url, message, {
24
+ timeout: this.options.timeoutMs ?? 5000,
25
+ headers: { 'Content-Type': 'application/json' },
26
+ });
27
+ return;
28
+ }
29
+ catch (err) {
30
+ if (attempt >= attempts)
31
+ throw err;
32
+ await this.delay(this.resolveDelay(err, backoffMs, attempt));
33
+ }
34
+ }
35
+ }
36
+ resolveRetry() {
37
+ const retry = this.options.retry;
38
+ if (!retry)
39
+ return { attempts: 0, backoffMs: DEFAULT_RETRY_BACKOFF_MS };
40
+ if (retry === true) {
41
+ return { attempts: DEFAULT_RETRY_ATTEMPTS, backoffMs: DEFAULT_RETRY_BACKOFF_MS };
42
+ }
43
+ return this.resolveRetryOptions(retry);
44
+ }
45
+ resolveRetryOptions(retry) {
46
+ return {
47
+ attempts: retry.attempts ?? DEFAULT_RETRY_ATTEMPTS,
48
+ backoffMs: retry.backoffMs ?? DEFAULT_RETRY_BACKOFF_MS,
49
+ };
50
+ }
51
+ // Discord가 429와 함께 보내는 Retry-After를 우선 따르고, 없으면 지수 백오프를 사용한다
52
+ resolveDelay(err, backoffMs, attempt) {
53
+ if (axios_1.default.isAxiosError(err) && err.response?.status === 429) {
54
+ const retryAfter = err.response.headers['retry-after'];
55
+ if (retryAfter)
56
+ return Number(retryAfter) * 1000;
57
+ }
58
+ return backoffMs * 2 ** attempt;
59
+ }
60
+ delay(ms) {
61
+ return new Promise((resolve) => setTimeout(resolve, ms));
17
62
  }
18
63
  }
19
64
  exports.DicoshotClientImpl = DicoshotClientImpl;
@@ -1 +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"}
1
+ {"version":3,"file":"dicoshot.client.impl.js","sourceRoot":"","sources":["../../src/client/dicoshot.client.impl.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAM1B,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAa,kBAAkB;IAC7B,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEzD,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU;YAAE,OAAO;QACrC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,OAAuB;QAC/C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEpD,KAAK,IAAI,OA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AM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACvD,IAAI,UAAU;gBAAE,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACnD,CAAC;QACD,OAAO,SAAS,GAAG,CAAC,IAAI,OAAO,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AArDD,gDAqDC"}
@@ -0,0 +1,22 @@
1
+ export type Locale = 'en' | 'ko' | 'ja' | 'zh';
2
+ export interface DicoshotMessages {
3
+ startupTitle: string;
4
+ shutdownTitle: string;
5
+ slowResponseLabel: string;
6
+ field: {
7
+ service: string;
8
+ environment: string;
9
+ version: string;
10
+ hostname: string;
11
+ time: string;
12
+ status: string;
13
+ method: string;
14
+ path: string;
15
+ duration: string;
16
+ location: string;
17
+ stackTrace: string;
18
+ requestBody: string;
19
+ };
20
+ }
21
+ export declare function getMessages(locale: Locale | DicoshotMessages | undefined): DicoshotMessages;
22
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/i18n/messages.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAmFD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,GAAG,gBAAgB,CAG3F"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMessages = getMessages;
4
+ const MESSAGES = {
5
+ en: {
6
+ startupTitle: '🟢 Application Started',
7
+ shutdownTitle: '🔴 Application Stopped',
8
+ slowResponseLabel: 'Slow Response',
9
+ field: {
10
+ service: 'Service',
11
+ environment: 'Environment',
12
+ version: 'Version',
13
+ hostname: 'Hostname',
14
+ time: 'Time',
15
+ status: 'Status',
16
+ method: 'Method',
17
+ path: 'Path',
18
+ duration: 'Duration',
19
+ location: 'Location',
20
+ stackTrace: 'Stack Trace',
21
+ requestBody: 'Request Body',
22
+ },
23
+ },
24
+ ko: {
25
+ startupTitle: '🟢 애플리케이션 시작',
26
+ shutdownTitle: '🔴 애플리케이션 종료',
27
+ slowResponseLabel: '느린 응답',
28
+ field: {
29
+ service: '서비스',
30
+ environment: '환경',
31
+ version: '버전',
32
+ hostname: '호스트명',
33
+ time: '시간',
34
+ status: '상태',
35
+ method: '메서드',
36
+ path: '경로',
37
+ duration: '소요 시간',
38
+ location: '발생 위치',
39
+ stackTrace: '스택 트레이스',
40
+ requestBody: '요청 바디',
41
+ },
42
+ },
43
+ ja: {
44
+ startupTitle: '🟢 アプリケーション起動',
45
+ shutdownTitle: '🔴 アプリケーション停止',
46
+ slowResponseLabel: '遅延レスポンス',
47
+ field: {
48
+ service: 'サービス',
49
+ environment: '環境',
50
+ version: 'バージョン',
51
+ hostname: 'ホスト名',
52
+ time: '時刻',
53
+ status: 'ステータス',
54
+ method: 'メソッド',
55
+ path: 'パス',
56
+ duration: '処理時間',
57
+ location: '発生箇所',
58
+ stackTrace: 'スタックトレース',
59
+ requestBody: 'リクエストボディ',
60
+ },
61
+ },
62
+ zh: {
63
+ startupTitle: '🟢 应用已启动',
64
+ shutdownTitle: '🔴 应用已停止',
65
+ slowResponseLabel: '响应缓慢',
66
+ field: {
67
+ service: '服务',
68
+ environment: '环境',
69
+ version: '版本',
70
+ hostname: '主机名',
71
+ time: '时间',
72
+ status: '状态',
73
+ method: '方法',
74
+ path: '路径',
75
+ duration: '耗时',
76
+ location: '发生位置',
77
+ stackTrace: '堆栈信息',
78
+ requestBody: '请求体',
79
+ },
80
+ },
81
+ };
82
+ // 예외 클래스 이름(TypeError 등)처럼 런타임 값인 부분은 번역 대상이 아니므로 그대로 둔다.
83
+ // 내장 언어 외 다른 언어가 필요하면 DicoshotMessages 객체를 통째로 넘겨 직접 번역을 지정할 수 있다.
84
+ function getMessages(locale) {
85
+ if (locale && typeof locale === 'object')
86
+ return locale;
87
+ return MESSAGES[locale ?? 'en'];
88
+ }
89
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/i18n/messages.ts"],"names":[],"mappings":";;AAuGA,kCAGC;AApFD,MAAM,QAAQ,GAAqC;IACjD,EAAE,EAAE;QACF,YAAY,EAAE,wBAAwB;QACtC,aAAa,EAAE,wBAAwB;QACvC,iBAAiB,EAAE,eAAe;QAClC,KAAK,EAAE;YACL,OAAO,EAAE,SAAS;YAClB,WAAW,EAAE,aAAa;YAC1B,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,UAAU;YACpB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,UAAU;YACpB,UAAU,EAAE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,WAAW,EAAE,KAAK;SACnB;KACF;CACF,CAAC;AAEF,0DAA0D;AAC1D,mEAAmE;AACnE,SAAgB,WAAW,CAAC,MAA6C;IACvE,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IACxD,OAAO,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;AAClC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
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
1
  export type { DicoshotClient } from './client/dicoshot.client';
5
2
  export { DicoshotClientImpl } from './client/dicoshot.client.impl';
3
+ export type { DicoshotMessages, Locale } from './i18n/messages';
4
+ export { getMessages } from './i18n/messages';
5
+ export type { DiscordEmbed, DiscordField, DiscordMessage } from './message/discord.message';
6
+ export { MessageFactory } from './message/message.factory';
7
+ export type { DicoshotOptions, DicoshotWebhooks, FilterOptions, InterceptorOptions, RetryOptions, } from './options/dicoshot.options';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
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; } });
3
+ exports.MessageFactory = exports.getMessages = exports.DicoshotClientImpl = void 0;
6
4
  var dicoshot_client_impl_1 = require("./client/dicoshot.client.impl");
7
5
  Object.defineProperty(exports, "DicoshotClientImpl", { enumerable: true, get: function () { return dicoshot_client_impl_1.DicoshotClientImpl; } });
6
+ var messages_1 = require("./i18n/messages");
7
+ Object.defineProperty(exports, "getMessages", { enumerable: true, get: function () { return messages_1.getMessages; } });
8
+ var message_factory_1 = require("./message/message.factory");
9
+ Object.defineProperty(exports, "MessageFactory", { enumerable: true, get: function () { return message_factory_1.MessageFactory; } });
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,sEAAmE;AAA1D,0HAAA,kBAAkB,OAAA;AAE3B,4CAA8C;AAArC,uGAAA,WAAW,OAAA;AAEpB,6DAA2D;AAAlD,iHAAA,cAAc,OAAA"}
@@ -11,7 +11,6 @@ export interface DiscordEmbed {
11
11
  timestamp?: string;
12
12
  }
13
13
  export interface DiscordMessage {
14
- username?: string;
15
14
  embeds?: DiscordEmbed[];
16
15
  }
17
16
  //# sourceMappingURL=discord.message.d.ts.map
@@ -1 +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"}
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,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB"}
@@ -1 +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"}
1
+ {"version":3,"file":"message.factory.d.ts","sourceRoot":"","sources":["../../src/message/message.factory.ts"],"names":[],"mappings":"AAGA,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;IAyBzB,QAAQ,IAAI,cAAc;CAuB3B"}
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.MessageFactory = void 0;
37
37
  const os = __importStar(require("os"));
38
+ const messages_1 = require("../i18n/messages");
38
39
  const STARTUP_COLOR = 5763719;
39
40
  const SHUTDOWN_COLOR = 15548997;
40
41
  class MessageFactory {
@@ -45,18 +46,22 @@ class MessageFactory {
45
46
  }
46
47
  startup() {
47
48
  const now = new Date().toISOString();
49
+ const msg = (0, messages_1.getMessages)(this.options.locale);
48
50
  return {
49
- username: this.options.username,
50
51
  embeds: [
51
52
  {
52
- title: '🟢 Application Started',
53
+ title: msg.startupTitle,
53
54
  color: STARTUP_COLOR,
54
55
  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 },
56
+ {
57
+ name: msg.field.service,
58
+ value: this.options.applicationName ?? 'Unknown',
59
+ inline: true,
60
+ },
61
+ { name: msg.field.environment, value: this.env, inline: true },
62
+ { name: msg.field.version, value: this.version, inline: true },
63
+ { name: msg.field.hostname, value: os.hostname(), inline: true },
64
+ { name: msg.field.time, value: now, inline: false },
60
65
  ],
61
66
  timestamp: now,
62
67
  },
@@ -65,17 +70,21 @@ class MessageFactory {
65
70
  }
66
71
  shutdown() {
67
72
  const now = new Date().toISOString();
73
+ const msg = (0, messages_1.getMessages)(this.options.locale);
68
74
  return {
69
- username: this.options.username,
70
75
  embeds: [
71
76
  {
72
- title: '🔴 Application Stopped',
77
+ title: msg.shutdownTitle,
73
78
  color: SHUTDOWN_COLOR,
74
79
  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 },
80
+ {
81
+ name: msg.field.service,
82
+ value: this.options.applicationName ?? 'Unknown',
83
+ inline: true,
84
+ },
85
+ { name: msg.field.environment, value: this.env, inline: true },
86
+ { name: msg.field.hostname, value: os.hostname(), inline: true },
87
+ { name: msg.field.time, value: now, inline: false },
79
88
  ],
80
89
  timestamp: now,
81
90
  },
@@ -1 +1 @@
1
- {"version":3,"file":"message.factory.js","sourceRoot":"","sources":["../../src/message/message.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uC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AO,CAAC,eAAe,IAAI,SAAS;4BAChD,MAAM,EAAE,IAAI;yBACb;wBACD,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;wBAC9D,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;wBAChE,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE;qBACpD;oBACD,SAAS,EAAE,GAAG;iBACf;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAzDD,wCAyDC"}
@@ -1,10 +1,43 @@
1
+ import { DicoshotMessages, Locale } from '../i18n/messages';
2
+ export interface FilterOptions {
3
+ ignore?: number[];
4
+ environment?: string | string[];
5
+ mention?: string;
6
+ throttle?: number;
7
+ includeStack?: boolean;
8
+ includeRequest?: boolean;
9
+ minStatus?: number;
10
+ }
11
+ export interface InterceptorOptions {
12
+ slowThreshold?: number;
13
+ excludePaths?: string[];
14
+ onlyErrors?: boolean;
15
+ minStatus?: number;
16
+ }
17
+ export interface DicoshotWebhooks {
18
+ error?: string;
19
+ slow?: string;
20
+ }
21
+ export interface RetryOptions {
22
+ attempts?: number;
23
+ backoffMs?: number;
24
+ }
1
25
  export interface DicoshotOptions {
2
- webhookUrl: string;
26
+ webhookUrl?: string;
3
27
  enabled?: boolean;
4
28
  notifyOnStartup?: boolean;
5
29
  notifyOnShutdown?: boolean;
6
30
  applicationName?: string;
7
- username?: string;
31
+ /**
32
+ * Language for notification titles/field labels. Defaults to 'en'.
33
+ * Built-in: 'en' | 'ko' | 'ja' | 'zh'. For any other language, pass a
34
+ * full DicoshotMessages object with your own translations.
35
+ */
36
+ locale?: Locale | DicoshotMessages;
8
37
  timeoutMs?: number;
38
+ webhooks?: DicoshotWebhooks;
39
+ filter?: boolean | FilterOptions;
40
+ interceptor?: boolean | InterceptorOptions;
41
+ retry?: boolean | RetryOptions;
9
42
  }
10
43
  //# sourceMappingURL=dicoshot.options.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"dicoshot.options.d.ts","sourceRoot":"","sources":["../../src/options/dicoshot.options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;CAChC"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "dicoshot-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "scripts": {
@@ -1,15 +1,63 @@
1
1
  import axios from 'axios';
2
- import { DicoshotOptions } from '../options/dicoshot.options';
2
+
3
3
  import { DiscordMessage } from '../message/discord.message';
4
+ import { DicoshotOptions, RetryOptions } from '../options/dicoshot.options';
4
5
  import { DicoshotClient } from './dicoshot.client';
5
6
 
7
+ const DEFAULT_RETRY_ATTEMPTS = 2;
8
+ const DEFAULT_RETRY_BACKOFF_MS = 500;
9
+
6
10
  export class DicoshotClientImpl implements DicoshotClient {
7
11
  constructor(private readonly options: DicoshotOptions) {}
8
12
 
9
13
  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
+ if (!this.options.webhookUrl) return;
15
+ await this.sendTo(this.options.webhookUrl, message);
16
+ }
17
+
18
+ async sendTo(url: string, message: DiscordMessage): Promise<void> {
19
+ const { attempts, backoffMs } = this.resolveRetry();
20
+
21
+ for (let attempt = 0; ; attempt++) {
22
+ try {
23
+ await axios.post(url, message, {
24
+ timeout: this.options.timeoutMs ?? 5000,
25
+ headers: { 'Content-Type': 'application/json' },
26
+ });
27
+ return;
28
+ } catch (err) {
29
+ if (attempt >= attempts) throw err;
30
+ await this.delay(this.resolveDelay(err, backoffMs, attempt));
31
+ }
32
+ }
33
+ }
34
+
35
+ private resolveRetry(): { attempts: number; backoffMs: number } {
36
+ const retry = this.options.retry;
37
+ if (!retry) return { attempts: 0, backoffMs: DEFAULT_RETRY_BACKOFF_MS };
38
+ if (retry === true) {
39
+ return { attempts: DEFAULT_RETRY_ATTEMPTS, backoffMs: DEFAULT_RETRY_BACKOFF_MS };
40
+ }
41
+ return this.resolveRetryOptions(retry);
42
+ }
43
+
44
+ private resolveRetryOptions(retry: RetryOptions): { attempts: number; backoffMs: number } {
45
+ return {
46
+ attempts: retry.attempts ?? DEFAULT_RETRY_ATTEMPTS,
47
+ backoffMs: retry.backoffMs ?? DEFAULT_RETRY_BACKOFF_MS,
48
+ };
49
+ }
50
+
51
+ // Discord가 429와 함께 보내는 Retry-After를 우선 따르고, 없으면 지수 백오프를 사용한다
52
+ private resolveDelay(err: unknown, backoffMs: number, attempt: number): number {
53
+ if (axios.isAxiosError(err) && err.response?.status === 429) {
54
+ const retryAfter = err.response.headers['retry-after'];
55
+ if (retryAfter) return Number(retryAfter) * 1000;
56
+ }
57
+ return backoffMs * 2 ** attempt;
58
+ }
59
+
60
+ private delay(ms: number): Promise<void> {
61
+ return new Promise((resolve) => setTimeout(resolve, ms));
14
62
  }
15
63
  }
@@ -2,4 +2,5 @@ import { DiscordMessage } from '../message/discord.message';
2
2
 
3
3
  export interface DicoshotClient {
4
4
  send(message: DiscordMessage): Promise<void>;
5
+ sendTo(url: string, message: DiscordMessage): Promise<void>;
5
6
  }
@@ -0,0 +1,107 @@
1
+ export type Locale = 'en' | 'ko' | 'ja' | 'zh';
2
+
3
+ export interface DicoshotMessages {
4
+ startupTitle: string;
5
+ shutdownTitle: string;
6
+ slowResponseLabel: string;
7
+ field: {
8
+ service: string;
9
+ environment: string;
10
+ version: string;
11
+ hostname: string;
12
+ time: string;
13
+ status: string;
14
+ method: string;
15
+ path: string;
16
+ duration: string;
17
+ location: string;
18
+ stackTrace: string;
19
+ requestBody: string;
20
+ };
21
+ }
22
+
23
+ const MESSAGES: Record<Locale, DicoshotMessages> = {
24
+ en: {
25
+ startupTitle: '🟢 Application Started',
26
+ shutdownTitle: '🔴 Application Stopped',
27
+ slowResponseLabel: 'Slow Response',
28
+ field: {
29
+ service: 'Service',
30
+ environment: 'Environment',
31
+ version: 'Version',
32
+ hostname: 'Hostname',
33
+ time: 'Time',
34
+ status: 'Status',
35
+ method: 'Method',
36
+ path: 'Path',
37
+ duration: 'Duration',
38
+ location: 'Location',
39
+ stackTrace: 'Stack Trace',
40
+ requestBody: 'Request Body',
41
+ },
42
+ },
43
+ ko: {
44
+ startupTitle: '🟢 애플리케이션 시작',
45
+ shutdownTitle: '🔴 애플리케이션 종료',
46
+ slowResponseLabel: '느린 응답',
47
+ field: {
48
+ service: '서비스',
49
+ environment: '환경',
50
+ version: '버전',
51
+ hostname: '호스트명',
52
+ time: '시간',
53
+ status: '상태',
54
+ method: '메서드',
55
+ path: '경로',
56
+ duration: '소요 시간',
57
+ location: '발생 위치',
58
+ stackTrace: '스택 트레이스',
59
+ requestBody: '요청 바디',
60
+ },
61
+ },
62
+ ja: {
63
+ startupTitle: '🟢 アプリケーション起動',
64
+ shutdownTitle: '🔴 アプリケーション停止',
65
+ slowResponseLabel: '遅延レスポンス',
66
+ field: {
67
+ service: 'サービス',
68
+ environment: '環境',
69
+ version: 'バージョン',
70
+ hostname: 'ホスト名',
71
+ time: '時刻',
72
+ status: 'ステータス',
73
+ method: 'メソッド',
74
+ path: 'パス',
75
+ duration: '処理時間',
76
+ location: '発生箇所',
77
+ stackTrace: 'スタックトレース',
78
+ requestBody: 'リクエストボディ',
79
+ },
80
+ },
81
+ zh: {
82
+ startupTitle: '🟢 应用已启动',
83
+ shutdownTitle: '🔴 应用已停止',
84
+ slowResponseLabel: '响应缓慢',
85
+ field: {
86
+ service: '服务',
87
+ environment: '环境',
88
+ version: '版本',
89
+ hostname: '主机名',
90
+ time: '时间',
91
+ status: '状态',
92
+ method: '方法',
93
+ path: '路径',
94
+ duration: '耗时',
95
+ location: '发生位置',
96
+ stackTrace: '堆栈信息',
97
+ requestBody: '请求体',
98
+ },
99
+ },
100
+ };
101
+
102
+ // 예외 클래스 이름(TypeError 등)처럼 런타임 값인 부분은 번역 대상이 아니므로 그대로 둔다.
103
+ // 내장 언어 외 다른 언어가 필요하면 DicoshotMessages 객체를 통째로 넘겨 직접 번역을 지정할 수 있다.
104
+ export function getMessages(locale: Locale | DicoshotMessages | undefined): DicoshotMessages {
105
+ if (locale && typeof locale === 'object') return locale;
106
+ return MESSAGES[locale ?? 'en'];
107
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,13 @@
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
1
  export type { DicoshotClient } from './client/dicoshot.client';
5
2
  export { DicoshotClientImpl } from './client/dicoshot.client.impl';
3
+ export type { DicoshotMessages, Locale } from './i18n/messages';
4
+ export { getMessages } from './i18n/messages';
5
+ export type { DiscordEmbed, DiscordField, DiscordMessage } from './message/discord.message';
6
+ export { MessageFactory } from './message/message.factory';
7
+ export type {
8
+ DicoshotOptions,
9
+ DicoshotWebhooks,
10
+ FilterOptions,
11
+ InterceptorOptions,
12
+ RetryOptions,
13
+ } from './options/dicoshot.options';
@@ -13,6 +13,5 @@ export interface DiscordEmbed {
13
13
  }
14
14
 
15
15
  export interface DiscordMessage {
16
- username?: string;
17
16
  embeds?: DiscordEmbed[];
18
17
  }
@@ -1,4 +1,6 @@
1
1
  import * as os from 'os';
2
+
3
+ import { getMessages } from '../i18n/messages';
2
4
  import { DicoshotOptions } from '../options/dicoshot.options';
3
5
  import { DiscordMessage } from './discord.message';
4
6
 
@@ -16,18 +18,22 @@ export class MessageFactory {
16
18
 
17
19
  startup(): DiscordMessage {
18
20
  const now = new Date().toISOString();
21
+ const msg = getMessages(this.options.locale);
19
22
  return {
20
- username: this.options.username,
21
23
  embeds: [
22
24
  {
23
- title: '🟢 Application Started',
25
+ title: msg.startupTitle,
24
26
  color: STARTUP_COLOR,
25
27
  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 },
28
+ {
29
+ name: msg.field.service,
30
+ value: this.options.applicationName ?? 'Unknown',
31
+ inline: true,
32
+ },
33
+ { name: msg.field.environment, value: this.env, inline: true },
34
+ { name: msg.field.version, value: this.version, inline: true },
35
+ { name: msg.field.hostname, value: os.hostname(), inline: true },
36
+ { name: msg.field.time, value: now, inline: false },
31
37
  ],
32
38
  timestamp: now,
33
39
  },
@@ -37,17 +43,21 @@ export class MessageFactory {
37
43
 
38
44
  shutdown(): DiscordMessage {
39
45
  const now = new Date().toISOString();
46
+ const msg = getMessages(this.options.locale);
40
47
  return {
41
- username: this.options.username,
42
48
  embeds: [
43
49
  {
44
- title: '🔴 Application Stopped',
50
+ title: msg.shutdownTitle,
45
51
  color: SHUTDOWN_COLOR,
46
52
  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 },
53
+ {
54
+ name: msg.field.service,
55
+ value: this.options.applicationName ?? 'Unknown',
56
+ inline: true,
57
+ },
58
+ { name: msg.field.environment, value: this.env, inline: true },
59
+ { name: msg.field.hostname, value: os.hostname(), inline: true },
60
+ { name: msg.field.time, value: now, inline: false },
51
61
  ],
52
62
  timestamp: now,
53
63
  },
@@ -1,9 +1,47 @@
1
+ import { DicoshotMessages, Locale } from '../i18n/messages';
2
+
3
+ export interface FilterOptions {
4
+ ignore?: number[];
5
+ environment?: string | string[];
6
+ mention?: string;
7
+ throttle?: number;
8
+ includeStack?: boolean;
9
+ includeRequest?: boolean;
10
+ minStatus?: number;
11
+ }
12
+
13
+ export interface InterceptorOptions {
14
+ slowThreshold?: number;
15
+ excludePaths?: string[];
16
+ onlyErrors?: boolean;
17
+ minStatus?: number;
18
+ }
19
+
20
+ export interface DicoshotWebhooks {
21
+ error?: string;
22
+ slow?: string;
23
+ }
24
+
25
+ export interface RetryOptions {
26
+ attempts?: number;
27
+ backoffMs?: number;
28
+ }
29
+
1
30
  export interface DicoshotOptions {
2
- webhookUrl: string;
31
+ webhookUrl?: string;
3
32
  enabled?: boolean;
4
33
  notifyOnStartup?: boolean;
5
34
  notifyOnShutdown?: boolean;
6
35
  applicationName?: string;
7
- username?: string;
36
+ /**
37
+ * Language for notification titles/field labels. Defaults to 'en'.
38
+ * Built-in: 'en' | 'ko' | 'ja' | 'zh'. For any other language, pass a
39
+ * full DicoshotMessages object with your own translations.
40
+ */
41
+ locale?: Locale | DicoshotMessages;
8
42
  timeoutMs?: number;
43
+ webhooks?: DicoshotWebhooks;
44
+ filter?: boolean | FilterOptions;
45
+ interceptor?: boolean | InterceptorOptions;
46
+ retry?: boolean | RetryOptions;
9
47
  }