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

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 (146) hide show
  1. package/package.json +3 -3
  2. package/src/GenerateCodeLibs/src/Consts.js +7 -2
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +11 -1
  4. package/src/MainLibs/src/Consts.js +64 -25
  5. package/src/MainLibs/src/GenerateCodeUtils.js +6 -6
  6. package/src/reStructure/GenerateCode.js +2 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/generateTemplateData.js +1 -1
  8. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -4
  9. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +49 -5
  10. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +3 -0
  11. package/src/reStructure/TemplateData/findData/findDataYaml/data.js +2 -2
  12. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +1 -1
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +3 -1
  14. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +14 -0
  15. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +2 -2
  16. package/src/reStructure/TemplateData/flowSchema/flowStep/functionYaml/data.js +3 -3
  17. package/src/reStructure/TemplateData/flowSchema/flowStep/handler/data.js +1 -1
  18. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/data.js +4 -2
  19. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/template.ejs +9 -9
  20. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +24 -24
  21. package/src/reStructure/TemplateData/generateRole/data.js +38 -24
  22. package/src/reStructure/TemplateData/generateRole/template.ejs +5 -7
  23. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +1 -1
  24. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +1 -1
  25. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +1 -1
  26. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +1 -1
  27. package/src/reStructure/TemplateData/processLogical/yaml/data.js +4 -4
  28. package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +2 -2
  29. package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +2 -2
  30. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/data.js +1 -1
  31. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/data.js +136 -0
  32. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/data.js +1 -1
  33. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/data.js +1 -1
  34. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/data.js +1 -1
  35. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/template.ejs +9 -0
  36. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  37. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  38. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  39. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  40. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/data.js +73 -0
  41. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/template.ejs +9 -0
  42. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  43. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  44. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/invTemplate.ejs +144 -0
  45. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  46. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +11 -11
  47. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/data.js +1 -1
  48. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +1 -1
  49. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/data.js +159 -0
  50. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +2 -2
  51. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +2 -2
  52. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +2 -2
  53. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/template.ejs +9 -0
  54. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  55. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  56. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  57. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  58. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/data.js +73 -0
  59. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/template.ejs +9 -0
  60. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  61. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  62. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/invTemplate.ejs +144 -0
  63. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  64. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +1 -1
  65. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +1 -1
  66. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/data.js +158 -0
  67. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +2 -2
  68. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +2 -2
  69. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +1 -1
  70. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/template.ejs +9 -0
  71. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  72. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  73. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  74. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  75. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/data.js +73 -0
  76. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/template.ejs +9 -0
  77. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  78. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  79. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/invTemplate.ejs +144 -0
  80. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  81. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +1 -1
  82. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +131 -88
  83. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +2 -2
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/data.js +158 -0
  85. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +2 -2
  86. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +2 -2
  87. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +1 -1
  88. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/template.ejs +9 -0
  89. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  90. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  91. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/data.js +73 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/template.ejs +9 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/invTemplate.ejs +144 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +1 -1
  100. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/data.js +160 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/template.ejs +9 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/data.js +73 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/template.ejs +9 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/apiTemplate.ejs +172 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/dsqTemplate.ejs +218 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/invTemplate.ejs +161 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/sqsTemplate.ejs +197 -0
  112. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/data.js +59 -0
  113. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/template.ejs +386 -0
  114. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/data.js +77 -0
  115. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/snsTemplate.ejs +59 -0
  116. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  117. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/functionYaml/data.js +121 -0
  118. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/functionYaml/template.ejs +20 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/handler/sqs/data.js +60 -0
  120. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/handler/sqs/template.ejs +129 -0
  121. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/mainFunction/data.js +56 -0
  122. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/mainFunction/template.ejs +159 -0
  123. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-in-sqs/data.js +71 -0
  124. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-in-sqs/template.ejs +46 -0
  125. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-out/data.js +71 -0
  126. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/sns-out/template.ejs +10 -0
  127. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +2 -2
  128. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/data.js +164 -0
  129. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +2 -2
  130. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +2 -2
  131. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +1 -1
  132. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/template.ejs +9 -0
  133. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/apiTemplate.ejs +20 -0
  134. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/dsqTemplate.ejs +17 -0
  135. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/invTemplate.ejs +13 -0
  136. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/templateByHandler/sqsTemplate.ejs +17 -0
  137. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/data.js +73 -0
  138. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/template.ejs +9 -0
  139. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/apiTemplate.ejs +155 -0
  140. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/dsqTemplate.ejs +202 -0
  141. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/invTemplate.ejs +144 -0
  142. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/sqsTemplate.ejs +181 -0
  143. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +1 -1
  144. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +8 -7
  145. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +36 -30
  146. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +3 -3
@@ -0,0 +1,197 @@
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
+ 'relType',
39
+ 'relationshipProperty',
40
+ 'relationshipDirection',
41
+ 'moveObject'
42
+ ],
43
+ properties: {
44
+ firstObject: {
45
+ type: 'object',
46
+ required: ['objType', 'identifiers'],
47
+ properties: {
48
+ objType: {
49
+ type: 'object',
50
+ required: ['objectType', 'serviceTag'],
51
+ properties: {
52
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
53
+ objectType: izara.validatorSchema.stringNotEmpty(),
54
+ }
55
+ },
56
+ identifiers: {
57
+ type: "object",
58
+ minProperties: 1
59
+ },
60
+ }
61
+ },
62
+ secondObject: {
63
+ type: 'object',
64
+ required: ['objType', 'identifiers'],
65
+ properties: {
66
+ objType: {
67
+ type: 'object',
68
+ required: ['objectType', 'serviceTag'],
69
+ properties: {
70
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
71
+ objectType: izara.validatorSchema.stringNotEmpty()
72
+ }
73
+ },
74
+ identifiers: {
75
+ type: "object",
76
+ minProperties: 1
77
+ },
78
+ }
79
+ },
80
+ relType: {
81
+ type: "object",
82
+ required: ['serviceTag','relationshipTag'],
83
+ properties: {
84
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
85
+ relationshipTag: izara.validatorSchema.stringNotEmpty()
86
+ }
87
+ },
88
+ relationshipDirection: {
89
+ type: "string",
90
+ enum: ['from','to']
91
+ },
92
+ relationshipProperty: {
93
+ type: "object",
94
+ minProperties: 1
95
+ },
96
+ moveObject: {
97
+ type: "object",
98
+ required: ['fromObjectRef','toObject'],
99
+ properties: {
100
+ fromObjectRef: {
101
+ type: 'string',
102
+ enum: ['firstObject','secondObject']
103
+ },
104
+ toObject: {
105
+ type: 'object',
106
+ required: ['objType', 'identifiers'],
107
+ properties: {
108
+ objType: {
109
+ type: 'object',
110
+ required: ['objectType', 'serviceTag'],
111
+ properties: {
112
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
113
+ objectType: izara.validatorSchema.stringNotEmpty()
114
+ }
115
+ },
116
+ identifiers: {
117
+ type: 'object',
118
+ minProperties: 1
119
+ }
120
+ }
121
+ }
122
+ }
123
+ },
124
+ settings: {
125
+ type: 'object'
126
+ }
127
+ }
128
+ };
129
+
130
+
131
+ //(<globalVariable>
132
+ //</globalVariable>)
133
+
134
+ // validate event params in middleware before into main function
135
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
136
+ // if need to validate authorizer or additional params , add code to hook tag below
137
+
138
+ //(<afterValidateWith>)
139
+ //(</afterValidateWith>)
140
+
141
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
142
+
143
+ try {
144
+
145
+ let recordPromises = []; // final return
146
+
147
+ // loop each record and send to mainFunction
148
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
149
+
150
+ let passOnProperties = []
151
+
152
+ // --- validate message (and MessageAttributes)
153
+ await recordHandlerSharedLib.validateRecord(
154
+ record, // one record will send to mainFunction
155
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
156
+ validatorSchema, // schema for record.Message
157
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
158
+ );
159
+
160
+ // add argument (to invoke lambda) to passOnProperties[]
161
+ passOnProperties.push(record.body.Message)
162
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
163
+ //(<afterPutParamIntoMainFunction>)
164
+ //(</afterPutParamIntoMainFunction>)
165
+
166
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
167
+
168
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
169
+ let recordPromise = recordHandlerSharedLib.recordHandler(
170
+ record, // one record will send to mainFunction
171
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
172
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
173
+ passOnProperties, // all parameters that mainFunction needed.
174
+ );
175
+ record._izContext.logger.debug('after recordPromise in handler');
176
+ recordPromises.push(recordPromise); // push promise to recordPromises
177
+ })) //end record
178
+
179
+ Logger.debug('before Promise.all(recordPromises) in handler');
180
+ try {
181
+ await Promise.all(recordPromises); // await all promises
182
+ return event.Records // return all for local test
183
+ } catch {
184
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
185
+ }
186
+ Logger.debug('after Promise.all(recordPromises) in handler');
187
+ } catch (err) {
188
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
189
+ throw (err);
190
+ }
191
+ });
192
+ <%_ function firstLetterUpperCase(text) {
193
+ return text.charAt(0).toUpperCase() + text.slice(1)
194
+ } _%>
195
+ <%_ function firstLetterLowerCase(str) {
196
+ return str.charAt(0).toLowerCase() + str.slice(1)
197
+ } _%>
@@ -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, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils.js");
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts.js");
25
+
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @param {Object} objectSchema
34
+ * @return {{ templatePath, templateData, setting } }
35
+ */
36
+ function data(_izContext, srcPath) {
37
+ const createSourceParams = createParamForCreateSource(srcPath)
38
+ return [createSourceParams];
39
+ }
40
+
41
+
42
+ function createParamForCreateSource(srcPath) {
43
+ let functionName = FUNCTION_NAME.moveRel
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
51
+ saveFileName: `${upperCase(FUNCTION_NAME.moveRel)}_Main`,
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;
@@ -0,0 +1,386 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const hash = require('@izara_project/izara-shared-core').objectHash;
21
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
23
+ const lambdaSharedLib = require("@izara_project/izara-core-library-lambda");
24
+ const snsSharedLib = require("@izara_project/izara-core-library-sns");
25
+ const dynamodbSharedLib = require("@izara_project/izara-core-library-dynamodb");
26
+ const asyncFlowSharedLib = require("@izara_project/izara-core-library-asynchronous-flow");
27
+
28
+ const sns = require("@izara_project/izara-core-library-external-request/src/resources/Sns");
29
+
30
+ const identifiersObject = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
31
+
32
+ // const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
33
+
34
+ const { findLinksByObjTypes } = require("@izara_project/izara-core-library-service-schemas/src/libs/RelSchemaLib");
35
+
36
+
37
+
38
+ const {
39
+ getRelationshipSchemaWithCache,
40
+ getObjSchemaS3WithHierarchy
41
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
42
+
43
+ const {
44
+ createLinkTypeId
45
+ } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
46
+
47
+ const {
48
+ getGraphServiceTagWithCache
49
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
50
+
51
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
52
+ const {
53
+ PREFIX,
54
+ TOPIC_NAME_GENERATE_CODE,
55
+ TOPIC_NAME_GRAPH_HANDLER
56
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
57
+ const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
58
+
59
+ //(<optionalRequire>)
60
+ //(</optionalRequire>)
61
+ /**
62
+ * update relationship endpoint
63
+ *
64
+ * @param {Object} _izContext
65
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
66
+ * @param {Logger} _izContext.logger - property of _izContext
67
+ * @param {Object} requestParams - request params
68
+ * @param {Object} callingFlowConfig
69
+ *
70
+ * @returns {object} description of return value
71
+ */
72
+ module.exports.<%- functionName %> = async (
73
+ _izContext,
74
+ requestParams,
75
+ callingFlowConfig = {},
76
+ //(<additionalParams>)
77
+ //(</additionalParams>)
78
+ ) => {
79
+ try {
80
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
81
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
82
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
83
+
84
+ const {
85
+ firstObject,
86
+ secondObject,
87
+ relType,
88
+ relationshipDirection,
89
+ relationshipProperties,
90
+ moveObject
91
+ //(<requestParamMoveRel>)
92
+ //(</requestParamMoveRel>)
93
+ } = requestParams;
94
+
95
+ let errorsFound = [];
96
+
97
+ //(<beforeValidateMoveRel>)
98
+ //(</beforeValidateMoveRel>).
99
+ // validate object and identifiers
100
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
101
+
102
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
103
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
104
+
105
+ if (!objectSchema) {
106
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
107
+ }
108
+
109
+ for (const schemaIdentifier of objectSchema.identifiers) {
110
+ let identifierNames = schemaIdentifier.fieldNames || [schemaIdentifier.fieldName];
111
+ for (const identifierName of identifierNames) {
112
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
113
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
114
+ } else {
115
+ if (
116
+ typeof (identifiersObject[identifierName]) !== "string" &&
117
+ typeof (identifiersObject[identifierName]) !== "number"
118
+ ) {
119
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ await validateIdentifiersExists(_izContext, firstObject.objType, firstObject.identifiers);
127
+ await validateIdentifiersExists(_izContext, secondObject.objType, secondObject.identifiers);
128
+ // finished validate object and identifiers
129
+
130
+ //(<afterValidateMoveRel>)
131
+ //(</afterValidateMoveRel>)
132
+
133
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
134
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
135
+
136
+ const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], relationshipSchema.links)
137
+ _izContext.logger.debug("links", links)
138
+ if (!links.length) {
139
+ errorsFound.push(`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`)
140
+ };
141
+
142
+ let checkCorrectLink = false;
143
+ for (let link of links) {
144
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = link.from.objType;
145
+ const { serviceTag: toServiceTag, objectType: toObjType } = link.to.objType;
146
+
147
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType
148
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType
149
+
150
+ const matchFromTo = fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
151
+ toServiceTag === secondServiceTag && toObjType === secondObjectType;
152
+
153
+ const matchToFrom = fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
154
+ toServiceTag === firstServiceTag && toObjType === firstObjectType;
155
+
156
+ if ((relationshipDirection === "from" && matchFromTo) ||
157
+ (relationshipDirection === "to" && matchToFrom)) {
158
+ checkCorrectLink = true
159
+ break;
160
+ }
161
+ };
162
+
163
+ if (checkCorrectLink == false) {
164
+ errorsFound.push(`Wrong Relationship Direction`)
165
+ };
166
+
167
+ let targetStorageResources = [];
168
+
169
+ if (relationshipSchema) {
170
+ // find targetStorageResources and validate each storageResources
171
+ await Promise.all(
172
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
173
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
174
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
175
+
176
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType;
177
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType;
178
+
179
+ // find exists link
180
+ if (
181
+ (
182
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType) &&
183
+ (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
184
+ ) ||
185
+ (
186
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType) &&
187
+ (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
188
+ )
189
+ ) {
190
+
191
+ // check founded storageResource of link and collect used storageResources
192
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
193
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
194
+
195
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
196
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
197
+ if (!graphServiceTag) {
198
+ errorsFound.push(`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`)
199
+ }
200
+
201
+ targetStorageResources.push({
202
+ ...usedStorageResource,
203
+ graphServiceTag: graphServiceTag
204
+ });
205
+ } else {
206
+ targetStorageResources.push(usedStorageResource);
207
+ }
208
+ }));
209
+ }
210
+ })
211
+ );
212
+ //(<afterGetRelMoveRel>)
213
+ //(</afterGetRelMoveRel>)
214
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
215
+
216
+ if (!targetStorageResources.length) {
217
+ errorsFound.push(`Not found link from relationship schema`);
218
+ }
219
+
220
+
221
+ // validate properties exists with schema
222
+ for (const propKey in relationshipProperties) {
223
+ if (!relationshipSchema.fieldNames.hasOwnProperty(propKey)) {
224
+ errorsFound.push(`property: ${propKey} not exists in relationshipSchema`);
225
+ }
226
+ }
227
+
228
+ } else {
229
+ errorsFound.push(`relationshipSchema not exists`);
230
+ }
231
+
232
+
233
+ // if found errors will stop processing
234
+ if (errorsFound.length) {
235
+
236
+ let moveRelCompleteMsg = {
237
+ fromObject: firstObject,
238
+ toObject: secondObject,
239
+ relType,
240
+ relationshipProperties,
241
+ relationshipDirection,
242
+ moveObject,
243
+ //(<inMoveCompleteMsg>)
244
+ //(</inMoveCompleteMsg>)
245
+ status: 'error',
246
+ errorsFound: errorsFound
247
+ };
248
+
249
+ // if have callingFlow will send to message complete
250
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
251
+ _izContext.logger.debug("HAVE CallingFlow");
252
+
253
+ moveRelCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, moveRelCompleteMsg);
254
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
255
+
256
+ let messageParams = {
257
+ Message: JSON.stringify(moveRelCompleteMsg),
258
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
259
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outMoveRelationshipComplete),
260
+ };
261
+
262
+ _izContext.logger.debug("messageParams OutCreateRelationshipComplete ::::::: ", messageParams);
263
+ await sns.publishAsync(_izContext, messageParams);
264
+ }
265
+
266
+ return moveRelCompleteMsg;
267
+ }
268
+
269
+
270
+ // before create awaitingStepId per graph storageResource
271
+ const linkTypeId = createLinkTypeId(_izContext, firstObject.objType, secondObject.objType, relType, relationshipDirection);
272
+
273
+ let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
274
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
275
+ let awaitingStepIds = [];
276
+
277
+ for (const targetStorageResource of targetStorageResources) {
278
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
279
+ !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
280
+ ) {
281
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
282
+ targetGraphStorageResources.push(targetStorageResource);
283
+
284
+ // awaitingStepId per graphServiceTag
285
+ awaitingStepIds.push(
286
+ asyncFlowSharedLib.createAwaitingStepId(
287
+ hash({
288
+ linkTypeId,
289
+ graphServiceTag: targetStorageResource.graphServiceTag,
290
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
291
+ firstObject,
292
+ secondObject,
293
+ relType,
294
+ relationshipDirection,
295
+ relationshipProperties,
296
+ moveObject
297
+ }), // hash id
298
+ PREFIX.changeRel // prefix, use constant further
299
+ )
300
+ );
301
+ }
302
+ }
303
+
304
+ if (awaitingStepIds.length) {
305
+ // save awaiting
306
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
307
+ _izContext,
308
+ awaitingStepIds, // awaitingStepIds
309
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
310
+ hash({
311
+ linkTypeId,
312
+ correlationId: _izContext.correlationIds.get("id"),
313
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
314
+ firstObject,
315
+ secondObject,
316
+ relType,
317
+ relationshipDirection,
318
+ relationshipProperties,
319
+ moveObject
320
+ }), // hash id
321
+ PREFIX.changeRel // prefix, use constant further
322
+ )
323
+ );
324
+
325
+ // prepare message body
326
+ let moveRelMessageBody = {
327
+ firstObject,
328
+ secondObject,
329
+ relType,
330
+ relationshipDirection,
331
+ relationshipProperties,
332
+ moveObject
333
+ //(<messageBodyMoveRel>)
334
+ //(</messageBodyMoveRel>)
335
+
336
+ // assign originTimestamp if not exists in relationshipProperties
337
+ }
338
+ _izContext.logger.debug('changeRelMessageBody: ', moveRelMessageBody);
339
+
340
+ await Promise.all(
341
+ targetGraphStorageResources.map(async (storageResource) => {
342
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
343
+
344
+ moveRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
345
+ moveRelMessageBody,
346
+ callingFlowSharedLib.addParentCallingFlowConfig(
347
+ callingFlowConfig, // receive parent callingFlowConfig.
348
+ callingFlowSharedLib.createCallingFlowConfig( // calling flow own service
349
+ //(<callingFlowProperties>)
350
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.moveRelationshipComplete),
351
+ //(</callingFlowProperties>)
352
+ {
353
+ graphServiceTag: storageResource.graphServiceTag
354
+ }
355
+ )
356
+ )
357
+ );
358
+ _izContext.logger.debug("messageObject before send message:", moveRelMessageBody)
359
+
360
+ let messageToInChangeRelationship = {
361
+ Message: JSON.stringify(moveRelMessageBody),
362
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GRAPH_HANDLER.inMoveRelationship, storageResource.graphServiceTag),
363
+ };
364
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInChangeRelationship);
365
+ await sns.publishAsync(_izContext, messageToInChangeRelationship);
366
+ }
367
+ })
368
+ )
369
+ }
370
+
371
+ return {
372
+ firstObject,
373
+ secondObject,
374
+ relType,
375
+ relationshipDirection,
376
+ relationshipProperties,
377
+ moveObject,
378
+ status: "complete"
379
+ };
380
+
381
+
382
+ } catch (err) {
383
+ _izContext.logger.error('error ChangeRelationship: ', err)
384
+ throw (err)
385
+ }
386
+ }