Skip to content

Commit

Permalink
Added additional config validator for thumbnail domain
Browse files Browse the repository at this point in the history
  • Loading branch information
dlymonkai committed Jul 18, 2024
1 parent 7c6ab33 commit c4a0c9c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions documentation/src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
Expand Down

0 comments on commit c4a0c9c

Please sign in to comment.