@izara_project/izara-core-generate-service-code 1.0.74 → 1.0.76
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/compile/loadSchemas.js +36 -30
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +2 -4
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +12 -2
- package/src/emit/coreFunction/templates/InitialSetupRunner.ejs +5 -3
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +13 -6
- package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +1 -1
- package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
- package/src/emit/custom/customFlows.js +15 -1
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +2 -0
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +20 -5
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +58 -43
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +68 -20
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +69 -20
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +69 -20
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
- package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +91 -87
- package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +90 -86
- package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +85 -81
- package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +2 -0
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
- package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +93 -89
- package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +85 -81
- package/src/emit/resource/emitResourceArtifacts.js +36 -2
- package/src/emit/shared/templates/FindData_Main.ejs +1 -1
- package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
- package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
- package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
- package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
- package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
- package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
- package/src/emit/system/templates/Register_Main.ejs +148 -0
- package/src/output/mergeHooks.js +4 -3
- package/test/customFlowApplicationArtifacts.test.js +16 -5
- package/test/publicApi.test.js +21 -0
- package/test/relationshipApplicationArtifacts.test.js +1 -1
- package/test/resourceArtifacts.test.js +20 -0
|
@@ -21,11 +21,16 @@ export async function emitRbacApplicationArtifacts(objects) {
|
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const hasSelfRbac = objects.some(hasSelfRbacAddOn);
|
|
24
25
|
const handlers = await Promise.all([
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
...(hasSelfRbac
|
|
27
|
+
? [
|
|
28
|
+
createTargetRoleHandler(),
|
|
29
|
+
...LIST_DEFINITIONS.map(createListHandler),
|
|
30
|
+
...MUTATION_DEFINITIONS.map(createMutationHandler),
|
|
31
|
+
...USER_ROLE_MUTATIONS.map(createUserRoleMutationHandler)
|
|
32
|
+
]
|
|
33
|
+
: []),
|
|
29
34
|
...objects.filter(hasRbacAddOn).map(createUserRbacFlowHandler)
|
|
30
35
|
]);
|
|
31
36
|
return [
|
|
@@ -83,49 +88,42 @@ const USER_ROLE_MUTATIONS = [
|
|
|
83
88
|
{ flowTag: 'DeleteUserFromRole', operation: 'Delete' }
|
|
84
89
|
];
|
|
85
90
|
|
|
91
|
+
const STATIC_RBAC_APPLICATION_PATHS = [
|
|
92
|
+
'app/src/generatedCode/FlowRbac/CreateTargetRole/source/CreateTargetRole_Main.js',
|
|
93
|
+
'app/src/generatedCode/FlowRbac/CreateTargetRole/source/CreateTargetRole_HdrSqs.js',
|
|
94
|
+
'app/src/generatedCode/FlowRbac/CreateTargetRole/source/CreateTargetRole_WbsMain.js',
|
|
95
|
+
'app/src/generatedCode/FlowRbac/CreateTargetRole/source/CreateTargetRole_HdrWbs.js',
|
|
96
|
+
...LIST_DEFINITIONS.flatMap(({ flowTag }) => [
|
|
97
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_Main.js`,
|
|
98
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
99
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrApi.js`
|
|
100
|
+
]),
|
|
101
|
+
...MUTATION_DEFINITIONS.flatMap(({ flowTag }) => [
|
|
102
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_Main.js`,
|
|
103
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
104
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_WbsMain.js`,
|
|
105
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrWbs.js`
|
|
106
|
+
]),
|
|
107
|
+
...USER_ROLE_MUTATIONS.flatMap(({ flowTag }) => [
|
|
108
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_Main.js`,
|
|
109
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
110
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_WbsMain.js`,
|
|
111
|
+
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrWbs.js`
|
|
112
|
+
]),
|
|
113
|
+
FLOW_RBAC_YAML_PATH
|
|
114
|
+
];
|
|
115
|
+
|
|
86
116
|
export function rbacApplicationManagedPaths(objects = []) {
|
|
87
117
|
if (!Array.isArray(objects)) {
|
|
88
118
|
throw new TypeError('objects must be an array');
|
|
89
119
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
98
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrApi.js`
|
|
99
|
-
]),
|
|
100
|
-
...MUTATION_DEFINITIONS.flatMap(({ flowTag }) => [
|
|
101
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_Main.js`,
|
|
102
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
103
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_WbsMain.js`,
|
|
104
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrWbs.js`
|
|
105
|
-
]),
|
|
106
|
-
...USER_ROLE_MUTATIONS.flatMap(({ flowTag }) => [
|
|
107
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_Main.js`,
|
|
108
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrSqs.js`,
|
|
109
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_WbsMain.js`,
|
|
110
|
-
`app/src/generatedCode/FlowRbac/${flowTag}/source/${flowTag}_HdrWbs.js`
|
|
111
|
-
]),
|
|
112
|
-
...objects.filter(hasRbacAddOn).flatMap((object) => {
|
|
113
|
-
const flowTag = rbacFlowTag(object);
|
|
114
|
-
const sourcePath = `app/src/generatedCode/FlowRbac/${flowTag}/source`;
|
|
115
|
-
return [
|
|
116
|
-
`${sourcePath}/${flowTag}_Main.js`,
|
|
117
|
-
`${sourcePath}/${flowTag}_HdrSqs.js`
|
|
118
|
-
];
|
|
119
|
-
}),
|
|
120
|
-
FLOW_RBAC_YAML_PATH
|
|
121
|
-
];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function hasRbacAddOn(object) {
|
|
125
|
-
return (
|
|
126
|
-
Array.isArray(object?.addOnDataStructure) &&
|
|
127
|
-
object.addOnDataStructure.some((addOn) => addOn?.type === 'rbac')
|
|
128
|
-
);
|
|
120
|
+
const rbacObjects = objects.filter(hasRbacAddOn);
|
|
121
|
+
const sourcePaths = rbacObjects.flatMap((object) => {
|
|
122
|
+
const flowTag = rbacFlowTag(object);
|
|
123
|
+
const sourcePath = `app/src/generatedCode/FlowRbac/${flowTag}/source`;
|
|
124
|
+
return [`${sourcePath}/${flowTag}_Main.js`, `${sourcePath}/${flowTag}_HdrSqs.js`];
|
|
125
|
+
});
|
|
126
|
+
return [...STATIC_RBAC_APPLICATION_PATHS, ...sourcePaths];
|
|
129
127
|
}
|
|
130
128
|
|
|
131
129
|
async function createTargetRoleHandler() {
|
|
@@ -367,3 +365,20 @@ async function renderTemplate(templateUrl, templateName, data) {
|
|
|
367
365
|
data
|
|
368
366
|
);
|
|
369
367
|
}
|
|
368
|
+
|
|
369
|
+
function hasSelfRbacAddOn(object) {
|
|
370
|
+
return (
|
|
371
|
+
Array.isArray(object?.addOnDataStructure) &&
|
|
372
|
+
object.addOnDataStructure.some((addOn) => addOn?.type === 'rbac')
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function hasRbacAddOn(object) {
|
|
377
|
+
const selfHasRbac = hasSelfRbacAddOn(object);
|
|
378
|
+
const belongToHasRbac =
|
|
379
|
+
Array.isArray(object?.belongToSchema?.addOnDataStructure) &&
|
|
380
|
+
object.belongToSchema.addOnDataStructure.some(
|
|
381
|
+
(addOn) => addOn?.type === 'rbac'
|
|
382
|
+
);
|
|
383
|
+
return selfHasRbac || belongToHasRbac;
|
|
384
|
+
}
|
|
@@ -15,33 +15,81 @@ 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
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler as middleware,
|
|
20
|
+
validatorSchema
|
|
21
|
+
} from '@izara_project/izara-middleware';
|
|
19
22
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
23
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
25
|
+
|
|
21
26
|
import CreateTargetRole from './CreateTargetRole_Main.js';
|
|
22
27
|
|
|
28
|
+
// validate event properties in body.Message of sqs event
|
|
23
29
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
let perRecordsValidatorSchema = {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
37
|
+
try {
|
|
38
|
+
let recordPromises = [];
|
|
39
|
+
|
|
40
|
+
// loop each record and send to mainFunction
|
|
41
|
+
await Promise.all(
|
|
42
|
+
event.Records.map(async (record) => {
|
|
43
|
+
// promise.all for map() function
|
|
44
|
+
|
|
45
|
+
let passOnProperties = [];
|
|
46
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
47
|
+
|
|
48
|
+
// validate message (and MessageAttributes)
|
|
49
|
+
await recordHandlerSharedLib.validateRecord(
|
|
50
|
+
record, // one record will send to mainFunction
|
|
51
|
+
'CreateTargetRoleHdrSqs', // queue name that need to retry or send to dlq
|
|
52
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
56
|
+
passOnProperties.push(record.body.Message);
|
|
57
|
+
passOnProperties.push(
|
|
40
58
|
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
41
59
|
record.body.Message
|
|
42
60
|
)
|
|
43
|
-
|
|
61
|
+
);
|
|
62
|
+
record._izContext.logger.debug(
|
|
63
|
+
'passOnProperties in handler',
|
|
64
|
+
passOnProperties
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
68
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
69
|
+
record, // one record will send to mainFunction
|
|
70
|
+
CreateTargetRole, // mainFunction that need to invoke.
|
|
71
|
+
'CreateTargetRoleHdrSqs', // queue name that need to retry or send to dlq
|
|
72
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
73
|
+
);
|
|
74
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
75
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
80
|
+
try {
|
|
81
|
+
// --- main await all promises
|
|
82
|
+
await Promise.all(recordPromises); // await all promises
|
|
83
|
+
|
|
84
|
+
return event.Records; // return all for local testing
|
|
85
|
+
} catch {
|
|
86
|
+
Logger.debug(
|
|
87
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
44
88
|
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
)
|
|
89
|
+
}
|
|
90
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
91
|
+
} catch (err) {
|
|
92
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -15,32 +15,81 @@ 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
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler as middleware,
|
|
20
|
+
validatorSchema
|
|
21
|
+
} from '@izara_project/izara-middleware';
|
|
19
22
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
23
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
25
|
+
|
|
21
26
|
import <%- flowTag %> from './<%- flowTag %>_Main.js';
|
|
22
27
|
|
|
28
|
+
// validate event properties in body.Message of sqs event
|
|
23
29
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
|
|
31
|
+
let perRecordsValidatorSchema = {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
37
|
+
try {
|
|
38
|
+
let recordPromises = [];
|
|
39
|
+
|
|
40
|
+
// loop each record and send to mainFunction
|
|
41
|
+
await Promise.all(
|
|
42
|
+
event.Records.map(async (record) => {
|
|
43
|
+
// promise.all for map() function
|
|
44
|
+
|
|
45
|
+
let passOnProperties = [];
|
|
46
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
47
|
+
|
|
48
|
+
// validate message (and MessageAttributes)
|
|
49
|
+
await recordHandlerSharedLib.validateRecord(
|
|
50
|
+
record, // one record will send to mainFunction
|
|
51
|
+
'<%- flowTag %>HdrSqs', // queue name that need to retry or send to dlq
|
|
52
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
56
|
+
passOnProperties.push(record.body.Message);
|
|
57
|
+
passOnProperties.push(
|
|
39
58
|
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
40
59
|
record.body.Message
|
|
41
60
|
)
|
|
42
|
-
|
|
61
|
+
);
|
|
62
|
+
record._izContext.logger.debug(
|
|
63
|
+
'passOnProperties in handler',
|
|
64
|
+
passOnProperties
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
68
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
69
|
+
record, // one record will send to mainFunction
|
|
70
|
+
<%- flowTag %>, // mainFunction that need to invoke.
|
|
71
|
+
'<%- flowTag %>HdrSqs', // queue name that need to retry or send to dlq
|
|
72
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
73
|
+
);
|
|
74
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
75
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
80
|
+
try {
|
|
81
|
+
// --- main await all promises
|
|
82
|
+
await Promise.all(recordPromises); // await all promises
|
|
83
|
+
|
|
84
|
+
return event.Records; // return all for local testing
|
|
85
|
+
} catch {
|
|
86
|
+
Logger.debug(
|
|
87
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
43
88
|
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
)
|
|
89
|
+
}
|
|
90
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
91
|
+
} catch (err) {
|
|
92
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -15,32 +15,81 @@ 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
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler as middleware,
|
|
20
|
+
validatorSchema
|
|
21
|
+
} from '@izara_project/izara-middleware';
|
|
19
22
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
23
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
25
|
+
|
|
21
26
|
import <%- flowTag %> from './<%- flowTag %>_Main.js';
|
|
22
27
|
|
|
28
|
+
// validate event properties in body.Message of sqs event
|
|
23
29
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
|
|
31
|
+
let perRecordsValidatorSchema = {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
37
|
+
try {
|
|
38
|
+
let recordPromises = [];
|
|
39
|
+
|
|
40
|
+
// loop each record and send to mainFunction
|
|
41
|
+
await Promise.all(
|
|
42
|
+
event.Records.map(async (record) => {
|
|
43
|
+
// promise.all for map() function
|
|
44
|
+
|
|
45
|
+
let passOnProperties = [];
|
|
46
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
47
|
+
|
|
48
|
+
// validate message (and MessageAttributes)
|
|
49
|
+
await recordHandlerSharedLib.validateRecord(
|
|
50
|
+
record, // one record will send to mainFunction
|
|
51
|
+
'<%- flowTag %>HdrSqs', // queue name that need to retry or send to dlq
|
|
52
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
56
|
+
passOnProperties.push(record.body.Message);
|
|
57
|
+
passOnProperties.push(
|
|
39
58
|
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
40
59
|
record.body.Message
|
|
41
60
|
)
|
|
42
|
-
|
|
61
|
+
);
|
|
62
|
+
record._izContext.logger.debug(
|
|
63
|
+
'passOnProperties in handler',
|
|
64
|
+
passOnProperties
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
68
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
69
|
+
record, // one record will send to mainFunction
|
|
70
|
+
<%- flowTag %>, // mainFunction that need to invoke.
|
|
71
|
+
'<%- flowTag %>HdrSqs', // queue name that need to retry or send to dlq
|
|
72
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
73
|
+
);
|
|
74
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
75
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
80
|
+
try {
|
|
81
|
+
// --- main await all promises
|
|
82
|
+
await Promise.all(recordPromises); // await all promises
|
|
83
|
+
|
|
84
|
+
return event.Records; // return all for local testing
|
|
85
|
+
} catch {
|
|
86
|
+
Logger.debug(
|
|
87
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
43
88
|
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
)
|
|
89
|
+
}
|
|
90
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
91
|
+
} catch (err) {
|
|
92
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -41,6 +41,15 @@ function createDynamicRelationshipFlow(action) {
|
|
|
41
41
|
const flowSteps = [
|
|
42
42
|
{
|
|
43
43
|
stepName: 'start',
|
|
44
|
+
...(outputTopic
|
|
45
|
+
? {
|
|
46
|
+
nextSteps: [
|
|
47
|
+
{
|
|
48
|
+
stepName: 'Complete'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
44
53
|
properties: [],
|
|
45
54
|
messageAttributes: MESSAGE_ATTRIBUTES,
|
|
46
55
|
...(outputTopic
|
|
@@ -58,7 +67,18 @@ function createDynamicRelationshipFlow(action) {
|
|
|
58
67
|
flowSteps.push({
|
|
59
68
|
stepName: 'Complete',
|
|
60
69
|
event: ['extTopic'],
|
|
61
|
-
|
|
70
|
+
previousSteps: [
|
|
71
|
+
{
|
|
72
|
+
stepName: 'start'
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
properties: [
|
|
76
|
+
'returnValue',
|
|
77
|
+
'parentFlowId',
|
|
78
|
+
'status',
|
|
79
|
+
'errorsFound',
|
|
80
|
+
'graphServiceTag'
|
|
81
|
+
],
|
|
62
82
|
messageAttributes: MESSAGE_ATTRIBUTES
|
|
63
83
|
});
|
|
64
84
|
}
|
|
@@ -158,7 +158,7 @@ async function emitAction(action, relationships, flows, serviceTag) {
|
|
|
158
158
|
},
|
|
159
159
|
{
|
|
160
160
|
path: `${source}/${complete}_HdrSqs.js`,
|
|
161
|
-
content: await
|
|
161
|
+
content: await render(`${action}Complete_HdrSqs.ejs`, {
|
|
162
162
|
...shared,
|
|
163
163
|
flowStepName: 'Complete',
|
|
164
164
|
mainFileName: `${complete}_Main`,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import ChangeRelationshipComplete from './ChangeRelationshipComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'ChangeRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
ChangeRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'ChangeRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, ChangeRelationshipComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|