@izara_project/izara-market-library-service-schemas 1.0.65 → 1.0.66

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 (128) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +7 -2
  3. package/src/MainLibs/src/Consts.js +30 -24
  4. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +4 -4
  5. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +1 -1
  6. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +3 -1
  7. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +14 -0
  8. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +1 -1
  9. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +1 -1
  10. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +1 -1
  11. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +1 -1
  12. package/src/reStructure/TemplateData/processLogical/yaml/data.js +2 -2
  13. package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +1 -1
  14. package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +1 -1
  15. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/data.js +1 -1
  16. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/data.js +132 -0
  17. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/data.js +1 -1
  18. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/data.js +1 -1
  19. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/data.js +1 -1
  20. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/template.ejs +9 -0
  21. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  22. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  23. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  24. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  25. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/data.js +73 -0
  26. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/template.ejs +9 -0
  27. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  28. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  29. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/invTemplate.ejs +144 -0
  30. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  31. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +11 -11
  32. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/data.js +1 -1
  33. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +1 -1
  34. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/data.js +151 -0
  35. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +2 -2
  36. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +2 -2
  37. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +2 -2
  38. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/template.ejs +9 -0
  39. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  40. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  41. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  42. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  43. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/data.js +73 -0
  44. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/template.ejs +9 -0
  45. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  46. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  47. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/invTemplate.ejs +144 -0
  48. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  49. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +1 -1
  50. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +1 -1
  51. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/data.js +151 -0
  52. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +2 -2
  53. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +2 -2
  54. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +1 -1
  55. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/template.ejs +9 -0
  56. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  57. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  58. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  59. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  60. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/data.js +73 -0
  61. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/template.ejs +9 -0
  62. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  63. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  64. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/invTemplate.ejs +144 -0
  65. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  66. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +1 -1
  67. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +131 -88
  68. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +2 -2
  69. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/data.js +151 -0
  70. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +2 -2
  71. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +2 -2
  72. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +1 -1
  73. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/template.ejs +9 -0
  74. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  75. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  76. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  77. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  78. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/data.js +73 -0
  79. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/template.ejs +9 -0
  80. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  81. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  82. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/invTemplate.ejs +144 -0
  83. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +1 -1
  85. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/data.js +153 -0
  86. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/template.ejs +9 -0
  87. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  88. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  89. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  90. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  91. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/data.js +73 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/template.ejs +9 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/apiTemplate.ejs +172 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/dsqTemplate.ejs +218 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/invTemplate.ejs +161 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/sqsTemplate.ejs +197 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/data.js +59 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/template.ejs +386 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/data.js +77 -0
  100. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/snsTemplate.ejs +59 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/functionYaml/data.js +121 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/functionYaml/template.ejs +20 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/handler/sqs/data.js +60 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/handler/sqs/template.ejs +129 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/mainFunction/data.js +56 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/mainFunction/template.ejs +159 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-in-sqs/data.js +71 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-in-sqs/template.ejs +46 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-out/data.js +71 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-out/template.ejs +10 -0
  112. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +2 -2
  113. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/data.js +154 -0
  114. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +2 -2
  115. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +2 -2
  116. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +1 -1
  117. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/template.ejs +9 -0
  118. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  120. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  121. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  122. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/data.js +73 -0
  123. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/template.ejs +9 -0
  124. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  125. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  126. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/invTemplate.ejs +144 -0
  127. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  128. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +1 -1
@@ -0,0 +1,181 @@
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
+ const Logger = require('@izara_project/izara-core-library-logger');
26
+ const recordHandlerSharedLib = require('@izara_project/izara-core-library-record-handler');
27
+
28
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
29
+
30
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
31
+
32
+ // validate event params in middleware before into function
33
+ let validatorSchema = {
34
+ type: "object",
35
+ required: [
36
+ 'firstObject',
37
+ 'secondObject',
38
+ 'oldReltypeAndDirection',
39
+ 'newRelType',
40
+ ],
41
+ properties: {
42
+ firstObject: {
43
+ type: 'object',
44
+ required: ['objType', 'identifiers'],
45
+ properties: {
46
+ objType: {
47
+ type: 'object',
48
+ required: ['objectType', 'serviceTag'],
49
+ properties: {
50
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
51
+ objectType: izara.validatorSchema.stringNotEmpty(),
52
+ }
53
+ },
54
+ identifiers: {
55
+ type: "object",
56
+ minProperties: 1
57
+ },
58
+ }
59
+ },
60
+ secondObject: {
61
+ type: 'object',
62
+ required: ['objType', 'identifiers'],
63
+ properties: {
64
+ objType: {
65
+ type: 'object',
66
+ required: ['objectType', 'serviceTag'],
67
+ properties: {
68
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
69
+ objectType: izara.validatorSchema.stringNotEmpty(),
70
+ }
71
+ },
72
+ identifiers: {
73
+ type: "object",
74
+ minProperties: 1
75
+ },
76
+ }
77
+ },
78
+ oldReltypeAndDirection: {
79
+ type: 'object',
80
+ required: ['relType', 'relationshipDirection'],
81
+ properties: {
82
+ relType: {
83
+ type: 'object',
84
+ required: ['serviceTag', 'relationshipTag'],
85
+ properties: {
86
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
87
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
88
+ }
89
+ },
90
+ relationshipProperties: {
91
+ type: 'object',
92
+ },
93
+ relationshipDirection: {
94
+ type: 'string',
95
+ enum: ['from', 'to']
96
+
97
+ },
98
+ }
99
+ },
100
+ newRelType: {
101
+ type: 'object',
102
+ required: ['serviceTag', 'relationshipTag'],
103
+ properties: {
104
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
105
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
106
+ }
107
+ },
108
+ settings: {
109
+ type: 'object'
110
+ }
111
+ }
112
+ };
113
+
114
+
115
+ //(<globalVariable>
116
+ //</globalVariable>)
117
+
118
+ // validate event params in middleware before into main function
119
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
120
+ // if need to validate authorizer or additional params , add code to hook tag below
121
+
122
+ //(<afterValidateWith>)
123
+ //(</afterValidateWith>)
124
+
125
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
126
+
127
+ try {
128
+
129
+ let recordPromises = []; // final return
130
+
131
+ // loop each record and send to mainFunction
132
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
133
+
134
+ let passOnProperties = []
135
+
136
+ // --- validate message (and MessageAttributes)
137
+ await recordHandlerSharedLib.validateRecord(
138
+ record, // one record will send to mainFunction
139
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
140
+ validatorSchema, // schema for record.Message
141
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
142
+ );
143
+
144
+ // add argument (to invoke lambda) to passOnProperties[]
145
+ passOnProperties.push(record.body.Message)
146
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
147
+ //(<afterPutParamIntoMainFunction>)
148
+ //(</afterPutParamIntoMainFunction>)
149
+
150
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
151
+
152
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
153
+ let recordPromise = recordHandlerSharedLib.recordHandler(
154
+ record, // one record will send to mainFunction
155
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
156
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
157
+ passOnProperties, // all parameters that mainFunction needed.
158
+ );
159
+ record._izContext.logger.debug('after recordPromise in handler');
160
+ recordPromises.push(recordPromise); // push promise to recordPromises
161
+ })) //end record
162
+
163
+ Logger.debug('before Promise.all(recordPromises) in handler');
164
+ try {
165
+ await Promise.all(recordPromises); // await all promises
166
+ return event.Records // return all for local test
167
+ } catch {
168
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
169
+ }
170
+ Logger.debug('after Promise.all(recordPromises) in handler');
171
+ } catch (err) {
172
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
173
+ throw (err);
174
+ }
175
+ });
176
+ <%_ function firstLetterUpperCase(text) {
177
+ return text.charAt(0).toUpperCase() + text.slice(1)
178
+ } _%>
179
+ <%_ function firstLetterLowerCase(str) {
180
+ return str.charAt(0).toLowerCase() + str.slice(1)
181
+ } _%>
@@ -101,7 +101,7 @@ function createParamForCreateSource(srcPath) {
101
101
  handlerType,
102
102
  additionalResourcePermission,
103
103
  resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction,
104
- functionNameConfig: upperCase(SHORT_FUNCTION_NAME.getRelComplete),
104
+ functionNameConfig: upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.getRelComplete)),
105
105
  roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole
106
106
  },
107
107
  setting: {
@@ -0,0 +1,153 @@
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, getLocalConfig } = require("../../../../../../MainLibs/src/Utils.js");
24
+ const {
25
+ createIamRole,
26
+ resourceNames,
27
+ RESOURCE_CLASSES,
28
+ SOURCE_PATH,
29
+ SAVE_FILE_NAME,
30
+ FUNCTION_NAME,
31
+ SNS_RESOURCE,
32
+ defaultIamRolePerAction,
33
+ awaitingMultipleStepsRole,
34
+ shortNameHandler,
35
+ SHORT_FUNCTION_NAME,
36
+ SOURCE_GENERATE_IAM_ROLE,
37
+ checkDynamoTypeRelationship,
38
+ createDynamoDbComponentByLinks,
39
+ DYNAMO_RESOURCE,
40
+ SQS_RESOURCE
41
+ } = require("../../../../../../MainLibs/src/Consts.js");
42
+ const templatePath = path.join(__dirname, "./template.ejs")
43
+
44
+ const apiTemplate = path.join(__dirname, "././templateByHandler/apiTemplate.ejs")
45
+ const dsqTemplate = path.join(__dirname, "././templateByHandler/dsqTemplate.ejs")
46
+ const invTemplate = path.join(__dirname, "././templateByHandler/invTemplate.ejs")
47
+ const sqsTemplate = path.join(__dirname, "././templateByHandler/sqsTemplate.ejs")
48
+
49
+ /**
50
+ * receive objectSchema
51
+ * create data for updateRelationshipSchema
52
+ *
53
+ * @param {Object} objectSchema
54
+ * @return {{ templatePath, templateData, setting } }
55
+ */
56
+
57
+ function data(_izContext, allObjectRelationships, srcPath) {
58
+ let createSourceArray = [];
59
+ for (const handlerType of Object.values(HANDLER)) {
60
+ const createSourceParam = createParamForCreateSource(allObjectRelationships, handlerType, srcPath);
61
+ createSourceArray.push(createSourceParam);
62
+ }
63
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
64
+ return createSourceArray
65
+ }
66
+
67
+
68
+ function createParamForCreateSource(allObjectRelationships, handlerType, srcPath) {
69
+
70
+ let functionName = upperCase(FUNCTION_NAME.changeRel)
71
+ let additionalResourcePermission = defaultIamRolePerAction();
72
+
73
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
74
+
75
+ additionalResourcePermission.push(
76
+ createIamRole(
77
+ {
78
+ [RESOURCE_CLASSES.sqs]: [
79
+ SQS_RESOURCE.deleteMessage,
80
+ SQS_RESOURCE.getQueueAttributes,
81
+ SQS_RESOURCE.receiveMessage,
82
+ SQS_RESOURCE.sendMessage,
83
+ SQS_RESOURCE.getQueueUrl,
84
+ SQS_RESOURCE.deleteMessageBatch
85
+ ],
86
+ },
87
+ [
88
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType)),
89
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType) + "DLQ"),
90
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType)),
91
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType) + "DLQ"),
92
+ ]
93
+ ),
94
+ createIamRole(
95
+ {
96
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish, SNS_RESOURCE.subscribe]
97
+ },
98
+ [
99
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.moveRelComplete) + "_Out"),
100
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(functionName) + "_In"),
101
+ resourceNames(RESOURCE_CLASSES.sns, upperCase(functionName) + "_Out"),
102
+ ]
103
+ )
104
+ )
105
+
106
+ for (const relationship of allObjectRelationships) {
107
+ let [storageType, relationshipTag, links] = checkDynamoTypeRelationship(relationship)
108
+ if (storageType === STORAGE_TYPES.dynamoDB) {
109
+ for (const link of links) {
110
+ let dynamoComponent = createDynamoDbComponentByLinks(link, relationshipTag)
111
+ additionalResourcePermission.push(
112
+ createIamRole(
113
+ {
114
+ [RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.getItem]
115
+ },
116
+ [
117
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(dynamoComponent.tableNameFrom)),
118
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(dynamoComponent.tableNameTo))
119
+ ]
120
+ )
121
+ )
122
+ }
123
+ }
124
+ }
125
+
126
+
127
+
128
+ return {
129
+ templatePath: templatePath,
130
+ templateData: {
131
+ functionName,
132
+ handlerType,
133
+ additionalResourcePermission,
134
+ resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction,
135
+ functionNameConfig: upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.moveRel)) + upperCase(shortNameHandler(handlerType)),
136
+ roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole,
137
+ serviceTag: getLocalConfig(path.join(srcPath, "../"), "iz_serviceTag"),
138
+ apiTemplate,
139
+ dsqTemplate,
140
+ invTemplate,
141
+ sqsTemplate
142
+ },
143
+ setting: {
144
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
145
+ saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
146
+ fileExtension: '.yml',
147
+ isAppend: true
148
+ }
149
+
150
+ }
151
+ }
152
+
153
+ module.exports = data;
@@ -0,0 +1,9 @@
1
+ <% if (handlerType === "hdrApi") { %>
2
+ <%- include(apiTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName, serviceTag } %>
3
+ <% } else if (handlerType === "hdrDsq") { %>
4
+ <%- include(dsqTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
5
+ <% } else if (handlerType === "hdrInv") { %>
6
+ <%- include(invTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
7
+ <% } else if (handlerType === "hdrSqs") { %>
8
+ <%- include(sqsTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
9
+ <% } %>
@@ -0,0 +1,20 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - http:
7
+ path: /<%- serviceTag %>/<%- firstLetterLowerCase(functionName) %>/<%- functionName %>/
8
+ method: put
9
+ cors: true
10
+ #<#Authorizer#>
11
+ #<#/Authorizer#>
12
+ role: <%- roleName %>Role
13
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>IamRole#>
14
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>IamRole#>
15
+ <%_ function firstLetterUpperCase(text){
16
+ return text.charAt(0).toUpperCase() + text.slice(1)
17
+ } _%>
18
+ <%_ function firstLetterLowerCase(str) {
19
+ return str.charAt(0).toLowerCase() + str.slice(1)
20
+ } _%>
@@ -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 %><%- firstLetterUpperCase(handlerType) %>IamRole#>
11
+ #<#/<%- functionName %><%- firstLetterUpperCase(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,13 @@
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
+ role: <%- roleName %>Role
6
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>IamRole#>
7
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>IamRole#>
8
+ <%_ function firstLetterUpperCase(text){
9
+ return text.charAt(0).toUpperCase() + text.slice(1)
10
+ } _%>
11
+ <%_ function firstLetterLowerCase(str) {
12
+ return str.charAt(0).toLowerCase() + str.slice(1)
13
+ } _%>
@@ -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 %><%- firstLetterUpperCase(handlerType) %>IamRole#>
11
+ #<#/<%- functionName %><%- firstLetterUpperCase(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,73 @@
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/src/Utils.js");
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts.js");
25
+
26
+ const templatePath = path.join(__dirname, "./template.ejs")
27
+ const apiTemplate = path.join(__dirname, "./templateByHandler/apiTemplate.ejs")
28
+ const dsqTemplate = path.join(__dirname, "./templateByHandler/dsqTemplate.ejs")
29
+ const invTemplate = path.join(__dirname, "./templateByHandler/invTemplate.ejs")
30
+ const sqsTemplate = path.join(__dirname, "./templateByHandler/sqsTemplate.ejs")
31
+
32
+
33
+ /**
34
+ * receive objectSchema
35
+ * create data for hdrInv template
36
+ *
37
+ * @return {{ templatePath, templateData, setting } }
38
+ */
39
+ function data(_izContext, srcPath) {
40
+ const createSourceParams = [];
41
+ for (const handler of Object.values(HANDLER)) {
42
+ const createSourceParam = createParamForCreateSource(handler, srcPath)
43
+ createSourceParams.push(createSourceParam)
44
+ }
45
+ return createSourceParams
46
+ }
47
+
48
+
49
+ function createParamForCreateSource(handler, srcPath) {
50
+ let functionName = FUNCTION_NAME.moveRel;
51
+ let queueName = functionName + upperCase(handler)
52
+ return {
53
+ templatePath: templatePath,
54
+ templateData: {
55
+ functionName,
56
+ queueName,
57
+ apiTemplate,
58
+ dsqTemplate,
59
+ invTemplate,
60
+ sqsTemplate,
61
+ handler
62
+ },
63
+ setting: {
64
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
65
+ saveFileName: upperCase(functionName) + "_" + upperCase(handler),
66
+ fileExtension: '.js',
67
+ isAppend: false
68
+ }
69
+ }
70
+ }
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,9 @@
1
+ <% if (handler === "hdrApi") { %>
2
+ <%- include(apiTemplate),{ functionName } %>
3
+ <% } else if (handler === "hdrDsq") { %>
4
+ <%- include(dsqTemplate), { functionName, queueName } %>
5
+ <% } else if (handler === "hdrInv") { %>
6
+ <%- include(invTemplate), { functionName} %>
7
+ <% } else if (handler === "hdrSqs") { %>
8
+ <%- include(sqsTemplate),{ functionName, queueName } %>
9
+ <% } %>
@@ -0,0 +1,172 @@
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: [
31
+ 'firstObject',
32
+ 'secondObject',
33
+ 'relType',
34
+ 'relationshipProperty',
35
+ 'relationshipDirection',
36
+ 'moveObject'
37
+ ],
38
+ properties: {
39
+ firstObject: {
40
+ type: 'object',
41
+ required: ['objType', 'identifiers'],
42
+ properties: {
43
+ objType: {
44
+ type: 'object',
45
+ required: ['objectType', 'serviceTag'],
46
+ properties: {
47
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
48
+ objectType: izara.validatorSchema.stringNotEmpty(),
49
+ }
50
+ },
51
+ identifiers: {
52
+ type: "object",
53
+ minProperties: 1
54
+ },
55
+ }
56
+ },
57
+ secondObject: {
58
+ type: 'object',
59
+ required: ['objType', 'identifiers'],
60
+ properties: {
61
+ objType: {
62
+ type: 'object',
63
+ required: ['objectType', 'serviceTag'],
64
+ properties: {
65
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
66
+ objectType: izara.validatorSchema.stringNotEmpty()
67
+ }
68
+ },
69
+ identifiers: {
70
+ type: "object",
71
+ minProperties: 1
72
+ },
73
+ }
74
+ },
75
+ relType: {
76
+ type: "object",
77
+ required: ['serviceTag','relationshipTag'],
78
+ properties: {
79
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
80
+ relationshipTag: izara.validatorSchema.stringNotEmpty()
81
+ }
82
+ },
83
+ relationshipDirection: {
84
+ type: "string",
85
+ enum: ['from','to']
86
+ },
87
+ relationshipProperty: {
88
+ type: "object",
89
+ minProperties: 1
90
+ },
91
+ moveObject: {
92
+ type: "object",
93
+ required: ['fromObjectRef','toObject'],
94
+ properties: {
95
+ fromObjectRef: {
96
+ type: 'string',
97
+ enum: ['firstObject','secondObject']
98
+ },
99
+ toObject: {
100
+ type: 'object',
101
+ required: ['objType', 'identifiers'],
102
+ properties: {
103
+ objType: {
104
+ type: 'object',
105
+ required: ['objectType', 'serviceTag'],
106
+ properties: {
107
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
108
+ objectType: izara.validatorSchema.stringNotEmpty()
109
+ }
110
+ },
111
+ identifiers: {
112
+ type: 'object',
113
+ minProperties: 1
114
+ }
115
+ }
116
+ }
117
+ }
118
+ },
119
+ settings: {
120
+ type: 'object'
121
+ }
122
+ }
123
+ };
124
+
125
+ //(<globalVariable>
126
+ //</globalVariable>)
127
+
128
+ // validate event params in middleware before into main function
129
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
130
+ middleware.setValidatorSchema(validatorSchema)
131
+ // if need to validate authorizer or additional params , add code to hook tag below
132
+
133
+ //(<afterValidateWith>)
134
+ //(</afterValidateWith>)
135
+
136
+
137
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
138
+ event._izContext.logger.debug('Event:', event);
139
+ try {
140
+ // invoke LambdaFunction
141
+ let lambdaFunctionResponse = await <%- functionName %>.<%- functionName %>(
142
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
143
+ {
144
+ firstObject: event.firstObject,
145
+ secondObject: event.secondObject,
146
+ relType: event.relType,
147
+ relationshipDirection: event.relationshipDirection,
148
+ relationshipProperties: event.relationshipProperties,
149
+ moveObject: event.moveObject
150
+ },
151
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
152
+ );
153
+
154
+ // return error to client
155
+ if (lambdaFunctionResponse instanceof Error) {
156
+ return (izara.response.failure(lambdaFunctionResponse));
157
+ }
158
+
159
+ // return success to client
160
+ return (izara.response.success(lambdaFunctionResponse));
161
+
162
+ } catch (err) {
163
+ event._izContext.logger.error('Error, <%- functionName %>HdrApi: ', err);
164
+ return (izara.response.failure(err));
165
+ }
166
+ });
167
+ <%_ function firstLetterUpperCase(text) {
168
+ return text.charAt(0).toUpperCase() + text.slice(1)
169
+ } _%>
170
+ <%_ function firstLetterLowerCase(str) {
171
+ return str.charAt(0).toLowerCase() + str.slice(1)
172
+ } _%>