@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
|
@@ -2,21 +2,41 @@ import { buildGenerationPlan } from '../../plan/buildGenerationPlan.js';
|
|
|
2
2
|
import { commitArtifacts } from '../../output/commitArtifacts.js';
|
|
3
3
|
import { compileProject } from '../../compile/compileProject.js';
|
|
4
4
|
import { loadLocalSchemaDirectory } from '../../compile/loadSchemas.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
customFlowApplicationManagedPaths,
|
|
7
|
+
emitCustomFlowApplicationArtifacts
|
|
8
|
+
} from './emitCustomFlowApplicationArtifacts.js';
|
|
9
|
+
import {
|
|
10
|
+
emitSystemWebSocketArtifacts,
|
|
11
|
+
hasSystemWebSocket,
|
|
12
|
+
systemWebSocketManagedPaths
|
|
13
|
+
} from '../system/emitSystemWebSocketArtifacts.js';
|
|
7
14
|
|
|
8
|
-
export async function generateCustomFlowApplicationArtifacts(
|
|
15
|
+
export async function generateCustomFlowApplicationArtifacts(
|
|
16
|
+
rootPath,
|
|
17
|
+
options = {}
|
|
18
|
+
) {
|
|
9
19
|
const project = compileProject({ ...options, rootPath });
|
|
10
20
|
const [flows, objects] = await Promise.all([
|
|
11
21
|
loadLocalSchemaDirectory(project, 'FlowSchemas'),
|
|
12
22
|
loadLocalSchemaDirectory(project, 'ObjectSchemas')
|
|
13
23
|
]);
|
|
14
24
|
const system = await emitSystemWebSocketArtifacts(flows);
|
|
15
|
-
const custom = await emitCustomFlowApplicationArtifacts(flows, {
|
|
25
|
+
const custom = await emitCustomFlowApplicationArtifacts(flows, {
|
|
26
|
+
systemFunctions: system.functions,
|
|
27
|
+
objects
|
|
28
|
+
});
|
|
16
29
|
const artifacts = [...system.artifacts, ...custom];
|
|
17
|
-
const files = await commitArtifacts(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
const files = await commitArtifacts(
|
|
31
|
+
buildGenerationPlan(project, artifacts, {
|
|
32
|
+
managedPaths: [
|
|
33
|
+
...systemWebSocketManagedPaths(),
|
|
34
|
+
...customFlowApplicationManagedPaths(flows, {
|
|
35
|
+
includeYaml: hasSystemWebSocket(flows)
|
|
36
|
+
})
|
|
37
|
+
],
|
|
38
|
+
managedScope: 'custom-flow-application'
|
|
39
|
+
})
|
|
40
|
+
);
|
|
21
41
|
return { project, files };
|
|
22
42
|
}
|
|
@@ -40,7 +40,6 @@ import { utils } from '@izara_project/izara-core-library-service-schemas';
|
|
|
40
40
|
const { createFlowTypeConcat } = utils;
|
|
41
41
|
//(</optionalImport>)
|
|
42
42
|
|
|
43
|
-
|
|
44
43
|
/**
|
|
45
44
|
*
|
|
46
45
|
*
|
|
@@ -59,40 +58,46 @@ const { createFlowTypeConcat } = utils;
|
|
|
59
58
|
export default async function <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>(
|
|
60
59
|
_izContext,
|
|
61
60
|
requestParams,
|
|
62
|
-
callingFlowConfig = {}
|
|
61
|
+
callingFlowConfig = {}
|
|
63
62
|
//(<additionalParams>)
|
|
64
63
|
//(</additionalParams>)
|
|
65
64
|
) {
|
|
66
|
-
|
|
67
65
|
try {
|
|
68
|
-
_izContext.logger.debug(
|
|
69
|
-
_izContext.logger.debug(
|
|
70
|
-
_izContext.logger.debug(
|
|
66
|
+
_izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> _izContext', _izContext);
|
|
67
|
+
_izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> requestParams', requestParams);
|
|
68
|
+
_izContext.logger.debug(
|
|
69
|
+
'<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> callingFlowConfig',
|
|
70
|
+
callingFlowConfig
|
|
71
|
+
);
|
|
71
72
|
|
|
72
|
-
<% if (typeof flow !== 'undefined' && flow.statusType === 'storedCache') { %>
|
|
73
|
+
<% if (typeof flow !== 'undefined' && flow.statusType === 'storedCache') { %>
|
|
73
74
|
|
|
74
75
|
//(<beforeCheckCache>)
|
|
75
76
|
//(</beforeCheckCache>)
|
|
76
77
|
|
|
77
|
-
let [
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
let [cacheMainStatus, cacheMain, cacheExist] =
|
|
79
|
+
await storedCacheSharedLib.checkStoredCacheStatus(
|
|
80
|
+
_izContext,
|
|
81
|
+
'<%= tableName %>',
|
|
82
|
+
{
|
|
83
|
+
//(<keyValueStoredCacheTable>)
|
|
84
|
+
//(</keyValueStoredCacheTable>)
|
|
85
|
+
},
|
|
86
|
+
//(<additionalAttributesWhenCreateStoredCache>)
|
|
87
|
+
//(</additionalAttributesWhenCreateStoredCache>),
|
|
88
|
+
createFlowTypeConcat(_izContext, {
|
|
89
|
+
flowTag: '<%= flowTag %>',
|
|
90
|
+
serviceTag: process.env.iz_serviceTag
|
|
91
|
+
})
|
|
92
|
+
//(<storedCacheConfig>)
|
|
93
|
+
//(</storedCacheConfig>)
|
|
94
|
+
);
|
|
90
95
|
|
|
91
96
|
//(<afterCheckStoredCache>)
|
|
92
97
|
//(</afterCheckStoredCache>)
|
|
93
98
|
|
|
94
|
-
if (cacheMainStatus !==
|
|
95
|
-
if (cacheMainStatus ===
|
|
99
|
+
if (cacheMainStatus !== 'process') {
|
|
100
|
+
if (cacheMainStatus === 'error' || cacheMainStatus === 'complete') {
|
|
96
101
|
//(<afterValidateStoredCacheStatus>)
|
|
97
102
|
//(</afterValidateStoredCacheStatus>)
|
|
98
103
|
}
|
|
@@ -100,40 +105,47 @@ export default async function <%- typeof functionName !== 'undefined' ? function
|
|
|
100
105
|
//(<checkStoredCacheHook>)
|
|
101
106
|
//(</checkStoredCacheHook>)
|
|
102
107
|
}
|
|
103
|
-
<% } %>
|
|
108
|
+
<% } %>
|
|
104
109
|
|
|
105
|
-
<% if (typeof flow !== 'undefined' && flow.isRbac) { %>
|
|
106
|
-
const { checkRbacPermission } =
|
|
110
|
+
<% if (typeof flow !== 'undefined' && flow.isRbac) { %>
|
|
111
|
+
const { checkRbacPermission } =
|
|
112
|
+
await import('@izara_project/izara-authorization');
|
|
107
113
|
|
|
108
114
|
//(<additionalParams_parameterGroups>)
|
|
109
115
|
const parameterGroups = {};
|
|
110
116
|
//(</additionalParams_parameterGroups>)
|
|
111
117
|
|
|
112
|
-
const resultPermissionCheck = await checkRbacPermission(
|
|
118
|
+
const resultPermissionCheck = await checkRbacPermission(
|
|
119
|
+
_izContext,
|
|
120
|
+
{ flowTag: '<%- flow.flowTag %>', serviceTag: '<%- flow.serviceTag || (flow.objType ? flow.objType.serviceTag : "") %>' },
|
|
121
|
+
parameterGroups
|
|
122
|
+
);
|
|
113
123
|
|
|
114
|
-
_izContext.logger.debug(
|
|
124
|
+
_izContext.logger.debug(
|
|
125
|
+
'[lib:auth:checkRbacPermission] resultPermissionCheck:',
|
|
126
|
+
resultPermissionCheck
|
|
127
|
+
);
|
|
115
128
|
|
|
116
129
|
if (resultPermissionCheck.permission === false) {
|
|
117
|
-
|
|
118
130
|
//(<messageOutPutPermissionCheckFailed>)
|
|
119
|
-
const message = {
|
|
120
|
-
|
|
121
|
-
}
|
|
131
|
+
const message = {};
|
|
122
132
|
//(</messageOutPutPermissionCheckFailed>)
|
|
123
133
|
|
|
124
134
|
return await sns.publishAsync(_izContext, {
|
|
125
135
|
Message: JSON.stringify(message),
|
|
126
|
-
TopicArn:
|
|
136
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
137
|
+
_izContext,
|
|
138
|
+
'<%- flow.flowTag %>_Out'
|
|
139
|
+
)
|
|
127
140
|
});
|
|
128
141
|
}
|
|
129
142
|
|
|
130
|
-
<% } %>
|
|
143
|
+
<% } %>
|
|
131
144
|
|
|
132
145
|
//(<endpointHook>)
|
|
133
146
|
//(</endpointHook>)
|
|
134
|
-
|
|
135
147
|
} catch (err) {
|
|
136
|
-
_izContext.logger.error('error WebSocketInvoke: ', err)
|
|
137
|
-
throw
|
|
148
|
+
_izContext.logger.error('error WebSocketInvoke: ', err);
|
|
149
|
+
throw err;
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -37,24 +37,22 @@ import { identifierUuid } from '@izara_project/izara-shared-core';
|
|
|
37
37
|
export default async function <%= functionName %>(
|
|
38
38
|
_izContext,
|
|
39
39
|
requestParams,
|
|
40
|
-
callingFlowConfig = {}
|
|
40
|
+
callingFlowConfig = {}
|
|
41
41
|
//(<additionalParams>)
|
|
42
42
|
//(</additionalParams>)
|
|
43
43
|
) {
|
|
44
|
-
|
|
45
|
-
|
|
46
44
|
try {
|
|
47
45
|
_izContext.logger.debug('<%= functionName %> _izContext: ', _izContext);
|
|
48
46
|
_izContext.logger.debug('<%= functionName %> requestParams: ', requestParams);
|
|
49
|
-
_izContext.logger.debug(
|
|
47
|
+
_izContext.logger.debug(
|
|
48
|
+
'<%= functionName %> callingFlowConfig: ',
|
|
49
|
+
callingFlowConfig
|
|
50
|
+
);
|
|
50
51
|
|
|
51
52
|
//(<hookCode>)
|
|
52
53
|
//(</hookCode>)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
54
|
} catch (err) {
|
|
57
|
-
_izContext.logger.error('error <%= functionName %>Main: ', err)
|
|
58
|
-
throw
|
|
55
|
+
_izContext.logger.error('error <%= functionName %>Main: ', err);
|
|
56
|
+
throw err;
|
|
59
57
|
}
|
|
60
58
|
}
|
|
@@ -15,32 +15,26 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
21
|
-
import { recordHandlerSharedLib } from "@izara_project/izara-core-library-record-handler";
|
|
18
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
22
20
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
23
|
-
import callingFlowSharedLib from
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
24
22
|
|
|
25
|
-
import <%= functionName %> from './<%= functionName %>_Main.js'
|
|
23
|
+
import <%= functionName %> from './<%= functionName %>_Main.js';
|
|
26
24
|
|
|
27
25
|
// validate event properties in body.Message of sqs event
|
|
28
26
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
29
27
|
|
|
30
28
|
// set schema for record.body.Message
|
|
31
29
|
let perRecordsValidatorSchema = {
|
|
32
|
-
type:
|
|
33
|
-
required: [
|
|
34
|
-
'returnMessage',
|
|
35
|
-
'errorsFound',
|
|
36
|
-
'passStatus'
|
|
37
|
-
],
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: ['returnMessage', 'errorsFound', 'passStatus'],
|
|
38
32
|
properties: {
|
|
39
33
|
returnMessage: {
|
|
40
|
-
type:
|
|
34
|
+
type: 'object'
|
|
41
35
|
},
|
|
42
36
|
errorsFound: {
|
|
43
|
-
type:
|
|
37
|
+
type: 'array'
|
|
44
38
|
},
|
|
45
39
|
passStatus: {
|
|
46
40
|
type: 'boolean'
|
|
@@ -62,62 +56,73 @@ let perRecordsValidatorSchema = {
|
|
|
62
56
|
// }
|
|
63
57
|
// };
|
|
64
58
|
|
|
65
|
-
perRecordsValidatorSchema =
|
|
59
|
+
perRecordsValidatorSchema =
|
|
60
|
+
callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
|
|
61
|
+
perRecordsValidatorSchema
|
|
62
|
+
);
|
|
66
63
|
|
|
67
64
|
export const main = middleware.wrap(async (event, context) => {
|
|
68
|
-
|
|
69
65
|
try {
|
|
70
|
-
|
|
71
66
|
let recordPromises = [];
|
|
72
67
|
|
|
73
68
|
// loop each record and send to mainFunction
|
|
74
|
-
await Promise.all(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
69
|
+
await Promise.all(
|
|
70
|
+
event.Records.map(async (record) => {
|
|
71
|
+
// promise.all for map() function
|
|
72
|
+
|
|
73
|
+
let passOnProperties = [];
|
|
74
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
75
|
+
|
|
76
|
+
// validate message (and MessageAttributes)
|
|
77
|
+
await recordHandlerSharedLib.validateRecord(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
80
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
81
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
85
|
+
passOnProperties.push(record.body.Message.returnMessage);
|
|
86
|
+
passOnProperties.push(record.body.Message.errorsFound);
|
|
87
|
+
passOnProperties.push(record.body.Message.passStatus);
|
|
88
|
+
//(<additionalProperties>)
|
|
89
|
+
//(</additionalProperties>)
|
|
90
|
+
passOnProperties.push(
|
|
91
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
92
|
+
record.body.Message
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
record._izContext.logger.debug(
|
|
96
|
+
'passOnProperties in handler',
|
|
97
|
+
passOnProperties
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
101
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
102
|
+
record, // one record will send to mainFunction
|
|
103
|
+
<%= functionName %>, // mainFunction that need to invoke.
|
|
104
|
+
'<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
|
|
105
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
106
|
+
);
|
|
107
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
108
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
109
|
+
})
|
|
110
|
+
);
|
|
106
111
|
|
|
107
112
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
108
113
|
try {
|
|
109
114
|
// --- main await all promises
|
|
110
115
|
await Promise.all(recordPromises); // await all promises
|
|
111
116
|
|
|
112
|
-
return event.Records // return all for local test
|
|
113
|
-
|
|
117
|
+
return event.Records; // return all for local test
|
|
114
118
|
} catch {
|
|
115
|
-
Logger.debug(
|
|
119
|
+
Logger.debug(
|
|
120
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
121
|
+
);
|
|
116
122
|
}
|
|
117
123
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
118
|
-
|
|
119
124
|
} catch (err) {
|
|
120
125
|
Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
|
|
121
|
-
throw
|
|
126
|
+
throw err;
|
|
122
127
|
}
|
|
123
128
|
});
|
|
@@ -15,8 +15,6 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
18
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
21
19
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
22
20
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
@@ -56,18 +54,21 @@ export default async function confirmNewReserved(
|
|
|
56
54
|
errorsFound: errorsFound,
|
|
57
55
|
passStatus: passStatus,
|
|
58
56
|
passBackProperties: passBackProperties
|
|
59
|
-
})
|
|
57
|
+
});
|
|
60
58
|
|
|
61
|
-
let servicePendingId =
|
|
62
|
-
|
|
59
|
+
let servicePendingId =
|
|
60
|
+
passBackProperties.passBackProperties.identifier.servicePendingId;
|
|
61
|
+
let reservedDataId =
|
|
62
|
+
passBackProperties.passBackProperties.identifier.reservedDataId;
|
|
63
63
|
let userId = passBackProperties.passBackProperties.identifier.userId;
|
|
64
|
-
let realFileSize =
|
|
64
|
+
let realFileSize =
|
|
65
|
+
passBackProperties.passBackProperties.identifier.realFileSize;
|
|
65
66
|
|
|
66
|
-
let uniqueIdentify = getNestObject(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
67
|
+
let uniqueIdentify = getNestObject(_izContext, returnMessage.limitFound, [
|
|
68
|
+
'runningTotal',
|
|
69
|
+
'uniqueIdentify',
|
|
70
|
+
'usedTimestampId'
|
|
71
|
+
]);
|
|
71
72
|
|
|
72
73
|
// confirmUsage
|
|
73
74
|
let confirmUsageMessage = {
|
|
@@ -75,14 +76,21 @@ export default async function confirmNewReserved(
|
|
|
75
76
|
//(<optionalLimitTag>)
|
|
76
77
|
limitTag: schemaConsts.LIMIT_TAG.uploadData,
|
|
77
78
|
//(</optionalLimitTag>)
|
|
78
|
-
uniqueIdentify: uniqueIdentify
|
|
79
|
-
}
|
|
79
|
+
uniqueIdentify: uniqueIdentify
|
|
80
|
+
};
|
|
80
81
|
|
|
81
82
|
let sendMessageToConfirmUsage = {
|
|
82
83
|
Message: JSON.stringify(confirmUsageMessage),
|
|
83
|
-
TopicArn:
|
|
84
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
85
|
+
_izContext,
|
|
86
|
+
'ConfirmUsage_In',
|
|
87
|
+
schemaConsts.EXTERNAL_SERVICE_NAME.accountLimits
|
|
88
|
+
)
|
|
84
89
|
};
|
|
85
|
-
_izContext.logger.debug(
|
|
90
|
+
_izContext.logger.debug(
|
|
91
|
+
'sendMessageToConfirmUsage',
|
|
92
|
+
sendMessageToConfirmUsage
|
|
93
|
+
);
|
|
86
94
|
await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
|
|
87
95
|
|
|
88
96
|
// update reservedDataValue as real size in ReservedDataMain table
|
|
@@ -96,7 +104,7 @@ export default async function confirmNewReserved(
|
|
|
96
104
|
{
|
|
97
105
|
reservedValue: realFileSize
|
|
98
106
|
}
|
|
99
|
-
)
|
|
107
|
+
);
|
|
100
108
|
|
|
101
109
|
let sendMessageToUpdateStatus = {
|
|
102
110
|
//(<messageObjectHook>)
|
|
@@ -111,19 +119,21 @@ export default async function confirmNewReserved(
|
|
|
111
119
|
//(</fields>)
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
|
-
}
|
|
122
|
+
};
|
|
115
123
|
|
|
116
124
|
let sendMessageToUpdateEndpoint = {
|
|
117
125
|
Message: JSON.stringify(sendMessageToUpdateStatus),
|
|
118
|
-
TopicArn:
|
|
126
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Update_In')
|
|
119
127
|
};
|
|
120
|
-
_izContext.logger.debug(
|
|
128
|
+
_izContext.logger.debug(
|
|
129
|
+
'sendMessageToUpdateEndpoint',
|
|
130
|
+
sendMessageToUpdateEndpoint
|
|
131
|
+
);
|
|
121
132
|
await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
|
|
122
133
|
|
|
123
|
-
return { returnResponse: 'success' }
|
|
124
|
-
|
|
134
|
+
return { returnResponse: 'success' };
|
|
125
135
|
} catch (err) {
|
|
126
|
-
_izContext.logger.debug('error ConfirmNewReservedMain: ', err)
|
|
127
|
-
throw
|
|
136
|
+
_izContext.logger.debug('error ConfirmNewReservedMain: ', err);
|
|
137
|
+
throw err;
|
|
128
138
|
}
|
|
129
139
|
}
|
|
@@ -15,56 +15,64 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler as middleware,
|
|
20
|
+
consts,
|
|
21
|
+
response
|
|
22
|
+
} from '@izara_project/izara-middleware';
|
|
21
23
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
22
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
25
|
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
24
26
|
const { postToConnection } = webSocket;
|
|
25
|
-
import { utils } from
|
|
26
|
-
const { createFlowTypeConcat } = utils
|
|
27
|
+
import { utils } from '@izara_project/izara-core-library-service-schemas';
|
|
28
|
+
const { createFlowTypeConcat } = utils;
|
|
27
29
|
|
|
28
30
|
import <%= functionName %> from './<%= functionName %>_Main.js';
|
|
29
31
|
|
|
30
32
|
export const main = middleware.wrap(async (event, context) => {
|
|
31
|
-
|
|
32
33
|
event._izContext.logger.debug('Event:', event);
|
|
33
34
|
|
|
34
35
|
try {
|
|
35
|
-
|
|
36
36
|
if (event.requestContext) {
|
|
37
37
|
const route = event.requestContext.routeKey;
|
|
38
38
|
const connectionId = event.requestContext.connectionId;
|
|
39
|
-
let correlationId = event._izContext.correlationIds.get(
|
|
39
|
+
let correlationId = event._izContext.correlationIds.get(
|
|
40
|
+
consts.X_CORRELATION_ID
|
|
41
|
+
);
|
|
40
42
|
|
|
41
43
|
switch (route) {
|
|
42
44
|
case '<%- route %>':
|
|
43
|
-
console.log(
|
|
44
|
-
let eventParams = JSON.parse(event.body)
|
|
45
|
+
console.log('event in route webSocket', event);
|
|
46
|
+
let eventParams = JSON.parse(event.body);
|
|
45
47
|
|
|
46
48
|
//(<createIdentifiersFlow>)
|
|
47
|
-
let identifiers
|
|
49
|
+
let identifiers;
|
|
48
50
|
//(</createIdentifiersFlow>)
|
|
49
51
|
|
|
50
|
-
await dynamodbSharedLib.putItem(
|
|
51
|
-
|
|
52
|
+
await dynamodbSharedLib.putItem(
|
|
53
|
+
event._izContext,
|
|
54
|
+
await dynamodbSharedLib.tableName(
|
|
55
|
+
event._izContext,
|
|
56
|
+
'WebSocketTask'
|
|
57
|
+
),
|
|
52
58
|
{
|
|
53
|
-
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag:
|
|
54
|
-
connectionId: connectionId
|
|
59
|
+
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: '<%- route %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
|
|
60
|
+
connectionId: connectionId
|
|
55
61
|
}
|
|
56
|
-
)
|
|
62
|
+
);
|
|
57
63
|
|
|
58
|
-
let callingFlow = eventParams?.callingFlow
|
|
64
|
+
let callingFlow = eventParams?.callingFlow
|
|
65
|
+
? eventParams.callingFlow
|
|
66
|
+
: {};
|
|
59
67
|
await <%= functionName %>(
|
|
60
68
|
event._izContext,
|
|
61
69
|
eventParams,
|
|
62
70
|
callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
|
|
63
71
|
//(<additionalParams>)
|
|
64
72
|
//(</additionalParams>)
|
|
65
|
-
)
|
|
73
|
+
);
|
|
66
74
|
|
|
67
|
-
break
|
|
75
|
+
break;
|
|
68
76
|
}
|
|
69
77
|
} else {
|
|
70
78
|
const connId = event.connId;
|
|
@@ -72,13 +80,12 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
72
80
|
await postToConnection({ message: event.message }, connId);
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
return
|
|
76
|
-
|
|
83
|
+
return response.webSocketSuccess();
|
|
77
84
|
} catch (err) {
|
|
78
|
-
const connId = event.requestContext.connectionId
|
|
85
|
+
const connId = event.requestContext.connectionId;
|
|
79
86
|
event._izContext.logger.error('Error, WebSocket: ', err);
|
|
80
87
|
// await sendErrorMessage({ message: err.message }, connId);
|
|
81
88
|
await postToConnection({ message: err.message }, connId);
|
|
82
|
-
return
|
|
89
|
+
return response.failure(err);
|
|
83
90
|
}
|
|
84
91
|
});
|