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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/index.js +2 -1
  2. package/package.json +9 -4
  3. package/src/GenerateCodeLibs/src/Consts.js +5 -2
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +6 -6
  5. package/src/MainLibs/src/Consts.js +45 -2
  6. package/src/TemplateManager/src/libs/Consts.js +0 -1
  7. package/src/reStructure/GenerateCode.js +23 -4
  8. package/src/reStructure/GenerateSchema.js +153 -0
  9. package/src/reStructure/SchemaConfig.js +29 -0
  10. package/src/reStructure/TemplateConfig.js +20 -0
  11. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +104 -0
  12. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/attributeLinkTemplate.ejs +21 -0
  13. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +188 -0
  14. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/request.json +11 -0
  15. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +3 -4
  16. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +1 -1
  17. package/src/reStructure/TemplateData/findData/handler/template.ejs +1 -1
  18. package/src/reStructure/TemplateData/findData/mainFunction/template.ejs +3 -3
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +3 -1
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/template.ejs +1 -14
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/template.ejs +2 -3
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +2 -3
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +4 -2
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +1 -14
  25. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +2 -3
  26. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +5 -6
  27. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +3 -1
  28. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/template.ejs +1 -14
  29. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/handler/template.ejs +1 -2
  30. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +3 -4
  31. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/data.js +3 -1
  32. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/template.ejs +1 -14
  33. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +2 -2
  34. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +3 -4
  35. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +3 -1
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +1 -14
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +2 -3
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -6
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +4 -2
  40. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/template.ejs +1 -14
  41. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/template.ejs +1 -1
  42. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +4 -5
  43. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +4 -2
  44. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js +2 -1
  45. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js +2 -1
  46. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +10 -0
  47. package/src/reStructure/TemplateData/perActionComplete/create/handler/template.ejs +2 -3
  48. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +4 -5
  49. package/src/reStructure/TemplateData/perActionComplete/delete/handler/template.ejs +2 -2
  50. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +4 -6
  51. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +1 -1
  52. package/src/reStructure/TemplateData/perActionComplete/get/handler/template.ejs +2 -3
  53. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +4 -6
  54. package/src/reStructure/TemplateData/perActionComplete/update/handler/template.ejs +2 -3
  55. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +4 -6
  56. package/src/reStructure/TemplateData/perActionComplete/update/sns-in-sqs/data.js +1 -1
  57. package/src/reStructure/TemplateData/perActionEndpoint/handler/api/template.ejs +1 -1
  58. package/src/reStructure/TemplateData/perActionEndpoint/handler/dsq/template.ejs +2 -2
  59. package/src/reStructure/TemplateData/perActionEndpoint/handler/inv/template.ejs +1 -3
  60. package/src/reStructure/TemplateData/perActionEndpoint/handler/sqs/template.ejs +2 -2
  61. package/src/reStructure/TemplateData/perActionEndpoint/handler/webSocket/template.ejs +3 -3
  62. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/create/template.ejs +6 -7
  63. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/delete/template.ejs +5 -4
  64. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/get/template.ejs +5 -6
  65. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/update/template.ejs +5 -6
  66. package/src/reStructure/TemplateData/processLogical/handler/template.ejs +1 -1
  67. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +5 -6
  68. package/src/reStructure/TemplateData/processLogicalPagination/handler/dsq/template.ejs +1 -1
  69. package/src/reStructure/TemplateData/processLogicalPagination/handler/sqs/template.ejs +1 -1
  70. package/src/reStructure/TemplateData/processLogicalPagination/mainFunction/template.ejs +6 -5
  71. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +27 -6
  72. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +25 -4
  73. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +26 -4
  74. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +26 -4
  75. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/api/template.ejs +1 -1
  76. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/dsq/template.ejs +2 -2
  77. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/inv/template.ejs +1 -1
  78. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/sqs/template.ejs +2 -2
  79. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +66 -18
  80. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -3
  81. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +5 -6
  82. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +25 -4
  83. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +25 -4
  84. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +25 -4
  85. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +26 -4
  86. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/api/template.ejs +1 -1
  87. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/dsq/template.ejs +2 -2
  88. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/inv/template.ejs +1 -1
  89. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/sqs/template.ejs +2 -2
  90. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +55 -5
  91. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +62 -6
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +119 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/template.ejs +20 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +131 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/template.ejs +17 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +119 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/template.ejs +13 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +131 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/template.ejs +17 -0
  100. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/data.js +57 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/request.json +0 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/template.ejs +138 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/data.js +58 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/request.json +0 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/template.ejs +183 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/data.js +59 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/request.json +0 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/template.ejs +125 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/data.js +59 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/request.json +0 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/template.ejs +163 -0
  112. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/data.js +59 -0
  113. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +322 -0
  114. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/data.js +77 -0
  115. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +59 -0
  116. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  117. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +110 -0
  118. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/request.json +0 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/template.ejs +20 -0
  120. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/data.js +60 -0
  121. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/request.json +0 -0
  122. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +125 -0
  123. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/data.js +55 -0
  124. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/request.json +0 -0
  125. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +141 -0
  126. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/data.js +71 -0
  127. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/request.json +0 -0
  128. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/template.ejs +47 -0
  129. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/data.js +71 -0
  130. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/request.json +0 -0
  131. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +10 -0
  132. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +25 -22
  133. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +25 -5
  134. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +26 -5
  135. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +25 -4
  136. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/api/template.ejs +1 -1
  137. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/dsq/template.ejs +2 -2
  138. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/inv/template.ejs +1 -1
  139. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/sqs/template.ejs +2 -2
  140. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +55 -7
  141. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +50 -42
  142. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +98 -0
  143. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +4 -5
  144. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -1
  145. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +11 -2
  146. package/src/reStructure/TemplateData/testTemplate/data.js +27 -0
  147. package/src/reStructure/TemplateData/testTemplate/template.ejs +5 -0
  148. package/src/reStructure/libs/GenerateCodeLibs.js +38 -0
@@ -0,0 +1,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
+
21
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/index.js").utils;
24
+ const {
25
+ createIamRole,
26
+ resourceNames,
27
+ RESOURCE_CLASSES,
28
+ SQS_RESOURCE,
29
+ SOURCE_PATH,
30
+ SAVE_FILE_NAME,
31
+ FUNCTION_NAME,
32
+ SNS_RESOURCE,
33
+ defaultIamRolePerAction,
34
+ awaitingMultipleStepsRole,
35
+ shortNameHandler,
36
+ SHORT_FUNCTION_NAME,
37
+ SOURCE_GENERATE_IAM_ROLE,
38
+ checkDynamoTypeRelationship,
39
+ createDynamoDbComponentByLinks,
40
+ DYNAMO_RESOURCE
41
+ } = require("../../../../../../../MainLibs/index.js").consts;
42
+
43
+ const templatePath = path.join(__dirname, './template.ejs')
44
+
45
+ /**
46
+ * receive objectSchema
47
+ * create data for updateRelationshipSchema
48
+ *
49
+ * @param {Object} objectSchema
50
+ * @return {{ templatePath, templateData, setting } }
51
+ */
52
+
53
+ function data(_izContext, allObjectRelationships, srcPath) {
54
+ let createSourceArray = [];
55
+ const createSourceParam = createParamForCreateSource(allObjectRelationships, srcPath);
56
+ createSourceArray.push(createSourceParam);
57
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
58
+ return createSourceArray
59
+ }
60
+
61
+
62
+ function createParamForCreateSource(allObjectRelationships, srcPath) {
63
+
64
+ let handlerType = HANDLER.hdrSqs
65
+ let functionName = FUNCTION_NAME.getRel
66
+ let additionalResourcePermission = defaultIamRolePerAction();
67
+
68
+ additionalResourcePermission.push(
69
+ // createIamRole(
70
+ // { [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
71
+ // [resourceNames(RESOURCE_CLASSES.lambda, "*GetNodeHdrInv")]),
72
+ createIamRole(
73
+ {
74
+ [RESOURCE_CLASSES.sqs]: [
75
+ SQS_RESOURCE.deleteMessage,
76
+ SQS_RESOURCE.getQueueAttributes,
77
+ SQS_RESOURCE.receiveMessage,
78
+ SQS_RESOURCE.sendMessage,
79
+ SQS_RESOURCE.getQueueUrl,
80
+ SQS_RESOURCE.deleteMessageBatch
81
+ ], [RESOURCE_CLASSES.sns]:
82
+ [SNS_RESOURCE.publish, SNS_RESOURCE.subscribe]
83
+ },
84
+ [
85
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
86
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs) + "DLQ"),
87
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
88
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
89
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(FUNCTION_NAME.getRelComplete))
90
+ ]
91
+ ),
92
+ )
93
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
94
+
95
+ for (const relationship of allObjectRelationships) {
96
+ let [relationshipTag, links] = checkDynamoTypeRelationship(relationship)
97
+ for (const link of links) {
98
+ let dynamoComponent = createDynamoDbComponentByLinks(link, relationshipTag)
99
+ additionalResourcePermission.push(
100
+ createIamRole(
101
+ {
102
+ [RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.updateItem]
103
+ },
104
+ [
105
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(dynamoComponent.tableNameFrom)),
106
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(dynamoComponent.tableNameTo))
107
+ ]
108
+ )
109
+ )
110
+ }
111
+ }
112
+ return {
113
+ templatePath: templatePath,
114
+ templateData: {
115
+ functionName,
116
+ handlerType,
117
+ additionalResourcePermission,
118
+ resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction,
119
+ functionNameConfig: upperCase(SHORT_FUNCTION_NAME.getRel) + upperCase(shortNameHandler(handlerType)),
120
+ roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole
121
+ },
122
+ setting: {
123
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
124
+ saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
125
+ fileExtension: '.yml',
126
+ isAppend: true
127
+ }
128
+ }
129
+ }
130
+
131
+ module.exports = data;
@@ -0,0 +1,17 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
8
+ batchSize: 10
9
+ role: <%- roleName %>Role
10
+ #<#<%- functionName %><%- handlerType %>IamRole#>
11
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
12
+ <%_ function firstLetterUpperCase(text){
13
+ return text.charAt(0).toUpperCase() + text.slice(1)
14
+ } _%>
15
+ <%_ function firstLetterLowerCase(str) {
16
+ return str.charAt(0).toLowerCase() + str.slice(1)
17
+ } _%>
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+
21
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/index.js").utils;
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../../MainLibs/index.js").consts;
25
+
26
+ const templatePath = path.join(__dirname, "./template.ejs")
27
+
28
+ /**
29
+ * receive objectSchema
30
+ * create data for hdrInv template
31
+ *
32
+ * @return {{ templatePath, templateData, setting } }
33
+ */
34
+ function data(_izContext, srcPath) {
35
+ const createSourceParams = createParamForCreateSource(srcPath)
36
+ return [createSourceParams];
37
+ }
38
+
39
+
40
+ function createParamForCreateSource(srcPath) {
41
+ let functionName = FUNCTION_NAME.getRel;
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ },
47
+ setting: {
48
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
49
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrApi),
50
+ fileExtension: '.js',
51
+ isAppend: false
52
+ }
53
+ }
54
+ }
55
+
56
+
57
+ module.exports = data;
@@ -0,0 +1,138 @@
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 izara = require("@izara_project/izara-middleware");
20
+ const middleware = izara.middlewareHandler;
21
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
22
+ const {
23
+ validateSchemaMiddleware
24
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
25
+
26
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
27
+ // validate event params in middleware before into function
28
+ let validatorSchema = {
29
+ type: "object",
30
+ required: ["firstObject", "secondObject", "relType", 'relId'],
31
+ properties: {
32
+ firstObject: {
33
+ type: "object",
34
+ required: ["objType", "identifiers"],
35
+ properties: {
36
+ objType: {
37
+ type: "object",
38
+ required: ["serviceTag", "objectType"],
39
+ properties: {
40
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
41
+ objectType: izara.validatorSchema.stringNotEmpty()
42
+ }
43
+ },
44
+ identifiers: {
45
+ type: "object",
46
+ minProperties: 1
47
+ }
48
+ }
49
+ },
50
+ secondObject: {
51
+ type: "object",
52
+ required: ["objType", "identifiers"],
53
+ properties: {
54
+ objType: {
55
+ type: "object",
56
+ required: ["serviceTag", "objectType"],
57
+ properties: {
58
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
59
+ objectType: izara.validatorSchema.stringNotEmpty()
60
+ }
61
+ },
62
+ identifiers: {
63
+ type: "object",
64
+ minProperties: 1
65
+ }
66
+ }
67
+ },
68
+ relType: {
69
+ type: "object",
70
+ required: ["relationshipTag", "serviceTag"],
71
+ properties: {
72
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
73
+ serviceTag: {
74
+ type: 'string',
75
+ pattern: "^[a-zA-Z0-9_-]+$",
76
+ enum: [process.env.iz_serviceTag]
77
+ },
78
+ }
79
+ },
80
+ relationshipDirection: {
81
+ type: "string",
82
+ default: ""
83
+ },
84
+ relId: {
85
+ type: 'string',
86
+ },
87
+ }
88
+ };
89
+
90
+
91
+
92
+ //(<globalVarible>
93
+ //</globalVarible>)
94
+
95
+ // validate event params in middleware before into main function
96
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
97
+ middleware.setValidatorSchema(validatorSchema)
98
+ // if need to validate authorizer or additional params , add code to hook tag below
99
+
100
+ //(<afterValidateWith>)
101
+ //(</afterValidateWith>)
102
+
103
+
104
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
105
+ event._izContext.logger.debug('Event:', event);
106
+ try {
107
+ // invoke LambdaFunction
108
+ let lambdaFunctionResponse = await <%- functionName %>.<%- functionName %>(
109
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
110
+ {
111
+ firstObject: event.firstObject,
112
+ secondObject: event.secondObject,
113
+ relType: event.relType,
114
+ relId: event.relId,
115
+ relationshipDirection: event.relationshipDirection,
116
+ },
117
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
118
+ );
119
+
120
+ // return error to client
121
+ if (lambdaFunctionResponse instanceof Error) {
122
+ return (izara.response.failure(lambdaFunctionResponse));
123
+ }
124
+
125
+ // return success to client
126
+ return (izara.response.success(lambdaFunctionResponse));
127
+
128
+ } catch (err) {
129
+ event._izContext.logger.error('Error, <%- functionName %>HdrApi: ', err);
130
+ return (izara.response.failure(err));
131
+ }
132
+ });
133
+ <%_ function firstLetterUpperCase(text) {
134
+ return text.charAt(0).toUpperCase() + text.slice(1)
135
+ } _%>
136
+ <%_ function firstLetterLowerCase(str) {
137
+ return str.charAt(0).toLowerCase() + str.slice(1)
138
+ } _%>
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+
21
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/index.js").utils;
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../../MainLibs/index.js").consts;
25
+
26
+ const templatePath = path.join(__dirname, "./template.ejs")
27
+
28
+ /**
29
+ * create data for hdrInv template
30
+ *
31
+ * @return {{ templatePath, templateData, setting } }
32
+ */
33
+ function data(_izContext, srcPath) {
34
+ const createSourceParams = createParamForCreateSource(srcPath)
35
+ return [createSourceParams];
36
+ }
37
+
38
+
39
+ function createParamForCreateSource(srcPath) {
40
+ let functionName = FUNCTION_NAME.getRel
41
+ let queueName = functionName + upperCase(HANDLER.hdrDsq)
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ queueName,
47
+ },
48
+ setting: {
49
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
50
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrDsq),
51
+ fileExtension: '.js',
52
+ isAppend: false
53
+ }
54
+ }
55
+ }
56
+
57
+
58
+ module.exports = data;
@@ -0,0 +1,183 @@
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 izara = require("@izara_project/izara-middleware");
21
+ const middleware = izara.middlewareHandler;
22
+
23
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
24
+
25
+ // const CorrelationIds = require('@izara_project/izara-core-library-correlation-ids')
26
+ // const IntegrationTestDetail = require('@izara_project/izara-core-library-integration-tests')
27
+ const Logger = require('@izara_project/izara-core-library-logger');
28
+ const recordHandlerSharedLib = require('@izara_project/izara-core-library-record-handler');
29
+
30
+
31
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
32
+ // validate event properties in body.Message of sqs event
33
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
34
+ {
35
+ type: "object",
36
+ required: ['body', 'messageAttributes'],
37
+ properties: {
38
+ body: {
39
+ type: 'object',
40
+ },
41
+ messageAttributes: {
42
+ type: 'object'
43
+ }
44
+ }
45
+ }
46
+ ));
47
+
48
+ // validate event params in middlewware before into function.
49
+ let validatorSchema = {
50
+ type: "object",
51
+ required: ["firstObject", "secondObject", "relType", 'relId'],
52
+ properties: {
53
+ firstObject: {
54
+ type: "object",
55
+ required: ["objType", "identifiers"],
56
+ properties: {
57
+ objType: {
58
+ type: "object",
59
+ required: ["serviceTag", "objectType"],
60
+ properties: {
61
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
62
+ objectType: izara.validatorSchema.stringNotEmpty()
63
+ }
64
+ },
65
+ identifiers: {
66
+ type: "object",
67
+ minProperties: 1
68
+ }
69
+ }
70
+ },
71
+ secondObject: {
72
+ type: "object",
73
+ required: ["objType", "identifiers"],
74
+ properties: {
75
+ objType: {
76
+ type: "object",
77
+ required: ["serviceTag", "objectType"],
78
+ properties: {
79
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
80
+ objectType: izara.validatorSchema.stringNotEmpty()
81
+ }
82
+ },
83
+ identifiers: {
84
+ type: "object",
85
+ minProperties: 1
86
+ }
87
+ }
88
+ },
89
+ relType: {
90
+ type: "object",
91
+ required: ["relationshipTag", "serviceTag"],
92
+ properties: {
93
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
94
+ serviceTag: {
95
+ type: 'string',
96
+ pattern: "^[a-zA-Z0-9_-]+$",
97
+ enum: [process.env.iz_serviceTag]
98
+ },
99
+ }
100
+ },
101
+ relationshipDirection: {
102
+ type: "string",
103
+ default: ""
104
+ },
105
+ relId: {
106
+ type: 'string',
107
+ },
108
+ }
109
+ };
110
+
111
+
112
+ //(<globalVarible>
113
+ //</globalVarible>)
114
+
115
+ // validate event params in middleware before into main function
116
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
117
+ // if need to validate authorizer or additional params , add code to hook tag below
118
+
119
+ //(<afterValidateWith>)
120
+ //(</afterValidateWith>)
121
+
122
+
123
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
124
+ Logger.debug('event:', event);
125
+ Logger.debug('context:', context);
126
+ try {
127
+
128
+ let recordPromises = []; // final return
129
+
130
+ // loop each record and send to mainFunction
131
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
132
+
133
+ // --- reforming record.body for Dsq request
134
+ record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
135
+ record._izContext.logger.debug('record LambdaFunctionHdrDsq after reform', record);
136
+
137
+ let passOnProperties = []
138
+
139
+ // --- validate message (and MessageAttributes)
140
+ await recordHandlerSharedLib.validateRecord(
141
+ record, // one record will send to mainFunction
142
+ "<%- queueName %>", // queue name that need to retry or send to dlq
143
+ validatorSchema, // schema for record.Message
144
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
145
+ );
146
+
147
+ // add argument (to invoke lambda) to passOnProperties[]
148
+ passOnProperties.push(record.body.Message)
149
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
150
+ //(<afterPutParamIntoMainFunction>)
151
+ //(</afterPutParamIntoMainFunction>)
152
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
153
+
154
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
155
+ let recordPromise = recordHandlerSharedLib.recordHandler(
156
+ record, // one record will send to mainFunction
157
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
158
+ "<%- queueName %>", // queue name that need to retry or send to dlq
159
+ passOnProperties, // all parameters that mainFunction needed.
160
+ );
161
+ record._izContext.logger.debug('after recordPromise in handler');
162
+ recordPromises.push(recordPromise); // push promise to recordPromises
163
+ })) //end record
164
+
165
+ Logger.debug('before Promise.all(recordPromises) in handler');
166
+ try {
167
+ await Promise.all(recordPromises); // await all promises
168
+ return event.Records // return all for local test
169
+ } catch {
170
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
171
+ }
172
+ Logger.debug('after Promise.all(recordPromises) in handler');
173
+ } catch (err) {
174
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
175
+ throw (err);
176
+ }
177
+ });
178
+ <%_ function firstLetterUpperCase(text) {
179
+ return text.charAt(0).toUpperCase() + text.slice(1)
180
+ } _%>
181
+ <%_ function firstLetterLowerCase(str) {
182
+ return str.charAt(0).toLowerCase() + str.slice(1)
183
+ } _%>
@@ -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
+
21
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/index.js").utils;
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../../MainLibs/index.js").consts;
25
+
26
+ const templatePath = path.join(__dirname, "./template.ejs")
27
+
28
+ /**
29
+ * receive objectSchema
30
+ * create data for hdrInv template
31
+ *
32
+ * @return {{ templatePath, templateData, setting } }
33
+ */
34
+ function data(_izContext, srcPath) {
35
+ const createSourceParams = createParamForCreateSource(srcPath)
36
+ return [createSourceParams];
37
+ }
38
+
39
+
40
+ function createParamForCreateSource(srcPath) {
41
+ let functionName = FUNCTION_NAME.getRel;
42
+ let handler = HANDLER.hdrInv
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ handler,
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;