@izara_project/izara-market-library-service-schemas 1.0.34 → 1.0.36

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 (135) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +7 -6
  4. package/src/MainLibs/src/Consts.js +47 -14
  5. package/src/MainLibs/src/GenerateCodeUtils.js +2 -0
  6. package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
  7. package/src/TemplateManager/src/attributeTreeSchema/generateTemplateData.js +103 -0
  8. package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
  9. package/src/TemplateManager/src/attributeTreeSchema/mainAttributeTree/data.js +134 -0
  10. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/data.js +84 -0
  11. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/tempReferenceRelationshipSchema.ejs +9 -0
  12. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/data.js +172 -0
  13. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
  14. package/src/reStructure/GenerateCode.js +1 -0
  15. package/src/reStructure/SchemaConfig.js +1 -3
  16. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
  17. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
  18. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +701 -0
  19. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +34 -159
  20. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -0
  21. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +3 -4
  22. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +2 -0
  23. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +38 -12
  24. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +5 -2
  25. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -14
  26. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +4 -1
  27. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
  28. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
  29. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
  30. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
  31. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
  32. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +131 -0
  33. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
  34. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
  35. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -1
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +12 -4
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +13 -8
  40. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
  41. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +141 -0
  42. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
  43. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
  44. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
  45. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
  46. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +131 -0
  47. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/dynamoDB/register.js +82 -0
  48. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
  49. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +45 -0
  50. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +19 -6
  51. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +9 -15
  52. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
  53. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
  54. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +164 -0
  55. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
  56. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
  57. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +88 -0
  58. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
  59. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +222 -0
  60. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +83 -44
  61. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
  62. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
  63. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
  64. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
  65. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
  66. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +5 -9
  67. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -7
  68. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +2 -3
  69. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +2 -4
  70. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +37 -11
  71. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +4 -4
  72. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +8 -9
  73. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +13 -13
  74. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +4 -4
  75. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +44 -69
  76. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +7 -44
  77. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +3 -3
  78. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +3 -10
  79. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +40 -86
  80. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +11 -4
  81. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +11 -8
  82. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +17 -3
  83. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +2 -2
  84. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +8 -2
  85. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +49 -84
  86. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +55 -10
  87. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -1
  88. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +2 -2
  89. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +1 -1
  90. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +27 -8
  91. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +50 -20
  92. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +20 -5
  93. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +1 -1
  94. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +2 -2
  95. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +5 -5
  96. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/data.js +5 -3
  97. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +7 -5
  98. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +6 -3
  99. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -2
  100. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/data.js +2 -2
  101. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +3 -3
  102. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +9 -9
  103. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +17 -39
  104. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +14 -8
  105. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +4 -1
  106. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +90 -21
  107. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +22 -1
  108. package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +3 -0
  109. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +9 -8
  110. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +5 -1
  111. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +2 -1
  112. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +1 -0
  113. package/src/reStructure/TemplateData/propertyValueSchema/generateTemplateData.js +66 -0
  114. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +131 -0
  115. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/templateObjectPropertyValueSchema.ejs +16 -0
  116. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +156 -0
  117. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/tempRelationship.ejs +13 -0
  118. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/templateRelationshipPropertyValueSchema.ejs +7 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +2 -1
  120. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +2 -1
  121. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +2 -1
  122. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/handler/sqs/template.ejs +5 -5
  123. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -4
  124. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -1
  125. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +4 -4
  126. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +4 -3
  127. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +2 -1
  128. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +2 -1
  129. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -3
  130. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +61 -0
  131. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +13 -4
  132. package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
  133. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +0 -104
  134. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
  135. /package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/request.json +0 -0
@@ -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,68 @@
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, FLOW_SCHEMA_EVENT_TYPE } = 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.createRecordComplete)
41
+ let flowSteps = Object.keys(flowSchema.flowSteps)
42
+ let splitFlowSteps = flowSteps[0].split("_")
43
+ let topicArn;
44
+ let serviceTag;
45
+ for (const event of flowSchema.event) {
46
+ if (event.includes(FLOW_SCHEMA_EVENT_TYPE.ownTopic)) {
47
+ topicArn = flowSteps[0]
48
+ } else if (event.includes(FLOW_SCHEMA_EVENT_TYPE.extTopic)) {
49
+ topicArn = splitFlowSteps[3] + "_" + splitFlowSteps[4]
50
+ serviceTag = splitFlowSteps[0]
51
+ }
52
+ }
53
+ return {
54
+ templatePath: templatePath,
55
+ templateData: {
56
+ topicArn,
57
+ serviceTag
58
+ },
59
+ setting: {
60
+ savePath: path.join(srcPath, SOURCE_PATH.createRecordComplete, flowSchema.flowTag, 'source/'),
61
+ saveFileName: `${functionName}_Main`,
62
+ fileExtension: ".js",
63
+ isAppend: false
64
+ }
65
+ }
66
+ }
67
+
68
+ module.exports = data
@@ -0,0 +1,131 @@
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');
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
+
34
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
35
+ const { NoRetryError } = require('@izara_project/izara-core-library-core')
36
+ const { v4: uuidv4 } = require('uuid')
37
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
38
+ // const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
39
+ const { generateCodeLibs: { consts: TOPIC_NAME_GENERATE_CODE } } = require('@izara_project/izara-market-library-service-schemas')
40
+
41
+ /**
42
+ * description of function.
43
+ * @param {Object} _izContext
44
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
45
+ * @param {Logger} _izContext.logger - property of _izContext
46
+ * @param {Object} requestParams - request params
47
+ * @param {Object} requestParams.identifiers - identifiers for get data
48
+ * @param {Object} requestParams.additionalRequest - additionalRequest
49
+ *
50
+ * @returns {object} description of return value
51
+ */
52
+ module.exports.<%- functionMain%> = async (
53
+ _izContext,
54
+ requestParams,
55
+ callingFlowConfig = {},
56
+ //(<additionalParams>)
57
+ //(</additionalParams>)
58
+ ) => {
59
+ try {
60
+ _izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
61
+ _izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
62
+ _izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
63
+
64
+ const connectionId = requestContext.connectionId;
65
+ let correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID);
66
+
67
+ const getRegisterRecords = await dynamodbSharedLib.getItem(
68
+ _izContext,
69
+ await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
70
+ {
71
+ taskKey: correlationId,
72
+ connectionId: connectionId,
73
+ }
74
+ );
75
+ _izContext.logger.debug("getRegisterRecords", getRegisterRecords)
76
+ if (!getRegisterRecords) {
77
+ throw new NoRetryError(`connectionId not found ${connectionId}`)
78
+ }
79
+
80
+ const flowType = getRegisterRecords.flowType;
81
+ const flowTag = flowType.split('_')[0];
82
+ const getFlowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
83
+ flowTag: flowTag,
84
+ serviceTag: process.env.iz_serviceTag
85
+ })
86
+ _izContext.logger.debug("getFlowSchema", getFlowSchema)
87
+ if (!getFlowSchema) {
88
+ throw new NoRetryError(`flowTag not found ${flowTag}`)
89
+ }
90
+
91
+ switch (flowSchema.statusType) {
92
+ case "statusField":
93
+ let payload = {
94
+ identifiers: requestParams.identifiers,
95
+ objectType: flowSchema.objType.objectType
96
+ }
97
+ let result = await externalRequest.lambda.invokeSync(
98
+ _izContext,
99
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv", flowSchema.objType.serviceTag),
100
+ payload
101
+ )
102
+ if (!result) {
103
+ throw new NoRetryError(`statusField not found ${requestParams.identifiers}`)
104
+ }
105
+ return result
106
+ case "storedCache":
107
+ // if statusType=storedCache then query storedCache > post message to client -> remove connectionId if status = error || complete
108
+ const getStoredCache = await dynamodbSharedLib.getItem(
109
+ _izContext,
110
+ await dynamodbSharedLib.tableName(_izContext, flowSchema.flowTag + "Main"),
111
+ {
112
+ taskKey: requestParams.identifiers,
113
+ connectionId: requestParams.connectionId
114
+ }
115
+ )
116
+ if (!getStoredCache) {
117
+ throw new NoRetryError(`storedCache not found ${requestParams.identifiers}`)
118
+ }
119
+ return getStoredCache
120
+ case "none":
121
+ // if statusType=none -> post message to client ---- not remove connectionId when post message, can remove connectionId when cannot use connectionId only(user disconnect)
122
+ break
123
+ default:
124
+ throw new NoRetryError(`statusType not found ${flowSchema.statusType}`)
125
+ }
126
+
127
+ } catch (err) {
128
+ _izContext.logger.error('error WebSocketInvoke: ', err)
129
+ throw (err)
130
+ }
131
+ }
@@ -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
+ const templatePath = path.join(__dirname, "./template.ejs");
34
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
35
+ const { TOPIC_NAME_GENERATE_CODE } = require("../../../../../GenerateCodeLibs/src/Consts.js");
36
+
37
+ /**
38
+ * create data for dynamoDbYaml tempalte 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 createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
48
+ let resultsForCreateDefaultSnsInSqs = [];
49
+
50
+ const setting = {
51
+ initialData: "Resources:\n",
52
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
53
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
54
+ fileExtension: ".yml",
55
+ isAppend: true
56
+ }
57
+
58
+ const generatedSnsTopicInForFlowSchema = [
59
+ {
60
+ queueName: upperCase(FUNCTION_NAME.createRecordComplete) + upperCase(flowSchema.flowTag) + upperCase(HANDLER.hdrSqs),
61
+ subScription: upperCase(TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
62
+ },
63
+ ];
64
+
65
+
66
+ for (let defaultSnsInSqsData of generatedSnsTopicInForFlowSchema) {
67
+ resultsForCreateDefaultSnsInSqs.push({
68
+ templatePath: templatePath,
69
+ templateData: defaultSnsInSqsData,
70
+ setting: setting
71
+ })
72
+ }
73
+
74
+ return resultsForCreateDefaultSnsInSqs;
75
+ }
76
+
77
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,49 @@
1
+ Subscription<%- queueName-%>:
2
+ Type: AWS::SNS::Subscription
3
+ Properties:
4
+ TopicArn: !Ref <%- subScription %>
5
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
6
+ Protocol: "sqs"
7
+ #------- queue ---------
8
+ <%- queueName %>:
9
+ Type: "AWS::SQS::Queue"
10
+ Properties:
11
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
12
+ RedrivePolicy:
13
+ deadLetterTargetArn: #!GetAtt
14
+ Fn::GetAtt:
15
+ - <%- queueName %>DLQ
16
+ - Arn
17
+ maxReceiveCount: 3
18
+ VisibilityTimeout: 120
19
+
20
+ <%- queueName %>DLQ:
21
+ Type: AWS::SQS::Queue
22
+ Properties:
23
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
24
+
25
+ <%- queueName %>Policy:
26
+ Type: AWS::SQS::QueuePolicy
27
+ Properties:
28
+ PolicyDocument:
29
+ Version: "2012-10-17"
30
+ Statement:
31
+ - Sid: "allow-sns-messages"
32
+ Effect: Allow
33
+ Principal: "*"
34
+ Resource: #!GetAtt
35
+ Fn::GetAtt:
36
+ - <%- queueName %>
37
+ - Arn
38
+ Action: "SQS:SendMessage"
39
+ Queues:
40
+ - Ref: <%- queueName %>
41
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
42
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
43
+
44
+ <%_ function firstLetterUpperCase(text){
45
+ return text.charAt(0).toUpperCase() + text.slice(1)
46
+ } _%>
47
+ <%_ function firstLetterLowerCase(str) {
48
+ return str.charAt(0).toLowerCase() + str.slice(1)
49
+ } _%>
@@ -26,7 +26,7 @@ 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/GenerateCodeLibs");
29
+ const { postToConnection } = require('../../../libs/source/GenerateCodeLibs')
30
30
  const createObject = require('./CreateObjectS3_Main');
31
31
  module.exports.main = middleware.wrap(async (event, context, callback) => {
32
32
 
@@ -21,7 +21,7 @@ const snsSharedLib = require('@izara_project/izara-core-library-sns');
21
21
  const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
22
22
  let coreConsts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
23
23
 
24
- const { postToConnection } = require('../../libs/source/GenerateCodeLibs')
24
+ const { postToConnection } = require('../../../libs/source/GenerateCodeLibs')
25
25
  module.exports.webSocketTaskComplete = async (
26
26
  _izContext,
27
27
  objType,
@@ -32,7 +32,7 @@ const client = new S3Client({ region: 'us-east-2' });
32
32
  const { createPresignedPost } = require('@aws-sdk/s3-presigned-post');
33
33
  const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
34
34
 
35
- const { postToConnection,getNestObject } = require("../../libs/source/GenerateCodeLibs");
35
+ const { postToConnection,getNestObject } = require('../../../../libs/source/GenerateCodeLibs')
36
36
  const hash = require('object-hash');
37
37
  const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils');
38
38
  const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
@@ -22,14 +22,22 @@ const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../../../../MainLibs/s
22
22
 
23
23
  const templatePath = path.join(__dirname, "./template.ejs")
24
24
 
25
- function data(_izContext, srcPath) {
26
- return [createSourceParams(_izContext, srcPath)]
25
+ function data(_izContext, flowSchema, srcPath) {
26
+ return [createSourceParams(_izContext,flowSchema, srcPath)]
27
27
  };
28
28
 
29
- function createSourceParams(_izContext, srcPath) {
29
+ function createSourceParams(_izContext, flowSchema, srcPath) {
30
+ let uploadS3 = false;
31
+ for (const event of flowSchema.event) {
32
+ if (event.includes("s3")) {
33
+ uploadS3 = true
34
+ }
35
+ }
30
36
  return {
31
37
  templatePath: templatePath,
32
- templateData: {},
38
+ templateData: {
39
+ uploadS3
40
+ },
33
41
  setting: {
34
42
  saveFileName: "GenerateCodeLibs",
35
43
  savePath: path.join(srcPath, SOURCE_PATH.generateCodeLib),
@@ -21,14 +21,15 @@ const externalRequest = require('@izara_project/izara-core-library-external-requ
21
21
  const lambda = externalRequest.lambda;
22
22
 
23
23
  const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
24
- const { inMemoryCacheLib } = require('@izara_project/izara-shared');
25
24
  const hash = require("object-hash")
26
- const csv = require('csv-parser');
27
- const streamifier = require('streamifier');
28
- const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError;
25
+ <% if (uploadS3) { %>
26
+ const csv = require('csv-parser');
27
+ const streamifier = require('streamifier');
28
+ <% } %>
29
+ const { NoRetryError,inMemoryCacheLib } = require('@izara_project/izara-core-library-core');
29
30
 
30
31
  const client = new ApiGatewayManagementApiClient({
31
- endpoint: `https://${process.env.iz_webSocketEndpoint}`
32
+ endpoint: `${process.env.iz_webSocketEndpoint}`
32
33
  })
33
34
 
34
35
  async function postToConnection(message, connectionId) {
@@ -60,7 +61,7 @@ async function getDataFromInvokeFunction(_izContext, functionName, payload) {
60
61
  return await lambda.invokeSync(_izContext, functionName, payload)
61
62
  }
62
63
 
63
- const getDataFromInvokeFunctionWithCache = inMemoryCacheLib.inMemoryCacheLib(
64
+ const getDataFromInvokeFunctionWithCache = inMemoryCacheLib(
64
65
  getDataFromInvokeFunction,
65
66
  {
66
67
  max: 100,
@@ -73,6 +74,7 @@ const getDataFromInvokeFunctionWithCache = inMemoryCacheLib.inMemoryCacheLib(
73
74
  }
74
75
  )
75
76
 
77
+ <% if (uploadS3) { %>
76
78
  /**
77
79
  *
78
80
  * @param {Object} _izContext
@@ -108,6 +110,7 @@ async function isValidCsv(_izContext, data) {
108
110
 
109
111
  return [validCsv, errorCheckCsv]
110
112
  }
113
+ <% } %>
111
114
 
112
115
  /**
113
116
  *
@@ -132,6 +135,8 @@ module.exports = {
132
135
  postToConnection,
133
136
  getDataFromInvokeFunction,
134
137
  getDataFromInvokeFunctionWithCache,
135
- isValidCsv,
136
- getNestObject
138
+ getNestObject,
139
+ <% if (uploadS3) { %>
140
+ isValidCsv,
141
+ <% } %>
137
142
  }
@@ -32,13 +32,13 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
32
32
  switch (eventType) {
33
33
  case 'CONNECT':
34
34
  console.log('Connect websocket')
35
- //(<additionalParams>)
36
- //(</additionalParams>)
35
+ //(<webSocketConnect>)
36
+ //(</webSocketConnect>)
37
37
  break
38
38
  case 'DISCONNECT':
39
39
  console.log('Websocket are Disconnection')
40
- //(<additionalParams>)
41
- //(</additionalParams>)
40
+ //(<webSocketDisconnect>)
41
+ //(</webSocketDisconnect>)
42
42
  break
43
43
  case '$default':
44
44
  console.log('Received unknown route:', route)