@natlibfi/melinda-rest-api-commons 4.0.17 → 4.0.18-alpha.10
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/dist/mongoLog.js +112 -42
- package/dist/mongoLog.js.map +1 -1
- package/package.json +1 -1
package/dist/mongoLog.js
CHANGED
|
@@ -41,6 +41,12 @@ var _constants = require("./constants");
|
|
|
41
41
|
*
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Create log operator
|
|
46
|
+
* @param {String} MONGO_URI connnection address to mongo
|
|
47
|
+
* @param {String} dbName Mongo DB name, defaults 'rest-api
|
|
48
|
+
* @returns {Object} containing all log handling functions
|
|
49
|
+
*/
|
|
44
50
|
async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
45
51
|
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
46
52
|
|
|
@@ -62,6 +68,12 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
62
68
|
remove,
|
|
63
69
|
removeBySequences
|
|
64
70
|
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Add log item to collection
|
|
74
|
+
* @param {Object}} logItem contains log item data
|
|
75
|
+
* @returns void
|
|
76
|
+
*/
|
|
65
77
|
async function addLogItem(logItem) {
|
|
66
78
|
const time = (0, _moment.default)().toDate();
|
|
67
79
|
const newLogItem = {
|
|
@@ -91,15 +103,22 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
91
103
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Querry log items
|
|
109
|
+
* @param {Integer} limit defaults 5
|
|
110
|
+
* @param {Integer} skip defaults 0
|
|
111
|
+
* @param {Object} rest query params
|
|
112
|
+
* @returns result array
|
|
113
|
+
*/
|
|
114
|
+
async function query({
|
|
115
|
+
limit = 5,
|
|
116
|
+
skip = 0,
|
|
117
|
+
...rest
|
|
118
|
+
}) {
|
|
119
|
+
logger.debug(`Query params: ${JSON.stringify(rest)}`);
|
|
120
|
+
logger.debug(`Limit and skip params: ${limit} | ${skip}`);
|
|
121
|
+
checkLogItemType(rest.logItemType, false, false);
|
|
103
122
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
104
123
|
.find(rest).sort({
|
|
105
124
|
creationTime: 1
|
|
@@ -110,11 +129,20 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
110
129
|
}
|
|
111
130
|
|
|
112
131
|
// DEVELOP: queryById returns jsut one (randomish) log! is this useful?
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Get single log item by correlationId
|
|
134
|
+
* @param {String} correlationId
|
|
135
|
+
* @param {String} logItemType contant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG
|
|
136
|
+
* @param {Integer} skip defaults 0
|
|
137
|
+
* @param {Integer} limit defaults 1
|
|
138
|
+
* @returns query result array
|
|
139
|
+
*/
|
|
140
|
+
async function queryById(correlationId, logItemType = _constants.LOG_ITEM_TYPE.MERGE_LOG, skip = 0, limit = 1) {
|
|
141
|
+
logger.debug(`QueryById: ${correlationId}`);
|
|
115
142
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
116
143
|
.find({
|
|
117
|
-
correlationId
|
|
144
|
+
correlationId,
|
|
145
|
+
logItemType
|
|
118
146
|
}).sort({
|
|
119
147
|
blobSequence: 1
|
|
120
148
|
}).skip(parseInt(skip, 10)).limit(parseInt(limit, 10)).toArray();
|
|
@@ -124,18 +152,25 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
124
152
|
|
|
125
153
|
// getListOfLogs returns list of correlationIds that have logs of given logItemType
|
|
126
154
|
// if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG
|
|
127
|
-
|
|
128
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Get list correlationId of logs filtered by logItemType
|
|
157
|
+
* @param {String} logItemType contant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG
|
|
158
|
+
* @returns Array of query results
|
|
159
|
+
*/
|
|
160
|
+
async function getListOfLogs(logItemType = _constants.LOG_ITEM_TYPE.MERGE_LOG) {
|
|
161
|
+
// checkLogItemType(logItemType, false, false);
|
|
129
162
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
130
163
|
.distinct('correlationId', {
|
|
131
164
|
logItemType
|
|
132
165
|
});
|
|
133
166
|
logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);
|
|
134
|
-
return
|
|
135
|
-
status: result.length > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
|
|
136
|
-
payload: result.length > 0 ? result : 'No logs found'
|
|
137
|
-
};
|
|
167
|
+
return result;
|
|
138
168
|
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get list of catalogers from logs
|
|
172
|
+
* @returns Array of query results
|
|
173
|
+
*/
|
|
139
174
|
async function getListOfCatalogers() {
|
|
140
175
|
logger.debug(`Getting list of Catalogers`);
|
|
141
176
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
@@ -143,12 +178,21 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
143
178
|
return result;
|
|
144
179
|
}
|
|
145
180
|
|
|
146
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Get filtered list of logs with extra info. Give params in Object
|
|
183
|
+
* @param {[String]} logItemTypes: String array of logItemTypes. Defaults [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG]
|
|
184
|
+
* @param {[String]} catalogers: String array of wanted catalogers. Defaults []
|
|
185
|
+
* @param {String} dateBefore: String date schema 'YYYY-MM-DD'. Defaults new Date()
|
|
186
|
+
* @param {String} dateAfter: String date schema 'YYYY-MM-DD'. Defaults '2000-01-01'
|
|
187
|
+
* @param {Boolean} test: Boolean is this test run. Defaults false
|
|
188
|
+
* @returns Parsed Object {'correlationId', 'logItemType', 'creationTime', 'cataloger', 'logCount'}
|
|
189
|
+
*/
|
|
147
190
|
async function getExpandedListOfLogs({
|
|
148
191
|
logItemTypes = [_constants.LOG_ITEM_TYPE.MERGE_LOG, _constants.LOG_ITEM_TYPE.MATCH_LOG],
|
|
149
192
|
catalogers = [],
|
|
150
193
|
dateBefore = new Date(),
|
|
151
|
-
dateAfter =
|
|
194
|
+
dateAfter = '2000-01-01',
|
|
195
|
+
test = false
|
|
152
196
|
}) {
|
|
153
197
|
logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);
|
|
154
198
|
logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line
|
|
@@ -156,7 +200,7 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
156
200
|
logger.debug(`Getting expanded list of logs`);
|
|
157
201
|
const pipeline = [
|
|
158
202
|
// currently return only MERGE_LOG and MATCH_LOG
|
|
159
|
-
generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter), {
|
|
203
|
+
generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter, test), {
|
|
160
204
|
'$sort': {
|
|
161
205
|
'correlationId': 1,
|
|
162
206
|
'logItemType': 1,
|
|
@@ -208,13 +252,18 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
208
252
|
logger.silly(`Query result: ${JSON.stringify(result)}`);
|
|
209
253
|
logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);
|
|
210
254
|
logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
255
|
+
return fixedResult;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Generate match object for aggregation pipeline
|
|
259
|
+
* @param {[String]} logItemTypes: String array of logItemTypes.
|
|
260
|
+
* @param {[String]} catalogers: String array of wanted catalogers
|
|
261
|
+
* @param {String} dateBefore: String date schema 'YYYY-MM-DD'
|
|
262
|
+
* @param {String} dateAfter: String date schema 'YYYY-MM-DD'
|
|
263
|
+
* @param {Boolean} test: Boolean is this test run. Defaults false
|
|
264
|
+
* @returns Match Object
|
|
265
|
+
*/
|
|
266
|
+
function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter, test = false) {
|
|
218
267
|
const matchOptions = {
|
|
219
268
|
'$match': {
|
|
220
269
|
'logItemType': logItemTypes.length > 0 ? {
|
|
@@ -224,14 +273,21 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
224
273
|
'$in': catalogers
|
|
225
274
|
} : /.*/ui,
|
|
226
275
|
'creationTime': {
|
|
227
|
-
'$gte':
|
|
228
|
-
'$lte':
|
|
276
|
+
'$gte': test ? new Date(dateAfter).toISOString() : new Date(dateAfter),
|
|
277
|
+
'$lte': test ? new Date(dateBefore).toISOString() : new Date(dateBefore)
|
|
229
278
|
}
|
|
230
279
|
}
|
|
231
280
|
};
|
|
232
281
|
return matchOptions;
|
|
233
282
|
}
|
|
234
283
|
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Protect logs from cleaning. Forced cleaning defaults 30days
|
|
287
|
+
* @param {String} correlationId
|
|
288
|
+
* @param {Integer} blobSequence
|
|
289
|
+
* @returns result
|
|
290
|
+
*/
|
|
235
291
|
async function protect(correlationId, blobSequence) {
|
|
236
292
|
logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);
|
|
237
293
|
const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -251,16 +307,20 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
251
307
|
}
|
|
252
308
|
}
|
|
253
309
|
}]);
|
|
254
|
-
return
|
|
255
|
-
status: result.modifiedCount > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
|
|
256
|
-
payload: result.modifiedCount > 0 ? result : 'No logs found'
|
|
257
|
-
};
|
|
310
|
+
return result;
|
|
258
311
|
} catch (error) {
|
|
259
312
|
const errorMessage = error.payload || error.message || '';
|
|
260
313
|
(0, _utils.logError)(error);
|
|
261
314
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
262
315
|
}
|
|
263
316
|
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Remove logs
|
|
320
|
+
* @param {String} correlationId
|
|
321
|
+
* @param {Boolean} force defaults false
|
|
322
|
+
* @returns result
|
|
323
|
+
*/
|
|
264
324
|
async function remove(correlationId, force = false) {
|
|
265
325
|
logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);
|
|
266
326
|
const clean = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -274,16 +334,21 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
274
334
|
};
|
|
275
335
|
try {
|
|
276
336
|
const result = await db.collection(collection).deleteMany(filter);
|
|
277
|
-
return
|
|
278
|
-
status: result.deletedCount > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
|
|
279
|
-
payload: result.deletedCount > 0 ? result : 'No logs found'
|
|
280
|
-
};
|
|
337
|
+
return result;
|
|
281
338
|
} catch (error) {
|
|
282
339
|
const errorMessage = error.payload || error.message || '';
|
|
283
340
|
(0, _utils.logError)(error);
|
|
284
341
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
285
342
|
}
|
|
286
343
|
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Remove logs by sequences
|
|
347
|
+
* @param {String} correlationId
|
|
348
|
+
* @param {[Integer]} sequences
|
|
349
|
+
* @param {Boolean} force defaults false
|
|
350
|
+
* @returns result
|
|
351
|
+
*/
|
|
287
352
|
async function removeBySequences(correlationId, sequences = [], force = false) {
|
|
288
353
|
logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);
|
|
289
354
|
const clean = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -309,16 +374,21 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
309
374
|
};
|
|
310
375
|
try {
|
|
311
376
|
const result = await db.collection(collection).deleteMany(filter);
|
|
312
|
-
return
|
|
313
|
-
status: result.deletedCount > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
|
|
314
|
-
payload: result.deletedCount > 0 ? result : 'No logs found'
|
|
315
|
-
};
|
|
377
|
+
return result;
|
|
316
378
|
} catch (error) {
|
|
317
379
|
const errorMessage = error.payload || error.message || '';
|
|
318
380
|
(0, _utils.logError)(error);
|
|
319
381
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
320
382
|
}
|
|
321
383
|
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Checks validy of logItemType
|
|
387
|
+
* @param {String} logItemType
|
|
388
|
+
* @param {Boolean} errorUnknown
|
|
389
|
+
* @param {Boolean} errorNotExisting
|
|
390
|
+
* @returns void
|
|
391
|
+
*/
|
|
322
392
|
function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {
|
|
323
393
|
if (logItemType) {
|
|
324
394
|
const typeInLogItemTypes = Object.values(_constants.LOG_ITEM_TYPE).indexOf(logItemType) > -1;
|
package/dist/mongoLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.js","names":["_mongodb","require","_melindaBackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","_default","MONGO_URI","dbName","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getListOfCatalogers","getExpandedListOfLogs","protect","remove","removeBySequences","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","errorMessage","payload","message","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","logItemTypes","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","catalogers","dateBefore","Date","dateAfter","generateMatchObject","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","dateBeforeIso","toISOString","dateAfterIso","matchOptions","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","force","clean","$ne","deleteMany","deletedCount","sequences","cleanSequences","sequence","Number","isInteger","$in","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\nexport default async function (MONGO_URI, dbName = 'rest-api') {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db(dbName);\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, getListOfCatalogers, getExpandedListOfLogs, protect, remove, removeBySequences};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n // console.log(newLogItem); // eslint-disable-line\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n // console.log('addLogItem done', result); // eslint-disable-line\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n checkLogItemType(params.logItemType, false, false);\n const {limit = 5, skip = 0, ...rest} = params;\n logger.debug(`Actual query params: ${JSON.stringify(rest)}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({creationTime: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n //logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n // DEVELOP: queryById returns jsut one (randomish) log! is this useful?\n async function queryById(correlationIdString, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId: correlationIdString})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n // getListOfLogs returns list of correlationIds that have logs of given logItemType\n // if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG\n async function getListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return {status: result.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.length > 0 ? result : 'No logs found'};\n }\n\n async function getListOfCatalogers() {\n logger.debug(`Getting list of Catalogers`);\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('cataloger');\n\n return result;\n }\n\n // getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs\n async function getExpandedListOfLogs({logItemTypes = [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG], catalogers = [], dateBefore = new Date(), dateAfter = new Date('2000-01-01')}) {\n logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line\n //checkLogItemType(logItemType, false, false);\n logger.debug(`Getting expanded list of logs`);\n const pipeline = [\n // currently return only MERGE_LOG and MATCH_LOG\n generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter),\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n },\n {\n '$group':\n {\n '_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}\n }\n },\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n }\n ];\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .aggregate(pipeline)\n .toArray();\n\n const fixedResult = result.map((logListing) => {\n const {correlationId, logItemType} = logListing._id;\n const {cataloger, creationTime, logCount} = logListing;\n return {correlationId, logItemType, cataloger, creationTime, logCount};\n });\n\n logger.silly(`Query result: ${JSON.stringify(result)}`);\n logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);\n\n logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);\n return {status: fixedResult.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: fixedResult.length > 0 ? fixedResult : 'No logs found'};\n\n function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {\n const dateBeforeIso = new Date(dateBefore).toISOString();\n const dateAfterIso = new Date(dateAfter).toISOString();\n const matchOptions = {\n '$match': {\n 'logItemType': logItemTypes.length > 0 ? {'$in': logItemTypes} : /.*/ui,\n 'cataloger': catalogers.length > 0 ? {'$in': catalogers} : /.*/ui,\n 'creationTime': {\n '$gte': dateAfterIso,\n '$lte': dateBeforeIso\n }\n }\n };\n\n return matchOptions;\n }\n }\n\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: parseInt(cleanBlobSequence, 10)} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: moment().toDate(),\n protected: {$not: '$protected'}\n }\n }\n ]\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function removeBySequences(correlationId, sequences = [], force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);\n const clean = sanitize(correlationId);\n // blobSequences are integers that start from 1\n // we accept also strings that are convertilble to integers greated than 0\n const cleanSequences = sequences.filter(sequence => Number.isInteger(Number(sequence)) && sequence > 0);\n\n if (sequences.length !== cleanSequences.length) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Invalid sequences in removeBySequences. Sequences should be positive integers`);\n }\n\n const filter = force ? {correlationId: clean, blobSequence: {$in: cleanSequences}} : {correlationId: clean, blobSequence: {$in: sequences}, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\n\n if (logItemType) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n\n if (errorNotExisting) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);\n }\n return logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;;AA4BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,cAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWe,eAAAS,SAAgBC,SAAS,EAAEC,MAAM,GAAG,UAAU,EAAE;EAC7D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EAC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ackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","_default","MONGO_URI","dbName","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getListOfCatalogers","getExpandedListOfLogs","protect","remove","removeBySequences","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","errorMessage","payload","message","logError","limit","skip","rest","debug","JSON","stringify","find","sort","parseInt","toArray","length","LOG_ITEM_TYPE","MERGE_LOG","distinct","logItemTypes","MATCH_LOG","catalogers","dateBefore","Date","dateAfter","test","generateMatchObject","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","matchOptions","toISOString","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","force","clean","$ne","deleteMany","sequences","cleanSequences","sequence","Number","isInteger","$in","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\n/**\n * Create log operator\n * @param {String} MONGO_URI connnection address to mongo\n * @param {String} dbName Mongo DB name, defaults 'rest-api\n * @returns {Object} containing all log handling functions\n */\nexport default async function (MONGO_URI, dbName = 'rest-api') {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db(dbName);\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, getListOfCatalogers, getExpandedListOfLogs, protect, remove, removeBySequences};\n\n /**\n * Add log item to collection\n * @param {Object}} logItem contains log item data\n * @returns void\n */\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n // console.log(newLogItem); // eslint-disable-line\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n // console.log('addLogItem done', result); // eslint-disable-line\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n /**\n * Querry log items\n * @param {Integer} limit defaults 5\n * @param {Integer} skip defaults 0\n * @param {Object} rest query params\n * @returns result array\n */\n async function query({limit = 5, skip = 0, ...rest}) {\n logger.debug(`Query params: ${JSON.stringify(rest)}`);\n logger.debug(`Limit and skip params: ${limit} | ${skip}`);\n checkLogItemType(rest.logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({creationTime: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n //logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n // DEVELOP: queryById returns jsut one (randomish) log! is this useful?\n /**\n * Get single log item by correlationId\n * @param {String} correlationId\n * @param {String} logItemType contant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @param {Integer} skip defaults 0\n * @param {Integer} limit defaults 1\n * @returns query result array\n */\n async function queryById(correlationId, logItemType = LOG_ITEM_TYPE.MERGE_LOG, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationId}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId, logItemType})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n // getListOfLogs returns list of correlationIds that have logs of given logItemType\n // if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG\n /**\n * Get list correlationId of logs filtered by logItemType\n * @param {String} logItemType contant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @returns Array of query results\n */\n async function getListOfLogs(logItemType = LOG_ITEM_TYPE.MERGE_LOG) {\n // checkLogItemType(logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n /**\n * Get list of catalogers from logs\n * @returns Array of query results\n */\n async function getListOfCatalogers() {\n logger.debug(`Getting list of Catalogers`);\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('cataloger');\n\n return result;\n }\n\n /**\n * Get filtered list of logs with extra info. Give params in Object\n * @param {[String]} logItemTypes: String array of logItemTypes. Defaults [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG]\n * @param {[String]} catalogers: String array of wanted catalogers. Defaults []\n * @param {String} dateBefore: String date schema 'YYYY-MM-DD'. Defaults new Date()\n * @param {String} dateAfter: String date schema 'YYYY-MM-DD'. Defaults '2000-01-01'\n * @param {Boolean} test: Boolean is this test run. Defaults false\n * @returns Parsed Object {'correlationId', 'logItemType', 'creationTime', 'cataloger', 'logCount'}\n */\n async function getExpandedListOfLogs({logItemTypes = [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG], catalogers = [], dateBefore = new Date(), dateAfter = '2000-01-01', test = false}) {\n logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line\n //checkLogItemType(logItemType, false, false);\n logger.debug(`Getting expanded list of logs`);\n const pipeline = [\n // currently return only MERGE_LOG and MATCH_LOG\n generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter, test),\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n },\n {\n '$group':\n {\n '_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}\n }\n },\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n }\n ];\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .aggregate(pipeline)\n .toArray();\n\n const fixedResult = result.map((logListing) => {\n const {correlationId, logItemType} = logListing._id;\n const {cataloger, creationTime, logCount} = logListing;\n return {correlationId, logItemType, cataloger, creationTime, logCount};\n });\n\n logger.silly(`Query result: ${JSON.stringify(result)}`);\n logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);\n\n logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);\n return fixedResult;\n\n /**\n * Generate match object for aggregation pipeline\n * @param {[String]} logItemTypes: String array of logItemTypes.\n * @param {[String]} catalogers: String array of wanted catalogers\n * @param {String} dateBefore: String date schema 'YYYY-MM-DD'\n * @param {String} dateAfter: String date schema 'YYYY-MM-DD'\n * @param {Boolean} test: Boolean is this test run. Defaults false\n * @returns Match Object\n */\n function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter, test = false) {\n const matchOptions = {\n '$match': {\n 'logItemType': logItemTypes.length > 0 ? {'$in': logItemTypes} : /.*/ui,\n 'cataloger': catalogers.length > 0 ? {'$in': catalogers} : /.*/ui,\n 'creationTime': {\n '$gte': test ? new Date(dateAfter).toISOString() : new Date(dateAfter),\n '$lte': test ? new Date(dateBefore).toISOString() : new Date(dateBefore)\n }\n }\n };\n\n return matchOptions;\n }\n }\n\n /**\n * Protect logs from cleaning. Forced cleaning defaults 30days\n * @param {String} correlationId\n * @param {Integer} blobSequence\n * @returns result\n */\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: parseInt(cleanBlobSequence, 10)} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: moment().toDate(),\n protected: {$not: '$protected'}\n }\n }\n ]\n );\n return result;\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n /**\n * Remove logs\n * @param {String} correlationId\n * @param {Boolean} force defaults false\n * @returns result\n */\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return result;\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n /**\n * Remove logs by sequences\n * @param {String} correlationId\n * @param {[Integer]} sequences\n * @param {Boolean} force defaults false\n * @returns result\n */\n async function removeBySequences(correlationId, sequences = [], force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);\n const clean = sanitize(correlationId);\n // blobSequences are integers that start from 1\n // we accept also strings that are convertilble to integers greated than 0\n const cleanSequences = sequences.filter(sequence => Number.isInteger(Number(sequence)) && sequence > 0);\n\n if (sequences.length !== cleanSequences.length) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Invalid sequences in removeBySequences. Sequences should be positive integers`);\n }\n\n const filter = force ? {correlationId: clean, blobSequence: {$in: cleanSequences}} : {correlationId: clean, blobSequence: {$in: sequences}, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return result;\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n /**\n * Checks validy of logItemType\n * @param {String} logItemType\n * @param {Boolean} errorUnknown\n * @param {Boolean} errorNotExisting\n * @returns void\n */\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\n if (logItemType) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n\n if (errorNotExisting) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);\n }\n return logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;;AA4BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,cAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACe,eAAAS,SAAgBC,SAAS,EAAEC,MAAM,GAAG,UAAU,EAAE;EAC7D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAW,CAACC,OAAO,CAACN,SAAS,EAAE;IAACO,eAAe,EAAE,IAAI;IAAEC,kBAAkB,EAAE;EAAI,CAAC,CAAC;EACtG,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAE,CAACR,MAAM,CAAC;EAC5B,MAAMS,UAAU,GAAG,MAAM;EACzB,OAAO;IAACC,UAAU;IAAEC,KAAK;IAAEC,SAAS;IA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