@kumori/aurora-backend-handler 1.0.79 → 1.0.81

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.
@@ -242,56 +242,12 @@ const updateServiceWithRevision = (
242
242
  const updatedService: Service = {
243
243
  ...existingService,
244
244
  revisions: updatedRevisions,
245
- currentRevision:
246
- Number(entityId) >= Number(existingService.currentRevision ?? 0)
247
- ? entityId
248
- : existingService.currentRevision,
249
245
  role: roles.length > 0 ? roles : existingService.role,
250
246
  usage: newRevision.usage,
251
247
  startedAt: newRevision.createdAt || existingService.startedAt,
252
248
  };
253
249
 
254
- let deploymentErrorEvent: Service | null = null;
255
-
256
- const incomingStatus = eventData.status.state;
257
- const incomingTs = getTimestamp(incomingStatus.timestamp);
258
- const currentTs = getTimestamp(existingService.status?.timestamp);
259
- const incomingRevisionId = Number(entityId);
260
- const currentRevisionId = Number(existingService.currentRevision ?? 0);
261
-
262
- if (incomingTs > currentTs) {
263
- updatedService.status = incomingStatus;
264
- if (eventData.status.error) {
265
- if (incomingRevisionId >= currentRevisionId) {
266
- updatedService.error = {
267
- code: eventData.status.error.code,
268
- message: eventData.status.error.message,
269
- timestamp:
270
- eventData.status.error.timestamp || incomingStatus.timestamp,
271
- };
272
- deploymentErrorEvent = updatedService;
273
- }
274
- } else {
275
- updatedService.error = undefined;
276
- }
277
- } else if (eventData.status.error) {
278
- if (incomingRevisionId >= currentRevisionId) {
279
- const incomingErrorTs = getTimestamp(eventData.status.error.timestamp);
280
- const currentErrorTs = getTimestamp(existingService.error?.timestamp);
281
- if (incomingErrorTs > currentErrorTs) {
282
- updatedService.error = {
283
- code: eventData.status.error.code,
284
- message: eventData.status.error.message,
285
- timestamp: eventData.status.error.timestamp,
286
- };
287
- deploymentErrorEvent = updatedService;
288
- }
289
- }
290
- }
291
-
292
- if (incomingRevisionId >= currentRevisionId && !eventData.status.error) {
293
- updatedService.error = undefined;
294
- }
250
+ const deploymentErrorEvent = eventData.status?.error ? updatedService : null;
295
251
 
296
252
  return { updatedService, deploymentErrorEvent };
297
253
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -684,27 +684,26 @@ const handleEvent = async (message: WSMessage) => {
684
684
  roleMap.set(revisionResult.serviceId, revisionResult.roles);
685
685
  }
686
686
  if (revisionResult.updatedService) {
687
- servicesMap.set(
688
- revisionResult.serviceId,
689
- revisionResult.updatedService,
690
- );
687
+ const resolved = resolveServiceStatus(revisionResult.updatedService);
688
+ servicesMap.set(revisionResult.serviceId, resolved);
691
689
  }
692
690
  if (revisionResult.updatedEnvironment) {
693
691
  const envId = revisionResult.updatedService?.environment;
694
- if (envId) {
692
+ if (envId)
695
693
  environmentsMap.set(envId, revisionResult.updatedEnvironment);
696
- }
697
694
  }
698
695
  if (revisionResult.updatedAccount) {
699
696
  const accId = revisionResult.updatedService?.account;
700
- if (accId) {
701
- accountsMap.set(accId, revisionResult.updatedAccount);
702
- }
697
+ if (accId) accountsMap.set(accId, revisionResult.updatedAccount);
703
698
  }
704
699
  if (revisionResult.pendingRevisionError) {
705
700
  pendingRevisionErrors.push(revisionResult.pendingRevisionError);
706
701
  }
707
- if (revisionResult.serviceDeploymentErrorEvent) {
702
+ if (
703
+ revisionResult.serviceDeploymentErrorEvent &&
704
+ String(entityId) ===
705
+ String(revisionResult.updatedService?.currentRevision)
706
+ ) {
708
707
  eventHelper.service.publish.deploymentError(
709
708
  revisionResult.serviceDeploymentErrorEvent,
710
709
  );
@@ -716,14 +715,12 @@ const handleEvent = async (message: WSMessage) => {
716
715
  getChannelsInfo(
717
716
  revisionResult.channelsFetchInfo.serviceId,
718
717
  revisionResult.channelsFetchInfo.tenantId,
719
- )
720
- .then((channelsInfo) => {})
721
- .catch((error) => {
722
- console.error("[ws] Error fetching channels info for revision", {
723
- revisionServiceId: revisionResult.channelsFetchInfo?.serviceId,
724
- error,
725
- });
726
- });
718
+ ).catch((error) => {
719
+ console.error(
720
+ "[ws] Error fetching channels info for revision",
721
+ error,
722
+ );
723
+ });
727
724
  }
728
725
  break;
729
726
  case "service":
@@ -742,25 +739,15 @@ const handleEvent = async (message: WSMessage) => {
742
739
  pendingRevisionErrors.push(
743
740
  ...serviceResult.updatedPendingRevisionErrors,
744
741
  );
745
- servicesMap.set(serviceResult.serviceFullKey, serviceResult.service);
746
-
747
- const savedService = servicesMap.get(serviceResult.serviceFullKey)!;
748
- if (savedService.error && savedService.currentRevision) {
749
- const currentRevId = Number(savedService.currentRevision);
750
- const errorTs = Number(savedService.error.timestamp ?? 0);
751
- if (currentRevId > errorTs) {
752
- savedService.error = undefined;
753
- servicesMap.set(serviceResult.serviceFullKey, savedService);
754
- }
755
- }
742
+
743
+ const resolvedService = resolveServiceStatus(serviceResult.service);
744
+ servicesMap.set(serviceResult.serviceFullKey, resolvedService);
756
745
 
757
746
  const projectLabel = eventData.meta?.labels?.project;
758
747
  if (projectLabel) {
759
748
  const tenant = tenantsMap.get(parentParts.tenant);
760
749
  if (tenant) {
761
- if (!tenant.projects) {
762
- tenant.projects = [];
763
- }
750
+ if (!tenant.projects) tenant.projects = [];
764
751
  if (!tenant.projects.includes(projectLabel)) {
765
752
  tenant.projects.push(projectLabel);
766
753
  tenantsMap.set(parentParts.tenant, tenant);
@@ -770,7 +757,7 @@ const handleEvent = async (message: WSMessage) => {
770
757
  }
771
758
  }
772
759
  if (serviceResult.wasDeployed) {
773
- eventHelper.service.publish.deployed(serviceResult.service);
760
+ eventHelper.service.publish.deployed(resolvedService);
774
761
  }
775
762
  const serviceState = eventData.status?.state?.code;
776
763
  if (serviceState === "SERVICE_READY") {
@@ -1158,7 +1145,7 @@ export const getReferenceDomain = () => {
1158
1145
  };
1159
1146
  const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1160
1147
  const { action, entityType, entityName, originalData } = operation;
1161
- if (action === "UPDATE_CONFIG") {
1148
+ if (action === "UPDATE_CONFIG") {
1162
1149
  const tenant = originalData?.payload?.tenant;
1163
1150
  const serviceName = originalData?.payload?.service;
1164
1151
  if (tenant && serviceName) {
@@ -1316,7 +1303,7 @@ const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1316
1303
  eventHelper.service.publish.updated(svcSuccessResult.updatedService);
1317
1304
  }
1318
1305
  }
1319
- break;;
1306
+ break;
1320
1307
  case "account":
1321
1308
  const accSuccessResult = handleAccountOperationSuccess({
1322
1309
  action,
@@ -1922,3 +1909,33 @@ export const updateUserComplete = (updatedUserData: UserData): User => {
1922
1909
  return user;
1923
1910
  }
1924
1911
  };
1912
+ const resolveServiceStatus = (service: Service): Service => {
1913
+ const revisionKey = `${service.tenant}/${service.name}-${service.currentRevision}`;
1914
+ const currentRevision = revisionsMap.get(revisionKey);
1915
+
1916
+ if (service.error) {
1917
+ return service;
1918
+ }
1919
+
1920
+ if (!currentRevision) {
1921
+ return service;
1922
+ }
1923
+
1924
+ if (currentRevision.errorCode) {
1925
+ return {
1926
+ ...service,
1927
+ status: currentRevision.status,
1928
+ error: {
1929
+ code: currentRevision.errorCode,
1930
+ message: currentRevision.errorMsg || "",
1931
+ timestamp: currentRevision.status?.timestamp,
1932
+ },
1933
+ };
1934
+ }
1935
+
1936
+ return {
1937
+ ...service,
1938
+ error: undefined,
1939
+ status: currentRevision.status,
1940
+ };
1941
+ };