@izara_project/izara-market-library-service-schemas 1.0.41 → 1.0.42

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 (88) hide show
  1. package/package.json +1 -1
  2. package/src/MainLibs/src/Consts.js +1 -1
  3. package/src/reStructure/GenerateSchema.js +6 -6
  4. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -12
  5. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +23 -8
  6. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +28 -21
  7. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +0 -32
  8. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +1 -1
  9. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +1 -0
  10. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/template.ejs +1 -0
  11. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +1 -1
  12. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/template.ejs +1 -0
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/functionYaml/template.ejs +1 -0
  14. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +5 -2
  15. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +0 -20
  16. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +7 -16
  17. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +2 -2
  18. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +0 -1
  19. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/functionYaml/data.js +112 -0
  20. package/src/reStructure/TemplateData/flowSchema/externalTopic/{functionYaml → Complete/functionYaml}/template.ejs +1 -0
  21. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/handler/data.js +93 -0
  22. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/mainFunction/data.js +61 -0
  23. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/mainFunction/template.ejs +96 -0
  24. package/src/reStructure/TemplateData/flowSchema/externalTopic/{functionYaml → Process/functionYaml}/data.js +20 -4
  25. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → externalTopic/Process}/functionYaml/template.ejs +1 -0
  26. package/src/reStructure/TemplateData/flowSchema/externalTopic/{handler → Process/handler}/data.js +3 -3
  27. package/src/reStructure/TemplateData/flowSchema/externalTopic/Process/handler/template.ejs +87 -0
  28. package/src/reStructure/TemplateData/flowSchema/externalTopic/{mainFunction → Process/mainFunction}/data.js +2 -2
  29. package/src/reStructure/TemplateData/flowSchema/externalTopic/{mainFunction → Process/mainFunction}/template.ejs +2 -2
  30. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +14 -4
  31. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/sqsTemplate.ejs +52 -0
  32. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +1 -1
  33. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +4 -4
  34. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +1 -0
  35. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +1 -2
  36. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +5 -5
  38. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +5 -2
  39. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +1 -1
  40. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -0
  41. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +1 -1
  42. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +2 -0
  43. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +3 -2
  44. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +2 -2
  45. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +1 -1
  46. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +1 -1
  47. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +2 -2
  48. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +9 -21
  49. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +0 -10
  50. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +1 -1
  51. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/functionYaml/data.js +36 -23
  52. package/src/reStructure/TemplateData/flowSchema/flowStep/functionYaml/template.ejs +20 -0
  53. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/handler/data.js +22 -18
  54. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/mainFunction/data.js +22 -18
  55. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/data.js +90 -0
  56. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/template.ejs +45 -0
  57. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +41 -25
  58. package/src/reStructure/TemplateData/flowSchema/register/complete/functionYaml/data.js +1 -0
  59. package/src/reStructure/TemplateData/flowSchema/register/complete/functionYaml/template.ejs +1 -0
  60. package/src/reStructure/TemplateData/flowSchema/register/complete/handler/data.js +0 -1
  61. package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +16 -17
  62. package/src/reStructure/TemplateData/flowSchema/register/dynamoDB/register.js +0 -17
  63. package/src/reStructure/TemplateData/flowSchema/register/sns-in/data.js +0 -1
  64. package/src/reStructure/TemplateData/flowSchema/register/subscriptionOutAll/data.js +1 -3
  65. package/src/reStructure/TemplateData/flowSchema/register/subscriptionOutAll/template.ejs +2 -2
  66. package/src/reStructure/TemplateData/flowSchema/register/wbs/functionYaml/data.js +0 -29
  67. package/src/reStructure/TemplateData/flowSchema/register/wbs/handler/data.js +0 -1
  68. package/src/reStructure/TemplateData/flowSchema/register/wbs/handler/template.ejs +0 -5
  69. package/src/reStructure/TemplateData/flowSchema/register/wbs/mainFunction/template.ejs +16 -15
  70. package/src/reStructure/TemplateData/flowSchema/templateBystatusType/triggerCacheTemplate.ejs +7 -1
  71. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/functionYaml/data.js +1 -1
  72. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/functionYaml/template.ejs +2 -1
  73. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/sqs/data.js +97 -0
  74. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/sqs/template.ejs +52 -0
  75. package/src/reStructure/TemplateData/perActionComplete/create/yaml/template.ejs +1 -0
  76. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/template.ejs +1 -0
  77. package/src/reStructure/TemplateData/perActionComplete/get/yaml/template.ejs +1 -0
  78. package/src/reStructure/TemplateData/perActionComplete/update/yaml/template.ejs +1 -0
  79. package/src/reStructure/TemplateData/propertyValueSchema/generateTemplateData.js +18 -18
  80. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +82 -79
  81. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +33 -37
  82. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/template.ejs +1 -0
  83. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/template.ejs +1 -0
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/template.ejs +1 -0
  85. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/template.ejs +1 -0
  86. /package/src/reStructure/TemplateData/flowSchema/externalTopic/{handler → Complete/handler}/template.ejs +0 -0
  87. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/handler/template.ejs +0 -0
  88. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/mainFunction/template.ejs +0 -0
@@ -0,0 +1,93 @@
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, STORAGE_TYPES } = 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
+ SQS_RESOURCE,
37
+ LAMBDA_RESOURCE
38
+ } = require('../../../../../../MainLibs/src/Consts');
39
+ const { NoRetryError } = require('@izara_project/izara-core-library-core');
40
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas').getObjectSchema;
41
+
42
+ const templatePath = path.join(__dirname, "template.ejs");
43
+ /**
44
+ * receive objectSchema
45
+ * create data for WebScoket handler template
46
+ *
47
+ * @param {Object} objectSchema
48
+ * @return {{templatePath, templateData,setting}}
49
+ */
50
+
51
+ function data(_izContext, flowSchema, srcPath) {
52
+ if (!flowSchema.outputTopic) {
53
+ return []
54
+ } else {
55
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
56
+ }
57
+ }
58
+
59
+ function createSourceParams(_izContext, flowSchema, srcPath) {
60
+ let functionName = upperCase(flowSchema.flowTag) + "Complete"
61
+ let handlerType = upperCase(HANDLER.hdrSqs)
62
+ let additionalResourcePermission = defaultIamRolePerAction();
63
+ let queueName = functionName + handlerType;
64
+
65
+ additionalResourcePermission.push(
66
+ createIamRole(
67
+ {
68
+ [RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
69
+ },
70
+ [
71
+ resourceNames(RESOURCE_CLASSES.sqs, queueName),
72
+ resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
73
+ ]
74
+ )
75
+ )
76
+
77
+ return {
78
+ templatePath: templatePath,
79
+ templateData: {
80
+ functionName,
81
+ handlerType,
82
+ queueName
83
+ },
84
+ setting: {
85
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, flowSchema.flowTag, "source/"),
86
+ saveFileName: `${functionName}_${handlerType}`,
87
+ fileExtension: ".js",
88
+ isAppend: false
89
+ }
90
+ }
91
+ }
92
+
93
+ module.exports = data;
@@ -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
+ const path = require('path');
20
+
21
+ const { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require('../../../../../../MainLibs/src/Consts');
22
+
23
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
24
+ const templatePath = path.join(__dirname, "template.ejs");
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
+ if (!flowSchema.outputTopic) {
37
+ return []
38
+ } else {
39
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
40
+ }
41
+ }
42
+
43
+ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
44
+ let functionName = upperCase(flowSchema.flowTag) + "Complete";
45
+ let flowSchemaComplete = functionName + "Complete"
46
+ return {
47
+ templatePath: templatePath,
48
+ templateData: {
49
+ flowTag: flowSchema.flowTag,
50
+ functionName,
51
+ flowSchemaComplete
52
+ },
53
+ setting: {
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, flowSchema.flowTag, "source/"),
55
+ saveFileName: `${functionName}_Main`,
56
+ fileExtension: ".js",
57
+ isAppend: false
58
+ }
59
+ }
60
+ }
61
+ module.exports = data
@@ -0,0 +1,96 @@
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('@izara_project/izara-shared-core').objectHash;
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 sqsSharedLib = require('@izara_project/izara-core-library-sqs');
27
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
28
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
29
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
30
+ const storedCacheSharedLib = require('@izara_project/izara-core-library-stored-cache')
31
+
32
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
33
+ const sns = externalRequest.sns
34
+ const sqs = externalRequest.sqs
35
+ const lambda = externalRequest.lambda
36
+ const { postToConnection } = require("../../../libs/source/GenerateCodeLibs");
37
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
38
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
39
+ const { v4: uuidv4 } = require('uuid')
40
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
41
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
42
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
43
+ const { createFieldNamesFromRequestParamsByObjectSchema } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs.js')
44
+ //(<optionalRequire>)
45
+ //(</optionalRequire>)
46
+ /**
47
+ *
48
+ *
49
+ * description of function.
50
+ * @param {Object} _izContext
51
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
52
+ * @param {Logger} _izContext.logger - property of _izContext
53
+ * @param {Object} requestParams - request params
54
+ * @param {Object} requestParams.identifiers - identifiers for get data
55
+ * @param {Object} requestParams.additionalRequest - additionalRequest
56
+ *
57
+ *
58
+ * @returns {object} description of return value
59
+ */
60
+
61
+ module.exports.<%- functionName %> = async (
62
+ _izContext,
63
+ requestParams,
64
+ callingFlowConfig = {},
65
+ //(<additionalParams>)
66
+ //(</additionalParams>)
67
+ ) => {
68
+
69
+ try {
70
+ _izContext.logger.debug("<%- functionName %> _izContext", _izContext)
71
+ _izContext.logger.debug("<%- functionName %> requestParams", requestParams)
72
+ _izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
73
+
74
+ let correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID)
75
+ let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID);
76
+
77
+ //(<endpointHookMainFunction>)
78
+ //(</endpointHookMainFunction>)
79
+
80
+ const flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
81
+ flowTag: "<%- flowTag %>",
82
+ serviceTag: process.env.iz_serviceTag
83
+ })
84
+
85
+ //(<endpointHook>)
86
+ //(</endpointHook>)
87
+
88
+ return {
89
+ //(<endpointReturn>)
90
+ //(</endpointReturn>)
91
+ }
92
+ } catch (err) {
93
+ _izContext.logger.error('error WebSocketInvoke: ', err)
94
+ throw (err)
95
+ }
96
+ }
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  const path = require('path');
20
20
 
21
21
  const { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
- const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils')
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
23
  const {
24
24
  SOURCE_PATH,
25
25
  defaultIamRolePerAction,
@@ -35,7 +35,7 @@ const {
35
35
  SOURCE_GENERATE_IAM_ROLE,
36
36
  SQS_RESOURCE,
37
37
  LAMBDA_RESOURCE
38
- } = require('../../../../../MainLibs/src/Consts');
38
+ } = require('../../../../../../MainLibs/src/Consts');
39
39
  const { NoRetryError } = require('@izara_project/izara-core-library-core');
40
40
  const getObjectSchema = require('@izara_project/izara-core-library-service-schemas').getObjectSchema;
41
41
 
@@ -57,7 +57,8 @@ async function createSourceParams(_izContext, flowSchema, srcPath) {
57
57
  let handlerType = upperCase(HANDLER.hdrSqs)
58
58
  let additionalResourcePermission = defaultIamRolePerAction();
59
59
  let route = upperCase(flowSchema.flowTag);
60
- let queueName = "Process" + upperCase(flowSchema.flowTag) + handlerType;
60
+ let queueName = upperCase(flowSchema.flowTag) + handlerType;
61
+ let topicIn = route + "_In";
61
62
  additionalResourcePermission.push(
62
63
  createIamRole(
63
64
  {
@@ -78,6 +79,21 @@ async function createSourceParams(_izContext, flowSchema, srcPath) {
78
79
  ),
79
80
  )
80
81
 
82
+ if (Object.keys(flowSchema.flowSteps).includes("In")) {
83
+ additionalResourcePermission.push(
84
+ createIamRole(
85
+ {
86
+ [RESOURCE_CLASSES.sns]: [
87
+ SNS_RESOURCE.publish
88
+ ]
89
+ },
90
+ [
91
+ resourceNames(RESOURCE_CLASSES.sns, topicIn)
92
+ ]
93
+ )
94
+ )
95
+ }
96
+
81
97
  if (flowSchema.statusType === "storedCache") {
82
98
  let tableStroedCaches = [];
83
99
  let objectSchema = await getObjectSchema.getLocalObjectSchemas(_izContext, [flowSchema.objType.objectType], path.join(srcPath, "./schemas")).then(res => res.records[0])
@@ -124,4 +140,4 @@ async function createSourceParams(_izContext, flowSchema, srcPath) {
124
140
  }
125
141
  }
126
142
 
127
- module.exports = data;
143
+ module.exports = data;
@@ -8,6 +8,7 @@
8
8
  batchSize: 10
9
9
  filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
10
  - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
11
12
  role: <%- roleName %>Role
12
13
  #<#<%- functionName %><%- handlerType %>IamRole#>
13
14
  #<#/<%- functionName %><%- handlerType %>IamRole#>
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  const path = require('path');
20
20
 
21
21
  const { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
- const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils')
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
23
  const {
24
24
  SOURCE_PATH,
25
25
  defaultIamRolePerAction,
@@ -35,7 +35,7 @@ const {
35
35
  SOURCE_GENERATE_IAM_ROLE,
36
36
  SQS_RESOURCE,
37
37
  LAMBDA_RESOURCE
38
- } = require('../../../../../MainLibs/src/Consts');
38
+ } = require('../../../../../../MainLibs/src/Consts');
39
39
  const { NoRetryError } = require('@izara_project/izara-core-library-core');
40
40
  const getObjectSchema = require('@izara_project/izara-core-library-service-schemas').getObjectSchema;
41
41
 
@@ -56,7 +56,7 @@ async function createSourceParams(_izContext, flowSchema, srcPath) {
56
56
  let functionName = "Process" + upperCase(flowSchema.flowTag)
57
57
  let handlerType = upperCase(HANDLER.hdrSqs)
58
58
  let additionalResourcePermission = defaultIamRolePerAction();
59
- let queueName = "Process" + upperCase(flowSchema.flowTag) + handlerType;
59
+ let queueName = upperCase(flowSchema.flowTag) + handlerType;
60
60
  additionalResourcePermission.push(
61
61
  createIamRole(
62
62
  {
@@ -0,0 +1,87 @@
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 <%- functionName %> = require('./<%- functionName %>_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
+ //(<additionalParams>)
57
+ //(</additionalParams>)
58
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
59
+
60
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
61
+ let recordPromise = recordHandlerSharedLib.recordHandler(
62
+ record, // one record will send to mainFunction
63
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
64
+ "<%- queueName %>", // queue name that need to retry or send to dlq
65
+ passOnProperties, // all parameters that mainFunction needed.
66
+ );
67
+ record._izContext.logger.debug('after recordPromise in handler');
68
+ recordPromises.push(recordPromise); // push promise to recordPromises
69
+ }))
70
+
71
+ Logger.debug('before Promise.all(recordPromises) in handler');
72
+ try {
73
+ // --- main await all promises
74
+ await Promise.all(recordPromises); // await all promises
75
+
76
+ return event.Records // return all for local testing
77
+
78
+ } catch {
79
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
80
+ }
81
+ Logger.debug('after Promise.all(recordPromises) in handler');
82
+
83
+ } catch (err) {
84
+ Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
85
+ throw (err);
86
+ }
87
+ });
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
  const path = require('path');
20
20
 
21
- const { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts');
21
+ const { SOURCE_PATH, FUNCTION_NAME, HANDLER } = require('../../../../../../MainLibs/src/Consts');
22
22
 
23
- const { firstLetterUpperCase: upperCase } = require('../../../../../MainLibs/src/Utils')
23
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
24
24
  const templatePath = path.join(__dirname, "template.ejs");
25
25
  const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
26
26
  const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
@@ -61,9 +61,9 @@ const { createFieldNamesFromRequestParamsByObjectSchema } = require('@izara_proj
61
61
  module.exports.<%- functionName %> = async (
62
62
  _izContext,
63
63
  requestParams,
64
- callingFlowConfig = {},
65
64
  //(<additionalParams>)
66
65
  //(</additionalParams>)
66
+ callingFlowConfig = {},
67
67
  ) => {
68
68
 
69
69
  try {
@@ -78,7 +78,7 @@ module.exports.<%- functionName %> = async (
78
78
  //(</endpointHookMainFunction>)
79
79
 
80
80
  const flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
81
- flowTag: requestParams.action,
81
+ flowTag: "<%- flowTag %>",
82
82
  serviceTag: process.env.iz_serviceTag
83
83
  })
84
84
 
@@ -31,8 +31,9 @@ const STORAGE_TYPES = {
31
31
  graph: "graph"
32
32
  }
33
33
 
34
- const snsTemplatePath = path.join(__dirname, '/template.ejs');
34
+ const snsTemplatePath = path.join(__dirname, '../../../resourceYaml/sns-in-sqs/snsTemplate.ejs');
35
35
  const subscriptionSqsTemplatePath = path.join(__dirname, './sqsTemplate.ejs');
36
+ const template = path.join(__dirname, "./template.ejs") // !! <----- Add here
36
37
 
37
38
  const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
38
39
 
@@ -57,18 +58,27 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
57
58
  isAppend: true
58
59
  }
59
60
 
60
- let topicIn = `${upperCase(flowSchema.flowTag)}`;
61
61
 
62
62
  const generatedSnsTopicInForFlowSchema = [];
63
+
63
64
  if (flowSteps.includes("In")) {
64
65
  generatedSnsTopicInForFlowSchema.push(
65
66
  {
66
- queueName: upperCase(topicIn) + "Complete" + upperCase(HANDLER.hdrSqs)
67
-
67
+ queueName: upperCase(flowSchema.flowTag),
68
68
  }
69
69
  )
70
70
  }
71
71
 
72
+ resultsForCreateDefaultSnsInSqs.push({
73
+ templatePath: template,
74
+ templateData: {
75
+ queueName: upperCase(flowSchema.flowTag) + "CompleteHdrSqs",
76
+ },
77
+ setting: setting
78
+ })
79
+
80
+
81
+
72
82
  for (let defaultSnsInSqsData of generatedSnsTopicInForFlowSchema) {
73
83
  resultsForCreateDefaultSnsInSqs.push({
74
84
  templatePath: snsTemplatePath,
@@ -0,0 +1,52 @@
1
+ ##===== [subsription to topic In]
2
+ Subscription<%- queueName-%>:
3
+ Type: AWS::SNS::Subscription
4
+ Properties:
5
+ TopicArn: !Ref <%- subScription %>
6
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
7
+ Protocol: "sqs"
8
+ ##===== [Queue]
9
+ <%- queueName %>:
10
+ Type: "AWS::SQS::Queue"
11
+ Properties:
12
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
13
+ RedrivePolicy:
14
+ deadLetterTargetArn:
15
+ # !GetAtt
16
+ Fn::GetAtt:
17
+ - <%- queueName %>DLQ
18
+ - Arn
19
+ maxReceiveCount: 3
20
+ VisibilityTimeout: 120
21
+ ##==== [QueueDLQ]
22
+ <%- queueName %>DLQ:
23
+ Type: AWS::SQS::Queue
24
+ Properties:
25
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
26
+ ##==== [QueuePolicy]
27
+ <%- queueName %>Policy:
28
+ Type: AWS::SQS::QueuePolicy
29
+ Properties:
30
+ PolicyDocument:
31
+ Version: "2012-10-17"
32
+ Statement:
33
+ - Sid: "allow-sns-messages"
34
+ Effect: Allow
35
+ Principal: "*"
36
+ Resource:
37
+ # !GetAtt
38
+ Fn::GetAtt:
39
+ - <%- queueName %>
40
+ - Arn
41
+ Action: "SQS:SendMessage"
42
+ Queues:
43
+ - Ref: <%- queueName %>
44
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
45
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
46
+
47
+ <%_ function firstLetterUpperCase(text){
48
+ return text.charAt(0).toUpperCase() + text.slice(1)
49
+ } _%>
50
+ <%_ function firstLetterLowerCase(str) {
51
+ return str.charAt(0).toLowerCase() + str.slice(1)
52
+ } _%>
@@ -62,7 +62,7 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
62
62
  if (flowSteps.includes("Out")) {
63
63
  generatedSnsTopicInForFlowSchema.push(
64
64
  {
65
- queueName: upperCase(topicOut) + "Complete"
65
+ queueName: upperCase(topicOut)
66
66
 
67
67
  }
68
68
  )
@@ -47,8 +47,7 @@ const templatePath = path.join(__dirname, "template.ejs");
47
47
  */
48
48
 
49
49
  function data(_izContext, flowSchema, srcPath) {
50
- let flowSteps = Object.keys(flowSchema.flowSteps)
51
- if (flowSteps.includes("Out") && flowSchema.outputTopic === false) {
50
+ if (flowSchema.outputTopic === false) {
52
51
  return []
53
52
  } else {
54
53
  return [createSourceParams(_izContext, flowSchema, srcPath)]
@@ -59,7 +58,7 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
59
58
  let functionName = upperCase(flowSchema.flowTag) + "Complete"
60
59
  let handlerType = upperCase(HANDLER.hdrSqs)
61
60
  let additionalResourcePermission = defaultIamRolePerAction();
62
- let topicOut = flowSchema.flowTag + "Complete_Out"
61
+ let topicOut = flowSchema.flowTag + "_Out"
63
62
  let queueName = functionName + handlerType
64
63
  additionalResourcePermission.push(
65
64
  createIamRole(
@@ -75,7 +74,8 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
75
74
  [RESOURCE_CLASSES.sqs]: [SQS_RESOURCE.sendMessage, SQS_RESOURCE.receiveMessage, SQS_RESOURCE.deleteMessage, SQS_RESOURCE.getQueueAttributes]
76
75
  },
77
76
  [
78
- resourceNames(RESOURCE_CLASSES.sqs, queueName)
77
+ resourceNames(RESOURCE_CLASSES.sqs, queueName),
78
+ resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
79
79
  ]
80
80
  )
81
81
  )
@@ -8,6 +8,7 @@
8
8
  batchSize: 10
9
9
  filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
10
  - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
11
12
  role: <%- roleName %>Role
12
13
  #<#<%- functionName %><%- handlerType %>IamRole#>
13
14
  #<#/<%- functionName %><%- handlerType %>IamRole#>
@@ -32,8 +32,7 @@ const templatePath = path.join(__dirname, "template.ejs")
32
32
 
33
33
 
34
34
  function data(_izContext, flowSchema, srcPath) {
35
- let flowSteps = Object.keys(flowSchema.flowSteps)
36
- if (flowSteps.includes("Out") && flowSchema.outputTopic === false) {
35
+ if (flowSchema.outputTopic === false) {
37
36
  return []
38
37
  } else {
39
38
  return [createSourceParams(_izContext, flowSchema, srcPath)]
@@ -25,7 +25,7 @@ const middleware = izara.middlewareHandler;
25
25
  const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
26
26
  const Logger = require('@izara_project/izara-core-library-logger');
27
27
 
28
- const FlowSchemaOwnTopicEndpoint = require('./FlowSchemaOwnTopicEndpoint_Main')
28
+ const <%- functionName %> = require('./<%- functionName %>_Main')
29
29
 
30
30
  // validate event properties in body.Message of sqs event
31
31
  let perRecordsValidatorSchema = {}
@@ -34,22 +34,22 @@ const getObjectSchema = require('@izara_project/izara-core-library-service-schem
34
34
 
35
35
 
36
36
  function data(_izContext, flowSchema, srcPath) {
37
- let flowSteps = Object.keys(flowSchema.flowSteps)
38
- if (flowSteps.includes("Out") && flowSchema.outputTopic === false) {
37
+ if (flowSchema.outputTopic === false) {
39
38
  return []
40
39
  } else {
41
- return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
40
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
42
41
  }
43
42
  }
44
43
 
45
- function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
46
- let functionName = upperCase(flowSchema.flowTag) + "Complete" + upperCase(HANDLER.hdrSqs)
44
+ function createSourceParams(_izContext, flowSchema, srcPath) {
45
+ let functionName = upperCase(flowSchema.flowTag) + "Complete"
47
46
  let topicOut = flowSchema.flowTag + "Complete_Out"
48
47
  return {
49
48
  templatePath: templatePath,
50
49
  templateData: {
51
50
  functionName,
52
51
  topicOut,
52
+ flowTag: flowSchema.flowTag
53
53
  },
54
54
  setting: {
55
55
  savePath: path.join(srcPath, SOURCE_PATH.flowSchema, flowSchema.flowTag, "source/"),