@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,89 @@
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, SAVE_FILE_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 createDataForCreateSourceSnsOut(_izContext, objectSchema, srcPath) {
36
+ const createSourceArray = [];
37
+ for (const action of Object.values(ACTIONS)) {
38
+ if (objectSchema.overWriteHandlers[action]) {
39
+ for (const handler of objectSchema.overWriteHandlers[action]) {
40
+ const snsOut = {
41
+ queueName: createQueueName(_izContext, objectSchema, action, handler, srcPath)
42
+ }
43
+ snsOut.queueName && createSourceArray.push(snsOut)
44
+ }
45
+ } else {
46
+ for (const handler of DEFAULT_HANDLER_PER_ACTION[action]) {
47
+ const snsOut = {
48
+ queueName: createQueueName(_izContext, objectSchema, action, handler, srcPath)
49
+ }
50
+ snsOut.queueName && createSourceArray.push(snsOut)
51
+ }
52
+ }
53
+ }
54
+ console.log("createSourceArrayInCreateSourceSnsOut", createSourceArray)
55
+ return createSourceArray;
56
+ }
57
+
58
+ function createQueueName(_izContext, objectSchema, action, handler) {
59
+ let objectType = objectSchema.objectType
60
+ let queueName = upperCase(objectType) + upperCase(action) + upperCase(handler)
61
+ if (queueName.includes("HdrSqs")) {
62
+ queueName = upperCase(objectType) + upperCase(action)
63
+ } else
64
+ return
65
+ return queueName
66
+ }
67
+ function createSourceSnsOut(_izContext, objectSchema, srcPath) {
68
+ let resultsForCreateSnsOut = [];
69
+ const snsOutDataList = createDataForCreateSourceSnsOut(_izContext, objectSchema, srcPath);
70
+ for (let snsOutData of snsOutDataList) {
71
+ resultsForCreateSnsOut.push(
72
+ {
73
+ templatePath: templatePath,
74
+ templateData: snsOutData,
75
+ setting: {
76
+ initialData: 'Resources:\n',
77
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
78
+ saveFileName: SAVE_FILE_NAME.snsOutYaml,
79
+ fileExtension: '.yml',
80
+ isAppend: true
81
+ }
82
+ }
83
+ )
84
+ }
85
+ return resultsForCreateSnsOut
86
+ }
87
+
88
+
89
+ module.exports = createSourceSnsOut
@@ -0,0 +1,3 @@
1
+ {
2
+ "queueName": "string"
3
+ }
@@ -0,0 +1,10 @@
1
+ ##--------- [Create Topic Out]
2
+ Out<%- firstLetterUpperCase(queueName) %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message out"
6
+ TopicName: ${self:custom.iz_resourcePrefix}Out<%- firstLetterUpperCase(queueName) %>
7
+
8
+ <%_ function firstLetterUpperCase(text) {
9
+ return text.charAt(0).toUpperCase() + text.slice(1)
10
+ } _%>
@@ -0,0 +1,135 @@
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, "./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
+ let awaitingTable = ["AwaitingMultipleSteps", "AwaitingMultipleStepByPending"]
78
+ let handlerType = upperCase(HANDLER.hdrSqs);
79
+ let functionName = FUNCTION_NAME.updateRelComplete
80
+ let additionalResourcePermission = defaultIamRolePerAction();
81
+
82
+ additionalResourcePermission.push(
83
+
84
+ createIamRole(
85
+ {
86
+ [RESOURCE_CLASSES.sqs]: [
87
+ SQS_RESOURCE.deleteMessage,
88
+ SQS_RESOURCE.getQueueAttributes,
89
+ SQS_RESOURCE.receiveMessage,
90
+ SQS_RESOURCE.sendMessage,
91
+ SQS_RESOURCE.deleteMessageBatch,
92
+ SQS_RESOURCE.getQueueUrl,
93
+ ],
94
+ [RESOURCE_CLASSES.sns]: [
95
+ "Publish", "Subscribe"
96
+ ]
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)),
102
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName))
103
+ ],
104
+ ))
105
+ additionalResourcePermission.push(
106
+ createIamRole(
107
+ {
108
+ [RESOURCE_CLASSES.dynamoDbTable]: ["UpdateItem", "Query", "DeleteItem"]
109
+ },
110
+ awaitingTable.map(tableName =>
111
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
112
+ )
113
+ )
114
+ )
115
+ return {
116
+ templatePath: templatePath,
117
+ templateData: {
118
+ functionName,
119
+ handlerType,
120
+ additionalResourcePermission,
121
+ resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction
122
+ },
123
+ setting: {
124
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
125
+ saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
126
+ fileExtension: '.yml',
127
+ isAppend: true
128
+ }
129
+
130
+ }
131
+ }
132
+
133
+
134
+
135
+ module.exports = data;
@@ -0,0 +1,33 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionName) %>:
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
+ iamRoleStatements:
13
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
14
+ - Effect: <%- resourcePermission.effect %>
15
+ Action:
16
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
17
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
18
+ - <%- resourcePerAction %>:<%- permission %>
19
+ <%_}) _%>
20
+ <%_ }) _%>
21
+ Resource:
22
+ <%_ resourcePermission.resource.forEach(resource => { _%>
23
+ - <%- resource %>
24
+ <%_ }) _%>
25
+ <%_}) _%>
26
+ #<#<%- functionName %><%- handlerType %>IamRole#>
27
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
28
+ <%_ function firstLetterUpperCase(text){
29
+ return text.charAt(0).toUpperCase() + text.slice(1)
30
+ } _%>
31
+ <%_ function firstLetterLowerCase(str) {
32
+ return str.charAt(0).toLowerCase() + str.slice(1)
33
+ } _%>
@@ -0,0 +1,62 @@
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.updateRelComplete;
43
+ const handler = HANDLER.hdrSqs
44
+
45
+ return {
46
+ templatePath: templatePath,
47
+ templateData: {
48
+ functionName: upperCase(functionName),
49
+ queueName: upperCase(functionName) + upperCase(handler),
50
+ isCreateMainFunction: false
51
+ },
52
+ setting: {
53
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
54
+ saveFileName: `${upperCase(functionName)}_${upperCase(handler)}`,
55
+ fileExtension: '.js',
56
+ isAppend: false
57
+ }
58
+ }
59
+ }
60
+
61
+
62
+ module.exports = data;
@@ -0,0 +1,127 @@
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 AWS = require('aws-sdk');
21
+ // const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
22
+
23
+ const izara = require("@izara_project/izara-middleware");
24
+ const middleware = izara.middlewareHandler;
25
+ const izaraShared = require('@izara_project/izara-shared');
26
+ const recordHandlerSharedLib = izaraShared.recordHandlerSharedLib
27
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
28
+
29
+ const updateRelationshipComplete = require('./UpdateRelationshipComplete_Main');
30
+ const Logger = require('@izara_project/izara-core-library-logger');
31
+ // validate event properties in body.Message of sqs event
32
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
33
+ // set schema for record.body.Message
34
+ let perRecordsValidatorSchema = {
35
+ type: "object",
36
+ required: [
37
+ 'returnValue',
38
+ 'status',
39
+ 'errorsFound'
40
+ ],
41
+ properties: {
42
+ returnValue: {//validate from authorizer
43
+ type: 'object',
44
+ },
45
+ status: {
46
+ type: 'string',
47
+ },
48
+ errorsFound: {
49
+ type: 'array',
50
+ default: []
51
+ }
52
+ }
53
+ };
54
+
55
+ // set schema for record.body.MessageAttributes
56
+ // const messageAttributeValidatorSchema = {
57
+ // type: "object",
58
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
59
+ // properties: {
60
+ // msgAtrrParam1: {
61
+ // type: "string"
62
+ // },
63
+ // msgAtrrParam2: {
64
+ // type: "object"
65
+ // }
66
+ // }
67
+ // };
68
+
69
+ perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema); // is Ok passBackProperties
70
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
71
+
72
+ try {
73
+
74
+ let recordPromises = [];
75
+
76
+ // loop each record and send to mainFunction
77
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
78
+
79
+ let passOnProperties = []
80
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
81
+
82
+ //validate message (and MessageAttributes)
83
+ await recordHandlerSharedLib.validateRecord(
84
+ record, // one record will send to mainFunction
85
+ "UpdateRelationshipComplete", // queue name that need to retry or send to dlq
86
+ perRecordsValidatorSchema, // schema for record.Message
87
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
88
+ );
89
+
90
+ // add argument (to invoke lambda) to passOnProperties[]
91
+ passOnProperties.push(record.body.Message.returnValue)
92
+ passOnProperties.push(record.body.Message.status)
93
+ passOnProperties.push(record.body.Message.errorsFound)
94
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
95
+ // passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callinfFlow
96
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
97
+ //(<afterSendParamToMainFunction>)
98
+ //(</afterSendParamToMainFunction>)
99
+
100
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
101
+ let recordPromise = recordHandlerSharedLib.recordHandler(
102
+ record, // one record will send to mainFunction
103
+ updateRelationshipComplete.updateRelationshipComplete, // mainFunction that need to invoke.
104
+ "UpdateRelationshipComplete", // queue name that need to retry or send to dlq
105
+ passOnProperties, // all parameters that mainFunction needed.
106
+ );
107
+ record._izContext.logger.debug('after recordPromise in handler');
108
+ recordPromises.push(recordPromise); // push promise to recordPromises
109
+ }))
110
+
111
+ Logger.debug('before Promise.all(recordPromises) in handler');
112
+ try {
113
+ // --- main await all promises
114
+ await Promise.all(recordPromises); // await all promises
115
+
116
+ return event.Records // return all for local testing
117
+
118
+ } catch {
119
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
120
+ }
121
+ Logger.debug('after Promise.all(recordPromises) in handler');
122
+
123
+ } catch (err) {
124
+ Logger.error('Unhandled Error, UpdateRelationshipCompleteHdrSqs: ', err);
125
+ throw (err);
126
+ }
127
+ });
@@ -0,0 +1,56 @@
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.updateRelComplete;
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ },
47
+ setting: {
48
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
49
+ saveFileName: `${upperCase(functionName)}_Main`,
50
+ fileExtension: '.js',
51
+ isAppend: false
52
+ }
53
+ }
54
+ }
55
+
56
+ module.exports = data;
@@ -0,0 +1,140 @@
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 hash = require("object-hash");
20
+
21
+ const izaraShared = require('@izara_project/izara-shared');
22
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
23
+ const configSharedLib = izaraShared.configSharedLib;
24
+ const snsSharedLib = izaraShared.snsSharedLib;
25
+ const asyncFlowSharedLib = izaraShared.asyncFlowSharedLib;
26
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
27
+
28
+ const sns = require("@izara_project/izara-core-library-external-request").sns;
29
+ const NoRetryError = require("@izara_project/izara-core-library-core/src/NoRetryError");
30
+
31
+ const { explodedObjectTypeId, explodedRelationshipTypeId, createLinkTypeId } = require('@izara_project/izara-core-library-service-schemas/src/Utils')
32
+
33
+ const {
34
+ PREFIX,
35
+ TOPIC_NAME_GRAPH_HANDLER,
36
+ TOPIC_NAME_GENERATE_CODE
37
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
38
+
39
+ module.exports.updateRelationshipComplete = async (
40
+ _izContext,
41
+ returnValue,
42
+ status,
43
+ errorsFound,
44
+ passBackProperties = {},
45
+ // callingFlowConfig = {}
46
+ ) => {
47
+ try {
48
+ _izContext.logger.debug("Function:updateRelationshipComplete", {
49
+ returnValue: returnValue,
50
+ status: status,
51
+ errorsFound: errorsFound,
52
+ passBackProperties: passBackProperties,
53
+ // callingFlowConfig: callingFlowConfig
54
+ });
55
+
56
+
57
+ // start create awaitingStepId
58
+ const linkTypeId = createLinkTypeId(
59
+ _izContext,
60
+ [
61
+ returnValue.objects[0].objType,
62
+ returnValue.objects[1].objType,
63
+ ],
64
+ returnValue.relType
65
+ );
66
+
67
+ let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
68
+ hash({
69
+ linkTypeId,
70
+ relId: returnValue.relId,
71
+ relationshipProperties: returnValue.updatePropertiesParam,
72
+ graphServiceTag: passBackProperties.passBackProperties.graphServiceTag
73
+ }), // hash id
74
+ PREFIX.updateRel // prefix, use constant further
75
+ )
76
+
77
+
78
+ let updateRelPendingObjects = await dynamodbSharedLib.query(
79
+ _izContext,
80
+ await dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
81
+ {
82
+ awaitingStepId: awaitingStepId
83
+ }
84
+ );
85
+ _izContext.logger.debug("record of updateRelPendingObjects ::", updateRelPendingObjects);
86
+
87
+
88
+
89
+ await Promise.all(
90
+ updateRelPendingObjects.Items.map(async ({ pendingStepId }) => {
91
+ if (await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
92
+ _izContext,
93
+ pendingStepId, // task waiting
94
+ awaitingStepId
95
+ )) {
96
+ _izContext.logger.debug("finished all awaitingStep");
97
+
98
+ let updateCompleteMsg = {
99
+ relId: returnValue.relId,
100
+ relType: returnValue.relType,
101
+ status: status,
102
+ errorFounds: errorsFound
103
+ //(<inUpdateCompleteMsg>)
104
+ //(</inUpdateCompleteMsg>)
105
+ };
106
+
107
+ updateCompleteMsg = callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(passBackProperties, updateCompleteMsg);
108
+ _izContext.logger.debug("After addCallingFlowToSnsResponseMessageObject", updateCompleteMsg);
109
+
110
+ let messageAttributes = callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(passBackProperties, {});
111
+ _izContext.logger.debug("After addCallingFlowToSnsResponseMessageAttributes", updateCompleteMsg);
112
+
113
+ let sendMessageToOutUpdateRelatonshipComplete = {
114
+ Message: JSON.stringify(updateCompleteMsg),
115
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
116
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateRelComplete)
117
+ };
118
+ _izContext.logger.debug("Send message to OutUpdateRelationshipComplete :::>", sendMessageToOutUpdateRelatonshipComplete);
119
+ await sns.publishAsync(_izContext, sendMessageToOutUpdateRelatonshipComplete);
120
+
121
+
122
+ // remove awaitingMultipleStep after finished
123
+ await asyncFlowSharedLib.removeAwaitingMultipleStep(
124
+ _izContext,
125
+ awaitingStepId,
126
+ pendingStepId,
127
+ );
128
+
129
+ } // check pendingStepId finished
130
+ }) // end per pendingStep
131
+ );
132
+
133
+
134
+ return { returnValue: 'function:updateRelationshipComplete' };
135
+
136
+ } catch (err) {
137
+ _izContext.logger.error('error updateRelationshipComplete:', err)
138
+ throw (err)
139
+ }
140
+ }