@izara_project/izara-core-generate-service-code 1.0.54 → 1.0.56
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/package.json +1 -1
- package/src/codeGenerators/app/initial_setup/InitialSetupGenerator.js +223 -123
- package/src/codeGenerators/app/initial_setup/templates/InitialSetup_LambdaRole.ejs +6 -6
- package/src/codeGenerators/app/sls_yaml/FindDataYamlGenerator.js +1 -1
- package/src/codeGenerators/app/sls_yaml/FunctionYamlGenerator.js +303 -201
- package/src/codeGenerators/app/sls_yaml/RoleNameConfigGenerator.js +84 -60
- package/src/codeGenerators/app/sls_yaml/SharedResourceYamlGenerator.js +304 -271
- package/src/codeGenerators/app/sls_yaml/__tests__/SharedResourceYamlGenerator.test.js +91 -32
- package/src/codeGenerators/app/sls_yaml/templates/SharedResource_Yaml.ejs +2 -2
- package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/EndpointsGenerator.js +1 -1
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowRbac/templates/rbac/FlowRbac_Main.ejs +252 -0
- package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/RelationshipFlowGenerator.js +1 -1
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/StatusFieldGenerator.js +1 -8
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/WebSocketGenerator.js +1 -7
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/BaseSqsHandler.js +3 -3
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowClassifier.js +3 -2
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js +12 -5
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/triggerCacheBase.js +1 -7
- package/src/codeGenerators/app/src/generatedCode/SystemFlowSchemas/RegisterGenerator.js +1 -7
- package/src/codeGenerators/app/src/generatedCode/libs/templates/Consts.ejs +23 -23
- package/src/codeGenerators/resource/sls_yaml/DynamoDBGenerator.js +8 -8
- package/src/codeGenerators/resource/sls_yaml/FlowOutGenerator.js +57 -51
- package/src/codeGenerators/resource/sls_yaml/FlowResourceYamlGenerator.js +164 -175
- package/src/codeGenerators/resource/sls_yaml/templates/SystemDynamoDB_Yaml.ejs +64 -0
- package/src/codeGenerators/resource/sls_yaml/templates/crud/ResourceYaml.ejs +10 -10
- package/src/generate.js +1 -1
- package/src/generateCode.js +181 -149
- package/src/generateSchema.js +1 -1
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/FlowSchemaGenerator.js +0 -1
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/RbacFlowSchemaGenerator.js +16 -2
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicFlowSchemaTemplate.ejs +3 -1
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicRbacFlowSchemaTemplate.ejs +1 -0
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/RelationshipFlowSchemaTemplate.ejs +6 -5
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/UserRbacFlowSchemaTemplate.ejs +22 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/.gitkeep +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/FlowEndpointBeforeLogical_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/CreateEndpoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/DeleteEndpoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/GetEndpoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/UpdateEndpoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessChangeRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessChangeRelationship_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessCreateRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessCreateRelationship_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessDeleteRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessDeleteRelationship_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessGetRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessGetRelationship_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessMoveRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessMoveRelationship_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessUpdateRelationshipComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessUpdateRelationship_Main.ejs +0 -0
|
@@ -7,77 +7,101 @@ import { getFlowsForGeneration } from '../src/generatedCode/Flow/_shared/shared/
|
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
9
9
|
|
|
10
|
+
const FLOW_OBJECTS_ROLE = 'FlowObjectsRole';
|
|
11
|
+
const CRUD_FLOW_TAGS = new Set(['Create', 'Update', 'Delete', 'Get']);
|
|
12
|
+
const RBAC_FLOW_TAGS = new Set([
|
|
13
|
+
'CreateTargetRole',
|
|
14
|
+
'ListTargetRole',
|
|
15
|
+
'DeleteTargetRole',
|
|
16
|
+
'CreateRolePermissions',
|
|
17
|
+
'ListRolePermissions',
|
|
18
|
+
'DeleteRolePermissions',
|
|
19
|
+
'CreateUserRole',
|
|
20
|
+
'ListUserInRoles',
|
|
21
|
+
'DeleteUserFromRole'
|
|
22
|
+
]);
|
|
23
|
+
const REL_FLOW_TAGS = new Set([
|
|
24
|
+
'CreateRelationship',
|
|
25
|
+
'UpdateRelationship',
|
|
26
|
+
'DeleteRelationship',
|
|
27
|
+
'GetRelationship',
|
|
28
|
+
'ChangeRelationship',
|
|
29
|
+
'MoveRelationship'
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function upperCase(str) {
|
|
33
|
+
if (!str) return str;
|
|
34
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
export async function generateRoleNameConfig(allSchemas, options) {
|
|
11
|
-
|
|
38
|
+
console.log(' [RoleNameConfigGenerator] Generating IAM Role Configurations...');
|
|
12
39
|
|
|
13
|
-
|
|
14
|
-
|
|
40
|
+
const resourceYamlDir = path.join(
|
|
41
|
+
options.outputPath,
|
|
42
|
+
'app',
|
|
43
|
+
'sls_yaml',
|
|
44
|
+
'generatedCode',
|
|
45
|
+
'source'
|
|
46
|
+
);
|
|
47
|
+
await fs.mkdir(resourceYamlDir, { recursive: true });
|
|
15
48
|
|
|
16
49
|
const roleNameConfigs = new Set();
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const flows = getFlowsForGeneration(allSchemas);
|
|
33
|
-
|
|
34
|
-
if (flows.length > 0) {
|
|
35
|
-
for (const flow of flows) {
|
|
36
|
-
if (flow.flowTag) {
|
|
37
|
-
const upperFlowTag = upperCase(flow.flowTag);
|
|
38
|
-
if (CRUD_FLOW_TAGS.has(upperFlowTag)) {
|
|
39
|
-
roleNameConfigs.add('PerActionEndpointRole');
|
|
40
|
-
} else if (REL_FLOW_TAGS.has(upperFlowTag)) {
|
|
41
|
-
roleNameConfigs.add('RelationshipRole');
|
|
42
|
-
} else {
|
|
43
|
-
roleNameConfigs.add(`${upperFlowTag}Role`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
50
|
+
const flows = getFlowsForGeneration(allSchemas);
|
|
51
|
+
|
|
52
|
+
for (const flow of flows) {
|
|
53
|
+
if (!flow.flowTag) continue;
|
|
54
|
+
|
|
55
|
+
const upperFlowTag = upperCase(flow.flowTag);
|
|
56
|
+
|
|
57
|
+
if (CRUD_FLOW_TAGS.has(upperFlowTag)) {
|
|
58
|
+
roleNameConfigs.add(FLOW_OBJECTS_ROLE);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (RBAC_FLOW_TAGS.has(upperFlowTag) || upperFlowTag.endsWith('RbacFlow')) {
|
|
63
|
+
roleNameConfigs.add('FlowRbacRole');
|
|
64
|
+
continue;
|
|
46
65
|
}
|
|
66
|
+
|
|
67
|
+
if (REL_FLOW_TAGS.has(upperFlowTag)) {
|
|
68
|
+
roleNameConfigs.add('FlowRelationshipRole');
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ((flow.event || []).includes('ownTopic')) {
|
|
73
|
+
roleNameConfigs.add('WebSocketMainRole');
|
|
74
|
+
// ponytail: removed continue; so custom flows with ownTopic get their own specific role
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
roleNameConfigs.add(`${upperFlowTag}Role`);
|
|
47
78
|
}
|
|
48
79
|
|
|
49
|
-
// Static core framework roles that are generated
|
|
50
80
|
roleNameConfigs.add('ProcFindDataRole');
|
|
51
|
-
|
|
52
|
-
// 2. Main Execution Roles (Based on initiateBy & outputTopic)
|
|
53
|
-
if (flows.length > 0 && flows.some(f => f.event && f.event.includes('ownTopic'))) {
|
|
54
|
-
roleNameConfigs.add('WebSocketMainRole');
|
|
55
|
-
}
|
|
56
81
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
const templatePath = path.join(__dirname, 'templates', 'RoleNameConfig_Yaml.ejs');
|
|
83
|
+
let templateString;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
templateString = await fs.readFile(templatePath, 'utf-8');
|
|
87
|
+
} catch {
|
|
88
|
+
templateString = `# for createIamRole
|
|
89
|
+
<% roleNameConfigs.forEach(function(roleNameConfig){ _%>
|
|
90
|
+
- arn:aws:iam::\${self:custom.iz_accountId}:role/\${self:custom.iz_resourcePrefix}<%- roleNameConfig %>
|
|
91
|
+
<% }) _%>
|
|
92
|
+
`;
|
|
61
93
|
await fs.mkdir(path.dirname(templatePath), { recursive: true });
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
templateString = await fs.readFile(templatePath, 'utf-8');
|
|
66
|
-
} catch (e) {
|
|
67
|
-
// Fallback to auto-creating the template based on old roleNameConfig
|
|
68
|
-
templateString = `# for createIamRole\n\n<% roleNameConfigs.forEach(roleNameConfig => { _%>\n- arn:aws:iam::\${self:custom.iz_accountId}:role/\${self:custom.iz_resourcePrefix}<%- roleNameConfig %>\n<% }) _%>\n`;
|
|
69
|
-
await fs.writeFile(templatePath, templateString, 'utf-8');
|
|
70
|
-
}
|
|
94
|
+
await fs.writeFile(templatePath, templateString, 'utf-8');
|
|
95
|
+
}
|
|
71
96
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
const fileContent = ejs.render(templateString, {
|
|
98
|
+
roleNameConfigs: Array.from(roleNameConfigs)
|
|
99
|
+
});
|
|
75
100
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Since isAppend was true in the old code, we should append or overwrite.
|
|
79
|
-
// However, since we clean the resource folder at start, writeFile is fine.
|
|
80
|
-
await fs.writeFile(outputPath, fileContent, 'utf-8');
|
|
101
|
+
const outputPath = path.join(resourceYamlDir, 'role-name-config.yml');
|
|
102
|
+
await fs.writeFile(outputPath, fileContent, 'utf-8');
|
|
81
103
|
|
|
82
|
-
|
|
104
|
+
console.log(
|
|
105
|
+
` [RoleNameConfigGenerator] Wrote ${roleNameConfigs.size} role configs to ${outputPath}`
|
|
106
|
+
);
|
|
83
107
|
}
|