@izara_project/izara-market-library-service-schemas 1.0.15 → 1.0.17
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 +2 -2
- package/src/GenerateCodeLibs/src/Consts.js +3 -1
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +94 -73
- package/src/MainLibs/src/Utils.js +10 -9
- package/src/TemplateManager/src/GenerateCode.js +53 -12
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +86 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +33 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/data.js +59 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/template.ejs +129 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/data.js +53 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/template.ejs +130 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sns-out/data.js +62 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/data.js +58 -0
- package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/template.ejs +47 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +15 -7
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +14 -6
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +14 -4
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +14 -4
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +171 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/request.json +19 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/template.ejs +29 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/data.js +60 -0
- package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/template.ejs +10 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/data.js +76 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/template.ejs +141 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/data.js +56 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/template.ejs +55 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +40 -36
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +54 -22
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +59 -25
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +4 -0
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrApi/template.ejs +2 -1
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrDsq/template.ejs +1 -5
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrSqs/template.ejs +1 -5
- package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +11 -7
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +4 -0
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/mainFunction/template.ejs +1 -1
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrApi/template.ejs +5 -4
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrInv/template.ejs +3 -2
- package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/mainFunction/template.ejs +16 -13
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +9 -6
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +4 -0
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +8 -5
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +1 -1
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +10 -8
- package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +1 -1
- package/src/TemplateManager/src/ResourceYaml/dynamodb/{awaitingMultipleStepData.js → defaultDynamoDbTable.js} +39 -3
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +6 -3
- package/src/TemplateManager/src/externalService/FunctionNameConfig/data.js +1 -1
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +5 -10
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +14 -0
- package/src/TemplateManager/src/flowTag/resources/dynamoDb/data.js +65 -0
- package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/data.js +56 -0
- package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/template.ejs +10 -0
- package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/data.js +55 -0
- package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/template.ejs +63 -0
- package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/data.js +75 -0
- package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/template.ejs +33 -0
- package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/data.js +57 -0
- package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/template.ejs +131 -0
- package/src/TemplateManager/src/libs/Consts.js +7 -2
- package/src/TemplateManager/src/libs/GenerateCodeUtils.js +3 -1
- package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +0 -99
|
@@ -21,7 +21,7 @@ const fs = require('fs');
|
|
|
21
21
|
|
|
22
22
|
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
23
|
|
|
24
|
-
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
|
|
25
25
|
const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, SNS_RESOURCE, FUNCTION_NAME, DYNAMO_RESOURCE, defaultIamRolePerAction, awaitingMultipleStepsRole, shortNameHandler } = require("../../../libs/Consts");
|
|
26
26
|
|
|
27
27
|
const templatePath = path.join(__dirname, "./template.ejs")
|
|
@@ -35,13 +35,12 @@ const templatePath = path.join(__dirname, "./template.ejs")
|
|
|
35
35
|
*/
|
|
36
36
|
function data(_izContext, objectSchema, srcPath) {
|
|
37
37
|
let createSourceArray = [];
|
|
38
|
-
let newObjectSchema = renameObjectType(objectSchema, srcPath)
|
|
39
38
|
for (const action of Object.values(ACTIONS)) {
|
|
40
39
|
if (objectSchema.overWriteHandlers?.[action]) {
|
|
41
40
|
// if have overWriteHander of action check hdrApi inside
|
|
42
41
|
if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrSqs)) {
|
|
43
42
|
// create template data
|
|
44
|
-
const createSourceParam = createParamForCreateSource(
|
|
43
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
45
44
|
createSourceArray.push(createSourceParam)
|
|
46
45
|
}
|
|
47
46
|
} else {
|
|
@@ -49,7 +48,7 @@ function data(_izContext, objectSchema, srcPath) {
|
|
|
49
48
|
const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
|
|
50
49
|
if (defaultHandler.includes(HANDLER.hdrSqs)) {
|
|
51
50
|
// create template data and object for create source
|
|
52
|
-
const createSourceParam = createParamForCreateSource(
|
|
51
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
53
52
|
createSourceArray.push(createSourceParam)
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -150,6 +149,17 @@ function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
|
150
149
|
// ]
|
|
151
150
|
// )
|
|
152
151
|
// )
|
|
152
|
+
} else if (action === ACTIONS.get) {
|
|
153
|
+
additionalResourcePermission.push(
|
|
154
|
+
createIamRole(
|
|
155
|
+
{
|
|
156
|
+
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
157
|
+
},
|
|
158
|
+
[
|
|
159
|
+
resourceNames(RESOURCE_CLASSES.sns, "OutGetNodeComplete")
|
|
160
|
+
]
|
|
161
|
+
)
|
|
162
|
+
)
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
// console.log("additionalResourcePermissionBeforeReturn", additionalResourcePermission)
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
|
|
22
|
+
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
|
|
25
|
+
const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, SNS_RESOURCE, FUNCTION_NAME, DYNAMO_RESOURCE, defaultIamRolePerAction, awaitingMultipleStepsRole, shortNameHandler } = require("../../../libs/Consts");
|
|
26
|
+
|
|
27
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* receive objectSchema
|
|
31
|
+
* create data for hdrInv template
|
|
32
|
+
*
|
|
33
|
+
* @param {Object} objectSchema
|
|
34
|
+
* @return {{ templatePath, templateData, setting } }
|
|
35
|
+
*/
|
|
36
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
37
|
+
let createSourceArray = [];
|
|
38
|
+
for (const action of Object.values(ACTIONS)) {
|
|
39
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
40
|
+
// if have overWriteHander of action check hdrApi inside
|
|
41
|
+
if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrWbs)) {
|
|
42
|
+
// create template data
|
|
43
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
44
|
+
createSourceArray.push(createSourceParam)
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
// if not have overWriteHander of action will use default handler
|
|
48
|
+
const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
|
|
49
|
+
if (defaultHandler.includes(HANDLER.hdrWbs)) {
|
|
50
|
+
// create template data and object for create source
|
|
51
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
52
|
+
createSourceArray.push(createSourceParam)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return createSourceArray;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
62
|
+
let objectType = objectSchema.objectType;
|
|
63
|
+
let actionHandler = action;
|
|
64
|
+
let functionName = upperCase(objectType) + upperCase(actionHandler);
|
|
65
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
66
|
+
let tableForGetItem = [];
|
|
67
|
+
let hasGraphStorage = false;
|
|
68
|
+
let functionNameObjectType = objectSchema?.shortNameObjectType ? objectSchema.shortNameObjectType : objectSchema.objectType
|
|
69
|
+
let functionNameConfig = upperCase(functionNameObjectType) + upperCase(action) + upperCase(shortNameHandler(HANDLER.hdrWbs))
|
|
70
|
+
|
|
71
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
72
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
73
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
74
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
75
|
+
|
|
76
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
77
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
78
|
+
|
|
79
|
+
if (hasGraphStorage) {
|
|
80
|
+
continue;
|
|
81
|
+
} else {
|
|
82
|
+
hasGraphStorage = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
additionalResourcePermission.push(awaitingMultipleStepsRole())
|
|
87
|
+
|
|
88
|
+
additionalResourcePermission.push(
|
|
89
|
+
createIamRole(
|
|
90
|
+
{
|
|
91
|
+
[RESOURCE_CLASSES.dynamoDbTable]: [
|
|
92
|
+
DYNAMO_RESOURCE.getItem,
|
|
93
|
+
DYNAMO_RESOURCE.putItem,
|
|
94
|
+
DYNAMO_RESOURCE.deleteItem
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
[
|
|
98
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
|
|
99
|
+
]
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
additionalResourcePermission.push(
|
|
104
|
+
createIamRole(
|
|
105
|
+
{
|
|
106
|
+
["execute-api"]: ["ManageConnections"]
|
|
107
|
+
},
|
|
108
|
+
[
|
|
109
|
+
resourceNames(RESOURCE_CLASSES.webSocket)
|
|
110
|
+
]
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if (action == ACTIONS.update) {
|
|
116
|
+
additionalResourcePermission.push(
|
|
117
|
+
createIamRole(
|
|
118
|
+
{
|
|
119
|
+
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
120
|
+
},
|
|
121
|
+
[
|
|
122
|
+
resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(FUNCTION_NAME.updateNodeComplete))
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
} else if (action == ACTIONS.create) {
|
|
127
|
+
additionalResourcePermission.push(
|
|
128
|
+
createIamRole(
|
|
129
|
+
{
|
|
130
|
+
[RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
131
|
+
},
|
|
132
|
+
[
|
|
133
|
+
resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(FUNCTION_NAME.createObjectComplete))
|
|
134
|
+
]
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
} else if (action == ACTIONS.delete) {
|
|
138
|
+
// additionalResourcePermission.push(
|
|
139
|
+
// createIamRole(
|
|
140
|
+
// {
|
|
141
|
+
// [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
|
|
142
|
+
// },
|
|
143
|
+
// [
|
|
144
|
+
// resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(FUNCTION_NAME.createObjectComplete))
|
|
145
|
+
// ]
|
|
146
|
+
// )
|
|
147
|
+
// )
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// console.log("additionalResourcePermissionBeforeReturn", additionalResourcePermission)
|
|
151
|
+
return {
|
|
152
|
+
templatePath: templatePath,
|
|
153
|
+
templateData: {
|
|
154
|
+
functionName: functionName,
|
|
155
|
+
actionHandler: actionHandler,
|
|
156
|
+
resourceLocation: SOURCE_PATH.resourceLocationPerAction,
|
|
157
|
+
handlerType: HANDLER.hdrWbs,
|
|
158
|
+
additionalResourcePermission,
|
|
159
|
+
functionNameConfig,
|
|
160
|
+
objectType
|
|
161
|
+
},
|
|
162
|
+
setting: {
|
|
163
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
164
|
+
saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
|
|
165
|
+
fileExtension: '.yml',
|
|
166
|
+
isAppend: true
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
module.exports = data;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
- websocket:
|
|
7
|
+
route: <%- objectType -%><%- firstLetterUpperCase(actionHandler) %>
|
|
8
|
+
iamRoleStatements:
|
|
9
|
+
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
10
|
+
- Effect: <%- resourcePermission.effect %>
|
|
11
|
+
Action:
|
|
12
|
+
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
13
|
+
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
14
|
+
- <%- resourcePerAction %>:<%- permission %>
|
|
15
|
+
<%_ }) _%>
|
|
16
|
+
<%_ }) _%>
|
|
17
|
+
Resource:
|
|
18
|
+
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
19
|
+
- "<%- resource %>"
|
|
20
|
+
<%_ }) _%>
|
|
21
|
+
<%_}) _%>
|
|
22
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
23
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
24
|
+
<%_ function firstLetterUpperCase(text){
|
|
25
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
26
|
+
} _%>
|
|
27
|
+
<%_ function firstLetterLowerCase(str) {
|
|
28
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
29
|
+
} _%>
|
|
@@ -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
|
+
const path = require('path');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
|
|
22
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER } = require("../../../libs/Consts");
|
|
23
|
+
|
|
24
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* receive objectSchema
|
|
28
|
+
* create data for websocket connect function yaml template
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} objectSchema
|
|
31
|
+
* @return {{ templatePath, templateData, setting } }
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function data(_izContext, webSocketStatus, srcPath) {
|
|
35
|
+
let createSourceParam;
|
|
36
|
+
if (webSocketStatus) {
|
|
37
|
+
createSourceParam = [createWebSocketConnectYaml(_izContext, srcPath)]
|
|
38
|
+
} else {
|
|
39
|
+
createSourceParam = []
|
|
40
|
+
}
|
|
41
|
+
return createSourceParam
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createWebSocketConnectYaml(_izContext, srcPath) {
|
|
45
|
+
let functionName = "WebSocketConnect"
|
|
46
|
+
return {
|
|
47
|
+
templatePath: templatePath,
|
|
48
|
+
templateData: {
|
|
49
|
+
functionName,
|
|
50
|
+
resourceLocation: SOURCE_PATH.resourceLocationPerAction
|
|
51
|
+
},
|
|
52
|
+
setting: {
|
|
53
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
54
|
+
saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
|
|
55
|
+
fileExtension: ".yml",
|
|
56
|
+
isAppend: true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
module.exports = data
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
WebSocketConnect:
|
|
2
|
+
handler: src/generatedCode/ObjectTypePerActionEndpoint/source/WebSocketConnect.main
|
|
3
|
+
name: ${self:custom.iz_resourcePrefix}WebSocketConnect
|
|
4
|
+
events:
|
|
5
|
+
- websocket:
|
|
6
|
+
route: $connect
|
|
7
|
+
- websocket:
|
|
8
|
+
route: $disconnect
|
|
9
|
+
#<#<WebSocketConnectIamRole#>
|
|
10
|
+
#<#/<WebSocketConnectIamRole#>
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
|
|
22
|
+
const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
|
+
|
|
24
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase, checkOverWriteGenerateMainFunction } = require("../../../../../MainLibs/src/Utils")
|
|
25
|
+
const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
|
|
26
|
+
|
|
27
|
+
const templatePath = path.join(__dirname, "template.ejs")
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* receive objectSchema
|
|
31
|
+
* create data for WebScoket handler template
|
|
32
|
+
*
|
|
33
|
+
* @param {Object} objectSchema
|
|
34
|
+
* @return {{templatePath, templateData,setting}}
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
39
|
+
let createSourceArray = [];
|
|
40
|
+
for (const action of Object.values(ACTIONS)) {
|
|
41
|
+
if (objectSchema.overWriteHandlers?.[action]) {
|
|
42
|
+
if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrWbs)) {
|
|
43
|
+
const createSourceParams = createParamsForCreateSource(objectSchema, action, HANDLER.hdrWbs, srcPath)
|
|
44
|
+
createSourceParams && createSourceArray.push(createSourceParams);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
if (DEFAULT_HANDLER_PER_ACTION[action].includes(HANDLER.hdrWbs)) {
|
|
48
|
+
const createSourceParams = createParamsForCreateSource(objectSchema, action, HANDLER.hdrWbs, srcPath)
|
|
49
|
+
createSourceParams && createSourceArray.push(createSourceParams);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return createSourceArray;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createParamsForCreateSource(objectSchema, action, handler, srcPath) {
|
|
57
|
+
let objectType = objectSchema.objectType;
|
|
58
|
+
let functionName = objectType + upperCase(action)
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
templatePath: templatePath,
|
|
62
|
+
templateData: {
|
|
63
|
+
functionName,
|
|
64
|
+
objectType,
|
|
65
|
+
action,
|
|
66
|
+
isCreateMainFunction: checkOverWriteGenerateMainFunction(objectSchema, action)
|
|
67
|
+
},
|
|
68
|
+
setting: {
|
|
69
|
+
savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
|
|
70
|
+
saveFileName: `${upperCase(objectType)}${upperCase(action)}_${upperCase(handler)}`,
|
|
71
|
+
fileExtension: ".js",
|
|
72
|
+
isAppend: false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
module.exports = data
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2021 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const izara = require("@izara_project/izara-middleware");
|
|
21
|
+
const middleware = izara.middlewareHandler;
|
|
22
|
+
const AWS = require('aws-sdk');
|
|
23
|
+
const api = new AWS.ApiGatewayManagementApi({ endpoint: process.env.iz_webSocketEndpoint });
|
|
24
|
+
const izaraShared = require('@izara_project/izara-shared');
|
|
25
|
+
const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
|
|
26
|
+
const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
|
|
27
|
+
|
|
28
|
+
const { validateSchemaPerWebSocket } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs')
|
|
29
|
+
<%_ if (isCreateMainFunction == true) { _%>
|
|
30
|
+
// user generate main function
|
|
31
|
+
<%_ } else { %>
|
|
32
|
+
const <%- functionName %> =require('./<%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(action) %>_Main')
|
|
33
|
+
<%_ } _%>
|
|
34
|
+
|
|
35
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
36
|
+
|
|
37
|
+
event._izContext.logger.debug('Event:', event);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
|
|
43
|
+
let requestParams = JSON.parse(event.body);
|
|
44
|
+
await validateSchemaPerWebSocket(
|
|
45
|
+
event._izContext,
|
|
46
|
+
requestParams,
|
|
47
|
+
"<%- objectType -%>",
|
|
48
|
+
"<%- action -%>",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
if (event.requestContext) {
|
|
52
|
+
const route = event.requestContext.routeKey;
|
|
53
|
+
const connectionId = event.requestContext.connectionId;
|
|
54
|
+
const attribute = event.body;
|
|
55
|
+
event._izContext.logger.debug('body:', attribute);
|
|
56
|
+
event._izContext.logger.debug('route:', route);
|
|
57
|
+
event.body = JSON.parse(attribute)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
switch (route) {
|
|
62
|
+
case '$default':
|
|
63
|
+
console.log('Received unknown route:', route)
|
|
64
|
+
break
|
|
65
|
+
case '<%- objectType -%><%- firstLetterUpperCase(action) %>':
|
|
66
|
+
|
|
67
|
+
// create Web socket task for respond
|
|
68
|
+
await dynamodbSharedLib.putItem(
|
|
69
|
+
event._izContext,
|
|
70
|
+
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
71
|
+
{
|
|
72
|
+
taskKey: "<%- objectType -%>" + "<%- firstLetterUpperCase(action) %>", // objType + action
|
|
73
|
+
connectionid: connectionId,
|
|
74
|
+
// connectionid: event.body.connectionid,
|
|
75
|
+
//(<additionalParams>)
|
|
76
|
+
//(</additionalParams>)
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let payloadBeforeInvokeFunction = requestParams
|
|
81
|
+
// delete action before send to main function
|
|
82
|
+
delete payloadBeforeInvokeFunction.action
|
|
83
|
+
console.log("payloadBeforeInvokeFunction", payloadBeforeInvokeFunction)
|
|
84
|
+
event._izContext.logger.debug("event before send to <%- functionName %>Main", requestParams)
|
|
85
|
+
//(<beforeInvokeMain>)
|
|
86
|
+
//(</beforeInvokeMain>)
|
|
87
|
+
// invoke main
|
|
88
|
+
let invokeUpdateMainFunction = await <%- functionName %>.<%- functionName %>Main(
|
|
89
|
+
event._izContext,
|
|
90
|
+
payloadBeforeInvokeFunction,
|
|
91
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(attribute)
|
|
92
|
+
);
|
|
93
|
+
//(<afterInvokeMain>)
|
|
94
|
+
//(</afterInvokeMain>)
|
|
95
|
+
|
|
96
|
+
await postMessage(invokeUpdateMainFunction, connectionId);
|
|
97
|
+
|
|
98
|
+
break
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
console.log("not have event.requestContext")
|
|
104
|
+
const connId = event.connId;
|
|
105
|
+
await postMessage({ message: event.message }, connId);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.log("event", event)
|
|
111
|
+
const connId = event.requestContext.connectionId
|
|
112
|
+
event._izContext.logger.error('Error, WebSocket: ', err);
|
|
113
|
+
await sendErrorMessage({ message: err.message }, connId);
|
|
114
|
+
return (izara.response.failure(err));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async function postMessage(data, connectionId) {
|
|
120
|
+
const params = {
|
|
121
|
+
ConnectionId: connectionId,
|
|
122
|
+
Data: JSON.stringify(data),
|
|
123
|
+
// Data: Buffer.from(JSON.stringify(data)),
|
|
124
|
+
}
|
|
125
|
+
return api.postToConnection(params).promise();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
async function sendErrorMessage(errorMessage, connectionId) {
|
|
129
|
+
const params = {
|
|
130
|
+
ConnectionId: connectionId,
|
|
131
|
+
Data: JSON.stringify(errorMessage)
|
|
132
|
+
}
|
|
133
|
+
return api.postToConnection(params).promise();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
<%_ function firstLetterUpperCase(text){
|
|
137
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
138
|
+
} _%>
|
|
139
|
+
<%_ function firstLetterLowerCase(str) {
|
|
140
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
141
|
+
} _%>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2021 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
|
|
22
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER } = require("../../../libs/Consts");
|
|
23
|
+
|
|
24
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* receive objectSchema
|
|
28
|
+
* create data for websocket connect function yaml template
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} objectSchema
|
|
31
|
+
* @return {{ templatePath, templateData, setting } }
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function data(_izContext, webSocketStatus, srcPath) {
|
|
35
|
+
let createSourceParam;
|
|
36
|
+
if (webSocketStatus) {
|
|
37
|
+
createSourceParam = [createWebSocketConnectYaml(_izContext, srcPath)]
|
|
38
|
+
} else {
|
|
39
|
+
createSourceParam = []
|
|
40
|
+
}
|
|
41
|
+
return createSourceParam
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createWebSocketConnectYaml(_izContext, srcPath) {
|
|
45
|
+
return {
|
|
46
|
+
templatePath: templatePath,
|
|
47
|
+
templateData: {},
|
|
48
|
+
setting: {
|
|
49
|
+
savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
|
|
50
|
+
saveFileName: "WebSocketConnect",
|
|
51
|
+
fileExtension: ".js",
|
|
52
|
+
isAppend: true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
module.exports = data
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2021 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const izara = require("@izara_project/izara-middleware");
|
|
21
|
+
const middleware = izara.middlewareHandler;
|
|
22
|
+
const AWS = require('aws-sdk');
|
|
23
|
+
const api = new AWS.ApiGatewayManagementApi({ endpoint: process.env.iz_webSocketEndpoint });
|
|
24
|
+
|
|
25
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
26
|
+
|
|
27
|
+
event._izContext.logger.debug('Event:', event);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
|
|
31
|
+
if (event.requestContext) {
|
|
32
|
+
const route = event.requestContext.routeKey;
|
|
33
|
+
const connectionId = event.requestContext.connectionId;
|
|
34
|
+
|
|
35
|
+
switch (route) {
|
|
36
|
+
case '$connect':
|
|
37
|
+
console.log('Connect websocket')
|
|
38
|
+
break
|
|
39
|
+
case '$disconnect':
|
|
40
|
+
console.log('Websocket are Disconnection')
|
|
41
|
+
break
|
|
42
|
+
case '$default':
|
|
43
|
+
console.log('Received unknown route:', route)
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
return (izara.response.webSocketSuccess());
|
|
50
|
+
|
|
51
|
+
} catch (err) {
|
|
52
|
+
event._izContext.logger.error('Error, WebSocketConnect: ', err);
|
|
53
|
+
return (izara.response.failure(err));
|
|
54
|
+
}
|
|
55
|
+
});
|