@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
@@ -1,18 +1,35 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
1
18
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
2
19
  import snsSharedLib from '@izara_project/izara-core-library-sns';
3
20
  import { sns } from '@izara_project/izara-core-library-external-request';
4
21
  import { consts, NoRetryError } from '@izara_project/izara-core-library-core';
5
22
 
6
- export default async function Process<%- flowTag %>(_izContext, requestParams) {
23
+ export default async function <%- flowTag %>(_izContext, requestParams) {
7
24
  try {
8
- <% if (useContextUserId) { -%>
25
+ <% if (useContextUserId) { -%>
9
26
  const userId = _izContext.correlationIds.get(consts.BASE_USER_ID);
10
27
  if (!userId) throw new NoRetryError('User Id not found.');
11
28
  const queryParams = { userId };
12
- <% } else { -%>
29
+ <% } else { -%>
13
30
  const { <%- requestProperty %> } = requestParams;
14
31
  const queryParams = { <%- requestProperty %> };
15
- <% } -%>
32
+ <% } -%>
16
33
  const resultQuery = await dynamodbSharedLib.query(
17
34
  _izContext,
18
35
  dynamodbSharedLib.tableName(_izContext, '<%- tableName %>'),
@@ -20,10 +37,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
20
37
  );
21
38
  await sns.publishMessage(_izContext, {
22
39
  message: { returnResult: { records: resultQuery.Items || [] } },
23
- TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, '<%- flowTag %>_Out')
40
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
41
+ _izContext,
42
+ '<%- flowTag %>_Out'
43
+ )
24
44
  });
25
45
  } catch (error) {
26
- _izContext.logger.error('[Rbac:Process<%- flowTag %>] error:', error);
46
+ _izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
27
47
  throw error;
28
48
  }
29
49
  }
@@ -1,9 +1,26 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
1
18
  <% const fieldList = fields.join(', '); -%>
2
19
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
3
20
  import snsSharedLib from '@izara_project/izara-core-library-sns';
4
21
  import { sns } from '@izara_project/izara-core-library-external-request';
5
22
 
6
- export default async function Process<%- flowTag %>(_izContext, requestParams) {
23
+ export default async function <%- flowTag %>(_izContext, requestParams) {
7
24
  try {
8
25
  const { <%- fieldList %> } = requestParams;
9
26
  await dynamodbSharedLib.<%- method %>(
@@ -13,10 +30,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
13
30
  );
14
31
  await sns.publishMessage(_izContext, {
15
32
  message: { returnResult: { <%- fieldList %> } },
16
- TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, '<%- flowTag %>_Out')
33
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
34
+ _izContext,
35
+ '<%- flowTag %>_Out'
36
+ )
17
37
  });
18
38
  } catch (error) {
19
- _izContext.logger.error('[Rbac:Process<%- flowTag %>] error:', error);
39
+ _izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
20
40
  throw error;
21
41
  }
22
42
  }
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
19
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
20
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
21
+ import <%- flowTag %> from './<%- flowTag %>_Main.js';
22
+
23
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
24
+ export const main = middleware.wrap(async (event) =>
25
+ Promise.all(
26
+ event.Records.map(async (record) => {
27
+ await recordHandlerSharedLib.validateRecord(
28
+ record,
29
+ '<%- flowTag %>HdrSqs',
30
+ {},
31
+ null
32
+ );
33
+ return recordHandlerSharedLib.recordHandler(
34
+ record,
35
+ <%- flowTag %>,
36
+ '<%- flowTag %>HdrSqs',
37
+ [
38
+ record.body.Message,
39
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(
40
+ record.body.Message
41
+ )
42
+ ]
43
+ );
44
+ })
45
+ )
46
+ );
@@ -1,44 +1,163 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
1
18
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
2
19
  import { coreConsts } from '@izara_project/izara-core-library-core';
20
+ import { sns } from '@izara_project/izara-core-library-external-request';
21
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
22
+
23
+ export default async function <%- flowTag %>(_izContext, requestParams = {}) {
24
+ const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
25
+ const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
26
+ if (!userId || !targetId) {
27
+ throw new Error('Missing required request parameters: userId or targetId');
28
+ }
29
+
30
+ const { flowTypeConcat, inputParameterGroups } = requestParams;
31
+ if (!flowTypeConcat) {
32
+ throw new Error('Missing flowTypeConcat in requestParams');
33
+ }
3
34
 
4
- export default async function Process<%- flowTag %>(_izContext, requestParams) {
5
- try {
6
- const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
7
- const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
8
- if (!userId && !targetId) throw new Error('Missing required request parameters: userId or targetId');
9
- const { flowTypeConcat, inputParameterGroups } = requestParams;
10
- if (!flowTypeConcat) throw new Error('Missing flowTypeConcat in requestParams');
11
- const userRoles = (await dynamodbSharedLib.query(
12
- _izContext,
13
- dynamodbSharedLib.tableName(_izContext, 'UserRoles'),
14
- { userId }
15
- )).Items || [];
16
- const targetRoles = userRoles.filter(role => role.roleIdKey?.startsWith(targetId + '_'));
17
- for (const role of targetRoles) {
18
- const permission = await dynamodbSharedLib.getItem(
19
- _izContext,
20
- dynamodbSharedLib.tableName(_izContext, 'RolePermissions'),
21
- { roleIdKey: role.roleIdKey, flowTypeConcat }
35
+ const userRolesResult = await dynamodbSharedLib.query(
36
+ _izContext,
37
+ dynamodbSharedLib.tableName(_izContext, 'UserRoles'),
38
+ { userId }
39
+ );
40
+
41
+ let userRoles = [];
42
+ if (Array.isArray(userRolesResult)) {
43
+ userRoles = userRolesResult;
44
+ } else if (userRolesResult && userRolesResult.Items) {
45
+ userRoles = userRolesResult.Items;
46
+ }
47
+
48
+ const targetIdPrefix = `${targetId}_`;
49
+ const targetRoles = [];
50
+ for (const role of userRoles) {
51
+ if (role && role.roleIdKey && role.roleIdKey.startsWith(targetIdPrefix)) {
52
+ targetRoles.push(role);
53
+ }
54
+ }
55
+
56
+ if (targetRoles.length === 0) {
57
+ await _publicMessageOut(_izContext, {
58
+ permission: false,
59
+ roleIdKey: ''
60
+ });
61
+ return;
62
+ }
63
+
64
+ const rolePermissionsTable = dynamodbSharedLib.tableName(
65
+ _izContext,
66
+ 'RolePermissions'
67
+ );
68
+ const rolePermissions = await Promise.all(
69
+ targetRoles.map(async (role) => {
70
+ return await dynamodbSharedLib.getItem(_izContext, rolePermissionsTable, {
71
+ roleIdKey: role.roleIdKey,
72
+ flowTypeConcat
73
+ });
74
+ })
75
+ );
76
+
77
+ let matched = null;
78
+ for (const permission of rolePermissions) {
79
+ if (permission && permission.permission === true) {
80
+ const isMatched = _matchesParameterGroups(
81
+ permission.parameterGroups,
82
+ inputParameterGroups
22
83
  );
23
- if (permission?.permission === true && matchesParameterGroups(permission.parameterGroups, inputParameterGroups)) {
24
- return { permission: true, roleIdKey: permission.roleIdKey };
84
+ if (isMatched) {
85
+ matched = permission;
86
+ break;
25
87
  }
26
88
  }
27
- return { permission: false, roleIdKey: '' };
28
- } catch (error) {
29
- _izContext.logger.error('error Process<%- flowTag %>:', error);
30
- throw error;
89
+ }
90
+
91
+ if (matched) {
92
+ await _publicMessageOut(_izContext, {
93
+ permission: true,
94
+ roleIdKey: matched.roleIdKey
95
+ });
96
+ } else {
97
+ await _publicMessageOut(_izContext, {
98
+ permission: false,
99
+ roleIdKey: ''
100
+ });
31
101
  }
32
102
  }
33
103
 
34
- function matchesParameterGroups(groups, input) {
35
- if (!groups || typeof groups !== 'object' || Array.isArray(groups) || Object.keys(groups).length === 0) return true;
36
- return Object.values(groups).some(group => Array.isArray(group) && group.every(check => {
37
- let value = input || {};
38
- for (const name of check.parameterNames || []) {
39
- if (!value || typeof value !== 'object' || !(name in value)) return false;
40
- value = value[name];
104
+ async function _publicMessageOut(_izContext, message) {
105
+ const topicOut = snsSharedLib.snsTopicArnByFlowSchema(
106
+ _izContext,
107
+ process.env.iz_flowTag + '_Out'
108
+ );
109
+
110
+ await sns.publishAsync(_izContext, {
111
+ topicArn: topicOut,
112
+ message: JSON.stringify(message)
113
+ });
114
+ }
115
+
116
+ function _matchesParameterGroups(groups, input) {
117
+ if (!groups || typeof groups !== 'object' || Array.isArray(groups)) {
118
+ return true;
119
+ }
120
+
121
+ const groupValues = Object.values(groups);
122
+ if (groupValues.length === 0) {
123
+ return true;
124
+ }
125
+
126
+ for (const group of groupValues) {
127
+ if (!Array.isArray(group)) {
128
+ continue;
129
+ }
130
+
131
+ let isGroupMatched = true;
132
+ for (const check of group) {
133
+ if (
134
+ !Array.isArray(check.parameterNames) ||
135
+ !Array.isArray(check.parameterValues)
136
+ ) {
137
+ isGroupMatched = false;
138
+ break;
139
+ }
140
+
141
+ let val = input || {};
142
+ for (const key of check.parameterNames) {
143
+ if (val && typeof val === 'object') {
144
+ val = val[key];
145
+ } else {
146
+ val = null;
147
+ break;
148
+ }
149
+ }
150
+
151
+ if (!check.parameterValues.includes(val)) {
152
+ isGroupMatched = false;
153
+ break;
154
+ }
41
155
  }
42
- return Array.isArray(check.parameterValues) && check.parameterValues.includes(value);
43
- }));
156
+
157
+ if (isGroupMatched) {
158
+ return true;
159
+ }
160
+ }
161
+
162
+ return false;
44
163
  }
@@ -1,11 +1,28 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
1
18
  <%
2
19
  const itemType = operation === 'Put' ? 'Item' : 'Key';
3
20
  const roleUsersKey = operation === 'Put' ? 'userId, roleIdKey' : 'roleIdKey, userId';
4
- -%>import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
+ -%> import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
5
22
  import snsSharedLib from '@izara_project/izara-core-library-sns';
6
23
  import { sns } from '@izara_project/izara-core-library-external-request';
7
24
 
8
- export default async function Process<%- flowTag %>(_izContext, requestParams) {
25
+ export default async function <%- flowTag %>(_izContext, requestParams) {
9
26
  try {
10
27
  const { roleIdKey, userId } = requestParams;
11
28
  await dynamodbSharedLib.transactWriteItems(_izContext, [
@@ -24,10 +41,13 @@ export default async function Process<%- flowTag %>(_izContext, requestParams) {
24
41
  ]);
25
42
  await sns.publishMessage(_izContext, {
26
43
  message: { returnResult: { userId, roleIdKey } },
27
- TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, '<%- flowTag %>_Out')
44
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
45
+ _izContext,
46
+ '<%- flowTag %>_Out'
47
+ )
28
48
  });
29
49
  } catch (error) {
30
- _izContext.logger.error('[Rbac:Process<%- flowTag %>] error:', error);
50
+ _izContext.logger.error('[Rbac:<%- flowTag %>] error:', error);
31
51
  throw error;
32
52
  }
33
53
  }
@@ -1,5 +1,3 @@
1
- import { renderDynamicRelationshipFlowSchema } from './dynamicRelationshipFlowSchemaTemplate.js';
2
-
3
1
  const ACTIONS = [
4
2
  'CreateRelationship',
5
3
  'UpdateRelationship',
@@ -11,17 +9,33 @@ const ACTIONS = [
11
9
  const MESSAGE_ATTRIBUTES = ['userId', 'correlationId'];
12
10
 
13
11
  export const dynamicRelationshipFlowSchemaPaths = ACTIONS.map(
14
- action => `app/src/schemas/FlowSchemas/generateCode/${action}.js`
12
+ (action) =>
13
+ `app/src/schemas/FlowSchemas/generateCode/FlowRelationship/${action}.js`
15
14
  );
16
15
 
17
16
  export function emitDynamicRelationshipFlowSchemas() {
18
17
  // Keep legacy compatibility: relationship flow endpoints exist even before a relationship is declared.
19
18
  return ACTIONS.map((action, index) => ({
20
19
  path: dynamicRelationshipFlowSchemaPaths[index],
21
- content: renderDynamicRelationshipFlowSchema(action, createDynamicRelationshipFlow(action))
20
+ content: _renderDynamicRelationshipFlowSchema(
21
+ action,
22
+ createDynamicRelationshipFlow(action)
23
+ )
22
24
  }));
23
25
  }
24
26
 
27
+ function _renderDynamicRelationshipFlowSchema(action, flow) {
28
+ return [
29
+ '/**',
30
+ ' * GENERATED DYNAMIC RELATIONSHIP FLOW SCHEMA',
31
+ ` * Action: ${action}`,
32
+ ' * Description: Handles dynamic relationship actions for all allowed RelationshipTypes via SQS/DSQ',
33
+ ' */',
34
+ `export default ${JSON.stringify(flow, null, 2)};`,
35
+ ''
36
+ ].join('\n');
37
+ }
38
+
25
39
  function createDynamicRelationshipFlow(action) {
26
40
  const outputTopic = action !== 'GetRelationship';
27
41
  const flowSteps = [
@@ -29,12 +43,14 @@ function createDynamicRelationshipFlow(action) {
29
43
  stepName: 'start',
30
44
  properties: [],
31
45
  messageAttributes: MESSAGE_ATTRIBUTES,
32
- ...(outputTopic ? {
33
- returnValues: {
34
- properties: [],
35
- messageAttributes: MESSAGE_ATTRIBUTES
36
- }
37
- } : {})
46
+ ...(outputTopic
47
+ ? {
48
+ returnValues: {
49
+ properties: [],
50
+ messageAttributes: MESSAGE_ATTRIBUTES
51
+ }
52
+ }
53
+ : {})
38
54
  }
39
55
  ];
40
56
 
@@ -49,7 +65,6 @@ function createDynamicRelationshipFlow(action) {
49
65
 
50
66
  return {
51
67
  flowTag: action,
52
- isDynamicRelationshipType: true,
53
68
  initiateBy: 'system',
54
69
  handleObj: 'one',
55
70
  statusType: 'none',