1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-24 22:46:41 +07:00
vk-tg-bot/src/service/vk/validation.ts
2021-05-20 17:33:42 +07:00

38 lines
1 KiB
TypeScript

import * as yup from "yup";
import { VkConfig, VkEvent } from "./types";
import { templateOptionalSchema } from "../../config/validate";
const vkChannelEventSchema = yup.string().oneOf(Object.values(VkEvent));
const vkChannelSchema = yup
.object()
.required()
.shape({
id: yup
.string()
.required()
.matches(/^@/, ({ path }) => `${path} should start with "@"`),
events: yup.array().of(vkChannelEventSchema),
templates: templateOptionalSchema,
});
export const vkConfigSchema = yup
.object<VkConfig>()
.required()
.shape({
endpoint: yup.string().optional(),
groups: yup
.array()
.required()
.of(
yup.object().shape({
id: yup.number().positive(),
name: yup.string().required(),
testResponse: yup.string().required(),
secretKey: yup.string().required(),
apiKey: yup.string().required(),
channels: yup.array().of(vkChannelSchema),
templates: templateOptionalSchema,
})
),
});