@kumori/aurora-backend-handler 1.0.7 → 1.0.8

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.
@@ -1,4 +1,10 @@
1
- import { Link, MarketplaceItem, MarketplaceService, Notification, Service } from "@kumori/aurora-interfaces";
1
+ import {
2
+ Link,
3
+ MarketplaceItem,
4
+ MarketplaceService,
5
+ Notification,
6
+ Service,
7
+ } from "@kumori/aurora-interfaces";
2
8
  import { eventHelper } from "../backend-handler";
3
9
  import { environment } from "../environment";
4
10
 
@@ -59,14 +65,14 @@ let pendingLinks = new Map<string, Link[]>();
59
65
  */
60
66
  export const deployMarketplaceItem = async (item: MarketplaceService) => {
61
67
  const complexDeployment = item.deploymentData.serverChannels.find(
62
- (channel) => channel.isPublic
68
+ (channel) => channel.isPublic,
63
69
  );
64
70
  if (complexDeployment !== undefined) {
65
71
  try {
66
72
  const formData = await deployServiceHelper(item.deploymentData, item);
67
73
 
68
74
  const url = new URL(
69
- `${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${item.deploymentData.tenant}/service/${item.deploymentData.name}`
75
+ `${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${item.deploymentData.tenant}/service/${item.deploymentData.name}`,
70
76
  );
71
77
  url.searchParams.append("dryrun", "false");
72
78
  url.searchParams.append("accept", "true");
@@ -86,7 +92,7 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
86
92
  const jsonResponse = await response.json();
87
93
 
88
94
  const isTimeout = jsonResponse?.events?.some(
89
- (event: any) => event.content === "_timeout_"
95
+ (event: any) => event.content === "_timeout_",
90
96
  );
91
97
 
92
98
  if (isTimeout) {
@@ -114,7 +120,7 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
114
120
  resource.type === "bool" ||
115
121
  resource.type === "boolean" ||
116
122
  resource.type === "fileContent" ||
117
- resource.type === "array"
123
+ resource.type === "array",
118
124
  )
119
125
  .map((resource) => {
120
126
  if (resource.type === "string") {
@@ -163,59 +169,67 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
163
169
 
164
170
  const deploymentData: Service = item.deploymentData as unknown as Service;
165
171
  const url = new URL(
166
- `${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${item.deploymentData.tenant}/service/${deploymentData.name}`
172
+ `${environment.apiServer.baseUrl}/api/${environment.apiServer.apiVersion}/tenant/${item.deploymentData.tenant}/service/${deploymentData.name}`,
167
173
  );
168
174
  url.searchParams.append("dsl", "true");
169
- const parametersObj = deploymentConfigParameters.reduce((acc, param) => {
170
- const paramMetadata = item.parameterList.find(
171
- (p) => p.name === param.name
172
- );
173
- if (paramMetadata && (paramMetadata as any).parent === "accesspolicies") {
174
- if (!acc.accesspolicies) {
175
- acc.accesspolicies = {};
175
+ const parametersObj = deploymentConfigParameters.reduce(
176
+ (acc, param) => {
177
+ const paramMetadata = item.parameterList.find(
178
+ (p) => p.name === param.name,
179
+ );
180
+ if (
181
+ paramMetadata &&
182
+ (paramMetadata as any).parent === "accesspolicies"
183
+ ) {
184
+ if (!acc.accesspolicies) {
185
+ acc.accesspolicies = {};
186
+ }
187
+ acc.accesspolicies[param.name] = param.value;
188
+ } else {
189
+ acc[param.name] = param.value;
176
190
  }
177
- acc.accesspolicies[param.name] = param.value;
178
- } else {
179
- acc[param.name] = param.value;
180
- }
181
- return acc;
182
- }, {} as { [key: string]: any });
183
-
184
- const resourcesObj = item.resourceList.reduce((acc, resource: any) => {
185
- if (resource.type === "secret") {
186
- acc[resource.name] = {
187
- secret: resource.value as string,
188
- } as unknown as DeploymentResource;
189
- } else if (resource.type === "volume") {
190
- acc[resource.name] = {
191
- volume: {
192
- kind: "storage",
193
- type: resource.kind,
194
- size: Number(resource.value || 1),
195
- unit: "G",
196
- },
197
- } as unknown as DeploymentResource;
198
- } else if (resource.type === "domain") {
199
- acc[resource.name] = {
200
- domain: resource.value,
201
- } as unknown as DeploymentResource;
202
- } else if (resource.type === "certificate") {
203
- acc[resource.name] = {
204
- certificate: resource.value,
205
- } as unknown as DeploymentResource;
206
- } else if (resource.type === "ca") {
207
- acc[resource.name] = {
208
- ca: resource.value,
209
- } as unknown as DeploymentResource;
210
- }
211
- else if (resource.type === "port") {
212
- acc[resource.name] = {
213
- port: resource.value,
214
- } as unknown as DeploymentResource;
215
- }
191
+ return acc;
192
+ },
193
+ {} as { [key: string]: any },
194
+ );
216
195
 
217
- return acc;
218
- }, {} as { [key: string]: DeploymentResource });
196
+ const resourcesObj = item.resourceList.reduce(
197
+ (acc, resource: any) => {
198
+ if (resource.type === "secret") {
199
+ acc[resource.name] = {
200
+ secret: resource.value as string,
201
+ } as unknown as DeploymentResource;
202
+ } else if (resource.type === "volume") {
203
+ acc[resource.name] = {
204
+ volume: {
205
+ kind: "storage",
206
+ type: resource.kind,
207
+ size: Number(resource.value || 1),
208
+ unit: "G",
209
+ },
210
+ } as unknown as DeploymentResource;
211
+ } else if (resource.type === "domain") {
212
+ acc[resource.name] = {
213
+ domain: resource.value,
214
+ } as unknown as DeploymentResource;
215
+ } else if (resource.type === "certificate") {
216
+ acc[resource.name] = {
217
+ certificate: resource.value,
218
+ } as unknown as DeploymentResource;
219
+ } else if (resource.type === "ca") {
220
+ acc[resource.name] = {
221
+ ca: resource.value,
222
+ } as unknown as DeploymentResource;
223
+ } else if (resource.type === "port") {
224
+ acc[resource.name] = {
225
+ port: resource.value,
226
+ } as unknown as DeploymentResource;
227
+ }
228
+
229
+ return acc;
230
+ },
231
+ {} as { [key: string]: DeploymentResource },
232
+ );
219
233
 
220
234
  const isInbound = item.module === "builtins/inbound";
221
235
 
@@ -224,19 +238,19 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
224
238
  (resource) =>
225
239
  resource.type === "certificate" ||
226
240
  resource.name.toLowerCase().includes("cert") ||
227
- resource.name === "servercert"
241
+ resource.name === "servercert",
228
242
  );
229
243
 
230
244
  const hasDomain = item.resourceList.some(
231
245
  (resource) =>
232
246
  resource.type === "domain" ||
233
247
  resource.name.toLowerCase().includes("domain") ||
234
- resource.name === "serverdomain"
248
+ resource.name === "serverdomain",
235
249
  );
236
250
  const hasPort = item.resourceList.some(
237
251
  (resource) =>
238
252
  resource.type === "port" ||
239
- resource.name.toLowerCase().includes("port")
253
+ resource.name.toLowerCase().includes("port"),
240
254
  );
241
255
  let correctType = "tcp";
242
256
  let requiredParameters: { [key: string]: any } = {};
@@ -266,7 +280,7 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
266
280
  name: r.name,
267
281
  type: r.type,
268
282
  })),
269
- }
283
+ },
270
284
  );
271
285
  }
272
286
  Object.assign(parametersObj, requiredParameters);
@@ -275,25 +289,25 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
275
289
  const serviceName = item.serviceName.startsWith("./")
276
290
  ? item.serviceName.split("./")[1]
277
291
  : item.serviceName.startsWith(".")
278
- ? item.serviceName.split(".")[1]
279
- : item.serviceName;
292
+ ? item.serviceName.split(".")[1]
293
+ : item.serviceName;
280
294
 
281
295
  const scale =
282
296
  item.type === "component" || item.serviceName === ""
283
297
  ? { hsize: 1 }
284
298
  : item.schema?.name === "builtins/inbound"
285
- ? { detail: {} }
286
- : item.type === "service" && item.roles && Array.isArray(item.roles)
287
- ? {
288
- detail: item.roles.reduce(
289
- (acc, role) => ({
290
- ...acc,
291
- [role]: { hsize: 1 },
292
- }),
293
- {}
294
- ),
295
- }
296
- : { detail: { [`${item.artifactName}`]: { hsize: 1 } } };
299
+ ? { detail: {} }
300
+ : item.type === "service" && item.roles && Array.isArray(item.roles)
301
+ ? {
302
+ detail: item.roles.reduce(
303
+ (acc, role) => ({
304
+ ...acc,
305
+ [role]: { hsize: 1 },
306
+ }),
307
+ {},
308
+ ),
309
+ }
310
+ : { detail: { [`${item.artifactName}`]: { hsize: 1 } } };
297
311
 
298
312
  const scaling: {
299
313
  simple: {
@@ -371,7 +385,7 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
371
385
  const jsonResponse = await response.json();
372
386
 
373
387
  const isTimeout = jsonResponse?.events?.some(
374
- (event: any) => event.content === "_timeout_"
388
+ (event: any) => event.content === "_timeout_",
375
389
  );
376
390
 
377
391
  if (isTimeout) {
@@ -396,7 +410,7 @@ export const deployMarketplaceItem = async (item: MarketplaceService) => {
396
410
 
397
411
  export const getMarketplaceItems = async (
398
412
  tenants: string[],
399
- security: string
413
+ security: string,
400
414
  ) => {
401
415
  await initializeGlobalWebSocketClient(security);
402
416
  const promises = tenants.map(async (tenant) => {
@@ -406,7 +420,7 @@ export const getMarketplaceItems = async (
406
420
  { tenant },
407
421
  30000,
408
422
  "GET",
409
- tenant
423
+ tenant,
410
424
  );
411
425
 
412
426
  const tenantItems: MarketplaceItem[] = [];
@@ -450,19 +464,19 @@ export const getMarketplaceItems = async (
450
464
  const schemaData = await getMarketplaceSchema(
451
465
  tenant,
452
466
  item,
453
- security
467
+ security,
454
468
  );
455
469
  item.schema = schemaData;
456
470
  } catch (schemaError) {
457
471
  console.error(
458
472
  `Error cargando schema para ${item.name}:`,
459
- schemaError
473
+ schemaError,
460
474
  );
461
475
  item.schema = undefined;
462
476
  }
463
477
 
464
478
  return item;
465
- }
479
+ },
466
480
  );
467
481
 
468
482
  const processedItems = await Promise.all(itemPromises);
@@ -482,7 +496,7 @@ export const getMarketplaceItems = async (
482
496
  export const getMarketplaceSchema = async (
483
497
  tenant: string,
484
498
  marketplaceItem: MarketplaceItem,
485
- security: string
499
+ security: string,
486
500
  ): Promise<
487
501
  | {
488
502
  resources: {
@@ -530,7 +544,7 @@ export const getMarketplaceSchema = async (
530
544
  requestPayload,
531
545
  30000,
532
546
  "GET",
533
- tenant
547
+ tenant,
534
548
  );
535
549
 
536
550
  const nameKeys = Object.keys(response.data);
@@ -643,22 +657,46 @@ function processSchema(schema: any, schemaType: string) {
643
657
  param.default !== undefined
644
658
  ? param.default
645
659
  : param.enum
646
- ? param.enum[0]
647
- : param.const
648
- ? param.const
649
- : undefined,
660
+ ? param.enum[0]
661
+ : param.const
662
+ ? param.const
663
+ : undefined,
650
664
  });
651
665
  });
652
666
  }
653
667
 
668
+ const volumeTypes = [
669
+ "Registered",
670
+ "NonReplicated",
671
+ "Persisted",
672
+ "Volatile",
673
+ "Ephemeral",
674
+ "Persistent",
675
+ ];
676
+
677
+ const isVolumeResource = (resourceValue: any): boolean => {
678
+ if (resourceValue.oneOf && Array.isArray(resourceValue.oneOf)) {
679
+ return resourceValue.oneOf.some((option: any) => {
680
+ if (option.oneOf && Array.isArray(option.oneOf)) {
681
+ return option.oneOf.some((nestedOption: any) => {
682
+ const typeName =
683
+ nestedOption?.properties?.$kdsl?.const?.NamedType?.Name;
684
+ return typeName && volumeTypes.includes(typeName);
685
+ });
686
+ }
687
+ const typeName = option?.properties?.$kdsl?.const?.NamedType?.Name;
688
+ return typeName && volumeTypes.includes(typeName);
689
+ });
690
+ }
691
+ return false;
692
+ };
693
+
654
694
  const resourceProps = schema.properties?.resource;
655
695
  if (resourceProps?.properties) {
656
696
  Object.entries(resourceProps.properties).forEach(([key, value]) => {
657
- if (
658
- key.toLowerCase() === "data" ||
659
- key.toLowerCase() === "jetstreamdata" ||
660
- key.toLowerCase() === "shared"
661
- ) {
697
+ const resourceValue = value as any;
698
+
699
+ if (isVolumeResource(resourceValue)) {
662
700
  resources.push({
663
701
  name: key,
664
702
  type: "volume",
@@ -666,7 +704,6 @@ function processSchema(schema: any, schemaType: string) {
666
704
  defaultValue: undefined,
667
705
  });
668
706
  } else {
669
- const resourceValue = value as any;
670
707
  let resourceType = "";
671
708
  let defaultValue: string | undefined = undefined;
672
709
 
@@ -741,7 +778,7 @@ function processSchema(schema: any, schemaType: string) {
741
778
  type: "client",
742
779
  resource,
743
780
  });
744
- }
781
+ },
745
782
  );
746
783
  }
747
784
  if (srvProps.server?.properties) {
@@ -771,7 +808,7 @@ function processSchema(schema: any, schemaType: string) {
771
808
  type: "server",
772
809
  resource,
773
810
  });
774
- }
811
+ },
775
812
  );
776
813
  }
777
814
  if (srvProps.duplex?.properties) {
@@ -801,7 +838,7 @@ function processSchema(schema: any, schemaType: string) {
801
838
  type: "duplex",
802
839
  resource,
803
840
  });
804
- }
841
+ },
805
842
  );
806
843
  }
807
844
  }
@@ -819,17 +856,17 @@ const generateLinkBody = (data: Service, link: Link) => {
819
856
  const originInClient = data.clientChannels.find(
820
857
  (channel) =>
821
858
  channel.name === link.originChannel ||
822
- channel.from === link.originChannel
859
+ channel.from === link.originChannel,
823
860
  );
824
861
  const originInServer = data.serverChannels.find(
825
862
  (channel) =>
826
863
  channel.name === link.originChannel ||
827
- channel.from === link.originChannel
864
+ channel.from === link.originChannel,
828
865
  );
829
866
  const originInDuplex = data.duplexChannels.find(
830
867
  (channel) =>
831
868
  channel.name === link.originChannel ||
832
- channel.from === link.originChannel
869
+ channel.from === link.originChannel,
833
870
  );
834
871
 
835
872
  if (originInClient) {
@@ -855,17 +892,17 @@ const generateLinkBody = (data: Service, link: Link) => {
855
892
  const targetInClient = data.clientChannels.find(
856
893
  (channel) =>
857
894
  channel.name === link.targetChannel ||
858
- channel.from === link.targetChannel
895
+ channel.from === link.targetChannel,
859
896
  );
860
897
  const targetInServer = data.serverChannels.find(
861
898
  (channel) =>
862
899
  channel.name === link.targetChannel ||
863
- channel.from === link.targetChannel
900
+ channel.from === link.targetChannel,
864
901
  );
865
902
  const targetInDuplex = data.duplexChannels.find(
866
903
  (channel) =>
867
904
  channel.name === link.targetChannel ||
868
- channel.from === link.targetChannel
905
+ channel.from === link.targetChannel,
869
906
  );
870
907
 
871
908
  if (targetInClient) {
@@ -889,7 +926,7 @@ const generateLinkBody = (data: Service, link: Link) => {
889
926
  }
890
927
  } else {
891
928
  console.warn(
892
- `Servicio actual no involucrado en el enlace: current=${data.name}, origin=${link.origin}, target=${link.target}`
929
+ `Servicio actual no involucrado en el enlace: current=${data.name}, origin=${link.origin}, target=${link.target}`,
893
930
  );
894
931
  linkBody = {
895
932
  client_tenant: data.tenant,
@@ -918,7 +955,7 @@ const linkPendingServices = async (service: Service, token: string) => {
918
955
  linkBody,
919
956
  30000,
920
957
  "LINK",
921
- service.name
958
+ service.name,
922
959
  );
923
960
 
924
961
  const notification: Notification = {
@@ -952,7 +989,7 @@ const linkPendingServices = async (service: Service, token: string) => {
952
989
  };
953
990
  eventHelper.notification.publish.creation(notification);
954
991
  }
955
- })
992
+ }),
956
993
  );
957
994
  }
958
995
  };
@@ -963,7 +1000,7 @@ const linkPendingServices = async (service: Service, token: string) => {
963
1000
  */
964
1001
  export const loadMarketplaceItemsForTenant = async (
965
1002
  tenant: string,
966
- security: string
1003
+ security: string,
967
1004
  ) => {
968
1005
  try {
969
1006
  await initializeGlobalWebSocketClient(security);
@@ -973,7 +1010,7 @@ export const loadMarketplaceItemsForTenant = async (
973
1010
  { tenant },
974
1011
  30000,
975
1012
  "GET",
976
- tenant
1013
+ tenant,
977
1014
  );
978
1015
  const items = response.data?.items || [];
979
1016
  if (!Array.isArray(items) || items.length === 0) {
@@ -1006,13 +1043,13 @@ export const loadMarketplaceItemsForTenant = async (
1006
1043
  const schemaData = await getMarketplaceSchema(
1007
1044
  tenant,
1008
1045
  marketplaceItem,
1009
- security
1046
+ security,
1010
1047
  );
1011
1048
  marketplaceItem.schema = schemaData;
1012
1049
  } catch (schemaError) {
1013
1050
  console.error(
1014
1051
  `Error loading schema for ${marketplaceItem.name}:`,
1015
- schemaError
1052
+ schemaError,
1016
1053
  );
1017
1054
  marketplaceItem.schema = undefined;
1018
1055
  }
@@ -1024,7 +1061,7 @@ export const loadMarketplaceItemsForTenant = async (
1024
1061
  } catch (error) {
1025
1062
  console.error(
1026
1063
  `Error loading marketplace items for tenant ${tenant}:`,
1027
- error
1064
+ error,
1028
1065
  );
1029
1066
  return [];
1030
1067
  }
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "ws": "^8.18.2"
24
24
  },
25
25
  "name": "@kumori/aurora-backend-handler",
26
- "version": "1.0.7",
26
+ "version": "1.0.8",
27
27
  "description": "backend handler",
28
28
  "main": "backend-handler.ts",
29
29
  "repository": {