@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,126 @@
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({ 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 reservedLimitComplete = require('./ReservedLimitComplete_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
+ // set schema for record.body.MessageAttributes
57
+ // const messageAttributeValidatorSchema = {
58
+ // type: "object",
59
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
60
+ // properties: {
61
+ // msgAtrrParam1: {
62
+ // type: "string"
63
+ // },
64
+ // msgAtrrParam2: {
65
+ // type: "object"
66
+ // }
67
+ // }
68
+ // };
69
+
70
+ perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema)
71
+
72
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
73
+
74
+ try {
75
+
76
+ let recordPromises = [];
77
+
78
+ // loop each record and send to mainFunction
79
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
80
+
81
+ let passOnProperties = []
82
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
83
+
84
+ // validate message (and MessageAttributes)
85
+ await recordHandlerSharedLib.validateRecord(
86
+ record, // one record will send to mainFunction
87
+ "ReservedLimitCompleteHdrSqs", // queue name that need to retry or send to dlq
88
+ perRecordsValidatorSchema, // schema for record.Message
89
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
90
+ );
91
+
92
+ // add argument (to invoke lambda) to passOnProperties[]
93
+ passOnProperties.push(record.body.Message.returnMessage)
94
+ passOnProperties.push(record.body.Message.errorsFound)
95
+ passOnProperties.push(record.body.Message.passStatus)
96
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message))
97
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
98
+
99
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
100
+ let recordPromise = recordHandlerSharedLib.recordHandler(
101
+ record, // one record will send to mainFunction
102
+ reservedLimitComplete.reservedLimitComplete, // mainFunction that need to invoke.
103
+ "ReservedLimitCompleteHdrSqs", // queue name that need to retry or send to dlq
104
+ passOnProperties, // all parameters that mainFunction needed.
105
+ );
106
+ record._izContext.logger.debug('after recordPromise in handler');
107
+ recordPromises.push(recordPromise); // push promise to recordPromises
108
+ }))
109
+
110
+ Logger.debug('before Promise.all(recordPromises) in handler');
111
+ try {
112
+ // --- main await all promises
113
+ await Promise.all(recordPromises); // await all promises
114
+
115
+ return event.Records // return all for local test
116
+
117
+ } catch {
118
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
119
+ }
120
+ Logger.debug('after Promise.all(recordPromises) in handler');
121
+
122
+ } catch (err) {
123
+ Logger.error('Unhandled Error, ReservedImageLimitCompleteHdrSqs: ', err);
124
+ throw (err);
125
+ }
126
+ });
@@ -0,0 +1,54 @@
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 templatePath = path.join(__dirname, "./template.ejs")
23
+
24
+ const { SOURCE_PATH } = require("../../../../../libs/Consts");
25
+
26
+ /**
27
+ * receive objectSchema
28
+ *
29
+ * @param {Object} flowSchema
30
+ * @return {{ templatePath, templateData, setting } }
31
+ */
32
+
33
+ function data(_izContext, flowSchema, srcPath) {
34
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
35
+ }
36
+
37
+ function createSourceParams(_izContext, flowSchema, srcPath) {
38
+ let functionName = "ReservedLimitComplete"
39
+ let bucketName = flowSchema.bucketName
40
+ return {
41
+ templatePath: templatePath,
42
+ templateData: {
43
+ bucketName
44
+ },
45
+ setting: {
46
+ saveFileName: `${functionName}_Main`,
47
+ savePath: path.join(srcPath, SOURCE_PATH.webSocket),
48
+ fileExtension: ".js",
49
+ isAppend: false
50
+ }
51
+ }
52
+ }
53
+
54
+ module.exports = data
@@ -0,0 +1,254 @@
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 izaraShared = require('@izara_project/izara-shared');
21
+ const asyncFlowSharedLib = izaraShared.asyncFlowSharedLib;
22
+ const snsSharedLib = izaraShared.snsSharedLib;
23
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
24
+ const lambdaSharedLib = izaraShared.lambdaSharedLib;
25
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
26
+
27
+ const externalRequest = require('@izara_project/izara-core-library-external-request')
28
+ const lambda = externalRequest.lambda;
29
+ const sns = externalRequest.sns;
30
+
31
+ const { S3Client } = require('@aws-sdk/client-s3');
32
+ const client = new S3Client({ region: 'us-east-2' });
33
+ const { createPresignedPost } = require('@aws-sdk/s3-presigned-post');
34
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
35
+
36
+ const { postToConnection } = require("../../libs/source/ImportDataLib");
37
+ const hash = require('object-hash');
38
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils');
39
+ const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
40
+ const { getNestObject } = require("../../libs/source/ImportDataLib");
41
+ const { EXTERNAL_SERVICE_NAME } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
42
+ /**
43
+ * description of function.
44
+ * @param {Object} _izContext
45
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
46
+ * @param {Logger} _izContext.logger - property of _izContext
47
+ * @param {Logger} _izContext.logger - property of _izContext
48
+ * @param {Object} returnMessage - limitValue or limitFound
49
+ * @param {Array} errorsFound - array
50
+ * @param {boolean} passStatus - true || false
51
+ * @param {Object} passBackProperties - identifier
52
+ *
53
+ * @returns {object} returnResponse
54
+ */
55
+
56
+ module.exports.reservedLimitComplete = async (
57
+ _izContext,
58
+ returnMessage,
59
+ errorsFound,
60
+ passStatus,
61
+ passBackProperties
62
+ ) => {
63
+
64
+ try {
65
+
66
+ _izContext.logger.debug('----- ReservedLimitComplete event params -----', {
67
+ returnMessage: returnMessage,
68
+ errorsFound: errorsFound,
69
+ passStatus: passStatus,
70
+ passBackProperties: passBackProperties
71
+ });
72
+
73
+ const servicePendingId = passBackProperties.passBackProperties.identifier.servicePendingId; // importBatchId
74
+ const reservedDataId = passBackProperties.passBackProperties.identifier.reservedDataId;
75
+ const objType = passBackProperties.passBackProperties.objType
76
+
77
+ const correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID)
78
+ const connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
79
+
80
+ // getImportBatchMain from table
81
+ let importBatchMain = await lambda.invokeSync(_izContext,
82
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "ImportBatchMainGetHdrInv"),
83
+ {
84
+ identifiers: {
85
+ importBatchId: servicePendingId
86
+ }
87
+ }
88
+ )
89
+ _izContext.logger.debug("importBatchMain", importBatchMain);
90
+
91
+ const {
92
+ importBatchId
93
+ } = importBatchMain.identifiers
94
+
95
+ const {
96
+ importBatchStatus,
97
+ importConfigId,
98
+ fileName,
99
+ fileSize,
100
+ importType,
101
+ startTime,
102
+ submittedByUserId,
103
+ userId
104
+ } = importBatchMain.fields
105
+
106
+ let uniqueIdentify = getNestObject(
107
+ _izContext,
108
+ returnMessage,
109
+ ['limitFound', 'runningTotal', 'uniqueIdentify', 'usedTimestampId']
110
+ );
111
+ _izContext.logger.debug("uniqueIdentify", uniqueIdentify);
112
+
113
+ await dynamodbSharedLib.putItem(_izContext,
114
+ await dynamodbSharedLib.tableName(_izContext, "ReservedDataMain"),
115
+ {
116
+ servicePendingId: importBatchId, // importBatchId
117
+ reservedDataId: reservedDataId,
118
+ reservedValue: fileSize,
119
+ uniqueIdentify: uniqueIdentify
120
+ }
121
+ );
122
+
123
+ if (passStatus === false) { // if passStatus false post message to client
124
+ // use correlationId to get connectionId and use connectionId to post message to client
125
+
126
+ _izContext.logger.debug("reserved has reach limit");
127
+
128
+ errorsFound.push("reserved has reach limit")
129
+ // update importBatchMainTable
130
+ let updateImportBatchMainMsg = {
131
+ objInstanceFull: {
132
+ identifiers: {
133
+ importBatchId: importBatchId
134
+ },
135
+ fields: {
136
+ importBatchStatus: "error",
137
+ errorsFound: errorsFound
138
+ }
139
+ }
140
+ }
141
+
142
+ let sendMessageToUpdateImportBatch = {
143
+ Message: JSON.stringify(updateImportBatchMainMsg),
144
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`)
145
+ }
146
+ _izContext.logger.debug("sendMessageToUpdateImportBatch", sendMessageToUpdateImportBatch);
147
+
148
+ // cancel reserved
149
+
150
+
151
+ let cancelReservedMsg = {
152
+ userId: userId,
153
+ limitTag: returnMessage.limitTag,
154
+ uniqueIdentify: uniqueIdentify
155
+ };
156
+
157
+ let sendMessageToCancelReserved = {
158
+ Message: JSON.stringify(cancelReservedMsg),
159
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InCancelUsage', EXTERNAL_SERVICE_NAME.accountLimits)
160
+ };
161
+
162
+ _izContext.logger.debug("sendMessageToCancelReserved", sendMessageToCancelReserved);
163
+ await sns.publishAsync(_izContext, sendMessageToCancelReserved);
164
+
165
+ await postToConnection({ message: "reserved has reach limit" }, connectionId)
166
+ // after post message delete websocket task
167
+ await dynamodbSharedLib.deleteItem(_izContext,
168
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
169
+ {
170
+ taskKey: correlationId,
171
+ connectionId: connectionId
172
+ }
173
+ )
174
+ }
175
+
176
+ // store reservedDataId and servicePendingId in ReservedDataMain
177
+
178
+
179
+ const Key = `${fileName}.${importType}`
180
+
181
+ const maximumSize = fileSize * 1048576 // convert to byte unit for restrict
182
+ _izContext.logger.debug("maximumSize", maximumSize);
183
+
184
+ // create PresignUrl
185
+ let createPresignUrlParam = {
186
+ Bucket: "<%- bucketName %>",
187
+ Key: Key,
188
+ Conditions: [
189
+ ["content-length-range", 0, maximumSize],
190
+ ["starts-with", "$Content-Type", "file/csv"],
191
+ ["eq", "$x-amz-meta-importBatchId", importBatchId]
192
+ ],
193
+ fields: {},
194
+ expires: 86400
195
+ };
196
+ _izContext.logger.debug('createPresignUrlParam', createPresignUrlParam);
197
+
198
+ const uploadUrl = await createPresignedPost(client, createPresignUrlParam);
199
+
200
+ uploadUrl.fields['x-amz-meta-importBatchId'] = importBatchId;
201
+ uploadUrl.fields['Content-Type'] = `file/${importType}`;
202
+
203
+ _izContext.logger.debug('uploadUrlLimitSize: ', uploadUrl) // return as object type = {url, fields}
204
+
205
+ // update to waiting to upload
206
+ if (importBatchStatus === "processing") {
207
+
208
+ let updateImportBatchMainMsg = {
209
+ objInstanceFull: {
210
+ identifiers: {
211
+ importBatchId: importBatchId
212
+ },
213
+ fields: {
214
+ importBatchStatus: "waitingToUpload",
215
+ expiryTimestamp: (startTime + (createPresignUrlParam.expires * 1000))
216
+ }
217
+ }
218
+ }
219
+
220
+ updateImportBatchMainMsg = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
221
+ updateImportBatchMainMsg,
222
+ callingFlowSharedLib.addParentCallingFlowConfig(
223
+ returnMessage, // resive parent callingFlowConfig.
224
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
225
+ await lambdaSharedLib.lambdaFunctionName(_izContext, `WebSocketTaskComplete`), {}
226
+ )
227
+ )
228
+ );
229
+
230
+ _izContext.logger.debug("after add callingFlow", updateImportBatchMainMsg)
231
+
232
+ let sendMessageToUpdateImportBatch = {
233
+ Message: JSON.stringify(updateImportBatchMainMsg),
234
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, `In${objType.objectType}Update`)
235
+ }
236
+ _izContext.logger.debug("sendMessageToUpdateImportBatch", sendMessageToUpdateImportBatch);
237
+ await sns.publishAsync(_izContext, sendMessageToUpdateImportBatch);
238
+
239
+ await dynamodbSharedLib.updateItem(_izContext,
240
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
241
+ {
242
+ taskKey: correlationId,
243
+ connectionId: connectionId
244
+ },
245
+ {
246
+ uploadUrl: uploadUrl
247
+ }
248
+ )
249
+ }
250
+ } catch (err) {
251
+ _izContext.logger.error('error ReservedImageLimitComplete: ', err)
252
+ throw (err)
253
+ }
254
+ }
@@ -0,0 +1,64 @@
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 path = require("path")
21
+
22
+ const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../../libs/Consts');
23
+ const { TOPIC_NAME_GENERATE_CODE } = require("../../../../../../../GenerateCodeLibs/src/Consts");
24
+
25
+ const templatePath = path.join(__dirname, './template.ejs');
26
+
27
+
28
+ /**
29
+ * create data for dynamoDbYaml tempalte from objectSchema
30
+ * return array of dynamoDb data
31
+ * because one objectSchema can create multiple dynamoDb table
32
+ *
33
+ * @param {Object} _izContext
34
+ * @param {Object} objectSchema
35
+ * @returns {Object[]} - data of multiple dynamoDb template
36
+ */
37
+
38
+ function data(_izContext, srcPath) {
39
+ let resultForCreateSqs = [];
40
+ const WebSocketSqsQueueNames = [];
41
+ const setting = {
42
+ initialData: "Resources:\n",
43
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
44
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
45
+ fileExtension: ".yml",
46
+ isAppend: true
47
+ }
48
+
49
+ WebSocketSqsQueueNames.push(
50
+ {
51
+ queueName: TOPIC_NAME_GENERATE_CODE.reservedLimitComplete
52
+ }
53
+ )
54
+
55
+ for (let WebSocketSqsQueueName of WebSocketSqsQueueNames) {
56
+ resultForCreateSqs.push(({
57
+ templatePath: templatePath,
58
+ templateData: WebSocketSqsQueueName,
59
+ setting: setting
60
+ }))
61
+ }
62
+ return resultForCreateSqs
63
+ }
64
+ module.exports = data;
@@ -0,0 +1,45 @@
1
+ ##===== [Queue]
2
+ <%- queueName %>HdrSqs:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
6
+ RedrivePolicy:
7
+ deadLetterTargetArn:
8
+ # !GetAtt
9
+ Fn::GetAtt:
10
+ - <%- queueName %>HdrSqsDLQ
11
+ - Arn
12
+ maxReceiveCount: 3
13
+ VisibilityTimeout: 120
14
+ ##==== [QueueDLQ]
15
+ <%- queueName %>HdrSqsDLQ:
16
+ Type: AWS::SQS::Queue
17
+ Properties:
18
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
19
+ ##==== [QueuePolicy]
20
+ <%- queueName %>HdrSqsPolicy:
21
+ Type: AWS::SQS::QueuePolicy
22
+ Properties:
23
+ PolicyDocument:
24
+ Version: "2012-10-17"
25
+ Statement:
26
+ - Sid: "allow-sns-messages"
27
+ Effect: Allow
28
+ Principal: "*"
29
+ Resource:
30
+ # !GetAtt
31
+ Fn::GetAtt:
32
+ - <%- queueName %>HdrSqs
33
+ - Arn
34
+ Action: "SQS:SendMessage"
35
+ Queues:
36
+ - Ref: <%- queueName %>HdrSqs
37
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
38
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
39
+
40
+ <%_ function firstLetterUpperCase(text){
41
+ return text.charAt(0).toUpperCase() + text.slice(1)
42
+ } _%>
43
+ <%_ function firstLetterLowerCase(str) {
44
+ return str.charAt(0).toLowerCase() + str.slice(1)
45
+ } _%>
@@ -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.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.generatedCodeWebSocketHook),
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.generatedCodeWebSocketHook),
86
+ saveFileName: `${upperCase(hookFunctionName)}_${upperCase(handlerType)}`,
87
+ fileExtension: ".js",
88
+ isAppend: false
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ module.exports = data;