@izara_project/izara-market-library-service-schemas 1.0.32 → 1.0.33

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 (49) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/MainLibs/src/Consts.js +7 -2
  4. package/src/reStructure/GenerateCode.js +16 -18
  5. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
  6. package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
  7. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +15 -15
  8. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
  9. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
  10. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  11. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
  12. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
  13. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +0 -0
  14. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
  15. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
  16. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
  17. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
  18. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
  19. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
  20. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
  21. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
  22. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
  23. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
  25. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +1 -1
  26. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +1 -1
  27. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
  28. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +20 -0
  29. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
  30. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
  31. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
  32. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
  33. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +3 -28
  34. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +6 -10
  35. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +4 -2
  36. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +4 -3
  37. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +26 -0
  38. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +2 -2
  39. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +6 -10
  40. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +4 -4
  41. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -4
  42. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +3 -4
  43. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +18 -18
  44. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
  45. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
  46. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +55 -10
  47. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +27 -7
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template copy.ejs +0 -125
  49. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/sns-in/template.ejs → createRecordByStatusType/statusFieldTemplate.ejs} +0 -0
@@ -0,0 +1,77 @@
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 { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ // const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, checkOverWriteGenerateMainFunction } = require("../#utils");
25
+ // const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../#const");
26
+ const {
27
+ utils: {
28
+ firstLetterLowerCase: lowerCase,
29
+ firstLetterUpperCase: upperCase,
30
+ firstLetterUpperCase,
31
+ checkOverWriteGenerateMainFunction
32
+ },
33
+ consts: {
34
+ DEFAULT_HANDLER_PER_ACTION,
35
+ SOURCE_PATH,
36
+ FUNCTION_NAME,
37
+ SOURCE_GENERATE_IAM_ROLE
38
+ }
39
+ } = require("../../../../../../MainLibs");
40
+
41
+ const templatePath = path.join(__dirname, "./template.ejs")
42
+ /**
43
+ * receive objectSchema
44
+ * create data for hdrInv template
45
+ *
46
+ * @param {Object} _izContext
47
+ * @param {Object} flowSchema
48
+ * @param {String} srcPath
49
+ * @return {Object[]}
50
+ */
51
+ function data(_izContext, flowSchema, srcPath) {
52
+ const handler = HANDLER.hdrInv;
53
+ const flowTag = flowSchema.flowTag;
54
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
55
+ const functionName = flowTag + action;
56
+ const fileName = `${upperCase(flowTag)}${upperCase(action)}_${upperCase(handler)}`;
57
+ return [{
58
+ templatePath: templatePath,
59
+ templateData: {
60
+ functionName: functionName,
61
+ flowTag: flowTag,
62
+ action: action,
63
+ handler,
64
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
65
+ firstLetterUpperCase: upperCase,
66
+ },
67
+ setting: {
68
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
69
+ saveFileName: fileName,
70
+ fileExtension: '.js',
71
+ isAppend: false
72
+ }
73
+ }]
74
+ }
75
+
76
+
77
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,64 @@
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 { middlewareHandler } = require("@izara_project/izara-middleware");
21
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
22
+ validateSchemaMiddleware
23
+ const {
24
+ validateSchemaMiddleware
25
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
26
+
27
+ const { <%- functionName %>Main } =require('./<%- firstLetterUpperCase(functionName)%>_Main')
28
+
29
+ //(<globalVariable>
30
+ //</globalVariable>)
31
+
32
+
33
+ //(<afterValidateWithGenereatedSchema>)
34
+ //(</afterValidateWithGenereatedSchema>)
35
+
36
+
37
+ module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
38
+ event._izContext.logger.debug('Event:', event);
39
+ event._izContext.logger.debug('context:', context);
40
+
41
+ try {
42
+
43
+ //(<beforeInvoke>)
44
+ //(</beforeInvoke>)
45
+
46
+ // invoke LambdaFunction
47
+ return await <%- functionName %>Main(
48
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
49
+ event,
50
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
51
+ );
52
+
53
+ } catch (err) {
54
+ event._izContext.logger.error('Error, <%- firstLetterUpperCase(flowTag) %>: ', err);
55
+ throw (err);
56
+ }
57
+ });
58
+
59
+ <%_ function firstLetterUpperCase(text){
60
+ return text.charAt(0).toUpperCase() + text.slice(1)
61
+ } _%>
62
+ <%_ function firstLetterLowerCase(str) {
63
+ return str.charAt(0).toLowerCase() + str.slice(1)
64
+ } _%>
@@ -0,0 +1,73 @@
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 { consts: { ACTIONS, HANDLER } } = require('@izara_project/izara-core-library-service-schemas')
23
+
24
+ // const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../#utils");
25
+ // const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../#const");
26
+ const {
27
+ utils: {
28
+ firstLetterLowerCase: lowerCase,
29
+ firstLetterUpperCase: upperCase,
30
+ checkOverWriteGenerateMainFunction
31
+ },
32
+ consts: {
33
+ DEFAULT_HANDLER_PER_ACTION,
34
+ SOURCE_PATH,
35
+ SOURCE_GENERATE_IAM_ROLE
36
+ }
37
+ } = require("../../../../../MainLibs");
38
+
39
+ const templatePath = path.join(__dirname, "./template.ejs")
40
+
41
+ /**
42
+ * receive objectSchema
43
+ * create data for hdrInv template
44
+ *
45
+ * @param {Object} flowSchema
46
+ * @return {{ templatePath, templateData, setting } }
47
+ */
48
+ function data(_izContext, flowSchema, srcPath) {
49
+ const handler = HANDLER.hdrInv;
50
+ const flowTag = flowSchema.flowTag;
51
+ const functionName = flowTag + upperCase(handler);
52
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
53
+ const fileName = `${upperCase(flowTag)}${upperCase(action)}_Main`;
54
+ return [{
55
+ templatePath: templatePath,
56
+ templateData: {
57
+ functionName: functionName,
58
+ flowTag: flowTag,
59
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
60
+ action: action,
61
+ firstLetterUpperCase: upperCase,
62
+ },
63
+ setting: {
64
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
65
+ saveFileName: fileName,
66
+ fileExtension: '.js',
67
+ isAppend: false
68
+ }
69
+ }]
70
+ }
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,5 @@
1
+ {
2
+ "getDataDetail": "object",
3
+ "objectType": "string",
4
+ "functionName": "string"
5
+ }
@@ -0,0 +1,88 @@
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 {
22
+ getObjSchemaS3WithHierarchy,
23
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
24
+ const {
25
+ getGraphServiceTagWithCache,
26
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
27
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
28
+ const {
29
+ objInstanceFromobjInstanceBase
30
+ } = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
31
+
32
+ const {
33
+ dynamoDbIdentifiersByStorageResource,
34
+ collectGetData,
35
+ createGetDataDetails,
36
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
37
+
38
+ const { createObjTypeConcat } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
39
+
40
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
41
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
42
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
43
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
44
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
45
+
46
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
47
+ const sns = externalRequest.sns
48
+
49
+ const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
50
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
51
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
52
+
53
+ /**
54
+ *
55
+ *
56
+ * description of function.
57
+ * @param {Object} _izContext
58
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
59
+ * @param {Logger} _izContext.logger - property of _izContext
60
+ * @param {Object} requestParams - request params
61
+ * @param {Object} requestParams.identifiers - identifiers for get data
62
+ * @param {Object} requestParams.additionalRequest - additionalRequest
63
+ *
64
+ *
65
+ * @returns {object} description of return value
66
+ */
67
+ module.exports.<%- functionName %>Main = async (
68
+ _izContext,
69
+ requestParams,
70
+ callingFlowConfig = {},
71
+ //(<additionalParams>)
72
+ //(</additionalParams>)
73
+ ) => {
74
+
75
+
76
+ try {
77
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
78
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
79
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
80
+
81
+ //(<additionalParams>)
82
+ //(</additionalParams>)
83
+
84
+ } catch (err) {
85
+ _izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
86
+ throw (err)
87
+ }
88
+ }
@@ -55,7 +55,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
55
55
  firstLetterUpperCase: upperCase,
56
56
  },
57
57
  setting: {
58
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
58
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
59
59
  saveFileName: `${functionName}Out_${handlerType}`,
60
60
  fileExtension: ".js",
61
61
  isAppend: false
@@ -51,7 +51,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
51
51
  externalTopicOutMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Out',
52
52
  },
53
53
  setting: {
54
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
55
55
  saveFileName: `${functionName}Out_Main`,
56
56
  fileExtension: ".js",
57
57
  isAppend: false
@@ -54,7 +54,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
54
54
  flowTag
55
55
  },
56
56
  setting: {
57
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
57
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
58
58
  saveFileName: `${upperCase(functionName)}_${handlerType}`,
59
59
  fileExtension: ".js",
60
60
  isAppend: false
@@ -50,7 +50,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
50
50
  externalTopicMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Main',
51
51
  },
52
52
  setting: {
53
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
53
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
54
54
  saveFileName: `${functionName}_Main`,
55
55
  fileExtension: ".js",
56
56
  isAppend: false
@@ -0,0 +1,89 @@
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 { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
+ const {
24
+ SOURCE_PATH,
25
+ defaultIamRolePerAction,
26
+ createIamRole,
27
+ RESOURCE_CLASSES,
28
+ SNS_RESOURCE,
29
+ resourceNames,
30
+ DYNAMO_RESOURCE,
31
+ SAVE_FILE_NAME,
32
+ FUNCTION_NAME,
33
+ shortNameHandler,
34
+ externalResourceYaml,
35
+ SOURCE_GENERATE_IAM_ROLE
36
+ } = require('../../../../../../MainLibs/src/Consts');
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('../../../../../../GenerateCodeLibs/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
+
49
+ function data(_izContext, flowSchema, srcPath) {
50
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
51
+ }
52
+
53
+ function createSourceParams(_izContext, flowSchema, srcPath) {
54
+ let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
55
+ let handlerType = upperCase(HANDLER.hdrSqs)
56
+ let additionalResourcePermission = defaultIamRolePerAction();
57
+ let flowSteps = Object.keys(flowSchema.flowSteps)
58
+ additionalResourcePermission.push(
59
+ createIamRole(
60
+ {
61
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
62
+ },
63
+ [
64
+ resourceNames(RESOURCE_CLASSES.sns, flowSteps[1])
65
+ ]
66
+ )
67
+ )
68
+
69
+
70
+ return {
71
+ templatePath: templatePath,
72
+ templateData: {
73
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaOwnTopic, flowSchema.flowTag, "source/"),
74
+ functionName,
75
+ handlerType,
76
+ additionalResourcePermission,
77
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
78
+ roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaOwnTopic
79
+ },
80
+ setting: {
81
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
82
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
83
+ fileExtension: ".yml",
84
+ isAppend: true
85
+ }
86
+ }
87
+ }
88
+
89
+ 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}<%- 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
+ } _%>
@@ -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