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