@natlibfi/melinda-rest-api-commons 2.3.1-alpha.5 → 2.3.1-alpha.7
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/constants.js +11 -3
- package/dist/constants.js.map +1 -1
- package/dist/mongoLog.js +29 -2
- package/dist/mongoLog.js.map +1 -1
- package/package.json +1 -1
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.IMPORT_JOB_STATE = exports.CONVERSION_FORMATS = exports.CHUNK_SIZE = void 0;
|
|
6
|
+
exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.IMPORT_JOB_STATE = exports.CONVERSION_FORMATS = exports.CHUNK_SIZE = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -11,7 +11,7 @@ exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.IMPORT_JOB_STATE = expor
|
|
|
11
11
|
*
|
|
12
12
|
* Shared modules for microservices of Melinda rest api batch import system
|
|
13
13
|
*
|
|
14
|
-
* Copyright (C) 2020-
|
|
14
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
15
15
|
*
|
|
16
16
|
* This file is part of melinda-rest-api-commons
|
|
17
17
|
*
|
|
@@ -68,8 +68,16 @@ const OPERATIONS = {
|
|
|
68
68
|
UPDATE: 'UPDATE'
|
|
69
69
|
};
|
|
70
70
|
exports.OPERATIONS = OPERATIONS;
|
|
71
|
-
const CHUNK_SIZE = 100;
|
|
71
|
+
const CHUNK_SIZE = 100; // We could configure here whether a logItemType is for a several records of a single record
|
|
72
|
+
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
73
|
+
|
|
72
74
|
exports.CHUNK_SIZE = CHUNK_SIZE;
|
|
75
|
+
const LOG_ITEM_TYPE = {
|
|
76
|
+
MERGE_LOG: 'MERGE_LOG',
|
|
77
|
+
MATCH_LOG: 'MATCH_LOG',
|
|
78
|
+
SPLITTER_LOG: 'SPLITTER_LOG'
|
|
79
|
+
};
|
|
80
|
+
exports.LOG_ITEM_TYPE = LOG_ITEM_TYPE;
|
|
73
81
|
const CONVERSION_FORMATS = {
|
|
74
82
|
MARCXML: 'MARCXML',
|
|
75
83
|
ISO2709: 'ISO2709',
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.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-
|
|
1
|
+
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.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\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":";;;;;;;AAAA;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;AAEA;AAEO,MAAMA,gBAAgB,GAAG;EAC9BC,SAAS,EAAE;IACTC,eAAe,EAAE,iBADR;IAETC,kBAAkB,EAAE,oBAFX;IAGTC,mBAAmB,EAAE,qBAHZ;IAITC,SAAS,EAAE,WAJF;IAKTC,UAAU,EAAE,YALH;IAMTC,mBAAmB,EAAE;EANZ,CADmB;EAS9BC,QAAQ,EAAE;IACRC,SAAS,EAAE,WADH;IAERC,UAAU,EAAE,YAFJ;IAGRC,QAAQ,EAAE;EAHF,CAToB;EAc9BC,IAAI,EAAE,MAdwB;EAe9BC,KAAK,EAAE,OAfuB;EAgB9BC,KAAK,EAAE;AAhBuB,CAAzB;;AAmBA,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,OADuB;EAE9BC,OAAO,EAAE,SAFqB;EAG9BN,QAAQ,EAAE,UAHoB;EAI9BF,SAAS,EAAE,WAJmB;EAK9BS,UAAU,EAAE,YALkB;EAM9BN,IAAI,EAAE,MANwB;EAO9BC,KAAK,EAAE,OAPuB;EAQ9BC,KAAK,EAAE;AARuB,CAAzB;;AAWA,MAAMK,UAAU,GAAG;EACxBC,MAAM,EAAE,QADgB;EAExBC,MAAM,EAAE;AAFgB,CAAnB;;AAKA,MAAMC,UAAU,GAAG,GAAnB,C,CAEP;AACA;;;AACO,MAAMC,aAAa,GAAG;EAC3BC,SAAS,EAAE,WADgB;EAE3BC,SAAS,EAAE,WAFgB;EAG3BC,YAAY,EAAE;AAHa,CAAtB;;AAMA,MAAMC,kBAAkB,GAAG;EAChCC,OAAO,EAAE,SADuB;EAEhCC,OAAO,EAAE,SAFuB;EAGhCC,IAAI,EAAE,MAH0B;EAIhCC,QAAQ,EAAE;AAJsB,CAA3B"}
|
package/dist/mongoLog.js
CHANGED
|
@@ -19,6 +19,8 @@ var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
|
19
19
|
|
|
20
20
|
var _mongoSanitize = _interopRequireDefault(require("mongo-sanitize"));
|
|
21
21
|
|
|
22
|
+
var _constants = require("./constants");
|
|
23
|
+
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -74,6 +76,7 @@ async function _default(MONGO_URI) {
|
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
try {
|
|
79
|
+
checkLogItemType(logItem.logItemType, false);
|
|
77
80
|
const result = await db.collection(collection).insertOne(newLogItem);
|
|
78
81
|
|
|
79
82
|
if (result.acknowledged) {
|
|
@@ -83,7 +86,7 @@ async function _default(MONGO_URI) {
|
|
|
83
86
|
blobSequenceEnd
|
|
84
87
|
} = logItem;
|
|
85
88
|
const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;
|
|
86
|
-
logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}
|
|
89
|
+
logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -96,6 +99,7 @@ async function _default(MONGO_URI) {
|
|
|
96
99
|
|
|
97
100
|
async function query(params) {
|
|
98
101
|
logger.debug(`Query params: ${JSON.stringify(params)}`);
|
|
102
|
+
checkLogItemType(params.logItemType, false, false);
|
|
99
103
|
const {
|
|
100
104
|
limit = 5,
|
|
101
105
|
skip = 0,
|
|
@@ -123,6 +127,7 @@ async function _default(MONGO_URI) {
|
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
async function getListOfLogs(logItemType = 'MERGE_LOG') {
|
|
130
|
+
checkLogItemType(logItemType, false, false);
|
|
126
131
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
127
132
|
.distinct('correlationId', {
|
|
128
133
|
logItemType
|
|
@@ -135,7 +140,7 @@ async function _default(MONGO_URI) {
|
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
async function protect(correlationId, blobSequence) {
|
|
138
|
-
logger.info(`
|
|
143
|
+
logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);
|
|
139
144
|
const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
|
|
140
145
|
const cleanBlobSequence = (0, _mongoSanitize.default)(blobSequence);
|
|
141
146
|
const filter = blobSequence ? {
|
|
@@ -185,5 +190,27 @@ async function _default(MONGO_URI) {
|
|
|
185
190
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, err.message);
|
|
186
191
|
}
|
|
187
192
|
}
|
|
193
|
+
|
|
194
|
+
function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {
|
|
195
|
+
if (logItemType) {
|
|
196
|
+
const typeInLogItemTypes = Object.values(_constants.LOG_ITEM_TYPE).indexOf(logItemType) > -1;
|
|
197
|
+
|
|
198
|
+
if (typeInLogItemTypes) {
|
|
199
|
+
return logger.debug(`Valid logItemType: ${logItemType}`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (errorUnknown) {
|
|
203
|
+
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return logger.debug(`WARN: We have unknown logType: ${logItemType}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (errorNotExisting) {
|
|
210
|
+
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return logger.debug(`No logItemType: ${logItemType}`);
|
|
214
|
+
}
|
|
188
215
|
}
|
|
189
216
|
//# sourceMappingURL=mongoLog.js.map
|
package/dist/mongoLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","logItemType","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount"],"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';\n\nexport default async function (MONGO_URI) {\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('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\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 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} items ${itemString}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n const {limit = 5, skip = 0, ...rest} = params;\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 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 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 async function getListOfLogs(logItemType = 'MERGE_LOG') {\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 protect(correlationId, blobSequence) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: cleanBlobSequence} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\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 (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n}\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAlCA;AACA;AACA;AACA;AACA;AACA;AACA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MAAM,EAAE7B,MAAM,CAACgD,YAAP,GAAsB,CAAtB,GAA0BrC,mBAAA,CAAWmB,EAArC,GAA0CnB,mBAAA,CAAWoB,SAA9D;QAAyEC,OAAO,EAAEhC,MAAM,CAACgD,YAAP,GAAsB,CAAtB,GAA0BhD,MAA1B,GAAmC;MAArH,CAAP;IACD,CAHD,CAGE,OAAO0C,GAAP,EAAY;MACZ,MAAM,IAAIhC,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAA+C8B,GAAG,CAACC,OAAnD,CAAN;IACD;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","LOG_ITEM_TYPE","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) {\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('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\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 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 return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\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 const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 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 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 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 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: cleanBlobSequence} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\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 (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\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;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;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,wBAAgBA,SAAhB,EAA2B;EACxC,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf,CADwC,CAGxC;;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAA,CAAYC,OAAZ,CAAoBL,SAApB,EAA+B;IAACM,eAAe,EAAE,IAAlB;IAAwBC,kBAAkB,EAAE;EAA5C,CAA/B,CAArB;EACA,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAP,CAAU,UAAV,CAAX;EACA,MAAMC,UAAU,GAAG,MAAnB;EACA,OAAO;IAACC,UAAD;IAAaC,KAAb;IAAoBC,SAApB;IAA+BC,aAA/B;IAA8CC,OAA9C;IAAuDC;EAAvD,CAAP;;EAEA,eAAeL,UAAf,CAA0BM,OAA1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