@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9

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.
Files changed (54) hide show
  1. package/dist/Application-DtWDHXr1.d.ts +2110 -0
  2. package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
  3. package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
  4. package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
  5. package/dist/EventManager-CmIoLt7r.d.ts +207 -0
  6. package/dist/Gate-CNkBYf8m.d.ts +268 -0
  7. package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
  8. package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
  9. package/dist/LogManager-7mxnkaPM.d.ts +256 -0
  10. package/dist/MailManager-DpMvYiP9.d.ts +292 -0
  11. package/dist/Scheduler-BstvSca7.d.ts +469 -0
  12. package/dist/StorageManager-oZTHqaza.d.ts +337 -0
  13. package/dist/api-token-JOif2CtG.d.ts +1792 -0
  14. package/dist/app-key-CsBfRC_Q.d.ts +214 -0
  15. package/dist/auth/index.d.ts +418 -0
  16. package/dist/auth/index.js +6742 -0
  17. package/dist/authorization/index.d.ts +129 -0
  18. package/dist/authorization/index.js +621 -0
  19. package/dist/broadcasting/index.d.ts +233 -0
  20. package/dist/broadcasting/index.js +907 -0
  21. package/dist/cache/index.d.ts +233 -0
  22. package/dist/cache/index.js +817 -0
  23. package/dist/encryption/index.d.ts +222 -0
  24. package/dist/encryption/index.js +602 -0
  25. package/dist/events/index.d.ts +155 -0
  26. package/dist/events/index.js +330 -0
  27. package/dist/health/index.d.ts +185 -0
  28. package/dist/health/index.js +379 -0
  29. package/dist/i18n/index.d.ts +101 -0
  30. package/dist/i18n/index.js +597 -0
  31. package/dist/index-9_Jzj5jo.d.ts +7 -0
  32. package/dist/index.d.ts +2628 -619
  33. package/dist/index.js +22229 -3116
  34. package/dist/lambda/index.d.ts +156 -0
  35. package/dist/lambda/index.js +91 -0
  36. package/dist/logging/index.d.ts +50 -0
  37. package/dist/logging/index.js +557 -0
  38. package/dist/mail/index.d.ts +288 -0
  39. package/dist/mail/index.js +695 -0
  40. package/dist/mcp/index.d.ts +139 -0
  41. package/dist/mcp/index.js +382 -0
  42. package/dist/notifications/index.d.ts +271 -0
  43. package/dist/notifications/index.js +741 -0
  44. package/dist/queue/index.d.ts +423 -0
  45. package/dist/queue/index.js +958 -0
  46. package/dist/runtime/index.d.ts +93 -0
  47. package/dist/runtime/index.js +834 -0
  48. package/dist/scheduling/index.d.ts +41 -0
  49. package/dist/scheduling/index.js +836 -0
  50. package/dist/storage/index.d.ts +196 -0
  51. package/dist/storage/index.js +832 -0
  52. package/dist/vite/index.js +203 -3
  53. package/package.json +93 -6
  54. package/dist/chunk-FK2XQSBF.js +0 -160
@@ -0,0 +1,557 @@
1
+ // src/logging/types.ts
2
+ var LOG_LEVEL_PRIORITY = {
3
+ emergency: 0,
4
+ alert: 1,
5
+ critical: 2,
6
+ error: 3,
7
+ warning: 4,
8
+ notice: 5,
9
+ info: 6,
10
+ debug: 7
11
+ };
12
+
13
+ // src/logging/Logger.ts
14
+ var DEFAULT_FILTER_KEYS = [
15
+ "password",
16
+ "password_confirmation",
17
+ "token",
18
+ "secret",
19
+ "credit_card",
20
+ "creditCard",
21
+ "card_number",
22
+ "cardNumber",
23
+ "cvv",
24
+ "ssn",
25
+ "authorization"
26
+ ];
27
+ function filterSensitiveData(data, filterKeys, replacement = "[FILTERED]") {
28
+ if (filterKeys.length === 0) return data;
29
+ const keySet = new Set(filterKeys.map((k) => k.toLowerCase()));
30
+ return filterObject(data, keySet, replacement);
31
+ }
32
+ function filterObject(obj, keySet, replacement) {
33
+ const result = {};
34
+ for (const [key, value] of Object.entries(obj)) {
35
+ if (keySet.has(key.toLowerCase())) {
36
+ result[key] = replacement;
37
+ } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
38
+ result[key] = filterObject(value, keySet, replacement);
39
+ } else if (Array.isArray(value)) {
40
+ result[key] = value.map(
41
+ (item) => item !== null && typeof item === "object" && !Array.isArray(item) ? filterObject(item, keySet, replacement) : item
42
+ );
43
+ } else {
44
+ result[key] = value;
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+ var Logger = class _Logger {
50
+ channels;
51
+ baseContext;
52
+ filterKeys;
53
+ replacement;
54
+ constructor(channels, context = {}, options = {}) {
55
+ this.channels = channels;
56
+ this.baseContext = context;
57
+ this.filterKeys = options.filterKeys ?? DEFAULT_FILTER_KEYS;
58
+ this.replacement = options.replacement ?? "[FILTERED]";
59
+ }
60
+ /**
61
+ * Log at emergency level (system is unusable).
62
+ */
63
+ emergency(message, context = {}) {
64
+ this.log("emergency", message, context);
65
+ }
66
+ /**
67
+ * Log at alert level (action must be taken immediately).
68
+ */
69
+ alert(message, context = {}) {
70
+ this.log("alert", message, context);
71
+ }
72
+ /**
73
+ * Log at critical level (critical conditions).
74
+ */
75
+ critical(message, context = {}) {
76
+ this.log("critical", message, context);
77
+ }
78
+ /**
79
+ * Log at error level (error conditions).
80
+ */
81
+ error(message, context = {}) {
82
+ this.log("error", message, context);
83
+ }
84
+ /**
85
+ * Log at warning level (warning conditions).
86
+ */
87
+ warning(message, context = {}) {
88
+ this.log("warning", message, context);
89
+ }
90
+ /**
91
+ * Alias for warning().
92
+ */
93
+ warn(message, context = {}) {
94
+ this.warning(message, context);
95
+ }
96
+ /**
97
+ * Log at notice level (normal but significant conditions).
98
+ */
99
+ notice(message, context = {}) {
100
+ this.log("notice", message, context);
101
+ }
102
+ /**
103
+ * Log at info level (informational messages).
104
+ */
105
+ info(message, context = {}) {
106
+ this.log("info", message, context);
107
+ }
108
+ /**
109
+ * Log at debug level (debug-level messages).
110
+ */
111
+ debug(message, context = {}) {
112
+ this.log("debug", message, context);
113
+ }
114
+ /**
115
+ * Log a message at the specified level.
116
+ */
117
+ log(level, message, context = {}) {
118
+ const merged = { ...this.baseContext, ...context };
119
+ const filtered = this.filterKeys.length > 0 ? filterSensitiveData(merged, this.filterKeys, this.replacement) : merged;
120
+ const entry = {
121
+ level,
122
+ message,
123
+ context: filtered,
124
+ timestamp: /* @__PURE__ */ new Date()
125
+ };
126
+ for (const channel of this.channels) {
127
+ try {
128
+ channel.log(entry);
129
+ } catch (error) {
130
+ console.error("Logging error:", error);
131
+ }
132
+ }
133
+ }
134
+ /**
135
+ * Create a new logger with additional context.
136
+ */
137
+ withContext(context) {
138
+ return new _Logger(this.channels, { ...this.baseContext, ...context }, {
139
+ filterKeys: this.filterKeys,
140
+ replacement: this.replacement
141
+ });
142
+ }
143
+ /**
144
+ * Create a child logger with additional context (alias for withContext).
145
+ */
146
+ child(context) {
147
+ return this.withContext(context);
148
+ }
149
+ /**
150
+ * Close all channels.
151
+ */
152
+ async close() {
153
+ for (const channel of this.channels) {
154
+ if (channel.close) {
155
+ await channel.close();
156
+ }
157
+ }
158
+ }
159
+ };
160
+
161
+ // src/logging/channels/ConsoleChannel.ts
162
+ var LEVEL_COLORS = {
163
+ emergency: "\x1B[41m\x1B[37m",
164
+ // White on red background
165
+ alert: "\x1B[41m\x1B[37m",
166
+ // White on red background
167
+ critical: "\x1B[31m",
168
+ // Red
169
+ error: "\x1B[31m",
170
+ // Red
171
+ warning: "\x1B[33m",
172
+ // Yellow
173
+ notice: "\x1B[36m",
174
+ // Cyan
175
+ info: "\x1B[32m",
176
+ // Green
177
+ debug: "\x1B[90m"
178
+ // Gray
179
+ };
180
+ var RESET = "\x1B[0m";
181
+ var ConsoleChannel = class {
182
+ config;
183
+ minLevel;
184
+ constructor(config) {
185
+ this.config = {
186
+ colors: true,
187
+ timestamps: true,
188
+ format: "text",
189
+ ...config
190
+ };
191
+ this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
192
+ }
193
+ log(entry) {
194
+ const entryLevel = LOG_LEVEL_PRIORITY[entry.level];
195
+ if (entryLevel > this.minLevel) {
196
+ return;
197
+ }
198
+ const output = this.format(entry);
199
+ if (entryLevel <= LOG_LEVEL_PRIORITY.error) {
200
+ console.error(output);
201
+ } else if (entryLevel <= LOG_LEVEL_PRIORITY.warning) {
202
+ console.warn(output);
203
+ } else if (entryLevel <= LOG_LEVEL_PRIORITY.info) {
204
+ console.info(output);
205
+ } else {
206
+ console.log(output);
207
+ }
208
+ }
209
+ format(entry) {
210
+ if (this.config.format === "json") {
211
+ return JSON.stringify({
212
+ timestamp: entry.timestamp.toISOString(),
213
+ level: entry.level,
214
+ message: entry.message,
215
+ ...entry.context
216
+ });
217
+ }
218
+ const parts = [];
219
+ if (this.config.timestamps) {
220
+ const time = entry.timestamp.toISOString();
221
+ parts.push(this.config.colors ? `\x1B[90m[${time}]\x1B[0m` : `[${time}]`);
222
+ }
223
+ const levelStr = entry.level.toUpperCase().padEnd(9);
224
+ if (this.config.colors) {
225
+ parts.push(`${LEVEL_COLORS[entry.level]}${levelStr}${RESET}`);
226
+ } else {
227
+ parts.push(levelStr);
228
+ }
229
+ parts.push(entry.message);
230
+ if (Object.keys(entry.context).length > 0) {
231
+ const contextStr = JSON.stringify(entry.context);
232
+ if (this.config.colors) {
233
+ parts.push(`\x1B[90m${contextStr}${RESET}`);
234
+ } else {
235
+ parts.push(contextStr);
236
+ }
237
+ }
238
+ return parts.join(" ");
239
+ }
240
+ };
241
+
242
+ // src/logging/channels/FileChannel.ts
243
+ import * as fs from "fs";
244
+ import * as path from "path";
245
+ var FileChannel = class {
246
+ config;
247
+ minLevel;
248
+ initialized = false;
249
+ constructor(config) {
250
+ this.config = {
251
+ format: "text",
252
+ ...config
253
+ };
254
+ this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
255
+ }
256
+ log(entry) {
257
+ const entryLevel = LOG_LEVEL_PRIORITY[entry.level];
258
+ if (entryLevel > this.minLevel) {
259
+ return;
260
+ }
261
+ const line = this.format(entry) + "\n";
262
+ this.write(line);
263
+ }
264
+ write(data) {
265
+ if (!this.initialized) {
266
+ this.ensureDirectory();
267
+ this.initialized = true;
268
+ }
269
+ fs.appendFileSync(this.config.path, data);
270
+ }
271
+ ensureDirectory() {
272
+ const dir = path.dirname(this.config.path);
273
+ if (!fs.existsSync(dir)) {
274
+ fs.mkdirSync(dir, { recursive: true });
275
+ }
276
+ }
277
+ format(entry) {
278
+ if (this.config.format === "json") {
279
+ return JSON.stringify({
280
+ timestamp: entry.timestamp.toISOString(),
281
+ level: entry.level,
282
+ message: entry.message,
283
+ ...entry.context
284
+ });
285
+ }
286
+ const timestamp = entry.timestamp.toISOString();
287
+ const level = entry.level.toUpperCase().padEnd(9);
288
+ const context = Object.keys(entry.context).length > 0 ? " " + JSON.stringify(entry.context) : "";
289
+ return `[${timestamp}] ${level} ${entry.message}${context}`;
290
+ }
291
+ close() {
292
+ }
293
+ };
294
+
295
+ // src/logging/channels/DailyFileChannel.ts
296
+ import * as fs2 from "fs";
297
+ import * as path2 from "path";
298
+ var DailyFileChannel = class {
299
+ config;
300
+ minLevel;
301
+ currentDate = null;
302
+ currentFilePath = null;
303
+ constructor(config) {
304
+ this.config = {
305
+ days: 14,
306
+ format: "text",
307
+ ...config
308
+ };
309
+ this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
310
+ }
311
+ log(entry) {
312
+ const entryLevel = LOG_LEVEL_PRIORITY[entry.level];
313
+ if (entryLevel > this.minLevel) {
314
+ return;
315
+ }
316
+ const dateStr = this.getDateString(entry.timestamp);
317
+ if (this.currentDate !== dateStr) {
318
+ this.rotate(dateStr);
319
+ }
320
+ const line = this.format(entry) + "\n";
321
+ this.write(line);
322
+ }
323
+ write(data) {
324
+ if (this.currentFilePath) {
325
+ fs2.appendFileSync(this.currentFilePath, data);
326
+ }
327
+ }
328
+ rotate(dateStr) {
329
+ this.currentDate = dateStr;
330
+ this.currentFilePath = this.getFilePath(dateStr);
331
+ this.ensureDirectory(this.currentFilePath);
332
+ this.cleanup();
333
+ }
334
+ getFilePath(dateStr) {
335
+ const { dir, name, ext } = path2.parse(this.config.path);
336
+ return path2.join(dir, `${name}-${dateStr}${ext}`);
337
+ }
338
+ getDateString(date) {
339
+ return date.toISOString().split("T")[0];
340
+ }
341
+ ensureDirectory(filePath) {
342
+ const dir = path2.dirname(filePath);
343
+ if (!fs2.existsSync(dir)) {
344
+ fs2.mkdirSync(dir, { recursive: true });
345
+ }
346
+ }
347
+ cleanup() {
348
+ const { dir, name, ext } = path2.parse(this.config.path);
349
+ if (!fs2.existsSync(dir)) {
350
+ return;
351
+ }
352
+ const files = fs2.readdirSync(dir);
353
+ const pattern = new RegExp(`^${name}-(\\d{4}-\\d{2}-\\d{2})${ext.replace(".", "\\.")}$`);
354
+ const cutoff = /* @__PURE__ */ new Date();
355
+ cutoff.setDate(cutoff.getDate() - (this.config.days ?? 14));
356
+ for (const file of files) {
357
+ const match = file.match(pattern);
358
+ if (match) {
359
+ const fileDate = new Date(match[1]);
360
+ if (fileDate < cutoff) {
361
+ fs2.unlinkSync(path2.join(dir, file));
362
+ }
363
+ }
364
+ }
365
+ }
366
+ format(entry) {
367
+ if (this.config.format === "json") {
368
+ return JSON.stringify({
369
+ timestamp: entry.timestamp.toISOString(),
370
+ level: entry.level,
371
+ message: entry.message,
372
+ ...entry.context
373
+ });
374
+ }
375
+ const timestamp = entry.timestamp.toISOString();
376
+ const level = entry.level.toUpperCase().padEnd(9);
377
+ const context = Object.keys(entry.context).length > 0 ? " " + JSON.stringify(entry.context) : "";
378
+ return `[${timestamp}] ${level} ${entry.message}${context}`;
379
+ }
380
+ close() {
381
+ }
382
+ };
383
+
384
+ // src/logging/LogManager.ts
385
+ var LogManager = class {
386
+ config;
387
+ channelFactories = /* @__PURE__ */ new Map();
388
+ channelInstances = /* @__PURE__ */ new Map();
389
+ loggers = /* @__PURE__ */ new Map();
390
+ loggerOptions;
391
+ constructor(config) {
392
+ this.config = config;
393
+ this.loggerOptions = {
394
+ filterKeys: config.filterKeys,
395
+ replacement: config.filterReplacement
396
+ };
397
+ this.registerDefaultDrivers();
398
+ }
399
+ registerDefaultDrivers() {
400
+ this.registerDriver("console", (config) => {
401
+ return new ConsoleChannel(config);
402
+ });
403
+ this.registerDriver("file", (config) => {
404
+ return new FileChannel(config);
405
+ });
406
+ this.registerDriver("daily", (config) => {
407
+ return new DailyFileChannel(config);
408
+ });
409
+ this.registerDriver("stack", (config) => {
410
+ return this.createStackChannel(config);
411
+ });
412
+ }
413
+ createStackChannel(config) {
414
+ const channels = config.channels.map((name) => this.resolveChannel(name));
415
+ return {
416
+ log: (entry) => {
417
+ for (const channel of channels) {
418
+ channel.log(entry);
419
+ }
420
+ },
421
+ close: async () => {
422
+ for (const channel of channels) {
423
+ if (channel.close) {
424
+ await channel.close();
425
+ }
426
+ }
427
+ }
428
+ };
429
+ }
430
+ /**
431
+ * Register a custom channel driver.
432
+ */
433
+ registerDriver(name, factory) {
434
+ this.channelFactories.set(name, factory);
435
+ }
436
+ /**
437
+ * Get a logger for a specific channel.
438
+ */
439
+ channel(name) {
440
+ const channelName = name ?? this.config.default;
441
+ if (!this.loggers.has(channelName)) {
442
+ const channel = this.resolveChannel(channelName);
443
+ this.loggers.set(channelName, new Logger([channel], {}, this.loggerOptions));
444
+ }
445
+ return this.loggers.get(channelName);
446
+ }
447
+ /**
448
+ * Get a logger that writes to multiple channels.
449
+ */
450
+ stack(channelNames) {
451
+ const key = `stack:${channelNames.join(",")}`;
452
+ if (!this.loggers.has(key)) {
453
+ const channels = channelNames.map((name) => this.resolveChannel(name));
454
+ this.loggers.set(key, new Logger(channels, {}, this.loggerOptions));
455
+ }
456
+ return this.loggers.get(key);
457
+ }
458
+ resolveChannel(name) {
459
+ if (this.channelInstances.has(name)) {
460
+ return this.channelInstances.get(name);
461
+ }
462
+ const config = this.config.channels[name];
463
+ if (!config) {
464
+ throw new Error(`Log channel [${name}] is not defined`);
465
+ }
466
+ const factory = this.channelFactories.get(config.driver);
467
+ if (!factory) {
468
+ throw new Error(`Log driver [${config.driver}] is not supported`);
469
+ }
470
+ const channel = factory(config);
471
+ this.channelInstances.set(name, channel);
472
+ return channel;
473
+ }
474
+ /**
475
+ * Create a logger with additional context using the default channel.
476
+ */
477
+ withContext(context) {
478
+ return this.channel().withContext(context);
479
+ }
480
+ // Convenience methods that delegate to default channel
481
+ emergency(message, context) {
482
+ this.channel().emergency(message, context);
483
+ }
484
+ alert(message, context) {
485
+ this.channel().alert(message, context);
486
+ }
487
+ critical(message, context) {
488
+ this.channel().critical(message, context);
489
+ }
490
+ error(message, context) {
491
+ this.channel().error(message, context);
492
+ }
493
+ warning(message, context) {
494
+ this.channel().warning(message, context);
495
+ }
496
+ warn(message, context) {
497
+ this.channel().warn(message, context);
498
+ }
499
+ notice(message, context) {
500
+ this.channel().notice(message, context);
501
+ }
502
+ info(message, context) {
503
+ this.channel().info(message, context);
504
+ }
505
+ debug(message, context) {
506
+ this.channel().debug(message, context);
507
+ }
508
+ /**
509
+ * Close all channel instances.
510
+ */
511
+ async close() {
512
+ for (const channel of this.channelInstances.values()) {
513
+ if (channel.close) {
514
+ await channel.close();
515
+ }
516
+ }
517
+ this.channelInstances.clear();
518
+ this.loggers.clear();
519
+ }
520
+ /**
521
+ * Get the default channel name.
522
+ */
523
+ getDefaultChannel() {
524
+ return this.config.default;
525
+ }
526
+ /**
527
+ * Get available channel names.
528
+ */
529
+ getChannelNames() {
530
+ return Object.keys(this.config.channels);
531
+ }
532
+ };
533
+ function createLogManager(config) {
534
+ return new LogManager(config);
535
+ }
536
+ var globalLogManager = null;
537
+ function setLogManager(manager) {
538
+ globalLogManager = manager;
539
+ }
540
+ function getLogManager() {
541
+ if (!globalLogManager) {
542
+ throw new Error("Log manager has not been initialized. Call setLogManager() first.");
543
+ }
544
+ return globalLogManager;
545
+ }
546
+ export {
547
+ ConsoleChannel,
548
+ DailyFileChannel,
549
+ FileChannel,
550
+ LOG_LEVEL_PRIORITY,
551
+ LogManager,
552
+ Logger,
553
+ createLogManager,
554
+ filterSensitiveData,
555
+ getLogManager,
556
+ setLogManager
557
+ };