@izara_project/izara-core-generate-service-code 1.0.53 → 1.0.55
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 -2
- package/src/codeGenerators/app/initial_setup/InitialSetupGenerator.js +1 -1
- package/src/codeGenerators/app/sls_yaml/FindDataYamlGenerator.js +23 -0
- package/src/codeGenerators/app/sls_yaml/FunctionYamlGenerator.js +16 -16
- package/src/codeGenerators/app/sls_yaml/ProcessLogicalYamlGenerator.js +11 -25
- package/src/codeGenerators/app/sls_yaml/RoleNameConfigGenerator.js +1 -1
- package/src/codeGenerators/app/sls_yaml/SharedResourceYamlGenerator.js +3 -3
- package/src/codeGenerators/app/sls_yaml/renderYamlTemplate.js +13 -0
- package/src/codeGenerators/app/sls_yaml/templates/SharedResource_Yaml.ejs +6 -2
- package/src/codeGenerators/app/src/generatedCode/FindData/FindDataGenerator.js +10 -44
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowEndpoints/EndpointsGenerator.js +119 -0
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowRbac/RbacFlowGenerator.js +91 -52
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowRelationshipEndpoints/RelationshipFlowGenerator.js +20 -16
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/StatusFieldGenerator.js +2 -9
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/WebSocketGenerator.js +1 -7
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/BaseSqsHandler.js +3 -3
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3Components/ConfirmAfterUploadS3Generator.js +2 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3Components/CreateObjectGenerator.js +2 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3Components/CreatePreSignUrlGenerator.js +2 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3Components/ProcessAfterUploadS3Generator.js +5 -5
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3Components/ReservedLimitGenerator.js +2 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowEntryPointBase.js +6 -6
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowMainFunctionBase.js +3 -3
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowStepBase.js +11 -11
- package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/triggerCacheBase.js +1 -7
- package/src/codeGenerators/app/src/generatedCode/ProcessLogical/ProcessLogicalGenerator.js +18 -15
- package/src/codeGenerators/app/src/generatedCode/ProcessLogical/templates/{PaginateProcessLogical_HdrDsq.js → PaginateProcessLogical_HdrDsq.ejs} +1 -1
- package/src/codeGenerators/app/src/generatedCode/SystemFlowSchemas/RegisterGenerator.js +127 -149
- package/src/codeGenerators/app/src/generatedCode/libs/ConstsGenerator.js +16 -8
- package/src/codeGenerators/app/src/generatedCode/libs/GenerateCodeLibsGenerator.js +17 -9
- package/src/codeGenerators/resource/sls_yaml/DynamoDBGenerator.js +8 -8
- package/src/codeGenerators/resource/sls_yaml/FlowOutGenerator.js +60 -43
- package/src/codeGenerators/resource/sls_yaml/FlowResourceYamlGenerator.js +151 -151
- package/src/codeGenerators/resource/sls_yaml/templates/crud/ResourceYaml.ejs +10 -10
- package/src/core/renderTemplateFile.js +22 -0
- package/src/generateCode.js +146 -81
- package/src/generateIntTest.js +45 -69
- package/src/generateResourceIntTest.js +22 -47
- package/src/intTestGeneratorShared.js +36 -0
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicFlowSchemaTemplate.ejs +12 -10
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/RelationshipFlowSchemaTemplate.ejs +6 -5
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/flowSchemaMainFunction/data.js +0 -119
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/flowSchemaMainFunction/template.ejs +0 -89
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/flowSchemaMainFunction/templateByStatusType/statusFieldTemplate.ejs +0 -30
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/flowSchemaMainFunction/templateByStatusType/storedCacheTemplate.ejs +0 -26
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/flowSchemaMainFunction/templateByStatusType/triggerCacheTemplate.ejs +0 -44
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/index.js +0 -80
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/functionYaml/data.js +0 -129
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/functionYaml/template.ejs +0 -17
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/handler/data.js +0 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/mainFunction/data.js +0 -54
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/mainFunction/template.ejs +0 -129
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/queue/data.js +0 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/confirmReserved/queue/template.ejs +0 -45
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObject/functionYaml/data.js +0 -117
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObject/functionYaml/template.ejs +0 -20
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObject/handler/data.js +0 -64
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObject/mainFunction/data.js +0 -64
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObject/mainFunction/template.ejs +0 -131
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/functionYaml/data.js +0 -122
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/functionYaml/template.ejs +0 -17
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/handler/data.js +0 -66
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/handler/template.ejs +0 -99
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/mainFunction/data.js +0 -64
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/mainFunction/template.ejs +0 -82
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/sns-sqs/data.js +0 -70
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/createObjectComplete/sns-sqs/template.ejs +0 -49
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/functionYaml/data.js +0 -139
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/functionYaml/template.ejs +0 -18
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/handler/data.js +0 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/mainFunction/data.js +0 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/mainFunction/template.ejs +0 -262
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/queue/data.js +0 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/createPreSignUrl/queue/template.ejs +0 -45
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/functionYaml/data.js +0 -146
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +0 -14
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/handler/data.js +0 -64
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/mainFunction/data.js +0 -59
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +0 -173
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/sqs/data.js +0 -67
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/preSignUrl/reservedLimit/sqs/template.ejs +0 -53
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/functionYml/HdrS3/data.js +0 -140
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/functionYml/HdrS3/template.ejs +0 -25
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/handler/handlerS3/data.js +0 -49
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/handler/handlerS3/template.ejs +0 -50
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/mainFunction/ProcessCsvtemplate.ejs +0 -182
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/mainFunction/data.js +0 -49
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/mainFunction/template.ejs +0 -66
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/queue/data.js +0 -77
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/queue/dsqTemplatePath.ejs +0 -32
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/processFile/queue/s3Template.ejs +0 -59
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/relate/S3/data.js +0 -61
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/relate/S3/template.ejs +0 -13
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/upload/relate/sns-out/data.js +0 -70
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3Legacy/websocket/dynamoDb/ReservedTableData.js +0 -69
- package/src/codeGenerators/app/src/generatedCode/Flow/SystemFlowDescriptorBuilder.js +0 -151
- /package/src/codeGenerators/app/{src/generatedCode/FindData → sls_yaml}/templates/FindData_Yaml.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared/endpoint → FlowEndpoints/templates}/FlowEndpointBeforeLogical_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/endpoint/FlowEndpoint_HdrWbs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/endpoint/FlowEndpoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/endpoint/FlowEntryPoint_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/endpoint/FlowMain_Wbs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/{s3Legacy/upload/confirmReserved/handler/template.ejs → s3/ConfirmReserved_HdrSqs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/{s3Legacy/upload/createObject/handler/template.ejs → s3/CreateObject_HdrWbs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/{s3Legacy/upload/preSignUrl/createPreSignUrl/handler/template.ejs → s3/CreatePreSignUrl_HdrSqs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/{s3Legacy/upload/preSignUrl/reservedLimit/handler/template.ejs → s3/ReservedLimit_HdrSqs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/FlowEndpointComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/FlowStep_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/FlowStep_ByConfig_Awaiting_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/FlowStep_ByConfig_Paginated_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/FlowStep_PlugIn_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/FlowStep_RecievePlugIn_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/templateAwaitingStep.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → FlowSchemas/templates}/step/plugIns/templateSendPlugin.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/eventBridge.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/extTopic.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/lambdaSyncApi.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/lambdaSyncInv.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/ownTopic.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/registry.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/events/s3.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/handlers/FlowHandler_HdrApi.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/handlers/FlowHandler_HdrInv.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/handlers/FlowHandler_HdrSqs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/eventTypes.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowClassifier.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowNaming.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowSelection.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowStepNormalizer.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/flowValidator.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal → _shared}/shared/registry.js +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/CheckTriggerCache_HdrSqs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/CheckTriggerCache_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/ProcessTriggerCache_HdrSqs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/ProcessTriggerCache_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/TriggerCacheComplete_HdrDsq.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/TriggerCacheComplete_HdrSqs.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/TriggerCacheComplete_Main.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/triggerCache/TriggerCacheQueue_Yaml.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/Flow/{_internal/_shared → _shared}/yaml/SharedFunctionSqs_Yaml.ejs +0 -0
- /package/src/codeGenerators/app/src/generatedCode/ProcessLogical/templates/{PaginateProcessLogical_HdrSqs.js → PaginateProcessLogical_HdrSqs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/ProcessLogical/templates/{PaginateProcessLogical_Main.js → PaginateProcessLogical_Main.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/ProcessLogical/templates/{ProcessLogical_HdrSqs.js → ProcessLogical_HdrSqs.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/ProcessLogical/templates/{ProcessLogical_Main.js → ProcessLogical_Main.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/libs/templates/{Consts.js → Consts.ejs} +0 -0
- /package/src/codeGenerators/app/src/generatedCode/libs/templates/{GenerateCodeLibs.js → GenerateCodeLibs.ejs} +0 -0
|
@@ -1,140 +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
|
-
import path from 'path';
|
|
19
|
-
import { fileURLToPath } from 'url';
|
|
20
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
-
const __dirname = path.dirname(__filename);
|
|
22
|
-
|
|
23
|
-
import consts from '#libs/Consts.js';
|
|
24
|
-
import utils from '#libs/Utils.js';
|
|
25
|
-
import libs from '#libs/Libs.js';
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
SOURCE_PATH,
|
|
29
|
-
SAVE_FILE_NAME,
|
|
30
|
-
RESOURCE_CLASSES,
|
|
31
|
-
S3_RESOURCE,
|
|
32
|
-
DYNAMO_RESOURCE,
|
|
33
|
-
SQS_RESOURCE,
|
|
34
|
-
SNS_RESOURCE,
|
|
35
|
-
FUNCTION_NAME,
|
|
36
|
-
LAMBDA_RESOURCE,
|
|
37
|
-
SOURCE_GENERATE_IAM_ROLE,
|
|
38
|
-
ACTIONS,
|
|
39
|
-
HANDLER
|
|
40
|
-
} = consts;
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
defaultIamRolePerAction,
|
|
44
|
-
createIamRole,
|
|
45
|
-
resourceNames,
|
|
46
|
-
shortNameHandler
|
|
47
|
-
} = libs;
|
|
48
|
-
|
|
49
|
-
const { firstLetterUpperCase: upperCase } = utils;
|
|
50
|
-
|
|
51
|
-
const templatePath = path.join(__dirname, 'template.ejs');
|
|
52
|
-
|
|
53
|
-
function createSourceParam(_izContext, flowSchema, appPath) {
|
|
54
|
-
let functionName = upperCase(FUNCTION_NAME.processAfterUploadS3);
|
|
55
|
-
let handlerType = 'HdrS3';
|
|
56
|
-
let additionalResourcePermission = defaultIamRolePerAction();
|
|
57
|
-
let bucketName = flowSchema.bucketName;
|
|
58
|
-
additionalResourcePermission.push(
|
|
59
|
-
createIamRole(
|
|
60
|
-
{
|
|
61
|
-
[RESOURCE_CLASSES.s3]: [
|
|
62
|
-
S3_RESOURCE.getObject,
|
|
63
|
-
S3_RESOURCE.getObjectTagging,
|
|
64
|
-
S3_RESOURCE.putObject,
|
|
65
|
-
S3_RESOURCE.putObjectTagging,
|
|
66
|
-
S3_RESOURCE.deleteObject,
|
|
67
|
-
S3_RESOURCE.deleteObjectTagging
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
[
|
|
71
|
-
resourceNames(RESOURCE_CLASSES.s3, bucketName),
|
|
72
|
-
resourceNames(RESOURCE_CLASSES.s3, bucketName + '/*')
|
|
73
|
-
]
|
|
74
|
-
),
|
|
75
|
-
createIamRole(
|
|
76
|
-
{
|
|
77
|
-
[RESOURCE_CLASSES.sqs]: [
|
|
78
|
-
SQS_RESOURCE.sendMessage,
|
|
79
|
-
SQS_RESOURCE.receiveMessage,
|
|
80
|
-
SQS_RESOURCE.deleteMessage,
|
|
81
|
-
SQS_RESOURCE.getQueueAttributes
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
[
|
|
85
|
-
resourceNames(RESOURCE_CLASSES.sqs, functionName),
|
|
86
|
-
resourceNames(RESOURCE_CLASSES.sqs, functionName + 'DLQ')
|
|
87
|
-
]
|
|
88
|
-
),
|
|
89
|
-
createIamRole(
|
|
90
|
-
{
|
|
91
|
-
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
92
|
-
},
|
|
93
|
-
[resourceNames(RESOURCE_CLASSES.sns, functionName + '_In')]
|
|
94
|
-
),
|
|
95
|
-
createIamRole(
|
|
96
|
-
{
|
|
97
|
-
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish],
|
|
98
|
-
[RESOURCE_CLASSES.lambda]: [LAMBDA_RESOURCE.invokeFunction]
|
|
99
|
-
},
|
|
100
|
-
[
|
|
101
|
-
resourceNames(RESOURCE_CLASSES.sns, upperCase(ACTIONS.update) + '_In'),
|
|
102
|
-
resourceNames(
|
|
103
|
-
RESOURCE_CLASSES.lambda,
|
|
104
|
-
upperCase(ACTIONS.get) + upperCase(HANDLER.hdrInv)
|
|
105
|
-
)
|
|
106
|
-
]
|
|
107
|
-
),
|
|
108
|
-
createIamRole(
|
|
109
|
-
{
|
|
110
|
-
[RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.getItem]
|
|
111
|
-
},
|
|
112
|
-
[resourceNames(RESOURCE_CLASSES.dynamoDbTable, 'ReservedDataMain')]
|
|
113
|
-
)
|
|
114
|
-
);
|
|
115
|
-
return {
|
|
116
|
-
templatePath: templatePath,
|
|
117
|
-
templateData: {
|
|
118
|
-
functionName,
|
|
119
|
-
handlerType,
|
|
120
|
-
additionalResourcePermission,
|
|
121
|
-
resourceLocation: path.join(
|
|
122
|
-
SOURCE_PATH.resourceLocationWebSocket,
|
|
123
|
-
flowSchema.flowTag,
|
|
124
|
-
'source/'
|
|
125
|
-
),
|
|
126
|
-
bucketName,
|
|
127
|
-
functionNameConfig:
|
|
128
|
-
upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
129
|
-
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
130
|
-
},
|
|
131
|
-
setting: {
|
|
132
|
-
savePath: path.join(appPath, SOURCE_PATH.appYaml),
|
|
133
|
-
saveFileName: SAVE_FILE_NAME.flowSchemaYaml,
|
|
134
|
-
isAppend: true,
|
|
135
|
-
fileExtension: '.yml'
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default createSourceParam;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<%_ const join = require('path').join; _%>
|
|
2
|
-
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
-
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
-
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
-
role: <%- roleName %>Role
|
|
6
|
-
#<#<%- functionName %><%- handlerType %>FunctionSetting#>
|
|
7
|
-
#<#/<%- functionName %><%- handlerType %>FunctionSetting#>
|
|
8
|
-
events:
|
|
9
|
-
- s3:
|
|
10
|
-
bucket: <%- bucketName %>
|
|
11
|
-
event: s3:ObjectCreated:*
|
|
12
|
-
existing: true
|
|
13
|
-
rules:
|
|
14
|
-
#<#<%- functionName %><%- handlerType %>rules#>
|
|
15
|
-
#<#/<%- functionName %><%- handlerType %>rules#>
|
|
16
|
-
- prefix: uploads/
|
|
17
|
-
- suffix: .csv
|
|
18
|
-
forceDeploy: true
|
|
19
|
-
|
|
20
|
-
<%_ function firstLetterUpperCase(text){
|
|
21
|
-
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
22
|
-
} _%>
|
|
23
|
-
<%_ function firstLetterLowerCase(str) {
|
|
24
|
-
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
25
|
-
} _%>
|
|
@@ -1,49 +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
|
-
import path from 'path';
|
|
19
|
-
import { fileURLToPath } from 'url';
|
|
20
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
-
const __dirname = path.dirname(__filename);
|
|
22
|
-
|
|
23
|
-
import consts from '#libs/Consts.js';
|
|
24
|
-
import utils from '#libs/Utils.js';
|
|
25
|
-
|
|
26
|
-
const { SOURCE_PATH, FUNCTION_NAME } = consts;
|
|
27
|
-
|
|
28
|
-
const { firstLetterUpperCase: upperCase } = utils;
|
|
29
|
-
const templatePath = path.join(__dirname, 'template.ejs');
|
|
30
|
-
|
|
31
|
-
function createSourceData(_izContext, flowSchema, appPath) {
|
|
32
|
-
let functionName = FUNCTION_NAME.processAfterUploadS3;
|
|
33
|
-
let handlerType = 'HdrS3';
|
|
34
|
-
return {
|
|
35
|
-
templatePath: templatePath,
|
|
36
|
-
templateData: {},
|
|
37
|
-
setting: {
|
|
38
|
-
savePath: path.join(
|
|
39
|
-
appPath,
|
|
40
|
-
SOURCE_PATH.webSocket,
|
|
41
|
-
flowSchema.flowTag,
|
|
42
|
-
'source/'
|
|
43
|
-
),
|
|
44
|
-
saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
|
|
45
|
-
fileExtension: '.js'
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export default createSourceData;
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
|
|
19
|
-
import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
|
|
20
|
-
import Logger from '@izara_project/izara-core-library-logger';
|
|
21
|
-
import recordHandlerS3SharedLib from '@izara_project/izara-core-library-record-handler';
|
|
22
|
-
|
|
23
|
-
import <%= functionName %> from './<%= functionName %>_Main.js';
|
|
24
|
-
//--------------------------------------------------------------------------
|
|
25
|
-
middleware.setValidatorSchema(recordHandlerS3SharedLib.baseValidatorSchemaS3());
|
|
26
|
-
|
|
27
|
-
export const main = middleware.wrap(async (event, context) => {
|
|
28
|
-
try {
|
|
29
|
-
Logger.debug("event is:", event)
|
|
30
|
-
Logger.debug("event.Records[0] is:", event.Records[0])
|
|
31
|
-
|
|
32
|
-
let processImageResponse = await <%= functionName %>(
|
|
33
|
-
event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
|
|
34
|
-
event.Records[0].s3.bucket,
|
|
35
|
-
event.Records[0].s3.object,
|
|
36
|
-
//(<additionalProperties>)
|
|
37
|
-
//(</additionalProperties>)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if (processImageResponse instanceof Error) {
|
|
41
|
-
return (response.failure(processImageResponse));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return (response.success(processImageResponse));
|
|
45
|
-
|
|
46
|
-
} catch (err) {
|
|
47
|
-
event._izContext.logger.error('Error, <%= functionName %><%= handlerType %>: ', err);
|
|
48
|
-
return (response.failure(err));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/* Copyright (C) 2021 Sven Mason <http://izara.io> This program is free
|
|
2
|
-
software: you can redistribute it and/or modify it under the terms of the GNU
|
|
3
|
-
Affero General Public License as published by the Free Software Foundation,
|
|
4
|
-
either version 3 of the License, or (at your option) any later version. This
|
|
5
|
-
program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
6
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
7
|
-
PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
-
You should have received a copy of the GNU Affero General Public License along
|
|
9
|
-
with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
10
|
-
const callingFlowSharedLib =
|
|
11
|
-
require('@izara_project/izara-core-library-calling-flow'); const snsSharedLib =
|
|
12
|
-
require('@izara_project/izara-core-library-sns'); const dynamodbSharedLib =
|
|
13
|
-
require('@izara_project/izara-core-library-dynamodb'); const lambdaSharedLib =
|
|
14
|
-
require('@izara_project/izara-core-library-lambda'); const externalRequest =
|
|
15
|
-
require('@izara_project/izara-core-library-external-request') const lambda =
|
|
16
|
-
externalRequest.lambda; const sns = externalRequest.sns; const NoRetryError =
|
|
17
|
-
require('@izara_project/izara-core-library-core').NoRetryError; const utils =
|
|
18
|
-
require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils');
|
|
19
|
-
const { S3Client, GetObjectCommand, DeleteObjectCommand, PutObjectCommand,
|
|
20
|
-
CopyObjectCommand } = require('@aws-sdk/client-s3'); const s3 = new S3Client({
|
|
21
|
-
region: 'us-east-2' }); const hash =
|
|
22
|
-
require('@izara_project/izara-shared-core').objectHash; const Readable =
|
|
23
|
-
require('stream'); const { isValidCsv, getNestObject } =
|
|
24
|
-
require('../../../../libs/source/GenerateCodeLibs/index.js'); const consts =
|
|
25
|
-
require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
26
|
-
const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
|
|
27
|
-
/** * description of function. * @param {Object} _izContext * @param
|
|
28
|
-
{CorrelationIds} _izContext.correlationIds - property of _izContext * @param
|
|
29
|
-
{Logger} _izContext.logger - property of _izContext * @param {Logger}
|
|
30
|
-
_izContext.logger.debug - property of _izContext * @param {Object} bucket -
|
|
31
|
-
bucket's data * @param {Array} field - image's data * @param {Array} importBy -
|
|
32
|
-
'webSocket' || 'importData' * @param {Array} imageImportId - from importData *
|
|
33
|
-
@param {Array} realImageSize - from importData * @param {Array}
|
|
34
|
-
passBackProperties - from importData * * @returns {object} returnResponse */
|
|
35
|
-
module.exports.processAfterUpload = async ( _izContext, bucket, field, importBy
|
|
36
|
-
= '', importBatchId = '', realImageSize = 0, passBackProperties = {} ) => { try
|
|
37
|
-
{ _izContext.logger.debug('----- processImageFile event params ----- ', {
|
|
38
|
-
bucket: bucket, field: field, importBy: importBy, importBatchId: importBatchId,
|
|
39
|
-
realImageSize: realImageSize, passBackProperties: passBackProperties }) let
|
|
40
|
-
errorsFound = []; const objectS3Param = { Bucket: bucket.name, Key: field.key }
|
|
41
|
-
_izContext.logger.debug("params before getObjectParam::", objectS3Param) const
|
|
42
|
-
fileObjectS3 = await s3.send(new GetObjectCommand(objectS3Param));
|
|
43
|
-
_izContext.logger.debug("get fileObjectS3", fileObjectS3); importBatchId =
|
|
44
|
-
fileObjectS3.Metadata.importbatchid let getImportBatchMain = await
|
|
45
|
-
lambda.invokeSync(_izContext, await
|
|
46
|
-
lambdaSharedLib.lambdaFunctionName(_izContext, "ImportBatchMainGetHdrInv"), {
|
|
47
|
-
identifiers: { importBatchId: importBatchId } } )
|
|
48
|
-
_izContext.logger.debug("getImportBatchMain", getImportBatchMain)
|
|
49
|
-
_izContext.correlationIds.set(coreConsts.BASE_USER_ID,
|
|
50
|
-
getImportBatchMain.fields.userId);
|
|
51
|
-
_izContext.correlationIds.set(coreConsts.TARGET_ID,
|
|
52
|
-
getImportBatchMain.fields.submittedByUserId); let userId =
|
|
53
|
-
_izContext.correlationIds.get(coreConsts.BASE_USER_ID); let targetId =
|
|
54
|
-
_izContext.correlationIds.get(coreConsts.TARGET_ID); if (Date.now() >
|
|
55
|
-
getImportBatchMain.fields.expiryTimestamp) { errorsFound.push("url expired can't
|
|
56
|
-
upload") let sendMessageUpdateUrlExpired = { objInstanceFull: { identifiers: {
|
|
57
|
-
importBatchId: importBatchId }, fields: { importBatchStatus: "urlExpired",
|
|
58
|
-
errorsFound: "url expired can't upload", processingError: true } } } let
|
|
59
|
-
sendMessageToInImportBatchUpdate = { Message:
|
|
60
|
-
JSON.stringify(sendMessageUpdateUrlExpired), TopicArn: await
|
|
61
|
-
snsSharedLib.snsTopicArn(_izContext, "InImportBatchMainUpdate") };
|
|
62
|
-
_izContext.logger.debug("message param before send to updateImportBatchMain",
|
|
63
|
-
sendMessageToInImportBatchUpdate); await sns.publishAsync(_izContext,
|
|
64
|
-
sendMessageToInImportBatchUpdate); let deleteFileObjectS3 = await s3.send(new
|
|
65
|
-
DeleteObjectCommand(objectS3Param)); _izContext.logger.debug("Delete object
|
|
66
|
-
response: ", deleteFileObjectS3) return } if (fileObjectS3) { if
|
|
67
|
-
(!importBatchId) { errorsFound.push("cant't get importBatchId from S3 uploaded
|
|
68
|
-
file"); } } else { errorsFound.push("cant't get fileObjectS3 from S3 uploaded
|
|
69
|
-
file"); }; let fileS3Body = fileObjectS3.Body;
|
|
70
|
-
_izContext.logger.debug("fileS3Body", fileS3Body); let fileS3Buffer = null; if
|
|
71
|
-
(fileS3Body instanceof Readable) { fileS3Buffer = Buffer.concat(await
|
|
72
|
-
fileS3Body.toArray()); _izContext.logger.debug("fileS3Buffer", fileS3Buffer) }
|
|
73
|
-
else { errorsFound.push('unknown object stream type'); } // check file type //
|
|
74
|
-
can be strict in function.yml that only trigger if it specific type of file
|
|
75
|
-
const srcKey = field.key; const importFieldType = srcKey.match(/\.([^.]*)$/);
|
|
76
|
-
_izContext.logger.debug("importFieldType", importFieldType); if
|
|
77
|
-
(!importFieldType) { throw new NoRetryError("error fileType") }; const
|
|
78
|
-
importKeyType = utils.firstLetterLowerCase(importFieldType[1]);
|
|
79
|
-
_izContext.logger.debug("importKeyType", importKeyType); if (importKeyType ===
|
|
80
|
-
"csv") { // check valid CSV file let [validCsv, errorCheckCsv] = await
|
|
81
|
-
isValidCsv(_izContext, fileObjectS3) _izContext.logger.debug("validCsv check::",
|
|
82
|
-
{ validCsv, errorsFound }) if (errorCheckCsv.length) {
|
|
83
|
-
errorsFound.push(errorCheckCsv[0]) } // check file size let reservedFileSize =
|
|
84
|
-
getImportBatchMain.fields.fileSize; _izContext.logger.debug("initialFileSize::",
|
|
85
|
-
reservedFileSize) let s3FileSize = fileObjectS3.ContentLength / 1048576 //
|
|
86
|
-
convert back to byte unit _izContext.logger.debug("s3FileSize in MiB::",
|
|
87
|
-
s3FileSize) if (s3FileSize < 0.5) { // round up to 1 s3FileSize = 1 } let
|
|
88
|
-
reservedData = await dynamodbSharedLib.getItem(_izContext, await
|
|
89
|
-
dynamodbSharedLib.tableName(_izContext, "ReservedDataMain"), { servicePendingId:
|
|
90
|
-
importBatchId, reservedDataId:
|
|
91
|
-
`${consts.ACCOUNTLIMIT_TAG.reservedDynamic}_${getImportBatchMain.fields.userId}_${consts.LIMIT_TAG.uploadData}`
|
|
92
|
-
} ) _izContext.logger.debug("reservedData::", reservedData); let sizeDiff; if
|
|
93
|
-
(s3FileSize > reservedFileSize) { sizeDiff = s3FileSize - reservedFileSize; if
|
|
94
|
-
(sizeDiff < 1) { // send message to confirmUsage let confirmUsageMessage = {
|
|
95
|
-
userId: userId, limitTag: consts.LIMIT_TAG.uploadData, uniqueIdentify:
|
|
96
|
-
reservedData.uniqueIdentify, } let sendMessageToConfirmUsage = { Message:
|
|
97
|
-
JSON.stringify(confirmUsageMessage), TopicArn: await
|
|
98
|
-
snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage',
|
|
99
|
-
consts.EXTERNAL_SERVICE_NAME.accountLimits) };
|
|
100
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
101
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage); let
|
|
102
|
-
sendMessageToUpdateImportBatchStatus = { objInstanceFull: { identifiers: {
|
|
103
|
-
importBatchId: servicePendingId }, fields: { importBatchStatus: 'uploadComplete'
|
|
104
|
-
} } } let sendMessageToUpdateImportBatch = { Message:
|
|
105
|
-
JSON.stringify(sendMessageToUpdateImportBatchStatus), TopicArn: await
|
|
106
|
-
snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`) };
|
|
107
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch",
|
|
108
|
-
sendMessageToUpdateImportBatch); await sns.publishAsync(_izContext,
|
|
109
|
-
sendMessageToUpdateImportBatch); } } else if (s3FileSize < reservedFileSize) {
|
|
110
|
-
sizeDiff = reservedFileSize - s3FileSize; if (sizeDiff < 1) { let
|
|
111
|
-
confirmUsageMessage = { userId: userId, limitTag: consts.LIMIT_TAG.uploadData,
|
|
112
|
-
uniqueIdentify: reservedData.uniqueIdentify, } let sendMessageToConfirmUsage = {
|
|
113
|
-
Message: JSON.stringify(confirmUsageMessage), TopicArn: await
|
|
114
|
-
snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage',
|
|
115
|
-
consts.EXTERNAL_SERVICE_NAME.accountLimits) };
|
|
116
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
117
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage); let
|
|
118
|
-
sendMessageToUpdateImportBatchStatus = { objInstanceFull: { identifiers: {
|
|
119
|
-
importBatchId: servicePendingId }, fields: { importBatchStatus: 'uploadComplete'
|
|
120
|
-
} } } let sendMessageToUpdateImportBatch = { Message:
|
|
121
|
-
JSON.stringify(sendMessageToUpdateImportBatchStatus), TopicArn: await
|
|
122
|
-
snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`) };
|
|
123
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch",
|
|
124
|
-
sendMessageToUpdateImportBatch); await sns.publishAsync(_izContext,
|
|
125
|
-
sendMessageToUpdateImportBatch); } else { let realFileSize =
|
|
126
|
-
Math.round(s3FileSize); // cancel reserved -> new reserved -> confirm // cancel
|
|
127
|
-
let sendMessageToCancelReserved = { Message: JSON.stringify({ userId: userId,
|
|
128
|
-
limitTag: consts.LIMIT_TAG.uploadData, uniqueIdentify:
|
|
129
|
-
reservedData.uniqueIdentify }), TopicArn: await
|
|
130
|
-
snsSharedLib.snsTopicArn(_izContext, 'InCancelUsage',
|
|
131
|
-
consts.EXTERNAL_SERVICE_NAME.accountLimits) };
|
|
132
|
-
_izContext.logger.debug("sendMessageToCancelReserved",
|
|
133
|
-
sendMessageToCancelReserved); await sns.publishAsync(_izContext,
|
|
134
|
-
sendMessageToCancelReserved); // new reserved let originTimestamp = Date.now();
|
|
135
|
-
let messageObjReserved = { userId: userId, limitTag:
|
|
136
|
-
consts.LIMIT_TAG.uploadData, value: realFileSize, rbacType:
|
|
137
|
-
consts.RBAC_TYPE.appLevel, usedTimestamp: originTimestamp, targetUserId:
|
|
138
|
-
targetId } let callingFlowProperties = { identifier: { servicePendingId:
|
|
139
|
-
importBatchId, reservedDataId:
|
|
140
|
-
`${consts.ACCOUNTLIMIT_TAG.reservedDynamic}_${getImportBatchMain.fields.userId}_${consts.LIMIT_TAG.uploadData}`,
|
|
141
|
-
userId: getImportBatchMain.fields.userId, realSize: realFileSize } }
|
|
142
|
-
messageObjReserved =
|
|
143
|
-
callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
144
|
-
messageObjReserved, callingFlowSharedLib.createCallingFlowConfig( await
|
|
145
|
-
lambdaSharedLib.lambdaFunctionName(_izContext, "ConfirmNewReservedHdrSqs"),
|
|
146
|
-
callingFlowProperties ) ) _izContext.logger.debug('after add callingFlow: ',
|
|
147
|
-
messageObjReserved) let sendMessageToReservedDynamic = { Message:
|
|
148
|
-
JSON.stringify(messageObjReserved), TopicArn: await
|
|
149
|
-
snsSharedLib.snsTopicArn(_izContext, 'InReservedDynamicUsage',
|
|
150
|
-
consts.EXTERNAL_SERVICE_NAME.accountLimits) };
|
|
151
|
-
_izContext.logger.debug("sendMessageToReservedDynamic",
|
|
152
|
-
sendMessageToReservedDynamic); await sns.publishAsync(_izContext,
|
|
153
|
-
sendMessageToReservedDynamic); }; } else if (s3FileSize === reservedFileSize) {
|
|
154
|
-
let confirmUsageMessage = { userId: getImportBatchMain.fields.userId, limitTag:
|
|
155
|
-
consts.LIMIT_TAG.uploadData, uniqueIdentify: reservedData.uniqueIdentify, } let
|
|
156
|
-
sendMessageToConfirmUsage = { Message: JSON.stringify(confirmUsageMessage),
|
|
157
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage',
|
|
158
|
-
consts.EXTERNAL_SERVICE_NAME.accountLimits) };
|
|
159
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
160
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage); let
|
|
161
|
-
sendMessageToUpdateImportBatchStatus = { objInstanceFull: { identifiers: {
|
|
162
|
-
importBatchId: servicePendingId }, fields: { importBatchStatus: 'uploadComplete'
|
|
163
|
-
} } } let sendMessageToUpdateImportBatch = { Message:
|
|
164
|
-
JSON.stringify(sendMessageToUpdateImportBatchStatus), TopicArn: await
|
|
165
|
-
snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`) };
|
|
166
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch",
|
|
167
|
-
sendMessageToUpdateImportBatch); await sns.publishAsync(_izContext,
|
|
168
|
-
sendMessageToUpdateImportBatch); } } else { errorsFound.push("error
|
|
169
|
-
importKeyType") } if (errorsFound.length) { // if error send message to update
|
|
170
|
-
error in importBatchMain let updateImportBatchMainError = { objInstanceFull: {
|
|
171
|
-
identifiers: { importBatchId: importBatchId }, fields: { importBatchStatus:
|
|
172
|
-
"errorToUpload", errorsFound: errorsFound, processingError: true } } } let
|
|
173
|
-
sendMessageToUpdateImportBatchMain = { Message:
|
|
174
|
-
JSON.stringify(updateImportBatchMainError), TopicArn: await
|
|
175
|
-
snsSharedLib.snsTopicArn(_izContext, "InImportBatchMainUpdate") };
|
|
176
|
-
_izContext.logger.debug('sendMessageToUpdateImportBatchMain::',
|
|
177
|
-
sendMessageToUpdateImportBatchMain); await sns.publishAsync(_izContext,
|
|
178
|
-
sendMessageToUpdateImportBatchMain); let deleteFileObjectS3 = await s3.send(new
|
|
179
|
-
DeleteObjectCommand(objectS3Param)); _izContext.logger.debug("Delete object
|
|
180
|
-
response: ", deleteFileObjectS3) } } catch (err) {
|
|
181
|
-
_izContext.logger.error('error ProcessImageAfterUploadMain: ', err) throw (err)
|
|
182
|
-
} }
|
|
@@ -1,49 +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
|
-
import path from 'path';
|
|
19
|
-
import { fileURLToPath } from 'url';
|
|
20
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
-
const __dirname = path.dirname(__filename);
|
|
22
|
-
|
|
23
|
-
import consts from '#libs/Consts.js';
|
|
24
|
-
import utils from '#libs/Utils.js';
|
|
25
|
-
|
|
26
|
-
const { SOURCE_PATH, FUNCTION_NAME } = consts;
|
|
27
|
-
const { firstLetterUpperCase: upperCase } = utils;
|
|
28
|
-
|
|
29
|
-
const templatePath = path.join(__dirname, 'template.ejs');
|
|
30
|
-
|
|
31
|
-
function createSourceParams(_izContext, flowSchema, appPath) {
|
|
32
|
-
let functionName = upperCase(FUNCTION_NAME.processAfterUploadS3);
|
|
33
|
-
return {
|
|
34
|
-
templatePath: templatePath,
|
|
35
|
-
templateData: {},
|
|
36
|
-
setting: {
|
|
37
|
-
saveFileName: `${functionName}_Main`,
|
|
38
|
-
savePath: path.join(
|
|
39
|
-
appPath,
|
|
40
|
-
SOURCE_PATH.webSocket,
|
|
41
|
-
flowSchema.flowTag,
|
|
42
|
-
'source/'
|
|
43
|
-
),
|
|
44
|
-
fileExtension: '.js'
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default createSourceParams;
|
|
@@ -1,66 +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
|
-
import { S3Client, GetObjectCommand, DeleteObjectCommand, PutObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
|
|
19
|
-
const s3 = new S3Client({ region: 'us-east-2' });
|
|
20
|
-
|
|
21
|
-
//(<optionalRequired>)
|
|
22
|
-
//(</optionalRequired>)
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* description of function.
|
|
26
|
-
* @param {Object} _izContext
|
|
27
|
-
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
28
|
-
* @param {Logger} _izContext.logger - property of _izContext
|
|
29
|
-
* @param {Logger} _izContext.logger.debug - property of _izContext
|
|
30
|
-
* @param {Object} bucket - bucket's data
|
|
31
|
-
* @param {Array} field - image's data
|
|
32
|
-
* @param {Array} importBy - 'webSocket' || 'importData'
|
|
33
|
-
* @param {Array} imageImportId - from importData
|
|
34
|
-
* @param {Array} realImageSize - from importData
|
|
35
|
-
* @param {Array} passBackProperties - from importData
|
|
36
|
-
*
|
|
37
|
-
* @returns {object} returnResponse
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
export default async function <%= functionName %> (
|
|
41
|
-
_izContext,
|
|
42
|
-
bucket,
|
|
43
|
-
field,
|
|
44
|
-
//(<additionalProperties>)
|
|
45
|
-
//(</additionalProperties>)
|
|
46
|
-
passBackProperties = {}
|
|
47
|
-
) {
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
|
|
51
|
-
_izContext.logger.debug('----- process AfterUpload event params ----- ', {
|
|
52
|
-
bucket: bucket,
|
|
53
|
-
field: field,
|
|
54
|
-
//(<loggerAdditionalParams>)
|
|
55
|
-
//(</loggerAdditionalParams>)
|
|
56
|
-
passBackProperties: passBackProperties
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
//(<endpointHook>)
|
|
60
|
-
//(</endpointHook>)
|
|
61
|
-
|
|
62
|
-
} catch (err) {
|
|
63
|
-
_izContext.logger.error('error ProcessImageAfterUploadMain: ', err)
|
|
64
|
-
throw (err)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
-
|
|
4
|
-
This program is free software: you can redistribute it and/or modify
|
|
5
|
-
it under the terms of the GNU Affero General Public License as
|
|
6
|
-
published by the Free Software Foundation, either version 3 of the
|
|
7
|
-
License, or (at your option) any later version.
|
|
8
|
-
|
|
9
|
-
This program is distributed in the hope that it will be useful,
|
|
10
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
GNU Affero General Public License for more details.
|
|
13
|
-
|
|
14
|
-
You should have received a copy of the GNU Affero General Public License
|
|
15
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import path from 'path';
|
|
19
|
-
import { fileURLToPath } from 'url';
|
|
20
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
-
const __dirname = path.dirname(__filename);
|
|
22
|
-
|
|
23
|
-
import consts from '#libs/Consts.js';
|
|
24
|
-
|
|
25
|
-
const { SOURCE_PATH, SAVE_FILE_NAME } = consts;
|
|
26
|
-
|
|
27
|
-
const s3TemplatePath = path.join(__dirname, './s3Template.ejs');
|
|
28
|
-
const dsqTemplatePath = path.join(__dirname, './dsqTemplatePath.ejs');
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* create data for dynamoDbYaml tempalte from objectSchema
|
|
32
|
-
* return array of dynamoDb data
|
|
33
|
-
* because one objectSchema can create multiple dynamoDb table
|
|
34
|
-
*
|
|
35
|
-
* @param {Object} _izContext
|
|
36
|
-
* @param {Object} objectSchema
|
|
37
|
-
* @returns {Object[]} - data of multiple dynamoDb template
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
function data(_izContext, srcPath) {
|
|
41
|
-
let resultForCreateSqs = [];
|
|
42
|
-
const WebSocketSqsQueueNames = [];
|
|
43
|
-
const setting = {
|
|
44
|
-
initialData: 'Resources:\n',
|
|
45
|
-
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
46
|
-
saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
|
|
47
|
-
fileExtension: '.yml',
|
|
48
|
-
isAppend: true
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
WebSocketSqsQueueNames.push(
|
|
52
|
-
{
|
|
53
|
-
queueName: 'ProcessAfterUploadS3'
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
queueName: 'ProcessAfterUploadHdrDsq'
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
for (let WebSocketSqsQueueName of WebSocketSqsQueueNames) {
|
|
61
|
-
if (WebSocketSqsQueueName.queueName.includes('HdrDsq')) {
|
|
62
|
-
resultForCreateSqs.push({
|
|
63
|
-
templatePath: dsqTemplatePath,
|
|
64
|
-
templateData: WebSocketSqsQueueName,
|
|
65
|
-
setting: setting
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
resultForCreateSqs.push({
|
|
69
|
-
templatePath: s3TemplatePath,
|
|
70
|
-
templateData: WebSocketSqsQueueName,
|
|
71
|
-
setting: setting
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return resultForCreateSqs;
|
|
76
|
-
}
|
|
77
|
-
export default data;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#----[Queue]
|
|
2
|
-
<%- queueName %>:
|
|
3
|
-
Type: "AWS::SQS::Queue"
|
|
4
|
-
Properties:
|
|
5
|
-
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
|
|
6
|
-
RedrivePolicy:
|
|
7
|
-
deadLetterTargetArn: !GetAtt
|
|
8
|
-
- <%- queueName %>DLQ
|
|
9
|
-
- Arn
|
|
10
|
-
maxReceiveCount: 3
|
|
11
|
-
VisibilityTimeout: 120
|
|
12
|
-
#----[QueueDLQ]
|
|
13
|
-
<%- queueName %>DLQ:
|
|
14
|
-
Type: AWS::SQS::Queue
|
|
15
|
-
Properties:
|
|
16
|
-
QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
|
|
17
|
-
#----[DataPolicy]
|
|
18
|
-
<%- queueName %>Policy:
|
|
19
|
-
Type: AWS::SQS::QueuePolicy
|
|
20
|
-
Properties:
|
|
21
|
-
PolicyDocument:
|
|
22
|
-
Version: "2012-10-17"
|
|
23
|
-
Statement:
|
|
24
|
-
- Sid: "allow-sns-messages"
|
|
25
|
-
Effect: Allow
|
|
26
|
-
Principal: "*"
|
|
27
|
-
Resource: !GetAtt
|
|
28
|
-
- <%- queueName %>
|
|
29
|
-
- Arn
|
|
30
|
-
Action: "SQS:SendMessage"
|
|
31
|
-
Queues:
|
|
32
|
-
- Ref: <%- queueName %>
|