@izara_project/izara-core-generate-service-code 1.0.66 → 1.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +11 -0
- package/docs/TriggeredCache Flow.drawio +193 -0
- package/docs/TriggeredCacheFlow.mmd +47 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +105 -0
- package/src/compile/compileProject.js +16 -1
- package/src/compile/loadSchemas.js +108 -1
- package/src/emit/crud/emitCrudApplicationArtifacts.js +9 -5
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +300 -109
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +221 -143
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +150 -38
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +57 -31
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +407 -252
- package/src/emit/custom/customFlows.js +112 -31
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +89 -77
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +49 -37
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +46 -12
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +179 -66
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +6 -5
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +260 -144
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +499 -108
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
- package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
- package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
- package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
- package/src/emit/system/emitSystemWebSocketArtifacts.js +2 -1
- package/src/generate.js +8 -4
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +1 -1
- package/test/customFlowApplicationArtifacts.test.js +71 -43
- package/test/dynamicCrudFlowSchemas.test.js +6 -6
- package/test/dynamicRbacFlowSchemas.test.js +8 -12
- package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
- package/test/publicApi.test.js +11 -13
- package/test/resourceArtifacts.test.js +13 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
|
@@ -15,32 +15,26 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
21
|
-
import { recordHandlerSharedLib } from "@izara_project/izara-core-library-record-handler";
|
|
18
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
22
20
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
23
|
-
import callingFlowSharedLib from
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
24
22
|
|
|
25
|
-
import <%= functionName %> from './<%= functionName %>_Main.js'
|
|
23
|
+
import <%= functionName %> from './<%= functionName %>_Main.js';
|
|
26
24
|
|
|
27
25
|
// validate event properties in body.Message of sqs event
|
|
28
26
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
29
27
|
|
|
30
28
|
// set schema for record.body.Message
|
|
31
29
|
let perRecordsValidatorSchema = {
|
|
32
|
-
type:
|
|
33
|
-
required: [
|
|
34
|
-
'returnMessage',
|
|
35
|
-
'errorsFound',
|
|
36
|
-
'passStatus'
|
|
37
|
-
],
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: ['returnMessage', 'errorsFound', 'passStatus'],
|
|
38
32
|
properties: {
|
|
39
33
|
returnMessage: {
|
|
40
|
-
type:
|
|
34
|
+
type: 'object'
|
|
41
35
|
},
|
|
42
36
|
errorsFound: {
|
|
43
|
-
type:
|
|
37
|
+
type: 'array'
|
|
44
38
|
},
|
|
45
39
|
passStatus: {
|
|
46
40
|
type: 'boolean'
|
|
@@ -62,62 +56,73 @@ let perRecordsValidatorSchema = {
|
|
|
62
56
|
// }
|
|
63
57
|
// };
|
|
64
58
|
|
|
65
|
-
perRecordsValidatorSchema =
|
|
59
|
+
perRecordsValidatorSchema =
|
|
60
|
+
callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
|
|
61
|
+
perRecordsValidatorSchema
|
|
62
|
+
);
|
|
66
63
|
|
|
67
64
|
export const main = middleware.wrap(async (event, context) => {
|
|
68
|
-
|
|
69
65
|
try {
|
|
70
|
-
|
|
71
66
|
let recordPromises = [];
|
|
72
67
|
|
|
73
68
|
// loop each record and send to mainFunction
|
|
74
|
-
await Promise.all(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
69
|
+
await Promise.all(
|
|
70
|
+
event.Records.map(async (record) => {
|
|
71
|
+
// promise.all for map() function
|
|
72
|
+
|
|
73
|
+
let passOnProperties = [];
|
|
74
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
75
|
+
|
|
76
|
+
// validate message (and MessageAttributes)
|
|
77
|
+
await recordHandlerSharedLib.validateRecord(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
80
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
81
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
85
|
+
passOnProperties.push(record.body.Message.returnMessage);
|
|
86
|
+
passOnProperties.push(record.body.Message.errorsFound);
|
|
87
|
+
passOnProperties.push(record.body.Message.passStatus);
|
|
88
|
+
//(<additionalProperties>)
|
|
89
|
+
//(</additionalProperties>)
|
|
90
|
+
passOnProperties.push(
|
|
91
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
92
|
+
record.body.Message
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
record._izContext.logger.debug(
|
|
96
|
+
'passOnProperties in handler',
|
|
97
|
+
passOnProperties
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
101
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
102
|
+
record, // one record will send to mainFunction
|
|
103
|
+
<%= functionName %>, // mainFunction that need to invoke.
|
|
104
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
105
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
106
|
+
);
|
|
107
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
108
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
109
|
+
})
|
|
110
|
+
);
|
|
106
111
|
|
|
107
112
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
108
113
|
try {
|
|
109
114
|
// --- main await all promises
|
|
110
115
|
await Promise.all(recordPromises); // await all promises
|
|
111
116
|
|
|
112
|
-
return event.Records // return all for local test
|
|
113
|
-
|
|
117
|
+
return event.Records; // return all for local test
|
|
114
118
|
} catch {
|
|
115
|
-
Logger.debug(
|
|
119
|
+
Logger.debug(
|
|
120
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
121
|
+
);
|
|
116
122
|
}
|
|
117
123
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
118
|
-
|
|
119
124
|
} catch (err) {
|
|
120
125
|
Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
|
|
121
|
-
throw
|
|
126
|
+
throw err;
|
|
122
127
|
}
|
|
123
128
|
});
|
|
@@ -15,8 +15,6 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
18
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
21
19
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
22
20
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
@@ -56,18 +54,21 @@ export default async function confirmNewReserved(
|
|
|
56
54
|
errorsFound: errorsFound,
|
|
57
55
|
passStatus: passStatus,
|
|
58
56
|
passBackProperties: passBackProperties
|
|
59
|
-
})
|
|
57
|
+
});
|
|
60
58
|
|
|
61
|
-
let servicePendingId =
|
|
62
|
-
|
|
59
|
+
let servicePendingId =
|
|
60
|
+
passBackProperties.passBackProperties.identifier.servicePendingId;
|
|
61
|
+
let reservedDataId =
|
|
62
|
+
passBackProperties.passBackProperties.identifier.reservedDataId;
|
|
63
63
|
let userId = passBackProperties.passBackProperties.identifier.userId;
|
|
64
|
-
let realFileSize =
|
|
64
|
+
let realFileSize =
|
|
65
|
+
passBackProperties.passBackProperties.identifier.realFileSize;
|
|
65
66
|
|
|
66
|
-
let uniqueIdentify = getNestObject(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
67
|
+
let uniqueIdentify = getNestObject(_izContext, returnMessage.limitFound, [
|
|
68
|
+
'runningTotal',
|
|
69
|
+
'uniqueIdentify',
|
|
70
|
+
'usedTimestampId'
|
|
71
|
+
]);
|
|
71
72
|
|
|
72
73
|
// confirmUsage
|
|
73
74
|
let confirmUsageMessage = {
|
|
@@ -75,14 +76,21 @@ export default async function confirmNewReserved(
|
|
|
75
76
|
//(<optionalLimitTag>)
|
|
76
77
|
limitTag: schemaConsts.LIMIT_TAG.uploadData,
|
|
77
78
|
//(</optionalLimitTag>)
|
|
78
|
-
uniqueIdentify: uniqueIdentify
|
|
79
|
-
}
|
|
79
|
+
uniqueIdentify: uniqueIdentify
|
|
80
|
+
};
|
|
80
81
|
|
|
81
82
|
let sendMessageToConfirmUsage = {
|
|
82
83
|
Message: JSON.stringify(confirmUsageMessage),
|
|
83
|
-
TopicArn:
|
|
84
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
85
|
+
_izContext,
|
|
86
|
+
'ConfirmUsage_In',
|
|
87
|
+
schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits
|
|
88
|
+
)
|
|
84
89
|
};
|
|
85
|
-
_izContext.logger.debug(
|
|
90
|
+
_izContext.logger.debug(
|
|
91
|
+
'sendMessageToConfirmUsage',
|
|
92
|
+
sendMessageToConfirmUsage
|
|
93
|
+
);
|
|
86
94
|
await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
|
|
87
95
|
|
|
88
96
|
// update reservedDataValue as real size in ReservedDataMain table
|
|
@@ -96,7 +104,7 @@ export default async function confirmNewReserved(
|
|
|
96
104
|
{
|
|
97
105
|
reservedValue: realFileSize
|
|
98
106
|
}
|
|
99
|
-
)
|
|
107
|
+
);
|
|
100
108
|
|
|
101
109
|
let sendMessageToUpdateStatus = {
|
|
102
110
|
//(<messageObjectHook>)
|
|
@@ -111,19 +119,21 @@ export default async function confirmNewReserved(
|
|
|
111
119
|
//(</fields>)
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
|
-
}
|
|
122
|
+
};
|
|
115
123
|
|
|
116
124
|
let sendMessageToUpdateEndpoint = {
|
|
117
125
|
Message: JSON.stringify(sendMessageToUpdateStatus),
|
|
118
|
-
TopicArn:
|
|
126
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Update_In')
|
|
119
127
|
};
|
|
120
|
-
_izContext.logger.debug(
|
|
128
|
+
_izContext.logger.debug(
|
|
129
|
+
'sendMessageToUpdateEndpoint',
|
|
130
|
+
sendMessageToUpdateEndpoint
|
|
131
|
+
);
|
|
121
132
|
await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
|
|
122
133
|
|
|
123
|
-
return { returnResponse: 'success' }
|
|
124
|
-
|
|
134
|
+
return { returnResponse: 'success' };
|
|
125
135
|
} catch (err) {
|
|
126
|
-
_izContext.logger.debug('error ConfirmNewReservedMain: ', err)
|
|
127
|
-
throw
|
|
136
|
+
_izContext.logger.debug('error ConfirmNewReservedMain: ', err);
|
|
137
|
+
throw err;
|
|
128
138
|
}
|
|
129
139
|
}
|
|
@@ -15,56 +15,64 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler as middleware,
|
|
20
|
+
consts,
|
|
21
|
+
response
|
|
22
|
+
} from '@izara_project/izara-middleware';
|
|
21
23
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
22
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
25
|
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
24
26
|
const { postToConnection } = webSocket;
|
|
25
|
-
import { utils } from
|
|
26
|
-
const { createFlowTypeConcat } = utils
|
|
27
|
+
import { utils } from '@izara_project/izara-core-library-service-schemas';
|
|
28
|
+
const { createFlowTypeConcat } = utils;
|
|
27
29
|
|
|
28
30
|
import <%= functionName %> from './<%= functionName %>_Main.js';
|
|
29
31
|
|
|
30
32
|
export const main = middleware.wrap(async (event, context) => {
|
|
31
|
-
|
|
32
33
|
event._izContext.logger.debug('Event:', event);
|
|
33
34
|
|
|
34
35
|
try {
|
|
35
|
-
|
|
36
36
|
if (event.requestContext) {
|
|
37
37
|
const route = event.requestContext.routeKey;
|
|
38
38
|
const connectionId = event.requestContext.connectionId;
|
|
39
|
-
let correlationId = event._izContext.correlationIds.get(
|
|
39
|
+
let correlationId = event._izContext.correlationIds.get(
|
|
40
|
+
consts.X_CORRELATION_ID
|
|
41
|
+
);
|
|
40
42
|
|
|
41
43
|
switch (route) {
|
|
42
44
|
case '<%- route %>':
|
|
43
|
-
console.log(
|
|
44
|
-
let eventParams = JSON.parse(event.body)
|
|
45
|
+
console.log('event in route webSocket', event);
|
|
46
|
+
let eventParams = JSON.parse(event.body);
|
|
45
47
|
|
|
46
48
|
//(<createIdentifiersFlow>)
|
|
47
|
-
let identifiers
|
|
49
|
+
let identifiers;
|
|
48
50
|
//(</createIdentifiersFlow>)
|
|
49
51
|
|
|
50
|
-
await dynamodbSharedLib.putItem(
|
|
51
|
-
|
|
52
|
+
await dynamodbSharedLib.putItem(
|
|
53
|
+
event._izContext,
|
|
54
|
+
await dynamodbSharedLib.tableName(
|
|
55
|
+
event._izContext,
|
|
56
|
+
'WebSocketTask'
|
|
57
|
+
),
|
|
52
58
|
{
|
|
53
|
-
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag:
|
|
54
|
-
connectionId: connectionId
|
|
59
|
+
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: '<%- route %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
|
|
60
|
+
connectionId: connectionId
|
|
55
61
|
}
|
|
56
|
-
)
|
|
62
|
+
);
|
|
57
63
|
|
|
58
|
-
let callingFlow = eventParams?.callingFlow
|
|
64
|
+
let callingFlow = eventParams?.callingFlow
|
|
65
|
+
? eventParams.callingFlow
|
|
66
|
+
: {};
|
|
59
67
|
await <%= functionName %>(
|
|
60
68
|
event._izContext,
|
|
61
69
|
eventParams,
|
|
62
70
|
callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
|
|
63
71
|
//(<additionalParams>)
|
|
64
72
|
//(</additionalParams>)
|
|
65
|
-
)
|
|
73
|
+
);
|
|
66
74
|
|
|
67
|
-
break
|
|
75
|
+
break;
|
|
68
76
|
}
|
|
69
77
|
} else {
|
|
70
78
|
const connId = event.connId;
|
|
@@ -72,13 +80,12 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
72
80
|
await postToConnection({ message: event.message }, connId);
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
return
|
|
76
|
-
|
|
83
|
+
return response.webSocketSuccess();
|
|
77
84
|
} catch (err) {
|
|
78
|
-
const connId = event.requestContext.connectionId
|
|
85
|
+
const connId = event.requestContext.connectionId;
|
|
79
86
|
event._izContext.logger.error('Error, WebSocket: ', err);
|
|
80
87
|
// await sendErrorMessage({ message: err.message }, connId);
|
|
81
88
|
await postToConnection({ message: err.message }, connId);
|
|
82
|
-
return
|
|
89
|
+
return response.failure(err);
|
|
83
90
|
}
|
|
84
91
|
});
|
|
@@ -16,8 +16,6 @@ along with this program. If not, see
|
|
|
16
16
|
<http: //www.gnu.org/licenses />.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
19
|
import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
22
20
|
import { consts } from '@izara_project/izara-middleware';
|
|
23
21
|
|
|
@@ -53,79 +51,98 @@ const { TOPIC_NAME_GENERATE_CODE } = schemaConsts;
|
|
|
53
51
|
export default async function createObject(
|
|
54
52
|
_izContext,
|
|
55
53
|
requestParams,
|
|
56
|
-
callingFlowConfig = {}
|
|
54
|
+
callingFlowConfig = {}
|
|
57
55
|
//(<additionalParams>)
|
|
58
56
|
//(</additionalParams>)
|
|
59
57
|
) {
|
|
60
|
-
|
|
61
58
|
try {
|
|
62
|
-
_izContext.logger.debug(
|
|
63
|
-
_izContext.logger.debug(
|
|
64
|
-
_izContext.logger.debug(
|
|
59
|
+
_izContext.logger.debug('WebSocketInvoke _izContext', _izContext);
|
|
60
|
+
_izContext.logger.debug('WebSocketInvoke requestParams', requestParams);
|
|
61
|
+
_izContext.logger.debug(
|
|
62
|
+
'WebSocketInvoke callingFlowConfig',
|
|
63
|
+
callingFlowConfig
|
|
64
|
+
);
|
|
65
65
|
|
|
66
|
-
let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
|
|
66
|
+
let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID);
|
|
67
67
|
|
|
68
|
-
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
|
|
69
|
+
_izContext,
|
|
70
|
+
{
|
|
71
|
+
flowTag: '<%- flowTag %>',
|
|
72
|
+
serviceTag: process.env.iz_serviceTag
|
|
73
|
+
}
|
|
74
|
+
);
|
|
72
75
|
|
|
73
|
-
_izContext.logger.debug(
|
|
76
|
+
_izContext.logger.debug('getFlowSchema', flowSchema);
|
|
74
77
|
|
|
75
|
-
let getUserFromTableUserUploadRecord = await dynamodbSharedLib.getItem(
|
|
76
|
-
|
|
78
|
+
let getUserFromTableUserUploadRecord = await dynamodbSharedLib.getItem(
|
|
79
|
+
_izContext,
|
|
80
|
+
await dynamodbSharedLib.tableName(_izContext, 'UserUploadRecords'),
|
|
77
81
|
{
|
|
78
82
|
connectionId: connectionId
|
|
79
83
|
}
|
|
80
|
-
)
|
|
84
|
+
);
|
|
81
85
|
|
|
82
|
-
const { userId, submittedByUserId } = getUserFromTableUserUploadRecord
|
|
83
|
-
_izContext.correlationIds.set(consts.BASE_USER_ID, userId)
|
|
84
|
-
_izContext.correlationIds.set(consts.TARGET_ID, submittedByUserId)
|
|
86
|
+
const { userId, submittedByUserId } = getUserFromTableUserUploadRecord;
|
|
87
|
+
_izContext.correlationIds.set(consts.BASE_USER_ID, userId);
|
|
88
|
+
_izContext.correlationIds.set(consts.TARGET_ID, submittedByUserId);
|
|
85
89
|
|
|
86
90
|
if (!flowSchema) {
|
|
87
|
-
throw new NoRetryError(`flowTag not found ${requestParams.action}`)
|
|
91
|
+
throw new NoRetryError(`flowTag not found ${requestParams.action}`);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
// get objectType
|
|
91
|
-
let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
92
|
-
|
|
95
|
+
let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
96
|
+
_izContext,
|
|
97
|
+
flowSchema.objType
|
|
98
|
+
);
|
|
99
|
+
_izContext.logger.debug(
|
|
100
|
+
'objectSchema in flowSchema mainFunction',
|
|
101
|
+
objectSchema
|
|
102
|
+
);
|
|
93
103
|
|
|
94
104
|
if (!objectSchema) {
|
|
95
|
-
throw new NoRetryError(`${flowSchema.objType.objectType} not found`)
|
|
105
|
+
throw new NoRetryError(`${flowSchema.objType.objectType} not found`);
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
//(<beforeCreateHook>)
|
|
99
109
|
//(</beforeCreateHook>)
|
|
100
110
|
// create message Object to create Endpoint
|
|
101
111
|
let messageObject = {
|
|
102
|
-
objectType:
|
|
112
|
+
objectType: '<%- objectType %>',
|
|
103
113
|
fieldNames: {
|
|
104
114
|
//(<fieldNamesHook>)
|
|
105
115
|
//(</fieldNamesHook>)
|
|
106
116
|
}
|
|
107
|
-
}
|
|
117
|
+
};
|
|
108
118
|
// create callingFlow
|
|
109
|
-
messageObject =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
messageObject =
|
|
120
|
+
callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
121
|
+
messageObject,
|
|
122
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
123
|
+
callingFlowConfig,
|
|
124
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
125
|
+
await lambdaSharedLib.lambdaFunctionName(
|
|
126
|
+
_izContext,
|
|
127
|
+
TOPIC_NAME_GENERATE_CODE.createNodeComplete
|
|
128
|
+
),
|
|
129
|
+
{}
|
|
130
|
+
)
|
|
115
131
|
)
|
|
116
|
-
)
|
|
117
|
-
)
|
|
132
|
+
);
|
|
118
133
|
|
|
119
134
|
// send message to Create endpoint
|
|
120
135
|
let sendMessageToCreateEndpoint = {
|
|
121
136
|
Message: JSON.stringify(messageObject),
|
|
122
|
-
TopicArn:
|
|
123
|
-
}
|
|
124
|
-
_izContext.logger.debug(
|
|
137
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Create_In')
|
|
138
|
+
};
|
|
139
|
+
_izContext.logger.debug(
|
|
140
|
+
'sendMessageToCreateEndpoint',
|
|
141
|
+
sendMessageToCreateEndpoint
|
|
142
|
+
);
|
|
125
143
|
await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
|
|
126
|
-
|
|
127
144
|
} catch (err) {
|
|
128
|
-
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
129
|
-
throw
|
|
145
|
+
_izContext.logger.error('error WebSocketInvoke: ', err);
|
|
146
|
+
throw err;
|
|
130
147
|
}
|
|
131
148
|
}
|
|
@@ -15,9 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
18
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
21
19
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
22
20
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
23
21
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
@@ -29,18 +27,14 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
|
29
27
|
|
|
30
28
|
// set schema for record.body.Message
|
|
31
29
|
let perRecordsValidatorSchema = {
|
|
32
|
-
type:
|
|
33
|
-
required: [
|
|
34
|
-
'returnMessage',
|
|
35
|
-
'errorsFound',
|
|
36
|
-
'passStatus'
|
|
37
|
-
],
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: ['returnMessage', 'errorsFound', 'passStatus'],
|
|
38
32
|
properties: {
|
|
39
33
|
returnMessage: {
|
|
40
|
-
type:
|
|
34
|
+
type: 'object'
|
|
41
35
|
},
|
|
42
36
|
errorsFound: {
|
|
43
|
-
type:
|
|
37
|
+
type: 'array'
|
|
44
38
|
},
|
|
45
39
|
passStatus: {
|
|
46
40
|
type: 'boolean'
|
|
@@ -62,62 +56,73 @@ let perRecordsValidatorSchema = {
|
|
|
62
56
|
// }
|
|
63
57
|
// };
|
|
64
58
|
|
|
65
|
-
perRecordsValidatorSchema =
|
|
59
|
+
perRecordsValidatorSchema =
|
|
60
|
+
callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
|
|
61
|
+
perRecordsValidatorSchema
|
|
62
|
+
);
|
|
66
63
|
|
|
67
64
|
export const main = middleware.wrap(async (event, context) => {
|
|
68
|
-
|
|
69
65
|
try {
|
|
70
|
-
|
|
71
66
|
let recordPromises = [];
|
|
72
67
|
|
|
73
68
|
// loop each record and send to mainFunction
|
|
74
|
-
await Promise.all(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
69
|
+
await Promise.all(
|
|
70
|
+
event.Records.map(async (record) => {
|
|
71
|
+
// promise.all for map() function
|
|
72
|
+
|
|
73
|
+
let passOnProperties = [];
|
|
74
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
75
|
+
|
|
76
|
+
// validate message (and MessageAttributes)
|
|
77
|
+
await recordHandlerSharedLib.validateRecord(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
80
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
81
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
85
|
+
passOnProperties.push(record.body.Message.returnMessage);
|
|
86
|
+
passOnProperties.push(record.body.Message.errorsFound);
|
|
87
|
+
passOnProperties.push(record.body.Message.passStatus);
|
|
88
|
+
//(<additionalProperties>)
|
|
89
|
+
//(</additionalProperties>)
|
|
90
|
+
passOnProperties.push(
|
|
91
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
92
|
+
record.body.Message
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
record._izContext.logger.debug(
|
|
96
|
+
'passOnProperties in handler',
|
|
97
|
+
passOnProperties
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
101
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
102
|
+
record, // one record will send to mainFunction
|
|
103
|
+
<%= functionName %>, // mainFunction that need to invoke.
|
|
104
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
105
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
106
|
+
);
|
|
107
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
108
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
109
|
+
})
|
|
110
|
+
);
|
|
106
111
|
|
|
107
112
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
108
113
|
try {
|
|
109
114
|
// --- main await all promises
|
|
110
115
|
await Promise.all(recordPromises); // await all promises
|
|
111
116
|
|
|
112
|
-
return event.Records // return all for local test
|
|
113
|
-
|
|
117
|
+
return event.Records; // return all for local test
|
|
114
118
|
} catch {
|
|
115
|
-
Logger.debug(
|
|
119
|
+
Logger.debug(
|
|
120
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
121
|
+
);
|
|
116
122
|
}
|
|
117
123
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
118
|
-
|
|
119
124
|
} catch (err) {
|
|
120
125
|
Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
|
|
121
|
-
throw
|
|
126
|
+
throw err;
|
|
122
127
|
}
|
|
123
128
|
});
|