@contractspec/module.notifications 3.7.16 → 3.7.17

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 (46) hide show
  1. package/dist/browser/channels/index.js +1 -314
  2. package/dist/browser/contracts/index.js +1 -356
  3. package/dist/browser/entities/index.js +1 -239
  4. package/dist/browser/i18n/catalogs/en.js +1 -68
  5. package/dist/browser/i18n/catalogs/es.js +1 -68
  6. package/dist/browser/i18n/catalogs/fr.js +1 -68
  7. package/dist/browser/i18n/catalogs/index.js +1 -169
  8. package/dist/browser/i18n/index.js +1 -229
  9. package/dist/browser/i18n/keys.js +1 -37
  10. package/dist/browser/i18n/locale.js +1 -29
  11. package/dist/browser/i18n/messages.js +1 -190
  12. package/dist/browser/index.js +7 -1126
  13. package/dist/browser/notifications.capability.js +1 -35
  14. package/dist/browser/notifications.feature.js +1 -50
  15. package/dist/browser/templates/index.js +7 -235
  16. package/dist/channels/index.js +1 -314
  17. package/dist/contracts/index.js +1 -356
  18. package/dist/entities/index.js +1 -239
  19. package/dist/i18n/catalogs/en.js +1 -68
  20. package/dist/i18n/catalogs/es.js +1 -68
  21. package/dist/i18n/catalogs/fr.js +1 -68
  22. package/dist/i18n/catalogs/index.js +1 -169
  23. package/dist/i18n/index.js +1 -229
  24. package/dist/i18n/keys.js +1 -37
  25. package/dist/i18n/locale.js +1 -29
  26. package/dist/i18n/messages.js +1 -190
  27. package/dist/index.js +7 -1126
  28. package/dist/node/channels/index.js +1 -314
  29. package/dist/node/contracts/index.js +1 -356
  30. package/dist/node/entities/index.js +1 -239
  31. package/dist/node/i18n/catalogs/en.js +1 -68
  32. package/dist/node/i18n/catalogs/es.js +1 -68
  33. package/dist/node/i18n/catalogs/fr.js +1 -68
  34. package/dist/node/i18n/catalogs/index.js +1 -169
  35. package/dist/node/i18n/index.js +1 -229
  36. package/dist/node/i18n/keys.js +1 -37
  37. package/dist/node/i18n/locale.js +1 -29
  38. package/dist/node/i18n/messages.js +1 -190
  39. package/dist/node/index.js +7 -1126
  40. package/dist/node/notifications.capability.js +1 -35
  41. package/dist/node/notifications.feature.js +1 -50
  42. package/dist/node/templates/index.js +7 -235
  43. package/dist/notifications.capability.js +1 -35
  44. package/dist/notifications.feature.js +1 -50
  45. package/dist/templates/index.js +7 -235
  46. package/package.json +6 -6
@@ -1,1144 +1,25 @@
1
- var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true,
11
- configurable: true,
12
- set: __exportSetter.bind(all, name)
13
- });
14
- };
15
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
-
17
- // src/i18n/catalogs/en.ts
18
- import { defineTranslation } from "@contractspec/lib.contracts-spec/translations";
19
- var enMessages;
20
- var init_en = __esm(() => {
21
- enMessages = defineTranslation({
22
- meta: {
23
- key: "notifications.messages",
24
- version: "1.0.0",
25
- domain: "notifications",
26
- description: "Template and channel strings for the notifications module",
27
- owners: ["platform"],
28
- stability: "experimental"
29
- },
30
- locale: "en",
31
- fallback: "en",
32
- messages: {
33
- "template.welcome.name": {
34
- value: "Welcome",
35
- description: "Welcome template display name"
36
- },
37
- "template.welcome.description": {
38
- value: "Sent when a user signs up.",
39
- description: "Welcome template description"
40
- },
41
- "template.orgInvite.name": {
42
- value: "Organization Invitation",
43
- description: "Org invite template display name"
44
- },
45
- "template.orgInvite.description": {
46
- value: "Sent when a user is invited to an organization.",
47
- description: "Org invite template description"
48
- },
49
- "template.mention.name": {
50
- value: "Mention",
51
- description: "Mention template display name"
52
- },
53
- "template.mention.description": {
54
- value: "Sent when a user is mentioned.",
55
- description: "Mention template description"
56
- },
57
- "channel.webhook.noUrl": {
58
- value: "No webhook URL configured",
59
- description: "Error when webhook channel has no URL"
60
- }
61
- }
62
- });
63
- });
64
-
65
- // src/i18n/catalogs/es.ts
66
- import { defineTranslation as defineTranslation2 } from "@contractspec/lib.contracts-spec/translations";
67
- var esMessages;
68
- var init_es = __esm(() => {
69
- esMessages = defineTranslation2({
70
- meta: {
71
- key: "notifications.messages",
72
- version: "1.0.0",
73
- domain: "notifications",
74
- description: "Template and channel strings (Spanish)",
75
- owners: ["platform"],
76
- stability: "experimental"
77
- },
78
- locale: "es",
79
- fallback: "en",
80
- messages: {
81
- "template.welcome.name": {
82
- value: "Bienvenida",
83
- description: "Welcome template display name"
84
- },
85
- "template.welcome.description": {
86
- value: "Enviado cuando un usuario se registra.",
87
- description: "Welcome template description"
88
- },
89
- "template.orgInvite.name": {
90
- value: "Invitación a la organización",
91
- description: "Org invite template display name"
92
- },
93
- "template.orgInvite.description": {
94
- value: "Enviado cuando un usuario es invitado a una organización.",
95
- description: "Org invite template description"
96
- },
97
- "template.mention.name": {
98
- value: "Mención",
99
- description: "Mention template display name"
100
- },
101
- "template.mention.description": {
102
- value: "Enviado cuando un usuario es mencionado.",
103
- description: "Mention template description"
104
- },
105
- "channel.webhook.noUrl": {
106
- value: "No se ha configurado una URL de webhook",
107
- description: "Error when webhook channel has no URL"
108
- }
109
- }
110
- });
111
- });
112
-
113
- // src/i18n/catalogs/fr.ts
114
- import { defineTranslation as defineTranslation3 } from "@contractspec/lib.contracts-spec/translations";
115
- var frMessages;
116
- var init_fr = __esm(() => {
117
- frMessages = defineTranslation3({
118
- meta: {
119
- key: "notifications.messages",
120
- version: "1.0.0",
121
- domain: "notifications",
122
- description: "Template and channel strings (French)",
123
- owners: ["platform"],
124
- stability: "experimental"
125
- },
126
- locale: "fr",
127
- fallback: "en",
128
- messages: {
129
- "template.welcome.name": {
130
- value: "Bienvenue",
131
- description: "Welcome template display name"
132
- },
133
- "template.welcome.description": {
134
- value: "Envoyé lorsqu'un utilisateur s'inscrit.",
135
- description: "Welcome template description"
136
- },
137
- "template.orgInvite.name": {
138
- value: "Invitation à l'organisation",
139
- description: "Org invite template display name"
140
- },
141
- "template.orgInvite.description": {
142
- value: "Envoyé lorsqu'un utilisateur est invité à une organisation.",
143
- description: "Org invite template description"
144
- },
145
- "template.mention.name": {
146
- value: "Mention",
147
- description: "Mention template display name"
148
- },
149
- "template.mention.description": {
150
- value: "Envoyé lorsqu'un utilisateur est mentionné.",
151
- description: "Mention template description"
152
- },
153
- "channel.webhook.noUrl": {
154
- value: "Aucune URL de webhook configurée",
155
- description: "Error when webhook channel has no URL"
156
- }
157
- }
158
- });
159
- });
160
-
161
- // src/i18n/messages.ts
162
- var exports_messages = {};
163
- __export(exports_messages, {
164
- resetI18nRegistry: () => resetI18nRegistry,
165
- getDefaultI18n: () => getDefaultI18n,
166
- createNotificationsI18n: () => createNotificationsI18n
167
- });
168
- import {
169
- createI18nFactory
170
- } from "@contractspec/lib.contracts-spec/translations";
171
- var factory, createNotificationsI18n, getDefaultI18n, resetI18nRegistry;
172
- var init_messages = __esm(() => {
173
- init_en();
174
- init_es();
175
- init_fr();
176
- factory = createI18nFactory({
177
- specKey: "notifications.messages",
178
- catalogs: [enMessages, frMessages, esMessages]
179
- });
180
- createNotificationsI18n = factory.create;
181
- getDefaultI18n = factory.getDefault;
182
- resetI18nRegistry = factory.resetRegistry;
183
- });
184
-
185
- // src/channels/index.ts
186
- class InAppChannel {
187
- channelId = "IN_APP";
188
- async send(_notification) {
189
- return {
190
- success: true,
191
- responseMessage: "Stored in database"
192
- };
193
- }
194
- async isAvailable() {
195
- return true;
196
- }
197
- }
198
-
199
- class ConsoleChannel {
200
- channelId = "CONSOLE";
201
- async send(notification) {
202
- console.log(`\uD83D\uDCEC [${notification.id}] ${notification.title}`);
203
- console.log(` ${notification.body}`);
204
- if (notification.actionUrl) {
205
- console.log(` Action: ${notification.actionUrl}`);
206
- }
207
- return {
208
- success: true,
209
- responseMessage: "Logged to console"
210
- };
211
- }
212
- async isAvailable() {
213
- return true;
214
- }
215
- }
216
-
217
- class EmailChannel {
218
- channelId = "EMAIL";
219
- async isAvailable() {
220
- return true;
221
- }
222
- }
223
-
224
- class PushChannel {
225
- channelId = "PUSH";
226
- async isAvailable() {
227
- return true;
228
- }
229
- }
230
-
231
- class WebhookChannel {
232
- channelId = "WEBHOOK";
233
- locale;
234
- constructor(options) {
235
- this.locale = options?.locale;
236
- }
237
- async send(notification) {
238
- if (!notification.webhook?.url) {
239
- const { createNotificationsI18n: createNotificationsI18n2 } = await Promise.resolve().then(() => (init_messages(), exports_messages));
240
- const i18n = createNotificationsI18n2(this.locale);
241
- return {
242
- success: false,
243
- responseMessage: i18n.t("channel.webhook.noUrl")
244
- };
245
- }
246
- try {
247
- const response = await fetch(notification.webhook.url, {
248
- method: "POST",
249
- headers: {
250
- "Content-Type": "application/json",
251
- ...notification.webhook.headers
252
- },
253
- body: JSON.stringify({
254
- id: notification.id,
255
- title: notification.title,
256
- body: notification.body,
257
- actionUrl: notification.actionUrl,
258
- metadata: notification.metadata
259
- })
260
- });
261
- return {
262
- success: response.ok,
263
- responseCode: String(response.status),
264
- responseMessage: response.statusText
265
- };
266
- } catch (error) {
267
- return {
268
- success: false,
269
- responseMessage: error instanceof Error ? error.message : "Unknown error"
270
- };
271
- }
272
- }
273
- async isAvailable() {
274
- return true;
275
- }
276
- }
277
-
278
- class ChannelRegistry {
279
- channels = new Map;
280
- register(channel) {
281
- this.channels.set(channel.channelId, channel);
282
- }
283
- get(channelId) {
284
- return this.channels.get(channelId);
285
- }
286
- getAll() {
287
- return Array.from(this.channels.values());
288
- }
289
- async getAvailable() {
290
- const available = [];
291
- for (const channel of this.channels.values()) {
292
- if (await channel.isAvailable()) {
293
- available.push(channel);
294
- }
295
- }
296
- return available;
297
- }
298
- }
299
- function createChannelRegistry() {
300
- const registry = new ChannelRegistry;
301
- registry.register(new InAppChannel);
302
- registry.register(new ConsoleChannel);
303
- registry.register(new WebhookChannel);
304
- return registry;
305
- }
306
-
307
- // src/contracts/index.ts
308
- import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
309
- import {
310
- defineEnum,
311
- defineSchemaModel,
312
- ScalarTypeEnum
313
- } from "@contractspec/lib.schema";
314
- var OWNERS = ["platform.notifications"];
315
- var NotificationStatusSchemaEnum = defineEnum("NotificationStatus", [
316
- "PENDING",
317
- "SENT",
318
- "DELIVERED",
319
- "READ",
320
- "FAILED",
321
- "CANCELLED"
322
- ]);
323
- var NotificationChannelSchemaEnum = defineEnum("NotificationChannel", [
324
- "EMAIL",
325
- "IN_APP",
326
- "PUSH",
327
- "WEBHOOK"
328
- ]);
329
- var NotificationFilterEnum = defineEnum("NotificationFilter", [
330
- "unread",
331
- "read",
332
- "all"
333
- ]);
334
- var NotificationModel = defineSchemaModel({
335
- name: "Notification",
336
- description: "A notification sent to a user",
337
- fields: {
338
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
339
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
340
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
341
- body: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
342
- type: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
343
- status: { type: NotificationStatusSchemaEnum, isOptional: false },
344
- channels: {
345
- type: NotificationChannelSchemaEnum,
346
- isArray: true,
347
- isOptional: false
348
- },
349
- actionUrl: { type: ScalarTypeEnum.URL(), isOptional: true },
350
- readAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
351
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
352
- }
353
- });
354
- var NotificationPreferenceModel = defineSchemaModel({
355
- name: "NotificationPreference",
356
- description: "User notification preferences",
357
- fields: {
358
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
359
- globalEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: false },
360
- channelPreferences: {
361
- type: ScalarTypeEnum.JSONObject(),
362
- isOptional: false
363
- },
364
- typePreferences: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
365
- quietHoursStart: {
366
- type: ScalarTypeEnum.String_unsecure(),
367
- isOptional: true
368
- },
369
- quietHoursEnd: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
370
- timezone: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
371
- digestEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: false },
372
- digestFrequency: {
373
- type: ScalarTypeEnum.String_unsecure(),
374
- isOptional: true
375
- }
376
- }
377
- });
378
- var SendNotificationInputModel = defineSchemaModel({
379
- name: "SendNotificationInput",
380
- description: "Input for sending a notification",
381
- fields: {
382
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
383
- templateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
384
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
385
- body: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
386
- type: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
387
- channels: {
388
- type: NotificationChannelSchemaEnum,
389
- isArray: true,
390
- isOptional: true
391
- },
392
- actionUrl: { type: ScalarTypeEnum.URL(), isOptional: true },
393
- variables: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
394
- metadata: { type: ScalarTypeEnum.JSONObject(), isOptional: true }
395
- }
396
- });
397
- var ListNotificationsInputModel = defineSchemaModel({
398
- name: "ListNotificationsInput",
399
- description: "Input for listing notifications",
400
- fields: {
401
- status: { type: NotificationFilterEnum, isOptional: true },
402
- type: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
403
- limit: {
404
- type: ScalarTypeEnum.Int_unsecure(),
405
- isOptional: true,
406
- defaultValue: 20
407
- },
408
- offset: {
409
- type: ScalarTypeEnum.Int_unsecure(),
410
- isOptional: true,
411
- defaultValue: 0
412
- }
413
- }
414
- });
415
- var ListNotificationsOutputModel = defineSchemaModel({
416
- name: "ListNotificationsOutput",
417
- description: "Output for listing notifications",
418
- fields: {
419
- notifications: {
420
- type: NotificationModel,
421
- isArray: true,
422
- isOptional: false
423
- },
424
- total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
425
- unreadCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
426
- }
427
- });
428
- var UpdatePreferencesInputModel = defineSchemaModel({
429
- name: "UpdateNotificationPreferencesInput",
430
- description: "Input for updating notification preferences",
431
- fields: {
432
- globalEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: true },
433
- channelPreferences: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
434
- typePreferences: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
435
- quietHoursStart: {
436
- type: ScalarTypeEnum.String_unsecure(),
437
- isOptional: true
438
- },
439
- quietHoursEnd: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
440
- timezone: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
441
- digestEnabled: { type: ScalarTypeEnum.Boolean(), isOptional: true },
442
- digestFrequency: {
443
- type: ScalarTypeEnum.String_unsecure(),
444
- isOptional: true
445
- }
446
- }
447
- });
448
- var SendNotificationContract = defineCommand({
449
- meta: {
450
- key: "notifications.send",
451
- version: "1.0.0",
452
- stability: "stable",
453
- owners: [...OWNERS],
454
- tags: ["notifications", "send"],
455
- description: "Send a notification to a user.",
456
- goal: "Deliver notifications across multiple channels.",
457
- context: "Called by services when events require user notification."
458
- },
459
- io: {
460
- input: SendNotificationInputModel,
461
- output: NotificationModel,
462
- errors: {
463
- USER_NOT_FOUND: {
464
- description: "Target user does not exist",
465
- http: 404,
466
- gqlCode: "USER_NOT_FOUND",
467
- when: "User ID is invalid"
468
- },
469
- TEMPLATE_NOT_FOUND: {
470
- description: "Notification template does not exist",
471
- http: 404,
472
- gqlCode: "TEMPLATE_NOT_FOUND",
473
- when: "Template ID is invalid"
474
- }
475
- }
476
- },
477
- policy: {
478
- auth: "user"
479
- },
480
- sideEffects: {
481
- emits: [
482
- {
483
- key: "notification.sent",
484
- version: "1.0.0",
485
- when: "Notification is sent",
486
- payload: NotificationModel
487
- }
488
- ]
489
- }
490
- });
491
- var ListNotificationsContract = defineQuery({
492
- meta: {
493
- key: "notifications.list",
494
- version: "1.0.0",
495
- stability: "stable",
496
- owners: [...OWNERS],
497
- tags: ["notifications", "list"],
498
- description: "List notifications for the current user.",
499
- goal: "Show user their notifications.",
500
- context: "Notification center UI."
501
- },
502
- io: {
503
- input: ListNotificationsInputModel,
504
- output: ListNotificationsOutputModel
505
- },
506
- policy: {
507
- auth: "user"
508
- }
509
- });
510
- var MarkNotificationReadContract = defineCommand({
511
- meta: {
512
- key: "notifications.markRead",
513
- version: "1.0.0",
514
- stability: "stable",
515
- owners: [...OWNERS],
516
- tags: ["notifications", "read"],
517
- description: "Mark a notification as read.",
518
- goal: "Track which notifications user has seen.",
519
- context: "User clicks on a notification."
520
- },
521
- io: {
522
- input: defineSchemaModel({
523
- name: "MarkNotificationReadInput",
524
- fields: {
525
- notificationId: {
526
- type: ScalarTypeEnum.String_unsecure(),
527
- isOptional: false
528
- }
529
- }
530
- }),
531
- output: NotificationModel
532
- },
533
- policy: {
534
- auth: "user"
535
- }
536
- });
537
- var MarkAllNotificationsReadContract = defineCommand({
538
- meta: {
539
- key: "notifications.markAllRead",
540
- version: "1.0.0",
541
- stability: "stable",
542
- owners: [...OWNERS],
543
- tags: ["notifications", "read"],
544
- description: "Mark all notifications as read.",
545
- goal: "Clear notification badge.",
546
- context: 'User clicks "mark all as read".'
547
- },
548
- io: {
549
- input: null,
550
- output: defineSchemaModel({
551
- name: "MarkAllNotificationsReadOutput",
552
- fields: {
553
- markedCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
554
- }
555
- })
556
- },
557
- policy: {
558
- auth: "user"
559
- }
560
- });
561
- var GetNotificationPreferencesContract = defineQuery({
562
- meta: {
563
- key: "notifications.preferences.get",
564
- version: "1.0.0",
565
- stability: "stable",
566
- owners: [...OWNERS],
567
- tags: ["notifications", "preferences", "get"],
568
- description: "Get notification preferences for current user.",
569
- goal: "Show user their notification settings.",
570
- context: "Notification settings page."
571
- },
572
- io: {
573
- input: null,
574
- output: NotificationPreferenceModel
575
- },
576
- policy: {
577
- auth: "user"
578
- }
579
- });
580
- var UpdateNotificationPreferencesContract = defineCommand({
581
- meta: {
582
- key: "notifications.preferences.update",
583
- version: "1.0.0",
584
- stability: "stable",
585
- owners: [...OWNERS],
586
- tags: ["notifications", "preferences", "update"],
587
- description: "Update notification preferences.",
588
- goal: "Allow user to control notification delivery.",
589
- context: "Notification settings page."
590
- },
591
- io: {
592
- input: UpdatePreferencesInputModel,
593
- output: NotificationPreferenceModel
594
- },
595
- policy: {
596
- auth: "user"
597
- }
598
- });
599
- var DeleteNotificationContract = defineCommand({
600
- meta: {
601
- key: "notifications.delete",
602
- version: "1.0.0",
603
- stability: "stable",
604
- owners: [...OWNERS],
605
- tags: ["notifications", "delete"],
606
- description: "Delete a notification.",
607
- goal: "Allow user to remove unwanted notifications.",
608
- context: "User dismisses a notification."
609
- },
610
- io: {
611
- input: defineSchemaModel({
612
- name: "DeleteNotificationInput",
613
- fields: {
614
- notificationId: {
615
- type: ScalarTypeEnum.String_unsecure(),
616
- isOptional: false
617
- }
618
- }
619
- }),
620
- output: defineSchemaModel({
621
- name: "DeleteNotificationOutput",
622
- fields: {
623
- success: { type: ScalarTypeEnum.Boolean(), isOptional: false }
624
- }
625
- })
626
- },
627
- policy: {
628
- auth: "user"
629
- }
630
- });
631
-
632
- // src/entities/index.ts
633
- import {
634
- defineEntity,
635
- defineEntityEnum,
636
- field,
637
- index
638
- } from "@contractspec/lib.schema";
639
- var NotificationStatusEnum = defineEntityEnum({
640
- name: "NotificationStatus",
641
- values: [
642
- "PENDING",
643
- "SENT",
644
- "DELIVERED",
645
- "READ",
646
- "FAILED",
647
- "CANCELLED"
648
- ],
649
- schema: "lssm_notifications",
650
- description: "Status of a notification."
651
- });
652
- var NotificationChannelEnum = defineEntityEnum({
653
- name: "NotificationChannel",
654
- values: ["EMAIL", "IN_APP", "PUSH", "WEBHOOK", "SMS"],
655
- schema: "lssm_notifications",
656
- description: "Delivery channel for notifications."
657
- });
658
- var NotificationEntity = defineEntity({
659
- name: "Notification",
660
- description: "An individual notification to be delivered to a user.",
661
- schema: "lssm_notifications",
662
- map: "notification",
663
- fields: {
664
- id: field.id({ description: "Unique notification ID" }),
665
- userId: field.foreignKey({ description: "Target user ID" }),
666
- orgId: field.string({
667
- isOptional: true,
668
- description: "Organization context"
669
- }),
670
- templateId: field.string({
671
- isOptional: true,
672
- description: "Template used"
673
- }),
674
- title: field.string({ description: "Notification title" }),
675
- body: field.string({ description: "Notification body" }),
676
- actionUrl: field.string({ isOptional: true, description: "Action URL" }),
677
- imageUrl: field.string({ isOptional: true, description: "Image URL" }),
678
- type: field.string({
679
- description: "Notification type (e.g., mention, update)"
680
- }),
681
- category: field.string({
682
- isOptional: true,
683
- description: "Notification category"
684
- }),
685
- priority: field.enum("NotificationPriority", { default: "NORMAL" }),
686
- channels: field.string({
687
- isArray: true,
688
- description: "Target delivery channels"
689
- }),
690
- status: field.enum("NotificationStatus", { default: "PENDING" }),
691
- sentAt: field.dateTime({ isOptional: true }),
692
- deliveredAt: field.dateTime({ isOptional: true }),
693
- readAt: field.dateTime({ isOptional: true }),
694
- metadata: field.json({
695
- isOptional: true,
696
- description: "Additional metadata"
697
- }),
698
- variables: field.json({
699
- isOptional: true,
700
- description: "Template variables used"
701
- }),
702
- triggeredBy: field.string({
703
- isOptional: true,
704
- description: "Event/action that triggered"
705
- }),
706
- sourceId: field.string({
707
- isOptional: true,
708
- description: "Source entity ID"
709
- }),
710
- sourceType: field.string({
711
- isOptional: true,
712
- description: "Source entity type"
713
- }),
714
- createdAt: field.createdAt(),
715
- updatedAt: field.updatedAt(),
716
- expiresAt: field.dateTime({
717
- isOptional: true,
718
- description: "Notification expiry"
719
- }),
720
- deliveryLogs: field.hasMany("DeliveryLog")
721
- },
722
- indexes: [
723
- index.on(["userId", "status", "createdAt"]),
724
- index.on(["userId", "readAt"]),
725
- index.on(["orgId", "createdAt"]),
726
- index.on(["type", "createdAt"])
727
- ],
728
- enums: [NotificationStatusEnum, NotificationChannelEnum]
729
- });
730
- var NotificationPriorityEnum = defineEntityEnum({
731
- name: "NotificationPriority",
732
- values: ["LOW", "NORMAL", "HIGH", "URGENT"],
733
- schema: "lssm_notifications",
734
- description: "Priority level of a notification."
735
- });
736
- var NotificationTemplateEntity = defineEntity({
737
- name: "NotificationTemplate",
738
- description: "Reusable notification template.",
739
- schema: "lssm_notifications",
740
- map: "notification_template",
741
- fields: {
742
- id: field.id(),
743
- templateId: field.string({
744
- isUnique: true,
745
- description: "Template identifier"
746
- }),
747
- name: field.string({ description: "Template display name" }),
748
- description: field.string({ isOptional: true }),
749
- emailSubject: field.string({ isOptional: true }),
750
- emailBody: field.string({ isOptional: true }),
751
- inAppTitle: field.string({ isOptional: true }),
752
- inAppBody: field.string({ isOptional: true }),
753
- pushTitle: field.string({ isOptional: true }),
754
- pushBody: field.string({ isOptional: true }),
755
- defaultChannels: field.string({ isArray: true }),
756
- category: field.string({ isOptional: true }),
757
- priority: field.enum("NotificationPriority", { default: "NORMAL" }),
758
- variablesSchema: field.json({
759
- isOptional: true,
760
- description: "JSON schema for variables"
761
- }),
762
- enabled: field.boolean({ default: true }),
763
- createdAt: field.createdAt(),
764
- updatedAt: field.updatedAt()
765
- },
766
- enums: [NotificationPriorityEnum]
767
- });
768
- var NotificationPreferenceEntity = defineEntity({
769
- name: "NotificationPreference",
770
- description: "User notification preferences by type and channel.",
771
- schema: "lssm_notifications",
772
- map: "notification_preference",
773
- fields: {
774
- id: field.id(),
775
- userId: field.foreignKey(),
776
- globalEnabled: field.boolean({ default: true }),
777
- quietHoursStart: field.string({
778
- isOptional: true,
779
- description: "Quiet hours start (HH:MM)"
780
- }),
781
- quietHoursEnd: field.string({
782
- isOptional: true,
783
- description: "Quiet hours end (HH:MM)"
784
- }),
785
- timezone: field.string({ default: '"UTC"' }),
786
- channelPreferences: field.json({
787
- description: "Channel-level preferences"
788
- }),
789
- typePreferences: field.json({ description: "Type-level preferences" }),
790
- digestEnabled: field.boolean({ default: false }),
791
- digestFrequency: field.string({
792
- isOptional: true,
793
- description: "daily, weekly, etc."
794
- }),
795
- digestTime: field.string({
796
- isOptional: true,
797
- description: "Digest send time (HH:MM)"
798
- }),
799
- createdAt: field.createdAt(),
800
- updatedAt: field.updatedAt()
801
- },
802
- indexes: [index.unique(["userId"])]
803
- });
804
- var DeliveryLogEntity = defineEntity({
805
- name: "DeliveryLog",
806
- description: "Log of notification delivery attempts.",
807
- schema: "lssm_notifications",
808
- map: "delivery_log",
809
- fields: {
810
- id: field.id(),
811
- notificationId: field.foreignKey(),
812
- channel: field.enum("NotificationChannel"),
813
- status: field.enum("NotificationStatus"),
814
- attemptedAt: field.dateTime(),
815
- deliveredAt: field.dateTime({ isOptional: true }),
816
- responseCode: field.string({ isOptional: true }),
817
- responseMessage: field.string({ isOptional: true }),
818
- externalId: field.string({
819
- isOptional: true,
820
- description: "Provider message ID"
821
- }),
822
- metadata: field.json({ isOptional: true }),
823
- notification: field.belongsTo("Notification", ["notificationId"], ["id"], {
824
- onDelete: "Cascade"
825
- })
826
- },
827
- indexes: [index.on(["notificationId", "channel"])]
828
- });
829
- var notificationEntities = [
830
- NotificationEntity,
831
- NotificationTemplateEntity,
832
- NotificationPreferenceEntity,
833
- DeliveryLogEntity
834
- ];
835
- var notificationsSchemaContribution = {
836
- moduleId: "@contractspec/module.notifications",
837
- entities: notificationEntities,
838
- enums: [
839
- NotificationStatusEnum,
840
- NotificationChannelEnum,
841
- NotificationPriorityEnum
842
- ]
843
- };
844
-
845
- // src/notifications.feature.ts
846
- import { defineFeature } from "@contractspec/lib.contracts-spec";
847
- var NotificationsFeature = defineFeature({
848
- meta: {
849
- key: "notifications",
850
- title: "Notifications",
851
- description: "Multi-channel notification delivery with preference management",
852
- domain: "platform",
853
- version: "1.0.0",
854
- owners: ["@platform.notifications"],
855
- tags: ["notifications", "email", "push", "in-app"],
856
- stability: "stable"
857
- },
858
- operations: [
859
- { key: "notifications.send", version: "1.0.0" },
860
- { key: "notifications.markRead", version: "1.0.0" },
861
- { key: "notifications.markAllRead", version: "1.0.0" },
862
- { key: "notifications.delete", version: "1.0.0" },
863
- { key: "notifications.list", version: "1.0.0" },
864
- { key: "notifications.preferences.update", version: "1.0.0" },
865
- { key: "notifications.preferences.get", version: "1.0.0" }
866
- ],
867
- events: [],
868
- presentations: [],
869
- opToPresentation: [],
870
- presentationsTargets: [],
871
- capabilities: {
872
- provides: [{ key: "notifications", version: "1.0.0" }],
873
- requires: [{ key: "identity", version: "1.0.0" }]
874
- }
875
- });
876
-
877
- // src/templates/index.ts
878
- function defineTemplate(def) {
879
- return def;
880
- }
881
- function renderTemplate(content, variables) {
882
- return content.replace(/\{\{(\w+)\}\}/g, (match, key) => {
883
- const value = variables[key];
884
- if (value === undefined || value === null) {
885
- return match;
886
- }
887
- return String(value);
888
- });
889
- }
890
- function renderNotificationTemplate(template, channel, variables, locale) {
891
- const channelContent = (locale && template.localeChannels?.[locale]?.[channel]) ?? template.channels[channel];
892
- if (!channelContent) {
893
- return null;
894
- }
895
- const title = channelContent.title ? renderTemplate(channelContent.title, variables) : template.name;
896
- const body = renderTemplate(channelContent.body, variables);
897
- const actionUrl = channelContent.actionUrl ? renderTemplate(channelContent.actionUrl, variables) : undefined;
898
- const result = {
899
- title,
900
- body,
901
- actionUrl
902
- };
903
- if (channel === "email" && channelContent.subject) {
904
- result.email = {
905
- subject: renderTemplate(channelContent.subject, variables),
906
- html: body,
907
- text: stripHtml(body)
908
- };
909
- }
910
- return result;
911
- }
912
- function stripHtml(html) {
913
- return html.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim();
914
- }
915
-
916
- class TemplateRegistry {
917
- templates = new Map;
918
- register(template) {
919
- this.templates.set(template.id, template);
920
- }
921
- get(templateId) {
922
- return this.templates.get(templateId);
923
- }
924
- getAll() {
925
- return Array.from(this.templates.values());
926
- }
927
- getByCategory(category) {
928
- return this.getAll().filter((t) => t.category === category);
929
- }
930
- }
931
- function createTemplateRegistry() {
932
- return new TemplateRegistry;
933
- }
934
- var WelcomeTemplate = defineTemplate({
935
- id: "welcome",
936
- name: "Welcome",
937
- description: "Sent when a user signs up.",
938
- category: "onboarding",
939
- variables: [
940
- { name: "name", type: "string", required: true },
941
- { name: "appName", type: "string", default: "ContractSpec" },
942
- { name: "actionUrl", type: "url" }
943
- ],
944
- defaultChannels: ["EMAIL", "IN_APP"],
945
- channels: {
946
- email: {
947
- subject: "Welcome to {{appName}}, {{name}}!",
948
- body: `
1
+ var m=Object.defineProperty;var r=(q)=>q;function d(q,D){this[q]=r.bind(null,D)}var f=(q,D)=>{for(var J in D)m(q,J,{get:D[J],enumerable:!0,configurable:!0,set:d.bind(D,J)})};var _=(q,D)=>()=>(q&&(D=q(q=0)),D);import{defineTranslation as o}from"@contractspec/lib.contracts-spec/translations";var L;var k=_(()=>{L=o({meta:{key:"notifications.messages",version:"1.0.0",domain:"notifications",description:"Template and channel strings for the notifications module",owners:["platform"],stability:"experimental"},locale:"en",fallback:"en",messages:{"template.welcome.name":{value:"Welcome",description:"Welcome template display name"},"template.welcome.description":{value:"Sent when a user signs up.",description:"Welcome template description"},"template.orgInvite.name":{value:"Organization Invitation",description:"Org invite template display name"},"template.orgInvite.description":{value:"Sent when a user is invited to an organization.",description:"Org invite template description"},"template.mention.name":{value:"Mention",description:"Mention template display name"},"template.mention.description":{value:"Sent when a user is mentioned.",description:"Mention template description"},"channel.webhook.noUrl":{value:"No webhook URL configured",description:"Error when webhook channel has no URL"}}})});import{defineTranslation as c}from"@contractspec/lib.contracts-spec/translations";var P;var O=_(()=>{P=c({meta:{key:"notifications.messages",version:"1.0.0",domain:"notifications",description:"Template and channel strings (Spanish)",owners:["platform"],stability:"experimental"},locale:"es",fallback:"en",messages:{"template.welcome.name":{value:"Bienvenida",description:"Welcome template display name"},"template.welcome.description":{value:"Enviado cuando un usuario se registra.",description:"Welcome template description"},"template.orgInvite.name":{value:"Invitación a la organización",description:"Org invite template display name"},"template.orgInvite.description":{value:"Enviado cuando un usuario es invitado a una organización.",description:"Org invite template description"},"template.mention.name":{value:"Mención",description:"Mention template display name"},"template.mention.description":{value:"Enviado cuando un usuario es mencionado.",description:"Mention template description"},"channel.webhook.noUrl":{value:"No se ha configurado una URL de webhook",description:"Error when webhook channel has no URL"}}})});import{defineTranslation as l}from"@contractspec/lib.contracts-spec/translations";var W;var I=_(()=>{W=l({meta:{key:"notifications.messages",version:"1.0.0",domain:"notifications",description:"Template and channel strings (French)",owners:["platform"],stability:"experimental"},locale:"fr",fallback:"en",messages:{"template.welcome.name":{value:"Bienvenue",description:"Welcome template display name"},"template.welcome.description":{value:"Envoyé lorsqu'un utilisateur s'inscrit.",description:"Welcome template description"},"template.orgInvite.name":{value:"Invitation à l'organisation",description:"Org invite template display name"},"template.orgInvite.description":{value:"Envoyé lorsqu'un utilisateur est invité à une organisation.",description:"Org invite template description"},"template.mention.name":{value:"Mention",description:"Mention template display name"},"template.mention.description":{value:"Envoyé lorsqu'un utilisateur est mentionné.",description:"Mention template description"},"channel.webhook.noUrl":{value:"Aucune URL de webhook configurée",description:"Error when webhook channel has no URL"}}})});var R={};f(R,{resetI18nRegistry:()=>n,getDefaultI18n:()=>i,createNotificationsI18n:()=>a});import{createI18nFactory as t}from"@contractspec/lib.contracts-spec/translations";var H,a,i,n;var v=_(()=>{k();O();I();H=t({specKey:"notifications.messages",catalogs:[L,W,P]}),a=H.create,i=H.getDefault,n=H.resetRegistry});class g{channelId="IN_APP";async send(q){return{success:!0,responseMessage:"Stored in database"}}async isAvailable(){return!0}}class M{channelId="CONSOLE";async send(q){if(console.log(`\uD83D\uDCEC [${q.id}] ${q.title}`),console.log(` ${q.body}`),q.actionUrl)console.log(` Action: ${q.actionUrl}`);return{success:!0,responseMessage:"Logged to console"}}async isAvailable(){return!0}}class e{channelId="EMAIL";async isAvailable(){return!0}}class jj{channelId="PUSH";async isAvailable(){return!0}}class b{channelId="WEBHOOK";locale;constructor(q){this.locale=q?.locale}async send(q){if(!q.webhook?.url){let{createNotificationsI18n:D}=await Promise.resolve().then(() => (v(),R));return{success:!1,responseMessage:D(this.locale).t("channel.webhook.noUrl")}}try{let D=await fetch(q.webhook.url,{method:"POST",headers:{"Content-Type":"application/json",...q.webhook.headers},body:JSON.stringify({id:q.id,title:q.title,body:q.body,actionUrl:q.actionUrl,metadata:q.metadata})});return{success:D.ok,responseCode:String(D.status),responseMessage:D.statusText}}catch(D){return{success:!1,responseMessage:D instanceof Error?D.message:"Unknown error"}}}async isAvailable(){return!0}}class C{channels=new Map;register(q){this.channels.set(q.channelId,q)}get(q){return this.channels.get(q)}getAll(){return Array.from(this.channels.values())}async getAvailable(){let q=[];for(let D of this.channels.values())if(await D.isAvailable())q.push(D);return q}}function Wj(){let q=new C;return q.register(new g),q.register(new M),q.register(new b),q}import{defineCommand as Y,defineQuery as N}from"@contractspec/lib.contracts-spec";import{defineEnum as A,defineSchemaModel as K,ScalarTypeEnum as B}from"@contractspec/lib.schema";var V=["platform.notifications"],qj=A("NotificationStatus",["PENDING","SENT","DELIVERED","READ","FAILED","CANCELLED"]),T=A("NotificationChannel",["EMAIL","IN_APP","PUSH","WEBHOOK"]),Bj=A("NotificationFilter",["unread","read","all"]),$=K({name:"Notification",description:"A notification sent to a user",fields:{id:{type:B.String_unsecure(),isOptional:!1},userId:{type:B.String_unsecure(),isOptional:!1},title:{type:B.String_unsecure(),isOptional:!1},body:{type:B.String_unsecure(),isOptional:!1},type:{type:B.String_unsecure(),isOptional:!1},status:{type:qj,isOptional:!1},channels:{type:T,isArray:!0,isOptional:!1},actionUrl:{type:B.URL(),isOptional:!0},readAt:{type:B.DateTime(),isOptional:!0},createdAt:{type:B.DateTime(),isOptional:!1}}}),h=K({name:"NotificationPreference",description:"User notification preferences",fields:{userId:{type:B.String_unsecure(),isOptional:!1},globalEnabled:{type:B.Boolean(),isOptional:!1},channelPreferences:{type:B.JSONObject(),isOptional:!1},typePreferences:{type:B.JSONObject(),isOptional:!1},quietHoursStart:{type:B.String_unsecure(),isOptional:!0},quietHoursEnd:{type:B.String_unsecure(),isOptional:!0},timezone:{type:B.String_unsecure(),isOptional:!1},digestEnabled:{type:B.Boolean(),isOptional:!1},digestFrequency:{type:B.String_unsecure(),isOptional:!0}}}),Dj=K({name:"SendNotificationInput",description:"Input for sending a notification",fields:{userId:{type:B.String_unsecure(),isOptional:!1},templateId:{type:B.String_unsecure(),isOptional:!0},title:{type:B.String_unsecure(),isOptional:!0},body:{type:B.String_unsecure(),isOptional:!0},type:{type:B.String_unsecure(),isOptional:!1},channels:{type:T,isArray:!0,isOptional:!0},actionUrl:{type:B.URL(),isOptional:!0},variables:{type:B.JSONObject(),isOptional:!0},metadata:{type:B.JSONObject(),isOptional:!0}}}),Gj=K({name:"ListNotificationsInput",description:"Input for listing notifications",fields:{status:{type:Bj,isOptional:!0},type:{type:B.String_unsecure(),isOptional:!0},limit:{type:B.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:B.Int_unsecure(),isOptional:!0,defaultValue:0}}}),Jj=K({name:"ListNotificationsOutput",description:"Output for listing notifications",fields:{notifications:{type:$,isArray:!0,isOptional:!1},total:{type:B.Int_unsecure(),isOptional:!1},unreadCount:{type:B.Int_unsecure(),isOptional:!1}}}),Kj=K({name:"UpdateNotificationPreferencesInput",description:"Input for updating notification preferences",fields:{globalEnabled:{type:B.Boolean(),isOptional:!0},channelPreferences:{type:B.JSONObject(),isOptional:!0},typePreferences:{type:B.JSONObject(),isOptional:!0},quietHoursStart:{type:B.String_unsecure(),isOptional:!0},quietHoursEnd:{type:B.String_unsecure(),isOptional:!0},timezone:{type:B.String_unsecure(),isOptional:!0},digestEnabled:{type:B.Boolean(),isOptional:!0},digestFrequency:{type:B.String_unsecure(),isOptional:!0}}}),gj=Y({meta:{key:"notifications.send",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","send"],description:"Send a notification to a user.",goal:"Deliver notifications across multiple channels.",context:"Called by services when events require user notification."},io:{input:Dj,output:$,errors:{USER_NOT_FOUND:{description:"Target user does not exist",http:404,gqlCode:"USER_NOT_FOUND",when:"User ID is invalid"},TEMPLATE_NOT_FOUND:{description:"Notification template does not exist",http:404,gqlCode:"TEMPLATE_NOT_FOUND",when:"Template ID is invalid"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"notification.sent",version:"1.0.0",when:"Notification is sent",payload:$}]}}),Mj=N({meta:{key:"notifications.list",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","list"],description:"List notifications for the current user.",goal:"Show user their notifications.",context:"Notification center UI."},io:{input:Gj,output:Jj},policy:{auth:"user"}}),bj=Y({meta:{key:"notifications.markRead",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","read"],description:"Mark a notification as read.",goal:"Track which notifications user has seen.",context:"User clicks on a notification."},io:{input:K({name:"MarkNotificationReadInput",fields:{notificationId:{type:B.String_unsecure(),isOptional:!1}}}),output:$},policy:{auth:"user"}}),Cj=Y({meta:{key:"notifications.markAllRead",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","read"],description:"Mark all notifications as read.",goal:"Clear notification badge.",context:'User clicks "mark all as read".'},io:{input:null,output:K({name:"MarkAllNotificationsReadOutput",fields:{markedCount:{type:B.Int_unsecure(),isOptional:!1}}})},policy:{auth:"user"}}),Nj=N({meta:{key:"notifications.preferences.get",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","preferences","get"],description:"Get notification preferences for current user.",goal:"Show user their notification settings.",context:"Notification settings page."},io:{input:null,output:h},policy:{auth:"user"}}),Tj=Y({meta:{key:"notifications.preferences.update",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","preferences","update"],description:"Update notification preferences.",goal:"Allow user to control notification delivery.",context:"Notification settings page."},io:{input:Kj,output:h},policy:{auth:"user"}}),hj=Y({meta:{key:"notifications.delete",version:"1.0.0",stability:"stable",owners:[...V],tags:["notifications","delete"],description:"Delete a notification.",goal:"Allow user to remove unwanted notifications.",context:"User dismisses a notification."},io:{input:K({name:"DeleteNotificationInput",fields:{notificationId:{type:B.String_unsecure(),isOptional:!1}}}),output:K({name:"DeleteNotificationOutput",fields:{success:{type:B.Boolean(),isOptional:!1}}})},policy:{auth:"user"}});import{defineEntity as w,defineEntityEnum as Q,field as j,index as X}from"@contractspec/lib.schema";var S=Q({name:"NotificationStatus",values:["PENDING","SENT","DELIVERED","READ","FAILED","CANCELLED"],schema:"lssm_notifications",description:"Status of a notification."}),y=Q({name:"NotificationChannel",values:["EMAIL","IN_APP","PUSH","WEBHOOK","SMS"],schema:"lssm_notifications",description:"Delivery channel for notifications."}),Vj=w({name:"Notification",description:"An individual notification to be delivered to a user.",schema:"lssm_notifications",map:"notification",fields:{id:j.id({description:"Unique notification ID"}),userId:j.foreignKey({description:"Target user ID"}),orgId:j.string({isOptional:!0,description:"Organization context"}),templateId:j.string({isOptional:!0,description:"Template used"}),title:j.string({description:"Notification title"}),body:j.string({description:"Notification body"}),actionUrl:j.string({isOptional:!0,description:"Action URL"}),imageUrl:j.string({isOptional:!0,description:"Image URL"}),type:j.string({description:"Notification type (e.g., mention, update)"}),category:j.string({isOptional:!0,description:"Notification category"}),priority:j.enum("NotificationPriority",{default:"NORMAL"}),channels:j.string({isArray:!0,description:"Target delivery channels"}),status:j.enum("NotificationStatus",{default:"PENDING"}),sentAt:j.dateTime({isOptional:!0}),deliveredAt:j.dateTime({isOptional:!0}),readAt:j.dateTime({isOptional:!0}),metadata:j.json({isOptional:!0,description:"Additional metadata"}),variables:j.json({isOptional:!0,description:"Template variables used"}),triggeredBy:j.string({isOptional:!0,description:"Event/action that triggered"}),sourceId:j.string({isOptional:!0,description:"Source entity ID"}),sourceType:j.string({isOptional:!0,description:"Source entity type"}),createdAt:j.createdAt(),updatedAt:j.updatedAt(),expiresAt:j.dateTime({isOptional:!0,description:"Notification expiry"}),deliveryLogs:j.hasMany("DeliveryLog")},indexes:[X.on(["userId","status","createdAt"]),X.on(["userId","readAt"]),X.on(["orgId","createdAt"]),X.on(["type","createdAt"])],enums:[S,y]}),E=Q({name:"NotificationPriority",values:["LOW","NORMAL","HIGH","URGENT"],schema:"lssm_notifications",description:"Priority level of a notification."}),Xj=w({name:"NotificationTemplate",description:"Reusable notification template.",schema:"lssm_notifications",map:"notification_template",fields:{id:j.id(),templateId:j.string({isUnique:!0,description:"Template identifier"}),name:j.string({description:"Template display name"}),description:j.string({isOptional:!0}),emailSubject:j.string({isOptional:!0}),emailBody:j.string({isOptional:!0}),inAppTitle:j.string({isOptional:!0}),inAppBody:j.string({isOptional:!0}),pushTitle:j.string({isOptional:!0}),pushBody:j.string({isOptional:!0}),defaultChannels:j.string({isArray:!0}),category:j.string({isOptional:!0}),priority:j.enum("NotificationPriority",{default:"NORMAL"}),variablesSchema:j.json({isOptional:!0,description:"JSON schema for variables"}),enabled:j.boolean({default:!0}),createdAt:j.createdAt(),updatedAt:j.updatedAt()},enums:[E]}),Yj=w({name:"NotificationPreference",description:"User notification preferences by type and channel.",schema:"lssm_notifications",map:"notification_preference",fields:{id:j.id(),userId:j.foreignKey(),globalEnabled:j.boolean({default:!0}),quietHoursStart:j.string({isOptional:!0,description:"Quiet hours start (HH:MM)"}),quietHoursEnd:j.string({isOptional:!0,description:"Quiet hours end (HH:MM)"}),timezone:j.string({default:'"UTC"'}),channelPreferences:j.json({description:"Channel-level preferences"}),typePreferences:j.json({description:"Type-level preferences"}),digestEnabled:j.boolean({default:!1}),digestFrequency:j.string({isOptional:!0,description:"daily, weekly, etc."}),digestTime:j.string({isOptional:!0,description:"Digest send time (HH:MM)"}),createdAt:j.createdAt(),updatedAt:j.updatedAt()},indexes:[X.unique(["userId"])]}),Zj=w({name:"DeliveryLog",description:"Log of notification delivery attempts.",schema:"lssm_notifications",map:"delivery_log",fields:{id:j.id(),notificationId:j.foreignKey(),channel:j.enum("NotificationChannel"),status:j.enum("NotificationStatus"),attemptedAt:j.dateTime(),deliveredAt:j.dateTime({isOptional:!0}),responseCode:j.string({isOptional:!0}),responseMessage:j.string({isOptional:!0}),externalId:j.string({isOptional:!0,description:"Provider message ID"}),metadata:j.json({isOptional:!0}),notification:j.belongsTo("Notification",["notificationId"],["id"],{onDelete:"Cascade"})},indexes:[X.on(["notificationId","channel"])]}),_j=[Vj,Xj,Yj,Zj],Ej={moduleId:"@contractspec/module.notifications",entities:_j,enums:[S,y,E]};import{defineFeature as $j}from"@contractspec/lib.contracts-spec";var sj=$j({meta:{key:"notifications",title:"Notifications",description:"Multi-channel notification delivery with preference management",domain:"platform",version:"1.0.0",owners:["@platform.notifications"],tags:["notifications","email","push","in-app"],stability:"stable"},operations:[{key:"notifications.send",version:"1.0.0"},{key:"notifications.markRead",version:"1.0.0"},{key:"notifications.markAllRead",version:"1.0.0"},{key:"notifications.delete",version:"1.0.0"},{key:"notifications.list",version:"1.0.0"},{key:"notifications.preferences.update",version:"1.0.0"},{key:"notifications.preferences.get",version:"1.0.0"}],events:[],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{provides:[{key:"notifications",version:"1.0.0"}],requires:[{key:"identity",version:"1.0.0"}]}});function U(q){return q}function x(q,D){return q.replace(/\{\{(\w+)\}\}/g,(J,Z)=>{let G=D[Z];if(G===void 0||G===null)return J;return String(G)})}function rj(q,D,J,Z){let G=(Z&&q.localeChannels?.[Z]?.[D])??q.channels[D];if(!G)return null;let p=G.title?x(G.title,J):q.name,z=x(G.body,J),s=G.actionUrl?x(G.actionUrl,J):void 0,F={title:p,body:z,actionUrl:s};if(D==="email"&&G.subject)F.email={subject:x(G.subject,J),html:z,text:wj(z)};return F}function wj(q){return q.replace(/<[^>]*>/g,"").replace(/\s+/g," ").trim()}class u{templates=new Map;register(q){this.templates.set(q.id,q)}get(q){return this.templates.get(q)}getAll(){return Array.from(this.templates.values())}getByCategory(q){return this.getAll().filter((D)=>D.category===q)}}function dj(){return new u}var fj=U({id:"welcome",name:"Welcome",description:"Sent when a user signs up.",category:"onboarding",variables:[{name:"name",type:"string",required:!0},{name:"appName",type:"string",default:"ContractSpec"},{name:"actionUrl",type:"url"}],defaultChannels:["EMAIL","IN_APP"],channels:{email:{subject:"Welcome to {{appName}}, {{name}}!",body:`
949
2
  <h1>Welcome, {{name}}!</h1>
950
3
  <p>Thanks for joining {{appName}}. We're excited to have you on board.</p>
951
4
  <p><a href="{{actionUrl}}">Get started now</a></p>
952
- `
953
- },
954
- inApp: {
955
- title: "Welcome to {{appName}}!",
956
- body: "Thanks for joining. Click to complete your profile.",
957
- actionUrl: "{{actionUrl}}"
958
- }
959
- },
960
- localeChannels: {
961
- fr: {
962
- email: {
963
- subject: "Bienvenue sur {{appName}}, {{name}} !",
964
- body: `
5
+ `},inApp:{title:"Welcome to {{appName}}!",body:"Thanks for joining. Click to complete your profile.",actionUrl:"{{actionUrl}}"}},localeChannels:{fr:{email:{subject:"Bienvenue sur {{appName}}, {{name}} !",body:`
965
6
  <h1>Bienvenue, {{name}} !</h1>
966
7
  <p>Merci d’avoir rejoint {{appName}}. Nous sommes ravis de vous compter parmi nous.</p>
967
8
  <p><a href="{{actionUrl}}">Commencer maintenant</a></p>
968
- `
969
- },
970
- inApp: {
971
- title: "Bienvenue sur {{appName}} !",
972
- body: "Merci de nous avoir rejoint. Cliquez pour compléter votre profil.",
973
- actionUrl: "{{actionUrl}}"
974
- }
975
- },
976
- es: {
977
- email: {
978
- subject: "¡Bienvenido a {{appName}}, {{name}}!",
979
- body: `
9
+ `},inApp:{title:"Bienvenue sur {{appName}} !",body:"Merci de nous avoir rejoint. Cliquez pour compléter votre profil.",actionUrl:"{{actionUrl}}"}},es:{email:{subject:"¡Bienvenido a {{appName}}, {{name}}!",body:`
980
10
  <h1>¡Bienvenido, {{name}}!</h1>
981
11
  <p>Gracias por unirte a {{appName}}. Estamos encantados de tenerte.</p>
982
12
  <p><a href="{{actionUrl}}">Comenzar ahora</a></p>
983
- `
984
- },
985
- inApp: {
986
- title: "¡Bienvenido a {{appName}}!",
987
- body: "Gracias por unirte. Haz clic para completar tu perfil.",
988
- actionUrl: "{{actionUrl}}"
989
- }
990
- }
991
- }
992
- });
993
- var OrgInviteTemplate = defineTemplate({
994
- id: "org-invite",
995
- name: "Organization Invitation",
996
- description: "Sent when a user is invited to an organization.",
997
- category: "organization",
998
- variables: [
999
- { name: "inviterName", type: "string", required: true },
1000
- { name: "orgName", type: "string", required: true },
1001
- { name: "role", type: "string", default: "member" },
1002
- { name: "actionUrl", type: "url", required: true }
1003
- ],
1004
- defaultChannels: ["EMAIL"],
1005
- channels: {
1006
- email: {
1007
- subject: "{{inviterName}} invited you to join {{orgName}}",
1008
- body: `
13
+ `},inApp:{title:"¡Bienvenido a {{appName}}!",body:"Gracias por unirte. Haz clic para completar tu perfil.",actionUrl:"{{actionUrl}}"}}}}),oj=U({id:"org-invite",name:"Organization Invitation",description:"Sent when a user is invited to an organization.",category:"organization",variables:[{name:"inviterName",type:"string",required:!0},{name:"orgName",type:"string",required:!0},{name:"role",type:"string",default:"member"},{name:"actionUrl",type:"url",required:!0}],defaultChannels:["EMAIL"],channels:{email:{subject:"{{inviterName}} invited you to join {{orgName}}",body:`
1009
14
  <h1>You've been invited!</h1>
1010
15
  <p>{{inviterName}} has invited you to join <strong>{{orgName}}</strong> as a {{role}}.</p>
1011
16
  <p><a href="{{actionUrl}}">Accept invitation</a></p>
1012
- `
1013
- },
1014
- inApp: {
1015
- title: "Invitation to {{orgName}}",
1016
- body: "{{inviterName}} invited you to join as {{role}}.",
1017
- actionUrl: "{{actionUrl}}",
1018
- actionText: "Accept"
1019
- }
1020
- },
1021
- localeChannels: {
1022
- fr: {
1023
- email: {
1024
- subject: "{{inviterName}} vous invite à rejoindre {{orgName}}",
1025
- body: `
17
+ `},inApp:{title:"Invitation to {{orgName}}",body:"{{inviterName}} invited you to join as {{role}}.",actionUrl:"{{actionUrl}}",actionText:"Accept"}},localeChannels:{fr:{email:{subject:"{{inviterName}} vous invite à rejoindre {{orgName}}",body:`
1026
18
  <h1>Vous êtes invité !</h1>
1027
19
  <p>{{inviterName}} vous a invité à rejoindre <strong>{{orgName}}</strong> en tant que {{role}}.</p>
1028
20
  <p><a href="{{actionUrl}}">Accepter l’invitation</a></p>
1029
- `
1030
- },
1031
- inApp: {
1032
- title: "Invitation à {{orgName}}",
1033
- body: "{{inviterName}} vous a invité à rejoindre en tant que {{role}}.",
1034
- actionUrl: "{{actionUrl}}",
1035
- actionText: "Accepter"
1036
- }
1037
- },
1038
- es: {
1039
- email: {
1040
- subject: "{{inviterName}} te invitó a unirte a {{orgName}}",
1041
- body: `
21
+ `},inApp:{title:"Invitation à {{orgName}}",body:"{{inviterName}} vous a invité à rejoindre en tant que {{role}}.",actionUrl:"{{actionUrl}}",actionText:"Accepter"}},es:{email:{subject:"{{inviterName}} te invitó a unirte a {{orgName}}",body:`
1042
22
  <h1>¡Has sido invitado!</h1>
1043
23
  <p>{{inviterName}} te ha invitado a unirte a <strong>{{orgName}}</strong> como {{role}}.</p>
1044
24
  <p><a href="{{actionUrl}}">Aceptar invitación</a></p>
1045
- `
1046
- },
1047
- inApp: {
1048
- title: "Invitación a {{orgName}}",
1049
- body: "{{inviterName}} te invitó a unirte como {{role}}.",
1050
- actionUrl: "{{actionUrl}}",
1051
- actionText: "Aceptar"
1052
- }
1053
- }
1054
- }
1055
- });
1056
- var MentionTemplate = defineTemplate({
1057
- id: "mention",
1058
- name: "Mention",
1059
- description: "Sent when a user is mentioned.",
1060
- category: "social",
1061
- variables: [
1062
- { name: "mentionerName", type: "string", required: true },
1063
- { name: "context", type: "string", required: true },
1064
- { name: "preview", type: "string" },
1065
- { name: "actionUrl", type: "url", required: true }
1066
- ],
1067
- defaultChannels: ["IN_APP", "PUSH"],
1068
- channels: {
1069
- inApp: {
1070
- title: "{{mentionerName}} mentioned you",
1071
- body: 'In {{context}}: "{{preview}}"',
1072
- actionUrl: "{{actionUrl}}"
1073
- },
1074
- push: {
1075
- title: "{{mentionerName}} mentioned you",
1076
- body: "{{preview}}"
1077
- }
1078
- },
1079
- localeChannels: {
1080
- fr: {
1081
- inApp: {
1082
- title: "{{mentionerName}} vous a mentionné",
1083
- body: "Dans {{context}} : « {{preview}} »",
1084
- actionUrl: "{{actionUrl}}"
1085
- },
1086
- push: {
1087
- title: "{{mentionerName}} vous a mentionné",
1088
- body: "{{preview}}"
1089
- }
1090
- },
1091
- es: {
1092
- inApp: {
1093
- title: "{{mentionerName}} te mencionó",
1094
- body: 'En {{context}}: "{{preview}}"',
1095
- actionUrl: "{{actionUrl}}"
1096
- },
1097
- push: {
1098
- title: "{{mentionerName}} te mencionó",
1099
- body: "{{preview}}"
1100
- }
1101
- }
1102
- }
1103
- });
1104
- export {
1105
- renderTemplate,
1106
- renderNotificationTemplate,
1107
- notificationsSchemaContribution,
1108
- notificationEntities,
1109
- defineTemplate,
1110
- createTemplateRegistry,
1111
- createChannelRegistry,
1112
- WelcomeTemplate,
1113
- WebhookChannel,
1114
- UpdatePreferencesInputModel,
1115
- UpdateNotificationPreferencesContract,
1116
- TemplateRegistry,
1117
- SendNotificationInputModel,
1118
- SendNotificationContract,
1119
- PushChannel,
1120
- OrgInviteTemplate,
1121
- NotificationsFeature,
1122
- NotificationTemplateEntity,
1123
- NotificationStatusEnum,
1124
- NotificationPriorityEnum,
1125
- NotificationPreferenceModel,
1126
- NotificationPreferenceEntity,
1127
- NotificationModel,
1128
- NotificationFilterEnum,
1129
- NotificationEntity,
1130
- NotificationChannelEnum,
1131
- MentionTemplate,
1132
- MarkNotificationReadContract,
1133
- MarkAllNotificationsReadContract,
1134
- ListNotificationsOutputModel,
1135
- ListNotificationsInputModel,
1136
- ListNotificationsContract,
1137
- InAppChannel,
1138
- GetNotificationPreferencesContract,
1139
- EmailChannel,
1140
- DeliveryLogEntity,
1141
- DeleteNotificationContract,
1142
- ConsoleChannel,
1143
- ChannelRegistry
1144
- };
25
+ `},inApp:{title:"Invitación a {{orgName}}",body:"{{inviterName}} te invitó a unirte como {{role}}.",actionUrl:"{{actionUrl}}",actionText:"Aceptar"}}}}),cj=U({id:"mention",name:"Mention",description:"Sent when a user is mentioned.",category:"social",variables:[{name:"mentionerName",type:"string",required:!0},{name:"context",type:"string",required:!0},{name:"preview",type:"string"},{name:"actionUrl",type:"url",required:!0}],defaultChannels:["IN_APP","PUSH"],channels:{inApp:{title:"{{mentionerName}} mentioned you",body:'In {{context}}: "{{preview}}"',actionUrl:"{{actionUrl}}"},push:{title:"{{mentionerName}} mentioned you",body:"{{preview}}"}},localeChannels:{fr:{inApp:{title:"{{mentionerName}} vous a mentionné",body:"Dans {{context}} : « {{preview}} »",actionUrl:"{{actionUrl}}"},push:{title:"{{mentionerName}} vous a mentionné",body:"{{preview}}"}},es:{inApp:{title:"{{mentionerName}} te mencionó",body:'En {{context}}: "{{preview}}"',actionUrl:"{{actionUrl}}"},push:{title:"{{mentionerName}} te mencionó",body:"{{preview}}"}}}});export{x as renderTemplate,rj as renderNotificationTemplate,Ej as notificationsSchemaContribution,_j as notificationEntities,U as defineTemplate,dj as createTemplateRegistry,Wj as createChannelRegistry,fj as WelcomeTemplate,b as WebhookChannel,Kj as UpdatePreferencesInputModel,Tj as UpdateNotificationPreferencesContract,u as TemplateRegistry,Dj as SendNotificationInputModel,gj as SendNotificationContract,jj as PushChannel,oj as OrgInviteTemplate,sj as NotificationsFeature,Xj as NotificationTemplateEntity,S as NotificationStatusEnum,E as NotificationPriorityEnum,h as NotificationPreferenceModel,Yj as NotificationPreferenceEntity,$ as NotificationModel,Bj as NotificationFilterEnum,Vj as NotificationEntity,y as NotificationChannelEnum,cj as MentionTemplate,bj as MarkNotificationReadContract,Cj as MarkAllNotificationsReadContract,Jj as ListNotificationsOutputModel,Gj as ListNotificationsInputModel,Mj as ListNotificationsContract,g as InAppChannel,Nj as GetNotificationPreferencesContract,e as EmailChannel,Zj as DeliveryLogEntity,hj as DeleteNotificationContract,M as ConsoleChannel,C as ChannelRegistry};