@izara_project/izara-market-library-service-schemas 1.0.36 → 1.0.38
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 +8 -7
- package/src/GenerateCodeLibs/src/Consts.js +2 -2
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +36 -6
- package/src/MainLibs/src/Consts.js +5 -2
- package/src/MainLibs/src/GenerateCodeUtils.js +3 -1
- package/src/MainLibs/src/Utils.js +12 -0
- package/src/TemplateManager/src/flowSchema/DefaultWebSocketResource/webSocketConnect/handler/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/handler/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/libs/template.ejs +1 -1
- package/src/reStructure/GenerateCode.js +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +37 -12
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +25 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +26 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +23 -1
- package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +37 -7
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +7 -7
- package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +1 -1
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +4 -2
- package/src/reStructure/TemplateData/findData/GetByStorage/getByGraph.ejs +4 -3
- package/src/reStructure/TemplateData/findData/handler/template.ejs +2 -1
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +4 -10
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/data.js +3 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +3 -12
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +6 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +18 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +9 -6
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/sqs/data.js +3 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/sqs/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/functionYaml/data.js +127 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/handler/data.js +121 -0
- package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/FlowSchemaCompleteComponent → externalTopic}/handler/template.ejs +4 -3
- package/src/reStructure/TemplateData/flowSchema/externalTopic/mainFunction/data.js +74 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/mainFunction/template.ejs +131 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +61 -34
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +9 -8
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +3 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +19 -8
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +19 -25
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +2 -4
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +2 -5
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +4 -3
- package/src/reStructure/TemplateData/flowSchema/{externalTopic/sqs → flowSchemaOwnTopic/flowStep}/functionYaml/data.js +43 -38
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowStep/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowStep/handler/data.js +80 -0
- package/src/reStructure/TemplateData/flowSchema/{externalTopic/sqs → flowSchemaOwnTopic/flowStep}/handler/template.ejs +16 -61
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/flowStep/mainFunction/data.js +92 -0
- package/src/reStructure/TemplateData/flowSchema/{externalTopic/websocket → flowSchemaOwnTopic/flowStep}/mainFunction/template.ejs +12 -14
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +48 -30
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +21 -24
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{FlowSchemaCompleteComponent → webSocketComplete}/functionYaml/data.js +7 -22
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/webSocketComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{FlowSchemaCompleteComponent → webSocketComplete}/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/webSocketComplete/handler/template.ejs +84 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{FlowSchemaCompleteComponent → webSocketComplete}/mainFunction/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{FlowSchemaCompleteComponent → webSocketComplete}/mainFunction/template.ejs +27 -11
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +25 -30
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/complete/functionYaml/data.js +0 -27
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/complete/handler/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/complete/mainFunction/data.js +3 -3
- package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +172 -0
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/dynamoDB/register.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/subscriptionOutAll/data.js +29 -19
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/wbs/functionYaml/data.js +28 -50
- package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/wbs/handler/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/register/wbs/mainFunction/template.ejs +165 -0
- package/src/reStructure/TemplateData/flowSchema/templateBystatusType/storedCacheTemplate.ejs +38 -0
- package/src/reStructure/TemplateData/flowSchema/templateBystatusType/triggerCacheTemplate.ejs +39 -0
- package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +0 -29
- package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/createObjectComplete_main.js +1 -1
- package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +4 -1
- package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +6 -2
- package/src/reStructure/TemplateData/perActionEndpoint/libs/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/create/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/delete/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/update/template.ejs +1 -1
- package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +2 -7
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +22 -3
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +14 -9
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +26 -6
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +11 -7
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +17 -7
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +23 -4
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +14 -9
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +26 -6
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +10 -7
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +11 -7
- package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +23 -4
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +14 -9
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +26 -7
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +10 -7
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +1 -2
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +12 -7
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +22 -3
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +14 -6
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +20 -3
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +9 -3
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +12 -6
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +6 -2
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +0 -131
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +0 -11
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +0 -222
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +0 -74
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +0 -8
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +0 -17
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +0 -64
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +0 -61
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +0 -45
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +0 -110
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +0 -18
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +0 -57
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +0 -40
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +0 -67
- package/src/reStructure/TemplateData/testTemplate/data.js +0 -27
- package/src/reStructure/TemplateData/testTemplate/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/FlowSchemaCompleteComponent → externalTopic}/functionYaml/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/complete/functionYaml/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/complete/handler/data.js +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/sns-in/data.js +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/sns-in/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/subscriptionOutAll/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/wbs/functionYaml/template.ejs +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/wbs/handler/data.js +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → register}/wbs/mainFunction/data.js +0 -0
- /package/src/reStructure/TemplateData/flowSchema/{createRecordByStatusType → templateBystatusType}/statusFieldTemplate.ejs +0 -0
|
@@ -47,32 +47,17 @@ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
|
|
|
47
47
|
* @return {{templatePath, templateData,setting}}
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
|
-
function data(_izContext,
|
|
51
|
-
return [createSourceParams(_izContext,
|
|
50
|
+
function data(_izContext, srcPath) {
|
|
51
|
+
return [createSourceParams(_izContext, srcPath)]
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function createSourceParams(_izContext,
|
|
55
|
-
let functionName =
|
|
54
|
+
function createSourceParams(_izContext, srcPath) {
|
|
55
|
+
let functionName = "WebSocketComplete"
|
|
56
56
|
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
57
57
|
let additionalResourcePermission = defaultIamRolePerAction();
|
|
58
|
-
let route = flowSchema.flowTag;
|
|
59
|
-
let flowStep = Object.keys(flowSchema.flowSteps)
|
|
60
|
-
let flowStepsIn = flowStep[0];
|
|
61
|
-
let splitFlowStepsIn = flowStepsIn.split("_");
|
|
62
|
-
let topicIn = `${splitFlowStepsIn[3]}_${splitFlowStepsIn[4]}`
|
|
63
58
|
let queueName = functionName + handlerType
|
|
64
59
|
|
|
65
60
|
additionalResourcePermission.push(
|
|
66
|
-
createIamRole(
|
|
67
|
-
{
|
|
68
|
-
[RESOURCE_CLASSES.sns]: [
|
|
69
|
-
SNS_RESOURCE.publish
|
|
70
|
-
]
|
|
71
|
-
},
|
|
72
|
-
[
|
|
73
|
-
resourceNames(RESOURCE_CLASSES.sns, topicIn)
|
|
74
|
-
]
|
|
75
|
-
),
|
|
76
61
|
createIamRole(
|
|
77
62
|
{
|
|
78
63
|
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
@@ -102,7 +87,8 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
|
102
87
|
[RESOURCE_CLASSES.sqs]: [SQS_RESOURCE.sendMessage, SQS_RESOURCE.receiveMessage, SQS_RESOURCE.deleteMessage, SQS_RESOURCE.getQueueAttributes]
|
|
103
88
|
},
|
|
104
89
|
[
|
|
105
|
-
resourceNames(RESOURCE_CLASSES.sqs, queueName)
|
|
90
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName),
|
|
91
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
|
|
106
92
|
]
|
|
107
93
|
)
|
|
108
94
|
)
|
|
@@ -111,11 +97,10 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
|
111
97
|
return {
|
|
112
98
|
templatePath: templatePath,
|
|
113
99
|
templateData: {
|
|
114
|
-
resourceLocation: path.join(SOURCE_PATH.
|
|
100
|
+
resourceLocation: path.join(SOURCE_PATH.resourceLocationWebSocketMain),
|
|
115
101
|
functionName,
|
|
116
102
|
handlerType,
|
|
117
103
|
additionalResourcePermission,
|
|
118
|
-
route,
|
|
119
104
|
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
120
105
|
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaOwnTopic,
|
|
121
106
|
queueName: queueName
|
|
@@ -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}<%- queueName %>
|
|
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
|
+
} _%>
|
|
@@ -36,7 +36,7 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
39
|
-
let functionName =
|
|
39
|
+
let functionName = "WebSocketComplete"
|
|
40
40
|
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
41
|
let queueName = upperCase(functionName) + upperCase(handlerType);
|
|
42
42
|
return {
|
|
@@ -47,7 +47,7 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
|
47
47
|
queueName
|
|
48
48
|
},
|
|
49
49
|
setting: {
|
|
50
|
-
savePath: path.join(srcPath, SOURCE_PATH.
|
|
50
|
+
savePath: path.join(srcPath, SOURCE_PATH.WebSocketMain),
|
|
51
51
|
saveFileName: `${functionName}_${handlerType}`,
|
|
52
52
|
fileExtension: ".js",
|
|
53
53
|
isAppend: false
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'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 recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
|
|
26
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
|
+
|
|
28
|
+
const <%- functionName %> = require('./<%- functionName %>_Main')
|
|
29
|
+
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
32
|
+
let perRecordsValidatorSchema = {}
|
|
33
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
|
|
37
|
+
let recordPromises = [];
|
|
38
|
+
|
|
39
|
+
// loop each record and send to mainFunction
|
|
40
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
41
|
+
|
|
42
|
+
let passOnProperties = []
|
|
43
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
44
|
+
|
|
45
|
+
//validate message (and MessageAttributes)
|
|
46
|
+
await recordHandlerSharedLib.validateRecord(
|
|
47
|
+
record, // one record will send to mainFunction
|
|
48
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
49
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
50
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
54
|
+
passOnProperties.push(record.body.Message)
|
|
55
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
56
|
+
|
|
57
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
58
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
59
|
+
record, // one record will send to mainFunction
|
|
60
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
61
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
62
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
63
|
+
);
|
|
64
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
65
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
69
|
+
try {
|
|
70
|
+
// --- main await all promises
|
|
71
|
+
await Promise.all(recordPromises); // await all promises
|
|
72
|
+
|
|
73
|
+
return event.Records // return all for local testing
|
|
74
|
+
|
|
75
|
+
} catch {
|
|
76
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
77
|
+
}
|
|
78
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
79
|
+
|
|
80
|
+
} catch (err) {
|
|
81
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
82
|
+
throw (err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -37,14 +37,14 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
40
|
-
let functionName =
|
|
40
|
+
let functionName = "WebSocketComplete"
|
|
41
41
|
return {
|
|
42
42
|
templatePath: templatePath,
|
|
43
43
|
templateData: {
|
|
44
44
|
functionName
|
|
45
45
|
},
|
|
46
46
|
setting: {
|
|
47
|
-
savePath: path.join(srcPath, SOURCE_PATH.
|
|
47
|
+
savePath: path.join(srcPath, SOURCE_PATH.WebSocketMain),
|
|
48
48
|
saveFileName: `${functionName}_Main`,
|
|
49
49
|
fileExtension: ".js",
|
|
50
50
|
isAppend: false
|
|
@@ -18,7 +18,7 @@ along with this program. If not, see
|
|
|
18
18
|
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
|
-
const hash = require(
|
|
21
|
+
const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
22
22
|
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
23
23
|
|
|
24
24
|
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
@@ -37,6 +37,8 @@ const { v4: uuidv4 } = require('uuid')
|
|
|
37
37
|
const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
|
|
38
38
|
const consts = require("@izara_project/izara-middleware").consts
|
|
39
39
|
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
40
|
+
//(<optionalRequire>)
|
|
41
|
+
//(</optionalRequire>)
|
|
40
42
|
/**
|
|
41
43
|
*
|
|
42
44
|
*
|
|
@@ -65,24 +67,38 @@ module.exports.<%- functionName %> = async (
|
|
|
65
67
|
_izContext.logger.debug("<%- functionName %> requestParams", requestParams)
|
|
66
68
|
_izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
|
|
67
69
|
|
|
68
|
-
let
|
|
69
|
-
let correlationId = _izContext.correlationIds.get(coreConsts.X_CORRELATION_ID);
|
|
70
|
+
let correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID);
|
|
70
71
|
|
|
71
|
-
await postToConnection(
|
|
72
|
-
{
|
|
73
|
-
message: requestParams
|
|
74
|
-
},
|
|
75
|
-
connectionId
|
|
76
|
-
)
|
|
77
72
|
|
|
78
|
-
await dynamodbSharedLib.
|
|
73
|
+
let wbsTasks = await dynamodbSharedLib.query(
|
|
74
|
+
_izContext,
|
|
79
75
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
80
76
|
{
|
|
81
77
|
taskKey: correlationId,
|
|
82
|
-
connectionId: connectionId
|
|
83
78
|
}
|
|
84
79
|
)
|
|
85
80
|
|
|
81
|
+
if (wbsTasks.Items.length) {
|
|
82
|
+
await Promise.all(wbsTasks.Items.map(async ({ connectionId }) => {
|
|
83
|
+
await postToConnection(
|
|
84
|
+
{
|
|
85
|
+
message: requestParams
|
|
86
|
+
},
|
|
87
|
+
connectionId
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
await dynamodbSharedLib.deleteItem(_izContext,
|
|
91
|
+
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
92
|
+
{
|
|
93
|
+
taskKey: correlationId,
|
|
94
|
+
connectionId: connectionId
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
86
102
|
} catch (err) {
|
|
87
103
|
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
88
104
|
throw (err)
|
|
@@ -71,14 +71,10 @@ const createConfirmAfterUploadS3MainFunction = require('./components/upload/conf
|
|
|
71
71
|
const createConfirmAfterUploadS3Queue = require('./components/upload/confirmReserved/queue/data');
|
|
72
72
|
|
|
73
73
|
// flowSchema ExternalTopic components //
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const createExternalSqsFunctionYaml = require('./externalTopic/sqs/functionYaml/data');
|
|
78
|
-
const createExternalSqsHandler = require('./externalTopic/sqs/handler/data');
|
|
79
|
-
const createExternalSqsMainFunction = require('./externalTopic/sqs/mainFunction/data');
|
|
74
|
+
const createExternalSqsFunctionYaml = require('./externalTopic/functionYaml/data');
|
|
75
|
+
const createExternalSqsHandler = require('./externalTopic/handler/data');
|
|
76
|
+
const createExternalSqsMainFunction = require('./externalTopic/mainFunction/data');
|
|
80
77
|
const createExternalTopicSnsInSqs = require('./externalTopic/sns-in-sqs/data');
|
|
81
|
-
const createExternalTopicSnsOut = require('./externalTopic/sns-out/data');
|
|
82
78
|
|
|
83
79
|
// flowSchema OwnTopic component
|
|
84
80
|
const createFlowSchemaOwnTopicFunctionYaml = require('./flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data');
|
|
@@ -86,15 +82,19 @@ const createFlowSchemaOwnTopicHandler = require('./flowSchemaOwnTopic/FlowSchema
|
|
|
86
82
|
const createFlowSchemaOwnTopicMainFunction = require('./flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data');
|
|
87
83
|
|
|
88
84
|
// flowSchema OwnTopicComplete component
|
|
89
|
-
const createFlowSchemaOwnTopicCompleteFunctionYaml = require("./flowSchemaOwnTopic/
|
|
90
|
-
const createFlowSchemaOwnTopicCompleteHandler = require("./flowSchemaOwnTopic/
|
|
91
|
-
const createFlowSchemaOwnTopicCompleteMainFunction = require("./flowSchemaOwnTopic/
|
|
85
|
+
const createFlowSchemaOwnTopicCompleteFunctionYaml = require("./flowSchemaOwnTopic/webSocketComplete/functionYaml/data");
|
|
86
|
+
const createFlowSchemaOwnTopicCompleteHandler = require("./flowSchemaOwnTopic/webSocketComplete/handler/data");
|
|
87
|
+
const createFlowSchemaOwnTopicCompleteMainFunction = require("./flowSchemaOwnTopic/webSocketComplete/mainFunction/data");
|
|
92
88
|
|
|
93
89
|
// flowSchema OwnTopicEndpoint component
|
|
94
90
|
const createFlowSchemaOwnTopicEndpointFuntionYaml = require('./flowSchemaOwnTopic/EndpointComponent/functionYaml/data');
|
|
95
91
|
const createFlowSchemaOwnTopicEndpointHandler = require('./flowSchemaOwnTopic/EndpointComponent/handler/data');
|
|
96
92
|
const createFlowSchemaOwnTopicEndpointMainFunction = require('./flowSchemaOwnTopic/EndpointComponent/mainFunction/data');
|
|
97
93
|
|
|
94
|
+
// flowSchema OnwTopic flowStep component
|
|
95
|
+
const createFlowScheamOwnTopicFlowStepFunctionYml = require('./flowSchemaOwnTopic/flowStep/functionYaml/data');
|
|
96
|
+
const createFlowSchemaOwnTopicFlowStepHandler = require('./flowSchemaOwnTopic/flowStep/handler/data');
|
|
97
|
+
const createFlowScheamOwnTopicFlowStepMainFunction = require('./flowSchemaOwnTopic/flowStep/mainFunction/data')
|
|
98
98
|
// flowSchema OwnTopicEndpointComplete component
|
|
99
99
|
const createFlowSchemaOwnTopicEndpointCompleteFuntionYaml = require('./flowSchemaOwnTopic/EndpointComplete/functionYaml/data');
|
|
100
100
|
const createFlowSchemaOwnTopicEndpointCompleteHandler = require('./flowSchemaOwnTopic/EndpointComplete/handler/data');
|
|
@@ -159,9 +159,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
159
159
|
const webSocketGenerateCodeLibs = createWebSocketGenerateCodeLibs(_izContext, flowSchema, saveFilePath)
|
|
160
160
|
createSourceParams.push(...webSocketGenerateCodeLibs)
|
|
161
161
|
|
|
162
|
-
if (flowSchema.statusType === "none" || flowSchema.handlerObj === "multi") {
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
162
|
for (const event of flowSchema.event) {
|
|
166
163
|
if (event.includes("s3")) {
|
|
167
164
|
const reservedDataTable = createReservedDataMainTable(_izContext, saveFilePath);
|
|
@@ -257,25 +254,17 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
257
254
|
|
|
258
255
|
} else if (event.includes("extTopic")) {
|
|
259
256
|
// ** External Topic ** //
|
|
257
|
+
const externalSqsFunctionYaml = await createExternalSqsFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
258
|
+
const externalSqsHandler = await createExternalSqsHandler(_izContext, flowSchema, saveFilePath);
|
|
259
|
+
const externalSqsMainFunction = await createExternalSqsMainFunction(_izContext, flowSchema, saveFilePath);
|
|
260
260
|
const externalTopicSnsInSqs = createExternalTopicSnsInSqs(_izContext, flowSchema, saveFilePath);
|
|
261
|
-
const externalTopicSnsOut = createExternalTopicSnsOut(_izContext, flowSchema, saveFilePath);
|
|
262
|
-
const externalWebsocketFunctionYaml = createExternalWebsocketFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
263
|
-
const externalWebsocketHandler = createExternalWebsocketHandler(_izContext, flowSchema, saveFilePath);
|
|
264
|
-
const externalWebsocketMainFunction = createExternalWebsocketMainFunction(_izContext, flowSchema, saveFilePath);
|
|
265
|
-
const externalSqsFunctionYaml = createExternalSqsFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
266
|
-
const externalSqsHandler = createExternalSqsHandler(_izContext, flowSchema, saveFilePath);
|
|
267
|
-
const externalSqsMainFunction = createExternalSqsMainFunction(_izContext, flowSchema, saveFilePath);
|
|
268
261
|
|
|
269
262
|
// Group related resources for better organization
|
|
270
263
|
const externalTopic = [
|
|
271
|
-
...externalWebsocketFunctionYaml,
|
|
272
|
-
...externalWebsocketHandler,
|
|
273
|
-
...externalWebsocketMainFunction,
|
|
274
264
|
...externalSqsFunctionYaml,
|
|
275
265
|
...externalSqsHandler,
|
|
276
266
|
...externalSqsMainFunction,
|
|
277
|
-
...externalTopicSnsInSqs
|
|
278
|
-
...externalTopicSnsOut
|
|
267
|
+
...externalTopicSnsInSqs
|
|
279
268
|
];
|
|
280
269
|
|
|
281
270
|
createSourceParams.push(...externalTopic)
|
|
@@ -288,7 +277,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
288
277
|
const flowSchemaOwnTopicMainFunction = await createFlowSchemaOwnTopicMainFunction(_izContext, flowSchema, saveFilePath);
|
|
289
278
|
const flowSchemaOwnTopicComponent = [...flowSchemaOwnTopicFunctionYaml, ...flowSchemaOwnTopicHandler, ...flowSchemaOwnTopicMainFunction]
|
|
290
279
|
// flowSchema OwnTopic Complete component
|
|
291
|
-
const flowSchemaOwnTopicCompleteFunctionYaml = createFlowSchemaOwnTopicCompleteFunctionYaml(_izContext,
|
|
280
|
+
const flowSchemaOwnTopicCompleteFunctionYaml = createFlowSchemaOwnTopicCompleteFunctionYaml(_izContext, saveFilePath);
|
|
292
281
|
const flowSchemaOwnTopicCompleteHandler = createFlowSchemaOwnTopicCompleteHandler(_izContext, flowSchema, saveFilePath);
|
|
293
282
|
const flowSchemaOwnTopicCompleteMainFunction = createFlowSchemaOwnTopicCompleteMainFunction(_izContext, flowSchema, saveFilePath);
|
|
294
283
|
const flowSchemaOwnTopicCompleteComponent = [...flowSchemaOwnTopicCompleteFunctionYaml, ...flowSchemaOwnTopicCompleteHandler, ...flowSchemaOwnTopicCompleteMainFunction]
|
|
@@ -306,16 +295,22 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
306
295
|
|
|
307
296
|
const flowSchemaOwnTopicQueue = createFlowSchemaOwnTopicQueue(_izContext, flowSchema, saveFilePath);
|
|
308
297
|
const flowSchemaOwnTopicSnsOut = createFlowSchemaOwnTopicSnsOut(_izContext, flowSchema, saveFilePath);
|
|
298
|
+
|
|
299
|
+
const flowSchemaOwnTopicFlowStepYml = createFlowScheamOwnTopicFlowStepFunctionYml(_izContext, flowSchema, saveFilePath);
|
|
300
|
+
const flowSchemaOwnTopicFlowStepHandler = createFlowSchemaOwnTopicFlowStepHandler(_izContext, flowSchema, saveFilePath);
|
|
301
|
+
const flowSchemaOwnTopicFlowStepMainFunction = createFlowScheamOwnTopicFlowStepMainFunction(_izContext, flowSchema, saveFilePath)
|
|
302
|
+
const flowSchemaOwnTopicFlowStep = [...flowSchemaOwnTopicFlowStepYml, ...flowSchemaOwnTopicFlowStepHandler, ...flowSchemaOwnTopicFlowStepMainFunction]
|
|
309
303
|
// Group the resources
|
|
310
304
|
const ownTopicResources = [
|
|
311
|
-
...flowSchemaOwnTopicComponent, ...flowSchemaOwnTopicCompleteComponent, ...flowSchemaOwnTopicEndpointComponent, ...flowSchemaOwnTopicQueue, ...flowSchemaOwnTopicSnsOut,
|
|
305
|
+
...flowSchemaOwnTopicComponent, ...flowSchemaOwnTopicCompleteComponent, ...flowSchemaOwnTopicEndpointComponent, ...flowSchemaOwnTopicQueue, ...flowSchemaOwnTopicSnsOut, ...flowSchemaOwnTopicFlowStep
|
|
312
306
|
// ...flowSchemaOwnTopicEndpointCompleteComponent
|
|
313
307
|
];
|
|
314
308
|
|
|
309
|
+
|
|
310
|
+
|
|
315
311
|
console.log("event ownTopic generated")
|
|
316
312
|
createSourceParams.push(...ownTopicResources);
|
|
317
313
|
|
|
318
|
-
|
|
319
314
|
} else if (event.includes("eventBridge")) {
|
|
320
315
|
const flowSchemaEventBridgeHandler = createFlowSchemaEventBridgeHandler(_izContext, flowSchema, saveFilePath);
|
|
321
316
|
const flowSchemaEventBridgeMainFunction = createFlowSchemaEventBridgeMainFunction(_izContext, flowSchema, saveFilePath);
|
|
@@ -361,11 +356,11 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
361
356
|
if (allLocalFlowSchemas.records.length) {
|
|
362
357
|
console.log("flowSchema Register");
|
|
363
358
|
const flowSchemaRegisterHandlerComplete = createFlowSchemaRegisterHandlerComplete(_izContext, saveFilePath);
|
|
364
|
-
const flowSchemaRegisterMainComplete = createFlowSchemaRegisterMainCompleteFunc(_izContext, saveFilePath);
|
|
359
|
+
const flowSchemaRegisterMainComplete = await createFlowSchemaRegisterMainCompleteFunc(_izContext, allLocalFlowSchemas, saveFilePath);
|
|
365
360
|
const flowSchemaRegisterHandlerWbs = createFlowSchemaRegisterHandlerWbsFunc(_izContext, saveFilePath);
|
|
366
361
|
const flowSchemaRegisterMainWbs = createFlowSchemaRegisterMainWbsFunc(_izContext, saveFilePath);
|
|
367
362
|
const flowSchemaRegisterFunctionYamlComplete = createFlowSchemaRegisterMainCompleteFuncYaml(_izContext, saveFilePath);
|
|
368
|
-
const flowSchemaRegisterFunctionYamlWbs = createFlowSchemaRegisterMainWbsFuncYaml(_izContext, allLocalFlowSchemas, saveFilePath);
|
|
363
|
+
const flowSchemaRegisterFunctionYamlWbs = await createFlowSchemaRegisterMainWbsFuncYaml(_izContext, allLocalFlowSchemas, saveFilePath);
|
|
369
364
|
const flowSchemaRegisterSubscribeOutAll = createFlowSchemaRegisterSubscribeOutAll(_izContext, allLocalFlowSchemas, saveFilePath);
|
|
370
365
|
const flowSchemaRegisterSnsInSqs = createFlowSchemaRegisterSnsInSqs(_izContext, saveFilePath);
|
|
371
366
|
|
|
@@ -91,33 +91,6 @@ function data(_izContext, srcPath) {
|
|
|
91
91
|
)
|
|
92
92
|
)
|
|
93
93
|
|
|
94
|
-
// if (flowSchema?.hook) {
|
|
95
|
-
// for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
|
|
96
|
-
// if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
|
|
97
|
-
// for (const hookFunction of hookProperties.functionList) {
|
|
98
|
-
// if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
|
|
99
|
-
// if (hookFunction?.permission) {
|
|
100
|
-
// for (const permission of hookFunction.permission) {
|
|
101
|
-
// additionalResourcePermission.push(
|
|
102
|
-
// createIamRole(
|
|
103
|
-
// permission.action,
|
|
104
|
-
// permission.resource.map(resource =>
|
|
105
|
-
// externalResourceYaml(
|
|
106
|
-
// resource.resource,
|
|
107
|
-
// resource.resourceName,
|
|
108
|
-
// resource.serviceTag),
|
|
109
|
-
// permission.effect
|
|
110
|
-
// )
|
|
111
|
-
// )
|
|
112
|
-
// )
|
|
113
|
-
// }
|
|
114
|
-
// }
|
|
115
|
-
// }
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
118
|
-
// }
|
|
119
|
-
// }
|
|
120
|
-
|
|
121
94
|
// console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
|
|
122
95
|
return [{
|
|
123
96
|
templatePath: templatePath,
|
|
@@ -28,7 +28,7 @@ const { <%- functionName %>Main } =require('./<%- firstLetterUpperCase(functionN
|
|
|
28
28
|
|
|
29
29
|
// validate event properties in body.Message of sqs event
|
|
30
30
|
middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
31
|
-
|
|
31
|
+
let perRecordsValidatorSchema = {}
|
|
32
32
|
module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
|
|
33
33
|
|
|
34
34
|
try {
|
|
@@ -33,11 +33,11 @@ const getObjectSchema = require('@izara_project/izara-core-library-service-schem
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
function data(_izContext,
|
|
37
|
-
return [createParamsForCreateSource(_izContext,
|
|
36
|
+
async function data(_izContext, allFlowSchemas, srcPath) {
|
|
37
|
+
return [await createParamsForCreateSource(_izContext, allFlowSchemas, srcPath)]
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function createParamsForCreateSource(_izContext, srcPath) {
|
|
40
|
+
async function createParamsForCreateSource(_izContext, allFlowSchemas, srcPath) {
|
|
41
41
|
const functionName = FUNCTION_NAME.flowSchemaRegister + 'Complete'
|
|
42
42
|
return {
|
|
43
43
|
templatePath: templatePath,
|
|
@@ -0,0 +1,172 @@
|
|
|
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('@izara_project/izara-shared-core').objectHash;
|
|
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')
|
|
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
|
+
const { generateCodeLibs: { consts: TOPIC_NAME_GENERATE_CODE } } = require('@izara_project/izara-market-library-service-schemas')
|
|
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
|
+
* @returns {object} description of return value
|
|
51
|
+
*/
|
|
52
|
+
module.exports.registerCompleteMain = async (
|
|
53
|
+
_izContext,
|
|
54
|
+
requestParams,
|
|
55
|
+
callingFlowConfig = {},
|
|
56
|
+
//(<additionalParams>)
|
|
57
|
+
//(</additionalParams>)
|
|
58
|
+
) => {
|
|
59
|
+
try {
|
|
60
|
+
_izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
|
|
61
|
+
_izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
|
|
62
|
+
_izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
|
|
63
|
+
|
|
64
|
+
// getflowSchema by using send topic name
|
|
65
|
+
// ! didn't got topicName from requestParams complete endpoint must send flowTag with identifiersTask
|
|
66
|
+
|
|
67
|
+
if (!requestParams.flowTag) {
|
|
68
|
+
throw new NoRetryError("not have flowTag in request")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
72
|
+
flowTag: requestParams.flowTag,
|
|
73
|
+
serviceTag: process.env.iz_serviceTag
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
if (!flowSchema) {
|
|
77
|
+
throw new NoRetryError("not have flowSchema in S3")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID);
|
|
81
|
+
|
|
82
|
+
const getResult = async (objectType) => {
|
|
83
|
+
const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
|
|
84
|
+
_izContext,
|
|
85
|
+
{
|
|
86
|
+
objectType: objectType,
|
|
87
|
+
serviceTag: process.env.iz_serviceTag,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
_izContext.logger.debug("==> objectSchema", objectSchema)
|
|
91
|
+
|
|
92
|
+
const result = await externalRequest.lambda.invokeSync(_izContext,
|
|
93
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv"),
|
|
94
|
+
{
|
|
95
|
+
identifiers: identifiersLibs.identifiersFromIdentifiersConcat(_izContext, objectType, requestParams.identifiersTask),
|
|
96
|
+
objectType: objectType
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
for (const [fieldName, fieldNameSetting] of Object.entries(objectSchema.fieldNames)) {
|
|
101
|
+
if (fieldNameSetting.hasOwnProperty("statusField") && fieldNameSetting.statusField === true) {
|
|
102
|
+
if (fieldName[result] !== "complete" || fieldName[result] !== "error") {
|
|
103
|
+
// if status is not complete or error will save data into table
|
|
104
|
+
await dynamodbSharedLib.putItem(_izContext,
|
|
105
|
+
await dynamodbSharedLib.tableName(_izContext, "RegisterRecord"),
|
|
106
|
+
{
|
|
107
|
+
identifiersTask: requestParams.identifiersTask,
|
|
108
|
+
connecttionId: connecttionId
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
} else {
|
|
112
|
+
if (!result) {
|
|
113
|
+
await generatedCodeLibs.postToConnection({ message: "not have record" }, connecttionId)
|
|
114
|
+
} else {
|
|
115
|
+
await generatedCodeLibs.postToConnection({ message: result }, connecttionId)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// check statusType
|
|
123
|
+
switch (flowSchema.statusType) {
|
|
124
|
+
case "statusField":
|
|
125
|
+
await getResult(flowSchema.objType.objectType);
|
|
126
|
+
break;
|
|
127
|
+
case "storedCache":
|
|
128
|
+
await getResult(flowSchema.objType.objectType);
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
case "none":
|
|
132
|
+
|
|
133
|
+
let identifier = {};
|
|
134
|
+
if (requestParams.hasOwnProperty("identifiersField") && Array.isArray(requestParams.identifierisField)) {
|
|
135
|
+
for (const fieldNames of requestParams.identifierisField) {
|
|
136
|
+
Object.assign(identifier, { [fieldNames]: requestParams[fieldNames] })
|
|
137
|
+
}
|
|
138
|
+
identifier = identifier;
|
|
139
|
+
} else {
|
|
140
|
+
identifier = requestParams
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// get task before putItem
|
|
144
|
+
let tasks = await dynamodbSharedLib.query(_izContext,
|
|
145
|
+
await dynamodbSharedLib.tableName(_izContext, "ResgisterRecords"),
|
|
146
|
+
{
|
|
147
|
+
identifiersTask: hash(identifier)
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
if (tasks && tasks.length > 0) {
|
|
151
|
+
await Promise.all(tasks.Items.map(async (task) => {
|
|
152
|
+
await generatedCodeLibs.postToConnection({ message: task }, task.connecttionId)
|
|
153
|
+
}))
|
|
154
|
+
} else {
|
|
155
|
+
await dynamodbSharedLib.putItem(_izContext,
|
|
156
|
+
await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
|
|
157
|
+
{
|
|
158
|
+
identifiersTask: hash(identifier),
|
|
159
|
+
connecttionId: connecttionId
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
break
|
|
164
|
+
default:
|
|
165
|
+
throw new NoRetryError(`statusType not found ${getFlowSchema.statusType}`)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
} catch (err) {
|
|
169
|
+
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
170
|
+
throw (err)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -31,7 +31,7 @@ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, defaultIamRolePerAction, DYN
|
|
|
31
31
|
*/
|
|
32
32
|
const createRegisterTable = (_izContext, srcPath) => {
|
|
33
33
|
let additionalResourcePermission = defaultIamRolePerAction();
|
|
34
|
-
const tableName = "
|
|
34
|
+
const tableName = "RegisterRecords";
|
|
35
35
|
additionalResourcePermission.push(
|
|
36
36
|
createIamRole(
|
|
37
37
|
{
|