shared-features 0.0.4 → 0.0.5

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 (90) hide show
  1. package/dist/{AdBanner-CZz8trdz.cjs → AnnouncementModal-Bqy0pn3V.cjs} +428 -3
  2. package/dist/AnnouncementModal-Bqy0pn3V.cjs.map +1 -0
  3. package/dist/{AdBanner-DF1QuMxR.js → AnnouncementModal-sxH4K5gy.js} +430 -5
  4. package/dist/AnnouncementModal-sxH4K5gy.js.map +1 -0
  5. package/dist/admin-notifications-D9n9h-eY.cjs +362 -0
  6. package/dist/admin-notifications-D9n9h-eY.cjs.map +1 -0
  7. package/dist/admin-notifications-p1dy3zIP.js +363 -0
  8. package/dist/admin-notifications-p1dy3zIP.js.map +1 -0
  9. package/dist/{analytics-CdpCtTpu.js → analytics-40-S_fHC.js} +3 -2
  10. package/dist/{analytics-CdpCtTpu.js.map → analytics-40-S_fHC.js.map} +1 -1
  11. package/dist/{analytics--ZSO9ova.cjs → analytics-lEzOx2vl.cjs} +2 -1
  12. package/dist/{analytics--ZSO9ova.cjs.map → analytics-lEzOx2vl.cjs.map} +1 -1
  13. package/dist/broadcasts-3_WfQMNL.cjs +278 -0
  14. package/dist/broadcasts-3_WfQMNL.cjs.map +1 -0
  15. package/dist/broadcasts-DgZUzqMf.js +257 -0
  16. package/dist/broadcasts-DgZUzqMf.js.map +1 -0
  17. package/dist/components/index.cjs +23 -20
  18. package/dist/components/index.cjs.map +1 -1
  19. package/dist/components/index.d.ts +1 -0
  20. package/dist/components/index.d.ts.map +1 -1
  21. package/dist/components/index.js +4 -1
  22. package/dist/components/notifications/AnnouncementModal.d.ts +21 -0
  23. package/dist/components/notifications/AnnouncementModal.d.ts.map +1 -0
  24. package/dist/components/notifications/BroadcastBanner.d.ts +55 -0
  25. package/dist/components/notifications/BroadcastBanner.d.ts.map +1 -0
  26. package/dist/components/notifications/index.d.ts +11 -0
  27. package/dist/components/notifications/index.d.ts.map +1 -0
  28. package/dist/hooks/index.cjs +9 -1
  29. package/dist/hooks/index.cjs.map +1 -1
  30. package/dist/hooks/index.d.ts +2 -0
  31. package/dist/hooks/index.d.ts.map +1 -1
  32. package/dist/hooks/index.js +9 -1
  33. package/dist/hooks/index.js.map +1 -1
  34. package/dist/hooks/useBroadcasts.d.ts +122 -0
  35. package/dist/hooks/useBroadcasts.d.ts.map +1 -0
  36. package/dist/index.cjs +99 -22
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +94 -17
  41. package/dist/index.js.map +1 -1
  42. package/dist/notifications/events/index.d.ts +14 -0
  43. package/dist/notifications/events/index.d.ts.map +1 -0
  44. package/dist/notifications/events/registry.d.ts +75 -0
  45. package/dist/notifications/events/registry.d.ts.map +1 -0
  46. package/dist/notifications/events/templates/engine.d.ts +57 -0
  47. package/dist/notifications/events/templates/engine.d.ts.map +1 -0
  48. package/dist/notifications/events/templates/standard.d.ts +20 -0
  49. package/dist/notifications/events/templates/standard.d.ts.map +1 -0
  50. package/dist/notifications/events/useNotificationEvents.d.ts +36 -0
  51. package/dist/notifications/events/useNotificationEvents.d.ts.map +1 -0
  52. package/dist/notifications/index.cjs +25 -0
  53. package/dist/notifications/index.cjs.map +1 -0
  54. package/dist/notifications/index.d.ts +9 -0
  55. package/dist/notifications/index.d.ts.map +1 -0
  56. package/dist/notifications/index.js +25 -0
  57. package/dist/notifications/index.js.map +1 -0
  58. package/dist/services/admin-notifications.d.ts +95 -0
  59. package/dist/services/admin-notifications.d.ts.map +1 -0
  60. package/dist/services/broadcasts.d.ts +55 -0
  61. package/dist/services/broadcasts.d.ts.map +1 -0
  62. package/dist/services/index.cjs +34 -1
  63. package/dist/services/index.cjs.map +1 -1
  64. package/dist/services/index.d.ts +2 -0
  65. package/dist/services/index.d.ts.map +1 -1
  66. package/dist/services/index.js +35 -2
  67. package/dist/services/index.js.map +1 -1
  68. package/dist/types/index.cjs +108 -0
  69. package/dist/types/index.cjs.map +1 -1
  70. package/dist/types/index.d.ts +1 -0
  71. package/dist/types/index.d.ts.map +1 -1
  72. package/dist/types/index.js +109 -1
  73. package/dist/types/index.js.map +1 -1
  74. package/dist/types/notifications.d.ts +634 -0
  75. package/dist/types/notifications.d.ts.map +1 -0
  76. package/dist/useBroadcasts-DzpCcbC8.js +161 -0
  77. package/dist/useBroadcasts-DzpCcbC8.js.map +1 -0
  78. package/dist/useBroadcasts-FP6ZrcY_.cjs +160 -0
  79. package/dist/useBroadcasts-FP6ZrcY_.cjs.map +1 -0
  80. package/dist/{useCampaigns-Dltisb9N.cjs → useCampaigns-BOZ9dDsG.cjs} +2 -2
  81. package/dist/{useCampaigns-Dltisb9N.cjs.map → useCampaigns-BOZ9dDsG.cjs.map} +1 -1
  82. package/dist/{useCampaigns-nwfsALsN.js → useCampaigns-D46b9zuf.js} +2 -2
  83. package/dist/{useCampaigns-nwfsALsN.js.map → useCampaigns-D46b9zuf.js.map} +1 -1
  84. package/dist/useNotificationEvents-BXeMqdak.cjs +954 -0
  85. package/dist/useNotificationEvents-BXeMqdak.cjs.map +1 -0
  86. package/dist/useNotificationEvents-D8DVxah1.js +955 -0
  87. package/dist/useNotificationEvents-D8DVxah1.js.map +1 -0
  88. package/package.json +11 -3
  89. package/dist/AdBanner-CZz8trdz.cjs.map +0 -1
  90. package/dist/AdBanner-DF1QuMxR.js.map +0 -1
@@ -0,0 +1,955 @@
1
+ import { useCallback } from "react";
2
+ function interpolate(template, context, options = {}) {
3
+ const { strict = false, defaultValue = "", formatters = {} } = options;
4
+ const pattern = /\{\{([^}|]+)(?:\|([^}]+))?\}\}/g;
5
+ return template.replace(pattern, (_match, variableName, formatterName) => {
6
+ const trimmedName = variableName.trim();
7
+ const value = context[trimmedName];
8
+ if (value === void 0 || value === null) {
9
+ if (strict) {
10
+ throw new Error(`Missing template variable: ${trimmedName}`);
11
+ }
12
+ return defaultValue;
13
+ }
14
+ if (formatterName) {
15
+ const formatter = formatters[formatterName.trim()];
16
+ if (formatter) {
17
+ return formatter(value);
18
+ }
19
+ }
20
+ return String(value);
21
+ });
22
+ }
23
+ function extractVariables(template) {
24
+ const pattern = /\{\{([^}|]+)(?:\|[^}]+)?\}\}/g;
25
+ const variables = [];
26
+ let match;
27
+ while ((match = pattern.exec(template)) !== null) {
28
+ const matchResult = match[1];
29
+ if (matchResult) {
30
+ const variableName = matchResult.trim();
31
+ if (!variables.includes(variableName)) {
32
+ variables.push(variableName);
33
+ }
34
+ }
35
+ }
36
+ return variables;
37
+ }
38
+ function validateContext(template, context) {
39
+ const required = extractVariables(template);
40
+ const missing = required.filter(
41
+ (v) => context[v] === void 0 || context[v] === null
42
+ );
43
+ return {
44
+ valid: missing.length === 0,
45
+ missing
46
+ };
47
+ }
48
+ const defaultFormatters = {
49
+ /**
50
+ * Capitalize first letter
51
+ */
52
+ capitalize: (value) => {
53
+ const str = String(value);
54
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
55
+ },
56
+ /**
57
+ * Convert to uppercase
58
+ */
59
+ upper: (value) => String(value).toUpperCase(),
60
+ /**
61
+ * Convert to lowercase
62
+ */
63
+ lower: (value) => String(value).toLowerCase(),
64
+ /**
65
+ * Format number with commas
66
+ */
67
+ number: (value) => {
68
+ const num = Number(value);
69
+ if (isNaN(num)) return String(value);
70
+ return num.toLocaleString();
71
+ },
72
+ /**
73
+ * Format as date
74
+ */
75
+ date: (value) => {
76
+ const date = new Date(value);
77
+ if (isNaN(date.getTime())) return String(value);
78
+ return date.toLocaleDateString();
79
+ },
80
+ /**
81
+ * Format as time
82
+ */
83
+ time: (value) => {
84
+ const date = new Date(value);
85
+ if (isNaN(date.getTime())) return String(value);
86
+ return date.toLocaleTimeString();
87
+ },
88
+ /**
89
+ * Format as datetime
90
+ */
91
+ datetime: (value) => {
92
+ const date = new Date(value);
93
+ if (isNaN(date.getTime())) return String(value);
94
+ return date.toLocaleString();
95
+ },
96
+ /**
97
+ * Truncate to 50 characters
98
+ */
99
+ truncate: (value) => {
100
+ const str = String(value);
101
+ return str.length > 50 ? str.substring(0, 47) + "..." : str;
102
+ },
103
+ /**
104
+ * Join array with commas
105
+ */
106
+ list: (value) => {
107
+ if (Array.isArray(value)) {
108
+ return value.join(", ");
109
+ }
110
+ return String(value);
111
+ }
112
+ };
113
+ function interpolateWithFormatters(template, context, options = {}) {
114
+ const { customFormatters = {}, ...restOptions } = options;
115
+ return interpolate(template, context, {
116
+ ...restOptions,
117
+ formatters: { ...defaultFormatters, ...customFormatters }
118
+ });
119
+ }
120
+ const ACCOUNT_TEMPLATES = [
121
+ {
122
+ id: "tpl_account_created",
123
+ name: "Account Created",
124
+ eventType: "ACCOUNT_CREATED",
125
+ category: "account",
126
+ title: "Welcome to {{appName}}!",
127
+ message: "Hi {{userName}}, your account has been created successfully. Start exploring all the features we have to offer.",
128
+ variables: ["appName", "userName"],
129
+ type: "success",
130
+ isImportant: true,
131
+ actionUrl: "/getting-started",
132
+ actionText: "Get Started",
133
+ enabled: true,
134
+ createdAt: /* @__PURE__ */ new Date(),
135
+ updatedAt: /* @__PURE__ */ new Date()
136
+ },
137
+ {
138
+ id: "tpl_account_welcome",
139
+ name: "Welcome Message",
140
+ eventType: "ACCOUNT_WELCOME",
141
+ category: "account",
142
+ title: "Tips to get started with {{appName}}",
143
+ message: "Here are some tips to help you get the most out of {{appName}}. Check out our quick start guide!",
144
+ variables: ["appName"],
145
+ type: "info",
146
+ isImportant: false,
147
+ actionUrl: "/help/quick-start",
148
+ actionText: "Quick Start Guide",
149
+ enabled: true,
150
+ createdAt: /* @__PURE__ */ new Date(),
151
+ updatedAt: /* @__PURE__ */ new Date()
152
+ },
153
+ {
154
+ id: "tpl_new_device_signin",
155
+ name: "New Device Sign-in",
156
+ eventType: "NEW_DEVICE_SIGNIN",
157
+ category: "account",
158
+ title: "New Sign-in Detected",
159
+ message: "Your account was accessed from a new device: {{deviceName}}{{#location}} in {{location}}{{/location}}. If this wasn't you, please secure your account.",
160
+ variables: ["deviceName", "location"],
161
+ type: "warning",
162
+ isImportant: true,
163
+ actionUrl: "/settings/security",
164
+ actionText: "Review Activity",
165
+ enabled: true,
166
+ createdAt: /* @__PURE__ */ new Date(),
167
+ updatedAt: /* @__PURE__ */ new Date()
168
+ },
169
+ {
170
+ id: "tpl_password_changed",
171
+ name: "Password Changed",
172
+ eventType: "PASSWORD_CHANGED",
173
+ category: "account",
174
+ title: "Password Changed Successfully",
175
+ message: "Your password was changed on {{timestamp}}. If you didn't make this change, please contact support immediately.",
176
+ variables: ["timestamp"],
177
+ type: "info",
178
+ isImportant: true,
179
+ actionUrl: "/settings/security",
180
+ actionText: "Security Settings",
181
+ enabled: true,
182
+ createdAt: /* @__PURE__ */ new Date(),
183
+ updatedAt: /* @__PURE__ */ new Date()
184
+ },
185
+ {
186
+ id: "tpl_profile_updated",
187
+ name: "Profile Updated",
188
+ eventType: "PROFILE_UPDATED",
189
+ category: "account",
190
+ title: "Profile Updated",
191
+ message: "Your profile has been updated: {{changes}}.",
192
+ variables: ["changes"],
193
+ type: "success",
194
+ isImportant: false,
195
+ enabled: true,
196
+ createdAt: /* @__PURE__ */ new Date(),
197
+ updatedAt: /* @__PURE__ */ new Date()
198
+ }
199
+ ];
200
+ const REPORT_TEMPLATES = [
201
+ {
202
+ id: "tpl_weekly_summary",
203
+ name: "Weekly Summary",
204
+ eventType: "WEEKLY_SUMMARY",
205
+ category: "report",
206
+ title: "Your Weekly Summary",
207
+ message: "Here's your activity summary for the week of {{weekStart}}: {{summary}}",
208
+ variables: ["weekStart", "summary"],
209
+ type: "info",
210
+ isImportant: false,
211
+ actionUrl: "/reports/weekly",
212
+ actionText: "View Full Report",
213
+ enabled: true,
214
+ createdAt: /* @__PURE__ */ new Date(),
215
+ updatedAt: /* @__PURE__ */ new Date()
216
+ },
217
+ {
218
+ id: "tpl_monthly_summary",
219
+ name: "Monthly Summary",
220
+ eventType: "MONTHLY_SUMMARY",
221
+ category: "report",
222
+ title: "Your Monthly Summary",
223
+ message: "Your activity summary for {{monthName}} is ready. {{summary}}",
224
+ variables: ["monthName", "summary"],
225
+ type: "info",
226
+ isImportant: false,
227
+ actionUrl: "/reports/monthly",
228
+ actionText: "View Full Report",
229
+ enabled: true,
230
+ createdAt: /* @__PURE__ */ new Date(),
231
+ updatedAt: /* @__PURE__ */ new Date()
232
+ },
233
+ {
234
+ id: "tpl_quarterly_summary",
235
+ name: "Quarterly Summary",
236
+ eventType: "QUARTERLY_SUMMARY",
237
+ category: "report",
238
+ title: "Your Quarterly Review",
239
+ message: "Your Q{{quarter}} {{year}} summary is ready. See how you've progressed!",
240
+ variables: ["quarter", "year"],
241
+ type: "milestone",
242
+ isImportant: true,
243
+ actionUrl: "/reports/quarterly",
244
+ actionText: "View Report",
245
+ enabled: true,
246
+ createdAt: /* @__PURE__ */ new Date(),
247
+ updatedAt: /* @__PURE__ */ new Date()
248
+ },
249
+ {
250
+ id: "tpl_yearly_summary",
251
+ name: "Yearly Summary",
252
+ eventType: "YEARLY_SUMMARY",
253
+ category: "report",
254
+ title: "Your Year in Review",
255
+ message: "Congratulations on another great year! Your {{year}} summary is ready.",
256
+ variables: ["year"],
257
+ type: "milestone",
258
+ isImportant: true,
259
+ actionUrl: "/reports/yearly",
260
+ actionText: "View Year in Review",
261
+ enabled: true,
262
+ createdAt: /* @__PURE__ */ new Date(),
263
+ updatedAt: /* @__PURE__ */ new Date()
264
+ }
265
+ ];
266
+ const PROMOTIONAL_TEMPLATES = [
267
+ {
268
+ id: "tpl_app_tip",
269
+ name: "App Tip",
270
+ eventType: "APP_TIP",
271
+ category: "promotional",
272
+ title: "Tip: {{tipTitle}}",
273
+ message: "{{tipBody}}",
274
+ variables: ["tipTitle", "tipBody"],
275
+ type: "info",
276
+ isImportant: false,
277
+ enabled: true,
278
+ createdAt: /* @__PURE__ */ new Date(),
279
+ updatedAt: /* @__PURE__ */ new Date()
280
+ },
281
+ {
282
+ id: "tpl_hidden_feature",
283
+ name: "Hidden Feature",
284
+ eventType: "HIDDEN_FEATURE",
285
+ category: "promotional",
286
+ title: "Did you know?",
287
+ message: "{{featureDescription}}",
288
+ variables: ["featureName", "featureDescription"],
289
+ type: "info",
290
+ isImportant: false,
291
+ actionUrl: "{{featureUrl}}",
292
+ actionText: "Try it now",
293
+ enabled: true,
294
+ createdAt: /* @__PURE__ */ new Date(),
295
+ updatedAt: /* @__PURE__ */ new Date()
296
+ },
297
+ {
298
+ id: "tpl_new_feature",
299
+ name: "New Feature Announcement",
300
+ eventType: "NEW_FEATURE_ANNOUNCEMENT",
301
+ category: "promotional",
302
+ title: "New Feature: {{featureName}}",
303
+ message: "{{featureDescription}}",
304
+ variables: ["featureName", "featureDescription"],
305
+ type: "announcement",
306
+ isImportant: true,
307
+ actionUrl: "{{featureUrl}}",
308
+ actionText: "Check it out",
309
+ enabled: true,
310
+ createdAt: /* @__PURE__ */ new Date(),
311
+ updatedAt: /* @__PURE__ */ new Date()
312
+ },
313
+ {
314
+ id: "tpl_holiday_greeting",
315
+ name: "Holiday Greeting",
316
+ eventType: "HOLIDAY_GREETING",
317
+ category: "promotional",
318
+ title: "Happy {{holidayName}}!",
319
+ message: "{{greetingMessage}}",
320
+ variables: ["holidayName", "greetingMessage"],
321
+ type: "info",
322
+ isImportant: false,
323
+ enabled: true,
324
+ createdAt: /* @__PURE__ */ new Date(),
325
+ updatedAt: /* @__PURE__ */ new Date()
326
+ }
327
+ ];
328
+ const SYSTEM_TEMPLATES = [
329
+ {
330
+ id: "tpl_system_maintenance",
331
+ name: "System Maintenance",
332
+ eventType: "SYSTEM_MAINTENANCE",
333
+ category: "system",
334
+ title: "Scheduled Maintenance",
335
+ message: "We'll be performing maintenance on {{date}} from {{startTime}} to {{endTime}} ({{timezone}}). Some features may be unavailable.",
336
+ variables: ["date", "startTime", "endTime", "timezone"],
337
+ type: "warning",
338
+ isImportant: true,
339
+ enabled: true,
340
+ createdAt: /* @__PURE__ */ new Date(),
341
+ updatedAt: /* @__PURE__ */ new Date()
342
+ },
343
+ {
344
+ id: "tpl_app_update",
345
+ name: "App Update Available",
346
+ eventType: "APP_UPDATE_AVAILABLE",
347
+ category: "system",
348
+ title: "Update Available",
349
+ message: "A new version ({{version}}) is available with improvements and bug fixes.",
350
+ variables: ["version"],
351
+ type: "info",
352
+ isImportant: false,
353
+ actionUrl: "/update",
354
+ actionText: "Update Now",
355
+ enabled: true,
356
+ createdAt: /* @__PURE__ */ new Date(),
357
+ updatedAt: /* @__PURE__ */ new Date()
358
+ },
359
+ {
360
+ id: "tpl_data_export_ready",
361
+ name: "Data Export Ready",
362
+ eventType: "DATA_EXPORT_READY",
363
+ category: "system",
364
+ title: "Your Data Export is Ready",
365
+ message: "Your requested data export is ready for download. The link will expire in {{expiryHours}} hours.",
366
+ variables: ["expiryHours"],
367
+ type: "success",
368
+ isImportant: true,
369
+ actionUrl: "{{downloadUrl}}",
370
+ actionText: "Download",
371
+ enabled: true,
372
+ createdAt: /* @__PURE__ */ new Date(),
373
+ updatedAt: /* @__PURE__ */ new Date()
374
+ }
375
+ ];
376
+ const ACTIVITY_TEMPLATES = [
377
+ {
378
+ id: "tpl_item_created",
379
+ name: "Item Created",
380
+ eventType: "ITEM_CREATED",
381
+ category: "activity",
382
+ title: "{{entityType}} Created",
383
+ message: 'Your {{entityType}} "{{entityName}}" has been created successfully.',
384
+ variables: ["entityType", "entityName"],
385
+ type: "success",
386
+ isImportant: false,
387
+ enabled: true,
388
+ createdAt: /* @__PURE__ */ new Date(),
389
+ updatedAt: /* @__PURE__ */ new Date()
390
+ },
391
+ {
392
+ id: "tpl_item_updated",
393
+ name: "Item Updated",
394
+ eventType: "ITEM_UPDATED",
395
+ category: "activity",
396
+ title: "{{entityType}} Updated",
397
+ message: 'Your {{entityType}} "{{entityName}}" has been updated.',
398
+ variables: ["entityType", "entityName"],
399
+ type: "info",
400
+ isImportant: false,
401
+ enabled: true,
402
+ createdAt: /* @__PURE__ */ new Date(),
403
+ updatedAt: /* @__PURE__ */ new Date()
404
+ },
405
+ {
406
+ id: "tpl_item_deleted",
407
+ name: "Item Deleted",
408
+ eventType: "ITEM_DELETED",
409
+ category: "activity",
410
+ title: "{{entityType}} Deleted",
411
+ message: 'Your {{entityType}} "{{entityName}}" has been deleted.',
412
+ variables: ["entityType", "entityName"],
413
+ type: "info",
414
+ isImportant: false,
415
+ enabled: true,
416
+ createdAt: /* @__PURE__ */ new Date(),
417
+ updatedAt: /* @__PURE__ */ new Date()
418
+ },
419
+ {
420
+ id: "tpl_bulk_operation",
421
+ name: "Bulk Operation Complete",
422
+ eventType: "BULK_OPERATION_COMPLETE",
423
+ category: "activity",
424
+ title: "Bulk Operation Complete",
425
+ message: "Successfully processed {{successCount}} of {{totalCount}} items. {{#failedCount}}{{failedCount}} items failed.{{/failedCount}}",
426
+ variables: ["successCount", "totalCount", "failedCount"],
427
+ type: "success",
428
+ isImportant: false,
429
+ enabled: true,
430
+ createdAt: /* @__PURE__ */ new Date(),
431
+ updatedAt: /* @__PURE__ */ new Date()
432
+ }
433
+ ];
434
+ const ALL_STANDARD_TEMPLATES = [
435
+ ...ACCOUNT_TEMPLATES,
436
+ ...REPORT_TEMPLATES,
437
+ ...PROMOTIONAL_TEMPLATES,
438
+ ...SYSTEM_TEMPLATES,
439
+ ...ACTIVITY_TEMPLATES
440
+ ];
441
+ function getTemplateByEventType(eventType) {
442
+ return ALL_STANDARD_TEMPLATES.find((t) => t.eventType === eventType);
443
+ }
444
+ function getTemplatesByCategory(category) {
445
+ return ALL_STANDARD_TEMPLATES.filter((t) => t.category === category);
446
+ }
447
+ function getEnabledTemplates() {
448
+ return ALL_STANDARD_TEMPLATES.filter((t) => t.enabled);
449
+ }
450
+ const STANDARD_EVENTS = {
451
+ // Account Events
452
+ ACCOUNT_CREATED: {
453
+ type: "ACCOUNT_CREATED",
454
+ name: "Account Created",
455
+ description: "Triggered when a new user account is created",
456
+ category: "account",
457
+ notificationType: "success",
458
+ priority: "high",
459
+ variables: ["appName", "userName", "email"],
460
+ defaultEnabled: true
461
+ },
462
+ ACCOUNT_WELCOME: {
463
+ type: "ACCOUNT_WELCOME",
464
+ name: "Welcome Message",
465
+ description: "Sent to new users with getting started tips",
466
+ category: "account",
467
+ notificationType: "info",
468
+ priority: "normal",
469
+ variables: ["appName", "userName"],
470
+ defaultEnabled: true
471
+ },
472
+ NEW_DEVICE_SIGNIN: {
473
+ type: "NEW_DEVICE_SIGNIN",
474
+ name: "New Device Sign-in",
475
+ description: "Alerts user when account is accessed from a new device",
476
+ category: "account",
477
+ notificationType: "warning",
478
+ priority: "high",
479
+ variables: ["deviceName", "location", "timestamp"],
480
+ defaultEnabled: true
481
+ },
482
+ PASSWORD_CHANGED: {
483
+ type: "PASSWORD_CHANGED",
484
+ name: "Password Changed",
485
+ description: "Confirms password change to user",
486
+ category: "account",
487
+ notificationType: "info",
488
+ priority: "high",
489
+ variables: ["timestamp"],
490
+ defaultEnabled: true
491
+ },
492
+ PROFILE_UPDATED: {
493
+ type: "PROFILE_UPDATED",
494
+ name: "Profile Updated",
495
+ description: "Confirms profile changes to user",
496
+ category: "account",
497
+ notificationType: "success",
498
+ priority: "low",
499
+ variables: ["changes"],
500
+ defaultEnabled: true
501
+ },
502
+ ACCOUNT_DELETED: {
503
+ type: "ACCOUNT_DELETED",
504
+ name: "Account Deleted",
505
+ description: "Confirms account deletion",
506
+ category: "account",
507
+ notificationType: "info",
508
+ priority: "high",
509
+ variables: ["deletionDate"],
510
+ defaultEnabled: true
511
+ },
512
+ // Report Events
513
+ DAILY_SUMMARY: {
514
+ type: "DAILY_SUMMARY",
515
+ name: "Daily Summary",
516
+ description: "Daily activity summary",
517
+ category: "report",
518
+ notificationType: "info",
519
+ priority: "low",
520
+ variables: ["date", "summary"],
521
+ defaultEnabled: false
522
+ },
523
+ WEEKLY_SUMMARY: {
524
+ type: "WEEKLY_SUMMARY",
525
+ name: "Weekly Summary",
526
+ description: "Weekly activity summary",
527
+ category: "report",
528
+ notificationType: "info",
529
+ priority: "normal",
530
+ variables: ["weekStart", "weekEnd", "summary"],
531
+ defaultEnabled: true
532
+ },
533
+ MONTHLY_SUMMARY: {
534
+ type: "MONTHLY_SUMMARY",
535
+ name: "Monthly Summary",
536
+ description: "Monthly activity summary",
537
+ category: "report",
538
+ notificationType: "info",
539
+ priority: "normal",
540
+ variables: ["monthName", "year", "summary"],
541
+ defaultEnabled: true
542
+ },
543
+ QUARTERLY_SUMMARY: {
544
+ type: "QUARTERLY_SUMMARY",
545
+ name: "Quarterly Summary",
546
+ description: "Quarterly activity review",
547
+ category: "report",
548
+ notificationType: "milestone",
549
+ priority: "normal",
550
+ variables: ["quarter", "year", "summary"],
551
+ defaultEnabled: true
552
+ },
553
+ YEARLY_SUMMARY: {
554
+ type: "YEARLY_SUMMARY",
555
+ name: "Yearly Summary",
556
+ description: "Year-in-review summary",
557
+ category: "report",
558
+ notificationType: "milestone",
559
+ priority: "high",
560
+ variables: ["year", "summary"],
561
+ defaultEnabled: true
562
+ },
563
+ // Promotional Events
564
+ APP_TIP: {
565
+ type: "APP_TIP",
566
+ name: "App Tip",
567
+ description: "Helpful tips about app features",
568
+ category: "promotional",
569
+ notificationType: "info",
570
+ priority: "low",
571
+ variables: ["tipTitle", "tipBody", "tipUrl"],
572
+ defaultEnabled: true
573
+ },
574
+ HIDDEN_FEATURE: {
575
+ type: "HIDDEN_FEATURE",
576
+ name: "Hidden Feature",
577
+ description: "Reveals lesser-known features to users",
578
+ category: "promotional",
579
+ notificationType: "info",
580
+ priority: "low",
581
+ variables: ["featureName", "featureDescription", "featureUrl"],
582
+ defaultEnabled: true
583
+ },
584
+ NEW_FEATURE_ANNOUNCEMENT: {
585
+ type: "NEW_FEATURE_ANNOUNCEMENT",
586
+ name: "New Feature Announcement",
587
+ description: "Announces new features to users",
588
+ category: "promotional",
589
+ notificationType: "announcement",
590
+ priority: "high",
591
+ variables: ["featureName", "featureDescription", "featureUrl"],
592
+ defaultEnabled: true
593
+ },
594
+ HOLIDAY_GREETING: {
595
+ type: "HOLIDAY_GREETING",
596
+ name: "Holiday Greeting",
597
+ description: "Seasonal and holiday greetings",
598
+ category: "promotional",
599
+ notificationType: "info",
600
+ priority: "low",
601
+ variables: ["holidayName", "greetingMessage"],
602
+ defaultEnabled: true
603
+ },
604
+ // System Events
605
+ SYSTEM_MAINTENANCE: {
606
+ type: "SYSTEM_MAINTENANCE",
607
+ name: "System Maintenance",
608
+ description: "Scheduled maintenance notifications",
609
+ category: "system",
610
+ notificationType: "warning",
611
+ priority: "high",
612
+ variables: ["date", "startTime", "endTime", "timezone", "description"],
613
+ defaultEnabled: true
614
+ },
615
+ APP_UPDATE_AVAILABLE: {
616
+ type: "APP_UPDATE_AVAILABLE",
617
+ name: "App Update Available",
618
+ description: "New version available notification",
619
+ category: "system",
620
+ notificationType: "info",
621
+ priority: "normal",
622
+ variables: ["version", "releaseNotes"],
623
+ defaultEnabled: true
624
+ },
625
+ DATA_EXPORT_READY: {
626
+ type: "DATA_EXPORT_READY",
627
+ name: "Data Export Ready",
628
+ description: "User data export is ready for download",
629
+ category: "system",
630
+ notificationType: "success",
631
+ priority: "high",
632
+ variables: ["downloadUrl", "expiryHours"],
633
+ defaultEnabled: true
634
+ },
635
+ // Activity Events
636
+ ITEM_CREATED: {
637
+ type: "ITEM_CREATED",
638
+ name: "Item Created",
639
+ description: "Generic item creation notification",
640
+ category: "activity",
641
+ notificationType: "success",
642
+ priority: "low",
643
+ variables: ["entityType", "entityName", "entityId"],
644
+ defaultEnabled: true
645
+ },
646
+ ITEM_UPDATED: {
647
+ type: "ITEM_UPDATED",
648
+ name: "Item Updated",
649
+ description: "Generic item update notification",
650
+ category: "activity",
651
+ notificationType: "info",
652
+ priority: "low",
653
+ variables: ["entityType", "entityName", "entityId", "changes"],
654
+ defaultEnabled: true
655
+ },
656
+ ITEM_DELETED: {
657
+ type: "ITEM_DELETED",
658
+ name: "Item Deleted",
659
+ description: "Generic item deletion notification",
660
+ category: "activity",
661
+ notificationType: "info",
662
+ priority: "low",
663
+ variables: ["entityType", "entityName"],
664
+ defaultEnabled: true
665
+ },
666
+ BULK_OPERATION_COMPLETE: {
667
+ type: "BULK_OPERATION_COMPLETE",
668
+ name: "Bulk Operation Complete",
669
+ description: "Bulk operation completion notification",
670
+ category: "activity",
671
+ notificationType: "success",
672
+ priority: "normal",
673
+ variables: ["operationType", "successCount", "totalCount", "failedCount"],
674
+ defaultEnabled: true
675
+ }
676
+ };
677
+ class EventRegistry {
678
+ events = /* @__PURE__ */ new Map();
679
+ customEvents = /* @__PURE__ */ new Map();
680
+ constructor() {
681
+ Object.values(STANDARD_EVENTS).forEach((event) => {
682
+ this.events.set(event.type, event);
683
+ });
684
+ }
685
+ /**
686
+ * Register a custom event
687
+ */
688
+ register(event) {
689
+ this.customEvents.set(event.type, event);
690
+ this.events.set(event.type, event);
691
+ }
692
+ /**
693
+ * Unregister a custom event
694
+ */
695
+ unregister(eventType) {
696
+ if (this.customEvents.has(eventType)) {
697
+ this.customEvents.delete(eventType);
698
+ this.events.delete(eventType);
699
+ return true;
700
+ }
701
+ return false;
702
+ }
703
+ /**
704
+ * Get event definition by type
705
+ */
706
+ get(eventType) {
707
+ return this.events.get(eventType);
708
+ }
709
+ /**
710
+ * Check if event type exists
711
+ */
712
+ has(eventType) {
713
+ return this.events.has(eventType);
714
+ }
715
+ /**
716
+ * Get all events
717
+ */
718
+ getAll() {
719
+ return Array.from(this.events.values());
720
+ }
721
+ /**
722
+ * Get events by category
723
+ */
724
+ getByCategory(category) {
725
+ return this.getAll().filter((e) => e.category === category);
726
+ }
727
+ /**
728
+ * Get all custom events
729
+ */
730
+ getCustomEvents() {
731
+ return Array.from(this.customEvents.values());
732
+ }
733
+ /**
734
+ * Get all standard events
735
+ */
736
+ getStandardEvents() {
737
+ return Object.values(STANDARD_EVENTS);
738
+ }
739
+ /**
740
+ * Check if event type is standard
741
+ */
742
+ isStandardEvent(eventType) {
743
+ return eventType in STANDARD_EVENTS;
744
+ }
745
+ /**
746
+ * Reset registry to standard events only
747
+ */
748
+ reset() {
749
+ this.customEvents.clear();
750
+ this.events.clear();
751
+ Object.values(STANDARD_EVENTS).forEach((event) => {
752
+ this.events.set(event.type, event);
753
+ });
754
+ }
755
+ }
756
+ const eventRegistry = new EventRegistry();
757
+ function getEventDefinition(eventType) {
758
+ return eventRegistry.get(eventType);
759
+ }
760
+ function getEventsByCategory(category) {
761
+ return eventRegistry.getByCategory(category);
762
+ }
763
+ function registerCustomEvent(event) {
764
+ eventRegistry.register(event);
765
+ }
766
+ function getAllEventTypes() {
767
+ return eventRegistry.getAll().map((e) => e.type);
768
+ }
769
+ function useNotificationEvents(options) {
770
+ const { appName, userId, onCreateNotification, debug = false } = options;
771
+ const processEvent = useCallback(
772
+ async (payload) => {
773
+ const { type, userId: payloadUserId, data, titleOverride, messageOverride, actionUrl, actionText, metadata } = payload;
774
+ const targetUserId = payloadUserId || userId;
775
+ if (!targetUserId) {
776
+ if (debug) {
777
+ console.warn("[notification-events] No userId provided for event:", type);
778
+ }
779
+ return;
780
+ }
781
+ const eventDef = getEventDefinition(type);
782
+ if (!eventDef) {
783
+ if (debug) {
784
+ console.warn("[notification-events] Unknown event type:", type);
785
+ }
786
+ return;
787
+ }
788
+ const template = getTemplateByEventType(type);
789
+ const context = {
790
+ appName,
791
+ ...data
792
+ };
793
+ let title;
794
+ let message;
795
+ if (titleOverride) {
796
+ title = titleOverride;
797
+ } else if (template) {
798
+ title = interpolate(template.title, context);
799
+ } else {
800
+ title = eventDef.name;
801
+ }
802
+ if (messageOverride) {
803
+ message = messageOverride;
804
+ } else if (template) {
805
+ message = interpolate(template.message, context);
806
+ } else {
807
+ message = `${eventDef.description}`;
808
+ }
809
+ const notificationInput = {
810
+ userId: targetUserId,
811
+ title,
812
+ message,
813
+ type: template?.type || eventDef.notificationType,
814
+ category: eventDef.category,
815
+ source: "event",
816
+ eventType: type,
817
+ isImportant: template?.isImportant,
818
+ actionUrl: actionUrl || (template?.actionUrl ? interpolate(template.actionUrl, context) : void 0),
819
+ actionText: actionText || template?.actionText,
820
+ metadata: {
821
+ ...metadata,
822
+ eventData: data
823
+ }
824
+ };
825
+ if (debug) {
826
+ console.log("[notification-events] Creating notification:", notificationInput);
827
+ }
828
+ await onCreateNotification(notificationInput);
829
+ },
830
+ [appName, userId, onCreateNotification, debug]
831
+ );
832
+ const trigger = useCallback(
833
+ async (payload) => {
834
+ await processEvent(payload);
835
+ },
836
+ [processEvent]
837
+ );
838
+ const triggerAccountCreated = useCallback(
839
+ async (data) => {
840
+ if (!userId) return;
841
+ await trigger({
842
+ type: "ACCOUNT_CREATED",
843
+ userId,
844
+ data
845
+ });
846
+ },
847
+ [userId, trigger]
848
+ );
849
+ const triggerNewDeviceSignin = useCallback(
850
+ async (data) => {
851
+ if (!userId) return;
852
+ await trigger({
853
+ type: "NEW_DEVICE_SIGNIN",
854
+ userId,
855
+ data: {
856
+ ...data,
857
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
858
+ }
859
+ });
860
+ },
861
+ [userId, trigger]
862
+ );
863
+ const triggerPasswordChanged = useCallback(async () => {
864
+ if (!userId) return;
865
+ await trigger({
866
+ type: "PASSWORD_CHANGED",
867
+ userId,
868
+ data: {
869
+ timestamp: (/* @__PURE__ */ new Date()).toLocaleString()
870
+ }
871
+ });
872
+ }, [userId, trigger]);
873
+ const triggerProfileUpdated = useCallback(
874
+ async (data) => {
875
+ if (!userId) return;
876
+ await trigger({
877
+ type: "PROFILE_UPDATED",
878
+ userId,
879
+ data: {
880
+ changes: data.changes.join(", ")
881
+ }
882
+ });
883
+ },
884
+ [userId, trigger]
885
+ );
886
+ const triggerCrudEvent = useCallback(
887
+ async (data) => {
888
+ if (!userId) return;
889
+ const eventTypeMap = {
890
+ created: "ITEM_CREATED",
891
+ updated: "ITEM_UPDATED",
892
+ deleted: "ITEM_DELETED"
893
+ };
894
+ await trigger({
895
+ type: eventTypeMap[data.action],
896
+ userId,
897
+ data: {
898
+ entityType: data.entityType,
899
+ entityName: data.entityName
900
+ }
901
+ });
902
+ },
903
+ [userId, trigger]
904
+ );
905
+ const triggerAppTip = useCallback(
906
+ async (data) => {
907
+ if (!userId) return;
908
+ await trigger({
909
+ type: "APP_TIP",
910
+ userId,
911
+ data: {
912
+ tipTitle: data.title,
913
+ tipBody: data.body
914
+ },
915
+ metadata: {
916
+ tipId: data.tipId
917
+ }
918
+ });
919
+ },
920
+ [userId, trigger]
921
+ );
922
+ return {
923
+ trigger,
924
+ triggerAccountCreated,
925
+ triggerNewDeviceSignin,
926
+ triggerPasswordChanged,
927
+ triggerProfileUpdated,
928
+ triggerCrudEvent,
929
+ triggerAppTip
930
+ };
931
+ }
932
+ export {
933
+ ACCOUNT_TEMPLATES as A,
934
+ PROMOTIONAL_TEMPLATES as P,
935
+ REPORT_TEMPLATES as R,
936
+ SYSTEM_TEMPLATES as S,
937
+ interpolateWithFormatters as a,
938
+ ACTIVITY_TEMPLATES as b,
939
+ ALL_STANDARD_TEMPLATES as c,
940
+ defaultFormatters as d,
941
+ extractVariables as e,
942
+ getTemplatesByCategory as f,
943
+ getTemplateByEventType as g,
944
+ getEnabledTemplates as h,
945
+ interpolate as i,
946
+ STANDARD_EVENTS as j,
947
+ eventRegistry as k,
948
+ getEventDefinition as l,
949
+ getEventsByCategory as m,
950
+ getAllEventTypes as n,
951
+ registerCustomEvent as r,
952
+ useNotificationEvents as u,
953
+ validateContext as v
954
+ };
955
+ //# sourceMappingURL=useNotificationEvents-D8DVxah1.js.map