feat: improve api key endpoints, add users endpoint
This commit is contained in:
1 parent
d9c34f67e6
commit
084c91f6c1
11 files changed
+228
-7
No files matched your search
@@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
|
||||
const schemaApiKey = z
|
||||
.object({
|
||||
expiresAt: z.date().optional(), // default is 30 days
|
||||
expiresAt: z.string().transform((date: string) => new Date(date)).optional(), // default is 30 days
|
||||
note: z.string().min(1).optional(),
|
||||
})
|
||||
.strict(); // Adding strict so that we can disallow passing in extra fields
|
||||
|
||||
@@ -7,7 +7,7 @@ const schemaQueryId = z
|
||||
.object({
|
||||
// since nextjs parses query params as strings,
|
||||
// we need to cast them to numbers using z.transform() and parseInt()
|
||||
id: z.string().uuid()
|
||||
id: z.string()
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { schemaEventType } from "./eventType";
|
||||
// import { schemaCredential } from "./credential";
|
||||
// import { schemaMembership } from "./membership";
|
||||
// import { schemaBooking } from "./booking";
|
||||
// import { schemaSchedule } from "./schedule";
|
||||
// import { schemaSelectedCalendar } from "./selectedCalendar";
|
||||
// import { schemaAvailability } from "./availability";
|
||||
// import { schemaWebhook } from "./webhook";
|
||||
|
||||
import { z } from "zod";
|
||||
import { schemaApiKey } from "./apiKey";
|
||||
|
||||
const schemaUser = z
|
||||
.object({
|
||||
username: z.string().min(3),
|
||||
name: z.string().min(3),
|
||||
email: z.string().email(), // max is a full day.
|
||||
emailVerified: z.date().optional(),
|
||||
password: z.string().optional(),
|
||||
bio: z.string().min(3).optional(),
|
||||
avatar: z.string().optional(),
|
||||
timeZone: z.string().default("Europe/London"),
|
||||
weekStart: z.string().default("Sunday"),
|
||||
bufferTime: z.number().default(0),
|
||||
hideBranding: z.boolean().default(false),
|
||||
theme: z.string().optional(),
|
||||
trialEndsAt: z.date().optional(),
|
||||
eventTypes: z.array((schemaEventType)).optional(),
|
||||
// credentials: z.array((schemaCredentials)).optional(),
|
||||
// teams: z.array((schemaMembership)).optional(),
|
||||
// bookings: z.array((schemaBooking)).optional(),
|
||||
// schedules: z.array((schemaSchedule)).optional(),
|
||||
defaultScheduleId: z.number().optional(),
|
||||
// selectedCalendars: z.array((schemaSelectedCalendar)).optional(),
|
||||
completedOnboarding: z.boolean().default(false),
|
||||
locale: z.string().optional(),
|
||||
timeFormat: z.number().optional().default(12),
|
||||
twoFactorEnabled: z.boolean().default(false),
|
||||
twoFactorSecret: z.string().optional(),
|
||||
identityProvider: z.enum(["CAL", "SAML", "GOOGLE"]).optional().default("CAL"),
|
||||
identityProviderId: z.string().optional(),
|
||||
// availavility: z.array((schemaAvailavility)).optional(),
|
||||
invitedTo: z.number().optional(),
|
||||
plan: z.enum(['FREE', 'TRIAL', 'PRO']).default("TRIAL"),
|
||||
// webhooks: z.array((schemaWebhook)).optional(),
|
||||
brandColor: z.string().default("#292929"),
|
||||
darkBrandColor: z.string().default("#fafafa"),
|
||||
// destinationCalendar: z.instanceof(schemaEventType).optional(), // FIXME: instanceof doesnt work here
|
||||
away: z.boolean().default(false),
|
||||
metadata: z.object({}).optional(),
|
||||
verified: z.boolean().default(false),
|
||||
apiKeys: z.array((schemaApiKey)).optional(),
|
||||
})
|
||||
.strict(); // Adding strict so that we can disallow passing in extra fields
|
||||
const withValidUser = withValidation({
|
||||
schema: schemaUser,
|
||||
type: "Zod",
|
||||
mode: "body",
|
||||
});
|
||||
|
||||
export { schemaUser, withValidUser };
|
||||
Reference in new issue
Block a user