import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex } from '../../index-DAUqbQ6h.js'; import { HTTPErrorClass } from '../common/httpError.js'; import { HTTP } from './http.js'; import { APIClient as APIClient$1, APIClientOptions, ErrorResponse } from '@homer0/api-utils'; export { ErrorResponse } from '@homer0/api-utils'; import '../../types/express.js'; import 'express'; import '../../types/http.js'; import 'https'; import 'http'; import 'spdy'; import 'node-fetch'; import '../../types/utils.js'; import '@homer0/path-utils'; import '@homer0/simple-logger'; import '@homer0/simple-config'; import '@homer0/events-hub'; import '../../utils/fns/statuses.js'; import 'statuses'; import '../common/appError.js'; /** * The required settings needed to create the an API client. * * @group Services/APIClient */ type APIClientConfig = Pick; /** * A dictionary of endpoints for the API client. * This is declared as standalone because it needs to reference them multiple times. * * @group Services/APIClient */ type EndpointsType = APIClientOptions['endpoints']; /** * The format the settings needs to have in the application configuration in order to * create a valid API client. * The settings may include the endpoints dictionary in the `endpoints` property, or the * gateway `property`, with `endpoints` always having priority if both exists. * The reason for the `gateway` property to be valid, is in case the application also * implements a {@link GatewayController}, using the same property for both things will * help reduce the amount of duplicated definitions. * * @group Services/APIClient */ type APIClientSettings = Omit & ({ endpoints: EndpointsType; gateway?: EndpointsType; } | { endpoints?: EndpointsType; gateway: EndpointsType; }); /** * The options to construct a {@link APIClient}. * * @group Services/APIClient */ type APIClientConstructorOptions = APIClientSettings & { /** * A dictionary with the dependencies to inject. */ inject: { http: HTTP; HTTPError: HTTPErrorClass; }; }; /** * An API client for the application to use. What makes this service special is that it * formats received errors using the {@link _HTTPError} class, and as fetch client, it * uses the {@link HTTP} service, allowing the application to to internally handle all the * requests and responses. * * The only reason to use the class directly is if you want to subclass it, as you would * normally just register the {@link apiClientProvider}. * * @group Services * @group Services/APIClient */ declare class APIClient extends APIClient$1 { /** * The service that makes the requests to the API. */ protected readonly _http: HTTP; /** * The class to generate possible errors in the requests. */ protected readonly _HTTPError: HTTPErrorClass; /** * The configuration of the API it uses. */ protected readonly _apiConfig: APIClientConfig; /** * @param options The options to construct the class. */ constructor({ inject: { http, HTTPError }, ...rest }: APIClientConstructorOptions); /** * The configuration for the API. */ get apiConfig(): Readonly; /** * Tries to obtain a message from an error caused on a failed request. * * @param response The response from the failed request. */ protected _getErrorMessageFromResponse(response: unknown): string; /** * Generates an {@link _HTTPError} from the response of a failed request. * * @param response The response from the failed request. * @param status The status code of the response. */ protected formatError(response: ResponseType, status: number): Error; } /** * The options for the provider creator that registers an {@link APIClient} in the * container. * These options allow the application to register multiple instances for different APIs. * * @group Services/APIClient */ type APIClientProviderOptions = { /** * The name of the service that will be registered into the app. * * @default 'apiClient' */ serviceName?: string; /** * The name of the configuration setting that has the API information. * * @default 'api' */ configSetting?: string; /** * The class the service will instantiate. It has to extend {@link APIClient}. * * @default APIClient */ clientClass?: typeof APIClient; }; /** * The provider creator to register an instance of {@link APIClient} on the container. * * @example * * Basic usage * * // Register it on the container * container.register(apiClientProvider); * // Getting access to the service instance * const apiClient = container.get('apiClient'); * * @example * * With custom options * * container.register( * apiClientProvider({ * serviceName: 'myApiClient', * configSetting: 'myApi', * }), * ); * * @group Providers * @group Services/APIClient */ declare const apiClientProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: APIClientProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn>; export { APIClient, type APIClientConfig, type APIClientConstructorOptions, type APIClientProviderOptions, type APIClientSettings, type EndpointsType, apiClientProvider };