used zod codemod

This commit is contained in:
Lokowitz
2025-11-16 14:18:17 +00:00
parent 000904eb31
commit 7db99a7dd5
191 changed files with 764 additions and 1232 deletions

View File

@@ -13,12 +13,10 @@ import { verifySession } from "@server/auth/sessions/verifySession";
import { usageService } from "@server/lib/billing/usageService";
import { FeatureId } from "@server/lib/billing";
const acceptInviteBodySchema = z
.object({
const acceptInviteBodySchema = z.strictObject({
token: z.string(),
inviteId: z.string()
})
.strict();
});
export type AcceptInviteResponse = {
accepted: boolean;

View File

@@ -9,13 +9,11 @@ import logger from "@server/logger";
import { eq } from "drizzle-orm";
import { fromError } from "zod-validation-error";
const addUserActionSchema = z
.object({
const addUserActionSchema = z.strictObject({
userId: z.string(),
actionId: z.string(),
orgId: z.string()
})
.strict();
});
export async function addUserAction(
req: Request,

View File

@@ -11,12 +11,10 @@ import { fromError } from "zod-validation-error";
import stoi from "@server/lib/stoi";
import { OpenAPITags, registry } from "@server/openApi";
const addUserRoleParamsSchema = z
.object({
const addUserRoleParamsSchema = z.strictObject({
userId: z.string(),
roleId: z.string().transform(stoi).pipe(z.number())
})
.strict();
});
export type AddUserRoleResponse = z.infer<typeof addUserRoleParamsSchema>;

View File

@@ -9,12 +9,10 @@ import logger from "@server/logger";
import { eq } from "drizzle-orm";
import { fromError } from "zod-validation-error";
const addUserSiteSchema = z
.object({
const addUserSiteSchema = z.strictObject({
userId: z.string(),
siteId: z.string().transform(Number).pipe(z.number().int().positive())
})
.strict();
siteId: z.string().transform(Number).pipe(z.int().positive())
});
export async function addUserSite(
req: Request,

View File

@@ -9,11 +9,9 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { OpenAPITags, registry } from "@server/openApi";
const adminGetUserSchema = z
.object({
const adminGetUserSchema = z.strictObject({
userId: z.string().min(1)
})
.strict();
});
registry.registerPath({
method: "get",

View File

@@ -9,22 +9,20 @@ import logger from "@server/logger";
import { idp, users } from "@server/db";
import { fromZodError } from "zod-validation-error";
const listUsersSchema = z
.object({
const listUsersSchema = z.strictObject({
limit: z
.string()
.optional()
.default("1000")
.transform(Number)
.pipe(z.number().int().nonnegative()),
.pipe(z.int().nonnegative()),
offset: z
.string()
.optional()
.default("0")
.transform(Number)
.pipe(z.number().int().nonnegative())
})
.strict();
.pipe(z.int().nonnegative())
});
async function queryUsers(limit: number, offset: number) {
return await db

View File

@@ -9,11 +9,9 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const removeUserSchema = z
.object({
const removeUserSchema = z.strictObject({
userId: z.string()
})
.strict();
});
export async function adminRemoveUser(
req: Request,

View File

@@ -10,17 +10,13 @@ import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { OpenAPITags, registry } from "@server/openApi";
const updateUser2FAParamsSchema = z
.object({
const updateUser2FAParamsSchema = z.strictObject({
userId: z.string()
})
.strict();
});
const updateUser2FABodySchema = z
.object({
const updateUser2FABodySchema = z.strictObject({
twoFactorSetupRequested: z.boolean()
})
.strict();
});
export type UpdateUser2FAResponse = {
userId: string;

View File

@@ -16,21 +16,17 @@ import { build } from "@server/build";
import { getOrgTierData } from "#dynamic/lib/billing";
import { TierId } from "@server/lib/billing/tiers";
const paramsSchema = z
.object({
const paramsSchema = z.strictObject({
orgId: z.string().nonempty()
})
.strict();
});
const bodySchema = z
.object({
email: z
.string()
const bodySchema = z.strictObject({
email: z.email()
.toLowerCase()
.optional()
.refine((data) => {
if (data) {
return z.string().email().safeParse(data).success;
return z.email().safeParse(data).success;
}
return true;
}),
@@ -39,8 +35,7 @@ const bodySchema = z
type: z.enum(["internal", "oidc"]).optional(),
idpId: z.number().optional(),
roleId: z.number()
})
.strict();
});
export type CreateOrgUserResponse = {};

View File

@@ -46,12 +46,10 @@ export type GetOrgUserResponse = NonNullable<
Awaited<ReturnType<typeof queryUser>>
>;
const getOrgUserParamsSchema = z
.object({
const getOrgUserParamsSchema = z.strictObject({
userId: z.string(),
orgId: z.string()
})
.strict();
});
registry.registerPath({
method: "get",

View File

@@ -21,21 +21,17 @@ import { FeatureId } from "@server/lib/billing";
import { build } from "@server/build";
import cache from "@server/lib/cache";
const inviteUserParamsSchema = z
.object({
const inviteUserParamsSchema = z.strictObject({
orgId: z.string()
})
.strict();
});
const inviteUserBodySchema = z
.object({
email: z.string().toLowerCase().email(),
const inviteUserBodySchema = z.strictObject({
email: z.email().toLowerCase(),
roleId: z.number(),
validHours: z.number().gt(0).lte(168),
sendEmail: z.boolean().optional(),
regenerate: z.boolean().optional()
})
.strict();
});
export type InviteUserBody = z.infer<typeof inviteUserBodySchema>;

View File

@@ -10,28 +10,24 @@ import logger from "@server/logger";
import { fromZodError } from "zod-validation-error";
import { OpenAPITags, registry } from "@server/openApi";
const listInvitationsParamsSchema = z
.object({
const listInvitationsParamsSchema = z.strictObject({
orgId: z.string()
})
.strict();
});
const listInvitationsQuerySchema = z
.object({
const listInvitationsQuerySchema = z.strictObject({
limit: z
.string()
.optional()
.default("1000")
.transform(Number)
.pipe(z.number().int().nonnegative()),
.pipe(z.int().nonnegative()),
offset: z
.string()
.optional()
.default("0")
.transform(Number)
.pipe(z.number().int().nonnegative())
})
.strict();
.pipe(z.int().nonnegative())
});
async function queryInvitations(orgId: string, limit: number, offset: number) {
return await db

View File

@@ -11,28 +11,24 @@ import { fromZodError } from "zod-validation-error";
import { OpenAPITags, registry } from "@server/openApi";
import { eq } from "drizzle-orm";
const listUsersParamsSchema = z
.object({
const listUsersParamsSchema = z.strictObject({
orgId: z.string()
})
.strict();
});
const listUsersSchema = z
.object({
const listUsersSchema = z.strictObject({
limit: z
.string()
.optional()
.default("1000")
.transform(Number)
.pipe(z.number().int().nonnegative()),
.pipe(z.int().nonnegative()),
offset: z
.string()
.optional()
.default("0")
.transform(Number)
.pipe(z.number().int().nonnegative())
})
.strict();
.pipe(z.int().nonnegative())
});
async function queryUsers(orgId: string, limit: number, offset: number) {
return await db

View File

@@ -9,12 +9,10 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const removeInvitationParamsSchema = z
.object({
const removeInvitationParamsSchema = z.strictObject({
orgId: z.string(),
inviteId: z.string()
})
.strict();
});
export async function removeInvitation(
req: Request,

View File

@@ -9,18 +9,14 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const removeUserActionParamsSchema = z
.object({
const removeUserActionParamsSchema = z.strictObject({
userId: z.string()
})
.strict();
});
const removeUserActionSchema = z
.object({
const removeUserActionSchema = z.strictObject({
actionId: z.string(),
orgId: z.string()
})
.strict();
});
export async function removeUserAction(
req: Request,

View File

@@ -14,12 +14,10 @@ import { FeatureId } from "@server/lib/billing";
import { build } from "@server/build";
import { UserType } from "@server/types/UserTypes";
const removeUserSchema = z
.object({
const removeUserSchema = z.strictObject({
userId: z.string(),
orgId: z.string()
})
.strict();
});
registry.registerPath({
method: "delete",

View File

@@ -9,15 +9,13 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const removeUserResourceSchema = z
.object({
const removeUserResourceSchema = z.strictObject({
userId: z.string(),
resourceId: z
.string()
.transform(Number)
.pipe(z.number().int().positive())
})
.strict();
.pipe(z.int().positive())
});
export async function removeUserResource(
req: Request,

View File

@@ -9,17 +9,13 @@ import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const removeUserSiteParamsSchema = z
.object({
const removeUserSiteParamsSchema = z.strictObject({
userId: z.string()
})
.strict();
});
const removeUserSiteSchema = z
.object({
siteId: z.number().int().positive()
})
.strict();
const removeUserSiteSchema = z.strictObject({
siteId: z.int().positive()
});
export async function removeUserSite(
req: Request,

View File

@@ -9,20 +9,16 @@ import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { OpenAPITags, registry } from "@server/openApi";
const paramsSchema = z
.object({
const paramsSchema = z.strictObject({
userId: z.string(),
orgId: z.string()
})
.strict();
});
const bodySchema = z
.object({
const bodySchema = z.strictObject({
autoProvisioned: z.boolean().optional()
})
.strict()
.refine((data) => Object.keys(data).length > 0, {
message: "At least one field must be provided for update"
error: "At least one field must be provided for update"
});
registry.registerPath({