@izara_project/izara-market-library-service-schemas 1.0.34 → 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.
- package/package.json +1 -1
- package/src/GenerateCodeLibs/src/Consts.js +2 -1
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +5 -5
- package/src/MainLibs/src/Consts.js +43 -10
- package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
- package/src/reStructure/GenerateCode.js +1 -0
- package/src/reStructure/SchemaConfig.js +1 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +3 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +28 -44
- package/src/reStructure/TemplateData/attributeTreeSchema/{mainAttributeTreeSchema → mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTree/data.js +134 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/data.js +172 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +96 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +138 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +133 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +12 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +19 -6
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +19 -2
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +142 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +89 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +120 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
- package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +3 -6
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +7 -9
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +8 -43
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +1 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +7 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +18 -7
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +7 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +52 -13
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +2 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +1 -6
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +1 -29
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +67 -6
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +20 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/generateTemplateData.js +66 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/data.js +151 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/templateObjectPropertyNodeSchema.ejs +16 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/data.js +179 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/templateRelationshipPropertyNodeSchema.ejs +7 -0
- package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
- /package/src/reStructure/TemplateData/attributeTreeSchema/{mainAttributeTreeSchema → mainAttributeTree}/request.json +0 -0
|
@@ -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
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils.js");
|
|
29
|
+
const STORAGE_TYPES = {
|
|
30
|
+
dynamoDB: "dynamoDB",
|
|
31
|
+
graph: "graph"
|
|
32
|
+
}
|
|
33
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
34
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
|
|
35
|
+
const { TOPIC_NAME_GENERATE_CODE } = require("../../../../../GenerateCodeLibs/src/Consts.js");
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* create data for dynamoDbYaml tempalte from objectSchema
|
|
39
|
+
* return array of dynamoDb data
|
|
40
|
+
* because one objectSchema can create multiple dynamoDb table
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} _izContext
|
|
43
|
+
* @param {String} saveFilePath
|
|
44
|
+
* @returns {Object[]} - data of multiple dynamoDb template
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
|
|
48
|
+
let resultsForCreateDefaultSnsInSqs = [];
|
|
49
|
+
|
|
50
|
+
const setting = {
|
|
51
|
+
initialData: "Resources:\n",
|
|
52
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
53
|
+
saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
|
|
54
|
+
fileExtension: ".yml",
|
|
55
|
+
isAppend: true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const generatedSnsTopicInForFlowSchema = [
|
|
59
|
+
{
|
|
60
|
+
queueName: upperCase(FUNCTION_NAME.createRecordComplete) + upperCase(flowSchema.flowTag) + upperCase(HANDLER.hdrSqs),
|
|
61
|
+
subScription: upperCase(TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
for (let defaultSnsInSqsData of generatedSnsTopicInForFlowSchema) {
|
|
67
|
+
resultsForCreateDefaultSnsInSqs.push({
|
|
68
|
+
templatePath: templatePath,
|
|
69
|
+
templateData: defaultSnsInSqsData,
|
|
70
|
+
setting: setting
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return resultsForCreateDefaultSnsInSqs;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = createDataForDefaultSnsInSqs;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Subscription<%- queueName-%>:
|
|
2
|
+
Type: AWS::SNS::Subscription
|
|
3
|
+
Properties:
|
|
4
|
+
TopicArn: !Ref <%- subScription %>
|
|
5
|
+
Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
|
|
6
|
+
Protocol: "sqs"
|
|
7
|
+
#------- queue ---------
|
|
8
|
+
<%- queueName %>:
|
|
9
|
+
Type: "AWS::SQS::Queue"
|
|
10
|
+
Properties:
|
|
11
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
|
|
12
|
+
RedrivePolicy:
|
|
13
|
+
deadLetterTargetArn: #!GetAtt
|
|
14
|
+
Fn::GetAtt:
|
|
15
|
+
- <%- queueName %>DLQ
|
|
16
|
+
- Arn
|
|
17
|
+
maxReceiveCount: 3
|
|
18
|
+
VisibilityTimeout: 120
|
|
19
|
+
|
|
20
|
+
<%- queueName %>DLQ:
|
|
21
|
+
Type: AWS::SQS::Queue
|
|
22
|
+
Properties:
|
|
23
|
+
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
|
|
24
|
+
|
|
25
|
+
<%- queueName %>Policy:
|
|
26
|
+
Type: AWS::SQS::QueuePolicy
|
|
27
|
+
Properties:
|
|
28
|
+
PolicyDocument:
|
|
29
|
+
Version: "2012-10-17"
|
|
30
|
+
Statement:
|
|
31
|
+
- Sid: "allow-sns-messages"
|
|
32
|
+
Effect: Allow
|
|
33
|
+
Principal: "*"
|
|
34
|
+
Resource: #!GetAtt
|
|
35
|
+
Fn::GetAtt:
|
|
36
|
+
- <%- queueName %>
|
|
37
|
+
- Arn
|
|
38
|
+
Action: "SQS:SendMessage"
|
|
39
|
+
Queues:
|
|
40
|
+
- Ref: <%- queueName %>
|
|
41
|
+
#<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
42
|
+
#<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
|
|
43
|
+
|
|
44
|
+
<%_ function firstLetterUpperCase(text){
|
|
45
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
46
|
+
} _%>
|
|
47
|
+
<%_ function firstLetterLowerCase(str) {
|
|
48
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
49
|
+
} _%>
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs
CHANGED
|
@@ -32,13 +32,13 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
32
32
|
switch (eventType) {
|
|
33
33
|
case 'CONNECT':
|
|
34
34
|
console.log('Connect websocket')
|
|
35
|
-
//(<
|
|
36
|
-
//(</
|
|
35
|
+
//(<webSocketConnect>)
|
|
36
|
+
//(</webSocketConnect>)
|
|
37
37
|
break
|
|
38
38
|
case 'DISCONNECT':
|
|
39
39
|
console.log('Websocket are Disconnection')
|
|
40
|
-
//(<
|
|
41
|
-
//(</
|
|
40
|
+
//(<webSocketDisconnect>)
|
|
41
|
+
//(</webSocketDisconnect>)
|
|
42
42
|
break
|
|
43
43
|
case '$default':
|
|
44
44
|
console.log('Received unknown route:', route)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const path = require('path');
|
|
21
|
+
|
|
22
|
+
const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
|
|
24
|
+
const { firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
25
|
+
const {
|
|
26
|
+
SOURCE_PATH,
|
|
27
|
+
defaultIamRolePerAction,
|
|
28
|
+
createIamRole,
|
|
29
|
+
RESOURCE_CLASSES,
|
|
30
|
+
SNS_RESOURCE,
|
|
31
|
+
resourceNames,
|
|
32
|
+
DYNAMO_RESOURCE,
|
|
33
|
+
SAVE_FILE_NAME,
|
|
34
|
+
FUNCTION_NAME,
|
|
35
|
+
shortNameHandler,
|
|
36
|
+
externalResourceYaml,
|
|
37
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
38
|
+
} = require("../../../../../../MainLibs/src/Consts");
|
|
39
|
+
|
|
40
|
+
const templatePath = path.join(__dirname, "template.ejs");
|
|
41
|
+
const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
|
|
42
|
+
/**
|
|
43
|
+
* receive objectSchema
|
|
44
|
+
* create data for WebSocket handler template
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} objectSchema
|
|
47
|
+
* @return {{templatePath, templateData,setting}}
|
|
48
|
+
*/
|
|
49
|
+
function data(_izContext, srcPath) {
|
|
50
|
+
const handlerType = upperCase("hdrSqs");
|
|
51
|
+
const functionName = FUNCTION_NAME.flowSchemaRegister;
|
|
52
|
+
let functionNameConfig = upperCase(functionName) + upperCase(shortNameHandler(handlerType));
|
|
53
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
54
|
+
additionalResourcePermission.push(
|
|
55
|
+
// createIamRole(
|
|
56
|
+
// {
|
|
57
|
+
// [RESOURCE_CLASSES.sns]: [
|
|
58
|
+
// SNS_RESOURCE.publish
|
|
59
|
+
// ]
|
|
60
|
+
// },
|
|
61
|
+
// [
|
|
62
|
+
// resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
|
|
63
|
+
// ]
|
|
64
|
+
// ),
|
|
65
|
+
createIamRole(
|
|
66
|
+
{
|
|
67
|
+
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
68
|
+
DYNAMO_RESOURCE.putItem,
|
|
69
|
+
DYNAMO_RESOURCE.getItem,
|
|
70
|
+
DYNAMO_RESOURCE.query,
|
|
71
|
+
DYNAMO_RESOURCE.deleteItem,
|
|
72
|
+
DYNAMO_RESOURCE.updateItem
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
[
|
|
76
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
|
|
77
|
+
]
|
|
78
|
+
),
|
|
79
|
+
createIamRole(
|
|
80
|
+
{
|
|
81
|
+
"execute-api": [
|
|
82
|
+
"ManageConnections"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
[
|
|
86
|
+
resourceNames(RESOURCE_CLASSES.webSocket)
|
|
87
|
+
]
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
// if (flowSchema?.hook) {
|
|
92
|
+
// for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
|
|
93
|
+
// if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
|
|
94
|
+
// for (const hookFunction of hookProperties.functionList) {
|
|
95
|
+
// if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
|
|
96
|
+
// if (hookFunction?.permission) {
|
|
97
|
+
// for (const permission of hookFunction.permission) {
|
|
98
|
+
// additionalResourcePermission.push(
|
|
99
|
+
// createIamRole(
|
|
100
|
+
// permission.action,
|
|
101
|
+
// permission.resource.map(resource =>
|
|
102
|
+
// externalResourceYaml(
|
|
103
|
+
// resource.resource,
|
|
104
|
+
// resource.resourceName,
|
|
105
|
+
// resource.serviceTag),
|
|
106
|
+
// permission.effect
|
|
107
|
+
// )
|
|
108
|
+
// )
|
|
109
|
+
// )
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
// }
|
|
117
|
+
|
|
118
|
+
// console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
|
|
119
|
+
return [{
|
|
120
|
+
templatePath: templatePath,
|
|
121
|
+
templateData: {
|
|
122
|
+
resourceLocation: SOURCE_PATH.resourceLocationFlowSchemaRegister,
|
|
123
|
+
additionalResourcePermission,
|
|
124
|
+
functionName,
|
|
125
|
+
handlerType,
|
|
126
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.RegisterRole,
|
|
127
|
+
functionNameConfig,
|
|
128
|
+
},
|
|
129
|
+
setting: {
|
|
130
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
131
|
+
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
132
|
+
fileExtension: ".yml",
|
|
133
|
+
isAppend: true
|
|
134
|
+
}
|
|
135
|
+
}]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
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) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- 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
|
+
} _%>
|
package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js
ADDED
|
@@ -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
|
+
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
|
+
|
|
23
|
+
const { SOURCE_PATH, FUNCTION_NAME, SOURCE_GENERATE_IAM_ROLE } = require("../../../../../../MainLibs/src/Consts");
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
25
|
+
const templatePath = path.join(__dirname, "template.ejs")
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* receive objectSchema
|
|
29
|
+
* create data for SQS handler template
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} objectSchema
|
|
32
|
+
* @return {{templatePath, templateData,setting}}
|
|
33
|
+
*/
|
|
34
|
+
function data(_izContext, srcPath) {
|
|
35
|
+
let queueName = FUNCTION_NAME.flowSchemaRegister + upperCase(HANDLER.hdrSqs);
|
|
36
|
+
let functionName = FUNCTION_NAME.flowSchemaRegister + 'Complete'
|
|
37
|
+
let handlerType = upperCase(HANDLER.hdrSqs);
|
|
38
|
+
return [{
|
|
39
|
+
templatePath: templatePath,
|
|
40
|
+
templateData: {
|
|
41
|
+
queueName,
|
|
42
|
+
functionName: functionName,
|
|
43
|
+
handler: HANDLER.hdrSqs,
|
|
44
|
+
firstLetterUpperCase: upperCase,
|
|
45
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.RegisterRole
|
|
46
|
+
},
|
|
47
|
+
setting: {
|
|
48
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaRegister, 'source/'),
|
|
49
|
+
saveFileName: `${upperCase(functionName)}_${handlerType}`,
|
|
50
|
+
fileExtension: ".js",
|
|
51
|
+
isAppend: false
|
|
52
|
+
}
|
|
53
|
+
}]
|
|
54
|
+
}
|
|
55
|
+
module.exports = data
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { middlewareHandler } = require("@izara_project/izara-middleware");
|
|
24
|
+
const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
|
|
25
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
26
|
+
|
|
27
|
+
const { <%- functionName %>Main } =require('./<%- firstLetterUpperCase(functionName) %>_Main.js')
|
|
28
|
+
|
|
29
|
+
// validate event properties in body.Message of sqs event
|
|
30
|
+
middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
31
|
+
|
|
32
|
+
module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
|
|
36
|
+
let recordPromises = [];
|
|
37
|
+
|
|
38
|
+
// loop each record and send to mainFunction
|
|
39
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
40
|
+
|
|
41
|
+
let passOnProperties = []
|
|
42
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
43
|
+
|
|
44
|
+
//validate message (and MessageAttributes)
|
|
45
|
+
await recordHandlerSharedLib.validateRecord(
|
|
46
|
+
record, // one record will send to mainFunction
|
|
47
|
+
"<%- firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
|
|
48
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
49
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
53
|
+
passOnProperties.push(record.body.Message)
|
|
54
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
55
|
+
|
|
56
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
57
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
58
|
+
record, // one record will send to mainFunction
|
|
59
|
+
<%- functionName %>Main, // mainFunction that need to invoke.
|
|
60
|
+
'<%- firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
|
|
61
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
62
|
+
);
|
|
63
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
64
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
65
|
+
}))
|
|
66
|
+
|
|
67
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
68
|
+
try {
|
|
69
|
+
// --- main await all promises
|
|
70
|
+
await Promise.all(recordPromises); // await all promises
|
|
71
|
+
|
|
72
|
+
return event.Records // return all for local testing
|
|
73
|
+
|
|
74
|
+
} catch {
|
|
75
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve');
|
|
76
|
+
}
|
|
77
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
78
|
+
|
|
79
|
+
} catch (err) {
|
|
80
|
+
Logger.error('Unhandled Error, <%- functionName%>: ', err);
|
|
81
|
+
throw (err);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -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
|
+
|
|
20
|
+
const path = require('path');
|
|
21
|
+
|
|
22
|
+
const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts");
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
|
|
24
|
+
const templatePath = path.join(__dirname, "template.ejs");
|
|
25
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* receive objectSchema
|
|
29
|
+
* create data for WebSocket Main template
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} objectSchema
|
|
32
|
+
* @return {{templatePath, templateData,setting}}
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
37
|
+
return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createParamsForCreateSource(_izContext, srcPath) {
|
|
41
|
+
const functionName = FUNCTION_NAME.flowSchemaRegister + 'Complete'
|
|
42
|
+
return {
|
|
43
|
+
templatePath: templatePath,
|
|
44
|
+
templateData: {
|
|
45
|
+
functionMain: functionName + 'Main',
|
|
46
|
+
},
|
|
47
|
+
setting: {
|
|
48
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchemaRegister, 'source/'),
|
|
49
|
+
saveFileName: `${upperCase(functionName)}_Main`,
|
|
50
|
+
fileExtension: ".js",
|
|
51
|
+
isAppend: false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
module.exports = data
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http: //izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const hash = require("object-hash");
|
|
22
|
+
const { getObjectSchema } = require('@izara_project/izara-core-library-service-schemas');
|
|
23
|
+
|
|
24
|
+
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
25
|
+
const snsSharedLib = require('@izara_project/izara-core-library-sns');
|
|
26
|
+
const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
|
|
27
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
28
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
|
|
29
|
+
|
|
30
|
+
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
31
|
+
const sns = externalRequest.sns
|
|
32
|
+
const { postToConnection } = require("../../../../libs/source/GenerateCodeLibs");
|
|
33
|
+
|
|
34
|
+
const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
|
|
35
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
36
|
+
const { v4: uuidv4 } = require('uuid')
|
|
37
|
+
const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
|
|
38
|
+
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*
|
|
42
|
+
* description of function.
|
|
43
|
+
* @param {Object} _izContext
|
|
44
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
45
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
46
|
+
* @param {Object} requestParams - request params
|
|
47
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
48
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
49
|
+
*
|
|
50
|
+
*
|
|
51
|
+
* @returns {object} description of return value
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
module.exports.<%- functionMain%> = async (
|
|
55
|
+
_izContext,
|
|
56
|
+
requestParams,
|
|
57
|
+
callingFlowConfig = {},
|
|
58
|
+
//(<additionalParams>)
|
|
59
|
+
//(</additionalParams>)
|
|
60
|
+
) => {
|
|
61
|
+
try {
|
|
62
|
+
_izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
|
|
63
|
+
_izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
|
|
64
|
+
_izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
|
|
65
|
+
|
|
66
|
+
const connectionId = event.requestContext.connectionId;
|
|
67
|
+
let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID);
|
|
68
|
+
|
|
69
|
+
const getRegisterRecords = await dynamodbSharedLib.getItem(
|
|
70
|
+
_izContext,
|
|
71
|
+
await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
|
|
72
|
+
{
|
|
73
|
+
taskKey: correlationId,
|
|
74
|
+
connectionId: connectionId,
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
_izContext.logger.debug("getRegisterRecords", getRegisterRecords)
|
|
78
|
+
if (!getRegisterRecords) {
|
|
79
|
+
throw new NoRetryError(`connectionId not found ${connectionId}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const flowType = getRegisterRecords.flowType;
|
|
83
|
+
const flowTag = flowType.split('_')[0];
|
|
84
|
+
const getFlowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
85
|
+
flowTag: flowTag,
|
|
86
|
+
serviceTag: process.env.iz_serviceTag
|
|
87
|
+
})
|
|
88
|
+
_izContext.logger.debug("getFlowSchema", getFlowSchema)
|
|
89
|
+
if (!getFlowSchema) {
|
|
90
|
+
throw new NoRetryError(`flowTag not found ${flowTag}`)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
switch (flowSchema.statusType) {
|
|
94
|
+
case "statusField":
|
|
95
|
+
let payload = {
|
|
96
|
+
identifiers: requestParams.identifiers,
|
|
97
|
+
objectType: flowSchema.objType.objectType
|
|
98
|
+
}
|
|
99
|
+
let result = await externalRequest.lambda.invokeSync(
|
|
100
|
+
_izContext,
|
|
101
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv", flowSchema.objType.serviceTag),
|
|
102
|
+
payload
|
|
103
|
+
)
|
|
104
|
+
if (!result) {
|
|
105
|
+
throw new NoRetryError(`statusField not found ${requestParams.identifiers}`)
|
|
106
|
+
}
|
|
107
|
+
return result
|
|
108
|
+
case "storedCache":
|
|
109
|
+
// if statusType=storedCache then query storedCache > post message to client -> remove connectionId if status = error || complete
|
|
110
|
+
const getStoredCache = await dynamodbSharedLib.getItem(
|
|
111
|
+
_izContext,
|
|
112
|
+
await dynamodbSharedLib.tableName(_izContext, flowSchema.flowTag + "Main"),
|
|
113
|
+
{
|
|
114
|
+
taskKey: requestParams.identifiers,
|
|
115
|
+
connectionId: requestParams.connectionId
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
if (!getStoredCache) {
|
|
119
|
+
throw new NoRetryError(`storedCache not found ${requestParams.identifiers}`)
|
|
120
|
+
}
|
|
121
|
+
return getStoredCache
|
|
122
|
+
case "none":
|
|
123
|
+
// if statusType=none -> post message to client ---- not remove connectionId when post message, can remove connectionId when cannot use connectionId only(user disconnect)
|
|
124
|
+
break
|
|
125
|
+
default:
|
|
126
|
+
throw new NoRetryError(`statusType not found ${flowSchema.statusType}`)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
} catch (err) {
|
|
130
|
+
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
131
|
+
throw (err)
|
|
132
|
+
}
|
|
133
|
+
}
|