@izara_project/izara-market-library-service-schemas 1.0.31 → 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 (85) hide show
  1. package/package.json +9 -9
  2. package/src/GenerateCodeLibs/src/Consts.js +29 -13
  3. package/src/MainLibs/src/Consts.js +13 -5
  4. package/src/reStructure/GenerateCode.js +16 -18
  5. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +2 -5
  6. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +1 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +1 -1
  8. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +1 -1
  9. package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +18 -8
  10. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +5 -5
  11. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +36 -14
  12. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +2 -2
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +1 -1
  14. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +0 -4
  15. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  16. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  17. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  18. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -2
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +1 -1
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +1 -1
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/sqs/template.ejs +18 -18
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +1 -1
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +11 -1
  25. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -14
  26. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +0 -0
  27. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +0 -0
  28. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +81 -0
  29. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +202 -0
  30. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +21 -0
  31. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +77 -0
  32. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/request.json +7 -0
  33. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +64 -0
  34. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +73 -0
  35. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/request.json +5 -0
  36. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +88 -0
  37. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +73 -0
  38. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +53 -0
  39. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +75 -0
  40. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +10 -0
  41. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +83 -0
  42. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +17 -0
  43. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +65 -0
  44. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +130 -0
  45. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +61 -0
  46. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +70 -0
  47. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +147 -0
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +18 -0
  49. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +64 -0
  50. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowSchema → externalTopic/websocket}/handler/template.ejs +17 -16
  51. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +60 -0
  52. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +74 -0
  53. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +89 -0
  54. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → EndpointComplete}/functionYaml/template.ejs +2 -2
  55. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +57 -0
  56. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +85 -0
  57. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +55 -0
  58. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +85 -0
  59. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +82 -0
  60. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +20 -0
  61. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +59 -0
  62. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +85 -0
  63. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +52 -0
  64. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → EndpointComponent}/mainFunction/template.ejs +24 -30
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/functionYaml/data.js +24 -22
  66. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +20 -0
  67. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/handler/data.js +7 -21
  68. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +84 -0
  69. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaCompleteComponent}/mainFunction/data.js +4 -15
  70. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +88 -0
  71. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/functionYaml/data.js +24 -22
  72. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/functionYaml/template.ejs +2 -0
  73. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/handler/data.js +6 -19
  74. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchemaComplete → FlowSchemaComponent}/handler/template.ejs +4 -3
  75. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/data.js +3 -1
  76. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/{flowSchema → FlowSchemaComponent}/mainFunction/template.ejs +3 -4
  77. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +96 -0
  78. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +53 -0
  79. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +77 -0
  80. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +207 -114
  81. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +36 -6
  82. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +3 -3
  83. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +3 -3
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +13 -14
  85. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +3 -3
@@ -0,0 +1,147 @@
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 } = 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
+ let functionName = upperCase(flowSchema.flowTag);
55
+ let handlerType = upperCase("hdrWbs");
56
+ let externalTopicName = FUNCTION_NAME.flowSchemaExternalTopic;
57
+ let externalTopicShortName = 'ExtTopic';
58
+ let functionConfig = upperCase(flowSchema.flowTag) + externalTopicShortName + upperCase(shortNameHandler(handlerType));
59
+ let additionalResourcePermission = defaultIamRolePerAction();
60
+ let route = "webSocket";
61
+
62
+ additionalResourcePermission.push(
63
+ createIamRole(
64
+ {
65
+ [RESOURCE_CLASSES.sns]: [
66
+ SNS_RESOURCE.publish
67
+ ]
68
+ },
69
+ [
70
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
71
+ ]
72
+ ),
73
+ createIamRole(
74
+ {
75
+ [RESOURCE_CLASSES.dynamoDbTable]: [
76
+ DYNAMO_RESOURCE.putItem,
77
+ DYNAMO_RESOURCE.getItem,
78
+ DYNAMO_RESOURCE.query,
79
+ DYNAMO_RESOURCE.deleteItem,
80
+ DYNAMO_RESOURCE.updateItem
81
+ ]
82
+ },
83
+ [
84
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
85
+ ]
86
+ ),
87
+ createIamRole(
88
+ {
89
+ "execute-api": [
90
+ "ManageConnections"
91
+ ]
92
+ },
93
+ [
94
+ resourceNames(RESOURCE_CLASSES.webSocket)
95
+ ]
96
+ )
97
+ )
98
+
99
+ if (flowSchema?.hook) {
100
+ for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
101
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
102
+ for (const hookFunction of hookProperties.functionList) {
103
+ if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
104
+ if (hookFunction?.permission) {
105
+ for (const permission of hookFunction.permission) {
106
+ additionalResourcePermission.push(
107
+ createIamRole(
108
+ permission.action,
109
+ permission.resource.map(resource =>
110
+ externalResourceYaml(
111
+ resource.resource,
112
+ resource.resourceName,
113
+ resource.serviceTag),
114
+ permission.effect
115
+ )
116
+ )
117
+ )
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
126
+ return {
127
+ templatePath: templatePath,
128
+ templateData: {
129
+ resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
130
+ functionName,
131
+ handlerType,
132
+ functionNameConfig: functionConfig,
133
+ additionalResourcePermission,
134
+ route,
135
+ roleName: SOURCE_GENERATE_IAM_ROLE.ExternalTopicRole,
136
+ externalTopicName
137
+ },
138
+ setting: {
139
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
140
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
141
+ fileExtension: ".yml",
142
+ isAppend: true
143
+ }
144
+ }
145
+ }
146
+
147
+ module.exports = data;
@@ -0,0 +1,18 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, functionName, `${firstLetterUpperCase(externalTopicName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
5
+ events:
6
+ - websocket:
7
+ route: <%- route %>
8
+ # authorizer: ${self:custom.iz_authorizerAppLevel}
9
+ # identifierResource: 'route.request.header.Auth'
10
+ role: <%- roleName %>Role
11
+ #<#<%- functionName %><%- handlerType %>IamRole#>
12
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
13
+ <%_ function firstLetterUpperCase(text){
14
+ return text.charAt(0).toUpperCase() + text.slice(1)
15
+ } _%>
16
+ <%_ function firstLetterLowerCase(str) {
17
+ return str.charAt(0).toLowerCase() + str.slice(1)
18
+ } _%>
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+ const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts");
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
25
+ const templatePath = path.join(__dirname, "template.ejs")
26
+
27
+ /**
28
+ * receive objectSchema
29
+ * create data for WebSocket handler template
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+ function data(_izContext, flowSchema, srcPath) {
35
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
36
+ }
37
+
38
+ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
39
+ // let functionName = upperCase(FUNCTION_NAME.createObjectS3)
40
+ let functionName = FUNCTION_NAME.flowSchemaExternalTopic
41
+ let handlerType = "HdrWbs"
42
+ let hook = false;
43
+ let hookFunctionName;
44
+ let isAsync = false;
45
+ const flowTag = flowSchema.flowTag
46
+ return {
47
+ templatePath: templatePath,
48
+ templateData: {
49
+ hook: hook,
50
+ hookFunctionName: hookFunctionName,
51
+ isAsync,
52
+ functionName: functionName,
53
+ fileName: upperCase(functionName),
54
+ flowTag
55
+ },
56
+ setting: {
57
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
58
+ saveFileName: `${upperCase(functionName)}_${handlerType}`,
59
+ fileExtension: ".js",
60
+ isAppend: false
61
+ }
62
+ }
63
+ }
64
+ module.exports = data
@@ -17,18 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- const izara = require("@izara_project/izara-middleware");
21
- const middleware = izara.middlewareHandler;
20
+ const { middlewareHandler, consts } = require("@izara_project/izara-middleware");
22
21
  // const AWS = require('aws-sdk');
23
22
  // const api = new AWS.ApiGatewayManagementApi({ endpoint: process.env.iz_webSocketEndpoint });
24
- const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb')
25
- const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow')
26
- const hash = require('object-hash')
23
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
24
+ const callingFlowSharedLib = require('@izara_project/izara-core-calling-flow');
25
+ const hash = require('object-hash');
27
26
  // const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
28
- const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
27
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts');
29
28
  const { postToConnection } = require("../../libs/source/ImportDataLib");
30
- const { flowSchemaOwnTopic } = require('./<%- `${functionName}_Main` %>');
31
- module.exports.main = middleware.wrap(async (event, context, callback) => {
29
+ const { <%- functionName%>Main } = require("./<%- fileName%>_Main");
30
+
31
+ module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
32
32
 
33
33
  event._izContext.logger.debug('Event:', event);
34
34
 
@@ -40,11 +40,8 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
40
40
  let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
41
41
 
42
42
  switch (route) {
43
- case '$default':
44
- console.log('Received unknown route:', route);
45
- break
46
- case '<%- route %>':
47
- console.log("event in route webSocket", event);
43
+ case '<%- flowTag%>':
44
+ console.log("event in route <%- flowTag%>", event);
48
45
  let eventParams = JSON.parse(event.body)
49
46
 
50
47
  await dynamodbSharedLib.putItem(
@@ -57,14 +54,14 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
57
54
  )
58
55
 
59
56
  let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
60
- await flowSchemaOwnTopic(
57
+
58
+ await <%- functionName%>Main(
61
59
  event._izContext,
62
60
  eventParams,
63
61
  callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
64
62
  //(<additionalParams>)
65
63
  //(</additionalParams>)
66
64
  )
67
-
68
65
  break
69
66
  }
70
67
  } else {
@@ -82,4 +79,8 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
82
79
  await postToConnection({ message: err.message }, connId);
83
80
  return (izara.response.failure(err));
84
81
  }
85
- });
82
+ });
83
+ <%_ const join = require('path').join _%>
84
+ <%_ function upperCase (text) {
85
+ return text.charAt(0).toUpperCase() + text.slice(1)
86
+ } _%>
@@ -0,0 +1,60 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/src/Consts");
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils");
24
+ const templatePath = path.join(__dirname, "template.ejs");
25
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
26
+
27
+ /**
28
+ * receive objectSchema
29
+ * create data for WebSocket Main template
30
+ *
31
+ * @param {Object} objectSchema
32
+ * @return {{templatePath, templateData,setting}}
33
+ */
34
+
35
+
36
+ function data(_izContext, flowSchema, srcPath) {
37
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
38
+ }
39
+
40
+ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
41
+ const functionName = upperCase(FUNCTION_NAME.flowSchemaExternalTopic)
42
+ const splitKey = Object.keys(flowSchema.flowSteps)[0].split('_')
43
+ // let objectSchema = await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(_izContext, flowSchema.objType)
44
+ // let fieldNames = Object.keys(objectSchema.fieldNames)
45
+ return {
46
+ templatePath: templatePath,
47
+ templateData: {
48
+ serviceTag: splitKey[0],
49
+ topicName: splitKey[3] + '_' + splitKey[4],
50
+ externalTopicMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Main',
51
+ },
52
+ setting: {
53
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag + '/'),
54
+ saveFileName: `${functionName}_Main`,
55
+ fileExtension: ".js",
56
+ isAppend: false
57
+ }
58
+ }
59
+ }
60
+ module.exports = data
@@ -0,0 +1,74 @@
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
16
+ <http: //www.gnu.org/licenses />.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ const hash = require("object-hash");
22
+ const { getObjectSchema } = require('@izara_project/izara-core-library-service-schemas');
23
+
24
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
25
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
26
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
27
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
28
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
29
+
30
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
31
+ const sns = externalRequest.sns
32
+
33
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
34
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
35
+ const { v4: uuidv4 } = require('uuid')
36
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
38
+ /**
39
+ *
40
+ *
41
+ * description of function.
42
+ * @param {Object} _izContext
43
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
44
+ * @param {Logger} _izContext.logger - property of _izContext
45
+ * @param {Object} requestParams - request params
46
+ * @param {Object} requestParams.identifiers - identifiers for get data
47
+ * @param {Object} requestParams.additionalRequest - additionalRequest
48
+ *
49
+ *
50
+ * @returns {object} description of return value
51
+ */
52
+
53
+ module.exports.<%- externalTopicMain%> = async (
54
+ _izContext,
55
+ requestParams,
56
+ callingFlowConfig = {},
57
+ //(<additionalParams>)
58
+ //(</additionalParams>)
59
+ ) => {
60
+
61
+ try {
62
+ // send message to ImportBatchCreateHdrSqs
63
+ let sendMessageToCreateEndpoint = {
64
+ Message: JSON.stringify(requestParams),
65
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, '<%- topicName%>', '<%- serviceTag%>')
66
+ }
67
+ _izContext.logger.debug("sendMessageToCreateEndpoint", sendMessageToCreateEndpoint);
68
+ await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
69
+
70
+ } catch (err) {
71
+ _izContext.logger.error('error WebSocketInvoke: ', err)
72
+ throw (err)
73
+ }
74
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+
21
+ const { FLOW_SCHEMA_HOOK_STATE, ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+ const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
23
+ const {
24
+ SOURCE_PATH,
25
+ defaultIamRolePerAction,
26
+ createIamRole,
27
+ RESOURCE_CLASSES,
28
+ SNS_RESOURCE,
29
+ resourceNames,
30
+ DYNAMO_RESOURCE,
31
+ SAVE_FILE_NAME,
32
+ FUNCTION_NAME,
33
+ shortNameHandler,
34
+ externalResourceYaml,
35
+ SOURCE_GENERATE_IAM_ROLE
36
+ } = require('../../../../../../MainLibs/src/Consts');
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('../../../../../../GenerateCodeLibs/src/Consts');
38
+
39
+ const templatePath = path.join(__dirname, "template.ejs");
40
+ const hookTemplate = path.join(__dirname, "./hookTemplate.ejs");
41
+ /**
42
+ * receive objectSchema
43
+ * create data for WebScoket handler template
44
+ *
45
+ * @param {Object} objectSchema
46
+ * @return {{templatePath, templateData,setting}}
47
+ */
48
+
49
+ function data(_izContext, flowSchema, srcPath) {
50
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
51
+ }
52
+
53
+ function createSourceParams(_izContext, flowSchema, srcPath) {
54
+ let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
55
+ let handlerType = upperCase(HANDLER.hdrSqs)
56
+ let additionalResourcePermission = defaultIamRolePerAction();
57
+ let flowSteps = Object.keys(flowSchema.flowSteps)
58
+ additionalResourcePermission.push(
59
+ createIamRole(
60
+ {
61
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
62
+ },
63
+ [
64
+ resourceNames(RESOURCE_CLASSES.sns, flowSteps[1])
65
+ ]
66
+ )
67
+ )
68
+
69
+
70
+ return {
71
+ templatePath: templatePath,
72
+ templateData: {
73
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaOwnTopic, flowSchema.flowTag, "source/"),
74
+ functionName,
75
+ handlerType,
76
+ additionalResourcePermission,
77
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
78
+ roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaOwnTopic
79
+ },
80
+ setting: {
81
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
82
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
83
+ fileExtension: ".yml",
84
+ isAppend: true
85
+ }
86
+ }
87
+ }
88
+
89
+ module.exports = data;
@@ -4,10 +4,10 @@
4
4
  name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
5
  events:
6
6
  - sqs:
7
- arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
8
8
  batchSize: 10
9
9
  filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
- - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%-firstLetterUpperCase(functionName) %>"]}}} # functionName of callingFlow
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
11
11
  - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
12
  role: <%- roleName %>Role
13
13
  #<#<%- functionName %><%- handlerType %>IamRole#>
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const { FLOW_SCHEMA_HOOK_STATE, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
21
+ const { SOURCE_PATH, FUNCTION_NAME } = require('../../../../../../MainLibs/src/Consts');
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
23
+ const templatePath = path.join(__dirname, "template.ejs")
24
+
25
+ /**
26
+ * receive objectSchema
27
+ * create data for WebScoket handler template
28
+ *
29
+ * @param {Object} objectSchema
30
+ * @return {{templatePath, templateData,setting}}
31
+ */
32
+
33
+
34
+ function data(_izContext, flowSchema, srcPath) {
35
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
36
+ }
37
+
38
+ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
39
+ let functionName = upperCase(FUNCTION_NAME.flowSchemaOwnTopicEndpointComplete)
40
+ let handlerType = upperCase(HANDLER.hdrSqs)
41
+ let queueName = upperCase(functionName) + upperCase(handlerType)
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ handlerType,
47
+ queueName
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaOwnTopic, flowSchema.flowTag, "source/"),
51
+ saveFileName: `${functionName}_${handlerType}`,
52
+ fileExtension: ".js",
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+ module.exports = data
@@ -0,0 +1,85 @@
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 AWS = require('aws-sdk');
21
+ // const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
22
+
23
+ const izara = require("@izara_project/izara-middleware");
24
+ const middleware = izara.middlewareHandler;
25
+ const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler")
26
+ const Logger = require('@izara_project/izara-core-library-logger');
27
+
28
+ const FlowSchemaOwnTopicEndpoint = require('./FlowSchemaOwnTopicEndpoint_Main')
29
+
30
+ // validate event properties in body.Message of sqs event
31
+ let perRecordsValidatorSchema = {}
32
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
33
+
34
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
35
+
36
+ try {
37
+
38
+ let recordPromises = [];
39
+
40
+ // loop each record and send to mainFunction
41
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
42
+
43
+ let passOnProperties = []
44
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
45
+
46
+ //validate message (and MessageAttributes)
47
+ await recordHandlerSharedLib.validateRecord(
48
+ record, // one record will send to mainFunction
49
+ "<%- queueName %>", // queue name that need to retry or send to dlq
50
+ perRecordsValidatorSchema, // schema for record.Message
51
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
52
+ );
53
+
54
+ // add argument (to invoke lambda) to passOnProperties[]
55
+ passOnProperties.push(record.body.Message)
56
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
57
+
58
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
59
+ let recordPromise = recordHandlerSharedLib.recordHandler(
60
+ record, // one record will send to mainFunction
61
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
62
+ "<%- queueName %>", // queue name that need to retry or send to dlq
63
+ passOnProperties, // all parameters that mainFunction needed.
64
+ );
65
+ record._izContext.logger.debug('after recordPromise in handler');
66
+ recordPromises.push(recordPromise); // push promise to recordPromises
67
+ }))
68
+
69
+ Logger.debug('before Promise.all(recordPromises) in handler');
70
+ try {
71
+ // --- main await all promises
72
+ await Promise.all(recordPromises); // await all promises
73
+
74
+ return event.Records // return all for local testing
75
+
76
+ } catch {
77
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
78
+ }
79
+ Logger.debug('after Promise.all(recordPromises) in handler');
80
+
81
+ } catch (err) {
82
+ Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
83
+ throw (err);
84
+ }
85
+ });