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

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 (90) hide show
  1. package/package.json +2 -2
  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 +2 -15
  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 +269 -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/FunctionNameConfig/data.js +98 -22
  66. package/src/TemplateManager/src/externalService/FunctionNameConfig/templateIntTesting.ejs +5 -5
  67. package/src/TemplateManager/src/externalService/FunctionNameConfig/templateYaml.ejs +2 -2
  68. package/src/TemplateManager/src/externalService/LambdaRole/data.js +32 -22
  69. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +1 -1
  70. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/data.js +16 -10
  71. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +8 -5
  72. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +22 -9
  73. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/data.js +102 -0
  74. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/template.ejs +43 -0
  75. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/data.js +94 -0
  76. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateAsyncHandler.ejs +110 -0
  77. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateSyncHandler.ejs +49 -0
  78. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/hookLogic/data.js +65 -0
  79. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/data.js +67 -0
  80. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/template.ejs +30 -0
  81. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/data.js +125 -0
  82. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/snsTemplate.ejs +59 -0
  83. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/sqsTemplate.ejs +43 -0
  84. package/src/TemplateManager/src/libs/Consts.js +38 -12
  85. package/src/TemplateManager/src/reStructureExample/GenerateCodeTest.js +31 -0
  86. package/src/TemplateManager/src/reStructureExample/TemplateConfig.js +11 -0
  87. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/data.js +0 -0
  88. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generateCodeShared.js +1 -0
  89. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generatePerAction.js +5 -0
  90. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/template.ejs +0 -0
@@ -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
+ } _%>
@@ -0,0 +1,125 @@
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 { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, SQS_RESOURCE } = require("../../../../libs/Consts");
24
+ const snsTemplatePath = path.join(__dirname, "./snsTemplate.ejs");
25
+ const sqsTemplatePath = path.join(__dirname, "./sqsTemplate.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 createSourceParams(_izContext, flowSchema, srcPath) {
35
+ let queueNames = [];
36
+ let resultForCreateQueueHook = []
37
+ const settings = {
38
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
39
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
40
+ fileExtension: ".yml",
41
+ isAppend: true
42
+ }
43
+ if (flowSchema?.hook) {
44
+ for (const hookProperties of Object.values(flowSchema.hook)) {
45
+ for (const hookFunction of hookProperties.functionList) {
46
+ if (hookFunction.event.continueFlow === true) {
47
+ if (hookFunction.event.handlerType === HANDLER.hdrSqs) {
48
+ queueNames.push(
49
+ {
50
+ queueName: "In" + createResourceSqsAndSns(
51
+ hookFunction.event.handlerType,
52
+ upperCase(hookProperties.name)
53
+ )
54
+ }
55
+ )
56
+ } else if (hookFunction.event.handlerType === HANDLER.hdrDsq) {
57
+ queueNames.push(
58
+ {
59
+ queueName: createResourceSqsAndSns(
60
+ hookFunction.event.handlerType,
61
+ upperCase(hookFunction.name)
62
+ )
63
+ }
64
+ )
65
+ }
66
+ if (hookFunction.event.createNewTopic === true) {
67
+ if (hookFunction.event.handlerType === HANDLER.hdrSqs) {
68
+ queueNames.push(
69
+ {
70
+ queueName: createResourceSqsAndSns(
71
+ hookFunction.event.handlerType,
72
+ upperCase(hookFunction.event.topicName)
73
+ )
74
+ }
75
+ )
76
+ } else if (hookFunction.event.handlerType === HANDLER.hdrDsq) {
77
+ queueNames.push(
78
+ {
79
+ queueName: createResourceSqsAndSns(
80
+ hookFunction.event.handlerType,
81
+ upperCase(hookFunction.event.queueName)
82
+
83
+ )
84
+ }
85
+ )
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+
94
+ for (const queueName of queueNames) {
95
+ if (queueName.queueName.includes(upperCase(HANDLER.hdrDsq))) {
96
+ resultForCreateQueueHook.push({
97
+ templatePath: sqsTemplatePath,
98
+ templateData: queueName.queueName,
99
+ setting: settings
100
+ })
101
+ } else {
102
+ resultForCreateQueueHook.push({
103
+ templatePath: snsTemplatePath,
104
+ templateData: queueName,
105
+ setting: settings
106
+ })
107
+ }
108
+ }
109
+ console.log("resultForCreateQueueHook: ", resultForCreateQueueHook);
110
+ return resultForCreateQueueHook;
111
+ }
112
+
113
+ function createResourceSqsAndSns(handlerType, resourceName) {
114
+ let queueName
115
+ if (handlerType === HANDLER.hdrDsq) {
116
+ queueName = upperCase(resourceName) + handlerType
117
+ } else if (handlerType === HANDLER.hdrSqs) {
118
+ if (resourceName.includes("In")) {
119
+ resourceName.slice(2)
120
+ }
121
+ queueName = resourceName
122
+ }
123
+ return queueName
124
+ }
125
+ module.exports = createSourceParams;
@@ -0,0 +1,59 @@
1
+ ##===== [Create topic in]
2
+ In<%- queueName %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message in"
6
+ TopicName: ${self:custom.iz_resourcePrefix}In<%- queueName %>
7
+ ##===== SNS Subscription
8
+ ##===== [Topic In]
9
+ SubscriptionIn<%- queueName %>:
10
+ Type: AWS::SNS::Subscription
11
+ Properties:
12
+ TopicArn: !Ref In<%- queueName %>
13
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
14
+ Protocol: "sqs"
15
+ ##===== [Queue]
16
+ <%- queueName %>HdrSqs:
17
+ Type: "AWS::SQS::Queue"
18
+ Properties:
19
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
20
+ RedrivePolicy:
21
+ deadLetterTargetArn:
22
+ # !GetAtt
23
+ Fn::GetAtt:
24
+ - <%- queueName %>HdrSqsDLQ
25
+ - Arn
26
+ maxReceiveCount: 3
27
+ VisibilityTimeout: 120
28
+ ##==== [QueueDLQ]
29
+ <%- queueName %>HdrSqsDLQ:
30
+ Type: AWS::SQS::Queue
31
+ Properties:
32
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
33
+ ##==== [QueuePolicy]
34
+ <%- queueName %>HdrSqsPolicy:
35
+ Type: AWS::SQS::QueuePolicy
36
+ Properties:
37
+ PolicyDocument:
38
+ Version: "2012-10-17"
39
+ Statement:
40
+ - Sid: "allow-sns-messages"
41
+ Effect: Allow
42
+ Principal: "*"
43
+ Resource:
44
+ # !GetAtt
45
+ Fn::GetAtt:
46
+ - <%- queueName %>HdrSqs
47
+ - Arn
48
+ Action: "SQS:SendMessage"
49
+ Queues:
50
+ - Ref: <%- queueName %>HdrSqs
51
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
52
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
53
+
54
+ <%_ function firstLetterUpperCase(text){
55
+ return text.charAt(0).toUpperCase() + text.slice(1)
56
+ } _%>
57
+ <%_ function firstLetterLowerCase(str) {
58
+ return str.charAt(0).toLowerCase() + str.slice(1)
59
+ } _%>
@@ -0,0 +1,43 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>DLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
+
19
+ <%- queueName %>Policy:
20
+ Type: AWS::SQS::QueuePolicy
21
+ Properties:
22
+ PolicyDocument:
23
+ Version: "2012-10-17"
24
+ Statement:
25
+ - Sid: "allow-sns-messages"
26
+ Effect: Allow
27
+ Principal: "*"
28
+ Resource: #!GetAtt
29
+ Fn::GetAtt:
30
+ - <%- queueName %>
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>
35
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
+
38
+ <%_ function firstLetterUpperCase(text){
39
+ return text.charAt(0).toUpperCase() + text.slice(1)
40
+ } _%>
41
+ <%_ function firstLetterLowerCase(str) {
42
+ return str.charAt(0).toLowerCase() + str.slice(1)
43
+ } _%>
@@ -23,6 +23,8 @@ const {
23
23
  STORAGE_TYPES
24
24
  } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
25
25
 
26
+ const { firstLetterUpperCase: upperCase } = require("../../../MainLibs/src/Utils")
27
+
26
28
  const { getGraphServiceNameFromGraphServerTagWithCache, getGraphServiceTagWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
27
29
 
28
30
  const DEFAULT_HANDLER_PER_ACTION = {
@@ -37,7 +39,7 @@ const RESOURCE_CLASSES = {
37
39
  s3: 's3',
38
40
  dynamoDbTable: 'dynamodb',
39
41
  dynamoDbAcrossService: 'dynamodb',
40
- sns: "SNS",
42
+ sns: "sns",
41
43
  lambda: "lambda",
42
44
  webSocket: "webSocket"
43
45
  };
@@ -72,7 +74,7 @@ function createIamRole(action, resource = [], effect = "Allow") {
72
74
  action.forEach(act => {
73
75
  if (act.includes(":")) {
74
76
  const [serviceAction, resourceAction] = act.split(":")
75
- actionObj[serviceAction] = [resourceAction]
77
+ actionObj[serviceAction] = [upperCase(resourceAction)]
76
78
  }
77
79
  });
78
80
  action = actionObj
@@ -113,10 +115,13 @@ const SOURCE_PATH = {
113
115
  resourceLocationRelationshipPerAction: 'src/generatedCode/RelationshipPerAction/source/',
114
116
  resourceLocationTranslateId: 'src/generatedCode/TranslateId/source/',
115
117
  resourceLocationProcessLogical: "src/generatedCode/ProcessLogical/source/",
116
- webSocket: "../src/generatedCode/WebSocket/source/",
117
- resourceLocationWebSocket: "src/generatedCode/WebSocket/source/",
118
+ webSocket: "../src/generatedCode/FlowSchema/source/",
119
+ resourceLocationWebSocket: "src/generatedCode/FlowSchema/source/",
118
120
  generateCodeLib: "../src/generatedCode/libs/source/",
119
- webSocketHook: "../src/generatedCode/WebSocket/source/hookFunction/source/"
121
+ logicalFunctionHook: "../src/generatedCode/WebSocket/source/FlowSchemaHook/HookLogicFunction/source/",
122
+ resourceLocationLogicalFunctionHook: "src/generatedCode/WebSocket/source/FlowSchemaHook/HookLogicFunction/source",
123
+ generatedCodeHookFunction: "../src/generatedCode/WebSocket/source/FlowSchemaHook/HookFunctionGeneratedCode/source/",
124
+ resourceLocationGeneratedCodeHookFunction: "src/generatedCode/WebSocket/source/FlowSchemaHook/HookFunctionGeneratedCode/source/",
120
125
  };
121
126
 
122
127
 
@@ -178,13 +183,26 @@ function externalResourceName(resourceClass, resourceName, serviceTag) {
178
183
  return {
179
184
  [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/${await dynamoSharedLib.tableName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
180
185
  // [RESOURCE_CLASSES.dynamoDbAcrossService]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/*/" + `${resourceName}`,
181
- [RESOURCE_CLASSES.dynamoDbAcrossService]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/*" + `${resourceName}`,
186
+ [RESOURCE_CLASSES.dynamoDbAcrossService]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/" + `"${serviceTag}"` + `"${resourceName}"`,
182
187
  [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${await lambdaSharedLib.lambdaFunctionName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
188
+ [RESOURCE_CLASSES.sns]: "arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${await snsSharedLib.snsTopicName(_izContext, " + `"${resourceName}", "${serviceTag}")}`
189
+
183
190
  }[resourceClass]
184
191
  };
185
192
 
186
- function externalResourceSns(resourceName, serviceTag) {
187
- return "arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${await snsSharedLib.snsTopicName(_izContext, " + `"${resourceName}", "${serviceTag}")}`
193
+ function externalResourceYaml(resourceClass, resourceName, serviceTag) {
194
+ if (!serviceTag) {
195
+ serviceTag = "${self:custom.iz_resourcePrefix}"
196
+ } else {
197
+ serviceTag = serviceTag + "Test"
198
+ }
199
+ return {
200
+ [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${self:custom.iz_region}:${self:custom.iz_accountId}:table/" + `${serviceTag}` + `${resourceName}`,
201
+ [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:" + `${serviceTag}` + `${resourceName}`,
202
+ [RESOURCE_CLASSES.sns]: "arn:aws:sns:${self:custom.iz_region}:${self:custom.iz_accountId}:" + `${serviceTag}` + `${resourceName}`,
203
+ [RESOURCE_CLASSES.sqs]: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:" + `${serviceTag}` + `${resourceName}`
204
+
205
+ }[resourceClass]
188
206
  };
189
207
 
190
208
  const SAVE_FILE_NAME = {
@@ -199,7 +217,8 @@ const SAVE_FILE_NAME = {
199
217
  findData: "findData",
200
218
  processLogicalYaml: "processLogical",
201
219
  flowSchema: "flowSchema",
202
- S3Bucket: "generated-s3-bucket"
220
+ S3Bucket: "generated-s3-bucket",
221
+ sharedResourceYaml: "generate-SharedResource",
203
222
  };
204
223
 
205
224
  const FUNCTION_NAME = {
@@ -275,7 +294,6 @@ function defaultIamRolePerAction() {
275
294
  },
276
295
  [
277
296
  resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
278
- resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
279
297
  resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
280
298
  ]
281
299
  )
@@ -340,6 +358,13 @@ function shortNameHandler(fullNameHandler) {
340
358
  return fullNameHandler.slice(3)
341
359
  };
342
360
 
361
+ const SOURCE_GENERATE_IAM_ROLE = {
362
+ ProcessFindDataRole: "ProcFindData",
363
+ ObjectCompleteRole: "ObjectCom",
364
+ RelationshipRole: "Relationship",
365
+ RelationshipCompleteRole: "RelationshipCom",
366
+ };
367
+
343
368
 
344
369
  module.exports = {
345
370
  ACTIONS,
@@ -355,7 +380,7 @@ module.exports = {
355
380
  LAMBDA_RESOURCE,
356
381
  HANDLER,
357
382
  externalResourceName,
358
- externalResourceSns,
383
+ externalResourceYaml,
359
384
  SAVE_FILE_NAME,
360
385
  FUNCTION_NAME,
361
386
  getGraphServiceNameFromAllRelSchema,
@@ -365,5 +390,6 @@ module.exports = {
365
390
  awaitingMultipleStepsRole,
366
391
  shortNameHandler,
367
392
  SHORT_FUNCTION_NAME,
368
- S3_RESOURCE
393
+ S3_RESOURCE,
394
+ SOURCE_GENERATE_IAM_ROLE
369
395
  }