@api-buddy/types
Version:
Shared types for API Buddy
230 lines • 7.71 kB
TypeScript
import { z } from 'zod';
import type { BaseAdapter } from './base.js';
import { AdapterType } from './types.js';
export interface AuthProvider {
id: string;
name: string;
type: 'oauth' | 'oidc' | 'saml' | 'email' | 'phone' | 'password' | 'magic-link' | 'webauthn';
clientId?: string;
clientSecret?: string;
scopes?: string[];
authorizationUrl?: string;
tokenUrl?: string;
userInfoUrl?: string;
issuer?: string;
jwksUri?: string;
redirectUri?: string;
params?: Record<string, string>;
style?: {
logo?: string;
logoDark?: string;
bgColor?: string;
textColor?: string;
bgDark?: string;
textDark?: string;
};
[key: string]: any;
}
export declare const userProfileSchema: z.ZodObject<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, z.ZodTypeAny, "passthrough">>;
export declare const authSessionSchema: z.ZodObject<{
user: z.ZodObject<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
id: z.ZodString;
email: z.ZodOptional<z.ZodString>;
emailVerified: z.ZodOptional<z.ZodBoolean>;
name: z.ZodOptional<z.ZodString>;
avatar: z.ZodOptional<z.ZodString>;
}, z.ZodTypeAny, "passthrough">>;
accessToken: z.ZodString;
refreshToken: z.ZodOptional<z.ZodString>;
expiresAt: z.ZodOptional<z.ZodUnion<[z.ZodDate, z.ZodString]>>;
}, "strip", z.ZodTypeAny, {
user: {
id: string;
name?: string | undefined;
email?: string | undefined;
emailVerified?: boolean | undefined;
avatar?: string | undefined;
} & {
[k: string]: unknown;
};
accessToken: string;
refreshToken?: string | undefined;
expiresAt?: string | Date | undefined;
}, {
user: {
id: string;
name?: string | undefined;
email?: string | undefined;
emailVerified?: boolean | undefined;
avatar?: string | undefined;
} & {
[k: string]: unknown;
};
accessToken: string;
refreshToken?: string | undefined;
expiresAt?: string | Date | undefined;
}>;
export declare const emailPasswordCredentialsSchema: z.ZodObject<{
email: z.ZodString;
password: z.ZodString;
}, "strip", z.ZodTypeAny, {
email: string;
password: string;
}, {
email: string;
password: string;
}>;
export interface UserProfile {
id: string;
email?: string;
emailVerified?: boolean;
name?: string;
avatar?: string;
[key: string]: any;
}
export interface AuthSession<TUser extends UserProfile = UserProfile> {
user: TUser;
accessToken: string;
refreshToken?: string;
expiresAt?: Date;
}
export interface EmailPasswordCredentials {
email: string;
password: string;
}
export interface AuthAdapter<TUser extends UserProfile = UserProfile> extends BaseAdapter {
readonly type: AdapterType.AUTH;
signIn(credentials: any): Promise<AuthSession<TUser>>;
signOut(): Promise<void>;
getCurrentUser(): Promise<TUser | null>;
onAuthStateChanged(callback: (user: TUser | null) => void): () => void;
signUp?(credentials: any): Promise<TUser>;
sendPasswordResetEmail?(email: string): Promise<void>;
confirmPasswordReset?(code: string, newPassword: string): Promise<void>;
updateProfile?(updates: Partial<TUser>): Promise<TUser>;
updateEmail?(email: string, currentPassword?: string): Promise<void>;
updatePassword?(newPassword: string, currentPassword?: string): Promise<void>;
signInWithProvider?(providerId: string, options?: any): Promise<AuthSession<TUser>>;
getAccessToken?(forceRefresh?: boolean): Promise<string | null>;
refreshSession?(): Promise<AuthSession<TUser>>;
getIdToken?(forceRefresh?: boolean): Promise<string | null>;
}
/**
* Options for configuring an auth adapter
*/
export interface AuthAdapterOptions {
/**
* Unique identifier for the auth adapter instance
* If not provided, a UUID will be generated automatically
*/
id?: string;
/**
* The persistence mechanism to use for the auth state
* @default 'local'
*/
persistence?: 'local' | 'session' | 'none';
/**
* Whether to automatically refresh the access token when it expires
* @default true
*/
autoRefreshToken?: boolean;
/**
* The threshold in seconds before token expiration to attempt a refresh
* @default 300 (5 minutes)
*/
refreshThreshold?: number;
/**
* The URL to redirect to after successful authentication
*/
redirectTo?: string;
/**
* The URL to redirect to after sign out
*/
redirectAfterSignOut?: string;
}
/**
* Configuration for a social authentication provider
*/
export interface SocialProviderConfig {
/** The OAuth client ID */
clientId: string;
/** The OAuth client secret (server-side only) */
clientSecret?: string;
/** The OAuth scopes to request */
scopes?: string[];
/** The redirect URI for OAuth callbacks */
redirectUri?: string;
/** Additional provider-specific parameters */
params?: Record<string, string>;
}
/**
* Schema for validating social provider configurations
*/
export declare const socialProviderConfigSchema: z.ZodObject<{
clientId: z.ZodString;
clientSecret: z.ZodOptional<z.ZodString>;
scopes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
redirectUri: z.ZodOptional<z.ZodString>;
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
}, "strip", z.ZodTypeAny, {
clientId: string;
scopes: string[];
params?: Record<string, string> | undefined;
clientSecret?: string | undefined;
redirectUri?: string | undefined;
}, {
clientId: string;
params?: Record<string, string> | undefined;
clientSecret?: string | undefined;
scopes?: string[] | undefined;
redirectUri?: string | undefined;
}>;
/**
* Type guard for UserProfile
* @param value - The value to check
* @returns True if the value is a valid UserProfile
*/
export declare function isUserProfile(value: unknown): value is UserProfile;
/**
* Type guard for AuthSession
* @param value - The value to check
* @returns True if the value is a valid AuthSession
*/
export declare function isAuthSession<T extends UserProfile = UserProfile>(value: unknown): value is AuthSession<T>;
/**
* Type guard for EmailPasswordCredentials
* @param value - The value to check
* @returns True if the value is a valid EmailPasswordCredentials
*/
export declare function isEmailPasswordCredentials(value: unknown): value is EmailPasswordCredentials;
//# sourceMappingURL=auth.d.ts.map