@izara_project/izara-core-generate-service-code 1.0.74 → 1.0.75
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/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/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 +23 -0
- 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/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
|
@@ -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 UpdateComplete from './UpdateComplete_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
|
+
'UpdateCompleteHdrSqs', // 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
|
+
UpdateComplete, // mainFunction that need to invoke.
|
|
80
|
+
'UpdateCompleteHdrSqs', // 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, UpdateComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
2
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
3
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
4
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
5
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
6
|
+
import { consts } from '@izara_project/izara-core-library-service-schemas';
|
|
7
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
8
|
+
|
|
9
|
+
//(<optionalRequire>)
|
|
10
|
+
//(</optionalRequire>)
|
|
11
|
+
|
|
12
|
+
const { TOPIC_NAME_GENERATE_CODE, PREFIX: _constPrefix } = consts;
|
|
13
|
+
const PREFIX = { ASYNC: _constPrefix.updateNode };
|
|
14
|
+
|
|
15
|
+
function empty(value) {
|
|
16
|
+
return (
|
|
17
|
+
value == null ||
|
|
18
|
+
(typeof value === 'object' && Object.keys(value).length === 0)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validateInput(returnValue, status, graphServiceTag, errorsFound) {
|
|
23
|
+
if (!returnValue?.queryResult)
|
|
24
|
+
errorsFound.push(
|
|
25
|
+
'message is not have property queryResult, should be not happen'
|
|
26
|
+
);
|
|
27
|
+
if (!returnValue?.requestParams?.objType)
|
|
28
|
+
errorsFound.push(
|
|
29
|
+
'message is not have property objType, should be not happen'
|
|
30
|
+
);
|
|
31
|
+
if (!returnValue?.requestParams?.objInstanceFull)
|
|
32
|
+
errorsFound.push(
|
|
33
|
+
'message is not have property objInstance, should be not objInstance'
|
|
34
|
+
);
|
|
35
|
+
if (status === 'error' && errorsFound.length === 0)
|
|
36
|
+
errorsFound.push(
|
|
37
|
+
'[invalid]status is error not have errorsFound form graphService'
|
|
38
|
+
);
|
|
39
|
+
if (status === 'complete' && errorsFound.length > 0)
|
|
40
|
+
errorsFound.push(
|
|
41
|
+
'[Invalid] status is complete should be not have errorsFound'
|
|
42
|
+
);
|
|
43
|
+
if (graphServiceTag == null)
|
|
44
|
+
errorsFound.push('[Invalid] graphServerTag is not empty string');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default async function UpdateComplete(
|
|
48
|
+
_izContext,
|
|
49
|
+
requestParams,
|
|
50
|
+
passBackProperties
|
|
51
|
+
//(<additionalParams>)
|
|
52
|
+
//(</additionalParams>)
|
|
53
|
+
) {
|
|
54
|
+
try {
|
|
55
|
+
_izContext.logger.debug('[UpdateComplete] started', {
|
|
56
|
+
requestParams
|
|
57
|
+
});
|
|
58
|
+
const {
|
|
59
|
+
returnValue,
|
|
60
|
+
status,
|
|
61
|
+
errorsFound = [],
|
|
62
|
+
graphServiceTag,
|
|
63
|
+
parentFlowId
|
|
64
|
+
} = requestParams;
|
|
65
|
+
if (empty(returnValue?.requestParams))
|
|
66
|
+
throw new NoRetryError('message not an object');
|
|
67
|
+
validateInput(returnValue, status, graphServiceTag, errorsFound);
|
|
68
|
+
if (errorsFound.length > 0) errorsFound.push(errorsFound.join(','));
|
|
69
|
+
|
|
70
|
+
const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
|
|
71
|
+
parentFlowId,
|
|
72
|
+
PREFIX.ASYNC
|
|
73
|
+
);
|
|
74
|
+
const pending =
|
|
75
|
+
await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
|
|
76
|
+
_izContext,
|
|
77
|
+
awaitingStepId
|
|
78
|
+
);
|
|
79
|
+
_izContext.logger.debug('[UpdateComplete] awaiting step', {
|
|
80
|
+
awaitingStepId,
|
|
81
|
+
pending
|
|
82
|
+
});
|
|
83
|
+
if (!pending) {
|
|
84
|
+
_izContext.logger.warn(
|
|
85
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`
|
|
86
|
+
);
|
|
87
|
+
return { returnValue, status, errorsFound };
|
|
88
|
+
}
|
|
89
|
+
const result =
|
|
90
|
+
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
91
|
+
_izContext,
|
|
92
|
+
pending.pendingStepId,
|
|
93
|
+
awaitingStepId,
|
|
94
|
+
errorsFound
|
|
95
|
+
);
|
|
96
|
+
_izContext.logger.debug(
|
|
97
|
+
'[UpdateComplete] all awaiting steps result',
|
|
98
|
+
{
|
|
99
|
+
isComplete: result.isComplete,
|
|
100
|
+
awaitingStepId,
|
|
101
|
+
pendingStepId: pending.pendingStepId
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (result.isComplete) {
|
|
106
|
+
const nodeResultKey = `returnUpdatedNode`;
|
|
107
|
+
const fallbackNodeResultKey = `returnUpdateNode`;
|
|
108
|
+
const nodeResult =
|
|
109
|
+
returnValue.queryResult[nodeResultKey] ??
|
|
110
|
+
returnValue.queryResult[fallbackNodeResultKey] ??
|
|
111
|
+
{};
|
|
112
|
+
const node = nodeResult.updateNodeResult ?? nodeResult;
|
|
113
|
+
const existsNode =
|
|
114
|
+
node.existsNode && Object.keys(node.existsNode).length
|
|
115
|
+
? {
|
|
116
|
+
objType: returnValue.requestParams.objType,
|
|
117
|
+
objInstanceFull: node.existsNode.objInstanceFull
|
|
118
|
+
}
|
|
119
|
+
: null;
|
|
120
|
+
if (status === 'complete') {
|
|
121
|
+
await Promise.all(
|
|
122
|
+
(pending.listOfRecords ?? []).flatMap((records) =>
|
|
123
|
+
Object.values(records).map(async (record) =>
|
|
124
|
+
dynamodbSharedLib.putItem(
|
|
125
|
+
_izContext,
|
|
126
|
+
await dynamodbSharedLib.tableName(
|
|
127
|
+
_izContext,
|
|
128
|
+
record.tableName,
|
|
129
|
+
record.serviceTag
|
|
130
|
+
),
|
|
131
|
+
{
|
|
132
|
+
...record.objInstanceFull.identifiers,
|
|
133
|
+
...record.objInstanceFull.fields
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const message =
|
|
141
|
+
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
142
|
+
passBackProperties,
|
|
143
|
+
{
|
|
144
|
+
objType: returnValue.requestParams.objType,
|
|
145
|
+
objInstanceFull: node.objInstanceFull,
|
|
146
|
+
relationships: node.relationships,
|
|
147
|
+
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
148
|
+
existsNode,
|
|
149
|
+
status,
|
|
150
|
+
errorsFound
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
const messageAttributes =
|
|
154
|
+
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
155
|
+
passBackProperties,
|
|
156
|
+
{}
|
|
157
|
+
);
|
|
158
|
+
const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
|
|
159
|
+
_izContext,
|
|
160
|
+
TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete
|
|
161
|
+
);
|
|
162
|
+
_izContext.logger.debug('[UpdateComplete] publishing to SNS', {
|
|
163
|
+
TopicArn: topicArn,
|
|
164
|
+
message
|
|
165
|
+
});
|
|
166
|
+
await sns.publishAsync(_izContext, {
|
|
167
|
+
Message: JSON.stringify(message),
|
|
168
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
169
|
+
_izContext,
|
|
170
|
+
messageAttributes
|
|
171
|
+
),
|
|
172
|
+
TopicArn: topicArn
|
|
173
|
+
});
|
|
174
|
+
//(<afterSendMessage>)
|
|
175
|
+
//(</afterSendMessage>)
|
|
176
|
+
}
|
|
177
|
+
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
178
|
+
_izContext,
|
|
179
|
+
awaitingStepId,
|
|
180
|
+
pending.pendingStepId,
|
|
181
|
+
errorsFound
|
|
182
|
+
);
|
|
183
|
+
return { returnValue, status, errorsFound };
|
|
184
|
+
} catch (error) {
|
|
185
|
+
_izContext.logger.error('[UpdateComplete] error:', error);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -122,6 +122,20 @@ export function generatedOwnTopicFlows(flows) {
|
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
export function generatedDsqFlows(flows) {
|
|
126
|
+
if (!Array.isArray(flows)) {
|
|
127
|
+
throw new TypeError('flows must be an array');
|
|
128
|
+
}
|
|
129
|
+
return flows.filter(
|
|
130
|
+
(flow) =>
|
|
131
|
+
typeof flow?.flowTag === 'string' &&
|
|
132
|
+
flow.flowTag !== '' &&
|
|
133
|
+
flow.generatedCodeConfig &&
|
|
134
|
+
Array.isArray(flow.event) &&
|
|
135
|
+
flow.event.includes('dsq')
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
125
139
|
export function upperFirst(value) {
|
|
126
140
|
return value[0].toUpperCase() + value.slice(1);
|
|
127
141
|
}
|
|
@@ -181,7 +195,7 @@ export function customFlowNextSteps(flows) {
|
|
|
181
195
|
if (typeof flow?.flowTag !== 'string' || flow.flowTag === '') {
|
|
182
196
|
continue;
|
|
183
197
|
}
|
|
184
|
-
const roleName =
|
|
198
|
+
const roleName = upperFirst(flow.flowTag);
|
|
185
199
|
const steps = flow.flowSteps ?? [];
|
|
186
200
|
const nextStepsList = [];
|
|
187
201
|
for (const step of steps) {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
customFlowRoleName,
|
|
14
14
|
flowDsqSteps,
|
|
15
15
|
flowExtTopicSteps,
|
|
16
|
+
generatedDsqFlows,
|
|
16
17
|
generatedOwnTopicFlows,
|
|
17
18
|
supportedCustomFlows,
|
|
18
19
|
upperFirst
|
|
@@ -94,6 +95,7 @@ export function customFlowApplicationManagedPaths(
|
|
|
94
95
|
}),
|
|
95
96
|
...(supportedCustomFlows(flows).length > 0 ||
|
|
96
97
|
generatedOwnTopicFlows(flows).length > 0 ||
|
|
98
|
+
generatedDsqFlows(flows).length > 0 ||
|
|
97
99
|
flowExtTopicSteps(flows).length > 0 ||
|
|
98
100
|
flowDsqSteps(flows).length > 0 ||
|
|
99
101
|
includeYaml
|
|
@@ -88,7 +88,7 @@ export default async function <%- typeof functionName !== 'undefined' ? function
|
|
|
88
88
|
createFlowTypeConcat(_izContext, {
|
|
89
89
|
flowTag: '<%= flowTag %>',
|
|
90
90
|
serviceTag: process.env.iz_serviceTag
|
|
91
|
-
})
|
|
91
|
+
}),
|
|
92
92
|
//(<storedCacheConfig>)
|
|
93
93
|
//(</storedCacheConfig>)
|
|
94
94
|
);
|
|
@@ -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
|
+
});
|