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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +104 -0
  4. package/src/compile/compileProject.js +40 -9
  5. package/src/compile/loadSchemas.js +120 -11
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
  8. package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
  9. package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  16. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  17. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  18. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  19. package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
  20. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  21. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
  22. package/src/emit/custom/customFlows.js +68 -28
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
  24. package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
  25. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  26. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  27. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  28. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  29. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  30. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  32. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  33. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
  34. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  35. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
  36. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  38. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  39. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  40. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  41. package/src/emit/function/functionYamlArtifact.js +272 -79
  42. package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
  43. package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
  44. package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
  45. package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
  46. package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
  47. package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
  48. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
  49. package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
  50. package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
  51. package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
  52. package/src/emit/rbac/rbacFlowTag.js +3 -1
  53. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  54. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  55. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  56. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  57. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  58. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  59. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  60. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  61. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  62. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
  63. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
  64. package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
  65. package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
  66. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  67. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  68. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  69. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  70. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  71. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  72. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  73. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  74. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  75. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  76. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  77. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  78. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  79. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  80. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  81. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  82. package/src/emit/resource/emitResourceArtifacts.js +274 -105
  83. package/src/emit/resource/generateResourceArtifacts.js +15 -6
  84. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
  85. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  86. package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
  87. package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
  88. package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
  89. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
  90. package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
  91. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
  92. package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
  93. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
  94. package/src/generate.js +141 -34
  95. package/src/generateIntTest.js +76 -28
  96. package/src/generateResourceIntTest.js +35 -12
  97. package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
  98. package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
  99. package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
  100. package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
  101. package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
  102. package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
  103. package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
  104. package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
  105. package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
  106. package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
  107. package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
  108. package/src/intTestGeneratorShared.js +15 -10
  109. package/src/output/commitArtifacts.js +99 -39
  110. package/src/output/mergeHooks.js +24 -10
  111. package/src/output/validateArtifacts.js +37 -27
  112. package/src/plan/buildGenerationPlan.js +24 -13
  113. package/test/core.test.js +116 -49
  114. package/test/createTargetRoleHandler.test.js +63 -14
  115. package/test/crudApplicationArtifacts.test.js +128 -23
  116. package/test/customFlowApplicationArtifacts.test.js +391 -84
  117. package/test/dynamicCrudFlowSchemas.test.js +74 -26
  118. package/test/dynamicRbacFlowSchemas.test.js +63 -20
  119. package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
  120. package/test/functionYamlArtifact.test.js +67 -10
  121. package/test/intTestApi.test.js +9 -10
  122. package/test/publicApi.test.js +184 -44
  123. package/test/relationshipApplicationArtifacts.test.js +90 -19
  124. package/test/resourceArtifacts.test.js +183 -33
  125. package/docs/test.png +0 -0
  126. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  127. package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
  128. /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
@@ -7,24 +7,31 @@ export default async function <%- functionName %>(
7
7
  ) {
8
8
  try {
9
9
  _izContext.logger.debug('<%- functionName %> requestParams', requestParams);
10
- _izContext.logger.debug('<%- functionName %> callingFlowConfig', callingFlowConfig);
10
+ _izContext.logger.debug(
11
+ '<%- functionName %> callingFlowConfig',
12
+ callingFlowConfig
13
+ );
11
14
 
12
15
  //(<beforeCheckTriggeredCache>)
13
16
  //(</beforeCheckTriggeredCache>)
14
17
 
15
- const checkTriggerResetedV2 = await triggeredCacheSharedLibV2.checkTriggerResetedV2(
16
- _izContext,
17
- { serviceTag: process.env.iz_serviceTag, flowTag: '<%- flowTag %>' },
18
- //(<identifiers>)
19
- {},
20
- //(</identifiers>)
21
- //(<uniqueRequestId>)
22
- //(</uniqueRequestId>)
23
- //(<settings>)
24
- //(</settings>)
25
- );
18
+ const checkTriggerResetedV2 =
19
+ await triggeredCacheSharedLibV2.checkTriggerResetedV2(
20
+ _izContext,
21
+ { serviceTag: process.env.iz_serviceTag, flowTag: '<%- flowTag %>' },
22
+ //(<identifiers>)
23
+ {}
24
+ //(</identifiers>)
25
+ //(<uniqueRequestId>)
26
+ //(</uniqueRequestId>)
27
+ //(<settings>)
28
+ //(</settings>)
29
+ );
26
30
 
27
- _izContext.logger.debug('<%- functionName %> checkTriggerResetedV2', checkTriggerResetedV2);
31
+ _izContext.logger.debug(
32
+ '<%- functionName %> checkTriggerResetedV2',
33
+ checkTriggerResetedV2
34
+ );
28
35
 
29
36
  //(<endpointHook>)
30
37
  //(</endpointHook>)
@@ -5,7 +5,10 @@ export default async function <%- functionName %>(
5
5
  ) {
6
6
  try {
7
7
  _izContext.logger.debug('<%- functionName %> requestParams', requestParams);
8
- _izContext.logger.debug('<%- functionName %> callingFlowConfig', callingFlowConfig);
8
+ _izContext.logger.debug(
9
+ '<%- functionName %> callingFlowConfig',
10
+ callingFlowConfig
11
+ );
9
12
 
10
13
  //(<endpointHook>)
11
14
  //(</endpointHook>)
@@ -1,115 +1,308 @@
1
- export function createSqsFunctionYamlArtifact({ functionName, handlerPath, roleName, queueName, fileName, flowTag, flowStepName, targetCompleteStepName }) {
2
- if (![functionName, handlerPath, roleName, queueName, fileName].every(value => typeof value === 'string' && value !== '')) {
3
- throw new TypeError('Function descriptor must include functionName, handlerPath, roleName, queueName, and fileName');
1
+ import { readFileSync } from 'node:fs';
2
+ import ejsLib from 'ejs';
3
+
4
+ const TEMPLATE_URL = new URL('./templates/', import.meta.url);
5
+
6
+ function _renderFunctionTemplate(templateName, data = {}) {
7
+ const content = readFileSync(new URL(templateName, TEMPLATE_URL), 'utf8');
8
+ return ejsLib.render(content, data);
9
+ }
10
+
11
+ export function createSqsFunctionYamlArtifact({
12
+ functionName,
13
+ handlerPath,
14
+ roleName,
15
+ queueName,
16
+ fileName,
17
+ flowTag,
18
+ flowStepName,
19
+ targetCompleteStepName
20
+ }) {
21
+ if (
22
+ ![functionName, handlerPath, roleName, queueName, fileName].every(
23
+ (value) => typeof value === 'string' && value !== ''
24
+ )
25
+ ) {
26
+ throw new TypeError(
27
+ 'Function descriptor must include functionName, handlerPath, roleName, queueName, and fileName'
28
+ );
4
29
  }
5
30
  return {
6
31
  path: `app/sls_yaml/generatedCode/source/${fileName}`,
7
- content: renderSqsFunctionYaml({ functionName, handlerPath, roleName, queueName, flowTag, flowStepName })
32
+ content: renderSqsFunctionYaml({
33
+ functionName,
34
+ handlerPath,
35
+ roleName,
36
+ queueName,
37
+ flowTag,
38
+ flowStepName,
39
+ targetCompleteStepName
40
+ })
8
41
  };
9
42
  }
10
43
 
11
- export function renderSqsFunctionYaml({ functionName, handlerPath, roleName, queueName, flowTag, flowStepName, targetCompleteStepName }) {
12
- if (![functionName, handlerPath, roleName, queueName].every(value => typeof value === 'string' && value !== '')) {
13
- throw new TypeError('SQS function descriptor must include functionName, handlerPath, roleName, and queueName');
44
+ export function renderSqsFunctionYaml({
45
+ functionName,
46
+ handlerPath,
47
+ roleName,
48
+ queueName,
49
+ flowTag,
50
+ flowStepName,
51
+ targetCompleteStepName
52
+ }) {
53
+ if (
54
+ ![functionName, handlerPath, roleName, queueName].every(
55
+ (value) => typeof value === 'string' && value !== ''
56
+ )
57
+ ) {
58
+ throw new TypeError(
59
+ 'SQS function descriptor must include functionName, handlerPath, roleName, and queueName'
60
+ );
14
61
  }
15
- return `${functionName}:
16
- handler: ${handlerPath}
17
- name: \${self:custom.iz_resourcePrefix}${functionName}
18
- role: ${roleName}
19
- ${environmentSetting(functionName, flowTag, flowStepName, targetCompleteStepName)}${functionSetting(functionName)}
20
- events:
21
- - sqs:
22
- arn: arn:aws:sqs:\${self:custom.iz_region}:\${self:custom.iz_accountId}:\${self:custom.iz_resourcePrefix}${queueName}
23
- batchSize: 10
24
- ${completionFilter(functionName)}`;
62
+ return _renderFunctionTemplate('SqsFunction_Yaml.ejs', {
63
+ functionName,
64
+ handlerPath,
65
+ roleName,
66
+ queueName,
67
+ environmentSetting: _environmentSetting(
68
+ functionName,
69
+ flowTag,
70
+ flowStepName,
71
+ targetCompleteStepName
72
+ ),
73
+ functionSetting: _functionSetting(functionName),
74
+ sqsFilterPatterns: _sqsFilterPatterns(functionName)
75
+ });
25
76
  }
26
77
 
27
- export function renderApiFunctionYaml({ functionName, handlerPath, roleName, routes = [], flowTag, flowStepName }) {
78
+ export function renderApiFunctionYaml({
79
+ functionName,
80
+ handlerPath,
81
+ roleName,
82
+ routes = [],
83
+ flowTag,
84
+ flowStepName
85
+ }) {
28
86
  if (!Array.isArray(routes)) {
29
87
  throw new TypeError('API function routes must be an array');
30
88
  }
31
- const routeEvents = routes.flatMap(({ path, upperName }) => {
32
- if (typeof path !== 'string' || path === '' || typeof upperName !== 'string' || upperName === '') {
33
- throw new TypeError('API function routes must include path and upperName');
34
- }
35
- return [
36
- ` - httpApi:\n path: ${path}\n method: post\n #<#${upperName}AppLevelAuthorizer#>\n # authorizer: authorizerServiceSchema\n #<#/${upperName}AppLevelAuthorizer#>`,
37
- ` - httpApi:\n path: ${path}/{targetUserId}\n method: post\n #<#${upperName}UserLevelAuthorizer#>\n # authorizer: authorizerIdentifiers\n #<#/${upperName}UserLevelAuthorizer#>`
38
- ];
39
- }).join('\n');
40
- return `${functionName}:
41
- handler: ${handlerPath}
42
- name: \${self:custom.iz_resourcePrefix}${functionName}
43
- role: ${roleName}
44
- ${environmentSetting(functionName, flowTag, flowStepName)}${functionSetting(functionName)}
45
- events:
46
- ${routeEvents ? `${routeEvents}\n` : ''}`;
89
+ const routeEvents = routes
90
+ .flatMap(({ path, upperName }) => {
91
+ if (
92
+ typeof path !== 'string' ||
93
+ path === '' ||
94
+ typeof upperName !== 'string' ||
95
+ upperName === ''
96
+ ) {
97
+ throw new TypeError(
98
+ 'API function routes must include path and upperName'
99
+ );
100
+ }
101
+ return [
102
+ ` - httpApi:\n path: ${path}\n method: post\n #<#${upperName}AppLevelAuthorizer#>\n # authorizer: authorizerServiceSchema\n #<#/${upperName}AppLevelAuthorizer#>`,
103
+ ` - httpApi:\n path: ${path}/{targetUserId}\n method: post\n #<#${upperName}UserLevelAuthorizer#>\n # authorizer: authorizerIdentifiers\n #<#/${upperName}UserLevelAuthorizer#>`
104
+ ];
105
+ })
106
+ .join('\n');
107
+ let eventsSection = '';
108
+ if (routeEvents) {
109
+ eventsSection = `${routeEvents}\n`;
110
+ }
111
+ return _renderFunctionTemplate('ApiFunction_Yaml.ejs', {
112
+ functionName,
113
+ handlerPath,
114
+ roleName,
115
+ environmentSetting: _environmentSetting(
116
+ functionName,
117
+ flowTag,
118
+ flowStepName
119
+ ),
120
+ functionSetting: _functionSetting(functionName),
121
+ eventsSection
122
+ });
47
123
  }
48
124
 
49
- export function renderWbsFunctionYaml({ functionName, handlerPath, roleName, routeName, flowTag, flowStepName }) {
50
- if (![functionName, handlerPath, roleName, routeName].every(value => typeof value === 'string' && value !== '')) {
51
- throw new TypeError('WebSocket function descriptor must include functionName, handlerPath, roleName, and routeName');
125
+ export function renderWbsFunctionYaml({
126
+ functionName,
127
+ handlerPath,
128
+ roleName,
129
+ routeName,
130
+ flowTag,
131
+ flowStepName
132
+ }) {
133
+ if (
134
+ ![functionName, handlerPath, roleName, routeName].every(
135
+ (value) => typeof value === 'string' && value !== ''
136
+ )
137
+ ) {
138
+ throw new TypeError(
139
+ 'WebSocket function descriptor must include functionName, handlerPath, roleName, and routeName'
140
+ );
52
141
  }
53
- return `${functionName}:
54
- handler: ${handlerPath}
55
- name: \${self:custom.iz_resourcePrefix}${functionName}
56
- role: ${roleName}
57
- ${environmentSetting(functionName, flowTag, flowStepName)}${functionSetting(functionName)}
58
- events:
59
- - websocket:
60
- route: ${routeName}
61
- # authorizer: \${self:custom.iz_authorizerAppLevel}
62
- # identifierResource: 'route.request.header.Auth'
63
- `;
142
+ return _renderFunctionTemplate('WbsFunction_Yaml.ejs', {
143
+ functionName,
144
+ handlerPath,
145
+ roleName,
146
+ routeName,
147
+ environmentSetting: _environmentSetting(
148
+ functionName,
149
+ flowTag,
150
+ flowStepName
151
+ ),
152
+ functionSetting: _functionSetting(functionName)
153
+ });
64
154
  }
65
155
 
66
- export function renderInvFunctionYaml({ functionName, handlerPath, roleName, flowTag, flowStepName }) {
67
- return `${functionName}:
68
- handler: ${handlerPath}
69
- name: \${self:custom.iz_resourcePrefix}${functionName}
70
- role: ${roleName}
71
- ${environmentSetting(functionName, flowTag, flowStepName)}${functionSetting(functionName)}
72
- `;
156
+ export function renderInvFunctionYaml({
157
+ functionName,
158
+ handlerPath,
159
+ roleName,
160
+ flowTag,
161
+ flowStepName
162
+ }) {
163
+ return _renderFunctionTemplate('InvFunction_Yaml.ejs', {
164
+ functionName,
165
+ handlerPath,
166
+ roleName,
167
+ environmentSetting: _environmentSetting(
168
+ functionName,
169
+ flowTag,
170
+ flowStepName
171
+ ),
172
+ functionSetting: _functionSetting(functionName)
173
+ });
174
+ }
175
+
176
+ export function renderS3FunctionYaml({
177
+ functionName,
178
+ handlerPath,
179
+ roleName,
180
+ bucketName,
181
+ flowTag,
182
+ flowStepName
183
+ }) {
184
+ return _renderFunctionTemplate('S3Function_Yaml.ejs', {
185
+ functionName,
186
+ handlerPath,
187
+ roleName,
188
+ bucketName,
189
+ environmentSetting: _environmentSetting(
190
+ functionName,
191
+ flowTag,
192
+ flowStepName
193
+ ),
194
+ functionSetting: _functionSetting(functionName)
195
+ });
73
196
  }
74
197
 
75
- export function renderEventBridgeFunctionYaml({ functionName, handlerPath, roleName, flowTag, flowStepName, schedules = [] }) {
76
- if (![functionName, handlerPath, roleName, flowTag].every(value => typeof value === 'string' && value !== '') || !Array.isArray(schedules)) {
77
- throw new TypeError('EventBridge function descriptor must include functionName, handlerPath, roleName, flowTag, and schedules');
198
+ export function renderEventBridgeFunctionYaml({
199
+ functionName,
200
+ handlerPath,
201
+ roleName,
202
+ flowTag,
203
+ flowStepName,
204
+ schedules = []
205
+ }) {
206
+ if (
207
+ ![functionName, handlerPath, roleName, flowTag].every(
208
+ (value) => typeof value === 'string' && value !== ''
209
+ ) ||
210
+ !Array.isArray(schedules)
211
+ ) {
212
+ throw new TypeError(
213
+ 'EventBridge function descriptor must include functionName, handlerPath, roleName, flowTag, and schedules'
214
+ );
78
215
  }
79
- if (!schedules.every(schedule => (
80
- typeof schedule?.name === 'string' && schedule.name !== '' &&
81
- Array.isArray(schedule.rate) && typeof schedule.rate[0] === 'string' && schedule.rate[0] !== ''
82
- ))) {
83
- throw new TypeError('Each EventBridge schedule must include a name and first rate value');
216
+ if (
217
+ !schedules.every(
218
+ (schedule) =>
219
+ typeof schedule?.name === 'string' &&
220
+ schedule.name !== '' &&
221
+ Array.isArray(schedule.rate) &&
222
+ typeof schedule.rate[0] === 'string' &&
223
+ schedule.rate[0] !== ''
224
+ )
225
+ ) {
226
+ throw new TypeError(
227
+ 'Each EventBridge schedule must include a name and first rate value'
228
+ );
84
229
  }
85
- return `\${self:custom.iz_resourcePrefix}${functionName}:
86
- handler: ${handlerPath}
87
- role: ${roleName}
88
- ${environmentSetting(functionName, flowTag, flowStepName)}${functionSetting(functionName)}
89
- description: ${flowTag} (EventBridge Schedule)
90
- ${schedules.length === 0 ? '' : ` events:\n${schedules.map(schedule => ` - schedule:\n name: \${self:custom.iz_resourcePrefix}${schedule.name}\n description: '${schedule.description ?? ''}'\n rate: ${schedule.rate?.[0]}\n enabled: true`).join('\n')}\n`}`;
230
+ let scheduleEventsSection = '';
231
+ if (schedules.length > 0) {
232
+ const renderedSchedules = schedules
233
+ .map((schedule) => {
234
+ let desc = '';
235
+ if (schedule.description) {
236
+ desc = schedule.description;
237
+ }
238
+ return ` - schedule:\n name: \${self:custom.iz_resourcePrefix}${schedule.name}\n description: '${desc}'\n rate: ${schedule.rate[0]}\n enabled: true`;
239
+ })
240
+ .join('\n');
241
+ scheduleEventsSection = ` events:\n${renderedSchedules}\n`;
242
+ }
243
+ return _renderFunctionTemplate('EventBridgeFunction_Yaml.ejs', {
244
+ functionName,
245
+ handlerPath,
246
+ roleName,
247
+ flowTag,
248
+ environmentSetting: _environmentSetting(
249
+ functionName,
250
+ flowTag,
251
+ flowStepName
252
+ ),
253
+ functionSetting: _functionSetting(functionName),
254
+ scheduleEventsSection
255
+ });
91
256
  }
92
257
 
93
- function environmentSetting(functionName, flowTag, flowStepName, targetCompleteStepName) {
94
- if (flowTag === undefined && flowStepName === undefined && targetCompleteStepName === undefined) return '';
258
+ function _environmentSetting(
259
+ functionName,
260
+ flowTag,
261
+ flowStepName,
262
+ targetCompleteStepName
263
+ ) {
264
+ if (
265
+ flowTag === undefined &&
266
+ flowStepName === undefined &&
267
+ targetCompleteStepName === undefined
268
+ ) {
269
+ return '';
270
+ }
95
271
  let envs = [];
96
- if (flowTag !== undefined) envs.push(` iz_flowTag: ${flowTag === '' ? "''" : flowTag}`);
97
- if (flowStepName !== undefined) envs.push(` iz_flowStepName: ${flowStepName === '' ? "''" : flowStepName}`);
98
- if (targetCompleteStepName !== undefined) envs.push(` iz_targetCompleteStepName: ${flowTag}${targetCompleteStepName}`);
99
-
100
- if (envs.length === 0) return '';
272
+ if (flowTag !== undefined) {
273
+ let flowTagVal = "''";
274
+ if (flowTag !== '') {
275
+ flowTagVal = flowTag;
276
+ }
277
+ envs.push(` iz_flowTag: ${flowTagVal}`);
278
+ }
279
+ if (flowStepName !== undefined) {
280
+ let flowStepNameVal = "''";
281
+ if (flowStepName !== '') {
282
+ flowStepNameVal = flowStepName;
283
+ }
284
+ envs.push(` iz_flowStepName: ${flowStepNameVal}`);
285
+ }
286
+ if (targetCompleteStepName !== undefined) {
287
+ envs.push(
288
+ ` iz_targetCompleteStepName: ${flowTag}${targetCompleteStepName}`
289
+ );
290
+ }
291
+
292
+ if (envs.length === 0) {
293
+ return '';
294
+ }
101
295
  return ` environment:
102
296
  ${envs.join('\n')}
103
297
  #<#${functionName}Environment#>
104
298
  #<#/${functionName}Environment#>\n`;
105
299
  }
106
300
 
107
- function functionSetting(functionName) {
301
+ function _functionSetting(functionName) {
108
302
  return ` #<#${functionName}FunctionSetting#>\n #<#/${functionName}FunctionSetting#>`;
109
303
  }
110
304
 
111
- function completionFilter(functionName) {
112
- if (!functionName.endsWith('CompleteHdrSqs')) return '';
305
+ function _sqsFilterPatterns(functionName) {
113
306
  return ` filterPatterns:
114
307
  - body:
115
308
  MessageAttributes:
@@ -0,0 +1,7 @@
1
+ <%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%= functionName %>
4
+ role: <%= roleName %>
5
+ <%- environmentSetting %><%- functionSetting %>
6
+ events:
7
+ <%- eventsSection %>
@@ -0,0 +1,6 @@
1
+ ${self:custom.iz_resourcePrefix}<%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ role: <%= roleName %>
4
+ <%- environmentSetting %><%- functionSetting %>
5
+ description: <%= flowTag %> (EventBridge Schedule)
6
+ <%- scheduleEventsSection %>
@@ -0,0 +1,5 @@
1
+ <%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%= functionName %>
4
+ role: <%= roleName %>
5
+ <%- environmentSetting %><%- functionSetting %>
@@ -0,0 +1,16 @@
1
+ <%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%= functionName %>
4
+ role: <%= roleName %>
5
+ <%- environmentSetting %><%- functionSetting %>
6
+ events:
7
+ - s3:
8
+ bucket: <%= bucketName %>
9
+ event: s3:ObjectCreated:*
10
+ existing: true
11
+ rules:
12
+ #<#<%= functionName %>rules#>
13
+ #<#/<%= functionName %>rules#>
14
+ - prefix: uploads/
15
+ - suffix: .csv
16
+ forceDeploy: true
@@ -0,0 +1,10 @@
1
+ <%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%= functionName %>
4
+ role: <%= roleName %>
5
+ <%- environmentSetting %><%- functionSetting %>
6
+ events:
7
+ - sqs:
8
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%= queueName %>
9
+ batchSize: 10
10
+ <%- sqsFilterPatterns %>
@@ -0,0 +1,10 @@
1
+ <%= functionName %>:
2
+ handler: <%= handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%= functionName %>
4
+ role: <%= roleName %>
5
+ <%- environmentSetting %><%- functionSetting %>
6
+ events:
7
+ - websocket:
8
+ route: <%= routeName %>
9
+ # authorizer: \${self:custom.iz_authorizerAppLevel}
10
+ # identifierResource: 'route.request.header.Auth'
@@ -1,4 +1,4 @@
1
- import ejs from 'ejs';
1
+ import ejsLib from 'ejs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { rbacFlowTag } from './rbacFlowTag.js';
4
4
 
@@ -16,17 +16,20 @@ const RBAC_FLOW_DEFINITIONS = [
16
16
  const TEMPLATE_URL = new URL('./templates/', import.meta.url);
17
17
 
18
18
  export const dynamicRbacFlowSchemaPaths = RBAC_FLOW_DEFINITIONS.map(
19
- ({ flowTag }) => `app/src/schemas/FlowSchemas/generateCode/${flowTag}.js`
19
+ ({ flowTag }) =>
20
+ `app/src/schemas/FlowSchemas/generateCode/FlowRbac/${flowTag}.js`
20
21
  );
21
22
 
22
23
  export function rbacFlowSchemaManagedPaths(objects = []) {
23
24
  if (!Array.isArray(objects)) {
24
25
  throw new TypeError('objects must be an array');
25
26
  }
26
- return [
27
- ...dynamicRbacFlowSchemaPaths,
28
- ...objects.filter(hasRbacAddOn).map(object => `app/src/schemas/FlowSchemas/generateCode/${rbacFlowTag(object)}.js`)
29
- ];
27
+ const rbacObjects = objects.filter(_hasRbacAddOn);
28
+ const rbacPaths = rbacObjects.map(
29
+ (object) =>
30
+ `app/src/schemas/FlowSchemas/generateCode/FlowRbac/${rbacFlowTag(object)}.js`
31
+ );
32
+ return [...dynamicRbacFlowSchemaPaths, ...rbacPaths];
30
33
  }
31
34
 
32
35
  export async function emitDynamicRbacFlowSchemas({ objects, serviceTag }) {
@@ -34,45 +37,53 @@ export async function emitDynamicRbacFlowSchemas({ objects, serviceTag }) {
34
37
  throw new TypeError('objects must be an array');
35
38
  }
36
39
 
37
- const rbacObjects = objects.filter(hasRbacAddOn);
40
+ const rbacObjects = objects.filter(_hasRbacAddOn);
38
41
  if (rbacObjects.length === 0) {
39
42
  return [];
40
43
  }
41
44
  if (typeof serviceTag !== 'string' || serviceTag.trim() === '') {
42
- throw new TypeError('GenerationRequest.serviceTag is required when generating RBAC schemas');
45
+ throw new TypeError(
46
+ 'GenerationRequest.serviceTag is required when generating RBAC schemas'
47
+ );
43
48
  }
44
49
 
45
- return Promise.all([
46
- ...RBAC_FLOW_DEFINITIONS.map(({ flowTag, event }) => artifact(
50
+ const sharedArtifacts = RBAC_FLOW_DEFINITIONS.map(({ flowTag, event }) =>
51
+ _artifact(flowTag, _createSharedRbacFlow(flowTag, event))
52
+ );
53
+ const userArtifacts = rbacObjects.map((object) => {
54
+ const flowTag = rbacFlowTag(object);
55
+ return _artifact(
47
56
  flowTag,
48
- createSharedRbacFlow(flowTag, event)
49
- )),
50
- ...rbacObjects.map(object => {
51
- const flowTag = rbacFlowTag(object);
52
- return artifact(flowTag, createUserRbacFlow(flowTag, serviceTag, object.objectType));
53
- })
54
- ]);
57
+ _createUserRbacFlow(flowTag, serviceTag, object.objectType)
58
+ );
59
+ });
60
+
61
+ return Promise.all([...sharedArtifacts, ...userArtifacts]);
55
62
  }
56
63
 
57
- function hasRbacAddOn(object) {
58
- return Array.isArray(object?.addOnDataStructure)
59
- && object.addOnDataStructure.some(addOn => addOn?.type === 'rbac');
64
+ function _hasRbacAddOn(object) {
65
+ return (
66
+ Array.isArray(object?.addOnDataStructure) &&
67
+ object.addOnDataStructure.some((addOn) => addOn?.type === 'rbac')
68
+ );
60
69
  }
61
70
 
62
- async function artifact(flowTag, flow) {
71
+ async function _artifact(flowTag, flow) {
63
72
  return {
64
- path: `app/src/schemas/FlowSchemas/generateCode/${flowTag}.js`,
65
- content: ejs.render(
66
- await readFile(new URL('DynamicRbacFlowSchema.ejs', TEMPLATE_URL), 'utf8'),
73
+ path: `app/src/schemas/FlowSchemas/generateCode/FlowRbac/${flowTag}.js`,
74
+ content: ejsLib.render(
75
+ await readFile(
76
+ new URL('DynamicRbacFlowSchema.ejs', TEMPLATE_URL),
77
+ 'utf8'
78
+ ),
67
79
  { flowTag, flow }
68
80
  )
69
81
  };
70
82
  }
71
83
 
72
- function createSharedRbacFlow(flowTag, event) {
84
+ function _createSharedRbacFlow(flowTag, event) {
73
85
  return {
74
86
  flowTag,
75
- fileName: 'flow-rbac',
76
87
  initiateBy: 'system',
77
88
  statusType: 'none',
78
89
  event,
@@ -94,15 +105,15 @@ function createSharedRbacFlow(flowTag, event) {
94
105
  };
95
106
  }
96
107
 
97
- function createUserRbacFlow(flowTag, serviceTag, objectType) {
108
+ function _createUserRbacFlow(flowTag, serviceTag, objectType) {
98
109
  return {
99
110
  flowTag,
100
- fileName: 'flow-rbac',
101
111
  objType: { serviceTag, objectType },
102
- event: ['lambdaSyncInv'],
112
+ event: ['ownTopic'],
103
113
  initiateBy: 'system',
104
114
  handleObj: 'one',
105
115
  statusType: 'none',
116
+ outputTopic: true,
106
117
  stepMessageAttributes: {
107
118
  userId: { propertyName: 'x-correlation-base-user-id', type: 'string' },
108
119
  correlationId: { propertyName: 'x-correlation-id', type: 'string' }