@izara_project/izara-market-library-service-schemas 1.0.57 → 1.0.58
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/EndpointPerService/yaml/data.js +3 -21
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +2 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +2 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/data.js +0 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +13 -8
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +10 -8
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +6 -6
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/template.ejs +0 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/S3/data.js +4 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/S3/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +2 -45
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/sns-out/data.js +75 -0
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +16 -16
- package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ttlDynamoTemplate.ejs +32 -0
- package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/userUploadRecords.js +58 -0
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +23 -15
- package/src/reStructure/TemplateData/flowSchema/webSocketComplete/mainFunction/template.ejs +7 -6
- package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +2 -2
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrDsq/data.js +0 -87
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrDsq/template.ejs +0 -30
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerDsq/data.js +0 -45
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerDsq/template.ejs +0 -151
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/request.json +0 -7
package/package.json
CHANGED
|
@@ -117,27 +117,9 @@ async function createParamForCreateSource(_izContext, allObjSchemas, action, han
|
|
|
117
117
|
createIamRole(
|
|
118
118
|
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
119
119
|
[
|
|
120
|
-
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.createObjectComplete) + "_Out")
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
createIamRole(
|
|
125
|
-
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
126
|
-
[
|
|
127
|
-
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.updateNodeComplete) + "_Out")
|
|
128
|
-
]
|
|
129
|
-
),
|
|
130
|
-
createIamRole(
|
|
131
|
-
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
132
|
-
[
|
|
133
|
-
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.deleteNodeComplete) + "_Out")
|
|
134
|
-
]
|
|
135
|
-
),
|
|
136
|
-
createIamRole(
|
|
137
|
-
{
|
|
138
|
-
[RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish
|
|
139
|
-
},
|
|
140
|
-
[
|
|
120
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.createObjectComplete) + "_Out"),
|
|
121
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.updateNodeComplete) + "_Out"),
|
|
122
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.deleteNodeComplete) + "_Out"),
|
|
141
123
|
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.getNodeComplete) + "_Out")
|
|
142
124
|
]
|
|
143
125
|
)
|
package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js
CHANGED
|
@@ -77,7 +77,8 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
|
77
77
|
]
|
|
78
78
|
},
|
|
79
79
|
[
|
|
80
|
-
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
|
|
80
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask"),
|
|
81
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "UserUploadRecords")
|
|
81
82
|
]
|
|
82
83
|
),
|
|
83
84
|
createIamRole(
|
package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/data.js
CHANGED
|
@@ -38,26 +38,12 @@ async function data(_izContext, flowSchema, srcPath) {
|
|
|
38
38
|
|
|
39
39
|
async function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
|
|
40
40
|
let functionName = upperCase(FUNCTION_NAME.createObjectS3)
|
|
41
|
-
let objectSchema = await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(_izContext, flowSchema.objType)
|
|
42
41
|
let objectType = flowSchema.objType.objectType
|
|
43
|
-
let createdFieldNames = [];
|
|
44
|
-
let statusFieldNames = [];
|
|
45
|
-
for (const [fieldNames, fieldSettings] of Object.entries(objectSchema.fieldNames)) {
|
|
46
|
-
if (fieldSettings.hasOwnProperty("requiredOnCreate") && fieldSettings.requiredOnCreate === true) {
|
|
47
|
-
createdFieldNames.push(fieldNames);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (fieldSettings.hasOwnProperty("statusField") && fieldSettings.statusField === true) {
|
|
51
|
-
statusFieldNames.push(fieldNames)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
42
|
|
|
55
43
|
return {
|
|
56
44
|
templatePath: templatePath,
|
|
57
45
|
templateData: {
|
|
58
46
|
flowTag: flowSchema.flowTag,
|
|
59
|
-
createdFieldNames: createdFieldNames,
|
|
60
|
-
statusFieldNames: statusFieldNames,
|
|
61
47
|
objectType
|
|
62
48
|
},
|
|
63
49
|
setting: {
|
|
@@ -33,8 +33,8 @@ const sns = externalRequest.sns
|
|
|
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
35
|
const { v4: uuidv4 } = require('uuid')
|
|
36
|
-
const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
|
|
37
36
|
const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
37
|
+
const { consts } = require('@izara_project/izara-middleware');
|
|
38
38
|
|
|
39
39
|
//(<optionalRequired>)
|
|
40
40
|
//(</optionalRequired>)
|
|
@@ -67,7 +67,7 @@ module.exports.createObject = async (
|
|
|
67
67
|
_izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
|
|
68
68
|
_izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
|
|
69
69
|
|
|
70
|
-
let
|
|
70
|
+
let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
|
|
71
71
|
|
|
72
72
|
let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
|
|
73
73
|
flowTag: "<%- flowTag %>",
|
|
@@ -76,16 +76,18 @@ module.exports.createObject = async (
|
|
|
76
76
|
|
|
77
77
|
_izContext.logger.debug("getFlowSchema", flowSchema)
|
|
78
78
|
|
|
79
|
-
let
|
|
80
|
-
await dynamodbSharedLib.tableName(_izContext, "
|
|
79
|
+
let getUserFromTableUserUploadRecord = await dynamodbSharedLib.getItem(_izContext,
|
|
80
|
+
await dynamodbSharedLib.tableName(_izContext, "UserUploadRecords"),
|
|
81
81
|
{
|
|
82
|
-
|
|
82
|
+
connectionId: connectionId
|
|
83
83
|
}
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
-
const { userId,
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const { userId, submittedByUserId } = getUserFromTableUserUploadRecord
|
|
87
|
+
_izContext.correlationIds.set(consts.BASE_USER_ID, userId)
|
|
88
|
+
_izContext.correlationIds.set(consts.TARGET_ID, submittedByUserId)
|
|
89
|
+
|
|
90
|
+
if (!flowSchema) {
|
|
89
91
|
throw new NoRetryError(`flowTag not found ${requestParams.action}`)
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -93,6 +95,9 @@ module.exports.createObject = async (
|
|
|
93
95
|
let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, flowSchema.objType)
|
|
94
96
|
_izContext.logger.debug("objectSchema in flowSchema mainFunction", objectSchema)
|
|
95
97
|
|
|
98
|
+
if (!objectSchema) {
|
|
99
|
+
throw new NoRetryError(`${flowSchema.objType.objectType} not found`)
|
|
100
|
+
}
|
|
96
101
|
|
|
97
102
|
//(<beforeCreateHook>)
|
|
98
103
|
//(</beforeCreateHook>)
|
|
@@ -38,6 +38,8 @@ const utils = require('@izara_project/izara-market-library-service-schemas/src/M
|
|
|
38
38
|
const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
|
|
39
39
|
const { EXTERNAL_SERVICE_NAME } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
|
|
40
40
|
const { createFlowTypeConcat } = require("@izara_project/izara-core-library-service-schemas").utils
|
|
41
|
+
//(<optionalRequired>)
|
|
42
|
+
//(</optionalRequired>)
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* description of function.
|
|
@@ -83,8 +85,8 @@ module.exports.createPresignUrl = async (
|
|
|
83
85
|
await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv"),
|
|
84
86
|
{
|
|
85
87
|
objectType: objType.objectType,
|
|
86
|
-
//(<
|
|
87
|
-
//(</
|
|
88
|
+
//(<identifiersForGetData>)
|
|
89
|
+
//(</identifiersForGetData>)
|
|
88
90
|
}
|
|
89
91
|
)
|
|
90
92
|
_izContext.logger.debug("getResult", getResult);
|
|
@@ -116,8 +118,8 @@ module.exports.createPresignUrl = async (
|
|
|
116
118
|
let updateStatusField = {
|
|
117
119
|
objInstanceFull: {
|
|
118
120
|
identifiers: {
|
|
119
|
-
//(<
|
|
120
|
-
//(</
|
|
121
|
+
//(<identifiersForUpdateStatus>)
|
|
122
|
+
//(</identifiersForUpdateStatus>)
|
|
121
123
|
},
|
|
122
124
|
fields: {
|
|
123
125
|
//(<fields>)
|
|
@@ -129,7 +131,7 @@ module.exports.createPresignUrl = async (
|
|
|
129
131
|
|
|
130
132
|
let sendMessageToUpdateEndpoint = {
|
|
131
133
|
Message: JSON.stringify(updateStatusField),
|
|
132
|
-
TopicArn: await snsSharedLib.
|
|
134
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, `Update_In`)
|
|
133
135
|
}
|
|
134
136
|
_izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
|
|
135
137
|
|
|
@@ -143,7 +145,7 @@ module.exports.createPresignUrl = async (
|
|
|
143
145
|
|
|
144
146
|
let sendMessageToCancelReserved = {
|
|
145
147
|
Message: JSON.stringify(cancelReservedMsg),
|
|
146
|
-
TopicArn: await snsSharedLib.
|
|
148
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'CancelUsage_In', EXTERNAL_SERVICE_NAME.accountLimits)
|
|
147
149
|
};
|
|
148
150
|
|
|
149
151
|
_izContext.logger.debug("sendMessageToCancelReserved", sendMessageToCancelReserved);
|
|
@@ -225,7 +227,7 @@ module.exports.createPresignUrl = async (
|
|
|
225
227
|
|
|
226
228
|
let sendMessageToUpdateEndpoint = {
|
|
227
229
|
Message: JSON.stringify(messageObject),
|
|
228
|
-
TopicArn: await snsSharedLib.
|
|
230
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Update_In")
|
|
229
231
|
}
|
|
230
232
|
_izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
|
|
231
233
|
await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
|
|
@@ -238,7 +240,7 @@ module.exports.createPresignUrl = async (
|
|
|
238
240
|
await dynamodbSharedLib.updateItem(_izContext,
|
|
239
241
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
240
242
|
{
|
|
241
|
-
taskKey: `${createFlowTypeConcat(
|
|
243
|
+
taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
|
|
242
244
|
connectionId: connectionId
|
|
243
245
|
},
|
|
244
246
|
{
|
|
@@ -87,7 +87,7 @@ module.exports.reservedLimit = async (
|
|
|
87
87
|
|
|
88
88
|
let sendMsgReservedDynamic = {
|
|
89
89
|
userId: _izContext.correlationIds.get(coreConsts.BASE_USER_ID),
|
|
90
|
-
|
|
90
|
+
targetId: _izContext.correlationIds.get(coreConsts.TARGET_ID),
|
|
91
91
|
//(<additionalPropertiesReservedDynamic>)
|
|
92
92
|
//(</additionalPropertiesReservedDynamic>)
|
|
93
93
|
}
|
|
@@ -105,9 +105,9 @@ module.exports.reservedLimit = async (
|
|
|
105
105
|
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
106
106
|
callingFlowConfig,
|
|
107
107
|
callingFlowSharedLib.createCallingFlowConfig(
|
|
108
|
-
//(<
|
|
108
|
+
//(<callingFlowPropertiesIfHaveCallingFlowConfig>)
|
|
109
109
|
await lambdaSharedLib.lambdaFunctionName(_izContext, "ReservedLimitCompleteHdrSqs"),
|
|
110
|
-
//(</
|
|
110
|
+
//(</callingFlowPropertiesIfHaveCallingFlowConfig>)
|
|
111
111
|
callingFlowProperties
|
|
112
112
|
)
|
|
113
113
|
)
|
|
@@ -116,9 +116,9 @@ module.exports.reservedLimit = async (
|
|
|
116
116
|
sendMsgReservedDynamic = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
117
117
|
sendMsgReservedDynamic,
|
|
118
118
|
callingFlowSharedLib.createCallingFlowConfig(
|
|
119
|
-
//(<
|
|
119
|
+
//(<callingFlowPropertiesIfNotHaveCallingFlowConfig>)
|
|
120
120
|
await lambdaSharedLib.lambdaFunctionName(_izContext, "ReservedLimitCompleteHdrSqs"),
|
|
121
|
-
//(</
|
|
121
|
+
//(</callingFlowPropertiesIfNotHaveCallingFlowConfig>)
|
|
122
122
|
callingFlowProperties
|
|
123
123
|
)
|
|
124
124
|
);
|
|
@@ -139,7 +139,7 @@ module.exports.reservedLimit = async (
|
|
|
139
139
|
|
|
140
140
|
let sendMessageToReservedDynamic = {
|
|
141
141
|
Message: JSON.stringify(sendMsgReservedDynamic),
|
|
142
|
-
TopicArn: await snsSharedLib.
|
|
142
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "ReservedDynamicUsage_In", consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
143
143
|
};
|
|
144
144
|
_izContext.logger.debug("sendMessageToReservedDynamic", sendMessageToReservedDynamic);
|
|
145
145
|
await sns.publishAsync(_izContext, sendMessageToReservedDynamic);
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
4
|
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
5
|
events:
|
|
6
|
-
- sqs:
|
|
7
|
-
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
-
batchSize: 10
|
|
9
6
|
- s3:
|
|
10
7
|
bucket: <%- bucketName %>
|
|
11
8
|
event: s3:ObjectCreated:*
|
|
@@ -36,10 +36,13 @@ function data(_izContext, flowSchema, srcPath) {
|
|
|
36
36
|
|
|
37
37
|
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
38
38
|
let bucketName = flowSchema.bucketName
|
|
39
|
+
let resourceName = bucketName.split("-").join("")
|
|
40
|
+
|
|
39
41
|
return {
|
|
40
42
|
templatePath: templatePath,
|
|
41
43
|
templateData: {
|
|
42
|
-
bucketName
|
|
44
|
+
bucketName,
|
|
45
|
+
resourceName
|
|
43
46
|
},
|
|
44
47
|
setting: {
|
|
45
48
|
initialData: 'Resources:\n',
|
|
@@ -22,10 +22,7 @@ const lambda = externalRequest.lambda;
|
|
|
22
22
|
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda')
|
|
23
23
|
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
|
|
24
24
|
const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
25
|
-
|
|
26
|
-
const csv = require('csv-parser');
|
|
27
|
-
const streamifier = require('streamifier');
|
|
28
|
-
<% } %>
|
|
25
|
+
|
|
29
26
|
const { NoRetryError,inMemoryCacheLib } = require('@izara_project/izara-core-library-core');
|
|
30
27
|
|
|
31
28
|
const client = new ApiGatewayManagementApiClient({
|
|
@@ -74,43 +71,6 @@ const processStaticLimitWithCache = inMemoryCacheLib(
|
|
|
74
71
|
}
|
|
75
72
|
)
|
|
76
73
|
|
|
77
|
-
<% if (uploadS3) { %>
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {Object} _izContext
|
|
81
|
-
* @param {Object} data - S3 data
|
|
82
|
-
* @returns
|
|
83
|
-
*/
|
|
84
|
-
async function isValidCsv(_izContext, data) {
|
|
85
|
-
_izContext.logger.debug("function checkValidCsv", { data })
|
|
86
|
-
let errorCheckCsv = [];
|
|
87
|
-
let validCsv = true;
|
|
88
|
-
let rowCount = 0;
|
|
89
|
-
let columnCount = null;
|
|
90
|
-
|
|
91
|
-
streamifier.createReadStream(data.Body).pipe(csv()).on('data', (row) => {
|
|
92
|
-
rowCount++;
|
|
93
|
-
if (columnCount === null) {
|
|
94
|
-
columnCount = Object.keys(row).length
|
|
95
|
-
} else if (Object.keys(row).length !== columnCount) {
|
|
96
|
-
validCsv = false
|
|
97
|
-
errorCheckCsv.push(`Row ${rowCount} has inconsistent columns: ${JSON.stringify(row)}`)
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
.on('end', () => {
|
|
101
|
-
if (rowCount === 0) {
|
|
102
|
-
errorCheckCsv.push("csv file not have data row")
|
|
103
|
-
} else {
|
|
104
|
-
_izContext.logger.debug("validCsv")
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.on('error', (error) => {
|
|
108
|
-
errorCheckCsv.push(`error:: ${error}`)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
return [validCsv, errorCheckCsv]
|
|
112
|
-
}
|
|
113
|
-
<% } %>
|
|
114
74
|
|
|
115
75
|
/**
|
|
116
76
|
*
|
|
@@ -135,8 +95,5 @@ module.exports = {
|
|
|
135
95
|
postToConnection,
|
|
136
96
|
processStaticLimit,
|
|
137
97
|
processStaticLimitWithCache,
|
|
138
|
-
getNestObject
|
|
139
|
-
<% if (uploadS3) { %>
|
|
140
|
-
isValidCsv,
|
|
141
|
-
<% } %>
|
|
98
|
+
getNestObject
|
|
142
99
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 path = require("path")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// const {
|
|
24
|
+
// HANDLER,
|
|
25
|
+
// STORAGE_TYPES
|
|
26
|
+
// } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const STORAGE_TYPES = {
|
|
30
|
+
dynamoDB: "dynamoDB",
|
|
31
|
+
graph: "graph"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const templatePath = path.join(__dirname, '../../../../../resourceYaml/sns-out/template.ejs')
|
|
35
|
+
const {
|
|
36
|
+
utils: { firstLetterUpperCase: upperCase },
|
|
37
|
+
consts: { SOURCE_PATH, SAVE_FILE_NAME }
|
|
38
|
+
} = require("../../../../../../../MainLibs")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* create data for template.ejs
|
|
43
|
+
* return array of defaultSnsOutData
|
|
44
|
+
* because must create for FindData and ProcessLogical
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} _izContext
|
|
47
|
+
* @param {String} saveFilePath
|
|
48
|
+
* @returns {Object[]} - data of multiple defaultSnsOutData
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
function createDataForDefaultSnsOut(_izContext, flowSchema, srcPath) {
|
|
52
|
+
let resultsForCreateDefaultSnsOut = [];
|
|
53
|
+
const defaultSnsOutDataList = [
|
|
54
|
+
{
|
|
55
|
+
queueName: upperCase(flowSchema.flowTag)
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
for (let defaultSnsOutData of defaultSnsOutDataList) {
|
|
60
|
+
resultsForCreateDefaultSnsOut.push({
|
|
61
|
+
templatePath: templatePath,
|
|
62
|
+
templateData: defaultSnsOutData,
|
|
63
|
+
setting: {
|
|
64
|
+
initialData: "Resources:\n",
|
|
65
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
66
|
+
saveFileName: SAVE_FILE_NAME.snsOutYaml,
|
|
67
|
+
fileExtension: ".yml",
|
|
68
|
+
isAppend: true
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
return resultsForCreateDefaultSnsOut;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = createDataForDefaultSnsOut;
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs
CHANGED
|
@@ -28,33 +28,33 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
28
28
|
const { eventType, connectionId } = event.requestContext
|
|
29
29
|
try {
|
|
30
30
|
|
|
31
|
-
let userId = event.queryStringParameters.userId
|
|
32
|
-
let submitByUserId = event.queryStringParameters.submitByUserId
|
|
33
|
-
let correlationIds = event._izContext.correlationIds.get(izara.consts.X_CORRELATION_ID)
|
|
34
|
-
|
|
35
31
|
if (event.requestContext) {
|
|
36
32
|
switch (eventType) {
|
|
37
33
|
case 'CONNECT':
|
|
38
34
|
console.log('Connect websocket')
|
|
35
|
+
|
|
36
|
+
let { userId, submittedByUserId } = event.queryStringParameters;
|
|
37
|
+
|
|
39
38
|
await dynamodbSharedLib.putItem(event._izContext,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
await dynamodbSharedLib.tableName(event._izContext, "UserUploadRecords"),
|
|
40
|
+
{
|
|
41
|
+
connectionId: connectionId,
|
|
42
|
+
userId: userId,
|
|
43
|
+
submittedByUserId: submittedByUserId,
|
|
44
|
+
expirationTime: Math.floor(Date.now() / 1000) + 7200 // ttl time milliSecond to second + 2 hour
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
47
|
//(<webSocketConnect>)
|
|
48
48
|
//(</webSocketConnect>)
|
|
49
49
|
break
|
|
50
50
|
case 'DISCONNECT':
|
|
51
51
|
console.log('Websocket are Disconnection')
|
|
52
52
|
await dynamodbSharedLib.deleteItem(event._izContext,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
await dynamodbSharedLib.tableName(event._izContext, "UserUploadRecords"),
|
|
54
|
+
{
|
|
55
|
+
connectionId: connectionId,
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
58
|
//(<webSocketDisconnect>)
|
|
59
59
|
//(</webSocketDisconnect>)
|
|
60
60
|
break
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ttlDynamoTemplate.ejs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<%- resourceName %>Table:
|
|
2
|
+
Type: "AWS::DynamoDB::Table"
|
|
3
|
+
Properties:
|
|
4
|
+
TableName: ${self:custom.iz_resourcePrefix}<%- tableName %>
|
|
5
|
+
BillingMode: PAY_PER_REQUEST
|
|
6
|
+
AttributeDefinitions:
|
|
7
|
+
<%_ attributes.forEach(attribute => { -%>
|
|
8
|
+
- AttributeName: <%- attribute['AttributeName'] %>
|
|
9
|
+
AttributeType: <%- attribute['AttributeType'] %>
|
|
10
|
+
<%_ }) _%>
|
|
11
|
+
KeySchema:
|
|
12
|
+
<%_ attributes.forEach(attribute => { -%>
|
|
13
|
+
<%_ if (attribute.keyType === 'partitionKey' || attribute.keyType === "identifier") { -%>
|
|
14
|
+
- AttributeName: <%- attribute["AttributeName"] %>
|
|
15
|
+
KeyType: HASH
|
|
16
|
+
<%_ } -%>
|
|
17
|
+
<%_ if(attribute.keyType === "sortKey") { -%>
|
|
18
|
+
- AttributeName: <%- attribute["AttributeName"] %>
|
|
19
|
+
KeyType: RANGE
|
|
20
|
+
<%_ } -%>
|
|
21
|
+
<%_ }) _%>
|
|
22
|
+
TimeToLiveSpecification:
|
|
23
|
+
AttributeName: expirationTime
|
|
24
|
+
Enabled: true
|
|
25
|
+
#<#<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
|
|
26
|
+
#<#/<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
|
|
27
|
+
<%_ function firstLetterUpperCase(text){
|
|
28
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
29
|
+
} _%>
|
|
30
|
+
<%_ function firstLetterLowerCase(str) {
|
|
31
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
32
|
+
} _%>
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/userUploadRecords.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
21
|
+
|
|
22
|
+
const templatePath = path.join(__dirname, "./ttlDynamoTemplate.ejs")
|
|
23
|
+
|
|
24
|
+
function data(_izContext, srcPath) {
|
|
25
|
+
let resultForCreateSources = [];
|
|
26
|
+
const userUploadRecords = [
|
|
27
|
+
{
|
|
28
|
+
tableName: "UserUploadRecords",
|
|
29
|
+
resourceName: "UserUploadRecords",
|
|
30
|
+
attributes: [
|
|
31
|
+
{
|
|
32
|
+
keyType: "partitionKey",
|
|
33
|
+
AttributeName: "connectionId",
|
|
34
|
+
AttributeType: "S"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
for (let userUploadRecord of userUploadRecords) {
|
|
41
|
+
resultForCreateSources.push(
|
|
42
|
+
{
|
|
43
|
+
templatePath: templatePath,
|
|
44
|
+
templateData: userUploadRecord,
|
|
45
|
+
setting: {
|
|
46
|
+
initialData: 'Resources:\n',
|
|
47
|
+
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
48
|
+
saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
|
|
49
|
+
fileExtension: ".yml",
|
|
50
|
+
isAppend: true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return resultForCreateSources;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = data;
|
|
@@ -29,21 +29,23 @@ const {
|
|
|
29
29
|
|
|
30
30
|
// Core components
|
|
31
31
|
const createWebSocketDynamoDb = require('./components/websocket/dynamoDb/WebSocketTaskData');
|
|
32
|
+
const createUserUploadRecordTable = require('./components/websocket/dynamoDb/userUploadRecords')
|
|
32
33
|
const createReservedDataMainTable = require('./components/websocket/dynamoDb/ReservedTableData');
|
|
33
34
|
const createBucketS3 = require('./components/upload/relate/S3/data');
|
|
34
35
|
const createWebSocketGenerateCodeLibs = require('./components/upload/relate/libs/data');
|
|
35
36
|
const createWebSocketConnectYaml = require('./components/websocket/connect/functionYaml/data')
|
|
36
37
|
const createWebSocketConnectHandler = require('./components/websocket/connect/handler/data')
|
|
38
|
+
const createSnsTopicForUploadS3 = require('./components/upload/relate/sns-out/data')
|
|
37
39
|
// CreateObject components
|
|
38
40
|
const createFunctionYamlCreateObjectWebSocket = require('./components/upload/createObject/functionYaml/data');
|
|
39
41
|
const createHandlerCreateObjectWebSocket = require('./components/upload/createObject/handler/data');
|
|
40
42
|
const createMainFunctionCreateObjectWebSocket = require('./components/upload/createObject/mainFunction/data');
|
|
41
43
|
|
|
42
44
|
// CreateObjectComplete components
|
|
43
|
-
const createWebSocketCreateObjectCompleteFunctionYaml = require('./components/upload/createObjectComplete/functionYaml/data');
|
|
44
|
-
const createWebSocketCreateObjectCompleteQueue = require('./components/upload/createObjectComplete/sns-sqs/data');
|
|
45
|
-
const createWebSocketCreateObjectCompleteHandler = require('./components/upload/createObjectComplete/handler/data');
|
|
46
|
-
const createWebSocketCreateObjectCompleteMainFunction = require('./components/upload/createObjectComplete/mainFunction/data');
|
|
45
|
+
// const createWebSocketCreateObjectCompleteFunctionYaml = require('./components/upload/createObjectComplete/functionYaml/data');
|
|
46
|
+
// const createWebSocketCreateObjectCompleteQueue = require('./components/upload/createObjectComplete/sns-sqs/data');
|
|
47
|
+
// const createWebSocketCreateObjectCompleteHandler = require('./components/upload/createObjectComplete/handler/data');
|
|
48
|
+
// const createWebSocketCreateObjectCompleteMainFunction = require('./components/upload/createObjectComplete/mainFunction/data');
|
|
47
49
|
|
|
48
50
|
// PreSign URL components
|
|
49
51
|
const createReservedLimitFunctionYaml = require('./components/upload/preSignUrl/reservedLimit/functionYaml/data');
|
|
@@ -72,9 +74,9 @@ const createConfirmAfterUploadS3Queue = require('./components/upload/confirmRese
|
|
|
72
74
|
// flowSchema ExternalTopic components //
|
|
73
75
|
const createExternalSqsFunctionYaml = require('./externalTopic/Process/functionYaml/data');
|
|
74
76
|
const createExternalSqsHandler = require('./externalTopic/Process/handler/data');
|
|
75
|
-
const createExternalSqsCompleteFunctionYaml = require("./externalTopic/Complete/functionYaml/data");
|
|
76
|
-
const createExternalSqsCompleteHandler = require("./externalTopic/Complete/handler/data");
|
|
77
|
-
const createExternalSqsCompleteMainFunction = require("./externalTopic/Complete/mainFunction/data");
|
|
77
|
+
// const createExternalSqsCompleteFunctionYaml = require("./externalTopic/Complete/functionYaml/data");
|
|
78
|
+
// const createExternalSqsCompleteHandler = require("./externalTopic/Complete/handler/data");
|
|
79
|
+
// const createExternalSqsCompleteMainFunction = require("./externalTopic/Complete/mainFunction/data");
|
|
78
80
|
const createExternalTopicSnsInSqs = require('./externalTopic/sns-in-sqs/data');
|
|
79
81
|
const createExternalTopicSnsOut = require('./externalTopic/sns-out/data')
|
|
80
82
|
|
|
@@ -101,9 +103,9 @@ const createFlowSchemaFlowStepHandler = require('./flowStep/handler/data');
|
|
|
101
103
|
const createFlowSchemaFlowStepMainFunction = require('./flowStep/mainFunction/data')
|
|
102
104
|
const createFlowSchemaFlowStepSnsIn = require('./flowStep/sns-in/data');
|
|
103
105
|
// flowSchema OwnTopicEndpointComplete component
|
|
104
|
-
const createFlowSchemaOwnTopicEndpointCompleteFuntionYaml = require('./flowSchemaOwnTopic/EndpointComplete/functionYaml/data');
|
|
105
|
-
const createFlowSchemaOwnTopicEndpointCompleteHandler = require('./flowSchemaOwnTopic/EndpointComplete/handler/data');
|
|
106
|
-
const createFlowSchemaOwnTopicEndpointCompleteMainFunction = require('./flowSchemaOwnTopic/EndpointComplete/mainFunction/data');
|
|
106
|
+
// const createFlowSchemaOwnTopicEndpointCompleteFuntionYaml = require('./flowSchemaOwnTopic/EndpointComplete/functionYaml/data');
|
|
107
|
+
// const createFlowSchemaOwnTopicEndpointCompleteHandler = require('./flowSchemaOwnTopic/EndpointComplete/handler/data');
|
|
108
|
+
// const createFlowSchemaOwnTopicEndpointCompleteMainFunction = require('./flowSchemaOwnTopic/EndpointComplete/mainFunction/data');
|
|
107
109
|
|
|
108
110
|
const createFlowSchemaOwnTopicQueue = require('./flowSchemaOwnTopic/sns-in/data');
|
|
109
111
|
const createFlowSchemaOwnTopicSnsOut = require('./flowSchemaOwnTopic/sns-out/data');
|
|
@@ -121,10 +123,10 @@ const createFlowSchemaLambdaSyncHandlerApi = require("./lambdaSync/Api/handler/d
|
|
|
121
123
|
|
|
122
124
|
const createAwaitingMultipleStepDynamoDbData = require('./dynamoDb/data');
|
|
123
125
|
// create record status Field Complete
|
|
124
|
-
const createCreateObjectCompleteFunctionYaml = require('./CreateRecordComplete/functionYaml/data');
|
|
125
|
-
const createCreateObjectCompleteHandler = require('./CreateRecordComplete/handler/data');
|
|
126
|
-
const createCreateObjectCompleteMainFunction = require('./CreateRecordComplete/mainFunction/data');
|
|
127
|
-
const createCreateObjectCompleteQueue = require('./CreateRecordComplete/queue/data');// flowSchema Register component //
|
|
126
|
+
// const createCreateObjectCompleteFunctionYaml = require('./CreateRecordComplete/functionYaml/data');
|
|
127
|
+
// const createCreateObjectCompleteHandler = require('./CreateRecordComplete/handler/data');
|
|
128
|
+
// const createCreateObjectCompleteMainFunction = require('./CreateRecordComplete/mainFunction/data');
|
|
129
|
+
// const createCreateObjectCompleteQueue = require('./CreateRecordComplete/queue/data');// flowSchema Register component //
|
|
128
130
|
|
|
129
131
|
const createFlowSchemaRegisterHandlerComplete = require('./register/complete/handler/data');
|
|
130
132
|
const createFlowSchemaRegisterMainCompleteFunc = require('./register/complete/mainFunction/data');
|
|
@@ -178,9 +180,10 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
178
180
|
for (const flowSchema of allLocalFlowSchemas.records) {
|
|
179
181
|
// console.log("flowSchema in Generate TemplateData", flowSchema);
|
|
180
182
|
const webSocketGenerateCodeLibs = createWebSocketGenerateCodeLibs(_izContext, flowSchema, saveFilePath)
|
|
183
|
+
createSourceParams.push(...webSocketGenerateCodeLibs)
|
|
181
184
|
if (!flowSchema.event.includes("s3")) {
|
|
182
185
|
const flowSchemaEndpointMainFunction = await createFlowSchemaEndpointMainFunction(_izContext, flowSchema, saveFilePath);
|
|
183
|
-
createSourceParams.push(...
|
|
186
|
+
createSourceParams.push(...flowSchemaEndpointMainFunction)
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
// event has [s3, extTopic, ownTopic, eventBridge, lambdaSync]
|
|
@@ -188,6 +191,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
188
191
|
if (event.includes("s3")) {
|
|
189
192
|
const reservedDataTable = createReservedDataMainTable(_izContext, saveFilePath);
|
|
190
193
|
const bucketS3 = createBucketS3(_izContext, flowSchema, saveFilePath)
|
|
194
|
+
const userUploadRecordTable = createUserUploadRecordTable(_izContext, saveFilePath)
|
|
191
195
|
|
|
192
196
|
const functionYamlCreateObjectWebSocket = createFunctionYamlCreateObjectWebSocket(_izContext, flowSchema, saveFilePath);
|
|
193
197
|
const handlerCreateObjectWebSocket = createHandlerCreateObjectWebSocket(_izContext, flowSchema, saveFilePath);
|
|
@@ -221,6 +225,8 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
221
225
|
const confirmReservedAfterUploadMainFunction = createConfirmAfterUploadS3MainFunction(_izContext, flowSchema, saveFilePath);
|
|
222
226
|
const confirmReservedAfterUploadQueue = createConfirmAfterUploadS3Queue(_izContext, saveFilePath);
|
|
223
227
|
|
|
228
|
+
const snsTopicOutFlowSchemaUploadS3 = createSnsTopicForUploadS3(_izContext, flowSchema, saveFilePath);
|
|
229
|
+
|
|
224
230
|
const webSocketFunctions = [
|
|
225
231
|
...functionYamlCreateObjectWebSocket,
|
|
226
232
|
...handlerCreateObjectWebSocket,
|
|
@@ -275,6 +281,8 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
275
281
|
...reservedLimitResources,
|
|
276
282
|
...processAfterUploadResources,
|
|
277
283
|
...confirmAfterUploadResources,
|
|
284
|
+
...snsTopicOutFlowSchemaUploadS3,
|
|
285
|
+
...userUploadRecordTable
|
|
278
286
|
);
|
|
279
287
|
|
|
280
288
|
} else if (event.includes("extTopic")) {
|
|
@@ -88,21 +88,24 @@ module.exports.<%- functionName %> = async (
|
|
|
88
88
|
throw new NoRetryError("not have flowSchema in S3")
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
let wbsTasks;
|
|
91
|
+
let wbsTasks;
|
|
92
|
+
let taskKey;
|
|
92
93
|
if (flowSchema.statusType === "statusField" || flowSchema.statusType === "storedCache" || flowSchema.statusType === "triggerCache") {
|
|
94
|
+
taskKey = `${createFlowTypeConcat(_izContext,{flowTag: topicName[2],serviceTag: topicName[0]})}${identifiers}`
|
|
93
95
|
wbsTasks = await dynamodbSharedLib.query(
|
|
94
96
|
_izContext,
|
|
95
97
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
96
98
|
{
|
|
97
|
-
taskKey:
|
|
99
|
+
taskKey: taskKey
|
|
98
100
|
}
|
|
99
101
|
)
|
|
100
102
|
} else if (flowSchema.statusType === "none") {
|
|
103
|
+
taskKey = `${createFlowTypeConcat(_izContext,{flowTag: topicName[2],serviceTag: topicName[0]})}${correlationId}`
|
|
101
104
|
wbsTasks = await dynamodbSharedLib.query(
|
|
102
105
|
_izContext,
|
|
103
106
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
104
107
|
{
|
|
105
|
-
taskKey:
|
|
108
|
+
taskKey: taskKey
|
|
106
109
|
}
|
|
107
110
|
)
|
|
108
111
|
}
|
|
@@ -119,13 +122,11 @@ module.exports.<%- functionName %> = async (
|
|
|
119
122
|
await dynamodbSharedLib.deleteItem(_izContext,
|
|
120
123
|
await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
|
|
121
124
|
{
|
|
122
|
-
taskKey:
|
|
125
|
+
taskKey: taskKey,
|
|
123
126
|
connectionId: connectionId
|
|
124
127
|
}
|
|
125
128
|
)
|
|
126
129
|
}))
|
|
127
|
-
|
|
128
|
-
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
} catch (err) {
|
|
@@ -315,7 +315,7 @@ module.exports.processLogical = async (
|
|
|
315
315
|
comparison: comparison,
|
|
316
316
|
callingFlow: callingFlow
|
|
317
317
|
}),
|
|
318
|
-
TopicArn: await snsSharedLib.
|
|
318
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "InPaginateProcessLogical")
|
|
319
319
|
};
|
|
320
320
|
_izContext.logger.debug('Request params before send to topic InPaginateProcessLogical: ', sentMessageToPaginateProcessLogical);
|
|
321
321
|
|
|
@@ -374,7 +374,7 @@ module.exports.processLogical = async (
|
|
|
374
374
|
sortKeyFieldName: sortKeyFieldName,
|
|
375
375
|
callingFlow: callingFlow
|
|
376
376
|
}),
|
|
377
|
-
TopicArn: await snsSharedLib.
|
|
377
|
+
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "InPaginateProcessLogical")
|
|
378
378
|
};
|
|
379
379
|
_izContext.logger.debug('Request params before send to topic InPaginateProcessLogical: ', sentMessageToPaginateProcessLogical);
|
|
380
380
|
|
package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js
CHANGED
|
@@ -70,7 +70,7 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema, srcPa
|
|
|
70
70
|
let attributeType;
|
|
71
71
|
if (fieldNameType === 'string') {
|
|
72
72
|
attributeType = "S"
|
|
73
|
-
} else if (fieldNameType === 'number') {
|
|
73
|
+
} else if (fieldNameType === 'number' || fieldNameType === "timestamp") {
|
|
74
74
|
attributeType = "N"
|
|
75
75
|
}
|
|
76
76
|
Object.assign(
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2021 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 path = require("path")
|
|
21
|
-
|
|
22
|
-
const { firstLetterUpperCase: upperCase } = require('../../../../../../../MainLibs/src/Utils');
|
|
23
|
-
const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, S3_RESOURCE, resourceNames, DYNAMO_RESOURCE, SQS_RESOURCE, SNS_RESOURCE, shortNameHandler, HANDLER, FUNCTION_NAME } = require("../../../../../libs/Consts");
|
|
24
|
-
const templatePath = path.join(__dirname, "./template.ejs")
|
|
25
|
-
|
|
26
|
-
function data(_izContext, srcPath) {
|
|
27
|
-
return [createSourceParam(_izContext, srcPath)]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function createSourceParam(_izContext, srcPath) {
|
|
31
|
-
let functionName = upperCase(FUNCTION_NAME.processAfterUploadS3);
|
|
32
|
-
let handlerType = HANDLER.hdrDsq;
|
|
33
|
-
let additionalResourcePermission = defaultIamRolePerAction();
|
|
34
|
-
additionalResourcePermission.push(
|
|
35
|
-
|
|
36
|
-
createIamRole(
|
|
37
|
-
{
|
|
38
|
-
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
39
|
-
DYNAMO_RESOURCE.updateItem,
|
|
40
|
-
DYNAMO_RESOURCE.getItem
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
[
|
|
44
|
-
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "ImportBatchMain")
|
|
45
|
-
]
|
|
46
|
-
),
|
|
47
|
-
createIamRole(
|
|
48
|
-
{
|
|
49
|
-
[RESOURCE_CLASSES.sqs]: [
|
|
50
|
-
SQS_RESOURCE.sendMessage,
|
|
51
|
-
SQS_RESOURCE.receiveMessage,
|
|
52
|
-
SQS_RESOURCE.deleteMessage,
|
|
53
|
-
SQS_RESOURCE.getQueueAttributes
|
|
54
|
-
]
|
|
55
|
-
},
|
|
56
|
-
[
|
|
57
|
-
resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType),
|
|
58
|
-
resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType + "DLQ")
|
|
59
|
-
]
|
|
60
|
-
),
|
|
61
|
-
createIamRole(
|
|
62
|
-
{
|
|
63
|
-
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
64
|
-
},
|
|
65
|
-
[
|
|
66
|
-
resourceNames(RESOURCE_CLASSES.sns, "In" + functionName)
|
|
67
|
-
]
|
|
68
|
-
)
|
|
69
|
-
)
|
|
70
|
-
return {
|
|
71
|
-
templatePath: templatePath,
|
|
72
|
-
templateData: {
|
|
73
|
-
functionName,
|
|
74
|
-
handlerType,
|
|
75
|
-
additionalResourcePermission,
|
|
76
|
-
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
77
|
-
},
|
|
78
|
-
setting: {
|
|
79
|
-
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
80
|
-
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
81
|
-
isAppend: true,
|
|
82
|
-
fileExtension: ".yml"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports = data
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<%_ const join = require('path').join; _%>
|
|
2
|
-
<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
|
|
3
|
-
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
-
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
-
events:
|
|
6
|
-
- sqs:
|
|
7
|
-
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
|
|
8
|
-
batchSize: 10
|
|
9
|
-
iamRoleStatements:
|
|
10
|
-
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
11
|
-
- Effect: <%- resourcePermission.effect %>
|
|
12
|
-
Action:
|
|
13
|
-
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
14
|
-
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
15
|
-
- <%- resourcePerAction %>:<%- permission %>
|
|
16
|
-
<%_}) _%>
|
|
17
|
-
<%_ }) _%>
|
|
18
|
-
Resource:
|
|
19
|
-
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
20
|
-
- <%- resource %>
|
|
21
|
-
<%_ }) _%>
|
|
22
|
-
<%_}) _%>
|
|
23
|
-
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
24
|
-
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
25
|
-
<%_ function firstLetterUpperCase(text){
|
|
26
|
-
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
27
|
-
} _%>
|
|
28
|
-
<%_ function firstLetterLowerCase(str) {
|
|
29
|
-
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
30
|
-
} _%>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2021 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 path = require("path")
|
|
21
|
-
|
|
22
|
-
const { firstLetterUpperCase: upperCase } = require('../../../../../../../MainLibs/src/Utils');
|
|
23
|
-
const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, S3_RESOURCE, resourceNames, DYNAMO_RESOURCE, SQS_RESOURCE, SNS_RESOURCE, shortNameHandler, HANDLER, FUNCTION_NAME } = require("../../../../../libs/Consts");
|
|
24
|
-
const templatePath = path.join(__dirname, "./template.ejs")
|
|
25
|
-
|
|
26
|
-
function data(_izContext, srcPath) {
|
|
27
|
-
return [createSourceData(_izContext, srcPath)]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function createSourceData(_izContext, srcPath) {
|
|
31
|
-
let functionName = FUNCTION_NAME.processAfterUploadS3;
|
|
32
|
-
let handlerType = HANDLER.hdrDsq;
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
templatePath: templatePath,
|
|
36
|
-
templateData: {},
|
|
37
|
-
setting: {
|
|
38
|
-
saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
|
|
39
|
-
savePath: path.join(srcPath, SOURCE_PATH.webSocket),
|
|
40
|
-
fileExtension: ".js",
|
|
41
|
-
isAppend: false
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
module.exports = data;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2021 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-shared").recordHandlerSharedLib;
|
|
26
|
-
const Logger = require('@izara_project/izara-core-library-logger');
|
|
27
|
-
const izaraShared = require('@izara_project/izara-shared');
|
|
28
|
-
const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
|
|
29
|
-
|
|
30
|
-
const processAfterUpload = require('./ProcessAfterUploadS3_Main')
|
|
31
|
-
|
|
32
|
-
// validate event properties in body.Message of sqs event
|
|
33
|
-
middleware.setValidatorSchema(
|
|
34
|
-
recordHandlerSharedLib.baseValidatorSchema({
|
|
35
|
-
type: 'object',
|
|
36
|
-
required: ['body', 'messageAttributes'],
|
|
37
|
-
properties: {
|
|
38
|
-
body: {
|
|
39
|
-
type: 'object',
|
|
40
|
-
},
|
|
41
|
-
messageAttributes: {
|
|
42
|
-
type: 'object',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// set schema for record.body.Message
|
|
49
|
-
let perRecordsValidatorSchema = {
|
|
50
|
-
type: "object",
|
|
51
|
-
required: [
|
|
52
|
-
'bucket',
|
|
53
|
-
'field',
|
|
54
|
-
'importBy'
|
|
55
|
-
],
|
|
56
|
-
properties: {
|
|
57
|
-
bucket: {
|
|
58
|
-
type: "string"
|
|
59
|
-
},
|
|
60
|
-
field: {
|
|
61
|
-
type: "object"
|
|
62
|
-
},
|
|
63
|
-
importBy: {
|
|
64
|
-
type: "string"
|
|
65
|
-
},
|
|
66
|
-
imageImportId: {
|
|
67
|
-
type: "string"
|
|
68
|
-
},
|
|
69
|
-
realImageSize: {
|
|
70
|
-
type: "number",
|
|
71
|
-
default: 0
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// set schema for record.body.MessageAttributes
|
|
77
|
-
// const messageAttributeValidatorSchema = {
|
|
78
|
-
// type: "object",
|
|
79
|
-
// required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
80
|
-
// properties: {
|
|
81
|
-
// msgAtrrParam1: {
|
|
82
|
-
// type: "string"
|
|
83
|
-
// },
|
|
84
|
-
// msgAtrrParam2: {
|
|
85
|
-
// type: "object"
|
|
86
|
-
// }
|
|
87
|
-
// }
|
|
88
|
-
// };
|
|
89
|
-
|
|
90
|
-
perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema)
|
|
91
|
-
|
|
92
|
-
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
|
|
96
|
-
let recordPromises = []; // final return
|
|
97
|
-
|
|
98
|
-
// loop each record and send to mainFunction
|
|
99
|
-
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
100
|
-
|
|
101
|
-
// --- reforming record.body for Dsq request
|
|
102
|
-
record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
|
|
103
|
-
record._izContext.logger.debug('record GetSignedUrlS3HdrDsq after reform', record);
|
|
104
|
-
|
|
105
|
-
let passOnProperties = []
|
|
106
|
-
|
|
107
|
-
// validate message (and MessageAttributes)
|
|
108
|
-
await recordHandlerSharedLib.validateRecord(
|
|
109
|
-
record, // one record will send to mainFunction
|
|
110
|
-
"ProcessAfterUploadHdrDsq", // queue name that need to retry or send to dlq
|
|
111
|
-
perRecordsValidatorSchema, // schema for record.Message
|
|
112
|
-
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// add argument (to invoke lambda) to passOnProperties[]
|
|
116
|
-
passOnProperties.push(record.body.Message.bucket),
|
|
117
|
-
passOnProperties.push(record.body.Message.field),
|
|
118
|
-
passOnProperties.push(record.body.Message.importBy),
|
|
119
|
-
passOnProperties.push(record.body.Message.imageImportId),
|
|
120
|
-
passOnProperties.push(record.body.Message.realImageSize),
|
|
121
|
-
passOnProperties.push(record.body.Message.passBackProperties),
|
|
122
|
-
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
123
|
-
|
|
124
|
-
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
125
|
-
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
126
|
-
record, // one record will send to mainFunction
|
|
127
|
-
processAfterUpload.processAfterUpload, // mainFunction that need to invoke.
|
|
128
|
-
"ProcessAfterUploadHdrDsq", // queue name that need to retry or send to dlq
|
|
129
|
-
passOnProperties, // all parameters that mainFunction needed.
|
|
130
|
-
);
|
|
131
|
-
record._izContext.logger.debug('after recordPromise in handler');
|
|
132
|
-
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
133
|
-
}))
|
|
134
|
-
|
|
135
|
-
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
136
|
-
try {
|
|
137
|
-
// --- main await all promises
|
|
138
|
-
await Promise.all(recordPromises); // await all promises
|
|
139
|
-
|
|
140
|
-
return event.Records // return all for local test
|
|
141
|
-
|
|
142
|
-
} catch {
|
|
143
|
-
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
144
|
-
}
|
|
145
|
-
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
146
|
-
|
|
147
|
-
} catch (err) {
|
|
148
|
-
Logger.error('Unhandled Error, processImageAfterUpload: ', err);
|
|
149
|
-
throw (err);
|
|
150
|
-
}
|
|
151
|
-
});
|