@kumori/aurora-backend-handler 1.1.5 → 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,31 +38,33 @@ 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 currentUserInTenant = tenantToDelete.users.find((u) => u.id === userId);
50
- console.log(`[handleUserEvent DEBUG] Processing missing tenant: ${key}`, {
51
- tenantName: tenantToDelete.name,
52
- tenantStatus: tenantToDelete.status,
53
- currentUserInTenantStatus: currentUserInTenant?.status,
54
- onlyOneUser: tenantToDelete.users.length === 1
55
- });
56
- if (currentUserInTenant?.status !== "rejected") {
55
+ const currentUserInTenant = tenantToDelete.users.find(
56
+ (u) => u.id === userId,
57
+ );
58
+ const isRejectedOrLeaving =
59
+ currentUserInTenant?.status === "rejected" ||
60
+ tenantToDelete.status === "leaving";
61
+
62
+ if (currentUserInTenant && !isRejectedOrLeaving) {
57
63
  const onlyOneUser = tenantToDelete.users.length === 1;
58
64
  const isSoloOwner =
59
- onlyOneUser && tenantToDelete.users[0].role === tenantRole.OWNER;
60
-
61
- console.log(`[handleUserEvent DEBUG] Notification will be sent. isSoloOwner: ${isSoloOwner}`);
65
+ onlyOneUser &&
66
+ currentUserInTenant.role === tenantRole.OWNER &&
67
+ currentUserInTenant.id === userId;
62
68
 
63
69
  if (isSoloOwner) {
64
70
  eventHelper.tenant.publish.deleted(tenantToDelete);
@@ -72,7 +78,9 @@ export const handleUserEvent = ({
72
78
  tenant: tenantToDelete.name,
73
79
  },
74
80
  };
75
- eventHelper.notification.publish.creation(tenantDeletedNotification);
81
+ eventHelper.notification.publish.creation(
82
+ tenantDeletedNotification,
83
+ );
76
84
  } else {
77
85
  const userRemovedNotification: Notification = {
78
86
  type: "info",
@@ -114,14 +122,14 @@ export const handleUserEvent = ({
114
122
  };
115
123
  userPlans.push(basicPlan);
116
124
  }
117
- }
125
+ },
118
126
  );
119
127
  }
120
128
  const tempProviders: Record<string, string> = eventData.spec.providers || {};
121
129
  const providers: { name: string; email: string; password?: string }[] = [];
122
130
 
123
131
  const existingProvidersMap = new Map(
124
- (currentUserData.provider || []).map((p) => [p.name, p])
132
+ (currentUserData.provider || []).map((p) => [p.name, p]),
125
133
  );
126
134
 
127
135
  for (const [providerName, providerId] of Object.entries(tempProviders)) {
@@ -161,18 +169,18 @@ export const handleUserEvent = ({
161
169
  };
162
170
  };
163
171
  export const handleUserOperationError = (): UserData => {
164
- return {
165
- id: "",
166
- name: "",
167
- surname: "",
168
- provider: [],
169
- notificationsEnabled: "",
170
- organizations: [],
171
- clusterTokens: [],
172
- tokens: [],
173
- tenants: [],
174
- axebowPlan: "freemium",
175
- companyName: "",
176
- rol: "",
177
- };
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
+ };
178
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {