@izara_project/izara-core-generate-service-code 1.0.68 → 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/package.json +1 -1
- package/scripts/format-ejs.js +1 -2
- package/src/compile/compileProject.js +26 -10
- package/src/compile/loadSchemas.js +47 -23
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -17
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
- package/src/emit/custom/customFlows.js +23 -13
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +515 -113
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +2 -2
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +1 -1
- package/src/emit/function/functionYamlArtifact.js +270 -97
- 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 +28 -30
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +6 -6
- 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/UserRbacFlow_Main.ejs +1 -1
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -10
- 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/resource/emitResourceArtifacts.js +187 -114
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
- package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +10 -9
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
- package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
- package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
- 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 +136 -33
- 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 +1 -1
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +353 -71
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +61 -14
- 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 +176 -34
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +172 -32
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
|
@@ -1,202 +1,202 @@
|
|
|
1
1
|
Resources:
|
|
2
2
|
WebSocketTaskTable:
|
|
3
|
-
Type:
|
|
3
|
+
Type: "AWS::DynamoDB::Table"
|
|
4
4
|
Properties:
|
|
5
5
|
TableName: ${self:custom.iz_resourcePrefix}WebSocketTask
|
|
6
6
|
BillingMode: PAY_PER_REQUEST
|
|
7
7
|
AttributeDefinitions:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
- AttributeName: taskKey
|
|
9
|
+
AttributeType: S
|
|
10
|
+
- AttributeName: connectionId
|
|
11
|
+
AttributeType: S
|
|
12
12
|
KeySchema:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
- AttributeName: taskKey
|
|
14
|
+
KeyType: HASH
|
|
15
|
+
- AttributeName: connectionId
|
|
16
|
+
KeyType: RANGE
|
|
17
17
|
TimeToLiveSpecification:
|
|
18
18
|
AttributeName: expirationTime
|
|
19
19
|
Enabled: true
|
|
20
20
|
|
|
21
21
|
UserUploadRecordsTable:
|
|
22
|
-
Type:
|
|
22
|
+
Type: "AWS::DynamoDB::Table"
|
|
23
23
|
Properties:
|
|
24
24
|
TableName: ${self:custom.iz_resourcePrefix}UserUploadRecords
|
|
25
25
|
BillingMode: PAY_PER_REQUEST
|
|
26
26
|
AttributeDefinitions:
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
- AttributeName: connectionId
|
|
28
|
+
AttributeType: S
|
|
29
29
|
KeySchema:
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
- AttributeName: connectionId
|
|
31
|
+
KeyType: HASH
|
|
32
32
|
TimeToLiveSpecification:
|
|
33
33
|
AttributeName: expirationTime
|
|
34
34
|
Enabled: true
|
|
35
35
|
|
|
36
36
|
RegisterRecordsTable:
|
|
37
|
-
Type:
|
|
37
|
+
Type: "AWS::DynamoDB::Table"
|
|
38
38
|
Properties:
|
|
39
39
|
TableName: ${self:custom.iz_resourcePrefix}RegisterRecords
|
|
40
40
|
BillingMode: PAY_PER_REQUEST
|
|
41
41
|
AttributeDefinitions:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
- AttributeName: identifiersTask
|
|
43
|
+
AttributeType: S
|
|
44
|
+
- AttributeName: connectionId
|
|
45
|
+
AttributeType: S
|
|
46
46
|
KeySchema:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
- AttributeName: identifiersTask
|
|
48
|
+
KeyType: HASH
|
|
49
|
+
- AttributeName: connectionId
|
|
50
|
+
KeyType: RANGE
|
|
51
51
|
|
|
52
52
|
AwaitingMultipleStepsTable:
|
|
53
|
-
Type:
|
|
53
|
+
Type: "AWS::DynamoDB::Table"
|
|
54
54
|
Properties:
|
|
55
55
|
TableName: ${self:custom.iz_resourcePrefix}AwaitingMultipleSteps
|
|
56
56
|
BillingMode: PAY_PER_REQUEST
|
|
57
57
|
AttributeDefinitions:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
- AttributeName: awaitingStepId
|
|
59
|
+
AttributeType: S
|
|
60
|
+
- AttributeName: pendingStepId
|
|
61
|
+
AttributeType: S
|
|
62
62
|
KeySchema:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
- AttributeName: awaitingStepId
|
|
64
|
+
KeyType: HASH
|
|
65
|
+
- AttributeName: pendingStepId
|
|
66
|
+
KeyType: RANGE
|
|
67
67
|
|
|
68
68
|
AwaitingMultipleStepByPendingTable:
|
|
69
|
-
Type:
|
|
69
|
+
Type: "AWS::DynamoDB::Table"
|
|
70
70
|
Properties:
|
|
71
71
|
TableName: ${self:custom.iz_resourcePrefix}AwaitingMultipleStepByPending
|
|
72
72
|
BillingMode: PAY_PER_REQUEST
|
|
73
73
|
AttributeDefinitions:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
- AttributeName: pendingStepId
|
|
75
|
+
AttributeType: S
|
|
76
|
+
- AttributeName: awaitingStepId
|
|
77
|
+
AttributeType: S
|
|
78
78
|
KeySchema:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
- AttributeName: pendingStepId
|
|
80
|
+
KeyType: HASH
|
|
81
|
+
- AttributeName: awaitingStepId
|
|
82
|
+
KeyType: RANGE
|
|
83
83
|
|
|
84
84
|
FindDataMainTable:
|
|
85
|
-
Type:
|
|
85
|
+
Type: "AWS::DynamoDB::Table"
|
|
86
86
|
Properties:
|
|
87
87
|
TableName: ${self:custom.iz_resourcePrefix}FindDataMain
|
|
88
88
|
BillingMode: PAY_PER_REQUEST
|
|
89
89
|
AttributeDefinitions:
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
- AttributeName: findDataId
|
|
91
|
+
AttributeType: S
|
|
92
92
|
KeySchema:
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
- AttributeName: findDataId
|
|
94
|
+
KeyType: HASH
|
|
95
95
|
|
|
96
96
|
LogicalResultsMainTable:
|
|
97
|
-
Type:
|
|
97
|
+
Type: "AWS::DynamoDB::Table"
|
|
98
98
|
Properties:
|
|
99
99
|
TableName: ${self:custom.iz_resourcePrefix}LogicalResultsMain
|
|
100
100
|
BillingMode: PAY_PER_REQUEST
|
|
101
101
|
AttributeDefinitions:
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
- AttributeName: logicalResultId
|
|
103
|
+
AttributeType: S
|
|
104
104
|
KeySchema:
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
- AttributeName: logicalResultId
|
|
106
|
+
KeyType: HASH
|
|
107
107
|
|
|
108
108
|
LogicalResultsDataTable:
|
|
109
|
-
Type:
|
|
109
|
+
Type: "AWS::DynamoDB::Table"
|
|
110
110
|
Properties:
|
|
111
111
|
TableName: ${self:custom.iz_resourcePrefix}LogicalResultsData
|
|
112
112
|
BillingMode: PAY_PER_REQUEST
|
|
113
113
|
AttributeDefinitions:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
- AttributeName: logicalResultId
|
|
115
|
+
AttributeType: S
|
|
116
|
+
- AttributeName: identifiersId
|
|
117
|
+
AttributeType: S
|
|
118
118
|
KeySchema:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
- AttributeName: logicalResultId
|
|
120
|
+
KeyType: HASH
|
|
121
|
+
- AttributeName: identifiersId
|
|
122
|
+
KeyType: RANGE
|
|
123
123
|
|
|
124
124
|
AwaitingStepTable:
|
|
125
|
-
Type:
|
|
125
|
+
Type: "AWS::DynamoDB::Table"
|
|
126
126
|
Properties:
|
|
127
127
|
TableName: ${self:custom.iz_resourcePrefix}AwaitingStep
|
|
128
128
|
BillingMode: PAY_PER_REQUEST
|
|
129
129
|
AttributeDefinitions:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
- AttributeName: awaitingStepId
|
|
131
|
+
AttributeType: S
|
|
132
|
+
- AttributeName: pendingStepId
|
|
133
|
+
AttributeType: S
|
|
134
134
|
KeySchema:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
- AttributeName: awaitingStepId
|
|
136
|
+
KeyType: HASH
|
|
137
|
+
- AttributeName: pendingStepId
|
|
138
|
+
KeyType: RANGE
|
|
139
139
|
|
|
140
140
|
TargetRolesTable:
|
|
141
|
-
Type:
|
|
141
|
+
Type: "AWS::DynamoDB::Table"
|
|
142
142
|
Properties:
|
|
143
143
|
TableName: ${self:custom.iz_resourcePrefix}TargetRoles
|
|
144
144
|
BillingMode: PAY_PER_REQUEST
|
|
145
145
|
AttributeDefinitions:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
- AttributeName: targetId
|
|
147
|
+
AttributeType: S
|
|
148
|
+
- AttributeName: roleIdKey
|
|
149
|
+
AttributeType: S
|
|
150
150
|
KeySchema:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
- AttributeName: targetId
|
|
152
|
+
KeyType: HASH
|
|
153
|
+
- AttributeName: roleIdKey
|
|
154
|
+
KeyType: RANGE
|
|
155
155
|
|
|
156
156
|
RolePermissionsTable:
|
|
157
|
-
Type:
|
|
157
|
+
Type: "AWS::DynamoDB::Table"
|
|
158
158
|
Properties:
|
|
159
159
|
TableName: ${self:custom.iz_resourcePrefix}RolePermissions
|
|
160
160
|
BillingMode: PAY_PER_REQUEST
|
|
161
161
|
AttributeDefinitions:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
- AttributeName: roleIdKey
|
|
163
|
+
AttributeType: S
|
|
164
|
+
- AttributeName: flowTypeConcat
|
|
165
|
+
AttributeType: S
|
|
166
166
|
KeySchema:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
- AttributeName: roleIdKey
|
|
168
|
+
KeyType: HASH
|
|
169
|
+
- AttributeName: flowTypeConcat
|
|
170
|
+
KeyType: RANGE
|
|
171
171
|
|
|
172
172
|
RoleUsersTable:
|
|
173
|
-
Type:
|
|
173
|
+
Type: "AWS::DynamoDB::Table"
|
|
174
174
|
Properties:
|
|
175
175
|
TableName: ${self:custom.iz_resourcePrefix}RoleUsers
|
|
176
176
|
BillingMode: PAY_PER_REQUEST
|
|
177
177
|
AttributeDefinitions:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
- AttributeName: roleIdKey
|
|
179
|
+
AttributeType: S
|
|
180
|
+
- AttributeName: userId
|
|
181
|
+
AttributeType: S
|
|
182
182
|
KeySchema:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
- AttributeName: roleIdKey
|
|
184
|
+
KeyType: HASH
|
|
185
|
+
- AttributeName: userId
|
|
186
|
+
KeyType: RANGE
|
|
187
187
|
|
|
188
188
|
UserRolesTable:
|
|
189
|
-
Type:
|
|
189
|
+
Type: "AWS::DynamoDB::Table"
|
|
190
190
|
Properties:
|
|
191
191
|
TableName: ${self:custom.iz_resourcePrefix}UserRoles
|
|
192
192
|
BillingMode: PAY_PER_REQUEST
|
|
193
193
|
AttributeDefinitions:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
- AttributeName: userId
|
|
195
|
+
AttributeType: S
|
|
196
|
+
- AttributeName: roleIdKey
|
|
197
|
+
AttributeType: S
|
|
198
198
|
KeySchema:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
- AttributeName: userId
|
|
200
|
+
KeyType: HASH
|
|
201
|
+
- AttributeName: roleIdKey
|
|
202
|
+
KeyType: RANGE
|
|
@@ -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
|