@izara_project/izara-core-library-service-schemas 1.0.87 → 1.0.88

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-service-schemas",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Consts.js CHANGED
@@ -310,7 +310,7 @@ function getEndpointPerObjectType(_izContext, objType) {
310
310
  return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/FrontEnd/Endpoint/Endpoint_Get_${objType.objectType}.json`
311
311
  }
312
312
 
313
- function getEndpointPerService(serviceTag) {
313
+ function getEndpointPerService(_izContext, serviceTag) {
314
314
  if (typeof serviceTag !== "string" || !serviceTag) {
315
315
  throw new NoRetryError("invalid serviceTag.")
316
316
  }
@@ -378,7 +378,7 @@ module.exports = {
378
378
 
379
379
  LOCAL_FILENAME: LOCAL_FILENAME,
380
380
  createValidationFieldNameForEachType,
381
-
381
+
382
382
  firstLetterUpperCase,
383
383
  firstLetterLowerCase
384
384
  }
@@ -328,24 +328,6 @@ async function uploadObjectSchemaByUseCase(_izContext, bucketName) {
328
328
  )
329
329
  );
330
330
 
331
- let apiLink = await getApiLinksV2(objSchema);
332
- // console.log("apiLink", apiLink)
333
- uploadList.push(
334
- uploadObjectToS3(
335
- _izContext,
336
- UPLOAD_PATH_S3.getEndpointPerObjectType(_izContext, { objectType: objSchema.objectType, serviceTag: process.env.iz_serviceTag }),
337
- apiLink
338
- )
339
- )
340
-
341
- // uploadList.push(
342
- // uploadObjectToS3(
343
- // _izContext,
344
- // UPLOAD_PATH_S3.getEndpointPerService(process.env.iz_serviceTag),
345
- // apiLink
346
- // )
347
- // )
348
-
349
331
  // upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
350
332
  let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
351
333
  if (existsRefObjectRel) {
@@ -396,6 +378,15 @@ async function uploadObjectSchemaByUseCase(_izContext, bucketName) {
396
378
  )
397
379
  );
398
380
 
381
+ let apiLinks = await getApiLinksV2(foundedObjectTypes);
382
+ uploadList.push(
383
+ uploadObjectToS3(
384
+ _izContext,
385
+ UPLOAD_PATH_S3.getEndpointPerService(_izContext, process.env.iz_serviceTag),
386
+ apiLinks
387
+ )
388
+ )
389
+
399
390
  let belongsTo = [];
400
391
  let createdBys = [];
401
392
  let translations = [];
package/src/Utils.js CHANGED
@@ -714,7 +714,7 @@ async function getApiLinksV1() {
714
714
  const resourcesRes = await client.send(
715
715
  new GetResourcesCommand({ restApiId: foundApi.id })
716
716
  );
717
- console.log({ resourcesRes })
717
+ // console.log({ resourcesRes })
718
718
  for (const resource of resourcesRes.items) {
719
719
  if (resource.resourceMethods) {
720
720
  const methods = Object.keys(resource.resourceMethods);
@@ -735,10 +735,10 @@ async function getApiLinksV1() {
735
735
  }
736
736
  }
737
737
 
738
- async function getApiLinksV2(objSchema) {
738
+ async function getApiLinksV2(objectTypes) {
739
739
  try {
740
740
  const client = new ApiGatewayV2Client({ region: process.env.iz_region });
741
- const apiLink = {};
741
+ const urls = [];
742
742
  let nextToken;
743
743
 
744
744
  do {
@@ -759,32 +759,35 @@ async function getApiLinksV2(objSchema) {
759
759
  } while (routeRestToken)
760
760
 
761
761
  for (const route of routeResResult) {
762
-
762
+ // console.log("route::", route)
763
763
  const routeKeyParts = route.RouteKey.split(" ");
764
764
  if (routeKeyParts.length !== 2) continue; // Invalid format
765
765
 
766
766
  const [method, path] = routeKeyParts;
767
- if (method === "POST" && path.endsWith("get")) {
768
- if (path.includes(consts.firstLetterLowerCase(objSchema.objectType))) {
769
- const fullUrl = `https://${apiId}.execute-api.${process.env.iz_region}.amazonaws.com/${process.env.iz_serviceTag}${path}`;
770
- Object.assign(apiLink, { Url: fullUrl })
767
+ const [_, object, action] = path.split("/")
768
+ for (const objectType of objectTypes) {
769
+ if (method === "POST" && path.endsWith("get")) {
770
+ if (object === consts.firstLetterLowerCase(objectType)) {
771
+ // console.log({ path, objectType: consts.firstLetterLowerCase(objectType) })
772
+ const fullUrl = `https://${apiId}.execute-api.${process.env.iz_region}.amazonaws.com/${process.env.iz_serviceTag}${path}`;
773
+ urls.push({
774
+ Url: fullUrl,
775
+ });
776
+ // Object.assign(apiLink, { Url: fullUrl })
777
+ // }
778
+ }
771
779
  }
772
- // urls.push({
773
- // url: fullUrl,
774
- // });
775
780
  }
781
+
776
782
  }
777
783
  } catch (err) {
778
784
  console.error(`Error processing API "${apiName}":`, err);
779
785
  }
780
786
  }
781
-
782
787
  nextToken = apisRes.NextToken;
783
788
 
784
789
  } while (nextToken);
785
- // console.log(apiLink)
786
- return apiLink;
787
- // return api;
790
+ return urls;
788
791
  } catch (err) {
789
792
  console.error("Error fetching API info:", err);
790
793
  }
@@ -1225,12 +1225,22 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1225
1225
  if (!flowSchema.hasOwnProperty("objType")) {
1226
1226
  validateStatus.status = false;
1227
1227
  validateStatus.validateErrors.push(`flowSchema ${flowSchema.flowTag} must have objType`)
1228
+ } else {
1229
+ let objSchema = await getObjSchemaS3WithHierarchy(_izContext, {
1230
+ objectType: flowSchema.objType.objectType,
1231
+ serviceTag: flowSchema.objType.serviceTag
1232
+ })
1233
+
1234
+ if (!objSchema) {
1235
+ validateStatus.status = false;
1236
+ validateStatus.validateErrors.push(`${flowSchema}.objType is invalid`)
1237
+ }
1228
1238
  }
1229
- }
1230
1239
 
1231
- if (!status) {
1232
- validateStatus.status = false;
1233
- validateStatus.validateErrors.push(errors);
1240
+ if (!status) {
1241
+ validateStatus.status = false;
1242
+ validateStatus.validateErrors.push(errors);
1243
+ }
1234
1244
  }
1235
1245
  }
1236
1246
  }