@kumori/aurora-backend-handler 1.0.41 → 1.0.42

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.
@@ -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 || channel.from === 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 || channel.from === 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 || channel.from === 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 || channel.from === 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 || channel.from === 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 || channel.from === 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,178 @@ export const updateService = async (
401
407
  // pendingLinks.set(data.name, newLinksToCreate);
402
408
  // await linkPendingServices(serviceWithNewLinks, token);
403
409
  // }
404
-
405
- const parameterObject: Record<string, any> = {};
406
- if (data.parameters && data.parameters.length > 0) {
407
- data.parameters.forEach((param) => {
408
- const key = param.configKey || param.name;
409
- const paramType = param.type?.toLowerCase();
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
+ if (data.dsl) {
414
+ url.searchParams.append("dsl", "true");
418
415
  }
419
-
420
- const resourceObject: Record<string, any> = {};
421
- if (data.resources && data.resources.length > 0) {
422
- data.resources.forEach((resource) => {
423
- if (resource.type === "volume") {
424
- resourceObject[resource.name] = {
425
- volume: {
426
- kind: "storage",
427
- size: parseInt(resource.value) || 1,
428
- unit: "G",
429
- type: resource.kind,
430
- },
431
- };
432
- } else if (resource.type === "secret") {
433
- resourceObject[resource.name] = {
434
- secret: `${data.tenant}/${resource.value}`,
435
- };
436
- } else if (resource.type === "domain") {
437
- resourceObject[resource.name] = {
438
- domain: `${data.tenant}/${resource.value}`,
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
- }
416
+ if (data.serviceData) {
417
+ const formData = new FormData();
418
+ formData.append("type", "update-bundle");
419
+ formData.append("bundle", data.serviceData);
420
+ formData.append(
421
+ "meta",
422
+ JSON.stringify({
423
+ targetAccount: data.account,
424
+ targetEnvironment: data.environment,
425
+ }),
426
+ );
427
+ formData.append("labels", JSON.stringify({ project: data.project }));
428
+ formData.append("comment", " ");
429
+ const response = await fetch(url.toString(), {
430
+ method: "POST",
431
+ body: formData,
453
432
  });
454
- }
455
-
456
- let previousRevision = 1;
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;
433
+ if (!response.ok) {
434
+ throw new Error(`HTTP error! status: ${response.status}`);
462
435
  }
463
- }
464
- else{
465
- previousRevision = getLatestRevision(data.revisions) || 1;
466
- }
467
436
 
468
- const scaleConfig: any = {};
469
- if (data.role && data.role.length > 0) {
470
- scaleConfig.detail = {};
471
- data.role.forEach((role) => {
472
- scaleConfig.detail[role.name] = {
473
- hsize: role.hsize || scale || data.minReplicas || 1,
474
- };
475
- });
437
+ const jsonResponse = await response.json();
438
+
439
+ const isTimeout = jsonResponse?.events?.some(
440
+ (event: any) => event.content === "_timeout_",
441
+ );
442
+
443
+ if (isTimeout) {
444
+ console.error("Timeout en la petición:", {
445
+ isOk: false,
446
+ code: "TIMEOUT",
447
+ error: "_timeout_",
448
+ });
449
+ }
476
450
  } else {
477
- scaleConfig.hsize = scale || data.minReplicas || 1;
478
- }
479
- const meta = {
480
- scaling: {
481
- simple:
482
- data.role?.reduce((acc, role) => {
483
- if (role.scalling && role.name) {
484
- acc[role.name] = {
485
- scale_up: {
486
- cpu: Math.min(parseInt(role.scalling.cpu.up) || 0, 100),
487
- memory: Math.min(parseInt(role.scalling.memory.up) || 0, 100),
488
- },
489
- scale_down: {
490
- cpu: Math.min(parseInt(role.scalling.cpu.down) || 0, 100),
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
- };
451
+ const parameterObject: Record<string, any> = {};
452
+ if (data.parameters && data.parameters.length > 0) {
453
+ data.parameters.forEach((param) => {
454
+ const key = param.configKey || param.name;
455
+ const paramType = param.type?.toLowerCase();
456
+ if (paramType === "number" || paramType === "integer") {
457
+ parameterObject[key] = Number(param.value) || 0;
458
+ } else if (paramType === "boolean") {
459
+ parameterObject[key] = param.value === "true";
460
+ } else {
461
+ parameterObject[key] = param.value;
462
+ }
463
+ });
464
+ }
505
465
 
506
- const updateBody = {
507
- spec: {
508
- type: "update-config",
509
- comment: "Service configuration update",
510
- config: {
511
- parameter: parameterObject,
512
- resource: resourceObject,
513
- resilience: 0,
514
- scale: scaleConfig,
466
+ const resourceObject: Record<string, any> = {};
467
+ if (data.resources && data.resources.length > 0) {
468
+ data.resources.forEach((resource) => {
469
+ if (resource.type === "volume") {
470
+ resourceObject[resource.name] = {
471
+ volume: {
472
+ kind: "storage",
473
+ size: parseInt(resource.value) || 1,
474
+ unit: "G",
475
+ type: resource.kind,
476
+ },
477
+ };
478
+ } else if (resource.type === "secret") {
479
+ resourceObject[resource.name] = {
480
+ secret: `${data.tenant}/${resource.value}`,
481
+ };
482
+ } else if (resource.type === "domain") {
483
+ resourceObject[resource.name] = {
484
+ domain: `${data.tenant}/${resource.value}`,
485
+ };
486
+ } else if (resource.type === "ca") {
487
+ resourceObject[resource.name] = {
488
+ ca: `${data.tenant}/${resource.value}`,
489
+ };
490
+ } else if (resource.type === "certificate") {
491
+ resourceObject[resource.name] = {
492
+ certificate: `${data.tenant}/${resource.value}`,
493
+ };
494
+ } else if (resource.type === "port") {
495
+ resourceObject[resource.name] = {
496
+ port: `${data.tenant}/${resource.value}`,
497
+ };
498
+ }
499
+ });
500
+ }
501
+
502
+ let previousRevision = 1;
503
+ if (data.currentRevision) {
504
+ previousRevision = parseInt(data.currentRevision.toString(), 10);
505
+ if (isNaN(previousRevision)) {
506
+ console.warn("currentRevision is not a valid number, using 1");
507
+ previousRevision = 1;
508
+ }
509
+ } else {
510
+ previousRevision = getLatestRevision(data.revisions) || 1;
511
+ }
512
+
513
+ const scaleConfig: any = {};
514
+ if (data.role && data.role.length > 0) {
515
+ scaleConfig.detail = {};
516
+ data.role.forEach((role) => {
517
+ scaleConfig.detail[role.name] = {
518
+ hsize: role.hsize || scale || data.minReplicas || 1,
519
+ };
520
+ });
521
+ } else {
522
+ scaleConfig.hsize = scale || data.minReplicas || 1;
523
+ }
524
+ const meta = {
525
+ scaling: {
526
+ simple:
527
+ data.role?.reduce(
528
+ (acc, role) => {
529
+ if (role.scalling && role.name) {
530
+ acc[role.name] = {
531
+ scale_up: {
532
+ cpu: Math.min(parseInt(role.scalling.cpu.up) || 0, 100),
533
+ memory: Math.min(
534
+ parseInt(role.scalling.memory.up) || 0,
535
+ 100,
536
+ ),
537
+ },
538
+ scale_down: {
539
+ cpu: Math.min(parseInt(role.scalling.cpu.down) || 0, 100),
540
+ memory: Math.min(
541
+ parseInt(role.scalling.memory.down) || 0,
542
+ 100,
543
+ ),
544
+ },
545
+ hysteresis: parseInt(role.scalling.histeresys) || 0,
546
+ min_replicas: role.scalling.instances.min || 0,
547
+ max_replicas: role.scalling.instances.max || 0,
548
+ };
549
+ }
550
+ return acc;
551
+ },
552
+ {} as Record<string, any>,
553
+ ) || {},
515
554
  },
516
- meta: meta,
517
- },
518
- tenant: data.tenant,
519
- service: data.name,
520
- previous: previousRevision,
521
- };
555
+ };
522
556
 
523
- const response = await makeGlobalWebSocketRequest(
524
- "revision:update_revision",
525
- updateBody,
526
- 30000,
527
- "UPDATE_CONFIG",
528
- data.name
529
- );
557
+ const updateBody = {
558
+ spec: {
559
+ type: "update-config",
560
+ comment: "Service configuration update",
561
+ config: {
562
+ parameter: parameterObject,
563
+ resource: resourceObject,
564
+ resilience: 0,
565
+ scale: scaleConfig,
566
+ },
567
+ meta: meta,
568
+ },
569
+ tenant: data.tenant,
570
+ service: data.name,
571
+ previous: previousRevision,
572
+ };
573
+
574
+ const response = await makeGlobalWebSocketRequest(
575
+ "revision:update_revision",
576
+ updateBody,
577
+ 30000,
578
+ "UPDATE_CONFIG",
579
+ data.name,
580
+ );
581
+ }
530
582
 
531
583
  const updatedService: Service = {
532
584
  ...data,
@@ -577,7 +629,7 @@ export const updateService = async (
577
629
  };
578
630
  export const unlinkServices = async (service: Service, token: string) => {
579
631
  const deleteLinks: Link[] = service.links.filter(
580
- (link) => link.delete === true
632
+ (link) => link.delete === true,
581
633
  );
582
634
  if (deleteLinks.length > 0) {
583
635
  await Promise.all(
@@ -592,7 +644,7 @@ export const unlinkServices = async (service: Service, token: string) => {
592
644
  unlinkBody,
593
645
  30000,
594
646
  "UNLINK",
595
- service.name
647
+ service.name,
596
648
  );
597
649
 
598
650
  const unlinkNotification: Notification = {
@@ -628,7 +680,7 @@ export const unlinkServices = async (service: Service, token: string) => {
628
680
  };
629
681
  eventHelper.notification.publish.creation(notification);
630
682
  }
631
- })
683
+ }),
632
684
  );
633
685
  }
634
686
  };
@@ -653,7 +705,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
653
705
  linkBody,
654
706
  30000,
655
707
  "UNLINK",
656
- link.origin
708
+ link.origin,
657
709
  );
658
710
 
659
711
  // const unlinkNotification: Notification = {
@@ -699,7 +751,7 @@ export const updateServiceLinks = async (link: Link, token: string) => {
699
751
  linkBody,
700
752
  30000,
701
753
  "LINK",
702
- link.origin
754
+ link.origin,
703
755
  );
704
756
 
705
757
  const notification: Notification = {
@@ -755,7 +807,7 @@ export const changeRevision = async (data: Service, token: string) => {
755
807
  revisionBody,
756
808
  30000,
757
809
  "UPDATE_REVISION",
758
- data.name
810
+ data.name,
759
811
  );
760
812
  const notification: Notification = {
761
813
  type: "success",
@@ -791,6 +843,6 @@ function getLatestRevision(revisions: string[]): number | null {
791
843
  if (!revisions || revisions.length === 0) {
792
844
  return null;
793
845
  }
794
-
846
+
795
847
  return Math.max(...revisions.map(Number));
796
- }
848
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.0.41",
3
+ "version": "1.0.42",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {