@izara_project/izara-market-library-service-schemas 1.0.3 → 1.0.5

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 (120) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +46 -0
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +69 -8
  4. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +111 -0
  5. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +132 -0
  6. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +110 -0
  7. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +132 -0
  8. package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/data.js +59 -0
  9. package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/template.ejs +338 -0
  10. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/data.js +58 -0
  11. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/request.json +0 -0
  12. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/template.ejs +120 -0
  13. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/data.js +60 -0
  14. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/request.json +0 -0
  15. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/template.ejs +167 -0
  16. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/data.js +60 -0
  17. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/request.json +0 -0
  18. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/template.ejs +107 -0
  19. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/data.js +60 -0
  20. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/request.json +0 -0
  21. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/template.ejs +146 -0
  22. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/request.json +30 -0
  23. package/src/TemplateManager/src/CreateRelationship/createRelationship/sns-in-sqs/data.js +80 -0
  24. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/data.js +133 -0
  25. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/request.json +0 -0
  26. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/template.ejs +33 -0
  27. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/data.js +62 -0
  28. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/request.json +0 -0
  29. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/template.ejs +125 -0
  30. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/data.js +56 -0
  31. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/request.json +0 -0
  32. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +137 -0
  33. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/data.js +72 -0
  34. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/request.json +0 -0
  35. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/template.ejs +47 -0
  36. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/data.js +72 -0
  37. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/request.json +0 -0
  38. package/src/TemplateManager/src/GenerateCode.js +176 -43
  39. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/data.js +7 -23
  40. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/data.js +10 -24
  41. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/data.js +6 -23
  42. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/data.js +14 -33
  43. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/template.ejs +2 -2
  44. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +2 -16
  45. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +3 -17
  46. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +3 -16
  47. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +4 -17
  48. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +0 -15
  49. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +28 -30
  50. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/testParam.json +5 -0
  51. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +95 -0
  52. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +7 -29
  53. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +5 -8
  54. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +3 -6
  55. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +6 -6
  56. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +1 -0
  57. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  58. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  59. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +135 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +62 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json +0 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  66. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +56 -0
  67. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  68. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  69. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +72 -0
  70. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  71. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +46 -0
  72. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +71 -0
  73. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  74. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +112 -0
  75. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json +0 -0
  76. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  77. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +128 -0
  78. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json +0 -0
  79. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +110 -0
  80. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json +0 -0
  81. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +131 -0
  82. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json +0 -0
  83. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +65 -0
  84. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  85. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +331 -0
  86. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +59 -0
  87. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  88. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  89. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +59 -0
  90. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  91. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  92. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +62 -0
  93. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  94. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  95. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +59 -0
  96. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  97. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  98. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +30 -0
  99. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +90 -0
  100. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  101. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  102. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  103. package/src/TemplateManager/src/externalService/LambdaRole/data.js +72 -25
  104. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +8 -3
  105. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +51 -3
  106. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  107. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -14
  108. package/src/TemplateManager/src/libs/Consts.js +52 -23
  109. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +0 -76
  110. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +0 -155
  111. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  112. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
  113. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/request.json +0 -0
  114. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/template.ejs +0 -0
  115. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/request.json +0 -0
  116. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/template.ejs +0 -0
  117. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/example req.js +0 -0
  118. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/request.json +0 -0
  119. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/template.ejs +0 -0
  120. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/request.json +0 -0
@@ -0,0 +1,131 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, '../../../../PerActionEndpoint/FunctionYaml/HdrSqs/template.ejs')
28
+
29
+ function defaultIamRolePerAction() {
30
+
31
+ let defaultIamRole = [];
32
+
33
+
34
+ defaultIamRole.push(
35
+ createIamRole(
36
+ {
37
+ [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
38
+ },
39
+ [
40
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
41
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
42
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
43
+ ]
44
+ )
45
+ );
46
+
47
+ defaultIamRole.push(
48
+ createIamRole(
49
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
50
+ [
51
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
52
+ ]
53
+ )
54
+ );
55
+
56
+ return defaultIamRole
57
+ }
58
+
59
+ /**
60
+ * receive objectSchema
61
+ * create data for updateRelationshipSchema
62
+ *
63
+ * @param {Object} objectSchema
64
+ * @return {{ templatePath, templateData, setting } }
65
+ */
66
+
67
+ function data(_izContext, srcPath) {
68
+ let createSourceArray = [];
69
+ const createSourceParam = createParamForCreateSource(srcPath);
70
+ createSourceArray.push(createSourceParam);
71
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
72
+ return createSourceArray
73
+ }
74
+
75
+
76
+ function createParamForCreateSource(srcPath) {
77
+
78
+ let handlerType = HANDLER.hdrSqs
79
+ let functionName = FUNCTION_NAME.updateRel
80
+ let additionalResourcePermission = defaultIamRolePerAction();
81
+
82
+ additionalResourcePermission.push(
83
+ createIamRole(
84
+ {
85
+ [RESOURCE_CLASSES.sqs]: [
86
+ SQS_RESOURCE.deleteMessage,
87
+ SQS_RESOURCE.getQueueAttributes,
88
+ SQS_RESOURCE.receiveMessage,
89
+ SQS_RESOURCE.sendMessage,
90
+ SQS_RESOURCE.getQueueUrl,
91
+ SQS_RESOURCE.deleteMessageBatch
92
+ ], [RESOURCE_CLASSES.sns]:
93
+ ["Publish", "Subscribe"]
94
+ },
95
+ [
96
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
97
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs) + "DLQ"),
98
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
99
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName) + upperCase(HANDLER.hdrSqs))
100
+ ]
101
+ ),
102
+ )
103
+ additionalResourcePermission.push(
104
+ createIamRole(
105
+ { [RESOURCE_CLASSES.dynamoDbTable]: ["PutItem"] },
106
+ [
107
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleSteps"),
108
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleStepByPending")
109
+ ]
110
+ ))
111
+ return {
112
+ templatePath: templatePath,
113
+ templateData: {
114
+ functionName,
115
+ handlerType,
116
+ additionalResourcePermission,
117
+ resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction
118
+ },
119
+ setting: {
120
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
121
+ saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
122
+ fileExtension: '.yml',
123
+ isAppend: true
124
+ }
125
+
126
+ }
127
+ }
128
+
129
+
130
+
131
+ module.exports = data;
@@ -0,0 +1,65 @@
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
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { createGetDataDetails } = require('../../../../../GenerateCodeLibs/src/GenerateCodeLibs')
24
+
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
26
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
27
+
28
+
29
+ const templatePath = path.join(__dirname, "./template.ejs")
30
+
31
+ /**
32
+ * receive objectSchema
33
+ * create data for hdrInv template
34
+ *
35
+ * @param {Object} objectSchema
36
+ * @return {{ templatePath, templateData, setting } }
37
+ */
38
+ function data(_izContext, srcPath) {
39
+ const createSourceParams = createParamForCreateSource(srcPath)
40
+
41
+
42
+ // console.log("createSourceArrayInUpdateRelationshipHdrInv", createSourceArray)
43
+ return [createSourceParams];
44
+ }
45
+
46
+
47
+ function createParamForCreateSource(srcPath) {
48
+ const functionName = "updateRelationship"
49
+ return {
50
+ templatePath: templatePath,
51
+ templateData: {
52
+ functionName: upperCase(functionName)
53
+ },
54
+ setting: {
55
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
56
+ saveFileName: `${upperCase(functionName)}_Main`,
57
+ fileExtension: '.js',
58
+ isAppend: false
59
+ }
60
+ }
61
+ }
62
+
63
+
64
+
65
+ module.exports = data;
@@ -0,0 +1,331 @@
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-shared/src/CallingFlowSharedLib');
23
+ const lambdaSharedLib = require('@izara_project/izara-shared/src/LambdaSharedLib');
24
+
25
+ const snsSharedLib = require('@izara_project/izara-shared/src/SnsSharedLib');
26
+ const sns = require("@izara_project/izara-core-library-external-request/src/resources/Sns");
27
+
28
+ const asyncFlowSharedLib = require('@izara_project/izara-shared/src/AsyncFlowSharedLib');
29
+
30
+ // const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
31
+
32
+ const { validateObject } = require('@izara_project/izara-core-library-core/src/Validator')
33
+
34
+ const {
35
+ getRelationshipSchemaWithCache,
36
+ getObjSchemaS3WithHierarchy
37
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
38
+
39
+
40
+ const {
41
+ createObjectTypeId,
42
+ createRelationshipTypeId,
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 { NoRetryError } = require("@izara_project/izara-core-library-core");
52
+
53
+ const {
54
+ PREFIX,
55
+ TOPIC_NAME_GRAPH_HANDLER,
56
+ TOPIC_NAME_GENERATE_CODE
57
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
58
+
59
+ /**
60
+ * update relationship endpoint
61
+ *
62
+ * @param {Object} _izContext
63
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
64
+ * @param {Logger} _izContext.logger - property of _izContext
65
+ * @param {Object} requestParams - request params
66
+ * @param {Object} callingFlowConfig
67
+ *
68
+ * @returns {object} description of return value
69
+ */
70
+ module.exports.updateRelationship = async (
71
+ _izContext,
72
+ requestParams,
73
+ callingFlowConfig = {},
74
+ //(<additionalParams>)
75
+ //(</additionalParams>)
76
+ ) => {
77
+
78
+
79
+ try {
80
+ _izContext.logger.debug('updateRelationship _izContext: ', _izContext);
81
+ _izContext.logger.debug('updateRelationship requestParams: ', requestParams);
82
+ _izContext.logger.debug('updateRelationship callingFlowConfig: ', callingFlowConfig);
83
+
84
+
85
+ const {
86
+ objects,
87
+ relType,
88
+ relId,
89
+ relationshipProperties
90
+ //(<requestparamUpdateRel>)
91
+ //(</requestparamUpdateRel>)
92
+ } = requestParams;
93
+
94
+ let errorsFound = [];
95
+
96
+ //(<beforeValidateUpdateRel>)
97
+ //(</beforeValidateUpdateRel>)
98
+ // validate object and identifiers
99
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
100
+
101
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
102
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
103
+
104
+ if (!objectSchema) {
105
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
106
+ }
107
+
108
+ for (const schemaIdentifier of objectSchema.identifiers) {
109
+ let identifierName = schemaIdentifier.fieldName || schemaIdentifier.name;
110
+
111
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
112
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
113
+ } else {
114
+ if (
115
+ typeof (identifiersObject[identifierName]) !== "string"
116
+ && typeof (identifiersObject[identifierName]) !== "number"
117
+ ) {
118
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ await validateIdentifiersExists(_izContext, objects[0].objType, objects[0].identifiers);
125
+ await validateIdentifiersExists(_izContext, objects[1].objType, objects[1].identifiers);
126
+ // finished validate object and identifiers
127
+
128
+ //(<afterValidateUpdateRel>)
129
+ //(</afterValidateUpdateRel>)
130
+
131
+ //(<beforeGetRelUpdateRel>)
132
+ //(</beforeGetRelUpdateRel>)
133
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
134
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
135
+
136
+ let targetStorageResources = [];
137
+
138
+ if (relationshipSchema) {
139
+ // find targetStorageResources and validate each storageResources
140
+ await Promise.all(
141
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
142
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
143
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
144
+
145
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = objects[0].objType;
146
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = objects[1].objType;
147
+
148
+ // find exists link
149
+ if (
150
+ (
151
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType)
152
+ && (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
153
+ )
154
+ ||
155
+ (
156
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType)
157
+ && (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
158
+ )
159
+ ) {
160
+
161
+ // check founded storageResource of link and collect used storageResources
162
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
163
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
164
+
165
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
166
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
167
+ if (!graphServiceTag) {
168
+ errorsFound.push(`storageResourceTag:${storageResourceTag} invalid, not found graph serviceTag from graphServerTag:${usedStorageResource.graphServerTag}`)
169
+ }
170
+
171
+ targetStorageResources.push({
172
+ ...usedStorageResource,
173
+ graphServiceTag: graphServiceTag
174
+ });
175
+ } else {
176
+ targetStorageResources.push(usedStorageResource);
177
+ }
178
+ }));
179
+ }
180
+ })
181
+ );
182
+ //(<afterGetRelUpdateRel>)
183
+ //(</afterGetRelUpdateRel>)
184
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
185
+
186
+ if (!targetStorageResources.length) {
187
+ errorsFound.push(`Not found link from relationship schema`);
188
+ }
189
+
190
+
191
+ // validate canUpdate properties relationship
192
+ for (const [propKey, propValue] of Object.entries(relationshipProperties)) {
193
+ _izContext.logger.debug("propKey: ", propKey);
194
+ _izContext.logger.debug("propValue: ", propValue);
195
+
196
+ if (relationshipSchema.properties[propKey]) {
197
+ if (relationshipSchema.properties[propKey].canUpdate !== true) {
198
+ errorsFound.push(`property:${propKey} cannot update`);
199
+ }
200
+ } else {
201
+ errorsFound.push(`property:${propKey} not exists in relationshipSchema`);
202
+ }
203
+ }
204
+
205
+ } else {
206
+ errorsFound.push(`relationshipSchema not exists`);
207
+ }
208
+
209
+
210
+ // if found errors will stop processing
211
+ if (errorsFound.length) {
212
+
213
+ let updateCompleteMsg = {
214
+ relId: relId,
215
+ relType: relType,
216
+ status: 'error',
217
+ errorFounds: errorsFound
218
+ //(<inUpdateCompleteMsgUpdateRel>)
219
+ //(</inUpdateCompleteMsgUpdateRel>)
220
+ };
221
+
222
+ // if have callingFlow will send to message complete
223
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
224
+ _izContext.logger.debug("HAVE CallingFlow");
225
+
226
+ updateCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, updateCompleteMsg);
227
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
228
+
229
+ let messageParams = {
230
+ Message: JSON.stringify(updateCompleteMsg),
231
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
232
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateRelComplete),
233
+ };
234
+
235
+ _izContext.logger.debug("messageParams OutUpdateRelationshipComplete ::::::: ", messageParams);
236
+ await sns.publishAsync(_izContext, messageParams);
237
+ }
238
+
239
+ return updateCompleteMsg;
240
+ }
241
+
242
+
243
+ // before create awaitingStepId per graph storageResource
244
+ const linkTypeId = createLinkTypeId(_izContext, [objects[0].objType, objects[1].objType], relType);
245
+
246
+ let usedGraphServiceTag = []; // collect used graph serviceName, use to check duplicate graph serviceName across graph serverTag
247
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
248
+ let awaitingStepIds = [];
249
+
250
+ for (const targetStorageResource of targetStorageResources) {
251
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph
252
+ && !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
253
+ ) {
254
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
255
+ targetGraphStorageResources.push(targetStorageResource);
256
+
257
+ // awaitingStepId per graphServiceTag
258
+ awaitingStepIds.push(
259
+ asyncFlowSharedLib.createAwaitingStepId(
260
+ hash({ linkTypeId, relId, relationshipProperties, graphServiceTag: targetStorageResource.graphServiceTag }), // hash id
261
+ PREFIX.updateRel // prefix, use constant further
262
+ )
263
+ );
264
+ }
265
+ }
266
+
267
+ if (awaitingStepIds.length) {
268
+ // save awaiting
269
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
270
+ _izContext,
271
+ awaitingStepIds, // awaitingStepIds
272
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
273
+ hash({ linkTypeId, relId, relationshipProperties, correlationId: _izContext.correlationIds.get("id") }), // hash id
274
+ PREFIX.updateRel // prefix, use constant further
275
+ )
276
+ );
277
+
278
+ // prepare message body
279
+ let updateRelMessageBody = {
280
+ objects: objects,
281
+ relId,
282
+ relType: relType,
283
+ relationshipProperties
284
+ //(<inUpdateRelMessageBodyUpdateRel>)
285
+ //(</inUpdateRelMessageBodyUpdateRel>)
286
+ }
287
+ _izContext.logger.debug('updateRelMessageBody: ', updateRelMessageBody);
288
+
289
+ await Promise.all(
290
+ targetGraphStorageResources.map(async (storageResource) => {
291
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
292
+
293
+ updateRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
294
+ updateRelMessageBody,
295
+ callingFlowSharedLib.addParentCallingFlowConfig(
296
+ callingFlowConfig, // receive parent callingFlowConfig.
297
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
298
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateRelComplete),
299
+ {
300
+ graphServiceTag: storageResource.graphServiceTag
301
+ }
302
+ )
303
+ )
304
+ );
305
+ _izContext.logger.debug("messageObject before send message:", updateRelMessageBody)
306
+
307
+ let messageToInUpdateRelationship = {
308
+ Message: JSON.stringify(updateRelMessageBody),
309
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inUpdateRel, storageResource.graphServiceTag),
310
+ };
311
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInUpdateRelationship);
312
+ await sns.publishAsync(_izContext, messageToInUpdateRelationship);
313
+ }
314
+ })
315
+ )
316
+
317
+ } else {
318
+ // if relationshipSchema stored in dynamoDB only will send message to outComplete
319
+ }
320
+
321
+ return {
322
+ relId: relId,
323
+ relType: relType,
324
+ errorFounds: errorsFound
325
+ };
326
+
327
+ } catch (err) {
328
+ _izContext.logger.error('error updateRelationship: ', err)
329
+ throw (err)
330
+ }
331
+ }
@@ -0,0 +1,59 @@
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
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+
41
+ function createParamForCreateSource(srcPath) {
42
+ const functionName = FUNCTION_NAME.updateRel;
43
+ const handler = HANDLER.hdrApi
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName,
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
51
+ saveFileName: `${upperCase(functionName)}_${upperCase(handler)}`,
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }