UNPKG

@tech-arelius/api-client

Version:

Configurable HTTP client with builder pattern for Node.js/TypeScript

50 lines (44 loc) 1.19 kB
/** * Authorization types supported by the API client */ export enum AuthorizationType { BEARER = 'Bearer', BASIC = 'Basic', OAUTH = 'OAuth', CUSTOM = 'Custom' } /** * Session provider interface for authentication */ export abstract class SessionProvider { constructor(protected authorizationType: AuthorizationType = AuthorizationType.BEARER) {} /** * Get the authorization token */ abstract getToken(): Promise<string | null>; /** * Get the authorization type */ getAuthorizationType(): AuthorizationType { return this.authorizationType; } /** * Generate the full authorization header value */ async getAuthorizationHeader(): Promise<string | null> { const token = await this.getToken(); if (!token) return null; switch (this.authorizationType) { case AuthorizationType.BEARER: return `Bearer ${token}`; case AuthorizationType.BASIC: return `Basic ${token}`; case AuthorizationType.OAUTH: return `OAuth ${token}`; case AuthorizationType.CUSTOM: return token; default: return `Bearer ${token}`; } } }