@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
@@ -4,11 +4,24 @@ let objectSchema = await getObjectSchema.getObjSchemaS3WithCache(_izContext, flo
4
4
  // create record
5
5
  let fieldNames = createFieldNamesFromRequestParamsByObjectSchema(_izContext, requestParams, objectSchema)
6
6
 
7
+ let payload = {
8
+ fieldNames
9
+ }
10
+ Object.assign(payload, {
11
+ objectType: flowSchema.objType.objectType
12
+ })
7
13
 
8
- let sendMessageToCreateEndpoint = {
9
- Message: JSON.stringify({fieldNames: fieldNames}),
10
- topicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Create_In")
11
- };
14
+ let result = await lambda.invokeSync(_izContext,
15
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "CreateHdrInv", flowSchema.objType.serviceTag),
16
+ {
17
+ payload: JSON.stringify(payload)
18
+ });
19
+
20
+ _izContext.logger.debug("result from createRecordByStatusType", result)
21
+
22
+ let messageObject = {
23
+ requestParams: requestParams
24
+ //(<messageObject>)
25
+ //(</messageObject>)
26
+ }
12
27
 
13
- _izContext.logger.debug("before sendMessageToCreateEndpoint:: ", sendMessageToCreateEndpoint);
14
- await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
@@ -1,17 +1,11 @@
1
- // create storedCache
2
- function createExpiryTime (_izContext, expiryInterval) {
3
- const currentTime = new Date();
4
- const expiryTime = new Date(currentTime);
5
- expiryTime.setTime(expiryTime.getTime() + expiryInterval);
6
- return expiryTime.getTime();
7
- };
1
+ let expiryTime = storedCacheSharedLib.createExpiryTime(_izContext, 31536000);
8
2
 
9
- await dynamodbSharedLib.putItem(_izContext,
10
- await dynamodbSharedLib.tableName(_izContext, "<%- flowTag %>Main"),
11
- {
12
- <%- flowTag %>Id: hash(requestParams),
13
- cacheExpiryTime: createExpiryTime(_izContext, 31536000000),
14
- cacheStatus: "processing",
15
- cacheUniqueRequestId: _izContext.uniqueRequestId
16
- }
3
+ let createCacheId = hash({
4
+ //(<optionalParams>)
5
+ //(</optionalParams>)
6
+ })
7
+ let [ cacheMainStauts, cacheId, cacheMain ] = await storedCacheSharedLib.checkStoredCacheStatus(
8
+ _izContext,
9
+ "<%- tableName %>",
10
+ createCacheId
17
11
  )
@@ -0,0 +1,76 @@
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, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils.js");
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const templatePath = path.join(__dirname, "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 createDataForSubscriptionOutAll(_izContext, allLocalFlowSchemas, srcPath) {
48
+ // console.log("allLocalFlowSchemas", allLocalFlowSchemas.records)
49
+ const result = []
50
+ for (const flowSchema of allLocalFlowSchemas.records) {
51
+ let event = flowSchema.event;
52
+ if (!event.includes("eventBridge")) {
53
+ const flowStepOut = Object.keys(flowSchema.flowSteps)[1].split("_")
54
+ // console.log("flowStepOut", flowStepOut)
55
+ result.push({
56
+ templatePath: templatePath,
57
+ templateData: {
58
+ queueName: flowStepOut[4] + flowStepOut[3],
59
+ endpoint: "Register",
60
+ firstLetterUpperCase: upperCase,
61
+ },
62
+ setting: {
63
+ initialData: "Resources:\n",
64
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
65
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
66
+ fileExtension: ".yml",
67
+ isAppend: true
68
+ }
69
+ })
70
+ };
71
+ }
72
+
73
+ return result
74
+ }
75
+
76
+ module.exports = createDataForSubscriptionOutAll;
@@ -0,0 +1,13 @@
1
+ ##===== [Topic In]
2
+ Subscription<%- queueName %>:
3
+ Type: AWS::SNS::Subscription
4
+ Properties:
5
+ TopicArn: !Ref <%- queueName %>
6
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- endpoint %>"
7
+ Protocol: "sqs"
8
+ <%_ function firstLetterUpperCase(text){
9
+ return text.charAt(0).toUpperCase() + text.slice(1)
10
+ } _%>
11
+ <%_ function firstLetterLowerCase(str) {
12
+ return str.charAt(0).toLowerCase() + str.slice(1)
13
+ } _%>
@@ -0,0 +1,164 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
25
+ const {
26
+ SOURCE_PATH,
27
+ defaultIamRolePerAction,
28
+ createIamRole,
29
+ RESOURCE_CLASSES,
30
+ SNS_RESOURCE,
31
+ resourceNames,
32
+ DYNAMO_RESOURCE,
33
+ SAVE_FILE_NAME,
34
+ FUNCTION_NAME,
35
+ shortNameHandler,
36
+ externalResourceYaml,
37
+ SOURCE_GENERATE_IAM_ROLE,
38
+ LAMBDA_RESOURCE
39
+ } = require("../../../../../../MainLibs/src/Consts");
40
+
41
+ const templatePath = path.join(__dirname, "template.ejs");
42
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
43
+ /**
44
+ * receive objectSchema
45
+ * create data for WebSocket handler template
46
+ *
47
+ * @param {Object} objectSchema
48
+ * @return {{templatePath, templateData,setting}}
49
+ */
50
+ function data(_izContext, allLocalFlowSchemas, srcPath) {
51
+ const handlerType = upperCase("hdrWbs");
52
+ const functionName = FUNCTION_NAME.flowSchemaRegister;
53
+ let functionNameConfig = upperCase(functionName) + upperCase(shortNameHandler(handlerType));
54
+ let additionalResourcePermission = defaultIamRolePerAction();
55
+
56
+ additionalResourcePermission.push(
57
+ createIamRole(
58
+ {
59
+ [RESOURCE_CLASSES.lambda]: [
60
+ LAMBDA_RESOURCE.invokeFunction
61
+ ]
62
+ },
63
+ [
64
+ resourceNames(RESOURCE_CLASSES.lambda, "GetHdrInv")
65
+ ]
66
+ ),
67
+ createIamRole(
68
+ {
69
+ [RESOURCE_CLASSES.dynamoDbTable]: [
70
+ DYNAMO_RESOURCE.putItem,
71
+ DYNAMO_RESOURCE.getItem,
72
+ DYNAMO_RESOURCE.query,
73
+ DYNAMO_RESOURCE.deleteItem,
74
+ DYNAMO_RESOURCE.updateItem
75
+ ]
76
+ },
77
+ [
78
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
79
+ ]
80
+ ),
81
+ createIamRole(
82
+ {
83
+ "execute-api": [
84
+ "ManageConnections"
85
+ ]
86
+ },
87
+ [
88
+ resourceNames(RESOURCE_CLASSES.webSocket)
89
+ ]
90
+ )
91
+ )
92
+
93
+ let tableStoredCacheList = [];
94
+ for (const flowSchema of allLocalFlowSchemas.records) {
95
+ if (flowSchema.statusType === "storedCache") {
96
+ tableStoredCacheList.push(flowSchema.flowTag + "Main");
97
+ }
98
+ }
99
+
100
+ additionalResourcePermission.push(
101
+ createIamRole(
102
+ {
103
+ [RESOURCE_CLASSES.dynamoDbTable]: [
104
+ DYNAMO_RESOURCE.getItem,
105
+ // DYNAMO_RESOURCE.putItem,
106
+ // DYNAMO_RESOURCE.query,
107
+ // DYNAMO_RESOURCE.deleteItem,
108
+ // DYNAMO_RESOURCE.updateItem
109
+ ]
110
+ },
111
+ [
112
+ ...tableStoredCacheList.map(tableName => resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName))
113
+ ]
114
+ )
115
+ )
116
+
117
+ // if (flowSchema?.hook) {
118
+ // for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
119
+ // if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
120
+ // for (const hookFunction of hookProperties.functionList) {
121
+ // if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
122
+ // if (hookFunction?.permission) {
123
+ // for (const permission of hookFunction.permission) {
124
+ // additionalResourcePermission.push(
125
+ // createIamRole(
126
+ // permission.action,
127
+ // permission.resource.map(resource =>
128
+ // externalResourceYaml(
129
+ // resource.resource,
130
+ // resource.resourceName,
131
+ // resource.serviceTag),
132
+ // permission.effect
133
+ // )
134
+ // )
135
+ // )
136
+ // }
137
+ // }
138
+ // }
139
+ // }
140
+ // }
141
+ // }
142
+ // }
143
+
144
+ // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
145
+ return [{
146
+ templatePath: templatePath,
147
+ templateData: {
148
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaRegister, "source/"),
149
+ additionalResourcePermission,
150
+ functionName,
151
+ handlerType,
152
+ roleName: SOURCE_GENERATE_IAM_ROLE.RegisterRole,
153
+ functionNameConfig,
154
+ },
155
+ setting: {
156
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
157
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
158
+ fileExtension: ".yml",
159
+ isAppend: true
160
+ }
161
+ }]
162
+ }
163
+
164
+ module.exports = data;
@@ -0,0 +1,18 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - websocket:
7
+ route: <%- functionName %>
8
+ # authorizer: ${self:custom.iz_authorizerAppLevel}
9
+ # identifierResource: 'route.request.header.Auth'
10
+ role: <%- roleName %>Role
11
+ #<#<%- functionName %><%- handlerType %>IamRole#>
12
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
13
+ <%_ function firstLetterUpperCase(text){
14
+ return text.charAt(0).toUpperCase() + text.slice(1)
15
+ } _%>
16
+ <%_ function firstLetterLowerCase(str) {
17
+ return str.charAt(0).toLowerCase() + str.slice(1)
18
+ } _%>
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { SOURCE_PATH, FUNCTION_NAME, SOURCE_GENERATE_IAM_ROLE } = require("../../../../../../MainLibs/src/Consts");
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
25
+ const templatePath = path.join(__dirname, "template.ejs")
26
+
27
+ /**
28
+ * receive objectSchema
29
+ * create data for WebSocket handler template
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+ function data(_izContext, flowSchema, srcPath) {
35
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
36
+ }
37
+
38
+ function createParamsForCreateSource(_izContext, srcPath) {
39
+ // let functionName = upperCase(FUNCTION_NAME.createObjectS3)
40
+ let functionName = FUNCTION_NAME.flowSchemaRegister
41
+ let handlerType = "HdrWbs"
42
+ let hook = false;
43
+ let hookFunctionName;
44
+ let isAsync = false;
45
+ return {
46
+ templatePath: templatePath,
47
+ templateData: {
48
+ hook: hook,
49
+ hookFunctionName: hookFunctionName,
50
+ isAsync,
51
+ functionName: functionName,
52
+ firstLetterUpperCase: upperCase,
53
+ roleName: SOURCE_GENERATE_IAM_ROLE.RegisterRole,
54
+ routeName: FUNCTION_NAME.flowSchemaRegister,
55
+ },
56
+ setting: {
57
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaRegister, 'source/'),
58
+ saveFileName: `${upperCase(functionName)}_${handlerType}`,
59
+ fileExtension: ".js",
60
+ isAppend: false
61
+ }
62
+ }
63
+ }
64
+ module.exports = data
@@ -0,0 +1,88 @@
1
+ /*
2
+ Copyright (C) 2021 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const { middlewareHandler, consts } = require("@izara_project/izara-middleware");
21
+ // const AWS = require('aws-sdk');
22
+ // const api = new AWS.ApiGatewayManagementApi({ endpoint: process.env.iz_webSocketEndpoint });
23
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
24
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
25
+ const hash = require('object-hash');
26
+ // const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
27
+ const { postToConnection } = require("../../../libs/source/GenerateCodeLibs");
28
+ const { <%- functionName%>Main } = require("./<%- firstLetterUpperCase(functionName) %>_Main");
29
+
30
+ module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
31
+
32
+ event._izContext.logger.debug('Event:', event);
33
+
34
+ try {
35
+
36
+ if (event.requestContext) {
37
+ const route = event.requestContext.routeKey;
38
+ const connectionId = event.requestContext.connectionId;
39
+ let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
40
+
41
+ switch (route) {
42
+ case '$default':
43
+ console.log('Received unknown route:', route);
44
+ break
45
+ case '<%- routeName%>':
46
+ console.log("event in route <%- routeName%>", event);
47
+ let eventParams = JSON.parse(event.body)
48
+
49
+ await dynamodbSharedLib.putItem(
50
+ event._izContext,
51
+ await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
52
+ {
53
+ taskKey: correlationId,
54
+ connectionId: connectionId,
55
+ }
56
+ )
57
+
58
+ let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
59
+
60
+ const result = await registerMain(
61
+ event._izContext,
62
+ eventParams,
63
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
64
+ //(<additionalParams>)
65
+ //(</additionalParams>)
66
+ )
67
+ await postToConnection(
68
+ { message: result },
69
+ connectionId
70
+ )
71
+ break
72
+ }
73
+ } else {
74
+ const connId = event.connId;
75
+ // await postMessage({ message: event.message }, connId);
76
+ await postToConnection({ message: event.message }, connId);
77
+ }
78
+ } catch (err) {
79
+ const connId = event.requestContext.connectionId
80
+ event._izContext.logger.error('Error, WebSocket: ', err);
81
+ // await sendErrorMessage({ message: err.message }, connId);
82
+ await postToConnection({ message: err.message }, connId);
83
+ }
84
+ });
85
+ <%_ const join = require('path').join _%>
86
+ <%_ function upperCase (text) {
87
+ return text.charAt(0).toUpperCase() + text.slice(1)
88
+ } _%>
@@ -0,0 +1,55 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts");
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
24
+ const templatePath = path.join(__dirname, "template.ejs");
25
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
26
+
27
+ /**
28
+ * receive objectSchema
29
+ * create data for WebSocket Main template
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+
35
+
36
+ function data(_izContext, flowSchema, srcPath) {
37
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ function createParamsForCreateSource(_izContext, srcPath) {
41
+ const functionName = upperCase(FUNCTION_NAME.flowSchemaRegister)
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionMain: FUNCTION_NAME.flowSchemaRegister + 'Main',
46
+ },
47
+ setting: {
48
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaRegister, 'source/'),
49
+ saveFileName: `${functionName}_Main`,
50
+ fileExtension: ".js",
51
+ isAppend: false
52
+ }
53
+ }
54
+ }
55
+ module.exports = data