diff --git a/package.json b/package.json index 93b3af9d..b95c6f99 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "@sinclair/typebox": "0.34.49", "@tryghost/errors": "3.2.0", "@tryghost/referrer-parser": "0.1.16", - "@tryghost/validator": "2.1.0", + "@tryghost/validator": "3.1.0", "fastify": "5.8.5", "fastify-plugin": "5.1.0", "pino": "10.3.1", diff --git a/src/schemas/format-registry.ts b/src/schemas/format-registry.ts index 5365811c..563668d6 100644 --- a/src/schemas/format-registry.ts +++ b/src/schemas/format-registry.ts @@ -7,9 +7,9 @@ import validator from '@tryghost/validator'; * format validators are available before any schema usage. */ export function registerFormatValidators(): void { - // UUID format validator using @tryghost/validator FormatRegistry.Set('uuid', (value) => { - return validator.isUUID(value); + // We only require UUID-shaped values here; they do not need to be fully RFC compliant. + return validator.isUUID(value, 'loose'); }); // URI format validator using @tryghost/validator @@ -23,4 +23,4 @@ export function registerFormatValidators(): void { const date = new Date(value); return !isNaN(date.getTime()) && date.toISOString() === value; }); -} \ No newline at end of file +} diff --git a/src/types/tryghost-validator.d.ts b/src/types/tryghost-validator.d.ts index e029c082..cc1a6853 100644 --- a/src/types/tryghost-validator.d.ts +++ b/src/types/tryghost-validator.d.ts @@ -5,7 +5,7 @@ declare module '@tryghost/validator' { isURL(str: string): boolean; isEmail(str: string): boolean; isIn(str: string, values: string[]): boolean; - isUUID(str: string, version?: number): boolean; + isUUID(str: string, version?: number | 'loose' | 'all' | 'nil' | 'max'): boolean; isBoolean(str: string): boolean; isInt(str: string, options?: {min?: number; max?: number}): boolean; isLowercase(str: string): boolean; @@ -20,4 +20,4 @@ declare module '@tryghost/validator' { const validator: Validator; export default validator; -} \ No newline at end of file +} diff --git a/test/unit/schemas/v1/page-hit-raw.test.ts b/test/unit/schemas/v1/page-hit-raw.test.ts index 6b3a4d6f..8f6c305a 100644 --- a/test/unit/schemas/v1/page-hit-raw.test.ts +++ b/test/unit/schemas/v1/page-hit-raw.test.ts @@ -104,6 +104,14 @@ describe('PageHitRawSchema v1', () => { expect(Value.Check(PageHitRawSchema, validData)).toBe(true); }); + it('should validate UUID-shaped values without requiring RFC version and variant bits', () => { + const validData = { + ...validPageHitRaw, + site_uuid: '12345678-1234-1234-1234-123456789012' + }; + expect(Value.Check(PageHitRawSchema, validData)).toBe(true); + }); + it('should reject invalid UUID format', () => { const invalidData = { ...validPageHitRaw, diff --git a/yarn.lock b/yarn.lock index c1fee1be..84ed7d37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1558,11 +1558,6 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.1.tgz#35adc6222e3662fa2222ce123b961476a746b9ea" integrity sha512-HqmEUIGRJ5fSXchkVgR5F7qn48bDBzv0kWj/Kfu5e6uci4UlEeng4331LnBkWffb++Ei3FOVLxo8JJWMFBDMeQ== -"@tryghost/errors@3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-3.1.0.tgz#d02112b290f5358c2e73f148084d3bad4cf72c17" - integrity sha512-vavmjjIAxngGuKK+D6vzYM+Bi36Td1cVEPtj25OFfHJj3xwoZL1Hji/wJylzqIRIFoCGvvHw+Ztnqjl9yLLAVw== - "@tryghost/errors@3.2.0": version "3.2.0" resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-3.2.0.tgz#d6dcc78fcdebd6c6767653e0fd859b93791194e7" @@ -1573,21 +1568,21 @@ resolved "https://registry.yarnpkg.com/@tryghost/referrer-parser/-/referrer-parser-0.1.16.tgz#47c26876d8b76f4e3f2b89968aed20380146e581" integrity sha512-lCs+puTmZW8UIJ3rI00GP70ndi/fntPKZ2ai2T5oKOfZg/X5QKLX6Pj6uLPvA2XTKp+4+jfAzuBUf3TiEMDZSA== -"@tryghost/tpl@2.1.0": - version "2.1.0" - resolved "https://registry.yarnpkg.com/@tryghost/tpl/-/tpl-2.1.0.tgz#48882a23bf929508d5a3faf2f27194ea520d6d75" - integrity sha512-NIzGwyHcFUnJRmaDkd5wx6X+lXfqXqUbsICKO4KcPFtwmqLVButlbidNZsXLdoblyI2J5jS6JIGY22TB+mtiBw== +"@tryghost/tpl@2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@tryghost/tpl/-/tpl-2.2.0.tgz#8178f529f36c6e9eb7a015e5a0a7eb5e11b8a33b" + integrity sha512-6OFCFHNzJxbZ0HXiLIAKJz5OkT6cdZId19m6UZ2+xN8oBg14iZwhoHoBWCzKNDrFN53t3N5JHM3oa/WtoB+BKw== -"@tryghost/validator@2.1.0": - version "2.1.0" - resolved "https://registry.yarnpkg.com/@tryghost/validator/-/validator-2.1.0.tgz#11cf6bc9690e5c45273e150e5df17bfbe7619b8f" - integrity sha512-HdM5ucxn91WG4pkLOIojPRFKWW1wF4IS9lhyxv95gA32AMWnGBpA5B1cQ9/Jv30Xn3ZBz6L7nxmoKtmdsRus7A== +"@tryghost/validator@3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@tryghost/validator/-/validator-3.1.0.tgz#53462554ae385384e9ed2ebbb7a8f64113d3aa0a" + integrity sha512-/C0uetcZA5In8jKnXJ31fVRbVkmxqBE+FBjz9w6Uj0/jG/7xbDzrpmwo1QHboc+5HfKFzvIvaLNTnjskBi28eQ== dependencies: - "@tryghost/errors" "3.1.0" - "@tryghost/tpl" "2.1.0" + "@tryghost/errors" "3.2.0" + "@tryghost/tpl" "2.2.0" lodash "4.18.1" moment-timezone "^0.5.23" - validator "7.2.0" + validator "13.15.35" "@tybys/wasm-util@^0.10.1": version "0.10.1" @@ -4886,10 +4881,10 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validator@7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/validator/-/validator-7.2.0.tgz#a63dcbaba51d4350bf8df20988e0d5a54d711791" - integrity sha512-c8NGTUYeBEcUIGeMppmNVKHE7wwfm3mYbNZxV+c5mlv9fDHI7Ad3p07qfNrn/CvpdkK2k61fOLRO2sTEhgQXmg== +validator@13.15.35: + version "13.15.35" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.15.35.tgz#81cf455c51f15b69d8d340be5914f3fab00dbf7f" + integrity sha512-TQ5pAGhd5whStmqWvYF4OjQROlmv9SMFVt37qoCBdqRffuuklWYQlCNnEs2ZaIBD1kZRNnikiZOS1eqgkar0iw== vite@8.0.10, "vite@^6.0.0 || ^7.0.0 || ^8.0.0": version "8.0.10"