UNPKG

userdo

Version:

A Durable Object base class for building applications on Cloudflare Workers.

188 lines (187 loc) 4.99 kB
import { z } from 'zod'; export declare const SignupRequestSchema: z.ZodObject<{ email: z.ZodString; password: z.ZodString; }, "strip", z.ZodTypeAny, { email: string; password: string; }, { email: string; password: string; }>; export declare const LoginRequestSchema: z.ZodObject<{ email: z.ZodString; password: z.ZodString; }, "strip", z.ZodTypeAny, { email: string; password: string; }, { email: string; password: string; }>; export declare const PasswordResetRequestSchema: z.ZodObject<{ email: z.ZodString; }, "strip", z.ZodTypeAny, { email: string; }, { email: string; }>; export declare const PasswordResetConfirmSchema: z.ZodObject<{ resetToken: z.ZodString; newPassword: z.ZodString; }, "strip", z.ZodTypeAny, { newPassword: string; resetToken: string; }, { newPassword: string; resetToken: string; }>; export declare const SetDataRequestSchema: z.ZodObject<{ key: z.ZodString; value: z.ZodUnknown; }, "strip", z.ZodTypeAny, { key: string; value?: unknown; }, { key: string; value?: unknown; }>; export declare const AuthResponseSchema: z.ZodObject<{ user: z.ZodObject<{ id: z.ZodString; email: z.ZodString; createdAt: z.ZodString; }, "strip", z.ZodTypeAny, { createdAt: string; id: string; email: string; }, { createdAt: string; id: string; email: string; }>; token: z.ZodString; refreshToken: z.ZodString; }, "strip", z.ZodTypeAny, { token: string; refreshToken: string; user: { createdAt: string; id: string; email: string; }; }, { token: string; refreshToken: string; user: { createdAt: string; id: string; email: string; }; }>; export declare const ErrorResponseSchema: z.ZodObject<{ error: z.ZodString; }, "strip", z.ZodTypeAny, { error: string; }, { error: string; }>; export declare const SuccessResponseSchema: z.ZodObject<{ ok: z.ZodLiteral<true>; }, "strip", z.ZodTypeAny, { ok: true; }, { ok: true; }>; export declare const DataResponseSchema: z.ZodObject<{ ok: z.ZodLiteral<true>; data: z.ZodUnknown; }, "strip", z.ZodTypeAny, { ok: true; data?: unknown; }, { ok: true; data?: unknown; }>; export declare const EventsResponseSchema: z.ZodArray<z.ZodObject<{ event: z.ZodString; data: z.ZodUnknown; timestamp: z.ZodNumber; }, "strip", z.ZodTypeAny, { event: string; timestamp: number; data?: unknown; }, { event: string; timestamp: number; data?: unknown; }>, "many">; export type SignupRequest = z.infer<typeof SignupRequestSchema>; export type LoginRequest = z.infer<typeof LoginRequestSchema>; export type PasswordResetRequest = z.infer<typeof PasswordResetRequestSchema>; export type PasswordResetConfirm = z.infer<typeof PasswordResetConfirmSchema>; export type SetDataRequest = z.infer<typeof SetDataRequestSchema>; export type AuthResponse = z.infer<typeof AuthResponseSchema>; export type ErrorResponse = z.infer<typeof ErrorResponseSchema>; export type SuccessResponse = z.infer<typeof SuccessResponseSchema>; export type DataResponse = z.infer<typeof DataResponseSchema>; export type EventsResponse = z.infer<typeof EventsResponseSchema>; export interface UserDOEndpoints { 'POST /api/signup': { body: SignupRequest; response: AuthResponse | ErrorResponse; }; 'POST /api/login': { body: LoginRequest; response: AuthResponse | ErrorResponse; }; 'POST /api/logout': { response: SuccessResponse; }; 'GET /api/me': { response: { user: AuthResponse['user']; } | ErrorResponse; }; 'POST /api/password-reset/request': { body: PasswordResetRequest; response: { ok: true; message: string; resetToken?: string; } | ErrorResponse; }; 'POST /api/password-reset/confirm': { body: PasswordResetConfirm; response: { ok: true; message: string; } | ErrorResponse; }; 'GET /api/events': { query: { since?: string; }; response: EventsResponse | ErrorResponse; }; 'GET /data': { response: DataResponse | ErrorResponse; }; 'POST /data': { body: SetDataRequest; response: DataResponse | ErrorResponse; }; 'GET /protected/profile': { response: { ok: true; user: AuthResponse['user']; } | ErrorResponse; }; } export type EndpointRequest<T extends keyof UserDOEndpoints> = UserDOEndpoints[T] extends { body: infer B; } ? B : never; export type EndpointResponse<T extends keyof UserDOEndpoints> = UserDOEndpoints[T]['response']; export type EndpointQuery<T extends keyof UserDOEndpoints> = UserDOEndpoints[T] extends { query: infer Q; } ? Q : never;