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

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 (105) hide show
  1. package/package.json +2 -2
  2. package/src/GenerateCodeLibs/src/Consts.js +32 -2
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +3 -61
  4. package/src/SourceManager/src/Utils.js +16 -1
  5. package/src/TemplateManager/src/GenerateCode.js +134 -45
  6. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +1 -1
  7. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/data.js +1 -1
  8. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +1 -1
  9. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +42 -23
  10. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Delete/template.ejs +0 -1
  11. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +13 -11
  12. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +34 -18
  13. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler/mainFunction → PerActionEndpoint/libs}/data.js +12 -23
  14. package/src/TemplateManager/src/PerActionEndpoint/libs/template.ejs +46 -0
  15. package/src/TemplateManager/src/externalService/LambdaRole/data.js +114 -4
  16. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +3 -4
  17. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +31 -6
  18. package/src/TemplateManager/src/flowSchema/DefaultWebSocketResource/dynamoDb/ReservedTableData.js +65 -0
  19. package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/functionYaml/data.js +3 -2
  20. package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/handler/data.js +1 -1
  21. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/functionYaml/data.js +77 -0
  22. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler → flowSchema/FlowSchemaEndpoint/InProcessFlowSchema}/functionYaml/template.ejs +9 -3
  23. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/handler/data.js +47 -0
  24. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler → flowSchema/FlowSchemaEndpoint/InProcessFlowSchema}/handler/template.ejs +25 -52
  25. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/mainFunction/data.js +46 -0
  26. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/mainFunction/template.ejs +0 -0
  27. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/sns-sqs/data.js +36 -0
  28. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/sns-sqs/template.ejs +0 -0
  29. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/functionYaml/data.js +35 -0
  30. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/functionYaml/template.ejs +0 -0
  31. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/handler/data.js +35 -0
  32. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/handler/template.ejs +0 -0
  33. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/mainFunction/data.js +35 -0
  34. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/mainFunction/template.ejs +0 -0
  35. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/sns-sqs/data.js +35 -0
  36. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/sns-sqs/template.ejs +0 -0
  37. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/functionYaml/data.js +102 -0
  38. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/functionYaml/template.ejs +30 -0
  39. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/handler/data.js +58 -0
  40. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/handler/template.ejs +126 -0
  41. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/mainFunction/data.js +51 -0
  42. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/mainFunction/template.ejs +121 -0
  43. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/queue/data.js +64 -0
  44. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/queue/template.ejs +45 -0
  45. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler → flowSchema/UploadS3Case/createObject}/functionYaml/data.js +35 -12
  46. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/template.ejs +37 -0
  47. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +72 -0
  48. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +107 -0
  49. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler/handler → flowSchema/UploadS3Case/createObject/mainFunction}/data.js +11 -15
  50. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler → flowSchema/UploadS3Case/createObject}/mainFunction/template.ejs +4 -4
  51. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createObjectComplete}/functionYaml/data.js +6 -4
  52. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/functionYaml/template.ejs +30 -0
  53. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createObjectComplete}/handler/data.js +1 -1
  54. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createObjectComplete}/handler/template.ejs +10 -10
  55. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createObjectComplete}/mainFunction/data.js +3 -4
  56. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/mainFunction/template.ejs +86 -0
  57. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createObjectComplete}/sns-sqs/data.js +4 -2
  58. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/sns-sqs/template.ejs +49 -0
  59. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/functionYaml/data.js +85 -0
  60. package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete → flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc}/functionYaml/template.ejs +1 -1
  61. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/handler/data.js +57 -0
  62. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/handler/template.ejs +120 -0
  63. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/mainFunction/data.js +51 -0
  64. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/mainFunction/template.ejs +164 -0
  65. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/sqs/data.js +65 -0
  66. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/sqs/template.ejs +53 -0
  67. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/functionYaml/data.js +112 -0
  68. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/functionYaml/template.ejs +30 -0
  69. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/handler/data.js +57 -0
  70. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/handler/template.ejs +126 -0
  71. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/mainFunction/data.js +54 -0
  72. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/mainFunction/template.ejs +254 -0
  73. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/queue/data.js +64 -0
  74. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/queue/template.ejs +45 -0
  75. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/data.js +94 -0
  76. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/templateAsyncHandler.ejs +110 -0
  77. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/templateSyncHandler.ejs +49 -0
  78. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/hookLogic/data.js +44 -0
  79. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/mainFunction/data.js +66 -0
  80. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/mainFunction/template.ejs +7 -0
  81. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/queue/data.js +73 -0
  82. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/queue/snsTemplate.ejs +59 -0
  83. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrDsq/data.js +87 -0
  84. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrDsq/template.ejs +30 -0
  85. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrS3/data.js +112 -0
  86. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrS3/template.ejs +38 -0
  87. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerDsq/data.js +45 -0
  88. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerDsq/template.ejs +151 -0
  89. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerS3/data.js +43 -0
  90. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerS3/template.ejs +68 -0
  91. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/mainFunction/data.js +43 -0
  92. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/mainFunction/template.ejs +392 -0
  93. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/data.js +77 -0
  94. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/dsqTemplatePath.ejs +32 -0
  95. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/s3Template.ejs +59 -0
  96. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/S3/data.js +51 -0
  97. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/S3/template.ejs +13 -0
  98. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/libs/data.js +42 -0
  99. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/libs/template.ejs +137 -0
  100. package/src/TemplateManager/src/libs/Consts.js +57 -28
  101. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/mainFunction/template.ejs +0 -180
  102. /package/src/TemplateManager/src/{flowTag/resources/dynamoDb/data.js → flowSchema/DefaultWebSocketResource/dynamoDb/WebSocketTaskData.js} +0 -0
  103. /package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/functionYaml/template.ejs +0 -0
  104. /package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/handler/template.ejs +0 -0
  105. /package/src/TemplateManager/src/{flowTag/webSocket/webSocketComplete/sns-sqs/template.ejs → flowSchema/UploadS3Case/hookCode/queue/sqsTemplate.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 %>.<%- 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 %>.<%- 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,44 @@
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
+
42
+ }
43
+
44
+ module.exports = data
@@ -0,0 +1,66 @@
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?.initialEvent && hookFunction.event.initialEvent === true) {
46
+ hook = true
47
+ hookFunctionName = hookFunction.name
48
+ createHookFunction(_izContext, hookFunction.logicFunction, path.join(srcPath, SOURCE_PATH.webSocketHook))
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ return {
55
+ templatePath: templatePath,
56
+ templateData: {},
57
+ setting: {
58
+ savePath: path.join(srcPath, SOURCE_PATH.webSocketHook),
59
+ saveFileName: `${upperCase(hookFunctionName)}_Main`,
60
+ fileExtension: ".js",
61
+ isAppend: false
62
+ }
63
+ }
64
+ }
65
+
66
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ const <%- hookFunctionName %> = require("../../FlowSchemaHook/source/<%- hookFunctionName %>");
2
+ const createObjectMain = require("../../../CreateObjectS3_Main")
3
+
4
+ module.exports.main = async (event, callingFlow) => {
5
+ const result = await <%- hookFunctionName %>(event);
6
+ await createObjectMain(...result, callingFlow);
7
+ }
@@ -0,0 +1,73 @@
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.handlerType === HANDLER.hdrSqs) {
47
+ queueNames.push({ queueName: hookFunction.event.topicName });
48
+ } else if (hookFunction.event.handlerType === HANDLER.hdrDsq) {
49
+ queueNames.push({ queueName: hookFunction.event.queueName });
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ for (const queueName of queueNames) {
56
+ if (queueName.queueName.includes(upperCase(HANDLER.hdrDsq))) {
57
+ resultForCreateQueueHook.push({
58
+ templatePath: snsTemplatePath,
59
+ templateData: queueName.queueName,
60
+ setting: settings
61
+ })
62
+ } else {
63
+ resultForCreateQueueHook.push({
64
+ templatePath: sqsTemplatePath,
65
+ templateData: queueName,
66
+ setting: settings
67
+ })
68
+ }
69
+ }
70
+ return resultForCreateQueueHook;
71
+ }
72
+
73
+ 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,87 @@
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 path = require("path")
21
+
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../../MainLibs/src/Utils');
23
+ const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, S3_RESOURCE, resourceNames, DYNAMO_RESOURCE, SQS_RESOURCE, SNS_RESOURCE, shortNameHandler, HANDLER, FUNCTION_NAME } = require("../../../../../libs/Consts");
24
+ const templatePath = path.join(__dirname, "./template.ejs")
25
+
26
+ function data(_izContext, srcPath) {
27
+ return [createSourceParam(_izContext, srcPath)]
28
+ }
29
+
30
+ function createSourceParam(_izContext, srcPath) {
31
+ let functionName = upperCase(FUNCTION_NAME.processAfterUploadS3);
32
+ let handlerType = HANDLER.hdrDsq;
33
+ let additionalResourcePermission = defaultIamRolePerAction();
34
+ additionalResourcePermission.push(
35
+
36
+ createIamRole(
37
+ {
38
+ [RESOURCE_CLASSES.dynamoDbTable]: [
39
+ DYNAMO_RESOURCE.updateItem,
40
+ DYNAMO_RESOURCE.getItem
41
+ ]
42
+ },
43
+ [
44
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "ImportBatchMain")
45
+ ]
46
+ ),
47
+ createIamRole(
48
+ {
49
+ [RESOURCE_CLASSES.sqs]: [
50
+ SQS_RESOURCE.sendMessage,
51
+ SQS_RESOURCE.receiveMessage,
52
+ SQS_RESOURCE.deleteMessage,
53
+ SQS_RESOURCE.getQueueAttributes
54
+ ]
55
+ },
56
+ [
57
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType),
58
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType + "DLQ")
59
+ ]
60
+ ),
61
+ createIamRole(
62
+ {
63
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
64
+ },
65
+ [
66
+ resourceNames(RESOURCE_CLASSES.sns, "In" + functionName)
67
+ ]
68
+ )
69
+ )
70
+ return {
71
+ templatePath: templatePath,
72
+ templateData: {
73
+ functionName,
74
+ handlerType,
75
+ additionalResourcePermission,
76
+ resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
77
+ },
78
+ setting: {
79
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
80
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
81
+ isAppend: true,
82
+ fileExtension: ".yml"
83
+ }
84
+ }
85
+ }
86
+
87
+ module.exports = data
@@ -0,0 +1,30 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
8
+ batchSize: 10
9
+ iamRoleStatements:
10
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
11
+ - Effect: <%- resourcePermission.effect %>
12
+ Action:
13
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
14
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
15
+ - <%- resourcePerAction %>:<%- permission %>
16
+ <%_}) _%>
17
+ <%_ }) _%>
18
+ Resource:
19
+ <%_ resourcePermission.resource.forEach(resource => { _%>
20
+ - <%- resource %>
21
+ <%_ }) _%>
22
+ <%_}) _%>
23
+ #<#<%- functionName %><%- handlerType %>IamRole#>
24
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
25
+ <%_ function firstLetterUpperCase(text){
26
+ return text.charAt(0).toUpperCase() + text.slice(1)
27
+ } _%>
28
+ <%_ function firstLetterLowerCase(str) {
29
+ return str.charAt(0).toLowerCase() + str.slice(1)
30
+ } _%>
@@ -0,0 +1,112 @@
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 path = require("path")
21
+
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../../MainLibs/src/Utils');
23
+ const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, S3_RESOURCE, resourceNames, DYNAMO_RESOURCE, SQS_RESOURCE, SNS_RESOURCE, shortNameHandler, FUNCTION_NAME, LAMBDA_RESOURCE } = require("../../../../../libs/Consts");
24
+ const templatePath = path.join(__dirname, "./template.ejs")
25
+
26
+ function data(_izContext, flowSchema, srcPath) {
27
+ return [createSourceParam(_izContext, flowSchema, srcPath)]
28
+ }
29
+
30
+ function createSourceParam(_izContext, flowSchema, srcPath) {
31
+ let functionName = upperCase(FUNCTION_NAME.processAfterUploadS3);
32
+ let handlerType = "HdrS3";
33
+ let additionalResourcePermission = defaultIamRolePerAction();
34
+ let bucketName = flowSchema.bucketName
35
+ additionalResourcePermission.push(
36
+ createIamRole(
37
+ {
38
+ [RESOURCE_CLASSES.s3]: [
39
+ S3_RESOURCE.getObject,
40
+ S3_RESOURCE.getObjectTagging,
41
+ S3_RESOURCE.putObject,
42
+ S3_RESOURCE.putObjectTagging,
43
+ S3_RESOURCE.deleteObject,
44
+ S3_RESOURCE.deleteObjectTagging
45
+ ]
46
+ },
47
+ [
48
+ resourceNames(RESOURCE_CLASSES.s3, bucketName),
49
+ resourceNames(RESOURCE_CLASSES.s3, bucketName + "/*")
50
+ ]
51
+ ),
52
+ createIamRole(
53
+ {
54
+ [RESOURCE_CLASSES.sqs]: [
55
+ SQS_RESOURCE.sendMessage,
56
+ SQS_RESOURCE.receiveMessage,
57
+ SQS_RESOURCE.deleteMessage,
58
+ SQS_RESOURCE.getQueueAttributes
59
+ ]
60
+ },
61
+ [
62
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType),
63
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType + "DLQ")
64
+ ]
65
+ ),
66
+ createIamRole(
67
+ {
68
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
69
+ },
70
+ [
71
+ resourceNames(RESOURCE_CLASSES.sns, "In" + functionName)
72
+ ]
73
+ ),
74
+ createIamRole(
75
+ {
76
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish],
77
+ [RESOURCE_CLASSES.lambda]: [LAMBDA_RESOURCE.invokeFunction]
78
+ },
79
+ [
80
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainUpdate"),
81
+ resourceNames(RESOURCE_CLASSES.lambda, "ImportBatchMainGetHdrInv")
82
+ ]
83
+ ),
84
+ createIamRole(
85
+ {
86
+ [RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.getItem]
87
+ },
88
+ [
89
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "ReservedDataMain")
90
+ ]
91
+ )
92
+ )
93
+ return {
94
+ templatePath: templatePath,
95
+ templateData: {
96
+ functionName,
97
+ handlerType,
98
+ additionalResourcePermission,
99
+ resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
100
+ bucketName,
101
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType))
102
+ },
103
+ setting: {
104
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
105
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
106
+ isAppend: true,
107
+ fileExtension: ".yml"
108
+ }
109
+ }
110
+ }
111
+
112
+ module.exports = data
@@ -0,0 +1,38 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
8
+ batchSize: 10
9
+ - s3:
10
+ bucket: <%- bucketName %>
11
+ event: s3:ObjectCreated:*
12
+ existing: true
13
+ # rules:
14
+ # - prefix: uploads/
15
+ # - suffix: .csv
16
+ forceDeploy: true
17
+ iamRoleStatements:
18
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
19
+ - Effect: <%- resourcePermission.effect %>
20
+ Action:
21
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
22
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
23
+ - <%- resourcePerAction %>:<%- permission %>
24
+ <%_}) _%>
25
+ <%_ }) _%>
26
+ Resource:
27
+ <%_ resourcePermission.resource.forEach(resource => { _%>
28
+ - <%- resource %>
29
+ <%_ }) _%>
30
+ <%_}) _%>
31
+ #<#<%- functionName %><%- handlerType %>IamRole#>
32
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
33
+ <%_ function firstLetterUpperCase(text){
34
+ return text.charAt(0).toUpperCase() + text.slice(1)
35
+ } _%>
36
+ <%_ function firstLetterLowerCase(str) {
37
+ return str.charAt(0).toLowerCase() + str.slice(1)
38
+ } _%>