UNPKG

@studiohyperdrive/ngx-auth

Version:

A library of core authentication functionality used with @studiohyperdrive/types-auth.

80 lines (79 loc) 4.09 kB
import { HttpClient, HttpContext } from '@angular/common/http'; import { Observable } from 'rxjs'; import { NgxAuthenticatedHttpClientConfiguration } from '../../types'; import * as i0 from "@angular/core"; /** * An opinionated wrapper of the HttpClient providing easy ways to make authenticated and unauthenticated calls */ export declare class NgxAuthenticatedHttpClient { private readonly httpClient; private baseUrl; constructor(httpClient: HttpClient, baseUrlHandler: NgxAuthenticatedHttpClientConfiguration['baseUrl']); /** * Adds a base-url to every request * @param {string} url - The url of the request */ private handleUrl; /** * Constructs a GET request to the provided API * * @param url - The url of the API * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ get<DataType = unknown>(url: string, params?: Parameters<HttpClient['get']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<DataType>; /** * Constructs a GET request tailored to downloading to the provided API * * @param url - The url of the API * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ download(url: string, params?: Parameters<HttpClient['get']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<{ fileType: string; blob: Blob; }>; /** * Constructs a DELETE request to the provided API * * @param url - The url of the API * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ delete<DataType = void>(url: string, params?: Parameters<HttpClient['delete']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<DataType>; /** * Constructs a POST request to the provided API * * @param url - The url of the API * @param body - The body we wish to send * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ post<DataType = void>(url: string, body: any, params?: Parameters<HttpClient['post']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<DataType>; /** * Constructs a PUT request to the provided API * * @param url - The url of the API * @param body - The body we wish to send * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ put<DataType = void>(url: string, body?: any, params?: Parameters<HttpClient['put']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<DataType>; /** * Constructs a PATCH request to the provided API * * @param url - The url of the API * @param body - The body we wish to send * @param params - An optional set of params we wish to send to the API * @param withCredentials - Whether the call is made by an authenticated user, by default true * @param context - An optional HTTPContext */ patch<DataType = void>(url: string, body: any, params?: Parameters<HttpClient['patch']>[1]['params'], withCredentials?: boolean, context?: HttpContext): Observable<DataType>; static ɵfac: i0.ɵɵFactoryDeclaration<NgxAuthenticatedHttpClient, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NgxAuthenticatedHttpClient>; }