UNPKG

@syngrisi/syngrisi

Version:
127 lines (121 loc) 4.32 kB
// src/server/schemas/CreateCheck.shema.ts import { z } from "zod"; var createCheckParamsSchema = z.object({ branch: z.string().min(1), appName: z.string().min(1), suitename: z.string().min(1), testid: z.string().regex(/^[a-f0-9]{24}$/), // Regex for 24 hex characters name: z.string().min(1), viewport: z.string().regex(/^\d+x\d+$/), // "WidthxHeight" format browserName: z.string().min(1), browserVersion: z.string().min(1), browserFullVersion: z.string(), os: z.string().min(1), hashcode: z.string().min(64), // SHA256 (64 chars) or SHA512 (128 chars) toleranceThreshold: z.coerce.number().min(0).max(100).optional() }); // src/server/schemas/GetBaseline.shema.ts import { z as z2 } from "zod"; var RequiredIdentOptionsSchema = z2.object({ name: z2.string().min(1), viewport: z2.string().min(3), browserName: z2.string().min(1), os: z2.string().min(1), app: z2.string().min(1), branch: z2.string().min(1) }); var IdentJSONStringSchema = z2.string().optional().refine((data) => { if (!data) return false; try { const parsed = JSON.parse(data); RequiredIdentOptionsSchema.parse(parsed); return true; } catch (e) { return false; } }, { message: "Invalid JSON string or does not match the required schema" }).openapi({ description: "baseline filter based on ident", example: '{"name": "Login page", "viewport": "1366x768", "browserName": "chrome", "os": "macOS", "app": "My App", "branch": "master"}' }); // src/server/schemas/App.schema.ts import { extendZodWithOpenApi as extendZodWithOpenApi3, OpenAPIRegistry } from "@asteasolutions/zod-to-openapi"; // src/server/schemas/utils/commonValidations.ts import { z as z4 } from "zod"; import { extendZodWithOpenApi as extendZodWithOpenApi2 } from "@asteasolutions/zod-to-openapi"; // src/server/schemas/common/Version.schema.ts import { z as z3 } from "zod"; import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi"; extendZodWithOpenApi(z3); var VersionBaseSchema = z3.string().regex(/^\d+\.\d+\.\d+$/, 'Version must be in the format "x.y.z"'); var VersionSchema = VersionBaseSchema.transform((value) => { const parts = value.split("."); return { major: parseInt(parts[0]), minor: parseInt(parts[1]), patch: parseInt(parts[2]) }; }); // src/server/schemas/utils/commonValidations.ts extendZodWithOpenApi2(z4); var mongooseIdRegex = /^[0-9a-fA-F]{24}$/; var id = z4.string().regex(mongooseIdRegex, { message: "Invalid Mongoose ObjectId format: /^[0-9a-fA-F]{24}$/" }).openapi({ description: "baseline ID", example: "6bbF35cAB3C59dA969edAe79" }); var commonValidations = { id, version: VersionBaseSchema.openapi({ example: "1.1.2" }), positiveNumberString: z4.string().refine((value) => { const num = Number(value); return Number.isInteger(num) && num >= 0; }, { message: "String must be a positive number or 0" }), password: z4.string().min(6).regex(/(?=.*[0-9])/, "Password must include a number").regex(/(?=.*[a-z])/, "Password must include a lowercase letter").regex(/(?=.*[A-Z])/, "Password must include an uppercase letter").refine((value) => { return /(?=.*[!@#$%^&*(),.?":{}|<>-])/.test(value); }, { message: "Password must include a special symbol" }).openapi({ example: "Aa1!IJASSNOJ" }), username: z4.string().min(1).openapi({ example: "john.doe@example.com" }), // TODO: workaround TBD date: z4.string().refine((val) => { const date = new Date(val); return !isNaN(date.getTime()); }, { message: "Invalid date format" }), paramsId: { params: z4.object({ id }) }, paramsTestId: { params: z4.object({ testid: id }) }, success: z4.object({ message: z4.literal("success") }) }; // src/server/schemas/App.schema.ts import { z as z5 } from "zod"; extendZodWithOpenApi3(z5); var registry = new OpenAPIRegistry(); var AppInfoRespSchema = z5.object({ version: commonValidations.version }); var AppRespSchema = z5.object({ _id: commonValidations.id, id: commonValidations.id, name: z5.string().min(1, "AppRespSchema: the name is empty").openapi({ example: "Admin Panel" }) }); export { AppInfoRespSchema, AppRespSchema, IdentJSONStringSchema, RequiredIdentOptionsSchema, VersionBaseSchema, createCheckParamsSchema, registry }; //# sourceMappingURL=index.js.map