@wipperoz/wipperoz-core 1.0.11 → 1.0.12

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.
@@ -0,0 +1,26 @@
1
+ import { JsonValue } from '@wipperoz/common-utils';
2
+ import { JSONObject } from '@wipperoz/common-utils/dist/lib/utils';
3
+ import { NotificationCategoryEnum, NotificationPriorityEnum, NotificationSeverityEnum } from '@wipperoz/common-entities/dist/src/enums';
4
+ type MetadataLeaf = string | number | boolean | null | Date;
5
+ type NotificationMetadata = Record<string, MetadataLeaf | JsonValue | JSONObject | MetadataLeaf[] | JsonValue[] | JSONObject[] | Record<string, MetadataLeaf | JsonValue | JSONObject>>;
6
+ export interface BellNotificationPayload {
7
+ userId: string;
8
+ id: string;
9
+ title: string;
10
+ message: string;
11
+ category?: NotificationCategoryEnum;
12
+ priority?: NotificationPriorityEnum;
13
+ severity?: NotificationSeverityEnum;
14
+ metadata?: NotificationMetadata;
15
+ read?: boolean;
16
+ dismissible?: boolean;
17
+ autoClose?: boolean;
18
+ channels?: Partial<Record<'websocket' | 'email' | 'push', boolean>>;
19
+ }
20
+ /**
21
+ * Send a generic bell notification (Notification Center).
22
+ * This creates a persistent notification in the user's notification center.
23
+ */
24
+ export declare function sendBellNotification(notification: BellNotificationPayload): Promise<void>;
25
+ export {};
26
+ //# sourceMappingURL=sendWebSocketNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendWebSocketNotification.d.ts","sourceRoot":"","sources":["../../src/utils/sendWebSocketNotification.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAC,UAAU,EAAC,MAAM,uCAAuC,CAAC;AACjE,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,0CAA0C,CAAC;AAElD,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5D,KAAK,oBAAoB,GAAG,MAAM,CAChC,MAAM,EACJ,YAAY,GACZ,SAAS,GACT,UAAU,GACV,YAAY,EAAE,GACd,SAAS,EAAE,GACX,UAAU,EAAE,GACZ,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC,CACxD,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,GAAG,OAAO,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrE;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,YAAY,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsE/F"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendBellNotification = sendBellNotification;
4
+ const client_sns_1 = require("@aws-sdk/client-sns");
5
+ const enums_1 = require("@wipperoz/common-entities/dist/src/enums");
6
+ /**
7
+ * Send a generic bell notification (Notification Center).
8
+ * This creates a persistent notification in the user's notification center.
9
+ */
10
+ async function sendBellNotification(notification) {
11
+ const snsTopicArn = process.env.WEBSOCKET_SNS_TOPIC_ARN;
12
+ if (!snsTopicArn) {
13
+ console.warn('[sendBellNotification] WEBSOCKET_SNS_TOPIC_ARN not configured, skipping bell notification');
14
+ return;
15
+ }
16
+ const snsClient = new client_sns_1.SNSClient({
17
+ region: process.env.AWS_REGION ?? 'us-east-1',
18
+ });
19
+ const channels = {
20
+ websocket: notification.channels?.websocket ?? true,
21
+ email: notification.channels?.email ?? false,
22
+ push: notification.channels?.push ?? false,
23
+ };
24
+ if (!channels.websocket && !channels.email && !channels.push) {
25
+ console.warn('[sendBellNotification] At least one channel must be enabled, skipping bell notification');
26
+ return;
27
+ }
28
+ const bellNotification = {
29
+ type: 'NOTIFICATION',
30
+ userId: notification.userId,
31
+ timestamp: Date.now(),
32
+ channels,
33
+ data: {
34
+ title: notification.title,
35
+ message: notification.message,
36
+ category: notification.category ?? enums_1.NotificationCategoryEnum.GENERAL,
37
+ priority: notification.priority ?? enums_1.NotificationPriorityEnum.MEDIUM,
38
+ severity: notification.severity ?? enums_1.NotificationSeverityEnum.INFO,
39
+ read: notification.read ?? false,
40
+ dismissible: notification.dismissible ?? true,
41
+ autoClose: notification.autoClose ?? false,
42
+ metadata: {
43
+ id: notification.id,
44
+ ...(notification.metadata ?? {}),
45
+ },
46
+ },
47
+ };
48
+ try {
49
+ const command = new client_sns_1.PublishCommand({
50
+ TopicArn: snsTopicArn,
51
+ Message: JSON.stringify(bellNotification),
52
+ MessageAttributes: {
53
+ messageType: {
54
+ DataType: 'String',
55
+ StringValue: 'NOTIFICATION',
56
+ },
57
+ userId: {
58
+ DataType: 'String',
59
+ StringValue: notification.userId,
60
+ },
61
+ },
62
+ });
63
+ await snsClient.send(command);
64
+ console.log('[sendBellNotification] Bell notification sent:', {
65
+ userId: notification.userId,
66
+ id: notification.id,
67
+ title: notification.title,
68
+ });
69
+ }
70
+ catch (error) {
71
+ console.error('[sendBellNotification] Failed to send notification:', error);
72
+ // Don't throw - notification failures shouldn't break the main flow
73
+ }
74
+ }
75
+ //# sourceMappingURL=sendWebSocketNotification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendWebSocketNotification.js","sourceRoot":"","sources":["../../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Y,CAAC,QAAQ,IAAI,gCAAwB,CAAC,IAAI;YAChE,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,KAAK;YAChC,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,IAAI;YAC7C,SAAS,EAAE,YAAY,CAAC,SAAS,IAAI,KAAK;YAC1C,QAAQ,EAAE;gBACR,EAAE,EAAE,YAAY,CAAC,EAAE;gBACnB,GAAG,CAAC,YAAY,CAAC,QAAQ,IAAI,EAAE,CAAC;aACjC;SACF;KACF,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,2BAAc,CAAC;YACjC,QAAQ,EAAE,WAAW;YACrB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACzC,iBAAiB,EAAE;gBACjB,WAAW,EAAE;oBACX,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,cAAc;iBAC5B;gBACD,MAAM,EAAE;oBACN,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,YAAY,CAAC,MAAM;iBACjC;aACF;SACF,CAAC,CAAC;QAEH,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,gDAAgD,EAAE;YAC5D,MAAM,EAAE,YAAY,CAAC,MAAM;YAC3B,EAAE,EAAE,YAAY,CAAC,EAAE;YACnB,KAAK,EAAE,YAAY,CAAC,KAAK;SAC1B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,KAAK,CAAC,CAAC;QAC5E,oEAAoE;IACtE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipperoz/wipperoz-core",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {