@kumori/aurora-backend-handler 1.1.58 → 1.1.59

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.
@@ -56,7 +56,8 @@ export const handleEnvironmentEvent = ({
56
56
  }: HandleEnvironmentEventParams): HandleEnvironmentEventResult => {
57
57
  const tenantId = parentParts.tenant;
58
58
  const accountId = parentParts.account;
59
- const relatedAccount = accountsMap.get(accountId);
59
+ const accountKey = tenantId ? `${tenantId}/${accountId}` : accountId;
60
+ const relatedAccount = accountsMap.get(accountKey);
60
61
  let cloudProviderName = relatedAccount?.cloudProvider?.name || "";
61
62
 
62
63
  let pendingCloudProviderUpdate: { environmentId: string; accountId: string } | null = null;
@@ -68,7 +69,8 @@ export const handleEnvironmentEvent = ({
68
69
  };
69
70
  }
70
71
 
71
- const existingEnvironment = environmentsMap.get(entityId);
72
+ const envKey = tenantId && accountId ? `${tenantId}/${accountId}/${entityId}` : entityId;
73
+ const existingEnvironment = environmentsMap.get(envKey);
72
74
 
73
75
  const newEnvironment: Environment = {
74
76
  id: entityId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.58",
3
+ "version": "1.1.59",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -676,7 +676,8 @@ const handleEvent = async (message: WSMessage) => {
676
676
  envEventResult.pendingCloudProviderUpdate,
677
677
  );
678
678
  }
679
- environmentsMap.set(entityId, envEventResult.environment);
679
+ const envSetKey = parentParts.tenant && parentParts.account ? `${parentParts.tenant}/${parentParts.account}/${entityId}` : entityId;
680
+ environmentsMap.set(envSetKey, envEventResult.environment);
680
681
  const envTenant = tenantsMap.get(envEventResult.tenantId);
681
682
  if (!envTenant) {
682
683
  pendingEnvironments.push({
@@ -710,8 +711,10 @@ const handleEvent = async (message: WSMessage) => {
710
711
  }
711
712
  if (revisionResult.updatedEnvironment) {
712
713
  const envId = revisionResult.updatedService?.environment;
713
- if (envId)
714
- environmentsMap.set(envId, revisionResult.updatedEnvironment);
714
+ const envRevTenant = revisionResult.updatedEnvironment.tenant;
715
+ const envRevAccount = revisionResult.updatedEnvironment.account;
716
+ const envRevKey = envRevTenant && envRevAccount && envId ? `${envRevTenant}/${envRevAccount}/${envId}` : envId;
717
+ if (envRevKey) environmentsMap.set(envRevKey, revisionResult.updatedEnvironment);
715
718
  }
716
719
  if (revisionResult.updatedAccount) {
717
720
  const accId = revisionResult.updatedService?.account;
@@ -1428,10 +1431,12 @@ const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1428
1431
  originalData: originalData as Environment,
1429
1432
  });
1430
1433
 
1434
+ const envOrigData = originalData as Environment;
1435
+ const envSuccessKey = envOrigData?.tenant && envOrigData?.account ? `${envOrigData.tenant}/${envOrigData.account}/${entityName}` : entityName;
1431
1436
  if (envSuccessResult.shouldDelete) {
1432
- environmentsMap.delete(entityName);
1437
+ environmentsMap.delete(envSuccessKey);
1433
1438
  } else if (envSuccessResult.updatedEnvironment) {
1434
- environmentsMap.set(entityName, envSuccessResult.updatedEnvironment);
1439
+ environmentsMap.set(envSuccessKey, envSuccessResult.updatedEnvironment);
1435
1440
  if (envSuccessResult.notification) {
1436
1441
  eventHelper.notification.publish.creation(
1437
1442
  envSuccessResult.notification,
@@ -1564,7 +1569,9 @@ const handleOperationError = (operation: PendingOperation, error: any) => {
1564
1569
  eventHelper.environment.publish.deletionError(originalData);
1565
1570
  }
1566
1571
  eventHelper.notification.publish.creation(envErrorResult.notification);
1567
- environmentsMap.set(entityName, envErrorResult.updatedEnvironment);
1572
+ const envErrOrigData = originalData as Environment;
1573
+ const envErrorKey = envErrOrigData?.tenant && envErrOrigData?.account ? `${envErrOrigData.tenant}/${envErrOrigData.account}/${entityName}` : entityName;
1574
+ environmentsMap.set(envErrorKey, envErrorResult.updatedEnvironment);
1568
1575
  break;
1569
1576
  }
1570
1577
  setTimeout(async () => {
@@ -1595,7 +1602,8 @@ const handleDeleteEvent = async (message: WSMessage) => {
1595
1602
  }
1596
1603
  if (keyParts.environment && !keyParts.service) {
1597
1604
  const environmentName = keyParts.environment;
1598
- const deletedEnv = environmentsMap.get(environmentName)!;
1605
+ const envDeleteKey = tenantName && keyParts.account ? `${tenantName}/${keyParts.account}/${environmentName}` : environmentName;
1606
+ const deletedEnv = environmentsMap.get(envDeleteKey)!;
1599
1607
  eventHelper.environment.publish.deleted(deletedEnv);
1600
1608
  const envNotification: Notification = {
1601
1609
  type: "success",
@@ -1610,7 +1618,7 @@ const handleDeleteEvent = async (message: WSMessage) => {
1610
1618
  },
1611
1619
  };
1612
1620
  eventHelper.notification.publish.creation(envNotification);
1613
- environmentsMap.delete(environmentName);
1621
+ environmentsMap.delete(envDeleteKey);
1614
1622
  }
1615
1623
  if (keyParts.account && !keyParts.environment) {
1616
1624
  const accountName = keyParts.account;
@@ -1909,7 +1917,8 @@ const loadReportingForEnvironment = async (environment: Environment) => {
1909
1917
  reportingData !== null &&
1910
1918
  Array.isArray(reportingData)
1911
1919
  ) {
1912
- const updatedEnvironment = environmentsMap.get(environment.id);
1920
+ const envReportKey = environment.tenant && environment.account ? `${environment.tenant}/${environment.account}/${environment.id}` : environment.id;
1921
+ const updatedEnvironment = environmentsMap.get(envReportKey);
1913
1922
 
1914
1923
  if (!updatedEnvironment) {
1915
1924
  console.warn(`Environment ${environment.id} not found in map`);
@@ -1940,7 +1949,7 @@ const loadReportingForEnvironment = async (environment: Environment) => {
1940
1949
  );
1941
1950
  }
1942
1951
 
1943
- environmentsMap.set(environment.id, updatedEnvironment);
1952
+ environmentsMap.set(envReportKey, updatedEnvironment);
1944
1953
  }
1945
1954
  } catch (error) {
1946
1955
  console.error(