@izara_project/izara-core-generate-service-code 1.0.78 → 1.0.80
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 +2 -2
- package/src/compile/flowValidator.js +163 -0
- package/src/compile/loadSchemas.js +15 -5
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +137 -7
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +137 -17
- package/src/emit/crud/crudActionPlan.js +82 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +169 -112
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -65
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateComplete_Main.ejs +8 -3
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +90 -513
- package/src/emit/crud/templates/CreateLogicalLib.ejs +541 -0
- package/src/emit/crud/templates/DeleteComplete_Main.ejs +8 -3
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +93 -203
- package/src/emit/crud/templates/DeleteLogicalLib.ejs +213 -0
- package/src/emit/crud/templates/FlowEndpointRbacCallback_Main.ejs +217 -0
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +118 -37
- package/src/emit/crud/templates/UpdateComplete_Main.ejs +8 -3
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +92 -444
- package/src/emit/crud/templates/UpdateLogicalLib.ejs +477 -0
- package/src/emit/custom/customFlows.js +27 -2
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +1 -2
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +10 -3
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -2
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +3 -9
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +21 -16
- package/src/emit/rbac/rbacFlowTag.js +2 -7
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +148 -21
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +4 -2
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +7 -2
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +6 -2
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +7 -2
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +6 -2
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +7 -2
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +6 -2
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +7 -2
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +6 -2
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +7 -2
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +6 -2
- package/src/emit/resource/emitResourceArtifacts.js +149 -79
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +4 -4
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +31 -5
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +21 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -2
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -2
- package/src/emit/systemText/emitSystemTextSchemas.js +246 -0
- package/src/emit/systemText/templates/SystemTextSchemas.ejs +10 -0
- package/src/generate.js +55 -8
- package/test/crudApplicationArtifacts.test.js +158 -19
- package/test/customFlowApplicationArtifacts.test.js +307 -16
- package/test/dynamicCrudFlowSchemas.test.js +150 -14
- package/test/dynamicRbacFlowSchemas.test.js +2 -2
- package/test/dynamicRelationshipFlowSchemas.test.js +1 -1
- package/test/graphDrivenFlowSchema.test.js +257 -0
- package/test/publicApi.test.js +14 -5
- package/test/resourceArtifacts.test.js +66 -19
- package/test/systemTextSchemas.test.js +154 -0
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +0 -99
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +0 -99
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +0 -174
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +0 -187
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +0 -99
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +0 -47
|
@@ -1,99 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2021 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 {
|
|
19
|
-
objectHash as hash,
|
|
20
|
-
identifierUuid
|
|
21
|
-
} from '@izara_project/izara-shared-core';
|
|
22
|
-
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
23
|
-
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
24
|
-
import {
|
|
25
|
-
utils,
|
|
26
|
-
createNodeLib,
|
|
27
|
-
uploadUseCase,
|
|
28
|
-
consts,
|
|
29
|
-
getObjectSchema,
|
|
30
|
-
identifiersObject,
|
|
31
|
-
dataDetailsLib
|
|
32
|
-
} from '@izara_project/izara-core-library-service-schemas';
|
|
33
|
-
|
|
34
|
-
const { createObjType, firstLetterUpperCase } = utils;
|
|
35
|
-
|
|
36
|
-
import { <%- flowTag %>MainLogical } from './<%- upperCaseFlowTag %>_Main.js';
|
|
37
|
-
|
|
38
|
-
//(<optionalRequire>)
|
|
39
|
-
//(</optionalRequire>)
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Handles callback after beforeLogical phase — verifies awaitingStep then proceeds to <%- flowTag %>MainLogical
|
|
43
|
-
* @param {Object} _izContext - Context object with logger
|
|
44
|
-
* @param {Object} requestParams - { fieldNames, relationships[] }
|
|
45
|
-
* @param {Object} callingFlowConfig - Calling flow configuration
|
|
46
|
-
* @returns {Promise<Object>}
|
|
47
|
-
*/
|
|
48
|
-
export default async function <%- flowTag %>BeforeLogicalMain(
|
|
49
|
-
_izContext,
|
|
50
|
-
requestParams,
|
|
51
|
-
flowTag,
|
|
52
|
-
callingFlowConfig = {}
|
|
53
|
-
) {
|
|
54
|
-
try {
|
|
55
|
-
_izContext.logger.debug('<%- flowTag %>BeforeLogicalMain:', {
|
|
56
|
-
requestParams,
|
|
57
|
-
flowTag,
|
|
58
|
-
callingFlowConfig
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// ── Build identifiers ──
|
|
62
|
-
const objType = createObjType(requestParams.returnRequestParams.objectType);
|
|
63
|
-
const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
64
|
-
_izContext,
|
|
65
|
-
objType
|
|
66
|
-
);
|
|
67
|
-
const objectSchemas =
|
|
68
|
-
uploadUseCase.generateObjectSchemaForCombineFieldNames(
|
|
69
|
-
_izContext,
|
|
70
|
-
objectSchema
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const identifiers = {};
|
|
74
|
-
for (const fieldName of objectSchemas.identifierFieldNames) {
|
|
75
|
-
if (
|
|
76
|
-
requestParams.returnRequestParams.fieldNames?.hasOwnProperty(fieldName)
|
|
77
|
-
) {
|
|
78
|
-
identifiers[fieldName] =
|
|
79
|
-
requestParams.returnRequestParams.fieldNames[fieldName];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
_izContext.logger.debug('identifiers:::: ', identifiers);
|
|
83
|
-
|
|
84
|
-
// build parentFlowId
|
|
85
|
-
<%_ if (flowTag === 'Create') { _%>
|
|
86
|
-
const parentFlowId = identifierUuid();
|
|
87
|
-
<%_ } else { _%>
|
|
88
|
-
const parentFlowId = hash(identifiers);
|
|
89
|
-
<%_ } _%>
|
|
90
|
-
|
|
91
|
-
// ── Verify + remove awaitingStep ──────────────────────────────────────────
|
|
92
|
-
const awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
93
|
-
parentFlowId,
|
|
94
|
-
`beforeLogical_${requestParams.returnRequestParams.objectType}_${flowTag}`
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
const pendingStepId = asyncFlowSharedLib.createPendingStepId(
|
|
98
|
-
parentFlowId,
|
|
99
|
-
`beforeLogical_${requestParams.returnRequestParams.objectType}`
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
_izContext.logger.debug('createBeforeLogicalMain: checking awaitingStep', {
|
|
103
|
-
awaitingStepId,
|
|
104
|
-
pendingStepId
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const [allComplete, collectedAttributes, errorsFound] =
|
|
108
|
-
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
109
|
-
_izContext,
|
|
110
|
-
pendingStepId,
|
|
111
|
-
awaitingStepId,
|
|
112
|
-
requestParams.errorsFound,
|
|
113
|
-
{
|
|
114
|
-
returnValue: requestParams.returnValue
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
_izContext.logger.debug('validate step::: ', {
|
|
119
|
-
allComplete,
|
|
120
|
-
collectedAttributes,
|
|
121
|
-
errorsFound
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (allComplete === false) {
|
|
125
|
-
_izContext.logger.debug(
|
|
126
|
-
'createBeforeLogicalMain: pendingStepId not completed',
|
|
127
|
-
{
|
|
128
|
-
pendingStepId
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
return 'all task not completed';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
await asyncFlowSharedLib.clearAllAwaitingSteps(_izContext, pendingStepId);
|
|
136
|
-
|
|
137
|
-
_izContext.logger.debug('createBeforeLogicalMain: pendingStepId removed', {
|
|
138
|
-
pendingStepId
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const beforeLogicalResults = Object.fromEntries(
|
|
142
|
-
Object.entries(collectedAttributes).map(([stepId, attrs]) => {
|
|
143
|
-
const flowTag = stepId.split('_').pop();
|
|
144
|
-
return [flowTag, attrs];
|
|
145
|
-
})
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
callingFlowConfig.callingFlow ===
|
|
150
|
-
`${process.env.iz_resourcePrefix}CreateBeforeLogical`
|
|
151
|
-
) {
|
|
152
|
-
callingFlowConfig =
|
|
153
|
-
callingFlowConfig.callingFlowProperties.parentPassBackProperties;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
_izContext.logger.debug(
|
|
157
|
-
'[createBeforeLogicalMain] callingFlowConfig',
|
|
158
|
-
callingFlowConfig
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
//(<beforeLogicalMain>)
|
|
162
|
-
//(</beforeLogicalMain>)
|
|
163
|
-
|
|
164
|
-
return await createMainLogical(
|
|
165
|
-
_izContext,
|
|
166
|
-
requestParams.returnRequestParams,
|
|
167
|
-
callingFlowConfig,
|
|
168
|
-
errorsFound,
|
|
169
|
-
beforeLogicalResults
|
|
170
|
-
);
|
|
171
|
-
} catch (err) {
|
|
172
|
-
throw err;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
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
|
-
const { TOPIC_NAME_GENERATE_CODE, PREFIX: _constPrefix } = consts;
|
|
10
|
-
<%_ if (action === 'Update') { _%>
|
|
11
|
-
const PREFIX = { ASYNC: _constPrefix.updateNode };
|
|
12
|
-
<%_ } else { _%>
|
|
13
|
-
const PREFIX = { ASYNC: '<%- action %>AsyncEndpoint' };
|
|
14
|
-
<%_ } _%>
|
|
15
|
-
|
|
16
|
-
function empty(value) {
|
|
17
|
-
return (
|
|
18
|
-
value == null ||
|
|
19
|
-
(typeof value === 'object' && Object.keys(value).length === 0)
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function validateInput(returnValue, status, graphServiceTag, errorsFound) {
|
|
24
|
-
if (!returnValue?.queryResult)
|
|
25
|
-
errorsFound.push(
|
|
26
|
-
'message is not have property queryResult, should be not happen'
|
|
27
|
-
);
|
|
28
|
-
if (!returnValue?.requestParams?.objType)
|
|
29
|
-
errorsFound.push(
|
|
30
|
-
'message is not have property objType, should be not happen'
|
|
31
|
-
);
|
|
32
|
-
if (!returnValue?.requestParams?.objInstanceFull)
|
|
33
|
-
errorsFound.push(
|
|
34
|
-
'message is not have property objInstance, should be not objInstance'
|
|
35
|
-
);
|
|
36
|
-
if (status === 'error' && errorsFound.length === 0)
|
|
37
|
-
errorsFound.push(
|
|
38
|
-
'[invalid]status is error not have errorsFound form graphService'
|
|
39
|
-
);
|
|
40
|
-
if (status === 'complete' && errorsFound.length > 0)
|
|
41
|
-
errorsFound.push(
|
|
42
|
-
'[Invalid] status is complete should be not have errorsFound'
|
|
43
|
-
);
|
|
44
|
-
if (graphServiceTag == null)
|
|
45
|
-
errorsFound.push('[Invalid] graphServerTag is not empty string');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default async function <%- action %>Complete(
|
|
49
|
-
_izContext,
|
|
50
|
-
requestParams,
|
|
51
|
-
passBackProperties
|
|
52
|
-
) {
|
|
53
|
-
try {
|
|
54
|
-
_izContext.logger.debug('[<%- action %>Complete] started', {
|
|
55
|
-
requestParams
|
|
56
|
-
});
|
|
57
|
-
const {
|
|
58
|
-
returnValue,
|
|
59
|
-
status,
|
|
60
|
-
errorsFound = [],
|
|
61
|
-
graphServiceTag,
|
|
62
|
-
parentFlowId
|
|
63
|
-
} = requestParams;
|
|
64
|
-
if (empty(returnValue?.requestParams))
|
|
65
|
-
throw new NoRetryError('message not an object');
|
|
66
|
-
validateInput(returnValue, status, graphServiceTag, errorsFound);
|
|
67
|
-
if (errorsFound.length > 0) errorsFound.push(errorsFound.join(','));
|
|
68
|
-
|
|
69
|
-
const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
|
|
70
|
-
parentFlowId,
|
|
71
|
-
PREFIX.ASYNC
|
|
72
|
-
);
|
|
73
|
-
const pending =
|
|
74
|
-
await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
|
|
75
|
-
_izContext,
|
|
76
|
-
awaitingStepId
|
|
77
|
-
);
|
|
78
|
-
_izContext.logger.debug('[<%- action %>Complete] awaiting step', {
|
|
79
|
-
awaitingStepId,
|
|
80
|
-
pending
|
|
81
|
-
});
|
|
82
|
-
if (!pending) {
|
|
83
|
-
_izContext.logger.warn(
|
|
84
|
-
`No pending step found for awaitingStepId: ${awaitingStepId}`
|
|
85
|
-
);
|
|
86
|
-
return { returnValue, status, errorsFound };
|
|
87
|
-
}
|
|
88
|
-
const result =
|
|
89
|
-
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
90
|
-
_izContext,
|
|
91
|
-
pending.pendingStepId,
|
|
92
|
-
awaitingStepId,
|
|
93
|
-
errorsFound
|
|
94
|
-
);
|
|
95
|
-
_izContext.logger.debug(
|
|
96
|
-
'[<%- action %>Complete] all awaiting steps result',
|
|
97
|
-
{
|
|
98
|
-
isComplete: result.isComplete,
|
|
99
|
-
awaitingStepId,
|
|
100
|
-
pendingStepId: pending.pendingStepId
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
if (result.isComplete) {
|
|
105
|
-
const nodeResultKey = `return<%- action %>dNode`;
|
|
106
|
-
const fallbackNodeResultKey = `return<%- action %>Node`;
|
|
107
|
-
const nodeResult =
|
|
108
|
-
returnValue.queryResult[nodeResultKey] ??
|
|
109
|
-
returnValue.queryResult[fallbackNodeResultKey] ??
|
|
110
|
-
{};
|
|
111
|
-
const node = nodeResult[`<%- action.toLowerCase() %>NodeResult`] ?? nodeResult;
|
|
112
|
-
const existsNode =
|
|
113
|
-
node.existsNode && Object.keys(node.existsNode).length
|
|
114
|
-
? {
|
|
115
|
-
objType: returnValue.requestParams.objType,
|
|
116
|
-
objInstanceFull: node.existsNode.objInstanceFull
|
|
117
|
-
}
|
|
118
|
-
: null;
|
|
119
|
-
if (status === 'complete') {
|
|
120
|
-
await Promise.all(
|
|
121
|
-
(pending.listOfRecords ?? []).flatMap((records) =>
|
|
122
|
-
Object.values(records).map(async (record) =>
|
|
123
|
-
dynamodbSharedLib.putItem(
|
|
124
|
-
_izContext,
|
|
125
|
-
await dynamodbSharedLib.tableName(
|
|
126
|
-
_izContext,
|
|
127
|
-
record.tableName,
|
|
128
|
-
record.serviceTag
|
|
129
|
-
),
|
|
130
|
-
{
|
|
131
|
-
...record.objInstanceFull.identifiers,
|
|
132
|
-
...record.objInstanceFull.fields
|
|
133
|
-
}
|
|
134
|
-
)
|
|
135
|
-
)
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
const message =
|
|
140
|
-
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
141
|
-
passBackProperties,
|
|
142
|
-
{
|
|
143
|
-
objType: returnValue.requestParams.objType,
|
|
144
|
-
objInstanceFull: node.objInstanceFull,
|
|
145
|
-
relationships: node.relationships,
|
|
146
|
-
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
147
|
-
existsNode,
|
|
148
|
-
status,
|
|
149
|
-
errorsFound
|
|
150
|
-
}
|
|
151
|
-
);
|
|
152
|
-
const messageAttributes =
|
|
153
|
-
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
154
|
-
passBackProperties,
|
|
155
|
-
{}
|
|
156
|
-
);
|
|
157
|
-
const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
|
|
158
|
-
_izContext,
|
|
159
|
-
TOPIC_NAME_GENERATE_CODE.out<%- action %>NodeComplete
|
|
160
|
-
);
|
|
161
|
-
_izContext.logger.debug('[<%- action %>Complete] publishing to SNS', {
|
|
162
|
-
TopicArn: topicArn,
|
|
163
|
-
message
|
|
164
|
-
});
|
|
165
|
-
await sns.publishAsync(_izContext, {
|
|
166
|
-
Message: JSON.stringify(message),
|
|
167
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
168
|
-
_izContext,
|
|
169
|
-
messageAttributes
|
|
170
|
-
),
|
|
171
|
-
TopicArn: topicArn
|
|
172
|
-
});
|
|
173
|
-
//(<afterSendMessage>)
|
|
174
|
-
//(</afterSendMessage>)
|
|
175
|
-
}
|
|
176
|
-
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
177
|
-
_izContext,
|
|
178
|
-
awaitingStepId,
|
|
179
|
-
pending.pendingStepId,
|
|
180
|
-
errorsFound
|
|
181
|
-
);
|
|
182
|
-
return { returnValue, status, errorsFound };
|
|
183
|
-
} catch (error) {
|
|
184
|
-
_izContext.logger.error('[<%- action %>Complete] error:', error);
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<%_ flowTags.forEach(flowTag => { _%>
|
|
2
|
-
SubscriptionOut<%- flowTag.charAt(0).toUpperCase() + flowTag.slice(1) %>To<%- queueName %>:
|
|
3
|
-
Type: AWS::SNS::Subscription
|
|
4
|
-
Properties:
|
|
5
|
-
TopicArn: !Ref Out<%- flowTag.charAt(0).toUpperCase() + flowTag.slice(1) %>
|
|
6
|
-
Endpoint: 'arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs'
|
|
7
|
-
Protocol: 'sqs'
|
|
8
|
-
<%_ }) _%>
|
|
9
|
-
##===== [Queue]
|
|
10
|
-
<%- queueName %>HdrSqs:
|
|
11
|
-
Type: 'AWS::SQS::Queue'
|
|
12
|
-
Properties:
|
|
13
|
-
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
|
|
14
|
-
RedrivePolicy:
|
|
15
|
-
deadLetterTargetArn:
|
|
16
|
-
Fn::GetAtt:
|
|
17
|
-
- <%- queueName %>HdrSqsDLQ
|
|
18
|
-
- Arn
|
|
19
|
-
maxReceiveCount: 3
|
|
20
|
-
VisibilityTimeout: 120
|
|
21
|
-
|
|
22
|
-
##===== [Queue DLQ]
|
|
23
|
-
<%- queueName %>HdrSqsDLQ:
|
|
24
|
-
Type: AWS::SQS::Queue
|
|
25
|
-
Properties:
|
|
26
|
-
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
|
|
27
|
-
|
|
28
|
-
##===== [Queue Policy]
|
|
29
|
-
<%- queueName %>HdrSqsPolicy:
|
|
30
|
-
Type: AWS::SQS::QueuePolicy
|
|
31
|
-
Properties:
|
|
32
|
-
PolicyDocument:
|
|
33
|
-
Version: '2012-10-17'
|
|
34
|
-
Statement:
|
|
35
|
-
- Sid: 'allow-sns-messages'
|
|
36
|
-
Effect: Allow
|
|
37
|
-
Principal: '*'
|
|
38
|
-
Resource:
|
|
39
|
-
Fn::GetAtt:
|
|
40
|
-
- <%- queueName %>HdrSqs
|
|
41
|
-
- Arn
|
|
42
|
-
Action: 'SQS:SendMessage'
|
|
43
|
-
Queues:
|
|
44
|
-
- Ref: <%- queueName %>HdrSqs
|
|
45
|
-
|
|
46
|
-
#<#<%- queueName %>QueueSetting#>
|
|
47
|
-
#<#/<%- queueName %>QueueSetting#>
|