@izara_project/izara-core-generate-service-code 1.0.68 → 1.0.70
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 +36 -32
- package/src/compile/compileProject.js +26 -10
- package/src/compile/loadSchemas.js +122 -59
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +163 -0
- package/src/emit/coreFunction/templates/CoreFunction_Yaml.ejs +38 -0
- package/src/emit/coreFunction/templates/CoreResource_Yaml.ejs +235 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_Main.ejs +38 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_Main.ejs +32 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +71 -0
- package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +47 -0
- package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +27 -0
- package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +34 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +108 -0
- package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +12 -0
- package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +51 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_Main.ejs +31 -0
- package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +37 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +52 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +194 -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/CreateEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
- package/src/emit/custom/customFlows.js +23 -13
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +535 -114
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- 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/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +4 -4
- package/src/emit/function/functionYamlArtifact.js +273 -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 +189 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
- package/src/emit/resource/emitResourceArtifacts.js +249 -123
- 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 +122 -105
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/shared/templates/FindData_HdrSqs.ejs +120 -0
- package/src/emit/shared/templates/FindData_Main.ejs +345 -0
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/{relationship → shared}/templates/FlowHandler_HdrDsq.ejs +4 -4
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrSqs.ejs +4 -4
- package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +162 -0
- package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +140 -0
- package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +268 -0
- package/src/emit/{relationship/templates/FlowHandler_HdrSqs.ejs → shared/templates/ProcessLogical_HdrSqs.ejs} +40 -55
- package/src/emit/shared/templates/ProcessLogical_Main.ejs +448 -0
- package/src/emit/system/emitSystemFindDataArtifacts.js +266 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +48 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +91 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +45 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +166 -36
- 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 +34 -21
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +117 -58
- package/test/createTargetRoleHandler.test.js +1 -1
- package/test/crudApplicationArtifacts.test.js +132 -31
- 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 +178 -36
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +173 -33
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +0 -59
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +0 -47
|
@@ -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,48 @@
|
|
|
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(
|
|
13
|
+
event.Records.map(async (record) => {
|
|
14
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
15
|
+
await recordHandlerSharedLib.validateRecord(
|
|
16
|
+
record,
|
|
17
|
+
'WebSocketCompleteHdrSqs',
|
|
18
|
+
perRecordsValidatorSchema
|
|
19
|
+
);
|
|
20
|
+
recordPromises.push(
|
|
21
|
+
recordHandlerSharedLib.recordHandler(
|
|
22
|
+
record,
|
|
23
|
+
WebSocketComplete,
|
|
24
|
+
'WebSocketCompleteHdrSqs',
|
|
25
|
+
[
|
|
26
|
+
record.body.TopicArn,
|
|
27
|
+
record.body.Message,
|
|
28
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
29
|
+
record.body.Message
|
|
30
|
+
)
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
try {
|
|
37
|
+
await Promise.all(recordPromises);
|
|
38
|
+
return event.Records;
|
|
39
|
+
} catch {
|
|
40
|
+
Logger.debug(
|
|
41
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
Logger.error('Unhandled Error, WebSocketComplete_HdrSqs: ', error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
2
|
+
import { consts } from '@izara_project/izara-middleware';
|
|
3
|
+
import {
|
|
4
|
+
getObjectSchema,
|
|
5
|
+
utils
|
|
6
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
7
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
8
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
9
|
+
|
|
10
|
+
const { createFlowTypeConcat } = utils;
|
|
11
|
+
const { postToConnection } = webSocket;
|
|
12
|
+
|
|
13
|
+
export default async function WebSocketComplete(
|
|
14
|
+
_izContext,
|
|
15
|
+
topicArn,
|
|
16
|
+
requestParams,
|
|
17
|
+
callingFlowConfig = {}
|
|
18
|
+
) {
|
|
19
|
+
try {
|
|
20
|
+
_izContext.logger.debug('WebSocketComplete _izContext', _izContext);
|
|
21
|
+
_izContext.logger.debug('WebSocketComplete requestParams', requestParams);
|
|
22
|
+
_izContext.logger.debug(
|
|
23
|
+
'WebSocketComplete callingFlowConfig',
|
|
24
|
+
callingFlowConfig
|
|
25
|
+
);
|
|
26
|
+
const correlationId = _izContext.correlationIds.get(
|
|
27
|
+
consts.X_CORRELATION_ID
|
|
28
|
+
);
|
|
29
|
+
if (!topicArn)
|
|
30
|
+
throw new NoRetryError('not have TopicArn for get FlowSchemas');
|
|
31
|
+
const topicName = topicArn.split(':')[5].split('_');
|
|
32
|
+
let flowTag = topicName[2];
|
|
33
|
+
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
|
|
34
|
+
_izContext,
|
|
35
|
+
{ flowTag, serviceTag: topicName[0] }
|
|
36
|
+
);
|
|
37
|
+
if (!flowSchema) {
|
|
38
|
+
if (!requestParams?.hasOwnProperty('flowTag'))
|
|
39
|
+
throw new NoRetryError(
|
|
40
|
+
'Could not find flowSchema from topicArn or requestParams.flowTag'
|
|
41
|
+
);
|
|
42
|
+
flowTag = requestParams.flowTag;
|
|
43
|
+
flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
44
|
+
flowTag,
|
|
45
|
+
serviceTag: process.env.iz_serviceTag
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//(<createIdentifiersFlow>)
|
|
49
|
+
let identifiers;
|
|
50
|
+
//(</createIdentifiersFlow>)
|
|
51
|
+
let taskKey;
|
|
52
|
+
if (
|
|
53
|
+
flowSchema.statusType === 'statusField' ||
|
|
54
|
+
flowSchema.statusType === 'storedCache' ||
|
|
55
|
+
flowSchema.statusType === 'triggerCache'
|
|
56
|
+
) {
|
|
57
|
+
taskKey =
|
|
58
|
+
createFlowTypeConcat(_izContext, {
|
|
59
|
+
flowTag,
|
|
60
|
+
serviceTag: topicName[0]
|
|
61
|
+
}) + identifiers;
|
|
62
|
+
} else if (flowSchema.statusType === 'none') {
|
|
63
|
+
taskKey =
|
|
64
|
+
createFlowTypeConcat(_izContext, {
|
|
65
|
+
flowTag,
|
|
66
|
+
serviceTag: topicName[0]
|
|
67
|
+
}) + correlationId;
|
|
68
|
+
}
|
|
69
|
+
if (!taskKey) return;
|
|
70
|
+
const tasks = await dynamodbSharedLib.query(
|
|
71
|
+
_izContext,
|
|
72
|
+
await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
|
|
73
|
+
{ taskKey }
|
|
74
|
+
);
|
|
75
|
+
await Promise.all(
|
|
76
|
+
(tasks.Items ?? []).map(async (task) => {
|
|
77
|
+
//(<beforePostMessage>)
|
|
78
|
+
//(</beforePostMessage>)
|
|
79
|
+
await postToConnection({ message: requestParams }, task.connectionId);
|
|
80
|
+
await dynamodbSharedLib.deleteItem(
|
|
81
|
+
_izContext,
|
|
82
|
+
await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
|
|
83
|
+
{ taskKey: task.taskKey, connectionId: task.connectionId }
|
|
84
|
+
);
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
_izContext.logger.error('error WebSocketInvoke: ', error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -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,45 @@
|
|
|
1
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
2
|
+
import {
|
|
3
|
+
middlewareHandler as middleware,
|
|
4
|
+
response
|
|
5
|
+
} from '@izara_project/izara-middleware';
|
|
6
|
+
|
|
7
|
+
export const main = middleware.wrap(async (event) => {
|
|
8
|
+
const { eventType, connectionId } = event.requestContext ?? {};
|
|
9
|
+
try {
|
|
10
|
+
event._izContext.logger.debug('Event:', event);
|
|
11
|
+
if (eventType === 'CONNECT') {
|
|
12
|
+
const { userId, submittedByUserId } = event.queryStringParameters ?? {};
|
|
13
|
+
await dynamodbSharedLib.putItem(
|
|
14
|
+
event._izContext,
|
|
15
|
+
await dynamodbSharedLib.tableName(
|
|
16
|
+
event._izContext,
|
|
17
|
+
'UserUploadRecords'
|
|
18
|
+
),
|
|
19
|
+
{
|
|
20
|
+
connectionId,
|
|
21
|
+
userId,
|
|
22
|
+
submittedByUserId,
|
|
23
|
+
expirationTime: Math.floor(Date.now() / 1000) + 7200
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
//(<webSocketConnect>)
|
|
27
|
+
//(</webSocketConnect>)
|
|
28
|
+
} else if (eventType === 'DISCONNECT') {
|
|
29
|
+
await dynamodbSharedLib.deleteItem(
|
|
30
|
+
event._izContext,
|
|
31
|
+
await dynamodbSharedLib.tableName(
|
|
32
|
+
event._izContext,
|
|
33
|
+
'UserUploadRecords'
|
|
34
|
+
),
|
|
35
|
+
{ connectionId }
|
|
36
|
+
);
|
|
37
|
+
//(<webSocketDisconnect>)
|
|
38
|
+
//(</webSocketDisconnect>)
|
|
39
|
+
}
|
|
40
|
+
return response.webSocketSuccess();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
event._izContext.logger.error('Error, WebSocketConnect: ', error);
|
|
43
|
+
return response.failure(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -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
|