@natlibfi/melinda-rest-api-commons 2.3.0-alpha.1 → 2.3.0-alpha.4
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/.github/CODEOWNERS +14 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +71 -0
- package/dist/mongoLog.js +16 -5
- package/dist/mongoLog.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /.github/
|
|
2
|
+
# directory at the root of the repository and any of its
|
|
3
|
+
# subdirectories.
|
|
4
|
+
/.github/ @NatLibFi/melinda-js-lead
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /src/
|
|
8
|
+
# directory at the root of the repository and any of its
|
|
9
|
+
# subdirectories.
|
|
10
|
+
/src/ @NatLibFi/melinda-js-lead
|
|
11
|
+
|
|
12
|
+
# With this line @NatLibFi/melinda-js-lead owns package.json file
|
|
13
|
+
# at the root of the repository
|
|
14
|
+
/package.json @NatLibFi/melinda-js-lead
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# NatLibFi/Melinda maintenance strategy
|
|
2
|
+
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
|
|
3
|
+
|
|
4
|
+
version: 2
|
|
5
|
+
updates:
|
|
6
|
+
# Maintain dependencies for GitHub Actions
|
|
7
|
+
- package-ecosystem: "github-actions"
|
|
8
|
+
directory: "/"
|
|
9
|
+
schedule:
|
|
10
|
+
interval: "daily"
|
|
11
|
+
time: "06:30"
|
|
12
|
+
timezone: "Europe/Helsinki"
|
|
13
|
+
|
|
14
|
+
# Minor updates to npm production dependencies daily
|
|
15
|
+
- package-ecosystem: "npm"
|
|
16
|
+
directory: "/"
|
|
17
|
+
schedule:
|
|
18
|
+
interval: "daily"
|
|
19
|
+
time: "06:45"
|
|
20
|
+
timezone: "Europe/Helsinki"
|
|
21
|
+
versioning-strategy: lockfile-only
|
|
22
|
+
labels:
|
|
23
|
+
- "npm minor dependencies"
|
|
24
|
+
allow:
|
|
25
|
+
- dependency-type: "production"
|
|
26
|
+
|
|
27
|
+
# Major updates to npm dependencies weekly @tuesday
|
|
28
|
+
# Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
|
|
29
|
+
# - package-ecosystem: "npm"
|
|
30
|
+
# directory: "/"
|
|
31
|
+
# schedule:
|
|
32
|
+
# interval: "weekly"
|
|
33
|
+
# day: "tuesday"
|
|
34
|
+
# time: "07:00"
|
|
35
|
+
# timezone: "Europe/Helsinki"
|
|
36
|
+
# versioning-strategy: increase-if-necessary
|
|
37
|
+
# labels:
|
|
38
|
+
# - "npm major dependencies"
|
|
39
|
+
# reviewers:
|
|
40
|
+
# - "natlibfi/melinda-js-lead"
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Melinda node tests
|
|
2
|
+
|
|
3
|
+
name: Melinda node tests
|
|
4
|
+
|
|
5
|
+
on: push
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-node-versions:
|
|
9
|
+
name: Node version matrix
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
node-version: [12.x, 14.x, 16.x, 18.x]
|
|
15
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout the code
|
|
19
|
+
uses: actions/checkout@v3
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v3
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: 'npm'
|
|
25
|
+
env:
|
|
26
|
+
NPM_CONFIG_IGNORE_SCRIPTS: true
|
|
27
|
+
- run: npm update
|
|
28
|
+
- run: npm audit --package-lock-only --production --audit-level=high
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm test
|
|
31
|
+
- run: npm run build --if-present
|
|
32
|
+
|
|
33
|
+
license-scan:
|
|
34
|
+
name: License compliance check
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v3
|
|
39
|
+
- uses: mikaelvesavuori/license-compliance-action@v1.0.1
|
|
40
|
+
with:
|
|
41
|
+
exclude_pattern: /^@natlibfi/
|
|
42
|
+
|
|
43
|
+
njsscan:
|
|
44
|
+
name: Njsscan check
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
|
|
47
|
+
steps:
|
|
48
|
+
- name: Checkout the code
|
|
49
|
+
uses: actions/checkout@v3
|
|
50
|
+
- name: nodejsscan scan
|
|
51
|
+
id: njsscan
|
|
52
|
+
uses: ajinabraham/njsscan-action@master
|
|
53
|
+
with:
|
|
54
|
+
args: '.'
|
|
55
|
+
|
|
56
|
+
publish:
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
needs: [build-node-versions, njsscan]
|
|
59
|
+
if: contains(github.ref, 'refs/tags/')
|
|
60
|
+
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/checkout@v3
|
|
63
|
+
# Setup .npmrc file to publish to npm
|
|
64
|
+
- uses: actions/setup-node@v3
|
|
65
|
+
with:
|
|
66
|
+
node-version: '14.x'
|
|
67
|
+
registry-url: 'https://registry.npmjs.org'
|
|
68
|
+
- run: npm ci
|
|
69
|
+
- run: npm publish
|
|
70
|
+
env:
|
|
71
|
+
NODE_AUTH_TOKEN: ${{ secrets.MELINDA_REST_API_COMMONS_NPM_TOKEN }}
|
package/dist/mongoLog.js
CHANGED
|
@@ -87,17 +87,28 @@ async function _default(MONGO_URI) {
|
|
|
87
87
|
|
|
88
88
|
async function query(params) {
|
|
89
89
|
logger.debug(`Query params: ${JSON.stringify(params)}`);
|
|
90
|
-
const
|
|
90
|
+
const {
|
|
91
|
+
limit = 5,
|
|
92
|
+
skip = 0,
|
|
93
|
+
...rest
|
|
94
|
+
} = params;
|
|
95
|
+
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
96
|
+
.find(rest).sort({
|
|
97
|
+
blobSequence: 1
|
|
98
|
+
}).skip(parseInt(skip, 10)).limit(parseInt(limit, 10)).toArray();
|
|
91
99
|
logger.debug(result);
|
|
92
|
-
logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items
|
|
100
|
+
logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);
|
|
93
101
|
return result;
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
async function queryById(correlationIdString) {
|
|
104
|
+
async function queryById(correlationIdString, skip = 0, limit = 1) {
|
|
97
105
|
logger.debug(`QueryById: ${correlationIdString}`);
|
|
98
|
-
const result = await db.collection(collection)
|
|
106
|
+
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
107
|
+
.find({
|
|
99
108
|
correlationId: correlationIdString
|
|
100
|
-
}).
|
|
109
|
+
}).sort({
|
|
110
|
+
blobSequence: 1
|
|
111
|
+
}).skip(parseInt(skip, 10)).limit(parseInt(limit, 10)).toArray();
|
|
101
112
|
logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);
|
|
102
113
|
return result;
|
|
103
114
|
}
|
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","remove","logItem","time","moment","toDate","newLogItem","creationTime","result","insertOne","acknowledged","info","logItemType","correlationId","blobSequenceStart","blobSequenceEnd","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","find","toArray","length","correlationIdString","silly","clean","sanitize","deleteMany","err","message"],"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, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time\n };\n try {\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId} items ${logItem.blobSequenceStart}-${logItem.blobSequenceEnd}. ***`);\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
|
|
1
|
+
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","remove","logItem","time","moment","toDate","newLogItem","creationTime","result","insertOne","acknowledged","info","logItemType","correlationId","blobSequenceStart","blobSequenceEnd","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","blobSequence","parseInt","toArray","length","correlationIdString","silly","clean","sanitize","deleteMany","err","message"],"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, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time\n };\n try {\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId} items ${logItem.blobSequenceStart}-${logItem.blobSequenceEnd}. ***`);\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(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 remove(params) {\n logger.silly(`${JSON.stringify(params)}`);\n logger.info(`Removing from Mongo (${collection}) correlationId: ${params.correlationId}`);\n const clean = sanitize(params.correlationId);\n logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n\n try {\n await db.collection(collection).deleteMany({correlationId: clean});\n return true;\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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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