UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

128 lines (120 loc) 6.38 kB
import { IFetchResponse, IFetchOptions, FetchClient, BasicAuth, CookieAuth, Realtime, EventBinaryService, EventService, InventoryService, MeasurementService, AlarmService, OperationBulkService, OperationService, ApplicationService, UserService, TenantService, SystemOptionsService, TenantOptionsService, TenantSecurityOptionsService, TenantLoginOptionsService, AuditService, InventoryRoleService, InventoryBinaryService, DeviceRegistrationService, DeviceRegistrationBulkService, UserRoleService, UserGroupService, IdentityService, TrustedCertificateService, CrlService, SmartGroupsService, SmartRulesService, FeatureService } from '@c8y/client'; import { Observable, MonoTypeOperatorFunction } from 'rxjs'; import * as i0 from '@angular/core'; import { Provider, ModuleWithProviders } from '@angular/core'; interface ApiCallOptions { silentError?: boolean; responseInterceptor?: (res: IFetchResponse) => IFetchResponse; } interface Ng1HttpResponse { data: any; status: number; headers: any; } interface ApiCall { url: string; method: string; phase?: 'start' | 'finish'; options: ApiCallOptions & IFetchOptions; response?: Ng1HttpResponse | IFetchResponse; } interface HttpInterceptor { intercept(req: ApiCall, next: HttpHandler): Observable<IFetchResponse>; } declare abstract class HttpHandler { abstract handle(req: ApiCall): Observable<IFetchResponse>; } interface RequestStartAndFinish { onStart(req: ApiCall): void; onFinish(res: ApiCall): void; } declare class ApiService implements RequestStartAndFinish { private client; calls: Observable<ApiCall>; isLoading$: Observable<boolean>; private callsSubject; private interceptors; private interceptorCounter; constructor(client: FetchClient); /** * Allows to hook into the responses received by the FetchClient. * This is meant to be used to react on the responses, not for manipulation of the responses. * @param hookFilter A filter function to filter for specific responses. * @returns An Observable of the filtered responses. */ hookResponse(hookFilter: (call: ApiCall) => boolean): Observable<ApiCall>; /** * Allows to hook into the requests performed by the FetchClient. * This is meant to be used to react on the requests, not for manipulation of the requests. * @param hookFilter A filter function to filter for specific requests. * @returns An Observable of the filtered requests. */ hookRequest(hookFilter: (call: ApiCall) => boolean): Observable<ApiCall>; /** * Notifies observers that an API call has finished. * @param call The API call that has finished. */ onFinish(call: ApiCall): void; /** * Notifies observers that an API call has started. * @param call The API call that has started. */ onStart(call: ApiCall): void; /** * Resolves data from an API call response. * @returns A Promise containing an object with resolved data, method, and URL. */ resolveData<T = unknown>(call: ApiCall): Promise<{ data: T; method: string; url: string; }>; /** * Can be added to a pipe to exclude any permission call. Permission calls are PUT * request with only an id in it, to verify if the user has access to this managed object. * @returns The operator to be added to a pipe. */ excludePermissionCall(): MonoTypeOperatorFunction<ApiCall>; /** * Allows to intercept requests performed via the FetchClient requests. * @param interceptor The interceptor to be added. * @param id An optional unique identifier for the interceptor. The chain of interceptors is ordered by this id. And it can be used to remove the interceptor later on. * @returns The id of the interceptor (same as provided id if one was provided, otherwise an id will be generated). */ addInterceptor(interceptor: HttpInterceptor, id?: string): string; /** * Allows to remove a previously added interceptor by it's id. * @param id The id of the interceptor that should be removed. * @returns true if an interceptor existed and has been removed, or false if id does not exist. */ removeInterceptor(id: string): boolean; /** * Checks if an interceptor with a given id exists. * @param id The id of the interceptor. * @returns - Returns true if an interceptor with the given id exists, otherwise false. */ hasInterceptor(id: string): boolean; private hookIntoClientFetch; private createInterceptorChain; static ɵfac: i0.ɵɵFactoryDeclaration<ApiService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ApiService>; } /** * Provides all services from `@c8y/client` library. * @returns An array of providers for all services from `@c8y/client` library. */ declare function provideClientLibServices(): Provider[]; /** * @deprecated use provideClientLibServices instead */ declare class DataModule { static providers(): Provider[]; static forRoot(): ModuleWithProviders<DataModule>; static ɵfac: i0.ɵɵFactoryDeclaration<DataModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<DataModule, never, never, never>; static ɵinj: i0.ɵɵInjectorDeclaration<DataModule>; } declare const defaultServicesFromClientLib: readonly [typeof FetchClient, typeof BasicAuth, typeof CookieAuth, typeof Realtime, typeof EventBinaryService, typeof EventService, typeof InventoryService, typeof MeasurementService, typeof AlarmService, typeof OperationBulkService, typeof OperationService, typeof ApplicationService, typeof UserService, typeof TenantService, typeof SystemOptionsService, typeof TenantOptionsService, typeof TenantSecurityOptionsService, typeof TenantLoginOptionsService, typeof AuditService, typeof InventoryRoleService, typeof InventoryBinaryService, typeof DeviceRegistrationService, typeof DeviceRegistrationBulkService, typeof UserRoleService, typeof UserGroupService, typeof IdentityService, typeof TrustedCertificateService, typeof CrlService, typeof SmartGroupsService, typeof SmartRulesService, typeof FeatureService]; export { ApiService, DataModule, HttpHandler, defaultServicesFromClientLib, provideClientLibServices }; export type { ApiCall, ApiCallOptions, HttpInterceptor, Ng1HttpResponse }; //# sourceMappingURL=index.d.ts.map