@natlibfi/melinda-rest-api-commons 4.0.18-alpha.8 → 4.0.18
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 +122 -20
- package/dist/mongoLog.js.map +1 -1
- package/package.json +16 -17
package/dist/mongoLog.js
CHANGED
|
@@ -13,14 +13,13 @@ var _moment = _interopRequireDefault(require("moment"));
|
|
|
13
13
|
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
14
14
|
var _mongoSanitize = _interopRequireDefault(require("mongo-sanitize"));
|
|
15
15
|
var _constants = require("./constants");
|
|
16
|
-
var _luxon = require("luxon");
|
|
17
16
|
/**
|
|
18
17
|
*
|
|
19
18
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
20
19
|
*
|
|
21
20
|
* Shared modules for microservices of Melinda rest api batch import system
|
|
22
21
|
*
|
|
23
|
-
* Copyright (C) 2020-
|
|
22
|
+
* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
|
|
24
23
|
*
|
|
25
24
|
* This file is part of melinda-rest-api-commons
|
|
26
25
|
*
|
|
@@ -42,6 +41,12 @@ var _luxon = require("luxon");
|
|
|
42
41
|
*
|
|
43
42
|
*/
|
|
44
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
|
+
*/
|
|
45
50
|
async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
46
51
|
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
47
52
|
|
|
@@ -63,6 +68,12 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
63
68
|
remove,
|
|
64
69
|
removeBySequences
|
|
65
70
|
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Add log item to collection
|
|
74
|
+
* @param {Object} logItem contains log item data
|
|
75
|
+
* @returns void
|
|
76
|
+
*/
|
|
66
77
|
async function addLogItem(logItem) {
|
|
67
78
|
const time = (0, _moment.default)().toDate();
|
|
68
79
|
const newLogItem = {
|
|
@@ -92,15 +103,22 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
92
103
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Query 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);
|
|
104
122
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
105
123
|
.find(rest).sort({
|
|
106
124
|
creationTime: 1
|
|
@@ -111,11 +129,20 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
// DEVELOP: queryById returns jsut one (randomish) log! is this useful?
|
|
114
|
-
|
|
115
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Get single log item by correlationId
|
|
134
|
+
* @param {String} correlationId
|
|
135
|
+
* @param {String} logItemType constant 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}`);
|
|
116
142
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
117
143
|
.find({
|
|
118
|
-
correlationId
|
|
144
|
+
correlationId,
|
|
145
|
+
logItemType
|
|
119
146
|
}).sort({
|
|
120
147
|
blobSequence: 1
|
|
121
148
|
}).skip(parseInt(skip, 10)).limit(parseInt(limit, 10)).toArray();
|
|
@@ -125,6 +152,11 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
125
152
|
|
|
126
153
|
// getListOfLogs returns list of correlationIds that have logs of given logItemType
|
|
127
154
|
// if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG
|
|
155
|
+
/**
|
|
156
|
+
* Get list of correlationIds of logs filtered by logItemType
|
|
157
|
+
* @param {String} logItemType constant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG
|
|
158
|
+
* @returns Array of query results
|
|
159
|
+
*/
|
|
128
160
|
async function getListOfLogs(logItemType = _constants.LOG_ITEM_TYPE.MERGE_LOG) {
|
|
129
161
|
// checkLogItemType(logItemType, false, false);
|
|
130
162
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
@@ -134,6 +166,11 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
134
166
|
logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);
|
|
135
167
|
return result;
|
|
136
168
|
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get list of catalogers from logs
|
|
172
|
+
* @returns Array of query results
|
|
173
|
+
*/
|
|
137
174
|
async function getListOfCatalogers() {
|
|
138
175
|
logger.debug(`Getting list of Catalogers`);
|
|
139
176
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
@@ -141,7 +178,15 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
141
178
|
return result;
|
|
142
179
|
}
|
|
143
180
|
|
|
144
|
-
|
|
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
|
+
*/
|
|
145
190
|
async function getExpandedListOfLogs({
|
|
146
191
|
logItemTypes = [_constants.LOG_ITEM_TYPE.MERGE_LOG, _constants.LOG_ITEM_TYPE.MATCH_LOG],
|
|
147
192
|
catalogers = [],
|
|
@@ -150,12 +195,23 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
150
195
|
test = false
|
|
151
196
|
}) {
|
|
152
197
|
logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);
|
|
153
|
-
logger.debug(JSON.stringify(generateMatchObject(
|
|
198
|
+
logger.debug(JSON.stringify(generateMatchObject({
|
|
199
|
+
logItemTypes,
|
|
200
|
+
catalogers,
|
|
201
|
+
dateBefore,
|
|
202
|
+
dateAfter
|
|
203
|
+
}))); // eslint-disable-line
|
|
154
204
|
//checkLogItemType(logItemType, false, false);
|
|
155
205
|
logger.debug(`Getting expanded list of logs`);
|
|
156
206
|
const pipeline = [
|
|
157
207
|
// currently return only MERGE_LOG and MATCH_LOG
|
|
158
|
-
generateMatchObject(
|
|
208
|
+
generateMatchObject({
|
|
209
|
+
logItemTypes,
|
|
210
|
+
catalogers,
|
|
211
|
+
dateBefore,
|
|
212
|
+
dateAfter,
|
|
213
|
+
test
|
|
214
|
+
}), {
|
|
159
215
|
'$sort': {
|
|
160
216
|
'correlationId': 1,
|
|
161
217
|
'logItemType': 1,
|
|
@@ -208,7 +264,23 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
208
264
|
logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);
|
|
209
265
|
logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);
|
|
210
266
|
return fixedResult;
|
|
211
|
-
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Generate match object for aggregation pipeline
|
|
270
|
+
* @param {[String]} logItemTypes: String array of logItemTypes.
|
|
271
|
+
* @param {[String]} catalogers: String array of wanted catalogers
|
|
272
|
+
* @param {String} dateBefore: String date schema 'YYYY-MM-DD'
|
|
273
|
+
* @param {String} dateAfter: String date schema 'YYYY-MM-DD'
|
|
274
|
+
* @param {Boolean} test: Boolean is this test run. Defaults false
|
|
275
|
+
* @returns Match Object
|
|
276
|
+
*/
|
|
277
|
+
function generateMatchObject({
|
|
278
|
+
logItemTypes,
|
|
279
|
+
catalogers,
|
|
280
|
+
dateBefore,
|
|
281
|
+
dateAfter,
|
|
282
|
+
test = false
|
|
283
|
+
}) {
|
|
212
284
|
const matchOptions = {
|
|
213
285
|
'$match': {
|
|
214
286
|
'logItemType': logItemTypes.length > 0 ? {
|
|
@@ -218,14 +290,21 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
218
290
|
'$in': catalogers
|
|
219
291
|
} : /.*/ui,
|
|
220
292
|
'creationTime': {
|
|
221
|
-
'$gte': test ?
|
|
222
|
-
'$lte': test ?
|
|
293
|
+
'$gte': test ? new Date(dateAfter).toISOString() : new Date(dateAfter),
|
|
294
|
+
'$lte': test ? new Date(dateBefore).toISOString() : new Date(dateBefore)
|
|
223
295
|
}
|
|
224
296
|
}
|
|
225
297
|
};
|
|
226
298
|
return matchOptions;
|
|
227
299
|
}
|
|
228
300
|
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Protect logs from cleaning. Forced cleaning defaults 30days
|
|
304
|
+
* @param {String} correlationId
|
|
305
|
+
* @param {Integer} blobSequence
|
|
306
|
+
* @returns result
|
|
307
|
+
*/
|
|
229
308
|
async function protect(correlationId, blobSequence) {
|
|
230
309
|
logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);
|
|
231
310
|
const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -252,6 +331,13 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
252
331
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
253
332
|
}
|
|
254
333
|
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Remove logs
|
|
337
|
+
* @param {String} correlationId
|
|
338
|
+
* @param {Boolean} force defaults false
|
|
339
|
+
* @returns result
|
|
340
|
+
*/
|
|
255
341
|
async function remove(correlationId, force = false) {
|
|
256
342
|
logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);
|
|
257
343
|
const clean = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -272,6 +358,14 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
272
358
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
273
359
|
}
|
|
274
360
|
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Remove logs by sequences
|
|
364
|
+
* @param {String} correlationId
|
|
365
|
+
* @param {[Integer]} sequences
|
|
366
|
+
* @param {Boolean} force defaults false
|
|
367
|
+
* @returns result
|
|
368
|
+
*/
|
|
275
369
|
async function removeBySequences(correlationId, sequences = [], force = false) {
|
|
276
370
|
logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);
|
|
277
371
|
const clean = (0, _mongoSanitize.default)(correlationId);
|
|
@@ -304,6 +398,14 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
304
398
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
305
399
|
}
|
|
306
400
|
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Checks existence and validity of logItemType
|
|
404
|
+
* @param {String} logItemType constant LOG_ITEM_TYPE
|
|
405
|
+
* @param {Boolean} errorUnknown defaults false
|
|
406
|
+
* @param {Boolean} errorNotExisting defaults false
|
|
407
|
+
* @returns void
|
|
408
|
+
*/
|
|
307
409
|
function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {
|
|
308
410
|
if (logItemType) {
|
|
309
411
|
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","_luxon","_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","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","DateTime","fromJSDate","startOf","toISODate","endOf","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';\nimport {DateTime} from 'luxon';\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 = 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 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 = '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 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 ? DateTime.fromJSDate(new Date(dateAfter)).startOf('day').toISODate() : new Date(dateAfter),\n '$lte': test ? DateTime.fromJSDate(new Date(dateBefore)).endOf('day').toISODate() : new Date(dateBefore)\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 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 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 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 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,IAA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,EAACJ,KAAK,CAAC;MACf,MAAM,IAAIH,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,kBAAiBE,YAAa,EAAC,CAAC;IACxF;EACF;EAEA,SAASf,gBAAgBA,CAACC,WAAW,EAAE2E,YAAY,GAAG,KAAK,EAAEC,gBAAgB,GAAG,KAAK,EAAE;IACrF,IAAI5E,WAAW,EAAE;MACf,MAAM6E,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAAChD,wBAAa,CAAC,CAACiD,OAAO,CAAChF,WAAW,CAAC,GAAG,CAAC,CAAC;MACjF,IAAI6E,kBAAkB,EAAE;QACtB,OAAOvG,MAAM,CAAC6C,KAAK,CAAE,sBAAqBnB,WAAY,EAAC,CAAC;MAC1D;MACA,IAAI2E,YAAY,EAAE;QAChB,MAAM,IAAIjE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,wBAAuBZ,WAAY,EAAC,CAAC;MAC7F;MACA,OAAO1B,MAAM,CAAC6C,KAAK,CAAE,kCAAiCnB,WAAY,EAAC,CAAC;IACtE;IAEA,IAAI4E,gBAAgB,EAAE;MACpB,MAAM,IAAIlE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,mBAAkBZ,WAAY,EAAC,CAAC;IACxF;IACA,OAAO1B,MAAM,CAAC6C,KAAK,CAAE,mBAAkBnB,WAAY,EAAC,CAAC;EACvD;AACF"}
|
|
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","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-2023 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 * Query 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 constant 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 of correlationIds of logs filtered by logItemType\n * @param {String} logItemType constant 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 existence and validity of logItemType\n * @param {String} logItemType constant LOG_ITEM_TYPE\n * @param {Boolean} errorUnknown defaults false\n * @param {Boolean} errorNotExisting defaults false\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;IAAEC,aAAa;IAAEC,mBAAmB;IAAEC,qBAAqB;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAiB,CAAC;;EAEpI;AACF;AACA;AACA;AACA;EACE,eAAeR,UAAUA,CAACS,OAAO,EAAE;IACjC,MAAMC,IAAI,GAAG,IAAAC,eAAM,EAAC,CAAC,CAACC,MAAM,CAAC,CAAC;IAC9B,MAAMC,UAAU,GAAG;MACjB,GAAGJ,OA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;IACxF;IACA,OAAO1B,MAAM,CAAC+C,KAAK,CAAE,mBAAkBrB,WAAY,EAAC,CAAC;EACvD;AACF"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "AGPL-3.0+",
|
|
17
|
-
"version": "4.0.18
|
|
17
|
+
"version": "4.0.18",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
@@ -39,33 +39,32 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@natlibfi/marc-record": "^8.0.0",
|
|
42
|
-
"@natlibfi/marc-record-serializers": "^10.1.1",
|
|
43
|
-
"@natlibfi/marc-record-validate": "^8.0.
|
|
44
|
-
"@natlibfi/marc-record-validators-melinda": "^10.
|
|
45
|
-
"@natlibfi/melinda-backend-commons": "^2.2.
|
|
46
|
-
"@natlibfi/melinda-commons": "^13.0.
|
|
42
|
+
"@natlibfi/marc-record-serializers": "^10.1.2-alpha.1",
|
|
43
|
+
"@natlibfi/marc-record-validate": "^8.0.3",
|
|
44
|
+
"@natlibfi/marc-record-validators-melinda": "^10.15.0",
|
|
45
|
+
"@natlibfi/melinda-backend-commons": "^2.2.2",
|
|
46
|
+
"@natlibfi/melinda-commons": "^13.0.7",
|
|
47
47
|
"amqplib": "^0.10.3",
|
|
48
48
|
"debug": "^4.3.4",
|
|
49
|
-
"http-status": "^1.7.
|
|
50
|
-
"luxon": "^3.4.3",
|
|
49
|
+
"http-status": "^1.7.3",
|
|
51
50
|
"moment": "^2.29.4",
|
|
52
51
|
"mongo-sanitize": "^1.1.0",
|
|
53
52
|
"mongodb": "^4.17.1"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@babel/cli": "^7.
|
|
57
|
-
"@babel/core": "^7.
|
|
58
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
59
|
-
"@babel/preset-env": "^7.
|
|
55
|
+
"@babel/cli": "^7.23.0",
|
|
56
|
+
"@babel/core": "^7.23.2",
|
|
57
|
+
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
58
|
+
"@babel/preset-env": "^7.23.2",
|
|
60
59
|
"@natlibfi/eslint-config-melinda-backend": "^3.0.2",
|
|
61
|
-
"@natlibfi/fixugen": "^2.0.
|
|
62
|
-
"@natlibfi/fixura": "^3.0.
|
|
63
|
-
"@natlibfi/fixura-mongo": "^2.0.10
|
|
60
|
+
"@natlibfi/fixugen": "^2.0.2",
|
|
61
|
+
"@natlibfi/fixura": "^3.0.2",
|
|
62
|
+
"@natlibfi/fixura-mongo": "^2.0.10",
|
|
64
63
|
"babel-plugin-istanbul": "^6.1.1",
|
|
65
64
|
"babel-plugin-rewire": "^1.2.0",
|
|
66
|
-
"chai": "^4.3.
|
|
65
|
+
"chai": "^4.3.10",
|
|
67
66
|
"cross-env": "^7.0.3",
|
|
68
|
-
"eslint": "^8.
|
|
67
|
+
"eslint": "^8.52.0",
|
|
69
68
|
"mocha": "^10.2.0",
|
|
70
69
|
"nodemon": "^3.0.1",
|
|
71
70
|
"nyc": "^15.1.0"
|