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

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 (75) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +40 -0
  3. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +4 -4
  4. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +7 -5
  5. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +3 -3
  6. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +11 -13
  7. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +1 -1
  8. package/src/TemplateManager/src/GenerateCode.js +117 -29
  9. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +1 -1
  10. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +1 -1
  11. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +1 -1
  12. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +1 -1
  13. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +1 -1
  14. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +98 -0
  15. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +7 -7
  16. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +4 -3
  17. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +4 -4
  18. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +4 -4
  19. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +1 -0
  20. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  21. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  22. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  23. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
  24. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  25. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  26. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
  27. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json +0 -0
  28. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  29. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
  30. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  31. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  32. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
  33. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  34. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
  35. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
  36. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  37. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
  38. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json +0 -0
  39. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  40. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
  41. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json +0 -0
  42. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
  43. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json +0 -0
  44. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
  45. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json +0 -0
  46. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
  47. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  48. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
  49. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
  50. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  51. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  52. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
  53. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  54. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  55. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
  56. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  57. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  58. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
  59. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  66. package/src/TemplateManager/src/externalService/LambdaRole/data.js +56 -10
  67. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +6 -2
  68. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +67 -2
  69. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  70. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -14
  71. package/src/TemplateManager/src/libs/Consts.js +16 -25
  72. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +0 -76
  73. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +0 -155
  74. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  75. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
@@ -0,0 +1,125 @@
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 } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "../../../../FunctionYaml/HdrInv/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
+
70
+ const createSourceParam = createParamForCreateSource(srcPath);
71
+ createSourceArray.push(createSourceParam);
72
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
73
+ return createSourceArray
74
+ }
75
+
76
+
77
+ function createParamForCreateSource(srcPath) {
78
+
79
+ let handlerType = "HdrInv"
80
+ let functionName = 'updateRelationship'
81
+ let additionalResourcePermission = defaultIamRolePerAction();
82
+
83
+ additionalResourcePermission.push(
84
+ createIamRole(
85
+ { [RESOURCE_CLASSES.dynamoDbTable]: ["PutItem"] },
86
+ [
87
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleSteps"),
88
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleStepByPending")
89
+ ]
90
+ ))
91
+ return {
92
+ templatePath: templatePath,
93
+ templateData: {
94
+ functionName,
95
+ handlerType,
96
+ additionalResourcePermission,
97
+ resourceLocation: SOURCE_PATH.resourceLocationUpdateRelationshipSchema
98
+ },
99
+ setting: {
100
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
101
+ saveFileName: 'updateRelationshipSchema',
102
+ fileExtension: '.yml',
103
+ isAppend: true
104
+ }
105
+
106
+ }
107
+ }
108
+
109
+
110
+
111
+ // [
112
+ // {
113
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
114
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
115
+ // setting: {
116
+ // savePath: '/generatedCode/source/',
117
+ // saveFileName: 'ObjectTypeGet',
118
+ // fileExtension: '.js',
119
+ // isAppend: false
120
+ // }
121
+ // }
122
+ // ]
123
+
124
+
125
+ module.exports = data;
@@ -0,0 +1,148 @@
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 } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "../../../../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 = "HdrSqs"
79
+ let functionName = 'updateRelationship'
80
+ let additionalResourcePermission = defaultIamRolePerAction();
81
+
82
+ additionalResourcePermission.push(
83
+ // createIamRole(
84
+ // { [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
85
+ // [resourceNames(RESOURCE_CLASSES.lambda, "*GetNodeHdrInv")]),
86
+ createIamRole(
87
+ {
88
+ [RESOURCE_CLASSES.sqs]: [
89
+ SQS_RESOURCE.deleteMessage,
90
+ SQS_RESOURCE.getQueueAttributes,
91
+ SQS_RESOURCE.receiveMessage,
92
+ SQS_RESOURCE.sendMessage,
93
+ SQS_RESOURCE.getQueueUrl,
94
+ SQS_RESOURCE.deleteMessageBatch
95
+ ], [RESOURCE_CLASSES.sns]:
96
+ ["Publish", "Subscribe"]
97
+ },
98
+ [
99
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
100
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs) + "DLQ"),
101
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
102
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName) + upperCase(HANDLER.hdrSqs))
103
+ ]
104
+ ),
105
+ )
106
+ additionalResourcePermission.push(
107
+ createIamRole(
108
+ { [RESOURCE_CLASSES.dynamoDbTable]: ["PutItem"] },
109
+ [
110
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleSteps"),
111
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "AwaitingMultipleStepByPending")
112
+ ]
113
+ ))
114
+ return {
115
+ templatePath: templatePath,
116
+ templateData: {
117
+ functionName,
118
+ handlerType,
119
+ additionalResourcePermission,
120
+ resourceLocation: SOURCE_PATH.resourceLocationUpdateRelationshipSchema
121
+ },
122
+ setting: {
123
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
124
+ saveFileName: 'updateRelationshipSchema',
125
+ fileExtension: '.yml',
126
+ isAppend: true
127
+ }
128
+
129
+ }
130
+ }
131
+
132
+
133
+
134
+ // [
135
+ // {
136
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
137
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
138
+ // setting: {
139
+ // savePath: '/generatedCode/source/',
140
+ // saveFileName: 'ObjectTypeGet',
141
+ // fileExtension: '.js',
142
+ // isAppend: false
143
+ // }
144
+ // }
145
+ // ]
146
+
147
+
148
+ module.exports = data;
@@ -0,0 +1,80 @@
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
+ let createSourceArray = [];
40
+ const createSourceParams = createParamForCreateSource(srcPath)
41
+ createSourceArray.push(createSourceParams)
42
+
43
+ // console.log("createSourceArrayInUpdateRelationshipHdrInv", createSourceArray)
44
+ return createSourceArray;
45
+ }
46
+
47
+
48
+ function createParamForCreateSource(srcPath) {
49
+ const functionName = "updateRelationship"
50
+ return {
51
+ templatePath: templatePath,
52
+ templateData: {
53
+ functionName: upperCase(functionName)
54
+ },
55
+ setting: {
56
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
57
+ saveFileName: `${upperCase(functionName)}_Main`,
58
+ fileExtension: '.js',
59
+ isAppend: false
60
+ }
61
+ }
62
+ }
63
+
64
+
65
+
66
+ // [
67
+ // {
68
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
69
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
70
+ // setting: {
71
+ // savePath: '/generatedCode/source/',
72
+ // saveFileName: 'ObjectTypeGet',
73
+ // fileExtension: '.js',
74
+ // isAppend: false
75
+ // }
76
+ // }
77
+ // ]
78
+
79
+
80
+ module.exports = data;
@@ -0,0 +1,324 @@
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
+ //(<inputParamFromHandler>)
75
+ //(</inputParamFromHandler>)
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
+ //(<additionalParam>)
91
+ //(</additionalParam>)
92
+ } = requestParams;
93
+
94
+ let errorsFound = [];
95
+
96
+ // validate object and identifiers
97
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
98
+
99
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
100
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
101
+
102
+ if (!objectSchema) {
103
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
104
+ }
105
+
106
+ for (const schemaIdentifier of objectSchema.identifiers) {
107
+ let identifierName = schemaIdentifier.fieldName || schemaIdentifier.name;
108
+
109
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
110
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
111
+ } else {
112
+ if (
113
+ typeof (identifiersObject[identifierName]) !== "string"
114
+ && typeof (identifiersObject[identifierName]) !== "number"
115
+ ) {
116
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ await validateIdentifiersExists(_izContext, objects[0].objType, objects[0].identifiers);
123
+ await validateIdentifiersExists(_izContext, objects[1].objType, objects[1].identifiers);
124
+ // finished validate object and identifiers
125
+
126
+
127
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
128
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
129
+
130
+ let targetStorageResources = [];
131
+
132
+ if (relationshipSchema) {
133
+ // find targetStorageResources and validate each storageResources
134
+ await Promise.all(
135
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
136
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
137
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
138
+
139
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = objects[0].objType;
140
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = objects[1].objType;
141
+
142
+ // find exists link
143
+ if (
144
+ (
145
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType)
146
+ && (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
147
+ )
148
+ ||
149
+ (
150
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType)
151
+ && (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
152
+ )
153
+ ) {
154
+
155
+ // check founded storageResource of link and collect used storageResources
156
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
157
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
158
+
159
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
160
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
161
+ if (!graphServiceTag) {
162
+ errorsFound.push(`storageResourceTag:${storageResourceTag} invalid, not found graph serviceTag from graphServerTag:${usedStorageResource.graphServerTag}`)
163
+ }
164
+
165
+ targetStorageResources.push({
166
+ ...usedStorageResource,
167
+ graphServiceTag: graphServiceTag
168
+ });
169
+ } else {
170
+ targetStorageResources.push(usedStorageResource);
171
+ }
172
+ }));
173
+ }
174
+ })
175
+ );
176
+
177
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
178
+
179
+ if (!targetStorageResources.length) {
180
+ errorsFound.push(`Not found link from relationship schema`);
181
+ }
182
+
183
+
184
+ // validate canUpdate properties relationship
185
+ for (const [propKey, propValue] of Object.entries(relationshipProperties)) {
186
+ _izContext.logger.debug("propKey: ", propKey);
187
+ _izContext.logger.debug("propValue: ", propValue);
188
+
189
+ if (relationshipSchema.properties[propKey]) {
190
+ if (relationshipSchema.properties[propKey].canUpdate !== true) {
191
+ errorsFound.push(`property:${propKey} cannot update`);
192
+ }
193
+ } else {
194
+ errorsFound.push(`property:${propKey} not exists in relationshipSchema`);
195
+ }
196
+ }
197
+
198
+ } else {
199
+ errorsFound.push(`relationshipSchema not exists`);
200
+ }
201
+
202
+
203
+ // if found errors will stop processing
204
+ if (errorsFound.length) {
205
+
206
+ let updateCompleteMsg = {
207
+ relId: relId,
208
+ relType: relType,
209
+ status: 'error',
210
+ errorFounds: errorsFound
211
+ //(<inUpdateCompleteMsg>)
212
+ //(</inUpdateCompleteMsg>)
213
+ };
214
+
215
+ // if have callingFlow will send to message complete
216
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
217
+ _izContext.logger.debug("HAVE CallingFlow");
218
+
219
+ updateCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, updateCompleteMsg);
220
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
221
+
222
+ let messageParams = {
223
+ Message: JSON.stringify(updateCompleteMsg),
224
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
225
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.outUpdateRelationshipComplete),
226
+ };
227
+
228
+ _izContext.logger.debug("messageParams OutUpdateRelationshipComplete ::::::: ", messageParams);
229
+ await sns.publishAsync(_izContext, messageParams);
230
+ }
231
+
232
+ return updateCompleteMsg;
233
+ }
234
+
235
+
236
+ // before create awaitingStepId per graph storageResource
237
+ const linkTypeId = createLinkTypeId(_izContext, [objects[0].objType, objects[1].objType], relType);
238
+
239
+ let usedGraphServiceTag = []; // collect used graph serviceName, use to check duplicate graph serviceName across graph serverTag
240
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
241
+ let awaitingStepIds = [];
242
+
243
+ for (const targetStorageResource of targetStorageResources) {
244
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph
245
+ && !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
246
+ ) {
247
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
248
+ targetGraphStorageResources.push(targetStorageResource);
249
+
250
+ // awaitingStepId per graphServiceTag
251
+ awaitingStepIds.push(
252
+ asyncFlowSharedLib.createAwaitingStepId(
253
+ hash({ linkTypeId, relId, relationshipProperties, graphServiceTag: targetStorageResource.graphServiceTag }), // hash id
254
+ PREFIX.updateRel // prefix, use constant further
255
+ )
256
+ );
257
+ }
258
+ }
259
+
260
+ if (awaitingStepIds.length) {
261
+ // save awaiting
262
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
263
+ _izContext,
264
+ awaitingStepIds, // awaitingStepIds
265
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
266
+ hash({ linkTypeId, relId, relationshipProperties, correlationId: _izContext.correlationIds.get("id") }), // hash id
267
+ PREFIX.updateRel // prefix, use constant further
268
+ )
269
+ );
270
+
271
+ // prepare message body
272
+ let updateRelMessageBody = {
273
+ objects: objects,
274
+ relId,
275
+ relType: relType,
276
+ relationshipProperties
277
+ //(<inUpdateRelMessageBody>)
278
+ //(</inUpdateRelMessageBody>)
279
+ }
280
+ _izContext.logger.debug('updateRelMessageBody: ', updateRelMessageBody);
281
+
282
+ await Promise.all(
283
+ targetGraphStorageResources.map(async (storageResource) => {
284
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
285
+
286
+ updateRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
287
+ updateRelMessageBody,
288
+ callingFlowSharedLib.addParentCallingFlowConfig(
289
+ callingFlowConfig, // receive parent callingFlowConfig.
290
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
291
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateRelComplete),
292
+ {
293
+ graphServiceTag: storageResource.graphServiceTag
294
+ }
295
+ )
296
+ )
297
+ );
298
+ _izContext.logger.debug("messageObject before send message:", updateRelMessageBody)
299
+
300
+ let messageToInUpdateRelationship = {
301
+ Message: JSON.stringify(updateRelMessageBody),
302
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inUpdateRel, storageResource.graphServiceTag),
303
+ };
304
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInUpdateRelationship);
305
+ await sns.publishAsync(_izContext, messageToInUpdateRelationship);
306
+ }
307
+ })
308
+ )
309
+
310
+ } else {
311
+ // if relationshipSchema stored in dynamoDB only will send message to outComplete
312
+ }
313
+
314
+ return {
315
+ relId: relId,
316
+ relType: relType,
317
+ errorFounds: errorsFound
318
+ };
319
+
320
+ } catch (err) {
321
+ _izContext.logger.error('error updateRelationship: ', err)
322
+ throw (err)
323
+ }
324
+ }