@izara_project/izara-core-generate-service-code 1.0.39 → 1.0.40

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 (29) hide show
  1. package/package.json +6 -6
  2. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/data.js +56 -0
  3. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templateAwaitingStep.ejs +105 -0
  4. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templatePaginated.ejs +137 -0
  5. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/data.js +57 -0
  6. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templateAwaitingStep.ejs +129 -0
  7. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templatePaginated.ejs +59 -0
  8. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/data.js +50 -0
  9. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/queueNoTopic.ejs +43 -0
  10. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/snsTemplate.ejs +58 -0
  11. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/sqsTemplate.ejs +43 -0
  12. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/data.js +47 -0
  13. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/template.ejs +43 -0
  14. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/data.js +7 -1
  15. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +38 -6
  16. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +5 -16
  17. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/awaitingSteps.ejs +63 -0
  18. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/templateSendPlugin.ejs +18 -0
  19. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/sqsTemplate.ejs +7 -7
  20. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/topicOut/data.js +1 -1
  21. package/src/generateCode/generateFlowStepWithPlugIn/index(old).js +290 -0
  22. package/src/generateCode/generateFlowStepWithPlugIn/index.js +411 -155
  23. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/data.js +22 -0
  24. package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/data.js +16 -0
  25. package/src/generateCode/generateSchema/actionEndpointCompleteComponent/create/mainFunction/template.ejs +44 -4
  26. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/create/main/template.ejs +58 -40
  27. package/src/libs/Libs.js +21 -15
  28. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/request.json +0 -18
  29. package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/request.json +0 -12
@@ -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 %>HdrDsq:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrDsq
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>HdrDsqDLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrDsqDLQ
18
+
19
+ <%- queueName %>HdrDsqPolicy:
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 %>HdrDsq
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>HdrDsq
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
+ } _%>
@@ -0,0 +1,47 @@
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
+ function data(_izContext, data, appPath) {
31
+ if (data.handleLogic === 'awaitingMultipleSteps') {
32
+ data.callingFlow = 'haveCallingFlow'
33
+ }
34
+ return {
35
+ templatePath: templatePath,
36
+ templateData: { ...data },
37
+ setting: {
38
+ savePath: path.join(appPath, SOURCE_PATH.appYaml),
39
+ saveFileName: SAVE_FILE_NAME.flowSchemaYaml,
40
+ fileExtension: '.yml',
41
+ isAppend: true
42
+ }
43
+ }
44
+ }
45
+
46
+
47
+ export default data;
@@ -0,0 +1,43 @@
1
+ <%- functionNameConfig %>:
2
+ handler: <%- handlerPath %>
3
+ name: ${self:custom.iz_resourcePrefix}<%- functionName %>
4
+ role: <%- roleName %>Role
5
+ #<#<%- hookTagSetting %>#>
6
+ #<#/<%- hookTagSetting %>#>
7
+ <%_ if (handlerType === 'hdrDsq' || handlerType === 'hdrSqs') { _%>
8
+ events:
9
+ - sqs:
10
+ arn: <%- event %>
11
+ batchSize: 10
12
+ <% if (callingFlow) { %>
13
+ filterPatterns: #**** need to update serverless framework upper v.2.69.1
14
+ - body: {
15
+ 'MessageAttributes':
16
+ {
17
+ 'callingFlow':
18
+ { 'Value': ['${self:custom.iz_resourcePrefix}<%- flowTag %><%- flowStepName %><%- handleLogic %>'] }
19
+ }
20
+ } # functionName of callingFlow
21
+ - body:
22
+ {
23
+ 'MessageAttributes':
24
+ { 'callingFlow': { 'Value': [{ 'exists': false }] } }
25
+ }
26
+ <% } %>
27
+ <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
28
+ events:
29
+ <%_ resourceApis.forEach(api => { _%>
30
+ - httpApi:
31
+ path: <%- api.path %>
32
+ method: <%- api.method %>
33
+ #<#<%- api.hookTagApp %>#>
34
+ # authorizer: authorizerServiceSchema
35
+ #<#/<%- api.hookTagApp %>#>
36
+ - httpApi:
37
+ path: <%- api.pathWithUser %>
38
+ method: <%- api.method %>
39
+ #<#<%- api.hookTagUser %>#>
40
+ # authorizer: authorizerIdentifiers
41
+ #<#/<%- api.hookTagUser %>#>
42
+ <%_ }) _%>
43
+ <%_ } _%>
@@ -42,7 +42,13 @@ async function data(_izContext, data, appPath) {
42
42
  ...data,
43
43
  },
44
44
  setting: {
45
- savePath: path.join(appPath, SOURCE_PATH.flowSchema, `${upperCase(data.flowTag)}`, `${upperCase(data.flowStepName)}`, 'source/'),
45
+ savePath: path.join(
46
+ appPath,
47
+ SOURCE_PATH.flowSchema,
48
+ `${upperCase(data.flowTag)}`,
49
+ `${upperCase(data.flowStepName)}`,
50
+ 'source/'
51
+ ),
46
52
  saveFileName: `${upperCase(data.functionName)}_${upperCase(data.handlerType)}`,
47
53
  fileExtension: '.js',
48
54
  isAppend: true
@@ -19,20 +19,52 @@ import path from 'path';
19
19
  import { fileURLToPath } from 'url';
20
20
  const __filename = fileURLToPath(import.meta.url);
21
21
  const __dirname = path.dirname(__filename);
22
-
22
+ import { NoRetryError } from '@izara_project/izara-core-library-core';
23
23
  import consts from '#libs/Consts.js';
24
24
  import utils from '#libs/Utils.js';
25
-
26
- const { firstLetterUpperCase: upperCase } = utils;
25
+ import libs from '#libs/Libs.js'
26
+ const { getLocalOrS3FlowSchema, } = libs
27
+ const { firstLetterUpperCase: upperCase, getLocalConfig } = utils;
27
28
  const { SOURCE_PATH, SAVE_FILE_NAME } = consts;
28
29
  const templatePath = path.join(__dirname, 'template.ejs');
29
-
30
+ const templateSendPlugin = path.join(__dirname, './templateByConfig/templateSendPlugin.ejs');
31
+ const templateAwaitingStep = path.join(__dirname, './templateByConfig/awaitingSteps.ejs');
30
32
 
31
33
  async function data(_izContext, data, appPath) {
32
- console.log("data", data)
34
+
35
+ const [mainFlow] = await getLocalOrS3FlowSchema(
36
+ _izContext,
37
+ {
38
+ serviceTag: getLocalConfig('iz_serviceTag'),
39
+ flowTag: data.flowTag,
40
+ },
41
+ path.join(
42
+ appPath, './src/schemas')
43
+ );
44
+
45
+ const [childFlow] = await getLocalOrS3FlowSchema(
46
+ _izContext,
47
+ data.childFlow,
48
+ path.join(
49
+ appPath, './src/schemas')
50
+ );
51
+
52
+ if (mainFlow.hasOwnProperty('objType')) {
53
+ data['mainObjType'] = mainFlow.objType;
54
+ };
55
+
56
+ if (!childFlow) {
57
+ throw new NoRetryError(`can't get ${childFlow.flowTag} from s3 or local`);
58
+ };
59
+
60
+ if (childFlow && childFlow.hasOwnProperty('objType')) {
61
+ data['childObjType'] = childFlow.objType;
62
+ };
63
+
64
+
33
65
  return {
34
66
  templatePath: templatePath,
35
- templateData: { ...data },
67
+ templateData: { ...data, templateSendPlugin, templateAwaitingStep },
36
68
  setting: {
37
69
  savePath: path.join(
38
70
  appPath,
@@ -55,24 +55,13 @@ export default async function <%- functionName %>(
55
55
  _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
56
56
 
57
57
  //(<hookCode>)
58
- <% if (havePlugIn) { -%>
59
- <% if (invokeType === 'async') { -%>
60
- let messageObject = {
61
- action: "recievePlugInRequestAsync"
62
- };
63
- <% } -%>
64
- <% } -%>
65
-
66
-
67
- //(</hookCode>)
68
-
58
+ //(<hookCode>)
69
59
 
60
+ <% if (handleLogic === 'awaitingMultipleSteps') { %>
61
+ <%- include(templateAwaitingStep, { childFlow, mainObjType, childObjType }) %>
62
+ <% } %>
70
63
  <% 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
- <% } -%>
64
+ <%- include(templateSendPlugin, {havePlugIn: havePlugIn, invokeType: invokeType, targetUrl: targetUrl}) %>
76
65
  <% } -%>
77
66
 
78
67
  } catch (err) {
@@ -0,0 +1,63 @@
1
+ const allAwaitingStepsId = [];
2
+
3
+ allAwaitingStepsId.push(
4
+ {
5
+ awaitingStepId: asyncFlowSharedLib.createAwaitingStepId(
6
+ hash({
7
+ //(<createAwaitingStepIds>)
8
+ //(</createAwaitingStepIds>)
9
+ }),
10
+ "<%- firstLetterUpperCase(flowTag) %><%- firstLetterUpperCase(flowStepName)%>"
11
+ )
12
+ }
13
+ )
14
+
15
+ await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
16
+ _izContext,
17
+ allAwaitingStepsId,
18
+ asyncFlowSharedLib.createPendingStepId(
19
+ hash({
20
+ <% if (mainObjType) { -%>
21
+ objType: {
22
+ serviceTag: "<%- mainObjType.serviceTag %>",
23
+ objectType: "<%- mainObjType.objectType %>"
24
+ },
25
+ //(<createPendingStepIds>)
26
+ //(</createPendingStepIds>)
27
+ <% } else { -%>
28
+ xCorrelationId: _izContext.correlationIds.xCorrelationId,
29
+ //(<createPendingStepIds>)
30
+ //(</createPendingStepIds>)
31
+ <% } %>
32
+ }),
33
+ "<%- firstLetterUpperCase(flowTag) %><%- firstLetterUpperCase(flowStepName)%><%- firstLetterUpperCase(handleLogic) %>"
34
+ )
35
+ );
36
+
37
+ //(<afterCreateAwatingSteps>)
38
+
39
+ let messageObject = {
40
+
41
+ };
42
+
43
+ messageObject = messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
44
+ messageObject,
45
+ callingFlowSharedLib.addParentCallingFlowConfig(
46
+ callingFlowConfig,
47
+ callingFlowSharedLib.createCallingFlowConfig(
48
+ //(<callingFlowProperties>)
49
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "<%- firstLetterUpperCase(flowTag) %><%- firstLetterUpperCase(flowStepName) %><%- firstLetterUpperCase(handleLogic) %>"), {}
50
+ //(</callingFlowProperties>)
51
+ )
52
+ )
53
+ );
54
+
55
+ await sns.publishAsync(_izContext, {
56
+ Message: JSON.stringify(messageObject),
57
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- childFlow.flowTag %>_In", "<%- childFlow.serviceTag %>")
58
+ });
59
+ //(</afterCreateAwatingSteps>)
60
+
61
+ <%_ function firstLetterUpperCase(text) {
62
+ return text.charAt(0).toUpperCase() + text.slice(1);
63
+ } -%>
@@ -0,0 +1,18 @@
1
+ //(<createParams>)
2
+ <% if (havePlugIn) { -%>
3
+ <% if (invokeType === 'async') { -%>
4
+ let messageObject = {
5
+ action: "recievePlugInRequestAsync"
6
+ };
7
+ <% } -%>
8
+ <% } -%>
9
+ //(</createParams>)
10
+
11
+
12
+ <% if (havePlugIn) { -%>
13
+ <% if (invokeType === 'sync') { -%>
14
+ await api.invokeLambdaApi(_izContext, "<%- targetUrl %>", messageObject)
15
+ <% } else if (invokeType === 'async') { -%>
16
+ await webSocket.invokeWebSocket(_izContext, "<%- targetUrl %>", messageObject)
17
+ <% } -%>
18
+ <% } -%>
@@ -1,8 +1,8 @@
1
1
  #------- queue ---------
2
- <%- queueName %>:
2
+ <%- queueName %>HdrDsq:
3
3
  Type: "AWS::SQS::Queue"
4
4
  Properties:
5
- QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrDsq
6
6
  RedrivePolicy:
7
7
  deadLetterTargetArn: #!GetAtt
8
8
  Fn::GetAtt:
@@ -11,12 +11,12 @@
11
11
  maxReceiveCount: 3
12
12
  VisibilityTimeout: 120
13
13
 
14
- <%- queueName %>DLQ:
14
+ <%- queueName %>HdrDsqDLQ:
15
15
  Type: AWS::SQS::Queue
16
16
  Properties:
17
- QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrDsqDLQ
18
18
 
19
- <%- queueName %>Policy:
19
+ <%- queueName %>HdrDsqPolicy:
20
20
  Type: AWS::SQS::QueuePolicy
21
21
  Properties:
22
22
  PolicyDocument:
@@ -27,11 +27,11 @@
27
27
  Principal: "*"
28
28
  Resource: #!GetAtt
29
29
  Fn::GetAtt:
30
- - <%- queueName %>
30
+ - <%- queueName %>HdrDsq
31
31
  - Arn
32
32
  Action: "SQS:SendMessage"
33
33
  Queues:
34
- - Ref: <%- queueName %>
34
+ - Ref: <%- queueName %>HdrDsq
35
35
  #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
36
  #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
37
 
@@ -28,7 +28,7 @@ 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
- const queueName = `${upperCase(data.flowTag)}_${upperCase(data.flowStepName)}`;
31
+ const queueName = `${upperCase(data.flowTag)}${upperCase(data.flowStepName)}`;
32
32
 
33
33
  return {
34
34
  templatePath: templatePath,