@kumori/aurora-backend-handler 1.0.127 → 1.0.128

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.
@@ -1,6 +1,50 @@
1
- import { Tenant, tenantRole, User, UserData } from "@kumori/aurora-interfaces";
1
+ import {
2
+ errors,
3
+ Notification,
4
+ Tenant,
5
+ tenantRole,
6
+ User,
7
+ UserData,
8
+ } from "@kumori/aurora-interfaces";
2
9
  import { parseKeyPath } from "../utils/utils";
3
10
 
11
+ const tenantInvitationNotifications = new Map<string, Notification>();
12
+
13
+ export const dismissTenantInvitationNotification = (
14
+ tenantId: string,
15
+ eventHelper: any,
16
+ ): void => {
17
+ const notification = tenantInvitationNotifications.get(tenantId);
18
+ if (!notification) return;
19
+ tenantInvitationNotifications.delete(tenantId);
20
+ eventHelper.notification.publish.deletion(notification);
21
+ };
22
+
23
+ export const syncTenantInvitationNotification = (
24
+ tenant: Tenant,
25
+ userId: string,
26
+ eventHelper: any,
27
+ ): void => {
28
+ const isInvitationPending = tenant.users?.some(
29
+ (u) => u.id === userId && u.status === "pending",
30
+ );
31
+ if (!isInvitationPending) {
32
+ dismissTenantInvitationNotification(tenant.id, eventHelper);
33
+ return;
34
+ }
35
+ if (tenantInvitationNotifications.has(tenant.id)) return;
36
+ const invitationReceivedNotification: Notification = {
37
+ type: "info",
38
+ subtype: errors.tenant.invitationReceived.subtype,
39
+ date: Date.now().toString(),
40
+ status: "unread",
41
+ notificationType: "regular",
42
+ data: { tenant: tenant.name },
43
+ };
44
+ tenantInvitationNotifications.set(tenant.id, invitationReceivedNotification);
45
+ eventHelper.notification.publish.creation(invitationReceivedNotification);
46
+ };
47
+
4
48
  export const handleTenantEvent: (
5
49
  entityId: string,
6
50
  eventData: any,
@@ -7,6 +7,7 @@ import {
7
7
  tenantRole,
8
8
  UserStatus
9
9
  } from "@kumori/aurora-interfaces";
10
+ import { dismissTenantInvitationNotification } from "./tenant-helper";
10
11
 
11
12
  interface HandleUserEventParams {
12
13
  eventData: any;
@@ -87,6 +88,7 @@ export const handleUserEvent = ({
87
88
  eventHelper.notification.publish.creation(userRemovedNotification);
88
89
  }
89
90
  }
91
+ dismissTenantInvitationNotification(key, eventHelper);
90
92
  deletedTenantKeys.push(key);
91
93
  }
92
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.0.127",
3
+ "version": "1.0.128",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "glob": "^11.0.0"
12
12
  },
13
13
  "dependencies": {
14
- "@kumori/aurora-interfaces": "1.0.37",
14
+ "@kumori/aurora-interfaces": "1.0.38",
15
15
  "@kumori/kumori-dsl-generator": "1.0.11",
16
16
  "@kumori/kumori-module-generator": "^1.1.6",
17
17
  "ts-node": "^10.9.2",
@@ -28,6 +28,7 @@ import { getReporting } from "./api/reporting-api-service";
28
28
  import { parseKeyPath } from "./utils/utils";
29
29
  import {
30
30
  handleTenantEvent,
31
+ syncTenantInvitationNotification,
31
32
  handleTenantOperationSuccess,
32
33
  } from "./helpers/tenant-helper";
33
34
  import {
@@ -1022,6 +1023,7 @@ const handleEvent = async (message: WSMessage) => {
1022
1023
  }
1023
1024
 
1024
1025
  tenantsMap.set(entityId, newTenant);
1026
+ syncTenantInvitationNotification(newTenant, userData.id, eventHelper);
1025
1027
  if (pendingTenantStatus.has(entityId)) {
1026
1028
  const pendingStatus = pendingTenantStatus.get(entityId)!;
1027
1029
  tenantsMap.set(entityId, { ...newTenant, status: pendingStatus });