@kumori/aurora-backend-handler 1.0.41 → 1.0.43
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.
- package/api/service-api-service.ts +204 -146
- package/helpers/revision-helper.ts +11 -15
- package/package.json +1 -1
|
@@ -15,13 +15,13 @@ let pendingLinks = new Map<string, Link[]>();
|
|
|
15
15
|
export const deployService = async (data: Service, token: string) => {
|
|
16
16
|
try {
|
|
17
17
|
const url = new URL(
|
|
18
|
-
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}
|
|
18
|
+
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}`,
|
|
19
19
|
);
|
|
20
20
|
url.searchParams.append("dryrun", "false");
|
|
21
21
|
url.searchParams.append("accept", "true");
|
|
22
22
|
url.searchParams.append("wait", "30000");
|
|
23
23
|
url.searchParams.append("validate", "true");
|
|
24
|
-
if(data.dsl){
|
|
24
|
+
if (data.dsl) {
|
|
25
25
|
url.searchParams.append("dsl", "true");
|
|
26
26
|
}
|
|
27
27
|
if (data.serviceData) {
|
|
@@ -32,7 +32,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
32
32
|
JSON.stringify({
|
|
33
33
|
targetAccount: data.account,
|
|
34
34
|
targetEnvironment: data.environment,
|
|
35
|
-
})
|
|
35
|
+
}),
|
|
36
36
|
);
|
|
37
37
|
formData.append("labels", JSON.stringify({ project: data.project }));
|
|
38
38
|
formData.append("comment", " ");
|
|
@@ -47,7 +47,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
47
47
|
const jsonResponse = await response.json();
|
|
48
48
|
|
|
49
49
|
const isTimeout = jsonResponse?.events?.some(
|
|
50
|
-
(event: any) => event.content === "_timeout_"
|
|
50
|
+
(event: any) => event.content === "_timeout_",
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
if (isTimeout) {
|
|
@@ -80,7 +80,7 @@ export const deployService = async (data: Service, token: string) => {
|
|
|
80
80
|
const jsonResponse = await response.json();
|
|
81
81
|
|
|
82
82
|
const isTimeout = jsonResponse?.events?.some(
|
|
83
|
-
(event: any) => event.content === "_timeout_"
|
|
83
|
+
(event: any) => event.content === "_timeout_",
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
if (isTimeout) {
|
|
@@ -110,7 +110,7 @@ export const redeployService = async (data: Service) => {
|
|
|
110
110
|
try {
|
|
111
111
|
const formData = await deployServiceHelper(data);
|
|
112
112
|
const url = new URL(
|
|
113
|
-
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}/revision/${data.currentRevision}
|
|
113
|
+
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}/revision/${data.currentRevision}`,
|
|
114
114
|
);
|
|
115
115
|
url.searchParams.append("dryrun", "false");
|
|
116
116
|
url.searchParams.append("accept", "true");
|
|
@@ -129,7 +129,7 @@ export const redeployService = async (data: Service) => {
|
|
|
129
129
|
const jsonResponse = await response.json();
|
|
130
130
|
|
|
131
131
|
const isTimeout = jsonResponse?.events?.some(
|
|
132
|
-
(event: any) => event.content === "_timeout_"
|
|
132
|
+
(event: any) => event.content === "_timeout_",
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
if (isTimeout) {
|
|
@@ -162,7 +162,7 @@ export const deleteService = async (data: Service, security: string) => {
|
|
|
162
162
|
deleteBody,
|
|
163
163
|
30000,
|
|
164
164
|
"DELETE",
|
|
165
|
-
data.name
|
|
165
|
+
data.name,
|
|
166
166
|
);
|
|
167
167
|
return response;
|
|
168
168
|
} catch (err) {
|
|
@@ -187,7 +187,7 @@ export const restartService = async (data: Service, security: string) => {
|
|
|
187
187
|
restartBody,
|
|
188
188
|
30000,
|
|
189
189
|
"RESTART",
|
|
190
|
-
data.name
|
|
190
|
+
data.name,
|
|
191
191
|
);
|
|
192
192
|
|
|
193
193
|
const updatedService: Service = {
|
|
@@ -210,27 +210,33 @@ export const restartService = async (data: Service, security: string) => {
|
|
|
210
210
|
const generateLinkBody = (data: Service, link: Link) => {
|
|
211
211
|
const originInClient = data.clientChannels.find(
|
|
212
212
|
(channel) =>
|
|
213
|
-
channel.name === link.originChannel ||
|
|
213
|
+
channel.name === link.originChannel ||
|
|
214
|
+
channel.from === link.originChannel,
|
|
214
215
|
);
|
|
215
216
|
const originInServer = data.serverChannels.find(
|
|
216
217
|
(channel) =>
|
|
217
|
-
channel.name === link.originChannel ||
|
|
218
|
+
channel.name === link.originChannel ||
|
|
219
|
+
channel.from === link.originChannel,
|
|
218
220
|
);
|
|
219
221
|
const originInDuplex = data.duplexChannels.find(
|
|
220
222
|
(channel) =>
|
|
221
|
-
channel.name === link.originChannel ||
|
|
223
|
+
channel.name === link.originChannel ||
|
|
224
|
+
channel.from === link.originChannel,
|
|
222
225
|
);
|
|
223
226
|
const targetInClient = data.clientChannels.find(
|
|
224
227
|
(channel) =>
|
|
225
|
-
channel.name === link.targetChannel ||
|
|
228
|
+
channel.name === link.targetChannel ||
|
|
229
|
+
channel.from === link.targetChannel,
|
|
226
230
|
);
|
|
227
231
|
const targetInServer = data.serverChannels.find(
|
|
228
232
|
(channel) =>
|
|
229
|
-
channel.name === link.targetChannel ||
|
|
233
|
+
channel.name === link.targetChannel ||
|
|
234
|
+
channel.from === link.targetChannel,
|
|
230
235
|
);
|
|
231
236
|
const targetInDuplex = data.duplexChannels.find(
|
|
232
237
|
(channel) =>
|
|
233
|
-
channel.name === link.targetChannel ||
|
|
238
|
+
channel.name === link.targetChannel ||
|
|
239
|
+
channel.from === link.targetChannel,
|
|
234
240
|
);
|
|
235
241
|
|
|
236
242
|
let linkBody;
|
|
@@ -290,7 +296,7 @@ const generateLinkBody = (data: Service, link: Link) => {
|
|
|
290
296
|
};
|
|
291
297
|
} else {
|
|
292
298
|
console.warn(
|
|
293
|
-
`No se encontraron canales para el enlace: origin=${link.origin}, target=${link.target}
|
|
299
|
+
`No se encontraron canales para el enlace: origin=${link.origin}, target=${link.target}`,
|
|
294
300
|
);
|
|
295
301
|
linkBody = {
|
|
296
302
|
client_tenant: data.tenant,
|
|
@@ -318,7 +324,7 @@ export const linkPendingServices = async (service: Service, token: string) => {
|
|
|
318
324
|
linkBody,
|
|
319
325
|
30000,
|
|
320
326
|
"LINK",
|
|
321
|
-
service.name
|
|
327
|
+
service.name,
|
|
322
328
|
);
|
|
323
329
|
|
|
324
330
|
const notification: Notification = {
|
|
@@ -352,7 +358,7 @@ export const linkPendingServices = async (service: Service, token: string) => {
|
|
|
352
358
|
};
|
|
353
359
|
eventHelper.notification.publish.creation(notification);
|
|
354
360
|
}
|
|
355
|
-
})
|
|
361
|
+
}),
|
|
356
362
|
);
|
|
357
363
|
}
|
|
358
364
|
};
|
|
@@ -374,7 +380,7 @@ export const requestRevisionData = async (service: Service, token: string) => {
|
|
|
374
380
|
"GET_REVISION",
|
|
375
381
|
service.name,
|
|
376
382
|
"service",
|
|
377
|
-
service
|
|
383
|
+
service,
|
|
378
384
|
);
|
|
379
385
|
return response;
|
|
380
386
|
} catch (err) {
|
|
@@ -385,7 +391,7 @@ export const requestRevisionData = async (service: Service, token: string) => {
|
|
|
385
391
|
export const updateService = async (
|
|
386
392
|
data: Service,
|
|
387
393
|
token: string,
|
|
388
|
-
scale?: number
|
|
394
|
+
scale?: number,
|
|
389
395
|
) => {
|
|
390
396
|
try {
|
|
391
397
|
await initializeGlobalWebSocketClient(token);
|
|
@@ -401,132 +407,184 @@ export const updateService = async (
|
|
|
401
407
|
// pendingLinks.set(data.name, newLinksToCreate);
|
|
402
408
|
// await linkPendingServices(serviceWithNewLinks, token);
|
|
403
409
|
// }
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (paramType === "number" || paramType === "integer") {
|
|
411
|
-
parameterObject[key] = Number(param.value) || 0;
|
|
412
|
-
} else if (paramType === "boolean") {
|
|
413
|
-
parameterObject[key] = param.value === "true";
|
|
414
|
-
} else {
|
|
415
|
-
parameterObject[key] = param.value;
|
|
416
|
-
}
|
|
417
|
-
});
|
|
410
|
+
const url = new URL(
|
|
411
|
+
`${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${data.tenant}/service/${data.name}/revision/${data.currentRevision}`,
|
|
412
|
+
);
|
|
413
|
+
console.log('DEBUG data', data);
|
|
414
|
+
if (data.dsl) {
|
|
415
|
+
url.searchParams.append("dsl", "true");
|
|
418
416
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
};
|
|
440
|
-
} else if (resource.type === "ca") {
|
|
441
|
-
resourceObject[resource.name] = {
|
|
442
|
-
ca: `${data.tenant}/${resource.value}`,
|
|
443
|
-
};
|
|
444
|
-
} else if (resource.type === "certificate") {
|
|
445
|
-
resourceObject[resource.name] = {
|
|
446
|
-
certificate: `${data.tenant}/${resource.value}`,
|
|
447
|
-
};
|
|
448
|
-
} else if (resource.type === "port") {
|
|
449
|
-
resourceObject[resource.name] = {
|
|
450
|
-
port: `${data.tenant}/${resource.value}`,
|
|
451
|
-
};
|
|
452
|
-
}
|
|
417
|
+
if (data.serviceData) {
|
|
418
|
+
console.log('DEBUG - Updating service with bundle data, URL:', url.toString());
|
|
419
|
+
console.log('DEBUG - Service data to update:', data.serviceData);
|
|
420
|
+
const formData = new FormData();
|
|
421
|
+
console.log('DEBUG - FormData before appending:', formData);
|
|
422
|
+
formData.append("type", "update-bundle");
|
|
423
|
+
formData.append("bundle", data.serviceData);
|
|
424
|
+
formData.append(
|
|
425
|
+
"meta",
|
|
426
|
+
JSON.stringify({
|
|
427
|
+
targetAccount: data.account,
|
|
428
|
+
targetEnvironment: data.environment,
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
formData.append("labels", JSON.stringify({ project: data.project }));
|
|
432
|
+
formData.append("comment", " ");
|
|
433
|
+
console.log('DEBUG - loaded FormData:', formData);
|
|
434
|
+
const response = await fetch(url.toString(), {
|
|
435
|
+
method: "POST",
|
|
436
|
+
body: formData,
|
|
453
437
|
});
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (data.currentRevision) {
|
|
458
|
-
previousRevision = parseInt(data.currentRevision.toString(), 10);
|
|
459
|
-
if (isNaN(previousRevision)) {
|
|
460
|
-
console.warn("currentRevision is not a valid number, using 1");
|
|
461
|
-
previousRevision = 1;
|
|
438
|
+
console.log('DEBUG - Update service response:', response);
|
|
439
|
+
if (!response.ok) {
|
|
440
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
462
441
|
}
|
|
463
|
-
}
|
|
464
|
-
else{
|
|
465
|
-
previousRevision = getLatestRevision(data.revisions) || 1;
|
|
466
|
-
}
|
|
467
442
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
443
|
+
const jsonResponse = await response.json();
|
|
444
|
+
console.log('DEBUG - Update service JSON response:', jsonResponse);
|
|
445
|
+
const isTimeout = jsonResponse?.events?.some(
|
|
446
|
+
(event: any) => event.content === "_timeout_",
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
if (isTimeout) {
|
|
450
|
+
console.error("Timeout en la petición:", {
|
|
451
|
+
isOk: false,
|
|
452
|
+
code: "TIMEOUT",
|
|
453
|
+
error: "_timeout_",
|
|
454
|
+
});
|
|
455
|
+
}
|
|
476
456
|
} else {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
memory: Math.min(
|
|
492
|
-
parseInt(role.scalling.memory.down) || 0,
|
|
493
|
-
100
|
|
494
|
-
),
|
|
495
|
-
},
|
|
496
|
-
hysteresis: parseInt(role.scalling.histeresys) || 0,
|
|
497
|
-
min_replicas: role.scalling.instances.min || 0,
|
|
498
|
-
max_replicas: role.scalling.instances.max || 0,
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
return acc;
|
|
502
|
-
}, {} as Record<string, any>) || {},
|
|
503
|
-
},
|
|
504
|
-
};
|
|
457
|
+
const parameterObject: Record<string, any> = {};
|
|
458
|
+
if (data.parameters && data.parameters.length > 0) {
|
|
459
|
+
data.parameters.forEach((param) => {
|
|
460
|
+
const key = param.configKey || param.name;
|
|
461
|
+
const paramType = param.type?.toLowerCase();
|
|
462
|
+
if (paramType === "number" || paramType === "integer") {
|
|
463
|
+
parameterObject[key] = Number(param.value) || 0;
|
|
464
|
+
} else if (paramType === "boolean") {
|
|
465
|
+
parameterObject[key] = param.value === "true";
|
|
466
|
+
} else {
|
|
467
|
+
parameterObject[key] = param.value;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
505
471
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
472
|
+
const resourceObject: Record<string, any> = {};
|
|
473
|
+
if (data.resources && data.resources.length > 0) {
|
|
474
|
+
data.resources.forEach((resource) => {
|
|
475
|
+
if (resource.type === "volume") {
|
|
476
|
+
resourceObject[resource.name] = {
|
|
477
|
+
volume: {
|
|
478
|
+
kind: "storage",
|
|
479
|
+
size: parseInt(resource.value) || 1,
|
|
480
|
+
unit: "G",
|
|
481
|
+
type: resource.kind,
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
} else if (resource.type === "secret") {
|
|
485
|
+
resourceObject[resource.name] = {
|
|
486
|
+
secret: `${data.tenant}/${resource.value}`,
|
|
487
|
+
};
|
|
488
|
+
} else if (resource.type === "domain") {
|
|
489
|
+
resourceObject[resource.name] = {
|
|
490
|
+
domain: `${data.tenant}/${resource.value}`,
|
|
491
|
+
};
|
|
492
|
+
} else if (resource.type === "ca") {
|
|
493
|
+
resourceObject[resource.name] = {
|
|
494
|
+
ca: `${data.tenant}/${resource.value}`,
|
|
495
|
+
};
|
|
496
|
+
} else if (resource.type === "certificate") {
|
|
497
|
+
resourceObject[resource.name] = {
|
|
498
|
+
certificate: `${data.tenant}/${resource.value}`,
|
|
499
|
+
};
|
|
500
|
+
} else if (resource.type === "port") {
|
|
501
|
+
resourceObject[resource.name] = {
|
|
502
|
+
port: `${data.tenant}/${resource.value}`,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
let previousRevision = 1;
|
|
509
|
+
if (data.currentRevision) {
|
|
510
|
+
previousRevision = parseInt(data.currentRevision.toString(), 10);
|
|
511
|
+
if (isNaN(previousRevision)) {
|
|
512
|
+
console.warn("currentRevision is not a valid number, using 1");
|
|
513
|
+
previousRevision = 1;
|
|
514
|
+
}
|
|
515
|
+
} else {
|
|
516
|
+
previousRevision = getLatestRevision(data.revisions) || 1;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const scaleConfig: any = {};
|
|
520
|
+
if (data.role && data.role.length > 0) {
|
|
521
|
+
scaleConfig.detail = {};
|
|
522
|
+
data.role.forEach((role) => {
|
|
523
|
+
scaleConfig.detail[role.name] = {
|
|
524
|
+
hsize: role.hsize || scale || data.minReplicas || 1,
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
} else {
|
|
528
|
+
scaleConfig.hsize = scale || data.minReplicas || 1;
|
|
529
|
+
}
|
|
530
|
+
const meta = {
|
|
531
|
+
scaling: {
|
|
532
|
+
simple:
|
|
533
|
+
data.role?.reduce(
|
|
534
|
+
(acc, role) => {
|
|
535
|
+
if (role.scalling && role.name) {
|
|
536
|
+
acc[role.name] = {
|
|
537
|
+
scale_up: {
|
|
538
|
+
cpu: Math.min(parseInt(role.scalling.cpu.up) || 0, 100),
|
|
539
|
+
memory: Math.min(
|
|
540
|
+
parseInt(role.scalling.memory.up) || 0,
|
|
541
|
+
100,
|
|
542
|
+
),
|
|
543
|
+
},
|
|
544
|
+
scale_down: {
|
|
545
|
+
cpu: Math.min(parseInt(role.scalling.cpu.down) || 0, 100),
|
|
546
|
+
memory: Math.min(
|
|
547
|
+
parseInt(role.scalling.memory.down) || 0,
|
|
548
|
+
100,
|
|
549
|
+
),
|
|
550
|
+
},
|
|
551
|
+
hysteresis: parseInt(role.scalling.histeresys) || 0,
|
|
552
|
+
min_replicas: role.scalling.instances.min || 0,
|
|
553
|
+
max_replicas: role.scalling.instances.max || 0,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return acc;
|
|
557
|
+
},
|
|
558
|
+
{} as Record<string, any>,
|
|
559
|
+
) || {},
|
|
515
560
|
},
|
|
516
|
-
|
|
517
|
-
},
|
|
518
|
-
tenant: data.tenant,
|
|
519
|
-
service: data.name,
|
|
520
|
-
previous: previousRevision,
|
|
521
|
-
};
|
|
561
|
+
};
|
|
522
562
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
563
|
+
const updateBody = {
|
|
564
|
+
spec: {
|
|
565
|
+
type: "update-config",
|
|
566
|
+
comment: "Service configuration update",
|
|
567
|
+
config: {
|
|
568
|
+
parameter: parameterObject,
|
|
569
|
+
resource: resourceObject,
|
|
570
|
+
resilience: 0,
|
|
571
|
+
scale: scaleConfig,
|
|
572
|
+
},
|
|
573
|
+
meta: meta,
|
|
574
|
+
},
|
|
575
|
+
tenant: data.tenant,
|
|
576
|
+
service: data.name,
|
|
577
|
+
previous: previousRevision,
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
const response = await makeGlobalWebSocketRequest(
|
|
581
|
+
"revision:update_revision",
|
|
582
|
+
updateBody,
|
|
583
|
+
30000,
|
|
584
|
+
"UPDATE_CONFIG",
|
|
585
|
+
data.name,
|
|
586
|
+
);
|
|
587
|
+
}
|
|
530
588
|
|
|
531
589
|
const updatedService: Service = {
|
|
532
590
|
...data,
|
|
@@ -577,7 +635,7 @@ export const updateService = async (
|
|
|
577
635
|
};
|
|
578
636
|
export const unlinkServices = async (service: Service, token: string) => {
|
|
579
637
|
const deleteLinks: Link[] = service.links.filter(
|
|
580
|
-
(link) => link.delete === true
|
|
638
|
+
(link) => link.delete === true,
|
|
581
639
|
);
|
|
582
640
|
if (deleteLinks.length > 0) {
|
|
583
641
|
await Promise.all(
|
|
@@ -592,7 +650,7 @@ export const unlinkServices = async (service: Service, token: string) => {
|
|
|
592
650
|
unlinkBody,
|
|
593
651
|
30000,
|
|
594
652
|
"UNLINK",
|
|
595
|
-
service.name
|
|
653
|
+
service.name,
|
|
596
654
|
);
|
|
597
655
|
|
|
598
656
|
const unlinkNotification: Notification = {
|
|
@@ -628,7 +686,7 @@ export const unlinkServices = async (service: Service, token: string) => {
|
|
|
628
686
|
};
|
|
629
687
|
eventHelper.notification.publish.creation(notification);
|
|
630
688
|
}
|
|
631
|
-
})
|
|
689
|
+
}),
|
|
632
690
|
);
|
|
633
691
|
}
|
|
634
692
|
};
|
|
@@ -653,7 +711,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
|
|
|
653
711
|
linkBody,
|
|
654
712
|
30000,
|
|
655
713
|
"UNLINK",
|
|
656
|
-
link.origin
|
|
714
|
+
link.origin,
|
|
657
715
|
);
|
|
658
716
|
|
|
659
717
|
// const unlinkNotification: Notification = {
|
|
@@ -699,7 +757,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
|
|
|
699
757
|
linkBody,
|
|
700
758
|
30000,
|
|
701
759
|
"LINK",
|
|
702
|
-
link.origin
|
|
760
|
+
link.origin,
|
|
703
761
|
);
|
|
704
762
|
|
|
705
763
|
const notification: Notification = {
|
|
@@ -755,7 +813,7 @@ export const changeRevision = async (data: Service, token: string) => {
|
|
|
755
813
|
revisionBody,
|
|
756
814
|
30000,
|
|
757
815
|
"UPDATE_REVISION",
|
|
758
|
-
data.name
|
|
816
|
+
data.name,
|
|
759
817
|
);
|
|
760
818
|
const notification: Notification = {
|
|
761
819
|
type: "success",
|
|
@@ -791,6 +849,6 @@ function getLatestRevision(revisions: string[]): number | null {
|
|
|
791
849
|
if (!revisions || revisions.length === 0) {
|
|
792
850
|
return null;
|
|
793
851
|
}
|
|
794
|
-
|
|
852
|
+
|
|
795
853
|
return Math.max(...revisions.map(Number));
|
|
796
|
-
}
|
|
854
|
+
}
|
|
@@ -253,25 +253,21 @@ const updateServiceWithRevision = (
|
|
|
253
253
|
const existingRevisionIndex = existingService.revisions.findIndex(
|
|
254
254
|
(rev) => rev === entityId,
|
|
255
255
|
);
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
} else {
|
|
267
|
-
updatedRevisions = existingService.revisions.filter(
|
|
268
|
-
(rev) => rev !== entityId,
|
|
269
|
-
);
|
|
270
|
-
}
|
|
256
|
+
const updatedRevisions =
|
|
257
|
+
existingRevisionIndex === -1
|
|
258
|
+
? [...existingService.revisions, entityId]
|
|
259
|
+
: existingService.revisions;
|
|
260
|
+
const currentRevisionTimestamp = Number(existingService.currentRevision) || 0;
|
|
261
|
+
const incomingRevisionTimestamp = Number(entityId) || 0;
|
|
262
|
+
const updatedCurrentRevision =
|
|
263
|
+
incomingRevisionTimestamp > currentRevisionTimestamp
|
|
264
|
+
? entityId
|
|
265
|
+
: existingService.currentRevision;
|
|
271
266
|
|
|
272
267
|
const updatedService: Service = {
|
|
273
268
|
...existingService,
|
|
274
269
|
revisions: updatedRevisions,
|
|
270
|
+
currentRevision: updatedCurrentRevision,
|
|
275
271
|
role: roles.length > 0 ? roles : existingService.role,
|
|
276
272
|
usage: newRevision.usage,
|
|
277
273
|
startedAt: newRevision.createdAt || existingService.startedAt,
|