@kumori/aurora-backend-handler 1.1.58 → 1.1.60

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.60",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -569,7 +569,7 @@ const rebuildHierarchy = () => {
569
569
  tenantsMap.forEach((tenant) => {
570
570
  tenant.accounts = Array.from(accountsMap.values()).filter((account) => {
571
571
  account.environments = Array.from(environmentsMap.values())
572
- .filter((env) => env.account === account.id)
572
+ .filter((env) => env.account === account.id && env.tenant === account.tenant)
573
573
  .map((env) => env.name);
574
574
  return account.tenant === tenant.id;
575
575
  });
@@ -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;
@@ -812,7 +815,7 @@ const handleEvent = async (message: WSMessage) => {
812
815
  if (!message.payload.deleted) {
813
816
  const accountKey = parentParts.tenant ? `${parentParts.tenant}/${entityId}` : entityId;
814
817
  accountsMap.set(accountKey, accountResult.account);
815
- updateEnvironmentsCloudProvider(entityId, eventData.spec.api);
818
+ updateEnvironmentsCloudProvider(entityId, eventData.spec.api, parentParts.tenant);
816
819
  }
817
820
  break;
818
821
 
@@ -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;
@@ -1889,9 +1897,10 @@ const getChannelsInfo = async (
1889
1897
  const updateEnvironmentsCloudProvider = (
1890
1898
  accountId: string,
1891
1899
  cloudProviderName: string,
1900
+ tenantId?: string,
1892
1901
  ) => {
1893
1902
  environmentsMap.forEach((environment, envId) => {
1894
- if (environment.account === accountId) {
1903
+ if (environment.account === accountId && (!tenantId || environment.tenant === tenantId)) {
1895
1904
  environment.cloudProvider = cloudProviderName;
1896
1905
  environmentsMap.set(envId, environment);
1897
1906
  }
@@ -1909,7 +1918,8 @@ const loadReportingForEnvironment = async (environment: Environment) => {
1909
1918
  reportingData !== null &&
1910
1919
  Array.isArray(reportingData)
1911
1920
  ) {
1912
- const updatedEnvironment = environmentsMap.get(environment.id);
1921
+ const envReportKey = environment.tenant && environment.account ? `${environment.tenant}/${environment.account}/${environment.id}` : environment.id;
1922
+ const updatedEnvironment = environmentsMap.get(envReportKey);
1913
1923
 
1914
1924
  if (!updatedEnvironment) {
1915
1925
  console.warn(`Environment ${environment.id} not found in map`);
@@ -1940,7 +1950,7 @@ const loadReportingForEnvironment = async (environment: Environment) => {
1940
1950
  );
1941
1951
  }
1942
1952
 
1943
- environmentsMap.set(environment.id, updatedEnvironment);
1953
+ environmentsMap.set(envReportKey, updatedEnvironment);
1944
1954
  }
1945
1955
  } catch (error) {
1946
1956
  console.error(