@izara_project/izara-core-library-service-schemas 1.0.86 → 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.86",
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,11 +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
741
  const urls = [];
742
- const apiLink = {};
743
742
  let nextToken;
744
743
 
745
744
  do {
@@ -760,32 +759,35 @@ async function getApiLinksV2(objSchema) {
760
759
  } while (routeRestToken)
761
760
 
762
761
  for (const route of routeResResult) {
763
-
762
+ // console.log("route::", route)
764
763
  const routeKeyParts = route.RouteKey.split(" ");
765
764
  if (routeKeyParts.length !== 2) continue; // Invalid format
766
765
 
767
766
  const [method, path] = routeKeyParts;
768
- if (method === "POST" && path.endsWith("get")) {
769
- if (path.includes(consts.firstLetterLowerCase(objSchema.objectType))) {
770
- const fullUrl = `https://${apiId}.execute-api.${process.env.iz_region}.amazonaws.com${path}`;
771
- 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
+ }
772
779
  }
773
- // urls.push({
774
- // url: fullUrl,
775
- // });
776
780
  }
781
+
777
782
  }
778
783
  } catch (err) {
779
784
  console.error(`Error processing API "${apiName}":`, err);
780
785
  }
781
786
  }
782
-
783
787
  nextToken = apisRes.NextToken;
784
788
 
785
789
  } while (nextToken);
786
- // console.log(apiLink)
787
- return apiLink;
788
- // return api;
790
+ return urls;
789
791
  } catch (err) {
790
792
  console.error("Error fetching API info:", err);
791
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
  }