@izara_project/izara-market-library-service-schemas 1.0.31 → 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 (85) hide show
  1. package/package.json +9 -9
  2. package/src/GenerateCodeLibs/src/Consts.js +29 -13
  3. package/src/MainLibs/src/Consts.js +13 -5
  4. package/src/reStructure/GenerateCode.js +16 -18
  5. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +2 -5
  6. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +1 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +1 -1
  8. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
  9. package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
  10. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +5 -5
  11. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +36 -14
  12. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +1 -1
  14. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
  15. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  16. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  17. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  18. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -2
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +1 -1
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +1 -1
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/sqs/template.ejs +18 -18
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +1 -1
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
  25. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
  26. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +0 -0
  27. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +0 -0
  28. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
  29. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
  30. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
  31. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
  32. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
  33. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
  34. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
  35. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
  36. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
  37. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +73 -0
  38. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +53 -0
  39. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +75 -0
  40. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +10 -0
  41. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +83 -0
  42. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +17 -0
  43. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +65 -0
  44. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +130 -0
  45. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +61 -0
  46. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +70 -0
  47. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +147 -0
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +18 -0
  49. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +64 -0
  50. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowSchema → externalTopic/websocket}/handler/template.ejs +17 -16
  51. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +60 -0
  52. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +74 -0
  53. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
  54. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → EndpointComplete}/functionYaml/template.ejs +2 -2
  55. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
  56. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
  57. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
  58. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
  59. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +82 -0
  60. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +20 -0
  61. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +59 -0
  62. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +85 -0
  63. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +52 -0
  64. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → EndpointComponent}/mainFunction/template.ejs +24 -30
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/functionYaml/data.js +24 -22
  66. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +20 -0
  67. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/handler/data.js +7 -21
  68. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +84 -0
  69. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/mainFunction/data.js +4 -15
  70. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +88 -0
  71. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/functionYaml/data.js +24 -22
  72. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/functionYaml/template.ejs +2 -0
  73. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/handler/data.js +6 -19
  74. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaComponent}/handler/template.ejs +4 -3
  75. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/data.js +3 -1
  76. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/template.ejs +3 -4
  77. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +96 -0
  78. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
  79. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
  80. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +207 -114
  81. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +36 -6
  82. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +3 -3
  83. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +3 -3
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +13 -14
  85. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +3 -3
@@ -17,23 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
  const path = require('path');
20
- const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
21
- const {
22
- SOURCE_PATH,
23
- defaultIamRolePerAction,
24
- createIamRole,
25
- RESOURCE_CLASSES,
26
- SNS_RESOURCE,
27
- resourceNames,
28
- DYNAMO_RESOURCE,
29
- SAVE_FILE_NAME,
30
- FUNCTION_NAME,
31
- shortNameHandler,
32
- externalResourceYaml,
33
- SOURCE_GENERATE_IAM_ROLE,
34
- HANDLER
35
- } = require('../../../../../../MainLibs/src/Consts');
36
- const templatePath = path.join(__dirname, "./template.ejs")
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")
37
24
 
38
25
  /**
39
26
  * receive objectSchema
@@ -50,15 +37,14 @@ function data(_izContext, flowSchema, srcPath) {
50
37
 
51
38
  function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
52
39
  let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicComplete)
53
- let handlerType = upperCase(HANDLER.hdrSqs);
54
- let route = flowSchema.flowTag
55
-
40
+ let handlerType = upperCase(HANDLER.hdrSqs)
41
+ let queueName = upperCase(functionName) + upperCase(handlerType);
56
42
  return {
57
43
  templatePath: templatePath,
58
44
  templateData: {
59
45
  functionName,
60
46
  handlerType,
61
- route
47
+ queueName
62
48
  },
63
49
  setting: {
64
50
  savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
@@ -0,0 +1,84 @@
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 FlowSchemaOwnTopicComplete = require('./FlowSchemaOwnTopicComplete_Main')
29
+
30
+ // validate event properties in body.Message of sqs event
31
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
32
+
33
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
34
+
35
+ try {
36
+
37
+ let recordPromises = [];
38
+
39
+ // loop each record and send to mainFunction
40
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
41
+
42
+ let passOnProperties = []
43
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
44
+
45
+ //validate message (and MessageAttributes)
46
+ await recordHandlerSharedLib.validateRecord(
47
+ record, // one record will send to mainFunction
48
+ "FlowSchemaOwnTopicComplete", // queue name that need to retry or send to dlq
49
+ perRecordsValidatorSchema, // schema for record.Message
50
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
51
+ );
52
+
53
+ // add argument (to invoke lambda) to passOnProperties[]
54
+ passOnProperties.push(record.body.Message)
55
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
56
+
57
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
58
+ let recordPromise = recordHandlerSharedLib.recordHandler(
59
+ record, // one record will send to mainFunction
60
+ FlowSchemaOwnTopicComplete.FlowSchemaOwnTopicComplete, // mainFunction that need to invoke.
61
+ "FlowSchemaOwnTopicComplete", // queue name that need to retry or send to dlq
62
+ passOnProperties, // all parameters that mainFunction needed.
63
+ );
64
+ record._izContext.logger.debug('after recordPromise in handler');
65
+ recordPromises.push(recordPromise); // push promise to recordPromises
66
+ }))
67
+
68
+ Logger.debug('before Promise.all(recordPromises) in handler');
69
+ try {
70
+ // --- main await all promises
71
+ await Promise.all(recordPromises); // await all promises
72
+
73
+ return event.Records // return all for local testing
74
+
75
+ } catch {
76
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
77
+ }
78
+ Logger.debug('after Promise.all(recordPromises) in handler');
79
+
80
+ } catch (err) {
81
+ Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
82
+ throw (err);
83
+ }
84
+ });
@@ -17,22 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
  const path = require('path');
20
- const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
21
- const {
22
- SOURCE_PATH,
23
- defaultIamRolePerAction,
24
- createIamRole,
25
- RESOURCE_CLASSES,
26
- SNS_RESOURCE,
27
- resourceNames,
28
- DYNAMO_RESOURCE,
29
- SAVE_FILE_NAME,
30
- FUNCTION_NAME,
31
- shortNameHandler,
32
- externalResourceYaml,
33
- SOURCE_GENERATE_IAM_ROLE
34
- } = require('../../../../../../MainLibs/src/Consts');
20
+
21
+ const { SOURCE_PATH, FUNCTION_NAME } = require('../../../../../../MainLibs/src/Consts');
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
35
23
  const templatePath = path.join(__dirname, "template.ejs");
24
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
36
25
 
37
26
  /**
38
27
  * receive objectSchema
@@ -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 hash = require("object-hash");
22
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
23
+
24
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
25
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
26
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
27
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
28
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
29
+
30
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
31
+ const sns = externalRequest.sns
32
+ const { postToConnection } = require("../../../../libs/source/GenerateCodeLibs");
33
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
34
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
35
+ const { v4: uuidv4 } = require('uuid')
36
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
38
+ /**
39
+ *
40
+ *
41
+ * description of function.
42
+ * @param {Object} _izContext
43
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
44
+ * @param {Logger} _izContext.logger - property of _izContext
45
+ * @param {Object} requestParams - request params
46
+ * @param {Object} requestParams.identifiers - identifiers for get data
47
+ * @param {Object} requestParams.additionalRequest - additionalRequest
48
+ *
49
+ *
50
+ * @returns {object} description of return value
51
+ */
52
+
53
+ module.exports.FlowSchemaOwnTopicComplete = async (
54
+ _izContext,
55
+ requestParams,
56
+ callingFlowConfig = {},
57
+ //(<additionalParams>)
58
+ //(</additionalParams>)
59
+ ) => {
60
+
61
+ try {
62
+ _izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
63
+ _izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
64
+ _izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
65
+
66
+ let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
67
+ let correlationId = _izContext.correlationIds.get(coreConsts.X_CORRELATION_ID);
68
+
69
+ await postToConnection(
70
+ {
71
+ message: requestParams
72
+ },
73
+ connectionId
74
+ )
75
+
76
+ await dynamodbSharedLib.deleteItem(_izContext,
77
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
78
+ {
79
+ taskKey: correlationId,
80
+ connectionId: connectionId
81
+ }
82
+ )
83
+
84
+ } catch (err) {
85
+ _izContext.logger.error('error WebSocketInvoke: ', err)
86
+ throw (err)
87
+ }
88
+ }
@@ -18,7 +18,7 @@ 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 { ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
21
+ const { FLOW_SCHEMA_HOOK_STATE, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
22
  const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
23
  const {
24
24
  SOURCE_PATH,
@@ -34,9 +34,10 @@ const {
34
34
  externalResourceYaml,
35
35
  SOURCE_GENERATE_IAM_ROLE
36
36
  } = require('../../../../../../MainLibs/src/Consts');
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('../../../../../../GenerateCodeLibs/src/Consts');
37
38
 
38
- const templatePath = path.join(__dirname, "./template.ejs");
39
-
39
+ const templatePath = path.join(__dirname, "template.ejs");
40
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
40
41
  /**
41
42
  * receive objectSchema
42
43
  * create data for WebScoket handler template
@@ -50,16 +51,31 @@ function data(_izContext, flowSchema, srcPath) {
50
51
  }
51
52
 
52
53
  function createSourceParams(_izContext, flowSchema, srcPath) {
53
-
54
54
  let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopic)
55
55
  let handlerType = upperCase("hdrWbs")
56
56
  let additionalResourcePermission = defaultIamRolePerAction();
57
- let route = flowSchema.flowTag
58
-
57
+ let route = flowSchema.flowTag;
58
+ let flowStep = Object.keys(flowSchema.flowSteps)
59
59
  additionalResourcePermission.push(
60
60
  createIamRole(
61
61
  {
62
- [RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE)
62
+ [RESOURCE_CLASSES.sns]: [
63
+ SNS_RESOURCE.publish
64
+ ]
65
+ },
66
+ [
67
+ resourceNames(RESOURCE_CLASSES.sns, flowStep[0])
68
+ ]
69
+ ),
70
+ createIamRole(
71
+ {
72
+ [RESOURCE_CLASSES.dynamoDbTable]: [
73
+ DYNAMO_RESOURCE.putItem,
74
+ DYNAMO_RESOURCE.getItem,
75
+ DYNAMO_RESOURCE.query,
76
+ DYNAMO_RESOURCE.deleteItem,
77
+ DYNAMO_RESOURCE.updateItem
78
+ ]
63
79
  },
64
80
  [
65
81
  resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
@@ -77,25 +93,11 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
77
93
  )
78
94
  )
79
95
 
80
- for (const flowStep of Object.keys(flowSchema.flowSteps)) {
81
- if (flowStep.includes("In")) {
82
- additionalResourcePermission.push(
83
- createIamRole(
84
- {
85
- [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish
86
- },
87
- [
88
- resourceNames(RESOURCE_CLASSES.sns, flowStep)
89
- ]
90
- )
91
- )
92
- }
93
- }
94
96
 
95
97
  return {
96
98
  templatePath: templatePath,
97
99
  templateData: {
98
- resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaOwnTopic, flowSchema.flowTag),
100
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaOwnTopic, flowSchema.flowTag, "source/"),
99
101
  functionName,
100
102
  handlerType,
101
103
  additionalResourcePermission,
@@ -3,6 +3,8 @@
3
3
  handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
4
  name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
5
  events:
6
+ - websocket:
7
+ route: $default
6
8
  - websocket:
7
9
  route: <%- route %>
8
10
  # authorizer: ${self:custom.iz_authorizerAppLevel}
@@ -17,22 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
  const path = require('path');
20
- const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
21
- const {
22
- SOURCE_PATH,
23
- defaultIamRolePerAction,
24
- createIamRole,
25
- RESOURCE_CLASSES,
26
- SNS_RESOURCE,
27
- resourceNames,
28
- DYNAMO_RESOURCE,
29
- SAVE_FILE_NAME,
30
- FUNCTION_NAME,
31
- shortNameHandler,
32
- externalResourceYaml,
33
- SOURCE_GENERATE_IAM_ROLE
34
- } = require('../../../../../../MainLibs/src/Consts');
35
- const templatePath = path.join(__dirname, "./template.ejs")
20
+ const { FLOW_SCHEMA_HOOK_STATE } = 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")
36
24
 
37
25
  /**
38
26
  * receive objectSchema
@@ -49,9 +37,8 @@ function data(_izContext, flowSchema, srcPath) {
49
37
 
50
38
  function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
51
39
  let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopic)
52
- let handlerType = "HdrWbs";
53
- let route = flowSchema.flowTag
54
-
40
+ let handlerType = "HdrWbs"
41
+ let route = flowSchema.flowTag;
55
42
  return {
56
43
  templatePath: templatePath,
57
44
  templateData: {
@@ -26,8 +26,8 @@ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-
26
26
  const hash = require('object-hash')
27
27
  // const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
28
28
  const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
29
- const { postToConnection } = require("../../libs/source/ImportDataLib");
30
- const { flowSchemaOwnTopic } = require('./<%- `${functionName}_Main` %>');
29
+ const { postToConnection } = require("../../libs/source/GenerateCodeLibs");
30
+ const flowSchemaOwnTopic = require('./FlowSchemaOwnTopic_Main');
31
31
  module.exports.main = middleware.wrap(async (event, context, callback) => {
32
32
 
33
33
  event._izContext.logger.debug('Event:', event);
@@ -40,6 +40,7 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
40
40
  let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
41
41
 
42
42
  switch (route) {
43
+
43
44
  case '$default':
44
45
  console.log('Received unknown route:', route);
45
46
  break
@@ -57,7 +58,7 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
57
58
  )
58
59
 
59
60
  let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
60
- await flowSchemaOwnTopic(
61
+ await flowSchemaOwnTopic.flowSchemaOwnTopic(
61
62
  event._izContext,
62
63
  eventParams,
63
64
  callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
@@ -52,7 +52,9 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
52
52
  let topicArn = Object.keys(flowSchema.flowSteps)[0];
53
53
  return {
54
54
  templatePath: templatePath,
55
- templateData: {},
55
+ templateData: {
56
+ topicArn
57
+ },
56
58
  setting: {
57
59
  savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
58
60
  saveFileName: `${functionName}_Main`,
@@ -64,16 +64,15 @@ module.exports.flowSchemaOwnTopic = async (
64
64
  _izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
65
65
 
66
66
  let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
67
- flowTag: requestParams.flowTag,
67
+ flowTag: requestParams.action,
68
68
  serviceTag: process.env.iz_serviceTag
69
- // serviceTag: "GenerateCodeTamplateBas002"
70
69
  })
71
70
 
72
71
  _izContext.logger.debug("flowSchema", flowSchema)
73
72
 
74
73
 
75
74
  if (!flowSchema) {
76
- throw new NoRetryError(`flowTag not found ${requestParams.flowTag}`)
75
+ throw new NoRetryError(`flowTag not found ${requestParams.action}`)
77
76
  }
78
77
 
79
78
  let messageObject = {
@@ -92,7 +91,7 @@ module.exports.flowSchemaOwnTopic = async (
92
91
 
93
92
  let sendMessageToCreateEndpoint = {
94
93
  Message: JSON.stringify(messageObject),
95
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, )
94
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- topicArn %>")
96
95
  }
97
96
  _izContext.logger.debug("sendMessageToCreateEndpoint", sendMessageToCreateEndpoint);
98
97
  await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
@@ -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 <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils.js");
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const snsTemplatePath = path.join(__dirname, '../../../resourceYaml/sns-in-sqs/snsTemplate.ejs');
35
+ const sqsTemplatePath = path.join(__dirname, './sqsTemplate.ejs');
36
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
37
+
38
+ /**
39
+ * create data for dynamoDbYaml tempalte from objectSchema
40
+ * return array of dynamoDb data
41
+ * because one objectSchema can create multiple dynamoDb table
42
+ *
43
+ * @param {Object} _izContext
44
+ * @param {String} saveFilePath
45
+ * @returns {Object[]} - data of multiple dynamoDb template
46
+ */
47
+
48
+ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
49
+ let resultsForCreateDefaultSnsInSqs = [];
50
+
51
+ const setting = {
52
+ initialData: "Resources:\n",
53
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
54
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
55
+ fileExtension: ".yml",
56
+ isAppend: true
57
+ }
58
+
59
+ // GCTpBasTestInPersonCreate => GCTpBas_Test_PersonCreate_In
60
+ let flowSteps = Object.keys(flowSchema.flowSteps)
61
+ const generatedSnsTopicInForFlowSchema = [
62
+ {
63
+ queueName: upperCase(flowSteps[0].split("_")[0]),
64
+ },
65
+ ];
66
+
67
+
68
+ for (let defaultSnsInSqsData of generatedSnsTopicInForFlowSchema) {
69
+ resultsForCreateDefaultSnsInSqs.push({
70
+ templatePath: snsTemplatePath,
71
+ templateData: defaultSnsInSqsData,
72
+ setting: setting
73
+ })
74
+ }
75
+
76
+ let defaultDsqQueueDataList = [
77
+ {
78
+ queueName: upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete) + upperCase(HANDLER.hdrSqs),
79
+ subscribeTo: upperCase(flowSteps[1].split("_")[0])
80
+ },
81
+ // {
82
+ // queueName: upperCase(FUNCTION_NAME.flowSchemaOwnTopicComplete) + upperCase(HANDLER.hdrSqs)
83
+ // }
84
+ ]
85
+ for (let defaultDsqQueueData of defaultDsqQueueDataList) {
86
+ resultsForCreateDefaultSnsInSqs.push({
87
+ templatePath: sqsTemplatePath,
88
+ templateData: defaultDsqQueueData,
89
+ setting: setting
90
+ })
91
+ }
92
+ console.log()
93
+ return resultsForCreateDefaultSnsInSqs;
94
+ }
95
+
96
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,53 @@
1
+ <% if (subscribeTo) { %>
2
+ ##===== SNS Subscription
3
+ ##===== [Topic In]
4
+ SubscriptionToOut<%- subscribeTo %>:
5
+ Type: AWS::SNS::Subscription
6
+ Properties:
7
+ TopicArn: !Ref Out<%- subscribeTo %>
8
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
9
+ Protocol: "sqs"
10
+ <% } %>
11
+ #------- queue ---------
12
+ <%- queueName %>:
13
+ Type: "AWS::SQS::Queue"
14
+ Properties:
15
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
16
+ RedrivePolicy:
17
+ deadLetterTargetArn: #!GetAtt
18
+ Fn::GetAtt:
19
+ - <%- queueName %>DLQ
20
+ - Arn
21
+ maxReceiveCount: 3
22
+ VisibilityTimeout: 120
23
+
24
+ <%- queueName %>DLQ:
25
+ Type: AWS::SQS::Queue
26
+ Properties:
27
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
28
+
29
+ <%- queueName %>Policy:
30
+ Type: AWS::SQS::QueuePolicy
31
+ Properties:
32
+ PolicyDocument:
33
+ Version: "2012-10-17"
34
+ Statement:
35
+ - Sid: "allow-sns-messages"
36
+ Effect: Allow
37
+ Principal: "*"
38
+ Resource: #!GetAtt
39
+ Fn::GetAtt:
40
+ - <%- queueName %>
41
+ - Arn
42
+ Action: "SQS:SendMessage"
43
+ Queues:
44
+ - Ref: <%- queueName %>
45
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
46
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
47
+
48
+ <%_ function firstLetterUpperCase(text){
49
+ return text.charAt(0).toUpperCase() + text.slice(1)
50
+ } _%>
51
+ <%_ function firstLetterLowerCase(str) {
52
+ return str.charAt(0).toLowerCase() + str.slice(1)
53
+ } _%>
@@ -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
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils.js");
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const templatePath = path.join(__dirname, '../../../resourceYaml/sns-out/template.ejs');
35
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js')
36
+
37
+ /**
38
+ * create data for dynamoDbYaml template from objectSchema
39
+ * return array of dynamoDb data
40
+ * because one objectSchema can create multiple dynamoDb table
41
+ *
42
+ * @param {Object} _izContext
43
+ * @param {String} saveFilePath
44
+ * @returns {Object[]} - data of multiple dynamoDb template
45
+ */
46
+
47
+ function createDataForSnsOut(_izContext, flowSchema, srcPath) {
48
+ let resultsForCreateDefaultSnsInSqs = [];
49
+
50
+ // GCTpBasTestInPersonCreate => GCTpBas_Test_PersonCreate_In
51
+ let flowSteps = Object.keys(flowSchema.flowSteps)
52
+ const generatedSnsTopicOutForFlowSchema = [
53
+ {
54
+ queueName: upperCase(flowSteps[1].split("_")[0])
55
+ }
56
+ ];
57
+
58
+
59
+ for (let defaultSnsOutData of generatedSnsTopicOutForFlowSchema) {
60
+ resultsForCreateDefaultSnsInSqs.push({
61
+ templatePath: templatePath,
62
+ templateData: defaultSnsOutData,
63
+ setting: {
64
+ initialData: "Resources:\n",
65
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
66
+ saveFileName: SAVE_FILE_NAME.snsOutYaml,
67
+ fileExtension: ".yml",
68
+ isAppend: true
69
+ }
70
+
71
+ })
72
+ }
73
+
74
+ return resultsForCreateDefaultSnsInSqs;
75
+ }
76
+
77
+ module.exports = createDataForSnsOut;