@izara_project/izara-market-library-service-schemas 1.0.69 → 1.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -2
- package/src/reStructure/TemplateData/flowSchema/flowSchemaMainFunction/template.ejs +1 -4
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +38 -5
- package/src/reStructure/TemplateData/flowSchema/templateByStatusType/triggerCacheTemplate.ejs +24 -11
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/functionYaml/template.ejs +0 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/handler/template.ejs +92 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/data.js +60 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/checkTriggerCacheComplete/mainFunction/template.ejs +97 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/template.ejs +91 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/data.js +59 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/mainFunction/template.ejs +70 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/data.js +101 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/data.js +62 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/template.ejs +91 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/data.js +60 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/mainFunction/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/data.js +70 -0
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/template.ejs +43 -0
package/package.json
CHANGED
|
@@ -85,13 +85,16 @@ module.exports.reservedLimit = async (
|
|
|
85
85
|
|
|
86
86
|
if (res.passStatus === false) {
|
|
87
87
|
importDataLibs.postToConnection({ message: "static limit over" }, connectionId)
|
|
88
|
-
let identifiers = hash({
|
|
88
|
+
let identifiers = hash({
|
|
89
|
+
//(<hashIdentifiers>)
|
|
90
|
+
//(</hashIdentifiers>)
|
|
91
|
+
})
|
|
89
92
|
|
|
90
93
|
// after post message delete websocket task
|
|
91
94
|
await dynamodbSharedLib.deleteItem(_izContext,
|
|
92
95
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
93
96
|
{
|
|
94
|
-
taskKey:
|
|
97
|
+
taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
|
|
95
98
|
connectionId: connectionId
|
|
96
99
|
}
|
|
97
100
|
)
|
|
@@ -68,9 +68,6 @@ module.exports.<%- functionName %> = async (
|
|
|
68
68
|
_izContext.logger.debug("<%- functionName %> requestParams", requestParams)
|
|
69
69
|
_izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
|
|
70
70
|
|
|
71
|
-
//(<beforeCheckStatus>)
|
|
72
|
-
//(</beforeCheckStatus>)
|
|
73
|
-
|
|
74
71
|
<% if (statusType === "statusField") { %>
|
|
75
72
|
<%- include(statusFieldTemplate) %>
|
|
76
73
|
<% } else if (statusType === "storedCache") { %>
|
|
@@ -81,7 +78,7 @@ module.exports.<%- functionName %> = async (
|
|
|
81
78
|
tableName: tableName,
|
|
82
79
|
flowSchemaComplete: flowSchemaComplete,
|
|
83
80
|
triggerType: triggerType,
|
|
84
|
-
flowTag
|
|
81
|
+
flowTag,
|
|
85
82
|
}) %>
|
|
86
83
|
<% } %>
|
|
87
84
|
|
|
@@ -32,7 +32,7 @@ const sns = externalRequest.sns
|
|
|
32
32
|
|
|
33
33
|
const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
|
|
34
34
|
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
35
|
-
const coreConsts = require("@izara_project/izara-
|
|
35
|
+
const coreConsts = require("@izara_project/izara-middleware").consts;
|
|
36
36
|
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
37
37
|
const { postToConnection } = require('../../../libs/source/GenerateCodeLibs')
|
|
38
38
|
//(<optionalRequire>)
|
|
@@ -138,6 +138,22 @@ const createFlowSchemaRegisterSubscribeOutAll = require('./register/subscription
|
|
|
138
138
|
const createFlowSchemaRegisterSnsInSqs = require('./register/sns-in/data');
|
|
139
139
|
const createFlowSchemaRegisterDynamoDb = require('./register/dynamoDB/register');
|
|
140
140
|
|
|
141
|
+
const createFlowSchemaTriggerCacheFunctionYaml = {
|
|
142
|
+
createProcessTriggerCacheYaml: require('./triggerCacheComponent/processTriggerCache/functionYaml/data'),
|
|
143
|
+
createCheckTriggerCacheYaml: require('./triggerCacheComponent/checkTriggerCacheComplete/functionYaml/data'),
|
|
144
|
+
createTriggerCacheCompleteYaml: require('./triggerCacheComponent/triggerCacheComplete/functionYaml/data')
|
|
145
|
+
}
|
|
146
|
+
const createFlowSchemaTriggerCacheHandler = {
|
|
147
|
+
createProcessTriggerCacheHandler: require('./triggerCacheComponent/processTriggerCache/handler/data'),
|
|
148
|
+
createCheckTriggerCacheHandler: require('./triggerCacheComponent/checkTriggerCacheComplete/handler/data'),
|
|
149
|
+
createTriggerCacheCompleteHandler: require('./triggerCacheComponent/triggerCacheComplete/handler/data')
|
|
150
|
+
}
|
|
151
|
+
const createFlowSchemaTriggerCacheMainFunction = {
|
|
152
|
+
createProcessTriggerCacheMainFunction: require('./triggerCacheComponent/processTriggerCache/mainFunction/data'),
|
|
153
|
+
createCheckTriggerCacheMainFunction: require('./triggerCacheComponent/checkTriggerCacheComplete/mainFunction/data'),
|
|
154
|
+
createTriggerCacheCompleteMainFunction: require('./triggerCacheComponent/triggerCacheComplete/mainFunction/data')
|
|
155
|
+
}
|
|
156
|
+
const createFlowSchemaTriggerCacheQueue = require('./triggerCacheComponent/triggerCacheQueue/data')
|
|
141
157
|
/**
|
|
142
158
|
* Generates code with templates for different actions
|
|
143
159
|
* @param {Object} _izContext - Context object
|
|
@@ -151,7 +167,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
151
167
|
// console.log("saveFilePath in flowSchema generateTemplateAndData", saveFilePath)
|
|
152
168
|
let createSourceParams = [];
|
|
153
169
|
const allLocalFlowSchemas = await getAllLocalFlowSchemas(_izContext, objSchemaPath);
|
|
154
|
-
const allLocalObjectSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
|
|
170
|
+
// const allLocalObjectSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
|
|
155
171
|
|
|
156
172
|
// default webSocket setting
|
|
157
173
|
const webSocketTaskTable = createWebSocketDynamoDb(_izContext, saveFilePath);
|
|
@@ -166,7 +182,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
166
182
|
const webSocketCompleteComponent = [...webSocketCompleteFunctionYaml, ...webSocketCompleteHandler, ...webSocketCompleteMainFunction, ...webSocketCompleteSqs]
|
|
167
183
|
const userUploadRecordTable = createUserUploadRecordTable(_izContext, saveFilePath)
|
|
168
184
|
|
|
169
|
-
const webSocketResource = [...webSocketTaskTable, ...webSocketConnectYaml, ...webSocketConnectHandler
|
|
185
|
+
const webSocketResource = [...webSocketTaskTable, ...webSocketConnectYaml, ...webSocketConnectHandler]
|
|
170
186
|
if (allLocalFlowSchemas.records.length) {
|
|
171
187
|
createSourceParams.push(
|
|
172
188
|
...webSocketResource,
|
|
@@ -181,7 +197,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
181
197
|
for (const flowSchema of allLocalFlowSchemas.records) {
|
|
182
198
|
// console.log("flowSchema in Generate TemplateData", flowSchema);
|
|
183
199
|
const webSocketGenerateCodeLibs = createWebSocketGenerateCodeLibs(_izContext, flowSchema, saveFilePath)
|
|
184
|
-
|
|
185
200
|
createSourceParams.push(...webSocketGenerateCodeLibs)
|
|
186
201
|
if (!flowSchema.event.includes("s3")) {
|
|
187
202
|
const flowSchemaEndpointMainFunction = await createFlowSchemaEndpointMainFunction(_izContext, flowSchema, saveFilePath);
|
|
@@ -191,6 +206,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
191
206
|
// event has [s3, extTopic, ownTopic, eventBridge, lambdaSync]
|
|
192
207
|
for (const event of flowSchema.event) {
|
|
193
208
|
if (event.includes("s3")) {
|
|
209
|
+
|
|
194
210
|
const reservedDataTable = createReservedDataMainTable(_izContext, saveFilePath);
|
|
195
211
|
const bucketS3 = createBucketS3(_izContext, flowSchema, saveFilePath)
|
|
196
212
|
|
|
@@ -216,7 +232,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
216
232
|
|
|
217
233
|
const processAfterUploadFunctionYmlS3 = createProcessAfterUploadS3FunctionYmlS3(_izContext, flowSchema, saveFilePath);
|
|
218
234
|
// const processAfterUploadFunctionYamlHdrDsq = createProcessAfterUploadS3FunctionYmlDsq(_izContext, saveFilePath);
|
|
219
|
-
const processAfterUploadSqs = createProcessAfterUploadS3Queue(_izContext, saveFilePath);
|
|
235
|
+
// const processAfterUploadSqs = createProcessAfterUploadS3Queue(_izContext, saveFilePath);
|
|
220
236
|
const processAfterUploadHandlerS3 = createProcessAfterUploadS3HandlerS3(_izContext, flowSchema, saveFilePath);
|
|
221
237
|
// const processAfterUploadHandlerDsq = createProcessAfterUploadS3HandlerDsq(_izContext, saveFilePath);
|
|
222
238
|
const processAfterUploadMainFunction = createProcessAfterUploadS3MainFunction(_izContext, flowSchema, saveFilePath);
|
|
@@ -254,7 +270,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
254
270
|
|
|
255
271
|
const processAfterUploadResources = [
|
|
256
272
|
...processAfterUploadFunctionYmlS3,
|
|
257
|
-
...processAfterUploadSqs,
|
|
273
|
+
// ...processAfterUploadSqs,
|
|
258
274
|
...processAfterUploadHandlerS3,
|
|
259
275
|
...processAfterUploadMainFunction
|
|
260
276
|
// Commented resources kept for reference
|
|
@@ -287,6 +303,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
287
303
|
);
|
|
288
304
|
|
|
289
305
|
} else if (event.includes("extTopic")) {
|
|
306
|
+
|
|
290
307
|
// ** External Topic ** //
|
|
291
308
|
const externalSqsFunctionYaml = await createExternalSqsFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
292
309
|
const externalSqsHandler = await createExternalSqsHandler(_izContext, flowSchema, saveFilePath);
|
|
@@ -342,6 +359,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
342
359
|
createSourceParams.push(...ownTopicResources);
|
|
343
360
|
|
|
344
361
|
} else if (event.includes("eventBridge")) {
|
|
362
|
+
|
|
345
363
|
const flowSchemaEventBridgeHandler = createFlowSchemaEventBridgeHandler(_izContext, flowSchema, saveFilePath);
|
|
346
364
|
const flowSchemaEventBridgeMainFunction = createFlowSchemaEventBridgeMainFunction(_izContext, flowSchema, saveFilePath);
|
|
347
365
|
const flowSchemaEventBridgeFunctionYaml = createFlowSchemaEventBridgeFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
@@ -357,6 +375,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
357
375
|
console.log("event eventBridge generated")
|
|
358
376
|
createSourceParams.push(...eventBridgeResources);
|
|
359
377
|
} else if (event.includes("lambdaSyncInv")) {
|
|
378
|
+
|
|
360
379
|
const flowSchemaLambdaSyncFunctionYamlInv = createFlowSchemaLambdaSyncFunctionYamlInv(_izContext, flowSchema, saveFilePath);
|
|
361
380
|
const flowSchemaLambdaSyncHandlerInv = createFlowSchemaLambdaSyncHandlerInv(_izContext, flowSchema, saveFilePath);
|
|
362
381
|
// const flowSchemaLambdaSyncMainFunctionInv = createFlowSchemaLambdaSyncMainFunctionInv(_izContext, flowSchema, saveFilePath);
|
|
@@ -416,9 +435,23 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
416
435
|
const flowSchemaFlowStepSnsIn = createFlowSchemaFlowStepSnsIn(_izContext, flowSchema, saveFilePath);
|
|
417
436
|
const flowSchemaOwnTopicFlowStep = [...flowSchemaFlowStepYml, ...flowSchemaFlowStepHandler, ...flowSchemaFlowStepMainFunction, ...flowSchemaFlowStepSnsIn]
|
|
418
437
|
createSourceParams.push(...flowSchemaOwnTopicFlowStep)
|
|
438
|
+
|
|
439
|
+
if (flowSchema.statusType === "triggerCache") {
|
|
440
|
+
const functionYaml = (await Promise.all(Object.entries(createFlowSchemaTriggerCacheFunctionYaml).map(([type, functionYaml]) => functionYaml(_izContext, flowSchema, saveFilePath)))).flat();
|
|
441
|
+
const mainFunction = Object.entries(createFlowSchemaTriggerCacheMainFunction).flatMap(([type, mainFunction]) => mainFunction(_izContext, flowSchema, saveFilePath));
|
|
442
|
+
const handler = Object.entries(createFlowSchemaTriggerCacheHandler).flatMap(([type, handler]) => handler(_izContext, flowSchema, saveFilePath));
|
|
443
|
+
const queue = createFlowSchemaTriggerCacheQueue(flowSchema, saveFilePath);
|
|
444
|
+
// console.log("functionYaml", JSON.stringify(...functionYaml, null, 2))
|
|
445
|
+
createSourceParams.push(...functionYaml, ...mainFunction, ...handler, ...queue)
|
|
446
|
+
// console.log("createSourceParams triggerCache", JSON.stringify(createSourceParams, null, 2))
|
|
447
|
+
console.log("mainFunction triggerCache", JSON.stringify(mainFunction, null, 2))
|
|
448
|
+
console.log("handler triggerCache", JSON.stringify(handler, null, 2))
|
|
449
|
+
console.log("Generate triggerCache component")
|
|
450
|
+
}
|
|
419
451
|
}
|
|
420
452
|
|
|
421
453
|
if (allLocalFlowSchemas.records.length) {
|
|
454
|
+
|
|
422
455
|
console.log("flowSchema Register");
|
|
423
456
|
const flowSchemaRegisterHandlerComplete = createFlowSchemaRegisterHandlerComplete(_izContext, saveFilePath);
|
|
424
457
|
const flowSchemaRegisterMainComplete = await createFlowSchemaRegisterMainCompleteFunc(_izContext, allLocalFlowSchemas, saveFilePath);
|
package/src/reStructure/TemplateData/flowSchema/templateByStatusType/triggerCacheTemplate.ejs
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
let [triggerCacheStatus, triggerCache] = await triggeredCacheSharedLib.
|
|
1
|
+
let [triggerCacheStatus, triggerCache] = await triggeredCacheSharedLib.checkTriggeredCacheV2(
|
|
2
2
|
_izContext,
|
|
3
|
-
"<%- tableName %>",
|
|
4
3
|
{
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
serviceTag: process.env.iz_serviceTag,
|
|
5
|
+
flowTag: "<%- flowTag %>"
|
|
7
6
|
},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//(
|
|
7
|
+
{
|
|
8
|
+
//(<identifiersTriggerCacheTable>)
|
|
9
|
+
//(</identifiersTriggerCacheTable>)
|
|
10
|
+
},
|
|
11
|
+
//(<additionalCheckTriggerCacheSetting>)
|
|
12
|
+
"", // overWriteUniqueRequestId
|
|
13
|
+
{}, //flowParams
|
|
14
|
+
false, // createIfNotHave
|
|
15
|
+
{} // triggerFlowIdentifiers
|
|
16
|
+
//(</additionalCheckTriggerCacheSetting>)
|
|
13
17
|
)
|
|
14
18
|
|
|
15
19
|
//(<afterCheckTriggerCache>)
|
|
@@ -20,6 +24,15 @@ if (triggerCacheStatus !== "process") {
|
|
|
20
24
|
//(<afterValidateTriggerCacheStatus>)
|
|
21
25
|
//(</afterValidateTriggerCacheStatus>)
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
//(<checkTriggerCacheHook>)
|
|
28
|
+
//(</checkTriggerCacheHook>)
|
|
29
|
+
|
|
30
|
+
// send message to ProcessTriggerCache
|
|
31
|
+
let sendMessageToProcessTriggerCache = {
|
|
32
|
+
MessageBody: JSON.stringify(
|
|
33
|
+
//(<messageBody>)
|
|
34
|
+
//(</messageBody>)
|
|
35
|
+
),
|
|
36
|
+
QueueUrl: await sqsSharedLib.sqsQueueUrl(_izContext, "ProcessTriggerCache<%- flowTag %>HdrSqs")
|
|
37
|
+
}
|
|
25
38
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
21
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SQS_RESOURCE, DYNAMO_RESOURCE, shortNameHandler } = require('../../../../../../MainLibs/src/Consts');
|
|
22
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = require("../../../../../../MainLibs/src/Utils")
|
|
23
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
24
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
25
|
+
const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* receive objectSchema
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} objectSchema
|
|
31
|
+
* @return {{templatePath, templateData,setting}}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async function data(_izContext, flowSchema, srcPath) {
|
|
36
|
+
return [await createSourceParams(_izContext, flowSchema, srcPath)]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
40
|
+
let functionName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
|
|
41
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
42
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
43
|
+
let queueName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
|
|
44
|
+
|
|
45
|
+
additionalResourcePermission.push(
|
|
46
|
+
createIamRole(
|
|
47
|
+
{
|
|
48
|
+
[RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
|
|
49
|
+
},
|
|
50
|
+
[
|
|
51
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName),
|
|
52
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName + "DLQ")
|
|
53
|
+
]
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
let tableTriggerCache = new Set();
|
|
58
|
+
let objectSchema = await getObjectSchema.getLocalObjectSchemas(_izContext, [flowSchema.objType.objectType], path.join(srcPath, "./schemas")).then(res => res.records[0])
|
|
59
|
+
if (!objectSchema) {
|
|
60
|
+
throw new NoRetryError('ObjectSchema not found')
|
|
61
|
+
}
|
|
62
|
+
for (const storageResource of Object.values(objectSchema.storageResources)) {
|
|
63
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
64
|
+
if (!tableTriggerCache.has(storageResource.tableName)) {
|
|
65
|
+
tableTriggerCache.add(storageResource.tableName)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
additionalResourcePermission.push(
|
|
71
|
+
createIamRole(
|
|
72
|
+
{
|
|
73
|
+
[RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE)
|
|
74
|
+
},
|
|
75
|
+
[...tableTriggerCache].map(
|
|
76
|
+
tableName => resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName))
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
additionalResourcePermission.push(awaitingMultipleStepsRole())
|
|
81
|
+
return {
|
|
82
|
+
templatePath: templatePath,
|
|
83
|
+
templateData: {
|
|
84
|
+
resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
|
|
85
|
+
functionName,
|
|
86
|
+
handlerType,
|
|
87
|
+
additionalResourcePermission,
|
|
88
|
+
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
89
|
+
roleName: upperCase(flowSchema.flowTag),
|
|
90
|
+
queueName
|
|
91
|
+
},
|
|
92
|
+
setting: {
|
|
93
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
94
|
+
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
95
|
+
fileExtension: ".yml",
|
|
96
|
+
isAppend: true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = data;
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
'use strict';
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
22
|
+
const { SOURCE_PATH, FUNCTION_NAME, HANDLER, awaitingMultipleStepsRole, resourceNames, defaultIamRolePerAction } = require('../../../../../../MainLibs/src/Consts');
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = require("../../../../../../MainLibs/src/Utils")
|
|
24
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
25
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
26
|
+
const { STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* receive objectSchema
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} objectSchema
|
|
32
|
+
* @return {{templatePath, templateData,setting}}
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
37
|
+
return [createSourceParams(_izContext, flowSchema, srcPath)]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
41
|
+
let functionName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
|
|
42
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
43
|
+
let queueName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
templatePath: templatePath,
|
|
48
|
+
templateData: {
|
|
49
|
+
resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(functionName), "source/"),
|
|
50
|
+
functionName,
|
|
51
|
+
queueName
|
|
52
|
+
},
|
|
53
|
+
setting: {
|
|
54
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
|
|
55
|
+
saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
|
|
56
|
+
fileExtension: ".js",
|
|
57
|
+
isAppend: true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = data;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
// const AWS = require('aws-sdk');
|
|
21
|
+
// const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
|
|
22
|
+
|
|
23
|
+
const izara = require("@izara_project/izara-middleware");
|
|
24
|
+
const middleware = izara.middlewareHandler;
|
|
25
|
+
const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
|
|
26
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
28
|
+
const <%- functionName %> = require('./<%- functionName %>_Main')
|
|
29
|
+
|
|
30
|
+
// validate event properties in body.Message of sqs event
|
|
31
|
+
let perRecordsValidatorSchema = {
|
|
32
|
+
//(<validatorSchema>)
|
|
33
|
+
//(</validatorSchema>)
|
|
34
|
+
}
|
|
35
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
36
|
+
|
|
37
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
|
|
41
|
+
let recordPromises = [];
|
|
42
|
+
|
|
43
|
+
// loop each record and send to mainFunction
|
|
44
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
45
|
+
|
|
46
|
+
let passOnProperties = []
|
|
47
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
48
|
+
|
|
49
|
+
//validate message (and MessageAttributes)
|
|
50
|
+
await recordHandlerSharedLib.validateRecord(
|
|
51
|
+
record, // one record will send to mainFunction
|
|
52
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
53
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
54
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
58
|
+
passOnProperties.push(record.body.Message.identifiers)
|
|
59
|
+
passOnProperties.push(record.body.TopicArn)
|
|
60
|
+
//(<additionalParams>)
|
|
61
|
+
//(</additionalParams>)
|
|
62
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
63
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
64
|
+
|
|
65
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
66
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
67
|
+
record, // one record will send to mainFunction
|
|
68
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
69
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
70
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
71
|
+
);
|
|
72
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
73
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
74
|
+
}))
|
|
75
|
+
|
|
76
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
77
|
+
try {
|
|
78
|
+
// --- main await all promises
|
|
79
|
+
await Promise.all(recordPromises); // await all promises
|
|
80
|
+
|
|
81
|
+
return event.Records // return all for local testing
|
|
82
|
+
|
|
83
|
+
} catch {
|
|
84
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
85
|
+
}
|
|
86
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
87
|
+
|
|
88
|
+
} catch (err) {
|
|
89
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
90
|
+
throw (err);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
21
|
+
const { SOURCE_PATH, FUNCTION_NAME, HANDLER, SAVE_FILE_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
22
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } = require("../../../../../../MainLibs/src/Utils")
|
|
23
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* receive objectSchema
|
|
28
|
+
* create data for WebScoket handler template
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} objectSchema
|
|
31
|
+
* @return {{templatePath, templateData,setting}}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
35
|
+
return [createSourceParams(_izContext, flowSchema, srcPath)]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
39
|
+
let functionName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete"
|
|
40
|
+
let handlerType = upperCase(HANDLER.hdrSqs)
|
|
41
|
+
let queueName = "CheckTriggerCache" + upperCase(flowSchema.flowTag) + "Complete" + handlerType;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
templatePath: templatePath,
|
|
46
|
+
templateData: {
|
|
47
|
+
functionName,
|
|
48
|
+
queueName,
|
|
49
|
+
flowTag: flowSchema.flowTag
|
|
50
|
+
},
|
|
51
|
+
setting: {
|
|
52
|
+
savePath: path.join(srcPath, SOURCE_PATH.flowSchema, upperCase(flowSchema.flowTag), 'source/'),
|
|
53
|
+
saveFileName: `${upperCase(functionName)}_Main`,
|
|
54
|
+
fileExtension: ".js",
|
|
55
|
+
isAppend: true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = data;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http: //izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
22
|
+
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
23
|
+
const snsSharedLib = require('@izara_project/izara-core-library-sns');
|
|
24
|
+
const sqsSharedLib = require('@izara_project/izara-core-library-sqs');
|
|
25
|
+
const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
|
|
26
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
27
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
|
|
28
|
+
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
29
|
+
const sns = externalRequest.sns
|
|
30
|
+
const sqs = externalRequest.sqs
|
|
31
|
+
const lambda = externalRequest.lambda
|
|
32
|
+
const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
|
|
33
|
+
const { createFlowTypeConcat } = require('@izara_project/izara-core-library-service-schemas').utils
|
|
34
|
+
//(<optionalRequire>)
|
|
35
|
+
//(</optionalRequire>)
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
* description of function.
|
|
40
|
+
* @param {Object} _izContext
|
|
41
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
42
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
43
|
+
* @param {Object} requestParams - request params
|
|
44
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
45
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
46
|
+
*
|
|
47
|
+
*
|
|
48
|
+
* @returns {object} description of return value
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
module.exports.<%- functionName %> = async (
|
|
52
|
+
_izContext,
|
|
53
|
+
identifiers,
|
|
54
|
+
topicArn,
|
|
55
|
+
//(<additionalParams>)
|
|
56
|
+
//(</additionalParams>)
|
|
57
|
+
callingFlowConfig = {},
|
|
58
|
+
) => {
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
_izContext.logger.debug("<%- functionName %> _izContext", _izContext)
|
|
62
|
+
_izContext.logger.debug("<%- functionName %> identifiers", requestParams)
|
|
63
|
+
_izContext.logger.debug("<%- functionName %> topicArn", callingFlowConfig)
|
|
64
|
+
|
|
65
|
+
let topicName = topicArn.split(":")[5].split("_")
|
|
66
|
+
let flowTag = topicName[2]
|
|
67
|
+
|
|
68
|
+
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
69
|
+
flowTag: flowTag,
|
|
70
|
+
serviceTag: topicName[0]
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
let checkTriggerCache = await triggeredCacheSharedLib.checkTriggeredCacheV2(
|
|
74
|
+
_izContext,
|
|
75
|
+
{ // flowType
|
|
76
|
+
serviceTag: topicName[0],
|
|
77
|
+
flowTag: flowTag
|
|
78
|
+
},
|
|
79
|
+
...identifiers,
|
|
80
|
+
//(<triggerCacheAdditionalParam>)
|
|
81
|
+
"", // overwriteUniqueRequestId,
|
|
82
|
+
{}, // flowParams
|
|
83
|
+
true, // createIfNotExists
|
|
84
|
+
{}, // triggerFlowIdentifiers
|
|
85
|
+
//(</triggerCacheAdditionalParam>)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
_izContext.logger.debug("checkTriggerCache: ", checkTriggerCache)
|
|
89
|
+
|
|
90
|
+
//(<endpointHook>)
|
|
91
|
+
//(</endpointHook>)
|
|
92
|
+
|
|
93
|
+
} catch (err) {
|
|
94
|
+
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
95
|
+
throw (err)
|
|
96
|
+
}
|
|
97
|
+
}
|