@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,107 @@
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 izara = require("@izara_project/izara-middleware");
21
+ const middleware = izara.middlewareHandler;
22
+ // const AWS = require('aws-sdk');
23
+ // const api = new AWS.ApiGatewayManagementApi({ endpoint: process.env.iz_webSocketEndpoint });
24
+ const izaraShared = require('@izara_project/izara-shared')
25
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib
26
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
27
+ const hash = require('object-hash')
28
+ // const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
29
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
30
+ const { postToConnection } = require("../../libs/source/ImportDataLib");
31
+ <% if (hook) { _%>
32
+ const <%- hookFunctionName %> = required("<% hookFunctionName _%>_Main ")
33
+ <% } else { _%>
34
+ const createObject = require('./CreateObjectS3_Main');
35
+ <% } _%>
36
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
37
+
38
+ event._izContext.logger.debug('Event:', event);
39
+
40
+ try {
41
+
42
+ if (event.requestContext) {
43
+ const route = event.requestContext.routeKey;
44
+ const connectionId = event.requestContext.connectionId;
45
+ let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
46
+
47
+ switch (route) {
48
+ case "$connect":
49
+ console.log("webSocket Connect");
50
+ break
51
+ case "$disconnect":
52
+ console.log("webSocket Disconnect");
53
+ break
54
+ case '$default':
55
+ console.log('Received unknown route:', route);
56
+ break
57
+ case 'webSocket':
58
+ console.log("event in route webSocket", event);
59
+ let eventParams = JSON.parse(event.body)
60
+
61
+ await dynamodbSharedLib.putItem(
62
+ event._izContext,
63
+ await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
64
+ {
65
+ taskKey: correlationId,
66
+ connectionId: connectionId,
67
+ }
68
+ )
69
+
70
+ let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
71
+ <% if (hook) { _%>
72
+ await <%- hookFunctionName %>.<%- hookFunctionName %>(
73
+ event._izContext,
74
+ eventParams,
75
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
76
+ //(<additionalParams>)
77
+ //(</additionalParams>)
78
+ )
79
+ <% } else { _%>
80
+ await createObject.createObject(
81
+ event._izContext,
82
+ eventParams,
83
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
84
+ //(<additionalParams>)
85
+ //(</additionalParams>)
86
+ )
87
+ <% } _%>
88
+
89
+ break
90
+ }
91
+ } else {
92
+ const connId = event.connId;
93
+ // await postMessage({ message: event.message }, connId);
94
+ await postToConnection({ message: event.message }, connId);
95
+ }
96
+
97
+ return (izara.response.webSocketSuccess());
98
+
99
+ } catch (err) {
100
+ const connId = event.requestContext.connectionId
101
+ event._izContext.logger.error('Error, WebSocket: ', err);
102
+ // await sendErrorMessage({ message: err.message }, connId);
103
+ await postToConnection({ message: err.message }, connId);
104
+ return (izara.response.failure(err));
105
+ }
106
+ });
107
+ <%_ const join = require('path').join _%>
@@ -19,12 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  const path = require('path');
20
20
  const fs = require('fs');
21
21
 
22
- const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
-
24
- const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
- const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../libs/Consts");
26
-
27
- const templatePath = path.join(__dirname, "template.ejs")
22
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../libs/Consts");
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
24
+ const templatePath = path.join(__dirname, "template.ejs");
25
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
28
26
 
29
27
  /**
30
28
  * receive objectSchema
@@ -35,22 +33,20 @@ const templatePath = path.join(__dirname, "template.ejs")
35
33
  */
36
34
 
37
35
 
38
- function data(_izContext, srcPath) {
39
-
40
- return [createParamsForCreateSource(_izContext, srcPath)]
41
-
42
-
36
+ async function data(_izContext, flowSchema, srcPath) {
37
+ return [await createParamsForCreateSource(_izContext, flowSchema, srcPath)]
43
38
  }
44
39
 
45
- function createParamsForCreateSource(_izContext, srcPath) {
46
- let functionName = "FlowSchema"
47
- let handlerType = "HdrWbs"
40
+ async function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
41
+ let functionName = upperCase(FUNCTION_NAME.createObjectS3)
42
+ // let objectSchema = await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(_izContext, flowSchema.objType)
43
+ // let fieldNames = Object.keys(objectSchema.fieldNames)
48
44
  return {
49
45
  templatePath: templatePath,
50
46
  templateData: {},
51
47
  setting: {
52
48
  savePath: path.join(srcPath, SOURCE_PATH.webSocket),
53
- saveFileName: `${functionName}_${handlerType}`,
49
+ saveFileName: `${functionName}_Main`,
54
50
  fileExtension: ".js",
55
51
  isAppend: false
56
52
  }
@@ -51,7 +51,7 @@ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-librar
51
51
  * @returns {object} description of return value
52
52
  */
53
53
 
54
- module.exports.flowSchema = async (
54
+ module.exports.createObject = async (
55
55
  _izContext,
56
56
  requestParams,
57
57
  callingFlowConfig = {},
@@ -65,7 +65,7 @@ module.exports.flowSchema = async (
65
65
  _izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
66
66
 
67
67
  _izContext.correlationIds.set(coreConsts.BASE_USER_ID, "BasDev");
68
- _izContext.correlationIds.set(coreConsts.RESOURCE_USE_USER_ID, "BasDevTarget");
68
+ _izContext.correlationIds.set(coreConsts.TARGET_ID, "BasDevTarget");
69
69
 
70
70
  let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
71
71
  flowTag: requestParams.flowTag,
@@ -97,11 +97,11 @@ module.exports.flowSchema = async (
97
97
  fieldNames: {
98
98
  userId: _izContext.correlationIds.get(coreConsts.BASE_USER_ID),
99
99
  // userId: "mockUserId",
100
- submittedByUserId: _izContext.correlationIds.get(coreConsts.RESOURCE_USE_USER_ID),
100
+ submittedByUserId: _izContext.correlationIds.get(coreConsts.TARGET_ID),
101
101
  // submittedByUserId: "mockSubmittedByUserId",
102
102
  startTime: Date.now(),
103
103
  importConfigId: requestParams.importConfigId,
104
- importBatchStatus: "process",
104
+ importBatchStatus: "processing",
105
105
  importType: requestParams.importType,
106
106
  fileName: requestParams.fileName,
107
107
  fileSize: requestParams.fileSize
@@ -23,7 +23,7 @@ const templatePath = path.join(__dirname, "./template.ejs")
23
23
 
24
24
  const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
25
25
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
26
- const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, defaultIamRolePerAction, DYNAMO_RESOURCE } = require("../../../../libs/Consts");
26
+ const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, defaultIamRolePerAction, DYNAMO_RESOURCE, SHORT_FUNCTION_NAME } = require("../../../../libs/Consts");
27
27
 
28
28
 
29
29
  /**
@@ -38,7 +38,7 @@ function data(_izContext, srcPath) {
38
38
  }
39
39
 
40
40
  function createSourceParams(_izContext, srcPath) {
41
- let functionName = "WebSocketTaskComplete";
41
+ let functionName = upperCase(FUNCTION_NAME.createObjectS3Complete);
42
42
  let handlerType = upperCase(HANDLER.hdrSqs);
43
43
  let additionalResourcePermission = defaultIamRolePerAction();
44
44
 
@@ -62,6 +62,7 @@ function createSourceParams(_izContext, srcPath) {
62
62
  [RESOURCE_CLASSES.dynamoDbTable]: [
63
63
  DYNAMO_RESOURCE.query,
64
64
  DYNAMO_RESOURCE.deleteItem,
65
+ DYNAMO_RESOURCE.getItem
65
66
  ]
66
67
  },
67
68
  [
@@ -86,11 +87,12 @@ function createSourceParams(_izContext, srcPath) {
86
87
  resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
87
88
  functionName: functionName,
88
89
  handlerType: handlerType,
89
- additionalResourcePermission: additionalResourcePermission
90
+ additionalResourcePermission: additionalResourcePermission,
91
+ functionNameConfig: upperCase(SHORT_FUNCTION_NAME.createObjectS3Complete) + upperCase(shortNameHandler(handlerType)),
90
92
  },
91
93
  setting: {
92
94
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
93
- saveFileName: SAVE_FILE_NAME.flowSchema,
95
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
94
96
  fileExtension: ".yml",
95
97
  isAppend: true
96
98
  }
@@ -0,0 +1,30 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- 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 %><%- firstLetterUpperCase(handlerType) %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
+ iamRoleStatements:
13
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
14
+ - Effect: <%- resourcePermission.effect %>
15
+ Action:
16
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
17
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
18
+ - <%- resourcePerAction %>:<%- permission %>
19
+ <%_ }) _%>
20
+ <%_ }) _%>
21
+ Resource:
22
+ <%_ resourcePermission.resource.forEach(resource => { _%>
23
+ - "<%- resource %>"
24
+ <%_ }) _%>
25
+ <%_}) _%>
26
+ #<#<%- functionName %><%- handlerType %>IamRole#>
27
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
28
+ <%_ function firstLetterUpperCase(text){
29
+ return text.charAt(0).toUpperCase() + text.slice(1)
30
+ } _%>
@@ -38,7 +38,7 @@ function data(_izContext, srcPath) {
38
38
  }
39
39
 
40
40
  function createSourceParams(_izContext, srcPath) {
41
- let functionName = "WebSocketTaskComplete"
41
+ let functionName = upperCase(FUNCTION_NAME.createObjectS3Complete)
42
42
  let handlerType = upperCase(HANDLER.hdrSqs)
43
43
  return {
44
44
  templatePath: templatePath,
@@ -62,25 +62,25 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
62
62
 
63
63
  //validate message (and MessageAttributes)
64
64
  await recordHandlerSharedLib.validateRecord(
65
- record, // one record will send to mainFunction
66
- "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
67
- perRecordsValidatorSchema, // schema for record.Message
65
+ record, // one record will send to mainFunction
66
+ "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
67
+ perRecordsValidatorSchema, // schema for record.Message
68
68
  // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
69
69
  );
70
70
 
71
71
  // add argument (to invoke lambda) to passOnProperties[]
72
72
  // passOnProperties.push(record.body.Message.MessageAttributes)
73
- passOnProperties.push(record.body.Message)
73
+ passOnProperties.push(record.body.Message.objType)
74
+ passOnProperties.push(record.body.Message.updateItem)
74
75
  // passOnProperties.push(record.body.Message.route)
75
- passOnProperties.push(record.body.TopicArn)
76
76
  Logger.debug('passOnProperties in handler', passOnProperties);
77
77
 
78
78
  // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
79
79
  let recordPromise = recordHandlerSharedLib.recordHandler(
80
- record, // one record will send to mainFunction
81
- webSocketTaskComplete.webSocketTaskComplete, // mainFunction that need to invoke.
82
- "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
83
- passOnProperties, // all parameters that mainFunction needed.
80
+ record, // one record will send to mainFunction
81
+ webSocketTaskComplete.webSocketTaskComplete, // mainFunction that need to invoke.
82
+ "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
83
+ passOnProperties, // all parameters that mainFunction needed.
84
84
  );
85
85
  record._izContext.logger.debug('after recordPromise in handler');
86
86
  recordPromises.push(recordPromise); // push promise to recordPromises
@@ -100,4 +100,4 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
100
100
  Logger.error('Unhandled Error, WebSocketTaskCompleteHdrSqs: ', err);
101
101
  throw (err);
102
102
  }
103
- });
103
+ });
@@ -21,9 +21,8 @@ const path = require('path');
21
21
 
22
22
  const templatePath = path.join(__dirname, "./template.ejs")
23
23
 
24
- const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
25
- const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
26
- const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, defaultIamRolePerAction, DYNAMO_RESOURCE } = require("../../../../libs/Consts");
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../libs/Consts");
25
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
27
26
 
28
27
 
29
28
  /**
@@ -38,7 +37,7 @@ function data(_izContext, srcPath) {
38
37
  }
39
38
 
40
39
  function createSourceParams(_izContext, srcPath) {
41
- let functionName = "WebSocketTaskComplete"
40
+ let functionName = upperCase(FUNCTION_NAME.createObjectS3Complete)
42
41
  return {
43
42
  templatePath: templatePath,
44
43
  templateData: {
@@ -0,0 +1,86 @@
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
+ 'use strict';
18
+ const { NoRetryError } = require('@izara_project/izara-core-library-core');
19
+ const izaraShared = require('@izara_project/izara-shared');
20
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
21
+ const snsSharedLib = izaraShared.snsSharedLib;
22
+ const asyncFlowSharedLib = izaraShared.asyncFlowSharedLib;
23
+ let coreConsts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
24
+
25
+ const { postToConnection } = require('../../libs/source/ImportDataLib')
26
+ module.exports.webSocketTaskComplete = async (
27
+ _izContext,
28
+ objType,
29
+ updateItem
30
+ ) => {
31
+ try {
32
+ _izContext.logger.debug("requestParams", {
33
+ objType,
34
+ updateItem
35
+ })
36
+
37
+ let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
38
+ let correlationId = _izContext.correlationIds.get(coreConsts.X_CORRELATION_ID);
39
+
40
+ if (updateItem.importBatchStatus === "waitingToUpload") {
41
+ // get upload url
42
+ let webSocketTask = await dynamodbSharedLib.getItem(_izContext,
43
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
44
+ {
45
+ taskKey: correlationId,
46
+ connectionId: connectionId
47
+ }
48
+ )
49
+ _izContext.logger.debug("webSocketTask", webSocketTask);
50
+
51
+
52
+ _izContext.logger.debug("post message to client")
53
+ // post message to client
54
+ await postToConnection({
55
+ message: {
56
+ uploadUrl: webSocketTask.uploadUrl,
57
+ importBatchId: updateItem.importBatchId
58
+ }
59
+ }, connectionId)
60
+
61
+ await dynamodbSharedLib.deleteItem(_izContext,
62
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
63
+ {
64
+ taskKey: correlationId,
65
+ connectionId: connectionId
66
+ }
67
+ )
68
+ } else {
69
+ await postToConnection({
70
+ message: "status is processing can't upload file"
71
+ }, connectionId)
72
+ // delete webSocketTask
73
+ await dynamodbSharedLib.deleteItem(_izContext,
74
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
75
+ {
76
+ taskKey: correlationId,
77
+ connectionId: connectionId
78
+ }
79
+ )
80
+
81
+ }
82
+ } catch (err) {
83
+ _izContext.logger.error('error websocketTaskComplete: ', err)
84
+ throw (err);
85
+ }
86
+ };
@@ -26,7 +26,8 @@ const {
26
26
 
27
27
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
28
28
  const templatePath = path.join(__dirname, "template.ejs")
29
- const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require('../../../../libs/Consts')
29
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require('../../../../libs/Consts');
30
+ const { TOPIC_NAME_GENERATE_CODE } = require("../../../../../../GenerateCodeLibs/src/Consts");
30
31
 
31
32
 
32
33
  /**
@@ -53,7 +54,8 @@ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
53
54
 
54
55
  defaultSnsInSqsDataList.push(
55
56
  {
56
- queueName: upperCase("webSocketTaskComplete" + upperCase(HANDLER.hdrSqs))
57
+ queueName: upperCase(FUNCTION_NAME.createObjectS3Complete) + upperCase(HANDLER.hdrSqs),
58
+ subScription: upperCase(TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete)
57
59
  }
58
60
  )
59
61
 
@@ -0,0 +1,49 @@
1
+ Subscription<%- subScription-%>:
2
+ Type: AWS::SNS::Subscription
3
+ Properties:
4
+ TopicArn: !Ref <%- subScription %>
5
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
6
+ Protocol: "sqs"
7
+ #------- queue ---------
8
+ <%- queueName %>:
9
+ Type: "AWS::SQS::Queue"
10
+ Properties:
11
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
12
+ RedrivePolicy:
13
+ deadLetterTargetArn: #!GetAtt
14
+ Fn::GetAtt:
15
+ - <%- queueName %>DLQ
16
+ - Arn
17
+ maxReceiveCount: 3
18
+ VisibilityTimeout: 120
19
+
20
+ <%- queueName %>DLQ:
21
+ Type: AWS::SQS::Queue
22
+ Properties:
23
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
24
+
25
+ <%- queueName %>Policy:
26
+ Type: AWS::SQS::QueuePolicy
27
+ Properties:
28
+ PolicyDocument:
29
+ Version: "2012-10-17"
30
+ Statement:
31
+ - Sid: "allow-sns-messages"
32
+ Effect: Allow
33
+ Principal: "*"
34
+ Resource: #!GetAtt
35
+ Fn::GetAtt:
36
+ - <%- queueName %>
37
+ - Arn
38
+ Action: "SQS:SendMessage"
39
+ Queues:
40
+ - Ref: <%- queueName %>
41
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
42
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
43
+
44
+ <%_ function firstLetterUpperCase(text){
45
+ return text.charAt(0).toUpperCase() + text.slice(1)
46
+ } _%>
47
+ <%_ function firstLetterLowerCase(str) {
48
+ return str.charAt(0).toLowerCase() + str.slice(1)
49
+ } _%>
@@ -0,0 +1,85 @@
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 { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/src/Utils")
25
+ const { HANDLER, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SQS_RESOURCE, SNS_RESOURCE, resourceNames, shortNameHandler, SOURCE_PATH, SAVE_FILE_NAME, awaitingMultipleStepsRole, externalResourceSns, externalResourceName } = require('../../../../../libs/Consts');
26
+ const { TOPIC_NAME_GENERATE_CODE } = require('../../../../../../../GenerateCodeLibs/src/Consts');
27
+
28
+ /**
29
+ * receive objectSchema
30
+ *
31
+ * @param {Object} flowSchema
32
+ * @return {{ templatePath, templateData, setting } }
33
+ */
34
+
35
+ function data(_izContext, srcPath) {
36
+ return [createSourceParams(_izContext, srcPath)]
37
+ }
38
+
39
+ function createSourceParams(_izContext, srcPath) {
40
+ let functionName = "GetPresignUrl";
41
+ let handlerType = upperCase(HANDLER.hdrSqs);
42
+ let additionalResourcePermission = defaultIamRolePerAction();
43
+
44
+ additionalResourcePermission.push(
45
+ createIamRole(
46
+ {
47
+ [RESOURCE_CLASSES.sqs]: [
48
+ SQS_RESOURCE.receiveMessage,
49
+ SQS_RESOURCE.sendMessage,
50
+ SQS_RESOURCE.deleteMessage,
51
+ SQS_RESOURCE.getQueueAttributes
52
+ ],
53
+ [RESOURCE_CLASSES.sns]: [
54
+ SNS_RESOURCE.publish,
55
+ SNS_RESOURCE.subscribe
56
+ ]
57
+ },
58
+ [
59
+ resourceNames(RESOURCE_CLASSES.sqs, "GetPresignUrl" + handlerType),
60
+ resourceNames(RESOURCE_CLASSES.sqs, "GetPresignUrl" + "DLQ"),
61
+ resourceNames(RESOURCE_CLASSES.sns, TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
62
+ ]
63
+ )
64
+ )
65
+
66
+ return {
67
+ templatePath: templatePath,
68
+ templateData: {
69
+ functionName,
70
+ handlerType,
71
+ functionNameConfig: functionName + upperCase(handlerType),
72
+ resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
73
+ additionalResourcePermission,
74
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
75
+ },
76
+ setting: {
77
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
78
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
79
+ fileExtension: ".yml",
80
+ isAppend: true
81
+ }
82
+ }
83
+ }
84
+
85
+ module.exports = data
@@ -1,5 +1,5 @@
1
1
  <%_ const join = require('path').join; _%>
2
- <%- firstLetterUpperCase(functionName) %><%- handlerType -%>:
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
3
  handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
4
4
  name: ${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
5
5
  events:
@@ -0,0 +1,57 @@
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
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../../MainLibs/src/Utils")
24
+
25
+ const { HANDLER, SOURCE_PATH } = require('../../../../../libs/Consts');
26
+
27
+ /**
28
+ * receive objectSchema
29
+ *
30
+ * @param {Object} flowSchema
31
+ * @return {{ templatePath, templateData, setting } }
32
+ */
33
+
34
+ function data(_izContext, srcPath) {
35
+ return [createSourceParams(_izContext, srcPath)]
36
+ }
37
+
38
+ function createSourceParams(_izContext, srcPath) {
39
+ let functionName = "GetPresignUrl";
40
+ let handlerType = upperCase(HANDLER.hdrSqs);
41
+
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ handlerType,
47
+ },
48
+ setting: {
49
+ saveFileName: `${functionName}_${handlerType}`,
50
+ savePath: path.join(srcPath, SOURCE_PATH.webSocket),
51
+ fileExtension: ".js",
52
+ isAppend: true
53
+ }
54
+ }
55
+ }
56
+
57
+ module.exports = data