diff --git a/dev/config/src/vite/vite.test.config.ts b/dev/config/src/vite/vite.test.config.ts index 17a3820f29..96d4a55243 100644 --- a/dev/config/src/vite/vite.test.config.ts +++ b/dev/config/src/vite/vite.test.config.ts @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + import { defineConfig } from "vitest/config"; import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js"; import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js"; @@ -52,6 +53,7 @@ export default function () { }, pool: "forks", // forks is slower than 'threads' but more compatible with low-level libs (e.g. bcrypt) testTimeout: 10000, + //disableConsoleIntercept: true, }, plugins: [ VitePluginSourcemapExclude({ excludeNodeModules: true }), diff --git a/packages/common/src/error.ts b/packages/common/src/error.ts index a638443fc1..ee86332a03 100644 --- a/packages/common/src/error.ts +++ b/packages/common/src/error.ts @@ -72,6 +72,9 @@ export abstract class ProsopoBaseError< private logError(logger: Logger, logLevel: LogLevel, errorName?: string) { const errorParams = { error: this.message, context: this.context }; const errorMessage = { errorType: errorName || this.name, errorParams }; + if (logLevel === "debug") { + logger.debug(this.stack); + } logger[logLevel](errorMessage); } } @@ -181,15 +184,15 @@ export class ProsopoApiError extends ProsopoBaseError { export const unwrapError = (err: ProsopoApiError | SyntaxError | ZodError) => { const code = "code" in err ? err.code : 400; - let message = err.message; + let message = i18next.t(err.message); let jsonError: ApiJsonError = { code, message }; let statusMessage = err.message; jsonError.message = message; // unwrap the errors to get the actual error message while (err instanceof ProsopoBaseError && err.context) { // base error will not have a translation key - jsonError.code = - err.context.translationKey || err.translationKey || jsonError.code; + jsonError.key = + err.context.translationKey || err.translationKey || "API.UNKNOWN"; jsonError.message = err.message; if (err.context.error) { err = err.context.error; @@ -197,7 +200,6 @@ export const unwrapError = (err: ProsopoApiError | SyntaxError | ZodError) => { break; } } - if (err instanceof ZodError) { message = i18next.t("CAPTCHA.PARSE_ERROR"); statusMessage = message; diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 2a3b33a4ca..f3c025f8a5 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -1,4 +1,18 @@ +// Copyright 2021-2024 Prosopo (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. export type ApiJsonError = { message: string; + key?: string; code: number; }; diff --git a/packages/locale/src/locales/de.json b/packages/locale/src/locales/de.json index b9e8b101a3..94ed6f094b 100644 --- a/packages/locale/src/locales/de.json +++ b/packages/locale/src/locales/de.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Falscher CAPTCHA-Typ", "UNAUTHORIZED_ORIGIN_URL": "Nicht autorisierte Ursprungs-URL", "INVALID_SITE_KEY": "Ungültiger Site-Schlüssel", - "INVALID_IP": "Ungültige IP" + "INVALID_IP": "Ungültige IP", + "INVALID_URL": "Ungültiger URL", + "INVALID_BODY": "Ungültiger Körper" }, "CLI": { "PARAMETER_ERROR": "Ungültiger Parameter" diff --git a/packages/locale/src/locales/en.json b/packages/locale/src/locales/en.json index 975e877d80..ba5f1ede15 100644 --- a/packages/locale/src/locales/en.json +++ b/packages/locale/src/locales/en.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Incorrect CAPTCHA type", "INVALID_SITE_KEY": "Invalid site key", "UNAUTHORIZED_ORIGIN_URL": "Unauthorized origin URL", - "INVALID_IP": "Invalid IP" + "INVALID_IP": "Invalid IP", + "INVALID_URL": "Invalid URL", + "INVALID_BODY": "Invalid body" }, "CLI": { "PARAMETER_ERROR": "Invalid parameter" diff --git a/packages/locale/src/locales/es.json b/packages/locale/src/locales/es.json index d7145e10c7..026ade08bf 100644 --- a/packages/locale/src/locales/es.json +++ b/packages/locale/src/locales/es.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Tipo di CAPTCHA errato", "UNAUTHORIZED_ORIGIN_URL": "URL de origen no autorizada", "INVALID_SITE_KEY": "Clave de sitio no válida", - "INVALID_IP": "IP no válida" + "INVALID_IP": "IP no válida", + "INVALID_URL": "URL inválida", + "INVALID_BODY": "Cuerpo inválido" }, "CLI": { "PARAMETER_ERROR": "Parámetro inválido" diff --git a/packages/locale/src/locales/fr.json b/packages/locale/src/locales/fr.json index f50d99a28a..1d1664d49b 100644 --- a/packages/locale/src/locales/fr.json +++ b/packages/locale/src/locales/fr.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Type de CAPTCHA incorrect", "UNAUTHORIZED_ORIGIN_URL": "URL d'origine non autorisée", "INVALID_SITE_KEY": "Clé de site non valide", - "INVALID_IP": "IP invalide" + "INVALID_IP": "IP invalide", + "INVALID_URL": "URL inválida", + "INVALID_BODY": "Cuerpo inválido" }, "CLI": { "PARAMETER_ERROR": "Paramètre invalide" diff --git a/packages/locale/src/locales/it.json b/packages/locale/src/locales/it.json index 08aca80628..6257670c88 100644 --- a/packages/locale/src/locales/it.json +++ b/packages/locale/src/locales/it.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Tipo di CAPTCHA errato", "UNAUTHORIZED_ORIGIN_URL": "URL di origine non autorizzato", "INVALID_SITE_KEY": "Chiave del sito non valida", - "INVALID_IP": "IP non valido" + "INVALID_IP": "IP non valido", + "INVALID_URL": "URL non valido", + "INVALID_BODY": "Corpo non valido" }, "CLI": { "PARAMETER_ERROR": "Parametro non valido" diff --git a/packages/locale/src/locales/pt-BR.json b/packages/locale/src/locales/pt-BR.json index 012cfba53c..c7f11630b2 100644 --- a/packages/locale/src/locales/pt-BR.json +++ b/packages/locale/src/locales/pt-BR.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Tipo de CAPTCHA incorreto", "UNAUTHORIZED_ORIGIN_URL": "URL de origem não autorizada", "INVALID_SITE_KEY": "Chave de site inválida", - "INVALID_IP": "IP inválido" + "INVALID_IP": "IP inválido", + "INVALID_URL": "URL inválido", + "INVALID_BODY": "Corpo inválido" }, "CLI": { "PARAMETER_ERROR": "Parâmetro inválido" diff --git a/packages/locale/src/locales/pt.json b/packages/locale/src/locales/pt.json index a223830a64..cf0c0f7843 100644 --- a/packages/locale/src/locales/pt.json +++ b/packages/locale/src/locales/pt.json @@ -108,7 +108,9 @@ "INCORRECT_CAPTCHA_TYPE": "Tipo de CAPTCHA incorreto", "UNAUTHORIZED_ORIGIN_URL": "URL de origem não autorizada", "INVALID_SITE_KEY": "Chave de site inválida", - "INVALID_IP": "IP inválido" + "INVALID_IP": "IP inválido", + "INVALID_URL": "URL inválido", + "INVALID_BODY": "Corpo inválido" }, "CLI": { "PARAMETER_ERROR": "Parâmetro inválido" diff --git a/packages/provider/src/api/captcha.ts b/packages/provider/src/api/captcha.ts index 0cd896f5a7..0355a0251c 100644 --- a/packages/provider/src/api/captcha.ts +++ b/packages/provider/src/api/captcha.ts @@ -26,29 +26,21 @@ import { type CaptchaSolutionResponse, type DappUserSolutionResult, GetFrictionlessCaptchaChallengeRequestBody, - type GetFrictionlessCaptchaResponse, GetPowCaptchaChallengeRequestBody, type GetPowCaptchaChallengeRequestBodyTypeOutput, type GetPowCaptchaResponse, type PowCaptchaSolutionResponse, SubmitPowCaptchaSolutionBody, type SubmitPowCaptchaSolutionBodyTypeOutput, - type TGetImageCaptchaChallengePathAndParams, } from "@prosopo/types"; -import { - FrictionlessToken, - FrictionlessTokenRecord, -} from "@prosopo/types-database"; import type { ProviderEnvironment } from "@prosopo/types-env"; -import { flatten, version } from "@prosopo/util"; +import { flatten } from "@prosopo/util"; import express, { type Router } from "express"; -import { v4 as uuidv4 } from "uuid"; import { getBotScore } from "../tasks/detection/getBotScore.js"; import { Tasks } from "../tasks/tasks.js"; import { getIPAddress } from "../util.js"; import { handleErrors } from "./errorHandler.js"; -const NO_IP_ADDRESS = "NO_IP_ADDRESS" as const; const DEFAULT_FRICTIONLESS_THRESHOLD = 0.5; /**