@izara_project/izara-market-library-service-schemas 1.0.26 → 1.0.28

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 (148) hide show
  1. package/index.js +2 -1
  2. package/package.json +9 -4
  3. package/src/GenerateCodeLibs/src/Consts.js +5 -2
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +6 -6
  5. package/src/MainLibs/src/Consts.js +45 -2
  6. package/src/TemplateManager/src/libs/Consts.js +0 -1
  7. package/src/reStructure/GenerateCode.js +23 -4
  8. package/src/reStructure/GenerateSchema.js +153 -0
  9. package/src/reStructure/SchemaConfig.js +29 -0
  10. package/src/reStructure/TemplateConfig.js +20 -0
  11. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +104 -0
  12. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/attributeLinkTemplate.ejs +21 -0
  13. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +188 -0
  14. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/request.json +11 -0
  15. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +3 -4
  16. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +1 -1
  17. package/src/reStructure/TemplateData/findData/handler/template.ejs +1 -1
  18. package/src/reStructure/TemplateData/findData/mainFunction/template.ejs +3 -3
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +3 -1
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/template.ejs +1 -14
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/template.ejs +2 -3
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +2 -3
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +4 -2
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +1 -14
  25. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +2 -3
  26. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +5 -6
  27. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +3 -1
  28. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/template.ejs +1 -14
  29. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/handler/template.ejs +1 -2
  30. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +3 -4
  31. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/data.js +3 -1
  32. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/template.ejs +1 -14
  33. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +2 -2
  34. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +3 -4
  35. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +3 -1
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +1 -14
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +2 -3
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -6
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +4 -2
  40. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/template.ejs +1 -14
  41. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/template.ejs +1 -1
  42. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +4 -5
  43. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +4 -2
  44. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js +2 -1
  45. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js +2 -1
  46. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +10 -0
  47. package/src/reStructure/TemplateData/perActionComplete/create/handler/template.ejs +2 -3
  48. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +4 -5
  49. package/src/reStructure/TemplateData/perActionComplete/delete/handler/template.ejs +2 -2
  50. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +4 -6
  51. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +1 -1
  52. package/src/reStructure/TemplateData/perActionComplete/get/handler/template.ejs +2 -3
  53. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +4 -6
  54. package/src/reStructure/TemplateData/perActionComplete/update/handler/template.ejs +2 -3
  55. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +4 -6
  56. package/src/reStructure/TemplateData/perActionComplete/update/sns-in-sqs/data.js +1 -1
  57. package/src/reStructure/TemplateData/perActionEndpoint/handler/api/template.ejs +1 -1
  58. package/src/reStructure/TemplateData/perActionEndpoint/handler/dsq/template.ejs +2 -2
  59. package/src/reStructure/TemplateData/perActionEndpoint/handler/inv/template.ejs +1 -3
  60. package/src/reStructure/TemplateData/perActionEndpoint/handler/sqs/template.ejs +2 -2
  61. package/src/reStructure/TemplateData/perActionEndpoint/handler/webSocket/template.ejs +3 -3
  62. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/create/template.ejs +6 -7
  63. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/delete/template.ejs +5 -4
  64. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/get/template.ejs +5 -6
  65. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/update/template.ejs +5 -6
  66. package/src/reStructure/TemplateData/processLogical/handler/template.ejs +1 -1
  67. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +5 -6
  68. package/src/reStructure/TemplateData/processLogicalPagination/handler/dsq/template.ejs +1 -1
  69. package/src/reStructure/TemplateData/processLogicalPagination/handler/sqs/template.ejs +1 -1
  70. package/src/reStructure/TemplateData/processLogicalPagination/mainFunction/template.ejs +6 -5
  71. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +27 -6
  72. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +25 -4
  73. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +26 -4
  74. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +26 -4
  75. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/api/template.ejs +1 -1
  76. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/dsq/template.ejs +2 -2
  77. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/inv/template.ejs +1 -1
  78. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/sqs/template.ejs +2 -2
  79. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +66 -18
  80. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -3
  81. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +5 -6
  82. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +25 -4
  83. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +25 -4
  84. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +25 -4
  85. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +26 -4
  86. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/api/template.ejs +1 -1
  87. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/dsq/template.ejs +2 -2
  88. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/inv/template.ejs +1 -1
  89. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/sqs/template.ejs +2 -2
  90. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +55 -5
  91. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +62 -6
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +119 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/template.ejs +20 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +131 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/template.ejs +17 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +119 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/template.ejs +13 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +131 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/template.ejs +17 -0
  100. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/data.js +57 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/request.json +0 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/template.ejs +138 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/data.js +58 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/request.json +0 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/template.ejs +183 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/data.js +59 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/request.json +0 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/template.ejs +125 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/data.js +59 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/request.json +0 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/template.ejs +163 -0
  112. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/data.js +59 -0
  113. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +322 -0
  114. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/data.js +77 -0
  115. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +59 -0
  116. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  117. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +110 -0
  118. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/request.json +0 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/template.ejs +20 -0
  120. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/data.js +60 -0
  121. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/request.json +0 -0
  122. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +125 -0
  123. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/data.js +55 -0
  124. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/request.json +0 -0
  125. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +141 -0
  126. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/data.js +71 -0
  127. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/request.json +0 -0
  128. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/template.ejs +47 -0
  129. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/data.js +71 -0
  130. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/request.json +0 -0
  131. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +10 -0
  132. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +25 -22
  133. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +25 -5
  134. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +26 -5
  135. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +25 -4
  136. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/api/template.ejs +1 -1
  137. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/dsq/template.ejs +2 -2
  138. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/inv/template.ejs +1 -1
  139. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/sqs/template.ejs +2 -2
  140. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +55 -7
  141. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +50 -42
  142. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +98 -0
  143. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +4 -5
  144. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -1
  145. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +11 -2
  146. package/src/reStructure/TemplateData/testTemplate/data.js +27 -0
  147. package/src/reStructure/TemplateData/testTemplate/template.ejs +5 -0
  148. package/src/reStructure/libs/GenerateCodeLibs.js +38 -0
@@ -0,0 +1,322 @@
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 hash = require("object-hash");
21
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
23
+ const lambdaSharedLib = require("@izara_project/izara-core-library-lambda");
24
+ const snsSharedLib = require("@izara_project/izara-core-library-sns");
25
+ const dynamodbSharedLib = require("@izara_project/izara-core-library-dynamodb");
26
+ const asyncFlowSharedLib = require("@izara_project/izara-core-library-asynchronous-flow");
27
+
28
+ const externalService = require('@izara_project/izara-core-library-external-request/')
29
+ const sns = externalService.sns;
30
+ const lambda = externalService.lambda;
31
+ const identifiersObject = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
32
+
33
+ // const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
34
+
35
+ const { findLinksByObjTypes } = require("@izara_project/izara-core-library-service-schemas/src/libs/RelSchemaLib");
36
+
37
+ const {
38
+ getRelationshipSchemaWithCache,
39
+ getObjSchemaS3WithHierarchy
40
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
41
+
42
+ const {
43
+ createLinkTypeId
44
+ } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
45
+
46
+ const {
47
+ getGraphServiceTagWithCache
48
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
49
+
50
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
51
+ const {
52
+ PREFIX,
53
+ TOPIC_NAME_GENERATE_CODE,
54
+ TOPIC_NAME_GRAPH_HANDLER
55
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
56
+
57
+ /**
58
+ * update relationship endpoint
59
+ *
60
+ * @param {Object} _izContext
61
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
62
+ * @param {Logger} _izContext.logger - property of _izContext
63
+ * @param {Object} requestParams - request params
64
+ * @param {Object} callingFlowConfig
65
+ *
66
+ * @returns {object} description of return value
67
+ */
68
+ module.exports.getRelationship = async (
69
+ _izContext,
70
+ requestParams,
71
+ callingFlowConfig = {},
72
+ //(<additionalParams>)
73
+ //(</additionalParams>)
74
+ ) => {
75
+
76
+
77
+ try {
78
+ _izContext.logger.debug('createRelationship _izContext: ', _izContext);
79
+ _izContext.logger.debug('createRelationship requestParams: ', requestParams);
80
+ _izContext.logger.debug('createRelationship callingFlowConfig: ', callingFlowConfig);
81
+
82
+
83
+ const {
84
+ firstObject,
85
+ secondObject,
86
+ relType,
87
+ relId,
88
+ relationshipDirection,
89
+ //(<requestparamCreateRel>)
90
+ //(</requestparamCreateRel>)
91
+ } = requestParams;
92
+
93
+ let errorsFound = [];
94
+
95
+ //(<beforeValidateCreateRel>)
96
+ //(</beforeValidateCreateRel>).
97
+ // validate object and identifiers
98
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
99
+
100
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
101
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
102
+
103
+ if (!objectSchema) {
104
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
105
+ }
106
+
107
+ for (const schemaIdentifier of objectSchema.identifiers) {
108
+ let identifierNames = schemaIdentifier.fieldNames || [schemaIdentifier.fieldName];
109
+ for (const identifierName of identifierNames) {
110
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
111
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
112
+ } else {
113
+ if (
114
+ typeof (identifiersObject[identifierName]) !== "string" &&
115
+ typeof (identifiersObject[identifierName]) !== "number"
116
+ ) {
117
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ await validateIdentifiersExists(_izContext, firstObject.objType, firstObject.identifiers);
125
+ await validateIdentifiersExists(_izContext, secondObject.objType, secondObject.identifiers);
126
+ // finished validate object and identifiers
127
+
128
+ //(<afterValidateCreateRel>)
129
+ //(</afterValidateCreateRel>)
130
+
131
+ //(<beforeGetRelCreateRel>)
132
+ //(</beforeGetRelCreateRel>)
133
+
134
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
135
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
136
+
137
+ const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], relationshipSchema.links)
138
+ _izContext.logger.debug("links", links)
139
+ if (!links.length) {
140
+ errorsFound.push(`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`)
141
+ };
142
+
143
+ let targetStorageResources = [];
144
+
145
+ if (relationshipSchema) {
146
+ // find targetStorageResources and validate each storageResources
147
+ await Promise.all(
148
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
149
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
150
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
151
+
152
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType;
153
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType;
154
+
155
+ // find exists link
156
+ if (
157
+ (
158
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType) &&
159
+ (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
160
+ ) ||
161
+ (
162
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType) &&
163
+ (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
164
+ )
165
+ ) {
166
+
167
+ // check founded storageResource of link and collect used storageResources
168
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
169
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
170
+
171
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
172
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
173
+ if (!graphServiceTag) {
174
+ errorsFound.push(`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`)
175
+ }
176
+
177
+ targetStorageResources.push({
178
+ ...usedStorageResource,
179
+ graphServiceTag: graphServiceTag
180
+ });
181
+ } else {
182
+ targetStorageResources.push(usedStorageResource);
183
+ }
184
+ }));
185
+ }
186
+ })
187
+ );
188
+ //(<afterGetRelCreateRel>)
189
+ //(</afterGetRelCreateRel>)
190
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
191
+
192
+ if (!targetStorageResources.length) {
193
+ errorsFound.push(`Not found link from relationship schema`);
194
+ }
195
+ } else {
196
+ errorsFound.push(`relationshipSchema not exists`);
197
+ }
198
+
199
+
200
+ // if found errors will stop processing
201
+ if (errorsFound.length) {
202
+
203
+ let getRelCompleteMsg = {
204
+ firstObject: firstObject,
205
+ secondObject: secondObject,
206
+ relType: relType,
207
+ relationshipDirection,
208
+ //(<inCreateRelCompleteMsgCrateRel>)
209
+ //(</inCreateRelCompleteMsgCrateRel>)
210
+ status: 'error',
211
+ errorFounds: errorsFound
212
+ };
213
+
214
+ // if have callingFlow will send to message complete
215
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
216
+ _izContext.logger.debug("HAVE CallingFlow");
217
+
218
+ getRelCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, getRelCompleteMsg);
219
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
220
+
221
+ let messageParams = {
222
+ Message: JSON.stringify(getRelCompleteMsg),
223
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
224
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateRelComplete),
225
+ };
226
+
227
+ _izContext.logger.debug("messageParams OutCreateRelationshipComplete ::::::: ", messageParams);
228
+ await sns.publishAsync(_izContext, messageParams);
229
+ }
230
+
231
+ return getRelCompleteMsg;
232
+ }
233
+
234
+ let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
235
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
236
+
237
+ for (const targetStorageResource of targetStorageResources) {
238
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
239
+ !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
240
+ ) {
241
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
242
+ targetGraphStorageResources.push(targetStorageResource);
243
+ }
244
+ }
245
+ let result;
246
+ await Promise.all(
247
+ targetGraphStorageResources.map(async (storageResource) => {
248
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
249
+ let getResultFromGraph = await lambda.invokeSync(_izContext,
250
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "GetRelationshipV2", storageResource.graphServiceTag),
251
+ {
252
+ firstObject: firstObject,
253
+ secondObject: secondObject,
254
+ relType: relType,
255
+ relId: relId,
256
+ relationshipDirection,
257
+ }
258
+ )
259
+ result = getResultFromGraph;
260
+ } else if (storageResource.storageType === consts.STORAGE_TYPES.dynamoDB) {
261
+
262
+ // if have storageResource.storageType === "dynamoDB" will create relationship here
263
+ let tableNameFrom = `${firstObject.objType.serviceTag}_${firstObject.objType.objectType}__${relType.relationshipTag}__${secondObject.objType.serviceTag}_${secondObject.objType.objectType}`;
264
+
265
+ let identifiersConcatFirstObject = await identifiersObject.identifiersConcatFromIdentifiers(_izContext, firstObject.objType, firstObject.identifiers);
266
+ let identifiersConcatSecondObject = await identifiersObject.identifiersConcatFromIdentifiers(_izContext, secondObject.objType, secondObject.identifiers);
267
+ const firstObjectIdentifiersConcat = `${firstObject.objType.serviceTag}_${firstObject.objType.objectType}__identifiersConcat`;
268
+ const secondObjectIdentifiersConcat = `${secondObject.objType.serviceTag}_${secondObject.objType.objectType}__identifiersConcat`;
269
+ // putItem first Object DynamoDb
270
+ let getResultFromDynamo = await dynamodbSharedLib.getItem(_izContext,
271
+ await dynamodbSharedLib.tableName(_izContext, tableNameFrom),
272
+ {
273
+ [firstObjectIdentifiersConcat]: identifiersConcatFirstObject,
274
+ [secondObjectIdentifiersConcat]: identifiersConcatSecondObject
275
+ }
276
+ )
277
+ result = getResultFromDynamo;
278
+ }
279
+ }
280
+ )
281
+ )
282
+
283
+ let messageObject = {
284
+ firstObject: firstObject,
285
+ secondObject: secondObject,
286
+ relType: relType,
287
+ relId: relId,
288
+ relationshipDirection,
289
+ result: result
290
+ };
291
+
292
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
293
+ _izContext.logger.debug("have callingFlow");
294
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
295
+
296
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
297
+ let sendMessageToOutGetRelComplete = {
298
+ Message: JSON.stringify(messageObject),
299
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
300
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outGetRelComplete)
301
+ }
302
+ _izContext.logger.debug("send Message to outCreateRelationshipComplete :::", sendMessageToOutGetRelComplete);
303
+ await sns.publishAsync(_izContext, sendMessageToOutGetRelComplete);
304
+
305
+ }
306
+
307
+ return {
308
+ firstObject: firstObject,
309
+ secondObject: secondObject,
310
+ relType: relType,
311
+ relId: relId,
312
+ relationshipDirection,
313
+ result: result,
314
+ status: "complete"
315
+ };
316
+
317
+
318
+ } catch (err) {
319
+ _izContext.logger.error('error getRelationship: ', err)
320
+ throw (err)
321
+ }
322
+ }
@@ -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
+ const {
23
+ HANDLER,
24
+ } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
25
+
26
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/index.js").utils;
27
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../../../../MainLibs/index.js").consts;
28
+ const snsTemplatePath = path.join(__dirname, "./snsTemplate.ejs")
29
+ const sqsTemplatePath = path.join(__dirname, "./sqsTemplate.ejs")
30
+
31
+ /**
32
+ * create data for dynamoDbYaml tempalte from objectSchema
33
+ *
34
+ * @param {Object} _izContext
35
+ * @param {String} saveFilePath
36
+ * @returns {Object[]} - data of multiple dynamoDb template
37
+ */
38
+
39
+ function createRelationshipSnsInSqs(_izContext, srcPath) {
40
+ let resultForCreateRelationshipSnsAndSqs = [];
41
+ const setting = {
42
+ initialData: "Resources:\n",
43
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
44
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
45
+ fileExtension: ".yml",
46
+ isAppend: true
47
+ }
48
+ const createRelationshipQueueNames = [
49
+ {
50
+ queueName: upperCase(FUNCTION_NAME.getRel)
51
+ },
52
+ {
53
+ queueName: upperCase(FUNCTION_NAME.getRel) + upperCase(HANDLER.hdrDsq)
54
+ }
55
+ ]
56
+ for (let createRelationshipQueueName of createRelationshipQueueNames) {
57
+ if (createRelationshipQueueName.queueName.includes("HdrDsq")) {
58
+ resultForCreateRelationshipSnsAndSqs.push({
59
+ templatePath: sqsTemplatePath,
60
+ templateData: createRelationshipQueueName,
61
+ setting: setting
62
+ }
63
+ )
64
+ } else {
65
+ resultForCreateRelationshipSnsAndSqs.push(
66
+ {
67
+ templatePath: snsTemplatePath,
68
+ templateData: createRelationshipQueueName,
69
+ setting: setting
70
+ }
71
+ )
72
+ }
73
+ }
74
+ return resultForCreateRelationshipSnsAndSqs
75
+ }
76
+
77
+ module.exports = createRelationshipSnsInSqs
@@ -0,0 +1,59 @@
1
+ ##===== [Create topic in]
2
+ In<%- queueName %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message in"
6
+ TopicName: ${self:custom.iz_resourcePrefix}In<%- queueName %>
7
+ ##===== SNS Subscription
8
+ ##===== [Topic In]
9
+ SubscriptionIn<%- queueName %>:
10
+ Type: AWS::SNS::Subscription
11
+ Properties:
12
+ TopicArn: !Ref In<%- queueName %>
13
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
14
+ Protocol: "sqs"
15
+ ##===== [Queue]
16
+ <%- queueName %>HdrSqs:
17
+ Type: "AWS::SQS::Queue"
18
+ Properties:
19
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
20
+ RedrivePolicy:
21
+ deadLetterTargetArn:
22
+ # !GetAtt
23
+ Fn::GetAtt:
24
+ - <%- queueName %>HdrSqsDLQ
25
+ - Arn
26
+ maxReceiveCount: 3
27
+ VisibilityTimeout: 120
28
+ ##==== [QueueDLQ]
29
+ <%- queueName %>HdrSqsDLQ:
30
+ Type: AWS::SQS::Queue
31
+ Properties:
32
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
33
+ ##==== [QueuePolicy]
34
+ <%- queueName %>HdrSqsPolicy:
35
+ Type: AWS::SQS::QueuePolicy
36
+ Properties:
37
+ PolicyDocument:
38
+ Version: "2012-10-17"
39
+ Statement:
40
+ - Sid: "allow-sns-messages"
41
+ Effect: Allow
42
+ Principal: "*"
43
+ Resource:
44
+ # !GetAtt
45
+ Fn::GetAtt:
46
+ - <%- queueName %>HdrSqs
47
+ - Arn
48
+ Action: "SQS:SendMessage"
49
+ Queues:
50
+ - Ref: <%- queueName %>HdrSqs
51
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
52
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
53
+
54
+ <%_ function firstLetterUpperCase(text){
55
+ return text.charAt(0).toUpperCase() + text.slice(1)
56
+ } _%>
57
+ <%_ function firstLetterLowerCase(str) {
58
+ return str.charAt(0).toLowerCase() + str.slice(1)
59
+ } _%>
@@ -0,0 +1,43 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>DLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
+
19
+ <%- queueName %>Policy:
20
+ Type: AWS::SQS::QueuePolicy
21
+ Properties:
22
+ PolicyDocument:
23
+ Version: "2012-10-17"
24
+ Statement:
25
+ - Sid: "allow-sns-messages"
26
+ Effect: Allow
27
+ Principal: "*"
28
+ Resource: #!GetAtt
29
+ Fn::GetAtt:
30
+ - <%- queueName %>
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>
35
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
+
38
+ <%_ function firstLetterUpperCase(text){
39
+ return text.charAt(0).toUpperCase() + text.slice(1)
40
+ } _%>
41
+ <%_ function firstLetterLowerCase(str) {
42
+ return str.charAt(0).toLowerCase() + str.slice(1)
43
+ } _%>
@@ -0,0 +1,110 @@
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 { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/index.js").utils;
24
+ const {
25
+ createIamRole,
26
+ resourceNames,
27
+ RESOURCE_CLASSES,
28
+ SQS_RESOURCE,
29
+ SOURCE_PATH,
30
+ SAVE_FILE_NAME,
31
+ FUNCTION_NAME,
32
+ defaultIamRolePerAction,
33
+ awaitingMultipleStepsRole,
34
+ SNS_RESOURCE,
35
+ shortNameHandler,
36
+ SHORT_FUNCTION_NAME,
37
+ SOURCE_GENERATE_IAM_ROLE
38
+ } = require("../../../../../../MainLibs/index.js").consts;
39
+
40
+ const templatePath = path.join(__dirname, "./template.ejs")
41
+
42
+ /**
43
+ * receive objectSchema
44
+ * create data for updateRelationshipSchema
45
+ *
46
+ * @param {Object} objectSchema
47
+ * @return {{ templatePath, templateData, setting } }
48
+ */
49
+
50
+ function data(_izContext, srcPath) {
51
+ let createSourceArray = [];
52
+ const createSourceParam = createParamForCreateSource(srcPath);
53
+ createSourceArray.push(createSourceParam);
54
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
55
+ return createSourceArray
56
+ }
57
+
58
+
59
+ function createParamForCreateSource(srcPath) {
60
+ let handlerType = upperCase(HANDLER.hdrSqs);
61
+ let functionName = FUNCTION_NAME.getRelComplete
62
+ let additionalResourcePermission = defaultIamRolePerAction();
63
+
64
+ additionalResourcePermission.push(
65
+ createIamRole(
66
+ {
67
+ [RESOURCE_CLASSES.sqs]: [
68
+ SQS_RESOURCE.deleteMessage,
69
+ SQS_RESOURCE.getQueueAttributes,
70
+ SQS_RESOURCE.receiveMessage,
71
+ SQS_RESOURCE.sendMessage,
72
+ SQS_RESOURCE.deleteMessageBatch,
73
+ SQS_RESOURCE.getQueueUrl,
74
+ ],
75
+ [RESOURCE_CLASSES.sns]:
76
+ [
77
+ SNS_RESOURCE.publish, SNS_RESOURCE.subscribe
78
+ ]
79
+ },
80
+ [
81
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)),
82
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + "DLQ"),
83
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName)),
84
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName))
85
+ ],
86
+ ))
87
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
88
+
89
+ return {
90
+ templatePath: templatePath,
91
+ templateData: {
92
+ functionName,
93
+ handlerType,
94
+ additionalResourcePermission,
95
+ resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction,
96
+ functionNameConfig: upperCase(SHORT_FUNCTION_NAME.getRelComplete),
97
+ roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole
98
+ },
99
+ setting: {
100
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
101
+ saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
102
+ fileExtension: '.yml',
103
+ isAppend: true
104
+ }
105
+
106
+ }
107
+ }
108
+
109
+
110
+ module.exports = data;
@@ -0,0 +1,20 @@
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) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%-firstLetterUpperCase(functionName) %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
+ role: <%- roleName %>Role
13
+ #<#<%- functionName %><%- handlerType %>IamRole#>
14
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
15
+ <%_ function firstLetterUpperCase(text){
16
+ return text.charAt(0).toUpperCase() + text.slice(1)
17
+ } _%>
18
+ <%_ function firstLetterLowerCase(str) {
19
+ return str.charAt(0).toLowerCase() + str.slice(1)
20
+ } _%>