@guren/server 1.0.0-rc.9 → 1.0.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.
Files changed (68) hide show
  1. package/dist/{Application-DtWDHXr1.d.ts → Application-BnsyCKXY.d.ts} +79 -8
  2. package/dist/AuthManager-SfhCNkAU.d.ts +79 -0
  3. package/dist/{BroadcastManager-AkIWUGJo.d.ts → BroadcastManager-CGWl9rUO.d.ts} +5 -0
  4. package/dist/{ConsoleKernel-CqCVrdZs.d.ts → ConsoleKernel-BDtBETjm.d.ts} +1 -1
  5. package/dist/{Gate-CNkBYf8m.d.ts → Gate-CynjZCtS.d.ts} +5 -0
  6. package/dist/{I18nManager-Dtgzsf5n.d.ts → I18nManager-BiSoczfV.d.ts} +6 -1
  7. package/dist/McpServiceProvider-JW6PDVMD.js +7 -0
  8. package/dist/api-token-BSSCLlFW.d.ts +541 -0
  9. package/dist/auth/index.d.ts +9 -327
  10. package/dist/auth/index.js +59 -6684
  11. package/dist/authorization/index.d.ts +2 -2
  12. package/dist/authorization/index.js +19 -604
  13. package/dist/broadcasting/index.d.ts +2 -2
  14. package/dist/broadcasting/index.js +12 -895
  15. package/dist/cache/index.js +8 -809
  16. package/dist/chunk-2T6JN4VR.js +1563 -0
  17. package/dist/chunk-44F7JQ7I.js +950 -0
  18. package/dist/chunk-74HTZG3V.js +331 -0
  19. package/dist/chunk-A3ISJVEV.js +598 -0
  20. package/dist/chunk-CSDKWLFD.js +652 -0
  21. package/dist/chunk-CSRQTEQA.js +839 -0
  22. package/dist/chunk-DAQKYKLH.js +182 -0
  23. package/dist/chunk-EDRGAM6G.js +647 -0
  24. package/dist/chunk-EGU5KB7V.js +818 -0
  25. package/dist/chunk-H32L2NE3.js +372 -0
  26. package/dist/chunk-HKQSAFSN.js +837 -0
  27. package/dist/chunk-IOTWFHZU.js +558 -0
  28. package/dist/chunk-ONSDE37A.js +125 -0
  29. package/dist/chunk-QQKTH5KX.js +114 -0
  30. package/dist/chunk-R2TCP7D7.js +409 -0
  31. package/dist/chunk-SIP34GBE.js +380 -0
  32. package/dist/chunk-THSX7OOR.js +454 -0
  33. package/dist/chunk-UY3AZSYL.js +14 -0
  34. package/dist/chunk-VT5KRDPH.js +134 -0
  35. package/dist/chunk-VXXZIXAP.js +255 -0
  36. package/dist/chunk-WJJ5CTNI.js +907 -0
  37. package/dist/chunk-WVY45EIW.js +359 -0
  38. package/dist/chunk-ZRBLZY3M.js +462 -0
  39. package/dist/client-CKXJLsTe.d.ts +232 -0
  40. package/dist/email-verification-CAeArjui.d.ts +327 -0
  41. package/dist/encryption/index.js +48 -556
  42. package/dist/errors-JOOPDDQ6.js +34 -0
  43. package/dist/events/index.js +14 -316
  44. package/dist/health/index.js +12 -367
  45. package/dist/i18n/index.d.ts +2 -2
  46. package/dist/i18n/index.js +14 -583
  47. package/dist/index.d.ts +37 -239
  48. package/dist/index.js +2873 -19166
  49. package/dist/lambda/index.d.ts +9 -7
  50. package/dist/lambda/index.js +4 -9
  51. package/dist/logging/index.js +12 -545
  52. package/dist/mail/index.d.ts +29 -1
  53. package/dist/mail/index.js +15 -684
  54. package/dist/mcp/index.d.ts +7 -5
  55. package/dist/mcp/index.js +5 -378
  56. package/dist/notifications/index.d.ts +8 -6
  57. package/dist/notifications/index.js +13 -730
  58. package/dist/queue/index.d.ts +37 -7
  59. package/dist/queue/index.js +22 -940
  60. package/dist/redis/index.d.ts +366 -0
  61. package/dist/redis/index.js +597 -0
  62. package/dist/runtime/index.d.ts +8 -6
  63. package/dist/runtime/index.js +26 -244
  64. package/dist/scheduling/index.js +14 -822
  65. package/dist/storage/index.d.ts +1 -0
  66. package/dist/storage/index.js +6 -824
  67. package/package.json +15 -7
  68. package/dist/api-token-JOif2CtG.d.ts +0 -1792
@@ -0,0 +1,380 @@
1
+ // src/health/HealthCheck.ts
2
+ var HealthCheck = class {
3
+ /**
4
+ * Create a healthy result.
5
+ */
6
+ healthy(message, meta) {
7
+ return this.result("healthy", message, meta);
8
+ }
9
+ /**
10
+ * Create a degraded result.
11
+ */
12
+ degraded(message, meta) {
13
+ return this.result("degraded", message, meta);
14
+ }
15
+ /**
16
+ * Create an unhealthy result.
17
+ */
18
+ unhealthy(message, meta) {
19
+ return this.result("unhealthy", message, meta);
20
+ }
21
+ /**
22
+ * Create an unhealthy result from a caught error.
23
+ */
24
+ handleError(error, fallbackMessage) {
25
+ return this.unhealthy(
26
+ error instanceof Error ? error.message : fallbackMessage
27
+ );
28
+ }
29
+ /**
30
+ * Create a check result.
31
+ */
32
+ result(status, message, meta) {
33
+ const result = {
34
+ name: this.name,
35
+ status,
36
+ duration: 0
37
+ // Will be set by HealthManager
38
+ };
39
+ if (message !== void 0) {
40
+ result.message = message;
41
+ }
42
+ if (meta !== void 0) {
43
+ result.meta = meta;
44
+ }
45
+ return result;
46
+ }
47
+ };
48
+
49
+ // src/health/HealthManager.ts
50
+ var HealthManager = class {
51
+ checks = /* @__PURE__ */ new Map();
52
+ /**
53
+ * Register a health check.
54
+ */
55
+ register(check, options = {}) {
56
+ this.checks.set(check.name, {
57
+ check,
58
+ options: {
59
+ timeout: options.timeout ?? 5e3,
60
+ critical: options.critical ?? false
61
+ }
62
+ });
63
+ return this;
64
+ }
65
+ /**
66
+ * Unregister a health check.
67
+ */
68
+ unregister(name) {
69
+ this.checks.delete(name);
70
+ return this;
71
+ }
72
+ /**
73
+ * Get all registered check names.
74
+ */
75
+ getCheckNames() {
76
+ return Array.from(this.checks.keys());
77
+ }
78
+ /**
79
+ * Run all health checks.
80
+ */
81
+ async check() {
82
+ return this.runChecks(this.getCheckNames());
83
+ }
84
+ /**
85
+ * Run specific health checks.
86
+ */
87
+ async checkOnly(names) {
88
+ const validNames = names.filter((name) => this.checks.has(name));
89
+ return this.runChecks(validNames);
90
+ }
91
+ /**
92
+ * Get a specific check result.
93
+ */
94
+ async getCheck(name) {
95
+ const registered = this.checks.get(name);
96
+ if (!registered) {
97
+ return null;
98
+ }
99
+ return this.runCheck(registered);
100
+ }
101
+ /**
102
+ * Create middleware for health endpoints.
103
+ */
104
+ middleware(options = {}) {
105
+ return async (ctx, next) => {
106
+ const report = options.checks ? await this.checkOnly(options.checks) : await this.check();
107
+ const statusCode = report.status === "healthy" ? 200 : report.status === "degraded" ? 200 : 503;
108
+ if (options.detailed === false) {
109
+ ctx.status(statusCode);
110
+ ctx.json({
111
+ status: report.status,
112
+ timestamp: report.timestamp.toISOString()
113
+ });
114
+ } else {
115
+ ctx.status(statusCode);
116
+ ctx.json({
117
+ status: report.status,
118
+ timestamp: report.timestamp.toISOString(),
119
+ checks: report.checks.map((check) => ({
120
+ name: check.name,
121
+ status: check.status,
122
+ message: check.message,
123
+ duration: check.duration,
124
+ meta: check.meta
125
+ }))
126
+ });
127
+ }
128
+ };
129
+ }
130
+ /**
131
+ * Run the specified checks.
132
+ */
133
+ async runChecks(names) {
134
+ const results = [];
135
+ let overallStatus = "healthy";
136
+ await Promise.all(
137
+ names.map(async (name) => {
138
+ const registered = this.checks.get(name);
139
+ if (!registered) return;
140
+ const result = await this.runCheck(registered);
141
+ results.push(result);
142
+ if (result.status === "unhealthy") {
143
+ if (registered.options.critical) {
144
+ overallStatus = "unhealthy";
145
+ } else if (overallStatus !== "unhealthy") {
146
+ overallStatus = "degraded";
147
+ }
148
+ } else if (result.status === "degraded" && overallStatus === "healthy") {
149
+ overallStatus = "degraded";
150
+ }
151
+ })
152
+ );
153
+ results.sort((a, b) => a.name.localeCompare(b.name));
154
+ return {
155
+ status: overallStatus,
156
+ timestamp: /* @__PURE__ */ new Date(),
157
+ checks: results
158
+ };
159
+ }
160
+ /**
161
+ * Run a single check with timeout.
162
+ */
163
+ async runCheck(registered) {
164
+ const { check, options } = registered;
165
+ const start = performance.now();
166
+ try {
167
+ const result = await Promise.race([
168
+ check.check(),
169
+ this.timeoutPromise(options.timeout)
170
+ ]);
171
+ result.duration = Math.round(performance.now() - start);
172
+ return result;
173
+ } catch (error) {
174
+ const duration = Math.round(performance.now() - start);
175
+ return {
176
+ name: check.name,
177
+ status: "unhealthy",
178
+ message: error instanceof Error ? error.message : "Check failed with error",
179
+ duration
180
+ };
181
+ }
182
+ }
183
+ /**
184
+ * Create a timeout promise.
185
+ */
186
+ timeoutPromise(ms) {
187
+ return new Promise((_, reject) => {
188
+ setTimeout(() => {
189
+ reject(new Error(`Health check timed out after ${ms}ms`));
190
+ }, ms);
191
+ });
192
+ }
193
+ };
194
+ function createHealthManager() {
195
+ return new HealthManager();
196
+ }
197
+
198
+ // src/health/checks/DatabaseCheck.ts
199
+ var DatabaseCheck = class extends HealthCheck {
200
+ name;
201
+ db;
202
+ query;
203
+ constructor(db, options = {}) {
204
+ super();
205
+ this.db = db;
206
+ this.name = options.name ?? "database";
207
+ this.query = options.query ?? "SELECT 1";
208
+ }
209
+ async check() {
210
+ try {
211
+ await this.db.query(this.query);
212
+ return this.healthy("Database connection is healthy");
213
+ } catch (error) {
214
+ return this.handleError(error, "Database connection failed");
215
+ }
216
+ }
217
+ };
218
+
219
+ // src/health/checks/RedisCheck.ts
220
+ var RedisCheck = class extends HealthCheck {
221
+ name;
222
+ redis;
223
+ constructor(redis, options = {}) {
224
+ super();
225
+ this.redis = redis;
226
+ this.name = options.name ?? "redis";
227
+ }
228
+ async check() {
229
+ try {
230
+ const response = await this.redis.ping();
231
+ if (response === "PONG") {
232
+ return this.healthy("Redis connection is healthy");
233
+ }
234
+ return this.degraded(`Redis ping returned: ${response}`);
235
+ } catch (error) {
236
+ return this.handleError(error, "Redis connection failed");
237
+ }
238
+ }
239
+ };
240
+
241
+ // src/health/checks/CacheCheck.ts
242
+ var CacheCheck = class extends HealthCheck {
243
+ name;
244
+ cache;
245
+ testKey;
246
+ constructor(cache, options = {}) {
247
+ super();
248
+ this.cache = cache;
249
+ this.name = options.name ?? "cache";
250
+ this.testKey = options.testKey ?? "__health_check__";
251
+ }
252
+ async check() {
253
+ const testValue = `health_check_${Date.now()}`;
254
+ try {
255
+ await this.cache.put(this.testKey, testValue, 60);
256
+ const retrieved = await this.cache.get(this.testKey);
257
+ await this.cache.forget(this.testKey);
258
+ if (retrieved === testValue) {
259
+ return this.healthy("Cache is functioning correctly");
260
+ }
261
+ return this.degraded(
262
+ `Cache read/write mismatch: expected "${testValue}", got "${retrieved}"`
263
+ );
264
+ } catch (error) {
265
+ return this.handleError(error, "Cache operation failed");
266
+ }
267
+ }
268
+ };
269
+
270
+ // src/health/checks/StorageCheck.ts
271
+ var StorageCheck = class extends HealthCheck {
272
+ name;
273
+ storage;
274
+ testPath;
275
+ constructor(storage, options = {}) {
276
+ super();
277
+ this.storage = storage;
278
+ this.name = options.name ?? "storage";
279
+ this.testPath = options.testPath ?? "__health_check__.txt";
280
+ }
281
+ async check() {
282
+ const testContent = `health_check_${Date.now()}`;
283
+ try {
284
+ await this.storage.put(this.testPath, testContent);
285
+ const retrieved = await this.storage.get(this.testPath);
286
+ await this.storage.delete(this.testPath);
287
+ if (retrieved && retrieved.toString() === testContent) {
288
+ return this.healthy("Storage is functioning correctly");
289
+ }
290
+ return this.degraded("Storage read/write mismatch");
291
+ } catch (error) {
292
+ return this.handleError(error, "Storage operation failed");
293
+ }
294
+ }
295
+ };
296
+
297
+ // src/health/checks/MemoryCheck.ts
298
+ var MemoryCheck = class extends HealthCheck {
299
+ name;
300
+ thresholdMb;
301
+ criticalThresholdMb;
302
+ constructor(options = {}) {
303
+ super();
304
+ this.name = options.name ?? "memory";
305
+ this.thresholdMb = options.thresholdMb ?? 512;
306
+ this.criticalThresholdMb = options.criticalThresholdMb ?? 1024;
307
+ }
308
+ async check() {
309
+ const usage = process.memoryUsage();
310
+ const usedMb = Math.round(usage.heapUsed / 1024 / 1024);
311
+ const totalMb = Math.round(usage.heapTotal / 1024 / 1024);
312
+ const rssMb = Math.round(usage.rss / 1024 / 1024);
313
+ const meta = {
314
+ usedMb,
315
+ totalMb,
316
+ rssMb,
317
+ thresholdMb: this.thresholdMb,
318
+ criticalThresholdMb: this.criticalThresholdMb
319
+ };
320
+ if (usedMb >= this.criticalThresholdMb) {
321
+ return this.unhealthy(
322
+ `Memory usage critical: ${usedMb}MB (threshold: ${this.criticalThresholdMb}MB)`,
323
+ meta
324
+ );
325
+ }
326
+ if (usedMb >= this.thresholdMb) {
327
+ return this.degraded(
328
+ `Memory usage elevated: ${usedMb}MB (threshold: ${this.thresholdMb}MB)`,
329
+ meta
330
+ );
331
+ }
332
+ return this.healthy(`Memory usage normal: ${usedMb}MB`, meta);
333
+ }
334
+ };
335
+
336
+ // src/health/checks/CustomCheck.ts
337
+ var CustomCheck = class extends HealthCheck {
338
+ name;
339
+ callback;
340
+ constructor(name, callback) {
341
+ super();
342
+ this.name = name;
343
+ this.callback = callback;
344
+ }
345
+ async check() {
346
+ try {
347
+ const result = await this.callback();
348
+ switch (result.status) {
349
+ case "healthy":
350
+ return this.healthy(result.message, result.meta);
351
+ case "degraded":
352
+ return this.degraded(result.message, result.meta);
353
+ case "unhealthy":
354
+ return this.unhealthy(result.message, result.meta);
355
+ default:
356
+ return this.unhealthy("Unknown status returned from check");
357
+ }
358
+ } catch (error) {
359
+ return this.unhealthy(
360
+ error instanceof Error ? error.message : "Custom check failed"
361
+ );
362
+ }
363
+ }
364
+ };
365
+ function customCheck(name, callback) {
366
+ return new CustomCheck(name, callback);
367
+ }
368
+
369
+ export {
370
+ HealthCheck,
371
+ HealthManager,
372
+ createHealthManager,
373
+ DatabaseCheck,
374
+ RedisCheck,
375
+ CacheCheck,
376
+ StorageCheck,
377
+ MemoryCheck,
378
+ CustomCheck,
379
+ customCheck
380
+ };