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

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 (87) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +20 -6
  4. package/src/MainLibs/src/Consts.js +43 -10
  5. package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
  6. package/src/reStructure/GenerateCode.js +1 -0
  7. package/src/reStructure/SchemaConfig.js +1 -0
  8. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
  9. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
  10. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +3 -0
  11. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +28 -44
  12. package/src/reStructure/TemplateData/attributeTreeSchema/{mainAttributeTreeSchema → mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
  13. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTree/data.js +134 -0
  14. package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/data.js +172 -0
  15. package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
  16. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +1 -1
  17. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
  18. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
  19. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
  20. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
  21. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
  22. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +96 -0
  23. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
  24. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
  25. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
  26. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +138 -0
  27. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
  28. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
  29. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
  30. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
  31. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +133 -0
  32. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
  33. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +12 -0
  34. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +27 -0
  35. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +34 -0
  36. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
  37. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
  38. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +142 -0
  39. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
  40. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
  41. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +89 -0
  42. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
  43. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +120 -0
  44. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
  45. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
  46. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
  47. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
  48. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
  49. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +3 -6
  50. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +7 -9
  51. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +2 -2
  52. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +2 -2
  53. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
  54. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +8 -43
  55. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +1 -1
  56. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +2 -2
  57. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +1 -0
  58. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +7 -1
  59. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +18 -7
  60. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +3 -1
  61. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +7 -1
  62. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +52 -13
  63. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +2 -0
  64. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +3 -1
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +18 -18
  66. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +67 -6
  67. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +20 -0
  68. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +3 -3
  69. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +9 -3
  70. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +1 -1
  71. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +9 -3
  72. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +1 -1
  73. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +10 -4
  74. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +1 -1
  75. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +9 -3
  76. package/src/reStructure/TemplateData/propertyNodeSchema/generateTemplateData.js +66 -0
  77. package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/data.js +151 -0
  78. package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/templateObjectPropertyNodeSchema.ejs +16 -0
  79. package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/data.js +179 -0
  80. package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/templateRelationshipPropertyNodeSchema.ejs +7 -0
  81. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +1 -1
  82. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -5
  83. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +5 -5
  84. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +1 -1
  85. package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
  86. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
  87. /package/src/reStructure/TemplateData/attributeTreeSchema/{mainAttributeTreeSchema → mainAttributeTree}/request.json +0 -0
@@ -0,0 +1,172 @@
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 fs = require('fs');
21
+ const yaml = require("yaml")
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils");
23
+ const {
24
+ SOURCE_PATH,
25
+ ADD_ON_DATA_STRUCTURE_TYPE,
26
+ SAVE_FILE_NAME,
27
+ PREFIX_RELATIONSHIP,
28
+ ATTRIBUTE_TAG
29
+ // } = require('../../libs/Consts');
30
+ } = require('../../../../MainLibs/src/Consts');
31
+ const { createBasicRelationshipsProperties } = require("../../../../GenerateCodeLibs/src/GenerateCodeLibs");
32
+ const templatePath = path.join(__dirname, "./template.ejs");
33
+
34
+ const modules = {
35
+ validateAddOnDataStructure: require('../../../libs/ValidateAddOnDataStructure')
36
+ };
37
+
38
+ async function data(_izContext, settings, srcPath) {
39
+ let [returnValue, errorFounds] = await modules.validateAddOnDataStructure(_izContext, settings);
40
+
41
+ if (returnValue.hasOwnProperty("addOnAttributeTree") && errorFounds.length > 0) {
42
+ errorFounds.push(`Not have data addOnAttributeTree and have error:${errorFounds}`)
43
+ };
44
+
45
+ if (errorFounds.length > 0) {
46
+ throw Error(errorFounds)
47
+ };
48
+
49
+ const addOnAttributeTree = returnValue.addOnAttributeTree;
50
+
51
+ let generateRelationships = createSourceParams(
52
+ _izContext,
53
+ addOnAttributeTree,
54
+ returnValue.objectSchema,
55
+ srcPath
56
+ );
57
+ console.log("generateRelationship", generateRelationships)
58
+
59
+ return {
60
+ templatePath: templatePath,
61
+ templateData: { datas: generateRelationships },
62
+ setting: {
63
+ savePath: path.join(srcPath, SOURCE_PATH.generatedAttributeTree),
64
+ hookPath: path.join(srcPath, "schemaHook", "attributeTree", "/"),
65
+ saveFileName: SAVE_FILE_NAME.objectRelationship,
66
+ fileExtension: ".js",
67
+ isAppend: true
68
+ }
69
+ };
70
+
71
+ };
72
+
73
+
74
+ function createSourceParams(
75
+ _izContext,
76
+ addOnAttributeTree,
77
+ objectSchema,
78
+ srcPath
79
+ ) {
80
+ const attributeRelationships = [];
81
+ const objectType = objectSchema.objectType; // main objectType
82
+ const storageResources = objectSchema.storageResources // storageResource from main objectType
83
+ const configPath = path.join(srcPath, '../../config/serverless.config.yml');
84
+ const serverlessConfig = fs.readFileSync(configPath, 'utf8');
85
+ const config = yaml.parse(serverlessConfig);
86
+ const serviceTag = config.main_config.iz_serviceTag;
87
+
88
+
89
+ attributeRelationships.push(
90
+ {// has{atributeTag}Link
91
+ relationshipTag: PREFIX_RELATIONSHIP.has + upperCase(addOnAttributeTree.attributeTreeTag) + ATTRIBUTE_TAG.attributeTagLink,
92
+ relationshipProperties: createBasicRelationshipsProperties(
93
+ {
94
+ serviceTag: serviceTag,
95
+ objectType: objectType,
96
+ linkType: "one",
97
+ requiredOnCreate: false
98
+ },
99
+ {
100
+ serviceTag: serviceTag,
101
+ objectType: addOnAttributeTree.attributeTreeTag + ATTRIBUTE_TAG.attributeTagLink,
102
+ linkType: "many",
103
+ requiredOnCreate: true
104
+ },
105
+ storageResources,
106
+ "from"
107
+ )
108
+ },
109
+ {// disabled{atributeTag}Link
110
+ relationshipTag: PREFIX_RELATIONSHIP.disabled + upperCase(addOnAttributeTree.attributeTreeTag) + ATTRIBUTE_TAG.attributeTagLink,
111
+ relationshipProperties: createBasicRelationshipsProperties(
112
+ {
113
+ serviceTag: serviceTag,
114
+ objectType: objectType,
115
+ linkType: "one",
116
+ requiredOnCreate: false
117
+ },
118
+ {
119
+ serviceTag: serviceTag,
120
+ objectType: addOnAttributeTree.attributeTreeTag + ATTRIBUTE_TAG.attributeTagLink,
121
+ linkType: "many",
122
+ requiredOnCreate: true
123
+ },
124
+ storageResources,
125
+ "from"
126
+ )
127
+ },
128
+ {// is{atributeTag}
129
+ relationshipTag: PREFIX_RELATIONSHIP.is + upperCase(addOnAttributeTree.attributeTreeTag),
130
+ relationshipProperties: createBasicRelationshipsProperties(
131
+ {
132
+ serviceTag: serviceTag,
133
+ objectType: addOnAttributeTree.attributeTreeTag + ATTRIBUTE_TAG.attributeTagLink,
134
+ linkType: "one",
135
+ requiredOnCreate: true
136
+ },
137
+ {
138
+ serviceTag: serviceTag,
139
+ objectType: addOnAttributeTree.attributeTreeTag,
140
+ linkType: "many",
141
+ requiredOnCreate: false
142
+ },
143
+ storageResources,
144
+ "from"
145
+ )
146
+ },
147
+ { // is{atributeTag}Label
148
+ relationshipTag: PREFIX_RELATIONSHIP.is + upperCase(addOnAttributeTree.attributeTreeTag) + ATTRIBUTE_TAG.attributeTagLabel,
149
+ relationshipProperties: createBasicRelationshipsProperties(
150
+ {
151
+ serviceTag: serviceTag,
152
+ objectType: addOnAttributeTree.attributeTreeTag,
153
+ linkType: "many",
154
+ requiredOnCreate: true
155
+ },
156
+ {
157
+ serviceTag: serviceTag,
158
+ objectType: addOnAttributeTree.attributeTreeTag + ATTRIBUTE_TAG.attributeTagLabel,
159
+ linkType: "one",
160
+ requiredOnCreate: false
161
+ },
162
+ storageResources,
163
+ "from"
164
+ )
165
+ }
166
+
167
+
168
+ )
169
+ return attributeRelationships
170
+ }
171
+
172
+ module.exports = data
@@ -0,0 +1,7 @@
1
+ module.exports = [
2
+ <% datas.forEach(data => { %>
3
+ {
4
+ <%- data.relationshipTag %>: <%- JSON.stringify(data.relationshipProperties,null,2) %>
5
+ },
6
+ <% }) %>
7
+ ]
@@ -131,7 +131,7 @@ async function externalLambdaIamRoleDataPerAction(_izContext, allObjSchemas) {
131
131
 
132
132
 
133
133
  return {
134
- objectType: SOURCE_GENERATE_IAM_ROLE.perActionEndpoint,
134
+ objectType: SOURCE_GENERATE_IAM_ROLE.PerActionEndpoint,
135
135
  additionalResourcePermission
136
136
  }
137
137
  }
@@ -0,0 +1,123 @@
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
+ FLOW_SCHEMA_EVENT_TYPE
37
+ } = require('../../../../../MainLibs/src/Consts');
38
+
39
+ const templatePath = path.join(__dirname, "template.ejs");
40
+ /**
41
+ * receive objectSchema
42
+ * create data for WebScoket handler template
43
+ *
44
+ * @param {Object} objectSchema
45
+ * @return {{templatePath, templateData,setting}}
46
+ */
47
+
48
+ function data(_izContext, flowSchema, srcPath) {
49
+ return [createSourceParams(_izContext, flowSchema, srcPath)]
50
+ }
51
+
52
+ function createSourceParams(_izContext, flowSchema, srcPath) {
53
+ let functionName = upperCase(FUNCTION_NAME.createRecordComplete) + upperCase(flowSchema.flowTag)
54
+ let handlerType = upperCase(HANDLER.hdrSqs)
55
+ let additionalResourcePermission = defaultIamRolePerAction();
56
+ let flowSteps = Object.keys(flowSchema.flowSteps)
57
+ // let splitFlowSteps = flowSteps[0].split("_")
58
+ let topicArn;
59
+ // let serviceTag;
60
+ for (const event of flowSchema.event) {
61
+ if (event.includes(FLOW_SCHEMA_EVENT_TYPE.ownTopic)) {
62
+ topicArn = flowSteps[0]
63
+ } else {
64
+ return
65
+ }
66
+ }
67
+
68
+ additionalResourcePermission.push(
69
+ createIamRole(
70
+ {
71
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
72
+ },
73
+ [
74
+ resourceNames(RESOURCE_CLASSES.sns, topicArn)
75
+ ]
76
+ )
77
+ )
78
+
79
+ additionalResourcePermission.push(
80
+ createIamRole(
81
+ {
82
+ [RESOURCE_CLASSES.dynamoDbTable]: [DYNAMO_RESOURCE.updateItem]
83
+ },
84
+ [
85
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
86
+ ]
87
+ )
88
+ )
89
+ // external lambda role
90
+ // if (serviceTag) {
91
+ // additionalResourcePermission.push(
92
+ // createIamRole(
93
+ // {
94
+ // [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
95
+ // },
96
+ // [
97
+ // externalResourceYaml(RESOURCE_CLASSES.sns, topicArn, serviceTag)
98
+ // ]
99
+ // )
100
+ // )
101
+ // }
102
+ console.log({ additionalResourcePermission: JSON.stringify(additionalResourcePermission, null, 2) })
103
+
104
+ return {
105
+ templatePath: templatePath,
106
+ templateData: {
107
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationCreateRecordComplete, flowSchema.flowTag, "source/"),
108
+ functionName,
109
+ handlerType,
110
+ additionalResourcePermission,
111
+ functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
112
+ roleName: SOURCE_GENERATE_IAM_ROLE.CreateRecordComplete
113
+ },
114
+ setting: {
115
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
116
+ saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
117
+ fileExtension: ".yml",
118
+ isAppend: true
119
+ }
120
+ }
121
+ }
122
+
123
+ module.exports = data;
@@ -0,0 +1,20 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
+ role: <%- roleName %>Role
13
+ #<#<%- functionName %><%- handlerType %>IamRole#>
14
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
15
+ <%_ function firstLetterUpperCase(text){
16
+ return text.charAt(0).toUpperCase() + text.slice(1)
17
+ } _%>
18
+ <%_ function firstLetterLowerCase(str) {
19
+ return str.charAt(0).toLowerCase() + str.slice(1)
20
+ } _%>
@@ -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.createRecordComplete);
40
+ let handlerType = upperCase(HANDLER.hdrSqs)
41
+ let queueName = upperCase(FUNCTION_NAME.createRecordComplete) + upperCase(flowSchema.flowTag) + upperCase(HANDLER.hdrSqs)
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ handlerType,
47
+ queueName
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.createRecordComplete, 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
+ });
@@ -0,0 +1,68 @@
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 { SOURCE_PATH, FUNCTION_NAME, FLOW_SCHEMA_EVENT_TYPE } = require('../../../../../MainLibs/src/Consts');
22
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
23
+ const templatePath = path.join(__dirname, "template.ejs");
24
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
25
+
26
+ /**
27
+ * receive objectSchema
28
+ * create data for WebScoket handler template
29
+ *
30
+ * @param {Object} objectSchema
31
+ * @return {{templatePath, templateData,setting}}
32
+ */
33
+
34
+
35
+ function data(_izContext, flowSchema, srcPath) {
36
+ return [createParamsForCreateSource(_izContext, flowSchema, srcPath)]
37
+ }
38
+
39
+ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
40
+ let functionName = upperCase(FUNCTION_NAME.createRecordComplete)
41
+ let flowSteps = Object.keys(flowSchema.flowSteps)
42
+ let splitFlowSteps = flowSteps[0].split("_")
43
+ let topicArn;
44
+ let serviceTag;
45
+ for (const event of flowSchema.event) {
46
+ if (event.includes(FLOW_SCHEMA_EVENT_TYPE.ownTopic)) {
47
+ topicArn = flowSteps[0]
48
+ } else if (event.includes(FLOW_SCHEMA_EVENT_TYPE.extTopic)) {
49
+ topicArn = splitFlowSteps[3] + "_" + splitFlowSteps[4]
50
+ serviceTag = splitFlowSteps[0]
51
+ }
52
+ }
53
+ return {
54
+ templatePath: templatePath,
55
+ templateData: {
56
+ topicArn,
57
+ serviceTag
58
+ },
59
+ setting: {
60
+ savePath: path.join(srcPath, SOURCE_PATH.createRecordComplete, flowSchema.flowTag, 'source/'),
61
+ saveFileName: `${functionName}_Main`,
62
+ fileExtension: ".js",
63
+ isAppend: false
64
+ }
65
+ }
66
+ }
67
+
68
+ module.exports = data
@@ -0,0 +1,96 @@
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/src/GetObjectSchema');
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
+ const { postToConnection } = require("../../../../libs/source/GenerateCodeLibs");
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.createRecordComplete = async (
54
+ _izContext,
55
+ requestParams,
56
+ callingFlowConfig = {},
57
+ //(<additionalParams>)
58
+ //(</additionalParams>)
59
+ ) => {
60
+
61
+ try {
62
+ _izContext.logger.debug("createRecordComplete _izContext", _izContext)
63
+ _izContext.logger.debug("createRecordComplete requestParams", requestParams)
64
+ _izContext.logger.debug("createRecordComplete callingFlowConfig", callingFlowConfig)
65
+
66
+ //(<endpointCompleteHookMainFunction>)
67
+ //(</endpointCompleteHookMainFunction>)
68
+
69
+ await dynamodbSharedLib.updateItem(_izContext,
70
+ await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
71
+ {
72
+ taskKey: _izContext.correlationIds.get(coreConsts.X_CORRELATION_ID),
73
+ connectionId: _izContext.correlationIds.get(coreConsts.CONNECTION_ID)
74
+ },
75
+ {
76
+ identifiersTask: requestParams.objInstaceFull.identifiers
77
+ }
78
+ )
79
+
80
+ let messageObject = {
81
+ //(<messageObjectHook>)
82
+ //(</messageObjectHook>)
83
+ }
84
+
85
+ let sendMessageToOutFlowSchema = {
86
+ Message: JSON.stringify(messageObject),
87
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- topicArn %>", <% if (serviceTag) { %> "<%- serviceTag %>" <% } %> %>)
88
+ };
89
+ _izContext.logger.debug("before sendMessageToOutFlowSchema::", sendMessageToOutFlowSchema);
90
+ await sns.publishAsync(_izContext, sendMessageToOutFlowSchema)
91
+
92
+ } catch (err) {
93
+ _izContext.logger.error('error FlowSchemaOwnTopicEndpointComplete: ', err)
94
+ throw (err)
95
+ }
96
+ }