@izara_project/izara-market-library-service-schemas 1.0.32 → 1.0.33

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 (49) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/MainLibs/src/Consts.js +7 -2
  4. package/src/reStructure/GenerateCode.js +16 -18
  5. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
  6. package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
  7. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +15 -15
  8. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
  9. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
  10. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  11. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
  12. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
  13. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +0 -0
  14. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
  15. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
  16. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
  17. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
  18. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
  19. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
  20. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
  21. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
  22. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
  23. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
  25. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +1 -1
  26. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +1 -1
  27. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
  28. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +20 -0
  29. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
  30. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
  31. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
  32. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
  33. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +3 -28
  34. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +6 -10
  35. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +4 -2
  36. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +4 -3
  37. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +26 -0
  38. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +2 -2
  39. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +6 -10
  40. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +4 -4
  41. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -4
  42. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +3 -4
  43. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +18 -18
  44. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
  45. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
  46. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +55 -10
  47. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +27 -7
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template copy.ejs +0 -125
  49. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/sns-in/template.ejs → createRecordByStatusType/statusFieldTemplate.ejs} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -77,7 +77,8 @@ const TOPIC_NAME_GENERATE_CODE = {
77
77
  outGetNodeComplete: "GetNodeComplete_Out",
78
78
  reservedLimitComplete: "ReservedLimitComplete",
79
79
  createPresignUrl: "CreatePresignUrl",
80
- flowSchemaOwnTopicComplete: "FlowSchemaOwnTopicComplete"
80
+ flowSchemaOwnTopicComplete: "FlowSchemaOwnTopicComplete",
81
+ flowSchemaOwnTopicEndpointComplete: "flowSchemaOwnTopicEndpointComplete",
81
82
  }
82
83
 
83
84
  const GRAPH_HANDLER_SERVICE_NAME = {
@@ -120,6 +120,10 @@ const SOURCE_PATH = {
120
120
  resourceLocationWebSocket: "src/generatedCode/FlowSchema/UploadS3/",
121
121
  flowSchemaOwnTopic: "../src/generatedCode/FlowSchema/FlowSchemaOwnTopic/",
122
122
  resourceLocationFlowSchemaOwnTopic: "src/generatedCode/flowSchemaOwnTopic/",
123
+ flowSchemaExternalTopic: "../src/generatedCode/FlowSchema/FlowSchemaExternalTopic/",
124
+ resourceLocationFlowSchemaExternalTopic: "src/generatedCode/flowSchemaExternalTopic/",
125
+ flowSchemaEventBridge: "../src/generatedCode/FlowSchema/EventBridge/",
126
+ resourceLocationFlowSchemaEventBridge: "src/generatedCode/FlowSchema/EventBridge/",
123
127
  generateCodeLib: "../src/generatedCode/libs/source/",
124
128
  logicalFunctionHook: "../src/generatedCode/WebSocket/source/FlowSchemaHook/HookLogicFunction/source/",
125
129
  resourceLocationLogicalFunctionHook: "src/generatedCode/WebSocket/source/FlowSchemaHook/HookLogicFunction/source",
@@ -257,6 +261,7 @@ const FUNCTION_NAME = {
257
261
  flowSchemaOwnTopic: "flowSchemaOwnTopic",
258
262
  flowSchemaOwnTopicComplete: "flowSchemaOwnTopicComplete",
259
263
  flowSchemaOwnTopicEndpoint: "flowSchemaOwnTopicEndpoint",
264
+ flowSchemaOwnTopicEndpointComplete: "flowSchemaOwnTopicEndpointComplete",
260
265
  flowSchemaExternalTopic: "externalTopic",
261
266
  };
262
267
 
@@ -374,9 +379,9 @@ const SOURCE_GENERATE_IAM_ROLE = {
374
379
  RelationshipCompleteRole: "RelationshipCom",
375
380
  FlowSchemaUploadS3Role: "FlowSchemaUploadS3",
376
381
  FlowSchemaOwnTopic: "FlowSchemaOwnTopic",
377
- FlowSchemaOwnTopic: "FlowSchemaOwnTopic",
378
- perActionEndpoint: "PerActionEndpoint",
382
+ PerActionEndpoint: "PerActionEndpoint",
379
383
  ExternalTopicRole: "ExternalTopic",
384
+ EventBridge: "EventBridge",
380
385
  };
381
386
 
382
387
  const ADD_ON_DATA_STRUCTURE_TYPE = {
@@ -45,16 +45,17 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
45
45
  let localServicePath = join(saveFilePath, "../../");
46
46
 
47
47
  // // define path for store yml file
48
- const GENERATE_CODE_SOURCE_PATH = {
49
- appYaml: join(saveFilePath, SOURCE_PATH.appYaml),
50
- resourceYaml: join(saveFilePath, SOURCE_PATH.resourceYaml),
51
- lambdaPerAction: join(saveFilePath, SOURCE_PATH.lambdaPerAction),
52
- externalService: join(saveFilePath, SOURCE_PATH.externalService),
53
- relationshipPerAction: join(saveFilePath, SOURCE_PATH.relationshipPerAction),
54
- webSocketEndpoint: join(saveFilePath, SOURCE_PATH.webSocket),
55
- generateCodeLib: join(saveFilePath, SOURCE_PATH.generateCodeLib),
56
- generatedMainFunctionPerService: join(saveFilePath, SOURCE_PATH.endpointPerService),
57
- };
48
+ // const GENERATE_CODE_SOURCE_PATH = {
49
+ // appYaml: join(saveFilePath, SOURCE_PATH.appYaml),
50
+ // resourceYaml: join(saveFilePath, SOURCE_PATH.resourceYaml),
51
+ // lambdaPerAction: join(saveFilePath, SOURCE_PATH.lambdaPerAction),
52
+ // externalService: join(saveFilePath, SOURCE_PATH.externalService),
53
+ // relationshipPerAction: join(saveFilePath, SOURCE_PATH.relationshipPerAction),
54
+ // webSocketEndpoint: join(saveFilePath, SOURCE_PATH.webSocket),
55
+ // generateCodeLib: join(saveFilePath, SOURCE_PATH.generateCodeLib),
56
+ // generatedMainFunctionPerService: join(saveFilePath, SOURCE_PATH.endpointPerService),
57
+ // flowSchema: join(saveFilePath,'../src/generatedCode/flowSchema')
58
+ // };
58
59
 
59
60
  //------ Start Create Source ------
60
61
 
@@ -108,18 +109,15 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
108
109
  if (status === false) {
109
110
  throw Error(errors)
110
111
  }
111
- }
112
112
 
113
- // validate path before empty folder
114
- for (let folderPathToEmpty of Object.values(GENERATE_CODE_SOURCE_PATH)) {
115
- validatePathWithRootServicePath(localServicePath, folderPathToEmpty)
116
- }
113
+ // console.log("templatePath in generateCode", setting.savePath)
114
+ // empty file by savePath
115
+ // validate path before empty folder
116
+ validatePathWithRootServicePath(localServicePath, setting.savePath)
117
117
 
118
- for (let folderPathToEmpty of Object.values(GENERATE_CODE_SOURCE_PATH)) {
119
- await deleteFileInDir(folderPathToEmpty);
118
+ await deleteFileInDir(setting.savePath);
120
119
  }
121
120
 
122
-
123
121
  // generate all source
124
122
  for (let item of allCreateSource) {
125
123
  // throw error if item is invalid
@@ -66,7 +66,7 @@ async function data(_izContext, allObjSchemas, srcPath) {
66
66
  }
67
67
 
68
68
  async function createParamForCreateSource(_izContext, allObjSchemas, action, handler, srcPath) {
69
- let groupBy = SOURCE_GENERATE_IAM_ROLE.perActionEndpoint;
69
+ let groupBy = SOURCE_GENERATE_IAM_ROLE.PerActionEndpoint;
70
70
  let additionalResourcePermission = defaultIamRolePerAction();
71
71
  let functionNameConfig = upperCase(action) + upperCase(shortNameHandler(handler))
72
72
 
@@ -21,7 +21,7 @@ const path = require('path');
21
21
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/index.js").utils;
22
22
  const templateYamlPath = path.join(__dirname, "./templateYaml.ejs");
23
23
  const templatePathIntTestPath = path.join(__dirname, "./templateIntTesting.ejs");
24
- const { SOURCE_PATH, SOURCE_GENERATE_IAM_ROLE } = require("../../../../MainLibs/index.js").consts;
24
+ const { SOURCE_PATH, SOURCE_GENERATE_IAM_ROLE } = require("../../../../MainLibs/src/Consts.js");
25
25
 
26
26
 
27
27
  function data(_izContext, createSourceParams, srcPath) {
@@ -50,13 +50,23 @@ function data(_izContext, createSourceParams, srcPath) {
50
50
  const roleNameConcatConfigs = new Set();
51
51
 
52
52
  // Add default IAM roles from configuration
53
- Object.entries(SOURCE_GENERATE_IAM_ROLE)
54
- .filter(([_, enabled]) => enabled)
55
- .forEach(([_, value]) => {
56
- if (value === SOURCE_GENERATE_IAM_ROLE.NodeCompleteRole) return;
57
- roleNameConfigs.add(`${upperCase(value)}Role`);
58
- roleNameConcatConfigs.add(`${upperCase(value)}`);
59
- });
53
+ // Object.entries(SOURCE_GENERATE_IAM_ROLE)
54
+ // .filter(([_, enabled]) => enabled)
55
+ // .forEach(([_, value]) => {
56
+ // if (value === SOURCE_GENERATE_IAM_ROLE.NodeCompleteRole) return;
57
+ // roleNameConfigs.add(`${upperCase(value)}Role`);
58
+ // roleNameConcatConfigs.add(`${upperCase(value)}`);
59
+ // });
60
+ for (const data of createSourceParams) {
61
+ let roleName = data.templateData?.roleName
62
+ if (roleName) {
63
+ if (roleName === SOURCE_GENERATE_IAM_ROLE.NodeCompleteRole) {
64
+ return
65
+ }
66
+ roleNameConfigs.add(`${upperCase(roleName)}Role`);
67
+ roleNameConcatConfigs.add(`${upperCase(roleName)}`);
68
+ }
69
+ }
60
70
 
61
71
  // Extract role names from templateData in createSourceParams
62
72
  createSourceParams.forEach(({ templateData }) => {
@@ -99,10 +99,10 @@ const createExternalSnsSubscriptions = async (_izContext, allObjSchemas, allRelS
99
99
 
100
100
  // update Relationship
101
101
  async function snsSubScriptionUpdateRelationshipComplete(_izContext, allRelSchemas) {
102
- let serviceNames = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
102
+ let serviceTag = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
103
103
 
104
104
  return {
105
- serviceNames: serviceNames,
105
+ serviceTag: serviceTag,
106
106
  topicName: TOPIC_NAME_GRAPH_HANDLER.outUpdateRel, // external service
107
107
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.updateRelComplete // in service
108
108
  }
@@ -110,10 +110,10 @@ async function snsSubScriptionUpdateRelationshipComplete(_izContext, allRelSchem
110
110
 
111
111
  // create Relationship
112
112
  async function snsSubscriptionCreateRelationshipComplete(_izContext, allRelSchemas) {
113
- let serviceNames = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
113
+ let serviceTag = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
114
114
 
115
115
  return {
116
- serviceNames: serviceNames,
116
+ serviceTag: serviceTag,
117
117
  topicName: TOPIC_NAME_GRAPH_HANDLER.outCreateRel,
118
118
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.createRelComplete
119
119
  }
@@ -122,20 +122,20 @@ async function snsSubscriptionCreateRelationshipComplete(_izContext, allRelSchem
122
122
  // topic not create yet will return error when initialSetup
123
123
  // create topic for OutUpdateNodeComplete
124
124
  async function snsSubscriptionOutUpdateNodeComplete(_izContext, allObjSchemas) {
125
- let serviceNames = await getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas)
125
+ let serviceTag = await getGraphServiceNameFromObjectSchema(_izContext, allObjSchemas)
126
126
 
127
127
  return {
128
- serviceNames: serviceNames,
128
+ serviceTag: serviceTag,
129
129
  topicName: TOPIC_NAME_GRAPH_HANDLER.outUpdateNode,
130
130
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.updateNodeComplete
131
131
  }
132
132
  }
133
133
 
134
134
  async function snsSubscriptionCreateNodeComplete(_izContext, allObjectSchemas) {
135
- let serviceNames = await getGraphServiceNameFromObjectSchema(_izContext, allObjectSchemas)
135
+ let serviceTag = await getGraphServiceNameFromObjectSchema(_izContext, allObjectSchemas)
136
136
 
137
137
  return {
138
- serviceNames: serviceNames,
138
+ serviceTag: serviceTag,
139
139
  topicName: TOPIC_NAME_GRAPH_HANDLER.outCreateNode,
140
140
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.createNodeComplete
141
141
  }
@@ -152,19 +152,19 @@ async function snsSubscriptionDeleteNodeComplate(_izContext, allObjectSchemas) {
152
152
  }
153
153
 
154
154
  async function snsSubscriptionDeleteRelatipnshipComplete(_izContext, allRelSchemas) {
155
- let serviceNames = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
155
+ let serviceTag = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
156
156
 
157
157
  return {
158
- serviceNames: serviceNames,
158
+ serviceTag: serviceTag,
159
159
  topicName: TOPIC_NAME_GRAPH_HANDLER.outDeleteRel,
160
160
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.deleteRelComplete
161
161
  }
162
162
  }
163
163
 
164
164
  function snsSubscriptionReservedLimitCompleteForReservedDynamicUsage(_izContext) {
165
- let serviceNames = [EXTERNAL_SERVICE_NAME.accountLimits]
165
+ let serviceTag = [EXTERNAL_SERVICE_NAME.accountLimits]
166
166
  return {
167
- serviceNames: serviceNames,
167
+ serviceTag: serviceTag,
168
168
  topicName: TOPIC_NAME_EXTERNAL_SERVICE.reservedDynamicUsageComplete,
169
169
  sqsEndpoint: TOPIC_NAME_GENERATE_CODE.createPresignUrl + upperCase(HANDLER.hdrSqs)
170
170
  }
@@ -172,9 +172,9 @@ function snsSubscriptionReservedLimitCompleteForReservedDynamicUsage(_izContext)
172
172
 
173
173
 
174
174
  function snsSubscriptionConfirmReserved(_izContext) {
175
- let serviceNames = [EXTERNAL_SERVICE_NAME.accountLimits];
175
+ let serviceTag = [EXTERNAL_SERVICE_NAME.accountLimits];
176
176
  return {
177
- serviceNames: serviceNames,
177
+ serviceTag: serviceTag,
178
178
  topicName: TOPIC_NAME_EXTERNAL_SERVICE.reservedDynamicUsageComplete,
179
179
  sqsEndpoint: "ConfirmNewReserved" + upperCase(HANDLER.hdrSqs)
180
180
  }
@@ -189,7 +189,7 @@ function snsSubscriptionFlowSchemaExternalTopic(_izContext, localFlowSchema) {
189
189
  const splitFlowStepKey = flowStep.split("_");
190
190
 
191
191
  return {
192
- serviceNames: [splitFlowStepKey[0]],
192
+ serviceTag: [splitFlowStepKey[0]],
193
193
  topicName: splitFlowStepKey[2],
194
194
  sqsEndpoint: splitFlowStepKey[3]
195
195
  };
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  module.exports.generatedSnsTopicSubscription = [ <% datas.forEach(data => { -%>
21
- <% data.serviceNames.forEach(serviceName => { _%>
21
+ <% data.serviceTag.forEach(serviceTag => { _%>
22
22
  {
23
- serviceName: "<%- serviceName %>",
23
+ serviceTag: "<%- serviceTag %>",
24
24
  topicName: "<%- data.topicName %>",
25
25
  sqsEndpoint: "<%- data.sqsEndpoint %>"
26
26
  },
@@ -3,10 +3,6 @@
3
3
  handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
4
  name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
5
  events:
6
- - websocket:
7
- route: $connect
8
- - websocket:
9
- route: $disconnect
10
6
  - websocket:
11
7
  route: $default
12
8
  - websocket:
@@ -55,7 +55,7 @@ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
55
55
  defaultSnsInSqsDataList.push(
56
56
  {
57
57
  queueName: upperCase(FUNCTION_NAME.createObjectS3Complete) + upperCase(HANDLER.hdrSqs),
58
- subScription: "Out" + upperCase(FUNCTION_NAME.updateNodeComplete)
58
+ subScription: upperCase(FUNCTION_NAME.updateNodeComplete) + "_Out"
59
59
  }
60
60
  )
61
61
 
@@ -52,6 +52,16 @@ function createWebSocketConnectYaml(_izContext, srcPath) {
52
52
  [
53
53
  resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
54
54
  ]
55
+ ),
56
+ createIamRole(
57
+ {
58
+ "execute-api": [
59
+ "ManageConnections"
60
+ ]
61
+ },
62
+ [
63
+ resourceNames(RESOURCE_CLASSES.webSocket)
64
+ ]
55
65
  )
56
66
  )
57
67
 
@@ -61,7 +71,7 @@ function createWebSocketConnectYaml(_izContext, srcPath) {
61
71
  functionName,
62
72
  resourceLocation: "src/generatedCode/FlowSchema/WebSocketConnect/source/",
63
73
  additionalResourcePermission,
64
- roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
74
+ roleName: "WebsocketConnect"
65
75
 
66
76
  },
67
77
  setting: {
@@ -9,20 +9,7 @@
9
9
  route: $disconnect
10
10
  - websocket:
11
11
  route: $default
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
- <%_}) _%>
12
+ role: WebsocketConnectRole
26
13
  #<#<WebSocketConnectIamRole#>
27
14
  #<#/<WebSocketConnectIamRole#>
28
15
 
@@ -0,0 +1,81 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const STORAGE_TYPES = {
29
+ dynamoDB: "dynamoDB",
30
+ graph: "graph"
31
+ }
32
+ const templatePath = path.join(__dirname, '../../resourceYaml/dynamodb/template.ejs')
33
+ const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../MainLibs/src/Consts.js')
34
+
35
+ /**
36
+ * create param of crateSouce for FindData And processLogical
37
+ *
38
+ * @param {Object} _izContext
39
+ * @param {String} srcPath
40
+ * @returns {Object[]}
41
+ */
42
+ const createAwaitingMultipleStepDynamoDbData = (_izContext, flowSchema, srcPath) => {
43
+
44
+ let resultsForCreateSource = [];
45
+ const defaultDynamoDataLists = [];
46
+
47
+ if (flowSchema.statusType === "storedCache") {
48
+ defaultDynamoDataLists.push(
49
+ {
50
+ tableName: flowSchema.flowTag + "Main",
51
+ resourceName: flowSchema.flowTag + "Main",
52
+ attributes: [
53
+ {
54
+ keyType: "partitionKey",
55
+ AttributeName: flowSchema.flowTag + "Id",
56
+ AttributeType: "S"
57
+ }
58
+ ]
59
+ }
60
+ )
61
+ }
62
+
63
+ for (let defaultDynamoData of defaultDynamoDataLists) {
64
+ resultsForCreateSource.push({
65
+ templatePath: templatePath,
66
+ templateData: defaultDynamoData,
67
+ setting: {
68
+ initialData: 'Resources:\n',
69
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
70
+ saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
71
+ fileExtension: '.yml',
72
+ isAppend: true
73
+ }
74
+ });
75
+ }
76
+ // console.log("resultsForCreateSource default dynamo", resultsForCreateSource)
77
+
78
+ return resultsForCreateSource;
79
+ }
80
+
81
+ module.exports = createAwaitingMultipleStepDynamoDbData
@@ -0,0 +1,202 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils");
25
+ const {
26
+ SOURCE_PATH,
27
+ defaultIamRolePerAction,
28
+ createIamRole,
29
+ RESOURCE_CLASSES,
30
+ SNS_RESOURCE,
31
+ resourceNames,
32
+ DYNAMO_RESOURCE,
33
+ SAVE_FILE_NAME,
34
+ FUNCTION_NAME,
35
+ shortNameHandler,
36
+ externalResourceYaml,
37
+ SOURCE_GENERATE_IAM_ROLE
38
+ } = require("../../../../../MainLibs/src/Consts");
39
+
40
+ const templatePath = path.join(__dirname, "template.ejs");
41
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
42
+ /**
43
+ * receive objectSchema
44
+ * create data for WebSocket handler template
45
+ *
46
+ * @param {Object} objectSchema
47
+ * @return {{templatePath, templateData,setting}}
48
+ */
49
+ function data(_izContext, flowSchema, srcPath) {
50
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
51
+ }
52
+
53
+ function createSourceParams(_izContext, flowSchema, srcPath) {
54
+ const functionName = upperCase(flowSchema.flowTag);
55
+ const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
56
+ const functionNameConfig = upperCase(flowSchema.flowTag) + SOURCE_GENERATE_IAM_ROLE.EventBridge;
57
+ const handlerType = HANDLER.hdrInv;
58
+ const schedules = flowSchema.schedules;
59
+
60
+ // validate schedule
61
+ if (!Array.isArray(schedules)) {
62
+ console.error("schedules is not an array");
63
+ return;
64
+ }
65
+ if (schedules.length === 0) {
66
+ console.error("No schedule found in flowSchema");
67
+ return;
68
+ }
69
+
70
+ // Validate each schedule in the array
71
+ for (const schedule of schedules) {
72
+ if (!schedule.name || schedule.name.length === 0) {
73
+ console.error("A schedule's name is not defined");
74
+ return;
75
+ }
76
+ if (!schedule.rate || schedule.rate.length === 0) {
77
+ console.error("A schedule's rate is not defined");
78
+ return;
79
+ }
80
+ if (!schedule.input || schedule.input.length === 0) {
81
+ console.error("A schedule's input is not defined");
82
+ return;
83
+ }
84
+ }
85
+
86
+ // Validate rate format for each schedule
87
+ for (const schedule of schedules) {
88
+ const rate = schedule.rate;
89
+ if (rate.startsWith('rate')) {
90
+ // Validate rate expression format: rate(value unit)
91
+ if (!/^rate\(\d+\s+(minute|minutes|hour|hours|day|days)\)$/.test(rate)) {
92
+ console.error(`Invalid rate format: ${rate}. Should be like 'rate(5 minutes)' or 'rate(1 day)'`);
93
+ return;
94
+ }
95
+ } else if (rate.startsWith('cron')) {
96
+ // Extract the cron components for more detailed validation
97
+ const cronMatch = rate.match(/^cron\((.*)\)$/);
98
+ if (!cronMatch) {
99
+ console.error(`Invalid cron format: ${rate}. Should be like 'cron(0 10 * * ? *)'`);
100
+ return;
101
+ }
102
+
103
+ const cronParts = cronMatch[1].split(/\s+/);
104
+ if (cronParts.length !== 6) {
105
+ console.error(`Invalid cron expression: ${rate}. Must contain 6 components: minutes hours day-of-month month day-of-week year`);
106
+ return;
107
+ }
108
+
109
+ } else {
110
+ console.error(`Invalid rate expression: ${rate} - must start with 'rate' or 'cron'`);
111
+ return;
112
+ }
113
+ }
114
+
115
+
116
+ let additionalResourcePermission = defaultIamRolePerAction();
117
+ additionalResourcePermission.push(
118
+ createIamRole(
119
+ {
120
+ [RESOURCE_CLASSES.sns]: [
121
+ SNS_RESOURCE.publish
122
+ ]
123
+ },
124
+ [
125
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
126
+ ]
127
+ ),
128
+ createIamRole(
129
+ {
130
+ [RESOURCE_CLASSES.dynamoDbTable]: [
131
+ DYNAMO_RESOURCE.putItem,
132
+ DYNAMO_RESOURCE.getItem,
133
+ DYNAMO_RESOURCE.query,
134
+ DYNAMO_RESOURCE.deleteItem,
135
+ DYNAMO_RESOURCE.updateItem
136
+ ]
137
+ },
138
+ [
139
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
140
+ ]
141
+ ),
142
+ createIamRole(
143
+ {
144
+ "execute-api": [
145
+ "ManageConnections"
146
+ ]
147
+ },
148
+ [
149
+ resourceNames(RESOURCE_CLASSES.webSocket)
150
+ ]
151
+ )
152
+ )
153
+
154
+ if (flowSchema?.hook) {
155
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
156
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
157
+ for (const hookFunction of hookProperties.functionList) {
158
+ if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
159
+ if (hookFunction?.permission) {
160
+ for (const permission of hookFunction.permission) {
161
+ additionalResourcePermission.push(
162
+ createIamRole(
163
+ permission.action,
164
+ permission.resource.map(resource =>
165
+ externalResourceYaml(
166
+ resource.resource,
167
+ resource.resourceName,
168
+ resource.serviceTag),
169
+ permission.effect
170
+ )
171
+ )
172
+ )
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
181
+ return {
182
+ templatePath: templatePath,
183
+ templateData: {
184
+ resourceLocation: SOURCE_PATH.resourceLocationFlowSchemaEventBridge,
185
+ functionName,
186
+ action,
187
+ functionNameConfig: functionNameConfig,
188
+ additionalResourcePermission,
189
+ roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
190
+ handlerType,
191
+ schedules
192
+ },
193
+ setting: {
194
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
195
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
196
+ fileExtension: ".yml",
197
+ isAppend: true
198
+ }
199
+ }
200
+ }
201
+
202
+ module.exports = data;
@@ -0,0 +1,21 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${functionName}${action}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
5
+ events:
6
+ <%_ schedules.forEach((schedule) => { _%>
7
+ - schedule:
8
+ name: <%- schedule.name %>
9
+ description: <%- schedule.description %>
10
+ rate: <%- schedule.rate %>
11
+ input: <%- JSON.stringify(schedule.input) %>
12
+ <%_ }) _%>
13
+ role: <%- roleName %>Role
14
+ #<#<%- functionName %><%- action %>IamRole#>
15
+ #<#/<%- functionName %><%- action %>IamRole#>
16
+ <%_ function firstLetterUpperCase(text){
17
+ return text.charAt(0).toUpperCase() + text.slice(1)
18
+ } _%>
19
+ <%_ function firstLetterLowerCase(str) {
20
+ return str.charAt(0).toLowerCase() + str.slice(1)
21
+ } _%>