@izara_project/izara-market-library-service-schemas 1.0.2 → 1.0.4

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 (108) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +40 -0
  3. package/src/SourceManager/src/CreateSource.js +0 -1
  4. package/src/SourceManager/src/Utils.js +15 -1
  5. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
  6. package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
  7. package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
  8. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +180 -0
  9. package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
  10. package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
  11. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
  12. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
  13. package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
  14. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
  15. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +182 -0
  16. package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
  17. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
  18. package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
  19. package/src/TemplateManager/src/GenerateCode.js +175 -15
  20. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
  32. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
  33. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
  34. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
  35. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
  36. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +98 -0
  37. package/src/TemplateManager/src/{MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js → ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js} +66 -46
  38. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +103 -0
  39. package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
  40. package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
  41. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
  42. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
  43. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
  44. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
  45. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +43 -0
  46. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  47. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  48. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  49. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
  50. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  51. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  52. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
  53. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  54. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
  55. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  56. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  57. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
  58. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  59. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
  66. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
  67. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
  68. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  69. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
  70. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
  71. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  72. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  73. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
  74. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  75. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  76. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
  77. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  78. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  79. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
  80. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  81. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  82. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
  83. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
  84. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  85. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  86. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  87. package/src/TemplateManager/src/externalService/LambdaRole/data.js +193 -0
  88. package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
  89. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +56 -0
  90. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +96 -0
  91. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  92. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -0
  93. package/src/TemplateManager/src/libs/Consts.js +32 -3
  94. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  95. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
  96. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
  97. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
  98. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +0 -18
  99. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
  100. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
  101. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
  102. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  103. /package/src/TemplateManager/src/{MainResourcesYaml → ResourceYaml}/CreateSourceData.js +0 -0
  104. /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json} +0 -0
  105. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/Handler/Handler.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json} +0 -0
  106. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json} +0 -0
  107. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json} +0 -0
  108. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json} +0 -0
@@ -0,0 +1,167 @@
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
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
23
+
24
+ // const CorrelationIds = require('@izara_project/izara-core-library-correlation-ids')
25
+ // const Logger = require('@izara_project/izara-core-library-logger');
26
+ // const IntegrationTestDetail = require('@izara_project/izara-core-library-integration-tests')
27
+ const recordHandlerSharedLib = require('@izara_project/izara-shared').recordHandlerSharedLib
28
+ const Logger = require("@izara_project/izara-core-library-logger/src/Logger");
29
+ const updateRelationship = require('./UpdateRelationship_Main');
30
+
31
+ // validate event properties in body.Message of sqs event
32
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
33
+ {
34
+ type: "object",
35
+ required: ['body', 'messageAttributes'],
36
+ properties: {
37
+ body: {
38
+ type: 'object',
39
+ },
40
+ messageAttributes: {
41
+ type: 'object'
42
+ }
43
+ }
44
+ }
45
+ ));
46
+
47
+ // validate event params in middleware before into function
48
+ let validatorSchema = {
49
+ type: "object",
50
+ required: ["objects", "relId", "relType", "relationshipProperties"],
51
+ properties: {
52
+ objects: {
53
+ type: "array",
54
+ minItems: 2,
55
+ maxItems: 2,
56
+ items: {
57
+ type: 'object',
58
+ required: ["objType", "identifiers"],
59
+ properties: {
60
+ objType: {
61
+ type: "object",
62
+ required: ["serviceTag", "objectType"],
63
+ properties: {
64
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
65
+ objectType: izara.validatorSchema.stringNotEmpty()
66
+ }
67
+ },
68
+ identifiers: {
69
+ type: "object",
70
+ minProperties: 1
71
+ }
72
+ }
73
+ }
74
+ },
75
+ relType: {
76
+ type: "object",
77
+ required: ["relationshipTag", "serviceTag"],
78
+ properties: {
79
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
80
+ serviceTag: {
81
+ type: 'string',
82
+ pattern: "^[a-zA-Z0-9_-]+$",
83
+ enum: [process.env.iz_serviceTag]
84
+ },
85
+ }
86
+ },
87
+ relId: izara.validatorSchema.stringNotEmpty(),
88
+ relationshipProperties: {
89
+ type: 'object',
90
+ minProperties: 1,
91
+ },
92
+ }
93
+ };
94
+
95
+
96
+ //(<globalVarible>
97
+ //</globalVarible>)
98
+
99
+ // validate event params in middleware before into main function
100
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
101
+ // if need to validate authorizer or additional params , add code to hook tag below
102
+
103
+ //(<afterValidateWith>)
104
+ //(</afterValidateWith>)
105
+
106
+
107
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
108
+ Logger.debug('event:', event);
109
+ Logger.debug('context:', context);
110
+ try {
111
+
112
+ let recordPromises = []; // final return
113
+
114
+ // loop each record and send to mainFunction
115
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
116
+
117
+ // --- reforming record.body for Dsq request
118
+ record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
119
+ record._izContext.logger.debug('record LambdaFunctionHdrDsq after reform', record);
120
+
121
+ let passOnProperties = []
122
+
123
+ // --- validate message (and MessageAttributes)
124
+ await recordHandlerSharedLib.validateRecord(
125
+ record, // one record will send to mainFunction
126
+ "<%- queueName %>", // queue name that need to retry or send to dlq
127
+ validatorSchema, // schema for record.Message
128
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
129
+ );
130
+
131
+ // add argument (to invoke lambda) to passOnProperties[]
132
+ passOnProperties.push(record.body.Message)
133
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
134
+ //(<afterPutParamIntoMainFunction>)
135
+ //(</afterPutParamIntoMainFunction>)
136
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
137
+
138
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
139
+ let recordPromise = recordHandlerSharedLib.recordHandler(
140
+ record, // one record will send to mainFunction
141
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
142
+ "<%- queueName %>", // queue name that need to retry or send to dlq
143
+ passOnProperties, // all parameters that mainFunction needed.
144
+ );
145
+ record._izContext.logger.debug('after recordPromise in handler');
146
+ recordPromises.push(recordPromise); // push promise to recordPromises
147
+ })) //end record
148
+
149
+ Logger.debug('before Promise.all(recordPromises) in handler');
150
+ try {
151
+ await Promise.all(recordPromises); // await all promises
152
+ return event.Records // return all for local test
153
+ } catch {
154
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
155
+ }
156
+ Logger.debug('after Promise.all(recordPromises) in handler');
157
+ } catch (err) {
158
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
159
+ throw (err);
160
+ }
161
+ });
162
+ <%_ function firstLetterUpperCase(text) {
163
+ return text.charAt(0).toUpperCase() + text.slice(1)
164
+ } _%>
165
+ <%_ function firstLetterLowerCase(str) {
166
+ return str.charAt(0).toLowerCase() + str.slice(1)
167
+ } _%>
@@ -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
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ // console.log("createSourceArrayInUpdateRelationshipHdrInv", createSourceArray)
38
+ return [createSourceParams];
39
+ }
40
+
41
+
42
+ function createParamForCreateSource(srcPath) {
43
+ let functionName = "updateRelationship";
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
51
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrInv),
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ // [
60
+ // {
61
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
62
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
63
+ // setting: {
64
+ // savePath: '/generatedCode/source/',
65
+ // saveFileName: 'ObjectTypeGet',
66
+ // fileExtension: '.js',
67
+ // isAppend: false
68
+ // }
69
+ // }
70
+ // ]
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,5 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "mainFunction": "xxx",
4
+ "mainFunctionFile": "directoryOfMainFunction"
5
+ }
@@ -0,0 +1,126 @@
1
+ /*
2
+ This program is free software: you can redistribute it and/or modify
3
+ it under the terms of the GNU Affero General Public License as
4
+ published by the Free Software Foundation, either version 3 of the
5
+ License, or (at your option) any later version.
6
+
7
+ This program is distributed in the hope that it will be useful,
8
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ GNU Affero General Public License for more details.
11
+
12
+ You should have received a copy of the GNU Affero General Public License
13
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const izara = require("@izara_project/izara-middleware");
19
+ const middleware = izara.middlewareHandler;
20
+
21
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
22
+
23
+ // const CorrelationIds = require('@izara_project/izara-core-library-correlation-ids')
24
+ // const Logger = require('@izara_project/izara-core-library-logger');
25
+ // const IntegrationTestDetail = require('@izara_project/izara-core-library-integration-tests')
26
+
27
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
28
+
29
+ // validate event params in middlewware before into function.
30
+ let validatorSchema = {
31
+ type: "object",
32
+ required: ["objects", "relId", "relType", "relationshipProperties"],
33
+ properties: {
34
+ objects: {
35
+ type: "array",
36
+ minItems: 2,
37
+ maxItems: 2,
38
+ items: {
39
+ type: 'object',
40
+ required: ["objType", "identifiers"],
41
+ properties: {
42
+ objType: {
43
+ type: "object",
44
+ required: ["serviceTag", "objectType"],
45
+ properties: {
46
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
47
+ objectType: izara.validatorSchema.stringNotEmpty()
48
+ }
49
+ },
50
+ identifiers: {
51
+ type: "object",
52
+ minProperties: 1
53
+ }
54
+ }
55
+ }
56
+ },
57
+ relType: {
58
+ type: "object",
59
+ required: ["relationshipTag", "serviceTag"],
60
+ properties: {
61
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
62
+ serviceTag: {
63
+ type: 'string',
64
+ pattern: "^[a-zA-Z0-9_-]+$",
65
+ enum: [process.env.iz_serviceTag]
66
+ },
67
+ }
68
+ },
69
+ relId: izara.validatorSchema.stringNotEmpty(),
70
+ relationshipProperties: {
71
+ type: 'object',
72
+ minProperties: 1,
73
+ },
74
+ }
75
+ };
76
+
77
+ //(<globalVarible>
78
+ //</globalVarible>)
79
+
80
+ // validate event params in middleware before into main function
81
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
82
+ middleware.setValidatorSchema(validatorSchema)
83
+ // if need to validate authorizer or additional params , add code to hook tag below
84
+
85
+ //(<afterValidateWith>)
86
+ //(</afterValidateWith>)
87
+
88
+
89
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
90
+ event._izContext.logger.debug('Event:', event);
91
+ event._izContext.logger.debug('context:',context);
92
+
93
+ try {
94
+ // invoke LambdaFunction
95
+ let lambdaFunctionResponse = await <%- functionName %>.<%- functionName %>(
96
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
97
+ {
98
+ objects: event.objects,
99
+ relType: event.relType,
100
+ relId: event.relId,
101
+ relationshipProperties: event.relationshipProperties
102
+ },
103
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
104
+ //(<afterPutParamIntoMainFunction>)
105
+ //(</afterPutParamIntoMainFunction>)
106
+ );
107
+
108
+ // return error to client
109
+ if (lambdaFunctionResponse instanceof Error) {
110
+ return (izara.response.failure(lambdaFunctionResponse));
111
+ }
112
+
113
+ // return success to client
114
+ return (izara.response.success(lambdaFunctionResponse));
115
+
116
+ } catch (err) {
117
+ event._izContext.logger.error('Error, <%- firstLetterUpperCase(functionName) %>HdrInv: ', err);
118
+ return (izara.response.failure(err));
119
+ }
120
+ });
121
+ <%_ function firstLetterUpperCase(text){
122
+ return text.charAt(0).toUpperCase() + text.slice(1)
123
+ } _%>
124
+ <%_ function firstLetterLowerCase(str) {
125
+ return str.charAt(0).toLowerCase() + str.slice(1)
126
+ } _%>
@@ -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
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+
41
+ function createParamForCreateSource(srcPath) {
42
+ let functionName = "updateRelationship";
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrSqs)
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
51
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrSqs),
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ // [
60
+ // {
61
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
62
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
63
+ // setting: {
64
+ // savePath: '/generatedCode/source/',
65
+ // saveFileName: 'ObjectTypeGet',
66
+ // fileExtension: '.js',
67
+ // isAppend: false
68
+ // }
69
+ // }
70
+ // ]
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,146 @@
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-shared/src/CallingFlowSharedLib')
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-shared').recordHandlerSharedLib
27
+
28
+ const updateRelationship = require('./UpdateRelationship_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: ["objects", "relId", "relType", "relationshipProperties"],
36
+ properties: {
37
+ objects: {
38
+ type: "array",
39
+ minItems: 2,
40
+ maxItems: 2,
41
+ items: {
42
+ type: 'object',
43
+ required: ["objType", "identifiers"],
44
+ properties: {
45
+ objType: {
46
+ type: "object",
47
+ required: ["serviceTag", "objectType"],
48
+ properties: {
49
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
50
+ objectType: izara.validatorSchema.stringNotEmpty()
51
+ }
52
+ },
53
+ identifiers: {
54
+ type: "object",
55
+ minProperties: 1
56
+ }
57
+ }
58
+ }
59
+ },
60
+ relType: {
61
+ type: "object",
62
+ required: ["relationshipTag", "serviceTag"],
63
+ properties: {
64
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
65
+ serviceTag: {
66
+ type: 'string',
67
+ pattern: "^[a-zA-Z0-9_-]+$",
68
+ enum: [process.env.iz_serviceTag]
69
+ },
70
+ }
71
+ },
72
+ relId: izara.validatorSchema.stringNotEmpty(),
73
+ relationshipProperties: {
74
+ type: 'object',
75
+ minProperties: 1,
76
+ },
77
+ }
78
+ };
79
+
80
+ //(<globalVarible>
81
+ //</globalVarible>)
82
+
83
+ // validate event params in middleware before into main function
84
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
85
+ // if need to validate authorizer or additional params , add code to hook tag below
86
+
87
+ //(<afterValidateWith>)
88
+ //(</afterValidateWith>)
89
+
90
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
91
+
92
+ try {
93
+
94
+ let recordPromises = []; // final return
95
+
96
+ // loop each record and send to mainFunction
97
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
98
+
99
+ let passOnProperties = []
100
+
101
+ // --- validate message (and MessageAttributes)
102
+ await recordHandlerSharedLib.validateRecord(
103
+ record, // one record will send to mainFunction
104
+ "<%- queueName %>", // queue name that need to retry or send to dlq
105
+ validatorSchema, // schema for record.Message
106
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
107
+ );
108
+
109
+ // add argument (to invoke lambda) to passOnProperties[]
110
+ passOnProperties.push(record.body.Message)
111
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
112
+ //(<afterPutParamIntoMainFunction>)
113
+ //(</afterPutParamIntoMainFunction>)
114
+
115
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
116
+
117
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
118
+ let recordPromise = recordHandlerSharedLib.recordHandler(
119
+ record, // one record will send to mainFunction
120
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
121
+ "<%- queueName %>", // queue name that need to retry or send to dlq
122
+ passOnProperties, // all parameters that mainFunction needed.
123
+ );
124
+ record._izContext.logger.debug('after recordPromise in handler');
125
+ recordPromises.push(recordPromise); // push promise to recordPromises
126
+ })) //end record
127
+
128
+ Logger.debug('before Promise.all(recordPromises) in handler');
129
+ try {
130
+ await Promise.all(recordPromises); // await all promises
131
+ return event.Records // return all for local test
132
+ } catch {
133
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
134
+ }
135
+ Logger.debug('after Promise.all(recordPromises) in handler');
136
+ } catch (err) {
137
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
138
+ throw (err);
139
+ }
140
+ });
141
+ <%_ function firstLetterUpperCase(text) {
142
+ return text.charAt(0).toUpperCase() + text.slice(1)
143
+ } _%>
144
+ <%_ function firstLetterLowerCase(str) {
145
+ return str.charAt(0).toLowerCase() + str.slice(1)
146
+ } _%>
@@ -0,0 +1,31 @@
1
+ {
2
+ "objects": [
3
+ {
4
+ "objType": {
5
+ "objectType": "Sunny",
6
+ "serviceTag": "GenerateCodeTemplateBas"
7
+ },
8
+ "identifiers": {
9
+ "personId": "Node1"
10
+ }
11
+ },
12
+ {
13
+ "objType": {
14
+ "objectType": "Weather",
15
+ "serviceTag": "GenerateCodeTemplateBas"
16
+ },
17
+ "identifiers": {
18
+ "personId": "Node2"
19
+ }
20
+ }
21
+ ],
22
+ "relType": {
23
+ "relationshipTag": "RelTag",
24
+ "serviceTag": "GenerateCodeTemplateBas"
25
+ },
26
+ "relId": "aa-bb-cc",
27
+ "relationshipProperties": {
28
+ "name": "bas007"
29
+ },
30
+ "callingFlow": "basCallingFlow"
31
+ }