@kumori/aurora-backend-handler 1.1.83 → 1.1.84

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,4 +1,4 @@
1
- import { ClusterToken, Token, UserData } from "@kumori/aurora-interfaces";
1
+ import { ClusterToken, errors, Notification, Token, UserData } from "@kumori/aurora-interfaces";
2
2
 
3
3
 
4
4
  interface HandleTokenEventParams {
@@ -107,4 +107,53 @@ export const handleTokenOperationSuccess = ({
107
107
  return {
108
108
  token: tokenWithData,
109
109
  };
110
+ };
111
+ interface HandleTokenDeletionParams {
112
+ tokenId: string;
113
+ tokenMap: Map<string, Token>;
114
+ userData: UserData;
115
+ }
116
+
117
+ interface HandleTokenDeletionResult {
118
+ removed: boolean;
119
+ updatedUserTokens: Token[];
120
+ notification: Notification | null;
121
+ }
122
+
123
+ export const handleTokenDeletion = ({
124
+ tokenId,
125
+ tokenMap,
126
+ userData,
127
+ }: HandleTokenDeletionParams): HandleTokenDeletionResult => {
128
+ const tokenIndex = userData.tokens.findIndex((t) => t.name === tokenId);
129
+ if (tokenIndex === -1) {
130
+ return {
131
+ removed: false,
132
+ updatedUserTokens: userData.tokens,
133
+ notification: null,
134
+ };
135
+ }
136
+
137
+ const deletedToken = userData.tokens[tokenIndex];
138
+ const updatedUserTokens = [...userData.tokens];
139
+ updatedUserTokens.splice(tokenIndex, 1);
140
+ tokenMap.delete(tokenId);
141
+
142
+ const notification: Notification = {
143
+ type: "success",
144
+ subtype: errors.user.tokenDeleted.subtype,
145
+ date: Date.now().toString(),
146
+ status: "unread",
147
+ callToAction: false,
148
+ data: {
149
+ tokenName: deletedToken.name,
150
+ tenant: deletedToken.tenant,
151
+ },
152
+ };
153
+
154
+ return {
155
+ removed: true,
156
+ updatedUserTokens,
157
+ notification,
158
+ };
110
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.83",
3
+ "version": "1.1.84",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -70,6 +70,7 @@ import {
70
70
  } from "./helpers/plan-helper";
71
71
  import { handleRegistryEvent } from "./helpers/registry-helper";
72
72
  import {
73
+ handleTokenDeletion,
73
74
  handleTokenEvent,
74
75
  handleTokenOperationSuccess,
75
76
  } from "./helpers/token-helper";
@@ -1513,12 +1514,16 @@ const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1513
1514
  if (action === "DELETE") {
1514
1515
  const deletedTokenId = entityName.split("/").pop();
1515
1516
  if (deletedTokenId) {
1516
- tokenMap.delete(deletedTokenId);
1517
- const tokenIndex = userData.tokens.findIndex(
1518
- (t) => t.name === deletedTokenId,
1519
- );
1520
- if (tokenIndex !== -1) {
1521
- userData.tokens.splice(tokenIndex, 1);
1517
+ const tokenDeletionResult = handleTokenDeletion({
1518
+ tokenId: deletedTokenId,
1519
+ tokenMap,
1520
+ userData,
1521
+ });
1522
+ if (tokenDeletionResult.removed) {
1523
+ userData.tokens = tokenDeletionResult.updatedUserTokens;
1524
+ eventHelper.notification.publish.creation(
1525
+ tokenDeletionResult.notification!,
1526
+ );
1522
1527
  }
1523
1528
  }
1524
1529
  } else {
@@ -1907,24 +1912,16 @@ const handleDeleteEvent = async (message: WSMessage) => {
1907
1912
  }
1908
1913
  }
1909
1914
  if (keyParts.token && keyParts.user) {
1910
- const tokenId = keyParts.token;
1911
- const tokenIndex = userData.tokens.findIndex((t) => t.name === tokenId);
1912
- if (tokenIndex !== -1) {
1913
- const deletedToken = userData.tokens[tokenIndex];
1914
- userData.tokens.splice(tokenIndex, 1);
1915
- tokenMap.delete(tokenId);
1916
- const tokenNotification: Notification = {
1917
- type: "success",
1918
- subtype: errors.user.tokenDeleted.subtype,
1919
- date: Date.now().toString(),
1920
- status: "unread",
1921
- callToAction: false,
1922
- data: {
1923
- tokenName: deletedToken.name,
1924
- tenant: deletedToken.tenant,
1925
- },
1926
- };
1927
- eventHelper.notification.publish.creation(tokenNotification);
1915
+ const tokenDeletionResult = handleTokenDeletion({
1916
+ tokenId: keyParts.token,
1917
+ tokenMap,
1918
+ userData,
1919
+ });
1920
+ if (tokenDeletionResult.removed) {
1921
+ userData.tokens = tokenDeletionResult.updatedUserTokens;
1922
+ eventHelper.notification.publish.creation(
1923
+ tokenDeletionResult.notification!,
1924
+ );
1928
1925
  }
1929
1926
  }
1930
1927
  rebuildHierarchy();