@kumori/aurora-backend-handler 1.0.131 → 1.0.133
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,5 @@
|
|
|
1
1
|
import { Account, errors, Notification } from "@kumori/aurora-interfaces";
|
|
2
|
+
import { AccountStatus } from "@kumori/aurora-interfaces/enums/accountStatusEnum";
|
|
2
3
|
import {
|
|
3
4
|
initializeGlobalWebSocketClient,
|
|
4
5
|
getWebSocketStatus,
|
|
@@ -621,7 +622,10 @@ export const createAccount = async (account: Account, security: Security) => {
|
|
|
621
622
|
"account",
|
|
622
623
|
account,
|
|
623
624
|
);
|
|
624
|
-
const updatedAccount: Account = {
|
|
625
|
+
const updatedAccount: Account = {
|
|
626
|
+
...account,
|
|
627
|
+
status: AccountStatus.ACTIVE,
|
|
628
|
+
};
|
|
625
629
|
eventHelper.account.publish.created(updatedAccount);
|
|
626
630
|
return response;
|
|
627
631
|
} catch (error) {
|
|
@@ -128,11 +128,13 @@ const extractCloudProviderCredentials = (
|
|
|
128
128
|
*
|
|
129
129
|
* Priority order:
|
|
130
130
|
* 1. Soft-deleted accounts → 'deleting'
|
|
131
|
-
* 2. validCredentials
|
|
131
|
+
* 2. No validCredentials object in the event → 'pending' (the
|
|
132
|
+
* credentials have not been validated yet)
|
|
133
|
+
* 3. validCredentials status reported by the backend (covers both
|
|
132
134
|
* success and the async credential-validation path)
|
|
133
|
-
*
|
|
135
|
+
* 4. Keep the existing status so we never regress a terminal state
|
|
134
136
|
* (e.g. don't overwrite 'invalid_credentials' with 'pending')
|
|
135
|
-
*
|
|
137
|
+
* 5. Default to 'pending' for brand-new accounts
|
|
136
138
|
*/
|
|
137
139
|
const determineAccountStatus = (
|
|
138
140
|
eventData: any,
|
|
@@ -141,6 +143,9 @@ const determineAccountStatus = (
|
|
|
141
143
|
if (eventData.meta?.deleted) {
|
|
142
144
|
return "deleting";
|
|
143
145
|
}
|
|
146
|
+
if (!eventData.status?.validCredentials) {
|
|
147
|
+
return "pending";
|
|
148
|
+
}
|
|
144
149
|
const rawStatus: string | undefined =
|
|
145
150
|
eventData.status?.validCredentials?.status;
|
|
146
151
|
if (rawStatus) {
|
|
@@ -346,7 +351,7 @@ export const handleAccountEvent = ({
|
|
|
346
351
|
const resolveStatusAfterCreate = (existingAccount?: Account): string =>
|
|
347
352
|
existingAccount?.status && existingAccount.status !== "pending"
|
|
348
353
|
? existingAccount.status
|
|
349
|
-
:
|
|
354
|
+
: AccountStatus.ACTIVE;
|
|
350
355
|
|
|
351
356
|
/**
|
|
352
357
|
* Handles successful account operations (CREATE, UPDATE, DELETE).
|
package/helpers/token-helper.ts
CHANGED
|
@@ -97,6 +97,21 @@ export const handleTokenEvent = ({
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
+
export const applyKnownTokenData = (
|
|
101
|
+
tokens: Token[],
|
|
102
|
+
tokenMap: Map<string, Token>
|
|
103
|
+
): Token[] =>
|
|
104
|
+
tokens.map((userToken) => {
|
|
105
|
+
const known = tokenMap.get(userToken.name);
|
|
106
|
+
if (!known) return userToken;
|
|
107
|
+
const token = known.token || userToken.token;
|
|
108
|
+
const lastUsed = known.lastUsed || userToken.lastUsed;
|
|
109
|
+
if (token === userToken.token && lastUsed === userToken.lastUsed) {
|
|
110
|
+
return userToken;
|
|
111
|
+
}
|
|
112
|
+
return { ...userToken, token, lastUsed };
|
|
113
|
+
});
|
|
114
|
+
|
|
100
115
|
interface HandleTokenOperationSuccessParams {
|
|
101
116
|
responsePayload: any;
|
|
102
117
|
}
|
package/package.json
CHANGED
package/websocket-manager.ts
CHANGED
|
@@ -73,6 +73,7 @@ import {
|
|
|
73
73
|
} from "./helpers/plan-helper";
|
|
74
74
|
import { handleRegistryEvent } from "./helpers/registry-helper";
|
|
75
75
|
import {
|
|
76
|
+
applyKnownTokenData,
|
|
76
77
|
handleTokenDeletion,
|
|
77
78
|
handleTokenEvent,
|
|
78
79
|
handleTokenOperationSuccess,
|
|
@@ -723,11 +724,13 @@ const rebuildHierarchy = () => {
|
|
|
723
724
|
notificationsEnabled: preservedUserData.notificationsEnabled,
|
|
724
725
|
organizations: Array.from(organizationsMap.values()),
|
|
725
726
|
clusterTokens: Array.from(clusterTokensMap.values()),
|
|
726
|
-
tokens: (
|
|
727
|
-
tokenMap.size > 0
|
|
727
|
+
tokens: applyKnownTokenData(
|
|
728
|
+
(tokenMap.size > 0
|
|
728
729
|
? (preservedUserData.tokens || []).filter(t => tokenMap.has(t.name))
|
|
729
730
|
: (preservedUserData.tokens || [])
|
|
730
|
-
|
|
731
|
+
).filter(t => !deletedTokenIds.has(t.name)),
|
|
732
|
+
tokenMap,
|
|
733
|
+
),
|
|
731
734
|
tenants: Array.from(tenantsMap.values()),
|
|
732
735
|
axebowPlan: preservedUserData.axebowPlan,
|
|
733
736
|
companyName: preservedUserData.companyName,
|
|
@@ -906,6 +909,7 @@ const handleEvent = async (message: WSMessage) => {
|
|
|
906
909
|
...serviceResult.updatedPendingRevisionErrors,
|
|
907
910
|
);
|
|
908
911
|
|
|
912
|
+
const isFirstSightingOfService = !servicesMap.has(serviceResult.serviceFullKey);
|
|
909
913
|
const resolvedService = resolveServiceStatus(serviceResult.service);
|
|
910
914
|
servicesMap.set(serviceResult.serviceFullKey, resolvedService);
|
|
911
915
|
|
|
@@ -928,6 +932,14 @@ const handleEvent = async (message: WSMessage) => {
|
|
|
928
932
|
eventHelper.service.publish.deployed(resolvedService);
|
|
929
933
|
}
|
|
930
934
|
}
|
|
935
|
+
if (
|
|
936
|
+
isFirstSightingOfService &&
|
|
937
|
+
resolvedService.error &&
|
|
938
|
+
resolvedService.status?.code !== "REMOVING_SERVICE" &&
|
|
939
|
+
!eventData.meta?.deleted
|
|
940
|
+
) {
|
|
941
|
+
eventHelper.service.publish.deploymentError(resolvedService);
|
|
942
|
+
}
|
|
931
943
|
const serviceState = eventData.status?.state?.code;
|
|
932
944
|
if (serviceState === "SERVICE_READY") {
|
|
933
945
|
const serviceKey = `${parentParts.tenant}/${entityId}`;
|
|
@@ -2170,10 +2182,13 @@ export const updateUserComplete = (updatedUserData: UserData): User => {
|
|
|
2170
2182
|
const localOnlyTokens = (userData.tokens || []).filter(
|
|
2171
2183
|
(t) => !incomingTokenNames.has(t.name)
|
|
2172
2184
|
);
|
|
2173
|
-
const mergedTokens =
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2185
|
+
const mergedTokens = applyKnownTokenData(
|
|
2186
|
+
[...(updatedUserData.tokens || []), ...localOnlyTokens]
|
|
2187
|
+
.filter((t, index, arr) => arr.findIndex(x => x.name === t.name) === index)
|
|
2188
|
+
.filter(t => tokenMap.size === 0 || tokenMap.has(t.name))
|
|
2189
|
+
.filter(t => !deletedTokenIds.has(t.name)),
|
|
2190
|
+
tokenMap,
|
|
2191
|
+
);
|
|
2177
2192
|
|
|
2178
2193
|
userData = {
|
|
2179
2194
|
id: updatedUserData.id || userData.id,
|