@izara_project/izara-market-library-service-schemas 1.0.29 → 1.0.30
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 +10 -9
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +54 -21
- package/src/MainLibs/src/Consts.js +33 -17
- package/src/reStructure/GenerateCode.js +2 -1
- package/src/reStructure/TemplateConfig.js +5 -1
- package/src/reStructure/TemplateData/EndpointPerService/generateTemplateData.js +108 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/data.js +76 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/request.json +7 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +73 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/data.js +81 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/request.json +7 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/template.ejs +125 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/data.js +70 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/request.json +7 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +73 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/data.js +79 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/request.json +7 -0
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/template.ejs +126 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/data.js +53 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +624 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/data.js +52 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +177 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/data.js +56 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +234 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/data.js +56 -0
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +330 -0
- package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +175 -0
- package/src/reStructure/TemplateData/EndpointPerService/yaml/template.ejs +26 -0
- package/src/reStructure/TemplateData/externalService/generateTemplateData.js +1 -1
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +91 -249
- package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +1 -1
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +10 -8
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +1 -1
- package/src/reStructure/TemplateData/findData/findDataYaml/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +4 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +3 -29
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/data.js +3 -21
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +3 -31
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/data.js +41 -10
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/template.ejs +3 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/{hook/handler/templateAsyncHandler.ejs → preSignUrl/createPresignUrl/handler/template.ejs} +26 -11
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/mainFunction/data.js +10 -7
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +253 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +10 -38
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +0 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/data.js +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +40 -45
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +7 -10
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +100 -190
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/data.js +4 -4
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +8 -6
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/queue/s3Template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/S3/data.js +5 -2
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +41 -38
- package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/queue/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +11 -1
- package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +35 -44
- package/src/reStructure/TemplateData/perActionComplete/create/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +4 -5
- package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +5 -4
- package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +15 -2
- package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +7 -4
- package/src/reStructure/TemplateData/perActionComplete/update/sns-out/data.js +1 -1
- package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +5 -4
- package/src/reStructure/TemplateData/processLogical/yaml/data.js +3 -3
- package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +1 -1
- package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +3 -3
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/sns-in-sqs/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-in-sqs/template.ejs +0 -1
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +3 -3
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/sns-in-sqs/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +4 -4
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +4 -4
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/sns-in-sqs/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +1 -1
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +1 -1
- package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +1 -1
- package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +6 -12
- package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +1 -1
- package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsAndSqsPerActionData.js +22 -49
- package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsTemplate.ejs +1 -1
- package/src/reStructure/TemplateData/resourceYaml/sns-out/data.js +8 -24
- package/src/reStructure/TemplateData/resourceYaml/sns-out/template.ejs +1 -1
- package/src/reStructure/TemplateData/testTemplate/template.ejs +0 -5
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/data.js +0 -93
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/templateSyncHandler.ejs +0 -49
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/hookLogic/data.js +0 -43
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/data.js +0 -65
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/template.ejs +0 -7
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/data.js +0 -72
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/snsTemplate.ejs +0 -59
- package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/sqsTemplate.ejs +0 -43
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +0 -120
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +0 -163
- package/src/reStructure/TemplateData/relationshipPerAction.zip +0 -0
- /package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/template.ejs +0 -0
|
@@ -0,0 +1,330 @@
|
|
|
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 {
|
|
23
|
+
getObjSchemaS3WithHierarchy,
|
|
24
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
25
|
+
const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
26
|
+
const {
|
|
27
|
+
dynamoDbIdentifiersByStorageResource,
|
|
28
|
+
createFieldForUpdateDynamoDb
|
|
29
|
+
} = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
|
|
30
|
+
const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
|
|
31
|
+
const snsSharedLib = require('@izara_project/izara-core-library-sns');
|
|
32
|
+
const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
|
|
33
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
34
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
|
|
35
|
+
|
|
36
|
+
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
37
|
+
const sns = externalRequest.sns
|
|
38
|
+
|
|
39
|
+
const { createUpdateDataDetail } = require("@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs")
|
|
40
|
+
const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
|
|
41
|
+
const coreConsts = require('@izara_project/izara-core-library-core/src/Consts')
|
|
42
|
+
const { createObjType } = require("@izara_project/izara-core-library-service-schemas/src/Utils")
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
* description of function.
|
|
47
|
+
* @param {Object} _izContext
|
|
48
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
49
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
50
|
+
* @param {Object} requestParams - request params
|
|
51
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
52
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
53
|
+
*
|
|
54
|
+
*
|
|
55
|
+
* @returns {object} description of return value
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
module.exports.updateMain = async (
|
|
59
|
+
_izContext,
|
|
60
|
+
requestParams,
|
|
61
|
+
callingFlowConfig = {},
|
|
62
|
+
//(<additionalParams>)
|
|
63
|
+
//(</additionalParams>)
|
|
64
|
+
) => {
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
_izContext.logger.debug('function UpdateMain: ', {
|
|
68
|
+
requestParams,
|
|
69
|
+
callingFlowConfig
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
let errorFounds = [];
|
|
73
|
+
const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
|
|
74
|
+
const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
|
|
75
|
+
|
|
76
|
+
if (!userId) {
|
|
77
|
+
errorFounds.push("Not have userId")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//(<beforeQuery>)
|
|
81
|
+
//(</beforeQuery>)
|
|
82
|
+
|
|
83
|
+
const identifiers = requestParams.objInstanceFull.identifiers;
|
|
84
|
+
const fields = requestParams.objInstanceFull.fields
|
|
85
|
+
let versionedDataIds = requestParams.versionedDataIds || {}
|
|
86
|
+
|
|
87
|
+
_izContext.logger.debug("explode requestParams", {
|
|
88
|
+
identifiers: identifiers,
|
|
89
|
+
fields: fields,
|
|
90
|
+
versionedDataIds: versionedDataIds
|
|
91
|
+
})
|
|
92
|
+
const objType = createObjType(requestParams.objectType);
|
|
93
|
+
let objectSchema = await getObjSchemaS3WithHierarchy(
|
|
94
|
+
_izContext,
|
|
95
|
+
objType
|
|
96
|
+
)
|
|
97
|
+
_izContext.logger.debug("objectSchema", objectSchema);
|
|
98
|
+
|
|
99
|
+
if (objectSchema.hasOwnProperty("belongTo") && !targetId) {
|
|
100
|
+
errorFounds.push('not have targetId')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let updateDataDetails = await createUpdateDataDetail(_izContext, objectSchema);
|
|
104
|
+
|
|
105
|
+
_izContext.logger.debug("updateDataDetails", updateDataDetails);
|
|
106
|
+
|
|
107
|
+
let originTimestamp = Date.now();
|
|
108
|
+
|
|
109
|
+
let haveVersionedDataIdsToUpdate = (requestParams.versionedDataIds && Object.keys(requestParams.versionedDataIds).length) ? true : false
|
|
110
|
+
if (haveVersionedDataIdsToUpdate) {
|
|
111
|
+
|
|
112
|
+
let updateMainNodeData = {};
|
|
113
|
+
let updateVersionedData = {};
|
|
114
|
+
_izContext.logger.debug("have versionedDataIds to update")
|
|
115
|
+
for (const fieldProp in requestParams.objInstanceFull.fields) {
|
|
116
|
+
const fieldSetting = objectSchema.fieldNames[fieldProp];
|
|
117
|
+
// collect updateData
|
|
118
|
+
if (fieldSetting.hasOwnProperty("versionedDataLabel")) {
|
|
119
|
+
if (!updateVersionedData.hasOwnProperty(fieldSetting.versionedDataLabel)) {
|
|
120
|
+
updateVersionedData[fieldSetting.versionedDataLabel] = {};
|
|
121
|
+
}
|
|
122
|
+
Object.assign(updateVersionedData[fieldSetting.versionedDataLabel], {
|
|
123
|
+
[fieldProp]: requestParams.objInstanceFull.fields[fieldProp]
|
|
124
|
+
})
|
|
125
|
+
} else {
|
|
126
|
+
Object.assign(updateMainNodeData, {
|
|
127
|
+
[fieldProp]: requestParams.objInstanceFull.fields[fieldProp]
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
_izContext.logger.debug("updateMainNodeData::", updateMainNodeData);
|
|
132
|
+
_izContext.logger.debug("updateVersionedData::", updateVersionedData);
|
|
133
|
+
|
|
134
|
+
const versionedDataIdLabelKeys = Object.keys(requestParams.versionedDataIds);
|
|
135
|
+
const updateVersionedDataLabelKeys = Object.keys(updateVersionedData);
|
|
136
|
+
|
|
137
|
+
_izContext.logger.debug("versionedDataIdLabelKeys:: ", versionedDataIdLabelKeys);
|
|
138
|
+
_izContext.logger.debug("updateVersionedDataLabelKeys:: ", updateVersionedDataLabelKeys);
|
|
139
|
+
//check missing versionedDataIds
|
|
140
|
+
const missingVersionedDataIdLabels = updateVersionedDataLabelKeys.filter(label => !versionedDataIdLabelKeys.includes(label));
|
|
141
|
+
_izContext.logger.debug("missingVersionedDataIdLabels:: ", missingVersionedDataIdLabels);
|
|
142
|
+
|
|
143
|
+
if (missingVersionedDataIdLabels.length) {
|
|
144
|
+
errorFounds.push(`missing versionedDataIds of versionedDataLabel '${missingVersionedDataIdLabels.join(", ")}'`)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// check missing update data of versionedDataLabels
|
|
148
|
+
const missingDataVersionedDataLabels = versionedDataIdLabelKeys.filter(label => !versionedDataIdLabelKeys.includes(label))
|
|
149
|
+
if (missingDataVersionedDataLabels.length) {
|
|
150
|
+
errorFounds.push(`missing data of versionedDataLabels '${missingDataVersionedDataLabels.join(", ")}'`);
|
|
151
|
+
}
|
|
152
|
+
// check mainNode Data should not exists
|
|
153
|
+
if (Object.keys(updateMainNodeData).length) {
|
|
154
|
+
errorFounds.push("cannot update mainNode if have versionedDataIds");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let messageAttributes
|
|
159
|
+
|
|
160
|
+
if (errorFounds.length) {
|
|
161
|
+
let updateNodeCompleteMessage = {
|
|
162
|
+
objType: objType,
|
|
163
|
+
objInstanceFull: {
|
|
164
|
+
identifiers: identifiers,
|
|
165
|
+
fields: fields,
|
|
166
|
+
},
|
|
167
|
+
versionedDataIds: versionedDataIds,
|
|
168
|
+
status: 'error',
|
|
169
|
+
errorFounds: errorFounds
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
updateNodeCompleteMessage = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, updateNodeCompleteMessage);
|
|
174
|
+
messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {})
|
|
175
|
+
|
|
176
|
+
let messageParams = {
|
|
177
|
+
Message: JSON.stringify(updateNodeCompleteMessage),
|
|
178
|
+
MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
|
|
179
|
+
TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete),
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
_izContext.logger.debug("messageParams OutUpdateNodeComplete ::::::: ", messageParams);
|
|
183
|
+
await sns.publishAsync(_izContext, messageParams);
|
|
184
|
+
|
|
185
|
+
return updateNodeCompleteMessage
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let awaitingStepIds = [];
|
|
189
|
+
|
|
190
|
+
// start update data
|
|
191
|
+
await Promise.all(
|
|
192
|
+
Object.entries(updateDataDetails).map(
|
|
193
|
+
async ([storageTag, updateDataDetail]) => {
|
|
194
|
+
if (updateDataDetail.storageType === consts.STORAGE_TYPES.graph) {
|
|
195
|
+
// let graphServiceName = await getGraphServiceTagWithCache(_izContext, getDataDetail.graphServiceTag)
|
|
196
|
+
|
|
197
|
+
awaitingStepIds.push( // createAwaitingstepId if updateGraph
|
|
198
|
+
asyncFlowSharedLib.createAwaitingStepId(
|
|
199
|
+
hash({
|
|
200
|
+
objectType: objType.objectType,
|
|
201
|
+
serviceTag: objType.serviceTag,
|
|
202
|
+
identifiers: identifiers,
|
|
203
|
+
fields: fields,
|
|
204
|
+
// correlationIds: _izContext.correlationIds.get("id")
|
|
205
|
+
}),
|
|
206
|
+
PREFIX.updateNode
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
_izContext.logger.debug("awaitingStepIds", awaitingStepIds)
|
|
210
|
+
|
|
211
|
+
if (awaitingStepIds.length) {
|
|
212
|
+
let awaitingMultipleStep = await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
213
|
+
_izContext,
|
|
214
|
+
awaitingStepIds,
|
|
215
|
+
asyncFlowSharedLib.createPendingStepId(
|
|
216
|
+
hash(
|
|
217
|
+
{
|
|
218
|
+
identifiers,
|
|
219
|
+
fields,
|
|
220
|
+
})
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
_izContext.logger.debug("awaitingMultipleStep", awaitingMultipleStep)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let updateNodeParams = {
|
|
227
|
+
objType: objType,
|
|
228
|
+
objInstanceFull: {
|
|
229
|
+
identifiers: identifiers,
|
|
230
|
+
fields: fields,
|
|
231
|
+
},
|
|
232
|
+
versionedDataIds: versionedDataIds,
|
|
233
|
+
originTimestamp
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
updateNodeParams = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
237
|
+
updateNodeParams,
|
|
238
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
239
|
+
callingFlowConfig,
|
|
240
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
241
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateNodeComplete), {}
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
_izContext.logger.debug("messageObject before send message:", updateNodeParams);
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
let updateNodeMessageBody = {
|
|
250
|
+
Message: JSON.stringify(updateNodeParams),
|
|
251
|
+
MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
|
|
252
|
+
TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inUpdateNode, storageTag,)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_izContext.logger.debug('requset param before send to topic InUpdateNode:::', updateNodeMessageBody);
|
|
256
|
+
|
|
257
|
+
let resSNS = await sns.publishAsync(_izContext, updateNodeMessageBody)
|
|
258
|
+
_izContext.logger.debug('resSNS send to topic InUpdateNode finish!', resSNS);
|
|
259
|
+
|
|
260
|
+
} else if (updateDataDetail.storageType === consts.STORAGE_TYPES.dynamoDB) {
|
|
261
|
+
|
|
262
|
+
let identifiersForUpdateData = await dynamoDbIdentifiersByStorageResource(
|
|
263
|
+
_izContext,
|
|
264
|
+
objectSchema,
|
|
265
|
+
updateDataDetail,
|
|
266
|
+
identifiers
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
let fieldForUpdateTableDynamo = createFieldForUpdateDynamoDb(_izContext, objectSchema, updateDataDetail, fields)
|
|
270
|
+
|
|
271
|
+
_izContext.logger.debug("identifiersForUpdateData", identifiersForUpdateData)
|
|
272
|
+
_izContext.logger.debug("fieldForUpdateTableDynamo", fieldForUpdateTableDynamo)
|
|
273
|
+
|
|
274
|
+
let updateItem = await dynamodbSharedLib.updateItem(
|
|
275
|
+
_izContext,
|
|
276
|
+
await dynamodbSharedLib.tableName(_izContext, updateDataDetail.tableName),
|
|
277
|
+
identifiersForUpdateData,
|
|
278
|
+
fieldForUpdateTableDynamo,
|
|
279
|
+
{
|
|
280
|
+
returnValues: "ALL_NEW"
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
_izContext.logger.debug("updateItem:", updateItem);
|
|
284
|
+
|
|
285
|
+
if (awaitingStepIds.length == 0) {
|
|
286
|
+
let messageObject = {
|
|
287
|
+
objType: objType,
|
|
288
|
+
updateItem
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOWPROPERTIES_PROPERTYNAME]) {
|
|
292
|
+
_izContext.logger.debug("HAVE CALLINGFLOW");
|
|
293
|
+
|
|
294
|
+
messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
|
|
295
|
+
let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
|
|
296
|
+
|
|
297
|
+
_izContext.logger.debug("after create callingFlow", messageObject)
|
|
298
|
+
let outUpdateNodeCompleteTopic = await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete);
|
|
299
|
+
let messageParams = {
|
|
300
|
+
Message: JSON.stringify(messageObject),
|
|
301
|
+
MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
|
|
302
|
+
TopicArn: outUpdateNodeCompleteTopic
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
_izContext.logger.debug("message params OutUpdateNodeComplete :::", messageParams);
|
|
306
|
+
await sns.publishAsync(_izContext, messageParams);
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
)
|
|
314
|
+
return {
|
|
315
|
+
returnValues: {
|
|
316
|
+
objType: objType,
|
|
317
|
+
objInstanceFull: {
|
|
318
|
+
identifiers: identifiers,
|
|
319
|
+
fields: fields,
|
|
320
|
+
},
|
|
321
|
+
versionedDataIds: versionedDataIds
|
|
322
|
+
},
|
|
323
|
+
status: "complete",
|
|
324
|
+
errorFounds
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {
|
|
327
|
+
_izContext.logger.error('error AddressUpdate: ', err)
|
|
328
|
+
throw (err)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const path = require('path');
|
|
21
|
+
|
|
22
|
+
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
firstLetterLowerCase: lowerCase,
|
|
26
|
+
firstLetterUpperCase: upperCase,
|
|
27
|
+
} = require("../../../../MainLibs/index.js").utils;
|
|
28
|
+
const {
|
|
29
|
+
DEFAULT_HANDLER_PER_ACTION,
|
|
30
|
+
createIamRole,
|
|
31
|
+
resourceNames,
|
|
32
|
+
RESOURCE_CLASSES,
|
|
33
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION,
|
|
34
|
+
SOURCE_PATH,
|
|
35
|
+
SAVE_FILE_NAME,
|
|
36
|
+
DYNAMO_RESOURCE,
|
|
37
|
+
SNS_RESOURCE,
|
|
38
|
+
FUNCTION_NAME,
|
|
39
|
+
defaultIamRolePerAction,
|
|
40
|
+
awaitingMultipleStepsRole,
|
|
41
|
+
shortNameHandler,
|
|
42
|
+
SOURCE_GENERATE_IAM_ROLE,
|
|
43
|
+
getStorageResourceFromObjectSchemas,
|
|
44
|
+
SQS_RESOURCE
|
|
45
|
+
} = require("../../../../MainLibs/src/Consts.js");
|
|
46
|
+
|
|
47
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* receive objectSchema
|
|
51
|
+
* create data for hdrInv template
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} objectSchema
|
|
54
|
+
* @return {{ templatePath, templateData, setting } }
|
|
55
|
+
*/
|
|
56
|
+
async function data(_izContext, allObjSchemas, srcPath) {
|
|
57
|
+
let createSourceSet = new Set();
|
|
58
|
+
for (const action of Object.values(ACTIONS)) {
|
|
59
|
+
const defaultHandlers = DEFAULT_HANDLER_PER_ACTION[action]
|
|
60
|
+
for (const defaultHandler of defaultHandlers) {
|
|
61
|
+
const createSourceParam = await createParamForCreateSource(_izContext, allObjSchemas, action, defaultHandler, srcPath)
|
|
62
|
+
createSourceParam && createSourceSet.add(createSourceParam)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return [...createSourceSet];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function createParamForCreateSource(_izContext, allObjSchemas, action, handler, srcPath) {
|
|
69
|
+
let groupBy = SOURCE_GENERATE_IAM_ROLE.perActionEndpoint;
|
|
70
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
71
|
+
let functionNameConfig = upperCase(action) + upperCase(shortNameHandler(handler))
|
|
72
|
+
|
|
73
|
+
let storageResourceAllLocalObjectSchemas = await getStorageResourceFromObjectSchemas(_izContext, allObjSchemas)
|
|
74
|
+
|
|
75
|
+
additionalResourcePermission.push(
|
|
76
|
+
createIamRole(
|
|
77
|
+
{
|
|
78
|
+
[RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE),
|
|
79
|
+
},
|
|
80
|
+
storageResourceAllLocalObjectSchemas.resourceDynamoTableName.map(tableName =>
|
|
81
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
function httpEvent(lambdaAction) {
|
|
87
|
+
return {
|
|
88
|
+
create: "put",
|
|
89
|
+
update: "post",
|
|
90
|
+
get: "post",
|
|
91
|
+
delete: "delete"
|
|
92
|
+
}[lambdaAction]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function sqsEvent(handler) {
|
|
96
|
+
return {
|
|
97
|
+
[HANDLER.hdrSqs]: resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(HANDLER.hdrSqs)),
|
|
98
|
+
[HANDLER.hdrDsq]: resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(HANDLER.hdrDsq))
|
|
99
|
+
}[handler]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let event;
|
|
103
|
+
if (handler === HANDLER.hdrApi) {
|
|
104
|
+
event = httpEvent(action)
|
|
105
|
+
} else if (handler === HANDLER.hdrDsq || handler === HANDLER.hdrSqs) {
|
|
106
|
+
event = sqsEvent(handler)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
additionalResourcePermission.push(awaitingMultipleStepsRole());
|
|
110
|
+
|
|
111
|
+
additionalResourcePermission.push(
|
|
112
|
+
createIamRole(
|
|
113
|
+
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
114
|
+
[
|
|
115
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.createObjectComplete) + "_Out")
|
|
116
|
+
]
|
|
117
|
+
),
|
|
118
|
+
|
|
119
|
+
createIamRole(
|
|
120
|
+
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
121
|
+
[
|
|
122
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.updateNodeComplete) + "_Out")
|
|
123
|
+
]
|
|
124
|
+
),
|
|
125
|
+
createIamRole(
|
|
126
|
+
{ [RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish },
|
|
127
|
+
[
|
|
128
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.deleteNodeComplete) + "_Out")
|
|
129
|
+
]
|
|
130
|
+
),
|
|
131
|
+
createIamRole(
|
|
132
|
+
{
|
|
133
|
+
[RESOURCE_CLASSES.sns]: SNS_RESOURCE.publish
|
|
134
|
+
},
|
|
135
|
+
[
|
|
136
|
+
resourceNames(RESOURCE_CLASSES.sns, upperCase(FUNCTION_NAME.getNodeComplete) + "_Out")
|
|
137
|
+
]
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
if (handler === HANDLER.hdrSqs) {
|
|
142
|
+
additionalResourcePermission.push(
|
|
143
|
+
createIamRole({
|
|
144
|
+
[RESOURCE_CLASSES.sqs]: [SQS_RESOURCE.receiveMessage, SQS_RESOURCE.sendMessage, SQS_RESOURCE.deleteMessage, SQS_RESOURCE.getQueueAttributes]
|
|
145
|
+
},
|
|
146
|
+
[
|
|
147
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler)),
|
|
148
|
+
resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler) + "DLQ")
|
|
149
|
+
]
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
templatePath: templatePath,
|
|
156
|
+
templateData: {
|
|
157
|
+
resourceLocation: SOURCE_PATH.resourceLocationHandlerEndpointPerService,
|
|
158
|
+
handlerType: handler,
|
|
159
|
+
additionalResourcePermission,
|
|
160
|
+
event: event,
|
|
161
|
+
roleName: groupBy,
|
|
162
|
+
action: action,
|
|
163
|
+
functionNameConfig
|
|
164
|
+
},
|
|
165
|
+
setting: {
|
|
166
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
167
|
+
saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
|
|
168
|
+
fileExtension: '.yml',
|
|
169
|
+
isAppend: true
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
module.exports = data;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%_ const join = require('path').join _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(action)}_${firstLetterUpperCase(handlerType)}.main`) %>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(action) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
events:
|
|
6
|
+
<%_ if (handlerType === "hdrDsq" || handlerType === "hdrSqs") { _%>
|
|
7
|
+
- sqs:
|
|
8
|
+
arn: <%- event %>
|
|
9
|
+
batchSize: 10
|
|
10
|
+
<%_ } else if (handlerType === "hdrApi") { _%>
|
|
11
|
+
- http:
|
|
12
|
+
path: <%- firstLetterUpperCase(action) %>
|
|
13
|
+
method: <%- event %>
|
|
14
|
+
cors: true
|
|
15
|
+
#<#<%- firstLetterUpperCase(action) _%><%- firstLetterUpperCase(handlerType) %>Authorizer#>
|
|
16
|
+
#<#/<%- firstLetterUpperCase(action) _%><%- firstLetterUpperCase(handlerType) %>Authorizer#>
|
|
17
|
+
<%_ } _%>
|
|
18
|
+
role: <%- firstLetterUpperCase(roleName) _%>Role
|
|
19
|
+
#<#<%_ action _%><%_ handlerType _%>IamRole#>
|
|
20
|
+
#<#/<%_ action _%><%_ handlerType _%>IamRole#>
|
|
21
|
+
<%_ function firstLetterUpperCase(text){
|
|
22
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
23
|
+
} _%>
|
|
24
|
+
<%_ function firstLetterLowerCase(str) {
|
|
25
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
26
|
+
} _%>
|
|
@@ -44,7 +44,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
44
44
|
const allObjectRelationships = getAllLocalRelationshipSchema(_izContext, objSchemaPath);
|
|
45
45
|
const allLocalFlowSchemas = await getAllLocalFlowSchemas(_izContext, objSchemaPath);
|
|
46
46
|
// create External service
|
|
47
|
-
const createFunctionIamRole = await createExternalLambdaRole(_izContext, allObjSchemas
|
|
47
|
+
const createFunctionIamRole = await createExternalLambdaRole(_izContext, allObjSchemas, allObjectRelationships, allLocalFlowSchemas.records, saveFilePath);
|
|
48
48
|
const createSnsSubscription = await createExternalSnsSubscriptions(_izContext, allObjSchemas.records, allObjectRelationships, allLocalFlowSchemas.records, saveFilePath);
|
|
49
49
|
|
|
50
50
|
createSourceParams.push(createFunctionIamRole, createSnsSubscription);
|