@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
@@ -34,22 +34,47 @@ export function flowExtTopicSteps(flows) {
34
34
  if (typeof flow?.flowTag !== 'string' || flow.flowTag === '') {
35
35
  return [];
36
36
  }
37
- return (flow.flowSteps ?? []).flatMap(step =>
38
- typeof step?.stepName === 'string' &&
39
- step.stepName !== '' &&
40
- step.stepName.toLowerCase() !== 'start' &&
41
- Array.isArray(step.event) &&
42
- step.event.includes('extTopic')
43
- ? [
44
- {
45
- flow,
46
- step,
47
- flowTag: upperFirst(flow.flowTag),
48
- stepName: upperFirst(step.stepName)
49
- }
50
- ]
51
- : []
37
+ const hasTriggerFlowTypes = Array.isArray(flow.triggerFlowTypes) && flow.triggerFlowTypes.length > 0;
38
+ const steps = flow.flowSteps ?? [];
39
+ const hasCheckStep = steps.some(
40
+ step => typeof step?.stepName === 'string' && step.stepName.toLowerCase().includes('checktrigger')
52
41
  );
42
+
43
+ const result = steps.flatMap(step => {
44
+ if (
45
+ typeof step?.stepName !== 'string' ||
46
+ step.stepName === '' ||
47
+ step.stepName.toLowerCase() === 'start' ||
48
+ !Array.isArray(step.event) ||
49
+ !step.event.includes('extTopic')
50
+ ) {
51
+ return [];
52
+ }
53
+ const isCheckStep = step.stepName.toLowerCase().includes('checktrigger');
54
+ if (isCheckStep && !hasTriggerFlowTypes) {
55
+ return [];
56
+ }
57
+ return [
58
+ {
59
+ flow,
60
+ step,
61
+ flowTag: upperFirst(flow.flowTag),
62
+ stepName: upperFirst(step.stepName)
63
+ }
64
+ ];
65
+ });
66
+
67
+ if (hasTriggerFlowTypes && !hasCheckStep) {
68
+ const defaultStepName = 'CheckTriggerFlows';
69
+ result.push({
70
+ flow,
71
+ step: { stepName: defaultStepName, event: ['extTopic'] },
72
+ flowTag: upperFirst(flow.flowTag),
73
+ stepName: defaultStepName
74
+ });
75
+ }
76
+
77
+ return result;
53
78
  });
54
79
  }
55
80
 
@@ -112,10 +137,15 @@ export function triggerCacheFlows(flows) {
112
137
 
113
138
  export function triggerCacheQueueNames(flow) {
114
139
  const tag = upperFirst(flow.flowTag);
115
- return [
116
- `TriggerCache${tag}HdrDsq`,
117
- `CheckTriggerCache${tag}CompleteHdrSqs`,
118
- `TriggerCache${tag}CompleteHdrSqs`,
119
- `TriggerCache${tag}CompleteHdrDsq`
120
- ];
140
+ const queues = [`TriggerCache${tag}HdrDsq`];
141
+ if (Array.isArray(flow.triggerFlowTypes) && flow.triggerFlowTypes.length > 0) {
142
+ const customCheckStep = (flow.flowSteps ?? []).find(
143
+ s => typeof s?.stepName === 'string' && s.stepName.toLowerCase().includes('checktrigger')
144
+ );
145
+ const checkStepName = customCheckStep
146
+ ? (upperFirst(customCheckStep.stepName).startsWith(tag) ? upperFirst(customCheckStep.stepName) : `${tag}${upperFirst(customCheckStep.stepName)}`)
147
+ : `${tag}CheckTriggerFlows`;
148
+ queues.push(`${checkStepName}HdrSqs`);
149
+ }
150
+ return queues;
121
151
  }
@@ -5,6 +5,7 @@ import {
5
5
  renderApiFunctionYaml,
6
6
  renderEventBridgeFunctionYaml,
7
7
  renderInvFunctionYaml,
8
+ renderS3FunctionYaml,
8
9
  renderSqsFunctionYaml,
9
10
  renderWbsFunctionYaml
10
11
  } from '../function/functionYamlArtifact.js';
@@ -123,27 +124,19 @@ function flowPaths(flow) {
123
124
  async function emitExtTopicStep({ flow, step, flowTag, stepName }) {
124
125
  const source = `app/src/generatedCode/FlowSchemas/${flowTag}/source`;
125
126
  const handlerRoot = `src/generatedCode/FlowSchemas/${flowTag}/source`;
126
- const functionName = `${flowTag}${stepName}`;
127
+ const functionName = stepName.startsWith(flowTag) ? stepName : `${flowTag}${stepName}`;
127
128
  const mainFileName = `${functionName}_Main`;
128
129
  const startConfig = stepConfig(flow, step);
129
130
 
130
- if (step.checkTriggerType === 'flowType') {
131
- const completeStep = flow.flowSteps?.find(s => s.checkTriggerType === 'complete');
132
- const completeStepName = completeStep ? completeStep.stepName : undefined;
131
+ const hasTriggerFlowTypes = Array.isArray(flow.triggerFlowTypes) && flow.triggerFlowTypes.length > 0;
132
+ const isCheckStep = stepName.toLowerCase().includes('checktrigger');
133
+
134
+ if (isCheckStep && hasTriggerFlowTypes) {
133
135
  const queueName = `${functionName}HdrSqs`;
134
136
  return {
135
137
  artifacts: [
136
138
  { path: `${source}/${mainFileName}.js`, content: await renderCustom('triggerCache/CheckTriggerCache_Main.ejs', { functionName, flowTag }) },
137
- { path: `${source}/${functionName}_HdrSqs.js`, content: await renderCustom('triggerCache/CheckTriggerCache_HdrSqs.ejs', { functionName, queueName }) }
138
- ],
139
- functions: [renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName, flowTag, flowStepName: step.stepName, targetCompleteStepName: completeStepName })]
140
- };
141
- } else if (step.checkTriggerType === 'complete') {
142
- const queueName = `${functionName}HdrSqs`;
143
- return {
144
- artifacts: [
145
- { path: `${source}/${mainFileName}.js`, content: await renderCustom('triggerCache/TriggerCacheComplete_Main.ejs', { functionName, flowTag }) },
146
- { path: `${source}/${functionName}_HdrSqs.js`, content: await render('FlowHandler_HdrSqs.ejs', { flowTag: flow.flowTag, flowStepName: step.stepName, functionName, mainFileName, startConfig, queueName, usePassBack: false }) }
139
+ { path: `${source}/${functionName}_HdrSqs.js`, content: await renderCustom('triggerCache/CheckTriggerCache_HdrSqs.ejs', { functionName, queueName, startConfig }) }
147
140
  ],
148
141
  functions: [renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName, flowTag, flowStepName: step.stepName })]
149
142
  };
@@ -224,7 +217,7 @@ async function emitS3Flow(flow, source, handlerRoot) {
224
217
  { action: 'CreateObject', handler: 'HdrWbs', type: 'wbs', mainTemplate: 'CreateObject_Main.ejs', handlerTemplate: 'CreateObject_HdrWbs.ejs' },
225
218
  { action: 'ReservedLimit', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'ReservedLimit_Main.ejs', handlerTemplate: 'ReservedLimit_HdrSqs.ejs' },
226
219
  { action: 'CreatePreSignUrl', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'CreatePreSignUrl_Main.ejs', handlerTemplate: 'CreatePreSignUrl_HdrSqs.ejs' },
227
- { action: 'ProcessAfterUpload', handler: 'HdrS3', type: 'inv', mainTemplate: 'ProcessS3File_Main.ejs', handlerTemplate: 'FlowHandler_HdrS3.ejs' },
220
+ { action: 'ProcessAfterUpload', handler: 'HdrS3', type: 's3', mainTemplate: 'ProcessS3File_Main.ejs', handlerTemplate: 'FlowHandler_HdrS3.ejs' },
228
221
  { action: 'ConfirmAfterUpload', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'ConfirmReserved_Main.ejs', handlerTemplate: 'ConfirmReserved_HdrSqs.ejs' }
229
222
  ];
230
223
  const emitted = await Promise.all(parts.map(async ({ action, handler, type, mainTemplate, handlerTemplate }) => {
@@ -237,8 +230,10 @@ async function emitS3Flow(flow, source, handlerRoot) {
237
230
  const functionYaml = type === 'wbs'
238
231
  ? renderWbsFunctionYaml({ ...descriptor, routeName: tag, flowTag: flow.flowTag, flowStepName: '' })
239
232
  : type === 'sqs'
240
- ? renderSqsFunctionYaml({ ...descriptor, queueName: handlerFileName, flowTag: flow.flowTag, flowStepName: '' })
241
- : renderInvFunctionYaml({ ...descriptor, flowTag: flow.flowTag, flowStepName: '' });
233
+ ? renderSqsFunctionYaml({ ...descriptor, queueName: descriptor.functionName, flowTag: flow.flowTag, flowStepName: '' })
234
+ : type === 's3'
235
+ ? renderS3FunctionYaml({ ...descriptor, bucketName: flow.bucketName ?? '', flowTag: flow.flowTag, flowStepName: '' })
236
+ : renderInvFunctionYaml({ ...descriptor, flowTag: flow.flowTag, flowStepName: '' });
242
237
  return {
243
238
  artifacts: [
244
239
  { path: `${source}/${mainFileName}.js`, content: mainContent },
@@ -265,7 +260,7 @@ function s3HandlerData({ action, flow, functionName, mainFileName, handler }) {
265
260
  }
266
261
 
267
262
  function startConfig(flow) {
268
- const start = flow.flowSteps?.find(step => step.stepName?.toLowerCase() === 'start');
263
+ const start = flow.flowSteps?.[0];
269
264
  return start ? stepConfig(flow, start) : null;
270
265
  }
271
266
 
@@ -40,7 +40,6 @@ import { utils } from '@izara_project/izara-core-library-service-schemas';
40
40
  const { createFlowTypeConcat } = utils;
41
41
  //(</optionalImport>)
42
42
 
43
-
44
43
  /**
45
44
  *
46
45
  *
@@ -59,40 +58,46 @@ const { createFlowTypeConcat } = utils;
59
58
  export default async function <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>(
60
59
  _izContext,
61
60
  requestParams,
62
- callingFlowConfig = {},
61
+ callingFlowConfig = {}
63
62
  //(<additionalParams>)
64
63
  //(</additionalParams>)
65
64
  ) {
66
-
67
65
  try {
68
- _izContext.logger.debug("<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> _izContext", _izContext)
69
- _izContext.logger.debug("<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> requestParams", requestParams)
70
- _izContext.logger.debug("<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> callingFlowConfig", callingFlowConfig)
66
+ _izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> _izContext', _izContext);
67
+ _izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> requestParams', requestParams);
68
+ _izContext.logger.debug(
69
+ '<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> callingFlowConfig',
70
+ callingFlowConfig
71
+ );
71
72
 
72
- <% if (typeof flow !== 'undefined' && flow.statusType === 'storedCache') { %>
73
+ <% if (typeof flow !== 'undefined' && flow.statusType === 'storedCache') { %>
73
74
 
74
75
  //(<beforeCheckCache>)
75
76
  //(</beforeCheckCache>)
76
77
 
77
- let [ cacheMainStatus, cacheMain, cacheExist ] = await storedCacheSharedLib.checkStoredCacheStatus(
78
- _izContext,
79
- "<%= tableName %>",
80
- {
81
- //(<keyValueStoredCacheTable>)
82
- //(</keyValueStoredCacheTable>)
83
- },
84
- //(<additionalAttributesWhenCreateStoredCache>)
85
- //(</additionalAttributesWhenCreateStoredCache>),
86
- createFlowTypeConcat(_izContext, { flowTag: "<%= flowTag %>", serviceTag: process.env.iz_serviceTag }),
87
- //(<storedCacheConfig>)
88
- //(</storedCacheConfig>)
89
- )
78
+ let [cacheMainStatus, cacheMain, cacheExist] =
79
+ await storedCacheSharedLib.checkStoredCacheStatus(
80
+ _izContext,
81
+ '<%= tableName %>',
82
+ {
83
+ //(<keyValueStoredCacheTable>)
84
+ //(</keyValueStoredCacheTable>)
85
+ },
86
+ //(<additionalAttributesWhenCreateStoredCache>)
87
+ //(</additionalAttributesWhenCreateStoredCache>),
88
+ createFlowTypeConcat(_izContext, {
89
+ flowTag: '<%= flowTag %>',
90
+ serviceTag: process.env.iz_serviceTag
91
+ })
92
+ //(<storedCacheConfig>)
93
+ //(</storedCacheConfig>)
94
+ );
90
95
 
91
96
  //(<afterCheckStoredCache>)
92
97
  //(</afterCheckStoredCache>)
93
98
 
94
- if (cacheMainStatus !== "process") {
95
- if (cacheMainStatus === "error" || cacheMainStatus === "complete") {
99
+ if (cacheMainStatus !== 'process') {
100
+ if (cacheMainStatus === 'error' || cacheMainStatus === 'complete') {
96
101
  //(<afterValidateStoredCacheStatus>)
97
102
  //(</afterValidateStoredCacheStatus>)
98
103
  }
@@ -100,40 +105,47 @@ export default async function <%- typeof functionName !== 'undefined' ? function
100
105
  //(<checkStoredCacheHook>)
101
106
  //(</checkStoredCacheHook>)
102
107
  }
103
- <% } %>
108
+ <% } %>
104
109
 
105
- <% if (typeof flow !== 'undefined' && flow.isRbac) { %>
106
- const { checkRbacPermission } = await import('@izara_project/izara-authorization');
110
+ <% if (typeof flow !== 'undefined' && flow.isRbac) { %>
111
+ const { checkRbacPermission } =
112
+ await import('@izara_project/izara-authorization');
107
113
 
108
114
  //(<additionalParams_parameterGroups>)
109
115
  const parameterGroups = {};
110
116
  //(</additionalParams_parameterGroups>)
111
117
 
112
- const resultPermissionCheck = await checkRbacPermission(_izContext, { flowTag: '<%- flow.flowTag %>', serviceTag: '<%- flow.serviceTag || (flow.objType ? flow.objType.serviceTag : "") %>' }, parameterGroups);
118
+ const resultPermissionCheck = await checkRbacPermission(
119
+ _izContext,
120
+ { flowTag: '<%- flow.flowTag %>', serviceTag: '<%- flow.serviceTag || (flow.objType ? flow.objType.serviceTag : "") %>' },
121
+ parameterGroups
122
+ );
113
123
 
114
- _izContext.logger.debug('[lib:auth:checkRbacPermission] resultPermissionCheck:', resultPermissionCheck);
124
+ _izContext.logger.debug(
125
+ '[lib:auth:checkRbacPermission] resultPermissionCheck:',
126
+ resultPermissionCheck
127
+ );
115
128
 
116
129
  if (resultPermissionCheck.permission === false) {
117
-
118
130
  //(<messageOutPutPermissionCheckFailed>)
119
- const message = {
120
-
121
- }
131
+ const message = {};
122
132
  //(</messageOutPutPermissionCheckFailed>)
123
133
 
124
134
  return await sns.publishAsync(_izContext, {
125
135
  Message: JSON.stringify(message),
126
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, '<%- flow.flowTag %>_Out')
136
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
137
+ _izContext,
138
+ '<%- flow.flowTag %>_Out'
139
+ )
127
140
  });
128
141
  }
129
142
 
130
- <% } %>
143
+ <% } %>
131
144
 
132
145
  //(<endpointHook>)
133
146
  //(</endpointHook>)
134
-
135
147
  } catch (err) {
136
- _izContext.logger.error('error WebSocketInvoke: ', err)
137
- throw (err)
148
+ _izContext.logger.error('error WebSocketInvoke: ', err);
149
+ throw err;
138
150
  }
139
151
  }
@@ -37,24 +37,22 @@ import { identifierUuid } from '@izara_project/izara-shared-core';
37
37
  export default async function <%= functionName %>(
38
38
  _izContext,
39
39
  requestParams,
40
- callingFlowConfig = {},
40
+ callingFlowConfig = {}
41
41
  //(<additionalParams>)
42
42
  //(</additionalParams>)
43
43
  ) {
44
-
45
-
46
44
  try {
47
45
  _izContext.logger.debug('<%= functionName %> _izContext: ', _izContext);
48
46
  _izContext.logger.debug('<%= functionName %> requestParams: ', requestParams);
49
- _izContext.logger.debug('<%= functionName %> callingFlowConfig: ', callingFlowConfig);
47
+ _izContext.logger.debug(
48
+ '<%= functionName %> callingFlowConfig: ',
49
+ callingFlowConfig
50
+ );
50
51
 
51
52
  //(<hookCode>)
52
53
  //(</hookCode>)
53
-
54
-
55
-
56
54
  } catch (err) {
57
- _izContext.logger.error('error <%= functionName %>Main: ', err)
58
- throw (err)
55
+ _izContext.logger.error('error <%= functionName %>Main: ', err);
56
+ throw err;
59
57
  }
60
58
  }
@@ -15,32 +15,26 @@ 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";
21
- import { recordHandlerSharedLib } from "@izara_project/izara-core-library-record-handler";
18
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
19
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
22
20
  import Logger from '@izara_project/izara-core-library-logger';
23
- import callingFlowSharedLib from "@izara_project/izara-core-library-calling-flow";
21
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
24
22
 
25
- import <%= functionName %> from './<%= functionName %>_Main.js'
23
+ import <%= functionName %> from './<%= functionName %>_Main.js';
26
24
 
27
25
  // validate event properties in body.Message of sqs event
28
26
  middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
29
27
 
30
28
  // set schema for record.body.Message
31
29
  let perRecordsValidatorSchema = {
32
- type: "object",
33
- required: [
34
- 'returnMessage',
35
- 'errorsFound',
36
- 'passStatus'
37
- ],
30
+ type: 'object',
31
+ required: ['returnMessage', 'errorsFound', 'passStatus'],
38
32
  properties: {
39
33
  returnMessage: {
40
- type: "object"
34
+ type: 'object'
41
35
  },
42
36
  errorsFound: {
43
- type: "array"
37
+ type: 'array'
44
38
  },
45
39
  passStatus: {
46
40
  type: 'boolean'
@@ -62,62 +56,73 @@ let perRecordsValidatorSchema = {
62
56
  // }
63
57
  // };
64
58
 
65
- perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema)
59
+ perRecordsValidatorSchema =
60
+ callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
61
+ perRecordsValidatorSchema
62
+ );
66
63
 
67
64
  export const main = middleware.wrap(async (event, context) => {
68
-
69
65
  try {
70
-
71
66
  let recordPromises = [];
72
67
 
73
68
  // loop each record and send to mainFunction
74
- await Promise.all(event.Records.map(async record => { // promise.all for map() function
75
-
76
- let passOnProperties = []
77
- record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
78
-
79
- // validate message (and MessageAttributes)
80
- await recordHandlerSharedLib.validateRecord(
81
- record, // one record will send to mainFunction
82
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
83
- perRecordsValidatorSchema, // schema for record.Message
84
- // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
85
- );
86
-
87
- // add argument (to invoke lambda) to passOnProperties[]
88
- passOnProperties.push(record.body.Message.returnMessage)
89
- passOnProperties.push(record.body.Message.errorsFound)
90
- passOnProperties.push(record.body.Message.passStatus)
91
- //(<additionalProperties>)
92
- //(</additionalProperties>)
93
- passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message))
94
- record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
95
-
96
- // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
97
- let recordPromise = recordHandlerSharedLib.recordHandler(
98
- record, // one record will send to mainFunction
99
- <%= functionName %>, // mainFunction that need to invoke.
100
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
101
- passOnProperties, // all parameters that mainFunction needed.
102
- );
103
- record._izContext.logger.debug('after recordPromise in handler');
104
- recordPromises.push(recordPromise); // push promise to recordPromises
105
- }))
69
+ await Promise.all(
70
+ event.Records.map(async (record) => {
71
+ // promise.all for map() function
72
+
73
+ let passOnProperties = [];
74
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
75
+
76
+ // validate message (and MessageAttributes)
77
+ await recordHandlerSharedLib.validateRecord(
78
+ record, // one record will send to mainFunction
79
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
80
+ perRecordsValidatorSchema // schema for record.Message
81
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
82
+ );
83
+
84
+ // add argument (to invoke lambda) to passOnProperties[]
85
+ passOnProperties.push(record.body.Message.returnMessage);
86
+ passOnProperties.push(record.body.Message.errorsFound);
87
+ passOnProperties.push(record.body.Message.passStatus);
88
+ //(<additionalProperties>)
89
+ //(</additionalProperties>)
90
+ passOnProperties.push(
91
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
92
+ record.body.Message
93
+ )
94
+ );
95
+ record._izContext.logger.debug(
96
+ 'passOnProperties in handler',
97
+ passOnProperties
98
+ );
99
+
100
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
101
+ let recordPromise = recordHandlerSharedLib.recordHandler(
102
+ record, // one record will send to mainFunction
103
+ <%= functionName %>, // mainFunction that need to invoke.
104
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
105
+ passOnProperties // all parameters that mainFunction needed.
106
+ );
107
+ record._izContext.logger.debug('after recordPromise in handler');
108
+ recordPromises.push(recordPromise); // push promise to recordPromises
109
+ })
110
+ );
106
111
 
107
112
  Logger.debug('before Promise.all(recordPromises) in handler');
108
113
  try {
109
114
  // --- main await all promises
110
115
  await Promise.all(recordPromises); // await all promises
111
116
 
112
- return event.Records // return all for local test
113
-
117
+ return event.Records; // return all for local test
114
118
  } catch {
115
- Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
119
+ Logger.debug(
120
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
121
+ );
116
122
  }
117
123
  Logger.debug('after Promise.all(recordPromises) in handler');
118
-
119
124
  } catch (err) {
120
125
  Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
121
- throw (err);
126
+ throw err;
122
127
  }
123
128
  });
@@ -15,8 +15,6 @@ 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 dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
19
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
20
  import { sns } from '@izara_project/izara-core-library-external-request';
@@ -56,18 +54,21 @@ export default async function confirmNewReserved(
56
54
  errorsFound: errorsFound,
57
55
  passStatus: passStatus,
58
56
  passBackProperties: passBackProperties
59
- })
57
+ });
60
58
 
61
- let servicePendingId = passBackProperties.passBackProperties.identifier.servicePendingId;
62
- let reservedDataId = passBackProperties.passBackProperties.identifier.reservedDataId;
59
+ let servicePendingId =
60
+ passBackProperties.passBackProperties.identifier.servicePendingId;
61
+ let reservedDataId =
62
+ passBackProperties.passBackProperties.identifier.reservedDataId;
63
63
  let userId = passBackProperties.passBackProperties.identifier.userId;
64
- let realFileSize = passBackProperties.passBackProperties.identifier.realFileSize;
64
+ let realFileSize =
65
+ passBackProperties.passBackProperties.identifier.realFileSize;
65
66
 
66
- let uniqueIdentify = getNestObject(
67
- _izContext,
68
- returnMessage.limitFound,
69
- ["runningTotal", "uniqueIdentify", "usedTimestampId"]
70
- );
67
+ let uniqueIdentify = getNestObject(_izContext, returnMessage.limitFound, [
68
+ 'runningTotal',
69
+ 'uniqueIdentify',
70
+ 'usedTimestampId'
71
+ ]);
71
72
 
72
73
  // confirmUsage
73
74
  let confirmUsageMessage = {
@@ -75,14 +76,21 @@ export default async function confirmNewReserved(
75
76
  //(<optionalLimitTag>)
76
77
  limitTag: schemaConsts.LIMIT_TAG.uploadData,
77
78
  //(</optionalLimitTag>)
78
- uniqueIdentify: uniqueIdentify,
79
- }
79
+ uniqueIdentify: uniqueIdentify
80
+ };
80
81
 
81
82
  let sendMessageToConfirmUsage = {
82
83
  Message: JSON.stringify(confirmUsageMessage),
83
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'ConfirmUsage_In', schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits)
84
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
85
+ _izContext,
86
+ 'ConfirmUsage_In',
87
+ schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits
88
+ )
84
89
  };
85
- _izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
90
+ _izContext.logger.debug(
91
+ 'sendMessageToConfirmUsage',
92
+ sendMessageToConfirmUsage
93
+ );
86
94
  await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
87
95
 
88
96
  // update reservedDataValue as real size in ReservedDataMain table
@@ -96,7 +104,7 @@ export default async function confirmNewReserved(
96
104
  {
97
105
  reservedValue: realFileSize
98
106
  }
99
- )
107
+ );
100
108
 
101
109
  let sendMessageToUpdateStatus = {
102
110
  //(<messageObjectHook>)
@@ -111,19 +119,21 @@ export default async function confirmNewReserved(
111
119
  //(</fields>)
112
120
  }
113
121
  }
114
- }
122
+ };
115
123
 
116
124
  let sendMessageToUpdateEndpoint = {
117
125
  Message: JSON.stringify(sendMessageToUpdateStatus),
118
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Update_In")
126
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Update_In')
119
127
  };
120
- _izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
128
+ _izContext.logger.debug(
129
+ 'sendMessageToUpdateEndpoint',
130
+ sendMessageToUpdateEndpoint
131
+ );
121
132
  await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
122
133
 
123
- return { returnResponse: 'success' }
124
-
134
+ return { returnResponse: 'success' };
125
135
  } catch (err) {
126
- _izContext.logger.debug('error ConfirmNewReservedMain: ', err)
127
- throw (err)
136
+ _izContext.logger.debug('error ConfirmNewReservedMain: ', err);
137
+ throw err;
128
138
  }
129
139
  }