diff --git a/package.json b/package.json index 001ed09..59872a5 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "dependencies": { "async-retry": "^1.2.1", "lru-cache": "^11.0.0", - "zod": "^3.20.2", - "zod-validation-error": "^1.0.1" + "zod": "^4.0.0" }, "devDependencies": { "@apollo/gateway": "^2.13.0", @@ -54,7 +53,8 @@ }, "jest": { "collectCoverageFrom": [ - "./src/**" + "./src/**", + "!./src/**/*.d.ts" ], "coverageThreshold": { "global": { diff --git a/src/config.js b/src/config.js index 0181b77..935a5d7 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,5 @@ // @ts-check const { z } = require('zod') -const { fromZodError } = require('zod-validation-error') const ConfigSchema = z.object({ apiKey: z.string().startsWith('logql:'), @@ -94,11 +93,7 @@ function getConfig(options) { return maybeConfig.data } - const validationError = fromZodError(maybeConfig.error, { - prefix: 'Invalid options', - }) - - logInitError(validationError.message) + logInitError(z.prettifyError(maybeConfig.error)) } module.exports = { getConfig, loadEnv } diff --git a/tests/config.test.js b/tests/config.test.js index acdae96..e6e9dac 100644 --- a/tests/config.test.js +++ b/tests/config.test.js @@ -18,12 +18,16 @@ describe('Config Validation', () => { it('log an error when no config is given', () => { expect(initPlugin()).toEqual({}) - expect(console.error).toHaveBeenCalledWith('[logql-plugin][ERROR][init] Invalid options: Required at "apiKey"') + expect(console.error).toHaveBeenCalledWith( + '[logql-plugin][ERROR][init] ✖ Invalid input: expected string, received undefined\n → at apiKey' + ) }) it('log an error when config is empty', () => { expect(initPlugin({})).toEqual({}) - expect(console.error).toHaveBeenCalledWith('[logql-plugin][ERROR][init] Invalid options: Required at "apiKey"') + expect(console.error).toHaveBeenCalledWith( + '[logql-plugin][ERROR][init] ✖ Invalid input: expected string, received undefined\n → at apiKey' + ) }) it('work with valid minimal config', () => { @@ -34,7 +38,9 @@ describe('Config Validation', () => { it('ignore env by default', () => { process.env.LOGQL_API_KEY = 'logql:FAKE_API_KEY' expect(initPlugin({})).toEqual({}) - expect(console.error).toHaveBeenCalledWith('[logql-plugin][ERROR][init] Invalid options: Required at "apiKey"') + expect(console.error).toHaveBeenCalledWith( + '[logql-plugin][ERROR][init] ✖ Invalid input: expected string, received undefined\n → at apiKey' + ) }) it('load config from env', () => { diff --git a/yarn.lock b/yarn.lock index 4768360..5ffaf6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4426,12 +4426,7 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -zod-validation-error@^1.0.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-1.3.1.tgz#7134579d2ba3994495133b879a076786c8c270f5" - integrity sha512-cNEXpla+tREtNdAnNKY4xKY1SGOn2yzyuZMu4O0RQylX9apRpUjNcPkEc3uHIAr5Ct7LenjZt6RzjEH6+JsqVQ== - -zod@^3.20.2: - version "3.22.3" - resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.3.tgz#2fbc96118b174290d94e8896371c95629e87a060" - integrity sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug== +zod@^4.0.0: + version "4.3.6" + resolved "https://registry.yarnpkg.com/zod/-/zod-4.3.6.tgz#89c56e0aa7d2b05107d894412227087885ab112a" + integrity sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==