@izara_project/izara-market-library-service-schemas 1.0.55 → 1.0.57
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/GenerateCodeLibs.js +4 -27
- package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +13 -14
- package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/template.ejs +14 -11
- package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +9 -11
- package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/template.ejs +16 -13
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -10
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +6 -4
- package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +18 -15
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/template.ejs +2 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +15 -11
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +12 -8
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/data.js +20 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +16 -21
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/handler/template.ejs +2 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +60 -62
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +5 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +4 -3
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +32 -44
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/template.ejs +3 -17
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/ProcessCsvtemplate.ejs +391 -0
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +9 -317
- package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +7 -7
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +18 -0
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +29 -5
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +11 -11
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +16 -16
- package/src/reStructure/TemplateData/flowSchema/register/complete/handler/template.ejs +3 -0
- package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/flowSchema/webSocketComplete/handler/template.ejs +4 -0
- package/src/reStructure/TemplateData/flowSchema/webSocketComplete/mainFunction/template.ejs +36 -7
- package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +4 -4
- package/src/reStructure/TemplateData/perActionEndpoint/handler/api/template.ejs +2 -2
- package/src/reStructure/TemplateData/perActionEndpoint/handler/dsq/template.ejs +2 -2
- package/src/reStructure/TemplateData/perActionEndpoint/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +1 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/api/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/dsq/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +6 -0
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/api/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/dsq/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/template.ejs +23 -23
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/template.ejs +18 -16
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/template.ejs +14 -12
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/template.ejs +21 -19
- package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -0
- package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +3 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/api/template.ejs +24 -22
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/dsq/template.ejs +21 -17
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/inv/template.ejs +21 -19
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/sqs/template.ejs +20 -20
- package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +1 -1
- package/src/reStructure/TemplateData/relationshipPerAction/update/complete/handler/sqs/template.ejs +1 -1
- package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +22 -2
|
@@ -32,11 +32,11 @@ const { S3Client, GetObjectCommand, DeleteObjectCommand, PutObjectCommand, CopyO
|
|
|
32
32
|
const s3 = new S3Client({ region: 'us-east-2' });
|
|
33
33
|
|
|
34
34
|
const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
35
|
-
const Readable = require('stream');
|
|
36
|
-
const { isValidCsv, getNestObject } = require('../../../../libs/source/GenerateCodeLibs');
|
|
37
35
|
const consts = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
|
|
38
36
|
const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
|
|
39
37
|
|
|
38
|
+
//(<optionalRequired>)
|
|
39
|
+
//(</optionalRequired>)
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* description of function.
|
|
@@ -58,331 +58,23 @@ module.exports.processAfterUpload = async (
|
|
|
58
58
|
_izContext,
|
|
59
59
|
bucket,
|
|
60
60
|
field,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
realImageSize = 0,
|
|
61
|
+
//(<additionalProperties>)
|
|
62
|
+
//(</additionalProperties>)
|
|
64
63
|
passBackProperties = {}
|
|
65
64
|
) => {
|
|
66
65
|
|
|
67
66
|
try {
|
|
68
67
|
|
|
69
|
-
_izContext.logger.debug('-----
|
|
68
|
+
_izContext.logger.debug('----- process AfterUpload event params ----- ', {
|
|
70
69
|
bucket: bucket,
|
|
71
70
|
field: field,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
realImageSize: realImageSize,
|
|
71
|
+
//(<loggerAdditionalParams>)
|
|
72
|
+
//(</loggerAdditionalParams>)
|
|
75
73
|
passBackProperties: passBackProperties
|
|
76
74
|
})
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const objectS3Param = {
|
|
81
|
-
Bucket: bucket.name,
|
|
82
|
-
Key: field.key
|
|
83
|
-
}
|
|
84
|
-
_izContext.logger.debug("params before getObjectParam::", objectS3Param)
|
|
85
|
-
|
|
86
|
-
const fileObjectS3 = await s3.send(new GetObjectCommand(objectS3Param));
|
|
87
|
-
_izContext.logger.debug("get fileObjectS3", fileObjectS3);
|
|
88
|
-
|
|
89
|
-
importBatchId = fileObjectS3.Metadata.importbatchid
|
|
90
|
-
|
|
91
|
-
let getImportBatchMain = await lambda.invokeSync(_izContext,
|
|
92
|
-
await lambdaSharedLib.lambdaFunctionName(_izContext, "ImportBatchMainGetHdrInv"),
|
|
93
|
-
{
|
|
94
|
-
identifiers: {
|
|
95
|
-
importBatchId: importBatchId
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
_izContext.logger.debug("getImportBatchMain", getImportBatchMain)
|
|
101
|
-
_izContext.correlationIds.set(coreConsts.BASE_USER_ID, getImportBatchMain.fields.userId);
|
|
102
|
-
_izContext.correlationIds.set(coreConsts.TARGET_ID, getImportBatchMain.fields.submittedByUserId);
|
|
103
|
-
|
|
104
|
-
let userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
|
|
105
|
-
let targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
|
|
106
|
-
|
|
107
|
-
if (Date.now() > getImportBatchMain.fields.expiryTimestamp) {
|
|
108
|
-
errorsFound.push("url expired can't upload")
|
|
109
|
-
let sendMessageUpdateUrlExpired = {
|
|
110
|
-
objInstanceFull: {
|
|
111
|
-
identifiers: {
|
|
112
|
-
importBatchId: importBatchId
|
|
113
|
-
},
|
|
114
|
-
fields: {
|
|
115
|
-
importBatchStatus: "urlExpired",
|
|
116
|
-
errorsFound: "url expired can't upload",
|
|
117
|
-
processingError: true
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let sendMessageToInImportBatchUpdate = {
|
|
123
|
-
Message: JSON.stringify(sendMessageUpdateUrlExpired),
|
|
124
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, "InImportBatchMainUpdate")
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
_izContext.logger.debug("message param before send to updateImportBatchMain", sendMessageToInImportBatchUpdate);
|
|
128
|
-
await sns.publishAsync(_izContext, sendMessageToInImportBatchUpdate);
|
|
129
|
-
|
|
130
|
-
let deleteFileObjectS3 = await s3.send(new DeleteObjectCommand(objectS3Param));
|
|
131
|
-
_izContext.logger.debug("Delete object response: ", deleteFileObjectS3)
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (fileObjectS3) {
|
|
137
|
-
if (!importBatchId) {
|
|
138
|
-
errorsFound.push("cant't get importBatchId from S3 uploaded file");
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
errorsFound.push("cant't get fileObjectS3 from S3 uploaded file");
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
let fileS3Body = fileObjectS3.Body;
|
|
145
|
-
_izContext.logger.debug("fileS3Body", fileS3Body);
|
|
146
|
-
|
|
147
|
-
let fileS3Buffer = null;
|
|
148
|
-
|
|
149
|
-
if (fileS3Body instanceof Readable) {
|
|
150
|
-
fileS3Buffer = Buffer.concat(await fileS3Body.toArray());
|
|
151
|
-
_izContext.logger.debug("fileS3Buffer", fileS3Buffer)
|
|
152
|
-
} else {
|
|
153
|
-
errorsFound.push('unknown object stream type');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// check file type
|
|
157
|
-
// can be strict in function.yml that only trigger if it specific type of file
|
|
158
|
-
const srcKey = field.key;
|
|
159
|
-
const importFieldType = srcKey.match(/\.([^.]*)$/);
|
|
160
|
-
_izContext.logger.debug("importFieldType", importFieldType);
|
|
161
|
-
if (!importFieldType) {
|
|
162
|
-
throw new NoRetryError("error fileType")
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const importKeyType = utils.firstLetterLowerCase(importFieldType[1]);
|
|
166
|
-
_izContext.logger.debug("importKeyType", importKeyType);
|
|
167
|
-
|
|
168
|
-
if (importKeyType === "csv") {
|
|
169
|
-
// check valid CSV file
|
|
170
|
-
let [validCsv, errorCheckCsv] = await isValidCsv(_izContext, fileObjectS3)
|
|
171
|
-
_izContext.logger.debug("validCsv check::", { validCsv, errorsFound })
|
|
172
|
-
if (errorCheckCsv.length) {
|
|
173
|
-
errorsFound.push(errorCheckCsv[0])
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// check file size
|
|
177
|
-
let reservedFileSize = getImportBatchMain.fields.fileSize;
|
|
178
|
-
_izContext.logger.debug("initialFileSize::", reservedFileSize)
|
|
179
|
-
let s3FileSize = fileObjectS3.ContentLength / 1048576 // convert back to byte unit
|
|
180
|
-
_izContext.logger.debug("s3FileSize in MiB::", s3FileSize)
|
|
181
|
-
|
|
182
|
-
if (s3FileSize < 0.5) { // round up to 1
|
|
183
|
-
s3FileSize = 1
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
let reservedData = await dynamodbSharedLib.getItem(_izContext,
|
|
187
|
-
await dynamodbSharedLib.tableName(_izContext, "ReservedDataMain"),
|
|
188
|
-
{
|
|
189
|
-
servicePendingId: importBatchId,
|
|
190
|
-
reservedDataId: `${consts.ACCOUNTLIMIT_TAG.reservedDynamic}_${getImportBatchMain.fields.userId}_${consts.LIMIT_TAG.uploadData}`
|
|
191
|
-
}
|
|
192
|
-
)
|
|
193
|
-
_izContext.logger.debug("reservedData::", reservedData);
|
|
194
|
-
|
|
195
|
-
let sizeDiff;
|
|
196
|
-
|
|
197
|
-
if (s3FileSize > reservedFileSize) {
|
|
198
|
-
sizeDiff = s3FileSize - reservedFileSize;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (sizeDiff < 1) {
|
|
202
|
-
|
|
203
|
-
// send message to confirmUsage
|
|
204
|
-
let confirmUsageMessage = {
|
|
205
|
-
userId: userId,
|
|
206
|
-
limitTag: consts.LIMIT_TAG.uploadData,
|
|
207
|
-
uniqueIdentify: reservedData.uniqueIdentify,
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
let sendMessageToConfirmUsage = {
|
|
211
|
-
Message: JSON.stringify(confirmUsageMessage),
|
|
212
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage', consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
213
|
-
};
|
|
214
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
215
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
|
|
216
|
-
|
|
217
|
-
let sendMessageToUpdateImportBatchStatus = {
|
|
218
|
-
objInstanceFull: {
|
|
219
|
-
identifiers: {
|
|
220
|
-
importBatchId: servicePendingId
|
|
221
|
-
},
|
|
222
|
-
fields: {
|
|
223
|
-
importBatchStatus: 'uploadComplete'
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
let sendMessageToUpdateImportBatch = {
|
|
229
|
-
Message: JSON.stringify(sendMessageToUpdateImportBatchStatus),
|
|
230
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`)
|
|
231
|
-
};
|
|
232
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch", sendMessageToUpdateImportBatch);
|
|
233
|
-
await sns.publishAsync(_izContext, sendMessageToUpdateImportBatch);
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
} else if (s3FileSize < reservedFileSize) {
|
|
237
|
-
sizeDiff = reservedFileSize - s3FileSize;
|
|
238
|
-
|
|
239
|
-
if (sizeDiff < 1) {
|
|
240
|
-
let confirmUsageMessage = {
|
|
241
|
-
userId: userId,
|
|
242
|
-
limitTag: consts.LIMIT_TAG.uploadData,
|
|
243
|
-
uniqueIdentify: reservedData.uniqueIdentify,
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let sendMessageToConfirmUsage = {
|
|
247
|
-
Message: JSON.stringify(confirmUsageMessage),
|
|
248
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage', consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
249
|
-
};
|
|
250
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
251
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
|
|
252
|
-
|
|
253
|
-
let sendMessageToUpdateImportBatchStatus = {
|
|
254
|
-
objInstanceFull: {
|
|
255
|
-
identifiers: {
|
|
256
|
-
importBatchId: servicePendingId
|
|
257
|
-
},
|
|
258
|
-
fields: {
|
|
259
|
-
importBatchStatus: 'uploadComplete'
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
let sendMessageToUpdateImportBatch = {
|
|
265
|
-
Message: JSON.stringify(sendMessageToUpdateImportBatchStatus),
|
|
266
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`)
|
|
267
|
-
};
|
|
268
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch", sendMessageToUpdateImportBatch);
|
|
269
|
-
await sns.publishAsync(_izContext, sendMessageToUpdateImportBatch);
|
|
270
|
-
|
|
271
|
-
} else {
|
|
272
|
-
let realFileSize = Math.round(s3FileSize);
|
|
273
|
-
// cancel reserved -> new reserved -> confirm
|
|
274
|
-
// cancel
|
|
275
|
-
let sendMessageToCancelReserved = {
|
|
276
|
-
Message: JSON.stringify({
|
|
277
|
-
userId: userId,
|
|
278
|
-
limitTag: consts.LIMIT_TAG.uploadData,
|
|
279
|
-
uniqueIdentify: reservedData.uniqueIdentify
|
|
280
|
-
}),
|
|
281
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InCancelUsage', consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
282
|
-
};
|
|
283
|
-
_izContext.logger.debug("sendMessageToCancelReserved", sendMessageToCancelReserved);
|
|
284
|
-
await sns.publishAsync(_izContext, sendMessageToCancelReserved);
|
|
285
|
-
|
|
286
|
-
// new reserved
|
|
287
|
-
let originTimestamp = Date.now();
|
|
288
|
-
let messageObjReserved = {
|
|
289
|
-
userId: userId,
|
|
290
|
-
limitTag: consts.LIMIT_TAG.uploadData,
|
|
291
|
-
value: realFileSize,
|
|
292
|
-
rbacType: consts.RBAC_TYPE.appLevel,
|
|
293
|
-
usedTimestamp: originTimestamp,
|
|
294
|
-
targetUserId: targetId
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
let callingFlowProperties = {
|
|
298
|
-
identifier: {
|
|
299
|
-
servicePendingId: importBatchId,
|
|
300
|
-
reservedDataId: `${consts.ACCOUNTLIMIT_TAG.reservedDynamic}_${getImportBatchMain.fields.userId}_${consts.LIMIT_TAG.uploadData}`,
|
|
301
|
-
userId: getImportBatchMain.fields.userId,
|
|
302
|
-
realSize: realFileSize
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
messageObjReserved = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
307
|
-
messageObjReserved,
|
|
308
|
-
callingFlowSharedLib.createCallingFlowConfig(
|
|
309
|
-
await lambdaSharedLib.lambdaFunctionName(_izContext, "ConfirmNewReservedHdrSqs"),
|
|
310
|
-
callingFlowProperties
|
|
311
|
-
)
|
|
312
|
-
)
|
|
313
|
-
_izContext.logger.debug('after add callingFlow: ', messageObjReserved)
|
|
314
|
-
|
|
315
|
-
let sendMessageToReservedDynamic = {
|
|
316
|
-
Message: JSON.stringify(messageObjReserved),
|
|
317
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InReservedDynamicUsage', consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
_izContext.logger.debug("sendMessageToReservedDynamic", sendMessageToReservedDynamic);
|
|
321
|
-
await sns.publishAsync(_izContext, sendMessageToReservedDynamic);
|
|
322
|
-
};
|
|
323
|
-
} else if (s3FileSize === reservedFileSize) {
|
|
324
|
-
let confirmUsageMessage = {
|
|
325
|
-
userId: getImportBatchMain.fields.userId,
|
|
326
|
-
limitTag: consts.LIMIT_TAG.uploadData,
|
|
327
|
-
uniqueIdentify: reservedData.uniqueIdentify,
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
let sendMessageToConfirmUsage = {
|
|
331
|
-
Message: JSON.stringify(confirmUsageMessage),
|
|
332
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, 'InConfirmUsage', consts.EXTERNAL_SERVICE_NAME.accountLimits)
|
|
333
|
-
};
|
|
334
|
-
_izContext.logger.debug("sendMessageToConfirmUsage", sendMessageToConfirmUsage);
|
|
335
|
-
await sns.publishAsync(_izContext, sendMessageToConfirmUsage);
|
|
336
|
-
|
|
337
|
-
let sendMessageToUpdateImportBatchStatus = {
|
|
338
|
-
objInstanceFull: {
|
|
339
|
-
identifiers: {
|
|
340
|
-
importBatchId: servicePendingId
|
|
341
|
-
},
|
|
342
|
-
fields: {
|
|
343
|
-
importBatchStatus: 'uploadComplete'
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
let sendMessageToUpdateImportBatch = {
|
|
349
|
-
Message: JSON.stringify(sendMessageToUpdateImportBatchStatus),
|
|
350
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, `InImportBatchMainUpdate`)
|
|
351
|
-
};
|
|
352
|
-
_izContext.logger.debug("sendMessageToUpdateImportBatch", sendMessageToUpdateImportBatch);
|
|
353
|
-
await sns.publishAsync(_izContext, sendMessageToUpdateImportBatch);
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
} else {
|
|
358
|
-
errorsFound.push("error importKeyType")
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (errorsFound.length) { // if error send message to update error in importBatchMain
|
|
362
|
-
let updateImportBatchMainError = {
|
|
363
|
-
objInstanceFull: {
|
|
364
|
-
identifiers: {
|
|
365
|
-
importBatchId: importBatchId
|
|
366
|
-
},
|
|
367
|
-
fields: {
|
|
368
|
-
importBatchStatus: "errorToUpload",
|
|
369
|
-
errorsFound: errorsFound,
|
|
370
|
-
processingError: true
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
let sendMessageToUpdateImportBatchMain = {
|
|
376
|
-
Message: JSON.stringify(updateImportBatchMainError),
|
|
377
|
-
TopicArn: await snsSharedLib.snsTopicArn(_izContext, "InImportBatchMainUpdate")
|
|
378
|
-
};
|
|
379
|
-
_izContext.logger.debug('sendMessageToUpdateImportBatchMain::', sendMessageToUpdateImportBatchMain);
|
|
380
|
-
await sns.publishAsync(_izContext, sendMessageToUpdateImportBatchMain);
|
|
381
|
-
|
|
382
|
-
let deleteFileObjectS3 = await s3.send(new DeleteObjectCommand(objectS3Param));
|
|
383
|
-
_izContext.logger.debug("Delete object response: ", deleteFileObjectS3)
|
|
384
|
-
|
|
385
|
-
}
|
|
76
|
+
//(<endpointHook>)
|
|
77
|
+
//(</endpointHook>)
|
|
386
78
|
|
|
387
79
|
} catch (err) {
|
|
388
80
|
_izContext.logger.error('error ProcessImageAfterUploadMain: ', err)
|
|
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
|
|
20
20
|
const externalRequest = require('@izara_project/izara-core-library-external-request');
|
|
21
21
|
const lambda = externalRequest.lambda;
|
|
22
|
-
|
|
22
|
+
const lambdaSharedLib = require('@izara_project/izara-core-library-lambda')
|
|
23
23
|
const { ApiGatewayManagementApiClient, PostToConnectionCommand } = require("@aws-sdk/client-apigatewaymanagementapi");
|
|
24
24
|
const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
25
25
|
<% if (uploadS3) { %>
|
|
@@ -57,17 +57,17 @@ async function postToConnection(message, connectionId) {
|
|
|
57
57
|
* @param {string} functionName
|
|
58
58
|
* @param {Object} payload
|
|
59
59
|
*/
|
|
60
|
-
async function
|
|
60
|
+
async function processStaticLimit(_izContext, functionName, payload) {
|
|
61
61
|
return await lambda.invokeSync(_izContext, functionName, payload)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const processStaticLimitWithCache = inMemoryCacheLib(
|
|
65
|
+
processStaticLimit,
|
|
66
66
|
{
|
|
67
67
|
max: 100,
|
|
68
68
|
maxAge: 86400000,
|
|
69
69
|
promise: true,
|
|
70
|
-
profileName: "
|
|
70
|
+
profileName: "processStaticLimit",
|
|
71
71
|
normalizer: function (args) {
|
|
72
72
|
return hash(args[1], args[2])
|
|
73
73
|
}
|
|
@@ -133,8 +133,8 @@ function getNestObject(_izContext, nestedObj, paths) {
|
|
|
133
133
|
|
|
134
134
|
module.exports = {
|
|
135
135
|
postToConnection,
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
processStaticLimit,
|
|
137
|
+
processStaticLimitWithCache,
|
|
138
138
|
getNestObject,
|
|
139
139
|
<% if (uploadS3) { %>
|
|
140
140
|
isValidCsv,
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs
CHANGED
|
@@ -28,15 +28,33 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
28
28
|
const { eventType, connectionId } = event.requestContext
|
|
29
29
|
try {
|
|
30
30
|
|
|
31
|
+
let userId = event.queryStringParameters.userId
|
|
32
|
+
let submitByUserId = event.queryStringParameters.submitByUserId
|
|
33
|
+
let correlationIds = event._izContext.correlationIds.get(izara.consts.X_CORRELATION_ID)
|
|
34
|
+
|
|
31
35
|
if (event.requestContext) {
|
|
32
36
|
switch (eventType) {
|
|
33
37
|
case 'CONNECT':
|
|
34
38
|
console.log('Connect websocket')
|
|
39
|
+
await dynamodbSharedLib.putItem(event._izContext,
|
|
40
|
+
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
41
|
+
{
|
|
42
|
+
taskKey: correlationIds,
|
|
43
|
+
userId: userId,
|
|
44
|
+
submitByUserId: submitByUserId
|
|
45
|
+
}
|
|
46
|
+
)
|
|
35
47
|
//(<webSocketConnect>)
|
|
36
48
|
//(</webSocketConnect>)
|
|
37
49
|
break
|
|
38
50
|
case 'DISCONNECT':
|
|
39
51
|
console.log('Websocket are Disconnection')
|
|
52
|
+
await dynamodbSharedLib.deleteItem(event._izContext,
|
|
53
|
+
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
54
|
+
{
|
|
55
|
+
taskKey: correlationIds,
|
|
56
|
+
}
|
|
57
|
+
)
|
|
40
58
|
//(<webSocketDisconnect>)
|
|
41
59
|
//(</webSocketDisconnect>)
|
|
42
60
|
break
|
|
@@ -111,7 +111,7 @@ async function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
|
111
111
|
return {
|
|
112
112
|
templatePath: templatePath,
|
|
113
113
|
templateData: {
|
|
114
|
-
resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, flowSchema.flowTag, "source/"),
|
|
114
|
+
resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, upperCase(flowSchema.flowTag), "source/"),
|
|
115
115
|
functionName,
|
|
116
116
|
handlerType,
|
|
117
117
|
additionalResourcePermission,
|
|
@@ -28,6 +28,7 @@ const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
|
28
28
|
const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
|
|
29
29
|
const { postToConnection } = require('../../../libs/source/GenerateCodeLibs')
|
|
30
30
|
const <%- functionName %> = require('./<%- functionName %>_Main');
|
|
31
|
+
const { createFlowTypeConcat } = require("@izara_project/izara-core-library-service-schemas").utils
|
|
31
32
|
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
32
33
|
|
|
33
34
|
event._izContext.logger.debug('Event:', event);
|
|
@@ -39,6 +40,10 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
39
40
|
const connectionId = event.requestContext.connectionId;
|
|
40
41
|
let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
|
|
41
42
|
|
|
43
|
+
//(<createIdentifiersFlow>)
|
|
44
|
+
let identifiers
|
|
45
|
+
//(</createIdentifiersFlow>)
|
|
46
|
+
|
|
42
47
|
switch (route) {
|
|
43
48
|
|
|
44
49
|
case '$default':
|
|
@@ -47,16 +52,35 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
47
52
|
case '<%- route %>':
|
|
48
53
|
console.log("event in route webSocket", event);
|
|
49
54
|
let eventParams = JSON.parse(event.body)
|
|
50
|
-
|
|
51
|
-
await dynamodbSharedLib.putItem(
|
|
55
|
+
let flowSchema = getObjectSchema.getFlowSchemaS3WithCache(
|
|
52
56
|
event._izContext,
|
|
53
|
-
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
54
57
|
{
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
flowTag: "<%- route %>",
|
|
59
|
+
serviceTag: process.env.iz_serviceTag
|
|
57
60
|
}
|
|
58
61
|
)
|
|
59
62
|
|
|
63
|
+
if (flowSchema.statusType === "statusField" || flowSchema.statusType === "storedCache" || flowSchema.statusType === "triggerCache") {
|
|
64
|
+
await dynamodbSharedLib.putItem(event._izContext,
|
|
65
|
+
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
66
|
+
{
|
|
67
|
+
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: "<%- route %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
|
|
68
|
+
connectionId: connectionId,
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
} else if (flowSchema.statusType === "none") {
|
|
73
|
+
await dynamodbSharedLib.putItem(
|
|
74
|
+
event._izContext,
|
|
75
|
+
await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
|
|
76
|
+
{
|
|
77
|
+
taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: "<%- route %>", serviceTag: process.env.iz_serviceTag })}${correlationId}`,
|
|
78
|
+
connectionId: connectionId,
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
60
84
|
let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
|
|
61
85
|
await <%- functionName %>.<%- functionName %>(
|
|
62
86
|
event._izContext,
|
|
@@ -72,17 +72,17 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
|
|
|
72
72
|
|
|
73
73
|
let defaultDsqQueueDataList = [];
|
|
74
74
|
|
|
75
|
-
if (flowSchema.outputTopic) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
75
|
+
// if (flowSchema.outputTopic) {
|
|
76
|
+
// if (flowSteps.includes("Out")) {
|
|
77
|
+
// if (flowSchema.outputTopic) {
|
|
78
|
+
// defaultDsqQueueDataList.push(
|
|
79
|
+
// {
|
|
80
|
+
// queueName: upperCase(topicIn) + "CompleteHdrSqs"
|
|
81
|
+
// }
|
|
82
|
+
// )
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
for (let defaultSnsInSqsData of generatedSnsTopicInForFlowSchema) {
|
|
@@ -199,15 +199,15 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
199
199
|
|
|
200
200
|
// const webSocketCreateObjectStordCache = createWebSocketCreateObjectStoredCache(_izContext, saveFilePath);
|
|
201
201
|
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
202
|
+
const reservedLimitFunctionYaml = createReservedLimitFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
203
|
+
const reservedLimitHandlerFunction = createReservedLimitHandler(_izContext, flowSchema, saveFilePath);
|
|
204
|
+
const reservedLimitMainFunction = await createReservedLimitMainFunction(_izContext, flowSchema, saveFilePath);
|
|
205
|
+
const reservedLimitQueueName = createReservedLimitQueueName(_izContext, saveFilePath);
|
|
206
206
|
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
207
|
+
const presignUrlFunctionYaml = createPresignUrlFunctionYaml(_izContext, flowSchema, saveFilePath);
|
|
208
|
+
const presignUrlMainFunction = createPresignUrlMainFunction(_izContext, flowSchema, saveFilePath);
|
|
209
|
+
const presignUrlHandlerFunction = createPresignUrlHandler(_izContext, flowSchema, saveFilePath);
|
|
210
|
+
const presignUrlQueueName = createPresignUrlQueueName(_izContext, saveFilePath);
|
|
211
211
|
|
|
212
212
|
const processAfterUploadFunctionYmlS3 = createProcessAfterUploadS3FunctionYmlS3(_izContext, flowSchema, saveFilePath);
|
|
213
213
|
// const processAfterUploadFunctionYamlHdrDsq = createProcessAfterUploadS3FunctionYmlDsq(_izContext, saveFilePath);
|
|
@@ -232,17 +232,17 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
232
232
|
];
|
|
233
233
|
|
|
234
234
|
const getPreSignUrlResources = [
|
|
235
|
-
...
|
|
236
|
-
...
|
|
237
|
-
...
|
|
238
|
-
...
|
|
235
|
+
...reservedLimitFunctionYaml,
|
|
236
|
+
...reservedLimitHandlerFunction,
|
|
237
|
+
...reservedLimitMainFunction,
|
|
238
|
+
...reservedLimitQueueName
|
|
239
239
|
];
|
|
240
240
|
|
|
241
241
|
const reservedLimitResources = [
|
|
242
|
-
...
|
|
243
|
-
...
|
|
244
|
-
...
|
|
245
|
-
...
|
|
242
|
+
...presignUrlFunctionYaml,
|
|
243
|
+
...presignUrlHandlerFunction,
|
|
244
|
+
...presignUrlMainFunction,
|
|
245
|
+
...presignUrlQueueName
|
|
246
246
|
];
|
|
247
247
|
|
|
248
248
|
const processAfterUploadResources = [
|
|
@@ -52,6 +52,9 @@ module.exports.main = middlewareHandler.wrap(async (event, context, callback) =>
|
|
|
52
52
|
// add argument (to invoke lambda) to passOnProperties[]
|
|
53
53
|
passOnProperties.push(record.body.TopicArn)
|
|
54
54
|
passOnProperties.push(record.body.Message)
|
|
55
|
+
//(<additionalParams>)
|
|
56
|
+
//(</additionalParams>)
|
|
57
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
55
58
|
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
56
59
|
|
|
57
60
|
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
@@ -53,9 +53,9 @@ module.exports.registerCompleteMain = async (
|
|
|
53
53
|
_izContext,
|
|
54
54
|
topicArn,
|
|
55
55
|
requestParams,
|
|
56
|
-
callingFlowConfig = {},
|
|
57
56
|
//(<additionalParams>)
|
|
58
57
|
//(</additionalParams>)
|
|
58
|
+
callingFlowConfig = {},
|
|
59
59
|
) => {
|
|
60
60
|
try {
|
|
61
61
|
_izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
|
|
@@ -51,7 +51,11 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
// add argument (to invoke lambda) to passOnProperties[]
|
|
54
|
+
passOnProperties.push(record.body.TopicArn)
|
|
54
55
|
passOnProperties.push(record.body.Message)
|
|
56
|
+
//(<additionalParams>)
|
|
57
|
+
//(</additionalParams>)
|
|
58
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
55
59
|
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
56
60
|
|
|
57
61
|
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|