autotrader-connect-api
Version:
Production-ready TypeScript wrapper for Auto Trader UK Connect APIs
85 lines • 1.81 kB
TypeScript
/**
* Authentication-related types for AutoTrader API
*/
/**
* Authentication credentials
*/
export interface AuthCredentials {
apiKey: string;
apiSecret: string;
}
/**
* OAuth2 token request payload
*/
export interface TokenRequest {
grant_type: 'client_credentials';
client_id: string;
client_secret: string;
scope?: string;
}
/**
* OAuth2 token response from API
*/
export interface AuthTokenResponse {
access_token: string;
token_type: 'Bearer';
expires_in: number;
scope?: string;
refresh_token?: string;
}
/**
* Internal token storage structure
*/
export interface StoredToken {
accessToken: string;
tokenType: string;
expiresIn: number;
issuedAt: number;
expiresAt: number;
scope?: string;
refreshToken?: string;
}
/**
* Authentication state
*/
export interface AuthState {
isAuthenticated: boolean;
token: StoredToken | null;
lastRefresh: number | null;
refreshInProgress: boolean;
}
/**
* Authentication configuration
*/
export interface AuthConfig {
credentials: AuthCredentials;
tokenEndpoint: string;
scope?: string;
tokenRefreshThreshold: number;
maxRetries: number;
retryDelay: number;
}
/**
* Authentication error types
*/
export type AuthErrorType = 'INVALID_CREDENTIALS' | 'TOKEN_EXPIRED' | 'REFRESH_FAILED' | 'NETWORK_ERROR' | 'INVALID_RESPONSE' | 'RATE_LIMITED';
/**
* Authentication error details
*/
export interface AuthError {
type: AuthErrorType;
message: string;
statusCode?: number;
retryAfter?: number;
originalError?: Error;
}
/**
* Token validation result
*/
export interface TokenValidation {
isValid: boolean;
expiresIn: number;
shouldRefresh: boolean;
error?: AuthError;
}
//# sourceMappingURL=auth.d.ts.map