@izara_project/izara-market-library-service-schemas 1.0.62 → 1.0.64
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 +1 -1
- package/src/GenerateCodeLibs/src/Consts.js +7 -3
- package/src/MainLibs/src/Consts.js +6 -2
- package/src/reStructure/GenerateCode.js +1 -1
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -8
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +114 -83
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +8 -0
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +11 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +13 -7
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +3 -2
- package/src/reStructure/TemplateData/flowSchema/register/complete/handler/template.ejs +1 -0
- package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +3 -1
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/template.ejs +20 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/data.js +122 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/template.ejs +17 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/template.ejs +13 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/template.ejs +17 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/data.js +57 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/template.ejs +155 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/data.js +58 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/template.ejs +202 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/template.ejs +144 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/template.ejs +181 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +382 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/data.js +77 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/snsTemplate.ejs +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/sqsTemplate.ejs +43 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/data.js +121 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/data.js +60 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/template.ejs +129 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/template.ejs +154 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/data.js +71 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/template.ejs +46 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/data.js +71 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/template.ejs +10 -0
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +55 -2
|
@@ -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 {
|
|
23
|
+
HANDLER,
|
|
24
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
25
|
+
|
|
26
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/index.js").utils;
|
|
27
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../../../../MainLibs/index.js").consts;
|
|
28
|
+
const snsTemplatePath = path.join(__dirname, "./snsTemplate.ejs")
|
|
29
|
+
const sqsTemplatePath = path.join(__dirname, "./sqsTemplate.ejs")
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} _izContext
|
|
35
|
+
* @param {String} saveFilePath
|
|
36
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function createRelationshipSnsInSqs(_izContext, srcPath) {
|
|
40
|
+
let resultForCreateRelationshipSnsAndSqs = [];
|
|
41
|
+
const setting = {
|
|
42
|
+
initialData: "Resources:\n",
|
|
43
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
44
|
+
saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
|
|
45
|
+
fileExtension: ".yml",
|
|
46
|
+
isAppend: true
|
|
47
|
+
}
|
|
48
|
+
const createRelationshipQueueNames = [
|
|
49
|
+
{
|
|
50
|
+
queueName: upperCase(FUNCTION_NAME.changeRel)
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
queueName: upperCase(FUNCTION_NAME.changeRel) + upperCase(HANDLER.hdrDsq)
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
for (let createRelationshipQueueName of createRelationshipQueueNames) {
|
|
57
|
+
if (createRelationshipQueueName.queueName.includes("HdrDsq")) {
|
|
58
|
+
resultForCreateRelationshipSnsAndSqs.push({
|
|
59
|
+
templatePath: sqsTemplatePath,
|
|
60
|
+
templateData: createRelationshipQueueName,
|
|
61
|
+
setting: setting
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
} else {
|
|
65
|
+
resultForCreateRelationshipSnsAndSqs.push(
|
|
66
|
+
{
|
|
67
|
+
templatePath: snsTemplatePath,
|
|
68
|
+
templateData: createRelationshipQueueName,
|
|
69
|
+
setting: setting
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return resultForCreateRelationshipSnsAndSqs
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = createRelationshipSnsInSqs
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
|
8
|
+
##===== [Topic In]
|
|
9
|
+
SubscriptionIn<%- queueName %>:
|
|
10
|
+
Type: AWS::SNS::Subscription
|
|
11
|
+
Properties:
|
|
12
|
+
TopicArn: !Ref In<%- queueName %>
|
|
13
|
+
Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
|
|
14
|
+
Protocol: "sqs"
|
|
15
|
+
##===== [Queue]
|
|
16
|
+
<%- queueName %>HdrSqs:
|
|
17
|
+
Type: "AWS::SQS::Queue"
|
|
18
|
+
Properties:
|
|
19
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
|
|
20
|
+
RedrivePolicy:
|
|
21
|
+
deadLetterTargetArn:
|
|
22
|
+
# !GetAtt
|
|
23
|
+
Fn::GetAtt:
|
|
24
|
+
- <%- queueName %>HdrSqsDLQ
|
|
25
|
+
- Arn
|
|
26
|
+
maxReceiveCount: 3
|
|
27
|
+
VisibilityTimeout: 120
|
|
28
|
+
##==== [QueueDLQ]
|
|
29
|
+
<%- queueName %>HdrSqsDLQ:
|
|
30
|
+
Type: AWS::SQS::Queue
|
|
31
|
+
Properties:
|
|
32
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
|
|
33
|
+
##==== [QueuePolicy]
|
|
34
|
+
<%- queueName %>HdrSqsPolicy:
|
|
35
|
+
Type: AWS::SQS::QueuePolicy
|
|
36
|
+
Properties:
|
|
37
|
+
PolicyDocument:
|
|
38
|
+
Version: "2012-10-17"
|
|
39
|
+
Statement:
|
|
40
|
+
- Sid: "allow-sns-messages"
|
|
41
|
+
Effect: Allow
|
|
42
|
+
Principal: "*"
|
|
43
|
+
Resource:
|
|
44
|
+
# !GetAtt
|
|
45
|
+
Fn::GetAtt:
|
|
46
|
+
- <%- queueName %>HdrSqs
|
|
47
|
+
- Arn
|
|
48
|
+
Action: "SQS:SendMessage"
|
|
49
|
+
Queues:
|
|
50
|
+
- Ref: <%- queueName %>HdrSqs
|
|
51
|
+
#<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
52
|
+
#<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
53
|
+
|
|
54
|
+
<%_ function firstLetterUpperCase(text){
|
|
55
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
56
|
+
} _%>
|
|
57
|
+
<%_ function firstLetterLowerCase(str) {
|
|
58
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
59
|
+
} _%>
|
|
@@ -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
|
+
} _%>
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
|
+
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/index.js").utils;
|
|
24
|
+
const {
|
|
25
|
+
createIamRole,
|
|
26
|
+
resourceNames,
|
|
27
|
+
RESOURCE_CLASSES,
|
|
28
|
+
SQS_RESOURCE,
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
SAVE_FILE_NAME,
|
|
31
|
+
FUNCTION_NAME,
|
|
32
|
+
defaultIamRolePerAction,
|
|
33
|
+
awaitingMultipleStepsRole,
|
|
34
|
+
SNS_RESOURCE,
|
|
35
|
+
shortNameHandler,
|
|
36
|
+
SHORT_FUNCTION_NAME,
|
|
37
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
38
|
+
} = require("../../../../../../MainLibs/src/Consts.js");
|
|
39
|
+
|
|
40
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* receive objectSchema
|
|
44
|
+
* create data for updateRelationshipSchema
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} objectSchema
|
|
47
|
+
* @return {{ templatePath, templateData, setting } }
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
function data(_izContext, srcPath) {
|
|
51
|
+
let createSourceArray = [];
|
|
52
|
+
const createSourceParam = createParamForCreateSource(srcPath);
|
|
53
|
+
createSourceArray.push(createSourceParam);
|
|
54
|
+
return createSourceArray
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function createParamForCreateSource(srcPath) {
|
|
59
|
+
let handlerType = upperCase(HANDLER.hdrSqs);
|
|
60
|
+
let functionName = FUNCTION_NAME.changeRelComplete
|
|
61
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
62
|
+
|
|
63
|
+
additionalResourcePermission.push(
|
|
64
|
+
createIamRole(
|
|
65
|
+
{
|
|
66
|
+
[RESOURCE_CLASSES.sqs]: [
|
|
67
|
+
SQS_RESOURCE.deleteMessage,
|
|
68
|
+
SQS_RESOURCE.getQueueAttributes,
|
|
69
|
+
SQS_RESOURCE.receiveMessage,
|
|
70
|
+
SQS_RESOURCE.sendMessage,
|
|
71
|
+
SQS_RESOURCE.deleteMessageBatch,
|
|
72
|
+
SQS_RESOURCE.getQueueUrl,
|
|
73
|
+
],
|
|
74
|
+
|
|
75
|
+
},
|
|
76
|
+
[
|
|
77
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)),
|
|
78
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + "DLQ"),
|
|
79
|
+
|
|
80
|
+
],
|
|
81
|
+
),
|
|
82
|
+
createIamRole(
|
|
83
|
+
{
|
|
84
|
+
[RESOURCE_CLASSES.sns]:
|
|
85
|
+
[
|
|
86
|
+
SNS_RESOURCE.publish, SNS_RESOURCE.subscribe
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
[
|
|
90
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(functionName) + "_In"),
|
|
91
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(functionName) + "_Out")
|
|
92
|
+
]
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
additionalResourcePermission.push(awaitingMultipleStepsRole())
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
templatePath: templatePath,
|
|
102
|
+
templateData: {
|
|
103
|
+
functionName,
|
|
104
|
+
handlerType,
|
|
105
|
+
additionalResourcePermission,
|
|
106
|
+
resourceLocation: SOURCE_PATH.resourceLocationRelationshipPerAction,
|
|
107
|
+
functionNameConfig: upperCase(SHORT_FUNCTION_NAME.changeRelComplete),
|
|
108
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole
|
|
109
|
+
},
|
|
110
|
+
setting: {
|
|
111
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
112
|
+
saveFileName: SAVE_FILE_NAME.functionRelationshipYaml,
|
|
113
|
+
fileExtension: '.yml',
|
|
114
|
+
isAppend: true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
module.exports = data;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%_ const join = require('path').join; _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns: #**** need to update serverless framework upper v.2.69.1
|
|
10
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%-firstLetterUpperCase(functionName) %>"]}}} # functionName of callingFlow
|
|
11
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
12
|
+
role: <%- roleName %>Role
|
|
13
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
14
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
15
|
+
<%_ function firstLetterUpperCase(text){
|
|
16
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
17
|
+
} _%>
|
|
18
|
+
<%_ function firstLetterLowerCase(str) {
|
|
19
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
20
|
+
} _%>
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
|
+
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/index.js").utils;
|
|
24
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../../MainLibs/index.js").consts;
|
|
25
|
+
|
|
26
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* receive objectSchema
|
|
30
|
+
* create data for hdrInv template
|
|
31
|
+
*
|
|
32
|
+
* @return {{ templatePath, templateData, setting } }
|
|
33
|
+
*/
|
|
34
|
+
function data(_izContext, srcPath) {
|
|
35
|
+
const createSourceParams = createParamForCreateSource(srcPath)
|
|
36
|
+
return [createSourceParams];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
function createParamForCreateSource(srcPath) {
|
|
41
|
+
const functionName = FUNCTION_NAME.changeRelComplete;
|
|
42
|
+
const handler = HANDLER.hdrSqs
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
templatePath: templatePath,
|
|
46
|
+
templateData: {
|
|
47
|
+
functionName: upperCase(functionName),
|
|
48
|
+
queueName: upperCase(functionName) + upperCase(handler),
|
|
49
|
+
},
|
|
50
|
+
setting: {
|
|
51
|
+
savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
|
|
52
|
+
saveFileName: `${upperCase(functionName)}_${upperCase(handler)}`,
|
|
53
|
+
fileExtension: '.js',
|
|
54
|
+
isAppend: false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
module.exports = data;
|
|
@@ -0,0 +1,129 @@
|
|
|
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 AWS = require('aws-sdk');
|
|
21
|
+
// const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
|
|
22
|
+
|
|
23
|
+
const izara = require("@izara_project/izara-middleware");
|
|
24
|
+
const middleware = izara.middlewareHandler;
|
|
25
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
26
|
+
const recordHandlerSharedLib = require('@izara_project/izara-core-library-record-handler');
|
|
27
|
+
|
|
28
|
+
const changeRelationshipComplete = require('./ChangeRelationshipComplete_Main');
|
|
29
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
32
|
+
// set schema for record.body.Message
|
|
33
|
+
let perRecordsValidatorSchema = {
|
|
34
|
+
type: "object",
|
|
35
|
+
required: [
|
|
36
|
+
'returnValue',
|
|
37
|
+
'status',
|
|
38
|
+
'errorsFound',
|
|
39
|
+
'graphServiceTag'
|
|
40
|
+
],
|
|
41
|
+
properties: {
|
|
42
|
+
returnValue: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
},
|
|
45
|
+
status: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
},
|
|
48
|
+
errorsFound: {
|
|
49
|
+
type: 'array',
|
|
50
|
+
default: []
|
|
51
|
+
},
|
|
52
|
+
graphServiceTag: {
|
|
53
|
+
type: 'string'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// set schema for record.body.MessageAttributes
|
|
59
|
+
// const messageAttributeValidatorSchema = {
|
|
60
|
+
// type: "object",
|
|
61
|
+
// required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
62
|
+
// properties: {
|
|
63
|
+
// msgAtrrParam1: {
|
|
64
|
+
// type: "string"
|
|
65
|
+
// },
|
|
66
|
+
// msgAtrrParam2: {
|
|
67
|
+
// type: "object"
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// };
|
|
71
|
+
|
|
72
|
+
perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema); // is Ok passBackProperties
|
|
73
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
|
|
77
|
+
let recordPromises = [];
|
|
78
|
+
|
|
79
|
+
// loop each record and send to mainFunction
|
|
80
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
81
|
+
|
|
82
|
+
let passOnProperties = []
|
|
83
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
84
|
+
|
|
85
|
+
//validate message (and MessageAttributes)
|
|
86
|
+
await recordHandlerSharedLib.validateRecord(
|
|
87
|
+
record, // one record will send to mainFunction
|
|
88
|
+
"ChangeRelationshipComplete", // queue name that need to retry or send to dlq
|
|
89
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
90
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
94
|
+
passOnProperties.push(record.body.Message.returnValue)
|
|
95
|
+
passOnProperties.push(record.body.Message.status)
|
|
96
|
+
passOnProperties.push(record.body.Message.errorsFound)
|
|
97
|
+
passOnProperties.push(record.body.Message.graphServiceTag)
|
|
98
|
+
passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
|
|
99
|
+
// passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callingFlow
|
|
100
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
101
|
+
|
|
102
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
103
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
104
|
+
record, // one record will send to mainFunction
|
|
105
|
+
changeRelationshipComplete.changeRelationshipComplete, // mainFunction that need to invoke.
|
|
106
|
+
"ChangeRelationshipComplete", // queue name that need to retry or send to dlq
|
|
107
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
108
|
+
);
|
|
109
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
110
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
111
|
+
}))
|
|
112
|
+
|
|
113
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
114
|
+
try {
|
|
115
|
+
// --- main await all promises
|
|
116
|
+
await Promise.all(recordPromises); // await all promises
|
|
117
|
+
|
|
118
|
+
return event.Records // return all for local testing
|
|
119
|
+
|
|
120
|
+
} catch {
|
|
121
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
122
|
+
}
|
|
123
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
124
|
+
|
|
125
|
+
} catch (err) {
|
|
126
|
+
Logger.error('Unhandled Error, CreateRelationshipCompleteHdrSqs: ', err);
|
|
127
|
+
throw (err);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
|
+
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/index.js").utils;
|
|
24
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts.js");
|
|
25
|
+
|
|
26
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* receive objectSchema
|
|
30
|
+
* create data for hdrInv template
|
|
31
|
+
*
|
|
32
|
+
* @return {{ templatePath, templateData, setting } }
|
|
33
|
+
*/
|
|
34
|
+
function data(_izContext, srcPath) {
|
|
35
|
+
const createSourceParams = createParamForCreateSource(srcPath)
|
|
36
|
+
return [createSourceParams];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
function createParamForCreateSource(srcPath) {
|
|
41
|
+
const functionName = FUNCTION_NAME.changeRelComplete;
|
|
42
|
+
return {
|
|
43
|
+
templatePath: templatePath,
|
|
44
|
+
templateData: {
|
|
45
|
+
},
|
|
46
|
+
setting: {
|
|
47
|
+
savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
|
|
48
|
+
saveFileName: `${upperCase(functionName)}_Main`,
|
|
49
|
+
fileExtension: '.js',
|
|
50
|
+
isAppend: false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = data;
|