@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.
- package/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /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(
|
|
10
|
+
_izContext.logger.debug(
|
|
11
|
+
'<%- functionName %> callingFlowConfig',
|
|
12
|
+
callingFlowConfig
|
|
13
|
+
);
|
|
11
14
|
|
|
12
15
|
//(<beforeCheckTriggeredCache>)
|
|
13
16
|
//(</beforeCheckTriggeredCache>)
|
|
14
17
|
|
|
15
|
-
const checkTriggerResetedV2 =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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(
|
|
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(
|
|
8
|
+
_izContext.logger.debug(
|
|
9
|
+
'<%- functionName %> callingFlowConfig',
|
|
10
|
+
callingFlowConfig
|
|
11
|
+
);
|
|
9
12
|
|
|
10
13
|
//(<endpointHook>)
|
|
11
14
|
//(</endpointHook>)
|
|
@@ -1,115 +1,308 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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({
|
|
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({
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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({
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
${
|
|
45
|
-
|
|
46
|
-
|
|
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({
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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({
|
|
76
|
-
|
|
77
|
-
|
|
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 (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
94
|
-
|
|
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)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
301
|
+
function _functionSetting(functionName) {
|
|
108
302
|
return ` #<#${functionName}FunctionSetting#>\n #<#/${functionName}FunctionSetting#>`;
|
|
109
303
|
}
|
|
110
304
|
|
|
111
|
-
function
|
|
112
|
-
if (!functionName.endsWith('CompleteHdrSqs')) return '';
|
|
305
|
+
function _sqsFilterPatterns(functionName) {
|
|
113
306
|
return ` filterPatterns:
|
|
114
307
|
- body:
|
|
115
308
|
MessageAttributes:
|
|
@@ -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
|
|
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 }) =>
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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(
|
|
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(
|
|
45
|
+
throw new TypeError(
|
|
46
|
+
'GenerationRequest.serviceTag is required when generating RBAC schemas'
|
|
47
|
+
);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
]);
|
|
57
|
+
_createUserRbacFlow(flowTag, serviceTag, object.objectType)
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return Promise.all([...sharedArtifacts, ...userArtifacts]);
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
function
|
|
58
|
-
return
|
|
59
|
-
|
|
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
|
|
71
|
+
async function _artifact(flowTag, flow) {
|
|
63
72
|
return {
|
|
64
|
-
path: `app/src/schemas/FlowSchemas/generateCode/${flowTag}.js`,
|
|
65
|
-
content:
|
|
66
|
-
await readFile(
|
|
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
|
|
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
|
|
108
|
+
function _createUserRbacFlow(flowTag, serviceTag, objectType) {
|
|
98
109
|
return {
|
|
99
110
|
flowTag,
|
|
100
|
-
fileName: 'flow-rbac',
|
|
101
111
|
objType: { serviceTag, objectType },
|
|
102
|
-
event: ['
|
|
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' }
|