From dc318cf4c631af5e0236ba6f799bb7d3bb9878d1 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Mon, 20 May 2024 17:56:06 +0200 Subject: [PATCH 01/36] only use hapi-pino in production, consolidate different logging modules under commons --- packages/auth/src/config/plugins.ts | 20 +++--- packages/auth/src/database.ts | 2 +- .../auth/src/features/authenticate/service.ts | 2 +- .../src/features/invalidateToken/handler.ts | 2 +- .../retrievalSteps/sendUserName/handler.ts | 2 +- .../retrievalSteps/verifyNumber/handler.ts | 2 +- .../auth/src/features/verifyCode/handler.ts | 2 +- packages/auth/src/server.ts | 2 +- packages/commons/package.json | 1 + packages/commons/src/authentication.ts | 2 +- packages/commons/src/index.ts | 1 + packages/{auth => commons}/src/logger.ts | 7 ++- packages/commons/tsconfig.json | 1 + packages/config/src/config/database.ts | 2 +- packages/config/src/config/logger.ts | 17 ----- packages/config/src/config/plugins.ts | 20 +++--- .../application/applicationConfigHandler.ts | 2 +- .../certificate/certificateHandler.ts | 2 +- .../config/src/handlers/forms/formsHandler.ts | 5 +- .../updateInformantSMSNotification/handler.ts | 2 +- packages/config/src/logger.ts | 17 ----- packages/config/src/server.ts | 2 +- packages/config/src/services/documents.ts | 2 +- packages/documents/src/config/plugins.ts | 63 +++++++++---------- packages/documents/src/logger.ts | 17 ----- packages/gateway/src/config/plugins.ts | 21 ++++--- .../src/features/OIDPUserInfo/utils.ts | 2 +- .../src/features/user/root-resolvers.ts | 2 +- .../gateway/src/features/user/utils/index.ts | 2 +- packages/gateway/src/logger.ts | 17 ----- .../gateway/src/routes/verifyCode/handler.ts | 2 +- packages/gateway/src/server.ts | 2 +- packages/gateway/src/utils/documents.ts | 2 +- packages/gateway/src/utils/logger.ts | 22 ------- packages/gateway/src/utils/redis.ts | 2 +- packages/metrics/src/config/database.ts | 2 +- packages/metrics/src/config/plugins.ts | 63 +++++++++---------- .../src/features/performance/viewRefresher.ts | 2 +- packages/metrics/src/influxdb/client.ts | 2 +- packages/metrics/src/logger.ts | 18 ------ packages/notification/src/config/plugins.ts | 20 +++--- packages/notification/src/database.ts | 2 +- .../src/features/email/all-user-handler.ts | 2 +- .../src/features/email/service..ts | 2 +- .../src/features/sms/birth-handler.ts | 2 +- .../src/features/sms/death-handler.ts | 2 +- .../notification/src/features/sms/service.ts | 2 +- .../src/features/sms/user-handler.ts | 2 +- packages/notification/src/logger.ts | 17 ----- packages/search/src/config/plugins.ts | 20 +++--- packages/search/src/config/routes.ts | 2 +- packages/search/src/elasticsearch/dbhelper.ts | 2 +- .../search/src/features/delete/handler.ts | 2 +- .../search/src/features/fhir/fhir-utils.ts | 2 +- .../registration/assignment/handler.ts | 2 +- .../features/registration/birth/handler.ts | 2 +- .../features/registration/death/handler.ts | 2 +- .../registration/deduplicate/handler.ts | 2 +- .../registration/deduplicate/service.ts | 2 +- .../features/registration/marriage/handler.ts | 2 +- .../search/src/features/search/handler.ts | 2 +- .../search/src/features/search/service.ts | 2 +- packages/search/src/logger.ts | 17 ----- packages/user-mgnt/src/config/plugins.ts | 20 +++--- packages/user-mgnt/src/database.ts | 2 +- .../src/features/activateUser/handler.ts | 2 +- .../src/features/changeAvatar/handler.ts | 2 +- .../src/features/changeEmail/handler.ts | 2 +- .../src/features/changePassword/handler.ts | 2 +- .../src/features/changePhone/handler.ts | 2 +- .../src/features/createUser/handler.ts | 2 +- .../src/features/createUser/service.ts | 2 +- .../src/features/resetPassword/handler.ts | 2 +- .../user-mgnt/src/features/system/handler.ts | 2 +- .../src/features/updateRole/handler.ts | 2 +- .../src/features/updateUser/handler.ts | 2 +- .../src/features/userAudit/handler.ts | 2 +- .../src/features/userSearchRecord/handler.ts | 2 +- .../usernameSMSReminderInvite/handler.ts | 2 +- .../features/verifySecurityAnswer/handler.ts | 2 +- packages/user-mgnt/src/logger.ts | 17 ----- packages/user-mgnt/src/server.ts | 2 +- packages/webhooks/src/config/plugins.ts | 20 +++--- packages/webhooks/src/database.ts | 2 +- .../webhooks/src/features/event/handler.ts | 2 +- .../webhooks/src/features/manage/handler.ts | 2 +- packages/webhooks/src/logger.ts | 17 ----- packages/webhooks/src/processor.ts | 2 +- packages/webhooks/src/queue.ts | 2 +- packages/workflow/src/config/plugins.ts | 22 ++++--- .../registration/fhir/fhir-bundle-modifier.ts | 2 +- .../features/registration/fhir/fhir-utils.ts | 2 +- .../registration/sms-notification-utils.ts | 2 +- .../src/features/registration/utils.ts | 2 +- packages/workflow/src/logger.ts | 17 ----- .../workflow/src/records/handler/create.ts | 2 +- .../workflow/src/records/handler/download.ts | 2 +- 97 files changed, 240 insertions(+), 399 deletions(-) rename packages/{auth => commons}/src/logger.ts (83%) delete mode 100644 packages/config/src/config/logger.ts delete mode 100644 packages/config/src/logger.ts delete mode 100644 packages/documents/src/logger.ts delete mode 100644 packages/gateway/src/logger.ts delete mode 100644 packages/gateway/src/utils/logger.ts delete mode 100644 packages/metrics/src/logger.ts delete mode 100644 packages/notification/src/logger.ts delete mode 100644 packages/search/src/logger.ts delete mode 100644 packages/user-mgnt/src/logger.ts delete mode 100644 packages/webhooks/src/logger.ts delete mode 100644 packages/workflow/src/logger.ts diff --git a/packages/auth/src/config/plugins.ts b/packages/auth/src/config/plugins.ts index f3f7c841b28..0f733247518 100644 --- a/packages/auth/src/config/plugins.ts +++ b/packages/auth/src/config/plugins.ts @@ -8,27 +8,27 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ +import { SENTRY_DSN } from '@auth/constants' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { logger } from '@opencrvs/commons' import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@auth/constants' -import { logger } from '@auth/logger' -interface IHapiPlugin { - plugin: typeof Sentry | typeof Pino - options: Record -} +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: IHapiPlugin[] = [ - { + const plugins: IHapiPlugin[] = [] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/auth/src/database.ts b/packages/auth/src/database.ts index c1db79b41c0..c48ece96897 100644 --- a/packages/auth/src/database.ts +++ b/packages/auth/src/database.ts @@ -11,7 +11,7 @@ import * as redis from 'redis' import { REDIS_HOST } from '@auth/constants' import { promisify } from 'util' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' let redisClient: redis.RedisClient diff --git a/packages/auth/src/features/authenticate/service.ts b/packages/auth/src/features/authenticate/service.ts index e20fb42f285..6e372a3a1e2 100644 --- a/packages/auth/src/features/authenticate/service.ts +++ b/packages/auth/src/features/authenticate/service.ts @@ -31,7 +31,7 @@ import { sendVerificationCode, storeVerificationCode } from '@auth/features/verifyCode/service' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' import { unauthorized } from '@hapi/boom' import { chainW, tryCatch } from 'fp-ts/Either' import { pipe } from 'fp-ts/function' diff --git a/packages/auth/src/features/invalidateToken/handler.ts b/packages/auth/src/features/invalidateToken/handler.ts index 615204830a4..986bf8cce3e 100644 --- a/packages/auth/src/features/invalidateToken/handler.ts +++ b/packages/auth/src/features/invalidateToken/handler.ts @@ -13,7 +13,7 @@ import * as Joi from 'joi' import { internal } from '@hapi/boom' import { invalidateToken } from '@auth/features/invalidateToken/service' import { postUserActionToMetrics } from '@auth/features/authenticate/service' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' interface IInvalidateTokenPayload { token: string diff --git a/packages/auth/src/features/retrievalSteps/sendUserName/handler.ts b/packages/auth/src/features/retrievalSteps/sendUserName/handler.ts index 08dc387800a..3eb07c40bdd 100644 --- a/packages/auth/src/features/retrievalSteps/sendUserName/handler.ts +++ b/packages/auth/src/features/retrievalSteps/sendUserName/handler.ts @@ -19,7 +19,7 @@ import { RetrievalSteps, deleteRetrievalStepInformation } from '@auth/features/retrievalSteps/verifyUser/service' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' import { PRODUCTION } from '@auth/constants' import { postUserActionToMetrics } from '@auth/features/authenticate/service' diff --git a/packages/auth/src/features/retrievalSteps/verifyNumber/handler.ts b/packages/auth/src/features/retrievalSteps/verifyNumber/handler.ts index 029f0a574a6..d87ba82857e 100644 --- a/packages/auth/src/features/retrievalSteps/verifyNumber/handler.ts +++ b/packages/auth/src/features/retrievalSteps/verifyNumber/handler.ts @@ -17,7 +17,7 @@ import { } from '@auth/features/retrievalSteps/verifyUser/service' import { checkVerificationCode } from '@auth/features/verifyCode/service' import { unauthorized } from '@hapi/boom' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' interface IVerifyNumberPayload { nonce: string diff --git a/packages/auth/src/features/verifyCode/handler.ts b/packages/auth/src/features/verifyCode/handler.ts index 00d65975c5d..2d913920494 100644 --- a/packages/auth/src/features/verifyCode/handler.ts +++ b/packages/auth/src/features/verifyCode/handler.ts @@ -20,7 +20,7 @@ import { createToken, postUserActionToMetrics } from '@auth/features/authenticate/service' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from '@auth/constants' interface IVerifyPayload { nonce: string diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.ts index 425756dc547..bb8def41742 100644 --- a/packages/auth/src/server.ts +++ b/packages/auth/src/server.ts @@ -67,7 +67,7 @@ import sendUserNameHandler, { requestSchema as reqSendUserNameSchema } from '@auth/features/retrievalSteps/sendUserName/handler' import { tokenHandler } from '@auth/features/system/handler' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' import { getPublicKey } from '@auth/features/authenticate/service' import anonymousTokenHandler, { responseSchema diff --git a/packages/commons/package.json b/packages/commons/package.json index a456da0153d..fba72f573ea 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -8,6 +8,7 @@ ".": "./build/dist/index.js", "./monitoring": "./build/dist/monitoring.js", "./types": "./build/dist/types.js", + "./logger": "./build/dist/logger.js", "./authentication": "./build/dist/authentication.js", "./http": "./build/dist/http.js", "./fixtures": "./build/dist/fixtures.js" diff --git a/packages/commons/src/authentication.ts b/packages/commons/src/authentication.ts index 0739673508d..54ddb43454f 100644 --- a/packages/commons/src/authentication.ts +++ b/packages/commons/src/authentication.ts @@ -10,7 +10,7 @@ */ import { IAuthHeader } from './http' -import * as decode from 'jwt-decode' +import decode from 'jwt-decode' /** All the scopes user can be assigned to */ export const userScopes = { diff --git a/packages/commons/src/index.ts b/packages/commons/src/index.ts index d6c2f371441..491c5b6a8b8 100644 --- a/packages/commons/src/index.ts +++ b/packages/commons/src/index.ts @@ -12,3 +12,4 @@ export * from './token-verifier' export * from './uuid' export * from './documents' export * from './http' +export * from './logger' diff --git a/packages/auth/src/logger.ts b/packages/commons/src/logger.ts similarity index 83% rename from packages/auth/src/logger.ts rename to packages/commons/src/logger.ts index bc3f171a97d..84e264d2433 100644 --- a/packages/auth/src/logger.ts +++ b/packages/commons/src/logger.ts @@ -9,7 +9,12 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import pino from 'pino' -export const logger = pino() +export const logger = + process.env.NODE_ENV === 'production' + ? pino() + : pino({ + prettyPrint: true + }) const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL if (level) { diff --git a/packages/commons/tsconfig.json b/packages/commons/tsconfig.json index f0c37bf1f92..bda401ca544 100644 --- a/packages/commons/tsconfig.json +++ b/packages/commons/tsconfig.json @@ -11,6 +11,7 @@ "moduleResolution": "node", "rootDir": "src", "declaration": true, + "esModuleInterop": true, "lib": ["esnext.asynciterable", "es2015", "es6"], "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, diff --git a/packages/config/src/config/database.ts b/packages/config/src/config/database.ts index 5f9a309fe85..e8c6aed0a13 100644 --- a/packages/config/src/config/database.ts +++ b/packages/config/src/config/database.ts @@ -10,7 +10,7 @@ */ import * as mongoose from 'mongoose' import { MONGO_URL } from '@config/config/constants' -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' const db = mongoose.connection diff --git a/packages/config/src/config/logger.ts b/packages/config/src/config/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/config/src/config/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/config/src/config/plugins.ts b/packages/config/src/config/plugins.ts index e56a526119b..1112d36fd00 100644 --- a/packages/config/src/config/plugins.ts +++ b/packages/config/src/config/plugins.ts @@ -8,24 +8,28 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' -import * as Sentry from 'hapi-sentry' +import { logger } from '@opencrvs/commons' import { SENTRY_DSN } from '@config/config/constants' +import { ServerRegisterPluginObject } from '@hapi/hapi' import * as JWT from 'hapi-auth-jwt2' -import { logger } from '@config/config/logger' +import * as Pino from 'hapi-pino' +import * as Sentry from 'hapi-sentry' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/config/src/handlers/application/applicationConfigHandler.ts b/packages/config/src/handlers/application/applicationConfigHandler.ts index 1b24ab614fd..0dada30b644 100644 --- a/packages/config/src/handlers/application/applicationConfigHandler.ts +++ b/packages/config/src/handlers/application/applicationConfigHandler.ts @@ -12,7 +12,7 @@ import * as Hapi from '@hapi/hapi' import ApplicationConfig, { IApplicationConfigurationModel } from '@config/models/config' -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' import { badData, internal } from '@hapi/boom' import * as Joi from 'joi' import { merge, pick } from 'lodash' diff --git a/packages/config/src/handlers/certificate/certificateHandler.ts b/packages/config/src/handlers/certificate/certificateHandler.ts index c4ebc5ab79b..7081820aba0 100644 --- a/packages/config/src/handlers/certificate/certificateHandler.ts +++ b/packages/config/src/handlers/certificate/certificateHandler.ts @@ -14,7 +14,7 @@ import Certificate, { Status, Event } from '@config/models/certificate' // IDeclarationConfigurationModel -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' import * as Joi from 'joi' import { badRequest, notFound } from '@hapi/boom' import { verifyToken } from '@config/utils/verifyToken' diff --git a/packages/config/src/handlers/forms/formsHandler.ts b/packages/config/src/handlers/forms/formsHandler.ts index 2d6dd9b12ff..3801ade0765 100644 --- a/packages/config/src/handlers/forms/formsHandler.ts +++ b/packages/config/src/handlers/forms/formsHandler.ts @@ -15,7 +15,7 @@ import FormVersions, { } from '@config/models/formVersions' import * as Hapi from '@hapi/hapi' import fetch from 'node-fetch' -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' import { badData } from '@hapi/boom' import { registrationForms } from './validation' import { fromZodError } from 'zod-validation-error' @@ -40,7 +40,8 @@ export default async function getForm( if (response.status !== 200) { logger.error('Country config did not return 200 on forms endpoint') - return h.response().code(400) + logger.error(response.statusText) + return h.response().code(500) } const forms: IFormsPayload = await response.json() diff --git a/packages/config/src/handlers/informantSMSNotifications/updateInformantSMSNotification/handler.ts b/packages/config/src/handlers/informantSMSNotifications/updateInformantSMSNotification/handler.ts index 01c5488abc7..d8f849762a5 100644 --- a/packages/config/src/handlers/informantSMSNotifications/updateInformantSMSNotification/handler.ts +++ b/packages/config/src/handlers/informantSMSNotifications/updateInformantSMSNotification/handler.ts @@ -10,7 +10,7 @@ */ import * as Hapi from '@hapi/hapi' -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' import * as Joi from 'joi' import InformantSMSNotification from '@config/models/informantSMSNotifications' import { badRequest } from '@hapi/boom' diff --git a/packages/config/src/logger.ts b/packages/config/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/config/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/config/src/server.ts b/packages/config/src/server.ts index 33e94b3ff60..f3aeef1a6df 100644 --- a/packages/config/src/server.ts +++ b/packages/config/src/server.ts @@ -26,7 +26,7 @@ import getPlugins from '@config/config/plugins' import * as database from '@config/config/database' import { validateFunc } from '@opencrvs/commons' import { readFileSync } from 'fs' -import { logger } from '@config/logger' +import { logger } from '@opencrvs/commons' import { Boom, badRequest } from '@hapi/boom' export const publicCert = readFileSync(CERT_PUBLIC_KEY_PATH) diff --git a/packages/config/src/services/documents.ts b/packages/config/src/services/documents.ts index 196a30b75cd..7158c86c94f 100644 --- a/packages/config/src/services/documents.ts +++ b/packages/config/src/services/documents.ts @@ -11,7 +11,7 @@ import fetch from 'node-fetch' import { DOCUMENTS_URL } from '@config/config/constants' import { internal } from '@hapi/boom' -import { logger } from '@config/logger' +import { logger } from '@opencrvs/commons' interface IAuthHeader { Authorization: string diff --git a/packages/documents/src/config/plugins.ts b/packages/documents/src/config/plugins.ts index 76e92f42be7..276595b4b23 100644 --- a/packages/documents/src/config/plugins.ts +++ b/packages/documents/src/config/plugins.ts @@ -8,42 +8,41 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { SENTRY_DSN } from '@documents/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@documents/constants' -import { logger } from '@documents/logger' + +import { ServerRegisterPluginObject } from '@hapi/hapi' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - ...(process.env.NODE_ENV === 'test' || process.env.LOG_LEVEL === 'silent' - ? [] - : [ - { - plugin: Pino, - options: { - prettyPrint: false, - logPayload: false, - instance: logger - } - }, - ...(!SENTRY_DSN - ? [] - : [ - { - plugin: Sentry, - options: { - client: { - environment: process.env.DOMAIN, - dsn: SENTRY_DSN - }, - catchLogErrors: true - } - } - ]) - ]) - ] + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ + plugin: Pino, + options: { + prettyPrint: false, + logPayload: false, + instance: logger + } + }) + } + if (SENTRY_DSN) { + plugins.push({ + plugin: Sentry, + options: { + client: { + environment: process.env.DOMAIN, + dsn: SENTRY_DSN + }, + catchLogErrors: true + } + }) + } return plugins } diff --git a/packages/documents/src/logger.ts b/packages/documents/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/documents/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/gateway/src/config/plugins.ts b/packages/gateway/src/config/plugins.ts index b4e110c8498..f34cb6b42c8 100644 --- a/packages/gateway/src/config/plugins.ts +++ b/packages/gateway/src/config/plugins.ts @@ -13,7 +13,7 @@ import * as JWT from 'hapi-auth-jwt2' import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' import { SENTRY_DSN } from '@gateway/constants' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import * as HapiSwagger from 'hapi-swagger' import { ServerRegisterPluginObject } from '@hapi/hapi' import * as H2o2 from '@hapi/h2o2' @@ -33,14 +33,6 @@ export const getPlugins = () => { const plugins = [ JWT, - { - plugin: Pino, - options: { - prettyPrint: true, - logPayload: false, - instance: logger - } - }, { plugin: HapiSwagger, options: swaggerOptions @@ -48,6 +40,17 @@ export const getPlugins = () => { H2o2 ] as Array> + if (process.env.NODE_ENV === 'production') { + plugins.push({ + plugin: Pino, + options: { + prettyPrint: false, + logPayload: false, + instance: logger + } + }) + } + if (SENTRY_DSN) { plugins.push({ plugin: Sentry, diff --git a/packages/gateway/src/features/OIDPUserInfo/utils.ts b/packages/gateway/src/features/OIDPUserInfo/utils.ts index c552df60b5e..f72a46f9f69 100644 --- a/packages/gateway/src/features/OIDPUserInfo/utils.ts +++ b/packages/gateway/src/features/OIDPUserInfo/utils.ts @@ -17,7 +17,7 @@ import { OIDP_JWT_AUD_CLAIM } from '@gateway/constants' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import { OIDPUserInfo } from './oidp-types' import { Bundle, Location } from '@opencrvs/commons/types' import { fetchFromHearth } from '@gateway/features/fhir/service' diff --git a/packages/gateway/src/features/user/root-resolvers.ts b/packages/gateway/src/features/user/root-resolvers.ts index c27f068e0f6..bb80c257f54 100644 --- a/packages/gateway/src/features/user/root-resolvers.ts +++ b/packages/gateway/src/features/user/root-resolvers.ts @@ -29,7 +29,7 @@ import { GQLUserIdentifierInput, GQLUserInput } from '@gateway/graphql/schema' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import { checkVerificationCode } from '@gateway/routes/verifyCode/handler' import { UserInputError } from 'apollo-server-hapi' import fetch from '@gateway/fetch' diff --git a/packages/gateway/src/features/user/utils/index.ts b/packages/gateway/src/features/user/utils/index.ts index eb5de2f3f7c..f69d0094562 100644 --- a/packages/gateway/src/features/user/utils/index.ts +++ b/packages/gateway/src/features/user/utils/index.ts @@ -14,7 +14,7 @@ import { ISystemModelData, IUserModelData } from '@gateway/features/user/type-resolvers' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import * as decode from 'jwt-decode' import fetch from '@gateway/fetch' import { Scope } from '@opencrvs/commons/authentication' diff --git a/packages/gateway/src/logger.ts b/packages/gateway/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/gateway/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/gateway/src/routes/verifyCode/handler.ts b/packages/gateway/src/routes/verifyCode/handler.ts index 731229d5cdd..2ce99dcb62a 100644 --- a/packages/gateway/src/routes/verifyCode/handler.ts +++ b/packages/gateway/src/routes/verifyCode/handler.ts @@ -24,7 +24,7 @@ import { readFileSync } from 'fs' import * as jwt from 'jsonwebtoken' import fetch from '@gateway/fetch' import { unauthorized } from '@hapi/boom' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import * as t from 'io-ts' import * as F from 'fp-ts' diff --git a/packages/gateway/src/server.ts b/packages/gateway/src/server.ts index d3077cccb04..5c00d3d8d9e 100644 --- a/packages/gateway/src/server.ts +++ b/packages/gateway/src/server.ts @@ -32,7 +32,7 @@ import { import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core' import { getApolloConfig } from '@gateway/graphql/config' import * as database from '@gateway/utils/redis' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import { badRequest, Boom } from '@hapi/boom' import { RateLimitError } from './rate-limit' diff --git a/packages/gateway/src/utils/documents.ts b/packages/gateway/src/utils/documents.ts index 66d6ff8356a..2c0dc1ae737 100644 --- a/packages/gateway/src/utils/documents.ts +++ b/packages/gateway/src/utils/documents.ts @@ -11,7 +11,7 @@ import fetch from '@gateway/fetch' import { DOCUMENTS_URL } from '@gateway/constants' import { internal } from '@hapi/boom' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import { IAuthHeader } from '@opencrvs/commons' export async function uploadSvg(fileData: string, authHeader: IAuthHeader) { diff --git a/packages/gateway/src/utils/logger.ts b/packages/gateway/src/utils/logger.ts deleted file mode 100644 index 00570937227..00000000000 --- a/packages/gateway/src/utils/logger.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import * as Bunyan from 'bunyan' - -export const getLogger = ( - logLevel: number | undefined, - appName: string | undefined -) => { - return Bunyan.createLogger({ - name: appName ? appName : 'testApp', - level: logLevel ? logLevel : 0, - serializers: Bunyan.stdSerializers - }) -} diff --git a/packages/gateway/src/utils/redis.ts b/packages/gateway/src/utils/redis.ts index 77cdcab2b7c..cda564209f1 100644 --- a/packages/gateway/src/utils/redis.ts +++ b/packages/gateway/src/utils/redis.ts @@ -11,7 +11,7 @@ import * as redis from 'redis' import { REDIS_HOST } from '@gateway/constants' import { promisify } from 'util' -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' let redisClient: redis.RedisClient diff --git a/packages/metrics/src/config/database.ts b/packages/metrics/src/config/database.ts index 362de546d33..e18edcb0cfd 100644 --- a/packages/metrics/src/config/database.ts +++ b/packages/metrics/src/config/database.ts @@ -10,7 +10,7 @@ */ import * as mongoose from 'mongoose' import { MONGO_URL } from '@metrics/constants' -import { logger } from '@metrics/logger' +import { logger } from '@opencrvs/commons' const db = mongoose.connection diff --git a/packages/metrics/src/config/plugins.ts b/packages/metrics/src/config/plugins.ts index 1a61ddf7229..89e5bd35fe5 100644 --- a/packages/metrics/src/config/plugins.ts +++ b/packages/metrics/src/config/plugins.ts @@ -8,42 +8,41 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { SENTRY_DSN } from '@metrics/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@metrics/constants' -import { logger } from '@metrics/logger' + +import { ServerRegisterPluginObject } from '@hapi/hapi' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - ...(process.env.NODE_ENV === 'test' || process.env.LOG_LEVEL === 'silent' - ? [] - : [ - { - plugin: Pino, - options: { - prettyPrint: false, - logPayload: false, - instance: logger - } - }, - ...(!SENTRY_DSN - ? [] - : [ - { - plugin: Sentry, - options: { - client: { - environment: process.env.DOMAIN, - dsn: SENTRY_DSN - }, - catchLogErrors: true - } - } - ]) - ]) - ] + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ + plugin: Pino, + options: { + prettyPrint: false, + logPayload: false, + instance: logger + } + }) + } + if (SENTRY_DSN) { + plugins.push({ + plugin: Sentry, + options: { + client: { + environment: process.env.DOMAIN, + dsn: SENTRY_DSN + }, + catchLogErrors: true + } + }) + } return plugins } diff --git a/packages/metrics/src/features/performance/viewRefresher.ts b/packages/metrics/src/features/performance/viewRefresher.ts index 6bdde683cb1..a8d566adff5 100644 --- a/packages/metrics/src/features/performance/viewRefresher.ts +++ b/packages/metrics/src/features/performance/viewRefresher.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { HEARTH_MONGO_URL } from '@metrics/constants' -import { logger } from '@metrics/logger' +import { logger } from '@opencrvs/commons' import { MongoClient } from 'mongodb' /* diff --git a/packages/metrics/src/influxdb/client.ts b/packages/metrics/src/influxdb/client.ts index b02161bde59..890a8d485c5 100644 --- a/packages/metrics/src/influxdb/client.ts +++ b/packages/metrics/src/influxdb/client.ts @@ -14,7 +14,7 @@ import { INFLUX_HOST, INFLUX_PORT } from '@metrics/influxdb/constants' -import { logger } from '@metrics/logger' +import { logger } from '@opencrvs/commons' import { IPoints } from '@metrics/features/registration' import fetch from 'node-fetch' diff --git a/packages/metrics/src/logger.ts b/packages/metrics/src/logger.ts deleted file mode 100644 index 1b5fc33092c..00000000000 --- a/packages/metrics/src/logger.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL - -if (level) { - logger.level = level -} diff --git a/packages/notification/src/config/plugins.ts b/packages/notification/src/config/plugins.ts index fa2c863d419..809bb945721 100644 --- a/packages/notification/src/config/plugins.ts +++ b/packages/notification/src/config/plugins.ts @@ -9,24 +9,28 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { SENTRY_DSN } from '@notification/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@notification/constants' -import { logger } from '@notification/logger' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/notification/src/database.ts b/packages/notification/src/database.ts index 0f538e900a5..b21294dd228 100644 --- a/packages/notification/src/database.ts +++ b/packages/notification/src/database.ts @@ -11,7 +11,7 @@ import * as mongoose from 'mongoose' import { MONGO_URL } from '@notification/constants' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' const db = mongoose.connection diff --git a/packages/notification/src/features/email/all-user-handler.ts b/packages/notification/src/features/email/all-user-handler.ts index 587bbf56514..1470683c756 100644 --- a/packages/notification/src/features/email/all-user-handler.ts +++ b/packages/notification/src/features/email/all-user-handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import * as Hapi from '@hapi/hapi' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import * as Joi from 'joi' import { sendAllUserEmails } from './service.' diff --git a/packages/notification/src/features/email/service..ts b/packages/notification/src/features/email/service..ts index 9e933776e5e..0891ccf3f7b 100644 --- a/packages/notification/src/features/email/service..ts +++ b/packages/notification/src/features/email/service..ts @@ -12,7 +12,7 @@ import NotificationQueue, { NotificationQueueRecord } from '@notification/model/notificationQueue' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import { notifyCountryConfig } from '@notification/features/sms/service' import { internal, tooManyRequests } from '@hapi/boom' import * as Hapi from '@hapi/hapi' diff --git a/packages/notification/src/features/sms/birth-handler.ts b/packages/notification/src/features/sms/birth-handler.ts index 524f6d728c6..59fd8da5edd 100644 --- a/packages/notification/src/features/sms/birth-handler.ts +++ b/packages/notification/src/features/sms/birth-handler.ts @@ -14,7 +14,7 @@ import { sendNotification, IEventMessageRecipient } from '@notification/features/sms/utils' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import { messageKeys } from '@notification/i18n/messages' export interface IInProgressPayload extends IEventMessageRecipient { diff --git a/packages/notification/src/features/sms/death-handler.ts b/packages/notification/src/features/sms/death-handler.ts index 27e197cf3dc..2817d909157 100644 --- a/packages/notification/src/features/sms/death-handler.ts +++ b/packages/notification/src/features/sms/death-handler.ts @@ -16,7 +16,7 @@ import { IRejectionPayload } from '@notification/features/sms/birth-handler' import { sendNotification } from '@notification/features/sms/utils' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import { messageKeys } from '@notification/i18n/messages' export async function sendDeathInProgressConfirmation( diff --git a/packages/notification/src/features/sms/service.ts b/packages/notification/src/features/sms/service.ts index ad7662e4ad3..c0732a174b2 100644 --- a/packages/notification/src/features/sms/service.ts +++ b/packages/notification/src/features/sms/service.ts @@ -11,7 +11,7 @@ import fetch from 'node-fetch' import { COUNTRY_CONFIG_URL } from '@notification/constants' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' export async function notifyCountryConfig( templateName: { diff --git a/packages/notification/src/features/sms/user-handler.ts b/packages/notification/src/features/sms/user-handler.ts index 3795e23b1fc..316a74d15ab 100644 --- a/packages/notification/src/features/sms/user-handler.ts +++ b/packages/notification/src/features/sms/user-handler.ts @@ -14,7 +14,7 @@ import { IMessageRecipient, sendNotification } from '@notification/features/sms/utils' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import { templateNames } from '@notification/i18n/messages' interface ICredentialsPayload extends IMessageRecipient { diff --git a/packages/notification/src/logger.ts b/packages/notification/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/notification/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/search/src/config/plugins.ts b/packages/search/src/config/plugins.ts index d341c8ab684..e3e1310a8d5 100644 --- a/packages/search/src/config/plugins.ts +++ b/packages/search/src/config/plugins.ts @@ -8,24 +8,28 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { SENTRY_DSN } from '@search/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@search/constants' -import { logger } from '@search/logger' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/search/src/config/routes.ts b/packages/search/src/config/routes.ts index dbdddc3f681..ae937a33d00 100644 --- a/packages/search/src/config/routes.ts +++ b/packages/search/src/config/routes.ts @@ -24,7 +24,7 @@ import { } from '@search/features/registration/assignment/handler' import { deleteOCRVSIndexHandler } from '@search/features/delete/handler' import { client } from '@search/elasticsearch/client' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { recordHandler } from '@search/features/registration/record/handler' import { getRecordByIdHandler } from '@search/features/records/handler' diff --git a/packages/search/src/elasticsearch/dbhelper.ts b/packages/search/src/elasticsearch/dbhelper.ts index 0e3ec347463..ec4553f5cbc 100644 --- a/packages/search/src/elasticsearch/dbhelper.ts +++ b/packages/search/src/elasticsearch/dbhelper.ts @@ -11,7 +11,7 @@ import { OPENCRVS_INDEX_NAME } from '@search/constants' import { ISearchResponse } from '@search/elasticsearch/client' import { ICompositionBody } from '@search/elasticsearch/utils' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import * as elasticsearch from '@elastic/elasticsearch' export const indexComposition = async ( diff --git a/packages/search/src/features/delete/handler.ts b/packages/search/src/features/delete/handler.ts index a47b15045cd..c53c90146d7 100644 --- a/packages/search/src/features/delete/handler.ts +++ b/packages/search/src/features/delete/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import * as Hapi from '@hapi/hapi' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import { client } from '@search/elasticsearch/client' import { OPENCRVS_INDEX_NAME } from '@search/constants' diff --git a/packages/search/src/features/fhir/fhir-utils.ts b/packages/search/src/features/fhir/fhir-utils.ts index 352420f1b4e..474778a1180 100644 --- a/packages/search/src/features/fhir/fhir-utils.ts +++ b/packages/search/src/features/fhir/fhir-utils.ts @@ -32,7 +32,7 @@ import { ICompositionBody, IDeathCompositionBody } from '@search/elasticsearch/utils' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import fetch from 'node-fetch' export interface ITemplatedComposition extends fhir.Composition { diff --git a/packages/search/src/features/registration/assignment/handler.ts b/packages/search/src/features/registration/assignment/handler.ts index dcadd6c0da3..5172aa4eb46 100644 --- a/packages/search/src/features/registration/assignment/handler.ts +++ b/packages/search/src/features/registration/assignment/handler.ts @@ -12,7 +12,7 @@ import { updateEventToAddAssignment, updateEventToRemoveAssignment } from '@search/features/registration/assignment/service' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import * as Hapi from '@hapi/hapi' import { getTokenPayload } from '@search/utils/authUtils' diff --git a/packages/search/src/features/registration/birth/handler.ts b/packages/search/src/features/registration/birth/handler.ts index dfcb4c19fb0..455b091b8ac 100644 --- a/packages/search/src/features/registration/birth/handler.ts +++ b/packages/search/src/features/registration/birth/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { upsertEvent } from '@search/features/registration/birth/service' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import * as Hapi from '@hapi/hapi' diff --git a/packages/search/src/features/registration/death/handler.ts b/packages/search/src/features/registration/death/handler.ts index e4dacb54e75..b6759ef6cdc 100644 --- a/packages/search/src/features/registration/death/handler.ts +++ b/packages/search/src/features/registration/death/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { upsertEvent } from '@search/features/registration/death/service' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import * as Hapi from '@hapi/hapi' diff --git a/packages/search/src/features/registration/deduplicate/handler.ts b/packages/search/src/features/registration/deduplicate/handler.ts index df41576ed62..2cf923420ce 100644 --- a/packages/search/src/features/registration/deduplicate/handler.ts +++ b/packages/search/src/features/registration/deduplicate/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import * as Hapi from '@hapi/hapi' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import { removeDuplicate } from '@search/features/registration/deduplicate/service' import { client } from '@search/elasticsearch/client' diff --git a/packages/search/src/features/registration/deduplicate/service.ts b/packages/search/src/features/registration/deduplicate/service.ts index 593dad36667..832a68dad6c 100644 --- a/packages/search/src/features/registration/deduplicate/service.ts +++ b/packages/search/src/features/registration/deduplicate/service.ts @@ -21,7 +21,7 @@ import { import { get } from 'lodash' import { ISearchResponse } from '@search/elasticsearch/client' import { OPENCRVS_INDEX_NAME } from '@search/constants' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { subYears, addYears, diff --git a/packages/search/src/features/registration/marriage/handler.ts b/packages/search/src/features/registration/marriage/handler.ts index 93ddf3d576f..e6e07703173 100644 --- a/packages/search/src/features/registration/marriage/handler.ts +++ b/packages/search/src/features/registration/marriage/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { upsertEvent } from '@search/features/registration/marriage/service' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { internal } from '@hapi/boom' import * as Hapi from '@hapi/hapi' diff --git a/packages/search/src/features/search/handler.ts b/packages/search/src/features/search/handler.ts index daab49afff9..4b6848a7d0a 100644 --- a/packages/search/src/features/search/handler.ts +++ b/packages/search/src/features/search/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import * as Hapi from '@hapi/hapi' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { badRequest, internal } from '@hapi/boom' import { DEFAULT_SIZE, advancedSearch } from '@search/features/search/service' import { ISearchCriteria } from '@search/features/search/types' diff --git a/packages/search/src/features/search/service.ts b/packages/search/src/features/search/service.ts index 212046cd308..5f8488c70c3 100644 --- a/packages/search/src/features/search/service.ts +++ b/packages/search/src/features/search/service.ts @@ -12,7 +12,7 @@ import { client, ISearchResponse } from '@search/elasticsearch/client' import { ApiResponse } from '@elastic/elasticsearch' import { ISearchCriteria, SortOrder } from '@search/features/search/types' import { advancedQueryBuilder } from '@search/features/search/utils' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { OPENCRVS_INDEX_NAME } from '@search/constants' export const DEFAULT_SIZE = 10 diff --git a/packages/search/src/logger.ts b/packages/search/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/search/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/user-mgnt/src/config/plugins.ts b/packages/user-mgnt/src/config/plugins.ts index fb03d1f1c8a..40487a91d66 100644 --- a/packages/user-mgnt/src/config/plugins.ts +++ b/packages/user-mgnt/src/config/plugins.ts @@ -8,24 +8,28 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { SENTRY_DSN } from '@user-mgnt/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@user-mgnt/constants' -import { logger } from '@user-mgnt/logger' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/user-mgnt/src/database.ts b/packages/user-mgnt/src/database.ts index 3b7ab471166..f9ac212f076 100644 --- a/packages/user-mgnt/src/database.ts +++ b/packages/user-mgnt/src/database.ts @@ -11,7 +11,7 @@ import * as mongoose from 'mongoose' import { MONGO_URL } from '@user-mgnt/constants' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' const db = mongoose.connection diff --git a/packages/user-mgnt/src/features/activateUser/handler.ts b/packages/user-mgnt/src/features/activateUser/handler.ts index ea853ac11a1..0981d8539e7 100644 --- a/packages/user-mgnt/src/features/activateUser/handler.ts +++ b/packages/user-mgnt/src/features/activateUser/handler.ts @@ -13,7 +13,7 @@ import * as Joi from 'joi' import { unauthorized } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' import { generateSaltedHash, generateHash } from '@user-mgnt/utils/hash' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { statuses } from '@user-mgnt/utils/userUtils' interface ISecurityQNA { diff --git a/packages/user-mgnt/src/features/changeAvatar/handler.ts b/packages/user-mgnt/src/features/changeAvatar/handler.ts index d3a0bc51cac..69eee5b484a 100644 --- a/packages/user-mgnt/src/features/changeAvatar/handler.ts +++ b/packages/user-mgnt/src/features/changeAvatar/handler.ts @@ -12,7 +12,7 @@ import * as Hapi from '@hapi/hapi' import * as Joi from 'joi' import { unauthorized } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { statuses } from '@user-mgnt/utils/userUtils' interface IChangeAvatarPayload { diff --git a/packages/user-mgnt/src/features/changeEmail/handler.ts b/packages/user-mgnt/src/features/changeEmail/handler.ts index 2fad93cac75..747eb11eb3a 100644 --- a/packages/user-mgnt/src/features/changeEmail/handler.ts +++ b/packages/user-mgnt/src/features/changeEmail/handler.ts @@ -12,7 +12,7 @@ import * as Hapi from '@hapi/hapi' import * as Joi from 'joi' import { unauthorized } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { statuses } from '@user-mgnt/utils/userUtils' import { resolve } from 'url' import fetch from 'node-fetch' diff --git a/packages/user-mgnt/src/features/changePassword/handler.ts b/packages/user-mgnt/src/features/changePassword/handler.ts index e4826cfa591..0187e0efb1f 100644 --- a/packages/user-mgnt/src/features/changePassword/handler.ts +++ b/packages/user-mgnt/src/features/changePassword/handler.ts @@ -13,7 +13,7 @@ import * as Joi from 'joi' import { unauthorized } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' import { generateHash } from '@user-mgnt/utils/hash' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { statuses } from '@user-mgnt/utils/userUtils' import { postUserActionToMetrics } from '@user-mgnt/features/changePhone/handler' diff --git a/packages/user-mgnt/src/features/changePhone/handler.ts b/packages/user-mgnt/src/features/changePhone/handler.ts index 06a78306b3a..7ad4afc464f 100644 --- a/packages/user-mgnt/src/features/changePhone/handler.ts +++ b/packages/user-mgnt/src/features/changePhone/handler.ts @@ -12,7 +12,7 @@ import * as Hapi from '@hapi/hapi' import * as Joi from 'joi' import { unauthorized } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { statuses } from '@user-mgnt/utils/userUtils' import { resolve } from 'url' import fetch from 'node-fetch' diff --git a/packages/user-mgnt/src/features/createUser/handler.ts b/packages/user-mgnt/src/features/createUser/handler.ts index 705f20b88ca..902cd9842f0 100644 --- a/packages/user-mgnt/src/features/createUser/handler.ts +++ b/packages/user-mgnt/src/features/createUser/handler.ts @@ -17,7 +17,7 @@ import { sendCredentialsNotification, getCatchmentAreaIdsByPrimaryOfficeId } from '@user-mgnt/features/createUser/service' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { IUser, IUserModel } from '@user-mgnt/model/user' import { generateSaltedHash, diff --git a/packages/user-mgnt/src/features/createUser/service.ts b/packages/user-mgnt/src/features/createUser/service.ts index d87d8e8f725..54a17b62213 100644 --- a/packages/user-mgnt/src/features/createUser/service.ts +++ b/packages/user-mgnt/src/features/createUser/service.ts @@ -11,7 +11,7 @@ import { FHIR_URL, NOTIFICATION_SERVICE_URL } from '@user-mgnt/constants' import User, { IUser, IUserName, UserRole } from '@user-mgnt/model/user' import fetch from 'node-fetch' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' export const createFhirPractitioner = ( user: IUser, diff --git a/packages/user-mgnt/src/features/resetPassword/handler.ts b/packages/user-mgnt/src/features/resetPassword/handler.ts index 49d7b0c6fcf..20d7b96efb2 100644 --- a/packages/user-mgnt/src/features/resetPassword/handler.ts +++ b/packages/user-mgnt/src/features/resetPassword/handler.ts @@ -18,7 +18,7 @@ import { } from '@user-mgnt/utils/hash' import { getUserId, hasDemoScope, statuses } from '@user-mgnt/utils/userUtils' import { NOTIFICATION_SERVICE_URL } from '@user-mgnt/constants' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { postUserActionToMetrics } from '@user-mgnt/features/changePhone/handler' import fetch from 'node-fetch' diff --git a/packages/user-mgnt/src/features/system/handler.ts b/packages/user-mgnt/src/features/system/handler.ts index 2258e0902d3..664986db97b 100644 --- a/packages/user-mgnt/src/features/system/handler.ts +++ b/packages/user-mgnt/src/features/system/handler.ts @@ -18,7 +18,7 @@ import { createFhirPractitionerRole, postFhir } from '@user-mgnt/features/createUser/service' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import System, { ISystemModel, WebhookPermissions diff --git a/packages/user-mgnt/src/features/updateRole/handler.ts b/packages/user-mgnt/src/features/updateRole/handler.ts index 60a8a6fcb98..f37daecea84 100644 --- a/packages/user-mgnt/src/features/updateRole/handler.ts +++ b/packages/user-mgnt/src/features/updateRole/handler.ts @@ -11,7 +11,7 @@ import * as Hapi from '@hapi/hapi' import { Types } from 'mongoose' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { UserRole } from '@user-mgnt/model/user' import SystemRole, { ISystemRoleModel, diff --git a/packages/user-mgnt/src/features/updateUser/handler.ts b/packages/user-mgnt/src/features/updateUser/handler.ts index 0e38516c86e..fdeafc4a209 100644 --- a/packages/user-mgnt/src/features/updateUser/handler.ts +++ b/packages/user-mgnt/src/features/updateUser/handler.ts @@ -18,7 +18,7 @@ import { getCatchmentAreaIdsByPrimaryOfficeId, postFhir } from '@user-mgnt/features/createUser/service' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { IUser, IUserModel } from '@user-mgnt/model/user' import { getUserId } from '@user-mgnt/utils/userUtils' import { QA_ENV } from '@user-mgnt/constants' diff --git a/packages/user-mgnt/src/features/userAudit/handler.ts b/packages/user-mgnt/src/features/userAudit/handler.ts index a41f25c0efa..359dfc32163 100644 --- a/packages/user-mgnt/src/features/userAudit/handler.ts +++ b/packages/user-mgnt/src/features/userAudit/handler.ts @@ -8,7 +8,7 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { AUDIT_ACTION, AUDIT_REASON, diff --git a/packages/user-mgnt/src/features/userSearchRecord/handler.ts b/packages/user-mgnt/src/features/userSearchRecord/handler.ts index 250d285b948..aef505b9977 100644 --- a/packages/user-mgnt/src/features/userSearchRecord/handler.ts +++ b/packages/user-mgnt/src/features/userSearchRecord/handler.ts @@ -8,7 +8,7 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { IUserModel, Event } from '@user-mgnt/model/user' import { unauthorized } from '@hapi/boom' import * as Hapi from '@hapi/hapi' diff --git a/packages/user-mgnt/src/features/usernameSMSReminderInvite/handler.ts b/packages/user-mgnt/src/features/usernameSMSReminderInvite/handler.ts index d9c44f403bf..7658f25019a 100644 --- a/packages/user-mgnt/src/features/usernameSMSReminderInvite/handler.ts +++ b/packages/user-mgnt/src/features/usernameSMSReminderInvite/handler.ts @@ -14,7 +14,7 @@ import User, { IUserModel } from '@user-mgnt/model/user' import { unauthorized } from '@hapi/boom' import { sendUserName } from './service' import { postUserActionToMetrics } from '@user-mgnt/features/changePhone/handler' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { getUserId } from '@user-mgnt/utils/userUtils' interface IResendUsernameSMSPayload { diff --git a/packages/user-mgnt/src/features/verifySecurityAnswer/handler.ts b/packages/user-mgnt/src/features/verifySecurityAnswer/handler.ts index 02968cd03d9..4e572b422b4 100644 --- a/packages/user-mgnt/src/features/verifySecurityAnswer/handler.ts +++ b/packages/user-mgnt/src/features/verifySecurityAnswer/handler.ts @@ -13,7 +13,7 @@ import * as Joi from 'joi' import { unauthorized, conflict } from '@hapi/boom' import User, { IUserModel } from '@user-mgnt/model/user' import { generateHash } from '@user-mgnt/utils/hash' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { getRandomQuestionKey } from '@user-mgnt/features/verifyUser/handler' import { isNonEmptyArray } from '@user-mgnt/utils/non-empty-array' diff --git a/packages/user-mgnt/src/logger.ts b/packages/user-mgnt/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/user-mgnt/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/user-mgnt/src/server.ts b/packages/user-mgnt/src/server.ts index 7936b15fd44..ddd862ab7b7 100644 --- a/packages/user-mgnt/src/server.ts +++ b/packages/user-mgnt/src/server.ts @@ -20,7 +20,7 @@ import getPlugins from '@user-mgnt/config/plugins' import * as database from '@user-mgnt/database' import { readFileSync } from 'fs' import { getRoutes } from '@user-mgnt/config/routes' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import { badRequest, Boom } from '@hapi/boom' const publicCert = readFileSync(CERT_PUBLIC_KEY_PATH) diff --git a/packages/webhooks/src/config/plugins.ts b/packages/webhooks/src/config/plugins.ts index a9e46cca461..1eed22f0da1 100644 --- a/packages/webhooks/src/config/plugins.ts +++ b/packages/webhooks/src/config/plugins.ts @@ -8,24 +8,28 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { logger } from '@opencrvs/commons' +import { SENTRY_DSN } from '@webhooks/constants' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@webhooks/constants' -import { logger } from '@webhooks/logger' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/webhooks/src/database.ts b/packages/webhooks/src/database.ts index abac86b821a..74af9a94c04 100644 --- a/packages/webhooks/src/database.ts +++ b/packages/webhooks/src/database.ts @@ -10,7 +10,7 @@ */ import * as mongoose from 'mongoose' import { MONGO_URL, REDIS_HOST } from '@webhooks/constants' -import { logger } from '@webhooks/logger' +import { logger } from '@opencrvs/commons' import Redis, * as IORedis from 'ioredis' const db = mongoose.connection diff --git a/packages/webhooks/src/features/event/handler.ts b/packages/webhooks/src/features/event/handler.ts index 28965aba19f..ca4728e190c 100644 --- a/packages/webhooks/src/features/event/handler.ts +++ b/packages/webhooks/src/features/event/handler.ts @@ -17,7 +17,7 @@ import { transformDeathBundle } from '@webhooks/features/event/service' import { EventType, ISystem } from '@webhooks/features/manage/service' -import { logger } from '@webhooks/logger' +import { logger } from '@opencrvs/commons' import Webhook, { IWebhookModel, TRIGGERS } from '@webhooks/model/webhook' import { getQueue } from '@webhooks/queue' import { Queue } from 'bullmq' diff --git a/packages/webhooks/src/features/manage/handler.ts b/packages/webhooks/src/features/manage/handler.ts index 51ad15c2cf9..7965b309b6c 100644 --- a/packages/webhooks/src/features/manage/handler.ts +++ b/packages/webhooks/src/features/manage/handler.ts @@ -19,7 +19,7 @@ import { } from '@webhooks/features/manage/service' import { internal } from '@hapi/boom' import Webhook, { TRIGGERS } from '@webhooks/model/webhook' -import { logger } from '@webhooks/logger' +import { logger } from '@opencrvs/commons' import * as uuid from 'uuid/v4' import fetch from 'node-fetch' import { resolve } from 'url' diff --git a/packages/webhooks/src/logger.ts b/packages/webhooks/src/logger.ts deleted file mode 100644 index bc3f171a97d..00000000000 --- a/packages/webhooks/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/webhooks/src/processor.ts b/packages/webhooks/src/processor.ts index 3e71cb330a4..b8cbed6fa19 100644 --- a/packages/webhooks/src/processor.ts +++ b/packages/webhooks/src/processor.ts @@ -10,7 +10,7 @@ */ import fetch from 'node-fetch' -import { logger } from '@webhooks/logger' +import { logger } from '@opencrvs/commons' import { Worker } from 'bullmq' import * as IORedis from 'ioredis' diff --git a/packages/webhooks/src/queue.ts b/packages/webhooks/src/queue.ts index 7fe9f89145f..fc528ca1c44 100644 --- a/packages/webhooks/src/queue.ts +++ b/packages/webhooks/src/queue.ts @@ -12,7 +12,7 @@ import { REDIS_HOST, QUEUE_NAME } from '@webhooks/constants' import { Queue, QueueEvents, Worker, Job } from 'bullmq' import { EventEmitter } from 'events' -import { logger } from '@webhooks/logger' +import { logger } from '@opencrvs/commons' import { getRedis } from '@webhooks/database' import { initWorker } from '@webhooks/processor' diff --git a/packages/workflow/src/config/plugins.ts b/packages/workflow/src/config/plugins.ts index 8b42a971dc2..b84086c20d5 100644 --- a/packages/workflow/src/config/plugins.ts +++ b/packages/workflow/src/config/plugins.ts @@ -8,24 +8,28 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as Pino from 'hapi-pino' +import { ServerRegisterPluginObject } from '@hapi/hapi' +import { SENTRY_DSN } from '@workflow/constants' +import { logger } from '@opencrvs/commons' import * as JWT from 'hapi-auth-jwt2' +import * as Pino from 'hapi-pino' import * as Sentry from 'hapi-sentry' -import { SENTRY_DSN } from '@workflow/constants' -import { logger } from '@workflow/logger' + +type IHapiPlugin = ServerRegisterPluginObject export default function getPlugins() { - const plugins: any[] = [ - JWT, - { + const plugins: IHapiPlugin[] = [{ plugin: JWT, options: {} }] + + if (process.env.NODE_ENV === 'production') { + plugins.push({ plugin: Pino, options: { - prettyPrint: true, + prettyPrint: false, logPayload: false, instance: logger } - } - ] + }) + } if (SENTRY_DSN) { plugins.push({ diff --git a/packages/workflow/src/features/registration/fhir/fhir-bundle-modifier.ts b/packages/workflow/src/features/registration/fhir/fhir-bundle-modifier.ts index 9474db895ce..b6a84f0b3c5 100644 --- a/packages/workflow/src/features/registration/fhir/fhir-bundle-modifier.ts +++ b/packages/workflow/src/features/registration/fhir/fhir-bundle-modifier.ts @@ -42,7 +42,7 @@ import { getPractitionerPrimaryLocation, getPractitionerRef } from '@workflow/features/user/utils' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' import { ITokenPayload } from '@workflow/utils/auth-utils' import fetch from 'node-fetch' diff --git a/packages/workflow/src/features/registration/fhir/fhir-utils.ts b/packages/workflow/src/features/registration/fhir/fhir-utils.ts index 7a45ef23a9c..c806175e173 100644 --- a/packages/workflow/src/features/registration/fhir/fhir-utils.ts +++ b/packages/workflow/src/features/registration/fhir/fhir-utils.ts @@ -41,7 +41,7 @@ import { getPatientBySection } from '@workflow/features/registration/utils' import { getTaskEventType } from '@workflow/features/task/fhir/utils' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' import { ITokenPayload, USER_SCOPE } from '@workflow/utils/auth-utils' import fetch, { RequestInit } from 'node-fetch' diff --git a/packages/workflow/src/features/registration/sms-notification-utils.ts b/packages/workflow/src/features/registration/sms-notification-utils.ts index c4149160bfa..68c8a9c43b1 100644 --- a/packages/workflow/src/features/registration/sms-notification-utils.ts +++ b/packages/workflow/src/features/registration/sms-notification-utils.ts @@ -10,7 +10,7 @@ */ import { APPLICATION_CONFIG_URL } from '@workflow/constants' import fetch from 'node-fetch' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' export enum InformantNotificationName { birthInProgressSMS = 'birthInProgressSMS', diff --git a/packages/workflow/src/features/registration/utils.ts b/packages/workflow/src/features/registration/utils.ts index 44467bedc1e..06aeee71607 100644 --- a/packages/workflow/src/features/registration/utils.ts +++ b/packages/workflow/src/features/registration/utils.ts @@ -22,7 +22,7 @@ import { COUNTRY_CONFIG_URL, MOSIP_TOKEN_SEEDER_URL } from '@workflow/constants' import { EVENT_TYPE } from '@workflow/features/registration/fhir/constants' import { concatenateName } from '@workflow/features/registration/fhir/fhir-utils' import { getTaskEventType } from '@workflow/features/task/fhir/utils' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' import fetch from 'node-fetch' import * as ShortUIDGen from 'short-uid' diff --git a/packages/workflow/src/logger.ts b/packages/workflow/src/logger.ts deleted file mode 100644 index dfdcc123e73..00000000000 --- a/packages/workflow/src/logger.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * OpenCRVS is also distributed under the terms of the Civil Registration - * & Healthcare Disclaimer located at http://opencrvs.org/license. - * - * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. - */ -import pino from 'pino' -export const logger = pino() - -const level = process.env.NODE_ENV === 'test' ? 'error' : process.env.LOG_LEVEL -if (level) { - logger.level = level -} diff --git a/packages/workflow/src/records/handler/create.ts b/packages/workflow/src/records/handler/create.ts index c70bc1a627d..202608d7ed9 100644 --- a/packages/workflow/src/records/handler/create.ts +++ b/packages/workflow/src/records/handler/create.ts @@ -69,7 +69,7 @@ import { toValidated, toWaitingForExternalValidationState } from '@workflow/records/state-transitions' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' const requestSchema = z.object({ event: z.custom(), diff --git a/packages/workflow/src/records/handler/download.ts b/packages/workflow/src/records/handler/download.ts index 9443e825680..5324a45fa1a 100644 --- a/packages/workflow/src/records/handler/download.ts +++ b/packages/workflow/src/records/handler/download.ts @@ -24,7 +24,7 @@ import { toDownloaded } from '@workflow/records/state-transitions' import { hasScope, inScope } from '@opencrvs/commons/authentication' import { sendBundleToHearth } from '@workflow/records/fhir' import { indexBundleToRoute } from '@workflow/records/search' -import { logger } from '@workflow/logger' +import { logger } from '@opencrvs/commons' import { auditEvent } from '@workflow/records/audit' function getDownloadedOrAssignedExtension( From 122712bf6edbf2ce14ee1955b63672bce686c00b Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Mon, 20 May 2024 18:24:24 +0200 Subject: [PATCH 02/36] fix warnings from Mongoose and BullMQ --- packages/config/src/config/database.ts | 4 ++++ packages/metrics/src/config/database.ts | 4 ++++ packages/notification/src/database.ts | 4 ++++ packages/user-mgnt/src/database.ts | 4 ++++ packages/webhooks/src/database.ts | 9 ++++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/config/src/config/database.ts b/packages/config/src/config/database.ts index e8c6aed0a13..f356240fda7 100644 --- a/packages/config/src/config/database.ts +++ b/packages/config/src/config/database.ts @@ -14,6 +14,10 @@ import { logger } from '@opencrvs/commons' const db = mongoose.connection +// This prepares code for Mongoose >7 where strictQuery +// is set to false by default +mongoose.set('strictQuery', false) + db.on('disconnected', () => { logger.info('MongoDB disconnected') }) diff --git a/packages/metrics/src/config/database.ts b/packages/metrics/src/config/database.ts index e18edcb0cfd..101e4c1df33 100644 --- a/packages/metrics/src/config/database.ts +++ b/packages/metrics/src/config/database.ts @@ -14,6 +14,10 @@ import { logger } from '@opencrvs/commons' const db = mongoose.connection +// This prepares code for Mongoose >7 where strictQuery +// is set to false by default +mongoose.set('strictQuery', false) + db.on('disconnected', () => { logger.info('MongoDB disconnected') }) diff --git a/packages/notification/src/database.ts b/packages/notification/src/database.ts index b21294dd228..d238a47a102 100644 --- a/packages/notification/src/database.ts +++ b/packages/notification/src/database.ts @@ -15,6 +15,10 @@ import { logger } from '@opencrvs/commons' const db = mongoose.connection +// This prepares code for Mongoose >7 where strictQuery +// is set to false by default +mongoose.set('strictQuery', false) + db.on('disconnected', () => { logger.info('MongoDB disconnected') }) diff --git a/packages/user-mgnt/src/database.ts b/packages/user-mgnt/src/database.ts index f9ac212f076..cf4bedf42b1 100644 --- a/packages/user-mgnt/src/database.ts +++ b/packages/user-mgnt/src/database.ts @@ -15,6 +15,10 @@ import { logger } from '@opencrvs/commons' const db = mongoose.connection +// This prepares code for Mongoose >7 where strictQuery +// is set to false by default +mongoose.set('strictQuery', false) + db.on('disconnected', () => { logger.info('MongoDB disconnected') }) diff --git a/packages/webhooks/src/database.ts b/packages/webhooks/src/database.ts index 74af9a94c04..87ae1b8b3ae 100644 --- a/packages/webhooks/src/database.ts +++ b/packages/webhooks/src/database.ts @@ -14,6 +14,10 @@ import { logger } from '@opencrvs/commons' import Redis, * as IORedis from 'ioredis' const db = mongoose.connection +// This prepares code for Mongoose >7 where strictQuery +// is set to false by default +mongoose.set('strictQuery', false) + db.on('disconnected', () => { logger.info('MongoDB disconnected') }) @@ -33,7 +37,10 @@ export function getRedis(): IORedis.Redis { const connect = async (): Promise => { try { - redisConnection = new Redis(REDIS_HOST) + redisConnection = new Redis({ + host: REDIS_HOST, + maxRetriesPerRequest: null + }) redisConnection.on('error', (error) => { logger.error('Redis connection error', error) From cd5df512fd941b8749859a23fdd3a29efdfb471b Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Mon, 20 May 2024 18:24:58 +0200 Subject: [PATCH 03/36] improve logging about core not being able to fetch form config --- packages/config/src/handlers/forms/formsHandler.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/config/src/handlers/forms/formsHandler.ts b/packages/config/src/handlers/forms/formsHandler.ts index 3801ade0765..b5284cf45dc 100644 --- a/packages/config/src/handlers/forms/formsHandler.ts +++ b/packages/config/src/handlers/forms/formsHandler.ts @@ -39,8 +39,10 @@ export default async function getForm( }) if (response.status !== 200) { - logger.error('Country config did not return 200 on forms endpoint') - logger.error(response.statusText) + logger.error( + `Core failed to fetch form definition from ${COUNTRY_CONFIG_URL}/forms. Check country config logs for more details` + ) + return h.response().code(500) } @@ -77,5 +79,5 @@ export default async function getForm( return h.response().code(400) } } - return h.response(forms).code(201) + return h.response(forms).code(200) } From 5f77db09fe098729e7055157abf8cccf716309d8 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Tue, 21 May 2024 07:40:17 +0200 Subject: [PATCH 04/36] default to retrying the submission of records if something goes wrong in the backend --- packages/client/src/SubmissionController.ts | 3 ++- .../src/declarations/submissionMiddleware.ts | 23 ++++++++++--------- packages/client/src/utils/referenceApi.ts | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/client/src/SubmissionController.ts b/packages/client/src/SubmissionController.ts index d22361195c5..bd442effa87 100644 --- a/packages/client/src/SubmissionController.ts +++ b/packages/client/src/SubmissionController.ts @@ -33,7 +33,8 @@ export const ALLOWED_STATUS_FOR_RETRY = [ SUBMISSION_STATUS.READY_TO_CERTIFY, SUBMISSION_STATUS.READY_TO_ISSUE, SUBMISSION_STATUS.READY_TO_ARCHIVE, - SUBMISSION_STATUS.FAILED_NETWORK + SUBMISSION_STATUS.FAILED_NETWORK, + SUBMISSION_STATUS.FAILED ] as const export const INPROGRESS_STATUS = [ diff --git a/packages/client/src/declarations/submissionMiddleware.ts b/packages/client/src/declarations/submissionMiddleware.ts index cd3a5e22925..ff895be522b 100644 --- a/packages/client/src/declarations/submissionMiddleware.ts +++ b/packages/client/src/declarations/submissionMiddleware.ts @@ -326,15 +326,8 @@ export const submissionMiddleware: Middleware<{}, IStoreState> = 2000 ) } catch (error) { - if (!(error instanceof ApolloError)) { - updateDeclaration(dispatch, { - ...declaration, - submissionStatus: SUBMISSION_STATUS.FAILED - }) - captureException(error) - return - } if ( + error instanceof ApolloError && error.graphQLErrors.length > 0 && error.graphQLErrors[0].extensions.code === 'UNASSIGNED' ) { @@ -346,11 +339,19 @@ export const submissionMiddleware: Middleware<{}, IStoreState> = dispatch(deleteDeclaration(declaration.id, client)) return } + if (error instanceof ApolloError && error.networkError) { + updateDeclaration(dispatch, { + ...declaration, + submissionStatus: SUBMISSION_STATUS.FAILED_NETWORK + }) + captureException(error) + return + } + updateDeclaration(dispatch, { ...declaration, - submissionStatus: error.networkError - ? SUBMISSION_STATUS.FAILED_NETWORK - : SUBMISSION_STATUS.FAILED + submissionStatus: SUBMISSION_STATUS.FAILED }) + captureException(error) } } diff --git a/packages/client/src/utils/referenceApi.ts b/packages/client/src/utils/referenceApi.ts index 2b51c36e653..e426b4dc9bf 100644 --- a/packages/client/src/utils/referenceApi.ts +++ b/packages/client/src/utils/referenceApi.ts @@ -199,8 +199,8 @@ async function loadForms(): Promise { throw err } - if (res && res.status !== 201) { - throw Error(res.statusText) + if (res && !res.ok) { + throw new Error(res.statusText) } const response = await res.json() From 54acac217f391cc3e5ac104a4a9c6bee3a2a4bac Mon Sep 17 00:00:00 2001 From: naftis Date: Wed, 22 May 2024 16:18:11 +0300 Subject: [PATCH 05/36] fix: commons not installing pino-pretty --- packages/commons/package.json | 1 + packages/commons/src/logger.ts | 7 +- yarn.lock | 128 +++++++++++++++++++++++++-------- 3 files changed, 104 insertions(+), 32 deletions(-) diff --git a/packages/commons/package.json b/packages/commons/package.json index fba72f573ea..7ca0f40fbce 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -51,6 +51,7 @@ "eslint-plugin-import": "^2.17.3", "eslint-plugin-prettier": "^4.0.0", "jest-fetch-mock": "^2.1.2", + "pino-pretty": "^11.0.0", "ts-jest": "^26.4.4" }, "lint-staged": { diff --git a/packages/commons/src/logger.ts b/packages/commons/src/logger.ts index 84e264d2433..0b7dabd54be 100644 --- a/packages/commons/src/logger.ts +++ b/packages/commons/src/logger.ts @@ -13,7 +13,12 @@ export const logger = process.env.NODE_ENV === 'production' ? pino() : pino({ - prettyPrint: true + transport: { + target: 'pino-pretty', + options: { + colorize: true + } + } }) const level = process.env.NODE_ENV === 'test' ? 'silent' : process.env.LOG_LEVEL diff --git a/yarn.lock b/yarn.lock index 3e76397cc6c..dcb64f82018 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8584,6 +8584,13 @@ abbrev@1, abbrev@^1.0.0: resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== +abort-controller@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" + integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== + dependencies: + event-target-shim "^5.0.0" + abstract-logging@^2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz" @@ -10009,6 +10016,14 @@ buffer@^5.1.0, buffer@^5.5.0, buffer@^5.6.0: base64-js "^1.3.1" ieee754 "^1.1.13" +buffer@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + buildcheck@~0.0.6: version "0.0.6" resolved "https://registry.npmjs.org/buildcheck/-/buildcheck-0.0.6.tgz" @@ -10707,7 +10722,7 @@ colord@^2.9.3: resolved "https://registry.npmjs.org/colord/-/colord-2.9.3.tgz" integrity sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw== -colorette@^2.0.16, colorette@^2.0.20: +colorette@^2.0.16, colorette@^2.0.20, colorette@^2.0.7: version "2.0.20" resolved "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz" integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w== @@ -11577,6 +11592,11 @@ dateformat@^3.0.0: resolved "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz" integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q== +dateformat@^4.6.3: + version "4.6.3" + resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5" + integrity sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA== + debounce@^1.2.0: version "1.2.1" resolved "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz" @@ -13181,6 +13201,11 @@ event-emitter@^0.3.5, event-emitter@~0.3.5: d "1" es5-ext "~0.10.14" +event-target-shim@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" + integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== + eventemitter3@^3.0.0: version "3.1.2" resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz" @@ -13419,6 +13444,11 @@ extract-zip@^2.0.1: optionalDependencies: "@types/yauzl" "^2.9.1" +fast-copy@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/fast-copy/-/fast-copy-3.0.2.tgz#59c68f59ccbcac82050ba992e0d5c389097c9d35" + integrity sha512-dl0O9Vhju8IrcLndv2eU4ldt1ftXMqqfgN4H1cpmGV7P6jeB9FwpN9a2c8DPGE1Ys88rNUJVYDHq73CGAGOPfQ== + fast-csv@^4.3.6: version "4.3.6" resolved "https://registry.npmjs.org/fast-csv/-/fast-csv-4.3.6.tgz" @@ -13512,7 +13542,7 @@ fast-redact@^3.0.0: resolved "https://registry.npmjs.org/fast-redact/-/fast-redact-3.3.0.tgz" integrity sha512-6T5V1QK1u4oF+ATxs1lWUmlEk6P2T9HqJG3e2DnHOdVgZy2rFJBoEnrIedcTXlkAHU/zKC+7KETJ+KGGKwxgMQ== -fast-safe-stringify@^2.0.7, fast-safe-stringify@^2.0.8: +fast-safe-stringify@^2.0.7, fast-safe-stringify@^2.0.8, fast-safe-stringify@^2.1.1: version "2.1.1" resolved "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz" integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA== @@ -14747,6 +14777,11 @@ headers-utils@^1.2.0: resolved "https://registry.npmjs.org/headers-utils/-/headers-utils-1.2.5.tgz" integrity sha512-DAzV5P/pk3wTU/8TLZN+zFTDv4Xa1QDTU8pRvovPetcOMbmqq8CwsAvZBLPZHH6usxyy31zMp7I4aCYb6XIf6w== +help-me@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/help-me/-/help-me-5.0.0.tgz#b1ebe63b967b74060027c2ac61f9be12d354a6f6" + integrity sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg== + history@^4.7.2, history@^4.9.0: version "4.10.1" resolved "https://registry.npmjs.org/history/-/history-4.10.1.tgz" @@ -16441,6 +16476,11 @@ jose@^4.13.1: resolved "https://registry.yarnpkg.com/jose/-/jose-4.15.5.tgz#6475d0f467ecd3c630a1b5dadd2735a7288df706" integrity sha512-jc7BFxgKPKi94uOvEmzlSWFFe2+vASyXaKUpdQKatWAESU2MWjDfFf0fdfc83CDKcA5QecabZeNLyfhe3yKNkg== +joycon@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/joycon/-/joycon-3.1.1.tgz#bce8596d6ae808f8b68168f5fc69280996894f03" + integrity sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw== + js-levenshtein@^1.1.6: version "1.1.6" resolved "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz" @@ -19206,6 +19246,11 @@ on-exit-leak-free@^0.2.0: resolved "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-0.2.0.tgz" integrity sha512-dqaz3u44QbRXQooZLTUKU41ZrzYrcvLISVgbrzbyCMxpmSLJvZ3ZamIJIZ29P6OhZIkNIQKosdeM6t1LYbA9hg== +on-exit-leak-free@^2.1.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz#fed195c9ebddb7d9e4c3842f93f281ac8dadd3b8" + integrity sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA== + on-finished@2.4.1: version "2.4.1" resolved "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz" @@ -19827,6 +19872,14 @@ pify@^5.0.0: resolved "https://registry.npmjs.org/pify/-/pify-5.0.0.tgz" integrity sha512-eW/gHNMlxdSP6dmG6uJip6FXN0EQBwm2clYYd8Wul42Cwu/DK8HEftzsapcNdYe2MfLiIwZqsDk2RDEsTE79hA== +pino-abstract-transport@^1.0.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/pino-abstract-transport/-/pino-abstract-transport-1.2.0.tgz#97f9f2631931e242da531b5c66d3079c12c9d1b5" + integrity sha512-Guhh8EZfPCfH+PMXAb6rKOjGQEoy0xlAIn+irODG5kgfYV+BQ0rGYYWTIel3P5mmyXqkYkPmdIkywsn6QKUR1Q== + dependencies: + readable-stream "^4.0.0" + split2 "^4.0.0" + pino-abstract-transport@v0.5.0: version "0.5.0" resolved "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-0.5.0.tgz" @@ -19835,6 +19888,26 @@ pino-abstract-transport@v0.5.0: duplexify "^4.1.2" split2 "^4.0.0" +pino-pretty@^11.0.0: + version "11.0.0" + resolved "https://registry.yarnpkg.com/pino-pretty/-/pino-pretty-11.0.0.tgz#9b883f7b933f58fa94caa44225aab302409461ef" + integrity sha512-YFJZqw59mHIY72wBnBs7XhLGG6qpJMa4pEQTRgEPEbjIYbng2LXEZZF1DoyDg9CfejEy8uZCyzpcBXXG0oOCwQ== + dependencies: + colorette "^2.0.7" + dateformat "^4.6.3" + fast-copy "^3.0.0" + fast-safe-stringify "^2.1.1" + help-me "^5.0.0" + joycon "^3.1.1" + minimist "^1.2.6" + on-exit-leak-free "^2.1.0" + pino-abstract-transport "^1.0.0" + pump "^3.0.0" + readable-stream "^4.0.0" + secure-json-parse "^2.4.0" + sonic-boom "^3.0.0" + strip-json-comments "^3.1.1" + pino-std-serializers@^3.1.0: version "3.2.0" resolved "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-3.2.0.tgz" @@ -20909,6 +20982,17 @@ readable-stream@^2.0.0, readable-stream@^2.0.2, readable-stream@^2.0.5, readable string_decoder "~1.1.1" util-deprecate "~1.0.1" +readable-stream@^4.0.0: + version "4.5.2" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.5.2.tgz#9e7fc4c45099baeed934bff6eb97ba6cf2729e09" + integrity sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g== + dependencies: + abort-controller "^3.0.0" + buffer "^6.0.3" + events "^3.3.0" + process "^0.11.10" + string_decoder "^1.3.0" + readable-stream@~1.0.31: version "1.0.34" resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz" @@ -22140,6 +22224,13 @@ sonic-boom@^2.2.1: dependencies: atomic-sleep "^1.0.0" +sonic-boom@^3.0.0: + version "3.8.1" + resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-3.8.1.tgz#d5ba8c4e26d6176c9a1d14d549d9ff579a163422" + integrity sha512-y4Z8LCDBuum+PBP3lSV7RHrXscqksve/bi0as7mhwVnBW+/wUqKT/2Kb7um8yqcFy0duYbbPxzt89Zy2nOCaxg== + dependencies: + atomic-sleep "^1.0.0" + sort-keys@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/sort-keys/-/sort-keys-2.0.0.tgz" @@ -22502,16 +22593,7 @@ string-similarity@^4.0.1: resolved "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz" integrity sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ== -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -22626,7 +22708,7 @@ string.prototype.trimstart@^1.0.7: define-properties "^1.2.0" es-abstract "^1.22.1" -string_decoder@^1.1.1: +string_decoder@^1.1.1, string_decoder@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz" integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== @@ -22654,7 +22736,7 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -22675,13 +22757,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz" @@ -24882,7 +24957,7 @@ workbox-window@7.1.0, workbox-window@^7.1.0: "@types/trusted-types" "^2.0.2" workbox-core "7.1.0" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -24909,15 +24984,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.0.1, wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz" From 4722514f5accfd75b3bdfb8e1789f41fc424965a Mon Sep 17 00:00:00 2001 From: naftis Date: Wed, 22 May 2024 16:24:37 +0300 Subject: [PATCH 06/36] ignore pid and hostname --- packages/commons/src/logger.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/commons/src/logger.ts b/packages/commons/src/logger.ts index 0b7dabd54be..a04b1567533 100644 --- a/packages/commons/src/logger.ts +++ b/packages/commons/src/logger.ts @@ -16,7 +16,8 @@ export const logger = transport: { target: 'pino-pretty', options: { - colorize: true + colorize: true, + ignore: 'pid,hostname' } } }) From f71db1886e1f3a574b151598d5b7fc4790ee8b4f Mon Sep 17 00:00:00 2001 From: naftis Date: Wed, 22 May 2024 16:26:59 +0300 Subject: [PATCH 07/36] fix: imports from logger --- .../src/features/retrievalSteps/sendUserName/handler.test.ts | 2 +- packages/config/src/config/database.test.ts | 2 +- packages/gateway/src/features/user/utils/index.test.ts | 2 +- packages/metrics/src/config/database.test.ts | 2 +- packages/notification/src/database.test.ts | 2 +- packages/notification/src/features/sms/service.test.ts | 2 +- packages/search/src/elasticsearch/dbhelper.test.ts | 2 +- packages/user-mgnt/src/database.test.ts | 2 +- packages/user-mgnt/src/features/activateUser/handler.test.ts | 2 +- packages/user-mgnt/src/features/createUser/service.test.ts | 2 +- packages/user-mgnt/src/features/userAudit/handler.test.ts | 2 +- .../user-mgnt/src/features/userSearchRecord/handler.test.ts | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/auth/src/features/retrievalSteps/sendUserName/handler.test.ts b/packages/auth/src/features/retrievalSteps/sendUserName/handler.test.ts index 1af0225e33b..ca0c667cd36 100644 --- a/packages/auth/src/features/retrievalSteps/sendUserName/handler.test.ts +++ b/packages/auth/src/features/retrievalSteps/sendUserName/handler.test.ts @@ -14,7 +14,7 @@ import { storeRetrievalStepInformation, RetrievalSteps } from '@auth/features/retrievalSteps/verifyUser/service' -import { logger } from '@auth/logger' +import { logger } from '@opencrvs/commons' const fetch = fetchAny as fetchAny.FetchMock diff --git a/packages/config/src/config/database.test.ts b/packages/config/src/config/database.test.ts index 9d786aa848b..be9f09dd02c 100644 --- a/packages/config/src/config/database.test.ts +++ b/packages/config/src/config/database.test.ts @@ -10,7 +10,7 @@ */ import * as mongoose from 'mongoose' import { start, stop } from '@config/config/database' -import { logger } from '@config/config/logger' +import { logger } from '@opencrvs/commons' jest.mock('mongoose', () => ({ connection: { diff --git a/packages/gateway/src/features/user/utils/index.test.ts b/packages/gateway/src/features/user/utils/index.test.ts index 7213503c10c..34cca636403 100644 --- a/packages/gateway/src/features/user/utils/index.test.ts +++ b/packages/gateway/src/features/user/utils/index.test.ts @@ -8,7 +8,7 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { logger } from '@gateway/logger' +import { logger } from '@opencrvs/commons' import { getUserMobile } from '@gateway/features/user/utils/' import * as fetchAny from 'jest-fetch-mock' const fetch = fetchAny as any diff --git a/packages/metrics/src/config/database.test.ts b/packages/metrics/src/config/database.test.ts index d6f89776e1d..577f684c269 100644 --- a/packages/metrics/src/config/database.test.ts +++ b/packages/metrics/src/config/database.test.ts @@ -10,7 +10,7 @@ */ import * as mongoose from 'mongoose' import { start, stop } from '@metrics/config/database' -import { logger } from '@metrics/logger' +import { logger } from '@opencrvs/commons' jest.mock('mongoose', () => ({ connection: { diff --git a/packages/notification/src/database.test.ts b/packages/notification/src/database.test.ts index b92795d1271..f17fc67f02b 100644 --- a/packages/notification/src/database.test.ts +++ b/packages/notification/src/database.test.ts @@ -18,7 +18,7 @@ jest.mock('mongoose', () => ({ import * as mongoose from 'mongoose' import { start, stop } from '@notification/database' -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' const wait = (time: number) => new Promise((resolve) => setTimeout(resolve, time)) diff --git a/packages/notification/src/features/sms/service.test.ts b/packages/notification/src/features/sms/service.test.ts index 6d5b95eaeba..f34eb2f8ee4 100644 --- a/packages/notification/src/features/sms/service.test.ts +++ b/packages/notification/src/features/sms/service.test.ts @@ -8,7 +8,7 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { logger } from '@notification/logger' +import { logger } from '@opencrvs/commons' import { notifyCountryConfig } from '@notification/features/sms/service' import * as fetchAny from 'jest-fetch-mock' diff --git a/packages/search/src/elasticsearch/dbhelper.test.ts b/packages/search/src/elasticsearch/dbhelper.test.ts index 948abd282a9..00471361ec2 100644 --- a/packages/search/src/elasticsearch/dbhelper.test.ts +++ b/packages/search/src/elasticsearch/dbhelper.test.ts @@ -14,7 +14,7 @@ import { searchByCompositionId } from '@search/elasticsearch/dbhelper' import { mockCompositionBody } from '@search/test/utils' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { IBirthCompositionBody } from '@search/elasticsearch/utils' import { searchForBirthDuplicates } from '@search/features/registration/deduplicate/service' import { client } from '@search/elasticsearch/client' diff --git a/packages/user-mgnt/src/database.test.ts b/packages/user-mgnt/src/database.test.ts index 9c90fc4eadb..f8eb6aa0840 100644 --- a/packages/user-mgnt/src/database.test.ts +++ b/packages/user-mgnt/src/database.test.ts @@ -18,7 +18,7 @@ jest.mock('mongoose', () => ({ import * as mongoose from 'mongoose' import { start, stop } from '@user-mgnt/database' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' const wait = (time: number) => new Promise((resolve) => setTimeout(resolve, time)) diff --git a/packages/user-mgnt/src/features/activateUser/handler.test.ts b/packages/user-mgnt/src/features/activateUser/handler.test.ts index 78d72237128..594bd14e5fa 100644 --- a/packages/user-mgnt/src/features/activateUser/handler.test.ts +++ b/packages/user-mgnt/src/features/activateUser/handler.test.ts @@ -13,7 +13,7 @@ import * as jwt from 'jsonwebtoken' import { readFileSync } from 'fs' import * as fetchMock from 'jest-fetch-mock' import User, { IUser } from '@user-mgnt/model/user' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import * as mockingoose from 'mockingoose' import { cloneDeep } from 'lodash' import { Types } from 'mongoose' diff --git a/packages/user-mgnt/src/features/createUser/service.test.ts b/packages/user-mgnt/src/features/createUser/service.test.ts index 83cec5213e3..c789ff750e2 100644 --- a/packages/user-mgnt/src/features/createUser/service.test.ts +++ b/packages/user-mgnt/src/features/createUser/service.test.ts @@ -14,7 +14,7 @@ import * as mockingoose from 'mockingoose' import * as fetchMock from 'jest-fetch-mock' import * as jwt from 'jsonwebtoken' import { readFileSync } from 'fs' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' const fetch = fetchMock as fetchMock.FetchMock const mockUser = { diff --git a/packages/user-mgnt/src/features/userAudit/handler.test.ts b/packages/user-mgnt/src/features/userAudit/handler.test.ts index 4e011e29387..ddea64e750e 100644 --- a/packages/user-mgnt/src/features/userAudit/handler.test.ts +++ b/packages/user-mgnt/src/features/userAudit/handler.test.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { createServer } from '@user-mgnt/server' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { AUDIT_ACTION, AUDIT_REASON, IUser } from '@user-mgnt/model/user' import { readFileSync } from 'fs' import * as fetchMock from 'jest-fetch-mock' diff --git a/packages/user-mgnt/src/features/userSearchRecord/handler.test.ts b/packages/user-mgnt/src/features/userSearchRecord/handler.test.ts index 058188ff6a0..7cc66c80593 100644 --- a/packages/user-mgnt/src/features/userSearchRecord/handler.test.ts +++ b/packages/user-mgnt/src/features/userSearchRecord/handler.test.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { createServer } from '@user-mgnt/server' -import { logger } from '@user-mgnt/logger' +import { logger } from '@opencrvs/commons' import User, { IUser } from '@user-mgnt/model/user' import { readFileSync } from 'fs' import * as fetchMock from 'jest-fetch-mock' From de83daa1bd6cf1365a7abda1a254a5e805658006 Mon Sep 17 00:00:00 2001 From: naftis Date: Wed, 22 May 2024 16:30:51 +0300 Subject: [PATCH 08/36] feat: quiet nodemons own info messages --- packages/auth/package.json | 2 +- packages/config/package.json | 2 +- packages/documents/package.json | 2 +- packages/gateway/package.json | 6 +++--- packages/metrics/package.json | 2 +- packages/notification/package.json | 2 +- packages/search/package.json | 2 +- packages/user-mgnt/package.json | 2 +- packages/webhooks/package.json | 2 +- packages/workflow/package.json | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index 8ad5eb6a1a1..62a65c9d2b9 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/config/package.json b/packages/config/package.json index fea6ba4645e..462c9c3f139 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -4,7 +4,7 @@ "description": "OpenCRVS public configuration microservice", "license": "MPL-2.0", "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/documents/package.json b/packages/documents/package.json index eb9bd8dee74..368ef6d5c02 100644 --- a/packages/documents/package.json +++ b/packages/documents/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "yarn test:compilation && jest --coverage --silent --noStackTrace", "test:watch": "jest --watch", diff --git a/packages/gateway/package.json b/packages/gateway/package.json index b3770e7d3c2..610ef3bced9 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "scripts": { "postinstall": "if [ \"$NODE_ENV\" != \"production\" ]; then npx crlf --set=LF ../../node_modules/graphql-schema-typescript/**/* || npx crlf --set=LF ./node_modules/graphql-schema-typescript/**/* || true; fi", - "start": "yarn gen:schema && yarn gen:types && concurrently \"NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts\" \"yarn gen:types:watch\" \"yarn gen:schema:watch\"", + "start": "yarn gen:schema && yarn gen:types && concurrently \"NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts\" \"yarn gen:types:watch\" \"yarn gen:schema:watch\"", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest && yarn test:compilation", "test:watch": "jest --watch", @@ -14,8 +14,8 @@ "build:clean": "rm -rf build", "gen:schema": "node -e \"const importSchema = require('graphql-import').importSchema; console.log(importSchema('src/graphql/index.graphql'))\" > src/graphql/schema.graphql && yarn prettier --write src/graphql/schema.graphql", "gen:types": "graphql-schema-typescript generate-ts src/graphql/schema.graphql --output src/graphql/schema.d.ts --importStatements 'import {Context} from \"./context\"' --contextType Context && yarn prettier --write src/graphql/schema.d.ts", - "gen:schema:watch": "nodemon --on-change-only -e graphql -i src/graphql/schema.graphql -x 'yarn gen:schema'", - "gen:types:watch": "nodemon --on-change-only -w src/graphql/schema.graphql -x 'yarn gen:types'", + "gen:schema:watch": "nodemon --quiet --on-change-only -e graphql -i src/graphql/schema.graphql -x 'yarn gen:schema'", + "gen:types:watch": "nodemon --quiet --on-change-only -w src/graphql/schema.graphql -x 'yarn gen:types'", "open:cov": "yarn test && opener coverage/index.html", "lint": "eslint -c .eslintrc.js --fix ./src", "precommit": "lint-staged" diff --git a/packages/metrics/package.json b/packages/metrics/package.json index e044edc9192..c44ae56beb7 100644 --- a/packages/metrics/package.json +++ b/packages/metrics/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "yarn test:compilation && jest --coverage --silent --noStackTrace", "test:watch": "jest --watch", diff --git a/packages/notification/package.json b/packages/notification/package.json index 18df8d6164f..2779ad97761 100644 --- a/packages/notification/package.json +++ b/packages/notification/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/search/package.json b/packages/search/package.json index 37fce8acada..cbb720955a9 100644 --- a/packages/search/package.json +++ b/packages/search/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/user-mgnt/package.json b/packages/user-mgnt/package.json index 1c69e5f6247..296324b7abd 100644 --- a/packages/user-mgnt/package.json +++ b/packages/user-mgnt/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/webhooks/package.json b/packages/webhooks/package.json index 0270c3ee426..f3eb6976e5a 100644 --- a/packages/webhooks/package.json +++ b/packages/webhooks/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace --forceExit && yarn test:compilation", "test:watch": "jest --watch", diff --git a/packages/workflow/package.json b/packages/workflow/package.json index e091a88f3b8..1b19954a0e8 100644 --- a/packages/workflow/package.json +++ b/packages/workflow/package.json @@ -5,7 +5,7 @@ "license": "MPL-2.0", "private": true, "scripts": { - "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --exec ts-node -r tsconfig-paths/register src/index.ts", + "start": "cross-env NODE_ENV=development NODE_OPTIONS=--dns-result-order=ipv4first nodemon --quiet --exec ts-node -r tsconfig-paths/register src/index.ts", "start:prod": "TS_NODE_BASEURL=./build/dist/src node -r tsconfig-paths/register build/dist/src/index.js", "test": "jest --coverage --silent --noStackTrace && yarn test:compilation", "test:watch": "jest --watch", From bf1f122fa3e2b7804290175a1c908486c45d1084 Mon Sep 17 00:00:00 2001 From: euanmillar Date: Wed, 29 May 2024 11:12:36 +0100 Subject: [PATCH 09/36] Remove nonce --- packages/client/src/setupTests.ts | 3 +- .../OIDPVerificationCallback.test.tsx | 3 +- .../OIDPVerificationCallback.tsx | 5 +-- .../views/OIDPVerificationCallback/utils.ts | 35 ------------------- 4 files changed, 3 insertions(+), 43 deletions(-) diff --git a/packages/client/src/setupTests.ts b/packages/client/src/setupTests.ts index 8998f0fb76c..55c0027e4d3 100644 --- a/packages/client/src/setupTests.ts +++ b/packages/client/src/setupTests.ts @@ -291,6 +291,5 @@ vi.mock('@client/views/OIDPVerificationCallback/utils', async () => ({ '@client/views/OIDPVerificationCallback/utils' )) as any), useExtractCallBackState: vi.fn(), - useQueryParams: vi.fn(), - useCheckNonce: vi.fn() + useQueryParams: vi.fn() })) diff --git a/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.test.tsx b/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.test.tsx index d3c9cd1129e..953a5628f77 100644 --- a/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.test.tsx +++ b/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.test.tsx @@ -20,7 +20,7 @@ import { waitFor, waitForElement } from '@client/tests/wait-for-element' import { vi, Mock } from 'vitest' import { OIDPVerificationCallback } from './OIDPVerificationCallback' import { URLSearchParams } from 'url' -import { useQueryParams, useExtractCallBackState, useCheckNonce } from './utils' +import { useQueryParams, useExtractCallBackState } from './utils' import { GET_OIDP_USER_INFO } from './queries' import { createDeclaration, storeDeclaration } from '@client/declarations' import { Event } from '@client/utils/gateway' @@ -131,7 +131,6 @@ beforeEach(async () => { ;(useQueryParams as Mock).mockImplementation( () => new URLSearchParams({ code: '1234' }) ) - ;(useCheckNonce as Mock).mockImplementation(() => true) await store.dispatch(checkAuth()) await store.dispatch(storeDeclaration(draft)) diff --git a/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.tsx b/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.tsx index af55cb2c9bf..a0686eedbda 100644 --- a/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.tsx +++ b/packages/client/src/views/OIDPVerificationCallback/OIDPVerificationCallback.tsx @@ -19,7 +19,6 @@ import { useIntl } from 'react-intl' import { useDispatch, useSelector } from 'react-redux' import { addNidUserInfoToDeclaration, - useCheckNonce, useExtractCallBackState, useQueryParams } from '@client/views/OIDPVerificationCallback/utils' @@ -38,7 +37,6 @@ import { OIDP_VERIFICATION_CALLBACK } from '@client/navigation/routes' // OIDP Verification Callback // -- // Checks the ?state= query parameter for a JSON string like: { pathname: "/path/somewhere" } -// Checks that the &nonce= parameter matches the one in localStorage, removes it if yes, throws if not // Redirects to the pathname in state const Page = styled.div` @@ -65,7 +63,6 @@ const UserActionsContainer = styled.div` export const OIDPVerificationCallback = () => { const params = useQueryParams() const { pathname, declarationId, section } = useExtractCallBackState() - const isNonceOk = useCheckNonce() const code = params.get('code') const offlineData = useSelector(getOfflineData) const clientId = offlineData.systems.find((s) => s.type === 'NATIONAL_ID') @@ -91,7 +88,7 @@ export const OIDPVerificationCallback = () => { } }) - if (!pathname || !isNonceOk) { + if (!pathname) { // Do not redirect and let the hooks throw return null } diff --git a/packages/client/src/views/OIDPVerificationCallback/utils.ts b/packages/client/src/views/OIDPVerificationCallback/utils.ts index c748ad1c3fb..0f9b13eb526 100644 --- a/packages/client/src/views/OIDPVerificationCallback/utils.ts +++ b/packages/client/src/views/OIDPVerificationCallback/utils.ts @@ -22,8 +22,6 @@ import { useDispatch, useSelector } from 'react-redux' import { useLocation, useRouteMatch } from 'react-router' import { v4 as uuid } from 'uuid' -const OIDP_VERIFICATION_NONCE_LOCALSTORAGE_KEY = 'oidp-verification-nonce' - interface OIDPUserAddress { formatted?: string | null street_address?: string | null @@ -183,10 +181,6 @@ export function addNidUserInfoToDeclaration( declarationDataSection[`${section}NidVerification`] = oidpUserInfo.sub } -function generateNonce() { - return uuid() -} - function splitName(name: string | undefined | null = '') { if (!name) { return { firstName: '', lastName: '' } @@ -231,8 +225,6 @@ export function redirectToNidIntegration( currentSection: string, currentPathname: string ) { - const nonce = generateNonce() - window.localStorage.setItem(OIDP_VERIFICATION_NONCE_LOCALSTORAGE_KEY, nonce) const nidSystemSetting = offlineCountryConfig.systems.find( (s) => s.type === 'NATIONAL_ID' )?.settings @@ -242,7 +234,6 @@ export function redirectToNidIntegration( } const url = new URL(`${nidSystemSetting?.openIdProviderBaseUrl}authorize`) - url.searchParams.append('nonce', nonce) url.searchParams.append( 'client_id', nidSystemSetting?.openIdProviderClientId || '' @@ -264,32 +255,6 @@ export function redirectToNidIntegration( window.location.href = url.toString() } -export const useCheckNonce = () => { - const params = useQueryParams() - const [nonceOk, setNonceOk] = useState(false) - - useEffect(() => { - if (!params.get('nonce')) { - throw new Error('No nonce provided from OIDP callback.') - } - - const nonceMatches = - window.localStorage.getItem(OIDP_VERIFICATION_NONCE_LOCALSTORAGE_KEY) === - params.get('nonce') - - if (nonceMatches) { - window.localStorage.removeItem(OIDP_VERIFICATION_NONCE_LOCALSTORAGE_KEY) - setNonceOk(true) - } else { - throw new Error( - 'Nonce did not match the one sent to the integration before callback' - ) - } - }, [params]) - - return nonceOk -} - export const useExtractCallBackState = () => { const params = useQueryParams() From 0aad66a13f6b581bc703ebb4e8c1cef49d6d4073 Mon Sep 17 00:00:00 2001 From: naftis Date: Wed, 17 Apr 2024 10:57:47 +0300 Subject: [PATCH 10/36] chore: allow specifying different url's for oauth token & oidc userinfo endpoints --- packages/gateway/src/constants.ts | 3 ++- packages/gateway/src/features/OIDPUserInfo/utils.ts | 13 +++++-------- packages/gateway/test/setupJest.ts | 5 ++++- packages/user-mgnt/src/constants.ts | 3 --- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/gateway/src/constants.ts b/packages/gateway/src/constants.ts index 2b39de2352f..ffda6697ff0 100644 --- a/packages/gateway/src/constants.ts +++ b/packages/gateway/src/constants.ts @@ -77,7 +77,8 @@ export const DEFAULT_TIMEOUT = 600000 export const MINIO_BUCKET = process.env.MINIO_BUCKET || 'ocrvs' export const OIDP_BASE_URL = process.env.NATIONAL_ID_OIDP_BASE_URL -export const OIDP_REST_URL = process.env.NATIONAL_ID_OIDP_REST_URL +export const OIDP_TOKEN_URL = process.env.NATIONAL_ID_OIDP_TOKEN_URL +export const OIDP_USERINFO_URL = process.env.NATIONAL_ID_OIDP_USERINFO_URL /** Base64 encoded RS256 JSON Web Key */ export const OIDP_CLIENT_PRIVATE_KEY = process.env.NATIONAL_ID_OIDP_CLIENT_PRIVATE_KEY diff --git a/packages/gateway/src/features/OIDPUserInfo/utils.ts b/packages/gateway/src/features/OIDPUserInfo/utils.ts index c552df60b5e..33cfccff04c 100644 --- a/packages/gateway/src/features/OIDPUserInfo/utils.ts +++ b/packages/gateway/src/features/OIDPUserInfo/utils.ts @@ -12,9 +12,10 @@ import * as jwt from 'jsonwebtoken' import * as jose from 'jose' import fetch from '@gateway/fetch' import { - OIDP_REST_URL, OIDP_CLIENT_PRIVATE_KEY, - OIDP_JWT_AUD_CLAIM + OIDP_JWT_AUD_CLAIM, + OIDP_TOKEN_URL, + OIDP_USERINFO_URL } from '@gateway/constants' import { logger } from '@gateway/logger' @@ -25,10 +26,6 @@ import { fetchFromHearth } from '@gateway/features/fhir/service' const TOKEN_GRANT_TYPE = 'authorization_code' const CLIENT_ASSERTION_TYPE = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' -const OIDP_TOKEN_ENDPOINT = - OIDP_REST_URL && new URL('oauth/token', OIDP_REST_URL).toString() -const OIDP_USERINFO_ENDPOINT = - OIDP_REST_URL && new URL('oidc/userinfo', OIDP_REST_URL).toString() const JWT_ALG = 'RS256' const JWT_EXPIRATION_TIME = '1h' @@ -94,7 +91,7 @@ export const fetchToken = async ({ client_assertion: await generateSignedJwt(clientId) }) - const request = await fetch(OIDP_TOKEN_ENDPOINT!, { + const request = await fetch(OIDP_TOKEN_URL!, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' @@ -107,7 +104,7 @@ export const fetchToken = async ({ } export const fetchUserInfo = async (accessToken: string) => { - const request = await fetch(OIDP_USERINFO_ENDPOINT!, { + const request = await fetch(OIDP_USERINFO_URL!, { headers: { Authorization: 'Bearer ' + accessToken } diff --git a/packages/gateway/test/setupJest.ts b/packages/gateway/test/setupJest.ts index ba602b45377..12052b031da 100644 --- a/packages/gateway/test/setupJest.ts +++ b/packages/gateway/test/setupJest.ts @@ -20,6 +20,9 @@ process.env.CERT_PUBLIC_KEY_PATH = join(__dirname, './cert.key.pub') process.env.NATIONAL_ID_OIDP_CLIENT_PRIVATE_KEY = 'ewogICAgInAiOiAiMVRMMlRPOWxNZnZOWThzeWVReFFrd3F1RThfdll5bV85ZS1yUkxRaV9reWJvLUMwUXJYVklQRFNfN2laV3I4WFB0MGlMWnJkemtjSzU0dGtKWGRkYWk3bEhxM3VyNndLU09uUHVPMURNS0stLXlNR3lCd0RfazdTbUdLUDlsTml3Q0pDT1Q2dDdjWEM1SnBEaVBNc05HQWNEUDZyRGFQQ2tlMzZUcjV5LW5NIiwKICAgICJrdHkiOiAiUlNBIiwKICAgICJxIjogIng4U1FwSHc2UlFnWmxHUC1EdWpiS1pRcUZxczAxU0ZsczFQa1lya25yM01rV1FrUFVGVDlubW5CbTlHWlVwbUV0TU9WZDc4SWVfdHV1UGZFVFo1SWYwTmt0bTNJdS1Pcm9jQzJBU3IzQnF0dUZyUnhUWTRJbnVBVnhHd0VuV0Frd1ZWR1dJQklEVkhSeHhGblAwZUo0YWNmVGVDcWs4QTE1cFRhOUo2MmY4ayIsCiAgICAiZCI6ICJubms3Q2RtT2hucVdyMTU1cW5hc25PY2pPamYyVEJLNlVpYUJOcWw1S1FBMmlJSnJGa0F1ZXFYcmwzM1J0eVgtZFFtOU1NTnhNLUYwMUpac3REME50eW1ZdXlzOVFMbGhKbld2RHlGLXlmMHJHOFJPVHROQkNuZjgxNUE2STQ1UzhqVUlXMGI1dl9lQlAxY1lKdWRLSW5QNlY0NVRZUEFlSjhKQ2hPeFJ2RlJHX2loOFVRaTdDZFZWNXFvVUVpX1lOWXNleTc1cTZpTFRiRVFFOExsNE9lMnRFNDMxTnltMTBaa185R2FNVEp0SU1YMm1iMW01blFfMTZmRC1ZNDZvWDlucW9zUUtUZ19uYmRoUFU3QWQwNW5MSjZFRER0X0JIbDNfc0d1blhrN3BhMjFTN1hfRjBQT0JrdG42dlNUV0FEZjQtM2pXaFNHa21yX3pyR3hLc1EiLAogICAgImUiOiAiQVFBQiIsCiAgICAicWkiOiAiRlpCaE55Uk5nMVhJVW44d1VFVGRCSEh4Qmx0Wk9tbDJhUzNXYlVZb3VuQlN1NDhoVk9BOGpWdFJFaWFBc25xUkxtaGNIN3V0aWVCTHBKazZsZ2pyM3RINnh3WklOSDRCb1NBYnRyUW5DMXd1ZE1fa1FCX1hpRk4tSFhPX0oyU2thV05nb19JSFFING1udXZnRUkxUEdpZGdwZzJ2NnJ6V3R3ZW5rbXhHblJnIiwKICAgICJkcCI6ICJNYkhMVDJ1TnZ2VGVqeUJTQjMwald1TG1hSl9UUU4zLWJLa00xdHJXUFVoR0R4RFZjNmRHb29MXzY3TnZxNE5YTzhQM3I0R2xxZXROVTJOZVdJMVdMT1g1YWdsSTFaSFlZOTU4R0xMVk1vVDgxelQyNDdZRUNFYl9ONTNoeUp6dks3SFFsZDlTVTFZQmM1LXhsajU0VTAwRHZOT3ZzMkkwZkNkb2JPcGZpcGsiLAogICAgImFsZyI6ICJSUzI1NiIsCiAgICAiZHEiOiAiYlJkRjJkMVJRTk5zaktHU1l2ZjhmeGNfYU1PMEJWUElvd2FFS1BsdDE1MHNVMGJrU3YwdXh1eF80eVN4OHU2TkR0M2o2TkcwdzJnS0RnNlg3NzhwWGY0aXFKRUpWcm04eDRkaW5QNm1pY2ppUkpuamFmUFBkMXR0NTZjSldodmYxb2hIOHhxU3ZsdFpFTG5MUlQ0LTZMQ0lJdEkydEpyNWxHTGpzMFJjNnlrIiwKICAgICJuIjogInBsNVE4QWVsT1ozWERyc093ems5T0ExNzR1WEF3ZnpxOW1NVXB2cVEwMC1sMFlKWGljZUlfWU13ZVJnS0tGTnpEMklEajhGNnJqaDh1THEwdjhiTE5oLWQzUEFwRHBTMTVOc3ZhN2U4VFZNR1paLVZJVDVKVGZqMzZsNWR2Q1oxa21MRUJ2ZjJhbzFHOVowMXU0NDNMZDRueEgzNHpkLTlUZU5VRXp4ejAweXUtOFBrRkJ5OGNySGVCR2JmcUlTLV9nbVJ6ZEIwclFQM29GT3hiNWJfa01WYUR6Wm5YSFVVemFIdDRNOEcxcHF2QjJOZzQzUDQ0d2NJME1YMVNHVkRQbGMtZVBfNjFjNW5qTzhoVnhnbUZzOUt0WVR5a0t3OXhsYUh6U1dCbG9ObVZFeG1Yd1ItckVzSTdJczdxOUpWTjdEVzNaNmYzRnk3NVpnN21rZXhTdyIKfQ==' process.env.NATIONAL_ID_OIDP_BASE_URL = 'http://localhost:27501/v1/oid/' -process.env.NATIONAL_ID_OIDP_REST_URL = 'http://localhost:27502/v1/oid/' +process.env.NATIONAL_ID_OIDP_TOKEN_URL = + 'http://localhost:27502/v1/esignet/oauth/v2/token' +process.env.NATIONAL_ID_OIDP_USERINFO_URL = + 'http://localhost:27502/v1/esignet/oidc/v2/userinfo' process.env.NATIONAL_ID_OIDP_JWT_AUD_CLAIM = 'http://localhost:27501/v1/idp/oauth/token' diff --git a/packages/user-mgnt/src/constants.ts b/packages/user-mgnt/src/constants.ts index d87807fb9ad..c8af7df6cc2 100644 --- a/packages/user-mgnt/src/constants.ts +++ b/packages/user-mgnt/src/constants.ts @@ -29,9 +29,6 @@ export const METRICS_URL = process.env.METRICS_URL || 'http://localhost:1050' export const NATIONAL_ID_OIDP_BASE_URL = process.env.NATIONAL_ID_OIDP_BASE_URL || null // e.g. https://api.esignet.io/v1/idp -export const NATIONAL_ID_OIDP_REST_URL = - process.env.NATIONAL_ID_OIDP_REST_URL || null - export const NATIONAL_ID_OIDP_CLIENT_ID = process.env.NATIONAL_ID_OIDP_CLIENT_ID || null From 5c2a411adcb1f378cc64c5485fe9769b86223550 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 30 May 2024 13:49:21 +0600 Subject: [PATCH 11/36] fix: update assignment check for unassign declaration --- .../components/interface/DownloadButton.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/interface/DownloadButton.tsx b/packages/client/src/components/interface/DownloadButton.tsx index 304395ac037..44c36ba2188 100644 --- a/packages/client/src/components/interface/DownloadButton.tsx +++ b/packages/client/src/components/interface/DownloadButton.tsx @@ -220,8 +220,7 @@ function DownloadButtonComponent(props: DownloadButtonProps & HOCProps) { downloadDeclaration, userRole, userId, - unassignDeclaration, - deleteDeclaration + unassignDeclaration } = props const { assignment, compositionId } = downloadConfigs const [assignModal, setAssignModal] = useState( @@ -238,18 +237,9 @@ function DownloadButtonComponent(props: DownloadButtonProps & HOCProps) { }, [downloadConfigs, client, downloadDeclaration]) const hideModal = useCallback(() => setAssignModal(null), []) const unassign = useCallback(async () => { - if (assignment) { - unassignDeclaration(compositionId, client) - } else { - deleteDeclaration(compositionId, client) - } - }, [ - compositionId, - client, - unassignDeclaration, - assignment, - deleteDeclaration - ]) + unassignDeclaration(compositionId, client) + }, [compositionId, client, unassignDeclaration]) + const isFailed = useMemo( () => status === DOWNLOAD_STATUS.FAILED || From f7b2d21d93ba513c9ffbf09170961cccfc6a2c9f Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 30 May 2024 20:38:44 +0600 Subject: [PATCH 12/36] chore(workflow): check for assignment before unassign action --- packages/commons/src/authentication.ts | 2 +- packages/workflow/src/features/user/utils.ts | 53 +++++++++++++++++++ .../workflow/src/records/handler/unassign.ts | 47 ++++++++++++++++ packages/workflow/src/records/user.ts | 35 ++++++++++-- 4 files changed, 133 insertions(+), 4 deletions(-) diff --git a/packages/commons/src/authentication.ts b/packages/commons/src/authentication.ts index 0739673508d..8b0f09afa8f 100644 --- a/packages/commons/src/authentication.ts +++ b/packages/commons/src/authentication.ts @@ -85,7 +85,7 @@ export interface ITokenPayload { sub: string exp: string algorithm: string - scope: string[] + scope: Scope[] } export function hasScope(authHeader: IAuthHeader, scope: Scope) { diff --git a/packages/workflow/src/features/user/utils.ts b/packages/workflow/src/features/user/utils.ts index 50df28a44b5..8342672fa7c 100644 --- a/packages/workflow/src/features/user/utils.ts +++ b/packages/workflow/src/features/user/utils.ts @@ -19,6 +19,11 @@ import { } from '@opencrvs/commons/types' import { UUID } from '@opencrvs/commons' +type UserSearchCriteria = 'userId' | 'practitionerId' | 'mobile' | 'email' +export type SearchCriteria = { + [K in UserSearchCriteria]?: string +} + export async function getUser( userId: string, authHeader: { Authorization: string } @@ -67,6 +72,54 @@ export async function getSystem( return body } +export async function getUserByCriteria( + authHeader: { Authorization: string }, + criteria: SearchCriteria +) { + const res = await fetch(`${USER_MANAGEMENT_URL}getUser`, { + method: 'POST', + body: JSON.stringify(criteria), + headers: { + 'Content-Type': 'application/json', + ...authHeader + } + }) + + if (!res.ok) { + throw new Error( + `Unable to retrieve user in workflow. Error: ${res.status} status received` + ) + } + + const body = await res.json() + + return body +} + +export async function getSystemByCriteria( + authHeader: { Authorization: string }, + criteria: SearchCriteria +) { + const res = await fetch(`${USER_MANAGEMENT_URL}getSystem`, { + method: 'POST', + body: JSON.stringify(criteria), + headers: { + 'Content-Type': 'application/json', + ...authHeader + } + }) + + if (!res.ok) { + throw new Error( + `Unable to retrieve system in workflow. Error: ${res.status} status received` + ) + } + + const body = await res.json() + + return body +} + export async function getPractitionerPrimaryLocation( practitionerId: string ): Promise { diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index 51db4e2a7e8..c37f1f6628d 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -17,6 +17,21 @@ import { toUnassigned } from '@workflow/records/state-transitions' import { indexBundleToRoute } from '@workflow/records/search' import { sendBundleToHearth } from '@workflow/records/fhir' import { auditEvent } from '@workflow/records/audit' +import { + findExtension, + isTaskOrTaskHistory, + Resource, + resourceIdentifierToUUID +} from '@opencrvs/commons/types' +import { getTokenPayload } from '@opencrvs/commons/authentication' +import { getUserOrSystemByCriteria } from '@workflow/records/user' + +function sortDescending( + a: Resource & { lastModified: string }, + b: Resource & { lastModified: string } +) { + return new Date(b.lastModified).valueOf() - new Date(a.lastModified).valueOf() +} export async function unassignRecordHandler( request: Hapi.Request, @@ -30,6 +45,7 @@ export async function unassignRecordHandler( ) const token = getToken(request) + const tokenPayload = getTokenPayload(token) const record = await getRecordById( // Task history is fetched rather than the task only `${payload.id}?includeHistoryResources`, @@ -45,6 +61,37 @@ export async function unassignRecordHandler( ] ) + const allTasks = record.entry + .map(({ resource }) => resource) + .filter(isTaskOrTaskHistory) + .sort(sortDescending) + + const task = allTasks.find((entry) => + entry.extension.find( + (ext) => ext.url === 'http://opencrvs.org/specs/extension/regAssigned' + ) + ) + + if (!task) throw new Error('No task found with assignment') + + const regLastUser = findExtension( + 'http://opencrvs.org/specs/extension/regLastUser', + task.extension + ) + + if (!regLastUser) throw new Error('No user is found assigned to this record') + + const practitionerId = resourceIdentifierToUUID( + regLastUser.valueReference.reference + ) + + const lastUser = await getUserOrSystemByCriteria({ practitionerId }, token) + + if (!tokenPayload.scope.includes('register')) { + if (lastUser.scope?.includes('register')) + throw new Error('The declaration can not assigned by this type of user') + } + const { unassignedRecord, unassignedRecordWithTaskOnly } = await toUnassigned( record, token diff --git a/packages/workflow/src/records/user.ts b/packages/workflow/src/records/user.ts index b7fa603a8d5..5298da7546c 100644 --- a/packages/workflow/src/records/user.ts +++ b/packages/workflow/src/records/user.ts @@ -9,8 +9,14 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { getTokenPayload } from '@opencrvs/commons/authentication' -import { getSystem, getUser } from '@workflow/features/user/utils' +import { getTokenPayload, Scope } from '@opencrvs/commons/authentication' +import { + getSystem, + getSystemByCriteria, + getUser, + getUserByCriteria, + SearchCriteria +} from '@workflow/features/user/utils' type Label = { lang: string @@ -47,7 +53,7 @@ interface IUserModelData { } interface ISystemModelData { - scope?: string[] + scope?: Scope[] name: string createdBy: string client_id: string @@ -83,3 +89,26 @@ export async function getUserOrSystem( Authorization: `Bearer ${token}` }) } + +export async function getUserOrSystemByCriteria( + criteria: SearchCriteria, + token: string +) { + const user = await getUserByCriteria( + { + Authorization: `Bearer ${token}` + }, + criteria + ) + + if (user) return user as IUserModelData + + const system = await getSystemByCriteria( + { + Authorization: `Bearer ${token}` + }, + criteria + ) + + return system as ISystemModelData +} From 38e07079dc72715dc390ae2d937978407936280e Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Fri, 31 May 2024 16:52:32 +0600 Subject: [PATCH 13/36] fix: amend unassign handler and add comments --- packages/workflow/src/records/handler/unassign.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index c37f1f6628d..b590ba0a553 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -87,9 +87,12 @@ export async function unassignRecordHandler( const lastUser = await getUserOrSystemByCriteria({ practitionerId }, token) - if (!tokenPayload.scope.includes('register')) { - if (lastUser.scope?.includes('register')) - throw new Error('The declaration can not assigned by this type of user') + // Non-registrars can't unassign declarations from registrars + if ( + !tokenPayload.scope.includes('register') && + lastUser.scope?.includes('register') + ) { + throw new Error('The declaration cannot be unassigned by this type of user') } const { unassignedRecord, unassignedRecordWithTaskOnly } = await toUnassigned( From f6eb4f1201f2c82c218468bb248c455b055ea4de Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Fri, 31 May 2024 18:52:43 +0600 Subject: [PATCH 14/36] chore(workflow): amend assignment check --- .../workflow/src/records/handler/unassign.ts | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index b590ba0a553..951a8f97e95 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -18,13 +18,16 @@ import { indexBundleToRoute } from '@workflow/records/search' import { sendBundleToHearth } from '@workflow/records/fhir' import { auditEvent } from '@workflow/records/audit' import { + Extension, findExtension, isTaskOrTaskHistory, Resource, - resourceIdentifierToUUID + resourceIdentifierToUUID, + Task } from '@opencrvs/commons/types' import { getTokenPayload } from '@opencrvs/commons/authentication' import { getUserOrSystemByCriteria } from '@workflow/records/user' +import { getTaskBusinessStatus } from '@workflow/features/task/fhir/utils' function sortDescending( a: Resource & { lastModified: string }, @@ -33,6 +36,21 @@ function sortDescending( return new Date(b.lastModified).valueOf() - new Date(a.lastModified).valueOf() } +function findTaskIndexByExtension( + tasks: Task[], + extensionUrl: Extension['url'] +) { + return tasks.findIndex((entry) => + entry.extension.some((ext) => ext.url === extensionUrl) + ) +} + +const getLastUnassignedTaskIndex = (index1: number, index2: number) => { + if (index1 === -1) return index2 + if (index2 === -1) return index1 + return Math.min(index1, index2) +} + export async function unassignRecordHandler( request: Hapi.Request, h: Hapi.ResponseToolkit @@ -66,13 +84,38 @@ export async function unassignRecordHandler( .filter(isTaskOrTaskHistory) .sort(sortDescending) - const task = allTasks.find((entry) => - entry.extension.find( - (ext) => ext.url === 'http://opencrvs.org/specs/extension/regAssigned' - ) + // declaration is unassigned when status changes + const latestChangedStatusIndex = allTasks.findIndex( + (entry, index, array) => + index < array.length - 1 && + getTaskBusinessStatus(entry) !== getTaskBusinessStatus(array[index + 1]) + ) + + const unassignIndex = findTaskIndexByExtension( + allTasks, + 'http://opencrvs.org/specs/extension/regUnassigned' + ) + + const lastUnassignedTaskIndex = getLastUnassignedTaskIndex( + latestChangedStatusIndex, + unassignIndex + ) + + const lastAssignedTaskIndex = findTaskIndexByExtension( + allTasks, + 'http://opencrvs.org/specs/extension/regAssigned' + ) + + if (lastAssignedTaskIndex === -1) throw new Error('Not assigned yet') + + // check for unassigned task and status change + if ( + lastUnassignedTaskIndex !== -1 && + lastAssignedTaskIndex > lastUnassignedTaskIndex ) + throw new Error('Declaration is found unassigned already') - if (!task) throw new Error('No task found with assignment') + const task = allTasks[lastAssignedTaskIndex] const regLastUser = findExtension( 'http://opencrvs.org/specs/extension/regLastUser', From 2ccae8cc2695f121bb44d5843bc0572bb99a306c Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Mon, 3 Jun 2024 13:58:16 +0600 Subject: [PATCH 15/36] chore(gateway): filter consecutive assignment in history --- packages/commons/src/fhir/task.ts | 25 +++++++++++++++++++ .../features/registration/type-resolvers.ts | 6 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/commons/src/fhir/task.ts b/packages/commons/src/fhir/task.ts index 4daf8b022e0..a4a0ddbee89 100644 --- a/packages/commons/src/fhir/task.ts +++ b/packages/commons/src/fhir/task.ts @@ -475,3 +475,28 @@ export function notCorrectedHistory( } return true } + +export function filterConsecutiveAssignment( + task: Task, + index: number, + allTasks: Task[] +) { + const currentAction = getActionFromTask(task) + + if (index === 0) { + return true + } + + const previousTask = allTasks[index - 1] + const previousAction = getActionFromTask(previousTask) + + // Only keep the task if it is not a consecutive ASSIGNED action + if ( + currentAction === TaskAction.ASSIGNED && + previousAction === TaskAction.ASSIGNED + ) { + return false + } + + return true +} diff --git a/packages/gateway/src/features/registration/type-resolvers.ts b/packages/gateway/src/features/registration/type-resolvers.ts index 1ffd2d84b86..8b9c5753bb8 100644 --- a/packages/gateway/src/features/registration/type-resolvers.ts +++ b/packages/gateway/src/features/registration/type-resolvers.ts @@ -83,7 +83,8 @@ import { isTaskOrTaskHistory, resourceIdentifierToUUID, Address, - notCorrectedHistory + notCorrectedHistory, + filterConsecutiveAssignment } from '@opencrvs/commons/types' import { GQLQuestionnaireQuestion, GQLResolver } from '@gateway/graphql/schema' @@ -1824,6 +1825,7 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) + .filter(filterConsecutiveAssignment) } }, BirthRegistration: { @@ -1984,6 +1986,7 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) + .filter(filterConsecutiveAssignment) } }, MarriageRegistration: { @@ -2122,6 +2125,7 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) + .filter(filterConsecutiveAssignment) } } } From f815d7b98178a099e3313c7a54089ea30c591b9f Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Mon, 3 Jun 2024 14:03:05 +0600 Subject: [PATCH 16/36] fix: remove delete declaration test --- .../src/components/interface/DownloadButton.test.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/client/src/components/interface/DownloadButton.test.tsx b/packages/client/src/components/interface/DownloadButton.test.tsx index c53cd9bc8aa..597ade8466b 100644 --- a/packages/client/src/components/interface/DownloadButton.test.tsx +++ b/packages/client/src/components/interface/DownloadButton.test.tsx @@ -45,14 +45,12 @@ describe('download button tests', () => { let store: AppStore let history: History let testComponent: ReactWrapper<{}, {}> - let deleteSpy: SpyInstance let unassignSpy: SpyInstance let client: ApolloClient<{}> describe('for download status downloaded', () => { describe('when assignment object is undefined in props', () => { beforeEach(async () => { - deleteSpy = vi.spyOn(declarationReducer, 'deleteDeclaration') const testStore = await createTestStore() store = testStore.store history = testStore.history @@ -80,11 +78,6 @@ describe('download button tests', () => { const modal = getAssignmentModal(testComponent) expect(modal.text()).toContain('Unassign record?') }) - - it('clicking on unassign button triggers deleteDeclaration action', () => { - clickOnModalAction(testComponent, '#unassign') - expect(deleteSpy).toBeCalledWith('123', client) - }) }) describe('when assignment object is defined in props', () => { beforeEach(async () => { From 4e0a9a4e0de520f8a7f6ab94cab5026265ed6fc1 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Wed, 5 Jun 2024 13:25:34 +0600 Subject: [PATCH 17/36] docs: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447e9d209a7..a3e9e5c21a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ - Supporting document fields can now be made required - If there is only one option in the document uploader select, then it stays hidden and only the upload button is showed with the only option being selected by default +## Bug fixes + +- Fix unassign action not appearing in audit history [#7035](https://github.com/opencrvs/opencrvs-core/pull/7072) + ## 1.5.0 (TBD) ## Breaking changes From d4585a91e860946ebedaabb8523f710c4483d4c8 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Wed, 5 Jun 2024 16:38:54 +0600 Subject: [PATCH 18/36] chore: refactor task sorting function --- .../workflow/src/records/handler/unassign.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index 951a8f97e95..ea9ee300c1e 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -21,21 +21,14 @@ import { Extension, findExtension, isTaskOrTaskHistory, - Resource, resourceIdentifierToUUID, + sortTasksDescending, Task } from '@opencrvs/commons/types' import { getTokenPayload } from '@opencrvs/commons/authentication' import { getUserOrSystemByCriteria } from '@workflow/records/user' import { getTaskBusinessStatus } from '@workflow/features/task/fhir/utils' -function sortDescending( - a: Resource & { lastModified: string }, - b: Resource & { lastModified: string } -) { - return new Date(b.lastModified).valueOf() - new Date(a.lastModified).valueOf() -} - function findTaskIndexByExtension( tasks: Task[], extensionUrl: Extension['url'] @@ -79,10 +72,9 @@ export async function unassignRecordHandler( ] ) - const allTasks = record.entry - .map(({ resource }) => resource) - .filter(isTaskOrTaskHistory) - .sort(sortDescending) + const allTasks = sortTasksDescending( + record.entry.map(({ resource }) => resource).filter(isTaskOrTaskHistory) + ) // declaration is unassigned when status changes const latestChangedStatusIndex = allTasks.findIndex( From 809ac92a7b0805e284c7d779c86799836f757583 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Wed, 5 Jun 2024 20:04:05 +0600 Subject: [PATCH 19/36] docs: amend changelog(#7035) --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e9e5c21a9..9fe005c1368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,6 @@ - Supporting document fields can now be made required - If there is only one option in the document uploader select, then it stays hidden and only the upload button is showed with the only option being selected by default -## Bug fixes - -- Fix unassign action not appearing in audit history [#7035](https://github.com/opencrvs/opencrvs-core/pull/7072) - ## 1.5.0 (TBD) ## Breaking changes @@ -64,6 +60,7 @@ - Fix French translation missing for relationship to informant when trying to correct record, print and issue record [#6341] (https://github.com/opencrvs/opencrvs-core/issues/6341) - Fix print record page for an unsaved declaration [#6893](https://github.com/opencrvs/opencrvs-core/issues/6893) - Fix Reset pagination to default page (1) when location changes in UserList [#6481](https://github.com/opencrvs/opencrvs-core/issues/6481) +- Fix unassign action not appearing in audit history [#7035](https://github.com/opencrvs/opencrvs-core/pull/7072) - Fix client modal glitches on integrations page [#7002](https://github.com/opencrvs/opencrvs-core/issues/7002) - Fix "Print and issue to groom|bride" is added to a different variable [#7066](https://github.com/opencrvs/opencrvs-core/pull/7066) - Fix Removed duplicateTrackingId check in createDuplicateTask method [#7081](https://github.com/opencrvs/opencrvs-core/pull/7081) From c79a1f7a9677e38a9c4f5b7f924b0f54e056b426 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 6 Jun 2024 15:24:45 +0600 Subject: [PATCH 20/36] fix: amend task function types --- packages/workflow/src/features/task/fhir/utils.ts | 4 ++-- packages/workflow/src/records/handler/unassign.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/workflow/src/features/task/fhir/utils.ts b/packages/workflow/src/features/task/fhir/utils.ts index 9dd803fdc6f..5864256366b 100644 --- a/packages/workflow/src/features/task/fhir/utils.ts +++ b/packages/workflow/src/features/task/fhir/utils.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { Composition, Task } from '@opencrvs/commons/types' +import { Composition, Task, TaskHistory } from '@opencrvs/commons/types' import { RegStatus } from '@workflow/features/registration/fhir/constants' export function isRejectedTask(taskResource: Task) { @@ -21,7 +21,7 @@ export function isArchiveTask(taskResource: Task) { } export function getTaskBusinessStatus( - taskResource: Task + taskResource: Task | TaskHistory ): RegStatus | undefined { return taskResource.businessStatus?.coding?.[0]?.code as RegStatus | undefined } diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index 30bc46b9281..0a6cb9540f6 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -23,14 +23,15 @@ import { isTaskOrTaskHistory, resourceIdentifierToUUID, sortTasksDescending, - Task + Task, + TaskHistory } from '@opencrvs/commons/types' import { getTokenPayload } from '@opencrvs/commons/authentication' import { getUserOrSystemByCriteria } from '@workflow/records/user' import { getTaskBusinessStatus } from '@workflow/features/task/fhir/utils' -function findTaskIndexByExtension( - tasks: Task[], +function findTaskIndexByExtension( + tasks: T[], extensionUrl: Extension['url'] ) { return tasks.findIndex((entry) => From a3c4fab35794d32b2a13fc54515aab09a8f71120 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 6 Jun 2024 18:47:41 +0600 Subject: [PATCH 21/36] chore: amend assignment check --- .../workflow/src/records/handler/unassign.ts | 76 +------------------ 1 file changed, 4 insertions(+), 72 deletions(-) diff --git a/packages/workflow/src/records/handler/unassign.ts b/packages/workflow/src/records/handler/unassign.ts index 0a6cb9540f6..71cf06067ad 100644 --- a/packages/workflow/src/records/handler/unassign.ts +++ b/packages/workflow/src/records/handler/unassign.ts @@ -17,33 +17,9 @@ import { toUnassigned } from '@workflow/records/state-transitions' import { indexBundleToRoute } from '@workflow/records/search' import { sendBundleToHearth } from '@workflow/records/fhir' import { auditEvent } from '@workflow/records/audit' -import { - Extension, - findExtension, - isTaskOrTaskHistory, - resourceIdentifierToUUID, - sortTasksDescending, - Task, - TaskHistory -} from '@opencrvs/commons/types' import { getTokenPayload } from '@opencrvs/commons/authentication' import { getUserOrSystemByCriteria } from '@workflow/records/user' -import { getTaskBusinessStatus } from '@workflow/features/task/fhir/utils' - -function findTaskIndexByExtension( - tasks: T[], - extensionUrl: Extension['url'] -) { - return tasks.findIndex((entry) => - entry.extension.some((ext) => ext.url === extensionUrl) - ) -} - -const getLastUnassignedTaskIndex = (index1: number, index2: number) => { - if (index1 === -1) return index2 - if (index2 === -1) return index1 - return Math.min(index1, index2) -} +import { findAssignment } from '@opencrvs/commons/assignment' export async function unassignRecordHandler( request: Hapi.Request, @@ -74,54 +50,10 @@ export async function unassignRecordHandler( true ) - const allTasks = sortTasksDescending( - record.entry.map(({ resource }) => resource).filter(isTaskOrTaskHistory) - ) - - // declaration is unassigned when status changes - const latestChangedStatusIndex = allTasks.findIndex( - (entry, index, array) => - index < array.length - 1 && - getTaskBusinessStatus(entry) !== getTaskBusinessStatus(array[index + 1]) - ) - - const unassignIndex = findTaskIndexByExtension( - allTasks, - 'http://opencrvs.org/specs/extension/regUnassigned' - ) - - const lastUnassignedTaskIndex = getLastUnassignedTaskIndex( - latestChangedStatusIndex, - unassignIndex - ) - - const lastAssignedTaskIndex = findTaskIndexByExtension( - allTasks, - 'http://opencrvs.org/specs/extension/regAssigned' - ) - - if (lastAssignedTaskIndex === -1) throw new Error('Not assigned yet') - - // check for unassigned task and status change - if ( - lastUnassignedTaskIndex !== -1 && - lastAssignedTaskIndex > lastUnassignedTaskIndex - ) - throw new Error('Declaration is found unassigned already') - - const task = allTasks[lastAssignedTaskIndex] - - const regLastUser = findExtension( - 'http://opencrvs.org/specs/extension/regLastUser', - task.extension - ) - - if (!regLastUser) throw new Error('No user is found assigned to this record') - - const practitionerId = resourceIdentifierToUUID( - regLastUser.valueReference.reference - ) + const assignment = findAssignment(record) + if (!assignment) throw new Error('The declaration is not assigned') + const practitionerId = assignment.practitioner.id const lastUser = await getUserOrSystemByCriteria({ practitionerId }, token) // Non-registrars can't unassign declarations from registrars From 7bb0e1bf0b42238da0b15e22d4a79fb1e329f8a8 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 6 Jun 2024 19:04:13 +0600 Subject: [PATCH 22/36] fix: amend task filter func type --- packages/commons/src/fhir/task.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/commons/src/fhir/task.ts b/packages/commons/src/fhir/task.ts index 02eb8c17391..11df91d074a 100644 --- a/packages/commons/src/fhir/task.ts +++ b/packages/commons/src/fhir/task.ts @@ -502,9 +502,9 @@ export function notCorrectedHistory( } export function filterConsecutiveAssignment( - task: Task, + task: TaskHistory, index: number, - allTasks: Task[] + allTasks: TaskHistory[] ) { const currentAction = getActionFromTask(task) From b8fe547e29f23eec86615b8dc7e598c4fda4781b Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 6 Jun 2024 19:36:45 +0600 Subject: [PATCH 23/36] fix: update unassign test --- .../src/records/handler/unassign.test.ts | 7 ++++ .../workflow/test/mocks/unassignedTask.ts | 42 +++++++++++++++++++ packages/workflow/test/mocks/user.ts | 29 +++++++++++++ 3 files changed, 78 insertions(+) diff --git a/packages/workflow/src/records/handler/unassign.test.ts b/packages/workflow/src/records/handler/unassign.test.ts index c3620c4cffa..9a40b498415 100644 --- a/packages/workflow/src/records/handler/unassign.test.ts +++ b/packages/workflow/src/records/handler/unassign.test.ts @@ -16,6 +16,7 @@ import { rest } from 'msw' import { server as mswServer } from '@test/setupServer' import { bundleWithAssignedTask } from '@test/mocks/unassignedTask' import { getTaskFromSavedBundle, Task } from '@opencrvs/commons/types' +import { registrar } from '@test/mocks/user' function checkForUnassignExtenstion(task: Task) { return task.extension.find( @@ -63,6 +64,12 @@ describe('unassign record endpoint', () => { }) ) + mswServer.use( + rest.post('http://localhost:3030/getUser', (_, res, ctx) => { + return res(ctx.json(registrar)) + }) + ) + const res = await server.server.inject({ method: 'POST', url: '/unassign-record', diff --git a/packages/workflow/test/mocks/unassignedTask.ts b/packages/workflow/test/mocks/unassignedTask.ts index 024bc8defea..75c09c36103 100644 --- a/packages/workflow/test/mocks/unassignedTask.ts +++ b/packages/workflow/test/mocks/unassignedTask.ts @@ -9,10 +9,14 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ +import { READY_FOR_REVIEW_BIRTH_RECORD } from './records/readyForReview' + export const bundleWithAssignedTask = { resourceType: 'Bundle', type: 'document', entry: [ + // mock composition + READY_FOR_REVIEW_BIRTH_RECORD.entry[0], { resource: { resourceType: 'Task', @@ -80,6 +84,44 @@ export const bundleWithAssignedTask = { versionId: '757f0e0e-2df4-4f8f-b4a4-065047bb35c0' } } + }, + { + fullUrl: + '/fhir/Practitioner/f20ad76d-87c3-46ab-8fbc-0d104a5b3e69/_history/d98a5727-eb9b-41b8-9851-f9be7b8d0eec', + resource: { + resourceType: 'Practitioner', + identifier: [], + telecom: [ + { + system: 'phone', + value: '0933333333' + }, + { + system: 'email', + value: '' + } + ], + name: [ + { + use: 'en', + family: 'Mweene', + given: ['Kennedy'] + } + ], + meta: { + lastUpdated: '2024-06-06T10:45:05.773+00:00', + versionId: 'd98a5727-eb9b-41b8-9851-f9be7b8d0eec' + }, + _transforms: { + meta: { + lastUpdated: '2024-06-06T10:45:05.773Z' + } + }, + _request: { + method: 'POST' + }, + id: 'f20ad76d-87c3-46ab-8fbc-0d104a5b3e69' + } } ] } diff --git a/packages/workflow/test/mocks/user.ts b/packages/workflow/test/mocks/user.ts index f212b61819d..9713711fb7c 100644 --- a/packages/workflow/test/mocks/user.ts +++ b/packages/workflow/test/mocks/user.ts @@ -51,3 +51,32 @@ export const user = { searches: [], __v: 0 } + +export const registrar = { + _id: '66619331a6a4a835aa689dfd', + name: [ + { + use: 'en', + given: ['Kennedy'], + family: 'Mweene' + } + ], + username: 'k.mweene', + identifiers: [], + email: '', + emailForNotification: 'kalushabwalya1.7@gmail.com', + mobile: '0933333333', + passwordHash: '$2a$10$Ss1IOh7BmD6wje96VMppheEpHywYjfQgvAy6BRB.ISwM79TvjfnN6', + salt: '$2a$10$Ss1IOh7BmD6wje96VMpphe', + systemRole: 'LOCAL_REGISTRAR', + role: '66619330a6a4a835aa689ddb', + practitionerId: '648c914d-de38-4c24-bdc9-ce8ee8cacd4c', + primaryOfficeId: '435e5301-063d-4f22-958e-24176cfb4e54', + scope: ['register', 'performance', 'certify', 'demo'], + status: 'active', + securityQuestionAnswers: [], + creationDate: 1717670705858, + auditHistory: [], + searches: [], + __v: 0 +} From ac0eb20cf1059a4b168b934718c2b7ab63b18e1b Mon Sep 17 00:00:00 2001 From: euanmillar Date: Wed, 12 Jun 2024 15:25:44 +0100 Subject: [PATCH 24/36] Fix failing test --- .../gateway/src/features/OIDPUserInfo/root-resolvers.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/gateway/src/features/OIDPUserInfo/root-resolvers.test.ts b/packages/gateway/src/features/OIDPUserInfo/root-resolvers.test.ts index 940423f700f..56b1a3a6534 100644 --- a/packages/gateway/src/features/OIDPUserInfo/root-resolvers.test.ts +++ b/packages/gateway/src/features/OIDPUserInfo/root-resolvers.test.ts @@ -221,9 +221,8 @@ describe('get user info from OIDP national id integration', () => { redirectUri: 'http://localhost:3000/mosip-callback' } ) - - expect(fetch.mock.calls[0][0]).toMatch(/oauth\/token$/) - expect(fetch.mock.calls[1][0]).toMatch(/oidc\/userinfo$/) + expect(fetch.mock.calls[0][0]).toMatch(/oauth\/v2\/token$/) + expect(fetch.mock.calls[1][0]).toMatch(/oidc\/v2\/userinfo$/) expect(fetch.mock.calls[2][0]).toMatch( /Location\?name=Farajaland&type=ADMIN_STRUCTURE$/ ) From 7c24eae4a40acefa54e78a9660c9833a68b0fdfb Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 13 Jun 2024 14:35:11 +0600 Subject: [PATCH 25/36] chore: remove unused util functions --- packages/workflow/src/features/user/utils.ts | 90 -------------------- 1 file changed, 90 deletions(-) diff --git a/packages/workflow/src/features/user/utils.ts b/packages/workflow/src/features/user/utils.ts index 0049d599e87..60f59e538e5 100644 --- a/packages/workflow/src/features/user/utils.ts +++ b/packages/workflow/src/features/user/utils.ts @@ -16,7 +16,6 @@ import { Practitioner, PractitionerRole, resourceIdentifierToUUID, - SavedLocation, SavedPractitioner } from '@opencrvs/commons/types' import { UUID } from '@opencrvs/commons' @@ -122,65 +121,6 @@ export async function getSystemByCriteria( return body } -export async function getPractitionerPrimaryLocation( - practitionerId: string -): Promise { - return getPrimaryLocationFromLocationList( - await getPractitionerLocations(practitionerId) - ) -} - -export async function getPractitionerOffice( - practitionerId: string -): Promise { - return getOfficeLocationFromLocationList( - await getPractitionerLocations(practitionerId) - ) -} - -function getPrimaryLocationFromLocationList( - locations: fhir3.Location[] -): fhir3.Location { - const primaryOffice = getOfficeLocationFromLocationList(locations) - const primaryLocationId = - primaryOffice && - primaryOffice.partOf && - primaryOffice.partOf.reference && - primaryOffice.partOf.reference.split('/')[1] - - if (!primaryLocationId) { - throw new Error('No primary location found') - } - - const location = locations.find((loc) => loc.id === primaryLocationId) - if (!location) { - throw new Error( - `No primary location not found for office: ${primaryLocationId}` - ) - } - return location -} - -function getOfficeLocationFromLocationList( - locations: fhir3.Location[] -): fhir3.Location { - let office: fhir3.Location | undefined - locations.forEach((location: fhir3.Location) => { - if (location.type && location.type.coding) { - location.type.coding.forEach((code) => { - if (code.code === 'CRVS_OFFICE') { - office = location - } - }) - } - }) - - if (!office) { - throw new Error('No CRVS office found') - } - return office -} - /** Find the office location of a given practitioner */ export const getPractitionerOfficeId = async (practitionerId: string) => { const roleResponse = await getFromFhir( @@ -212,36 +152,6 @@ export async function getLoggedInPractitionerResource( return await getFromFhir(`/Practitioner/${userResponse.practitionerId}`) } -export async function getLocationOrOfficeById( - locationId: string -): Promise { - return await getFromFhir(`/Location/${locationId}`) -} - -export async function getPractitionerLocations( - practitionerId: string -): Promise<[fhir3.Location]> { - const roleResponse = await getFromFhir( - `/PractitionerRole?practitioner=${practitionerId}` - ) - const roleEntry = roleResponse.entry[0].resource - if (!roleEntry || !roleEntry.location) { - throw new Error('PractitionerRole has no locations associated') - } - const locList = [] - for (const location of roleEntry.location) { - const splitRef = location.reference.split('/') - const locationResponse: fhir3.Location = await getFromFhir( - `/Location/${splitRef[1]}` - ) - if (!locationResponse) { - throw new Error(`Location not found for ${location}`) - } - locList.push(locationResponse) - } - return locList as [fhir3.Location] -} - export function getPractitionerRef(practitioner: Practitioner) { if (!practitioner || !practitioner.id) { throw new Error('Invalid practitioner data found') From 02353b1db0f1db8e8907cc30ea3ab365de9df478 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 13 Jun 2024 14:41:43 +0600 Subject: [PATCH 26/36] fix: revert filtering consecutive assignments of history --- packages/commons/src/fhir/task.ts | 25 ------------------- .../features/registration/type-resolvers.ts | 4 --- 2 files changed, 29 deletions(-) diff --git a/packages/commons/src/fhir/task.ts b/packages/commons/src/fhir/task.ts index 11df91d074a..45bc2631d6d 100644 --- a/packages/commons/src/fhir/task.ts +++ b/packages/commons/src/fhir/task.ts @@ -500,28 +500,3 @@ export function notCorrectedHistory( } return true } - -export function filterConsecutiveAssignment( - task: TaskHistory, - index: number, - allTasks: TaskHistory[] -) { - const currentAction = getActionFromTask(task) - - if (index === 0) { - return true - } - - const previousTask = allTasks[index - 1] - const previousAction = getActionFromTask(previousTask) - - // Only keep the task if it is not a consecutive ASSIGNED action - if ( - currentAction === TaskAction.ASSIGNED && - previousAction === TaskAction.ASSIGNED - ) { - return false - } - - return true -} diff --git a/packages/gateway/src/features/registration/type-resolvers.ts b/packages/gateway/src/features/registration/type-resolvers.ts index e2f6f0d84ab..07a58a4f43f 100644 --- a/packages/gateway/src/features/registration/type-resolvers.ts +++ b/packages/gateway/src/features/registration/type-resolvers.ts @@ -87,7 +87,6 @@ import { findLastOfficeFromSavedBundle, findLastOfficeLocationFromSavedBundle, notCorrectedHistory, - filterConsecutiveAssignment, findResourceFromBundleById } from '@opencrvs/commons/types' @@ -1823,7 +1822,6 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) - .filter(filterConsecutiveAssignment) } }, BirthRegistration: { @@ -1984,7 +1982,6 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) - .filter(filterConsecutiveAssignment) } }, MarriageRegistration: { @@ -2123,7 +2120,6 @@ export const typeResolvers: GQLResolver = { .filter(isTaskOrTaskHistory) .filter(notCorrectedHistory) .sort(sortDescending) - .filter(filterConsecutiveAssignment) } } } From dcc412e29706f993bb13dc5f72dbd2710447923d Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 12:48:21 +0300 Subject: [PATCH 27/36] fix type error by adding a language item for the FAILED status --- packages/client/src/i18n/messages/views/notifications.ts | 5 +++++ packages/client/src/views/OfficeHome/outbox/Outbox.tsx | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/client/src/i18n/messages/views/notifications.ts b/packages/client/src/i18n/messages/views/notifications.ts index 29911d63288..0269a1cac2c 100644 --- a/packages/client/src/i18n/messages/views/notifications.ts +++ b/packages/client/src/i18n/messages/views/notifications.ts @@ -164,6 +164,11 @@ const messagesToDefine = { description: 'Label for declaration status waiting for connection', id: 'regHome.outbox.waitingToRetry' }, + failed: { + defaultMessage: 'Retrying', + description: 'Label for declaration status failed', + id: 'regHome.outbox.failed' + }, downloadDeclarationFailed: { defaultMessage: 'Failed to download declaration. Please try again', description: 'Label for declaration downloading failed', diff --git a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx index ca71dea115c..dc6f544d96f 100644 --- a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx +++ b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx @@ -78,7 +78,8 @@ const statusMessageMap = { [SUBMISSION_STATUS.READY_TO_ISSUE]: messages.statusWaitingToIssue, [SUBMISSION_STATUS.CERTIFYING]: messages.statusCertifying, [SUBMISSION_STATUS.ISSUING]: messages.statusIssuing, - [SUBMISSION_STATUS.FAILED_NETWORK]: messages.waitingToRetry + [SUBMISSION_STATUS.FAILED_NETWORK]: messages.waitingToRetry, + [SUBMISSION_STATUS.FAILED]: messages.failed } as const const statusInprogressIconIdMap = { From d97656d3bfd3ce49a4e715c31090f0c6966bb060 Mon Sep 17 00:00:00 2001 From: "Md. Ashikul Alam" Date: Thu, 13 Jun 2024 16:00:31 +0600 Subject: [PATCH 28/36] chore: check a record is already assigned --- packages/workflow/src/records/handler/download.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/workflow/src/records/handler/download.ts b/packages/workflow/src/records/handler/download.ts index 3f5bb2104cb..7769757db88 100644 --- a/packages/workflow/src/records/handler/download.ts +++ b/packages/workflow/src/records/handler/download.ts @@ -25,6 +25,8 @@ import { sendBundleToHearth } from '@workflow/records/fhir' import { indexBundleToRoute } from '@workflow/records/search' import { logger } from '@workflow/logger' import { auditEvent } from '@workflow/records/audit' +import { findAssignment } from '@opencrvs/commons/assignment' +import { getUserOrSystem } from '@workflow/records/user' function getDownloadedOrAssignedExtension( authHeader: IAuthHeader, @@ -54,6 +56,15 @@ export async function downloadRecordHandler( const token = getToken(request) // Task history is fetched rather than the task only const record = await getValidRecordById(payload.id, token, true) + const assignment = findAssignment(record) + + if (assignment) { + const userOrSystem = await getUserOrSystem(token) + const practitionerId = userOrSystem.practitionerId + + if (assignment.practitioner.id !== practitionerId) + throw new Error('Record is assigned to a different user') + } const task = getTaskFromSavedBundle(record) const businessStatus = getStatusFromTask(task) From de63f0044d3d488165c6a414d6a9ba706718a3d8 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 13:09:03 +0300 Subject: [PATCH 29/36] add pino to commons dependencies --- packages/commons/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/commons/package.json b/packages/commons/package.json index ae169591a31..7d296fe9301 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -42,7 +42,8 @@ "node-fetch": "^2.6.7", "pkg-up": "^3.1.0", "typescript": "4.9.5", - "uuid": "^9.0.0" + "uuid": "^9.0.0", + "pino": "^7.0.0" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.5.0", From a6f5f177a2140990d5e5755c488633aa397cb7a9 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 13:16:17 +0300 Subject: [PATCH 30/36] revert tsconfig changes temporarily --- packages/commons/src/authentication.ts | 2 +- packages/commons/tsconfig.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/commons/src/authentication.ts b/packages/commons/src/authentication.ts index 54ddb43454f..0739673508d 100644 --- a/packages/commons/src/authentication.ts +++ b/packages/commons/src/authentication.ts @@ -10,7 +10,7 @@ */ import { IAuthHeader } from './http' -import decode from 'jwt-decode' +import * as decode from 'jwt-decode' /** All the scopes user can be assigned to */ export const userScopes = { diff --git a/packages/commons/tsconfig.json b/packages/commons/tsconfig.json index bda401ca544..f0c37bf1f92 100644 --- a/packages/commons/tsconfig.json +++ b/packages/commons/tsconfig.json @@ -11,7 +11,6 @@ "moduleResolution": "node", "rootDir": "src", "declaration": true, - "esModuleInterop": true, "lib": ["esnext.asynciterable", "es2015", "es6"], "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, From e1e01d82eab934e4def1a5c4c29cbe580614e5f9 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 13:25:04 +0300 Subject: [PATCH 31/36] fix references to wrong logger --- packages/search/src/features/reindex/handler.ts | 2 +- packages/search/src/features/reindex/prune.ts | 2 +- packages/search/src/features/reindex/reindex.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/search/src/features/reindex/handler.ts b/packages/search/src/features/reindex/handler.ts index 73945c53de9..b96c2f97d5c 100644 --- a/packages/search/src/features/reindex/handler.ts +++ b/packages/search/src/features/reindex/handler.ts @@ -9,7 +9,7 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import * as Hapi from '@hapi/hapi' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import * as uuid from 'uuid' import { prune } from './prune' import { reindex, updateAliases } from './reindex' diff --git a/packages/search/src/features/reindex/prune.ts b/packages/search/src/features/reindex/prune.ts index 42b890df17f..eaefa9ca13c 100644 --- a/packages/search/src/features/reindex/prune.ts +++ b/packages/search/src/features/reindex/prune.ts @@ -10,7 +10,7 @@ */ import { OPENCRVS_INDEX_NAME } from '@search/constants' import { client } from '@search/elasticsearch/client' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { isBefore, parse, subMonths } from 'date-fns' export const prune = async ({ before = subMonths(new Date(), 3) } = {}) => { diff --git a/packages/search/src/features/reindex/reindex.ts b/packages/search/src/features/reindex/reindex.ts index 3d160ddcaba..9555e844cf1 100644 --- a/packages/search/src/features/reindex/reindex.ts +++ b/packages/search/src/features/reindex/reindex.ts @@ -17,7 +17,7 @@ import { streamAllRecords } from '@search/features/records/service' import { composeDocument as composeBirthDocument } from '@search/features/registration/birth/service' import { composeDocument as composeDeathDocument } from '@search/features/registration/death/service' import { composeDocument as composeMarriageDocument } from '@search/features/registration/marriage/service' -import { logger } from '@search/logger' +import { logger } from '@opencrvs/commons' import { getEventType } from '@search/utils/event' import { Transform } from 'stream' import { orderBy } from 'lodash' From 745e8bbd4005c24c6b02621e64eba0e69d7f134d Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 13:29:52 +0300 Subject: [PATCH 32/36] mock mongoose set --- packages/config/src/config/database.test.ts | 1 + packages/metrics/src/config/database.test.ts | 2 +- packages/notification/src/database.test.ts | 1 + packages/user-mgnt/src/database.test.ts | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/config/src/config/database.test.ts b/packages/config/src/config/database.test.ts index be9f09dd02c..aa8b972d95b 100644 --- a/packages/config/src/config/database.test.ts +++ b/packages/config/src/config/database.test.ts @@ -16,6 +16,7 @@ jest.mock('mongoose', () => ({ connection: { on: jest.fn() }, + set: () => {}, connect: () => Promise.reject(), disconnect: () => {} })) diff --git a/packages/metrics/src/config/database.test.ts b/packages/metrics/src/config/database.test.ts index 577f684c269..9c62263e207 100644 --- a/packages/metrics/src/config/database.test.ts +++ b/packages/metrics/src/config/database.test.ts @@ -16,8 +16,8 @@ jest.mock('mongoose', () => ({ connection: { on: jest.fn() }, + set: () => {}, connect: () => Promise.reject(), - // tslint:disable-next-line no-empty disconnect: () => {} })) const wait = (time: number) => diff --git a/packages/notification/src/database.test.ts b/packages/notification/src/database.test.ts index f17fc67f02b..68d8d4e560c 100644 --- a/packages/notification/src/database.test.ts +++ b/packages/notification/src/database.test.ts @@ -12,6 +12,7 @@ jest.mock('mongoose', () => ({ connection: { on: jest.fn() }, + set: () => {}, connect: () => Promise.reject(), disconnect: () => {} })) diff --git a/packages/user-mgnt/src/database.test.ts b/packages/user-mgnt/src/database.test.ts index f8eb6aa0840..5077c71867f 100644 --- a/packages/user-mgnt/src/database.test.ts +++ b/packages/user-mgnt/src/database.test.ts @@ -12,6 +12,7 @@ jest.mock('mongoose', () => ({ connection: { on: jest.fn() }, + set: () => {}, connect: () => Promise.reject(), disconnect: () => {} })) From 2cbe719776398814a26f88ce4ca1b2627ae543f2 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 13 Jun 2024 13:48:06 +0300 Subject: [PATCH 33/36] do not clear terminal window when rebuilding commons, bring log level back to default in dev script --- development-environment/dev.sh | 1 - packages/commons/package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/development-environment/dev.sh b/development-environment/dev.sh index f422063bf1d..a356b00e467 100755 --- a/development-environment/dev.sh +++ b/development-environment/dev.sh @@ -10,7 +10,6 @@ set -e DIR=$(cd "$(dirname "$0")"; pwd) export LANGUAGES="en,fr" -export LOG_LEVEL="error" if [ -n "$(uname -a | grep Ubuntu)" ]; then OS="UBUNTU" diff --git a/packages/commons/package.json b/packages/commons/package.json index 7d296fe9301..884bd045235 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -21,7 +21,7 @@ "test:compilation": "tsc --noEmit", "postinstall": "yarn build", "build": "tsc --project tsconfig.build.json", - "build:watch": "tsc --watch", + "build:watch": "tsc --watch --preserveWatchOutput", "build:clean": "rm -rf build" }, "private": true, From 0ebbec559e20358326f7e41c8d1bf5a82afbe61d Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Fri, 14 Jun 2024 09:50:33 +0300 Subject: [PATCH 34/36] Show failed records in outbox with a button to retry sending. Failed records are also automatically sent when the application first loads --- packages/client/src/SubmissionController.ts | 25 +++-- .../src/components/interface/Navigation.tsx | 3 +- .../src/i18n/messages/views/notifications.ts | 2 +- .../src/views/OfficeHome/outbox/Outbox.tsx | 97 +++++++++++++------ 4 files changed, 89 insertions(+), 38 deletions(-) diff --git a/packages/client/src/SubmissionController.ts b/packages/client/src/SubmissionController.ts index bd442effa87..26dec84c31d 100644 --- a/packages/client/src/SubmissionController.ts +++ b/packages/client/src/SubmissionController.ts @@ -33,8 +33,7 @@ export const ALLOWED_STATUS_FOR_RETRY = [ SUBMISSION_STATUS.READY_TO_CERTIFY, SUBMISSION_STATUS.READY_TO_ISSUE, SUBMISSION_STATUS.READY_TO_ARCHIVE, - SUBMISSION_STATUS.FAILED_NETWORK, - SUBMISSION_STATUS.FAILED + SUBMISSION_STATUS.FAILED_NETWORK ] as const export const INPROGRESS_STATUS = [ @@ -48,7 +47,7 @@ export const INPROGRESS_STATUS = [ SUBMISSION_STATUS.REQUESTING_CORRECTION ] as const -function isSubmissionAction(action: Action): action is SubmissionAction { +export function isSubmissionAction(action: Action): action is SubmissionAction { return Object.values(SubmissionAction).includes(action as SubmissionAction) } @@ -105,6 +104,7 @@ export class SubmissionController { /* eslint-disable no-console */ public sync = () => { + const firstSync = this.syncCount === 0 this.syncCount++ console.debug(`[${this.syncCount}] Starting sync...`) if (!isNavigatorOnline() || this.syncRunning) { @@ -117,11 +117,24 @@ export class SubmissionController { this.syncRunning = true this.requeueHangingDeclarations() - const declarations = this.getSubmitableDeclarations() + const submitableDeclarations = this.getSubmitableDeclarations() + + if (firstSync) { + const failedDeclarations = this.getDeclarations().filter( + (declaration) => + declaration.submissionStatus === SUBMISSION_STATUS.FAILED + ) + + submitableDeclarations.push(...failedDeclarations) + console.debug( + `[${this.syncCount}] First sync, adding ${failedDeclarations.length} failed declarations` + ) + } + console.debug( - `[${this.syncCount}] Syncing ${declarations.length} declarations` + `[${this.syncCount}] Syncing ${submitableDeclarations.length} declarations` ) - for (const declaration of declarations) { + for (const declaration of submitableDeclarations) { const action = declaration.action if (action && isSubmissionAction(action)) { this.store.dispatch( diff --git a/packages/client/src/components/interface/Navigation.tsx b/packages/client/src/components/interface/Navigation.tsx index faf110be929..ef0f03f5c48 100644 --- a/packages/client/src/components/interface/Navigation.tsx +++ b/packages/client/src/components/interface/Navigation.tsx @@ -407,7 +407,8 @@ const NavigationView = (props: IFullProps) => { ( [ ...ALLOWED_STATUS_FOR_RETRY, - ...INPROGRESS_STATUS + ...INPROGRESS_STATUS, + SUBMISSION_STATUS.FAILED ] as SUBMISSION_STATUS[] ).includes(draft.submissionStatus as SUBMISSION_STATUS) ).length diff --git a/packages/client/src/i18n/messages/views/notifications.ts b/packages/client/src/i18n/messages/views/notifications.ts index 0269a1cac2c..a9cf530d0b7 100644 --- a/packages/client/src/i18n/messages/views/notifications.ts +++ b/packages/client/src/i18n/messages/views/notifications.ts @@ -165,7 +165,7 @@ const messagesToDefine = { id: 'regHome.outbox.waitingToRetry' }, failed: { - defaultMessage: 'Retrying', + defaultMessage: 'Failed to send', description: 'Label for declaration status failed', id: 'regHome.outbox.failed' }, diff --git a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx index dc6f544d96f..30738e56a1e 100644 --- a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx +++ b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx @@ -8,33 +8,30 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import * as React from 'react' -import { WQContentWrapper } from '@client/views/OfficeHome/WQContentWrapper' -import { useIntl } from 'react-intl' -import { navigationMessages } from '@client/i18n/messages/views/navigation' -import { getTheme } from '@opencrvs/components/lib/theme' +import { + ALLOWED_STATUS_FOR_RETRY, + IInProgressStatus, + INPROGRESS_STATUS, + IRetryStatus, + isSubmissionAction +} from '@client/SubmissionController' +import { IDeclaration, SUBMISSION_STATUS } from '@client/declarations' +import { declarationReadyForStatusChange } from '@client/declarations/submissionMiddleware' +import { SubmissionAction } from '@client/forms' import { constantsMessages, dynamicConstantsMessages } from '@client/i18n/messages' -import { - ColumnContentAlignment, - COLUMNS, - Workqueue, - SORT_ORDER -} from '@opencrvs/components/lib/Workqueue' +import { navigationMessages } from '@client/i18n/messages/views/navigation' import { messages } from '@client/i18n/messages/views/notifications' -import { IDeclaration, SUBMISSION_STATUS } from '@client/declarations' -import { - ConnectionError, - StatusSubmissionWaiting as StatusWaiting -} from '@opencrvs/components/lib/icons' -import { useSelector } from 'react-redux' import { IStoreState } from '@client/store' +import { useOnlineStatus } from '@client/utils' import { formatPlainDate, isValidPlainDate } from '@client/utils/date-formatting' +import { getDeclarationFullName } from '@client/utils/draftUtils' +import { WQContentWrapper } from '@client/views/OfficeHome/WQContentWrapper' import { IconWithName, IconWithNameEvent, @@ -45,16 +42,22 @@ import { changeSortedColumn, getSortedItems } from '@client/views/OfficeHome/utils' -import { - ALLOWED_STATUS_FOR_RETRY, - IInProgressStatus, - INPROGRESS_STATUS, - IRetryStatus -} from '@client/SubmissionController' -import { useOnlineStatus } from '@client/utils' import { Spinner } from '@opencrvs/components/lib' -import { getDeclarationFullName } from '@client/utils/draftUtils' +import { + COLUMNS, + ColumnContentAlignment, + SORT_ORDER, + Workqueue +} from '@opencrvs/components/lib/Workqueue' import { useWindowSize } from '@opencrvs/components/lib/hooks' +import { + ConnectionError, + StatusSubmissionWaiting as StatusWaiting +} from '@opencrvs/components/lib/icons' +import { getTheme } from '@opencrvs/components/lib/theme' +import * as React from 'react' +import { useIntl } from 'react-intl' +import { useDispatch, useSelector } from 'react-redux' const statusMessageMap = { [SUBMISSION_STATUS.READY_TO_SUBMIT]: messages.statusWaitingToSubmit, @@ -94,7 +97,10 @@ const statusInprogressIconIdMap = { [SUBMISSION_STATUS.ISSUING]: 'issuing' } -type OutboxSubmissionStatus = IRetryStatus | IInProgressStatus +type OutboxSubmissionStatus = + | IRetryStatus + | IInProgressStatus + | SUBMISSION_STATUS.FAILED function isInprogressStatus( status: OutboxSubmissionStatus @@ -132,7 +138,11 @@ const isOutboxDeclaration = ( } => Boolean(declaration.submissionStatus) && ( - [...ALLOWED_STATUS_FOR_RETRY, ...INPROGRESS_STATUS] as SUBMISSION_STATUS[] + [ + ...ALLOWED_STATUS_FOR_RETRY, + ...INPROGRESS_STATUS, + SUBMISSION_STATUS.FAILED + ] as SUBMISSION_STATUS[] ).includes(declaration.submissionStatus as SUBMISSION_STATUS) export function Outbox() { @@ -145,6 +155,7 @@ export function Outbox() { const declarations = useSelector((state: IStoreState) => state.declarationsState?.declarations.filter(isOutboxDeclaration) ) + const dispatch = useDispatch() const onColumnClick = (columnName: string) => { const { newSortedCol, newSortOrder } = changeSortedColumn( @@ -208,7 +219,33 @@ export function Outbox() { /> ), submissionStatus: statusText, - statusIndicator: icon ? [{ actionComponent: icon }] : null, + statusIndicator: + declaration.submissionStatus === SUBMISSION_STATUS.FAILED + ? [ + { + label: 'Retry', + disabled: false, + handler: ( + e: + | React.MouseEvent + | undefined + ) => { + e && e.stopPropagation() + if (!isSubmissionAction(declaration.action!)) { + return + } + dispatch( + declarationReadyForStatusChange({ + ...declaration, + action: declaration.action + }) + ) + } + } + ] + : icon + ? [{ actionComponent: icon }] + : null, dateOfEvent } }) @@ -261,14 +298,14 @@ export function Outbox() { }, { label: '', - width: 21, + width: 15, key: 'submissionStatus', alignment: ColumnContentAlignment.RIGHT, color: theme.colors.supportingCopy }, { label: '', - width: 4, + width: 10, key: 'statusIndicator', isActionColumn: true } From 25620a24f89b7e144d55370d8abb60ecf7cbc2ba Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Fri, 14 Jun 2024 10:01:31 +0300 Subject: [PATCH 35/36] make retry text a language item --- packages/client/src/i18n/messages/views/notifications.ts | 6 ++++++ packages/client/src/views/OfficeHome/outbox/Outbox.tsx | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/client/src/i18n/messages/views/notifications.ts b/packages/client/src/i18n/messages/views/notifications.ts index a9cf530d0b7..baada02805a 100644 --- a/packages/client/src/i18n/messages/views/notifications.ts +++ b/packages/client/src/i18n/messages/views/notifications.ts @@ -129,6 +129,12 @@ const messagesToDefine = { description: 'Label for declaration status waiting for reject', id: 'regHome.outbox.statusWaitingToSubmit' }, + retry: { + id: 'regHome.outbox.statusRejecting', + defaultMessage: 'Retry', + description: + 'Copy for "Retry" button in Outbox shown for records that failed to send' + }, userAuditSuccess: { defaultMessage: '{name} was {action, select, DEACTIVATE {deactivated} REACTIVATE {reactivated} other {deactivated}}', diff --git a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx index 30738e56a1e..c5b909a69b7 100644 --- a/packages/client/src/views/OfficeHome/outbox/Outbox.tsx +++ b/packages/client/src/views/OfficeHome/outbox/Outbox.tsx @@ -17,7 +17,6 @@ import { } from '@client/SubmissionController' import { IDeclaration, SUBMISSION_STATUS } from '@client/declarations' import { declarationReadyForStatusChange } from '@client/declarations/submissionMiddleware' -import { SubmissionAction } from '@client/forms' import { constantsMessages, dynamicConstantsMessages @@ -223,7 +222,7 @@ export function Outbox() { declaration.submissionStatus === SUBMISSION_STATUS.FAILED ? [ { - label: 'Retry', + label: intl.formatMessage(messages.retry), disabled: false, handler: ( e: From e9cf66dd94b199fdc812f3af9e48fcfb90637d6c Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Fri, 14 Jun 2024 10:08:49 +0300 Subject: [PATCH 36/36] fix language item id --- packages/client/src/i18n/messages/views/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/i18n/messages/views/notifications.ts b/packages/client/src/i18n/messages/views/notifications.ts index baada02805a..a419dffc8f2 100644 --- a/packages/client/src/i18n/messages/views/notifications.ts +++ b/packages/client/src/i18n/messages/views/notifications.ts @@ -130,7 +130,7 @@ const messagesToDefine = { id: 'regHome.outbox.statusWaitingToSubmit' }, retry: { - id: 'regHome.outbox.statusRejecting', + id: 'regHome.outbox.retry', defaultMessage: 'Retry', description: 'Copy for "Retry" button in Outbox shown for records that failed to send'