@izara_project/izara-core-generate-service-code 1.0.55 → 1.0.57

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 (48) hide show
  1. package/package.json +1 -1
  2. package/src/codeGenerators/app/initial_setup/InitialSetupGenerator.js +223 -123
  3. package/src/codeGenerators/app/initial_setup/templates/InitialSetup_LambdaRole.ejs +6 -6
  4. package/src/codeGenerators/app/sls_yaml/FindDataYamlGenerator.js +1 -1
  5. package/src/codeGenerators/app/sls_yaml/FunctionYamlGenerator.js +299 -197
  6. package/src/codeGenerators/app/sls_yaml/RoleNameConfigGenerator.js +84 -60
  7. package/src/codeGenerators/app/sls_yaml/SharedResourceYamlGenerator.js +304 -271
  8. package/src/codeGenerators/app/sls_yaml/__tests__/SharedResourceYamlGenerator.test.js +91 -32
  9. package/src/codeGenerators/app/sls_yaml/templates/SharedResource_Yaml.ejs +2 -2
  10. package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/EndpointsGenerator.js +1 -1
  11. package/src/codeGenerators/app/src/generatedCode/Flow/FlowRbac/templates/rbac/FlowRbac_Main.ejs +252 -0
  12. package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/RelationshipFlowGenerator.js +19 -3
  13. package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessCreateRelationship_Main.ejs +1 -1
  14. package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/WebSocketGenerator.js +4 -4
  15. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowClassifier.js +3 -2
  16. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js +12 -5
  17. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowValidator.js +1 -1
  18. package/src/codeGenerators/app/src/generatedCode/libs/templates/Consts.ejs +23 -23
  19. package/src/codeGenerators/resource/sls_yaml/DynamoDBGenerator.js +1 -1
  20. package/src/codeGenerators/resource/sls_yaml/FlowOutGenerator.js +3 -6
  21. package/src/codeGenerators/resource/sls_yaml/FlowResourceYamlGenerator.js +29 -10
  22. package/src/codeGenerators/resource/sls_yaml/templates/SystemDynamoDB_Yaml.ejs +64 -0
  23. package/src/generate.js +1 -1
  24. package/src/generateCode.js +14 -11
  25. package/src/generateSchema.js +1 -1
  26. package/src/schemaGenerators/app/src/schemas/FlowSchemas/FlowSchemaGenerator.js +0 -1
  27. package/src/schemaGenerators/app/src/schemas/FlowSchemas/RbacFlowSchemaGenerator.js +16 -2
  28. package/src/schemaGenerators/app/src/schemas/FlowSchemas/RelationshipFlowSchemaGenerator.js +2 -2
  29. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicFlowSchemaTemplate.ejs +12 -12
  30. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicRbacFlowSchemaTemplate.ejs +1 -0
  31. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/UserRbacFlowSchemaTemplate.ejs +22 -0
  32. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/.gitkeep +0 -0
  33. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/FlowEndpointBeforeLogical_Main.ejs +0 -0
  34. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/CreateEndpoint_Main.ejs +0 -0
  35. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/DeleteEndpoint_Main.ejs +0 -0
  36. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/GetEndpoint_Main.ejs +0 -0
  37. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowEndpoints → FlowObjects}/templates/crud/UpdateEndpoint_Main.ejs +0 -0
  38. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessChangeRelationshipComplete_Main.ejs +0 -0
  39. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessChangeRelationship_Main.ejs +0 -0
  40. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessCreateRelationshipComplete_Main.ejs +0 -0
  41. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessDeleteRelationshipComplete_Main.ejs +0 -0
  42. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessDeleteRelationship_Main.ejs +0 -0
  43. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessGetRelationshipComplete_Main.ejs +0 -0
  44. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessGetRelationship_Main.ejs +0 -0
  45. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessMoveRelationshipComplete_Main.ejs +0 -0
  46. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessMoveRelationship_Main.ejs +0 -0
  47. /package/src/codeGenerators/app/src/generatedCode/Flow/{FlowRelationshipEndpoints → FlowRelationships}/templates/relationship/ProcessUpdateRelationshipComplete_Main.ejs +0 -0
  48. /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
- console.log(' [RoleNameConfigGenerator] Generating IAM Role Configurations...');
38
+ console.log(' [RoleNameConfigGenerator] Generating IAM Role Configurations...');
12
39
 
13
- const resourceYamlDir = path.join(options.outputPath, 'app', 'sls_yaml', 'generatedCode', 'source');
14
- await fs.mkdir(resourceYamlDir, { recursive: true });
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 CRUD_FLOW_TAGS = new Set(['Create', 'Update', 'Delete', 'Get']);
18
- const REL_FLOW_TAGS = new Set([
19
- 'CreateRelationship',
20
- 'UpdateRelationship',
21
- 'DeleteRelationship',
22
- 'GetRelationship',
23
- 'ChangeRelationship',
24
- 'MoveRelationship'
25
- ]);
26
-
27
- const upperCase = (str) => {
28
- if (!str) return str;
29
- return str.charAt(0).toUpperCase() + str.slice(1);
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
- // Prepare template output
58
- const templatePath = path.join(__dirname, 'templates', 'RoleNameConfig_Yaml.ejs');
59
-
60
- // Create templates directory and file if it doesn't exist
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
- let templateString;
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
- const fileContent = ejs.render(templateString, {
73
- roleNameConfigs: Array.from(roleNameConfigs)
74
- });
97
+ const fileContent = ejs.render(templateString, {
98
+ roleNameConfigs: Array.from(roleNameConfigs)
99
+ });
75
100
 
76
- const outputPath = path.join(resourceYamlDir, 'role-name-config.yml');
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
- console.log(` [RoleNameConfigGenerator] Wrote ${roleNameConfigs.size} role configs to ${outputPath}`);
104
+ console.log(
105
+ ` [RoleNameConfigGenerator] Wrote ${roleNameConfigs.size} role configs to ${outputPath}`
106
+ );
83
107
  }