@kumori/aurora-backend-handler 1.0.79 → 1.0.80

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.80",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {
@@ -684,22 +684,17 @@ 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);
@@ -716,14 +711,12 @@ const handleEvent = async (message: WSMessage) => {
716
711
  getChannelsInfo(
717
712
  revisionResult.channelsFetchInfo.serviceId,
718
713
  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
- });
714
+ ).catch((error) => {
715
+ console.error(
716
+ "[ws] Error fetching channels info for revision",
717
+ error,
718
+ );
719
+ });
727
720
  }
728
721
  break;
729
722
  case "service":
@@ -742,25 +735,15 @@ const handleEvent = async (message: WSMessage) => {
742
735
  pendingRevisionErrors.push(
743
736
  ...serviceResult.updatedPendingRevisionErrors,
744
737
  );
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
- }
738
+
739
+ const resolvedService = resolveServiceStatus(serviceResult.service);
740
+ servicesMap.set(serviceResult.serviceFullKey, resolvedService);
756
741
 
757
742
  const projectLabel = eventData.meta?.labels?.project;
758
743
  if (projectLabel) {
759
744
  const tenant = tenantsMap.get(parentParts.tenant);
760
745
  if (tenant) {
761
- if (!tenant.projects) {
762
- tenant.projects = [];
763
- }
746
+ if (!tenant.projects) tenant.projects = [];
764
747
  if (!tenant.projects.includes(projectLabel)) {
765
748
  tenant.projects.push(projectLabel);
766
749
  tenantsMap.set(parentParts.tenant, tenant);
@@ -770,7 +753,7 @@ const handleEvent = async (message: WSMessage) => {
770
753
  }
771
754
  }
772
755
  if (serviceResult.wasDeployed) {
773
- eventHelper.service.publish.deployed(serviceResult.service);
756
+ eventHelper.service.publish.deployed(resolvedService);
774
757
  }
775
758
  const serviceState = eventData.status?.state?.code;
776
759
  if (serviceState === "SERVICE_READY") {
@@ -1158,7 +1141,7 @@ export const getReferenceDomain = () => {
1158
1141
  };
1159
1142
  const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1160
1143
  const { action, entityType, entityName, originalData } = operation;
1161
- if (action === "UPDATE_CONFIG") {
1144
+ if (action === "UPDATE_CONFIG") {
1162
1145
  const tenant = originalData?.payload?.tenant;
1163
1146
  const serviceName = originalData?.payload?.service;
1164
1147
  if (tenant && serviceName) {
@@ -1316,7 +1299,7 @@ const handleOperationSuccess = (operation: PendingOperation, response: any) => {
1316
1299
  eventHelper.service.publish.updated(svcSuccessResult.updatedService);
1317
1300
  }
1318
1301
  }
1319
- break;;
1302
+ break;
1320
1303
  case "account":
1321
1304
  const accSuccessResult = handleAccountOperationSuccess({
1322
1305
  action,
@@ -1922,3 +1905,33 @@ export const updateUserComplete = (updatedUserData: UserData): User => {
1922
1905
  return user;
1923
1906
  }
1924
1907
  };
1908
+ const resolveServiceStatus = (service: Service): Service => {
1909
+ const revisionKey = `${service.tenant}/${service.name}-${service.currentRevision}`;
1910
+ const currentRevision = revisionsMap.get(revisionKey);
1911
+
1912
+ if (service.error) {
1913
+ return service;
1914
+ }
1915
+
1916
+ if (!currentRevision) {
1917
+ return service;
1918
+ }
1919
+
1920
+ if (currentRevision.errorCode) {
1921
+ return {
1922
+ ...service,
1923
+ status: currentRevision.status,
1924
+ error: {
1925
+ code: currentRevision.errorCode,
1926
+ message: currentRevision.errorMsg || "",
1927
+ timestamp: currentRevision.status?.timestamp,
1928
+ },
1929
+ };
1930
+ }
1931
+
1932
+ return {
1933
+ ...service,
1934
+ error: undefined,
1935
+ status: currentRevision.status,
1936
+ };
1937
+ };