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

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 (86) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +105 -0
  4. package/src/compile/compileProject.js +16 -1
  5. package/src/compile/loadSchemas.js +89 -4
  6. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
  7. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  8. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  9. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  10. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  11. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  12. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  13. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  14. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  15. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  16. package/src/emit/crud/templates/GetEndpoint_Main.ejs +5 -2
  17. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  18. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
  19. package/src/emit/custom/customFlows.js +51 -21
  20. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +13 -18
  21. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  22. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  23. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  24. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  25. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  26. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  27. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  28. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  29. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
  30. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  31. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
  32. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  33. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  34. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  35. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  36. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  37. package/src/emit/function/functionYamlArtifact.js +20 -0
  38. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
  39. package/src/emit/rbac/emitRbacApplicationArtifacts.js +168 -69
  40. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  41. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  42. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  43. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  44. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  45. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  46. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  47. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  48. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  49. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
  50. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  51. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  52. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  53. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  54. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  55. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  56. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  57. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  58. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  59. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  60. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  61. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  62. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  63. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  64. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  65. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  66. package/src/emit/resource/emitResourceArtifacts.js +107 -11
  67. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  68. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  69. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
  70. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  71. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  72. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  73. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  74. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  75. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
  76. package/src/generate.js +6 -2
  77. package/test/createTargetRoleHandler.test.js +63 -14
  78. package/test/customFlowApplicationArtifacts.test.js +48 -23
  79. package/test/dynamicCrudFlowSchemas.test.js +6 -6
  80. package/test/dynamicRbacFlowSchemas.test.js +8 -12
  81. package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
  82. package/test/publicApi.test.js +10 -12
  83. package/test/resourceArtifacts.test.js +12 -2
  84. package/docs/test.png +0 -0
  85. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  86. /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
@@ -15,25 +15,32 @@ 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 snsSharedLib from '@izara_project/izara-core-library-sns';
21
19
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
20
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
23
21
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
24
22
 
25
- import { lambda, sns } from '@izara_project/izara-core-library-external-request'
23
+ import {
24
+ lambda,
25
+ sns
26
+ } from '@izara_project/izara-core-library-external-request';
26
27
 
27
28
  import { S3Client } from '@aws-sdk/client-s3';
28
29
  import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
29
30
  const client = new S3Client({ region: process.env.AWS_REGION });
30
31
  import { consts } from '@izara_project/izara-middleware';
31
32
 
32
- import { postToConnection, getNestObject } from '../../../libs/source/GenerateCodeLibs.js'
33
+ import {
34
+ postToConnection,
35
+ getNestObject
36
+ } from '../../../libs/source/GenerateCodeLibs.js';
33
37
  import { consts as coreConsts } from '@izara_project/izara-core-library-core';
34
- import { consts as schemaConsts, utils } from "@izara_project/izara-core-library-service-schemas"
38
+ import {
39
+ consts as schemaConsts,
40
+ utils
41
+ } from '@izara_project/izara-core-library-service-schemas';
35
42
  const { EXTERNAL_SERVICE_NAME } = schemaConsts;
36
- const { createFlowTypeConcat } = utils
43
+ const { createFlowTypeConcat } = utils;
37
44
  //(<optionalRequired>)
38
45
  //(</optionalRequired>)
39
46
 
@@ -51,7 +58,7 @@ const { createFlowTypeConcat } = utils
51
58
  * @returns {object} returnResponse
52
59
  */
53
60
 
54
- export default async function createPreSignUrl (
61
+ export default async function createPreSignUrl(
55
62
  _izContext,
56
63
  returnMessage,
57
64
  errorsFound,
@@ -59,10 +66,8 @@ export default async function createPreSignUrl (
59
66
  //(<additionalProperties>)
60
67
  //(</additionalProperties>)
61
68
  passBackProperties = {}
62
- ) {
63
-
69
+ ) {
64
70
  try {
65
-
66
71
  _izContext.logger.debug('----- createPreSignUrl event params -----', {
67
72
  returnMessage: returnMessage,
68
73
  errorsFound: errorsFound,
@@ -70,46 +75,54 @@ export default async function createPreSignUrl (
70
75
  passBackProperties: passBackProperties
71
76
  });
72
77
 
73
- const servicePendingId = passBackProperties.passBackProperties.identifier.servicePendingId; // importBatchId
74
- const reservedDataId = passBackProperties.passBackProperties.identifier.reservedDataId;
75
- const objType = passBackProperties.passBackProperties.objType
78
+ const servicePendingId =
79
+ passBackProperties.passBackProperties.identifier.servicePendingId; // importBatchId
80
+ const reservedDataId =
81
+ passBackProperties.passBackProperties.identifier.reservedDataId;
82
+ const objType = passBackProperties.passBackProperties.objType;
76
83
 
77
- const correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID)
78
- const connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
84
+ const correlationId = _izContext.correlationIds.get(
85
+ consts.X_CORRELATION_ID
86
+ );
87
+ const connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID);
79
88
 
80
- let getResult = await lambda.invokeSync(_izContext,
81
- await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv"),
89
+ let getResult = await lambda.invokeSync(
90
+ _izContext,
91
+ await lambdaSharedLib.lambdaFunctionName(_izContext, 'GetHdrInv'),
82
92
  {
83
- objectType: objType.objectType,
93
+ objectType: objType.objectType
84
94
  //(<identifiersForGetData>)
85
95
  //(</identifiersForGetData>)
86
96
  }
87
- )
88
- _izContext.logger.debug("getResult", getResult);
97
+ );
98
+ _izContext.logger.debug('getResult', getResult);
89
99
 
90
100
  //(<afterGetResult>)
91
101
  //(</afterGetResult>)
92
102
 
93
- let uniqueIdentify = getNestObject(
94
- _izContext,
95
- returnMessage,
96
- ['limitFound', 'runningTotal', 'uniqueIdentify', 'usedTimestampId']
97
- );
98
- _izContext.logger.debug("uniqueIdentify", uniqueIdentify);
103
+ let uniqueIdentify = getNestObject(_izContext, returnMessage, [
104
+ 'limitFound',
105
+ 'runningTotal',
106
+ 'uniqueIdentify',
107
+ 'usedTimestampId'
108
+ ]);
109
+ _izContext.logger.debug('uniqueIdentify', uniqueIdentify);
99
110
 
100
- await dynamodbSharedLib.putItem(_izContext,
101
- await dynamodbSharedLib.tableName(_izContext, "ReservedDataMain"),
111
+ await dynamodbSharedLib.putItem(
112
+ _izContext,
113
+ await dynamodbSharedLib.tableName(_izContext, 'ReservedDataMain'),
102
114
  //(<createReservedDataMain>)
103
115
  {}
104
116
  //(</createReservedDataMain>)
105
117
  );
106
118
 
107
- if (passStatus === false) { // if passStatus false post message to client
119
+ if (passStatus === false) {
120
+ // if passStatus false post message to client
108
121
  // use correlationId to get connectionId and use connectionId to post message to client
109
122
 
110
- _izContext.logger.debug("reserved has reach limit");
123
+ _izContext.logger.debug('reserved has reach limit');
111
124
 
112
- errorsFound.push("reserved has reach limit")
125
+ errorsFound.push('reserved has reach limit');
113
126
  // update status
114
127
  let updateStatusField = {
115
128
  objInstanceFull: {
@@ -123,13 +136,16 @@ export default async function createPreSignUrl (
123
136
  }
124
137
  },
125
138
  objectType: objType.objectType
126
- }
139
+ };
127
140
 
128
141
  let sendMessageToUpdateEndpoint = {
129
142
  Message: JSON.stringify(updateStatusField),
130
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, `Update_In`)
131
- }
132
- _izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
143
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, `Update_In`)
144
+ };
145
+ _izContext.logger.debug(
146
+ 'sendMessageToUpdateEndpoint',
147
+ sendMessageToUpdateEndpoint
148
+ );
133
149
 
134
150
  // cancel reserved
135
151
 
@@ -141,38 +157,49 @@ export default async function createPreSignUrl (
141
157
 
142
158
  let sendMessageToCancelReserved = {
143
159
  Message: JSON.stringify(cancelReservedMsg),
144
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'CancelUsage_In', EXTERNAL_SERVICE_NAME.accountLimits)
160
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
161
+ _izContext,
162
+ 'CancelUsage_In',
163
+ EXTERNAL_SERVICE_NAME.accountLimits
164
+ )
145
165
  };
146
166
 
147
- _izContext.logger.debug("sendMessageToCancelReserved", sendMessageToCancelReserved);
167
+ _izContext.logger.debug(
168
+ 'sendMessageToCancelReserved',
169
+ sendMessageToCancelReserved
170
+ );
148
171
  await sns.publishAsync(_izContext, sendMessageToCancelReserved);
149
172
 
150
- await postToConnection({ message: "reserved has reach limit" }, connectionId)
173
+ await postToConnection(
174
+ { message: 'reserved has reach limit' },
175
+ connectionId
176
+ );
151
177
 
152
178
  //(<createIdentifiersForDeleteTask>)
153
- let identifiers
179
+ let identifiers;
154
180
  //(</createIdentifiersForDeleteTask>)
155
181
  // after post message delete websocket task
156
- await dynamodbSharedLib.deleteItem(_izContext,
157
- await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
182
+ await dynamodbSharedLib.deleteItem(
183
+ _izContext,
184
+ await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
158
185
  {
159
- taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
186
+ taskKey: `${createFlowTypeConcat(_izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
160
187
  connectionId: connectionId
161
188
  }
162
- )
189
+ );
163
190
 
164
191
  //(<afterCancelReservedLimit>)
165
192
  //(</afterCancelReservedLimit>)
166
193
 
167
- return "reserved not pass"
194
+ return 'reserved not pass';
168
195
  }
169
196
 
170
197
  //(<createKeyForUploadFile>)
171
- const Key = `${fileName}.${importType}`
198
+ const Key = `${fileName}.${importType}`;
172
199
  //(</createKeyForUploadFile>)
173
200
 
174
- const maximumSize = getResult.fields.fileSize * 1048576 // convert to byte unit for restrict
175
- _izContext.logger.debug("maximumSize", maximumSize);
201
+ const maximumSize = getResult.fields.fileSize * 1048576; // convert to byte unit for restrict
202
+ _izContext.logger.debug('maximumSize', maximumSize);
176
203
 
177
204
  // create PresignUrl
178
205
  let createPreSignUrlParam = {
@@ -180,9 +207,9 @@ export default async function createPreSignUrl (
180
207
  Key: Key,
181
208
  Conditions: [
182
209
  //(<conditionCreateUrlLink>)
183
- ["content-length-range", 0, maximumSize],
184
- ["starts-with", "$Content-Type", "file/csv"],
185
- ["eq", "$x-amz-meta-importBatchId", importBatchId]
210
+ ['content-length-range', 0, maximumSize],
211
+ ['starts-with', '$Content-Type', 'file/csv'],
212
+ ['eq', '$x-amz-meta-importBatchId', importBatchId]
186
213
  //(</conditionCreateUrlLink>)
187
214
  ],
188
215
  Fields: {},
@@ -197,11 +224,11 @@ export default async function createPreSignUrl (
197
224
  uploadUrl.fields['Content-Type'] = `file/${importType}`;
198
225
  //(</modifyUploadLinkField>)
199
226
 
200
- _izContext.logger.debug('uploadUrlLimitSize: ', uploadUrl) // return as object type = {url, fields}
227
+ _izContext.logger.debug('uploadUrlLimitSize: ', uploadUrl); // return as object type = {url, fields}
201
228
 
202
229
  // update to waiting to upload
203
230
  //(<checkStatusField>)
204
- if (status === "processing") {
231
+ if (status === 'processing') {
205
232
  //(</checkStatusField>)
206
233
  let messageObject = {
207
234
  objInstanceFull: {
@@ -210,52 +237,62 @@ export default async function createPreSignUrl (
210
237
  //(</identifiersForUpdateTable>)
211
238
  },
212
239
  fields: {
213
- importBatchStatus: "waitingToUpload",
214
- expiryTimestamp: (getResult.fields.startTime + (createPreSignUrlParam.Expires * 1000))
240
+ importBatchStatus: 'waitingToUpload',
241
+ expiryTimestamp:
242
+ getResult.fields.startTime + createPreSignUrlParam.Expires * 1000
215
243
  }
216
244
  },
217
245
  objectType: objType.objectType
218
- }
246
+ };
219
247
 
220
- messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
221
- messageObject,
222
- callingFlowSharedLib.addParentCallingFlowConfig(
223
- returnMessage, // resive parent callingFlowConfig.
224
- callingFlowSharedLib.createCallingFlowConfig( // calling flow own service
225
- await lambdaSharedLib.lambdaFunctionName(_izContext, `WebSocketComplete`), {}
248
+ messageObject =
249
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
250
+ messageObject,
251
+ callingFlowSharedLib.addParentCallingFlowConfig(
252
+ returnMessage, // resive parent callingFlowConfig.
253
+ callingFlowSharedLib.createCallingFlowConfig(
254
+ // calling flow own service
255
+ await lambdaSharedLib.lambdaFunctionName(
256
+ _izContext,
257
+ `WebSocketComplete`
258
+ ),
259
+ {}
260
+ )
226
261
  )
227
- )
228
- );
262
+ );
229
263
 
230
- _izContext.logger.debug("after add callingFlow", messageObject)
264
+ _izContext.logger.debug('after add callingFlow', messageObject);
231
265
 
232
266
  let sendMessageToUpdateEndpoint = {
233
267
  Message: JSON.stringify(messageObject),
234
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Update_In")
235
- }
236
- _izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
268
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Update_In')
269
+ };
270
+ _izContext.logger.debug(
271
+ 'sendMessageToUpdateEndpoint',
272
+ sendMessageToUpdateEndpoint
273
+ );
237
274
  await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
238
275
 
239
276
  //(<createIdentifierFlow>)
240
- let identifiers
277
+ let identifiers;
241
278
  //(</createIdentifierFlow>)
242
- await dynamodbSharedLib.updateItem(_izContext,
243
- await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
279
+ await dynamodbSharedLib.updateItem(
280
+ _izContext,
281
+ await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
244
282
  {
245
- taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
283
+ taskKey: `${createFlowTypeConcat(_izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
246
284
  connectionId: connectionId
247
285
  },
248
286
  {
249
287
  uploadUrl: uploadUrl
250
288
  }
251
- )
289
+ );
252
290
  }
253
291
 
254
292
  //(<mainFunctionHookCode>)
255
293
  //(</mainFunctionHookCode>)
256
-
257
294
  } catch (err) {
258
- _izContext.logger.error('error createPreSignUrl: ', err)
259
- throw (err)
295
+ _izContext.logger.error('error createPreSignUrl: ', err);
296
+ throw err;
260
297
  }
261
298
  }
@@ -15,8 +15,10 @@ 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
23
  import recordHandlerSharedLib from '@izara_project/izara-core-library-record-handler';
22
24
 
@@ -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';
@@ -28,94 +26,105 @@ import <%= functionName %> from './<%= functionName %>_Main.js';
28
26
  middleware.setServiceSchema(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
  });