@izara_project/izara-market-library-service-schemas 1.0.19 → 1.0.20

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.
Files changed (86) hide show
  1. package/package.json +1 -1
  2. package/src/SourceManager/src/Utils.js +33 -9
  3. package/src/TemplateManager/src/FindData/FindDataYaml/data.js +4 -1
  4. package/src/TemplateManager/src/FindData/FindDataYaml/template.ejs +1 -14
  5. package/src/TemplateManager/src/GenerateCode.js +22 -5
  6. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +22 -2
  7. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/template.ejs +1 -14
  8. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/data.js +21 -2
  9. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/template.ejs +1 -14
  10. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +23 -3
  11. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +1 -14
  12. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +22 -2
  13. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/template.ejs +1 -14
  14. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +6 -6
  15. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/template.ejs +1 -14
  16. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +2 -1
  17. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/template.ejs +1 -14
  18. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +1 -1
  19. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/template.ejs +1 -14
  20. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +3 -1
  21. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/template.ejs +1 -14
  22. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +1 -1
  23. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +23 -3
  24. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/data.js +18 -2
  25. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/template.ejs +1 -14
  26. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/data.js +20 -3
  27. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/template.ejs +1 -14
  28. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/data.js +21 -3
  29. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/template.ejs +1 -14
  30. package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/template.ejs +1 -1
  31. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +16 -2
  32. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/template.ejs +1 -14
  33. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +17 -2
  34. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  35. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +16 -2
  36. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/template.ejs +1 -14
  37. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +18 -3
  38. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  39. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/data.js +18 -3
  40. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/template.ejs +1 -14
  41. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/data.js +15 -2
  42. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/template.ejs +1 -14
  43. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/data.js +17 -2
  44. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  45. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/data.js +16 -2
  46. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/template.ejs +1 -14
  47. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/data.js +18 -3
  48. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  49. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/data.js +18 -3
  50. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/template.ejs +1 -14
  51. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +19 -4
  52. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +1 -14
  53. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +19 -2
  54. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +1 -14
  55. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +19 -2
  56. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  57. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +20 -2
  58. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/template.ejs +1 -14
  59. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +20 -2
  60. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  61. package/src/TemplateManager/src/Role/createSharedResource.js +270 -0
  62. package/src/TemplateManager/src/Role/sharedResourceTemplate.ejs +58 -0
  63. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data.js +1 -1
  64. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data.js +1 -1
  65. package/src/TemplateManager/src/externalService/LambdaRole/data.js +13 -13
  66. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/data.js +16 -10
  67. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +8 -5
  68. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +22 -9
  69. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/data.js +102 -0
  70. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/template.ejs +43 -0
  71. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/data.js +94 -0
  72. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateAsyncHandler.ejs +110 -0
  73. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateSyncHandler.ejs +49 -0
  74. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/hookLogic/data.js +65 -0
  75. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/data.js +67 -0
  76. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/template.ejs +30 -0
  77. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/data.js +125 -0
  78. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/snsTemplate.ejs +59 -0
  79. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/sqsTemplate.ejs +43 -0
  80. package/src/TemplateManager/src/libs/Consts.js +36 -10
  81. package/src/TemplateManager/src/reStructureExample/GenerateCodeTest.js +31 -0
  82. package/src/TemplateManager/src/reStructureExample/TemplateConfig.js +11 -0
  83. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/data.js +0 -0
  84. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generateCodeShared.js +1 -0
  85. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generatePerAction.js +5 -0
  86. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/template.ejs +0 -0
@@ -0,0 +1,102 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+ const { HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
24
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, SQS_RESOURCE } = require("../../../../libs/Consts");
25
+ const templatePath = path.join(__dirname, "template.ejs")
26
+ /**
27
+ * receive objectSchema
28
+ * create data for WebScoket handler template
29
+ *
30
+ * @param {Object} objectSchema
31
+ * @return {{templatePath, templateData,setting}}
32
+ */
33
+
34
+ function data(_izContext, flowSchema, srcPath) {
35
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
36
+ }
37
+
38
+ function createSourceParams(_izContext, flowSchema, srcPath) {
39
+ let hook;
40
+ let hookFunctionName
41
+ let handlerType;
42
+ let queueName;
43
+ let filterPattern;
44
+ let additionalResourcePermission = defaultIamRolePerAction();
45
+ if (flowSchema?.hook) {
46
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
47
+ for (const hookFunction of hookProperties.functionList) {
48
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
49
+ if (hookFunction.event.continueFlow === true && hookFunction.event.initialEvent === false) {
50
+ hook = true
51
+ hookFunctionName = upperCase(hookFunction.name)
52
+ handlerType = upperCase(hookFunction.event.handlerType);
53
+ filterPattern = hookFunction.event.filterPattern;
54
+ additionalResourcePermission.push(
55
+ createIamRole(
56
+ {
57
+ [RESOURCE_CLASSES.sns]: [
58
+ SNS_RESOURCE.publish
59
+ ]
60
+ },
61
+ [
62
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
63
+ ]
64
+ )
65
+ )
66
+ if (upperCase(handlerType) === upperCase(HANDLER.hdrDsq)) {
67
+ queueName = hookFunction.event.queueName;
68
+ } else if (upperCase(handlerType) === upperCase(HANDLER.hdrSqs)) {
69
+ if (hookFunction.event.topicName.includes("In")) {
70
+ queueName = upperCase(hookFunction.event.topicName.slice(2));
71
+ } else {
72
+ queueName = hookFunction.event.topicName;
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ return {
81
+ templatePath: templatePath,
82
+ templateData: {
83
+ hookFunctionName,
84
+ handlerType,
85
+ queueName,
86
+ additionalResourcePermission,
87
+ functionName: upperCase(hookFunctionName),
88
+ functionNameConfig: upperCase(hookFunctionName) + upperCase(shortNameHandler(handlerType)),
89
+ resourceLocation: SOURCE_PATH.resourceLocationGeneratedCodeHookFunction,
90
+ filterPattern
91
+ },
92
+ setting: {
93
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
94
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
95
+ fileExtension: ".yml",
96
+ isAppend: true
97
+ }
98
+ }
99
+
100
+ }
101
+
102
+ module.exports = data;
@@ -0,0 +1,43 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%_ const { HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts'); _%>
3
+ <%- firstLetterUpperCase(functionNameConfig) %>:
4
+ handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
5
+ name: ${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
6
+ <%_ if (handlerType === firstLetterUpperCase(HANDLER.hdrDsq) || handlerType === firstLetterUpperCase(HANDLER.hdrSqs)) { _%>
7
+ events:
8
+ - sqs:
9
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %><%- firstLetterUpperCase(handlerType) %>
10
+ batchSize: 10
11
+ <%_ if (filterPattern) { _%>
12
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
13
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- filterPattern %>"]}}} # functionName of callingFlow
14
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
15
+ <%_ } _%>
16
+ <%_ } else if (handlerType === firstLetterUpperCase(HANDLER.hdrApi)) { _%>
17
+ events:
18
+ - http:
19
+ path: <%- objectType %>/<%- firstLetterUpperCase(action) %>
20
+ method: <%- event %>
21
+ cors: true
22
+ #<#<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>Authorizer#>
23
+ #<#/<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>Authorizer#>
24
+ <%_ } _%>
25
+ iamRoleStatements:
26
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
27
+ - Effect: <%- resourcePermission.effect %>
28
+ Action:
29
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
30
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
31
+ - <%- resourcePerAction %>:<%- permission %>
32
+ <%_ }) _%>
33
+ <%_ }) _%>
34
+ Resource:
35
+ <%_ resourcePermission.resource.forEach(resource => { _%>
36
+ - "<%- resource %>"
37
+ <%_ }) _%>
38
+ <%_}) _%>
39
+ #<#<%- functionName %><%- handlerType %>IamRole#>
40
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
41
+ <%_ function firstLetterUpperCase(text){
42
+ return text.charAt(0).toUpperCase() + text.slice(1)
43
+ } _%>
@@ -0,0 +1,94 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+ const { HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { createHookFunction } = require('../../../../../../SourceManager/src/Utils')
23
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
24
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
25
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, SQS_RESOURCE } = require("../../../../libs/Consts");
26
+ const asyncTemplatePath = path.join(__dirname, "templateAsyncHandler.ejs")
27
+ const syncTemplatePath = path.join(__dirname, "templateSyncHandler.ejs")
28
+ /**
29
+ * receive objectSchema
30
+ * create data for WebScoket handler template
31
+ *
32
+ * @param {Object} objectSchema
33
+ * @return {{templatePath, templateData,setting}}
34
+ */
35
+
36
+ function data(_izContext, flowSchema, srcPath) {
37
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ function createSourceParams(_izContext, flowSchema, srcPath) {
41
+ let hook;
42
+ let hookFunctionName
43
+ let handlerType;
44
+ let queueName;
45
+ if (flowSchema?.hook) {
46
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
47
+ for (const hookFunction of hookProperties.functionList) {
48
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
49
+ if (hookFunction.event.continueFlow === true && hookFunction.event.initialEvent === false) {
50
+ hook = true
51
+ hookFunctionName = upperCase(hookFunction.name)
52
+ handlerType = upperCase(hookFunction.event.handlerType);
53
+ if (upperCase(handlerType) === upperCase(HANDLER.hdrDsq)) {
54
+ queueName = hookFunction.event.queueName;
55
+ } else if (upperCase(handlerType) === upperCase(HANDLER.hdrSqs)) {
56
+ queueName = hookFunction.event.topicName;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ if (upperCase(handlerType) === upperCase(HANDLER.hdrSqs) || upperCase(handlerType) === upperCase(HANDLER.hdrDsq)) {
65
+ return {
66
+ templatePath: asyncTemplatePath,
67
+ templateData: {
68
+ hookFunctionName,
69
+ queueName
70
+ },
71
+ setting: {
72
+ savePath: path.join(srcPath, SOURCE_PATH.generatedCodeHookFunction),
73
+ saveFileName: `${upperCase(hookFunctionName)}_${upperCase(handlerType)}`,
74
+ fileExtension: ".js",
75
+ isAppend: false
76
+ }
77
+ }
78
+ } else if (upperCase(handlerType) === upperCase(HANDLER.hdrApi) || upperCase(handlerType) === upperCase(HANDLER.hdrInv)) {
79
+ return {
80
+ templatePath: syncTemplatePath,
81
+ templateData: {
82
+ hookFunctionName,
83
+ },
84
+ setting: {
85
+ savePath: path.join(srcPath, SOURCE_PATH.generatedCodeHookFunction),
86
+ saveFileName: `${upperCase(hookFunctionName)}_${upperCase(handlerType)}`,
87
+ fileExtension: ".js",
88
+ isAppend: false
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ module.exports = data;
@@ -0,0 +1,110 @@
1
+ /*
2
+ Copyright (C) 2021 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ // const AWS = require('aws-sdk');
21
+ // const sqs = new AWS.SQS(firstLetterUpperCase{ apiVersion: '2012-11-05' });
22
+
23
+ const izara = require("@izara_project/izara-middleware");
24
+ const middleware = izara.middlewareHandler;
25
+ const recordHandlerSharedLib = require("@izara_project/izara-shared").recordHandlerSharedLib;
26
+ const Logger = require('@izara_project/izara-core-library-logger');
27
+ const izaraShared = require('@izara_project/izara-shared');
28
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
29
+
30
+ const <%- hookFunctionName %> = require('./<%- hookFunctionName %>_Main')
31
+
32
+ // validate event properties in body.Message of sqs event
33
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
34
+
35
+ // set schema for record.body.Message
36
+ let perRecordsValidatorSchema = {
37
+ type: "object",
38
+ required: [
39
+ 'returnMessage',
40
+ 'errorsFound',
41
+ 'passStatus'
42
+ ],
43
+ properties: {
44
+ returnMessage: {
45
+ type: "object"
46
+ },
47
+ errorsFound: {
48
+ type: "array"
49
+ },
50
+ passStatus: {
51
+ type: 'boolean'
52
+ }
53
+ }
54
+ };
55
+
56
+ perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema)
57
+
58
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
59
+
60
+ try {
61
+
62
+ let recordPromises = [];
63
+
64
+ // loop each record and send to mainFunction
65
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
66
+
67
+ let passOnProperties = []
68
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
69
+
70
+ // validate message (and MessageAttributes)
71
+ await recordHandlerSharedLib.validateRecord(
72
+ record, // one record will send to mainFunction
73
+ "<%- queueName %>", // queue name that need to retry or send to dlq
74
+ perRecordsValidatorSchema, // schema for record.Message
75
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
76
+ );
77
+
78
+ // add argument (to invoke lambda) to passOnProperties[]
79
+ passOnProperties.push(record.body.Message)
80
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message))
81
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
82
+
83
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
84
+ let recordPromise = recordHandlerSharedLib.recordHandler(
85
+ record, // one record will send to mainFunction
86
+ <%- hookFunctionName %>, // mainFunction that need to invoke.
87
+ "<%- queueName %>", // queue name that need to retry or send to dlq
88
+ passOnProperties, // all parameters that mainFunction needed.
89
+ );
90
+ record._izContext.logger.debug('after recordPromise in handler');
91
+ recordPromises.push(recordPromise); // push promise to recordPromises
92
+ }))
93
+
94
+ Logger.debug('before Promise.all(recordPromises) in handler');
95
+ try {
96
+ // --- main await all promises
97
+ await Promise.all(recordPromises); // await all promises
98
+
99
+ return event.Records // return all for local test
100
+
101
+ } catch {
102
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
103
+ }
104
+ Logger.debug('after Promise.all(recordPromises) in handler');
105
+
106
+ } catch (err) {
107
+ Logger.error('Unhandled Error, <%- hookFunctionName %>: ', err);
108
+ throw (err);
109
+ }
110
+ });
@@ -0,0 +1,49 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const izara = require("@izara_project/izara-middleware");
21
+ const middleware = izara.middlewareHandler;
22
+
23
+ // const CorrelationIds = require('@izara_project/izara-core-library-correlation-ids')
24
+ // const Logger = require('@izara_project/izara-core-library-logger');
25
+ // const IntegrationTestDetail = require('@izara_project/izara-core-library-integration-tests')
26
+
27
+ const <%- hookFunctionName %> = require('./<%- hookFunctionName %>_Main');
28
+
29
+ // validate event params in middlewware before into function.
30
+ const validatorSchema = {};
31
+ middleware.setValidatorSchema(validatorSchema);
32
+
33
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
34
+ event._izContext.logger.debug('Event:', event);
35
+ event._izContext.logger.debug('context:', context);
36
+
37
+ try {
38
+
39
+ // invoke LambdaFunction
40
+ return await <%- hookFunctionName %>(
41
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
42
+ event
43
+ );
44
+
45
+ } catch (err) {
46
+ event._izContext.logger.error('Error, <%- hookFunctionName %>: ', err);
47
+ throw (err);
48
+ }
49
+ });
@@ -0,0 +1,65 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+ const { HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { createHookFunction } = require('../../../../../../SourceManager/src/Utils')
23
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
24
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
25
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, SQS_RESOURCE } = require("../../../../libs/Consts");
26
+ const asyncTemplatePath = path.join(__dirname, "templateAsyncHandler.ejs")
27
+ const syncTemplatePath = path.join(__dirname, "templateSyncHandler.ejs")
28
+ /**
29
+ * receive objectSchema
30
+ * create data for WebScoket handler template
31
+ *
32
+ * @param {Object} objectSchema
33
+ * @return {{templatePath, templateData,setting}}
34
+ */
35
+
36
+ async function data(_izContext, flowSchema, srcPath) {
37
+ return [await createSourceParams(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ async function createSourceParams(_izContext, flowSchema, srcPath) {
41
+ if (flowSchema?.hook) {
42
+ await Promise.all(
43
+ Object.values(flowSchema.hook).map(hookProperties =>
44
+ Promise.all(
45
+ hookProperties.functionList.map(hookFunction =>
46
+ createHookFunction(
47
+ _izContext,
48
+ hookFunction.logicFunction,
49
+ {
50
+ fileExtension: ".js",
51
+ isAppend: false,
52
+ saveFileName: `${hookFunction.name}`,
53
+ destinationPath: path.join(srcPath, SOURCE_PATH.logicalFunctionHook),
54
+ }
55
+ )
56
+ )
57
+ )
58
+ )
59
+ );
60
+ }
61
+ }
62
+
63
+
64
+
65
+ module.exports = data
@@ -0,0 +1,67 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+ const { createHookFunction } = require('../../../../../../GenerateCodeLibs/src/GenerateCodeLibs')
22
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
24
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler } = require("../../../../libs/Consts");
25
+ const templatePath = path.join(__dirname, "template.ejs")
26
+ /**
27
+ * receive objectSchema
28
+ * create data for WebScoket handler template
29
+ *
30
+ * @param {Object} objectSchema
31
+ * @return {{templatePath, templateData,setting}}
32
+ */
33
+
34
+ function data(_izContext, flowSchema, srcPath) {
35
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
36
+ }
37
+
38
+ function createSourceParams(_izContext, flowSchema, srcPath) {
39
+ let hook;
40
+ let hookFunctionName;
41
+ if (flowSchema?.hook) {
42
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
43
+ for (const hookFunction of hookProperties.functionList) {
44
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
45
+ if (hookFunction.event.continueFlow === true) {
46
+ hook = true
47
+ hookFunctionName = hookFunction.name
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ return {
54
+ templatePath: templatePath,
55
+ templateData: {
56
+ hookFunctionName
57
+ },
58
+ setting: {
59
+ savePath: path.join(srcPath, SOURCE_PATH.generatedCodeHookFunction),
60
+ saveFileName: `${upperCase(hookFunctionName)}_Main`,
61
+ fileExtension: ".js",
62
+ isAppend: false
63
+ }
64
+ }
65
+ }
66
+
67
+ module.exports = data;
@@ -0,0 +1,30 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const <%- hookFunctionName %> = require("../../HookLogicFunction/source/<%- upperCase(hookFunctionName) %>");
21
+ const createObjectMain = require("../../../CreateObjectS3_Main")
22
+
23
+ module.exports.main = async (event, callingFlow) => {
24
+ const result = await <%- hookFunctionName %>(event);
25
+ await createObjectMain(...result, callingFlow);
26
+ }
27
+
28
+ <%_ function upperCase(string) {
29
+ return string.charAt(0).toUpperCase() + string.slice(1);
30
+ } _%>