@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.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -2
  3. package/src/reStructure/TemplateData/flowSchema/flowSchemaMainFunction/template.ejs +1 -4
  4. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +1 -1
  5. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +38 -5
  6. package/src/reStructure/TemplateData/flowSchema/templateByStatusType/triggerCacheTemplate.ejs +24 -11
  7. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/data.js +101 -0
  8. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/template.ejs +0 -0
  9. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/data.js +62 -0
  10. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/template.ejs +92 -0
  11. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/data.js +60 -0
  12. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/template.ejs +97 -0
  13. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/data.js +101 -0
  14. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/template.ejs +20 -0
  15. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/data.js +62 -0
  16. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/template.ejs +91 -0
  17. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/data.js +59 -0
  18. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/template.ejs +70 -0
  19. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/data.js +101 -0
  20. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/template.ejs +20 -0
  21. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/data.js +62 -0
  22. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/template.ejs +91 -0
  23. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/data.js +60 -0
  24. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/template.ejs +85 -0
  25. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/data.js +70 -0
  26. package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/template.ejs +43 -0
@@ -0,0 +1,101 @@
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, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SQS_RESOURCE, DYNAMO_RESOURCE, shortNameHandler } = require('../../../../../../MainLibs/src/Consts');
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = 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
+ const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+
27
+ /**
28
+ * receive objectSchema
29
+ *
30
+ * @param {Object} objectSchema
31
+ * @return {{templatePath, templateData,setting}}
32
+ */
33
+
34
+
35
+ async function data(_izContext, flowSchema, srcPath) {
36
+ return [await createSourceParams(_izContext, flowSchema, srcPath)]
37
+ }
38
+
39
+ async function createSourceParams(_izContext, flowSchema, srcPath) {
40
+ let functionName = "ProcessTriggerCache" + upperCase(flowSchema.flowTag)
41
+ let handlerType = upperCase(HANDLER.hdrSqs)
42
+ let additionalResourcePermission = defaultIamRolePerAction();
43
+ let queueName = "ProcessTriggerCache" + upperCase(flowSchema.flowTag) + handlerType;
44
+
45
+ additionalResourcePermission.push(
46
+ createIamRole(
47
+ {
48
+ [RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
49
+ },
50
+ [
51
+ resourceNames(RESOURCE_CLASSES.sqs, queueName),
52
+ resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
53
+ ]
54
+ ),
55
+ )
56
+
57
+ let tableTriggerCache = new Set();
58
+ let objectSchema = await getObjectSchema.getLocalObjectSchemas(_izContext, [flowSchema.objType.objectType], path.join(srcPath, "./schemas")).then(res => res.records[0])
59
+ if (!objectSchema) {
60
+ throw new NoRetryError('ObjectSchema not found')
61
+ }
62
+ for (const storageResource of Object.values(objectSchema.storageResources)) {
63
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
64
+ if (!tableTriggerCache.has(storageResource.tableName)) {
65
+ tableTriggerCache.add(storageResource.tableName)
66
+ }
67
+ }
68
+ }
69
+
70
+ additionalResourcePermission.push(
71
+ createIamRole(
72
+ {
73
+ [RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE)
74
+ },
75
+ [...tableTriggerCache].map(
76
+ tableName => resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName))
77
+ )
78
+ )
79
+
80
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
81
+ return {
82
+ templatePath: templatePath,
83
+ templateData: {
84
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
85
+ functionName,
86
+ handlerType,
87
+ additionalResourcePermission,
88
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
89
+ roleName: upperCase(flowSchema.flowTag),
90
+ queueName
91
+ },
92
+ setting: {
93
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
94
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
95
+ fileExtension: ".yml",
96
+ isAppend: true
97
+ }
98
+ }
99
+ }
100
+
101
+ module.exports = data;
@@ -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}<%- queueName %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framework 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
+ } _%>
@@ -0,0 +1,62 @@
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
+ 'use strict';
20
+ const path = require('path');
21
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
22
+ const { SOURCE_PATH, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction } = require('../../../../../../MainLibs/src/Consts');
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = 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
+ const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ /**
29
+ * receive objectSchema
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+
35
+
36
+ function data(_izContext, flowSchema, srcPath) {
37
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ function createSourceParams(_izContext, flowSchema, srcPath) {
41
+ let functionName = "ProcessTriggerCache" + upperCase(flowSchema.flowTag)
42
+ let handlerType = upperCase(HANDLER.hdrSqs)
43
+ let queueName = "ProcessTriggerCache" + upperCase(flowSchema.flowTag) + handlerType;
44
+
45
+
46
+ return {
47
+ templatePath: templatePath,
48
+ templateData: {
49
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
50
+ functionName,
51
+ queueName
52
+ },
53
+ setting: {
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
55
+ saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
56
+ fileExtension: ".js",
57
+ isAppend: true
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = data;
@@ -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,59 @@
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 = "ProcessTriggerCache" + upperCase(flowSchema.flowTag)
40
+ let handlerType = upperCase(HANDLER.hdrSqs)
41
+ let queueName = "ProcessTriggerCache" + upperCase(flowSchema.flowTag) + handlerType;
42
+
43
+
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName,
48
+ queueName
49
+ },
50
+ setting: {
51
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
52
+ saveFileName: `${upperCase(functionName)}_Main`,
53
+ fileExtension: ".js",
54
+ isAppend: true
55
+ }
56
+ }
57
+ }
58
+
59
+ 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 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
+ //(<optionalRequire>)
34
+ //(</optionalRequire>)
35
+ /**
36
+ *
37
+ *
38
+ * description of function.
39
+ * @param {Object} _izContext
40
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
41
+ * @param {Logger} _izContext.logger - property of _izContext
42
+ * @param {Object} requestParams - request params
43
+ * @param {Object} requestParams.identifiers - identifiers for get data
44
+ * @param {Object} requestParams.additionalRequest - additionalRequest
45
+ *
46
+ *
47
+ * @returns {object} description of return value
48
+ */
49
+
50
+ module.exports.<%- functionName %> = async (
51
+ _izContext,
52
+ requestParams,
53
+ //(<additionalParams>)
54
+ //(</additionalParams>)
55
+ callingFlowConfig = {},
56
+ ) => {
57
+
58
+ try {
59
+ _izContext.logger.debug("<%- functionName %> _izContext", _izContext)
60
+ _izContext.logger.debug("<%- functionName %> requestParams", requestParams)
61
+ _izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
62
+
63
+ //(<endpointHook>)
64
+ //(</endpointHook>)
65
+
66
+ } catch (err) {
67
+ _izContext.logger.error('error WebSocketInvoke: ', err)
68
+ throw (err)
69
+ }
70
+ }
@@ -0,0 +1,101 @@
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, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SQS_RESOURCE, DYNAMO_RESOURCE, shortNameHandler } = require('../../../../../../MainLibs/src/Consts');
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = 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
+ const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+
27
+ /**
28
+ * receive objectSchema
29
+ *
30
+ * @param {Object} objectSchema
31
+ * @return {{templatePath, templateData,setting}}
32
+ */
33
+
34
+
35
+ async function data(_izContext, flowSchema, srcPath) {
36
+ return [await createSourceParams(_izContext, flowSchema, srcPath)]
37
+ }
38
+
39
+ async function createSourceParams(_izContext, flowSchema, srcPath) {
40
+ let functionName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
41
+ let handlerType = upperCase(HANDLER.hdrSqs)
42
+ let additionalResourcePermission = defaultIamRolePerAction();
43
+ let queueName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
44
+
45
+ additionalResourcePermission.push(
46
+ createIamRole(
47
+ {
48
+ [RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
49
+ },
50
+ [
51
+ resourceNames(RESOURCE_CLASSES.sqs, queueName),
52
+ resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
53
+ ]
54
+ ),
55
+ )
56
+
57
+ let tableTriggerCache = new Set();
58
+ let objectSchema = await getObjectSchema.getLocalObjectSchemas(_izContext, [flowSchema.objType.objectType], path.join(srcPath, "./schemas")).then(res => res.records[0])
59
+ if (!objectSchema) {
60
+ throw new NoRetryError('ObjectSchema not found')
61
+ }
62
+ for (const storageResource of Object.values(objectSchema.storageResources)) {
63
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
64
+ if (!tableTriggerCache.has(storageResource.tableName)) {
65
+ tableTriggerCache.add(storageResource.tableName)
66
+ }
67
+ }
68
+ }
69
+
70
+ additionalResourcePermission.push(
71
+ createIamRole(
72
+ {
73
+ [RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE)
74
+ },
75
+ [...tableTriggerCache].map(
76
+ tableName => resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName))
77
+ )
78
+ )
79
+
80
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
81
+ return {
82
+ templatePath: templatePath,
83
+ templateData: {
84
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
85
+ functionName,
86
+ handlerType,
87
+ additionalResourcePermission,
88
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
89
+ roleName: upperCase(flowSchema.flowTag),
90
+ queueName
91
+ },
92
+ setting: {
93
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
94
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
95
+ fileExtension: ".yml",
96
+ isAppend: true
97
+ }
98
+ }
99
+ }
100
+
101
+ module.exports = data;
@@ -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}<%- queueName %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framework 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
+ } _%>
@@ -0,0 +1,62 @@
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
+ 'use strict';
20
+ const path = require('path');
21
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
22
+ const { SOURCE_PATH, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction } = require('../../../../../../MainLibs/src/Consts');
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = 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
+ const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ /**
29
+ * receive objectSchema
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+
35
+
36
+ function data(_izContext, flowSchema, srcPath) {
37
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ function createSourceParams(_izContext, flowSchema, srcPath) {
41
+ let functionName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
42
+ let handlerType = upperCase(HANDLER.hdrSqs)
43
+ let queueName = "TriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
44
+
45
+
46
+ return {
47
+ templatePath: templatePath,
48
+ templateData: {
49
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
50
+ functionName,
51
+ queueName
52
+ },
53
+ setting: {
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
55
+ saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
56
+ fileExtension: ".js",
57
+ isAppend: true
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = data;