@izara_project/izara-core-generate-service-code 1.0.66 → 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 (90) hide show
  1. package/.prettierrc +11 -0
  2. package/docs/TriggeredCache Flow.drawio +193 -0
  3. package/docs/TriggeredCacheFlow.mmd +47 -0
  4. package/package.json +16 -12
  5. package/scripts/format-ejs.js +105 -0
  6. package/src/compile/compileProject.js +16 -1
  7. package/src/compile/loadSchemas.js +108 -1
  8. package/src/emit/crud/emitCrudApplicationArtifacts.js +9 -5
  9. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +300 -109
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +221 -143
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +150 -38
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +57 -31
  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 +407 -252
  22. package/src/emit/custom/customFlows.js +112 -31
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +89 -77
  24. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +49 -37
  25. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  26. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  27. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  28. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  29. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  30. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  32. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
  33. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  34. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
  35. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  36. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  38. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  39. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  40. package/src/emit/function/functionYamlArtifact.js +46 -12
  41. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
  42. package/src/emit/rbac/emitRbacApplicationArtifacts.js +179 -66
  43. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  44. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  45. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  46. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  47. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  48. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  49. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  50. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  51. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  52. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
  53. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +6 -5
  54. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  55. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +260 -144
  56. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  57. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  58. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  59. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  60. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  61. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  62. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  63. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  64. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  65. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  66. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  67. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  68. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  69. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  70. package/src/emit/resource/emitResourceArtifacts.js +499 -108
  71. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  72. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  73. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
  74. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  75. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  76. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  77. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  78. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  79. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
  80. package/src/emit/system/emitSystemWebSocketArtifacts.js +2 -1
  81. package/src/generate.js +8 -4
  82. package/test/createTargetRoleHandler.test.js +63 -14
  83. package/test/crudApplicationArtifacts.test.js +1 -1
  84. package/test/customFlowApplicationArtifacts.test.js +71 -43
  85. package/test/dynamicCrudFlowSchemas.test.js +6 -6
  86. package/test/dynamicRbacFlowSchemas.test.js +8 -12
  87. package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
  88. package/test/publicApi.test.js +11 -13
  89. package/test/resourceArtifacts.test.js +13 -3
  90. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
@@ -1,15 +1,25 @@
1
- const SUPPORTED_EVENTS = new Set(['eventBridge', 'extTopic', 'lambdaSyncInv', 'lambdaSyncApi', 'ownTopic', 's3']);
1
+ const SUPPORTED_EVENTS = new Set([
2
+ 'eventBridge',
3
+ 'extTopic',
4
+ 'lambdaSyncInv',
5
+ 'lambdaSyncApi',
6
+ 'ownTopic',
7
+ 's3',
8
+ 'dsq'
9
+ ]);
2
10
 
3
11
  export function supportedCustomFlows(flows) {
4
12
  if (!Array.isArray(flows)) {
5
13
  throw new TypeError('flows must be an array');
6
14
  }
7
- return flows.filter(flow => (
8
- typeof flow?.flowTag === 'string' && flow.flowTag !== '' &&
9
- !flow.generatedCodeConfig &&
10
- Array.isArray(flow.event) &&
11
- flow.event.some(event => SUPPORTED_EVENTS.has(event))
12
- ));
15
+ return flows.filter(
16
+ flow =>
17
+ typeof flow?.flowTag === 'string' &&
18
+ flow.flowTag !== '' &&
19
+ !flow.generatedCodeConfig &&
20
+ Array.isArray(flow.event) &&
21
+ flow.event.some(event => SUPPORTED_EVENTS.has(event))
22
+ );
13
23
  }
14
24
 
15
25
  export function customFlowRoleName(flowTag) {
@@ -24,13 +34,74 @@ export function flowExtTopicSteps(flows) {
24
34
  if (typeof flow?.flowTag !== 'string' || flow.flowTag === '') {
25
35
  return [];
26
36
  }
27
- return (flow.flowSteps ?? []).flatMap(step => (
28
- typeof step?.stepName === 'string' && step.stepName !== '' &&
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')
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;
78
+ });
79
+ }
80
+
81
+ export function flowDsqSteps(flows) {
82
+ if (!Array.isArray(flows)) {
83
+ throw new TypeError('flows must be an array');
84
+ }
85
+ return flows.flatMap(flow => {
86
+ if (typeof flow?.flowTag !== 'string' || flow.flowTag === '') {
87
+ return [];
88
+ }
89
+ return (flow.flowSteps ?? []).flatMap(step =>
90
+ typeof step?.stepName === 'string' &&
91
+ step.stepName !== '' &&
29
92
  step.stepName.toLowerCase() !== 'start' &&
30
- Array.isArray(step.event) && step.event.includes('extTopic')
31
- ? [{ flow, step, flowTag: upperFirst(flow.flowTag), stepName: upperFirst(step.stepName) }]
93
+ Array.isArray(step.event) &&
94
+ step.event.includes('dsq')
95
+ ? [
96
+ {
97
+ flow,
98
+ step,
99
+ flowTag: upperFirst(flow.flowTag),
100
+ stepName: upperFirst(step.stepName)
101
+ }
102
+ ]
32
103
  : []
33
- ));
104
+ );
34
105
  });
35
106
  }
36
107
 
@@ -38,33 +109,43 @@ export function generatedOwnTopicFlows(flows) {
38
109
  if (!Array.isArray(flows)) {
39
110
  throw new TypeError('flows must be an array');
40
111
  }
41
- return flows.filter(flow => (
42
- typeof flow?.flowTag === 'string' && flow.flowTag !== '' &&
43
- flow.generatedCodeConfig &&
44
- Array.isArray(flow.event) && flow.event.includes('ownTopic')
45
- ));
112
+ return flows.filter(
113
+ flow =>
114
+ typeof flow?.flowTag === 'string' &&
115
+ flow.flowTag !== '' &&
116
+ flow.generatedCodeConfig &&
117
+ Array.isArray(flow.event) &&
118
+ flow.event.includes('ownTopic')
119
+ );
120
+ }
121
+
122
+ export function upperFirst(value) {
123
+ return value[0].toUpperCase() + value.slice(1);
46
124
  }
47
125
 
48
126
  export function triggerCacheFlows(flows) {
49
127
  if (!Array.isArray(flows)) {
50
128
  throw new TypeError('flows must be an array');
51
129
  }
52
- return flows.filter(flow => (
53
- typeof flow?.flowTag === 'string' && flow.flowTag !== '' &&
54
- flow.statusType === 'triggerCache'
55
- ));
130
+ return flows.filter(
131
+ flow =>
132
+ typeof flow?.flowTag === 'string' &&
133
+ flow.flowTag !== '' &&
134
+ flow.statusType === 'triggerCache'
135
+ );
56
136
  }
57
137
 
58
138
  export function triggerCacheQueueNames(flow) {
59
139
  const tag = upperFirst(flow.flowTag);
60
- return [
61
- `TriggerCache${tag}HdrDsq`,
62
- `CheckTriggerCache${tag}CompleteHdrSqs`,
63
- `TriggerCache${tag}CompleteHdrSqs`,
64
- `TriggerCache${tag}CompleteHdrDsq`
65
- ];
66
- }
67
-
68
- export function upperFirst(value) {
69
- return value[0].toUpperCase() + value.slice(1);
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;
70
151
  }
@@ -5,10 +5,11 @@ import {
5
5
  renderApiFunctionYaml,
6
6
  renderEventBridgeFunctionYaml,
7
7
  renderInvFunctionYaml,
8
+ renderS3FunctionYaml,
8
9
  renderSqsFunctionYaml,
9
10
  renderWbsFunctionYaml
10
11
  } from '../function/functionYamlArtifact.js';
11
- import { customFlowRoleName, flowExtTopicSteps, generatedOwnTopicFlows, supportedCustomFlows, triggerCacheFlows, triggerCacheQueueNames, upperFirst } from './customFlows.js';
12
+ import { customFlowRoleName, flowDsqSteps, flowExtTopicSteps, generatedOwnTopicFlows, supportedCustomFlows, upperFirst } from './customFlows.js';
12
13
 
13
14
  const YAML_PATH = 'app/sls_yaml/generatedCode/source/flow-schema.yml';
14
15
  const TEMPLATE_URL = new URL('../crud/templates/', import.meta.url);
@@ -19,19 +20,19 @@ export async function emitCustomFlowApplicationArtifacts(flows, { systemFunction
19
20
  const customFlows = supportedCustomFlows(flows);
20
21
  const generatedRoots = generatedOwnTopicFlows(flows);
21
22
  const steps = flowExtTopicSteps(flows);
22
- const triggerCache = triggerCacheFlows(flows);
23
- if (customFlows.length === 0 && generatedRoots.length === 0 && steps.length === 0 && triggerCache.length === 0 && systemFunctions.length === 0) return [];
23
+ const dsqSteps = flowDsqSteps(flows);
24
+ if (customFlows.length === 0 && generatedRoots.length === 0 && steps.length === 0 && dsqSteps.length === 0 && systemFunctions.length === 0) return [];
24
25
 
25
26
  const emitted = await Promise.all(customFlows.map(flow => emitFlow(flow, objects)));
26
27
  const roots = await Promise.all(generatedRoots.map(flow => emitOwnTopicRoot(flow, objects)));
27
28
  const stepResults = await Promise.all(steps.map(emitExtTopicStep));
28
- const triggerCacheResults = await Promise.all(triggerCache.map(emitTriggerCacheFlow));
29
+ const dsqStepResults = await Promise.all(dsqSteps.map(emitDsqStep));
29
30
  return [
30
31
  ...emitted.flatMap(result => result.artifacts),
31
32
  ...roots.flatMap(result => result.artifacts),
32
33
  ...stepResults.flatMap(result => result.artifacts),
33
- ...triggerCacheResults.flatMap(result => result.artifacts),
34
- { path: YAML_PATH, content: [...systemFunctions, ...emitted.flatMap(result => result.functions), ...roots.flatMap(result => result.functions), ...stepResults.map(result => result.function), ...triggerCacheResults.flatMap(result => result.functions)].join('\n') }
34
+ ...dsqStepResults.flatMap(result => result.artifacts),
35
+ { path: YAML_PATH, content: [...systemFunctions, ...emitted.flatMap(result => result.functions), ...roots.flatMap(result => result.functions), ...stepResults.flatMap(result => result.functions), ...dsqStepResults.flatMap(result => result.functions)].join('\n') }
35
36
  ];
36
37
  }
37
38
 
@@ -43,61 +44,23 @@ export function customFlowApplicationManagedPaths(flows, { includeYaml = false }
43
44
  const source = `app/src/generatedCode/FlowSchemas/${flowTag}/source`;
44
45
  return [`${source}/${flowTag}${stepName}_Main.js`, `${source}/${flowTag}${stepName}_HdrSqs.js`];
45
46
  }),
46
- ...triggerCacheFlows(flows).flatMap(triggerCachePaths),
47
- ...(supportedCustomFlows(flows).length > 0 || generatedOwnTopicFlows(flows).length > 0 || flowExtTopicSteps(flows).length > 0 || triggerCacheFlows(flows).length > 0 || includeYaml ? [YAML_PATH] : [])
47
+ ...flowDsqSteps(flows).flatMap(({ flowTag, stepName, step }) => {
48
+ const source = `app/src/generatedCode/FlowSchemas/${flowTag}/source`;
49
+ const stepEvents = Array.isArray(step.event) ? step.event : [];
50
+ return [
51
+ ...(stepEvents.includes('extTopic') ? [] : [`${source}/${flowTag}${stepName}_Main.js`]),
52
+ `${source}/${flowTag}${stepName}_HdrDsq.js`
53
+ ];
54
+ }),
55
+ ...(supportedCustomFlows(flows).length > 0 || generatedOwnTopicFlows(flows).length > 0 || flowExtTopicSteps(flows).length > 0 || flowDsqSteps(flows).length > 0 || includeYaml ? [YAML_PATH] : [])
48
56
  ];
49
57
  }
50
58
 
51
- async function emitTriggerCacheFlow(flow) {
52
- const tag = upperFirst(flow.flowTag);
53
- const source = `app/src/generatedCode/FlowSchemas/${tag}/source`;
54
- const handlerRoot = `src/generatedCode/FlowSchemas/${tag}/source`;
55
- const roleName = customFlowRoleName(flow.flowTag);
56
- const [processQueue, checkQueue, completeSqsQueue, completeDsqQueue] = triggerCacheQueueNames(flow);
57
- const process = `TriggerCache${tag}`;
58
- const check = `CheckTriggerCache${tag}Complete`;
59
- const complete = `TriggerCache${tag}Complete`;
60
- const handler = (functionName, handlerType) => `${handlerRoot}/${functionName}_${handlerType}.main`;
61
-
62
- return {
63
- artifacts: [
64
- { path: `${source}/${process}_Main.js`, content: await renderCustom('triggerCache/TriggerCache_Main.ejs', { functionName: process }) },
65
- { path: `${source}/${process}_HdrDsq.js`, content: await renderDsq('FlowHandler_HdrDsq.ejs', { functionName: process, mainFileName: `${process}_Main`, queueName: processQueue, startConfig: null }) },
66
- { path: `${source}/${check}_Main.js`, content: await renderCustom('triggerCache/CheckTriggerCache_Main.ejs', { functionName: check, flowTag: flow.flowTag }) },
67
- { path: `${source}/${check}_HdrSqs.js`, content: await renderCustom('triggerCache/CheckTriggerCache_HdrSqs.ejs', { functionName: check, queueName: checkQueue }) },
68
- { path: `${source}/${complete}_Main.js`, content: await renderCustom('triggerCache/TriggerCacheComplete_Main.ejs', { functionName: complete, flowTag: flow.flowTag }) },
69
- { path: `${source}/${complete}_HdrSqs.js`, content: await render('FlowHandler_HdrSqs.ejs', { functionName: complete, mainFileName: `${complete}_Main`, queueName: completeSqsQueue, startConfig: null, usePassBack: false }) },
70
- { path: `${source}/${complete}_HdrDsq.js`, content: await renderDsq('FlowHandler_HdrDsq.ejs', { functionName: complete, mainFileName: `${complete}_Main`, queueName: completeDsqQueue, startConfig: null, usePassBack: false }) }
71
- ],
72
- functions: [
73
- renderSqsFunctionYaml({ functionName: `${process}HdrDsq`, handlerPath: handler(process, 'HdrDsq'), roleName, queueName: processQueue }),
74
- renderSqsFunctionYaml({ functionName: `${check}HdrSqs`, handlerPath: handler(check, 'HdrSqs'), roleName, queueName: checkQueue }),
75
- renderSqsFunctionYaml({ functionName: `${complete}HdrSqs`, handlerPath: handler(complete, 'HdrSqs'), roleName, queueName: completeSqsQueue }),
76
- renderSqsFunctionYaml({ functionName: `${complete}HdrDsq`, handlerPath: handler(complete, 'HdrDsq'), roleName, queueName: completeDsqQueue })
77
- ]
78
- };
79
- }
80
59
 
81
- function triggerCachePaths(flow) {
82
- const tag = upperFirst(flow.flowTag);
83
- const source = `app/src/generatedCode/FlowSchemas/${tag}/source`;
84
- const process = `TriggerCache${tag}`;
85
- const check = `CheckTriggerCache${tag}Complete`;
86
- const complete = `TriggerCache${tag}Complete`;
87
- return [
88
- `${source}/${process}_Main.js`,
89
- `${source}/${process}_HdrDsq.js`,
90
- `${source}/${check}_Main.js`,
91
- `${source}/${check}_HdrSqs.js`,
92
- `${source}/${complete}_Main.js`,
93
- `${source}/${complete}_HdrSqs.js`,
94
- `${source}/${complete}_HdrDsq.js`
95
- ];
96
- }
97
60
 
98
61
  async function emitFlow(flow, objects) {
99
62
  const tag = upperFirst(flow.flowTag);
100
- const process = `Process${tag}`;
63
+ const process = tag;
101
64
  const source = `app/src/generatedCode/FlowSchemas/${tag}/source`;
102
65
  const handlerRoot = `src/generatedCode/FlowSchemas/${tag}/source`;
103
66
  const shared = { flowTag: flow.flowTag, flowStepName: '', mainFileName: `${process}_Main`, functionName: process, startConfig: startConfig(flow) };
@@ -106,21 +69,25 @@ async function emitFlow(flow, objects) {
106
69
  : [];
107
70
  const functions = [];
108
71
 
109
- if (flow.event.includes('extTopic')) {
72
+ if (flow.event.includes('extTopic') && !flow.event.includes('ownTopic')) {
110
73
  artifacts.push({ path: `${source}/${process}_HdrSqs.js`, content: await render('FlowHandler_HdrSqs.ejs', { ...shared, queueName: `${process}HdrSqs` }) });
111
- functions.push(renderSqsFunctionYaml({ functionName: `${process}HdrSqs`, handlerPath: `${handlerRoot}/${process}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName: `${process}HdrSqs` }));
74
+ functions.push(renderSqsFunctionYaml({ functionName: `${process}HdrSqs`, handlerPath: `${handlerRoot}/${process}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName: `${process}HdrSqs`, flowTag: flow.flowTag, flowStepName: '' }));
75
+ }
76
+ if (flow.event.includes('dsq')) {
77
+ artifacts.push({ path: `${source}/${process}_HdrDsq.js`, content: await renderDsq('FlowHandler_HdrDsq.ejs', { ...shared, queueName: `${process}HdrDsq` }) });
78
+ functions.push(renderSqsFunctionYaml({ functionName: `${process}HdrDsq`, handlerPath: `${handlerRoot}/${process}_HdrDsq.main`, roleName: customFlowRoleName(flow.flowTag), queueName: `${process}HdrDsq`, flowTag: flow.flowTag, flowStepName: '' }));
112
79
  }
113
80
  if (flow.event.includes('lambdaSyncInv')) {
114
81
  artifacts.push({ path: `${source}/${process}_HdrInv.js`, content: await render('FlowHandler_HdrInv.ejs', shared) });
115
- functions.push(renderInvFunctionYaml({ functionName: `${process}HdrInv`, handlerPath: `${handlerRoot}/${process}_HdrInv.main`, roleName: customFlowRoleName(flow.flowTag) }));
82
+ functions.push(renderInvFunctionYaml({ functionName: `${process}HdrInv`, handlerPath: `${handlerRoot}/${process}_HdrInv.main`, roleName: customFlowRoleName(flow.flowTag), flowTag: flow.flowTag, flowStepName: '' }));
116
83
  }
117
84
  if (flow.event.includes('lambdaSyncApi')) {
118
85
  artifacts.push({ path: `${source}/${process}_HdrApi.js`, content: await render('FlowHandler_HdrApi.ejs', shared) });
119
- functions.push(renderApiFunctionYaml({ functionName: `${process}HdrApi`, handlerPath: `${handlerRoot}/${process}_HdrApi.main`, roleName: customFlowRoleName(flow.flowTag) }));
86
+ functions.push(renderApiFunctionYaml({ functionName: `${process}HdrApi`, handlerPath: `${handlerRoot}/${process}_HdrApi.main`, roleName: customFlowRoleName(flow.flowTag), flowTag: flow.flowTag, flowStepName: '' }));
120
87
  }
121
88
  if (flow.event.includes('eventBridge')) {
122
89
  artifacts.push({ path: `${source}/${process}_HdrInv.js`, content: await render('FlowHandler_HdrInv.ejs', shared) });
123
- functions.push(renderEventBridgeFunctionYaml({ functionName: `${process}HdrInv`, handlerPath: `${handlerRoot}/${process}_HdrInv.main`, roleName: customFlowRoleName(flow.flowTag), flowTag: tag, schedules: flow.schedules ?? [] }));
90
+ functions.push(renderEventBridgeFunctionYaml({ functionName: `${process}HdrInv`, handlerPath: `${handlerRoot}/${process}_HdrInv.main`, roleName: customFlowRoleName(flow.flowTag), flowTag: flow.flowTag, flowStepName: '', schedules: flow.schedules ?? [] }));
124
91
  }
125
92
  if (flow.event.includes('ownTopic')) {
126
93
  const root = await emitOwnTopicRoot(flow, objects);
@@ -137,10 +104,11 @@ async function emitFlow(flow, objects) {
137
104
 
138
105
  function flowPaths(flow) {
139
106
  const tag = upperFirst(flow.flowTag);
140
- const process = `Process${tag}`;
107
+ const process = tag;
141
108
  const source = `app/src/generatedCode/FlowSchemas/${tag}/source`;
142
109
  const paths = needsProcessMain(flow) ? [`${source}/${process}_Main.js`] : [];
143
- if (flow.event.includes('extTopic')) paths.push(`${source}/${process}_HdrSqs.js`);
110
+ if (flow.event.includes('extTopic') && !flow.event.includes('ownTopic')) paths.push(`${source}/${process}_HdrSqs.js`);
111
+ if (flow.event.includes('dsq')) paths.push(`${source}/${process}_HdrDsq.js`);
144
112
  if (flow.event.includes('lambdaSyncInv') || flow.event.includes('eventBridge')) paths.push(`${source}/${process}_HdrInv.js`);
145
113
  if (flow.event.includes('lambdaSyncApi')) paths.push(`${source}/${process}_HdrApi.js`);
146
114
  if (flow.event.includes('ownTopic')) paths.push(...ownTopicRootPaths(flow));
@@ -154,19 +122,61 @@ function flowPaths(flow) {
154
122
  }
155
123
 
156
124
  async function emitExtTopicStep({ flow, step, flowTag, stepName }) {
125
+ const source = `app/src/generatedCode/FlowSchemas/${flowTag}/source`;
126
+ const handlerRoot = `src/generatedCode/FlowSchemas/${flowTag}/source`;
127
+ const functionName = stepName.startsWith(flowTag) ? stepName : `${flowTag}${stepName}`;
128
+ const mainFileName = `${functionName}_Main`;
129
+ const startConfig = stepConfig(flow, step);
130
+
131
+ const hasTriggerFlowTypes = Array.isArray(flow.triggerFlowTypes) && flow.triggerFlowTypes.length > 0;
132
+ const isCheckStep = stepName.toLowerCase().includes('checktrigger');
133
+
134
+ if (isCheckStep && hasTriggerFlowTypes) {
135
+ const queueName = `${functionName}HdrSqs`;
136
+ return {
137
+ artifacts: [
138
+ { path: `${source}/${mainFileName}.js`, content: await renderCustom('triggerCache/CheckTriggerCache_Main.ejs', { functionName, flowTag }) },
139
+ { path: `${source}/${functionName}_HdrSqs.js`, content: await renderCustom('triggerCache/CheckTriggerCache_HdrSqs.ejs', { functionName, queueName, startConfig }) }
140
+ ],
141
+ functions: [renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName, flowTag, flowStepName: step.stepName })]
142
+ };
143
+ }
144
+
145
+ const artifacts = [{ path: `${source}/${mainFileName}.js`, content: await renderStepMain(functionName) }];
146
+ const functions = [];
147
+
148
+ const stepEvents = Array.isArray(step.event) ? step.event : [];
149
+ const hasSqs = stepEvents.includes('extTopic') || stepEvents.includes('sqs');
150
+
151
+ if (hasSqs) {
152
+ const queueName = `${functionName}HdrSqs`;
153
+ artifacts.push({ path: `${source}/${functionName}_HdrSqs.js`, content: await render('FlowHandler_HdrSqs.ejs', { flowTag: flow.flowTag, flowStepName: step.stepName, functionName, mainFileName, startConfig, queueName }) });
154
+ functions.push(renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName, flowTag, flowStepName: step.stepName }));
155
+ }
156
+
157
+ return { artifacts, functions };
158
+ }
159
+
160
+ async function emitDsqStep({ flow, step, flowTag, stepName }) {
157
161
  const source = `app/src/generatedCode/FlowSchemas/${flowTag}/source`;
158
162
  const handlerRoot = `src/generatedCode/FlowSchemas/${flowTag}/source`;
159
163
  const functionName = `${flowTag}${stepName}`;
160
164
  const mainFileName = `${functionName}_Main`;
161
- const queueName = `${functionName}HdrSqs`;
162
165
  const startConfig = stepConfig(flow, step);
163
- return {
164
- artifacts: [
165
- { path: `${source}/${mainFileName}.js`, content: await renderStepMain(functionName) },
166
- { path: `${source}/${functionName}_HdrSqs.js`, content: await render('FlowHandler_HdrSqs.ejs', { flowTag: flow.flowTag, flowStepName: step.stepName, functionName, mainFileName, startConfig, queueName }) }
167
- ],
168
- function: renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName })
169
- };
166
+
167
+ const stepEvents = Array.isArray(step.event) ? step.event : [];
168
+ const artifacts = stepEvents.includes('extTopic') ? [] : [{ path: `${source}/${mainFileName}.js`, content: await renderStepMain(functionName) }];
169
+ const functions = [];
170
+
171
+ const hasDsq = stepEvents.includes('dsq');
172
+
173
+ if (hasDsq) {
174
+ const queueName = `${functionName}HdrDsq`;
175
+ artifacts.push({ path: `${source}/${functionName}_HdrDsq.js`, content: await renderDsq('FlowHandler_HdrDsq.ejs', { flowTag: flow.flowTag, flowStepName: step.stepName, functionName, mainFileName, startConfig, queueName }) });
176
+ functions.push(renderSqsFunctionYaml({ functionName: queueName, handlerPath: `${handlerRoot}/${functionName}_HdrDsq.main`, roleName: customFlowRoleName(flow.flowTag), queueName, flowTag, flowStepName: step.stepName }));
177
+ }
178
+
179
+ return { artifacts, functions };
170
180
  }
171
181
 
172
182
  async function emitOwnTopicRoot(flow, objects) {
@@ -184,8 +194,8 @@ async function emitOwnTopicRoot(flow, objects) {
184
194
  { path: `${source}/${tag}_HdrWbs.js`, content: await render('FlowEndpoint_HdrWbs.ejs', { ...shared, functionName: tag, mainFileName: wbsMainFileName, route: tag }) }
185
195
  ],
186
196
  functions: [
187
- renderWbsFunctionYaml({ functionName: `${tag}HdrWbs`, handlerPath: `${handlerRoot}/${tag}_HdrWbs.main`, roleName: customFlowRoleName(flow.flowTag), routeName: tag }),
188
- renderSqsFunctionYaml({ functionName: `${tag}HdrSqs`, handlerPath: `${handlerRoot}/${tag}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName: `${tag}HdrSqs` })
197
+ renderWbsFunctionYaml({ functionName: `${tag}HdrWbs`, handlerPath: `${handlerRoot}/${tag}_HdrWbs.main`, roleName: customFlowRoleName(flow.flowTag), routeName: tag, flowTag: flow.flowTag, flowStepName: '' }),
198
+ renderSqsFunctionYaml({ functionName: `${tag}HdrSqs`, handlerPath: `${handlerRoot}/${tag}_HdrSqs.main`, roleName: customFlowRoleName(flow.flowTag), queueName: `${tag}HdrSqs`, flowTag: flow.flowTag, flowStepName: '' })
189
199
  ]
190
200
  };
191
201
  }
@@ -197,7 +207,7 @@ function ownTopicRootPaths(flow) {
197
207
  }
198
208
 
199
209
  function needsProcessMain(flow) {
200
- return !isS3Only(flow) && flow.event.some(event => event !== 'ownTopic' && event !== 's3');
210
+ return !isS3Only(flow) && !flow.event.includes('ownTopic') && flow.event.some(event => event !== 'ownTopic' && event !== 's3');
201
211
  }
202
212
 
203
213
  async function emitS3Flow(flow, source, handlerRoot) {
@@ -207,7 +217,7 @@ async function emitS3Flow(flow, source, handlerRoot) {
207
217
  { action: 'CreateObject', handler: 'HdrWbs', type: 'wbs', mainTemplate: 'CreateObject_Main.ejs', handlerTemplate: 'CreateObject_HdrWbs.ejs' },
208
218
  { action: 'ReservedLimit', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'ReservedLimit_Main.ejs', handlerTemplate: 'ReservedLimit_HdrSqs.ejs' },
209
219
  { action: 'CreatePreSignUrl', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'CreatePreSignUrl_Main.ejs', handlerTemplate: 'CreatePreSignUrl_HdrSqs.ejs' },
210
- { 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' },
211
221
  { action: 'ConfirmAfterUpload', handler: 'HdrSqs', type: 'sqs', mainTemplate: 'ConfirmReserved_Main.ejs', handlerTemplate: 'ConfirmReserved_HdrSqs.ejs' }
212
222
  ];
213
223
  const emitted = await Promise.all(parts.map(async ({ action, handler, type, mainTemplate, handlerTemplate }) => {
@@ -218,10 +228,12 @@ async function emitS3Flow(flow, source, handlerRoot) {
218
228
  const handlerContent = await renderCustom(`s3/${handlerTemplate}`, s3HandlerData({ action, flow, functionName, mainFileName, handler }));
219
229
  const descriptor = { functionName: `${functionName}${handler}`, handlerPath: `${handlerRoot}/${handlerFileName}.main`, roleName };
220
230
  const functionYaml = type === 'wbs'
221
- ? renderWbsFunctionYaml({ ...descriptor, routeName: tag })
231
+ ? renderWbsFunctionYaml({ ...descriptor, routeName: tag, flowTag: flow.flowTag, flowStepName: '' })
222
232
  : type === 'sqs'
223
- ? renderSqsFunctionYaml({ ...descriptor, queueName: handlerFileName })
224
- : renderInvFunctionYaml(descriptor);
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: '' });
225
237
  return {
226
238
  artifacts: [
227
239
  { path: `${source}/${mainFileName}.js`, content: mainContent },
@@ -248,7 +260,7 @@ function s3HandlerData({ action, flow, functionName, mainFileName, handler }) {
248
260
  }
249
261
 
250
262
  function startConfig(flow) {
251
- const start = flow.flowSteps?.find(step => step.stepName?.toLowerCase() === 'start');
263
+ const start = flow.flowSteps?.[0];
252
264
  return start ? stepConfig(flow, start) : null;
253
265
  }
254
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
  *
@@ -56,43 +55,49 @@ const { createFlowTypeConcat } = utils;
56
55
  * @returns {object} description of return value
57
56
  */
58
57
 
59
- export default async function <%- typeof functionName !== 'undefined' ? functionName : `Process${upperCaseFlowTag}` %>(
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 : `Process${upperCaseFlowTag}` %> _izContext", _izContext)
69
- _izContext.logger.debug("<%- typeof functionName !== 'undefined' ? functionName : `Process${upperCaseFlowTag}` %> requestParams", requestParams)
70
- _izContext.logger.debug("<%- typeof functionName !== 'undefined' ? functionName : `Process${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
  }