@izara_project/izara-market-library-service-schemas 1.0.31 → 1.0.32
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 +9 -9
- package/src/GenerateCodeLibs/src/Consts.js +27 -12
- package/src/MainLibs/src/Consts.js +7 -4
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +2 -5
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +1 -1
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +1 -1
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +5 -5
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/sqs/template.ejs +18 -18
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +73 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +53 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +75 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +10 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +83 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +17 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +65 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template copy.ejs +125 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +130 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +61 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +70 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +147 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +18 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +64 -0
- package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowSchema → externalTopic/websocket}/handler/template.ejs +17 -16
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +60 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +74 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → EndpointComponent}/functionYaml/data.js +15 -23
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → EndpointComponent}/functionYaml/template.ejs +6 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +57 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +84 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +52 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +73 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/functionYaml/data.js +25 -23
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/functionYaml/template.ejs +10 -6
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/handler/data.js +6 -20
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +84 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/mainFunction/data.js +4 -15
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/mainFunction/template.ejs +16 -33
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +117 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +24 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/handler/data.js +6 -19
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaComponent}/handler/template.ejs +4 -3
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +96 -0
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +163 -115
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +10 -0
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +3 -3
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +3 -3
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +13 -14
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +3 -3
- /package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{sns-out/data.js → sns-in/template.ejs} +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
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 path = require('path');
|
|
21
|
+
|
|
22
|
+
const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
const { firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
24
|
+
const {
|
|
25
|
+
SOURCE_PATH,
|
|
26
|
+
defaultIamRolePerAction,
|
|
27
|
+
createIamRole,
|
|
28
|
+
RESOURCE_CLASSES,
|
|
29
|
+
SNS_RESOURCE,
|
|
30
|
+
resourceNames,
|
|
31
|
+
DYNAMO_RESOURCE,
|
|
32
|
+
SAVE_FILE_NAME,
|
|
33
|
+
FUNCTION_NAME,
|
|
34
|
+
shortNameHandler,
|
|
35
|
+
externalResourceYaml,
|
|
36
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
37
|
+
} = require("../../../../../../MainLibs/src/Consts");
|
|
38
|
+
|
|
39
|
+
const templatePath = path.join(__dirname, "template.ejs");
|
|
40
|
+
const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
|
|
41
|
+
/**
|
|
42
|
+
* receive objectSchema
|
|
43
|
+
* create data for WebScoket handler template
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} objectSchema
|
|
46
|
+
* @return {{templatePath, templateData,setting}}
|
|
47
|
+
*/
|
|
48
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
49
|
+
return [createSourceParams(_izContext, flowSchema, srcPath)]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
53
|
+
let functionName = upperCase(flowSchema.flowTag);
|
|
54
|
+
let handlerType = upperCase(HANDLER.hdrSqs);
|
|
55
|
+
let externalTopicName = FUNCTION_NAME.flowSchemaExternalTopic + 'Out';
|
|
56
|
+
let externalTopicShortName = 'ExtTopicOut';
|
|
57
|
+
let functionConfig = upperCase(flowSchema.flowTag) + externalTopicShortName + upperCase(shortNameHandler(handlerType));
|
|
58
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
59
|
+
const handler = HANDLER.hdrSqs; // Using hdrSqs as the default handler
|
|
60
|
+
const action = flowSchema.flowTag || 'defaultAction'; // Using flowTag as the action name
|
|
61
|
+
const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler));
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
templatePath: templatePath,
|
|
65
|
+
templateData: {
|
|
66
|
+
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
67
|
+
event,
|
|
68
|
+
functionName,
|
|
69
|
+
handlerType,
|
|
70
|
+
functionNameConfig: functionConfig,
|
|
71
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.ExternalTopicRole,
|
|
72
|
+
externalTopicName
|
|
73
|
+
},
|
|
74
|
+
setting: {
|
|
75
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
76
|
+
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
77
|
+
fileExtension: ".yml",
|
|
78
|
+
isAppend: true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = data;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%_ const join = require('path').join _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, functionName, `${firstLetterUpperCase(externalTopicName)}_${firstLetterUpperCase(handlerType)}.main`) %>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: <%- event %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
role: <%- firstLetterUpperCase(roleName) _%>Role
|
|
10
|
+
#<#<%_ functionName _%><%_ handlerType _%>IamRole#>
|
|
11
|
+
#<#/<%_ functionName _%><%_ handlerType _%>IamRole#>
|
|
12
|
+
<%_ function firstLetterUpperCase(text){
|
|
13
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
14
|
+
} _%>
|
|
15
|
+
<%_ function firstLetterLowerCase(str) {
|
|
16
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
17
|
+
} _%>
|
|
@@ -0,0 +1,65 @@
|
|
|
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 path = require('path');
|
|
21
|
+
const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
|
+
|
|
23
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts");
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
25
|
+
const templatePath = path.join(__dirname, "template.ejs")
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* receive objectSchema
|
|
29
|
+
* create data for SQS handler template
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} objectSchema
|
|
32
|
+
* @return {{templatePath, templateData,setting}}
|
|
33
|
+
*/
|
|
34
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
35
|
+
return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
39
|
+
const flowStepInSplitKey = Object.keys(flowSchema.flowSteps)[0].split('_');
|
|
40
|
+
if (flowStepInSplitKey.length < 4) {
|
|
41
|
+
_izContext.logger.error(`flowStepInSplitKey.length < 4: ${flowStepInSplitKey.length} ${flowSchema.flowTag}`);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const ExternalTopicName = FUNCTION_NAME.flowSchemaExternalTopic + 'Out';
|
|
45
|
+
let queueName = (flowStepInSplitKey[2]) + (flowStepInSplitKey[3]) + 'Out';
|
|
46
|
+
let functionName = upperCase(FUNCTION_NAME.flowSchemaExternalTopic)
|
|
47
|
+
let handlerType = upperCase(HANDLER.hdrSqs);
|
|
48
|
+
return {
|
|
49
|
+
templatePath: templatePath,
|
|
50
|
+
templateData: {
|
|
51
|
+
queueName,
|
|
52
|
+
fileName: ExternalTopicName + 'Out_Main',
|
|
53
|
+
functionMain: ExternalTopicName + 'Out',
|
|
54
|
+
handler: HANDLER.hdrSqs,
|
|
55
|
+
firstLetterUpperCase: upperCase,
|
|
56
|
+
},
|
|
57
|
+
setting: {
|
|
58
|
+
savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
|
|
59
|
+
saveFileName: `${functionName}Out_${handlerType}`,
|
|
60
|
+
fileExtension: ".js",
|
|
61
|
+
isAppend: false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
module.exports = data
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { middlewareHandler, consts } = require("@izara_project/izara-middleware");
|
|
20
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
21
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
22
|
+
const {validateSchemaPerRecord} = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs')
|
|
23
|
+
const recordHandlerSharedLib = require('@izara_project/izara-core-library-record-handler');
|
|
24
|
+
|
|
25
|
+
const { <%- action %>Main } =require('./<%- firstLetterUpperCase(action) %>_Main.js')
|
|
26
|
+
|
|
27
|
+
//(<globalVarible>
|
|
28
|
+
//</globalVarible>)
|
|
29
|
+
|
|
30
|
+
//validate event params in middleware before into main function
|
|
31
|
+
middleware.setValidatorSchema(
|
|
32
|
+
recordHandlerSharedLib.baseValidatorSchema(),
|
|
33
|
+
//(<middlewareSettings>)
|
|
34
|
+
//(</middlewareSettings>)
|
|
35
|
+
)
|
|
36
|
+
/*
|
|
37
|
+
const perRecordsValidatorSchema = {
|
|
38
|
+
type: "object",
|
|
39
|
+
required: [],
|
|
40
|
+
properties: {},
|
|
41
|
+
}
|
|
42
|
+
*/
|
|
43
|
+
//(<globalValidatorSchema>)
|
|
44
|
+
//(</globalValidatorSchema>)
|
|
45
|
+
|
|
46
|
+
// if need to validate authorizer or additional params , add code to hook tag below
|
|
47
|
+
|
|
48
|
+
module.exports.main = middlewareHandler.wrap(async (event,context, callback) => {
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
|
|
52
|
+
let recordPromises = [];
|
|
53
|
+
|
|
54
|
+
await Promise.all(event.Records.map(async record => {
|
|
55
|
+
record._izContext.logger.debug('record RecieveMsgOutHdrSqs', record);
|
|
56
|
+
|
|
57
|
+
let passOnProperties = [];
|
|
58
|
+
|
|
59
|
+
const OBJTYPE = {
|
|
60
|
+
objectType: record.body.Message.objectType,
|
|
61
|
+
serviceTag: process.env.iz_serviceTag
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await validateSchemaPerRecord(
|
|
65
|
+
record,
|
|
66
|
+
"<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handler) %>",
|
|
67
|
+
OBJTYPE,
|
|
68
|
+
"<%- action %>"
|
|
69
|
+
//(<validateSchemaSetting>)
|
|
70
|
+
//(</validateSchemaSetting>)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
//for validate additional params
|
|
74
|
+
/*
|
|
75
|
+
await recordHandlerSharedLib.validateRecord(
|
|
76
|
+
record,
|
|
77
|
+
"<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handler) %>",
|
|
78
|
+
perRecordsValidatorSchema
|
|
79
|
+
);
|
|
80
|
+
*/
|
|
81
|
+
//(<afterGenerateValidatorSchema>)
|
|
82
|
+
//(</afterGenerateValidatorSchema>)
|
|
83
|
+
|
|
84
|
+
//(<additionalParams>)
|
|
85
|
+
//(</additionalParams>)
|
|
86
|
+
|
|
87
|
+
passOnProperties.push(record.body.Message);
|
|
88
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
89
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
90
|
+
|
|
91
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
92
|
+
record,
|
|
93
|
+
<%- action %>Main, // mainFunction
|
|
94
|
+
'<%- firstLetterUpperCase(queueName) %>', // queueName
|
|
95
|
+
passOnProperties
|
|
96
|
+
);
|
|
97
|
+
record._izContext.logger.debug('after record Promise in handler');
|
|
98
|
+
recordPromises.push(recordPromise);
|
|
99
|
+
}))
|
|
100
|
+
|
|
101
|
+
Logger.debug('before Promise.all(recordPromise) in handler');
|
|
102
|
+
try {
|
|
103
|
+
await Promise.all(recordPromises);
|
|
104
|
+
|
|
105
|
+
return event.Records
|
|
106
|
+
} catch {
|
|
107
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
108
|
+
}
|
|
109
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
110
|
+
|
|
111
|
+
} catch (err) {
|
|
112
|
+
Logger.debug('unhandled error <%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handler) %>')
|
|
113
|
+
throw err
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
<%_ function firstLetterUpperCase(text){
|
|
121
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
122
|
+
} _%>
|
|
123
|
+
<%_ function firstLetterLowerCase(str) {
|
|
124
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
125
|
+
} _%>
|
|
@@ -0,0 +1,130 @@
|
|
|
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 { middlewareHandler } = require("@izara_project/izara-middleware");
|
|
24
|
+
const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
|
|
25
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
26
|
+
|
|
27
|
+
const { <%- functionMain %> } =require('./<%- firstLetterUpperCase(fileName) %>.js')
|
|
28
|
+
|
|
29
|
+
// validate event properties in body.Message of sqs event
|
|
30
|
+
middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
31
|
+
// set schema for record.body.Message
|
|
32
|
+
// const perRecordsValidatorSchema = {
|
|
33
|
+
// type: "object",
|
|
34
|
+
// required: ['param1', 'param2', 'param3', 'param4',],
|
|
35
|
+
// properties: {
|
|
36
|
+
// param1: {
|
|
37
|
+
// type: 'object',
|
|
38
|
+
// default: {}
|
|
39
|
+
// },
|
|
40
|
+
// param2: {
|
|
41
|
+
// type: 'string',
|
|
42
|
+
// default: true,
|
|
43
|
+
// pattern: "^[a-zA-Z0-9_-]+$",
|
|
44
|
+
// },
|
|
45
|
+
// param3: {
|
|
46
|
+
// type: 'array',
|
|
47
|
+
// items: { // items in array
|
|
48
|
+
// type: "object", // string
|
|
49
|
+
// properties: {
|
|
50
|
+
// "c": {
|
|
51
|
+
// type: "string"
|
|
52
|
+
// },
|
|
53
|
+
// "d": {
|
|
54
|
+
// type: "number"
|
|
55
|
+
// }
|
|
56
|
+
// },
|
|
57
|
+
// }
|
|
58
|
+
// },
|
|
59
|
+
// param4: {
|
|
60
|
+
// type: 'number',
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
// };
|
|
64
|
+
|
|
65
|
+
// set schema for record.body.MessageAttributes
|
|
66
|
+
const messageAttributeValidatorSchema = {
|
|
67
|
+
type: "object",
|
|
68
|
+
required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
69
|
+
properties: {
|
|
70
|
+
msgAtrrParam1: {
|
|
71
|
+
type: "string"
|
|
72
|
+
},
|
|
73
|
+
msgAtrrParam2: {
|
|
74
|
+
type: "object"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
|
|
83
|
+
let recordPromises = [];
|
|
84
|
+
|
|
85
|
+
// loop each record and send to mainFunction
|
|
86
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
87
|
+
|
|
88
|
+
let passOnProperties = []
|
|
89
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
90
|
+
|
|
91
|
+
//validate message (and MessageAttributes)
|
|
92
|
+
await recordHandlerSharedLib.validateRecord(
|
|
93
|
+
record, // one record will send to mainFunction
|
|
94
|
+
"<%- firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
|
|
95
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
96
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
100
|
+
passOnProperties.push(record.body.Message)
|
|
101
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
102
|
+
|
|
103
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
104
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
105
|
+
record, // one record will send to mainFunction
|
|
106
|
+
<%- functionMain %>, // mainFunction that need to invoke.
|
|
107
|
+
'<%- firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
|
|
108
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
109
|
+
);
|
|
110
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
111
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
112
|
+
}))
|
|
113
|
+
|
|
114
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
115
|
+
try {
|
|
116
|
+
// --- main await all promises
|
|
117
|
+
await Promise.all(recordPromises); // await all promises
|
|
118
|
+
|
|
119
|
+
return event.Records // return all for local testing
|
|
120
|
+
|
|
121
|
+
} catch {
|
|
122
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve');
|
|
123
|
+
}
|
|
124
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
125
|
+
|
|
126
|
+
} catch (err) {
|
|
127
|
+
Logger.error('Unhandled Error, <%- functionMain%>: ', err);
|
|
128
|
+
throw (err);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
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 path = require('path');
|
|
21
|
+
|
|
22
|
+
const { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require("../../../../../../MainLibs/src/Consts");
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
24
|
+
const templatePath = path.join(__dirname, "template.ejs");
|
|
25
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* receive objectSchema
|
|
29
|
+
* create data for Sqs Main template
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} objectSchema
|
|
32
|
+
* @return {{templatePath, templateData,setting}}
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
37
|
+
return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
41
|
+
let functionName = upperCase(FUNCTION_NAME.flowSchemaExternalTopic)
|
|
42
|
+
let snsTopicIn = Object.keys(flowSchema.flowSteps)
|
|
43
|
+
let snsTopicInWithoutUnderscore = snsTopicIn[0].replace(/_/g, '')
|
|
44
|
+
let handlerType = upperCase(HANDLER.hdrSqs);
|
|
45
|
+
// let objectSchema = await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(_izContext, flowSchema.objType)
|
|
46
|
+
// let fieldNames = Object.keys(objectSchema.fieldNames)
|
|
47
|
+
return {
|
|
48
|
+
templatePath: templatePath,
|
|
49
|
+
templateData: {
|
|
50
|
+
snsTopicIn: snsTopicInWithoutUnderscore,
|
|
51
|
+
externalTopicOutMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Out',
|
|
52
|
+
},
|
|
53
|
+
setting: {
|
|
54
|
+
savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
|
|
55
|
+
saveFileName: `${functionName}Out_Main`,
|
|
56
|
+
fileExtension: ".js",
|
|
57
|
+
isAppend: false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
module.exports = data
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
|
|
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.<%- externalTopicOutMain%>Main = async (
|
|
54
|
+
_izContext,
|
|
55
|
+
requestParams,
|
|
56
|
+
callingFlowConfig = {},
|
|
57
|
+
//(<additionalParams>)
|
|
58
|
+
//(</additionalParams>)
|
|
59
|
+
) => {
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
|
|
63
|
+
//(<additionalParams>)
|
|
64
|
+
//(</additionalParams>)
|
|
65
|
+
|
|
66
|
+
} catch (err) {
|
|
67
|
+
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
68
|
+
throw (err)
|
|
69
|
+
}
|
|
70
|
+
}
|