diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5669035..a4029d8c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.59.2](https://github.com/betagouv/api-subventions-asso/compare/v0.59.1...v0.59.2) (2024-12-17) + +### Bug Fixes + +- **api:** rebuild req to log with string userId ([b09c7c6](https://github.com/betagouv/api-subventions-asso/commit/b09c7c6ab32652f8d7391f58f138418c2958bba5)) + +## [0.59.1](https://github.com/betagouv/api-subventions-asso/compare/v0.59.0...v0.59.1) (2024-12-16) + +### Bug Fixes + +- **api:** put userId elsewhere to not override req ([99c8dbf](https://github.com/betagouv/api-subventions-asso/commit/99c8dbffa56f6ff07f0f3a99772ea59497c02733)) + # [0.59.0](https://github.com/betagouv/api-subventions-asso/compare/v0.58.2...v0.59.0) (2024-12-09) ### Bug Fixes diff --git a/lerna.json b/lerna.json index 1292301fc..29e66de4d 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "packages": ["packages/*"], - "version": "0.59.0", + "version": "0.59.2", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/package-lock.json b/package-lock.json index cb8cb82f6..1baf4f2ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24738,7 +24738,7 @@ } }, "packages/api": { - "version": "0.59.0", + "version": "0.59.2", "license": "MIT", "dependencies": { "@getbrevo/brevo": "^1.0.1", diff --git a/packages/api/CHANGELOG.md b/packages/api/CHANGELOG.md index e08551653..31b75630f 100644 --- a/packages/api/CHANGELOG.md +++ b/packages/api/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.59.2](https://github.com/betagouv/api-subventions-asso/compare/v0.59.1...v0.59.2) (2024-12-17) + +### Bug Fixes + +- **api:** rebuild req to log with string userId ([b09c7c6](https://github.com/betagouv/api-subventions-asso/commit/b09c7c6ab32652f8d7391f58f138418c2958bba5)) + +## [0.59.1](https://github.com/betagouv/api-subventions-asso/compare/v0.59.0...v0.59.1) (2024-12-16) + +### Bug Fixes + +- **api:** put userId elsewhere to not override req ([99c8dbf](https://github.com/betagouv/api-subventions-asso/commit/99c8dbffa56f6ff07f0f3a99772ea59497c02733)) + # [0.59.0](https://github.com/betagouv/api-subventions-asso/compare/v0.58.2...v0.59.0) (2024-12-09) ### Features diff --git a/packages/api/package-lock.json b/packages/api/package-lock.json index f1e71187e..b3931de17 100644 --- a/packages/api/package-lock.json +++ b/packages/api/package-lock.json @@ -1,12 +1,12 @@ { "name": "api", - "version": "0.59.0", + "version": "0.59.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "api", - "version": "0.59.0", + "version": "0.59.2", "license": "MIT", "dependencies": { "@getbrevo/brevo": "^1.0.1", diff --git a/packages/api/package.json b/packages/api/package.json index 5e73ff916..b092e8fb8 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "0.59.0", + "version": "0.59.2", "description": "", "main": "index.js", "engines": { diff --git a/packages/api/src/dataProviders/db/stats/stats.port.ts b/packages/api/src/dataProviders/db/stats/stats.port.ts index 349766f48..fb0b15447 100644 --- a/packages/api/src/dataProviders/db/stats/stats.port.ts +++ b/packages/api/src/dataProviders/db/stats/stats.port.ts @@ -7,8 +7,7 @@ export class StatsPort extends MongoPort<any> { collectionName = "log"; async createIndexes() { - // await this.collection.createIndex({ timestamp: -1 }); - await this.collection.createIndex({ "meta.req.user.email": 1 }); + await this.collection.createIndex({ timestamp: -1 }); await this.collection.createIndex({ "meta.req.user._id": 1 }); // to handle in #1874 // await this.collection.createIndex({ "meta.req.url": 1 }); diff --git a/packages/api/src/middlewares/LogMiddleware.ts b/packages/api/src/middlewares/LogMiddleware.ts index 2fa4d71e5..5963798b7 100644 --- a/packages/api/src/middlewares/LogMiddleware.ts +++ b/packages/api/src/middlewares/LogMiddleware.ts @@ -1,6 +1,7 @@ import winston from "winston"; import expressWinston from "express-winston"; import "winston-mongodb"; +import { ObjectId } from "mongodb"; import { UserDto } from "dto"; import { client } from "../shared/MongoConnection"; @@ -21,6 +22,18 @@ function recursiveFilter(obj: object) { }); } +const requestWhitelist = [ + "url", + "method", + "httpVersion", + "originalUrl", + "query", + "body", + "user", + "connection", + "headers", +]; + export const expressLogger = () => expressWinston.logger({ transports: [ @@ -36,23 +49,14 @@ export const expressLogger = () => ], meta: true, dynamicMeta: function (req, res) { - // completes generated meta in log - return { - req: { user: { _id: (req.user as UserDto)?._id?.toString() } }, - }; + if ((req.user as UserDto)?._id == null) return {}; + // completes generated meta in log, careful it overrides nested values + const whiteReq = {}; + requestWhitelist.map(propertyName => (whiteReq[propertyName] = req[propertyName])); + return { req: { ...whiteReq, user: { ...req.user, _id: (req.user as UserDto)?._id?.toString() } } }; }, msg: "Request: HTTP {{req.method}} {{req.url}}; ipAddress {{req.connection.remoteAddress}}", - requestWhitelist: [ - "url", - "method", - "httpVersion", - "originalUrl", - "query", - "body", - "user", - "connection", - "headers", - ], + requestWhitelist, responseWhitelist: ["statusCode"], ignoreRoute: req => { return LOGGER_IGNORED_ROUTES.some(regex => regex.test(req.url));