@book000/node-utils 1.24.123 → 1.24.125
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/package.json +3 -3
- package/dist/__tests__/configuration.test.d.ts +0 -2
- package/dist/__tests__/configuration.test.d.ts.map +0 -1
- package/dist/__tests__/configuration.test.js +0 -159
- package/dist/__tests__/configuration.test.js.map +0 -1
- package/dist/__tests__/discord.test.d.ts +0 -2
- package/dist/__tests__/discord.test.d.ts.map +0 -1
- package/dist/__tests__/discord.test.js +0 -362
- package/dist/__tests__/discord.test.js.map +0 -1
- package/dist/__tests__/logger.test.d.ts +0 -2
- package/dist/__tests__/logger.test.d.ts.map +0 -1
- package/dist/__tests__/logger.test.js +0 -268
- package/dist/__tests__/logger.test.js.map +0 -1
- package/dist/configuration.d.ts +0 -12
- package/dist/configuration.d.ts.map +0 -1
- package/dist/configuration.js +0 -54
- package/dist/configuration.js.map +0 -1
- package/dist/discord.d.ts +0 -125
- package/dist/discord.d.ts.map +0 -1
- package/dist/discord.js +0 -164
- package/dist/discord.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -20
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -11
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -160
- package/dist/logger.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,268 +0,0 @@
|
|
|
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
|
-
const logger_1 = require("../logger");
|
|
7
|
-
const winston_1 = __importDefault(require("winston"));
|
|
8
|
-
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
9
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
10
|
-
jest.mock('winston', () => {
|
|
11
|
-
const mockFormat = {
|
|
12
|
-
combine: jest.fn().mockReturnValue('combined-format'),
|
|
13
|
-
timestamp: jest.fn().mockReturnValue('timestamp-format'),
|
|
14
|
-
printf: jest.fn().mockReturnValue('printf-format'),
|
|
15
|
-
colorize: jest.fn().mockReturnValue('colorize-format'),
|
|
16
|
-
uncolorize: jest.fn().mockReturnValue('uncolorize-format'),
|
|
17
|
-
errors: jest.fn().mockReturnValue('errors-format'),
|
|
18
|
-
json: jest.fn().mockReturnValue('json-format'),
|
|
19
|
-
};
|
|
20
|
-
const formatFunc = jest.fn().mockReturnValue('format');
|
|
21
|
-
formatFunc.mockImplementation(() => jest.fn().mockReturnValue('custom-format'));
|
|
22
|
-
Object.assign(formatFunc, mockFormat);
|
|
23
|
-
const mockLogger = {
|
|
24
|
-
debug: jest.fn(),
|
|
25
|
-
info: jest.fn(),
|
|
26
|
-
warn: jest.fn(),
|
|
27
|
-
error: jest.fn(),
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
createLogger: jest.fn(() => mockLogger),
|
|
31
|
-
format: formatFunc,
|
|
32
|
-
transports: {
|
|
33
|
-
Console: jest.fn(),
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
jest.mock('winston-daily-rotate-file');
|
|
38
|
-
jest.mock('cycle', () => ({
|
|
39
|
-
decycle: jest.fn((obj) => obj),
|
|
40
|
-
}));
|
|
41
|
-
jest.mock('moment-timezone', () => {
|
|
42
|
-
const mockMomentObj = {
|
|
43
|
-
format: jest.fn(() => '2025-05-05 12:00:00.000'),
|
|
44
|
-
tz: jest.fn(function () {
|
|
45
|
-
return this;
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
const mockMomentFn = jest.fn(() => mockMomentObj);
|
|
49
|
-
mockMomentFn.tz = {
|
|
50
|
-
zone: jest.fn((timezone) => timezone === 'Invalid/Timezone' ? null : true),
|
|
51
|
-
};
|
|
52
|
-
return mockMomentFn;
|
|
53
|
-
});
|
|
54
|
-
const originalProcessOn = process.on;
|
|
55
|
-
describe('Logger', () => {
|
|
56
|
-
const originalEnv = process.env;
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
jest.clearAllMocks();
|
|
59
|
-
process.env = { ...originalEnv };
|
|
60
|
-
delete process.env.LOG_LEVEL;
|
|
61
|
-
delete process.env.LOG_FILE_LEVEL;
|
|
62
|
-
delete process.env.LOG_DIR;
|
|
63
|
-
delete process.env.VERCEL;
|
|
64
|
-
delete process.env.LOG_FILE_MAX_AGE;
|
|
65
|
-
delete process.env.LOG_FILE_FORMAT;
|
|
66
|
-
delete process.env.TZ;
|
|
67
|
-
});
|
|
68
|
-
afterEach(() => {
|
|
69
|
-
process.env = originalEnv;
|
|
70
|
-
});
|
|
71
|
-
describe('configure', () => {
|
|
72
|
-
it('should create a logger with default settings', () => {
|
|
73
|
-
const logger = logger_1.Logger.configure('test');
|
|
74
|
-
expect(winston_1.default.createLogger).toHaveBeenCalled();
|
|
75
|
-
expect(winston_1.default.transports.Console).toHaveBeenCalledWith(expect.objectContaining({
|
|
76
|
-
level: 'info',
|
|
77
|
-
}));
|
|
78
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
79
|
-
level: 'info',
|
|
80
|
-
dirname: 'logs',
|
|
81
|
-
maxFiles: '30d',
|
|
82
|
-
}));
|
|
83
|
-
expect(logger).toBeInstanceOf(logger_1.Logger);
|
|
84
|
-
});
|
|
85
|
-
it('should use LOG_LEVEL environment variable when provided', () => {
|
|
86
|
-
process.env.LOG_LEVEL = 'debug';
|
|
87
|
-
logger_1.Logger.configure('test');
|
|
88
|
-
expect(winston_1.default.transports.Console).toHaveBeenCalledWith(expect.objectContaining({
|
|
89
|
-
level: 'debug',
|
|
90
|
-
}));
|
|
91
|
-
});
|
|
92
|
-
it('should use LOG_FILE_LEVEL environment variable when provided', () => {
|
|
93
|
-
process.env.LOG_FILE_LEVEL = 'warn';
|
|
94
|
-
logger_1.Logger.configure('test');
|
|
95
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
96
|
-
level: 'warn',
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
99
|
-
it('should use VERCEL environment variable for log directory when provided', () => {
|
|
100
|
-
process.env.VERCEL = 'true';
|
|
101
|
-
logger_1.Logger.configure('test');
|
|
102
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
103
|
-
dirname: '/tmp/logs',
|
|
104
|
-
}));
|
|
105
|
-
});
|
|
106
|
-
it('should use LOG_DIR environment variable when provided', () => {
|
|
107
|
-
process.env.LOG_DIR = 'custom-logs';
|
|
108
|
-
logger_1.Logger.configure('test');
|
|
109
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
110
|
-
dirname: 'custom-logs',
|
|
111
|
-
}));
|
|
112
|
-
});
|
|
113
|
-
it('should use LOG_FILE_MAX_AGE environment variable when provided', () => {
|
|
114
|
-
process.env.LOG_FILE_MAX_AGE = '7d';
|
|
115
|
-
logger_1.Logger.configure('test');
|
|
116
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
117
|
-
maxFiles: '7d',
|
|
118
|
-
}));
|
|
119
|
-
});
|
|
120
|
-
it('should use ndjson format when LOG_FILE_FORMAT is set to ndjson', () => {
|
|
121
|
-
process.env.LOG_FILE_FORMAT = 'ndjson';
|
|
122
|
-
logger_1.Logger.configure('test');
|
|
123
|
-
expect(winston_1.default.format.json).toHaveBeenCalled();
|
|
124
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
125
|
-
filename: '%DATE%.ndjson',
|
|
126
|
-
}));
|
|
127
|
-
});
|
|
128
|
-
it('should use text format when LOG_FILE_FORMAT is not set to ndjson', () => {
|
|
129
|
-
logger_1.Logger.configure('test');
|
|
130
|
-
expect(winston_1.default.format.json).not.toHaveBeenCalled();
|
|
131
|
-
expect(winston_daily_rotate_file_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
132
|
-
filename: '%DATE%.log',
|
|
133
|
-
}));
|
|
134
|
-
});
|
|
135
|
-
it('should create text format correctly', () => {
|
|
136
|
-
const formatPrintf = require('winston').format.printf;
|
|
137
|
-
logger_1.Logger.configure('test');
|
|
138
|
-
expect(formatPrintf).toHaveBeenCalled();
|
|
139
|
-
const printfCallback = formatPrintf.mock.calls[0][0];
|
|
140
|
-
const simpleInfo = {
|
|
141
|
-
timestamp: '2025-05-05 12:00:00',
|
|
142
|
-
level: 'info',
|
|
143
|
-
message: 'Test message',
|
|
144
|
-
};
|
|
145
|
-
const simpleResult = printfCallback(simpleInfo);
|
|
146
|
-
expect(simpleResult).toContain('[2025-05-05 12:00:00]');
|
|
147
|
-
expect(simpleResult).toContain('[test/INFO]');
|
|
148
|
-
expect(simpleResult).toContain('Test message');
|
|
149
|
-
const metadataInfo = {
|
|
150
|
-
timestamp: '2025-05-05 12:00:00',
|
|
151
|
-
level: 'info',
|
|
152
|
-
message: 'Test message',
|
|
153
|
-
extra: 'data',
|
|
154
|
-
};
|
|
155
|
-
const metadataResult = printfCallback(metadataInfo);
|
|
156
|
-
expect(metadataResult).toContain('"extra":"data"');
|
|
157
|
-
const stackInfo = {
|
|
158
|
-
timestamp: '2025-05-05 12:00:00',
|
|
159
|
-
level: 'error',
|
|
160
|
-
message: 'Error message',
|
|
161
|
-
stack: 'Error\n at line1\n at line2',
|
|
162
|
-
};
|
|
163
|
-
const stackResult = printfCallback(stackInfo);
|
|
164
|
-
expect(stackResult).toContain(' at line1');
|
|
165
|
-
const objectStackInfo = {
|
|
166
|
-
timestamp: '2025-05-05 12:00:00',
|
|
167
|
-
level: 'error',
|
|
168
|
-
message: 'Error message',
|
|
169
|
-
stack: { trace: 'stack trace' },
|
|
170
|
-
};
|
|
171
|
-
const objectStackResult = printfCallback(objectStackInfo);
|
|
172
|
-
expect(objectStackResult).toContain('{"trace":"stack trace"}');
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe('getTimestamp', () => {
|
|
176
|
-
it('should use TZ environment variable when provided and valid', () => {
|
|
177
|
-
process.env.TZ = 'America/New_York';
|
|
178
|
-
const timestampFn = logger_1.Logger.getTimestamp();
|
|
179
|
-
timestampFn();
|
|
180
|
-
expect(moment_timezone_1.default.tz.zone).toHaveBeenCalledWith('America/New_York');
|
|
181
|
-
});
|
|
182
|
-
it('should use default timezone (Asia/Tokyo) when TZ is not provided', () => {
|
|
183
|
-
delete process.env.TZ;
|
|
184
|
-
const timestampFn = logger_1.Logger.getTimestamp();
|
|
185
|
-
const result = timestampFn();
|
|
186
|
-
expect(result).toBe('2025-05-05 12:00:00.000');
|
|
187
|
-
});
|
|
188
|
-
it('should use default timezone (Asia/Tokyo) when TZ is invalid', () => {
|
|
189
|
-
process.env.TZ = 'Invalid/Timezone';
|
|
190
|
-
const timestampFn = logger_1.Logger.getTimestamp();
|
|
191
|
-
const result = timestampFn();
|
|
192
|
-
expect(result).toBe('2025-05-05 12:00:00.000');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe('logging methods', () => {
|
|
196
|
-
let loggerInstance;
|
|
197
|
-
let mockWinstonLogger;
|
|
198
|
-
beforeEach(() => {
|
|
199
|
-
mockWinstonLogger = winston_1.default.createLogger();
|
|
200
|
-
loggerInstance = logger_1.Logger.configure('test');
|
|
201
|
-
});
|
|
202
|
-
it('should call debug method with message', () => {
|
|
203
|
-
loggerInstance.debug('Debug message');
|
|
204
|
-
expect(mockWinstonLogger.debug).toHaveBeenCalledWith('Debug message', {});
|
|
205
|
-
});
|
|
206
|
-
it('should call debug method with message and metadata', () => {
|
|
207
|
-
const metadata = { key: 'value' };
|
|
208
|
-
loggerInstance.debug('Debug message', metadata);
|
|
209
|
-
expect(mockWinstonLogger.debug).toHaveBeenCalledWith('Debug message', metadata);
|
|
210
|
-
});
|
|
211
|
-
it('should call info method with message', () => {
|
|
212
|
-
loggerInstance.info('Info message');
|
|
213
|
-
expect(mockWinstonLogger.info).toHaveBeenCalledWith('Info message', {});
|
|
214
|
-
});
|
|
215
|
-
it('should call info method with message and metadata', () => {
|
|
216
|
-
const metadata = { key: 'value' };
|
|
217
|
-
loggerInstance.info('Info message', metadata);
|
|
218
|
-
expect(mockWinstonLogger.info).toHaveBeenCalledWith('Info message', metadata);
|
|
219
|
-
});
|
|
220
|
-
it('should call warn method with message', () => {
|
|
221
|
-
loggerInstance.warn('Warning message');
|
|
222
|
-
expect(mockWinstonLogger.warn).toHaveBeenCalledWith('Warning message', undefined);
|
|
223
|
-
});
|
|
224
|
-
it('should call warn method with message and error', () => {
|
|
225
|
-
const error = new Error('Test error');
|
|
226
|
-
loggerInstance.warn('Warning message', error);
|
|
227
|
-
expect(mockWinstonLogger.warn).toHaveBeenCalledWith('Warning message', error);
|
|
228
|
-
});
|
|
229
|
-
it('should call error method with message', () => {
|
|
230
|
-
loggerInstance.error('Error message');
|
|
231
|
-
expect(mockWinstonLogger.error).toHaveBeenCalledWith('Error message', undefined);
|
|
232
|
-
});
|
|
233
|
-
it('should call error method with message and error', () => {
|
|
234
|
-
const error = new Error('Test error');
|
|
235
|
-
loggerInstance.error('Error message', error);
|
|
236
|
-
expect(mockWinstonLogger.error).toHaveBeenCalledWith('Error message', error);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
describe('process event handlers', () => {
|
|
240
|
-
it('should register events for unhandledRejection and uncaughtException', () => {
|
|
241
|
-
try {
|
|
242
|
-
const eventHandlers = {};
|
|
243
|
-
process.on = jest
|
|
244
|
-
.fn()
|
|
245
|
-
.mockImplementation((event, handler) => {
|
|
246
|
-
eventHandlers[event] = handler;
|
|
247
|
-
return process;
|
|
248
|
-
});
|
|
249
|
-
jest.isolateModules(() => {
|
|
250
|
-
require('../logger');
|
|
251
|
-
});
|
|
252
|
-
expect(process.on).toHaveBeenCalledWith('unhandledRejection', expect.any(Function));
|
|
253
|
-
expect(process.on).toHaveBeenCalledWith('uncaughtException', expect.any(Function));
|
|
254
|
-
expect(eventHandlers).toHaveProperty('unhandledRejection');
|
|
255
|
-
expect(eventHandlers).toHaveProperty('uncaughtException');
|
|
256
|
-
const mockError = new Error('Test error');
|
|
257
|
-
eventHandlers.unhandledRejection(mockError);
|
|
258
|
-
expect(winston_1.default.createLogger().error).toHaveBeenCalledWith('unhandledRejection', mockError);
|
|
259
|
-
eventHandlers.uncaughtException(mockError);
|
|
260
|
-
expect(winston_1.default.createLogger().error).toHaveBeenCalledWith('uncaughtException', mockError);
|
|
261
|
-
}
|
|
262
|
-
finally {
|
|
263
|
-
process.on = originalProcessOn;
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
//# sourceMappingURL=logger.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.test.js","sourceRoot":"","sources":["../../src/__tests__/logger.test.ts"],"names":[],"mappings":";;;;;AAOA,sCAAkC;AAIlC,sDAA6B;AAC7B,0FAA8D;AAC9D,sEAAoC;AAGpC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;IACxB,MAAM,UAAU,GAAG;QACjB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC;QACrD,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,kBAAkB,CAAC;QACxD,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,eAAe,CAAC;QAClD,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC;QACtD,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,mBAAmB,CAAC;QAC1D,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,eAAe,CA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B,CAAC,SAAS,CAAC,CAAA;gBAC1C,MAAM,CAAC,iBAAO,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,oBAAoB,CACvD,mBAAmB,EACnB,SAAS,CACV,CAAA;YACH,CAAC;oBAAS,CAAC;gBAET,OAAO,CAAC,EAAE,GAAG,iBAAiB,CAAA;YAChC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/configuration.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare abstract class ConfigFramework<IConfig> {
|
|
2
|
-
private path;
|
|
3
|
-
private config;
|
|
4
|
-
private validateFailures;
|
|
5
|
-
constructor(path?: string);
|
|
6
|
-
protected abstract validates(): Record<string, (config: IConfig) => boolean>;
|
|
7
|
-
load(): void;
|
|
8
|
-
validate(): boolean;
|
|
9
|
-
getValidateFailures(): string[];
|
|
10
|
-
get<T extends keyof IConfig>(key: T): IConfig[T];
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAUA,8BAAsB,eAAe,CAAC,OAAO;IAE3C,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,gBAAgB,CAAe;gBAgB3B,IAAI,CAAC,EAAE,MAAM;IAoBzB,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IAQrE,IAAI,IAAI,IAAI;IAcZ,QAAQ,IAAI,OAAO;IAsBnB,mBAAmB,IAAI,MAAM,EAAE;IAU/B,GAAG,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAIxD"}
|
package/dist/configuration.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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.ConfigFramework = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const jsonc_parser_1 = require("jsonc-parser");
|
|
9
|
-
class ConfigFramework {
|
|
10
|
-
constructor(path) {
|
|
11
|
-
this.validateFailures = [];
|
|
12
|
-
const paths = [
|
|
13
|
-
process.env.CONFIG_PATH,
|
|
14
|
-
process.env.CONFIG_FILE,
|
|
15
|
-
path,
|
|
16
|
-
].filter((p) => p !== undefined && node_fs_1.default.existsSync(p));
|
|
17
|
-
if (paths.length === 0) {
|
|
18
|
-
throw new Error('Config path not found');
|
|
19
|
-
}
|
|
20
|
-
this.path = paths[0];
|
|
21
|
-
}
|
|
22
|
-
load() {
|
|
23
|
-
const data = node_fs_1.default.readFileSync(this.path, 'utf8');
|
|
24
|
-
const json = (0, jsonc_parser_1.parse)(data);
|
|
25
|
-
this.config = json;
|
|
26
|
-
}
|
|
27
|
-
validate() {
|
|
28
|
-
if (!this.config)
|
|
29
|
-
throw new Error('Config not loaded');
|
|
30
|
-
this.validateFailures = [];
|
|
31
|
-
const validates = this.validates();
|
|
32
|
-
for (const key in validates) {
|
|
33
|
-
try {
|
|
34
|
-
if (!validates[key](this.config)) {
|
|
35
|
-
this.validateFailures.push(key);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
this.validateFailures.push(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return this.validateFailures.length === 0;
|
|
43
|
-
}
|
|
44
|
-
getValidateFailures() {
|
|
45
|
-
return this.validateFailures;
|
|
46
|
-
}
|
|
47
|
-
get(key) {
|
|
48
|
-
if (!this.config)
|
|
49
|
-
throw new Error('Config not loaded');
|
|
50
|
-
return this.config[key];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.ConfigFramework = ConfigFramework;
|
|
54
|
-
//# sourceMappingURL=configuration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,+CAAoC;AASpC,MAAsB,eAAe;IAoBnC,YAAY,IAAa;QAhBjB,qBAAgB,GAAa,EAAE,CAAA;QAiBrC,MAAM,KAAK,GAAG;YACZ,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,IAAI;SACL,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,iBAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAa,CAAA;QAChE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IACtB,CAAC;IAkBM,IAAI;QACT,MAAM,IAAI,GAAG,iBAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC/C,MAAM,IAAI,GAAG,IAAA,oBAAK,EAAC,IAAI,CAAY,CAAA;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACpB,CAAC;IAUM,QAAQ;QACb,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAEtD,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAA;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAClC,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACjC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACjC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAA;IAC3C,CAAC;IAOM,mBAAmB;QACxB,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAC9B,CAAC;IAQM,GAAG,CAA0B,GAAM;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;CACF;AAlGD,0CAkGC"}
|
package/dist/discord.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
interface DiscordBotOptions {
|
|
2
|
-
token: string;
|
|
3
|
-
channelId: string;
|
|
4
|
-
}
|
|
5
|
-
interface DiscordWebhookOptions {
|
|
6
|
-
webhookUrl: string;
|
|
7
|
-
}
|
|
8
|
-
export type DiscordOptions = DiscordBotOptions | DiscordWebhookOptions;
|
|
9
|
-
export interface DiscordEmbedFooter {
|
|
10
|
-
text: string;
|
|
11
|
-
icon_url?: string;
|
|
12
|
-
proxy_icon_url?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface DiscordEmbedImage {
|
|
15
|
-
url?: string;
|
|
16
|
-
proxy_url?: string;
|
|
17
|
-
height?: number;
|
|
18
|
-
width?: number;
|
|
19
|
-
}
|
|
20
|
-
export interface DiscordEmbedThumbnail {
|
|
21
|
-
url?: string;
|
|
22
|
-
proxy_url?: string;
|
|
23
|
-
height?: number;
|
|
24
|
-
width?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface DiscordEmbedVideo {
|
|
27
|
-
url?: string;
|
|
28
|
-
proxy_url?: string;
|
|
29
|
-
height?: number;
|
|
30
|
-
width?: number;
|
|
31
|
-
}
|
|
32
|
-
export interface DiscordEmbedProvider {
|
|
33
|
-
name?: string;
|
|
34
|
-
url?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface DiscordEmbedAuthor {
|
|
37
|
-
name?: string;
|
|
38
|
-
url?: string;
|
|
39
|
-
icon_url?: string;
|
|
40
|
-
proxy_icon_url?: string;
|
|
41
|
-
}
|
|
42
|
-
export interface DiscordEmbedField {
|
|
43
|
-
name: string;
|
|
44
|
-
value: string;
|
|
45
|
-
inline?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export interface DiscordEmbed {
|
|
48
|
-
title?: string;
|
|
49
|
-
type?: 'rich' | 'image' | 'video' | 'gifv' | 'article' | 'link';
|
|
50
|
-
description?: string;
|
|
51
|
-
url?: string;
|
|
52
|
-
timestamp?: string;
|
|
53
|
-
color?: number;
|
|
54
|
-
footer?: DiscordEmbedFooter;
|
|
55
|
-
image?: DiscordEmbedImage;
|
|
56
|
-
thumbnail?: DiscordEmbedThumbnail;
|
|
57
|
-
video?: DiscordEmbedVideo;
|
|
58
|
-
provider?: DiscordEmbedProvider;
|
|
59
|
-
author?: DiscordEmbedAuthor;
|
|
60
|
-
fields?: DiscordEmbedField[];
|
|
61
|
-
}
|
|
62
|
-
interface DiscordNormalMessage {
|
|
63
|
-
content: string;
|
|
64
|
-
}
|
|
65
|
-
interface DiscordEmbedMessage {
|
|
66
|
-
embeds: DiscordEmbed[];
|
|
67
|
-
}
|
|
68
|
-
interface DiscordFile {
|
|
69
|
-
name: string;
|
|
70
|
-
file: ArrayBuffer;
|
|
71
|
-
contentType?: string;
|
|
72
|
-
isSpoiler?: boolean;
|
|
73
|
-
}
|
|
74
|
-
interface DiscordFileMessage {
|
|
75
|
-
file: DiscordFile;
|
|
76
|
-
}
|
|
77
|
-
declare const DiscordButtonStyles: {
|
|
78
|
-
readonly Primary: 1;
|
|
79
|
-
readonly Secondary: 2;
|
|
80
|
-
readonly Success: 3;
|
|
81
|
-
readonly Danger: 4;
|
|
82
|
-
readonly Link: 5;
|
|
83
|
-
};
|
|
84
|
-
interface DiscordButton {
|
|
85
|
-
type: 2;
|
|
86
|
-
style: typeof DiscordButtonStyles.Link;
|
|
87
|
-
label?: string;
|
|
88
|
-
emoji?: {
|
|
89
|
-
id?: string;
|
|
90
|
-
name?: string;
|
|
91
|
-
animated?: boolean;
|
|
92
|
-
};
|
|
93
|
-
url: string;
|
|
94
|
-
disabled?: boolean;
|
|
95
|
-
}
|
|
96
|
-
interface DiscordComponent {
|
|
97
|
-
type: 1;
|
|
98
|
-
components: DiscordButton[];
|
|
99
|
-
}
|
|
100
|
-
interface DiscordComponentMessage {
|
|
101
|
-
components: DiscordComponent[];
|
|
102
|
-
}
|
|
103
|
-
export declare const DiscordMessageFlag: {
|
|
104
|
-
readonly SuppressEmbeds: number;
|
|
105
|
-
readonly SuppressNotifications: number;
|
|
106
|
-
};
|
|
107
|
-
interface DiscordMessageFlags {
|
|
108
|
-
flags: number;
|
|
109
|
-
}
|
|
110
|
-
export type DiscordMessage = DiscordNormalMessage | DiscordEmbedMessage | DiscordFileMessage | DiscordComponentMessage | DiscordMessageFlags;
|
|
111
|
-
export declare class Discord {
|
|
112
|
-
private options;
|
|
113
|
-
constructor(options: DiscordOptions);
|
|
114
|
-
static get validations(): Record<string, (options: any) => boolean>;
|
|
115
|
-
sendMessage(message: string | DiscordMessage): Promise<string>;
|
|
116
|
-
private sendBot;
|
|
117
|
-
private sendWebhook;
|
|
118
|
-
editMessage(messageId: string, message: string | DiscordMessage): Promise<void>;
|
|
119
|
-
private editBot;
|
|
120
|
-
private editWebhook;
|
|
121
|
-
private isDiscordBotOptions;
|
|
122
|
-
private isDiscordWebhookOptions;
|
|
123
|
-
}
|
|
124
|
-
export {};
|
|
125
|
-
//# sourceMappingURL=discord.d.ts.map
|
package/dist/discord.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discord.d.ts","sourceRoot":"","sources":["../src/discord.ts"],"names":[],"mappings":"AAGA,UAAU,iBAAiB;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,qBAAqB;IAC7B,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,qBAAqB,CAAA;AACtE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,M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) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Discord = exports.DiscordMessageFlag = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
9
|
-
const DiscordButtonStyles = {
|
|
10
|
-
Primary: 1,
|
|
11
|
-
Secondary: 2,
|
|
12
|
-
Success: 3,
|
|
13
|
-
Danger: 4,
|
|
14
|
-
Link: 5,
|
|
15
|
-
};
|
|
16
|
-
exports.DiscordMessageFlag = {
|
|
17
|
-
SuppressEmbeds: 1 << 2,
|
|
18
|
-
SuppressNotifications: 1 << 12,
|
|
19
|
-
};
|
|
20
|
-
class Discord {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
if (this.isDiscordBotOptions(options)) {
|
|
23
|
-
this.options = options;
|
|
24
|
-
}
|
|
25
|
-
else if (this.isDiscordWebhookOptions(options)) {
|
|
26
|
-
this.options = options;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw new Error('Invalid options');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
static get validations() {
|
|
33
|
-
return {
|
|
34
|
-
'token or webhookUrl and channelId': (options) => 'token' in options ||
|
|
35
|
-
('webhookUrl' in options && 'channelId' in options),
|
|
36
|
-
'token is valid': (options) => 'token' in options && typeof options.token === 'string',
|
|
37
|
-
'webhookUrl is valid': (options) => 'webhookUrl' in options && typeof options.webhookUrl === 'string',
|
|
38
|
-
'channelId is valid': (options) => 'channelId' in options && typeof options.channelId === 'string',
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
async sendMessage(message) {
|
|
42
|
-
const formData = new form_data_1.default();
|
|
43
|
-
if (typeof message === 'string') {
|
|
44
|
-
formData.append('payload_json', JSON.stringify({ content: message }));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
formData.append('payload_json', JSON.stringify({
|
|
48
|
-
content: 'content' in message ? message.content : undefined,
|
|
49
|
-
embeds: 'embeds' in message ? message.embeds : undefined,
|
|
50
|
-
components: 'components' in message ? message.components : undefined,
|
|
51
|
-
}));
|
|
52
|
-
if ('file' in message) {
|
|
53
|
-
formData.append('file', message.file.file, {
|
|
54
|
-
filename: `${message.file.isSpoiler === true ? 'SPOILER_' : ''}${message.file.name}`,
|
|
55
|
-
contentType: message.file.contentType,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return await (this.isDiscordBotOptions(this.options)
|
|
60
|
-
? this.sendBot(formData)
|
|
61
|
-
: this.sendWebhook(formData));
|
|
62
|
-
}
|
|
63
|
-
async sendBot(formData) {
|
|
64
|
-
if (!this.isDiscordBotOptions(this.options)) {
|
|
65
|
-
throw new Error('Invalid bot options');
|
|
66
|
-
}
|
|
67
|
-
const response = await axios_1.default.post(`https://discord.com/api/channels/${this.options.channelId}/messages`, formData, {
|
|
68
|
-
headers: {
|
|
69
|
-
...formData.getHeaders(),
|
|
70
|
-
Authorization: `Bot ${this.options.token}`,
|
|
71
|
-
},
|
|
72
|
-
validateStatus: () => true,
|
|
73
|
-
});
|
|
74
|
-
if (response.status !== 200) {
|
|
75
|
-
throw new Error(`Discord API returned ${response.status}: ${JSON.stringify(response.data)}`);
|
|
76
|
-
}
|
|
77
|
-
return response.data.id;
|
|
78
|
-
}
|
|
79
|
-
async sendWebhook(formData) {
|
|
80
|
-
if (!this.isDiscordWebhookOptions(this.options)) {
|
|
81
|
-
throw new Error('Invalid webhook options');
|
|
82
|
-
}
|
|
83
|
-
const urlObject = new URL(this.options.webhookUrl);
|
|
84
|
-
urlObject.searchParams.append('wait', 'true');
|
|
85
|
-
const response = await axios_1.default.post(urlObject.toString(), formData, {
|
|
86
|
-
headers: {
|
|
87
|
-
...formData.getHeaders(),
|
|
88
|
-
},
|
|
89
|
-
validateStatus: () => true,
|
|
90
|
-
});
|
|
91
|
-
if (response.status !== 200 && response.status !== 204) {
|
|
92
|
-
throw new Error(`Discord API returned ${response.status}: ${JSON.stringify(response.data)}`);
|
|
93
|
-
}
|
|
94
|
-
return response.data.id;
|
|
95
|
-
}
|
|
96
|
-
async editMessage(messageId, message) {
|
|
97
|
-
const formData = new form_data_1.default();
|
|
98
|
-
if (typeof message === 'string') {
|
|
99
|
-
formData.append('payload_json', JSON.stringify({ content: message }));
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
formData.append('payload_json', JSON.stringify({
|
|
103
|
-
content: 'content' in message ? message.content : undefined,
|
|
104
|
-
embeds: 'embeds' in message ? message.embeds : undefined,
|
|
105
|
-
components: 'components' in message ? message.components : undefined,
|
|
106
|
-
}));
|
|
107
|
-
if ('file' in message) {
|
|
108
|
-
formData.append('file', message.file.file, {
|
|
109
|
-
filename: `${message.file.isSpoiler === true ? 'SPOILER_' : ''}${message.file.name}`,
|
|
110
|
-
contentType: message.file.contentType,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
await (this.isDiscordBotOptions(this.options)
|
|
115
|
-
? this.editBot(messageId, formData)
|
|
116
|
-
: this.editWebhook(messageId, formData));
|
|
117
|
-
}
|
|
118
|
-
async editBot(messageId, formData) {
|
|
119
|
-
if (!this.isDiscordBotOptions(this.options)) {
|
|
120
|
-
throw new Error('Invalid bot options');
|
|
121
|
-
}
|
|
122
|
-
const response = await axios_1.default.patch(`https://discord.com/api/channels/${this.options.channelId}/messages/${messageId}`, formData, {
|
|
123
|
-
headers: {
|
|
124
|
-
...formData.getHeaders(),
|
|
125
|
-
Authorization: `Bot ${this.options.token}`,
|
|
126
|
-
},
|
|
127
|
-
validateStatus: () => true,
|
|
128
|
-
});
|
|
129
|
-
if (response.status !== 200) {
|
|
130
|
-
throw new Error(`Discord API returned ${response.status}: ${JSON.stringify(response.data)}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async editWebhook(messageId, formData) {
|
|
134
|
-
if (!this.isDiscordWebhookOptions(this.options)) {
|
|
135
|
-
throw new Error('Invalid webhook options');
|
|
136
|
-
}
|
|
137
|
-
const urlObject = new URL(this.options.webhookUrl);
|
|
138
|
-
urlObject.searchParams.append('wait', 'true');
|
|
139
|
-
const response = await axios_1.default.patch(`${urlObject.toString()}/messages/${messageId}`, formData, {
|
|
140
|
-
headers: {
|
|
141
|
-
...formData.getHeaders(),
|
|
142
|
-
},
|
|
143
|
-
validateStatus: () => true,
|
|
144
|
-
});
|
|
145
|
-
if (response.status !== 200 && response.status !== 204) {
|
|
146
|
-
throw new Error(`Discord API returned ${response.status}: ${response.data}`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
isDiscordBotOptions(options) {
|
|
150
|
-
return ('token' in options &&
|
|
151
|
-
typeof options.token === 'string' &&
|
|
152
|
-
options.token.length > 0 &&
|
|
153
|
-
'channelId' in options &&
|
|
154
|
-
typeof options.channelId === 'string' &&
|
|
155
|
-
options.channelId.length > 0);
|
|
156
|
-
}
|
|
157
|
-
isDiscordWebhookOptions(options) {
|
|
158
|
-
return ('webhookUrl' in options &&
|
|
159
|
-
typeof options.webhookUrl === 'string' &&
|
|
160
|
-
options.webhookUrl.length > 0);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.Discord = Discord;
|
|
164
|
-
//# sourceMappingURL=discord.js.map
|