@izara_project/izara-market-library-service-schemas 1.0.29 → 1.0.31

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 (170) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +11 -9
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +54 -21
  4. package/src/MainLibs/src/Consts.js +43 -20
  5. package/src/reStructure/GenerateCode.js +2 -1
  6. package/src/reStructure/TemplateConfig.js +5 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/generateTemplateData.js +108 -0
  8. package/src/reStructure/TemplateData/EndpointPerService/handler/api/data.js +76 -0
  9. package/src/reStructure/TemplateData/EndpointPerService/handler/api/request.json +7 -0
  10. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +73 -0
  11. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/data.js +81 -0
  12. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/request.json +7 -0
  13. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/template.ejs +125 -0
  14. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/data.js +70 -0
  15. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/request.json +7 -0
  16. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +73 -0
  17. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/data.js +79 -0
  18. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/request.json +7 -0
  19. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/template.ejs +126 -0
  20. package/src/reStructure/TemplateData/{flowSchema/components/schema/inProcess/handler → EndpointPerService/mainFunction/create}/data.js +20 -13
  21. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +624 -0
  22. package/src/reStructure/TemplateData/{flowSchema/components/schema/inProcess/mainFunction → EndpointPerService/mainFunction/delete}/data.js +18 -11
  23. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +176 -0
  24. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/data.js +56 -0
  25. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +234 -0
  26. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/data.js +56 -0
  27. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +330 -0
  28. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +177 -0
  29. package/src/reStructure/TemplateData/EndpointPerService/yaml/template.ejs +26 -0
  30. package/src/reStructure/TemplateData/externalService/generateTemplateData.js +1 -1
  31. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +91 -249
  32. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +1 -1
  33. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +10 -8
  34. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +1 -1
  35. package/src/reStructure/TemplateData/findData/findDataYaml/data.js +2 -2
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +8 -7
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/data.js +4 -4
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/data.js +2 -2
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +5 -31
  40. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/data.js +4 -22
  41. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +3 -31
  42. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/data.js +1 -1
  43. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +6 -6
  44. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/handler/data.js +4 -4
  45. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/data.js +4 -4
  46. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  47. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/template.ejs +1 -1
  48. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/data.js +45 -14
  49. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/template.ejs +3 -0
  50. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/handler/data.js +6 -6
  51. package/src/reStructure/TemplateData/flowSchema/{legacy/hookCode-old/handler/templateAsyncHandler.ejs → components/upload/preSignUrl/createPresignUrl/handler/template.ejs} +26 -11
  52. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/mainFunction/data.js +11 -8
  53. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +253 -0
  54. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/data.js +1 -1
  55. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +14 -42
  56. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +0 -3
  57. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/data.js +6 -6
  58. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +40 -45
  59. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +5 -8
  60. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +100 -190
  61. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/data.js +4 -4
  62. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/template.ejs +2 -2
  63. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +9 -7
  64. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/data.js +4 -4
  65. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/data.js +4 -4
  66. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/queue/s3Template.ejs +1 -1
  67. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/S3/data.js +5 -2
  68. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +3 -3
  69. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +2 -0
  70. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/data.js +3 -2
  71. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -16
  72. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchema/functionYaml/data.js +115 -0
  73. package/src/reStructure/TemplateData/flowSchema/{components/schema/inProcess → flowSchemaOwnTopic/flowSchema}/functionYaml/template.ejs +1 -20
  74. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchema/handler/data.js +70 -0
  75. package/src/reStructure/TemplateData/flowSchema/{components/schema/inProcess → flowSchemaOwnTopic/flowSchema}/handler/template.ejs +14 -32
  76. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchema/mainFunction/data.js +64 -0
  77. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchema/mainFunction/template.ejs +104 -0
  78. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchemaComplete/functionYaml/data.js +115 -0
  79. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchemaComplete/functionYaml/template.ejs +20 -0
  80. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchemaComplete/handler/data.js +71 -0
  81. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchemaComplete/handler/template.ejs +85 -0
  82. package/src/reStructure/TemplateData/flowSchema/{components/upload/hook/hookLogic → flowSchemaOwnTopic/flowSchemaComplete/mainFunction}/data.js +30 -10
  83. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowSchemaComplete/mainFunction/template.ejs +105 -0
  84. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +78 -55
  85. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +21 -1
  86. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +35 -44
  87. package/src/reStructure/TemplateData/perActionComplete/create/sns-out/template.ejs +1 -1
  88. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +4 -5
  89. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +5 -4
  90. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +15 -2
  91. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +7 -4
  92. package/src/reStructure/TemplateData/perActionComplete/update/sns-out/data.js +1 -1
  93. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +5 -4
  94. package/src/reStructure/TemplateData/processLogical/yaml/data.js +3 -3
  95. package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +1 -1
  96. package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +2 -2
  97. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +1 -1
  98. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +1 -1
  99. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +1 -1
  100. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +3 -3
  101. package/src/reStructure/TemplateData/relationshipPerAction/create/action/sns-in-sqs/snsTemplate.ejs +1 -1
  102. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +2 -2
  103. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/data.js +1 -1
  104. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-in-sqs/template.ejs +0 -1
  105. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-out/template.ejs +1 -1
  106. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +1 -1
  107. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +1 -1
  108. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +1 -1
  109. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +3 -3
  110. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/sns-in-sqs/snsTemplate.ejs +1 -1
  111. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +2 -2
  112. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/sns-out/template.ejs +1 -1
  113. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +1 -1
  114. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +1 -1
  115. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +1 -1
  116. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +4 -4
  117. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +1 -1
  118. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +2 -2
  119. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +1 -1
  120. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +1 -1
  121. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +1 -1
  122. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +1 -1
  123. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +4 -4
  124. package/src/reStructure/TemplateData/relationshipPerAction/update/action/sns-in-sqs/snsTemplate.ejs +1 -1
  125. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +2 -2
  126. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/sns-out/template.ejs +1 -1
  127. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +1 -1
  128. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +1 -1
  129. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +1 -1
  130. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +6 -12
  131. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +1 -1
  132. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsAndSqsPerActionData.js +22 -49
  133. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsTemplate.ejs +1 -1
  134. package/src/reStructure/TemplateData/resourceYaml/sns-out/data.js +8 -24
  135. package/src/reStructure/TemplateData/resourceYaml/sns-out/template.ejs +1 -1
  136. package/src/reStructure/TemplateData/testTemplate/template.ejs +0 -5
  137. package/src/reStructure/TemplateData/flowSchema/components/schema/inProcess/functionYaml/data.js +0 -76
  138. package/src/reStructure/TemplateData/flowSchema/components/schema/inProcess/sns-sqs/data.js +0 -35
  139. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/functionYaml/data.js +0 -34
  140. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/functionYaml/template.ejs +0 -0
  141. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/handler/data.js +0 -34
  142. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/handler/template.ejs +0 -0
  143. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/mainFunction/data.js +0 -34
  144. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/mainFunction/template.ejs +0 -0
  145. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/sns-sqs/data.js +0 -34
  146. package/src/reStructure/TemplateData/flowSchema/components/schema/outComplete/sns-sqs/template.ejs +0 -0
  147. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/data.js +0 -93
  148. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/templateAsyncHandler.ejs +0 -110
  149. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/templateSyncHandler.ejs +0 -49
  150. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/data.js +0 -65
  151. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/template.ejs +0 -7
  152. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/data.js +0 -72
  153. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/snsTemplate.ejs +0 -59
  154. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/sqsTemplate.ejs +0 -43
  155. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +0 -120
  156. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +0 -163
  157. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/functionYaml/data.js +0 -101
  158. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/functionYaml/template.ejs +0 -43
  159. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/handler/data.js +0 -93
  160. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/handler/templateSyncHandler.ejs +0 -49
  161. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/hookLogic/data.js +0 -64
  162. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/mainFunction/data.js +0 -66
  163. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/mainFunction/template.ejs +0 -30
  164. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/queue/data.js +0 -124
  165. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/queue/snsTemplate.ejs +0 -59
  166. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/queue/sqsTemplate.ejs +0 -43
  167. package/src/reStructure/TemplateData/relationshipPerAction.zip +0 -0
  168. /package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/template.ejs +0 -0
  169. /package/src/reStructure/TemplateData/flowSchema/{components/schema/inProcess/mainFunction/template.ejs → flowSchemaOwnTopic/sns-in/data.js} +0 -0
  170. /package/src/reStructure/TemplateData/flowSchema/{components/schema/inProcess/sns-sqs/template.ejs → flowSchemaOwnTopic/sns-out/data.js} +0 -0
@@ -0,0 +1,330 @@
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 {
23
+ getObjSchemaS3WithHierarchy,
24
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
25
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+ const {
27
+ dynamoDbIdentifiersByStorageResource,
28
+ createFieldForUpdateDynamoDb
29
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
30
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
31
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
32
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
33
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
34
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
35
+
36
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
37
+ const sns = externalRequest.sns
38
+
39
+ const { createUpdateDataDetail } = require("@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs")
40
+ const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
41
+ const coreConsts = require('@izara_project/izara-core-library-core/src/Consts')
42
+ const { createObjType } = require("@izara_project/izara-core-library-service-schemas/src/Utils")
43
+ /**
44
+ *
45
+ *
46
+ * description of function.
47
+ * @param {Object} _izContext
48
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
49
+ * @param {Logger} _izContext.logger - property of _izContext
50
+ * @param {Object} requestParams - request params
51
+ * @param {Object} requestParams.identifiers - identifiers for get data
52
+ * @param {Object} requestParams.additionalRequest - additionalRequest
53
+ *
54
+ *
55
+ * @returns {object} description of return value
56
+ */
57
+
58
+ module.exports.updateMain = async (
59
+ _izContext,
60
+ requestParams,
61
+ callingFlowConfig = {},
62
+ //(<additionalParams>)
63
+ //(</additionalParams>)
64
+ ) => {
65
+
66
+ try {
67
+ _izContext.logger.debug('function UpdateMain: ', {
68
+ requestParams,
69
+ callingFlowConfig
70
+ });
71
+
72
+ let errorFounds = [];
73
+ const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
74
+ const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
75
+
76
+ if (!userId) {
77
+ errorFounds.push("Not have userId")
78
+ }
79
+
80
+ //(<beforeQuery>)
81
+ //(</beforeQuery>)
82
+
83
+ const identifiers = requestParams.objInstanceFull.identifiers;
84
+ const fields = requestParams.objInstanceFull.fields
85
+ let versionedDataIds = requestParams.versionedDataIds || {}
86
+
87
+ _izContext.logger.debug("explode requestParams", {
88
+ identifiers: identifiers,
89
+ fields: fields,
90
+ versionedDataIds: versionedDataIds
91
+ })
92
+ const objType = createObjType(requestParams.objectType);
93
+ let objectSchema = await getObjSchemaS3WithHierarchy(
94
+ _izContext,
95
+ objType
96
+ )
97
+ _izContext.logger.debug("objectSchema", objectSchema);
98
+
99
+ if (objectSchema.hasOwnProperty("belongTo") && !targetId) {
100
+ errorFounds.push('not have targetId')
101
+ }
102
+
103
+ let updateDataDetails = await createUpdateDataDetail(_izContext, objectSchema);
104
+
105
+ _izContext.logger.debug("updateDataDetails", updateDataDetails);
106
+
107
+ let originTimestamp = Date.now();
108
+
109
+ let haveVersionedDataIdsToUpdate = (requestParams.versionedDataIds && Object.keys(requestParams.versionedDataIds).length) ? true : false
110
+ if (haveVersionedDataIdsToUpdate) {
111
+
112
+ let updateMainNodeData = {};
113
+ let updateVersionedData = {};
114
+ _izContext.logger.debug("have versionedDataIds to update")
115
+ for (const fieldProp in requestParams.objInstanceFull.fields) {
116
+ const fieldSetting = objectSchema.fieldNames[fieldProp];
117
+ // collect updateData
118
+ if (fieldSetting.hasOwnProperty("versionedDataLabel")) {
119
+ if (!updateVersionedData.hasOwnProperty(fieldSetting.versionedDataLabel)) {
120
+ updateVersionedData[fieldSetting.versionedDataLabel] = {};
121
+ }
122
+ Object.assign(updateVersionedData[fieldSetting.versionedDataLabel], {
123
+ [fieldProp]: requestParams.objInstanceFull.fields[fieldProp]
124
+ })
125
+ } else {
126
+ Object.assign(updateMainNodeData, {
127
+ [fieldProp]: requestParams.objInstanceFull.fields[fieldProp]
128
+ })
129
+ }
130
+ }
131
+ _izContext.logger.debug("updateMainNodeData::", updateMainNodeData);
132
+ _izContext.logger.debug("updateVersionedData::", updateVersionedData);
133
+
134
+ const versionedDataIdLabelKeys = Object.keys(requestParams.versionedDataIds);
135
+ const updateVersionedDataLabelKeys = Object.keys(updateVersionedData);
136
+
137
+ _izContext.logger.debug("versionedDataIdLabelKeys:: ", versionedDataIdLabelKeys);
138
+ _izContext.logger.debug("updateVersionedDataLabelKeys:: ", updateVersionedDataLabelKeys);
139
+ //check missing versionedDataIds
140
+ const missingVersionedDataIdLabels = updateVersionedDataLabelKeys.filter(label => !versionedDataIdLabelKeys.includes(label));
141
+ _izContext.logger.debug("missingVersionedDataIdLabels:: ", missingVersionedDataIdLabels);
142
+
143
+ if (missingVersionedDataIdLabels.length) {
144
+ errorFounds.push(`missing versionedDataIds of versionedDataLabel '${missingVersionedDataIdLabels.join(", ")}'`)
145
+ }
146
+
147
+ // check missing update data of versionedDataLabels
148
+ const missingDataVersionedDataLabels = versionedDataIdLabelKeys.filter(label => !versionedDataIdLabelKeys.includes(label))
149
+ if (missingDataVersionedDataLabels.length) {
150
+ errorFounds.push(`missing data of versionedDataLabels '${missingDataVersionedDataLabels.join(", ")}'`);
151
+ }
152
+ // check mainNode Data should not exists
153
+ if (Object.keys(updateMainNodeData).length) {
154
+ errorFounds.push("cannot update mainNode if have versionedDataIds");
155
+ }
156
+ }
157
+
158
+ let messageAttributes
159
+
160
+ if (errorFounds.length) {
161
+ let updateNodeCompleteMessage = {
162
+ objType: objType,
163
+ objInstanceFull: {
164
+ identifiers: identifiers,
165
+ fields: fields,
166
+ },
167
+ versionedDataIds: versionedDataIds,
168
+ status: 'error',
169
+ errorFounds: errorFounds
170
+ };
171
+
172
+
173
+ updateNodeCompleteMessage = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, updateNodeCompleteMessage);
174
+ messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {})
175
+
176
+ let messageParams = {
177
+ Message: JSON.stringify(updateNodeCompleteMessage),
178
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
179
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete),
180
+ };
181
+
182
+ _izContext.logger.debug("messageParams OutUpdateNodeComplete ::::::: ", messageParams);
183
+ await sns.publishAsync(_izContext, messageParams);
184
+
185
+ return updateNodeCompleteMessage
186
+ }
187
+
188
+ let awaitingStepIds = [];
189
+
190
+ // start update data
191
+ await Promise.all(
192
+ Object.entries(updateDataDetails).map(
193
+ async ([storageTag, updateDataDetail]) => {
194
+ if (updateDataDetail.storageType === consts.STORAGE_TYPES.graph) {
195
+ // let graphServiceName = await getGraphServiceTagWithCache(_izContext, getDataDetail.graphServiceTag)
196
+
197
+ awaitingStepIds.push( // createAwaitingstepId if updateGraph
198
+ asyncFlowSharedLib.createAwaitingStepId(
199
+ hash({
200
+ objectType: objType.objectType,
201
+ serviceTag: objType.serviceTag,
202
+ identifiers: identifiers,
203
+ fields: fields,
204
+ // correlationIds: _izContext.correlationIds.get("id")
205
+ }),
206
+ PREFIX.updateNode
207
+ )
208
+ )
209
+ _izContext.logger.debug("awaitingStepIds", awaitingStepIds)
210
+
211
+ if (awaitingStepIds.length) {
212
+ let awaitingMultipleStep = await asyncFlowSharedLib.createAwaitingMultipleSteps(
213
+ _izContext,
214
+ awaitingStepIds,
215
+ asyncFlowSharedLib.createPendingStepId(
216
+ hash(
217
+ {
218
+ identifiers,
219
+ fields,
220
+ })
221
+ )
222
+ )
223
+ _izContext.logger.debug("awaitingMultipleStep", awaitingMultipleStep)
224
+ }
225
+
226
+ let updateNodeParams = {
227
+ objType: objType,
228
+ objInstanceFull: {
229
+ identifiers: identifiers,
230
+ fields: fields,
231
+ },
232
+ versionedDataIds: versionedDataIds,
233
+ originTimestamp
234
+ }
235
+
236
+ updateNodeParams = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
237
+ updateNodeParams,
238
+ callingFlowSharedLib.addParentCallingFlowConfig(
239
+ callingFlowConfig,
240
+ callingFlowSharedLib.createCallingFlowConfig(
241
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateNodeComplete), {}
242
+ )
243
+ )
244
+ )
245
+
246
+ _izContext.logger.debug("messageObject before send message:", updateNodeParams);
247
+
248
+
249
+ let updateNodeMessageBody = {
250
+ Message: JSON.stringify(updateNodeParams),
251
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
252
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inUpdateNode, storageTag,)
253
+ }
254
+
255
+ _izContext.logger.debug('requset param before send to topic InUpdateNode:::', updateNodeMessageBody);
256
+
257
+ let resSNS = await sns.publishAsync(_izContext, updateNodeMessageBody)
258
+ _izContext.logger.debug('resSNS send to topic InUpdateNode finish!', resSNS);
259
+
260
+ } else if (updateDataDetail.storageType === consts.STORAGE_TYPES.dynamoDB) {
261
+
262
+ let identifiersForUpdateData = await dynamoDbIdentifiersByStorageResource(
263
+ _izContext,
264
+ objectSchema,
265
+ updateDataDetail,
266
+ identifiers
267
+ )
268
+
269
+ let fieldForUpdateTableDynamo = createFieldForUpdateDynamoDb(_izContext, objectSchema, updateDataDetail, fields)
270
+
271
+ _izContext.logger.debug("identifiersForUpdateData", identifiersForUpdateData)
272
+ _izContext.logger.debug("fieldForUpdateTableDynamo", fieldForUpdateTableDynamo)
273
+
274
+ let updateItem = await dynamodbSharedLib.updateItem(
275
+ _izContext,
276
+ await dynamodbSharedLib.tableName(_izContext, updateDataDetail.tableName),
277
+ identifiersForUpdateData,
278
+ fieldForUpdateTableDynamo,
279
+ {
280
+ returnValues: "ALL_NEW"
281
+ }
282
+ )
283
+ _izContext.logger.debug("updateItem:", updateItem);
284
+
285
+ if (awaitingStepIds.length == 0) {
286
+ let messageObject = {
287
+ objType: objType,
288
+ updateItem
289
+ }
290
+
291
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOWPROPERTIES_PROPERTYNAME]) {
292
+ _izContext.logger.debug("HAVE CALLINGFLOW");
293
+
294
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
295
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
296
+
297
+ _izContext.logger.debug("after create callingFlow", messageObject)
298
+ let outUpdateNodeCompleteTopic = await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete);
299
+ let messageParams = {
300
+ Message: JSON.stringify(messageObject),
301
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
302
+ TopicArn: outUpdateNodeCompleteTopic
303
+ }
304
+
305
+ _izContext.logger.debug("message params OutUpdateNodeComplete :::", messageParams);
306
+ await sns.publishAsync(_izContext, messageParams);
307
+
308
+ }
309
+ }
310
+ }
311
+ }
312
+ )
313
+ )
314
+ return {
315
+ returnValues: {
316
+ objType: objType,
317
+ objInstanceFull: {
318
+ identifiers: identifiers,
319
+ fields: fields,
320
+ },
321
+ versionedDataIds: versionedDataIds
322
+ },
323
+ status: "complete",
324
+ errorFounds
325
+ }
326
+ } catch (err) {
327
+ _izContext.logger.error('error AddressUpdate: ', err)
328
+ throw (err)
329
+ }
330
+ }
@@ -0,0 +1,177 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
23
+
24
+ const {
25
+ firstLetterLowerCase: lowerCase,
26
+ firstLetterUpperCase: upperCase,
27
+ } = require("../../../../MainLibs/index.js").utils;
28
+ const {
29
+ DEFAULT_HANDLER_PER_ACTION,
30
+ createIamRole,
31
+ resourceNames,
32
+ RESOURCE_CLASSES,
33
+ DEFAULT_LAMBDA_ROLE_PER_ACTION,
34
+ SOURCE_PATH,
35
+ SAVE_FILE_NAME,
36
+ DYNAMO_RESOURCE,
37
+ SNS_RESOURCE,
38
+ FUNCTION_NAME,
39
+ defaultIamRolePerAction,
40
+ awaitingMultipleStepsRole,
41
+ shortNameHandler,
42
+ SOURCE_GENERATE_IAM_ROLE,
43
+ getStorageResourceFromObjectSchemas,
44
+ SQS_RESOURCE
45
+ } = require("../../../../MainLibs/src/Consts.js");
46
+
47
+ const templatePath = path.join(__dirname, "./template.ejs")
48
+
49
+ /**
50
+ * receive objectSchema
51
+ * create data for hdrInv template
52
+ *
53
+ * @param {Object} objectSchema
54
+ * @return {{ templatePath, templateData, setting } }
55
+ */
56
+ async function data(_izContext, allObjSchemas, srcPath) {
57
+ let createSourceSet = new Set();
58
+ for (const action of Object.values(ACTIONS)) {
59
+ const defaultHandlers = DEFAULT_HANDLER_PER_ACTION[action]
60
+ for (const defaultHandler of defaultHandlers) {
61
+ const createSourceParam = await createParamForCreateSource(_izContext, allObjSchemas, action, defaultHandler, srcPath)
62
+ createSourceParam && createSourceSet.add(createSourceParam)
63
+ }
64
+ }
65
+ return [...createSourceSet];
66
+ }
67
+
68
+ async function createParamForCreateSource(_izContext, allObjSchemas, action, handler, srcPath) {
69
+ let groupBy = SOURCE_GENERATE_IAM_ROLE.perActionEndpoint;
70
+ let additionalResourcePermission = defaultIamRolePerAction();
71
+ let functionNameConfig = upperCase(action) + upperCase(shortNameHandler(handler))
72
+
73
+ let storageResourceAllLocalObjectSchemas = await getStorageResourceFromObjectSchemas(_izContext, allObjSchemas)
74
+
75
+ if (storageResourceAllLocalObjectSchemas.resourceDynamoTableName.length) {
76
+ additionalResourcePermission.push(
77
+ createIamRole(
78
+ {
79
+ [RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE),
80
+ },
81
+ storageResourceAllLocalObjectSchemas.resourceDynamoTableName.map(tableName =>
82
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
83
+ )
84
+ )
85
+ )
86
+ }
87
+
88
+ function httpEvent(lambdaAction) {
89
+ return {
90
+ create: "put",
91
+ update: "post",
92
+ get: "post",
93
+ delete: "delete"
94
+ }[lambdaAction]
95
+ }
96
+
97
+ function sqsEvent(handler) {
98
+ return {
99
+ [HANDLER.hdrSqs]: resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(HANDLER.hdrSqs)),
100
+ [HANDLER.hdrDsq]: resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(HANDLER.hdrDsq))
101
+ }[handler]
102
+ }
103
+
104
+ let event;
105
+ if (handler === HANDLER.hdrApi) {
106
+ event = httpEvent(action)
107
+ } else if (handler === HANDLER.hdrDsq || handler === HANDLER.hdrSqs) {
108
+ event = sqsEvent(handler)
109
+ }
110
+
111
+ additionalResourcePermission.push(awaitingMultipleStepsRole());
112
+
113
+ additionalResourcePermission.push(
114
+ createIamRole(
115
+ { [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
116
+ [
117
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.createObjectComplete) + "_Out")
118
+ ]
119
+ ),
120
+
121
+ createIamRole(
122
+ { [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
123
+ [
124
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.updateNodeComplete) + "_Out")
125
+ ]
126
+ ),
127
+ createIamRole(
128
+ { [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
129
+ [
130
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.deleteNodeComplete) + "_Out")
131
+ ]
132
+ ),
133
+ createIamRole(
134
+ {
135
+ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish
136
+ },
137
+ [
138
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.getNodeComplete) + "_Out")
139
+ ]
140
+ )
141
+ )
142
+
143
+ if (handler === HANDLER.hdrSqs) {
144
+ additionalResourcePermission.push(
145
+ createIamRole({
146
+ [RESOURCE_CLASSES.sqs]: [SQS_RESOURCE.receiveMessage, SQS_RESOURCE.sendMessage, SQS_RESOURCE.deleteMessage, SQS_RESOURCE.getQueueAttributes]
147
+ },
148
+ [
149
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler)),
150
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler) + "DLQ")
151
+ ]
152
+ )
153
+ )
154
+ }
155
+
156
+ return {
157
+ templatePath: templatePath,
158
+ templateData: {
159
+ resourceLocation: SOURCE_PATH.resourceLocationHandlerEndpointPerService,
160
+ handlerType: handler,
161
+ additionalResourcePermission,
162
+ event: event,
163
+ roleName: groupBy,
164
+ action: action,
165
+ functionNameConfig
166
+ },
167
+ setting: {
168
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
169
+ saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
170
+ fileExtension: '.yml',
171
+ isAppend: true
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+ module.exports = data;
@@ -0,0 +1,26 @@
1
+ <%_ const join = require('path').join _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(action)}_${firstLetterUpperCase(handlerType)}.main`) %>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ <%_ if (handlerType === "hdrDsq" || handlerType === "hdrSqs") { _%>
7
+ - sqs:
8
+ arn: <%- event %>
9
+ batchSize: 10
10
+ <%_ } else if (handlerType === "hdrApi") { _%>
11
+ - http:
12
+ path: <%- firstLetterUpperCase(action) %>
13
+ method: <%- event %>
14
+ cors: true
15
+ #<#<%- firstLetterUpperCase(action) _%><%- firstLetterUpperCase(handlerType) %>Authorizer#>
16
+ #<#/<%- firstLetterUpperCase(action) _%><%- firstLetterUpperCase(handlerType) %>Authorizer#>
17
+ <%_ } _%>
18
+ role: <%- firstLetterUpperCase(roleName) _%>Role
19
+ #<#<%_ action _%><%_ handlerType _%>IamRole#>
20
+ #<#/<%_ action _%><%_ handlerType _%>IamRole#>
21
+ <%_ function firstLetterUpperCase(text){
22
+ return text.charAt(0).toUpperCase() + text.slice(1)
23
+ } _%>
24
+ <%_ function firstLetterLowerCase(str) {
25
+ return str.charAt(0).toLowerCase() + str.slice(1)
26
+ } _%>
@@ -44,7 +44,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
44
44
  const allObjectRelationships = getAllLocalRelationshipSchema(_izContext, objSchemaPath);
45
45
  const allLocalFlowSchemas = await getAllLocalFlowSchemas(_izContext, objSchemaPath);
46
46
  // create External service
47
- const createFunctionIamRole = await createExternalLambdaRole(_izContext, allObjSchemas.records, allObjectRelationships, allLocalFlowSchemas.records, saveFilePath);
47
+ const createFunctionIamRole = await createExternalLambdaRole(_izContext, allObjSchemas, allObjectRelationships, allLocalFlowSchemas.records, saveFilePath);
48
48
  const createSnsSubscription = await createExternalSnsSubscriptions(_izContext, allObjSchemas.records, allObjectRelationships, allLocalFlowSchemas.records, saveFilePath);
49
49
 
50
50
  createSourceParams.push(createFunctionIamRole, createSnsSubscription);