@guren/server 1.0.0-rc.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) 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-QH4NUKSV.js +255 -0
  30. package/dist/chunk-QQKTH5KX.js +114 -0
  31. package/dist/chunk-R2TCP7D7.js +409 -0
  32. package/dist/chunk-SIP34GBE.js +380 -0
  33. package/dist/chunk-THSX7OOR.js +454 -0
  34. package/dist/chunk-UY3AZSYL.js +14 -0
  35. package/dist/chunk-VT5KRDPH.js +134 -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 +2931 -19222
  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/dist/vite/index.d.ts +2 -2
  68. package/dist/vite/index.js +5 -1
  69. package/package.json +15 -7
  70. package/dist/api-token-JOif2CtG.d.ts +0 -1792
@@ -0,0 +1,647 @@
1
+ import {
2
+ Job,
3
+ getQueueDriver,
4
+ registerJob
5
+ } from "./chunk-R2TCP7D7.js";
6
+
7
+ // src/mail/transports/SmtpTransport.ts
8
+ import nodemailer from "nodemailer";
9
+ function formatAddress(addr) {
10
+ if (addr.name) {
11
+ return `"${addr.name}" <${addr.email}>`;
12
+ }
13
+ return addr.email;
14
+ }
15
+ var SmtpTransport = class {
16
+ name = "smtp";
17
+ // Using any to avoid complex nodemailer type gymnastics
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ transporter;
20
+ constructor(options) {
21
+ this.transporter = nodemailer.createTransport({
22
+ host: options.host,
23
+ port: options.port ?? 587,
24
+ secure: options.secure ?? false,
25
+ auth: options.auth,
26
+ pool: options.pool ?? true,
27
+ maxConnections: options.maxConnections ?? 5
28
+ });
29
+ }
30
+ /**
31
+ * Send an email via SMTP.
32
+ */
33
+ async send(message) {
34
+ try {
35
+ const mailOptions = {
36
+ from: message.from ? formatAddress(message.from) : void 0,
37
+ to: message.to.map(formatAddress).join(", "),
38
+ cc: message.cc?.map(formatAddress).join(", "),
39
+ bcc: message.bcc?.map(formatAddress).join(", "),
40
+ replyTo: message.replyTo ? formatAddress(message.replyTo) : void 0,
41
+ subject: message.subject,
42
+ text: message.text,
43
+ html: message.html,
44
+ attachments: message.attachments?.map((a) => ({
45
+ filename: a.filename,
46
+ content: a.content,
47
+ path: a.path,
48
+ contentType: a.contentType,
49
+ cid: a.cid
50
+ })),
51
+ headers: message.headers
52
+ };
53
+ const result = await this.transporter.sendMail(mailOptions);
54
+ return {
55
+ success: true,
56
+ messageId: result.messageId,
57
+ response: result.response
58
+ };
59
+ } catch (error) {
60
+ return {
61
+ success: false,
62
+ error: error instanceof Error ? error.message : String(error)
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Verify SMTP connection.
68
+ */
69
+ async verify() {
70
+ try {
71
+ await this.transporter.verify();
72
+ return true;
73
+ } catch {
74
+ return false;
75
+ }
76
+ }
77
+ /**
78
+ * Close the transport.
79
+ */
80
+ close() {
81
+ this.transporter.close();
82
+ }
83
+ };
84
+
85
+ // src/mail/transports/ResendTransport.ts
86
+ var ResendTransport = class {
87
+ name = "resend";
88
+ apiKey;
89
+ baseUrl = "https://api.resend.com";
90
+ constructor(options) {
91
+ this.apiKey = options.apiKey;
92
+ }
93
+ /**
94
+ * Format email address for Resend API.
95
+ */
96
+ formatAddress(addr) {
97
+ if (addr.name) {
98
+ return `${addr.name} <${addr.email}>`;
99
+ }
100
+ return addr.email;
101
+ }
102
+ /**
103
+ * Send an email via Resend API.
104
+ */
105
+ async send(message) {
106
+ try {
107
+ const payload = {
108
+ from: message.from ? this.formatAddress(message.from) : void 0,
109
+ to: message.to.map((a) => this.formatAddress(a)),
110
+ subject: message.subject
111
+ };
112
+ if (message.cc?.length) {
113
+ payload.cc = message.cc.map((a) => this.formatAddress(a));
114
+ }
115
+ if (message.bcc?.length) {
116
+ payload.bcc = message.bcc.map((a) => this.formatAddress(a));
117
+ }
118
+ if (message.replyTo) {
119
+ payload.reply_to = this.formatAddress(message.replyTo);
120
+ }
121
+ if (message.text) {
122
+ payload.text = message.text;
123
+ }
124
+ if (message.html) {
125
+ payload.html = message.html;
126
+ }
127
+ if (message.attachments?.length) {
128
+ payload.attachments = message.attachments.map((a) => ({
129
+ filename: a.filename,
130
+ content: a.content instanceof Buffer ? a.content.toString("base64") : a.content,
131
+ content_type: a.contentType
132
+ }));
133
+ }
134
+ if (message.headers) {
135
+ payload.headers = message.headers;
136
+ }
137
+ const response = await fetch(`${this.baseUrl}/emails`, {
138
+ method: "POST",
139
+ headers: {
140
+ "Content-Type": "application/json",
141
+ Authorization: `Bearer ${this.apiKey}`
142
+ },
143
+ body: JSON.stringify(payload)
144
+ });
145
+ if (!response.ok) {
146
+ const errorData = await response.json();
147
+ return {
148
+ success: false,
149
+ error: errorData.message || `HTTP ${response.status}`
150
+ };
151
+ }
152
+ const data = await response.json();
153
+ return {
154
+ success: true,
155
+ messageId: data.id,
156
+ response: `Message sent with ID: ${data.id}`
157
+ };
158
+ } catch (error) {
159
+ return {
160
+ success: false,
161
+ error: error instanceof Error ? error.message : String(error)
162
+ };
163
+ }
164
+ }
165
+ };
166
+
167
+ // src/mail/transports/MemoryTransport.ts
168
+ var MemoryTransport = class {
169
+ name = "memory";
170
+ messages = [];
171
+ simulateFailure;
172
+ failureMessage;
173
+ constructor(options = {}) {
174
+ this.simulateFailure = options.simulateFailure ?? false;
175
+ this.failureMessage = options.failureMessage ?? "Simulated email failure";
176
+ }
177
+ /**
178
+ * Send an email (stores in memory).
179
+ */
180
+ async send(message) {
181
+ if (this.simulateFailure) {
182
+ return {
183
+ success: false,
184
+ error: this.failureMessage
185
+ };
186
+ }
187
+ const messageId = `memory-${Date.now()}-${Math.random().toString(36).slice(2)}`;
188
+ this.messages.push({ ...message });
189
+ return {
190
+ success: true,
191
+ messageId,
192
+ response: "Message stored in memory"
193
+ };
194
+ }
195
+ /**
196
+ * Get all sent messages.
197
+ */
198
+ getMessages() {
199
+ return [...this.messages];
200
+ }
201
+ /**
202
+ * Get the last sent message.
203
+ */
204
+ getLastMessage() {
205
+ return this.messages[this.messages.length - 1];
206
+ }
207
+ /**
208
+ * Find messages by recipient email.
209
+ */
210
+ findByRecipient(email) {
211
+ return this.messages.filter(
212
+ (m) => m.to.some((addr) => addr.email.toLowerCase() === email.toLowerCase())
213
+ );
214
+ }
215
+ /**
216
+ * Find messages by subject.
217
+ */
218
+ findBySubject(subject) {
219
+ return this.messages.filter(
220
+ (m) => m.subject.toLowerCase().includes(subject.toLowerCase())
221
+ );
222
+ }
223
+ /**
224
+ * Check if any message was sent to a recipient.
225
+ */
226
+ hasSentTo(email) {
227
+ return this.findByRecipient(email).length > 0;
228
+ }
229
+ /**
230
+ * Check if any message was sent with a subject.
231
+ */
232
+ hasSentWithSubject(subject) {
233
+ return this.findBySubject(subject).length > 0;
234
+ }
235
+ /**
236
+ * Get the count of sent messages.
237
+ */
238
+ count() {
239
+ return this.messages.length;
240
+ }
241
+ /**
242
+ * Clear all stored messages.
243
+ */
244
+ clear() {
245
+ this.messages = [];
246
+ }
247
+ /**
248
+ * Set whether to simulate failures.
249
+ */
250
+ setSimulateFailure(simulate, message) {
251
+ this.simulateFailure = simulate;
252
+ if (message) {
253
+ this.failureMessage = message;
254
+ }
255
+ }
256
+ /**
257
+ * Assert that a message was sent to a recipient.
258
+ * Throws if no message was found.
259
+ */
260
+ assertSentTo(email) {
261
+ if (!this.hasSentTo(email)) {
262
+ throw new Error(`No email was sent to ${email}`);
263
+ }
264
+ }
265
+ /**
266
+ * Assert that a message was sent with a subject.
267
+ * Throws if no message was found.
268
+ */
269
+ assertSentWithSubject(subject) {
270
+ if (!this.hasSentWithSubject(subject)) {
271
+ throw new Error(`No email was sent with subject containing "${subject}"`);
272
+ }
273
+ }
274
+ /**
275
+ * Assert that exactly n messages were sent.
276
+ * Throws if count doesn't match.
277
+ */
278
+ assertSentCount(count) {
279
+ if (this.messages.length !== count) {
280
+ throw new Error(`Expected ${count} emails to be sent, but got ${this.messages.length}`);
281
+ }
282
+ }
283
+ };
284
+
285
+ // src/mail/transports/LogTransport.ts
286
+ var LogTransport = class {
287
+ name = "log";
288
+ logger;
289
+ constructor(options = {}) {
290
+ this.logger = options.logger ?? console.log;
291
+ }
292
+ async send(message) {
293
+ const to = message.to.map((address) => address.email).join(", ");
294
+ const from = message.from ? message.from.email : "(default sender)";
295
+ const body = message.text ?? message.html ?? "";
296
+ this.logger(
297
+ [
298
+ "[mail] ------------------------------------------------------------",
299
+ `[mail] To: ${to}`,
300
+ `[mail] From: ${from}`,
301
+ `[mail] Subject: ${message.subject}`,
302
+ `[mail] ${body.split("\n").join("\n[mail] ")}`,
303
+ "[mail] ------------------------------------------------------------"
304
+ ].join("\n")
305
+ );
306
+ return {
307
+ success: true,
308
+ messageId: `log-${Date.now()}-${Math.random().toString(36).slice(2)}`,
309
+ response: "Message written to log"
310
+ };
311
+ }
312
+ };
313
+
314
+ // src/mail/MailManager.ts
315
+ var MailManager = class {
316
+ defaultTransportName;
317
+ defaultFrom;
318
+ transportFactories = /* @__PURE__ */ new Map();
319
+ resolvedTransports = /* @__PURE__ */ new Map();
320
+ constructor(config = {}) {
321
+ this.defaultTransportName = config.default ?? "smtp";
322
+ this.defaultFrom = config.from;
323
+ this.registerBuiltinDrivers();
324
+ if (config.transports) {
325
+ for (const [name, transportConfig] of Object.entries(config.transports)) {
326
+ this.registerTransportFromConfig(name, transportConfig);
327
+ }
328
+ }
329
+ }
330
+ /**
331
+ * Register built-in transport drivers.
332
+ */
333
+ registerBuiltinDrivers() {
334
+ this.registerDriverFactory("smtp", (options) => {
335
+ return new SmtpTransport(options);
336
+ });
337
+ this.registerDriverFactory("resend", (options) => {
338
+ return new ResendTransport(options);
339
+ });
340
+ this.registerDriverFactory("memory", (options) => {
341
+ return new MemoryTransport(options);
342
+ });
343
+ this.registerDriverFactory("log", (options) => {
344
+ return new LogTransport(options);
345
+ });
346
+ }
347
+ driverFactories = /* @__PURE__ */ new Map();
348
+ /**
349
+ * Register a driver factory.
350
+ */
351
+ registerDriverFactory(driver, factory) {
352
+ this.driverFactories.set(driver, factory);
353
+ }
354
+ /**
355
+ * Register a transport from configuration.
356
+ */
357
+ registerTransportFromConfig(name, config) {
358
+ const { driver, ...options } = config;
359
+ const factory = this.driverFactories.get(driver);
360
+ if (!factory) {
361
+ throw new Error(`Unknown mail driver: ${driver}`);
362
+ }
363
+ this.transportFactories.set(name, () => factory(options));
364
+ }
365
+ /**
366
+ * Get a mail transport by name.
367
+ * Returns the default transport if no name is specified.
368
+ */
369
+ transport(name) {
370
+ const transportName = name ?? this.defaultTransportName;
371
+ const cached = this.resolvedTransports.get(transportName);
372
+ if (cached) {
373
+ return cached;
374
+ }
375
+ const factory = this.transportFactories.get(transportName);
376
+ if (!factory) {
377
+ throw new Error(`Mail transport not found: ${transportName}`);
378
+ }
379
+ const transport = factory();
380
+ this.resolvedTransports.set(transportName, transport);
381
+ return transport;
382
+ }
383
+ /**
384
+ * Register a custom transport.
385
+ */
386
+ registerTransport(name, factory) {
387
+ this.transportFactories.set(name, factory);
388
+ this.resolvedTransports.delete(name);
389
+ }
390
+ /**
391
+ * Check if a transport is registered.
392
+ */
393
+ hasTransport(name) {
394
+ return this.transportFactories.has(name);
395
+ }
396
+ /**
397
+ * Get the default transport name.
398
+ */
399
+ getDefaultTransportName() {
400
+ return this.defaultTransportName;
401
+ }
402
+ /**
403
+ * Get the default from address.
404
+ */
405
+ getDefaultFrom() {
406
+ return this.defaultFrom;
407
+ }
408
+ /**
409
+ * Get all registered transport names.
410
+ */
411
+ getTransportNames() {
412
+ return Array.from(this.transportFactories.keys());
413
+ }
414
+ };
415
+ function createMailManager(config) {
416
+ return new MailManager(config);
417
+ }
418
+
419
+ // src/mail/Mail.ts
420
+ function parseAddress(input) {
421
+ if (typeof input === "string") {
422
+ const match = input.match(/^(.+)\s*<(.+)>$/);
423
+ if (match) {
424
+ return { name: match[1].trim(), email: match[2].trim() };
425
+ }
426
+ return { email: input };
427
+ }
428
+ return input;
429
+ }
430
+ var Mail = class {
431
+ constructor(manager) {
432
+ this.manager = manager;
433
+ const defaultFrom = manager.getDefaultFrom();
434
+ if (defaultFrom) {
435
+ this.message.from = defaultFrom;
436
+ }
437
+ }
438
+ message = {
439
+ to: [],
440
+ cc: [],
441
+ bcc: [],
442
+ attachments: []
443
+ };
444
+ transportName;
445
+ /**
446
+ * Set the sender address.
447
+ */
448
+ from(address) {
449
+ this.message.from = parseAddress(address);
450
+ return this;
451
+ }
452
+ /**
453
+ * Add a recipient.
454
+ */
455
+ to(address) {
456
+ this.message.to.push(parseAddress(address));
457
+ return this;
458
+ }
459
+ /**
460
+ * Add multiple recipients.
461
+ */
462
+ toMany(addresses) {
463
+ for (const addr of addresses) {
464
+ this.to(addr);
465
+ }
466
+ return this;
467
+ }
468
+ /**
469
+ * Add a CC recipient.
470
+ */
471
+ cc(address) {
472
+ this.message.cc.push(parseAddress(address));
473
+ return this;
474
+ }
475
+ /**
476
+ * Add a BCC recipient.
477
+ */
478
+ bcc(address) {
479
+ this.message.bcc.push(parseAddress(address));
480
+ return this;
481
+ }
482
+ /**
483
+ * Set the reply-to address.
484
+ */
485
+ replyTo(address) {
486
+ this.message.replyTo = parseAddress(address);
487
+ return this;
488
+ }
489
+ /**
490
+ * Set the subject.
491
+ */
492
+ subject(subject) {
493
+ this.message.subject = subject;
494
+ return this;
495
+ }
496
+ /**
497
+ * Set the plain text body.
498
+ */
499
+ text(content) {
500
+ this.message.text = content;
501
+ return this;
502
+ }
503
+ /**
504
+ * Set the HTML body.
505
+ */
506
+ html(content) {
507
+ this.message.html = content;
508
+ return this;
509
+ }
510
+ /**
511
+ * Render a React component as HTML body.
512
+ * Requires @react-email/render to be installed.
513
+ *
514
+ * @param component - React component function
515
+ * @param props - Props to pass to the component
516
+ */
517
+ async template(component, props) {
518
+ try {
519
+ const reactEmailModule = "@react-email/render";
520
+ const reactEmail = await import(
521
+ /* @vite-ignore */
522
+ reactEmailModule
523
+ );
524
+ const html = await reactEmail.render(component(props));
525
+ this.message.html = html;
526
+ } catch (error) {
527
+ throw new Error(
528
+ "Failed to render email template. Make sure @react-email/render is installed."
529
+ );
530
+ }
531
+ return this;
532
+ }
533
+ /**
534
+ * Add an attachment.
535
+ */
536
+ attach(attachment) {
537
+ this.message.attachments.push(attachment);
538
+ return this;
539
+ }
540
+ /**
541
+ * Add a custom header.
542
+ * Rejects CR/LF characters to prevent SMTP header injection.
543
+ */
544
+ header(key, value) {
545
+ if (/[\r\n]/.test(key) || /[\r\n]/.test(value)) {
546
+ throw new Error("Mail: header names and values cannot contain newline characters.");
547
+ }
548
+ if (!this.message.headers) {
549
+ this.message.headers = {};
550
+ }
551
+ this.message.headers[key] = value;
552
+ return this;
553
+ }
554
+ /**
555
+ * Specify which transport to use.
556
+ */
557
+ via(transport) {
558
+ this.transportName = transport;
559
+ return this;
560
+ }
561
+ hasRunBuild = false;
562
+ runBuildOnce() {
563
+ if (this.hasRunBuild) {
564
+ return;
565
+ }
566
+ this.hasRunBuild = true;
567
+ this.build?.();
568
+ }
569
+ buildMessage() {
570
+ this.runBuildOnce();
571
+ if (!this.message.to || this.message.to.length === 0) {
572
+ throw new Error("Email must have at least one recipient");
573
+ }
574
+ if (!this.message.subject) {
575
+ throw new Error("Email must have a subject");
576
+ }
577
+ if (!this.message.text && !this.message.html) {
578
+ throw new Error("Email must have a text or html body");
579
+ }
580
+ return this.message;
581
+ }
582
+ /**
583
+ * Send the email immediately.
584
+ */
585
+ async send() {
586
+ const message = this.buildMessage();
587
+ const transport = this.manager.transport(this.transportName);
588
+ return transport.send(message);
589
+ }
590
+ /**
591
+ * Queue the email for async sending.
592
+ */
593
+ async queue(queueName = "default") {
594
+ const driver = getQueueDriver();
595
+ if (!driver) {
596
+ throw new Error("Queue driver not configured. Use send() instead or configure a queue driver.");
597
+ }
598
+ const message = this.buildMessage();
599
+ registerJob(SendMailJob);
600
+ return SendMailJob.dispatch(
601
+ {
602
+ message,
603
+ transport: this.transportName ?? this.manager.getDefaultTransportName()
604
+ },
605
+ { queue: queueName }
606
+ );
607
+ }
608
+ };
609
+ var globalMailManager = null;
610
+ function setMailManager(manager) {
611
+ globalMailManager = manager;
612
+ }
613
+ function getMailManager() {
614
+ return globalMailManager;
615
+ }
616
+ var SendMailJob = class extends Job {
617
+ static queue = "default";
618
+ static maxAttempts = 3;
619
+ static backoff = "exponential";
620
+ async handle(payload) {
621
+ const manager = globalMailManager;
622
+ if (!manager) {
623
+ throw new Error("Mail manager not configured for queue jobs. Call setMailManager() first.");
624
+ }
625
+ const transport = manager.transport(payload.transport);
626
+ const result = await transport.send(payload.message);
627
+ if (!result.success) {
628
+ throw new Error(result.error ?? "Failed to send email");
629
+ }
630
+ }
631
+ };
632
+ function mail(manager) {
633
+ return new Mail(manager);
634
+ }
635
+
636
+ export {
637
+ SmtpTransport,
638
+ ResendTransport,
639
+ MemoryTransport,
640
+ LogTransport,
641
+ MailManager,
642
+ createMailManager,
643
+ Mail,
644
+ setMailManager,
645
+ getMailManager,
646
+ mail
647
+ };