@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,137 @@
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 externalRequest = require('@izara_project/izara-core-library-external-request');
21
+ const lambda = externalRequest.lambda;
22
+
23
+ const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
24
+ const { inMemoryCacheLib } = require('@izara_project/izara-shared');
25
+ const hash = require("object-hash")
26
+ const csv = require('csv-parser');
27
+ const streamifier = require('streamifier');
28
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError;
29
+
30
+ const client = new ApiGatewayManagementApiClient({
31
+ endpoint: `https://${process.env.iz_webSocketEndpoint}`
32
+ })
33
+
34
+ async function postToConnection(message, connectionId) {
35
+ try {
36
+ const messageParams = JSON.stringify(message)
37
+ const command = new PostToConnectionCommand({
38
+ ConnectionId: connectionId,
39
+ Data: Buffer.from(messageParams)
40
+ })
41
+ // console.log("command::", command)
42
+ // console.log("client::", client)
43
+ await client.send(command);
44
+ console.log(`send Message: ${JSON.stringify(message)} to ${connectionId} 1`)
45
+ } catch (err) {
46
+ if (err.name === "GoneException") {
47
+ console.log(`message send to connectionIds ${connectionId} is no longer connect`)
48
+ } else {
49
+ console.error(`Error post message: ${err}`)
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ *
55
+ * @param {Object} _izContext
56
+ * @param {string} functionName
57
+ * @param {Object} payload
58
+ */
59
+ async function getDataFromInvokeFunction(_izContext, functionName, payload) {
60
+ return await lambda.invokeSync(_izContext, functionName, payload)
61
+ }
62
+
63
+ const getDataFromInvokeFunctionWithCache = inMemoryCacheLib.inMemoryCacheLib(
64
+ getDataFromInvokeFunction,
65
+ {
66
+ max: 100,
67
+ maxAge: 86400000,
68
+ promise: true,
69
+ profileName: "getDataFromInvokeFunction",
70
+ normalizer: function (args) {
71
+ return hash(args[1], args[2])
72
+ }
73
+ }
74
+ )
75
+
76
+ /**
77
+ *
78
+ * @param {Object} _izContext
79
+ * @param {Object} data - S3 data
80
+ * @returns
81
+ */
82
+ async function isValidCsv(_izContext, data) {
83
+ _izContext.logger.debug("function checkValidCsv", { data })
84
+ let errorCheckCsv = [];
85
+ let validCsv = true;
86
+ let rowCount = 0;
87
+ let columnCount = null;
88
+
89
+ streamifier.createReadStream(data.Body).pipe(csv()).on('data', (row) => {
90
+ rowCount++;
91
+ if (columnCount === null) {
92
+ columnCount = Object.keys(row).length
93
+ } else if (Object.keys(row).length !== columnCount) {
94
+ validCsv = false
95
+ errorCheckCsv.push(`Row ${rowCount} has inconsistent columns: ${JSON.stringify(row)}`)
96
+ }
97
+ })
98
+ .on('end', () => {
99
+ if (rowCount === 0) {
100
+ errorCheckCsv.push("csv file not have data row")
101
+ } else {
102
+ _izContext.logger.debug("validCsv")
103
+ }
104
+ })
105
+ .on('error', (error) => {
106
+ errorCheckCsv.push(`error:: ${error}`)
107
+ })
108
+
109
+ return [validCsv, errorCheckCsv]
110
+ }
111
+
112
+ /**
113
+ *
114
+ * @param {Object} _izContext
115
+ * @param {Object} nestedObj - source Object
116
+ * @param {String[]} paths - path to get value
117
+ */
118
+ function getNestObject(_izContext, nestedObj, paths) {
119
+ _izContext.logger.debug("function getNestObject", { nestedObj, paths });
120
+ let data;
121
+
122
+ if (typeof nestedObj === "object" && Array.isArray(paths)) {
123
+ data = paths.reduce((obj, key) => obj && typeof obj[key] !== 'undefined' ? obj[key] : undefined, nestedObj);
124
+ } else {
125
+ throw new NoRetryError("Type error: Invalid type in getNestObject")
126
+ }
127
+
128
+ return data;
129
+ }
130
+
131
+ module.exports = {
132
+ postToConnection,
133
+ getDataFromInvokeFunction,
134
+ getDataFromInvokeFunctionWithCache,
135
+ isValidCsv,
136
+ getNestObject
137
+ }
@@ -54,7 +54,7 @@ function resourceNames(resourceClass, resourceName) {
54
54
  [RESOURCE_CLASSES.s3]: "arn:aws:s3:::" + resourceName,
55
55
  [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${self:custom.iz_region}:${self:custom.iz_accountId}:table/${self:custom.iz_resourcePrefix}" + resourceName,
56
56
  [RESOURCE_CLASSES.sns]: "arn:aws:sns:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}" + resourceName,
57
- [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:" + resourceName,
57
+ [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:${self:custom.iz_resourcePrefix}" + resourceName,
58
58
  [RESOURCE_CLASSES.webSocket]: "arn:aws:execute-api:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_webSocketHostId}/Test/POST/@connections/{connectionId}"
59
59
  }[resourceClass];
60
60
  }
@@ -67,13 +67,24 @@ function resourceNames(resourceClass, resourceName) {
67
67
  * @returns {{ effect, action, resource}}
68
68
  */
69
69
  function createIamRole(action, resource = [], effect = "Allow") {
70
- for (const resourceAction in action) {
71
- if (typeof (action[resourceAction]) === 'string') {
72
- action[resourceAction] = [action[resourceAction]]
73
- }
70
+ if (Array.isArray(action)) {
71
+ const actionObj = {};
72
+ action.forEach(act => {
73
+ if (act.includes(":")) {
74
+ const [serviceAction, resourceAction] = act.split(":")
75
+ actionObj[serviceAction] = [resourceAction]
76
+ }
77
+ });
78
+ action = actionObj
79
+ } else {
80
+ for (const resourceAction in action) {
81
+ if (typeof (action[resourceAction]) === 'string') {
82
+ action[resourceAction] = [action[resourceAction]]
83
+ }
74
84
 
75
- if (!Array.isArray(action[resourceAction])) {
76
- throw new Error(`resourceAction:${resourceAction} should be string or array`);
85
+ if (!Array.isArray(action[resourceAction])) {
86
+ throw new Error(`resourceAction:${resourceAction} should be string or array`);
87
+ }
77
88
  }
78
89
  }
79
90
 
@@ -103,7 +114,9 @@ const SOURCE_PATH = {
103
114
  resourceLocationTranslateId: 'src/generatedCode/TranslateId/source/',
104
115
  resourceLocationProcessLogical: "src/generatedCode/ProcessLogical/source/",
105
116
  webSocket: "../src/generatedCode/WebSocket/source/",
106
- resourceLocationWebSocket: "src/generatedCode/WebSocket/source/"
117
+ resourceLocationWebSocket: "src/generatedCode/WebSocket/source/",
118
+ generateCodeLib: "../src/generatedCode/libs/source/",
119
+ webSocketHook: "../src/generatedCode/WebSocket/source/hookFunction/source/"
107
120
  };
108
121
 
109
122
 
@@ -124,7 +137,7 @@ const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
124
137
  dynamoDbPermission: 'DeleteItem',
125
138
  httpMethod: 'delete',
126
139
  }
127
- }
140
+ };
128
141
 
129
142
  const SQS_RESOURCE = {
130
143
  sendMessage: "SendMessage",
@@ -133,12 +146,12 @@ const SQS_RESOURCE = {
133
146
  getQueueAttributes: "GetQueueAttributes",
134
147
  deleteMessageBatch: "DeleteMessageBatch",
135
148
  getQueueUrl: "GetQueueUrl"
136
- }
149
+ };
137
150
 
138
151
  const SNS_RESOURCE = {
139
152
  publish: "Publish",
140
- subscription: "Subscription"
141
- }
153
+ subscribe: "Subscribe"
154
+ };
142
155
 
143
156
  const DYNAMO_RESOURCE = {
144
157
  putItem: "PutItem",
@@ -146,11 +159,21 @@ const DYNAMO_RESOURCE = {
146
159
  query: "Query",
147
160
  updateItem: "UpdateItem",
148
161
  deleteItem: "DeleteItem"
149
- }
162
+ };
150
163
 
151
164
  const LAMBDA_RESOURCE = {
152
165
  invokeFunction: "InvokeFunction"
153
- }
166
+ };
167
+
168
+ const S3_RESOURCE = {
169
+ getObject: "GetObject",
170
+ getObjectTagging: "GetObjectTagging",
171
+ deleteObject: "DeleteObject",
172
+ deleteObjectTagging: "DeleteObjectTagging",
173
+ putObject: "PutObject",
174
+ putObjectTagging: "PutObjectTagging",
175
+ };
176
+
154
177
  function externalResourceName(resourceClass, resourceName, serviceTag) {
155
178
  return {
156
179
  [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/${await dynamoSharedLib.tableName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
@@ -158,11 +181,11 @@ function externalResourceName(resourceClass, resourceName, serviceTag) {
158
181
  [RESOURCE_CLASSES.dynamoDbAcrossService]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/*" + `${resourceName}`,
159
182
  [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${await lambdaSharedLib.lambdaFunctionName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
160
183
  }[resourceClass]
161
- }
184
+ };
162
185
 
163
186
  function externalResourceSns(resourceName, serviceTag) {
164
187
  return "arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${await snsSharedLib.snsTopicName(_izContext, " + `"${resourceName}", "${serviceTag}")}`
165
- }
188
+ };
166
189
 
167
190
  const SAVE_FILE_NAME = {
168
191
  dynamoDbYaml: "generated-dynamoDB-table",
@@ -175,8 +198,9 @@ const SAVE_FILE_NAME = {
175
198
  translateId: "TranslateIdsRequest",
176
199
  findData: "findData",
177
200
  processLogicalYaml: "processLogical",
178
- flowSchema: "flowSchema"
179
- }
201
+ flowSchema: "flowSchema",
202
+ S3Bucket: "generated-s3-bucket"
203
+ };
180
204
 
181
205
  const FUNCTION_NAME = {
182
206
  updateRel: "updateRelationship",
@@ -195,8 +219,11 @@ const FUNCTION_NAME = {
195
219
  getNodeComplete: "getNodeComplete",
196
220
  paginateProcessLogical: "paginateProcessLogical",
197
221
  deleteNode: "deleteNode",
198
- deleteNodeComplete: "deleteNodeComplete"
199
- }
222
+ deleteNodeComplete: "deleteNodeComplete",
223
+ createObjectS3: "createObjectS3",
224
+ createObjectS3Complete: "webSocketTaskComplete",
225
+ processAfterUploadS3: "processAfterUploadS3"
226
+ };
200
227
 
201
228
  const SHORT_FUNCTION_NAME = {
202
229
  updateRel: "updateRel",
@@ -215,7 +242,8 @@ const SHORT_FUNCTION_NAME = {
215
242
  getNodeComplete: "getNodeComp",
216
243
  paginateProcessLogical: "paginateProLogical",
217
244
  deleteNode: "deleteNode",
218
- deleteNodeComplete: "deleteNodeComp"
245
+ deleteNodeComplete: "deleteNodeComp",
246
+ createObjectS3Complete: "webSocketTaskComp",
219
247
  }
220
248
 
221
249
  const getGraphServiceNameFromAllRelSchema = async (_izContext, allRelSchemas) => {
@@ -233,7 +261,7 @@ const getGraphServiceNameFromAllRelSchema = async (_izContext, allRelSchemas) =>
233
261
  }))
234
262
  const graphServiceName = [...graphServiceNameSet]
235
263
  return graphServiceName
236
- }
264
+ };
237
265
 
238
266
  function defaultIamRolePerAction() {
239
267
 
@@ -263,7 +291,7 @@ function defaultIamRolePerAction() {
263
291
  );
264
292
 
265
293
  return defaultIamRole
266
- }
294
+ };
267
295
 
268
296
  function getComplexFilterServiceTag(allObjectSchemas) {
269
297
  const complexFilterServiceTagSet = new Set();
@@ -272,7 +300,7 @@ function getComplexFilterServiceTag(allObjectSchemas) {
272
300
  }
273
301
  let complexFilterServiceTags = [...complexFilterServiceTagSet];
274
302
  return complexFilterServiceTags
275
- }
303
+ };
276
304
 
277
305
  async function getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas) {
278
306
  const graphServiceName = new Set();
@@ -287,7 +315,7 @@ async function getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas) {
287
315
  let graphServiceNames = [...graphServiceName]
288
316
  // console.log("graphServiceName", graphServiceNames)
289
317
  return graphServiceNames
290
- }
318
+ };
291
319
 
292
320
  function awaitingMultipleStepsRole() {
293
321
  let awaitingMultipleStepsRole = createIamRole(
@@ -306,11 +334,11 @@ function awaitingMultipleStepsRole() {
306
334
  ]
307
335
  )
308
336
  return awaitingMultipleStepsRole
309
- }
337
+ };
310
338
 
311
339
  function shortNameHandler(fullNameHandler) {
312
340
  return fullNameHandler.slice(3)
313
- }
341
+ };
314
342
 
315
343
 
316
344
  module.exports = {
@@ -336,5 +364,6 @@ module.exports = {
336
364
  getGraphServiceNameFromObjectSchema,
337
365
  awaitingMultipleStepsRole,
338
366
  shortNameHandler,
339
- SHORT_FUNCTION_NAME
367
+ SHORT_FUNCTION_NAME,
368
+ S3_RESOURCE
340
369
  }
@@ -1,180 +0,0 @@
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
- const AWS = require('aws-sdk');
24
- const api = new AWS.ApiGatewayManagementApi({
25
- endpoint: process.env.iz_webSocketEndpoint,
26
- });
27
-
28
- module.exports.webSocketTaskComplete = async (
29
- _izContext,
30
- passStatus,
31
- errorsFound,
32
- uploadUrl,
33
- imageImportId,
34
- maximumSize,
35
- cacheStatus,
36
- imageImportCacheData,
37
- imageImportCacheId,
38
- // route,
39
- topicArn
40
- ) => {
41
- // _izContext.logger.debug('functionGet params: ', params);
42
- try {
43
-
44
- // you must have data in table.
45
- console.log("topicArn", topicArn)
46
- let taskId = imageImportId;
47
- let taskTag = null;
48
-
49
- switch (topicArn) {
50
- case snsSharedLib.snsTopicArn("OutReservedImageLimitComplete"):
51
- taskTag = 'UploadImage';
52
- break
53
- // case 'message':
54
- // break
55
- // default:
56
- // console.log('Received unknown route:', route)
57
- }
58
-
59
- // console.log("topicArn", topicArn)
60
- // let taskTag = topicArn.split(":")[5];
61
- // let taskId = sortResultId;
62
- // console.log("taskTag", taskTag)
63
- // switch (taskTag) {
64
- // case 'SortedResultsTestSortResultComplete':
65
- // taskTag = 'SortedResultsTestSortResultComplete';
66
- // break
67
- // // case 'message':
68
- // // break
69
- // // default:
70
- // // console.log('Received unknown route:', route)
71
- // }
72
-
73
- let webSocketTask = null;
74
-
75
- for (let i = 0; i < 4; i++) {
76
- // let value = await dynamodbSharedLib.getItem(
77
- webSocketTask = await dynamodbSharedLib.query(
78
- _izContext,
79
- dynamodbSharedLib.tableName("WebSocketTask"),
80
- {
81
- taskKey: taskTag + "_" + taskId,
82
- // connectionid: "ZKPBId2CCYcCG6A="
83
- }
84
- );
85
-
86
- if (webSocketTask.length < 1) {
87
- continue;
88
- } else {
89
- break;
90
- }
91
- }
92
- console.log("Item: ", webSocketTask.Items)
93
-
94
- for (let itemIter = 0; itemIter < webSocketTask.Items.length; itemIter++) {
95
-
96
- let connectionid = webSocketTask.Items[itemIter].connectionid;
97
- let taskKey = webSocketTask.Items[itemIter].taskKey;
98
-
99
- // if (route) {
100
- let data = {};
101
-
102
- if (cacheStatus) {
103
- data = {
104
- connId: connectionid,
105
- cacheStatus: cacheStatus,
106
- imageImportId: imageImportId,
107
- imageImportCacheId: imageImportCacheId,
108
- imageImportCacheData: imageImportCacheData
109
- }
110
- }
111
-
112
- if (passStatus) {
113
- if (passStatus === 'complete') {
114
- let maxSize = maximumSize / 1048576
115
- data = {
116
- connId: connectionid,
117
- passStatus: passStatus,
118
- imageImportId: imageImportId,
119
- uploadUrl: uploadUrl,
120
- maximumSize: `${maxSize} MiB`
121
- }
122
- } else if (passStatus === 'error') {
123
- data = {
124
- connId: connectionid,
125
- passStatus: passStatus,
126
- imageImportId: imageImportId,
127
- errorsFound: errorsFound
128
- }
129
- } else {
130
- throw new NoRetryError('Another passStatus: pass status is not complete or error')
131
- }
132
- }
133
-
134
- try {
135
- _izContext.logger.debug("endpoint: ", process.env.iz_webSocketEndpoint)
136
- await postMessage(
137
- data,
138
- connectionid
139
- )
140
- } catch (err) {
141
- _izContext.logger.info("postMessage error: ", err, connectionid);
142
- }
143
- // }
144
-
145
-
146
- await dynamodbSharedLib.deleteItem(
147
- _izContext,
148
- dynamodbSharedLib.tableName("WebSocketTask"),
149
- {
150
- taskKey: taskKey,
151
- connectionid: connectionid,
152
- }
153
- );
154
- console.log('testdelete and delete item')
155
-
156
- _izContext.logger.debug("connectionid", connectionid, itemIter)
157
- }
158
-
159
- async function postMessage(data, connectionId) {
160
- const params = {
161
- ConnectionId: connectionId,
162
- Data: JSON.stringify(data),
163
- // Data: Buffer.from(JSON.stringify(data)),
164
- }
165
- return api.postToConnection(params).promise();
166
- };
167
-
168
- //loop value and send message back to client
169
- //fix cachetime
170
- const time = new Date();
171
- _izContext.logger.debug("value:", webSocketTask, Date.now(), new Date(), time, time.toLocaleTimeString())
172
- return {
173
- value: webSocketTask
174
- }
175
-
176
- } catch (err) {
177
- _izContext.logger.error('error websocketTaskComplete: ', err)
178
- throw (err);
179
- }
180
- };