@burdenoff/be-sdk 2026.1101.4 → 2026.1102.1

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 (49) hide show
  1. package/README.md +39 -0
  2. package/dist/auth/index.d.ts +2 -2
  3. package/dist/auth/index.js +2 -2
  4. package/dist/{chunk-INAZ3PKF.js → chunk-23WAZL7I.js} +232 -135
  5. package/dist/chunk-23WAZL7I.js.map +1 -0
  6. package/dist/{chunk-QGBXVNRM.js → chunk-5SIL5AG2.js} +2 -2
  7. package/dist/chunk-5SIL5AG2.js.map +1 -0
  8. package/dist/{chunk-CKL6U4XE.js → chunk-64QUSPYG.js} +3 -3
  9. package/dist/{chunk-CKL6U4XE.js.map → chunk-64QUSPYG.js.map} +1 -1
  10. package/dist/{chunk-6XZ4ELHR.js → chunk-7TOWWNHR.js} +3 -3
  11. package/dist/{chunk-6XZ4ELHR.js.map → chunk-7TOWWNHR.js.map} +1 -1
  12. package/dist/{chunk-UD5PPGVU.js → chunk-DXTBH7IW.js} +3 -3
  13. package/dist/{chunk-UD5PPGVU.js.map → chunk-DXTBH7IW.js.map} +1 -1
  14. package/dist/{chunk-3UKS6TPM.js → chunk-XUS3NXR5.js} +8 -8
  15. package/dist/{chunk-3UKS6TPM.js.map → chunk-XUS3NXR5.js.map} +1 -1
  16. package/dist/{chunk-PQGMZH6K.js → chunk-Y4N7N2G4.js} +3 -3
  17. package/dist/{chunk-PQGMZH6K.js.map → chunk-Y4N7N2G4.js.map} +1 -1
  18. package/dist/{chunk-Q5MGYZHG.js → chunk-YZIWBUIN.js} +3 -3
  19. package/dist/{chunk-Q5MGYZHG.js.map → chunk-YZIWBUIN.js.map} +1 -1
  20. package/dist/database/index.js +2 -2
  21. package/dist/event-queue/index.d.ts +3 -3
  22. package/dist/graph/index.d.ts +3 -3
  23. package/dist/graph/index.js +2 -2
  24. package/dist/{graphql-BUbw43Zx.d.ts → graphql-CEblo7lw.d.ts} +1 -1
  25. package/dist/{index-CV3r9Taj.d.ts → index-7pTpoN3Q.d.ts} +1 -0
  26. package/dist/{index-BKOBmdq7.d.ts → index-BHe7zIVb.d.ts} +16 -8
  27. package/dist/{index-DXPFlxpZ.d.ts → index-BV8hveh_.d.ts} +3 -3
  28. package/dist/{index-Coua7_P7.d.ts → index-BioY0Ewz.d.ts} +1 -1
  29. package/dist/{index-Dtj9Eer3.d.ts → index-KZ4OzW6D.d.ts} +1 -1
  30. package/dist/{index-3ZE1m-ZJ.d.ts → index-XzbbMKe4.d.ts} +2 -2
  31. package/dist/{index-JTx7ZQHe.d.ts → index-zCx_euvK.d.ts} +2 -2
  32. package/dist/index.d.ts +13 -13
  33. package/dist/index.js +20 -17
  34. package/dist/index.js.map +1 -1
  35. package/dist/instrumentation/index.d.ts +3 -3
  36. package/dist/logger/index.d.ts +2 -2
  37. package/dist/notifications/index.d.ts +3 -3
  38. package/dist/notifications/index.js +2 -2
  39. package/dist/rbac/index.d.ts +2 -2
  40. package/dist/rbac/index.js +2 -2
  41. package/dist/resource-caps/index.d.ts +2 -2
  42. package/dist/telemetry/index.d.ts +4 -4
  43. package/dist/tracker/index.d.ts +4 -4
  44. package/dist/tracker/index.js +5 -5
  45. package/dist/usage/index.d.ts +2 -2
  46. package/dist/usage/index.js +2 -2
  47. package/package.json +3 -3
  48. package/dist/chunk-INAZ3PKF.js.map +0 -1
  49. package/dist/chunk-QGBXVNRM.js.map +0 -1
package/README.md CHANGED
@@ -91,6 +91,45 @@ await sdk.translation.upsertProductTranslations({
91
91
  });
92
92
  ```
93
93
 
94
+ ## Tenant notification delivery
95
+
96
+ Workspace services use the private `GLOBAL_PUBLIC_GATEWAY_URL` for tenant/global calls.
97
+ Supply the actual service identity through the normal runtime configuration. Per-request
98
+ workspace and organization context can be passed without mutating a shared SDK instance:
99
+
100
+ ```typescript
101
+ import {
102
+ TenantNotificationChannel,
103
+ TenantNotificationType,
104
+ } from '@burdenoff/be-sdk';
105
+
106
+ const notificationId = await sdk.tenantNotifications.send(
107
+ {
108
+ recipient: { userId: recipientId },
109
+ channel: TenantNotificationChannel.IN_APP,
110
+ type: TenantNotificationType.SYSTEM,
111
+ subject: 'Workflow completed',
112
+ body: 'Your workflow has completed.',
113
+ metadata: { eventId, resourceId },
114
+ expiresAt,
115
+ },
116
+ { workspaceId, organizationId },
117
+ );
118
+ ```
119
+
120
+ `send()` uses the owner's trigger API, preserving metadata and expiry, and returns a real
121
+ notification identifier only after acknowledgement. External delivery remains asynchronous.
122
+ A supplied `scheduledFor` uses the dedicated scheduling API. Batch notifications must share
123
+ a schedule; use individual sends for different schedules. The legacy batch `totalQueued`
124
+ field aliases the owner's `totalTriggered` acceptance counter, not a final delivery count.
125
+
126
+ Read/delete helpers return the owner's acknowledgement, including `false` for incomplete
127
+ operations. List helpers unwrap owner connections; template inventory is paginated completely
128
+ within a bounded limit. `getStats()` exposes actual owner counters, including `triggered`,
129
+ `scheduled` and `cancelled`; deprecated `queued` and `processing` fields are absent because the
130
+ owner does not publish those measurements. The `TenantNotificationType` delivery-intent enum
131
+ is distinct from the convenience API's severity enum.
132
+
94
133
  ## Features
95
134
 
96
135
  - **Unified Tracking**: Single function for RBAC + Activity + Usage + Quota checking
@@ -1,5 +1,5 @@
1
- import { B as BurdenoffGraphQLClient } from '../graphql-BUbw43Zx.js';
2
- import { a as SDKContext } from '../index-CV3r9Taj.js';
1
+ import { B as BurdenoffGraphQLClient } from '../graphql-CEblo7lw.js';
2
+ import { a as SDKContext } from '../index-7pTpoN3Q.js';
3
3
  import { G as GraphQLContext } from '../types-USOv09qy.js';
4
4
  import 'graphql-request';
5
5
  import '../layer-Cv9vSwBx.js';
@@ -1,6 +1,6 @@
1
- export { AuthCookieHelper, AuthModule } from '../chunk-Q5MGYZHG.js';
1
+ export { AuthCookieHelper, AuthModule } from '../chunk-YZIWBUIN.js';
2
2
  import '../chunk-LA5KPWZ2.js';
3
- import '../chunk-QGBXVNRM.js';
3
+ import '../chunk-5SIL5AG2.js';
4
4
  import '../chunk-5CAFHK2Z.js';
5
5
  import '../chunk-RU266375.js';
6
6
  import '../chunk-XE4OXN2W.js';
@@ -1,4 +1,4 @@
1
- import { ValidationError } from './chunk-QGBXVNRM.js';
1
+ import { APIError, ValidationError } from './chunk-5SIL5AG2.js';
2
2
  import { logger } from './chunk-RU266375.js';
3
3
  import { __export, __name } from './chunk-XE4OXN2W.js';
4
4
 
@@ -50,54 +50,89 @@ var TenantNotificationsModule = class {
50
50
  /**
51
51
  * Send a single notification
52
52
  */
53
- async send(input) {
53
+ async send(input, context) {
54
54
  this.validateSendInput(input);
55
- logger.info("[TenantNotifications] Sending notification", {
56
- channel: input.channel,
57
- type: input.type || "TRANSACTIONAL",
58
- priority: input.priority || "MEDIUM"
59
- });
60
- const mutation = `
61
- mutation SendNotification($input: SendNotificationInput!) {
62
- sendNotification(input: $input)
55
+ const notification = this.createNotificationInput(input);
56
+ const callContext = {
57
+ ...this.context,
58
+ ...context
59
+ };
60
+ if (input.scheduledFor) {
61
+ const response2 = await this.client.tenantQuery(`mutation ScheduleTenantNotification($input: ScheduleNotificationInput!) {
62
+ scheduleNotification(input: $input) { notificationId status }
63
+ }`, {
64
+ input: {
65
+ notification,
66
+ scheduledFor: input.scheduledFor.toISOString(),
67
+ timezone: input.recipient.timezone
68
+ }
69
+ }, callContext);
70
+ const result2 = response2.scheduleNotification;
71
+ if (!result2?.notificationId || result2.status !== "PENDING") {
72
+ throw new APIError("Notification scheduling was not acknowledged", {
73
+ operation: "scheduleNotification"
74
+ });
63
75
  }
64
- `;
65
- const variables = {
76
+ return result2.notificationId;
77
+ }
78
+ const response = await this.client.tenantQuery(`mutation TriggerTenantNotification($input: TriggerNotificationInput!) {
79
+ triggerNotification(input: $input) { id status channel }
80
+ }`, {
66
81
  input: {
67
- recipient: input.recipient,
68
- channel: input.channel,
69
- type: input.type || "TRANSACTIONAL",
70
- priority: input.priority || "MEDIUM",
71
- subject: input.subject,
72
- body: input.body,
73
- htmlBody: input.htmlBody,
74
- data: input.data,
75
- metadata: input.metadata,
76
- scheduledFor: input.scheduledFor?.toISOString(),
77
- expiresAt: input.expiresAt?.toISOString(),
78
- trackOpens: input.trackOpens,
79
- trackClicks: input.trackClicks
82
+ notification,
83
+ platform: input.channel,
84
+ includeInApp: false
80
85
  }
81
- };
82
- const response = await this.client.tenantQuery(mutation, variables, this.context);
83
- logger.info("[TenantNotifications] Notification sent", {
84
- notificationId: response.sendNotification
86
+ }, callContext);
87
+ const result = response.triggerNotification;
88
+ if (!result?.id || result.channel !== input.channel || ![
89
+ "TRIGGERED",
90
+ "SENT",
91
+ "DELIVERED"
92
+ ].includes(result.status)) {
93
+ throw new APIError("Notification trigger was not acknowledged", {
94
+ operation: "triggerNotification",
95
+ notificationId: result?.id
96
+ });
97
+ }
98
+ logger.info("[TenantNotifications] Notification accepted", {
99
+ notificationId: result.id,
100
+ channel: result.channel,
101
+ status: result.status
85
102
  });
86
- return response.sendNotification;
103
+ return result.id;
104
+ }
105
+ /** Owner input deliberately excludes scheduling, which has a separate API. */
106
+ createNotificationInput(input, priority) {
107
+ return {
108
+ recipient: input.recipient,
109
+ channel: input.channel,
110
+ type: input.type ?? "TRANSACTIONAL",
111
+ priority: input.priority ?? priority ?? "MEDIUM",
112
+ subject: input.subject,
113
+ body: input.body,
114
+ htmlBody: input.htmlBody,
115
+ data: input.data,
116
+ metadata: input.metadata,
117
+ expiresAt: input.expiresAt?.toISOString(),
118
+ trackOpens: input.trackOpens,
119
+ trackClicks: input.trackClicks
120
+ };
87
121
  }
88
122
  /**
89
123
  * Send notification using a template
90
124
  */
91
- async sendWithTemplate(input) {
125
+ async sendWithTemplate(input, context) {
92
126
  if (!input.templateSlug || input.templateSlug.trim().length === 0) {
93
127
  throw new ValidationError("Template slug is required");
94
128
  }
95
- if (!input.variables || Object.keys(input.variables).length === 0) {
96
- throw new ValidationError("Template variables are required");
129
+ if (!input.variables || typeof input.variables !== "object" || Array.isArray(input.variables)) {
130
+ throw new ValidationError("Template variables must be an object");
97
131
  }
98
132
  if (!input.recipient || !input.recipient.email && !input.recipient.userId) {
99
133
  throw new ValidationError("Recipient email or userId is required");
100
134
  }
135
+ this.validateDates(input);
101
136
  logger.info("[TenantNotifications] Sending notification with template", {
102
137
  templateSlug: input.templateSlug,
103
138
  priority: input.priority || "MEDIUM"
@@ -133,7 +168,10 @@ var TenantNotificationsModule = class {
133
168
  timezone: input.timezone
134
169
  }
135
170
  };
136
- const response = await this.client.tenantQuery(mutation, variables, this.context);
171
+ const response = await this.client.tenantQuery(mutation, variables, {
172
+ ...this.context,
173
+ ...context
174
+ });
137
175
  const result = response.triggerNotificationWithTemplate;
138
176
  const firstNotification = result.notifications[0];
139
177
  if (result.totalTriggered === 0 || !firstNotification) {
@@ -150,53 +188,38 @@ var TenantNotificationsModule = class {
150
188
  /**
151
189
  * Send batch notifications
152
190
  */
153
- async sendBatch(input) {
154
- if (!input.notifications || input.notifications.length === 0) {
155
- throw new ValidationError("At least one notification is required");
191
+ async sendBatch(input, context) {
192
+ if (!input.notifications?.length) throw new ValidationError("At least one notification is required");
193
+ for (const notification of input.notifications) this.validateSendInput(notification);
194
+ const schedules = new Set(input.notifications.map((notification) => notification.scheduledFor?.toISOString() ?? ""));
195
+ if (schedules.size > 1) {
196
+ throw new ValidationError("Batch notifications must share a schedule; use send() for distinct schedules");
156
197
  }
157
- logger.info("[TenantNotifications] Sending batch notifications", {
158
- count: input.notifications.length,
159
- batchSize: input.batchSize
160
- });
161
- const mutation = `
162
- mutation SendBatchNotifications($input: BatchNotificationInput!) {
163
- sendBatchNotifications(input: $input) {
164
- totalRequested
165
- totalQueued
166
- totalFailed
167
- batchId
168
- }
169
- }
170
- `;
171
- const variables = {
198
+ if (input.batchSize !== void 0 && (!Number.isInteger(input.batchSize) || input.batchSize <= 0)) {
199
+ throw new ValidationError("Batch size must be a positive integer");
200
+ }
201
+ if (input.delayBetweenBatches !== void 0 && (!Number.isInteger(input.delayBetweenBatches) || input.delayBetweenBatches < 0)) {
202
+ throw new ValidationError("Batch delay must be a nonnegative integer");
203
+ }
204
+ const response = await this.client.tenantQuery(`mutation TriggerTenantBatchNotifications($input: TriggerBatchNotificationsInput!) {
205
+ triggerBatchNotifications(input: $input) { totalRequested totalQueued: totalTriggered totalFailed batchId }
206
+ }`, {
172
207
  input: {
173
- notifications: input.notifications.map((n) => ({
174
- recipient: n.recipient,
175
- channel: n.channel,
176
- type: n.type || "TRANSACTIONAL",
177
- priority: n.priority || "MEDIUM",
178
- subject: n.subject,
179
- body: n.body,
180
- htmlBody: n.htmlBody,
181
- data: n.data,
182
- metadata: n.metadata,
183
- scheduledFor: n.scheduledFor?.toISOString(),
184
- expiresAt: n.expiresAt?.toISOString(),
185
- trackOpens: n.trackOpens,
186
- trackClicks: n.trackClicks
187
- })),
208
+ notifications: input.notifications.map((notification) => this.createNotificationInput(notification, input.priority)),
209
+ priority: input.priority,
210
+ scheduledFor: input.notifications[0]?.scheduledFor?.toISOString(),
188
211
  batchSize: input.batchSize,
189
- delayBetweenBatches: input.delayBetweenBatches,
190
- priority: input.priority
212
+ delayBetweenBatches: input.delayBetweenBatches
191
213
  }
192
- };
193
- const response = await this.client.tenantQuery(mutation, variables, this.context);
194
- logger.info("[TenantNotifications] Batch notifications sent", {
195
- batchId: response.sendBatchNotifications.batchId,
196
- queued: response.sendBatchNotifications.totalQueued,
197
- failed: response.sendBatchNotifications.totalFailed
214
+ }, {
215
+ ...this.context,
216
+ ...context
217
+ });
218
+ const result = response.triggerBatchNotifications;
219
+ if (!result?.batchId) throw new APIError("Notification batch was not acknowledged", {
220
+ operation: "triggerBatchNotifications"
198
221
  });
199
- return response.sendBatchNotifications;
222
+ return result;
200
223
  }
201
224
  /**
202
225
  * Get a notification by ID
@@ -241,6 +264,7 @@ var TenantNotificationsModule = class {
241
264
  const query = `
242
265
  query GetNotifications($filter: NotificationFilterInput, $limit: Int, $offset: Int) {
243
266
  notifications(filter: $filter, limit: $limit, offset: $offset) {
267
+ items {
244
268
  id
245
269
  userId
246
270
  channel
@@ -260,6 +284,7 @@ var TenantNotificationsModule = class {
260
284
  deliveredAt
261
285
  createdAt
262
286
  updatedAt
287
+ }
263
288
  }
264
289
  }
265
290
  `;
@@ -273,11 +298,11 @@ var TenantNotificationsModule = class {
273
298
  startDate: filter.startDate?.toISOString(),
274
299
  endDate: filter.endDate?.toISOString()
275
300
  } : void 0,
276
- limit: filter?.limit || 50,
277
- offset: filter?.offset || 0
301
+ limit: filter?.limit ?? 50,
302
+ offset: filter?.offset ?? 0
278
303
  };
279
304
  const response = await this.client.tenantQuery(query, variables, this.context);
280
- return response.notifications;
305
+ return response.notifications.items;
281
306
  }
282
307
  /**
283
308
  * Get notification template
@@ -314,31 +339,45 @@ var TenantNotificationsModule = class {
314
339
  * Get all notification templates
315
340
  */
316
341
  async getTemplates(filter) {
317
- const query = `
318
- query GetNotificationTemplates($filter: TemplateFilterInput) {
319
- notificationTemplates(filter: $filter) {
320
- id
321
- name
322
- slug
323
- description
324
- channel
325
- type
326
- locale
327
- subject
328
- bodyTemplate
329
- htmlTemplate
330
- variables
331
- enabled
332
- version
333
- createdAt
334
- updatedAt
342
+ const query = `query GetNotificationTemplates($filter: TemplateFilterInput, $limit: Int!, $offset: Int!) {
343
+ notificationTemplates(filter: $filter, limit: $limit, offset: $offset) {
344
+ items { id name slug description channel type locale subject bodyTemplate htmlTemplate variables enabled version createdAt updatedAt }
345
+ hasMore
346
+ }
347
+ }`;
348
+ const templates = [];
349
+ const seen = /* @__PURE__ */ new Set();
350
+ for (let page = 0; page < 100; page++) {
351
+ const response = await this.client.tenantQuery(query, {
352
+ filter,
353
+ limit: 100,
354
+ offset: templates.length
355
+ }, this.context);
356
+ const result = response.notificationTemplates;
357
+ if (!result || !Array.isArray(result.items) || typeof result.hasMore !== "boolean") {
358
+ throw new APIError("Notification template page was invalid", {
359
+ operation: "notificationTemplates"
360
+ });
361
+ }
362
+ for (const template of result.items) {
363
+ if (!template.id || seen.has(template.id)) {
364
+ throw new APIError("Notification template pagination did not progress", {
365
+ operation: "notificationTemplates"
366
+ });
335
367
  }
368
+ seen.add(template.id);
369
+ templates.push(template);
336
370
  }
337
- `;
338
- const response = await this.client.tenantQuery(query, {
339
- filter
340
- }, this.context);
341
- return response.notificationTemplates;
371
+ if (!result.hasMore) return templates;
372
+ if (!result.items.length) {
373
+ throw new APIError("Notification template pagination did not progress", {
374
+ operation: "notificationTemplates"
375
+ });
376
+ }
377
+ }
378
+ throw new APIError("Notification template pagination exceeded its bounded limit", {
379
+ operation: "notificationTemplates"
380
+ });
342
381
  }
343
382
  /**
344
383
  * Get notification statistics
@@ -349,8 +388,9 @@ var TenantNotificationsModule = class {
349
388
  notificationStats(filter: $filter) {
350
389
  total
351
390
  pending
352
- queued
353
- processing
391
+ triggered
392
+ scheduled
393
+ cancelled
354
394
  sent
355
395
  delivered
356
396
  failed
@@ -375,16 +415,17 @@ var TenantNotificationsModule = class {
375
415
  async markAsRead(notificationIds) {
376
416
  const mutation = `
377
417
  mutation MarkNotificationsAsRead($notificationIds: [ID!]!) {
378
- markNotificationsAsRead(notificationIds: $notificationIds)
418
+ markNotificationsAsRead(notificationIds: $notificationIds) { success count failedIds }
379
419
  }
380
420
  `;
381
- await this.client.tenantQuery(mutation, {
421
+ const result = await this.client.tenantQuery(mutation, {
382
422
  notificationIds
383
423
  }, this.context);
384
- logger.info("[TenantNotifications] Notifications marked as read", {
424
+ logger.info("[TenantNotifications] Read request completed", {
425
+ success: result.markNotificationsAsRead.success,
385
426
  count: notificationIds.length
386
427
  });
387
- return true;
428
+ return result.markNotificationsAsRead.success;
388
429
  }
389
430
  /**
390
431
  * Mark all notifications as read for the current user
@@ -392,12 +433,14 @@ var TenantNotificationsModule = class {
392
433
  async markAllAsRead() {
393
434
  const mutation = `
394
435
  mutation MarkAllMyNotificationsAsRead {
395
- markAllMyNotificationsAsRead
436
+ markAllMyNotificationsAsRead { success count failedIds }
396
437
  }
397
438
  `;
398
- await this.client.tenantQuery(mutation, {}, this.context);
399
- logger.info("[TenantNotifications] All notifications marked as read");
400
- return true;
439
+ const result = await this.client.tenantQuery(mutation, {}, this.context);
440
+ logger.info("[TenantNotifications] Read-all request completed", {
441
+ success: result.markAllMyNotificationsAsRead.success
442
+ });
443
+ return result.markAllMyNotificationsAsRead.success;
401
444
  }
402
445
  /**
403
446
  * Delete notifications
@@ -408,13 +451,14 @@ var TenantNotificationsModule = class {
408
451
  deleteNotifications(notificationIds: $notificationIds)
409
452
  }
410
453
  `;
411
- await this.client.tenantQuery(mutation, {
454
+ const result = await this.client.tenantQuery(mutation, {
412
455
  notificationIds
413
456
  }, this.context);
414
- logger.info("[TenantNotifications] Notifications deleted", {
457
+ logger.info("[TenantNotifications] Delete request completed", {
458
+ success: result.deleteNotifications,
415
459
  count: notificationIds.length
416
460
  });
417
- return true;
461
+ return result.deleteNotifications;
418
462
  }
419
463
  /**
420
464
  * Delete all read notifications for the current user
@@ -425,31 +469,79 @@ var TenantNotificationsModule = class {
425
469
  deleteMyReadNotifications
426
470
  }
427
471
  `;
428
- await this.client.tenantQuery(mutation, {}, this.context);
429
- logger.info("[TenantNotifications] All read notifications deleted");
430
- return true;
472
+ const result = await this.client.tenantQuery(mutation, {}, this.context);
473
+ logger.info("[TenantNotifications] Delete-read request completed", {
474
+ success: result.deleteMyReadNotifications
475
+ });
476
+ return result.deleteMyReadNotifications;
431
477
  }
432
478
  /**
433
479
  * Validate send notification input
434
480
  */
435
481
  validateSendInput(input) {
436
- if (!input.recipient || !input.recipient.email && !input.recipient.userId && !input.recipient.phoneNumber) {
437
- throw new ValidationError("Recipient email, userId, or phoneNumber is required");
482
+ if (!Object.values(NotificationChannel).includes(input.channel)) {
483
+ throw new ValidationError("A supported notification channel is required");
438
484
  }
439
- if (!input.channel) {
440
- throw new ValidationError("Notification channel is required");
441
- }
442
- if (!input.body || input.body.trim().length === 0) {
485
+ const recipientKeys = {
486
+ EMAIL: [
487
+ "email",
488
+ "userId"
489
+ ],
490
+ SMS: [
491
+ "phoneNumber",
492
+ "userId"
493
+ ],
494
+ PUSH: [
495
+ "pushToken",
496
+ "userId"
497
+ ],
498
+ IN_APP: [
499
+ "userId"
500
+ ],
501
+ WEBHOOK: [
502
+ "webhookUrl",
503
+ "userId"
504
+ ],
505
+ WHATSAPP: [
506
+ "whatsappNumber",
507
+ "phoneNumber",
508
+ "userId"
509
+ ],
510
+ TEAMS: [
511
+ "teamsUserId",
512
+ "userId"
513
+ ],
514
+ SLACK: [
515
+ "slackUserId",
516
+ "userId"
517
+ ],
518
+ TELEGRAM: [
519
+ "userId"
520
+ ],
521
+ DISCORD: [
522
+ "userId"
523
+ ]
524
+ };
525
+ if (!input.recipient || !recipientKeys[input.channel].some((key) => {
526
+ const value = input.recipient[key];
527
+ return typeof value === "string" && value.trim().length > 0;
528
+ })) throw new ValidationError("A recipient address or userId appropriate for the channel is required");
529
+ if (typeof input.body !== "string" || input.body.trim().length === 0) {
443
530
  throw new ValidationError("Notification body is required");
444
531
  }
445
- if (input.channel === "EMAIL" && !input.recipient.email) {
446
- throw new ValidationError("Recipient email is required for EMAIL channel");
447
- }
448
- if (input.channel === "SMS" && !input.recipient.phoneNumber) {
449
- throw new ValidationError("Recipient phone number is required for SMS channel");
532
+ this.validateDates(input);
533
+ }
534
+ validateDates(input) {
535
+ for (const value of [
536
+ input.scheduledFor,
537
+ input.expiresAt
538
+ ]) {
539
+ if (value != null && (!(value instanceof Date) || !Number.isFinite(value.getTime()))) {
540
+ throw new ValidationError("Notification dates must be valid Date values");
541
+ }
450
542
  }
451
- if (input.channel === "PUSH" && !input.recipient.pushToken && !input.recipient.userId) {
452
- throw new ValidationError("Recipient push token or userId is required for PUSH channel");
543
+ if (input.scheduledFor && input.expiresAt && input.expiresAt <= input.scheduledFor) {
544
+ throw new ValidationError("Notification expiry must follow its scheduled delivery");
453
545
  }
454
546
  }
455
547
  };
@@ -505,8 +597,10 @@ var NotificationsModule = class {
505
597
  if (!options.userIds || options.userIds.length === 0) {
506
598
  throw new ValidationError("At least one user ID is required");
507
599
  }
600
+ if (options.expiresAt && (!(options.expiresAt instanceof Date) || !Number.isFinite(options.expiresAt.getTime()))) {
601
+ throw new ValidationError("Notification expiry must be a valid Date");
602
+ }
508
603
  logger.info("[Notifications] Sending notification", {
509
- title: options.title,
510
604
  userCount: options.userIds.length,
511
605
  type: options.type || "info"
512
606
  });
@@ -532,6 +626,9 @@ var NotificationsModule = class {
532
626
  type: mapNotificationType(options.type),
533
627
  subject: options.title,
534
628
  body: options.message,
629
+ metadata: options.metadata,
630
+ data: options.data,
631
+ expiresAt: options.expiresAt?.toISOString(),
535
632
  ...options.redirectUrl ? {
536
633
  redirectUrl: options.redirectUrl
537
634
  } : {},
@@ -961,6 +1058,6 @@ var NotificationsModule = class {
961
1058
  }
962
1059
  };
963
1060
 
964
- export { NotificationChannel2 as NotificationChannel, NotificationPriority, NotificationType2 as NotificationType, NotificationsModule, TenantNotificationsModule, tenant_notifications_exports };
965
- //# sourceMappingURL=chunk-INAZ3PKF.js.map
966
- //# sourceMappingURL=chunk-INAZ3PKF.js.map
1061
+ export { NotificationChannel, NotificationChannel2, NotificationPriority, NotificationType, NotificationType2, NotificationsModule, TenantNotificationsModule, tenant_notifications_exports };
1062
+ //# sourceMappingURL=chunk-23WAZL7I.js.map
1063
+ //# sourceMappingURL=chunk-23WAZL7I.js.map