@izara_project/izara-market-library-service-schemas 1.0.27 → 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 (127) hide show
  1. package/package.json +9 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +5 -2
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +5 -5
  4. package/src/MainLibs/src/Consts.js +44 -2
  5. package/src/reStructure/GenerateCode.js +0 -4
  6. package/src/reStructure/GenerateSchema.js +17 -5
  7. package/src/reStructure/SchemaConfig.js +3 -2
  8. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +58 -6
  9. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +161 -101
  10. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +3 -4
  11. package/src/reStructure/TemplateData/findData/handler/template.ejs +1 -1
  12. package/src/reStructure/TemplateData/findData/mainFunction/template.ejs +3 -3
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/template.ejs +2 -3
  14. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +2 -3
  15. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +2 -3
  16. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +5 -6
  17. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/handler/template.ejs +1 -2
  18. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +3 -4
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +2 -2
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +3 -4
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +2 -3
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -6
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/template.ejs +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +4 -5
  25. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js +1 -0
  26. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js +1 -0
  27. package/src/reStructure/TemplateData/perActionComplete/create/handler/template.ejs +2 -3
  28. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +4 -5
  29. package/src/reStructure/TemplateData/perActionComplete/delete/handler/template.ejs +2 -2
  30. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +4 -6
  31. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +1 -1
  32. package/src/reStructure/TemplateData/perActionComplete/get/handler/template.ejs +2 -3
  33. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +4 -6
  34. package/src/reStructure/TemplateData/perActionComplete/update/handler/template.ejs +2 -3
  35. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +4 -6
  36. package/src/reStructure/TemplateData/perActionEndpoint/handler/api/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/perActionEndpoint/handler/dsq/template.ejs +2 -2
  38. package/src/reStructure/TemplateData/perActionEndpoint/handler/inv/template.ejs +1 -3
  39. package/src/reStructure/TemplateData/perActionEndpoint/handler/sqs/template.ejs +2 -2
  40. package/src/reStructure/TemplateData/perActionEndpoint/handler/webSocket/template.ejs +3 -3
  41. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/create/template.ejs +6 -7
  42. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/delete/template.ejs +5 -4
  43. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/get/template.ejs +5 -6
  44. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/update/template.ejs +5 -6
  45. package/src/reStructure/TemplateData/processLogical/handler/template.ejs +1 -1
  46. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +5 -6
  47. package/src/reStructure/TemplateData/processLogicalPagination/handler/dsq/template.ejs +1 -1
  48. package/src/reStructure/TemplateData/processLogicalPagination/handler/sqs/template.ejs +1 -1
  49. package/src/reStructure/TemplateData/processLogicalPagination/mainFunction/template.ejs +6 -5
  50. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +27 -6
  51. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +25 -4
  52. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +26 -4
  53. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +26 -4
  54. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/api/template.ejs +1 -1
  55. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/dsq/template.ejs +2 -2
  56. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/inv/template.ejs +1 -1
  57. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/sqs/template.ejs +2 -2
  58. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +66 -18
  59. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -3
  60. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +5 -6
  61. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +25 -4
  62. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +25 -4
  63. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +25 -4
  64. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +26 -4
  65. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/api/template.ejs +1 -1
  66. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/dsq/template.ejs +2 -2
  67. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/inv/template.ejs +1 -1
  68. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/sqs/template.ejs +2 -2
  69. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +55 -5
  70. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +62 -6
  71. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +119 -0
  72. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/template.ejs +20 -0
  73. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +131 -0
  74. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/template.ejs +17 -0
  75. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +119 -0
  76. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/template.ejs +13 -0
  77. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +131 -0
  78. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/template.ejs +17 -0
  79. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/data.js +57 -0
  80. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/request.json +0 -0
  81. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/template.ejs +138 -0
  82. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/data.js +58 -0
  83. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/request.json +0 -0
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/template.ejs +183 -0
  85. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/data.js +59 -0
  86. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/request.json +0 -0
  87. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/template.ejs +125 -0
  88. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/data.js +59 -0
  89. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/request.json +0 -0
  90. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/template.ejs +163 -0
  91. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/data.js +59 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +322 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/data.js +77 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +59 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +110 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/request.json +0 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/template.ejs +20 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/data.js +60 -0
  100. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/request.json +0 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +125 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/data.js +55 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/request.json +0 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +141 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/data.js +71 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/request.json +0 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/template.ejs +47 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/data.js +71 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/request.json +0 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +10 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +25 -22
  112. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +25 -5
  113. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +26 -5
  114. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +25 -4
  115. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/api/template.ejs +1 -1
  116. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/dsq/template.ejs +2 -2
  117. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/inv/template.ejs +1 -1
  118. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/sqs/template.ejs +2 -2
  119. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +55 -7
  120. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +50 -42
  121. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +98 -0
  122. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +4 -5
  123. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -1
  124. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +11 -2
  125. package/src/reStructure/TemplateData/testTemplate/data.js +27 -0
  126. package/src/reStructure/TemplateData/testTemplate/template.ejs +5 -0
  127. /package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/{attributeLink.ejs → attributeLinkTemplate.ejs} +0 -0
@@ -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;
@@ -0,0 +1,125 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
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 Logger = require('@izara_project/izara-core-library-logger');
27
+ // const IntegrationTestDetail = require('@izara_project/izara-core-library-integration-tests')
28
+
29
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
30
+
31
+ // validate event params in middlewware before into function.
32
+ let validatorSchema = {
33
+ type: "object",
34
+ required: ["firstObject", "secondObject", "relType", 'relId'],
35
+ properties: {
36
+ firstObject: {
37
+ type: "object",
38
+ required: ["objType", "identifiers"],
39
+ properties: {
40
+ objType: {
41
+ type: "object",
42
+ required: ["serviceTag", "objectType"],
43
+ properties: {
44
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
45
+ objectType: izara.validatorSchema.stringNotEmpty()
46
+ }
47
+ },
48
+ identifiers: {
49
+ type: "object",
50
+ minProperties: 1
51
+ }
52
+ }
53
+ },
54
+ secondObject: {
55
+ type: "object",
56
+ required: ["objType", "identifiers"],
57
+ properties: {
58
+ objType: {
59
+ type: "object",
60
+ required: ["serviceTag", "objectType"],
61
+ properties: {
62
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
63
+ objectType: izara.validatorSchema.stringNotEmpty()
64
+ }
65
+ },
66
+ identifiers: {
67
+ type: "object",
68
+ minProperties: 1
69
+ }
70
+ }
71
+ },
72
+ relType: {
73
+ type: "object",
74
+ required: ["relationshipTag", "serviceTag"],
75
+ properties: {
76
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
77
+ serviceTag: {
78
+ type: 'string',
79
+ pattern: "^[a-zA-Z0-9_-]+$",
80
+ enum: [process.env.iz_serviceTag]
81
+ },
82
+ }
83
+ },
84
+ relationshipDirection: {
85
+ type: "string",
86
+ default: ""
87
+ },
88
+ relId: {
89
+ type: 'string',
90
+ },
91
+ }
92
+ };
93
+
94
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema); // is Ok callinfFlow
95
+ middleware.setValidatorSchema(validatorSchema)
96
+
97
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
98
+ event._izContext.logger.debug('Event:', event);
99
+ event._izContext.logger.debug('context:', context);
100
+
101
+ try {
102
+ // invoke LambdaFunction
103
+ return await <%- functionName %>.<%- functionName %>(
104
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
105
+ {
106
+ firstObject: event.firstObject,
107
+ secondObject: event.secondObject,
108
+ relType: event.relType,
109
+ relId: event.relId,
110
+ relationshipDirection: event.relationshipDirection,
111
+ },
112
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
113
+ );
114
+
115
+ } catch (err) {
116
+ event._izContext.logger.error('Error, <%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handler) %> : ', err);
117
+ throw (err);
118
+ }
119
+ });
120
+ <%_ function firstLetterUpperCase(text) {
121
+ return text.charAt(0).toUpperCase() + text.slice(1)
122
+ } _%>
123
+ <%_ function firstLetterLowerCase(str) {
124
+ return str.charAt(0).toLowerCase() + str.slice(1)
125
+ } _%>
@@ -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 sqs 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 queueName = functionName + upperCase(HANDLER.hdrSqs)
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName,
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
51
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrSqs),
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;
@@ -0,0 +1,163 @@
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: ["firstObject", "secondObject", "relType", 'relId'],
36
+ properties: {
37
+ firstObject: {
38
+ type: "object",
39
+ required: ["objType", "identifiers"],
40
+ properties: {
41
+ objType: {
42
+ type: "object",
43
+ required: ["serviceTag", "objectType"],
44
+ properties: {
45
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
46
+ objectType: izara.validatorSchema.stringNotEmpty()
47
+ }
48
+ },
49
+ identifiers: {
50
+ type: "object",
51
+ minProperties: 1
52
+ }
53
+ }
54
+ },
55
+ secondObject: {
56
+ type: "object",
57
+ required: ["objType", "identifiers"],
58
+ properties: {
59
+ objType: {
60
+ type: "object",
61
+ required: ["serviceTag", "objectType"],
62
+ properties: {
63
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
64
+ objectType: izara.validatorSchema.stringNotEmpty()
65
+ }
66
+ },
67
+ identifiers: {
68
+ type: "object",
69
+ minProperties: 1
70
+ }
71
+ }
72
+ },
73
+ relType: {
74
+ type: "object",
75
+ required: ["relationshipTag", "serviceTag"],
76
+ properties: {
77
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
78
+ serviceTag: {
79
+ type: 'string',
80
+ pattern: "^[a-zA-Z0-9_-]+$",
81
+ enum: [process.env.iz_serviceTag]
82
+ },
83
+ }
84
+ },
85
+ relationshipDirection: {
86
+ type: "string",
87
+ default: ""
88
+ },
89
+ relId: {
90
+ type: 'string',
91
+ },
92
+ }
93
+ };
94
+
95
+
96
+
97
+ //(<globalVarible>
98
+ //</globalVarible>)
99
+
100
+ // validate event params in middleware before into main function
101
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
102
+ // if need to validate authorizer or additional params , add code to hook tag below
103
+
104
+ //(<afterValidateWith>)
105
+ //(</afterValidateWith>)
106
+
107
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
108
+
109
+ try {
110
+
111
+ let recordPromises = []; // final return
112
+
113
+ // loop each record and send to mainFunction
114
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
115
+
116
+ let passOnProperties = []
117
+
118
+ // --- validate message (and MessageAttributes)
119
+ await recordHandlerSharedLib.validateRecord(
120
+ record, // one record will send to mainFunction
121
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
122
+ validatorSchema, // schema for record.Message
123
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
124
+ );
125
+
126
+ // add argument (to invoke lambda) to passOnProperties[]
127
+ passOnProperties.push(record.body.Message)
128
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
129
+ //(<afterPutParamIntoMainFunction>)
130
+ //(</afterPutParamIntoMainFunction>)
131
+
132
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
133
+
134
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
135
+ let recordPromise = recordHandlerSharedLib.recordHandler(
136
+ record, // one record will send to mainFunction
137
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
138
+ "<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
139
+ passOnProperties, // all parameters that mainFunction needed.
140
+ );
141
+ record._izContext.logger.debug('after recordPromise in handler');
142
+ recordPromises.push(recordPromise); // push promise to recordPromises
143
+ })) //end record
144
+
145
+ Logger.debug('before Promise.all(recordPromises) in handler');
146
+ try {
147
+ await Promise.all(recordPromises); // await all promises
148
+ return event.Records // return all for local test
149
+ } catch {
150
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
151
+ }
152
+ Logger.debug('after Promise.all(recordPromises) in handler');
153
+ } catch (err) {
154
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
155
+ throw (err);
156
+ }
157
+ });
158
+ <%_ function firstLetterUpperCase(text) {
159
+ return text.charAt(0).toUpperCase() + text.slice(1)
160
+ } _%>
161
+ <%_ function firstLetterLowerCase(str) {
162
+ return str.charAt(0).toLowerCase() + str.slice(1)
163
+ } _%>
@@ -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/index.js").utils;
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/index.js").consts;
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.getRel;
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.getRel)}_Main`,
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;