@izara_project/izara-core-generate-service-code 1.0.73 → 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/coreFunction/emitCoreFunctionArtifacts.js +3 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +100 -28
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +2 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +2 -0
- 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 +56 -0
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +24 -9
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -1
- package/src/emit/function/functionYamlArtifact.js +8 -3
- 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 +99 -100
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +5 -14
- package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +98 -99
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +7 -16
- package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +93 -85
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +6 -24
- package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +10 -4
- 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 +101 -104
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +6 -15
- package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +92 -110
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +6 -15
- package/src/emit/resource/emitResourceArtifacts.js +25 -1
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +3 -0
- package/src/emit/shared/templates/FindData_Main.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -1
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -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/emit/system/templates/WebSocketComplete_Yaml.ejs +2 -0
- package/test/crudApplicationArtifacts.test.js +22 -0
- package/test/customFlowApplicationArtifacts.test.js +147 -1
- package/test/functionYamlArtifact.test.js +5 -2
- package/test/publicApi.test.js +50 -0
- package/test/relationshipApplicationArtifacts.test.js +42 -8
- package/test/resourceArtifacts.test.js +54 -16
|
@@ -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 DeleteComplete from './DeleteComplete_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
|
+
'DeleteCompleteHdrSqs', // 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
|
+
DeleteComplete, // mainFunction that need to invoke.
|
|
80
|
+
'DeleteCompleteHdrSqs', // 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, DeleteComplete_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 } = consts;
|
|
13
|
+
const PREFIX = { ASYNC: 'DeleteAsyncEndpoint' };
|
|
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 DeleteComplete(
|
|
48
|
+
_izContext,
|
|
49
|
+
requestParams,
|
|
50
|
+
passBackProperties
|
|
51
|
+
//(<additionalParams>)
|
|
52
|
+
//(</additionalParams>)
|
|
53
|
+
) {
|
|
54
|
+
try {
|
|
55
|
+
_izContext.logger.debug('[DeleteComplete] 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('[DeleteComplete] 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
|
+
'[DeleteComplete] 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 = `returnDeletedNode`;
|
|
107
|
+
const fallbackNodeResultKey = `returnDeleteNode`;
|
|
108
|
+
const nodeResult =
|
|
109
|
+
returnValue.queryResult[nodeResultKey] ??
|
|
110
|
+
returnValue.queryResult[fallbackNodeResultKey] ??
|
|
111
|
+
{};
|
|
112
|
+
const node = nodeResult.deleteNodeResult ?? 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.outDeleteNodeComplete
|
|
161
|
+
);
|
|
162
|
+
_izContext.logger.debug('[DeleteComplete] 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('[DeleteComplete] error:', error);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -143,7 +143,7 @@ export default async function <%- action %>Complete(
|
|
|
143
143
|
objType: returnValue.requestParams.objType,
|
|
144
144
|
objInstanceFull: node.objInstanceFull,
|
|
145
145
|
relationships: node.relationships,
|
|
146
|
-
parentFlowId: returnValue
|
|
146
|
+
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
147
147
|
existsNode,
|
|
148
148
|
status,
|
|
149
149
|
errorsFound
|
|
@@ -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
|
}
|
|
@@ -159,3 +173,45 @@ export function triggerCacheQueueNames(flow) {
|
|
|
159
173
|
}
|
|
160
174
|
return queues;
|
|
161
175
|
}
|
|
176
|
+
|
|
177
|
+
function _stepNextSteps(step) {
|
|
178
|
+
if (!step || !Array.isArray(step.nextSteps)) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
return step.nextSteps.filter(
|
|
182
|
+
(item) =>
|
|
183
|
+
typeof item === 'object' &&
|
|
184
|
+
item !== null &&
|
|
185
|
+
typeof item.targetType === 'string'
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function customFlowNextSteps(flows) {
|
|
190
|
+
if (!Array.isArray(flows)) {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
const results = [];
|
|
194
|
+
for (const flow of flows) {
|
|
195
|
+
if (typeof flow?.flowTag !== 'string' || flow.flowTag === '') {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const roleName = upperFirst(flow.flowTag);
|
|
199
|
+
const steps = flow.flowSteps ?? [];
|
|
200
|
+
const nextStepsList = [];
|
|
201
|
+
for (const step of steps) {
|
|
202
|
+
const items = _stepNextSteps(step);
|
|
203
|
+
for (const item of items) {
|
|
204
|
+
nextStepsList.push(item);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (nextStepsList.length > 0) {
|
|
208
|
+
results.push({
|
|
209
|
+
flowTag: flow.flowTag,
|
|
210
|
+
roleName,
|
|
211
|
+
nextSteps: nextStepsList
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return results;
|
|
216
|
+
}
|
|
217
|
+
|