@kumori/aurora-backend-handler 1.0.50 → 1.0.52

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.
@@ -4,7 +4,23 @@ import {
4
4
  makeGlobalWebSocketRequest,
5
5
  } from "../websocket-manager.ts";
6
6
  import { environment } from "../environment.ts";
7
- import { Account, Container, Environment, Instance, MarketplaceItem, Notification, Organization, Platform, Registry, Resource, Service, Tenant, User, UserData } from "@kumori/aurora-interfaces";
7
+ import {
8
+ Account,
9
+ Container,
10
+ Environment,
11
+ Instance,
12
+ MarketplaceItem,
13
+ Notification,
14
+ Organization,
15
+ Platform,
16
+ Registry,
17
+ Resource,
18
+ Service,
19
+ Tenant,
20
+ User,
21
+ UserData,
22
+ } from "@kumori/aurora-interfaces";
23
+ import { Revision } from "@kumori/aurora-interfaces/interfaces/revision-interface.ts";
8
24
 
9
25
  type Security = string;
10
26
 
@@ -30,7 +46,7 @@ export const isUserLogged = async (security: Security) => {
30
46
  {},
31
47
  30000,
32
48
  "GET",
33
- "USER_INFO"
49
+ "USER_INFO",
34
50
  );
35
51
  userLogged = true;
36
52
  } catch (error) {
@@ -54,9 +70,9 @@ export const createUser = async (user: User) => {
54
70
  {
55
71
  method: "POST",
56
72
  body: JSON.stringify(userBody),
57
- }
73
+ },
58
74
  );
59
- if(response.ok){
75
+ if (response.ok) {
60
76
  eventHelper.user.publish.created(user);
61
77
  }
62
78
  if (!response.ok) {
@@ -64,10 +80,11 @@ export const createUser = async (user: User) => {
64
80
  user.name = error.code;
65
81
  eventHelper.user.publish.creationError(user);
66
82
  throw new Error(
67
- `HTTP Error ${response.status}: ${error.message || "Unknown error"}`
83
+ `HTTP Error ${response.status}: ${error.message || "Unknown error"}`,
68
84
  );
69
85
  }
70
86
  };
87
+
71
88
  export const loadUserData = async () => {
72
89
  try {
73
90
  const response = await makeGlobalWebSocketRequest("user:user_info", {});
@@ -79,13 +96,7 @@ export const loadUserData = async () => {
79
96
  id: userResponse.userRecord.id.name,
80
97
  name: userResponse.userRecord.spec.userinfo.name,
81
98
  surname: userResponse.userRecord.spec.userinfo.surname,
82
- provider: [
83
- {
84
- name: provider,
85
- email: email || "",
86
- password: "",
87
- },
88
- ],
99
+ provider: [{ name: provider, email: email || "", password: "" }],
89
100
  notificationsEnabled: "true",
90
101
  organizations: [],
91
102
  clusterTokens: [],
@@ -102,11 +113,12 @@ export const loadUserData = async () => {
102
113
  { strict: true },
103
114
  30000,
104
115
  "GET",
105
- "ALL_TENANTS"
116
+ "ALL_TENANTS",
106
117
  );
107
118
  const tenantsData = tenantsResponse.data;
108
119
  const userTenants: Tenant[] = [];
109
120
  const userOrganizations: Organization[] = [];
121
+
110
122
  for (const [_, value] of Object.entries(tenantsData)) {
111
123
  const parts = (value as any).toString().split(",");
112
124
  userTenants.push({
@@ -121,26 +133,18 @@ export const loadUserData = async () => {
121
133
  role: parts[1],
122
134
  status: "healthy",
123
135
  users: [],
124
- registry: [
125
- {
126
- name: "",
127
- public: false,
128
- credentials: "",
129
- domain: "",
130
- },
131
- ],
136
+ registry: [{ name: "", public: false, credentials: "", domain: "" }],
132
137
  });
133
138
  }
139
+
134
140
  for (const tenant of userTenants) {
135
141
  try {
136
142
  const tenantResponse = await makeGlobalWebSocketRequest(
137
143
  "tenant:tenant_info",
138
- {
139
- tenant: tenant.name,
140
- },
144
+ { tenant: tenant.name },
141
145
  30000,
142
146
  "GET",
143
- tenant.name
147
+ tenant.name,
144
148
  );
145
149
  const tenantData = tenantResponse.data;
146
150
  const registries = tenantData?.registries?.registries;
@@ -157,22 +161,18 @@ export const loadUserData = async () => {
157
161
  extra: {},
158
162
  password: "",
159
163
  };
160
- if (tenantOptions?.endpoint) {
164
+ if (tenantOptions?.endpoint)
161
165
  registry.domain = tenantOptions.endpoint;
162
- }
163
- if (tenantOptions?.credentials) {
166
+ if (tenantOptions?.credentials)
164
167
  registry.credentials = tenantOptions.credentials;
165
- }
166
- if (typeof tenantOptions?.public === "boolean") {
168
+ if (typeof tenantOptions?.public === "boolean")
167
169
  registry.public = tenantOptions.public;
168
- }
169
- if (tenantData?.domains && Object.keys(tenantData.domains)[0]) {
170
+ if (tenantData?.domains && Object.keys(tenantData.domains)[0])
170
171
  registry.name = Object.keys(tenantData.domains)[0];
171
- }
172
172
  tenant.registry.push(registry);
173
173
  } else {
174
174
  console.warn(
175
- `No se encontró información de registry para el tenant ${tenant.name}`
175
+ `No se encontró información de registry para el tenant ${tenant.name}`,
176
176
  );
177
177
  }
178
178
 
@@ -193,10 +193,7 @@ export const loadUserData = async () => {
193
193
  name: env.id.name,
194
194
  account: `${account.account.id.parent.name}-${account.account.id.name}`,
195
195
  tenant: account.account.id.parent.name.split("tenant/")[1],
196
- logo: `${
197
- env.logo ||
198
- "https://kumori.systems/wp-content/uploads/2023/07/cropped-favicon-kumori.png"
199
- }`,
196
+ logo: `${env.logo || "https://kumori.systems/wp-content/uploads/2023/07/cropped-favicon-kumori.png"}`,
200
197
  services: [],
201
198
  domains: [],
202
199
  status: {
@@ -255,7 +252,7 @@ export const loadUserData = async () => {
255
252
  }
256
253
 
257
254
  const cloudProviderInfo = extractCloudProviderInfo(
258
- account.account.spec
255
+ account.account.spec,
259
256
  );
260
257
  const newAccount: Account = {
261
258
  id: `${account.account.id.parent.name}-${account.account.id.name}`,
@@ -265,10 +262,7 @@ export const loadUserData = async () => {
265
262
  name: account.account.spec.api,
266
263
  ...cloudProviderInfo,
267
264
  },
268
- logo: `${
269
- account.account.spec.api ||
270
- "https://kumori.systems/wp-content/uploads/2023/07/cropped-favicon-kumori.png"
271
- }`,
265
+ logo: `${account.account.spec.api || "https://kumori.systems/wp-content/uploads/2023/07/cropped-favicon-kumori.png"}`,
272
266
  environments: environmentsIds,
273
267
  services: [],
274
268
  domains: [],
@@ -277,9 +271,9 @@ export const loadUserData = async () => {
277
271
  "InvalidCredentials"
278
272
  ? "InvalidCredentials"
279
273
  : !account.account.status.validCredentials?.status &&
280
- account.account.id !== "kumori"
281
- ? "pending"
282
- : "healthy"
274
+ account.account.id !== "kumori"
275
+ ? "pending"
276
+ : "healthy"
283
277
  : "",
284
278
  usage: {
285
279
  current: {
@@ -335,6 +329,7 @@ export const loadUserData = async () => {
335
329
 
336
330
  tenantAccounts.push(newAccount);
337
331
  }
332
+
338
333
  const kinds = [
339
334
  "ca",
340
335
  "certificate",
@@ -343,18 +338,14 @@ export const loadUserData = async () => {
343
338
  "secret",
344
339
  "volume",
345
340
  ];
346
-
347
341
  for (const kind of kinds) {
348
342
  try {
349
343
  const resourcesResponse = await makeGlobalWebSocketRequest(
350
344
  "resource:list_resources",
351
- {
352
- tenant: tenant.name,
353
- kind: kind,
354
- },
345
+ { tenant: tenant.name, kind },
355
346
  30000,
356
347
  "GET",
357
- "ALL_RESOURCES"
348
+ "ALL_RESOURCES",
358
349
  );
359
350
  const resourcesData = resourcesResponse.data;
360
351
  if (
@@ -362,7 +353,7 @@ export const loadUserData = async () => {
362
353
  !Array.isArray(resourcesData[kind])
363
354
  ) {
364
355
  console.warn(
365
- `No se encontraron recursos de tipo ${kind} o no es un array`
356
+ `No se encontraron recursos de tipo ${kind} o no es un array`,
366
357
  );
367
358
  continue;
368
359
  }
@@ -372,28 +363,21 @@ export const loadUserData = async () => {
372
363
  const resourceName = resource.id.name;
373
364
  const resourceResponse = await makeGlobalWebSocketRequest(
374
365
  "resource:resource_info",
375
- {
376
- tenant: tenant.name,
377
- kind: kind,
378
- resource: resourceName,
379
- },
366
+ { tenant: tenant.name, kind, resource: resourceName },
380
367
  30000,
381
368
  "GET",
382
- resourceName
369
+ resourceName,
383
370
  );
384
371
  const resourceDataJson = resourceResponse.data;
385
372
  const resourceType = resourceDataJson.id.kind;
386
373
  let resourceStatus: "used" | "available" | "error" =
387
374
  "available";
388
375
 
389
- if (
390
- resourceDataJson.status &&
391
- resourceDataJson.status.requested
392
- ) {
393
- const requestedKeys = Object.keys(
394
- resourceDataJson.status.requested
395
- );
396
- if (requestedKeys.length > 0) {
376
+ if (resourceDataJson.status?.requested) {
377
+ if (
378
+ Object.keys(resourceDataJson.status.requested).length >
379
+ 0
380
+ ) {
397
381
  resourceStatus = "used";
398
382
  }
399
383
  }
@@ -417,10 +401,7 @@ export const loadUserData = async () => {
417
401
  status: resourceStatus,
418
402
  } as Resource);
419
403
  } else if (
420
- resourceType === "domain" ||
421
- resourceType === "port" ||
422
- resourceType === "ca" ||
423
- resourceType === "secret"
404
+ ["domain", "port", "ca", "secret"].includes(resourceType)
424
405
  ) {
425
406
  tenant.resources.push({
426
407
  type: kind,
@@ -432,26 +413,25 @@ export const loadUserData = async () => {
432
413
  } catch (resourceError) {
433
414
  console.error(
434
415
  `Error procesando recurso individual de tipo ${kind}:`,
435
- resourceError
416
+ resourceError,
436
417
  );
437
418
  }
438
419
  }
439
420
  } catch (error) {
440
421
  console.error(
441
422
  `Error procesando recursos de tipo ${kind}:`,
442
- error
423
+ error,
443
424
  );
444
425
  }
445
426
  }
446
427
  }
428
+
447
429
  const servicesResponse = await makeGlobalWebSocketRequest(
448
430
  "service:list_services",
449
- {
450
- tenant: tenant.name,
451
- },
431
+ { tenant: tenant.name },
452
432
  30000,
453
433
  "GET",
454
- "ALL_SERVICES"
434
+ "ALL_SERVICES",
455
435
  );
456
436
  const servicesData = servicesResponse.data;
457
437
  const serviceEntries = Object.entries(servicesData);
@@ -464,6 +444,7 @@ export const loadUserData = async () => {
464
444
  timestamp: "",
465
445
  args: [],
466
446
  };
447
+
467
448
  const serviceResponse = await makeGlobalWebSocketRequest(
468
449
  "service:describe_service",
469
450
  {
@@ -473,10 +454,11 @@ export const loadUserData = async () => {
473
454
  },
474
455
  30000,
475
456
  "GET",
476
- (serviceValue as any).name
457
+ (serviceValue as any).name,
477
458
  );
478
459
  const serviceData = serviceResponse.data;
479
- let revisionData;
460
+
461
+ let revisionData: any;
480
462
  try {
481
463
  const revisionResponse = await makeGlobalWebSocketRequest(
482
464
  "revision:revision_info",
@@ -487,7 +469,7 @@ export const loadUserData = async () => {
487
469
  },
488
470
  30000,
489
471
  "GET_REVISION",
490
- (serviceValue as any).name
472
+ (serviceValue as any).name,
491
473
  );
492
474
  revisionData = revisionResponse.data;
493
475
  } catch (revisionError) {
@@ -496,48 +478,76 @@ export const loadUserData = async () => {
496
478
  message: "",
497
479
  timestamp: "",
498
480
  args: [],
499
- },
481
+ };
500
482
  console.warn(
501
- `No se pudo obtener la revisión para el servicio ${
502
- (serviceValue as any).name
503
- }:`,
504
- revisionError
483
+ `No se pudo obtener la revisión para el servicio ${(serviceValue as any).name}:`,
484
+ revisionError,
505
485
  );
506
486
  continue;
507
487
  }
508
488
 
509
489
  const serviceName = revisionData.solution.top;
510
- let revisionsData;
490
+
491
+ // revisionData.revision is a string ID, revisionData.intensives has the resource limits
492
+ const revisionId: string = revisionData.revision;
493
+ const intensives = revisionData.intensives ?? {};
494
+
495
+ let rawHistoryData: any[] = [];
511
496
  try {
512
497
  const revisionsResponse = await makeGlobalWebSocketRequest(
513
498
  "service:report_history_service",
514
- {
515
- tenant: tenant.name,
516
- service: serviceName,
517
- },
499
+ { tenant: tenant.name, service: serviceName },
518
500
  30000,
519
501
  "GET_HISTORY",
520
- serviceName
502
+ serviceName,
521
503
  );
522
- revisionsData = revisionsResponse.data;
504
+ rawHistoryData = revisionsResponse.data ?? [];
523
505
  } catch (historyError) {
524
506
  serviceStatus = {
525
507
  code: "PENDING",
526
508
  message: "",
527
509
  timestamp: "",
528
510
  args: [],
529
- },
511
+ };
530
512
  console.warn(
531
513
  `No se pudo obtener el historial para el servicio ${serviceName}:`,
532
- historyError
514
+ historyError,
533
515
  );
534
516
  continue;
535
517
  }
536
518
 
537
- const revisions: string[] = [];
538
- for (const revision of revisionsData) {
539
- revisions.push(revision.revision);
540
- }
519
+ const revisions: Revision[] = (rawHistoryData as any[]).map(
520
+ (entry: any) => ({
521
+ id: String(entry.revision ?? entry.id ?? ""),
522
+ schema: entry.spec ?? {},
523
+ usage: {
524
+ current: {
525
+ cpu: 0,
526
+ memory: 0,
527
+ storage: 0,
528
+ volatileStorage: 0,
529
+ nonReplicatedStorage: 0,
530
+ persistentStorage: 0,
531
+ },
532
+ limit: {
533
+ cpu: { max: 0, min: 0 },
534
+ memory: { max: 0, min: 0 },
535
+ storage: { max: 0, min: 0 },
536
+ volatileStorage: { max: 0, min: 0 },
537
+ nonReplicatedStorage: { max: 0, min: 0 },
538
+ persistentStorage: { max: 0, min: 0 },
539
+ },
540
+ cost: 0,
541
+ },
542
+ status: entry.status ?? {
543
+ code: "",
544
+ message: "",
545
+ timestamp: "",
546
+ args: [],
547
+ },
548
+ createdAt: entry.createdAt ?? "",
549
+ }),
550
+ );
541
551
 
542
552
  const serviceRoles: { name: string; instances: Instance[] }[] =
543
553
  [];
@@ -558,13 +568,13 @@ export const loadUserData = async () => {
558
568
  },
559
569
  30000,
560
570
  "GET_ROLE",
561
- serviceName + "_" + roleName
571
+ `${serviceName}_${roleName}`,
562
572
  );
563
573
  const instancesData = instancesResponse.data;
564
574
  const instances: Instance[] = [];
565
575
 
566
576
  for (const [instanceName, instanceValue] of Object.entries(
567
- instancesData.instances
577
+ instancesData.instances,
568
578
  )) {
569
579
  const containers: Container[] = [];
570
580
  for (const [
@@ -620,27 +630,15 @@ export const loadUserData = async () => {
620
630
  .artifact.description.code[roleName]?.size
621
631
  ?.memory?.size / 1000,
622
632
  },
623
- storage: {
624
- max: 0,
625
- min: 0,
626
- },
627
- volatileStorage: {
628
- max: 0,
629
- min: 0,
630
- },
631
- nonReplicatedStorage: {
632
- max: 0,
633
- min: 0,
634
- },
635
- persistentStorage: {
636
- max: 0,
637
- min: 0,
638
- },
633
+ storage: { max: 0, min: 0 },
634
+ volatileStorage: { max: 0, min: 0 },
635
+ nonReplicatedStorage: { max: 0, min: 0 },
636
+ persistentStorage: { max: 0, min: 0 },
639
637
  },
640
638
  cost: 0,
641
639
  },
642
640
  logs: [],
643
- containers: containers,
641
+ containers,
644
642
  });
645
643
  }
646
644
  serviceRoles.push({ name: roleName, instances });
@@ -650,10 +648,10 @@ export const loadUserData = async () => {
650
648
  message: "",
651
649
  timestamp: "",
652
650
  args: [],
653
- },
651
+ };
654
652
  console.warn(
655
653
  `Error obteniendo instancias para el rol ${roleName}:`,
656
- instanceError
654
+ instanceError,
657
655
  );
658
656
  }
659
657
  }
@@ -676,7 +674,7 @@ export const loadUserData = async () => {
676
674
  name: (serviceValue as any).name,
677
675
  logo: "",
678
676
  description: "",
679
- revisions: revisions,
677
+ revisions,
680
678
  status: serviceStatus,
681
679
  role: serviceRoles,
682
680
  links: [],
@@ -693,57 +691,53 @@ export const loadUserData = async () => {
693
691
  },
694
692
  limit: {
695
693
  cpu: {
696
- max: revisionData.revision.spec.intensives.vcpu / 1000,
697
- min: revisionData.revision.spec.intensives.vcpu / 1000,
694
+ max: intensives.vcpu / 1000,
695
+ min: intensives.vcpu / 1000,
698
696
  },
699
697
  memory: {
700
- max: revisionData.revision.spec.intensives.ram / 1000,
701
- min: revisionData.revision.spec.intensives.ram / 1000,
698
+ max: intensives.ram / 1000,
699
+ min: intensives.ram / 1000,
702
700
  },
703
701
  storage: {
704
- max: revisionData.revision.spec.intensives.shared_disk,
705
- min: revisionData.revision.spec.intensives.shared_disk,
702
+ max: intensives.shared_disk,
703
+ min: intensives.shared_disk,
706
704
  },
707
705
  volatileStorage: {
708
- max: revisionData.revision.spec.intensives.volatile_disk,
709
- min: revisionData.revision.spec.intensives.volatile_disk,
706
+ max: intensives.volatile_disk,
707
+ min: intensives.volatile_disk,
710
708
  },
711
709
  nonReplicatedStorage: {
712
- max: revisionData.revision.spec.intensives
713
- .nrpersistent_disk,
714
- min: revisionData.revision.spec.intensives
715
- .nrpersistent_disk,
710
+ max: intensives.nrpersistent_disk,
711
+ min: intensives.nrpersistent_disk,
716
712
  },
717
713
  persistentStorage: {
718
- max: revisionData.revision.spec.intensives
719
- .persistent_disk,
720
- min: revisionData.revision.spec.intensives
721
- .persistent_disk,
714
+ max: intensives.persistent_disk,
715
+ min: intensives.persistent_disk,
722
716
  },
723
717
  },
724
718
  cost: 0,
725
719
  },
726
720
  minReplicas: 0,
727
721
  maxReplicas: 0,
728
- lastDeployed: `${revisionData.revision.spec.tstamp}`,
722
+ lastDeployed: `${revisionData.tstamp ?? ""}`,
729
723
  project: "",
730
724
  registry:
731
725
  roles[firstRoleName].artifact.description.code[containerName]
732
- .image.hub.name,
726
+ ?.image?.hub?.name ?? "",
733
727
  imageName:
734
728
  roles[firstRoleName].artifact.description.code[containerName]
735
- .image.tag,
729
+ ?.image?.tag ?? "",
736
730
  entrypoint:
737
731
  roles[firstRoleName].artifact.description.code[containerName]
738
- .entrypoint,
739
- cmd: roles[firstRoleName].artifact.description.code[
740
- containerName
741
- ].cmd,
732
+ ?.entrypoint ?? "",
733
+ cmd:
734
+ roles[firstRoleName].artifact.description.code[containerName]
735
+ ?.cmd ?? "",
742
736
  serverChannels: [],
743
737
  clientChannels: [],
744
738
  duplexChannels: [],
745
739
  cloudProvider: "",
746
- currentRevision: revisionData.revision.id.name,
740
+ currentRevision: revisionId,
747
741
  };
748
742
 
749
743
  userServices.push(newService);
@@ -751,27 +745,25 @@ export const loadUserData = async () => {
751
745
  console.error("Error al obtener los datos del servicio:", error);
752
746
  }
753
747
  }
748
+
754
749
  for (const account of tenantAccounts) {
755
750
  account.services = userServices
756
751
  .filter((service) => service.account === account.name)
757
752
  .map((service) => service.name);
758
753
  }
759
- for (const environment of tenantEnvironments) {
760
- environment.services = userServices
761
- .filter((service) => service.environment === environment.name)
754
+ for (const env of tenantEnvironments) {
755
+ env.services = userServices
756
+ .filter((service) => service.environment === env.name)
762
757
  .map((service) => service.name);
763
758
  }
764
759
 
765
760
  try {
766
761
  const marketplaceResponse = await makeGlobalWebSocketRequest(
767
762
  "marketplace:search_marketplace",
768
- {
769
- tenant: tenant.name,
770
- name: "",
771
- },
763
+ { tenant: tenant.name, name: "" },
772
764
  30000,
773
765
  "GET",
774
- "MARKETPLACE"
766
+ "MARKETPLACE",
775
767
  );
776
768
  const marketplaceData = marketplaceResponse.data;
777
769
  const tenantItems: MarketplaceItem[] = [];
@@ -779,36 +771,31 @@ export const loadUserData = async () => {
779
771
  let cpu = 0;
780
772
  let memory = 0;
781
773
  (value as any).tags.forEach((tag: string) => {
782
- if (tag.includes("cpu")) {
774
+ if (tag.includes("cpu"))
783
775
  cpu = Number(tag.split("::")[1].split("vCPU")[0]);
784
- } else if (tag.includes("memory")) {
776
+ else if (tag.includes("memory"))
785
777
  memory = Number(tag.split("::")[1].split("MB")[0]);
786
- }
787
778
  });
788
- const item: MarketplaceItem = {
779
+ tenantItems.push({
789
780
  tenant: tenant.toString(),
790
781
  name: (value as any).name,
791
782
  logo: (value as any).icon,
792
783
  description: (value as any).name,
793
784
  version: (value as any).version,
794
- requirements: {
795
- cpu: cpu,
796
- memory: memory,
797
- },
785
+ requirements: { cpu, memory },
798
786
  status: "",
799
787
  instances: [],
800
788
  links: [],
801
789
  resources: [],
802
790
  domain: (value as any).domain,
803
791
  type: (value as any).artifactTypes[0],
804
- };
805
- tenantItems.push(item);
792
+ });
806
793
  });
807
794
  tenant.marketplaceItems = tenantItems;
808
795
  } catch (marketplaceError) {
809
796
  console.error(
810
797
  `Error obteniendo marketplace para tenant ${tenant.name}:`,
811
- marketplaceError
798
+ marketplaceError,
812
799
  );
813
800
  tenant.marketplaceItems = [];
814
801
  }
@@ -824,17 +811,14 @@ export const loadUserData = async () => {
824
811
  try {
825
812
  const organizationsResponse = await makeGlobalWebSocketRequest(
826
813
  "organization:list_organizations",
827
- {
828
- strict: true,
829
- },
814
+ { strict: true },
830
815
  30000,
831
816
  "GET",
832
- "ORGANIZATIONS"
817
+ "ORGANIZATIONS",
833
818
  );
834
819
  const organizationsData = organizationsResponse.data;
835
- const organizationsEntries = Object.entries(organizationsData);
836
- for (const [, organizationValue] of organizationsEntries) {
837
- const newOrg = {
820
+ for (const [, organizationValue] of Object.entries(organizationsData)) {
821
+ userOrganizations.push({
838
822
  id: (organizationValue as any).spec.companyName,
839
823
  name: (organizationValue as any).id.name,
840
824
  usersIds: Object.keys((organizationValue as any).spec.users),
@@ -851,8 +835,7 @@ export const loadUserData = async () => {
851
835
  zipcode: (organizationValue as any).spec.billing.zip,
852
836
  },
853
837
  invoices: [],
854
- };
855
- userOrganizations.push(newOrg);
838
+ });
856
839
  }
857
840
  } catch (organizationError) {
858
841
  console.error("Error obteniendo organizaciones:", organizationError);
@@ -864,9 +847,8 @@ export const loadUserData = async () => {
864
847
  {},
865
848
  30000,
866
849
  "GET",
867
- "PLATFORM"
850
+ "PLATFORM",
868
851
  );
869
-
870
852
  const platformData: Platform = {
871
853
  instanceName: String(platformResponse.instanceName),
872
854
  platformVersion: String(platformResponse.platformVersion),
@@ -885,72 +867,72 @@ export const loadUserData = async () => {
885
867
  freemiumAdvancedLimits: {
886
868
  vcpu: {
887
869
  lowmark: Number(
888
- platformResponse.freemiumAdvancedLimits.vcpu.lowmark
870
+ platformResponse.freemiumAdvancedLimits.vcpu.lowmark,
889
871
  ),
890
872
  highmark: Number(
891
- platformResponse.freemiumAdvancedLimits.vcpu.highmark
873
+ platformResponse.freemiumAdvancedLimits.vcpu.highmark,
892
874
  ),
893
875
  unit: String(platformResponse.freemiumAdvancedLimits.vcpu.unit),
894
876
  },
895
877
  memory: {
896
878
  lowmark: Number(
897
- platformResponse.freemiumAdvancedLimits.memory.lowmark
879
+ platformResponse.freemiumAdvancedLimits.memory.lowmark,
898
880
  ),
899
881
  highmark: Number(
900
- platformResponse.freemiumAdvancedLimits.memory.highmark
882
+ platformResponse.freemiumAdvancedLimits.memory.highmark,
901
883
  ),
902
884
  unit: String(platformResponse.freemiumAdvancedLimits.memory.unit),
903
885
  },
904
886
  vstorage: {
905
887
  lowmark: Number(
906
- platformResponse.freemiumAdvancedLimits.vstorage.lowmark
888
+ platformResponse.freemiumAdvancedLimits.vstorage.lowmark,
907
889
  ),
908
890
  highmark: Number(
909
- platformResponse.freemiumAdvancedLimits.vstorage.highmark
891
+ platformResponse.freemiumAdvancedLimits.vstorage.highmark,
910
892
  ),
911
893
  unit: String(
912
- platformResponse.freemiumAdvancedLimits.vstorage.unit
894
+ platformResponse.freemiumAdvancedLimits.vstorage.unit,
913
895
  ),
914
896
  },
915
897
  nrstorage: {
916
898
  lowmark: Number(
917
- platformResponse.freemiumAdvancedLimits.nrstorage.lowmark
899
+ platformResponse.freemiumAdvancedLimits.nrstorage.lowmark,
918
900
  ),
919
901
  highmark: Number(
920
- platformResponse.freemiumAdvancedLimits.nrstorage.highmark
902
+ platformResponse.freemiumAdvancedLimits.nrstorage.highmark,
921
903
  ),
922
904
  unit: String(
923
- platformResponse.freemiumAdvancedLimits.nrstorage.unit
905
+ platformResponse.freemiumAdvancedLimits.nrstorage.unit,
924
906
  ),
925
907
  },
926
908
  rstorage: {
927
909
  lowmark: Number(
928
- platformResponse.freemiumAdvancedLimits.rstorage.lowmark
910
+ platformResponse.freemiumAdvancedLimits.rstorage.lowmark,
929
911
  ),
930
912
  highmark: Number(
931
- platformResponse.freemiumAdvancedLimits.rstorage.highmark
913
+ platformResponse.freemiumAdvancedLimits.rstorage.highmark,
932
914
  ),
933
915
  unit: String(
934
- platformResponse.freemiumAdvancedLimits.rstorage.unit
916
+ platformResponse.freemiumAdvancedLimits.rstorage.unit,
935
917
  ),
936
918
  },
937
919
  storage: {
938
920
  lowmark: Number(
939
- platformResponse.freemiumAdvancedLimits.storage.lowmark
921
+ platformResponse.freemiumAdvancedLimits.storage.lowmark,
940
922
  ),
941
923
  highmark: Number(
942
- platformResponse.freemiumAdvancedLimits.storage.highmark
924
+ platformResponse.freemiumAdvancedLimits.storage.highmark,
943
925
  ),
944
926
  unit: String(
945
- platformResponse.freemiumAdvancedLimits.storage.unit
927
+ platformResponse.freemiumAdvancedLimits.storage.unit,
946
928
  ),
947
929
  },
948
930
  cost: {
949
931
  lowmark: Number(
950
- platformResponse.freemiumAdvancedLimits.cost.lowmark
932
+ platformResponse.freemiumAdvancedLimits.cost.lowmark,
951
933
  ),
952
934
  highmark: Number(
953
- platformResponse.freemiumAdvancedLimits.cost.highmark
935
+ platformResponse.freemiumAdvancedLimits.cost.highmark,
954
936
  ),
955
937
  unit: String(platformResponse.freemiumAdvancedLimits.cost.unit),
956
938
  },
@@ -969,30 +951,30 @@ export const loadUserData = async () => {
969
951
  vstorage: {
970
952
  lowmark: Number(platformResponse.freemiumLimits.vstorage.lowmark),
971
953
  highmark: Number(
972
- platformResponse.freemiumLimits.vstorage.highmark
954
+ platformResponse.freemiumLimits.vstorage.highmark,
973
955
  ),
974
956
  unit: String(platformResponse.freemiumLimits.vstorage.unit),
975
957
  },
976
958
  nrstorage: {
977
959
  lowmark: Number(
978
- platformResponse.freemiumLimits.nrstorage.lowmark
960
+ platformResponse.freemiumLimits.nrstorage.lowmark,
979
961
  ),
980
962
  highmark: Number(
981
- platformResponse.freemiumLimits.nrstorage.highmark
963
+ platformResponse.freemiumLimits.nrstorage.highmark,
982
964
  ),
983
965
  unit: String(platformResponse.freemiumLimits.nrstorage.unit),
984
966
  },
985
967
  rstorage: {
986
968
  lowmark: Number(platformResponse.freemiumLimits.rstorage.lowmark),
987
969
  highmark: Number(
988
- platformResponse.freemiumLimits.rstorage.highmark
970
+ platformResponse.freemiumLimits.rstorage.highmark,
989
971
  ),
990
972
  unit: String(platformResponse.freemiumLimits.rstorage.unit),
991
973
  },
992
974
  storage: {
993
975
  lowmark: Number(platformResponse.freemiumLimits.storage.lowmark),
994
976
  highmark: Number(
995
- platformResponse.freemiumLimits.storage.highmark
977
+ platformResponse.freemiumLimits.storage.highmark,
996
978
  ),
997
979
  unit: String(platformResponse.freemiumLimits.storage.unit),
998
980
  },
@@ -1008,9 +990,8 @@ export const loadUserData = async () => {
1008
990
  };
1009
991
  if (eventHelper.user) {
1010
992
  eventHelper.user.publish.loaded(
1011
- new User(userData, userTenants, userOrganizations, platformData)
993
+ new User(userData, userTenants, userOrganizations, platformData),
1012
994
  );
1013
- } else {
1014
995
  }
1015
996
  } catch (error) {
1016
997
  console.error("Error al obtener los datos del tenant:", error);
@@ -1064,6 +1045,7 @@ const extractCloudProviderInfo = (accountSpec: any) => {
1064
1045
  credentialSecret: "",
1065
1046
  };
1066
1047
  };
1048
+
1067
1049
  export const updateUser = async (user: User) => {
1068
1050
  try {
1069
1051
  const userBody = {
@@ -1075,25 +1057,22 @@ export const updateUser = async (user: User) => {
1075
1057
  companyRole: user.rol,
1076
1058
  },
1077
1059
  };
1078
- const response = await makeGlobalWebSocketRequest(
1060
+ await makeGlobalWebSocketRequest(
1079
1061
  "user:modify_user_info",
1080
1062
  userBody,
1081
1063
  30000,
1082
1064
  "PUT",
1083
- "UPDATE_USER"
1065
+ "UPDATE_USER",
1084
1066
  );
1085
1067
  eventHelper.user.publish.updated(user);
1086
- const userUpdatedNotification: Notification = {
1068
+ eventHelper.notification.publish.creation({
1087
1069
  type: "success",
1088
1070
  subtype: "user-updated",
1089
1071
  date: Date.now().toString(),
1090
1072
  status: "unread",
1091
1073
  callToAction: false,
1092
- data: {
1093
- user: user.name
1094
- }
1095
- };
1096
- eventHelper.notification.publish.creation(userUpdatedNotification);
1074
+ data: { user: user.name },
1075
+ });
1097
1076
  } catch (error) {
1098
1077
  console.error("Error updating user:", {
1099
1078
  error,
@@ -1101,65 +1080,56 @@ export const updateUser = async (user: User) => {
1101
1080
  stack: error instanceof Error ? error.stack : undefined,
1102
1081
  });
1103
1082
  eventHelper.user.publish.updateError(user);
1104
- const userUpdatedNotificationError: Notification = {
1083
+ eventHelper.notification.publish.creation({
1105
1084
  type: "error",
1106
1085
  subtype: "tenant-update-error",
1107
1086
  date: Date.now().toString(),
1108
1087
  status: "unread",
1109
1088
  callToAction: false,
1110
- info_content:{
1089
+ info_content: {
1111
1090
  code: (error as any).error.code,
1112
- message: (error as any).error.content
1091
+ message: (error as any).error.content,
1113
1092
  },
1114
- data: {
1115
- user: user.name
1116
- }
1117
- };
1118
- eventHelper.notification.publish.creation(userUpdatedNotificationError);
1093
+ data: { user: user.name },
1094
+ });
1119
1095
  throw error;
1120
1096
  }
1121
1097
  };
1098
+
1122
1099
  export const deleteUSer = async (user: User, security: string) => {
1123
1100
  try {
1124
1101
  await initializeGlobalWebSocketClient(security);
1125
1102
  const response = await makeGlobalWebSocketRequest(
1126
1103
  "user:delete_user",
1127
1104
  {},
1128
- 30000,
1105
+ 30000,
1129
1106
  "DELETE",
1130
1107
  "DELETE_USER",
1131
- "user"
1108
+ "user",
1132
1109
  );
1133
-
1134
- const userDeletedNotification: Notification = {
1110
+ eventHelper.notification.publish.creation({
1135
1111
  type: "success",
1136
1112
  subtype: "user-deleted",
1137
1113
  date: Date.now().toString(),
1138
1114
  status: "unread",
1139
1115
  callToAction: false,
1140
- data: {
1141
- user: user.name
1142
- }
1143
- };
1144
- eventHelper.notification.publish.creation(userDeletedNotification);
1116
+ data: { user: user.name },
1117
+ });
1145
1118
  return response;
1146
1119
  } catch (error) {
1147
1120
  console.error("Error deleting user:", error);
1148
- const userDeletedNotificationError: Notification = {
1121
+ eventHelper.notification.publish.creation({
1149
1122
  type: "error",
1150
1123
  subtype: "user-delete-error",
1151
1124
  date: Date.now().toString(),
1152
1125
  status: "unread",
1153
1126
  callToAction: false,
1154
- info_content:{
1127
+ info_content: {
1155
1128
  code: (error as any).error.code,
1156
- message: (error as any).error.content
1129
+ message: (error as any).error.content,
1157
1130
  },
1158
- data: {
1159
- user: user.name
1160
- }
1161
- };
1162
- eventHelper.notification.publish.creation(userDeletedNotificationError);
1131
+ data: { user: user.name },
1132
+ });
1163
1133
  throw error;
1164
1134
  }
1165
- };
1135
+ };