@izara_project/izara-core-generate-service-code 1.0.66 → 1.0.68

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 (90) hide show
  1. package/.prettierrc +11 -0
  2. package/docs/TriggeredCache Flow.drawio +193 -0
  3. package/docs/TriggeredCacheFlow.mmd +47 -0
  4. package/package.json +16 -12
  5. package/scripts/format-ejs.js +105 -0
  6. package/src/compile/compileProject.js +16 -1
  7. package/src/compile/loadSchemas.js +108 -1
  8. package/src/emit/crud/emitCrudApplicationArtifacts.js +9 -5
  9. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +300 -109
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +221 -143
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +150 -38
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +57 -31
  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 +407 -252
  22. package/src/emit/custom/customFlows.js +112 -31
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +89 -77
  24. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +49 -37
  25. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  26. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  27. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  28. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  29. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  30. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  32. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
  33. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  34. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
  35. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  36. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  38. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  39. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  40. package/src/emit/function/functionYamlArtifact.js +46 -12
  41. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
  42. package/src/emit/rbac/emitRbacApplicationArtifacts.js +179 -66
  43. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  44. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  45. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  46. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  47. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  48. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  49. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  50. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  51. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  52. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
  53. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +6 -5
  54. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  55. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +260 -144
  56. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  57. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  58. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  59. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  60. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  61. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  62. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  63. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  64. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  65. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  66. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  67. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  68. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  69. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  70. package/src/emit/resource/emitResourceArtifacts.js +499 -108
  71. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  72. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  73. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
  74. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  75. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  76. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  77. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  78. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  79. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
  80. package/src/emit/system/emitSystemWebSocketArtifacts.js +2 -1
  81. package/src/generate.js +8 -4
  82. package/test/createTargetRoleHandler.test.js +63 -14
  83. package/test/crudApplicationArtifacts.test.js +1 -1
  84. package/test/customFlowApplicationArtifacts.test.js +71 -43
  85. package/test/dynamicCrudFlowSchemas.test.js +6 -6
  86. package/test/dynamicRbacFlowSchemas.test.js +8 -12
  87. package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
  88. package/test/publicApi.test.js +11 -13
  89. package/test/resourceArtifacts.test.js +13 -3
  90. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
@@ -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 = undefined;
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
  }
@@ -11,7 +11,7 @@ const ACTIONS = [
11
11
  const MESSAGE_ATTRIBUTES = ['userId', 'correlationId'];
12
12
 
13
13
  export const dynamicRelationshipFlowSchemaPaths = ACTIONS.map(
14
- action => `app/src/schemas/FlowSchemas/generateCode/${action}.js`
14
+ action => `app/src/schemas/FlowSchemas/generateCode/FlowRelationship/${action}.js`
15
15
  );
16
16
 
17
17
  export function emitDynamicRelationshipFlowSchemas() {
@@ -49,7 +49,6 @@ function createDynamicRelationshipFlow(action) {
49
49
 
50
50
  return {
51
51
  flowTag: action,
52
- isDynamicRelationshipType: true,
53
52
  initiateBy: 'system',
54
53
  handleObj: 'one',
55
54
  statusType: 'none',
@@ -68,7 +68,7 @@ async function emitAction(action, relationships, flows, serviceTag) {
68
68
  { path: `${source}/${action}_WbsMain.js`, content: await renderShared('FlowMain_Wbs.ejs', { flowTag: action, upperCaseFlowTag: action, functionName: action }) },
69
69
  { path: `${source}/${action}_HdrWbs.js`, content: await renderShared('FlowEndpoint_HdrWbs.ejs', { flowTag: action, upperCaseFlowTag: action, functionName: action, mainFileName: `${action}_WbsMain`, route: action }) }
70
70
  );
71
- functions.push({ type: 'wbs', functionName: `${action}HdrWbs`, handlerPath: `${handlerRoot}/${action}_HdrWbs.main`, roleName: 'FlowRelationshipRole', routeName: action });
71
+ functions.push({ type: 'wbs', functionName: `${action}HdrWbs`, handlerPath: `${handlerRoot}/${action}_HdrWbs.main`, roleName: 'FlowRelationshipRole', routeName: action, flowTag: action, flowStepName: '' });
72
72
  }
73
73
 
74
74
  for (const event of events) {
@@ -83,7 +83,7 @@ async function emitAction(action, relationships, flows, serviceTag) {
83
83
  { path: `${source}/${complete}_Main.js`, content: await render(`${action}Complete_Main.ejs`, { functionName: complete, upperFunctionName: complete }) },
84
84
  { path: `${source}/${complete}_HdrSqs.js`, content: await renderShared('FlowHandler_HdrSqs.ejs', { ...shared, flowStepName: 'Complete', mainFileName: `${complete}_Main`, functionName: complete, queueName: `${complete}HdrSqs` }) }
85
85
  );
86
- functions.push({ type: 'sqs', functionName: `${action}CompleteHdrSqs`, handlerPath: `${handlerRoot}/${complete}_HdrSqs.main`, roleName: 'FlowRelationshipRole', queueName: `${complete}HdrSqs` });
86
+ functions.push({ type: 'sqs', functionName: `${action}CompleteHdrSqs`, handlerPath: `${handlerRoot}/${complete}_HdrSqs.main`, roleName: 'FlowRelationshipRole', queueName: `${complete}HdrSqs`, flowTag: action, flowStepName: 'Complete' });
87
87
  return { artifacts, functions };
88
88
  }
89
89
 
@@ -91,19 +91,19 @@ function eventHandler(event, action, handlerRoot, relationships, serviceTag) {
91
91
  if (event === 'ownTopic' || event === 'extTopic') {
92
92
  return {
93
93
  fileName: `${action}_HdrSqs`, template: 'FlowHandler_HdrSqs.ejs', queueName: `${action}HdrSqs`,
94
- descriptor: { type: 'sqs', functionName: `${action.replace('Relationship', 'Rel')}HdrSqs`, handlerPath: `${handlerRoot}/${action}_HdrSqs.main`, roleName: 'FlowRelationshipRole', queueName: `${action}HdrSqs` }
94
+ descriptor: { type: 'sqs', functionName: `${action.replace('Relationship', 'Rel')}HdrSqs`, handlerPath: `${handlerRoot}/${action}_HdrSqs.main`, roleName: 'FlowRelationshipRole', queueName: `${action}HdrSqs`, flowTag: action, flowStepName: '' }
95
95
  };
96
96
  }
97
97
  if (event === 'dsq') {
98
98
  return {
99
99
  fileName: `${action}_HdrDsq`, template: 'FlowHandler_HdrDsq.ejs', queueName: `${action}HdrDsq`,
100
- descriptor: { type: 'sqs', functionName: `${action.replace('Relationship', 'Rel')}HdrDsq`, handlerPath: `${handlerRoot}/${action}_HdrDsq.main`, roleName: 'FlowRelationshipRole', queueName: `${action}HdrDsq` }
100
+ descriptor: { type: 'sqs', functionName: `${action.replace('Relationship', 'Rel')}HdrDsq`, handlerPath: `${handlerRoot}/${action}_HdrDsq.main`, roleName: 'FlowRelationshipRole', queueName: `${action}HdrDsq`, flowTag: action, flowStepName: '' }
101
101
  };
102
102
  }
103
103
  if (event === 'lambdaSyncInv') {
104
104
  return {
105
105
  fileName: `${action}_HdrInv`, template: 'FlowHandler_HdrInv.ejs',
106
- descriptor: { type: 'inv', functionName: `${action.replace('Relationship', 'Rel')}HdrInv`, handlerPath: `${handlerRoot}/${action}_HdrInv.main`, roleName: 'FlowRelationshipRole' }
106
+ descriptor: { type: 'inv', functionName: `${action.replace('Relationship', 'Rel')}HdrInv`, handlerPath: `${handlerRoot}/${action}_HdrInv.main`, roleName: 'FlowRelationshipRole', flowTag: action, flowStepName: '' }
107
107
  };
108
108
  }
109
109
  if (event === 'lambdaSyncApi') {
@@ -111,6 +111,7 @@ function eventHandler(event, action, handlerRoot, relationships, serviceTag) {
111
111
  fileName: `${action}_HdrApi`, template: 'FlowHandler_HdrApi.ejs',
112
112
  descriptor: {
113
113
  type: 'api', functionName: `${action.replace('Relationship', 'Rel')}HdrApi`, handlerPath: `${handlerRoot}/${action}_HdrApi.main`, roleName: 'FlowRelationshipRole',
114
+ flowTag: action, flowStepName: '',
114
115
  routes: relationships.map(relationship => {
115
116
  const name = relationship.relationshipTag ?? Object.keys(relationship)[0];
116
117
  return { path: `/${serviceTag ?? '${self:custom.iz_serviceName}'}/${name}/${action.toLowerCase().replace('relationship', '')}`, upperName: upperFirst(name) };
@@ -15,22 +15,21 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
18
  import { objectHash as hash } from '@izara_project/izara-shared-core';
20
19
 
21
20
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
- import snsSharedLib from "@izara_project/izara-core-library-sns";
23
- import dynamodbSharedLib from "@izara_project/izara-core-library-dynamodb";
24
- import asyncFlowSharedLib from "@izara_project/izara-core-library-asynchronous-flow";
25
-
26
- import { sns } from "@izara_project/izara-core-library-external-request";
27
- import { utils, consts } from '@izara_project/izara-core-library-service-schemas';
21
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
22
+ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
23
+ import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
24
+
25
+ import { sns } from '@izara_project/izara-core-library-external-request';
26
+ import {
27
+ utils,
28
+ consts
29
+ } from '@izara_project/izara-core-library-service-schemas';
28
30
  const { createLinkTypeId } = utils;
29
31
 
30
- const {
31
- TOPIC_NAME_GENERATE_CODE,
32
- PREFIX
33
- } = consts;
32
+ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
34
33
 
35
34
  //(<optionalRequire>)
36
35
  //(</optionalRequire>)
@@ -41,15 +40,15 @@ export default async function changeRelationshipComplete(
41
40
  status,
42
41
  errorsFound,
43
42
  graphServiceTag,
44
- passBackProperties = {},
43
+ passBackProperties = {}
45
44
  ) {
46
45
  try {
47
- _izContext.logger.debug("Function:ChangeRelationshipComplete", {
46
+ _izContext.logger.debug('Function:ChangeRelationshipComplete', {
48
47
  returnValue: returnValue,
49
48
  status: status,
50
49
  errorsFound: errorsFound,
51
50
  graphServiceTag: graphServiceTag,
52
- passBackProperties: passBackProperties,
51
+ passBackProperties: passBackProperties
53
52
  });
54
53
 
55
54
  // start create awaitingStepId
@@ -64,54 +63,83 @@ export default async function changeRelationshipComplete(
64
63
  let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
65
64
  returnValue.parentFlowId, // hash id
66
65
  PREFIX.changeRel // prefix, use constant further
67
- )
68
-
66
+ );
69
67
 
70
68
  let createRelPendingObjects = await dynamodbSharedLib.query(
71
69
  _izContext,
72
- await dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
70
+ await dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
73
71
  {
74
72
  awaitingStepId: awaitingStepId
75
73
  }
76
74
  );
77
- _izContext.logger.debug("record of createRelPendingObjects ::", createRelPendingObjects);
78
-
79
-
75
+ _izContext.logger.debug(
76
+ 'record of createRelPendingObjects ::',
77
+ createRelPendingObjects
78
+ );
80
79
 
81
80
  await Promise.all(
82
81
  createRelPendingObjects.Items.map(async ({ pendingStepId }) => {
83
- if (await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
82
+ if (
83
+ await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
84
84
  _izContext,
85
85
  pendingStepId, // task waiting
86
86
  awaitingStepId,
87
87
  errorsFound
88
- )) {
89
- _izContext.logger.debug("finished all awaitingStep");
88
+ )
89
+ ) {
90
+ _izContext.logger.debug('finished all awaitingStep');
90
91
 
91
92
  let changeRelCompleteMsg = {
92
93
  firstObject: returnValue.requestParams.firstObject,
93
94
  secondObject: returnValue.requestParams.secondObject,
94
95
  relType: returnValue.requestParams.relType,
95
- oldRelTypeAndDirection: returnValue.requestParams.oldRelTypeAndDirection,
96
+ oldRelTypeAndDirection:
97
+ returnValue.requestParams.oldRelTypeAndDirection,
96
98
  newRelType: returnValue.requestParams.newRelType,
97
99
  parentFlowId: returnValue.parentFlowId,
98
100
  status: status,
99
101
  errorsFound: errorsFound
100
102
  };
101
103
 
102
- changeRelCompleteMsg = callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(passBackProperties, changeRelCompleteMsg);
103
- _izContext.logger.debug("After addCallingFlowToSnsResponseMessageObject", changeRelCompleteMsg);
104
-
105
- let messageAttributes = callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(passBackProperties, {});
106
- _izContext.logger.debug("After addCallingFlowToSnsResponseMessageAttributes", changeRelCompleteMsg);
104
+ changeRelCompleteMsg =
105
+ callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
106
+ passBackProperties,
107
+ changeRelCompleteMsg
108
+ );
109
+ _izContext.logger.debug(
110
+ 'After addCallingFlowToSnsResponseMessageObject',
111
+ changeRelCompleteMsg
112
+ );
113
+
114
+ let messageAttributes =
115
+ callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
116
+ passBackProperties,
117
+ {}
118
+ );
119
+ _izContext.logger.debug(
120
+ 'After addCallingFlowToSnsResponseMessageAttributes',
121
+ changeRelCompleteMsg
122
+ );
107
123
 
108
124
  let sendMessageToOutChangeRelationshipComplete = {
109
125
  Message: JSON.stringify(changeRelCompleteMsg),
110
- MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
111
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete)
126
+ MessageAttributes: sns.createStringMessageAttributes(
127
+ _izContext,
128
+ messageAttributes
129
+ ),
130
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
131
+ _izContext,
132
+ TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete
133
+ )
112
134
  };
113
- _izContext.logger.debug("Send message to OutChangeRelationshipComplete :::>", sendMessageToOutChangeRelationshipComplete);
114
- await sns.publishAsync(_izContext, sendMessageToOutChangeRelationshipComplete);
135
+ _izContext.logger.debug(
136
+ 'Send message to OutChangeRelationshipComplete :::>',
137
+ sendMessageToOutChangeRelationshipComplete
138
+ );
139
+ await sns.publishAsync(
140
+ _izContext,
141
+ sendMessageToOutChangeRelationshipComplete
142
+ );
115
143
 
116
144
  //(<afterCheckAwaitingStep>)
117
145
  //(</afterCheckAwaitingStep>)
@@ -134,10 +162,9 @@ export default async function changeRelationshipComplete(
134
162
  returnValue,
135
163
  status,
136
164
  errorsFound
137
- }
138
-
165
+ };
139
166
  } catch (err) {
140
- _izContext.logger.error('error createRelationshipComplete:', err)
141
- throw (err)
167
+ _izContext.logger.error('error createRelationshipComplete:', err);
168
+ throw err;
142
169
  }
143
170
  }