@izara_project/izara-market-library-service-schemas 1.0.84 → 1.0.85
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/index.js +0 -1
- package/package.json +1 -2
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +17 -1938
- package/src/MainLibs/src/Consts.js +383 -4
- package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/data.js +9 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +16 -3
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +18 -5
- package/src/reStructure/TemplateData/IntTest/generateTests/events/data.js +2 -0
- package/src/reStructure/TemplateData/IntTest/generateTests/pathIntTest/data.js +10 -1
- package/src/reStructure/TemplateData/IntTest/generateTests/pathIntTest/template.ejs +4 -4
- package/src/reStructure/TemplateData/IntTest/libs/libs.js +1 -1
- package/src/reStructure/TemplateData/externalService/functionNameConfig/templateIntTesting.ejs +1 -1
- package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +1 -1
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/triggerCacheComponent/processTriggerCache/handler/template.ejs +1 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/dsqTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/templateByHandler/sqsTemplate.ejs +2 -3
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +1 -1
- package/src/CheckPermission/CheckPermission.js +0 -122
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/request.json +0 -0
|
@@ -21,7 +21,7 @@ import { middlewareHandler } from "@izara_project/izara-middleware";
|
|
|
21
21
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
22
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
23
|
import recordHandlerSharedLib from '@izara_project/izara-core-library-record-handler';
|
|
24
|
-
import {
|
|
24
|
+
import { validator } from '@izara-core-library-service-schemas';
|
|
25
25
|
|
|
26
26
|
//(<optionalRequire>)
|
|
27
27
|
//(</optionalRequire>)
|
|
@@ -68,7 +68,7 @@ export const main = middlewareHandler.wrap(async (event, context) => {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
await
|
|
71
|
+
await validator.validateSchemaPerRecord(
|
|
72
72
|
record,
|
|
73
73
|
"<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handler) %>",
|
|
74
74
|
object,
|
|
@@ -22,8 +22,17 @@ const __dirname = path.dirname(__filename);
|
|
|
22
22
|
|
|
23
23
|
import { consts, utils } from '../../../../../MainLibs/index.js';
|
|
24
24
|
const { ACTIONS, HANDLER, DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = consts;
|
|
25
|
+
<<<<<<< HEAD
|
|
25
26
|
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
26
27
|
utils;
|
|
28
|
+
=======
|
|
29
|
+
<<<<<<< HEAD
|
|
30
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } =
|
|
31
|
+
utils;
|
|
32
|
+
=======
|
|
33
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = utils;
|
|
34
|
+
>>>>>>> 92addbe (Refactor JavaScript files for improved readability and consistency)
|
|
35
|
+
>>>>>>> 50cbec7 (Refactor JavaScript files for improved readability and consistency)
|
|
27
36
|
|
|
28
37
|
const templatePath = path.join(__dirname, 'template.ejs');
|
|
29
38
|
|
|
@@ -21,7 +21,7 @@ import { middlewareHandler } from "@izara_project/izara-middleware";
|
|
|
21
21
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
22
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
23
23
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
24
|
-
import {
|
|
24
|
+
import { validator } from '@izara-core-library-service-schemas';
|
|
25
25
|
|
|
26
26
|
//(<optionalRequire>)
|
|
27
27
|
//(</optionalRequire>)
|
|
@@ -65,7 +65,7 @@ export const main = middlewareHandler.wrap(async (event, context) => {
|
|
|
65
65
|
serviceTag: process.env.iz_serviceTag
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
await
|
|
68
|
+
await validator.validateSchemaPerRecord(
|
|
69
69
|
record,
|
|
70
70
|
"<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handler) %>",
|
|
71
71
|
object,
|
|
@@ -15,8 +15,15 @@ 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
|
+
<<<<<<< HEAD
|
|
18
19
|
|
|
20
|
+
=======
|
|
21
|
+
<<<<<<< HEAD
|
|
22
|
+
>>>>>>> 50cbec7 (Refactor JavaScript files for improved readability and consistency)
|
|
19
23
|
|
|
24
|
+
|
|
25
|
+
=======
|
|
26
|
+
>>>>>>> 92addbe (Refactor JavaScript files for improved readability and consistency)
|
|
20
27
|
// ──────────────────────── Core Node Modules ────────────────────────
|
|
21
28
|
import lodash from "lodash";
|
|
22
29
|
|
|
@@ -369,7 +376,10 @@ export default async function createMain(
|
|
|
369
376
|
callingFlowProperties: callingFlowConfig.callingFlowProperties || {}
|
|
370
377
|
})),
|
|
371
378
|
PREFIX.CREATE_OBJECT_ASYNC
|
|
372
|
-
)
|
|
379
|
+
),
|
|
380
|
+
//(<additionalAttributeCreateObjectAsync>)
|
|
381
|
+
//(</additionalAttributeCreateObjectAsync>)
|
|
382
|
+
);
|
|
373
383
|
listOfObjectForCreates.push({
|
|
374
384
|
[storageTag]: {
|
|
375
385
|
objInstanceFull: {
|
|
@@ -397,7 +407,10 @@ export default async function createMain(
|
|
|
397
407
|
callingFlowProperties: callingFlowConfig.callingFlowProperties || {}
|
|
398
408
|
})),
|
|
399
409
|
PREFIX.CREATE_OBJECT_EXTERNAL_TOPIC
|
|
400
|
-
)
|
|
410
|
+
),
|
|
411
|
+
//(<additionalAttributeCreateExternalObjectAsync>)
|
|
412
|
+
//(</additionalAttributeCreateExternalObjectAsync>)
|
|
413
|
+
);
|
|
401
414
|
|
|
402
415
|
let sendToCreateExternalTopic = {
|
|
403
416
|
Message: JSON.stringify(objInstanceFullForExternalTopic),
|
|
@@ -430,7 +443,7 @@ export default async function createMain(
|
|
|
430
443
|
/// step save awaitingMultipleStep of storageType graph ...........................................................
|
|
431
444
|
if (!userAgent) {
|
|
432
445
|
_izContext.logger.debug("not api will create awaitingStep")
|
|
433
|
-
await asyncFlowSharedLib.
|
|
446
|
+
await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
|
|
434
447
|
_izContext,
|
|
435
448
|
allAwaitingStepsId,
|
|
436
449
|
asyncFlowSharedLib.createPendingStepId((hash({ objType: objType, identifiers: objInstanceFull.identifiers })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)
|
|
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20
20
|
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
21
21
|
|
|
22
22
|
// ==================== Core Service Schemas ====================
|
|
23
|
-
import { getObjectSchema, consts, createObjType } from '@izara_project/izara-core-library-service-schemas'
|
|
23
|
+
import { getObjectSchema, consts, createObjType, dataDetailsLib } from '@izara_project/izara-core-library-service-schemas'
|
|
24
24
|
|
|
25
25
|
// ==================== Market Service Schemas ====================
|
|
26
26
|
import { constsGenerateCodeLibs, generateCodeLibs } from '@izara_project/izara-market-library-service-schemas';
|
|
@@ -99,7 +99,7 @@ export default async function deleteMain(
|
|
|
99
99
|
create deleteDataDetail that decade what storage that have to access or not
|
|
100
100
|
because it only use identifier and don't care fieldName
|
|
101
101
|
*/
|
|
102
|
-
let deleteDataDetails = await createDeleteDataDetail(
|
|
102
|
+
let deleteDataDetails = await dataDetailsLib.createDeleteDataDetail(
|
|
103
103
|
_izContext,
|
|
104
104
|
objectSchema,
|
|
105
105
|
);
|
|
@@ -19,7 +19,7 @@ Copyright (C) 2020 Sven Mason <http: //izara.io>
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
// ==================== Izara Core Service Schemas ====================
|
|
22
|
-
import { getObjectSchema, serviceConfig, consts, identifiersObject, utils } from '@izara_project/izara-core-library-service-schemas'
|
|
22
|
+
import { getObjectSchema, serviceConfig, consts, identifiersObject, utils, dataDetailsLib } from '@izara_project/izara-core-library-service-schemas'
|
|
23
23
|
const { getObjSchemaS3WithHierarchy } = getObjectSchema;
|
|
24
24
|
const { getGraphServiceTagWithCache } = serviceConfig;
|
|
25
25
|
const { objInstanceFromObjInstanceBase } = identifiersObject;
|
|
@@ -131,7 +131,7 @@ export default async function getMain(
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
let getDataDetails = await createGetDataDetails(
|
|
134
|
+
let getDataDetails = await dataDetailsLib.createGetDataDetails(
|
|
135
135
|
_izContext,
|
|
136
136
|
objectSchema,
|
|
137
137
|
);
|
|
@@ -16,7 +16,14 @@ along with this program. If not, see
|
|
|
16
16
|
<http: //www.gnu.org/licenses />.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
<<<<<<< HEAD
|
|
19
20
|
|
|
21
|
+
=======
|
|
22
|
+
<<<<<<< HEAD
|
|
23
|
+
|
|
24
|
+
=======
|
|
25
|
+
>>>>>>> 92addbe (Refactor JavaScript files for improved readability and consistency)
|
|
26
|
+
>>>>>>> 50cbec7 (Refactor JavaScript files for improved readability and consistency)
|
|
20
27
|
// ==================== Shared Core Utilities ====================
|
|
21
28
|
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
22
29
|
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
@@ -30,7 +37,6 @@ const { createObjType } = utils;
|
|
|
30
37
|
import { generateCodeLibs, constsGenerateCodeLibs } from '@izara_project/izara-market-library-service-schemas'
|
|
31
38
|
const {
|
|
32
39
|
dynamoDbIdentifiersByStorageResource,
|
|
33
|
-
createFieldForUpdateDynamoDb,
|
|
34
40
|
createUpdateDataDetail,
|
|
35
41
|
} = generateCodeLibs;
|
|
36
42
|
|
|
@@ -229,6 +235,7 @@ export default async function updateMain(
|
|
|
229
235
|
|
|
230
236
|
let awaitingStepIds = [];
|
|
231
237
|
let updateItem;
|
|
238
|
+
|
|
232
239
|
function createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, updateDataDetail) {
|
|
233
240
|
let fields = {};
|
|
234
241
|
for (let fieldName of Object.keys(requestParams.objInstanceFull.fields)) {
|
|
@@ -285,12 +292,14 @@ export default async function updateMain(
|
|
|
285
292
|
// correlationIds: _izContext.correlationIds.get("id")
|
|
286
293
|
}),
|
|
287
294
|
PREFIX.updateNode
|
|
288
|
-
)
|
|
295
|
+
),
|
|
296
|
+
//(<additionalAttributes>)
|
|
297
|
+
//(</additionalAttributes>)
|
|
289
298
|
)
|
|
290
299
|
_izContext.logger.debug("awaitingStepIds", awaitingStepIds)
|
|
291
300
|
|
|
292
301
|
if (awaitingStepIds.length) {
|
|
293
|
-
let awaitingMultipleStep = await asyncFlowSharedLib.
|
|
302
|
+
let awaitingMultipleStep = await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
|
|
294
303
|
_izContext,
|
|
295
304
|
awaitingStepIds,
|
|
296
305
|
asyncFlowSharedLib.createPendingStepId(
|
|
@@ -374,11 +383,15 @@ export default async function updateMain(
|
|
|
374
383
|
|
|
375
384
|
for (const field in object) {
|
|
376
385
|
if (requestParams.objInstanceFull.identifiers.hasOwnProperty(field)) {
|
|
377
|
-
Object.assign(objInstanceFull.identifiers, {
|
|
386
|
+
Object.assign(objInstanceFull.identifiers, {
|
|
387
|
+
[field]: requestParams.objInstanceFull.identifiers[field]
|
|
388
|
+
})
|
|
378
389
|
}
|
|
379
390
|
|
|
380
391
|
if (requestParams.objInstanceFull.fields.hasOwnProperty(field)) {
|
|
381
|
-
Object.assign(objInstanceFull.fields, {
|
|
392
|
+
Object.assign(objInstanceFull.fields, {
|
|
393
|
+
[field]: requestParams.objInstanceFull.fields[field]
|
|
394
|
+
})
|
|
382
395
|
}
|
|
383
396
|
}
|
|
384
397
|
|
|
@@ -44,6 +44,7 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
44
44
|
let outputEventTag = `Output_${inputEventTag}`;
|
|
45
45
|
|
|
46
46
|
let inputConfig = {
|
|
47
|
+
forStageMatching: true,
|
|
47
48
|
...setEvent(
|
|
48
49
|
eachStage.inputConfig.inputEvent,
|
|
49
50
|
eachStage.inputConfig.inputEventSettings
|
|
@@ -55,6 +56,7 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
let outputConfig = {
|
|
59
|
+
forStageMatching: true,
|
|
58
60
|
...setEvent(
|
|
59
61
|
eachStage.outputConfig.outputEvent,
|
|
60
62
|
eachStage.outputConfig.outputEventSettings
|
|
@@ -30,18 +30,27 @@ async function data(_izContext, srcPath, settings) {
|
|
|
30
30
|
settings
|
|
31
31
|
);
|
|
32
32
|
console.log({ pathIntTestInBuckets });
|
|
33
|
+
let intTestPaths = [];
|
|
34
|
+
for (const pathIntTestInBucket of pathIntTestInBuckets) {
|
|
35
|
+
if (pathIntTestInBucket.key.endsWith(".json")) {
|
|
36
|
+
let path = pathIntTestInBucket.key.replace(/(events|tests|resources|dynamoDBSeedDataTags|graphSeedDataTags).json$/, '/');
|
|
37
|
+
intTestPaths.push(`${path}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
|
|
34
41
|
return {
|
|
35
|
-
templateData: {
|
|
42
|
+
templateData: { intTestPaths },
|
|
36
43
|
templatePath: templatePath,
|
|
37
44
|
setting: {
|
|
38
45
|
generateHookFile: false,
|
|
39
46
|
savePath: path.join(srcPath, `./libs/`),
|
|
40
47
|
saveFileName: 'IntTestPath',
|
|
41
48
|
fileExtension: '.js',
|
|
49
|
+
fileExtension: '.js',
|
|
42
50
|
isAppend: false
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
|
|
47
56
|
export default data;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let intTestPath = [
|
|
2
|
-
<%
|
|
3
|
-
|
|
4
|
-
<% })
|
|
5
|
-
]
|
|
2
|
+
<% intTestPaths.forEach((intTestPath,index) => { -%>
|
|
3
|
+
"<%- intTestPath %>"<%= index < intTestPaths.length - 1 ? "," : "" %>
|
|
4
|
+
<% }) -%>
|
|
5
|
+
]
|
|
@@ -100,7 +100,7 @@ function createTestFunctionName(eventTag) { // set resourceName GCTpBas_Create
|
|
|
100
100
|
|
|
101
101
|
function setEvent(input, settings = {}) {
|
|
102
102
|
const transformedObject = {
|
|
103
|
-
forStageMatching: true
|
|
103
|
+
// forStageMatching: true
|
|
104
104
|
};
|
|
105
105
|
const forStageMatchs = settings?.forStageMatchs || [];
|
|
106
106
|
const testValueMatches = settings?.testValueMatches || [];
|
package/src/reStructure/TemplateData/externalService/functionNameConfig/templateIntTesting.ejs
CHANGED
|
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
export
|
|
20
|
+
export function generatedIntTestRoleNameConfig () {
|
|
21
21
|
let roleNameConfigIntTest = [
|
|
22
22
|
<% roleNameConfigs.forEach(roleNameConfig => { _%>
|
|
23
23
|
"<%- firstLetterUpperCase(roleNameConfig) %>",
|
|
@@ -23,7 +23,7 @@ import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
|
23
23
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
24
24
|
const _izContext = {logger : Logger}
|
|
25
25
|
|
|
26
|
-
export
|
|
26
|
+
export function generatedLambdaRole() {
|
|
27
27
|
let externalLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
|
|
28
28
|
{
|
|
29
29
|
roleName: "<%- data.objectType %>",
|
|
@@ -41,6 +41,7 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
41
41
|
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
42
42
|
|
|
43
43
|
let passOnProperties = []
|
|
44
|
+
record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
|
|
44
45
|
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
45
46
|
|
|
46
47
|
//validate message (and MessageAttributes)
|
|
@@ -154,7 +154,7 @@ let validator = {
|
|
|
154
154
|
await recordHandlerSharedLib.validateRecord(
|
|
155
155
|
record, // one record will send to mainFunction
|
|
156
156
|
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
157
|
-
|
|
157
|
+
validator, // schema for record.Message
|
|
158
158
|
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
159
159
|
);
|
|
160
160
|
|
|
@@ -137,7 +137,7 @@ let validator = {
|
|
|
137
137
|
await recordHandlerSharedLib.validateRecord(
|
|
138
138
|
record, // one record will send to mainFunction
|
|
139
139
|
"<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
|
|
140
|
-
|
|
140
|
+
validator, // schema for record.Message
|
|
141
141
|
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
142
142
|
);
|
|
143
143
|
|
|
@@ -178,5 +178,4 @@ let validator = {
|
|
|
178
178
|
} _%>
|
|
179
179
|
<%_ function firstLetterLowerCase(str) {
|
|
180
180
|
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
181
|
-
} _%>
|
|
182
|
-
Package
|
|
181
|
+
} _%>
|
|
@@ -49,7 +49,7 @@ const {
|
|
|
49
49
|
TOPIC_NAME_GRAPH_HANDLER
|
|
50
50
|
} = constsGenerateCodeLibs;
|
|
51
51
|
|
|
52
|
-
import {
|
|
52
|
+
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
53
53
|
|
|
54
54
|
//(<optionalRequire>)
|
|
55
55
|
//(</optionalRequire>)
|
package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs
CHANGED
|
@@ -47,7 +47,7 @@ import { constsGenerateCodeLibs } from '@izara_project/izara-market-library-serv
|
|
|
47
47
|
const { PREFIX,
|
|
48
48
|
TOPIC_NAME_GENERATE_CODE,
|
|
49
49
|
TOPIC_NAME_GRAPH_HANDLER } = constsGenerateCodeLibs;
|
|
50
|
-
import {
|
|
50
|
+
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
51
51
|
|
|
52
52
|
//(<optionalRequire>)
|
|
53
53
|
//(</optionalRequire>)
|
|
@@ -46,7 +46,7 @@ import { constsGenerateCodeLibs } from '@izara_project/izara-market-library-serv
|
|
|
46
46
|
const { PREFIX,
|
|
47
47
|
TOPIC_NAME_GENERATE_CODE,
|
|
48
48
|
TOPIC_NAME_GRAPH_HANDLER } = constsGenerateCodeLibs;
|
|
49
|
-
import {
|
|
49
|
+
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
50
50
|
|
|
51
51
|
//(<optionalRequire>)
|
|
52
52
|
//(</optionalRequire>)
|
package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs
CHANGED
|
@@ -47,7 +47,7 @@ import { constsGenerateCodeLibs } from '@izara_project/izara-market-library-serv
|
|
|
47
47
|
const { PREFIX,
|
|
48
48
|
TOPIC_NAME_GENERATE_CODE,
|
|
49
49
|
TOPIC_NAME_GRAPH_HANDLER } = constsGenerateCodeLibs;
|
|
50
|
-
import {
|
|
50
|
+
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
51
51
|
|
|
52
52
|
//(<optionalRequire>)
|
|
53
53
|
//(</optionalRequire>)
|
|
@@ -1,122 +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 lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
19
|
-
import { lambda } from '@izara_project/izara-core-library-external-request';
|
|
20
|
-
import { consts } from '@izara_project/izara-core-library-core';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Checks a user's permission by invoking another Lambda function.
|
|
24
|
-
* Adheres to Izara.io backend syntax guidelines.
|
|
25
|
-
*
|
|
26
|
-
* @param {object} _izContext - The context object containing logger, credentials, etc.
|
|
27
|
-
* @param {object} payload - The data payload for the permission check.
|
|
28
|
-
* @param {string} [payload.objectType] - The type of the object (e.g., 'INVOICE'). Must be used with `action`.
|
|
29
|
-
* @param {string} [payload.action] - The action to perform (e.g., 'READ', 'APPROVE'). Must be used with `objectType`.
|
|
30
|
-
* @param {string} [payload.flowTag] - The tag for a flow-based permission check. Used instead of `objectType`/`action`.
|
|
31
|
-
* @param {string} [payload.serviceName] - The name of the calling service (optional).
|
|
32
|
-
* @returns {Promise<{status: boolean, errorFound?: string}>}
|
|
33
|
-
* Resolves with the result of the permission check:
|
|
34
|
-
* - `status`: Whether the user has permission.
|
|
35
|
-
* - `errorFound`: Optional error message if the permission check failed.
|
|
36
|
-
*
|
|
37
|
-
* @throws {Error} If the payload is invalid or Lambda invocation fails.
|
|
38
|
-
*/
|
|
39
|
-
async function checkPermission(_izContext, payload) {
|
|
40
|
-
// Validate that the payload object itself is provided.
|
|
41
|
-
if (!payload || typeof payload !== 'object') {
|
|
42
|
-
const error = new Error('Payload object is required.');
|
|
43
|
-
_izContext.logger.error(error.message);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const userId = _izContext.correlationIds.get(consts.BASE_USER_ID);
|
|
48
|
-
const targetId = _izContext.correlationIds.get(consts.TARGET_ID);
|
|
49
|
-
|
|
50
|
-
// Validate the required 'userId' field.
|
|
51
|
-
if (!userId || typeof userId !== 'string' || userId.trim() === '') {
|
|
52
|
-
const error = new Error(
|
|
53
|
-
'userId is required and must be a non-empty string.'
|
|
54
|
-
);
|
|
55
|
-
_izContext.logger.error(error.message);
|
|
56
|
-
throw error;
|
|
57
|
-
} else {
|
|
58
|
-
payload.userId = userId;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (targetId) {
|
|
62
|
-
payload.targetId = targetId;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Define validation flags for business rules.
|
|
66
|
-
const hasObjectParams = payload.objectType || payload.action;
|
|
67
|
-
const hasFlowTag = payload.flowTag;
|
|
68
|
-
|
|
69
|
-
// Rule: Cannot mix object-based and flow-based parameters.
|
|
70
|
-
if (hasObjectParams && hasFlowTag) {
|
|
71
|
-
const error = new Error(
|
|
72
|
-
'Invalid payload: Cannot provide flowTag together with objectType or action.'
|
|
73
|
-
);
|
|
74
|
-
_izContext.logger.error(error.message, { payload });
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Rule: If using object-based, both objectType and action are required.
|
|
79
|
-
if (hasObjectParams && (!payload.objectType || !payload.action)) {
|
|
80
|
-
const error = new Error(
|
|
81
|
-
'Invalid payload: Both objectType and action must be provided together.'
|
|
82
|
-
);
|
|
83
|
-
_izContext.logger.error(error.message, { payload });
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Rule: Must provide at least one of the two valid schemas.
|
|
88
|
-
if (!hasObjectParams && !hasFlowTag) {
|
|
89
|
-
const error = new Error(
|
|
90
|
-
'Invalid payload: Must provide either (objectType and action) or flowTag.'
|
|
91
|
-
);
|
|
92
|
-
_izContext.logger.error(error.message, { payload });
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Log the payload for debugging before invoking the next service.
|
|
97
|
-
_izContext.logger.debug('Checking permission with payload:', payload);
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const lambdaName = lambdaSharedLib.lambdaFunctionName(
|
|
101
|
-
_izContext,
|
|
102
|
-
'CheckPermissionHdrInv',
|
|
103
|
-
'UserAccount'
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const result = await lambda.invokeSync(_izContext, lambdaName, payload);
|
|
107
|
-
|
|
108
|
-
_izContext.logger.info('Permission check invoked successfully.');
|
|
109
|
-
|
|
110
|
-
// example result = { status: boolean , errorFound: string }
|
|
111
|
-
return result;
|
|
112
|
-
} catch (err) {
|
|
113
|
-
// Log the full error object for better traceability.
|
|
114
|
-
_izContext.logger.error(
|
|
115
|
-
'Error invoking CheckPermissionHdrInv Lambda: ',
|
|
116
|
-
err
|
|
117
|
-
);
|
|
118
|
-
throw err;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export default checkPermission;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|