From c4a0c9c6bbfb5997180db55bcd09e2b950b83878 Mon Sep 17 00:00:00 2001 From: David Ly Date: Wed, 17 Jul 2024 16:13:10 +0200 Subject: [PATCH] Added additional config validator for thumbnail domain --- documentation/src/utils/schemas.ts | 33 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/documentation/src/utils/schemas.ts b/documentation/src/utils/schemas.ts index 897ce8d21..868a5b022 100644 --- a/documentation/src/utils/schemas.ts +++ b/documentation/src/utils/schemas.ts @@ -212,6 +212,32 @@ export const CreateInspectionDiscriminatedUnionSchema = z.discriminatedUnion( ], ); +const apiDomain = ['api.monk.ai/v1', 'api.preview.monk.ai/v1', 'api.staging.monk.ai/v1'] as const; +const thumbnailDomain = [ + 'europe-west1-monk-staging-321715.cloudfunctions.net/image_resize', + 'europe-west1-monk-preview-321715.cloudfunctions.net/image_resize', + 'europe-west1-monk-prod.cloudfunctions.net/image_resize', +] as const; + +export const DomainsSchema = z + .object({ + apiDomain: z.enum(apiDomain), + thumbnailDomain: z.enum(thumbnailDomain), + }) + .refine( + (data) => { + const apiDomainIndex = apiDomain.indexOf(data.apiDomain); + const thumbnailDomainIndex = thumbnailDomain.indexOf(data.thumbnailDomain); + return apiDomainIndex === thumbnailDomainIndex; + }, + (data) => ({ + message: `The selected thumbnailDomain must correspond to the selected apiDomain. Please use the corresponding thumbnailDomain: ${ + thumbnailDomain[apiDomain.indexOf(data.apiDomain)] + }`, + path: ['thumbnailDomain'], + }), + ); + export const LiveConfigSchema = z .object({ id: z.string(), @@ -234,15 +260,10 @@ export const LiveConfigSchema = z allowManualLogin: z.boolean(), allowVehicleTypeSelection: z.boolean(), fetchFromSearchParams: z.boolean(), - apiDomain: z.enum(['api.monk.ai/v1', 'api.preview.monk.ai/v1', 'api.staging.monk.ai/v1']), - thumbnailDomain: z.enum([ - 'europe-west1-monk-staging-321715.cloudfunctions.net/image_resize', - 'europe-west1-monk-preview-321715.cloudfunctions.net/image_resize', - 'europe-west1-monk-prod.cloudfunctions.net/image_resize', - ]), requiredApiPermissions: z.array(z.nativeEnum(MonkApiPermission)).optional(), palette: MonkPaletteSchema.partial().optional(), }) + .and(DomainsSchema) .and(SteeringWheelDiscriminatedUnionSchema) .and(CreateInspectionDiscriminatedUnionSchema) .and(CameraConfigSchema)