@kumori/aurora-backend-handler 1.1.6 → 1.1.7

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,10 @@
1
- import { Notification, Plan, Tenant, UserData, tenantRole } from "@kumori/aurora-interfaces";
2
-
3
-
1
+ import {
2
+ Notification,
3
+ Plan,
4
+ Tenant,
5
+ UserData,
6
+ tenantRole,
7
+ } from "@kumori/aurora-interfaces";
4
8
 
5
9
  interface HandleUserEventParams {
6
10
  eventData: any;
@@ -34,46 +38,62 @@ export const handleUserEvent = ({
34
38
  const userId = eventData.id.name;
35
39
  const userTenants = Object.keys(eventData.status.tenants);
36
40
  const deletedTenantKeys: string[] = [];
37
- Object.entries(eventData.status.tenants).forEach(([tenantId, tenantInfo]: [string, any]) => {
38
- if (tenantInfo.status === "rejected") {
39
- const tenant = tenantsMap.get(tenantId);
40
- if (tenant) {
41
- tenantsMap.set(tenantId, { ...tenant, status: "leaving" });
41
+ Object.entries(eventData.status.tenants).forEach(
42
+ ([tenantId, tenantInfo]: [string, any]) => {
43
+ if (tenantInfo.status === "rejected") {
44
+ const tenant = tenantsMap.get(tenantId);
45
+ if (tenant) {
46
+ tenantsMap.set(tenantId, { ...tenant, status: "leaving" });
47
+ }
42
48
  }
43
- }
44
- });
49
+ },
50
+ );
45
51
  for (const key of tenantsMap.keys()) {
46
52
  if (!userTenants.includes(key)) {
47
53
  const tenantToDelete = tenantsMap.get(key);
48
54
  if (tenantToDelete) {
49
- const onlyOneUser = tenantToDelete.users.length === 1;
50
- const isSoloOwner = onlyOneUser && tenantToDelete.users[0].role === tenantRole.OWNER;
55
+ const currentUserInTenant = tenantToDelete.users.find(
56
+ (u) => u.id === userId,
57
+ );
58
+ const isRejectedOrLeaving =
59
+ currentUserInTenant?.status === "rejected" ||
60
+ tenantToDelete.status === "leaving";
51
61
 
52
- if (isSoloOwner) {
53
- eventHelper.tenant.publish.deleted(tenantToDelete);
54
- const tenantDeletedNotification: Notification = {
55
- type: "success",
56
- subtype: "tenant-deleted",
57
- date: Date.now().toString(),
58
- callToAction: false,
59
- status: "unread",
60
- data: {
61
- tenant: tenantToDelete.name,
62
- },
63
- };
64
- eventHelper.notification.publish.creation(tenantDeletedNotification);
65
- } else {
66
- const userRemovedNotification: Notification = {
67
- type: "info",
68
- subtype: "user-removed-from-tenant",
69
- date: Date.now().toString(),
70
- callToAction: false,
71
- status: "unread",
72
- data: {
73
- tenant: tenantToDelete.name,
74
- },
75
- };
76
- eventHelper.notification.publish.creation(userRemovedNotification);
62
+ if (currentUserInTenant && !isRejectedOrLeaving) {
63
+ const onlyOneUser = tenantToDelete.users.length === 1;
64
+ const isSoloOwner =
65
+ onlyOneUser &&
66
+ currentUserInTenant.role === tenantRole.OWNER &&
67
+ currentUserInTenant.id === userId;
68
+
69
+ if (isSoloOwner) {
70
+ eventHelper.tenant.publish.deleted(tenantToDelete);
71
+ const tenantDeletedNotification: Notification = {
72
+ type: "success",
73
+ subtype: "tenant-deleted",
74
+ date: Date.now().toString(),
75
+ callToAction: false,
76
+ status: "unread",
77
+ data: {
78
+ tenant: tenantToDelete.name,
79
+ },
80
+ };
81
+ eventHelper.notification.publish.creation(
82
+ tenantDeletedNotification,
83
+ );
84
+ } else {
85
+ const userRemovedNotification: Notification = {
86
+ type: "info",
87
+ subtype: "user-removed-from-tenant",
88
+ date: Date.now().toString(),
89
+ callToAction: false,
90
+ status: "unread",
91
+ data: {
92
+ tenant: tenantToDelete.name,
93
+ },
94
+ };
95
+ eventHelper.notification.publish.creation(userRemovedNotification);
96
+ }
77
97
  }
78
98
  deletedTenantKeys.push(key);
79
99
  }
@@ -102,14 +122,14 @@ export const handleUserEvent = ({
102
122
  };
103
123
  userPlans.push(basicPlan);
104
124
  }
105
- }
125
+ },
106
126
  );
107
127
  }
108
128
  const tempProviders: Record<string, string> = eventData.spec.providers || {};
109
129
  const providers: { name: string; email: string; password?: string }[] = [];
110
130
 
111
131
  const existingProvidersMap = new Map(
112
- (currentUserData.provider || []).map((p) => [p.name, p])
132
+ (currentUserData.provider || []).map((p) => [p.name, p]),
113
133
  );
114
134
 
115
135
  for (const [providerName, providerId] of Object.entries(tempProviders)) {
@@ -149,18 +169,18 @@ export const handleUserEvent = ({
149
169
  };
150
170
  };
151
171
  export const handleUserOperationError = (): UserData => {
152
- return {
153
- id: "",
154
- name: "",
155
- surname: "",
156
- provider: [],
157
- notificationsEnabled: "",
158
- organizations: [],
159
- clusterTokens: [],
160
- tokens: [],
161
- tenants: [],
162
- axebowPlan: "freemium",
163
- companyName: "",
164
- rol: "",
165
- };
172
+ return {
173
+ id: "",
174
+ name: "",
175
+ surname: "",
176
+ provider: [],
177
+ notificationsEnabled: "",
178
+ organizations: [],
179
+ clusterTokens: [],
180
+ tokens: [],
181
+ tenants: [],
182
+ axebowPlan: "freemium",
183
+ companyName: "",
184
+ rol: "",
185
+ };
166
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -192,7 +192,6 @@ const REPORTING_ITERATIONS = 5;
192
192
  const REPORTING_INTERVAL = 1000;
193
193
  let hasLoadedReportingOnce = false;
194
194
  let recentlyUpdatedServices = new Map<string, Service>();
195
- let pendingTenantStatus = new Map<string, string>();
196
195
  /**
197
196
  * Helper function to safely stringify error objects
198
197
  */
@@ -640,18 +639,6 @@ const handleEvent = async (message: WSMessage) => {
640
639
  parseKeyPath,
641
640
  eventHelper,
642
641
  });
643
- Object.entries(eventData.status.tenants).forEach(
644
- ([tenantId, tenantInfo]: [string, any]) => {
645
- if (tenantInfo.status === "rejected") {
646
- const tenant = tenantsMap.get(tenantId);
647
- if (tenant) {
648
- tenantsMap.set(tenantId, { ...tenant, status: "leaving" });
649
- } else {
650
- pendingTenantStatus.set(tenantId, "leaving");
651
- }
652
- }
653
- },
654
- );
655
642
  userData = userEventResult.userData;
656
643
  tempProviders = userEventResult.tempProviders;
657
644
  userEventResult.deletedTenantKeys.forEach((key) => {
@@ -863,12 +850,6 @@ const handleEvent = async (message: WSMessage) => {
863
850
  }
864
851
 
865
852
  tenantsMap.set(entityId, newTenant);
866
- if (pendingTenantStatus.has(entityId)) {
867
- const pendingStatus = pendingTenantStatus.get(entityId)!;
868
- tenantsMap.set(entityId, { ...newTenant, status: pendingStatus });
869
- pendingTenantStatus.delete(entityId);
870
- }
871
-
872
853
  loadMarketplaceItemsForTenant(entityId, "") //TODO Move to helper
873
854
  .then((items) => {
874
855
  const tenant = tenantsMap.get(entityId);
@@ -971,17 +952,13 @@ const handleEvent = async (message: WSMessage) => {
971
952
  break;
972
953
 
973
954
  case "ca":
974
- const caResult = handleCAEvent(
975
- eventData,
976
- parentParts,
977
- tenantsMap,
978
- hasRequestingServices,
979
- );
955
+ const caResult = handleCAEvent(eventData, parentParts, tenantsMap, hasRequestingServices,);
980
956
  processResourceResult(
981
957
  caResult,
982
958
  tenantsMap,
983
959
  pendingDomains,
984
960
  eventHelper,
961
+
985
962
  );
986
963
  break;
987
964