@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69

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.
Files changed (128) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +104 -0
  4. package/src/compile/compileProject.js +40 -9
  5. package/src/compile/loadSchemas.js +120 -11
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
  8. package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
  9. package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  16. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  17. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  18. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  19. package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
  20. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  21. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
  22. package/src/emit/custom/customFlows.js +68 -28
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
  24. package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
  25. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  26. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  27. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  28. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  29. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  30. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  32. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  33. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
  34. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  35. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
  36. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  38. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  39. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  40. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  41. package/src/emit/function/functionYamlArtifact.js +272 -79
  42. package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
  43. package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
  44. package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
  45. package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
  46. package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
  47. package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
  48. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
  49. package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
  50. package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
  51. package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
  52. package/src/emit/rbac/rbacFlowTag.js +3 -1
  53. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  54. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  55. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  56. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  57. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  58. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  59. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  60. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  61. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  62. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
  63. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
  64. package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
  65. package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
  66. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  67. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  68. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  69. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  70. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  71. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  72. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  73. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  74. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  75. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  76. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  77. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  78. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  79. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  80. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  81. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  82. package/src/emit/resource/emitResourceArtifacts.js +274 -105
  83. package/src/emit/resource/generateResourceArtifacts.js +15 -6
  84. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
  85. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  86. package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
  87. package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
  88. package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
  89. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
  90. package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
  91. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
  92. package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
  93. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
  94. package/src/generate.js +141 -34
  95. package/src/generateIntTest.js +76 -28
  96. package/src/generateResourceIntTest.js +35 -12
  97. package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
  98. package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
  99. package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
  100. package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
  101. package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
  102. package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
  103. package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
  104. package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
  105. package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
  106. package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
  107. package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
  108. package/src/intTestGeneratorShared.js +15 -10
  109. package/src/output/commitArtifacts.js +99 -39
  110. package/src/output/mergeHooks.js +24 -10
  111. package/src/output/validateArtifacts.js +37 -27
  112. package/src/plan/buildGenerationPlan.js +24 -13
  113. package/test/core.test.js +116 -49
  114. package/test/createTargetRoleHandler.test.js +63 -14
  115. package/test/crudApplicationArtifacts.test.js +128 -23
  116. package/test/customFlowApplicationArtifacts.test.js +391 -84
  117. package/test/dynamicCrudFlowSchemas.test.js +74 -26
  118. package/test/dynamicRbacFlowSchemas.test.js +63 -20
  119. package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
  120. package/test/functionYamlArtifact.test.js +67 -10
  121. package/test/intTestApi.test.js +9 -10
  122. package/test/publicApi.test.js +184 -44
  123. package/test/relationshipApplicationArtifacts.test.js +90 -19
  124. package/test/resourceArtifacts.test.js +183 -33
  125. package/docs/test.png +0 -0
  126. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  127. package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
  128. /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
@@ -15,15 +15,17 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
- import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
18
+ import {
19
+ middlewareHandler as middleware,
20
+ response
21
+ } from '@izara_project/izara-middleware';
20
22
  import Logger from '@izara_project/izara-core-library-logger';
21
- import recordHandlerSharedLib from '@izara_project/izara-core-library-record-handler';
23
+ import { recordHandlerS3SharedLib } from '@izara_project/izara-core-library-record-handler';
22
24
 
23
25
  import <%- functionName %> from './<%- mainFileName %>.js';
24
26
 
25
27
  // S3 event validator (record.body shape differs from SNS/SQS — uses event.Records[0].s3)
26
- middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchemaS3());
28
+ middleware.setValidatorSchema(recordHandlerS3SharedLib.baseValidatorSchemaS3());
27
29
 
28
30
  /**
29
31
  * GENERATED HANDLER: S3 Entry Point (Flow: <%- flowTag %>)
@@ -32,11 +34,11 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchemaS3());
32
34
  */
33
35
  export const main = middleware.wrap(async (event, context) => {
34
36
  try {
35
- Logger.debug("event is:", event);
36
- Logger.debug("event.Records[0] is:", event.Records && event.Records[0]);
37
+ Logger.debug('event is:', event);
38
+ Logger.debug('event.Records[0] is:', event.Records && event.Records[0]);
37
39
 
38
40
  if (!event.Records || !event.Records[0] || !event.Records[0].s3) {
39
- throw new Error("Invalid S3 event: missing Records[0].s3");
41
+ throw new Error('Invalid S3 event: missing Records[0].s3');
40
42
  }
41
43
 
42
44
  const s3Record = event.Records[0].s3;
@@ -44,7 +46,7 @@ export const main = middleware.wrap(async (event, context) => {
44
46
  const result = await <%- functionName %>(
45
47
  event._izContext,
46
48
  s3Record.bucket,
47
- s3Record.object,
49
+ s3Record.object
48
50
  //(<additionalParams>)
49
51
  //(</additionalParams>)
50
52
  );
@@ -54,7 +56,10 @@ export const main = middleware.wrap(async (event, context) => {
54
56
  }
55
57
  return response.success(result);
56
58
  } catch (err) {
57
- event._izContext?.logger?.error('Error in S3 handler for flow <%- flowTag %>:', err);
59
+ event._izContext?.logger?.error(
60
+ 'Error in S3 handler for flow <%- flowTag %>:',
61
+ err
62
+ );
58
63
  return response.failure(err);
59
64
  }
60
65
  });
@@ -15,7 +15,13 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import { S3Client, GetObjectCommand, DeleteObjectCommand, PutObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
18
+ import {
19
+ S3Client,
20
+ GetObjectCommand,
21
+ DeleteObjectCommand,
22
+ PutObjectCommand,
23
+ CopyObjectCommand
24
+ } from '@aws-sdk/client-s3';
19
25
  const s3 = new S3Client({ region: process.env.AWS_REGION });
20
26
 
21
27
  //(<optionalRequired>)
@@ -37,7 +43,7 @@ const s3 = new S3Client({ region: process.env.AWS_REGION });
37
43
  * @returns {object} returnResponse
38
44
  */
39
45
 
40
- export default async function processAfterUpload (
46
+ export default async function processAfterUpload(
41
47
  _izContext,
42
48
  bucket,
43
49
  field,
@@ -45,22 +51,19 @@ export default async function processAfterUpload (
45
51
  //(</additionalProperties>)
46
52
  passBackProperties = {}
47
53
  ) {
48
-
49
54
  try {
50
-
51
55
  _izContext.logger.debug('----- process AfterUpload event params ----- ', {
52
56
  bucket: bucket,
53
57
  field: field,
54
58
  //(<loggerAdditionalParams>)
55
59
  //(</loggerAdditionalParams>)
56
60
  passBackProperties: passBackProperties
57
- })
61
+ });
58
62
 
59
63
  //(<endpointHook>)
60
64
  //(</endpointHook>)
61
-
62
65
  } catch (err) {
63
- _izContext.logger.error('error ProcessImageAfterUploadMain: ', err)
64
- throw (err)
66
+ _izContext.logger.error('error ProcessImageAfterUploadMain: ', err);
67
+ throw err;
65
68
  }
66
69
  }
@@ -15,9 +15,7 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
-
20
- import { middlewareHandler as middleware } from "@izara_project/izara-middleware"
18
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
21
19
 
22
20
  import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
23
21
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
@@ -25,97 +23,108 @@ import Logger from '@izara_project/izara-core-library-logger';
25
23
 
26
24
  import <%= functionName %> from './<%= functionName %>_Main.js';
27
25
 
28
- middleware.setServiceSchema(recordHandlerSharedLib.baseValidatorSchema());
26
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
29
27
 
30
28
  let perRecordsValidatorSchema = {
31
- type: "object",
32
- required: ["objType", "objInstanceFull"],
29
+ type: 'object',
30
+ required: ['objType', 'objInstanceFull'],
33
31
  properties: {
34
32
  objType: {
35
- type: "object",
36
- required: ["objectType", "serviceTag"],
33
+ type: 'object',
34
+ required: ['objectType', 'serviceTag'],
37
35
  properties: {
38
36
  objectType: {
39
- type: "string",
40
- pattern: "^[a-zA-Z0-9_-]+$"
37
+ type: 'string',
38
+ pattern: '^[a-zA-Z0-9_-]+$'
41
39
  },
42
40
  serviceTag: {
43
- type: "string",
44
- pattern: "^[a-zA-Z0-9_-]+$"
41
+ type: 'string',
42
+ pattern: '^[a-zA-Z0-9_-]+$'
45
43
  }
46
- },
44
+ }
47
45
  },
48
46
  objInstanceFull: {
49
- type: "object",
47
+ type: 'object',
50
48
  properties: {
51
49
  identifiers: {
52
- type: "object",
50
+ type: 'object',
53
51
  minProperties: 1
54
52
  },
55
53
  fields: {
56
- type: "object"
54
+ type: 'object'
57
55
  }
58
56
  }
59
57
  }
60
58
  }
61
59
  };
62
60
 
63
- perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema);
61
+ perRecordsValidatorSchema =
62
+ callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
63
+ perRecordsValidatorSchema
64
+ );
64
65
 
65
66
  export const main = middleware.wrap(async (event, context) => {
66
-
67
67
  try {
68
-
69
68
  let recordPromises = [];
70
69
 
71
70
  // loop each record and send to mainFunction
72
- await Promise.all(event.Records.map(async record => { // promise.all for map() function
73
-
74
- let passOnProperties = []
75
- record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
76
-
77
- //validate message (and MessageAttributes)
78
- await recordHandlerSharedLib.validateRecord(
79
- record, // one record will send to mainFunction
80
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
81
- perRecordsValidatorSchema, // schema for record.Message
82
- // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
83
- );
84
-
85
- // add argument (to invoke lambda) to passOnProperties[]
86
- passOnProperties.push(record.body.Message.objType)
87
- passOnProperties.push(record.body.Message.objInstanceFull)
88
- //(<additionalProperties>)
89
- //(</additionalProperties>)
90
- passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
91
- // passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callinfFlow
92
- record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
93
-
94
- // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
95
- let recordPromise = recordHandlerSharedLib.recordHandler(
96
- record, // one record will send to mainFunction
97
- <%= functionName %>, // mainFunction that need to invoke.
98
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
99
- passOnProperties, // all parameters that mainFunction needed.
100
- );
101
- record._izContext.logger.debug('after recordPromise in handler');
102
- recordPromises.push(recordPromise); // push promise to recordPromises
103
- }))
71
+ await Promise.all(
72
+ event.Records.map(async (record) => {
73
+ // promise.all for map() function
74
+
75
+ let passOnProperties = [];
76
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
77
+
78
+ //validate message (and MessageAttributes)
79
+ await recordHandlerSharedLib.validateRecord(
80
+ record, // one record will send to mainFunction
81
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
82
+ perRecordsValidatorSchema // schema for record.Message
83
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
84
+ );
85
+
86
+ // add argument (to invoke lambda) to passOnProperties[]
87
+ passOnProperties.push(record.body.Message.objType);
88
+ passOnProperties.push(record.body.Message.objInstanceFull);
89
+ //(<additionalProperties>)
90
+ //(</additionalProperties>)
91
+ passOnProperties.push(
92
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
93
+ record.body.Message
94
+ )
95
+ ); // is Ok PassBackProperties
96
+ // passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callinfFlow
97
+ record._izContext.logger.debug(
98
+ 'passOnProperties in handler',
99
+ passOnProperties
100
+ );
101
+
102
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
103
+ let recordPromise = recordHandlerSharedLib.recordHandler(
104
+ record, // one record will send to mainFunction
105
+ <%= functionName %>, // mainFunction that need to invoke.
106
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
107
+ passOnProperties // all parameters that mainFunction needed.
108
+ );
109
+ record._izContext.logger.debug('after recordPromise in handler');
110
+ recordPromises.push(recordPromise); // push promise to recordPromises
111
+ })
112
+ );
104
113
 
105
114
  Logger.debug('before Promise.all(recordPromises) in handler');
106
115
  try {
107
116
  // --- main await all promises
108
117
  await Promise.all(recordPromises); // await all promises
109
118
 
110
- return event.Records // return all for local testing
111
-
119
+ return event.Records; // return all for local testing
112
120
  } catch {
113
- Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
121
+ Logger.debug(
122
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
123
+ );
114
124
  }
115
125
  Logger.debug('after Promise.all(recordPromises) in handler');
116
-
117
126
  } catch (err) {
118
127
  Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
119
- throw (err);
128
+ throw err;
120
129
  }
121
130
  });
@@ -15,19 +15,23 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
-
20
18
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
21
19
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
22
20
  import snsSharedLib from '@izara_project/izara-core-library-sns';
23
- import asyncFlowSharedLib from "@izara_project/izara-core-library-asynchronous-flow";
24
- import { sns, webSocket } from '@izara_project/izara-core-library-external-request';
21
+ import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
22
+ import {
23
+ sns,
24
+ webSocket
25
+ } from '@izara_project/izara-core-library-external-request';
25
26
  import { consts as coreConsts } from '@izara_project/izara-middleware';
26
27
  import { objectHash as hash } from '@izara_project/izara-shared-core';
27
28
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
28
29
  import { processStaticLimit } from '../../../libs/source/GenerateCodeLibs.js';
29
- import { consts as schemaConsts, utils } from "@izara_project/izara-core-library-service-schemas";
30
- const { createFlowTypeConcat } = utils
30
+ import {
31
+ consts as schemaConsts,
32
+ utils
33
+ } from '@izara_project/izara-core-library-service-schemas';
34
+ const { createFlowTypeConcat } = utils;
31
35
  const { postToConnection } = webSocket;
32
36
 
33
37
  //(<optionalRequired>)
@@ -54,51 +58,54 @@ export default async function reservedLimit(
54
58
  //(</additionalProperties>)
55
59
  callingFlowConfig = {}
56
60
  ) {
57
-
58
61
  try {
59
-
60
62
  _izContext.logger.debug('----- reservedLimit event params ----- ', {
61
63
  objType,
62
64
  objInstanceFull,
63
65
  callingFlowConfig
64
66
  });
65
67
 
66
- let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID)
68
+ let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
67
69
 
68
70
  //(<beforeReserved>)
69
71
  //(</beforeReserved>)
70
72
 
71
-
72
73
  // get static
73
74
  let payloadBeforeInvokeStaticLimit = {
74
75
  //(<additionalPropertiesStaticLimit>)
75
76
  //(</additionalPropertiesStaticLimit>)
76
- }
77
+ };
77
78
 
78
- let res = await processStaticLimit(_izContext,
79
- await lambdaSharedLib.lambdaFunctionName(_izContext, "StaticLimitProcessHdrInv", schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits),
79
+ let res = await processStaticLimit(
80
+ _izContext,
81
+ await lambdaSharedLib.lambdaFunctionName(
82
+ _izContext,
83
+ 'StaticLimitProcessHdrInv',
84
+ schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits
85
+ ),
80
86
  payloadBeforeInvokeStaticLimit
81
- )
87
+ );
82
88
 
83
- _izContext.logger.debug("res::", res);
89
+ _izContext.logger.debug('res::', res);
84
90
 
85
91
  if (res.passStatus === false) {
86
- postToConnection({ message: "static limit over" }, connectionId)
92
+ postToConnection({ message: 'static limit over' }, connectionId);
87
93
  let identifiers = hash({
88
94
  //(<hashIdentifiers>)
89
95
  //(</hashIdentifiers>)
90
- })
96
+ });
91
97
 
92
98
  // after post message delete websocket task
93
- await dynamodbSharedLib.deleteItem(_izContext,
94
- await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
99
+ await dynamodbSharedLib.deleteItem(
100
+ _izContext,
101
+ await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
95
102
  {
96
- taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
103
+ taskKey: `${createFlowTypeConcat(_izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
97
104
  connectionId: connectionId
98
105
  }
99
- )
106
+ );
100
107
  //(<afterFailReservedStaticLimit>)
101
- return
108
+ return;
102
109
  //(</afterFailReservedStaticLimit>)
103
110
  }
104
111
 
@@ -107,42 +114,51 @@ export default async function reservedLimit(
107
114
  let sendMsgReservedDynamic = {
108
115
  //(<additionalPropertiesReservedDynamic>)
109
116
  //(</additionalPropertiesReservedDynamic>)
110
- }
117
+ };
111
118
 
112
119
  let callingFlowProperties = {
113
120
  //(<baseCallingFlowProperties>)
114
121
  //(</baseCallingFlowProperties>)
115
- }
122
+ };
116
123
 
117
- _izContext.logger.debug("callingFlowProperties", callingFlowProperties);
124
+ _izContext.logger.debug('callingFlowProperties', callingFlowProperties);
118
125
 
119
126
  if (callingFlowConfig) {
120
- sendMsgReservedDynamic = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
121
- sendMsgReservedDynamic,
122
- callingFlowSharedLib.addParentCallingFlowConfig(
123
- callingFlowConfig,
127
+ sendMsgReservedDynamic =
128
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
129
+ sendMsgReservedDynamic,
130
+ callingFlowSharedLib.addParentCallingFlowConfig(
131
+ callingFlowConfig,
132
+ callingFlowSharedLib.createCallingFlowConfig(
133
+ //(<callingFlowPropertiesIfHaveCallingFlowConfig>)
134
+ await lambdaSharedLib.lambdaFunctionName(
135
+ _izContext,
136
+ 'ReservedLimitCompleteHdrSqs'
137
+ ),
138
+ //(</callingFlowPropertiesIfHaveCallingFlowConfig>)
139
+ callingFlowProperties
140
+ )
141
+ )
142
+ );
143
+ } else {
144
+ sendMsgReservedDynamic =
145
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
146
+ sendMsgReservedDynamic,
124
147
  callingFlowSharedLib.createCallingFlowConfig(
125
- //(<callingFlowPropertiesIfHaveCallingFlowConfig>)
126
- await lambdaSharedLib.lambdaFunctionName(_izContext, "ReservedLimitCompleteHdrSqs"),
127
- //(</callingFlowPropertiesIfHaveCallingFlowConfig>)
148
+ //(<callingFlowPropertiesIfNotHaveCallingFlowConfig>)
149
+ await lambdaSharedLib.lambdaFunctionName(
150
+ _izContext,
151
+ 'ReservedLimitCompleteHdrSqs'
152
+ ),
153
+ //(</callingFlowPropertiesIfNotHaveCallingFlowConfig>)
128
154
  callingFlowProperties
129
155
  )
130
- )
131
- )
132
- } else {
133
- sendMsgReservedDynamic = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
134
- sendMsgReservedDynamic,
135
- callingFlowSharedLib.createCallingFlowConfig(
136
- //(<callingFlowPropertiesIfNotHaveCallingFlowConfig>)
137
- await lambdaSharedLib.lambdaFunctionName(_izContext, "ReservedLimitCompleteHdrSqs"),
138
- //(</callingFlowPropertiesIfNotHaveCallingFlowConfig>)
139
- callingFlowProperties
140
- )
141
- );
156
+ );
142
157
  }
143
158
 
144
159
  // create awaitingSteps
145
- await asyncFlowSharedLib.createAwaitingStep(_izContext,
160
+ await asyncFlowSharedLib.createAwaitingStep(
161
+ _izContext,
146
162
  asyncFlowSharedLib.createAwaitingStepId(
147
163
  //(<createAwaitStepId>)
148
164
  //(</createAwaitStepId>)
@@ -151,22 +167,28 @@ export default async function reservedLimit(
151
167
  //(<createPendingStepId>)
152
168
  //(</createPendingStepId>)
153
169
  )
154
- )
155
-
170
+ );
156
171
 
157
172
  let sendMessageToReservedDynamic = {
158
173
  Message: JSON.stringify(sendMsgReservedDynamic),
159
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "ReservedDynamicUsage_In", schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits)
174
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
175
+ _izContext,
176
+ 'ReservedDynamicUsage_In',
177
+ schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits
178
+ )
160
179
  };
161
- _izContext.logger.debug("sendMessageToReservedDynamic", sendMessageToReservedDynamic);
180
+ _izContext.logger.debug(
181
+ 'sendMessageToReservedDynamic',
182
+ sendMessageToReservedDynamic
183
+ );
162
184
  await sns.publishAsync(_izContext, sendMessageToReservedDynamic);
163
185
 
164
186
  return {
165
187
  objType,
166
- objInstanceFull,
167
- }
188
+ objInstanceFull
189
+ };
168
190
  } catch (err) {
169
191
  _izContext.logger.error('error GetSignedUrlAccountLimit: ', err);
170
- throw (err)
192
+ throw err;
171
193
  }
172
194
  }
@@ -5,24 +5,68 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
5
5
 
6
6
  import <%- functionName %> from './<%- functionName %>_Main.js';
7
7
 
8
+ let perRecordsValidatorSchema = {
9
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
10
+ type: 'object',
11
+ properties: {
12
+ <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: {
13
+ type: '<%- prop.type || 'string' %>'
14
+ } /*__EJS_COMMA_6__*/
15
+ <% }) %>
16
+ },
17
+ required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
18
+ <% } -%>
19
+ };
20
+
21
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.messageAttributes && startConfig.messageAttributes.length > 0) { -%>
22
+ let messageAttributeValidatorSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ <% startConfig.messageAttributes.forEach((prop, index) => { %> <%- prop.propertyName %>: {
26
+ type: 'object',
27
+ properties: {
28
+ Type: { type: 'string' },
29
+ Value: { type: '<%- prop.type || 'string' %>' }
30
+ },
31
+ required: ['Type', 'Value']
32
+ } /*__EJS_COMMA_14__*/
33
+ <% }) %>
34
+ },
35
+ required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
36
+ };
37
+ <% } else { -%>
38
+ let messageAttributeValidatorSchema = null;
39
+ <% } -%>
40
+
8
41
  middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
9
42
 
10
- export const main = middleware.wrap(async event => {
43
+ export const main = middleware.wrap(async (event) => {
11
44
  try {
12
45
  const recordPromises = [];
13
- await Promise.all(event.Records.map(async record => {
14
- await recordHandlerSharedLib.validateRecord(record, '<%- queueName %>', {}, null);
15
- recordPromises.push(recordHandlerSharedLib.recordHandler(
16
- record,
17
- <%- functionName %>,
18
- '<%- queueName %>',
19
- [
20
- record.body.Message.identifiers,
21
- record.body.TopicArn,
22
- callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)
23
- ]
24
- ));
25
- }));
46
+ await Promise.all(
47
+ event.Records.map(async (record) => {
48
+ await recordHandlerSharedLib.validateRecord(
49
+ record,
50
+ '<%- queueName %>',
51
+ perRecordsValidatorSchema,
52
+ messageAttributeValidatorSchema
53
+ );
54
+ recordPromises.push(
55
+ recordHandlerSharedLib.recordHandler(
56
+ record,
57
+ <%- functionName %>,
58
+ '<%- queueName %>',
59
+ [
60
+ record.body.Message,
61
+ record.body.TopicArn,
62
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(
63
+ record.body.Message
64
+ )
65
+ ]
66
+ )
67
+ );
68
+ })
69
+ );
26
70
  await Promise.all(recordPromises);
27
71
  return event.Records;
28
72
  } catch (error) {
@@ -1,6 +1,9 @@
1
1
  import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
2
2
  import { triggeredCacheSharedLibV2 } from '@izara_project/izara-core-library-trigger-cache';
3
3
 
4
+ //(<optionalRequire>)
5
+ //(</optionalRequire>)
6
+
4
7
  export default async function <%- functionName %>(
5
8
  _izContext,
6
9
  requestParams,
@@ -8,14 +11,8 @@ export default async function <%- functionName %>(
8
11
  callingFlowConfig = {}
9
12
  ) {
10
13
  try {
11
- _izContext.logger.debug(
12
- '<%- functionName %> requestParams',
13
- requestParams
14
- );
15
- _izContext.logger.debug(
16
- '<%- functionName %> topicArn',
17
- topicArn
18
- );
14
+ _izContext.logger.debug('<%- functionName %> requestParams', requestParams);
15
+ _izContext.logger.debug('<%- functionName %> topicArn', topicArn);
19
16
  _izContext.logger.debug(
20
17
  '<%- functionName %> callingFlowConfig',
21
18
  callingFlowConfig
@@ -39,13 +36,14 @@ export default async function <%- functionName %>(
39
36
  _izContext,
40
37
  { serviceTag: topicName[0], flowTag: topicName[2] },
41
38
  identifiers,
42
- { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag, targetCompleteStep: process.env.iz_targetCompleteStepName }
39
+ {
40
+ flowTag: '<%- flowTag %>',
41
+ serviceTag: process.env.iz_serviceTag,
42
+ targetCompleteStep: process.env.iz_targetCompleteStepName
43
+ }
43
44
  );
44
45
 
45
- _izContext.logger.debug(
46
- '<%- functionName %> flowSchema',
47
- flowSchema
48
- );
46
+ _izContext.logger.debug('<%- functionName %> flowSchema', flowSchema);
49
47
  _izContext.logger.debug(
50
48
  '<%- functionName %> checkTriggerCache',
51
49
  checkTriggerCache
@@ -54,10 +52,7 @@ export default async function <%- functionName %>(
54
52
  //(<endpointHook>)
55
53
  //(</endpointHook>)
56
54
  } catch (error) {
57
- _izContext.logger.error(
58
- '<%- functionName %> failed',
59
- error
60
- );
55
+ _izContext.logger.error('<%- functionName %> failed', error);
61
56
  throw error;
62
57
  }
63
58
  }