Skip to content

Commit

Permalink
chore: Clean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 12, 2023
1 parent c5342aa commit c20cd16
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions api.planx.uk/modules/webhooks/service/validateInput/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@ type HasuraValidateInputRequestSchema = z.infer<
typeof hasuraValidateInputRequestSchema
>;

interface IsCleanJSONBSchema {
interface IsCleanJSONBTransformedRequest {
body: {
isClean: boolean;
};
}

type isCleanJSONBSchema = z.ZodType<
IsCleanJSONBTransformedRequest,
z.ZodTypeDef,
HasuraValidateInputRequestSchema
>;

/**
* Schema which iterates over values of a JSONB column
* Checks using DOMPurify to ensure that user-submitted HTML is clean
* Fails fast - will reject on first instance of unclean HTML
*/
export const isCleanJSONBSchema: z.ZodType<
IsCleanJSONBSchema,
z.ZodTypeDef,
HasuraValidateInputRequestSchema
> = hasuraValidateInputRequestSchema.transform((original) => {
const isClean = original.body.data.input.every((input) =>
isObjectValid(input, isCleanHTML),
);
return { body: { isClean } };
});
export const isCleanJSONBSchema: isCleanJSONBSchema =
hasuraValidateInputRequestSchema.transform((original) => {
const isClean = original.body.data.input.every((input) =>
isObjectValid(input, isCleanHTML),
);
return { body: { isClean } };
});

export type IsCleanJSONBController = ValidatedRequestHandler<
typeof isCleanJSONBSchema,
Expand Down

0 comments on commit c20cd16

Please sign in to comment.