@izara_project/izara-core-generate-service-code 1.0.34 → 1.0.36

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
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",
@@ -39,13 +39,13 @@ async function data(_izContext, data, appPath) {
39
39
 
40
40
  const functionName = 'recievePlugInHook' + upperCase(data.recieveType)
41
41
  let handlerType;
42
- const additionalResourcePremission = defaultIamRolePerAction();
42
+ const additionalResourcePermission = defaultIamRolePerAction();
43
43
 
44
44
  if (data.recieveType === 'sync') {
45
45
  handlerType = HANDLER.hdrApi;
46
46
  } else if (data.recieveType === 'async') {
47
47
  handlerType = 'hdrWbs';
48
- additionalResourcePremission.push(
48
+ additionalResourcePermission.push(
49
49
  createIamRole(
50
50
  {
51
51
  'execute-api': ['ManageConnections']
@@ -64,7 +64,7 @@ async function data(_izContext, data, appPath) {
64
64
  serviceTag,
65
65
  functionName: upperCase(functionName),
66
66
  functionNameConfig,
67
- additionalResourcePremission,
67
+ additionalResourcePermission,
68
68
  roleName,
69
69
  event: 'post',
70
70
  resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, `${data.flowTag}`, `${data.flowStepName}`, 'source/'),
@@ -7,7 +7,7 @@
7
7
  events:
8
8
  <% if (handlerType === 'HdrApi') { %>
9
9
  - httpApi:
10
- path: /<%- serviceTag %>/<%- lowerCase(functionName) %>/
10
+ path: /<%- serviceTag %>/<%- lowerCase(functionName) %>
11
11
  method: <%- event %>
12
12
  - httpApi:
13
13
  path: /<%- serviceTag %>/<%- lowerCase(functionName) %>/{targetUserId}
@@ -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
+ }
@@ -54,7 +54,7 @@ export default async function <%- functionName %>(
54
54
  _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
55
55
  _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
56
56
 
57
- //(<AFlowStepsHook>)
57
+ //(<hookCode>)
58
58
  <% if (havePlugIn) { -%>
59
59
  <% if (invokeType === 'async') { -%>
60
60
  let messageObject = {
@@ -64,8 +64,7 @@ export default async function <%- functionName %>(
64
64
  <% } -%>
65
65
 
66
66
 
67
- // add properties to messageObject invoke lambda
68
- //(</AFlowStepsHook>)
67
+ //(</hookCode>)
69
68
 
70
69
 
71
70
  <% if (havePlugIn) { -%>
@@ -26,9 +26,9 @@ import utils from '#libs/Utils.js';
26
26
  const { firstLetterUpperCase: upperCase } = utils;
27
27
  const { SOURCE_PATH, SAVE_FILE_NAME, HANDLER } = consts;
28
28
  const templatePathByHandler = {
29
- [HANDLER.hdrDsq]: path.join(__dirname, '../../../resourceYamlComponent/sns-in-sqs/sqsTemplate.ejs'),
30
- [HANDLER.hdrSqs]: path.join(__dirname, '../../../resourceYamlComponent/sns-in-sqs/snsTemplate.ejs'),
31
- queueNoTopic: path.join(__dirname, '../../../resourceYamlComponent/sns-in-sqs/sqsTemplate.ejs')
29
+ [HANDLER.hdrDsq]: path.join(__dirname, './sqsTemplate.ejs'),
30
+ [HANDLER.hdrSqs]: path.join(__dirname, './snsTemplate.ejs'),
31
+ queueNoTopic: path.join(__dirname, './sqsTemplate.ejs')
32
32
  };
33
33
 
34
34
  async function data(_izContext, data, appPath) {
@@ -0,0 +1,58 @@
1
+ ##===== [Create topic in]
2
+ In<%- queueName %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message in"
6
+ TopicName: ${self:custom.iz_serviceTag}_${self:custom.iz_stage}_<%- queueName %>_In
7
+ ##===== SNS Subscription [Topic In] =====##
8
+ SubscriptionIn<%- queueName %>:
9
+ Type: AWS::SNS::Subscription
10
+ Properties:
11
+ TopicArn: !Ref In<%- queueName %>
12
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
13
+ Protocol: "sqs"
14
+ ##===== [Queue]
15
+ <%- queueName %>HdrSqs:
16
+ Type: "AWS::SQS::Queue"
17
+ Properties:
18
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
19
+ RedrivePolicy:
20
+ deadLetterTargetArn:
21
+ # !GetAtt
22
+ Fn::GetAtt:
23
+ - <%- queueName %>HdrSqsDLQ
24
+ - Arn
25
+ maxReceiveCount: 3
26
+ VisibilityTimeout: 120
27
+ ##==== [QueueDLQ]
28
+ <%- queueName %>HdrSqsDLQ:
29
+ Type: AWS::SQS::Queue
30
+ Properties:
31
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
32
+ ##==== [QueuePolicy]
33
+ <%- queueName %>HdrSqsPolicy:
34
+ Type: AWS::SQS::QueuePolicy
35
+ Properties:
36
+ PolicyDocument:
37
+ Version: "2012-10-17"
38
+ Statement:
39
+ - Sid: "allow-sns-messages"
40
+ Effect: Allow
41
+ Principal: "*"
42
+ Resource:
43
+ # !GetAtt
44
+ Fn::GetAtt:
45
+ - <%- queueName %>HdrSqs
46
+ - Arn
47
+ Action: "SQS:SendMessage"
48
+ Queues:
49
+ - Ref: <%- queueName %>HdrSqs
50
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
51
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
52
+
53
+ <%_ function firstLetterUpperCase(text){
54
+ return text.charAt(0).toUpperCase() + text.slice(1)
55
+ } _%>
56
+ <%_ function firstLetterLowerCase(str) {
57
+ return str.charAt(0).toLowerCase() + str.slice(1)
58
+ } _%>
@@ -0,0 +1,43 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>DLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
+
19
+ <%- queueName %>Policy:
20
+ Type: AWS::SQS::QueuePolicy
21
+ Properties:
22
+ PolicyDocument:
23
+ Version: "2012-10-17"
24
+ Statement:
25
+ - Sid: "allow-sns-messages"
26
+ Effect: Allow
27
+ Principal: "*"
28
+ Resource: #!GetAtt
29
+ Fn::GetAtt:
30
+ - <%- queueName %>
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>
35
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
+
38
+ <%_ function firstLetterUpperCase(text){
39
+ return text.charAt(0).toUpperCase() + text.slice(1)
40
+ } _%>
41
+ <%_ function firstLetterLowerCase(str) {
42
+ return str.charAt(0).toLowerCase() + str.slice(1)
43
+ } _%>
@@ -28,7 +28,6 @@ const { SOURCE_PATH, SAVE_FILE_NAME, HANDLER } = consts;
28
28
  const templatePath = path.join(__dirname, '../../../resourceYamlComponent/sns-out/template.ejs')
29
29
 
30
30
  async function data(_izContext, data, appPath) {
31
- console.log("generate sns out")
32
31
  const queueName = `${upperCase(data.flowTag)}_${upperCase(data.flowStepName)}`;
33
32
 
34
33
  return {
@@ -81,10 +81,10 @@ async function generatePlunIg(
81
81
  const roleName = upperCase(flowTag);
82
82
  const resourceApis = [];
83
83
  let handler;
84
- const additionalResourcePremission = defaultIamRolePerAction();
84
+ const additionalResourcePermission = defaultIamRolePerAction();
85
85
 
86
86
  const data = {
87
- additionalResourcePremission: additionalResourcePremission,
87
+ additionalResourcePermission: additionalResourcePermission,
88
88
  flowStepName: flowStepName,
89
89
  flowTag: flowTag,
90
90
  resourceApis: resourceApis,
@@ -96,7 +96,7 @@ async function generatePlunIg(
96
96
  if (flowStepConfig.event.includes("ownTopic")) {
97
97
  data['eventFlow'] = 'ownTopic'
98
98
  handler = HANDLER.hdrSqs;
99
- additionalResourcePremission.push(
99
+ additionalResourcePermission.push(
100
100
  createSnsResource(
101
101
  [
102
102
  upperCase(flowSchema.flowTag) + upperCase(flowStepName) + "_In"
@@ -112,7 +112,7 @@ async function generatePlunIg(
112
112
  } else if (flowStepConfig.event.includes("extTopic")) {
113
113
  data['eventFlow'] = 'extTopic'
114
114
  handler = HANDLER.hdrSqs;
115
- additionalResourcePremission.push(
115
+ additionalResourcePermission.push(
116
116
  createSqsResource(
117
117
  [
118
118
  upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
@@ -133,7 +133,7 @@ async function generatePlunIg(
133
133
  })
134
134
  } else if (flowStepConfig.event.includes("queue")) {
135
135
  handler = HANDLER.hdrDsq;
136
- additionalResourcePremission.push(
136
+ additionalResourcePermission.push(
137
137
  createSqsResource(
138
138
  [
139
139
  upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
@@ -154,7 +154,7 @@ async function generatePlunIg(
154
154
  ),
155
155
  functionNameConfig: upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
156
156
  event: resourceNames(RESOURCE_CLASSES.sqs, upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler)),
157
- queueName: upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
157
+ queueName: upperCase(flowSchema.flowTag) + upperCase(flowStepName),
158
158
  })
159
159
 
160
160
  const yamlFlowStepRes = await yamlFlowStep(_izContext, data, appPath);
@@ -222,6 +222,9 @@ async function generatePlunIg(
222
222
  }
223
223
  }
224
224
  }
225
+ } else {
226
+ mainResult = await mainFunctionFlowStep(_izContext, { ...data, havePlugIn: false }, appPath);
227
+ allCreateSourceParams.push(mainResult);
225
228
  }
226
229
  }
227
230
  }
@@ -68,7 +68,9 @@ function createSourceSystemText(
68
68
  };
69
69
  const systemTextObjectSchemas = {
70
70
  nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
71
- systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
71
+ systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}`, // for each fieldName
72
+ openHook: `//(<${coreUtils.createObjTypeConcat(_izContext, objType)}${fieldName}Hook>)`,
73
+ closeHook: `//(</${coreUtils.createObjTypeConcat(_izContext, objType)}${fieldName}Hook>)`
72
74
  };
73
75
  createSourceArray.push(systemTextObjectSchemas);
74
76
  }
@@ -83,7 +85,9 @@ function createSourceSystemText(
83
85
  };
84
86
  const systemTextFlowSchemas = {
85
87
  nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
86
- systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
88
+ systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`,
89
+ openHook: `//(<${coreUtils.createFlowTypeConcat(_izContext, flowType)}Hook>)`,
90
+ closeHook: `//(</${coreUtils.createFlowTypeConcat(_izContext, flowType)}Hook>)`
87
91
  };
88
92
  createSourceArray.push(systemTextFlowSchemas);
89
93
  }
@@ -101,7 +105,9 @@ function createSourceSystemText(
101
105
  for (const fieldName of Object.keys(relSchema[relTag].fieldNames)) {
102
106
  const systemTextRelSchemas = {
103
107
  nameSpace: `${coreUtils.createRelTypeConcat(_izContext, relType)}_description`,
104
- systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`
108
+ systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`,
109
+ openHook: `//(<${coreUtils.createRelTypeConcat(_izContext, relType)}${fieldName}Hook>)`,
110
+ closeHook: `//(</${coreUtils.createRelTypeConcat(_izContext, relType)}${fieldName}Hook>)`
105
111
  }
106
112
  createSourceArray.push(systemTextRelSchemas);
107
113
  }
@@ -113,7 +119,9 @@ function createSourceSystemText(
113
119
  for (const notification of notificationSchemas) {
114
120
  const notificationSystemText = {
115
121
  nameSpace: `sysNotification_${notification.notificationGrouping}`,
116
- systemTextTag: notification.notificationTag
122
+ systemTextTag: notification.notificationTag,
123
+ openHook: `//(<${notification.notificationTag}Hook>)`,
124
+ closeHook: `//(</${notification.notificationTag}Hook>)`
117
125
  }
118
126
  createSourceArray.push(notificationSystemText)
119
127
  }
@@ -127,7 +135,11 @@ function createSourceSystemText(
127
135
  saveFileName: SAVE_FILE_NAME.systemTextSchema,
128
136
  fileExtension: '.js',
129
137
  isAppend: true,
130
- generateHookFile: false
138
+ hookPath: path.join(
139
+ schemaPath,
140
+ '../schemaHook/'
141
+ ),
142
+ // generateHookFile: false
131
143
  }
132
144
  };
133
145
  }
@@ -1,5 +1,10 @@
1
1
  export default [
2
2
  <% datas.forEach((data, index) => { -%>
3
- <%- JSON.stringify(data,null,2) %><%= index < datas.length - 1 ? ',' : '' %>
3
+ {
4
+ nameSpace: "<%- data.nameSpace %>",
5
+ systemTextTag: "<%- data.systemTextTag %>",
6
+ <%- data.openHook %>
7
+ <%- data.closeHook %>
8
+ }<%= index < datas.length - 1 ? ',' : '' %>
4
9
  <% }); -%>
5
10
  ];