@kumori/aurora-backend-handler 1.1.65 → 1.1.67

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.
@@ -5,6 +5,7 @@ import {
5
5
  initializeGlobalWebSocketClient,
6
6
  getWebSocketStatus,
7
7
  makeGlobalWebSocketRequest,
8
+ markEnvironmentAsPurging,
8
9
  } from "../websocket-manager";
9
10
 
10
11
  type Security = string;
@@ -259,6 +260,10 @@ export const clearEnvironment = async (
259
260
  }
260
261
  };
261
262
  eventHelper.notification.publish.creation(envNotification);
263
+ const purgeKey = env.tenant && env.account
264
+ ? `${env.tenant}/${env.account}/${env.name}`
265
+ : env.name;
266
+ markEnvironmentAsPurging(purgeKey);
262
267
  await initializeGlobalWebSocketClient(security, "environment", env.name);
263
268
  const status = getWebSocketStatus();
264
269
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -145,6 +145,7 @@ interface Role {
145
145
  */
146
146
  let wsConnection: WebSocket | null = null;
147
147
  let pendingRequests = new Map<string, PendingOperation>();
148
+ let purgingEnvironments = new Set<string>();
148
149
  let currentToken: string | null = null;
149
150
  let connectionPromise: Promise<WebSocket> | null = null;
150
151
  let userData: UserData = {
@@ -428,6 +429,14 @@ export const makeGlobalWebSocketRequest = async (
428
429
  payload,
429
430
  };
430
431
 
432
+ let purgeEnvKey: string | null = null;
433
+ if (petitionAction === "CLEAN" && entityType === "environment" && originalData) {
434
+ purgeEnvKey = originalData.tenant && originalData.account
435
+ ? `${originalData.tenant}/${originalData.account}/${petitionInfo}`
436
+ : petitionInfo;
437
+ purgingEnvironments.add(purgeEnvKey);
438
+ }
439
+
431
440
  return new Promise((resolve, reject) => {
432
441
  const timeoutId = setTimeout(() => {
433
442
  const pending = pendingRequests.get(messageId);
@@ -443,6 +452,7 @@ export const makeGlobalWebSocketRequest = async (
443
452
  new Error(`Request timeout for ${topic}`),
444
453
  );
445
454
  }
455
+ if (purgeEnvKey) purgingEnvironments.delete(purgeEnvKey);
446
456
  const timeoutError = Object.assign(
447
457
  new Error(`Request timeout for ${topic}`),
448
458
  { isTimeout: true },
@@ -453,10 +463,12 @@ export const makeGlobalWebSocketRequest = async (
453
463
  const operation: PendingOperation = {
454
464
  resolve: (response: any) => {
455
465
  clearTimeout(timeoutId);
466
+ if (purgeEnvKey) purgingEnvironments.delete(purgeEnvKey);
456
467
  resolve(response.payload || response);
457
468
  },
458
469
  reject: (error: any) => {
459
470
  clearTimeout(timeoutId);
471
+ if (purgeEnvKey) purgingEnvironments.delete(purgeEnvKey);
460
472
  const errorMessage = safeStringifyError(error);
461
473
  console.error(`WebSocket request failed for ${topic}:`, {
462
474
  originalError: error,
@@ -533,6 +545,23 @@ export const makeGlobalWebSocketRequestWithRetry = async (
533
545
  );
534
546
  };
535
547
 
548
+ export const markEnvironmentAsPurging = (envKey: string) => {
549
+ purgingEnvironments.add(envKey);
550
+ const env = environmentsMap.get(envKey);
551
+ if (env) {
552
+ const updatedEnv: Environment = {
553
+ ...env,
554
+ status: {
555
+ code: "PURGING",
556
+ message: `Environment ${env.name} is being purged.`,
557
+ timestamp: new Date().toISOString(),
558
+ },
559
+ };
560
+ environmentsMap.set(envKey, updatedEnv);
561
+ eventHelper.environment.publish.updated(updatedEnv);
562
+ }
563
+ };
564
+
536
565
  /**
537
566
  * Get the current WebSocket connection status
538
567
  * @returns Connection status and token info
@@ -682,7 +711,18 @@ const handleEvent = async (message: WSMessage) => {
682
711
  );
683
712
  }
684
713
  const envSetKey = parentParts.tenant && parentParts.account ? `${parentParts.tenant}/${parentParts.account}/${entityId}` : entityId;
685
- environmentsMap.set(envSetKey, envEventResult.environment);
714
+ let envToStore = envEventResult.environment;
715
+ if (envToStore.status?.code === "DELETING" && purgingEnvironments.has(envSetKey)) {
716
+ envToStore = {
717
+ ...envToStore,
718
+ status: {
719
+ code: "PURGING",
720
+ message: `Environment ${entityId} is being purged.`,
721
+ timestamp: new Date().toISOString(),
722
+ },
723
+ };
724
+ }
725
+ environmentsMap.set(envSetKey, envToStore);
686
726
  const envTenant = tenantsMap.get(envEventResult.tenantId);
687
727
  if (!envTenant) {
688
728
  pendingEnvironments.push({