@izara_project/izara-core-generate-service-code 1.0.78 → 1.0.79
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 +2 -2
- package/src/compile/flowValidator.js +163 -0
- package/src/compile/loadSchemas.js +15 -5
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +137 -7
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +132 -17
- package/src/emit/crud/crudActionPlan.js +82 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +162 -112
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -65
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +84 -512
- package/src/emit/crud/templates/CreateLogicalLib.ejs +536 -0
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +87 -202
- package/src/emit/crud/templates/DeleteLogicalLib.ejs +213 -0
- package/src/emit/crud/templates/FlowEndpointRbacCallback_Main.ejs +217 -0
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +9 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +87 -444
- package/src/emit/crud/templates/UpdateLogicalLib.ejs +472 -0
- package/src/emit/custom/customFlows.js +27 -2
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +1 -2
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +10 -3
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -2
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +3 -9
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +21 -16
- package/src/emit/rbac/rbacFlowTag.js +2 -7
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +148 -21
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +4 -2
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
- package/src/emit/resource/emitResourceArtifacts.js +83 -68
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +31 -5
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +21 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -2
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -2
- package/src/emit/systemText/emitSystemTextSchemas.js +246 -0
- package/src/emit/systemText/templates/SystemTextSchemas.ejs +10 -0
- package/src/generate.js +55 -8
- package/test/crudApplicationArtifacts.test.js +147 -19
- package/test/customFlowApplicationArtifacts.test.js +308 -16
- package/test/dynamicCrudFlowSchemas.test.js +150 -14
- package/test/dynamicRbacFlowSchemas.test.js +2 -2
- package/test/dynamicRelationshipFlowSchemas.test.js +1 -1
- package/test/graphDrivenFlowSchema.test.js +257 -0
- package/test/publicApi.test.js +14 -5
- package/test/resourceArtifacts.test.js +25 -19
- package/test/systemTextSchemas.test.js +154 -0
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +0 -99
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +0 -99
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +0 -174
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +0 -187
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +0 -99
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +0 -47
|
@@ -0,0 +1,217 @@
|
|
|
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 {
|
|
19
|
+
objectHash as hash,
|
|
20
|
+
identifierUuid
|
|
21
|
+
} from '@izara_project/izara-shared-core';
|
|
22
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
23
|
+
import {
|
|
24
|
+
utils,
|
|
25
|
+
uploadUseCase,
|
|
26
|
+
getObjectSchema
|
|
27
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
28
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
29
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
30
|
+
|
|
31
|
+
const { createObjType } = utils;
|
|
32
|
+
|
|
33
|
+
import { <%- flowTag %>LogicalLib } from './<%- upperCaseFlowTag %>LogicalLib.js';
|
|
34
|
+
|
|
35
|
+
//(<optionalRequire>)
|
|
36
|
+
//(</optionalRequire>)
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Handles callback after RbacCallback phase — verifies awaitingStep then proceeds to next phase
|
|
40
|
+
* @param {Object} _izContext - Context object with logger
|
|
41
|
+
* @param {Object} requestParams - { fieldNames, relationships[] }
|
|
42
|
+
* @param {Object} callingFlowConfig - Calling flow configuration
|
|
43
|
+
* @returns {Promise<Object>}
|
|
44
|
+
*/
|
|
45
|
+
export default async function <%- flowTag %>RbacCallbackMain(
|
|
46
|
+
_izContext,
|
|
47
|
+
requestParams,
|
|
48
|
+
flowTag,
|
|
49
|
+
callingFlowConfig = {}
|
|
50
|
+
) {
|
|
51
|
+
try {
|
|
52
|
+
_izContext.logger.debug('[<%- flowTag %>RbacCallbackMain] Started with params:', {
|
|
53
|
+
requestParams,
|
|
54
|
+
flowTag,
|
|
55
|
+
callingFlowConfig
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const parts = requestParams.parentFlowId.split('_');
|
|
59
|
+
const rbacType = parts.pop();
|
|
60
|
+
const rbacPendingStepId = '<%- flowTag %>RbacCallback_' + parts.join('_');
|
|
61
|
+
const currentAwaitingStepId = requestParams.parentFlowId;
|
|
62
|
+
|
|
63
|
+
_izContext.logger.debug(
|
|
64
|
+
'[<%- flowTag %>RbacCallbackMain] Parsed RBAC pending details:',
|
|
65
|
+
{
|
|
66
|
+
rbacType,
|
|
67
|
+
rbacPendingStepId,
|
|
68
|
+
currentAwaitingStepId,
|
|
69
|
+
parentFlowId: requestParams.parentFlowId
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const rbacAwaitingStepsResult =
|
|
74
|
+
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
75
|
+
_izContext,
|
|
76
|
+
rbacPendingStepId,
|
|
77
|
+
currentAwaitingStepId,
|
|
78
|
+
requestParams.errorsFound,
|
|
79
|
+
{
|
|
80
|
+
returnValue: requestParams.returnValue,
|
|
81
|
+
rbacType
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
_izContext.logger.debug(
|
|
86
|
+
'[<%- flowTag %>RbacCallbackMain] checkAllAwaitingStepsFinishedWithReturnParams result:',
|
|
87
|
+
{
|
|
88
|
+
rbacAwaitingStepsResult
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const {
|
|
93
|
+
isComplete,
|
|
94
|
+
collectedReturnValueByAwaitingStepId,
|
|
95
|
+
collectedErrors: errorsFound = [],
|
|
96
|
+
additionalAttributes
|
|
97
|
+
} = rbacAwaitingStepsResult;
|
|
98
|
+
|
|
99
|
+
if (isComplete === false) {
|
|
100
|
+
_izContext.logger.debug(
|
|
101
|
+
'[<%- flowTag %>RbacCallbackMain] Awaiting steps still pending completion:',
|
|
102
|
+
{
|
|
103
|
+
rbacPendingStepId,
|
|
104
|
+
isComplete
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return 'all task not completed';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_izContext.logger.debug(
|
|
112
|
+
'[<%- flowTag %>RbacCallbackMain] All awaiting steps completed — clearing awaiting steps:',
|
|
113
|
+
{
|
|
114
|
+
rbacPendingStepId
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
await asyncFlowSharedLib.clearAllAwaitingSteps(
|
|
119
|
+
_izContext,
|
|
120
|
+
rbacPendingStepId
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const originalRequestParams = additionalAttributes?.requestParams || {};
|
|
124
|
+
|
|
125
|
+
_izContext.logger.debug(
|
|
126
|
+
'[<%- flowTag %>RbacCallbackMain] Retrieved originalRequestParams:',
|
|
127
|
+
{
|
|
128
|
+
originalRequestParams
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const rbacResults = Object.fromEntries(
|
|
133
|
+
Object.entries(collectedReturnValueByAwaitingStepId || {}).map(
|
|
134
|
+
([stepId, attrs]) => {
|
|
135
|
+
const type = stepId.split('_').pop();
|
|
136
|
+
return [type, attrs];
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const rbacCallbackResults = {};
|
|
142
|
+
const hasError = Object.entries(rbacResults).some(([type, result]) => {
|
|
143
|
+
if (result && result.error) {
|
|
144
|
+
errorsFound.push(result.error);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
rbacCallbackResults[type] = result;
|
|
148
|
+
return false;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const isAllowed = Object.values(rbacCallbackResults).some(
|
|
152
|
+
item => item?.returnValue?.permission === true
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (!isAllowed) {
|
|
156
|
+
errorsFound.push('Permission denied');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_izContext.logger.debug(
|
|
160
|
+
'[<%- flowTag %>RbacCallbackMain] Final rbacCallbackResults before calling <%- flowTag %>MainLogical:',
|
|
161
|
+
{
|
|
162
|
+
rbacCallbackResults,
|
|
163
|
+
isAllowed,
|
|
164
|
+
errorsFound
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (hasError || errorsFound.length > 0) {
|
|
169
|
+
const errorResult = {
|
|
170
|
+
errorsFound,
|
|
171
|
+
status: 'rejected',
|
|
172
|
+
requestParams: originalRequestParams
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
_izContext.logger.debug(
|
|
176
|
+
'[<%- flowTag %>RbacCallbackMain] RBAC check failed, publishing rejected status:',
|
|
177
|
+
errorResult
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
await sns.publishAsync(_izContext, {
|
|
181
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
182
|
+
_izContext,
|
|
183
|
+
'<%- upperCaseFlowTag %>_Out',
|
|
184
|
+
process.env.iz_serviceTag
|
|
185
|
+
),
|
|
186
|
+
Message: JSON.stringify(errorResult)
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return errorResult;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//(<rbacCallbackMain>)
|
|
193
|
+
//(</rbacCallbackMain>)
|
|
194
|
+
|
|
195
|
+
const logicalResult = await <%- flowTag %>LogicalLib(
|
|
196
|
+
_izContext,
|
|
197
|
+
originalRequestParams,
|
|
198
|
+
callingFlowConfig,
|
|
199
|
+
errorsFound,
|
|
200
|
+
rbacCallbackResults
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
_izContext.logger.debug(
|
|
204
|
+
'[<%- flowTag %>RbacCallbackMain] <%- flowTag %>LogicalLib completed successfully:',
|
|
205
|
+
{
|
|
206
|
+
logicalResult
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
return logicalResult;
|
|
211
|
+
} catch (err) {
|
|
212
|
+
_izContext.logger.error('[<%- flowTag %>RbacCallbackMain] Error caught:', {
|
|
213
|
+
error: err
|
|
214
|
+
});
|
|
215
|
+
throw err;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -58,7 +58,7 @@ import { sns } from '@izara_project/izara-core-library-external-request';
|
|
|
58
58
|
export default async function <%- flowTag %>(
|
|
59
59
|
_izContext,
|
|
60
60
|
requestParams,
|
|
61
|
-
callingFlowConfig = {}
|
|
61
|
+
callingFlowConfig = {},
|
|
62
62
|
//(<additionalParams>)
|
|
63
63
|
//(</additionalParams>)
|
|
64
64
|
) {
|
|
@@ -43,7 +43,7 @@ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
|
43
43
|
export default async function <%- mainFileName %>(
|
|
44
44
|
_izContext,
|
|
45
45
|
requestParams,
|
|
46
|
-
callingFlowConfig = {}
|
|
46
|
+
callingFlowConfig = {},
|
|
47
47
|
//(<additionalParams>)
|
|
48
48
|
//(</additionalParams>)
|
|
49
49
|
) {
|
|
@@ -97,7 +97,14 @@ export default async function <%- mainFileName %>(
|
|
|
97
97
|
getDataDetail.serviceTag
|
|
98
98
|
);
|
|
99
99
|
|
|
100
|
-
const
|
|
100
|
+
const pkIdentifier = objectSchema.identifiers?.find(
|
|
101
|
+
(id) => id.type === 'partitionKey'
|
|
102
|
+
);
|
|
103
|
+
const pkName =
|
|
104
|
+
getDataDetail.groupByPartitionKeyField ||
|
|
105
|
+
pkIdentifier?.fieldName ||
|
|
106
|
+
pkIdentifier?.name ||
|
|
107
|
+
'pk';
|
|
101
108
|
const partitionKeyValue = { [pkName]: pk };
|
|
102
109
|
|
|
103
110
|
//(<beforeGetRangeDynamoDb>)
|