@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69
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/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
|
@@ -2,7 +2,10 @@ import { buildGenerationPlan } from '../../plan/buildGenerationPlan.js';
|
|
|
2
2
|
import { commitArtifacts } from '../../output/commitArtifacts.js';
|
|
3
3
|
import { compileProject } from '../../compile/compileProject.js';
|
|
4
4
|
import { loadLocalSchemaDirectory } from '../../compile/loadSchemas.js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
emitResourceArtifacts,
|
|
7
|
+
resourceArtifactPaths
|
|
8
|
+
} from './emitResourceArtifacts.js';
|
|
6
9
|
|
|
7
10
|
export async function generateResourceArtifacts(rootPath, options = {}) {
|
|
8
11
|
const project = compileProject({ ...options, rootPath });
|
|
@@ -11,10 +14,16 @@ export async function generateResourceArtifacts(rootPath, options = {}) {
|
|
|
11
14
|
loadLocalSchemaDirectory(project, 'RelationshipSchemas'),
|
|
12
15
|
loadLocalSchemaDirectory(project, 'FlowSchemas')
|
|
13
16
|
]);
|
|
14
|
-
const artifacts = await emitResourceArtifacts({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
17
|
+
const artifacts = await emitResourceArtifacts({
|
|
18
|
+
objects,
|
|
19
|
+
relationships,
|
|
20
|
+
flows
|
|
21
|
+
});
|
|
22
|
+
const files = await commitArtifacts(
|
|
23
|
+
buildGenerationPlan(project, artifacts, {
|
|
24
|
+
managedPaths: resourceArtifactPaths,
|
|
25
|
+
managedScope: 'shared-resources'
|
|
26
|
+
})
|
|
27
|
+
);
|
|
19
28
|
return { project, files };
|
|
20
29
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
19
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
20
|
+
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
21
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
22
|
+
import initialSetupConfig from '../../config/Config.js';
|
|
23
|
+
|
|
24
|
+
const _izContext = { logger: Logger };
|
|
25
|
+
|
|
26
|
+
export function generatedLambdaRole() {
|
|
27
|
+
const externalLambdaRole = [
|
|
28
|
+
<% if (crud) { -%>
|
|
29
|
+
{
|
|
30
|
+
roleName: 'FlowObjects',
|
|
31
|
+
statement: [
|
|
32
|
+
{
|
|
33
|
+
Sid: 'FlowObjectsRoleTest0',
|
|
34
|
+
Effect: 'Allow',
|
|
35
|
+
Action: ['lambda:InvokeFunction'],
|
|
36
|
+
Resource: [
|
|
37
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetNodeHdrInv' ,'GraphHandler')}`
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
Sid: 'FlowObjectsRoleTest1',
|
|
43
|
+
Effect: 'Allow',
|
|
44
|
+
Action: ['sns:Publish'],
|
|
45
|
+
Resource: [
|
|
46
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'UpdateNode_In', 'GraphHandler')}`
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
Sid: 'FlowObjectsRoleTest2',
|
|
52
|
+
Effect: 'Allow',
|
|
53
|
+
Action: ['sns:Publish'],
|
|
54
|
+
Resource: [
|
|
55
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'CreateNode_In', 'GraphHandler')}`
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
//(<createFlowObjectsRole>)
|
|
59
|
+
//(</createFlowObjectsRole>)
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
<% } -%>
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
roleName: 'ProcFindData',
|
|
66
|
+
statement: [
|
|
67
|
+
{
|
|
68
|
+
Sid: 'ProcFindDataRoleTest0',
|
|
69
|
+
Effect: 'Allow',
|
|
70
|
+
Action: ['lambda:InvokeFunction'],
|
|
71
|
+
Resource: [
|
|
72
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetNodeHdrInv' ,'GraphHandler')}`
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
//(<createProcFindDataRole>)
|
|
76
|
+
//(</createProcFindDataRole>)
|
|
77
|
+
]
|
|
78
|
+
}<% if (relationships) { %>,
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
roleName: 'FlowRelationship',
|
|
82
|
+
statement: [
|
|
83
|
+
{
|
|
84
|
+
Sid: 'FlowRelationshipRoleTest0',
|
|
85
|
+
Effect: 'Allow',
|
|
86
|
+
Action: ['lambda:InvokeFunction'],
|
|
87
|
+
Resource: [
|
|
88
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetRelationshipHdrInv' ,'GraphHandler')}`
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
Sid: 'FlowRelationshipRoleTest1',
|
|
94
|
+
Effect: 'Allow',
|
|
95
|
+
Action: ['sns:Publish'],
|
|
96
|
+
Resource: [
|
|
97
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'CreateRelationship_In', 'GraphHandler')}`,
|
|
98
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'UpdateRelationship_In', 'GraphHandler')}`,
|
|
99
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'DeleteRelationship_In', 'GraphHandler')}`,
|
|
100
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ChangeRelationship_In', 'GraphHandler')}`,
|
|
101
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'MoveRelationship_In', 'GraphHandler')}`
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
//(<createFlowRelationshipRole>)
|
|
105
|
+
//(</createFlowRelationshipRole>)
|
|
106
|
+
]
|
|
107
|
+
}<% } -%>
|
|
108
|
+
<% s3Flows.forEach(function(flow) { -%>,
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
roleName: '<%= flow.roleName %>',
|
|
112
|
+
statement: [
|
|
113
|
+
{
|
|
114
|
+
Sid: '<%= flow.roleName %>RoleTest0',
|
|
115
|
+
Effect: 'Allow',
|
|
116
|
+
Action: ['sns:Publish'],
|
|
117
|
+
Resource: [
|
|
118
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ReservedDynamicUsage_In', 'AccountLimits')}`
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
{
|
|
123
|
+
Sid: '<%= flow.roleName %>RoleTest1',
|
|
124
|
+
Effect: 'Allow',
|
|
125
|
+
Action: ['sns:Publish'],
|
|
126
|
+
Resource: [
|
|
127
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ConfirmDynamicAfterUpload_In', 'AccountLimits')}`
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
//(<create<%= flow.roleName %>Role>)
|
|
131
|
+
//(</create<%= flow.roleName %>Role>)
|
|
132
|
+
]
|
|
133
|
+
}<% }); %>
|
|
134
|
+
//(<additionalRole>)
|
|
135
|
+
//(</additionalRole>)
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
return externalLambdaRole;
|
|
139
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
##===== [S3 Bucket: <%- bucketName %>]
|
|
2
|
+
<%- bucketName %>S3Bucket:
|
|
3
|
+
Type: AWS::S3::Bucket
|
|
4
|
+
Properties:
|
|
5
|
+
BucketName: <%- bucketName %>
|
|
6
|
+
CorsConfiguration:
|
|
7
|
+
CorsRules:
|
|
8
|
+
- AllowedHeaders:
|
|
9
|
+
- '*'
|
|
10
|
+
AllowedMethods:
|
|
11
|
+
- GET
|
|
12
|
+
- PUT
|
|
13
|
+
- POST
|
|
14
|
+
- DELETE
|
|
15
|
+
- HEAD
|
|
16
|
+
AllowedOrigins:
|
|
17
|
+
- '*'
|
|
18
|
+
MaxAge: 3000
|
|
19
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
##===== SNS Subscription
|
|
2
|
+
<%- subscriptionName %>:
|
|
3
|
+
Type: AWS::SNS::Subscription
|
|
4
|
+
Properties:
|
|
5
|
+
TopicArn: !Ref <%- topicName %>
|
|
6
|
+
Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
|
|
7
|
+
Protocol: "sqs"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
##===== WebSocket completion subscription
|
|
2
|
+
SubscriptionToOut<%= topicName %>WebSocketComplete:
|
|
3
|
+
Type: AWS::SNS::Subscription
|
|
4
|
+
Properties:
|
|
5
|
+
TopicArn: !Ref Out<%= topicName %>
|
|
6
|
+
Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs"
|
|
7
|
+
Protocol: "sqs"
|
|
@@ -1,18 +1,55 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import ejsLib from 'ejs';
|
|
3
|
+
|
|
4
|
+
const TEMPLATE_URL = new URL('./templates/', import.meta.url);
|
|
1
5
|
const SOURCE = 'app/src/generatedCode/SystemFlowSchemas/WebSocketMain/source';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
async function _renderSystemTemplate(templateName, data = {}) {
|
|
8
|
+
const templatePath = new URL(templateName, TEMPLATE_URL);
|
|
9
|
+
const content = await readFile(templatePath, 'utf8');
|
|
10
|
+
return ejsLib.render(content, data);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function emitSystemWebSocketArtifacts(
|
|
14
|
+
flows,
|
|
15
|
+
{ includeRelationshipOwnTopic = false } = {}
|
|
16
|
+
) {
|
|
17
|
+
if (!hasSystemWebSocket(flows, { includeRelationshipOwnTopic })) {
|
|
18
|
+
return { artifacts: [], functions: [] };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const webSocketConnectContent = await _renderSystemTemplate(
|
|
22
|
+
'WebSocketConnect.ejs'
|
|
23
|
+
);
|
|
24
|
+
const webSocketCompleteMainContent = await _renderSystemTemplate(
|
|
25
|
+
'WebSocketComplete_Main.ejs'
|
|
26
|
+
);
|
|
27
|
+
const webSocketCompleteHdrSqsContent = await _renderSystemTemplate(
|
|
28
|
+
'WebSocketComplete_HdrSqs.ejs'
|
|
29
|
+
);
|
|
30
|
+
const webSocketConnectYaml = await _renderSystemTemplate(
|
|
31
|
+
'WebSocketConnect_Yaml.ejs'
|
|
32
|
+
);
|
|
33
|
+
const webSocketCompleteYaml = await _renderSystemTemplate(
|
|
34
|
+
'WebSocketComplete_Yaml.ejs'
|
|
35
|
+
);
|
|
5
36
|
|
|
6
37
|
return {
|
|
7
38
|
artifacts: [
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
39
|
+
{
|
|
40
|
+
path: `${SOURCE}/WebSocketConnect.js`,
|
|
41
|
+
content: webSocketConnectContent
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: `${SOURCE}/WebSocketComplete_Main.js`,
|
|
45
|
+
content: webSocketCompleteMainContent
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
path: `${SOURCE}/WebSocketComplete_HdrSqs.js`,
|
|
49
|
+
content: webSocketCompleteHdrSqsContent
|
|
50
|
+
}
|
|
11
51
|
],
|
|
12
|
-
functions: [
|
|
13
|
-
renderWebSocketConnectYaml(),
|
|
14
|
-
renderWebSocketCompleteYaml()
|
|
15
|
-
]
|
|
52
|
+
functions: [webSocketConnectYaml, webSocketCompleteYaml]
|
|
16
53
|
};
|
|
17
54
|
}
|
|
18
55
|
|
|
@@ -24,160 +61,19 @@ export function systemWebSocketManagedPaths() {
|
|
|
24
61
|
];
|
|
25
62
|
}
|
|
26
63
|
|
|
27
|
-
export function hasSystemWebSocket(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- websocket:
|
|
43
|
-
route: $default
|
|
44
|
-
`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function renderWebSocketCompleteYaml() {
|
|
48
|
-
return `WebSocketCompleteHdrSqs:
|
|
49
|
-
handler: src/generatedCode/SystemFlowSchemas/WebSocketMain/source/WebSocketComplete_HdrSqs.main
|
|
50
|
-
name: \${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
51
|
-
role: WebSocketMainRole
|
|
52
|
-
events:
|
|
53
|
-
- sqs:
|
|
54
|
-
arn: arn:aws:sqs:\${self:custom.iz_region}:\${self:custom.iz_accountId}:\${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
55
|
-
batchSize: 10
|
|
56
|
-
filterPatterns:
|
|
57
|
-
- body:
|
|
58
|
-
MessageAttributes:
|
|
59
|
-
callingFlow:
|
|
60
|
-
Value:
|
|
61
|
-
- \${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
62
|
-
- body:
|
|
63
|
-
MessageAttributes:
|
|
64
|
-
callingFlow:
|
|
65
|
-
Value:
|
|
66
|
-
- exists: false
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function webSocketConnect() {
|
|
71
|
-
return `import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
72
|
-
import { middlewareHandler as middleware, response } from '@izara_project/izara-middleware';
|
|
73
|
-
|
|
74
|
-
export const main = middleware.wrap(async event => {
|
|
75
|
-
const { eventType, connectionId } = event.requestContext ?? {};
|
|
76
|
-
try {
|
|
77
|
-
event._izContext.logger.debug('Event:', event);
|
|
78
|
-
if (eventType === 'CONNECT') {
|
|
79
|
-
const { userId, submittedByUserId } = event.queryStringParameters ?? {};
|
|
80
|
-
await dynamodbSharedLib.putItem(event._izContext, await dynamodbSharedLib.tableName(event._izContext, 'UserUploadRecords'), {
|
|
81
|
-
connectionId, userId, submittedByUserId, expirationTime: Math.floor(Date.now() / 1000) + 7200
|
|
82
|
-
});
|
|
83
|
-
//(<webSocketConnect>)
|
|
84
|
-
//(</webSocketConnect>)
|
|
85
|
-
} else if (eventType === 'DISCONNECT') {
|
|
86
|
-
await dynamodbSharedLib.deleteItem(event._izContext, await dynamodbSharedLib.tableName(event._izContext, 'UserUploadRecords'), { connectionId });
|
|
87
|
-
//(<webSocketDisconnect>)
|
|
88
|
-
//(</webSocketDisconnect>)
|
|
89
|
-
}
|
|
90
|
-
return response.webSocketSuccess();
|
|
91
|
-
} catch (error) {
|
|
92
|
-
event._izContext.logger.error('Error, WebSocketConnect: ', error);
|
|
93
|
-
return response.failure(error);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function webSocketCompleteMain() {
|
|
100
|
-
return `import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
101
|
-
import { consts } from '@izara_project/izara-middleware';
|
|
102
|
-
import { getObjectSchema, utils } from '@izara_project/izara-core-library-service-schemas';
|
|
103
|
-
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
104
|
-
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
105
|
-
|
|
106
|
-
const { createFlowTypeConcat } = utils;
|
|
107
|
-
const { postToConnection } = webSocket;
|
|
108
|
-
|
|
109
|
-
export default async function WebSocketComplete(_izContext, topicArn, requestParams, callingFlowConfig = {}) {
|
|
110
|
-
try {
|
|
111
|
-
_izContext.logger.debug('WebSocketComplete _izContext', _izContext);
|
|
112
|
-
_izContext.logger.debug('WebSocketComplete requestParams', requestParams);
|
|
113
|
-
_izContext.logger.debug('WebSocketComplete callingFlowConfig', callingFlowConfig);
|
|
114
|
-
const correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID);
|
|
115
|
-
if (!topicArn) throw new NoRetryError('not have TopicArn for get FlowSchemas');
|
|
116
|
-
const topicName = topicArn.split(':')[5].split('_');
|
|
117
|
-
let flowTag = topicName[2];
|
|
118
|
-
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, { flowTag, serviceTag: topicName[0] });
|
|
119
|
-
if (!flowSchema) {
|
|
120
|
-
if (!requestParams?.hasOwnProperty('flowTag')) throw new NoRetryError('Could not find flowSchema from topicArn or requestParams.flowTag');
|
|
121
|
-
flowTag = requestParams.flowTag;
|
|
122
|
-
flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, { flowTag, serviceTag: process.env.iz_serviceTag });
|
|
123
|
-
}
|
|
124
|
-
//(<createIdentifiersFlow>)
|
|
125
|
-
let identifiers;
|
|
126
|
-
//(</createIdentifiersFlow>)
|
|
127
|
-
let taskKey;
|
|
128
|
-
if (flowSchema.statusType === 'statusField' || flowSchema.statusType === 'storedCache' || flowSchema.statusType === 'triggerCache') {
|
|
129
|
-
taskKey = createFlowTypeConcat(_izContext, { flowTag, serviceTag: topicName[0] }) + identifiers;
|
|
130
|
-
} else if (flowSchema.statusType === 'none') {
|
|
131
|
-
taskKey = createFlowTypeConcat(_izContext, { flowTag, serviceTag: topicName[0] }) + correlationId;
|
|
132
|
-
}
|
|
133
|
-
if (!taskKey) return;
|
|
134
|
-
const tasks = await dynamodbSharedLib.query(_izContext, await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'), { taskKey });
|
|
135
|
-
await Promise.all((tasks.Items ?? []).map(async task => {
|
|
136
|
-
//(<beforePostMessage>)
|
|
137
|
-
//(</beforePostMessage>)
|
|
138
|
-
await postToConnection({ message: requestParams }, task.connectionId);
|
|
139
|
-
await dynamodbSharedLib.deleteItem(_izContext, await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'), { taskKey: task.taskKey, connectionId: task.connectionId });
|
|
140
|
-
}));
|
|
141
|
-
} catch (error) {
|
|
142
|
-
_izContext.logger.error('error WebSocketInvoke: ', error);
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
`;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function webSocketCompleteHandler() {
|
|
150
|
-
return `import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
151
|
-
import Logger from '@izara_project/izara-core-library-logger';
|
|
152
|
-
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
153
|
-
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
154
|
-
import WebSocketComplete from './WebSocketComplete_Main.js';
|
|
155
|
-
|
|
156
|
-
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
157
|
-
const perRecordsValidatorSchema = {};
|
|
158
|
-
export const main = middleware.wrap(async (event, context, callback) => {
|
|
159
|
-
try {
|
|
160
|
-
const recordPromises = [];
|
|
161
|
-
await Promise.all(event.Records.map(async record => {
|
|
162
|
-
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
163
|
-
await recordHandlerSharedLib.validateRecord(record, 'WebSocketCompleteHdrSqs', perRecordsValidatorSchema);
|
|
164
|
-
recordPromises.push(recordHandlerSharedLib.recordHandler(
|
|
165
|
-
record,
|
|
166
|
-
WebSocketComplete,
|
|
167
|
-
'WebSocketCompleteHdrSqs',
|
|
168
|
-
[record.body.TopicArn, record.body.Message, callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)]
|
|
169
|
-
));
|
|
170
|
-
}));
|
|
171
|
-
try {
|
|
172
|
-
await Promise.all(recordPromises);
|
|
173
|
-
return event.Records;
|
|
174
|
-
} catch {
|
|
175
|
-
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
176
|
-
}
|
|
177
|
-
} catch (error) {
|
|
178
|
-
Logger.error('Unhandled Error, WebSocketComplete_HdrSqs: ', error);
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
`;
|
|
64
|
+
export function hasSystemWebSocket(
|
|
65
|
+
flows,
|
|
66
|
+
{ includeRelationshipOwnTopic = false } = {}
|
|
67
|
+
) {
|
|
68
|
+
return (
|
|
69
|
+
Array.isArray(flows) &&
|
|
70
|
+
flows.some(
|
|
71
|
+
(flow) =>
|
|
72
|
+
Array.isArray(flow?.event) &&
|
|
73
|
+
(flow.event.includes('s3') ||
|
|
74
|
+
(includeRelationshipOwnTopic &&
|
|
75
|
+
flow.event.includes('ownTopic') &&
|
|
76
|
+
flow.initiateBy === 'user'))
|
|
77
|
+
)
|
|
78
|
+
);
|
|
183
79
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
3
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import WebSocketComplete from './WebSocketComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
8
|
+
const perRecordsValidatorSchema = {};
|
|
9
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
10
|
+
try {
|
|
11
|
+
const recordPromises = [];
|
|
12
|
+
await Promise.all(event.Records.map(async record => {
|
|
13
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
14
|
+
await recordHandlerSharedLib.validateRecord(record, 'WebSocketCompleteHdrSqs', perRecordsValidatorSchema);
|
|
15
|
+
recordPromises.push(recordHandlerSharedLib.recordHandler(
|
|
16
|
+
record,
|
|
17
|
+
WebSocketComplete,
|
|
18
|
+
'WebSocketCompleteHdrSqs',
|
|
19
|
+
[record.body.TopicArn, record.body.Message, callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)]
|
|
20
|
+
));
|
|
21
|
+
}));
|
|
22
|
+
try {
|
|
23
|
+
await Promise.all(recordPromises);
|
|
24
|
+
return event.Records;
|
|
25
|
+
} catch {
|
|
26
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
Logger.error('Unhandled Error, WebSocketComplete_HdrSqs: ', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
2
|
+
import { consts } from '@izara_project/izara-middleware';
|
|
3
|
+
import { getObjectSchema, utils } from '@izara_project/izara-core-library-service-schemas';
|
|
4
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
5
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
6
|
+
|
|
7
|
+
const { createFlowTypeConcat } = utils;
|
|
8
|
+
const { postToConnection } = webSocket;
|
|
9
|
+
|
|
10
|
+
export default async function WebSocketComplete(_izContext, topicArn, requestParams, callingFlowConfig = {}) {
|
|
11
|
+
try {
|
|
12
|
+
_izContext.logger.debug('WebSocketComplete _izContext', _izContext);
|
|
13
|
+
_izContext.logger.debug('WebSocketComplete requestParams', requestParams);
|
|
14
|
+
_izContext.logger.debug('WebSocketComplete callingFlowConfig', callingFlowConfig);
|
|
15
|
+
const correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID);
|
|
16
|
+
if (!topicArn) throw new NoRetryError('not have TopicArn for get FlowSchemas');
|
|
17
|
+
const topicName = topicArn.split(':')[5].split('_');
|
|
18
|
+
let flowTag = topicName[2];
|
|
19
|
+
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, { flowTag, serviceTag: topicName[0] });
|
|
20
|
+
if (!flowSchema) {
|
|
21
|
+
if (!requestParams?.hasOwnProperty('flowTag')) throw new NoRetryError('Could not find flowSchema from topicArn or requestParams.flowTag');
|
|
22
|
+
flowTag = requestParams.flowTag;
|
|
23
|
+
flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, { flowTag, serviceTag: process.env.iz_serviceTag });
|
|
24
|
+
}
|
|
25
|
+
//(<createIdentifiersFlow>)
|
|
26
|
+
let identifiers;
|
|
27
|
+
//(</createIdentifiersFlow>)
|
|
28
|
+
let taskKey;
|
|
29
|
+
if (flowSchema.statusType === 'statusField' || flowSchema.statusType === 'storedCache' || flowSchema.statusType === 'triggerCache') {
|
|
30
|
+
taskKey = createFlowTypeConcat(_izContext, { flowTag, serviceTag: topicName[0] }) + identifiers;
|
|
31
|
+
} else if (flowSchema.statusType === 'none') {
|
|
32
|
+
taskKey = createFlowTypeConcat(_izContext, { flowTag, serviceTag: topicName[0] }) + correlationId;
|
|
33
|
+
}
|
|
34
|
+
if (!taskKey) return;
|
|
35
|
+
const tasks = await dynamodbSharedLib.query(_izContext, await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'), { taskKey });
|
|
36
|
+
await Promise.all((tasks.Items ?? []).map(async task => {
|
|
37
|
+
//(<beforePostMessage>)
|
|
38
|
+
//(</beforePostMessage>)
|
|
39
|
+
await postToConnection({ message: requestParams }, task.connectionId);
|
|
40
|
+
await dynamodbSharedLib.deleteItem(_izContext, await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'), { taskKey: task.taskKey, connectionId: task.connectionId });
|
|
41
|
+
}));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
_izContext.logger.error('error WebSocketInvoke: ', error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
WebSocketCompleteHdrSqs:
|
|
2
|
+
handler: src/generatedCode/SystemFlowSchemas/WebSocketMain/source/WebSocketComplete_HdrSqs.main
|
|
3
|
+
name: ${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
4
|
+
role: WebSocketMainRole
|
|
5
|
+
events:
|
|
6
|
+
- sqs:
|
|
7
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
8
|
+
batchSize: 10
|
|
9
|
+
filterPatterns:
|
|
10
|
+
- body:
|
|
11
|
+
MessageAttributes:
|
|
12
|
+
callingFlow:
|
|
13
|
+
Value:
|
|
14
|
+
- ${self:custom.iz_resourcePrefix}WebSocketCompleteHdrSqs
|
|
15
|
+
- body:
|
|
16
|
+
MessageAttributes:
|
|
17
|
+
callingFlow:
|
|
18
|
+
Value:
|
|
19
|
+
- exists: false
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
2
|
+
import { middlewareHandler as middleware, response } from '@izara_project/izara-middleware';
|
|
3
|
+
|
|
4
|
+
export const main = middleware.wrap(async event => {
|
|
5
|
+
const { eventType, connectionId } = event.requestContext ?? {};
|
|
6
|
+
try {
|
|
7
|
+
event._izContext.logger.debug('Event:', event);
|
|
8
|
+
if (eventType === 'CONNECT') {
|
|
9
|
+
const { userId, submittedByUserId } = event.queryStringParameters ?? {};
|
|
10
|
+
await dynamodbSharedLib.putItem(event._izContext, await dynamodbSharedLib.tableName(event._izContext, 'UserUploadRecords'), {
|
|
11
|
+
connectionId, userId, submittedByUserId, expirationTime: Math.floor(Date.now() / 1000) + 7200
|
|
12
|
+
});
|
|
13
|
+
//(<webSocketConnect>)
|
|
14
|
+
//(</webSocketConnect>)
|
|
15
|
+
} else if (eventType === 'DISCONNECT') {
|
|
16
|
+
await dynamodbSharedLib.deleteItem(event._izContext, await dynamodbSharedLib.tableName(event._izContext, 'UserUploadRecords'), { connectionId });
|
|
17
|
+
//(<webSocketDisconnect>)
|
|
18
|
+
//(</webSocketDisconnect>)
|
|
19
|
+
}
|
|
20
|
+
return response.webSocketSuccess();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
event._izContext.logger.error('Error, WebSocketConnect: ', error);
|
|
23
|
+
return response.failure(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
WebSocketConnect:
|
|
2
|
+
handler: src/generatedCode/SystemFlowSchemas/WebSocketMain/source/WebSocketConnect.main
|
|
3
|
+
name: ${self:custom.iz_resourcePrefix}WebSocketConnect
|
|
4
|
+
role: WebSocketMainRole
|
|
5
|
+
events:
|
|
6
|
+
- websocket:
|
|
7
|
+
route: $connect
|
|
8
|
+
- websocket:
|
|
9
|
+
route: $disconnect
|
|
10
|
+
- websocket:
|
|
11
|
+
route: $default
|