@izara_project/izara-core-library-service-schemas 1.0.84 → 1.0.86

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.84",
3
+ "version": "1.0.86",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,16 +20,17 @@
20
20
  "testEnvironment": "node"
21
21
  },
22
22
  "dependencies": {
23
- "@aws-sdk/client-api-gateway": "^3.848.0",
24
- "@aws-sdk/client-lambda": "^3.851.0",
25
- "@aws-sdk/client-s3": "^3.850.0",
26
- "@aws-sdk/crc64-nvme-crt": "^3.848.0",
27
- "@izara_project/izara-core-library-core": "^1.0.19",
23
+ "@aws-sdk/client-api-gateway": "^3.862.0",
24
+ "@aws-sdk/client-apigatewayv2": "^3.862.0",
25
+ "@aws-sdk/client-lambda": "^3.862.0",
26
+ "@aws-sdk/client-s3": "^3.862.0",
27
+ "@aws-sdk/crc64-nvme-crt": "^3.862.0",
28
+ "@izara_project/izara-core-library-core": "^1.0.20",
28
29
  "@izara_project/izara-core-library-external-request": "^1.0.20",
29
30
  "@izara_project/izara-core-library-lambda": "^1.0.4",
30
31
  "@izara_project/izara-core-library-logger": "^1.0.7",
31
32
  "@izara_project/izara-shared-core": "^1.0.2",
32
- "@izara_project/izara-shared-service-schemas": "^1.0.27",
33
+ "@izara_project/izara-shared-service-schemas": "^1.0.28",
33
34
  "glob": "^11.0.3",
34
35
  "lodash": "^4.17.21",
35
36
  "object-hash": "^3.0.0",
package/src/Consts.js CHANGED
@@ -342,6 +342,14 @@ const UPLOAD_PATH_S3 = {
342
342
  getEndpointPerService: getEndpointPerService
343
343
  }
344
344
 
345
+ function firstLetterUpperCase(str) {
346
+ return str.charAt(0).toUpperCase() + str.slice(1)
347
+ }
348
+
349
+ function firstLetterLowerCase(str) {
350
+ return str.charAt(0).toLowerCase() + str.slice(1)
351
+ }
352
+
345
353
  // --------- End Upload path ---------------
346
354
 
347
355
  module.exports = {
@@ -370,4 +378,7 @@ module.exports = {
370
378
 
371
379
  LOCAL_FILENAME: LOCAL_FILENAME,
372
380
  createValidationFieldNameForEachType,
381
+
382
+ firstLetterUpperCase,
383
+ firstLetterLowerCase
373
384
  }
@@ -49,7 +49,7 @@ const {
49
49
  validateRelationshipSchema,
50
50
  validateRefRelationshipSchema,
51
51
  validateBasicFlowSchema,
52
- getApiLinks
52
+ getApiLinksV2
53
53
  } = require('./Utils')
54
54
 
55
55
  const {
@@ -328,7 +328,7 @@ async function uploadObjectSchemaByUseCase(_izContext, bucketName) {
328
328
  )
329
329
  );
330
330
 
331
- let apiLink = await getApiLinks();
331
+ let apiLink = await getApiLinksV2(objSchema);
332
332
  // console.log("apiLink", apiLink)
333
333
  uploadList.push(
334
334
  uploadObjectToS3(
@@ -338,13 +338,13 @@ async function uploadObjectSchemaByUseCase(_izContext, bucketName) {
338
338
  )
339
339
  )
340
340
 
341
- uploadList.push(
342
- uploadObjectToS3(
343
- _izContext,
344
- UPLOAD_PATH_S3.getEndpointPerService(process.env.iz_serviceTag),
345
- apiLink
346
- )
347
- )
341
+ // uploadList.push(
342
+ // uploadObjectToS3(
343
+ // _izContext,
344
+ // UPLOAD_PATH_S3.getEndpointPerService(process.env.iz_serviceTag),
345
+ // apiLink
346
+ // )
347
+ // )
348
348
 
349
349
  // upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
350
350
  let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
package/src/Utils.js CHANGED
@@ -52,6 +52,13 @@ const {
52
52
  GetMethodCommand,
53
53
  } = require("@aws-sdk/client-api-gateway");
54
54
 
55
+ const {
56
+ ApiGatewayV2Client,
57
+ GetApisCommand,
58
+ GetRoutesCommand,
59
+ GetStagesCommand,
60
+ } = require("@aws-sdk/client-apigatewayv2");
61
+
55
62
  function createObjType(objectType, serviceTag) {
56
63
  if (!process.env.iz_serviceTag && !serviceTag) {
57
64
  throw new NoRetryError('serviceNameTag not defined and iz_serviceNameTag not defined in environment variables');
@@ -683,7 +690,7 @@ function switchDirection(direction) {
683
690
  }
684
691
  }
685
692
 
686
- async function getApiLinks() {
693
+ async function getApiLinksV1() {
687
694
  try {
688
695
  let apiGateway = {}
689
696
  let position;
@@ -707,7 +714,7 @@ async function getApiLinks() {
707
714
  const resourcesRes = await client.send(
708
715
  new GetResourcesCommand({ restApiId: foundApi.id })
709
716
  );
710
-
717
+ console.log({ resourcesRes })
711
718
  for (const resource of resourcesRes.items) {
712
719
  if (resource.resourceMethods) {
713
720
  const methods = Object.keys(resource.resourceMethods);
@@ -728,6 +735,61 @@ async function getApiLinks() {
728
735
  }
729
736
  }
730
737
 
738
+ async function getApiLinksV2(objSchema) {
739
+ try {
740
+ const client = new ApiGatewayV2Client({ region: process.env.iz_region });
741
+ const urls = [];
742
+ const apiLink = {};
743
+ let nextToken;
744
+
745
+ do {
746
+ const apisRes = await client.send(new GetApisCommand({ NextToken: nextToken }));
747
+
748
+ for (const api of apisRes.Items) {
749
+ const { Name: apiName, ApiId: apiId } = api;
750
+ let routeResResult = []
751
+ let routeRestToken;
752
+
753
+ try {
754
+
755
+ do {
756
+ const routesRes = await client.send(new GetRoutesCommand({ ApiId: apiId, NextToken: routeRestToken }));
757
+ routeResResult.push(...routesRes.Items)
758
+ routeRestToken = routesRes.NextToken;
759
+
760
+ } while (routeRestToken)
761
+
762
+ for (const route of routeResResult) {
763
+
764
+ const routeKeyParts = route.RouteKey.split(" ");
765
+ if (routeKeyParts.length !== 2) continue; // Invalid format
766
+
767
+ 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 })
772
+ }
773
+ // urls.push({
774
+ // url: fullUrl,
775
+ // });
776
+ }
777
+ }
778
+ } catch (err) {
779
+ console.error(`Error processing API "${apiName}":`, err);
780
+ }
781
+ }
782
+
783
+ nextToken = apisRes.NextToken;
784
+
785
+ } while (nextToken);
786
+ // console.log(apiLink)
787
+ return apiLink;
788
+ // return api;
789
+ } catch (err) {
790
+ console.error("Error fetching API info:", err);
791
+ }
792
+ }
731
793
  module.exports = {
732
794
  createObjType,
733
795
  getIdentifierTypeByPriority,
@@ -753,5 +815,6 @@ module.exports = {
753
815
  explodedFlowTypeConcat,
754
816
 
755
817
  createLinkTypeId,
756
- getApiLinks
818
+ getApiLinksV1,
819
+ getApiLinksV2
757
820
  }