@izara_project/izara-market-library-service-schemas 1.0.32 → 1.0.34
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/GenerateCodeLibs/src/Consts.js +2 -1
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +15 -1
- package/src/MainLibs/src/Consts.js +7 -2
- package/src/reStructure/GenerateCode.js +16 -18
- package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
- package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +1 -1
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +15 -15
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +14 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +17 -0
- package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +3 -28
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +6 -10
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +4 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +4 -3
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +26 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +6 -10
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +4 -4
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -4
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +8 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +32 -5
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +18 -18
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +55 -10
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +27 -7
- package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +3 -3
- package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +9 -3
- package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +9 -3
- package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +10 -4
- package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +9 -3
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -5
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +5 -5
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template copy.ejs +0 -125
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/template.ejs +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%_ const join = require('path').join; _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
|
|
11
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
12
|
+
role: <%- roleName %>Role
|
|
13
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
14
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
15
|
+
<%_ function firstLetterUpperCase(text){
|
|
16
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
17
|
+
} _%>
|
|
18
|
+
<%_ function firstLetterLowerCase(str) {
|
|
19
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
20
|
+
} _%>
|
package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 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
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
21
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
22
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
|
|
23
|
+
const templatePath = path.join(__dirname, "template.ejs")
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* receive objectSchema
|
|
27
|
+
* create data for WebScoket handler template
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} objectSchema
|
|
30
|
+
* @return {{templatePath, templateData,setting}}
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
35
|
+
return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
39
|
+
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
|
|
40
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
|
+
let queueName = upperCase(functionName) + upperCase(handlerType)
|
|
42
|
+
return {
|
|
43
|
+
templatePath: templatePath,
|
|
44
|
+
templateData: {
|
|
45
|
+
functionName,
|
|
46
|
+
handlerType,
|
|
47
|
+
queueName
|
|
48
|
+
},
|
|
49
|
+
setting: {
|
|
50
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
|
|
51
|
+
saveFileName: `${functionName}_${handlerType}`,
|
|
52
|
+
fileExtension: ".js",
|
|
53
|
+
isAppend: false
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
module.exports = data
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 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
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
// const AWS = require('aws-sdk');
|
|
21
|
+
// const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
|
|
22
|
+
|
|
23
|
+
const izara = require("@izara_project/izara-middleware");
|
|
24
|
+
const middleware = izara.middlewareHandler;
|
|
25
|
+
const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
|
|
26
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
|
+
|
|
28
|
+
const FlowSchemaOwnTopicEndpoint = require('./FlowSchemaOwnTopicEndpoint_Main')
|
|
29
|
+
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
let perRecordsValidatorSchema = {}
|
|
32
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
33
|
+
|
|
34
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
|
|
38
|
+
let recordPromises = [];
|
|
39
|
+
|
|
40
|
+
// loop each record and send to mainFunction
|
|
41
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
42
|
+
|
|
43
|
+
let passOnProperties = []
|
|
44
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
45
|
+
|
|
46
|
+
//validate message (and MessageAttributes)
|
|
47
|
+
await recordHandlerSharedLib.validateRecord(
|
|
48
|
+
record, // one record will send to mainFunction
|
|
49
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
50
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
51
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
55
|
+
passOnProperties.push(record.body.Message)
|
|
56
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
57
|
+
|
|
58
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
59
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
60
|
+
record, // one record will send to mainFunction
|
|
61
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
62
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
63
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
64
|
+
);
|
|
65
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
66
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
70
|
+
try {
|
|
71
|
+
// --- main await all promises
|
|
72
|
+
await Promise.all(recordPromises); // await all promises
|
|
73
|
+
|
|
74
|
+
return event.Records // return all for local testing
|
|
75
|
+
|
|
76
|
+
} catch {
|
|
77
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
78
|
+
}
|
|
79
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
80
|
+
|
|
81
|
+
} catch (err) {
|
|
82
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
83
|
+
throw (err);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 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
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
22
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
|
|
23
|
+
const templatePath = path.join(__dirname, "template.ejs");
|
|
24
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* receive objectSchema
|
|
28
|
+
* create data for WebScoket handler template
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} objectSchema
|
|
31
|
+
* @return {{templatePath, templateData,setting}}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
36
|
+
return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
40
|
+
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
|
|
41
|
+
let topicArn = Object.keys(flowSchema.flowSteps)[1]
|
|
42
|
+
return {
|
|
43
|
+
templatePath: templatePath,
|
|
44
|
+
templateData: {
|
|
45
|
+
topicArn
|
|
46
|
+
},
|
|
47
|
+
setting: {
|
|
48
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
|
|
49
|
+
saveFileName: `${functionName}_Main`,
|
|
50
|
+
fileExtension: ".js",
|
|
51
|
+
isAppend: false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
module.exports = data
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 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
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const hash = require("object-hash");
|
|
22
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
23
|
+
|
|
24
|
+
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
25
|
+
const snsSharedLib = require('@izara_project/izara-core-library-sns');
|
|
26
|
+
const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
|
|
27
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
28
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
|
|
29
|
+
|
|
30
|
+
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
31
|
+
const sns = externalRequest.sns
|
|
32
|
+
const { postToConnection } = require("../../../../libs/source/GenerateCodeLibs");
|
|
33
|
+
const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
|
|
34
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
35
|
+
const { v4: uuidv4 } = require('uuid')
|
|
36
|
+
const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
|
|
37
|
+
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* description of function.
|
|
42
|
+
* @param {Object} _izContext
|
|
43
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
44
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
45
|
+
* @param {Object} requestParams - request params
|
|
46
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
47
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
48
|
+
*
|
|
49
|
+
*
|
|
50
|
+
* @returns {object} description of return value
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
module.exports.FlowSchemaOwnTopicEndpointComplete = async (
|
|
54
|
+
_izContext,
|
|
55
|
+
requestParams,
|
|
56
|
+
callingFlowConfig = {},
|
|
57
|
+
//(<additionalParams>)
|
|
58
|
+
//(</additionalParams>)
|
|
59
|
+
) => {
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
_izContext.logger.debug("FlowSchemaOwnTopicEndpointComplete _izContext", _izContext)
|
|
63
|
+
_izContext.logger.debug("FlowSchemaOwnTopicEndpointComplete requestParams", requestParams)
|
|
64
|
+
_izContext.logger.debug("FlowSchemaOwnTopicEndpointComplete callingFlowConfig", callingFlowConfig)
|
|
65
|
+
|
|
66
|
+
//(<endpointCompleteHookMainFunction>)
|
|
67
|
+
//(</endpointCompleteHookMainFunction>)
|
|
68
|
+
|
|
69
|
+
let messageObject = {
|
|
70
|
+
//(<messageObjectHook>)
|
|
71
|
+
//(</messageObjectHook>)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let sendMessageToOutFlowSchema = {
|
|
75
|
+
Message: JSON.stringify(messageObject),
|
|
76
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- topicArn %>")
|
|
77
|
+
};
|
|
78
|
+
_izContext.logger.debug("before sendMessageToOutFlowSchema::", sendMessageToOutFlowSchema);
|
|
79
|
+
await sns.publishAsync(_izContext, sendMessageToOutFlowSchema)
|
|
80
|
+
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_izContext.logger.error('error FlowSchemaOwnTopicEndpointComplete: ', err)
|
|
83
|
+
throw (err)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
'use strict';
|
|
19
19
|
const path = require('path');
|
|
20
20
|
|
|
21
|
-
const { FLOW_SCHEMA_HOOK_STATE, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
21
|
+
const { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
22
|
const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
|
|
23
23
|
const {
|
|
24
24
|
SOURCE_PATH,
|
|
@@ -52,36 +52,11 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
52
52
|
|
|
53
53
|
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
54
54
|
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpoint)
|
|
55
|
-
let handlerType = upperCase(
|
|
55
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
56
56
|
let additionalResourcePermission = defaultIamRolePerAction();
|
|
57
57
|
let route = flowSchema.flowTag;
|
|
58
58
|
|
|
59
|
-
additionalResourcePermission.push(
|
|
60
|
-
createIamRole(
|
|
61
|
-
{
|
|
62
|
-
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
63
|
-
DYNAMO_RESOURCE.putItem,
|
|
64
|
-
DYNAMO_RESOURCE.getItem,
|
|
65
|
-
DYNAMO_RESOURCE.query,
|
|
66
|
-
DYNAMO_RESOURCE.deleteItem,
|
|
67
|
-
DYNAMO_RESOURCE.updateItem
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
[
|
|
71
|
-
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
|
|
72
|
-
]
|
|
73
|
-
),
|
|
74
|
-
createIamRole(
|
|
75
|
-
{
|
|
76
|
-
"execute-api": [
|
|
77
|
-
"ManageConnections"
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
[
|
|
81
|
-
resourceNames(RESOURCE_CLASSES.webSocket)
|
|
82
|
-
]
|
|
83
|
-
)
|
|
84
|
-
)
|
|
59
|
+
additionalResourcePermission.push()
|
|
85
60
|
|
|
86
61
|
|
|
87
62
|
return {
|
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
4
|
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
5
|
events:
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- websocket:
|
|
13
|
-
route: <%- route %>
|
|
14
|
-
# authorizer: ${self:custom.iz_authorizerAppLevel}
|
|
15
|
-
# identifierResource: 'route.request.header.Auth'
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
|
|
11
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
16
12
|
role: <%- roleName %>Role
|
|
17
13
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
18
14
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js
CHANGED
|
@@ -37,14 +37,16 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
37
37
|
|
|
38
38
|
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
39
39
|
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpoint)
|
|
40
|
-
let handlerType = HANDLER.hdrSqs
|
|
40
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
41
|
let route = flowSchema.flowTag;
|
|
42
|
+
let queueName = functionName
|
|
42
43
|
return {
|
|
43
44
|
templatePath: templatePath,
|
|
44
45
|
templateData: {
|
|
45
46
|
functionName,
|
|
46
47
|
handlerType,
|
|
47
|
-
route
|
|
48
|
+
route,
|
|
49
|
+
queueName
|
|
48
50
|
},
|
|
49
51
|
setting: {
|
|
50
52
|
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
|
|
@@ -28,6 +28,7 @@ const Logger = require('@izara_project/izara-core-library-logger');
|
|
|
28
28
|
const FlowSchemaOwnTopicEndpoint = require('./FlowSchemaOwnTopicEndpoint_Main')
|
|
29
29
|
|
|
30
30
|
// validate event properties in body.Message of sqs event
|
|
31
|
+
let perRecordsValidatorSchema = {}
|
|
31
32
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
32
33
|
|
|
33
34
|
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
@@ -45,7 +46,7 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
45
46
|
//validate message (and MessageAttributes)
|
|
46
47
|
await recordHandlerSharedLib.validateRecord(
|
|
47
48
|
record, // one record will send to mainFunction
|
|
48
|
-
"
|
|
49
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
49
50
|
perRecordsValidatorSchema, // schema for record.Message
|
|
50
51
|
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
51
52
|
);
|
|
@@ -57,8 +58,8 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
57
58
|
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
58
59
|
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
59
60
|
record, // one record will send to mainFunction
|
|
60
|
-
|
|
61
|
-
"
|
|
61
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
62
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
62
63
|
passOnProperties, // all parameters that mainFunction needed.
|
|
63
64
|
);
|
|
64
65
|
record._izContext.logger.debug('after recordPromise in handler');
|
|
@@ -66,6 +66,32 @@ module.exports.FlowSchemaOwnTopicEndpoint = async (
|
|
|
66
66
|
//(<endpointHookMainFunction>)
|
|
67
67
|
//(</endpointHookMainFunction>)
|
|
68
68
|
|
|
69
|
+
let messageObject = {
|
|
70
|
+
//(<messageObject>)
|
|
71
|
+
//(</messageObject>)
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
75
|
+
sendMessageToTranslateIdIterFromAHdrDsq,
|
|
76
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
77
|
+
callingFlow,
|
|
78
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
79
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.flowSchemaOwnTopicComplete), {}
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
let sendMessageToFlowSchemaOutEndpointComplete = {
|
|
85
|
+
MessageBody: JSON.stringify(messageObject),
|
|
86
|
+
QueueUrl: await sqsSharedLib.sqsQueueUrl(_izContext, "FlowSchemaOwnTopicEndpointHdrSqs")
|
|
87
|
+
}
|
|
88
|
+
_izContext.logger.debug("before sendMessageToFlowSchemaOutEndpointComplete::",sendMessageToFlowSchemaOutEndpointComplete),
|
|
89
|
+
await sqs.sendMessage(_izContext, sendMessageToFlowSchemaOutEndpointComplete);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
//(<returnParams>)
|
|
93
|
+
//(</returnParams>)
|
|
94
|
+
}
|
|
69
95
|
} catch (err) {
|
|
70
96
|
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
71
97
|
throw (err)
|
|
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
'use strict';
|
|
19
19
|
const path = require('path');
|
|
20
20
|
|
|
21
|
-
const { FLOW_SCHEMA_HOOK_STATE, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
21
|
+
const { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
22
|
const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
|
|
23
23
|
const {
|
|
24
24
|
SOURCE_PATH,
|
|
@@ -52,7 +52,7 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
52
52
|
|
|
53
53
|
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
54
54
|
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicComplete)
|
|
55
|
-
let handlerType = upperCase(
|
|
55
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
56
56
|
let additionalResourcePermission = defaultIamRolePerAction();
|
|
57
57
|
let route = flowSchema.flowTag;
|
|
58
58
|
let flowStep = Object.keys(flowSchema.flowSteps)
|
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
4
|
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
5
|
events:
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- websocket:
|
|
13
|
-
route: <%- route %>
|
|
14
|
-
# authorizer: ${self:custom.iz_authorizerAppLevel}
|
|
15
|
-
# identifierResource: 'route.request.header.Auth'
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
|
|
11
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
16
12
|
role: <%- roleName %>Role
|
|
17
13
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
18
14
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
const path = require('path');
|
|
20
|
-
const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
20
|
+
const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
21
21
|
const { SOURCE_PATH, FUNCTION_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
22
22
|
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
|
|
23
23
|
const templatePath = path.join(__dirname, "template.ejs")
|
|
@@ -37,14 +37,14 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
37
37
|
|
|
38
38
|
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
39
39
|
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicComplete)
|
|
40
|
-
let handlerType =
|
|
41
|
-
let
|
|
40
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
|
+
let queueName = upperCase(functionName) + upperCase(handlerType);
|
|
42
42
|
return {
|
|
43
43
|
templatePath: templatePath,
|
|
44
44
|
templateData: {
|
|
45
45
|
functionName,
|
|
46
46
|
handlerType,
|
|
47
|
-
|
|
47
|
+
queueName
|
|
48
48
|
},
|
|
49
49
|
setting: {
|
|
50
50
|
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
|
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
4
|
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
5
|
events:
|
|
6
|
-
- websocket:
|
|
7
|
-
route: $connect
|
|
8
|
-
- websocket:
|
|
9
|
-
route: $disconnect
|
|
10
6
|
- websocket:
|
|
11
7
|
route: $default
|
|
12
8
|
- websocket:
|
|
@@ -33,6 +33,8 @@ const {
|
|
|
33
33
|
SOURCE_GENERATE_IAM_ROLE
|
|
34
34
|
} = require('../../../../../../MainLibs/src/Consts');
|
|
35
35
|
const templatePath = path.join(__dirname, "template.ejs");
|
|
36
|
+
const statusFieldTemplate = path.join(__dirname, "../../../createRecordByStatusType/statusFieldTemplate.ejs")
|
|
37
|
+
const storedCacheTemplate = path.join(__dirname, "../../../createRecordByStatusType/storedCacheTemplate.ejs")
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* receive objectSchema
|
|
@@ -50,10 +52,15 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
50
52
|
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
51
53
|
let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopic)
|
|
52
54
|
let topicArn = Object.keys(flowSchema.flowSteps)[0];
|
|
55
|
+
let statusType = flowSchema.statusType
|
|
53
56
|
return {
|
|
54
57
|
templatePath: templatePath,
|
|
55
58
|
templateData: {
|
|
56
|
-
topicArn
|
|
59
|
+
topicArn,
|
|
60
|
+
statusType,
|
|
61
|
+
statusFieldTemplate,
|
|
62
|
+
storedCacheTemplate,
|
|
63
|
+
flowTag: flowSchema.flowTag,
|
|
57
64
|
},
|
|
58
65
|
setting: {
|
|
59
66
|
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
|
|
@@ -32,9 +32,11 @@ const sns = externalRequest.sns
|
|
|
32
32
|
|
|
33
33
|
const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
|
|
34
34
|
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
35
|
-
const { v4: uuidv4 } = require('uuid')
|
|
36
35
|
const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
|
|
37
36
|
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
37
|
+
<% if (statusType === "statusField") { %>
|
|
38
|
+
const { createFieldNamesFromRequestParamsByObjectSchema } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs')
|
|
39
|
+
<% } %>
|
|
38
40
|
/**
|
|
39
41
|
*
|
|
40
42
|
*
|
|
@@ -64,18 +66,21 @@ module.exports.flowSchemaOwnTopic = async (
|
|
|
64
66
|
_izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
|
|
65
67
|
|
|
66
68
|
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
67
|
-
flowTag: requestParams.
|
|
69
|
+
flowTag: requestParams.action,
|
|
68
70
|
serviceTag: process.env.iz_serviceTag
|
|
69
|
-
// serviceTag: "GenerateCodeTamplateBas002"
|
|
70
71
|
})
|
|
71
72
|
|
|
72
73
|
_izContext.logger.debug("flowSchema", flowSchema)
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
if (!flowSchema) {
|
|
76
|
-
throw new NoRetryError(`flowTag not found ${requestParams.
|
|
77
|
+
throw new NoRetryError(`flowTag not found ${requestParams.action}`)
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
<% if (statusType === "statusField") { %>
|
|
81
|
+
<%- include(statusFieldTemplate) %>
|
|
82
|
+
<% } else if (statusType === "storedCache") { %>
|
|
83
|
+
<%- include(storedCacheTemplate) %>
|
|
79
84
|
let messageObject = {
|
|
80
85
|
requestParams:requestParams
|
|
81
86
|
}
|
|
@@ -92,10 +97,32 @@ module.exports.flowSchemaOwnTopic = async (
|
|
|
92
97
|
|
|
93
98
|
let sendMessageToCreateEndpoint = {
|
|
94
99
|
Message: JSON.stringify(messageObject),
|
|
95
|
-
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, )
|
|
100
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- topicArn %>")
|
|
96
101
|
}
|
|
97
102
|
_izContext.logger.debug("sendMessageToCreateEndpoint", sendMessageToCreateEndpoint);
|
|
98
103
|
await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
|
|
104
|
+
<% } else if (statusType === "none") { %>
|
|
105
|
+
let messageObject = {
|
|
106
|
+
requestParams:requestParams
|
|
107
|
+
}
|
|
108
|
+
// create callingFlow
|
|
109
|
+
messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
110
|
+
messageObject,
|
|
111
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
112
|
+
callingFlowConfig,
|
|
113
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
114
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.flowSchemaOwnTopicComplete), {}
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
let sendMessageToCreateEndpoint = {
|
|
120
|
+
Message: JSON.stringify(messageObject),
|
|
121
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- topicArn %>")
|
|
122
|
+
}
|
|
123
|
+
_izContext.logger.debug("sendMessageToCreateEndpoint", sendMessageToCreateEndpoint);
|
|
124
|
+
await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
|
|
125
|
+
<% } %>
|
|
99
126
|
|
|
100
127
|
} catch (err) {
|
|
101
128
|
_izContext.logger.error('error WebSocketInvoke: ', err)
|