@izara_project/izara-market-library-service-schemas 1.0.34 → 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.
- package/package.json +1 -1
- package/src/GenerateCodeLibs/src/Consts.js +2 -1
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +5 -5
- package/src/MainLibs/src/Consts.js +43 -10
- package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
- package/src/reStructure/GenerateCode.js +1 -0
- package/src/reStructure/SchemaConfig.js +1 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +3 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +28 -44
- package/src/reStructure/TemplateData/attributeTreeSchema/{mainAttributeTreeSchema → mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTree/data.js +134 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/data.js +172 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +96 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
- package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +138 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +133 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +12 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +19 -6
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +19 -2
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +142 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +89 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +120 -0
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
- package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
- package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
- package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +3 -6
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +7 -9
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +8 -43
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +1 -0
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +7 -1
- package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +18 -7
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +7 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +52 -13
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +2 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +1 -6
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +1 -29
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +67 -6
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +20 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/generateTemplateData.js +66 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/data.js +151 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/templateObjectPropertyNodeSchema.ejs +16 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/data.js +179 -0
- package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/templateRelationshipPropertyNodeSchema.ejs +7 -0
- package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
- /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,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;
|
package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs
ADDED
|
@@ -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
|
package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs
ADDED
|
@@ -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
|
+
}
|