UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

70 lines (69 loc) 4.11 kB
import { ApiOptions } from '../../internal-common/src/public-types/api-client.public-types'; import { ApiEndpointId, HttpMethod } from '../../internal-common/src/public-types/api.public-types'; import { IntegrationId } from '../../internal-common/src/public-types/communication.public-types'; import { HttpResponse } from './squid-http-client'; /** * ApiClient facilitates making HTTP API requests to external integrations, * supporting various HTTP methods such as GET, POST, PUT, PATCH, and DELETE. * @category Platform */ export declare class ApiClient { private readonly rpcManager; /** * Sends a GET request to the specified integration endpoint. * * @param integrationId The integration to send the request to. * @param endpointId The API endpoint to call. * @param options Optional API request options (headers, query params, etc). * @returns A promise resolving to the HTTP response. */ get<ResponseBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>; /** * Sends a POST request to the specified integration endpoint. * * @param integrationId The integration to send the request to. * @param endpointId The API endpoint to call. * @param body Optional request body to send. * @param options Optional API request options (headers, query params, etc). * @returns A promise resolving to the HTTP response. */ post<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>; /** * Sends a DELETE request to the specified integration endpoint. * * @param integrationId The integration to send the request to. * @param endpointId The API endpoint to call. * @param body Optional request body to send. * @param options Optional API request options (headers, query params, etc). * @returns A promise resolving to the HTTP response. */ delete<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>; /** * Sends a PATCH request to the specified integration endpoint. * * @param integrationId The integration to send the request to. * @param endpointId The API endpoint to call. * @param body Optional request body to send. * @param options Optional API request options (headers, query params, etc). * @returns A promise resolving to the HTTP response. */ patch<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>; /** * Sends a PUT request to the specified integration endpoint. * * @param integrationId The integration to send the request to. * @param endpointId The API endpoint to call. * @param body Optional request body to send. * @param options Optional API request options (headers, query params, etc). * @returns A promise resolving to the HTTP response. */ put<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>; /** * Performs an HTTP API request to the given integration ID and endpoint ID. * The provided options will be merged with the default options. * In case of error (status code >= 400 or other error), the promise will be rejected with an RpcError. */ request<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions, method?: HttpMethod): Promise<HttpResponse<ResponseBodyType>>; private convertOptionsToStrings; private convertToStrings; }