@guren/server 2.10.0 → 2.11.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 (91) hide show
  1. package/dist/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
  2. package/dist/Hash-CzrwKeDp.js +133 -0
  3. package/dist/HttpException-BkS3euNG.js +161 -0
  4. package/dist/Job-BVT813DO.js +441 -0
  5. package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
  6. package/dist/MessageSigner-Bd25ZJAV.js +93 -0
  7. package/dist/Random-DbIJ22KQ.js +191 -0
  8. package/dist/address-D0Iq-XIH.js +20 -0
  9. package/dist/auth/index.js +2 -122
  10. package/dist/auth-C7sVmYgc.js +1954 -0
  11. package/dist/authorization/index.js +2 -38
  12. package/dist/authorization-Dbcuc5ZK.js +610 -0
  13. package/dist/broadcasting/index.js +2 -26
  14. package/dist/broadcasting-Dw-FhyjN.js +1055 -0
  15. package/dist/cache/index.js +2 -17
  16. package/dist/cache/types.d.ts +4 -4
  17. package/dist/cache-BYnZf2FR.js +812 -0
  18. package/dist/client-Dd7vLcqp.js +27 -0
  19. package/dist/console/Output.d.ts +18 -18
  20. package/dist/encryption/index.js +5 -96
  21. package/dist/encryption-fOWQaKqX.js +250 -0
  22. package/dist/endpoint-D-20PiHY.js +46 -0
  23. package/dist/endpoint-D6GIqOpe.js +31 -0
  24. package/dist/errors-quJOkkCn.js +81 -0
  25. package/dist/events/index.js +2 -28
  26. package/dist/events-aIH_bWRx.js +410 -0
  27. package/dist/health/index.js +2 -24
  28. package/dist/health-VWdWXRwh.js +345 -0
  29. package/dist/hot-disposables-WsTX2ySN.js +281 -0
  30. package/dist/hot-reload/testing.d.ts +1 -1
  31. package/dist/http/resources/Resource.d.ts +23 -3
  32. package/dist/i18n/index.js +2 -30
  33. package/dist/i18n-mcWi7LCd.js +617 -0
  34. package/dist/index.js +7515 -7276
  35. package/dist/lambda/index.js +114 -71
  36. package/dist/logging/index.js +2 -24
  37. package/dist/logging-CPaRMuPP.js +518 -0
  38. package/dist/loopback-guard-D0Kc7-xc.js +224 -0
  39. package/dist/mail/index.js +2 -27
  40. package/dist/mail-DfEfSQEr.js +699 -0
  41. package/dist/mcp/index.js +2 -10
  42. package/dist/notifications/index.js +2 -33
  43. package/dist/notifications-BGqmUNZ8.js +759 -0
  44. package/dist/queue/index.js +3 -42
  45. package/dist/queue-CXrRK85G.js +948 -0
  46. package/dist/redis/index.js +672 -642
  47. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  48. package/dist/runtime/index.js +472 -616
  49. package/dist/scheduling/index.js +2 -29
  50. package/dist/scheduling-CPiEdtQd.js +839 -0
  51. package/dist/storage/index.js +2 -15
  52. package/dist/storage-tWHMv2H_.js +841 -0
  53. package/dist/support/expiry.js +69 -12
  54. package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
  55. package/dist/vite/index.js +118 -181
  56. package/dist/vite/plugin.d.ts +1 -1
  57. package/dist/vite-dev-server-BSJkduhZ.js +131 -0
  58. package/package.json +6 -5
  59. package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
  60. package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
  61. package/dist/chunk-2SC566CD.js +0 -376
  62. package/dist/chunk-2V3YID4H.js +0 -20
  63. package/dist/chunk-3KV5X2FL.js +0 -31
  64. package/dist/chunk-63SKW5PS.js +0 -457
  65. package/dist/chunk-6J6B5KOB.js +0 -425
  66. package/dist/chunk-A5JJ7XTH.js +0 -24
  67. package/dist/chunk-AZOYI43J.js +0 -18
  68. package/dist/chunk-B5E5VBDI.js +0 -115
  69. package/dist/chunk-DAQKYKLH.js +0 -182
  70. package/dist/chunk-DRNPVBAA.js +0 -1002
  71. package/dist/chunk-EI5GYMAT.js +0 -853
  72. package/dist/chunk-H3B23O6T.js +0 -271
  73. package/dist/chunk-HPET6XY5.js +0 -853
  74. package/dist/chunk-HR2KZ3WL.js +0 -616
  75. package/dist/chunk-IOTWFHZU.js +0 -558
  76. package/dist/chunk-K6CUBJX6.js +0 -642
  77. package/dist/chunk-KTNJG7R7.js +0 -911
  78. package/dist/chunk-LAJQCSSF.js +0 -355
  79. package/dist/chunk-LHR6OHI7.js +0 -189
  80. package/dist/chunk-N7PLD7MB.js +0 -729
  81. package/dist/chunk-Q2P6YLRR.js +0 -24
  82. package/dist/chunk-QQKTH5KX.js +0 -114
  83. package/dist/chunk-SFQP6O52.js +0 -126
  84. package/dist/chunk-SQR7277M.js +0 -911
  85. package/dist/chunk-T2FFUU6J.js +0 -484
  86. package/dist/chunk-TVV5YNEC.js +0 -1842
  87. package/dist/chunk-UY3AZSYL.js +0 -14
  88. package/dist/chunk-V4DNC2ER.js +0 -114
  89. package/dist/chunk-VSA3QY5Q.js +0 -274
  90. package/dist/chunk-YSOJKAAU.js +0 -427
  91. package/dist/errors-PUNHAFL2.js +0 -34
@@ -1,729 +0,0 @@
1
- import {
2
- parseMailAddress
3
- } from "./chunk-2V3YID4H.js";
4
- import {
5
- Job,
6
- registerJob
7
- } from "./chunk-6J6B5KOB.js";
8
-
9
- // src/notifications/Notification.ts
10
- var Notification = class {
11
- /**
12
- * Whether this notification should be queued.
13
- */
14
- static shouldQueue = false;
15
- /**
16
- * The queue name for this notification.
17
- */
18
- static queue;
19
- /**
20
- * Delay in milliseconds before sending.
21
- */
22
- static delay;
23
- /**
24
- * Unique notification ID.
25
- */
26
- id;
27
- /**
28
- * When the notification was created.
29
- */
30
- createdAt;
31
- constructor() {
32
- this.id = this.generateId();
33
- this.createdAt = /* @__PURE__ */ new Date();
34
- }
35
- /**
36
- * Get the notification type (default: class name).
37
- */
38
- get type() {
39
- return this.constructor.name;
40
- }
41
- /**
42
- * Check if the notification should be sent to the given notifiable.
43
- * Override to add custom logic.
44
- */
45
- shouldSend(_notifiable) {
46
- return true;
47
- }
48
- /**
49
- * Generate a unique notification ID.
50
- */
51
- generateId() {
52
- const timestamp = Date.now().toString(36);
53
- const random = Math.random().toString(36).substring(2, 10);
54
- return `notif_${timestamp}${random}`;
55
- }
56
- /**
57
- * Get static queue configuration.
58
- */
59
- static getQueueConfig() {
60
- return {
61
- shouldQueue: this.shouldQueue,
62
- queue: this.queue,
63
- delay: this.delay
64
- };
65
- }
66
- };
67
-
68
- // src/notifications/registry.ts
69
- var notificationRegistry = /* @__PURE__ */ new Map();
70
- function resolveRegistryKey(notificationClass) {
71
- try {
72
- const { type } = Object.create(notificationClass.prototype);
73
- if (typeof type === "string" && type.length > 0) {
74
- return type;
75
- }
76
- } catch {
77
- }
78
- return notificationClass.name;
79
- }
80
- function registerNotification(notificationClass, type) {
81
- notificationRegistry.set(
82
- type ?? resolveRegistryKey(notificationClass),
83
- notificationClass
84
- );
85
- }
86
- function getNotification(type) {
87
- return notificationRegistry.get(type);
88
- }
89
- function clearNotificationRegistry() {
90
- notificationRegistry.clear();
91
- }
92
-
93
- // src/notifications/notifiable-type.ts
94
- function resolveNotifiableType(notifiable) {
95
- return notifiable.notifiableType ?? notifiable.constructor?.name ?? "Unknown";
96
- }
97
-
98
- // src/notifications/NotificationManager.ts
99
- var NotificationManager = class {
100
- channels = /* @__PURE__ */ new Map();
101
- channelFactories = /* @__PURE__ */ new Map();
102
- resolvedChannels = /* @__PURE__ */ new Map();
103
- constructor(options = {}) {
104
- if (options.channels) {
105
- for (const [name, channel] of Object.entries(options.channels)) {
106
- this.registerChannel(name, channel);
107
- }
108
- }
109
- if (options.channelFactories) {
110
- for (const [name, factory] of Object.entries(options.channelFactories)) {
111
- this.registerChannelFactory(name, factory);
112
- }
113
- }
114
- }
115
- /**
116
- * Register a notification channel.
117
- */
118
- registerChannel(name, channel) {
119
- this.channels.set(name, channel);
120
- return this;
121
- }
122
- /**
123
- * Register a notification channel factory.
124
- */
125
- registerChannelFactory(name, factory) {
126
- this.channelFactories.set(name, factory);
127
- return this;
128
- }
129
- /**
130
- * Get a notification channel by name.
131
- */
132
- channel(name) {
133
- const resolved = this.resolvedChannels.get(name);
134
- if (resolved) {
135
- return resolved;
136
- }
137
- const channel = this.channels.get(name);
138
- if (channel) {
139
- return channel;
140
- }
141
- const factory = this.channelFactories.get(name);
142
- if (factory) {
143
- const created = factory({});
144
- this.resolvedChannels.set(name, created);
145
- return created;
146
- }
147
- throw new Error(`Notification channel "${name}" not found`);
148
- }
149
- /**
150
- * Check if a channel is registered.
151
- */
152
- hasChannel(name) {
153
- return this.channels.has(name) || this.channelFactories.has(name) || this.resolvedChannels.has(name);
154
- }
155
- /**
156
- * Get all registered channel names.
157
- */
158
- getChannelNames() {
159
- const names = /* @__PURE__ */ new Set([
160
- ...this.channels.keys(),
161
- ...this.channelFactories.keys(),
162
- ...this.resolvedChannels.keys()
163
- ]);
164
- return Array.from(names);
165
- }
166
- /**
167
- * Send a notification to a notifiable entity.
168
- * Respects queue configuration on the notification class.
169
- */
170
- async send(notifiable, notification) {
171
- const NotificationClass = notification.constructor;
172
- const queueConfig = NotificationClass.getQueueConfig?.() ?? {
173
- shouldQueue: false
174
- };
175
- if (queueConfig.shouldQueue) {
176
- await this.queue(notifiable, notification, queueConfig);
177
- } else {
178
- await this.sendNow(notifiable, notification);
179
- }
180
- }
181
- /**
182
- * Send a notification immediately (bypasses queue).
183
- */
184
- async sendNow(notifiable, notification) {
185
- const shouldSend = await notification.shouldSend(notifiable);
186
- if (!shouldSend) {
187
- return;
188
- }
189
- const viaChannels = notification.via(notifiable);
190
- await Promise.all(
191
- viaChannels.map(async (channelName) => {
192
- try {
193
- const channel = this.channel(channelName);
194
- await channel.send(notifiable, notification);
195
- } catch (error) {
196
- console.error(
197
- `Failed to send notification via ${channelName}:`,
198
- error
199
- );
200
- throw error;
201
- }
202
- })
203
- );
204
- }
205
- /**
206
- * Queue a notification for later delivery.
207
- */
208
- async queue(notifiable, notification, queueConfig) {
209
- const job = this.registerQueueJob();
210
- registerNotification(
211
- notification.constructor,
212
- notification.type
213
- );
214
- const payload = {
215
- notifiableData: this.serializeNotifiable(
216
- notifiable,
217
- notification.via(notifiable)
218
- ),
219
- notificationData: this.serializeNotification(notification),
220
- notificationType: notification.type
221
- };
222
- if (queueConfig.delay) {
223
- await job.dispatchAfter(queueConfig.delay, payload, {
224
- queue: queueConfig.queue
225
- });
226
- } else {
227
- await job.dispatch(payload, { queue: queueConfig.queue });
228
- }
229
- }
230
- /**
231
- * Send notification to multiple notifiables.
232
- */
233
- async sendToMany(notifiables, notification) {
234
- await Promise.all(
235
- notifiables.map((notifiable) => this.send(notifiable, notification))
236
- );
237
- }
238
- /**
239
- * Send notification immediately to multiple notifiables.
240
- */
241
- async sendNowToMany(notifiables, notification) {
242
- await Promise.all(
243
- notifiables.map((notifiable) => this.sendNow(notifiable, notification))
244
- );
245
- }
246
- /**
247
- * Serialize notifiable for queue storage.
248
- *
249
- * Routing is resolved here rather than in the worker: `routeNotificationFor`
250
- * is arbitrary user code — often a closure on an object literal — and cannot
251
- * be reconstructed from a payload.
252
- *
253
- * @param channels - Channels to resolve routes for
254
- */
255
- serializeNotifiable(notifiable, channels = []) {
256
- const routes = {};
257
- for (const channel of channels) {
258
- routes[channel] = notifiable.routeNotificationFor(channel);
259
- }
260
- return {
261
- type: resolveNotifiableType(notifiable),
262
- routes,
263
- data: { ...notifiable }
264
- };
265
- }
266
- /**
267
- * Serialize notification for queue storage.
268
- *
269
- * Only own enumerable properties are captured. Behaviour is restored by
270
- * rebuilding the registered class in the job handler, not by serializing it.
271
- */
272
- serializeNotification(notification) {
273
- return {
274
- id: notification.id,
275
- createdAt: notification.createdAt.toISOString(),
276
- data: { ...notification }
277
- };
278
- }
279
- /**
280
- * Bind this manager to the queued-notification job and register it.
281
- *
282
- * Call this during boot in a process that runs a worker but may never send
283
- * a notification itself: without it, the worker cannot resolve the job.
284
- */
285
- registerQueueJob() {
286
- SendNotificationJob.notificationManager = this;
287
- registerJob(SendNotificationJob);
288
- return SendNotificationJob;
289
- }
290
- };
291
- var SendNotificationJob = class extends Job {
292
- static jobName = "SendNotificationJob";
293
- static queue = "notifications";
294
- static maxAttempts = 3;
295
- // Will be set by NotificationManager
296
- static notificationManager = null;
297
- async handle(payload) {
298
- const manager = this.constructor.notificationManager;
299
- if (!manager) {
300
- throw new Error("NotificationManager not set on SendNotificationJob");
301
- }
302
- const notifiable = this.rebuildNotifiable(payload.notifiableData);
303
- const notification = this.rebuildNotification(
304
- payload.notificationType,
305
- payload.notificationData
306
- );
307
- await manager.sendNow(notifiable, notification);
308
- }
309
- /**
310
- * Rebuild the notifiable from its serialized data.
311
- */
312
- rebuildNotifiable(serialized) {
313
- const { data, routes } = serialized;
314
- return {
315
- ...data,
316
- notifiableType: serialized.type,
317
- routeNotificationFor(channel) {
318
- if (routes && channel in routes) {
319
- return routes[channel] ?? null;
320
- }
321
- const value = data[`${channel}Route`];
322
- if (typeof value === "string") return value;
323
- if (channel === "mail") {
324
- const email = data["email"];
325
- return typeof email === "string" ? email : null;
326
- }
327
- return null;
328
- }
329
- };
330
- }
331
- /**
332
- * Rebuild a real notification instance from its serialized data.
333
- *
334
- * The class is looked up in the notification registry and instantiated via
335
- * its prototype, so prototype methods (`via`, `toMail`, `toDatabase`,
336
- * `toSlack`, `shouldSend`) are restored without running the constructor.
337
- */
338
- rebuildNotification(type, serialized) {
339
- const NotificationClass = getNotification(type);
340
- if (!NotificationClass) {
341
- throw new Error(
342
- `Notification type "${type}" is not registered. Call registerNotification(${type}) before running the queue worker.`
343
- );
344
- }
345
- return Object.assign(
346
- Object.create(NotificationClass.prototype),
347
- serialized.data,
348
- { id: serialized.id, createdAt: new Date(serialized.createdAt) }
349
- );
350
- }
351
- };
352
- var globalNotificationManager = null;
353
- function setNotificationManager(manager) {
354
- globalNotificationManager = manager;
355
- }
356
- function getNotificationManager() {
357
- if (!globalNotificationManager) {
358
- throw new Error("NotificationManager not initialized. Call setNotificationManager() first.");
359
- }
360
- return globalNotificationManager;
361
- }
362
- function createNotificationManager(options) {
363
- return new NotificationManager(options);
364
- }
365
-
366
- // src/notifications/channels/MailChannel.ts
367
- function parseAddress(input) {
368
- if (!input) {
369
- return void 0;
370
- }
371
- return parseMailAddress(input);
372
- }
373
- function parseAddressList(input) {
374
- if (!input) {
375
- return void 0;
376
- }
377
- const items = Array.isArray(input) ? input : [input];
378
- const parsed = items.map((item) => parseAddress(item)).filter((item) => Boolean(item));
379
- return parsed.length > 0 ? parsed : void 0;
380
- }
381
- var MailChannel = class {
382
- constructor(mailManager, options = {}) {
383
- this.mailManager = mailManager;
384
- this.options = options;
385
- }
386
- mailManager;
387
- options;
388
- name = "mail";
389
- /**
390
- * Send the notification via mail.
391
- */
392
- async send(notifiable, notification) {
393
- const message = notification.toMail?.(notifiable);
394
- if (!message) {
395
- return;
396
- }
397
- const to = notifiable.routeNotificationFor("mail");
398
- if (!to) {
399
- return;
400
- }
401
- const transport = this.mailManager.transport(this.options.transport);
402
- const toAddresses = parseAddressList(to);
403
- if (!toAddresses || toAddresses.length === 0) {
404
- return;
405
- }
406
- await transport.send({
407
- to: toAddresses,
408
- from: parseAddress(message.from ?? this.options.from),
409
- replyTo: parseAddress(message.replyTo),
410
- cc: parseAddressList(message.cc),
411
- bcc: parseAddressList(message.bcc),
412
- subject: message.subject,
413
- html: message.html,
414
- text: message.text,
415
- attachments: message.attachments?.map((a) => ({
416
- filename: a.filename,
417
- content: a.content,
418
- path: a.path,
419
- contentType: a.contentType
420
- }))
421
- });
422
- }
423
- };
424
-
425
- // src/notifications/channels/DatabaseChannel.ts
426
- var DatabaseChannel = class {
427
- constructor(options = {}) {
428
- this.options = options;
429
- }
430
- options;
431
- name = "database";
432
- stored = [];
433
- /**
434
- * Send the notification to the database.
435
- */
436
- async send(notifiable, notification) {
437
- const data = notification.toDatabase?.(notifiable);
438
- if (!data) {
439
- return;
440
- }
441
- const record = {
442
- id: notification.id,
443
- type: notification.type,
444
- notifiableId: this.getNotifiableId(notifiable),
445
- notifiableType: this.getNotifiableType(notifiable),
446
- data,
447
- readAt: null,
448
- createdAt: notification.createdAt
449
- };
450
- if (this.options.store) {
451
- await this.options.store(notifiable, record);
452
- } else {
453
- this.stored.push(record);
454
- if (notifiable.notifications) {
455
- notifiable.notifications.push(record);
456
- }
457
- }
458
- }
459
- /**
460
- * Get the notifiable ID.
461
- */
462
- getNotifiableId(notifiable) {
463
- const withId = notifiable;
464
- if (withId.id !== void 0) {
465
- return withId.id;
466
- }
467
- return String(notifiable);
468
- }
469
- /**
470
- * Get the notifiable type.
471
- */
472
- getNotifiableType(notifiable) {
473
- return resolveNotifiableType(notifiable);
474
- }
475
- /**
476
- * Get all stored notifications (for testing).
477
- */
478
- getStored() {
479
- return [...this.stored];
480
- }
481
- /**
482
- * Get stored notifications for a notifiable.
483
- */
484
- getStoredFor(notifiable) {
485
- const id = this.getNotifiableId(notifiable);
486
- const type = this.getNotifiableType(notifiable);
487
- return this.stored.filter(
488
- (n) => n.notifiableId === id && n.notifiableType === type
489
- );
490
- }
491
- /**
492
- * Clear stored notifications (for testing).
493
- */
494
- clear() {
495
- this.stored = [];
496
- }
497
- };
498
-
499
- // src/notifications/channels/SlackChannel.ts
500
- var SlackChannel = class {
501
- constructor(webhookUrl, options = {}) {
502
- this.webhookUrl = webhookUrl;
503
- this.options = options;
504
- }
505
- webhookUrl;
506
- options;
507
- name = "slack";
508
- /**
509
- * Send the notification to Slack.
510
- */
511
- async send(notifiable, notification) {
512
- const message = notification.toSlack?.(notifiable);
513
- if (!message) {
514
- return;
515
- }
516
- const webhookUrl = notifiable.routeNotificationFor("slack") ?? this.webhookUrl;
517
- if (!webhookUrl) {
518
- return;
519
- }
520
- const payload = this.buildPayload(message);
521
- const response = await fetch(webhookUrl, {
522
- method: "POST",
523
- headers: {
524
- "Content-Type": "application/json"
525
- },
526
- body: JSON.stringify(payload)
527
- });
528
- if (!response.ok) {
529
- const text = await response.text();
530
- throw new Error(`Slack webhook failed: ${response.status} ${text}`);
531
- }
532
- }
533
- /**
534
- * Build the Slack webhook payload.
535
- */
536
- buildPayload(message) {
537
- const payload = {};
538
- if (message.text) {
539
- payload.text = message.text;
540
- }
541
- if (message.blocks && message.blocks.length > 0) {
542
- payload.blocks = message.blocks;
543
- }
544
- if (message.attachments && message.attachments.length > 0) {
545
- payload.attachments = message.attachments;
546
- }
547
- if (message.channel) {
548
- payload.channel = message.channel;
549
- }
550
- if (message.username ?? this.options.username) {
551
- payload.username = message.username ?? this.options.username;
552
- }
553
- if (message.icon_emoji ?? this.options.iconEmoji) {
554
- payload.icon_emoji = message.icon_emoji ?? this.options.iconEmoji;
555
- }
556
- if (message.icon_url ?? this.options.iconUrl) {
557
- payload.icon_url = message.icon_url ?? this.options.iconUrl;
558
- }
559
- return payload;
560
- }
561
- };
562
-
563
- // src/notifications/channels/MemoryChannel.ts
564
- var MemoryChannel = class {
565
- name = "memory";
566
- /**
567
- * All sent notifications.
568
- */
569
- sent = [];
570
- /**
571
- * Send (store) the notification.
572
- */
573
- async send(notifiable, notification) {
574
- this.sent.push({
575
- notifiable,
576
- notification,
577
- channels: notification.via(notifiable),
578
- timestamp: /* @__PURE__ */ new Date()
579
- });
580
- }
581
- /**
582
- * Assert that a notification was sent to a notifiable.
583
- */
584
- assertSentTo(notifiable, notificationType) {
585
- const found = this.sent.some((record) => {
586
- const matchesNotifiable = record.notifiable === notifiable;
587
- const matchesType = notificationType ? record.notification.type === notificationType : true;
588
- return matchesNotifiable && matchesType;
589
- });
590
- if (!found) {
591
- const typeMsg = notificationType ? ` of type "${notificationType}"` : "";
592
- throw new Error(`Expected notification${typeMsg} to be sent to notifiable`);
593
- }
594
- }
595
- /**
596
- * Assert that a notification was not sent to a notifiable.
597
- */
598
- assertNotSentTo(notifiable, notificationType) {
599
- const found = this.sent.some((record) => {
600
- const matchesNotifiable = record.notifiable === notifiable;
601
- const matchesType = notificationType ? record.notification.type === notificationType : true;
602
- return matchesNotifiable && matchesType;
603
- });
604
- if (found) {
605
- const typeMsg = notificationType ? ` of type "${notificationType}"` : "";
606
- throw new Error(
607
- `Expected notification${typeMsg} not to be sent to notifiable`
608
- );
609
- }
610
- }
611
- /**
612
- * Assert the total count of sent notifications.
613
- */
614
- assertCount(count) {
615
- if (this.sent.length !== count) {
616
- throw new Error(
617
- `Expected ${count} notifications to be sent, but ${this.sent.length} were sent`
618
- );
619
- }
620
- }
621
- /**
622
- * Assert that a notification type was sent.
623
- */
624
- assertSent(notificationType) {
625
- const found = this.sent.some(
626
- (record) => record.notification.type === notificationType
627
- );
628
- if (!found) {
629
- throw new Error(
630
- `Expected notification of type "${notificationType}" to be sent`
631
- );
632
- }
633
- }
634
- /**
635
- * Assert that a notification type was not sent.
636
- */
637
- assertNotSent(notificationType) {
638
- const found = this.sent.some(
639
- (record) => record.notification.type === notificationType
640
- );
641
- if (found) {
642
- throw new Error(
643
- `Expected notification of type "${notificationType}" not to be sent`
644
- );
645
- }
646
- }
647
- /**
648
- * Assert that no notifications were sent.
649
- */
650
- assertNothingSent() {
651
- if (this.sent.length > 0) {
652
- throw new Error(
653
- `Expected no notifications to be sent, but ${this.sent.length} were sent`
654
- );
655
- }
656
- }
657
- /**
658
- * Get notifications sent to a specific notifiable.
659
- */
660
- getSentTo(notifiable) {
661
- return this.sent.filter((record) => record.notifiable === notifiable);
662
- }
663
- /**
664
- * Get notifications of a specific type.
665
- */
666
- getSentOfType(notificationType) {
667
- return this.sent.filter(
668
- (record) => record.notification.type === notificationType
669
- );
670
- }
671
- /**
672
- * Check if a notification was sent to a notifiable.
673
- */
674
- hasSentTo(notifiable, notificationType) {
675
- return this.sent.some((record) => {
676
- const matchesNotifiable = record.notifiable === notifiable;
677
- const matchesType = notificationType ? record.notification.type === notificationType : true;
678
- return matchesNotifiable && matchesType;
679
- });
680
- }
681
- /**
682
- * Check if a notification type was sent.
683
- */
684
- hasSent(notificationType) {
685
- return this.sent.some(
686
- (record) => record.notification.type === notificationType
687
- );
688
- }
689
- /**
690
- * Get the count of sent notifications.
691
- */
692
- count() {
693
- return this.sent.length;
694
- }
695
- /**
696
- * Get the last sent notification.
697
- */
698
- last() {
699
- return this.sent[this.sent.length - 1];
700
- }
701
- /**
702
- * Get the first sent notification.
703
- */
704
- first() {
705
- return this.sent[0];
706
- }
707
- /**
708
- * Clear all sent notifications.
709
- */
710
- clear() {
711
- this.sent = [];
712
- }
713
- };
714
-
715
- export {
716
- Notification,
717
- registerNotification,
718
- getNotification,
719
- clearNotificationRegistry,
720
- resolveNotifiableType,
721
- NotificationManager,
722
- setNotificationManager,
723
- getNotificationManager,
724
- createNotificationManager,
725
- MailChannel,
726
- DatabaseChannel,
727
- SlackChannel,
728
- MemoryChannel
729
- };