-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create key toggle issue (#2711)
- Loading branch information
1 parent
19c814a
commit e622204
Showing
2 changed files
with
121 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { z } from "zod"; | ||
|
||
export const formSchema = z.object({ | ||
bytes: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" | ||
? "Amount must be a number and greater than 0" | ||
: defaultError, | ||
}), | ||
}) | ||
.default(16), | ||
prefix: z | ||
.string() | ||
.trim() | ||
.max(8, { message: "Please limit the prefix to under 8 characters." }) | ||
.optional(), | ||
ownerId: z.string().trim().optional(), | ||
name: z.string().trim().optional(), | ||
metaEnabled: z.boolean().default(false), | ||
meta: z | ||
.string() | ||
.refine( | ||
(s) => { | ||
try { | ||
JSON.parse(s); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}, | ||
{ | ||
message: "Must be valid json", | ||
}, | ||
) | ||
.optional(), | ||
limitEnabled: z.boolean().default(false), | ||
limit: z | ||
.object({ | ||
remaining: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" | ||
? "Remaining amount must be greater than 0" | ||
: defaultError, | ||
}), | ||
}) | ||
.int() | ||
.positive({ message: "Please enter a positive number" }), | ||
refill: z | ||
.object({ | ||
interval: z.enum(["daily", "monthly"]).default("monthly"), | ||
amount: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" | ||
? "Refill amount must be greater than 0 and a integer" | ||
: defaultError, | ||
}), | ||
}) | ||
.int() | ||
.min(1) | ||
.positive(), | ||
refillDay: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" | ||
? "Refill day must be an integer between 1 and 31" | ||
: defaultError, | ||
}), | ||
}) | ||
.int() | ||
.min(1) | ||
.max(31) | ||
.optional(), | ||
}) | ||
.optional(), | ||
}) | ||
.optional(), | ||
expireEnabled: z.boolean().default(false), | ||
expires: z.coerce | ||
.date() | ||
.min(new Date(new Date().getTime() + 2 * 60000)) | ||
.optional(), | ||
ratelimitEnabled: z.boolean().default(false), | ||
ratelimit: z | ||
.object({ | ||
async: z.boolean().default(false), | ||
duration: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" ? "Duration must be greater than 0" : defaultError, | ||
}), | ||
}) | ||
.positive({ message: "Refill interval must be greater than 0" }), | ||
limit: z.coerce | ||
.number({ | ||
errorMap: (issue, { defaultError }) => ({ | ||
message: | ||
issue.code === "invalid_type" ? "Refill limit must be greater than 0" : defaultError, | ||
}), | ||
}) | ||
.positive({ message: "Limit must be greater than 0" }), | ||
}) | ||
.optional(), | ||
environment: z.string().optional(), | ||
}); |