@izara_project/izara-market-library-service-schemas 1.0.69 → 1.0.71
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/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaMainFunction/template.ejs +1 -4
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +38 -5
- package/src/reStructure/TemplateData/flowSchema/templateByStatusType/triggerCacheTemplate.ejs +24 -11
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/template.ejs +0 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/template.ejs +92 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/data.js +60 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/template.ejs +97 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/template.ejs +91 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/data.js +59 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/template.ejs +70 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/template.ejs +91 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/data.js +60 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/data.js +70 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/template.ejs +43 -0
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
28
|
+
const <%- functionName %> = require('./<%- functionName %>_Main')
|
|
29
|
+
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
let perRecordsValidatorSchema = {
|
|
32
|
+
//(<validatorSchema>)
|
|
33
|
+
//(</validatorSchema>)
|
|
34
|
+
}
|
|
35
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
36
|
+
|
|
37
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
|
|
41
|
+
let recordPromises = [];
|
|
42
|
+
|
|
43
|
+
// loop each record and send to mainFunction
|
|
44
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
45
|
+
|
|
46
|
+
let passOnProperties = []
|
|
47
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
48
|
+
|
|
49
|
+
//validate message (and MessageAttributes)
|
|
50
|
+
await recordHandlerSharedLib.validateRecord(
|
|
51
|
+
record, // one record will send to mainFunction
|
|
52
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
53
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
54
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
58
|
+
passOnProperties.push(record.body.Message)
|
|
59
|
+
//(<additionalParams>)
|
|
60
|
+
//(</additionalParams>)
|
|
61
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
62
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
63
|
+
|
|
64
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
65
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
66
|
+
record, // one record will send to mainFunction
|
|
67
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
68
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
69
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
70
|
+
);
|
|
71
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
72
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
73
|
+
}))
|
|
74
|
+
|
|
75
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
76
|
+
try {
|
|
77
|
+
// --- main await all promises
|
|
78
|
+
await Promise.all(recordPromises); // await all promises
|
|
79
|
+
|
|
80
|
+
return event.Records // return all for local testing
|
|
81
|
+
|
|
82
|
+
} catch {
|
|
83
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
84
|
+
}
|
|
85
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
86
|
+
|
|
87
|
+
} catch (err) {
|
|
88
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
89
|
+
throw (err);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
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 NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
21
|
+
const { SOURCE_PATH, FUNCTION_NAME, HANDLER, SAVE_FILE_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
22
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = require("../../../../../../MainLibs/src/Utils")
|
|
23
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
24
|
+
|
|
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
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
35
|
+
return [createSourceParams(_izContext, flowSchema, srcPath)]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
39
|
+
let functionName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
|
|
40
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
|
+
let queueName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
templatePath: templatePath,
|
|
46
|
+
templateData: {
|
|
47
|
+
functionName,
|
|
48
|
+
queueName,
|
|
49
|
+
flowTag: flowSchema.flowTag
|
|
50
|
+
},
|
|
51
|
+
setting: {
|
|
52
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
|
|
53
|
+
saveFileName: `${upperCase(functionName)}_Main`,
|
|
54
|
+
fileExtension: ".js",
|
|
55
|
+
isAppend: true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
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 getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
22
|
+
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
23
|
+
const snsSharedLib = require('@izara_project/izara-core-library-sns');
|
|
24
|
+
const sqsSharedLib = require('@izara_project/izara-core-library-sqs');
|
|
25
|
+
const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
|
|
26
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
27
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
|
|
28
|
+
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
29
|
+
const sns = externalRequest.sns
|
|
30
|
+
const sqs = externalRequest.sqs
|
|
31
|
+
const lambda = externalRequest.lambda
|
|
32
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
33
|
+
const { createFlowTypeConcat } = require('@izara_project/izara-core-library-service-schemas').utils
|
|
34
|
+
//(<optionalRequire>)
|
|
35
|
+
//(</optionalRequire>)
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
* description of function.
|
|
40
|
+
* @param {Object} _izContext
|
|
41
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
42
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
43
|
+
* @param {Object} requestParams - request params
|
|
44
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
45
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
46
|
+
*
|
|
47
|
+
*
|
|
48
|
+
* @returns {object} description of return value
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
module.exports.<%- functionName %> = async (
|
|
52
|
+
_izContext,
|
|
53
|
+
requestParams,
|
|
54
|
+
//(<additionalParams>)
|
|
55
|
+
//(</additionalParams>)
|
|
56
|
+
callingFlowConfig = {},
|
|
57
|
+
) => {
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
_izContext.logger.debug("<%- functionName %> _izContext", _izContext)
|
|
61
|
+
_izContext.logger.debug("<%- functionName %> requestParams", requestParams)
|
|
62
|
+
_izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
|
|
63
|
+
|
|
64
|
+
let checkTriggerResetedV2 = await triggeredCacheSharedLib.checkTriggerResetedV2(
|
|
65
|
+
_izContext,
|
|
66
|
+
{ // flowType
|
|
67
|
+
serviceTag: process.env.iz_serviceTag,
|
|
68
|
+
flowTag: "<%- flowTag %>"
|
|
69
|
+
},
|
|
70
|
+
{ // identifiers of objType in flowType
|
|
71
|
+
trigger1Id: "frame1_1122"
|
|
72
|
+
},
|
|
73
|
+
"testUnique001"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
_izContext.logger.debug("checkTriggerResetedV2: ", checkTriggerResetedV2)
|
|
77
|
+
|
|
78
|
+
//(<endpointHook>)
|
|
79
|
+
//(</endpointHook>)
|
|
80
|
+
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
83
|
+
throw (err)
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/data.js
ADDED
|
@@ -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 <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const path = require("path")
|
|
21
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils.js");
|
|
22
|
+
const templatePath = path.join(__dirname, './template.ejs');
|
|
23
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
27
|
+
* return array of dynamoDb data
|
|
28
|
+
* because one objectSchema can create multiple dynamoDb table
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} _izContext
|
|
31
|
+
* @param {String} saveFilePath
|
|
32
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function createDataForDefaultSnsInSqs(flowSchema, srcPath) {
|
|
36
|
+
let resultsForCreateDefaultSnsInSqs = [];
|
|
37
|
+
let flowTag = upperCase(flowSchema.flowTag)
|
|
38
|
+
// console.log("create topic by flowSteps", flowSteps)
|
|
39
|
+
const setting = {
|
|
40
|
+
initialData: "Resources:\n",
|
|
41
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
42
|
+
saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
|
|
43
|
+
fileExtension: ".yml",
|
|
44
|
+
isAppend: true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let generateTriggerCacheQueueNames = [
|
|
48
|
+
{
|
|
49
|
+
queueName: "ProcessTriggerCache" + upperCase(flowTag) + upperCase(HANDLER.hdrSqs)
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
queueName: "CheckTriggerCache" + upperCase(flowTag) + "Complete" + upperCase(HANDLER.hdrSqs)
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
queueName: "TriggerCache" + upperCase(flowTag) + "Complete" + upperCase(HANDLER.hdrSqs)
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
for (let defaultSnsInSqsData of generateTriggerCacheQueueNames) {
|
|
60
|
+
resultsForCreateDefaultSnsInSqs.push({
|
|
61
|
+
templatePath: templatePath,
|
|
62
|
+
templateData: defaultSnsInSqsData,
|
|
63
|
+
setting: setting
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return resultsForCreateDefaultSnsInSqs;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = createDataForDefaultSnsInSqs;
|
package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/template.ejs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#------- queue ---------
|
|
2
|
+
<%- queueName %>:
|
|
3
|
+
Type: "AWS::SQS::Queue"
|
|
4
|
+
Properties:
|
|
5
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
|
|
6
|
+
RedrivePolicy:
|
|
7
|
+
deadLetterTargetArn: #!GetAtt
|
|
8
|
+
Fn::GetAtt:
|
|
9
|
+
- <%- queueName %>DLQ
|
|
10
|
+
- Arn
|
|
11
|
+
maxReceiveCount: 3
|
|
12
|
+
VisibilityTimeout: 120
|
|
13
|
+
|
|
14
|
+
<%- queueName %>DLQ:
|
|
15
|
+
Type: AWS::SQS::Queue
|
|
16
|
+
Properties:
|
|
17
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
|
|
18
|
+
|
|
19
|
+
<%- queueName %>Policy:
|
|
20
|
+
Type: AWS::SQS::QueuePolicy
|
|
21
|
+
Properties:
|
|
22
|
+
PolicyDocument:
|
|
23
|
+
Version: "2012-10-17"
|
|
24
|
+
Statement:
|
|
25
|
+
- Sid: "allow-sns-messages"
|
|
26
|
+
Effect: Allow
|
|
27
|
+
Principal: "*"
|
|
28
|
+
Resource: #!GetAtt
|
|
29
|
+
Fn::GetAtt:
|
|
30
|
+
- <%- queueName %>
|
|
31
|
+
- Arn
|
|
32
|
+
Action: "SQS:SendMessage"
|
|
33
|
+
Queues:
|
|
34
|
+
- Ref: <%- queueName %>
|
|
35
|
+
#<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
36
|
+
#<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
37
|
+
|
|
38
|
+
<%_ function firstLetterUpperCase(text){
|
|
39
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
40
|
+
} _%>
|
|
41
|
+
<%_ function firstLetterLowerCase(str) {
|
|
42
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
43
|
+
} _%>
|