@izara_project/izara-market-library-service-schemas 1.0.32 → 1.0.34

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 (65) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +15 -1
  4. package/src/MainLibs/src/Consts.js +7 -2
  5. package/src/reStructure/GenerateCode.js +16 -18
  6. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
  7. package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
  8. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +1 -1
  9. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +15 -15
  10. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
  11. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
  12. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  13. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
  14. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
  15. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +14 -0
  16. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +17 -0
  17. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
  18. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
  19. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
  20. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
  21. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
  22. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
  23. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
  24. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
  25. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
  26. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +1 -1
  27. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
  28. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +1 -1
  29. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +1 -1
  30. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
  31. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +20 -0
  32. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
  33. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
  34. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
  35. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
  36. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +3 -28
  37. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +6 -10
  38. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +4 -2
  39. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +4 -3
  40. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +26 -0
  41. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +2 -2
  42. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +6 -10
  43. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +4 -4
  44. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -4
  45. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +8 -1
  46. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +32 -5
  47. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +18 -18
  48. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
  49. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
  50. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +55 -10
  51. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +27 -7
  52. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +3 -3
  53. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +9 -3
  54. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +1 -1
  55. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +9 -3
  56. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +1 -1
  57. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +10 -4
  58. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +1 -1
  59. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +9 -3
  60. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +1 -1
  61. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -5
  62. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +5 -5
  63. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +1 -1
  64. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template copy.ejs +0 -125
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/template.ejs +0 -0
@@ -0,0 +1,202 @@
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 path = require('path');
21
+
22
+ const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils");
25
+ const {
26
+ SOURCE_PATH,
27
+ defaultIamRolePerAction,
28
+ createIamRole,
29
+ RESOURCE_CLASSES,
30
+ SNS_RESOURCE,
31
+ resourceNames,
32
+ DYNAMO_RESOURCE,
33
+ SAVE_FILE_NAME,
34
+ FUNCTION_NAME,
35
+ shortNameHandler,
36
+ externalResourceYaml,
37
+ SOURCE_GENERATE_IAM_ROLE
38
+ } = require("../../../../../MainLibs/src/Consts");
39
+
40
+ const templatePath = path.join(__dirname, "template.ejs");
41
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
42
+ /**
43
+ * receive objectSchema
44
+ * create data for WebSocket handler template
45
+ *
46
+ * @param {Object} objectSchema
47
+ * @return {{templatePath, templateData,setting}}
48
+ */
49
+ function data(_izContext, flowSchema, srcPath) {
50
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
51
+ }
52
+
53
+ function createSourceParams(_izContext, flowSchema, srcPath) {
54
+ const functionName = upperCase(flowSchema.flowTag);
55
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
56
+ const functionNameConfig = upperCase(flowSchema.flowTag) + SOURCE_GENERATE_IAM_ROLE.EventBridge;
57
+ const handlerType = HANDLER.hdrInv;
58
+ const schedules = flowSchema.schedules;
59
+
60
+ // validate schedule
61
+ if (!Array.isArray(schedules)) {
62
+ console.error("schedules is not an array");
63
+ return;
64
+ }
65
+ if (schedules.length === 0) {
66
+ console.error("No schedule found in flowSchema");
67
+ return;
68
+ }
69
+
70
+ // Validate each schedule in the array
71
+ for (const schedule of schedules) {
72
+ if (!schedule.name || schedule.name.length === 0) {
73
+ console.error("A schedule's name is not defined");
74
+ return;
75
+ }
76
+ if (!schedule.rate || schedule.rate.length === 0) {
77
+ console.error("A schedule's rate is not defined");
78
+ return;
79
+ }
80
+ if (!schedule.input || schedule.input.length === 0) {
81
+ console.error("A schedule's input is not defined");
82
+ return;
83
+ }
84
+ }
85
+
86
+ // Validate rate format for each schedule
87
+ for (const schedule of schedules) {
88
+ const rate = schedule.rate;
89
+ if (rate.startsWith('rate')) {
90
+ // Validate rate expression format: rate(value unit)
91
+ if (!/^rate\(\d+\s+(minute|minutes|hour|hours|day|days)\)$/.test(rate)) {
92
+ console.error(`Invalid rate format: ${rate}. Should be like 'rate(5 minutes)' or 'rate(1 day)'`);
93
+ return;
94
+ }
95
+ } else if (rate.startsWith('cron')) {
96
+ // Extract the cron components for more detailed validation
97
+ const cronMatch = rate.match(/^cron\((.*)\)$/);
98
+ if (!cronMatch) {
99
+ console.error(`Invalid cron format: ${rate}. Should be like 'cron(0 10 * * ? *)'`);
100
+ return;
101
+ }
102
+
103
+ const cronParts = cronMatch[1].split(/\s+/);
104
+ if (cronParts.length !== 6) {
105
+ console.error(`Invalid cron expression: ${rate}. Must contain 6 components: minutes hours day-of-month month day-of-week year`);
106
+ return;
107
+ }
108
+
109
+ } else {
110
+ console.error(`Invalid rate expression: ${rate} - must start with 'rate' or 'cron'`);
111
+ return;
112
+ }
113
+ }
114
+
115
+
116
+ let additionalResourcePermission = defaultIamRolePerAction();
117
+ additionalResourcePermission.push(
118
+ createIamRole(
119
+ {
120
+ [RESOURCE_CLASSES.sns]: [
121
+ SNS_RESOURCE.publish
122
+ ]
123
+ },
124
+ [
125
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
126
+ ]
127
+ ),
128
+ createIamRole(
129
+ {
130
+ [RESOURCE_CLASSES.dynamoDbTable]: [
131
+ DYNAMO_RESOURCE.putItem,
132
+ DYNAMO_RESOURCE.getItem,
133
+ DYNAMO_RESOURCE.query,
134
+ DYNAMO_RESOURCE.deleteItem,
135
+ DYNAMO_RESOURCE.updateItem
136
+ ]
137
+ },
138
+ [
139
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
140
+ ]
141
+ ),
142
+ createIamRole(
143
+ {
144
+ "execute-api": [
145
+ "ManageConnections"
146
+ ]
147
+ },
148
+ [
149
+ resourceNames(RESOURCE_CLASSES.webSocket)
150
+ ]
151
+ )
152
+ )
153
+
154
+ if (flowSchema?.hook) {
155
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
156
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
157
+ for (const hookFunction of hookProperties.functionList) {
158
+ if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
159
+ if (hookFunction?.permission) {
160
+ for (const permission of hookFunction.permission) {
161
+ additionalResourcePermission.push(
162
+ createIamRole(
163
+ permission.action,
164
+ permission.resource.map(resource =>
165
+ externalResourceYaml(
166
+ resource.resource,
167
+ resource.resourceName,
168
+ resource.serviceTag),
169
+ permission.effect
170
+ )
171
+ )
172
+ )
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
181
+ return {
182
+ templatePath: templatePath,
183
+ templateData: {
184
+ resourceLocation: SOURCE_PATH.resourceLocationFlowSchemaEventBridge,
185
+ functionName,
186
+ action,
187
+ functionNameConfig: functionNameConfig,
188
+ additionalResourcePermission,
189
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
190
+ handlerType,
191
+ schedules
192
+ },
193
+ setting: {
194
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
195
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
196
+ fileExtension: ".yml",
197
+ isAppend: true
198
+ }
199
+ }
200
+ }
201
+
202
+ module.exports = data;
@@ -0,0 +1,21 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${functionName}${action}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
5
+ events:
6
+ <%_ schedules.forEach((schedule) => { _%>
7
+ - schedule:
8
+ name: <%- schedule.name %>
9
+ description: <%- schedule.description %>
10
+ rate: <%- schedule.rate %>
11
+ input: <%- JSON.stringify(schedule.input) %>
12
+ <%_ }) _%>
13
+ role: <%- roleName %>Role
14
+ #<#<%- functionName %><%- action %>IamRole#>
15
+ #<#/<%- functionName %><%- action %>IamRole#>
16
+ <%_ function firstLetterUpperCase(text){
17
+ return text.charAt(0).toUpperCase() + text.slice(1)
18
+ } _%>
19
+ <%_ function firstLetterLowerCase(str) {
20
+ return str.charAt(0).toLowerCase() + str.slice(1)
21
+ } _%>
@@ -0,0 +1,77 @@
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 path = require('path');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ // const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, checkOverWriteGenerateMainFunction } = require("../#utils");
25
+ // const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../#const");
26
+ const {
27
+ utils: {
28
+ firstLetterLowerCase: lowerCase,
29
+ firstLetterUpperCase: upperCase,
30
+ firstLetterUpperCase,
31
+ checkOverWriteGenerateMainFunction
32
+ },
33
+ consts: {
34
+ DEFAULT_HANDLER_PER_ACTION,
35
+ SOURCE_PATH,
36
+ FUNCTION_NAME,
37
+ SOURCE_GENERATE_IAM_ROLE
38
+ }
39
+ } = require("../../../../../../MainLibs");
40
+
41
+ const templatePath = path.join(__dirname, "./template.ejs")
42
+ /**
43
+ * receive objectSchema
44
+ * create data for hdrInv template
45
+ *
46
+ * @param {Object} _izContext
47
+ * @param {Object} flowSchema
48
+ * @param {String} srcPath
49
+ * @return {Object[]}
50
+ */
51
+ function data(_izContext, flowSchema, srcPath) {
52
+ const handler = HANDLER.hdrInv;
53
+ const flowTag = flowSchema.flowTag;
54
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
55
+ const functionName = flowTag + action;
56
+ const fileName = `${upperCase(flowTag)}${upperCase(action)}_${upperCase(handler)}`;
57
+ return [{
58
+ templatePath: templatePath,
59
+ templateData: {
60
+ functionName: functionName,
61
+ flowTag: flowTag,
62
+ action: action,
63
+ handler,
64
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
65
+ firstLetterUpperCase: upperCase,
66
+ },
67
+ setting: {
68
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
69
+ saveFileName: fileName,
70
+ fileExtension: '.js',
71
+ isAppend: false
72
+ }
73
+ }]
74
+ }
75
+
76
+
77
+ 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,64 @@
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 { middlewareHandler } = require("@izara_project/izara-middleware");
21
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
22
+ validateSchemaMiddleware
23
+ const {
24
+ validateSchemaMiddleware
25
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
26
+
27
+ const { <%- functionName %>Main } =require('./<%- firstLetterUpperCase(functionName)%>_Main')
28
+
29
+ //(<globalVariable>
30
+ //</globalVariable>)
31
+
32
+
33
+ //(<afterValidateWithGenereatedSchema>)
34
+ //(</afterValidateWithGenereatedSchema>)
35
+
36
+
37
+ module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
38
+ event._izContext.logger.debug('Event:', event);
39
+ event._izContext.logger.debug('context:', context);
40
+
41
+ try {
42
+
43
+ //(<beforeInvoke>)
44
+ //(</beforeInvoke>)
45
+
46
+ // invoke LambdaFunction
47
+ return await <%- functionName %>Main(
48
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
49
+ event,
50
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
51
+ );
52
+
53
+ } catch (err) {
54
+ event._izContext.logger.error('Error, <%- firstLetterUpperCase(flowTag) %>: ', err);
55
+ throw (err);
56
+ }
57
+ });
58
+
59
+ <%_ function firstLetterUpperCase(text){
60
+ return text.charAt(0).toUpperCase() + text.slice(1)
61
+ } _%>
62
+ <%_ function firstLetterLowerCase(str) {
63
+ return str.charAt(0).toLowerCase() + str.slice(1)
64
+ } _%>
@@ -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
+
20
+ const path = require('path');
21
+
22
+ const { consts: { ACTIONS, HANDLER } } = require('@izara_project/izara-core-library-service-schemas')
23
+
24
+ // const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../#utils");
25
+ // const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../#const");
26
+ const {
27
+ utils: {
28
+ firstLetterLowerCase: lowerCase,
29
+ firstLetterUpperCase: upperCase,
30
+ checkOverWriteGenerateMainFunction
31
+ },
32
+ consts: {
33
+ DEFAULT_HANDLER_PER_ACTION,
34
+ SOURCE_PATH,
35
+ SOURCE_GENERATE_IAM_ROLE
36
+ }
37
+ } = require("../../../../../MainLibs");
38
+
39
+ const templatePath = path.join(__dirname, "./template.ejs")
40
+
41
+ /**
42
+ * receive objectSchema
43
+ * create data for hdrInv template
44
+ *
45
+ * @param {Object} flowSchema
46
+ * @return {{ templatePath, templateData, setting } }
47
+ */
48
+ function data(_izContext, flowSchema, srcPath) {
49
+ const handler = HANDLER.hdrInv;
50
+ const flowTag = flowSchema.flowTag;
51
+ const functionName = flowTag + upperCase(handler);
52
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
53
+ const fileName = `${upperCase(flowTag)}${upperCase(action)}_Main`;
54
+ return [{
55
+ templatePath: templatePath,
56
+ templateData: {
57
+ functionName: functionName,
58
+ flowTag: flowTag,
59
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
60
+ action: action,
61
+ firstLetterUpperCase: upperCase,
62
+ },
63
+ setting: {
64
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
65
+ saveFileName: fileName,
66
+ fileExtension: '.js',
67
+ isAppend: false
68
+ }
69
+ }]
70
+ }
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,5 @@
1
+ {
2
+ "getDataDetail": "object",
3
+ "objectType": "string",
4
+ "functionName": "string"
5
+ }
@@ -0,0 +1,88 @@
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
16
+ <http: //www.gnu.org/licenses />.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ const {
22
+ getObjSchemaS3WithHierarchy,
23
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
24
+ const {
25
+ getGraphServiceTagWithCache,
26
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
27
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
28
+ const {
29
+ objInstanceFromobjInstanceBase
30
+ } = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
31
+
32
+ const {
33
+ dynamoDbIdentifiersByStorageResource,
34
+ collectGetData,
35
+ createGetDataDetails,
36
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
37
+
38
+ const { createObjTypeConcat } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
39
+
40
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
41
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
42
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
43
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
44
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
45
+
46
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
47
+ const sns = externalRequest.sns
48
+
49
+ const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
50
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
51
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
52
+
53
+ /**
54
+ *
55
+ *
56
+ * description of function.
57
+ * @param {Object} _izContext
58
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
59
+ * @param {Logger} _izContext.logger - property of _izContext
60
+ * @param {Object} requestParams - request params
61
+ * @param {Object} requestParams.identifiers - identifiers for get data
62
+ * @param {Object} requestParams.additionalRequest - additionalRequest
63
+ *
64
+ *
65
+ * @returns {object} description of return value
66
+ */
67
+ module.exports.<%- functionName %>Main = async (
68
+ _izContext,
69
+ requestParams,
70
+ callingFlowConfig = {},
71
+ //(<additionalParams>)
72
+ //(</additionalParams>)
73
+ ) => {
74
+
75
+
76
+ try {
77
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
78
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
79
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
80
+
81
+ //(<additionalParams>)
82
+ //(</additionalParams>)
83
+
84
+ } catch (err) {
85
+ _izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
86
+ throw (err)
87
+ }
88
+ }
@@ -55,7 +55,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
55
55
  firstLetterUpperCase: upperCase,
56
56
  },
57
57
  setting: {
58
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
58
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
59
59
  saveFileName: `${functionName}Out_${handlerType}`,
60
60
  fileExtension: ".js",
61
61
  isAppend: false
@@ -51,7 +51,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
51
51
  externalTopicOutMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Out',
52
52
  },
53
53
  setting: {
54
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
55
55
  saveFileName: `${functionName}Out_Main`,
56
56
  fileExtension: ".js",
57
57
  isAppend: false
@@ -54,7 +54,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
54
54
  flowTag
55
55
  },
56
56
  setting: {
57
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
57
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
58
58
  saveFileName: `${upperCase(functionName)}_${handlerType}`,
59
59
  fileExtension: ".js",
60
60
  isAppend: false
@@ -50,7 +50,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
50
50
  externalTopicMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Main',
51
51
  },
52
52
  setting: {
53
- savePath: path.join(srcPath, SOURCE_PATH.webSocket, flowSchema.flowTag + '/'),
53
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
54
54
  saveFileName: `${functionName}_Main`,
55
55
  fileExtension: ".js",
56
56
  isAppend: false
@@ -0,0 +1,89 @@
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 { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
+ const {
24
+ SOURCE_PATH,
25
+ defaultIamRolePerAction,
26
+ createIamRole,
27
+ RESOURCE_CLASSES,
28
+ SNS_RESOURCE,
29
+ resourceNames,
30
+ DYNAMO_RESOURCE,
31
+ SAVE_FILE_NAME,
32
+ FUNCTION_NAME,
33
+ shortNameHandler,
34
+ externalResourceYaml,
35
+ SOURCE_GENERATE_IAM_ROLE
36
+ } = require('../../../../../../MainLibs/src/Consts');
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('../../../../../../GenerateCodeLibs/src/Consts');
38
+
39
+ const templatePath = path.join(__dirname, "template.ejs");
40
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
41
+ /**
42
+ * receive objectSchema
43
+ * create data for WebScoket handler template
44
+ *
45
+ * @param {Object} objectSchema
46
+ * @return {{templatePath, templateData,setting}}
47
+ */
48
+
49
+ function data(_izContext, flowSchema, srcPath) {
50
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
51
+ }
52
+
53
+ function createSourceParams(_izContext, flowSchema, srcPath) {
54
+ let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
55
+ let handlerType = upperCase(HANDLER.hdrSqs)
56
+ let additionalResourcePermission = defaultIamRolePerAction();
57
+ let flowSteps = Object.keys(flowSchema.flowSteps)
58
+ additionalResourcePermission.push(
59
+ createIamRole(
60
+ {
61
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
62
+ },
63
+ [
64
+ resourceNames(RESOURCE_CLASSES.sns, flowSteps[1])
65
+ ]
66
+ )
67
+ )
68
+
69
+
70
+ return {
71
+ templatePath: templatePath,
72
+ templateData: {
73
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaOwnTopic, flowSchema.flowTag, "source/"),
74
+ functionName,
75
+ handlerType,
76
+ additionalResourcePermission,
77
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
78
+ roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaOwnTopic
79
+ },
80
+ setting: {
81
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
82
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
83
+ fileExtension: ".yml",
84
+ isAppend: true
85
+ }
86
+ }
87
+ }
88
+
89
+ module.exports = data;