feat: add more auth features and remove auth module
Some checks failed
Build, Lint & Test Lib / Build, Lint and Test Library (push) Has been cancelled

This commit is contained in:
2025-02-08 01:02:00 +08:00
parent c8c4fc847d
commit fe10ed2850
15 changed files with 263 additions and 155 deletions

View File

@@ -1,10 +1,15 @@
import {
// biome-ignore lint/nursery/noExportedImports: <explanation>
HttpClient as DefaultHttpClient,
type HttpBackend,
HttpClient,
type HttpFeature,
HttpFeatureKind,
// biome-ignore lint/nursery/noExportedImports: <explanation>
HttpHeaders,
type HttpInterceptor,
type HttpInterceptorFn,
type HttpRequest,
type HttpParams as NgifyHttpParams,
withInterceptors,
withLegacyInterceptors,
} from '@ngify/http';
@@ -13,8 +18,12 @@ import {
Optional,
type Provider,
} from '@outposts/injection-js';
import type { Observable } from 'rxjs';
import type { ArrayOrNullableOne } from '../utils/types';
export { HttpParams, type HttpParamsOptions } from './params';
// biome-ignore lint/nursery/noExportedImports: <explanation>
import { HttpParams, type HttpParamsOptions } from './params';
export { HttpParams, HttpHeaders, type HttpParamsOptions, DefaultHttpClient };
export const HTTP_FEATURES = new InjectionToken<HttpFeature[]>('HTTP_FEATURES');
@@ -112,14 +121,29 @@ export function provideHttpClient(features: HttpFeature[] = []): Provider[] {
multi: true,
},
{
provide: HttpClient,
provide: HTTP_CLIENT,
useFactory: (features: ArrayOrNullableOne<HttpFeature>[]) => {
const normalizedFeatures = [features]
.flat(Number.MAX_SAFE_INTEGER)
.filter(Boolean) as HttpFeature[];
return new HttpClient(...normalizedFeatures);
return new DefaultHttpClient(...normalizedFeatures);
},
deps: [HTTP_FEATURES],
},
];
}
export type HttpClient = {
get<T>(
url: string,
options?: { headers?: HttpHeaders; params?: NgifyHttpParams }
): Observable<T>;
post<T>(
url: string,
body?: HttpRequest<any>['body'],
options?: { headers?: HttpHeaders; params?: NgifyHttpParams }
): Observable<T>;
};
export const HTTP_CLIENT = new InjectionToken<HttpClient>('HTTP_CLIENT');