@izara_project/izara-core-generate-service-code 1.0.33 → 1.0.35

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 (37) hide show
  1. package/package.json +1 -1
  2. package/src/generateCode/generateFlowSchema/GenerateCodeFlowSchema.js +1 -1
  3. package/src/generateCode/generateFlowSchema/event/s3Component/upload/preSignUrl/createPreSignUrl/mainFunction/template.ejs +1 -1
  4. package/src/generateCode/generateFlowSchema/flowSchemaMainFunction/template.ejs +11 -5
  5. package/src/generateCode/generateFlowSchema/flowStep/flowStep.js +3 -3
  6. package/src/generateCode/generateFlowSchema/statusType/statusFieldComponent/mainFunction/template.ejs +0 -2
  7. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/data.js +61 -0
  8. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/templateApi.ejs +84 -0
  9. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/templateWebSocket.ejs +64 -0
  10. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/mainFunction/data.js +52 -0
  11. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/mainFunction/template.ejs +76 -0
  12. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/yaml/data.js +86 -0
  13. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/yaml/template.ejs +18 -0
  14. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/handler/data.js +0 -0
  15. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/handler/template.ejs +0 -0
  16. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/mainFunction/data.js +45 -0
  17. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/mainFunction/template.ejs +82 -0
  18. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/yaml/data.js +0 -0
  19. package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/yaml/template.ejs +0 -0
  20. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/data.js +53 -0
  21. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateApi.ejs +84 -0
  22. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateDsq.ejs +105 -0
  23. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateInv.ejs +53 -0
  24. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateSqs.ejs +87 -0
  25. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +45 -0
  26. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +82 -0
  27. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/data.js +50 -0
  28. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/template.ejs +0 -0
  29. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/topicOut/data.js +45 -0
  30. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/yaml/data.js +47 -0
  31. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/yaml/template.ejs +28 -0
  32. package/src/generateCode/generateFlowStepWithPlugIn/index.js +259 -0
  33. package/src/generateCode/generateSchema/generateTextTag/systemText/data.js +68 -47
  34. package/src/generateCode/generateSchema/generateTextTag/systemText/template.ejs +6 -1
  35. package/src/generateCode/resourceYamlComponent/sns-out/template.ejs +4 -0
  36. package/src/generateCode.js +41 -32
  37. package/src/libs/Libs.js +106 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Code for locally generating per service files",
5
5
  "author": "Sven Mason <thebarbariansven@gmail.com>",
6
6
  "license": "AGPL-3.0-or-later",
@@ -86,7 +86,7 @@ async function generateTemplateDataFromFlowSchema(
86
86
  // ── per-flowSchema resources ─────────────────────────────────────────
87
87
  const perFlowParams = [
88
88
  createWebSocketGenerateCodeLibs(_izContext, flowSchema, appPath),
89
- ...buildFlowStepResources(_izContext, flowSchema, appPath)
89
+ // ...buildFlowStepResources(_izContext, flowSchema, appPath)
90
90
  ];
91
91
 
92
92
  if (!flowSchema.event.includes('s3')) {
@@ -177,7 +177,7 @@ export default async function createPresignUrl (
177
177
 
178
178
  // create PresignUrl
179
179
  let createPresignUrlParam = {
180
- Bucket: "<%- bucketName %>",
180
+ Bucket: process.env.iz_csvBucketName,
181
181
  Key: Key,
182
182
  Conditions: [
183
183
  //(<conditionCreateUrlLink>)
@@ -16,17 +16,25 @@ along with this program. If not, see
16
16
  <http: //www.gnu.org/licenses />.
17
17
  */
18
18
 
19
- import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
20
19
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
20
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
21
  import sqsSharedLib from '@izara_project/izara-core-library-sqs';
23
22
  import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
24
23
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
25
24
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
26
- import { lambda,sns,sqs } from '@izara_project/izara-core-library-external-request';
25
+
26
+ //(<optionalImport>)
27
+ import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
28
+ import {
29
+ lambda,
30
+ sns,
31
+ sqs
32
+ } from '@izara_project/izara-core-library-external-request';
27
33
  import { NoRetryError } from '@izara_project/izara-core-library-core';
28
- import { utils} from '@izara_project/izara-core-library-service-schemas';
34
+ import { utils } from '@izara_project/izara-core-library-service-schemas';
35
+
29
36
  const { createFlowTypeConcat } = utils;
37
+ //(</optionalImport>)
30
38
 
31
39
  <% if (statusType === "triggerCache") { -%>
32
40
  import { triggeredCacheSharedLibV2 } from '@izara_project/izara-core-library-trigger-cache';
@@ -36,8 +44,6 @@ import statusFieldSharedLib from '@izara_project/izara-core-library-status-field
36
44
  import storedCacheSharedLib from '@izara_project/izara-core-library-stored-cache';
37
45
  <% } -%>
38
46
 
39
- //(<optionalRequire>)
40
- //(</optionalRequire>)
41
47
  /**
42
48
  *
43
49
  *
@@ -206,9 +206,9 @@ function buildAfterPluginHookResources(
206
206
  resourceNames(
207
207
  RESOURCE_CLASSES.sqs,
208
208
  upperCase(flowTag) +
209
- upperCase(flowStepName) +
210
- currentIndex +
211
- 'HdrDsqDLQ'
209
+ upperCase(flowStepName) +
210
+ currentIndex +
211
+ 'HdrDsqDLQ'
212
212
  )
213
213
  ])
214
214
  );
@@ -16,8 +16,6 @@ along with this program. If not, see
16
16
  <http: //www.gnu.org/licenses />.
17
17
  */
18
18
 
19
-
20
-
21
19
  import statusFieldSharedLib from '@izara_project/izara-core-library-status-field';
22
20
 
23
21
  //(<optionalRequire>)
@@ -0,0 +1,61 @@
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
+ import path from 'path';
18
+ import { fileURLToPath } from 'url';
19
+ import consts from '#libs/Consts.js';
20
+ const { HANDLER, SOURCE_PATH } = consts;
21
+ import utils from '#libs/Utils.js';
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = utils;
23
+ import libs from '#libs/Libs.js';
24
+
25
+ const __filename = fileURLToPath(import.meta.url);
26
+ const __dirname = path.dirname(__filename);
27
+
28
+ const templatePathByHandler = {
29
+ [HANDLER.hdrApi]: path.join(__dirname, 'templateApi.ejs'),
30
+ 'hdrWbs': path.join(__dirname, 'templateWebSocket.ejs')
31
+ }
32
+
33
+
34
+ async function data(_izContext, data, appPath) {
35
+ console.log("data in handler recieve plug", data)
36
+ const createSources = [];
37
+ const functionName = 'recievePlugInHook' + upperCase(data.recieveType);
38
+ let handlerType;
39
+ if (data.recieveType === 'sync') {
40
+ handlerType = HANDLER.hdrApi;
41
+ } else if (data.recieveType === 'async') {
42
+ handlerType = 'hdrWbs';
43
+ };
44
+ console.log("handlerType", handlerType)
45
+ createSources.push({
46
+ templatePath: templatePathByHandler[handlerType],
47
+ templateData: {
48
+ functionName: upperCase(functionName),
49
+ route: functionName
50
+ },
51
+ setting: {
52
+ savePath: path.join(appPath, SOURCE_PATH.flowSchema, `${upperCase(data.flowTag)}`, `${data.flowStepName}`, 'source/'),
53
+ saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
54
+ fileExtension: '.js',
55
+ isAppend: true
56
+ }
57
+ });
58
+ return createSources;
59
+ }
60
+
61
+ export default data;
@@ -0,0 +1,84 @@
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
+ const RBAC_TARGET_ID = process.env.iz_rbacTargetIdUser // iz_rbacTargetIdUser | iz_rbacDeliveryMethodId
19
+
20
+ import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
21
+ import Logger from '@izara_project/izara-core-library-logger';
22
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
+
24
+ import <%- functionName %> from './<%- functionName %>_Main.js';
25
+
26
+ // validate event params in middleware before into function.
27
+ let validatorSchema = {
28
+ //(<validatorSchema>)
29
+ //(</validatorSchema>)
30
+ };
31
+ // NOTE: not sure about remap_when_flatten and remove_when_flatten function of api still require for validate or not? Tam(19-Nov) -- Yes
32
+
33
+ // for auth userLevel
34
+ // if (process.env.iz_rbacTargetIdUser) {
35
+ // validatorSchema["required"] = ['pathParameters'];
36
+ // validatorSchema.properties.pathParameters = {
37
+ // additionalProperties: false,
38
+ // type: ['object', 'boolean'],
39
+ // required: [process.env.iz_rbacTargetIdUser],
40
+ // properties: {
41
+ // }
42
+ // };
43
+ // validatorSchema.properties.pathParameters.properties[process.env.iz_rbacTargetIdUser] = {
44
+ // type: 'string'
45
+ // };
46
+ //}
47
+ // If not have Authorizer set setMiddlewareSettings.
48
+ middleware.setValidatorSchema(validatorSchema, { noAuthorizer: true })
49
+
50
+ // // default user Authorizer.
51
+ // middleware.setValidatorSchema(validatorSchema)
52
+
53
+
54
+ export const main = middleware.wrap(async (event, context, callback) => {
55
+ event._izContext.logger.debug('Event:', event);
56
+ try {
57
+
58
+ // for targetUserId
59
+ // let targetUserId = null
60
+ // if (process.env.iz_rbacTargetIdUser) {
61
+ // targetUserId = event.pathParameters[process.env.iz_rbacTargetIdUser]
62
+ // }
63
+ // invoke LambdaFunction
64
+ let lambdaFunctionResponse = await <%- functionName %>(
65
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
66
+ event.body,
67
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
68
+ //(<additionalParams>)
69
+ //(</additionalParams>)
70
+ );
71
+
72
+ // return error to client
73
+ if (lambdaFunctionResponse instanceof Error) {
74
+ return (response.failure(lambdaFunctionResponse));
75
+ }
76
+
77
+ // return success to client
78
+ return (response.success(lambdaFunctionResponse));
79
+
80
+ } catch (err) {
81
+ event._izContext.logger.error('Error, LambdaFunctionHdrApi: ', err);
82
+ return (response.failure(err));
83
+ }
84
+ });
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright (C) 2021 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
+ import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
19
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
20
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
21
+ const { postToConnection } = webSocket;
22
+
23
+ export const main = middleware.wrap(async (event, context) => {
24
+
25
+ event._izContext.logger.debug('Event:', event);
26
+
27
+ try {
28
+ if (event.requestContext) {
29
+ const route = event.requestContext.routeKey;
30
+ switch (route) {
31
+ case '$default':
32
+ console.log('Received unknown route:', route);
33
+ break
34
+ case '<%- route %>':
35
+ console.log("event in route webSocket", event);
36
+ let eventParams = JSON.parse(event.body)
37
+
38
+ let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
39
+ await <%- functionName %>(
40
+ event._izContext,
41
+ eventParams,
42
+ //(<additionalParams>)
43
+ //(</additionalParams>)
44
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
45
+ )
46
+
47
+ break
48
+ }
49
+ } else {
50
+ const connId = event.connId;
51
+ // await postMessage({ message: event.message }, connId);
52
+ await postToConnection({ message: event.message }, connId);
53
+ }
54
+
55
+ return (response.webSocketSuccess());
56
+
57
+ } catch (err) {
58
+ const connId = event.requestContext.connectionId
59
+ event._izContext.logger.error('Error, WebSocket: ', err);
60
+ // await sendErrorMessage({ message: err.message }, connId);
61
+ await postToConnection({ message: err.message }, connId);
62
+ return (response.failure(err));
63
+ }
64
+ });
@@ -0,0 +1,52 @@
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
+ import path from 'path';
18
+ import { fileURLToPath } from 'url';
19
+ import consts from '#libs/Consts.js';
20
+ const { HANDLER, SOURCE_PATH } = consts;
21
+ import utils from '#libs/Utils.js';
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = utils;
23
+ import libs from '#libs/Libs.js';
24
+
25
+ const __filename = fileURLToPath(import.meta.url);
26
+ const __dirname = path.dirname(__filename);
27
+
28
+ const templatePath = path.join(__dirname, 'template.ejs')
29
+
30
+
31
+ async function data(_izContext, data, appPath) {
32
+ const functionName = 'recievePlugInHook';
33
+ let flowType = data.flowType || {}
34
+
35
+ return {
36
+ templatePath: templatePath,
37
+ templateData: {
38
+ recieveType: data.recieveType,
39
+ flowTag: flowType ? flowType.flowTag : null,
40
+ serviceTag: flowType ? flowType.serviceTag : null,
41
+ functionName
42
+ },
43
+ setting: {
44
+ savePath: path.join(appPath, SOURCE_PATH.flowSchema, `${upperCase(data.flowTag)}`, `${data.flowStepName}`, 'source/'),
45
+ saveFileName: `${upperCase(functionName)}${upperCase(data.recieveType)}_Main`,
46
+ fileExtension: '.js',
47
+ isAppend: false
48
+ }
49
+ }
50
+ }
51
+
52
+ export default data;
@@ -0,0 +1,76 @@
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
+ <% if (recieveType === 'async') { %>
20
+ import { sns } from '@izara_project/izara-core-library-external-request'
21
+ import snsSahredLib from '@izara_project/izara-core-library-sns'
22
+ <% } %>
23
+
24
+ //(<optionalRequire>)
25
+ //(</optionalRequire>)
26
+ /**
27
+ *
28
+ *
29
+ * description of function.
30
+ * @param {Object} _izContext
31
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
32
+ * @param {Logger} _izContext.logger - property of _izContext
33
+ * @param {Object} requestParams - request params
34
+ * @param {Object} requestParams.identifiers - identifiers for get data
35
+ * @param {Object} requestParams.additionalRequest - additionalRequest
36
+ *
37
+ *
38
+ * @returns {object} description of return value
39
+ */
40
+
41
+ export default async function <%- functionName %> (
42
+ _izContext,
43
+ requestParams,
44
+ callingFlowConfig = {},
45
+ //(<additionalParams>)
46
+ //(</additionalParams>)
47
+ ) {
48
+
49
+ try {
50
+ _izContext.logger.debug("<%- functionName %> _izContext", _izContext)
51
+ _izContext.logger.debug("<%- functionName %> requestParams", requestParams)
52
+ _izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
53
+
54
+ //(<endpointHook>)
55
+ <% if (recieveType === 'async') { -%>
56
+ let messageObject = {};
57
+ <% } -%>
58
+
59
+ <% if (recieveType === 'async') { -%>
60
+ let sendMessageTo<%- flowTag %> = {
61
+ Message: JSON.stringify(messageObject),
62
+ TopicArn: snsSahredLib.snsTopicArnByFlowSchema(_izContext, "<%- flowTag %>_In", <%- serviceTag %>)
63
+ };
64
+
65
+ _izContext.logger.debug("before sendMessageTo <%- flowTag %>", sendMessageTo<%- flowTag %>)
66
+ await sns.publishAsync(_izContext, sendMessageTo<%- flowTag %>);
67
+ <% } -%>
68
+ //(</endpointHook>)
69
+
70
+
71
+
72
+ } catch (err) {
73
+ _izContext.logger.error('error WebSocketInvoke: ', err)
74
+ throw (err)
75
+ }
76
+ }
@@ -0,0 +1,86 @@
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
+ import path from 'path';
18
+ import yaml from 'yaml';
19
+ import { fileURLToPath } from 'url';
20
+ import consts from '#libs/Consts.js';
21
+ const { HANDLER, SOURCE_PATH, SAVE_FILE_NAME, RESOURCE_CLASSES } = consts;
22
+ import utils from '#libs/Utils.js';
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = utils;
24
+ import libs from '#libs/Libs.js';
25
+ const { defaultIamRolePerAction, createIamRole, resourceNames } = libs;
26
+
27
+ const __filename = fileURLToPath(import.meta.url);
28
+ const __dirname = path.dirname(__filename);
29
+
30
+ const templatePath = path.join(__dirname, 'template.ejs')
31
+
32
+
33
+ async function data(_izContext, data, appPath) {
34
+ const createSources = [];
35
+ const configPath = path.join(appPath, '../config/serverless.config.yml');
36
+ const serverlessConfig = fs.readFileSync(configPath, 'utf8');
37
+ const config = yaml.parse(serverlessConfig);
38
+ const serviceTag = config.main_config.iz_serviceTag;
39
+
40
+ const functionName = 'recievePlugInHook' + upperCase(data.recieveType)
41
+ let handlerType;
42
+ const additionalResourcePremission = defaultIamRolePerAction();
43
+
44
+ if (data.recieveType === 'sync') {
45
+ handlerType = HANDLER.hdrApi;
46
+ } else if (data.recieveType === 'async') {
47
+ handlerType = 'hdrWbs';
48
+ additionalResourcePremission.push(
49
+ createIamRole(
50
+ {
51
+ 'execute-api': ['ManageConnections']
52
+ },
53
+ [resourceNames(RESOURCE_CLASSES.webSocket)]
54
+ )
55
+ )
56
+ };
57
+
58
+ const functionNameConfig = upperCase(functionName) + upperCase(handlerType);
59
+ const roleName = data.roleName;
60
+
61
+ createSources.push({
62
+ templatePath: templatePath,
63
+ templateData: {
64
+ serviceTag,
65
+ functionName: upperCase(functionName),
66
+ functionNameConfig,
67
+ additionalResourcePremission,
68
+ roleName,
69
+ event: 'post',
70
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, `${data.flowTag}`, `${data.flowStepName}`, 'source/'),
71
+ handlerType: upperCase(handlerType),
72
+ lowerCase,
73
+ route: functionName
74
+ },
75
+ setting: {
76
+ savePath: path.join(appPath, SOURCE_PATH.appYaml),
77
+ saveFileName: SAVE_FILE_NAME.flowSchemaYaml,
78
+ fileExtension: '.yml',
79
+ isAppend: true
80
+ }
81
+ })
82
+
83
+ return createSources;
84
+ }
85
+
86
+ export default data;
@@ -0,0 +1,18 @@
1
+ <%- functionNameConfig %>:
2
+ handler: <%- `${resourceLocation}${functionName}_${handlerType}.main` %>
3
+ name: ${self:custom.iz_resourcePrefix}<%- functionName %><%- handlerType %>
4
+ role: <%- roleName %>Role
5
+ #<#<%- functionName %><%- handlerType %>FunctionSetting#>
6
+ #<#/<%- functionName %><%- handlerType %>FunctionSetting#>
7
+ events:
8
+ <% if (handlerType === 'HdrApi') { %>
9
+ - httpApi:
10
+ path: /<%- serviceTag %>/<%- lowerCase(functionName) %>/
11
+ method: <%- event %>
12
+ - httpApi:
13
+ path: /<%- serviceTag %>/<%- lowerCase(functionName) %>/{targetUserId}
14
+ method: <%- event %>
15
+ <% } else if (handlerType === 'HdrWbs') { %>
16
+ - websocket:
17
+ route: <%- route %>
18
+ <% } %>
@@ -0,0 +1,45 @@
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
+ import path from 'path';
19
+ import { fileURLToPath } from 'url';
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ import consts from '#libs/Consts.js';
24
+ import utils from '#libs/Utils.js';
25
+
26
+ const { firstLetterUpperCase: upperCase } = utils;
27
+ const { SOURCE_PATH, SAVE_FILE_NAME } = consts;
28
+ const templatePath = path.join(__dirname, 'template.ejs');
29
+
30
+
31
+ async function data(_izContext, data, appPath) {
32
+ console.log("data", data)
33
+ return {
34
+ templatePath: templatePath,
35
+ templateData: { ...data },
36
+ setting: {
37
+ savePath: path.join(appPath, SOURCE_PATH.flowSchema, `${upperCase(data.flowTag)}`, `${data.flowStepName}`, 'source/'),
38
+ saveFileName: `${upperCase(data.functionName)}_Main`,
39
+ fileExtension: '.js',
40
+ isAppend: false
41
+ }
42
+ }
43
+ }
44
+
45
+ export default data;
@@ -0,0 +1,82 @@
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
+ <% if (havePlugIn) { -%>
19
+ <% if (invokeType === 'sync') { -%>
20
+ import { api } from '@izara_project/izara-core-library-external-request';
21
+ <% } else if (invokeType === 'async') { -%>
22
+ import { webSocket } from '@izara_project/izara-core-library-external-request'
23
+ <% } -%>
24
+ <% } -%>
25
+
26
+ //(<optionalRequire>)
27
+ //(</optionalRequire>)
28
+
29
+ /**
30
+ *
31
+ *
32
+ * description of function.
33
+ * @param {Object} _izContext
34
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
35
+ * @param {Logger} _izContext.logger - property of _izContext
36
+ * @param {Object} requestParams - request params
37
+ * @param {Object} requestParams.identifiers - identifiers for get data
38
+ * @param {Object} requestParams.additionalRequest - additionalRequest
39
+ *
40
+ *
41
+ * @returns {object} description of return value
42
+ */
43
+ export default async function <%- functionName %>(
44
+ _izContext,
45
+ requestParams,
46
+ callingFlowConfig = {},
47
+ //(<additionalParams>)
48
+ //(</additionalParams>)
49
+ ) {
50
+
51
+
52
+ try {
53
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
54
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
55
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
56
+
57
+ //(<hookCode>)
58
+ <% if (havePlugIn) { -%>
59
+ <% if (invokeType === 'async') { -%>
60
+ let messageObject = {
61
+ action: "recievePlugInRequestAsync"
62
+ };
63
+ <% } -%>
64
+ <% } -%>
65
+
66
+
67
+ //(</hookCode>)
68
+
69
+
70
+ <% if (havePlugIn) { -%>
71
+ <% if (invokeType === 'sync') { -%>
72
+ await api.invokeLambdaApi(_izContext, "<%- targetUrl %>", messageObject)
73
+ <% } else if (invokeType === 'async') { -%>
74
+ await webSocket.invokeWebSocket(_izContext, "<%- targetUrl %>", messageObject)
75
+ <% } -%>
76
+ <% } -%>
77
+
78
+ } catch (err) {
79
+ _izContext.logger.error('error AFlowStepsMain: ', err)
80
+ throw (err)
81
+ }
82
+ }