@izara_project/izara-market-library-service-schemas 1.0.17 → 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 (114) hide show
  1. package/package.json +4 -4
  2. package/src/GenerateCodeLibs/src/Consts.js +32 -2
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +27 -61
  4. package/src/SourceManager/src/Utils.js +16 -1
  5. package/src/TemplateManager/src/FindData/FindDataYaml/data.js +0 -9
  6. package/src/TemplateManager/src/GenerateCode.js +133 -33
  7. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +1 -1
  8. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/data.js +1 -1
  9. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +1 -1
  10. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/template.ejs +1 -1
  11. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +2 -2
  12. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +2 -2
  13. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +78 -47
  14. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Delete/template.ejs +0 -1
  15. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +13 -11
  16. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +57 -13
  17. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler/lambda → PerActionEndpoint/libs}/data.js +12 -21
  18. package/src/TemplateManager/src/PerActionEndpoint/libs/template.ejs +46 -0
  19. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +1 -1
  20. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/mainFunction/template.ejs +1 -1
  21. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +1 -1
  22. package/src/TemplateManager/src/ResourceYaml/dynamodb/defaultDynamoDbTable.js +15 -0
  23. package/src/TemplateManager/src/externalService/LambdaRole/data.js +120 -23
  24. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +3 -4
  25. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +31 -6
  26. package/src/TemplateManager/src/flowSchema/DefaultWebSocketResource/dynamoDb/ReservedTableData.js +65 -0
  27. package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/functionYaml/data.js +23 -5
  28. package/src/TemplateManager/src/flowSchema/DefaultWebSocketResource/webSocketConnect/functionYaml/template.ejs +29 -0
  29. package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/handler/data.js +3 -3
  30. package/src/TemplateManager/src/{flowTag/webSocket → flowSchema/DefaultWebSocketResource}/webSocketConnect/handler/template.ejs +19 -14
  31. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler → flowSchema/FlowSchemaEndpoint/InProcessFlowSchema}/functionYaml/data.js +29 -27
  32. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/functionYaml/template.ejs +37 -0
  33. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/handler/data.js +47 -0
  34. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/handler/template.ejs +103 -0
  35. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/mainFunction/data.js +46 -0
  36. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/mainFunction/template.ejs +0 -0
  37. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/sns-sqs/data.js +36 -0
  38. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/InProcessFlowSchema/sns-sqs/template.ejs +0 -0
  39. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/functionYaml/data.js +35 -0
  40. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/functionYaml/template.ejs +0 -0
  41. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/handler/data.js +35 -0
  42. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/handler/template.ejs +0 -0
  43. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/mainFunction/data.js +35 -0
  44. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/mainFunction/template.ejs +0 -0
  45. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/sns-sqs/data.js +35 -0
  46. package/src/TemplateManager/src/flowSchema/FlowSchemaEndpoint/OutComplete/sns-sqs/template.ejs +0 -0
  47. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/functionYaml/data.js +102 -0
  48. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/functionYaml/template.ejs +30 -0
  49. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/handler/data.js +58 -0
  50. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/handler/template.ejs +126 -0
  51. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/mainFunction/data.js +51 -0
  52. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/mainFunction/template.ejs +121 -0
  53. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/queue/data.js +64 -0
  54. package/src/TemplateManager/src/flowSchema/UploadS3Case/confirmReservedAfterUpload/queue/template.ejs +45 -0
  55. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/data.js +122 -0
  56. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/template.ejs +37 -0
  57. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +72 -0
  58. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +107 -0
  59. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/mainFunction/data.js +55 -0
  60. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/mainFunction/template.ejs +133 -0
  61. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/functionYaml/data.js +102 -0
  62. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/functionYaml/template.ejs +30 -0
  63. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/handler/data.js +58 -0
  64. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/handler/template.ejs +103 -0
  65. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/mainFunction/data.js +55 -0
  66. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/mainFunction/template.ejs +86 -0
  67. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/sns-sqs/data.js +72 -0
  68. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObjectComplete/sns-sqs/template.ejs +49 -0
  69. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/functionYaml/data.js +85 -0
  70. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/functionYaml/template.ejs +27 -0
  71. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/handler/data.js +57 -0
  72. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/handler/template.ejs +120 -0
  73. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/mainFunction/data.js +51 -0
  74. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/mainFunction/template.ejs +164 -0
  75. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/sqs/data.js +65 -0
  76. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/getsignUrlsAcc/sqs/template.ejs +53 -0
  77. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/functionYaml/data.js +112 -0
  78. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/functionYaml/template.ejs +30 -0
  79. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/handler/data.js +57 -0
  80. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/handler/template.ejs +126 -0
  81. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/mainFunction/data.js +54 -0
  82. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/mainFunction/template.ejs +254 -0
  83. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/queue/data.js +64 -0
  84. package/src/TemplateManager/src/flowSchema/UploadS3Case/createPresignUrl/reservedLimitComplete/queue/template.ejs +45 -0
  85. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/data.js +94 -0
  86. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/templateAsyncHandler.ejs +110 -0
  87. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/handler/templateSyncHandler.ejs +49 -0
  88. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/hookLogic/data.js +44 -0
  89. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/mainFunction/data.js +66 -0
  90. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/mainFunction/template.ejs +7 -0
  91. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/queue/data.js +73 -0
  92. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/queue/snsTemplate.ejs +59 -0
  93. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode/queue/sqsTemplate.ejs +43 -0
  94. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrDsq/data.js +87 -0
  95. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrDsq/template.ejs +30 -0
  96. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrS3/data.js +112 -0
  97. package/src/TemplateManager/src/{flowTag/webSocket/websocketHandler/functionYaml → flowSchema/UploadS3Case/processFileS3AfterUpload/functionYml/HdrS3}/template.ejs +10 -5
  98. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerDsq/data.js +45 -0
  99. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerDsq/template.ejs +151 -0
  100. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerS3/data.js +43 -0
  101. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/handler/handlerS3/template.ejs +68 -0
  102. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/mainFunction/data.js +43 -0
  103. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/mainFunction/template.ejs +392 -0
  104. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/data.js +77 -0
  105. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/dsqTemplatePath.ejs +32 -0
  106. package/src/TemplateManager/src/flowSchema/UploadS3Case/processFileS3AfterUpload/queue/s3Template.ejs +59 -0
  107. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/S3/data.js +51 -0
  108. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/S3/template.ejs +13 -0
  109. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/libs/data.js +42 -0
  110. package/src/TemplateManager/src/flowSchema/UploadS3Case/relate/libs/template.ejs +137 -0
  111. package/src/TemplateManager/src/libs/Consts.js +60 -28
  112. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/template.ejs +0 -10
  113. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/template.ejs +0 -131
  114. /package/src/TemplateManager/src/{flowTag/resources/dynamoDb/data.js → flowSchema/DefaultWebSocketResource/dynamoDb/WebSocketTaskData.js} +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
 
@@ -101,7 +112,11 @@ const SOURCE_PATH = {
101
112
  resourceLocationFindData: 'src/generatedCode/FindData/source',
102
113
  resourceLocationRelationshipPerAction: 'src/generatedCode/RelationshipPerAction/source/',
103
114
  resourceLocationTranslateId: 'src/generatedCode/TranslateId/source/',
104
- resourceLocationProcessLogical: "src/generatedCode/ProcessLogical/source/"
115
+ resourceLocationProcessLogical: "src/generatedCode/ProcessLogical/source/",
116
+ webSocket: "../src/generatedCode/WebSocket/source/",
117
+ resourceLocationWebSocket: "src/generatedCode/WebSocket/source/",
118
+ generateCodeLib: "../src/generatedCode/libs/source/",
119
+ webSocketHook: "../src/generatedCode/WebSocket/source/hookFunction/source/"
105
120
  };
106
121
 
107
122
 
@@ -122,7 +137,7 @@ const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
122
137
  dynamoDbPermission: 'DeleteItem',
123
138
  httpMethod: 'delete',
124
139
  }
125
- }
140
+ };
126
141
 
127
142
  const SQS_RESOURCE = {
128
143
  sendMessage: "SendMessage",
@@ -131,12 +146,12 @@ const SQS_RESOURCE = {
131
146
  getQueueAttributes: "GetQueueAttributes",
132
147
  deleteMessageBatch: "DeleteMessageBatch",
133
148
  getQueueUrl: "GetQueueUrl"
134
- }
149
+ };
135
150
 
136
151
  const SNS_RESOURCE = {
137
152
  publish: "Publish",
138
- subscription: "Subscription"
139
- }
153
+ subscribe: "Subscribe"
154
+ };
140
155
 
141
156
  const DYNAMO_RESOURCE = {
142
157
  putItem: "PutItem",
@@ -144,11 +159,21 @@ const DYNAMO_RESOURCE = {
144
159
  query: "Query",
145
160
  updateItem: "UpdateItem",
146
161
  deleteItem: "DeleteItem"
147
- }
162
+ };
148
163
 
149
164
  const LAMBDA_RESOURCE = {
150
165
  invokeFunction: "InvokeFunction"
151
- }
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
+
152
177
  function externalResourceName(resourceClass, resourceName, serviceTag) {
153
178
  return {
154
179
  [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/${await dynamoSharedLib.tableName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
@@ -156,11 +181,11 @@ function externalResourceName(resourceClass, resourceName, serviceTag) {
156
181
  [RESOURCE_CLASSES.dynamoDbAcrossService]: "arn:aws:dynamodb:${process.env.iz_region}:${process.env.iz_accountId}:table/*" + `${resourceName}`,
157
182
  [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${await lambdaSharedLib.lambdaFunctionName(_izContext, " + `"${resourceName}" ,"${serviceTag}")}`,
158
183
  }[resourceClass]
159
- }
184
+ };
160
185
 
161
186
  function externalResourceSns(resourceName, serviceTag) {
162
187
  return "arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${await snsSharedLib.snsTopicName(_izContext, " + `"${resourceName}", "${serviceTag}")}`
163
- }
188
+ };
164
189
 
165
190
  const SAVE_FILE_NAME = {
166
191
  dynamoDbYaml: "generated-dynamoDB-table",
@@ -172,8 +197,10 @@ const SAVE_FILE_NAME = {
172
197
  snsSubscription: "generatedSnsServiceConfig",
173
198
  translateId: "TranslateIdsRequest",
174
199
  findData: "findData",
175
- processLogicalYaml: "processLogical"
176
- }
200
+ processLogicalYaml: "processLogical",
201
+ flowSchema: "flowSchema",
202
+ S3Bucket: "generated-s3-bucket"
203
+ };
177
204
 
178
205
  const FUNCTION_NAME = {
179
206
  updateRel: "updateRelationship",
@@ -192,8 +219,11 @@ const FUNCTION_NAME = {
192
219
  getNodeComplete: "getNodeComplete",
193
220
  paginateProcessLogical: "paginateProcessLogical",
194
221
  deleteNode: "deleteNode",
195
- deleteNodeComplete: "deleteNodeComplete"
196
- }
222
+ deleteNodeComplete: "deleteNodeComplete",
223
+ createObjectS3: "createObjectS3",
224
+ createObjectS3Complete: "webSocketTaskComplete",
225
+ processAfterUploadS3: "processAfterUploadS3"
226
+ };
197
227
 
198
228
  const SHORT_FUNCTION_NAME = {
199
229
  updateRel: "updateRel",
@@ -212,7 +242,8 @@ const SHORT_FUNCTION_NAME = {
212
242
  getNodeComplete: "getNodeComp",
213
243
  paginateProcessLogical: "paginateProLogical",
214
244
  deleteNode: "deleteNode",
215
- deleteNodeComplete: "deleteNodeComp"
245
+ deleteNodeComplete: "deleteNodeComp",
246
+ createObjectS3Complete: "webSocketTaskComp",
216
247
  }
217
248
 
218
249
  const getGraphServiceNameFromAllRelSchema = async (_izContext, allRelSchemas) => {
@@ -230,7 +261,7 @@ const getGraphServiceNameFromAllRelSchema = async (_izContext, allRelSchemas) =>
230
261
  }))
231
262
  const graphServiceName = [...graphServiceNameSet]
232
263
  return graphServiceName
233
- }
264
+ };
234
265
 
235
266
  function defaultIamRolePerAction() {
236
267
 
@@ -260,7 +291,7 @@ function defaultIamRolePerAction() {
260
291
  );
261
292
 
262
293
  return defaultIamRole
263
- }
294
+ };
264
295
 
265
296
  function getComplexFilterServiceTag(allObjectSchemas) {
266
297
  const complexFilterServiceTagSet = new Set();
@@ -269,7 +300,7 @@ function getComplexFilterServiceTag(allObjectSchemas) {
269
300
  }
270
301
  let complexFilterServiceTags = [...complexFilterServiceTagSet];
271
302
  return complexFilterServiceTags
272
- }
303
+ };
273
304
 
274
305
  async function getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas) {
275
306
  const graphServiceName = new Set();
@@ -284,7 +315,7 @@ async function getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas) {
284
315
  let graphServiceNames = [...graphServiceName]
285
316
  // console.log("graphServiceName", graphServiceNames)
286
317
  return graphServiceNames
287
- }
318
+ };
288
319
 
289
320
  function awaitingMultipleStepsRole() {
290
321
  let awaitingMultipleStepsRole = createIamRole(
@@ -303,11 +334,11 @@ function awaitingMultipleStepsRole() {
303
334
  ]
304
335
  )
305
336
  return awaitingMultipleStepsRole
306
- }
337
+ };
307
338
 
308
339
  function shortNameHandler(fullNameHandler) {
309
340
  return fullNameHandler.slice(3)
310
- }
341
+ };
311
342
 
312
343
 
313
344
  module.exports = {
@@ -333,5 +364,6 @@ module.exports = {
333
364
  getGraphServiceNameFromObjectSchema,
334
365
  awaitingMultipleStepsRole,
335
366
  shortNameHandler,
336
- SHORT_FUNCTION_NAME
367
+ SHORT_FUNCTION_NAME,
368
+ S3_RESOURCE
337
369
  }
@@ -1,10 +0,0 @@
1
- WebSocketConnect:
2
- handler: src/generatedCode/ObjectTypePerActionEndpoint/source/WebSocketConnect.main
3
- name: ${self:custom.iz_resourcePrefix}WebSocketConnect
4
- events:
5
- - websocket:
6
- route: $connect
7
- - websocket:
8
- route: $disconnect
9
- #<#<WebSocketConnectIamRole#>
10
- #<#/<WebSocketConnectIamRole#>
@@ -1,131 +0,0 @@
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 sqsSharedLib = izaraShared.sqsSharedLib;
27
- const snsSharedLib = izaraShared.snsSharedLib;
28
- const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
29
-
30
- const externalRequest = require('@izara_project/izara-core-library-external-request');
31
- const sns = externalRequest.sns;
32
- const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
33
-
34
- const utils = require("@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils");
35
- const NoRetryError = require("@izara_project/izara-core-library-core/src/NoRetryError");
36
-
37
- module.exports.main = middleware.wrap(async (event, context, callback) => {
38
-
39
- event._izContext.logger.debug('Event:', event);
40
-
41
- try {
42
-
43
- let eventParams = JSON.parse(event.body)
44
-
45
- if (event.requestContext) {
46
- const route = event.requestContext.routeKey;
47
- const connectionId = event.requestContext.connectionId;
48
-
49
- // const time = Date.now();
50
- // console.log(`socketxx: ${time}`);
51
-
52
- switch (route) {
53
- case null:
54
- console.log('Received unknown route:', route)
55
- break
56
- case 'webScoket':
57
- console.log("event in route", event)
58
- let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {}
59
-
60
- let getFlowSchema = await getObjectSchema.getLocalFlowSchemas(event._izContext, eventParams.flowTag).then(res => res.records)
61
- event._izContext.logger.debug("getFlowSchema", getFlowSchema)
62
- let flowSchema = getFlowSchema[0]
63
- event._izContext.logger.debug("flowSchema", flowSchema);
64
-
65
- if (!flowSchema) {
66
- throw new NoRetryError(`flowTag not found ${flowSchema.flowTag}`)
67
- }
68
-
69
- // create messageObject send to topic
70
- let messageObject = {
71
- propertiesA: eventParams.propertiesA,
72
- }
73
-
74
- messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlow, messageObject);
75
-
76
- let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlow, {});
77
-
78
- let sendMessageToTopic = {
79
- Message: JSON.stringify(messageObject),
80
- MessageAttributes: messageAttributes,
81
- TopicArn: await snsSharedLib.snsTopicArn(event._izContext, `InProcess${utils.firstLetterLowerCase(flowSchema.flowTag)}`)
82
- }
83
-
84
- event._izContext.logger.debug(`message Params before send toInProcess${utils.firstLetterUpperCase(flowSchema.flowTag)}`, sendMessageToTopic);
85
- await sns.publishAsync(event._izContext, sendMessageToTopic)
86
-
87
-
88
- await dynamodbSharedLib.putItem(
89
- event._izContext,
90
- await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
91
- {
92
- taskKey: flowSchema.flowTag + connectionId,
93
- connectionid: connectionId
94
- }
95
- )
96
-
97
- postMessage(sendMessageToTopic, connectionId)
98
- break
99
- }
100
- } else {
101
- const connId = event.connId;
102
- await postMessage({ message: event.message }, connId);
103
- }
104
-
105
- return (izara.response.webSocketSuccess());
106
-
107
- } catch (err) {
108
- console.log("event", event)
109
- const connId = event.requestContext.connectionId
110
- event._izContext.logger.error('Error, WebSocket: ', err);
111
- await sendErrorMessage({ message: err.message }, connId);
112
- return (izara.response.failure(err));
113
- }
114
- });
115
-
116
- async function postMessage(data, connectionId) {
117
- const params = {
118
- ConnectionId: connectionId,
119
- Data: JSON.stringify(data),
120
- // Data: Buffer.from(JSON.stringify(data)),
121
- }
122
- return api.postToConnection(params).promise();
123
- };
124
-
125
- async function sendErrorMessage(errorMessage, connectionId) {
126
- const params = {
127
- ConnectionId: connectionId,
128
- Data: JSON.stringify(errorMessage)
129
- }
130
- return api.postToConnection(params).promise();
131
- }