UNPKG

@replit/connectors

Version:

The official TypeScript library for the Replit API

264 lines 18.8 kB
import type { RequestInit, RequestInfo } from "./internal/builtin-types.js"; import type { PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from "./internal/types.js"; export type { Logger, LogLevel } from "./internal/utils/log.js"; import * as Opts from "./internal/request-options.js"; import * as Errors from "./core/error.js"; import * as Pagination from "./core/pagination.js"; import { type OffsetPaginationParams, OffsetPaginationResponse } from "./core/pagination.js"; import * as Uploads from "./core/uploads.js"; import * as TopLevelAPI from "./resources/top-level.js"; import { AssignConnectionParams, AssignConnectionResponse, CheckConnectionResponse, Connector, ConnectorRpcParams, ConnectorRpcResponse, CreateConnectionParams, CreateConnectionResponse, CreateConnnectorConfigParams, CreateConnnectorConfigResponse, CreateTokenParams, CreateTokenResponse, DeleteAssignmentParams, DeleteAssignmentResponse, DeleteConnectionResponse, DeleteConnectorConfigResponse, GetConectorConfigParams, GetConectorConfigResponse, GetConnectionParams, GetConnectionResponse, GetCurrentUserResponse, Integration, ListAssignmentsResponse, ListConnectionsParams, ListConnectionsResponse, ListConnectionsResponsesOffsetPagination, ListConnectorConfigsParams, ListConnectorConfigsResponse, ListConnectorConfigsResponsesOffsetPagination, ListConnectorsParams, ListConnectorsResponse, ListConnectorsResponsesOffsetPagination, ListConnnectorConfigsParams, ListConnnectorConfigsResponse, ListConnnectorConfigsResponsesOffsetPagination, ListCustomersParams, ListCustomersResponse, ListCustomersResponsesOffsetPagination, ListEventsParams, ListEventsResponse, ListEventsResponsesOffsetPagination, PostConnectParams, PostConnectResponse, PreConfigureConnectorParams, PreConfigureConnectorResponse, PreConnectParams, PreConnectResponse, UpsertConnnectorConfigParams, UpsertConnnectorConfigResponse, UpsertCustomerParams, UpsertCustomerResponse, UpsertOrganizationParams, UpsertOrganizationResponse } from "./resources/top-level.js"; import { APIPromise } from "./core/api-promise.js"; import { type Fetch } from "./internal/builtin-types.js"; import { HeadersLike, NullableHeaders } from "./internal/headers.js"; import { FinalRequestOptions, RequestOptions } from "./internal/request-options.js"; import { type LogLevel, type Logger } from "./internal/utils/log.js"; export interface ClientOptions { /** * Defaults to process.env['OPENINT_API_KEY']. */ token?: string | null | undefined; /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * * Defaults to process.env['REPLIT_BASE_URL']. */ baseURL?: string | null | undefined; /** * The maximum amount of time (in milliseconds) that the client should wait for a response * from the server before timing out a single request. * * Note that request timeouts are retried by default, so in a worst-case scenario you may wait * much longer than this timeout before the promise succeeds or fails. * * @unit milliseconds */ timeout?: number | undefined; /** * Additional `RequestInit` options to be passed to `fetch` calls. * Properties will be overridden by per-request `fetchOptions`. */ fetchOptions?: MergedRequestInit | undefined; /** * Specify a custom `fetch` function implementation. * * If not provided, we expect that `fetch` is defined globally. */ fetch?: Fetch | undefined; /** * The maximum number of times that the client will retry a request in case of a * temporary failure, like a network error or a 5XX error from the server. * * @default 2 */ maxRetries?: number | undefined; /** * Default headers to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * header to `null` in request options. */ defaultHeaders?: HeadersLike | undefined; /** * Default query parameters to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * param to `undefined` in request options. */ defaultQuery?: Record<string, string | undefined> | undefined; /** * Set the log level. * * Defaults to process.env['REPLIT_LOG'] or 'warn' if it isn't set. */ logLevel?: LogLevel | undefined; /** * Set the logger. * * Defaults to globalThis.console. */ logger?: Logger | undefined; } /** * API Client for interfacing with the Replit API. */ export declare class Replit { #private; token: string | null; baseURL: string; maxRetries: number; timeout: number; logger: Logger | undefined; logLevel: LogLevel | undefined; fetchOptions: MergedRequestInit | undefined; private fetch; protected idempotencyHeader?: string; private _options; /** * API Client for interfacing with the Replit API. * * @param {string | null | undefined} [opts.token=process.env['OPENINT_API_KEY'] ?? null] * @param {string} [opts.baseURL=process.env['REPLIT_BASE_URL'] ?? https://connectors.replit.com] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls. * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API. */ constructor({ baseURL, token, ...opts }?: ClientOptions); /** * Create a new client instance re-using the same options given to the current client with optional overriding. */ withOptions(options: Partial<ClientOptions>): this; /** * Assign a connection to a customer */ assignConnection(replID: string, params: TopLevelAPI.AssignConnectionParams, options?: RequestOptions): APIPromise<TopLevelAPI.AssignConnectionResponse>; /** * Verify that a connection is healthy */ checkConnection(id: string, options?: RequestOptions): APIPromise<TopLevelAPI.CheckConnectionResponse>; /** * Execute RPC function on connector */ connectorRpc(functionName: string, params: TopLevelAPI.ConnectorRpcParams, options?: RequestOptions): APIPromise<TopLevelAPI.ConnectorRpcResponse>; /** * Import an existing connection after validation */ createConnection(body: TopLevelAPI.CreateConnectionParams, options?: RequestOptions): APIPromise<TopLevelAPI.CreateConnectionResponse>; createConnnectorConfig(body: TopLevelAPI.CreateConnnectorConfigParams, options?: RequestOptions): APIPromise<TopLevelAPI.CreateConnnectorConfigResponse>; /** * Create a @Connect authentication token for a customer. This token can be used to * embed @Connect in your application via the `@openint/connect` npm package. */ createToken(customerID: string, body: TopLevelAPI.CreateTokenParams, options?: RequestOptions): APIPromise<TopLevelAPI.CreateTokenResponse>; /** * Remove a repl assignment from a connection */ deleteAssignment(replID: string, params: TopLevelAPI.DeleteAssignmentParams, options?: RequestOptions): APIPromise<TopLevelAPI.DeleteAssignmentResponse>; /** * Delete a connection */ deleteConnection(id: string, options?: RequestOptions): APIPromise<TopLevelAPI.DeleteConnectionResponse>; deleteConnectorConfig(id: string, options?: RequestOptions): APIPromise<TopLevelAPI.DeleteConnectorConfigResponse>; getConectorConfig(id: string, query?: TopLevelAPI.GetConectorConfigParams | null | undefined, options?: RequestOptions): APIPromise<TopLevelAPI.GetConectorConfigResponse>; /** * Get details of a specific connection, including credentials */ getConnection(id: string, query?: TopLevelAPI.GetConnectionParams | null | undefined, options?: RequestOptions): APIPromise<TopLevelAPI.GetConnectionResponse>; /** * Get information about the current authenticated user */ getCurrentUser(options?: RequestOptions): APIPromise<TopLevelAPI.GetCurrentUserResponse>; /** * Get the list of assignments for a specific connection */ listAssignments(id: string, options?: RequestOptions): APIPromise<TopLevelAPI.ListAssignmentsResponse>; /** * List all connections with optional filtering. Does not retrieve secrets or * perform any connection healthcheck. For that use `getConnection` or * `checkConnectionHealth`. */ listConnections(query?: TopLevelAPI.ListConnectionsParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListConnectionsResponsesOffsetPagination, TopLevelAPI.ListConnectionsResponse>; /** * List Configured Connectors */ listConnectorConfigs(query?: TopLevelAPI.ListConnectorConfigsParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListConnectorConfigsResponsesOffsetPagination, TopLevelAPI.ListConnectorConfigsResponse>; /** * List all connectors to understand what integrations are available to configure */ listConnectors(query?: TopLevelAPI.ListConnectorsParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListConnectorsResponsesOffsetPagination, TopLevelAPI.ListConnectorsResponse>; /** * List Configured Connectors */ listConnnectorConfigs(query?: TopLevelAPI.ListConnnectorConfigsParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListConnnectorConfigsResponsesOffsetPagination, TopLevelAPI.ListConnnectorConfigsResponse>; /** * List all customers */ listCustomers(query?: TopLevelAPI.ListCustomersParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListCustomersResponsesOffsetPagination, TopLevelAPI.ListCustomersResponse>; /** * List all events for an organization */ listEvents(query?: TopLevelAPI.ListEventsParams | null | undefined, options?: RequestOptions): Pagination.PagePromise<ListEventsResponsesOffsetPagination, TopLevelAPI.ListEventsResponse>; postConnect(body: TopLevelAPI.PostConnectParams, options?: RequestOptions): APIPromise<TopLevelAPI.PostConnectResponse>; preConfigureConnector(body: TopLevelAPI.PreConfigureConnectorParams, options?: RequestOptions): APIPromise<TopLevelAPI.PreConfigureConnectorResponse>; preConnect(body: TopLevelAPI.PreConnectParams, options?: RequestOptions): APIPromise<TopLevelAPI.PreConnectResponse>; upsertConnnectorConfig(id: string, body: TopLevelAPI.UpsertConnnectorConfigParams, options?: RequestOptions): APIPromise<TopLevelAPI.UpsertConnnectorConfigResponse>; /** * Create or update a customer */ upsertCustomer(body: TopLevelAPI.UpsertCustomerParams, options?: RequestOptions): APIPromise<TopLevelAPI.UpsertCustomerResponse>; /** * Upsert an organization by ID. Creates if it does not exist. */ upsertOrganization(orgID: string, body: TopLevelAPI.UpsertOrganizationParams, options?: RequestOptions): APIPromise<TopLevelAPI.UpsertOrganizationResponse>; protected defaultQuery(): Record<string, string | undefined> | undefined; protected validateHeaders({ values, nulls }: NullableHeaders): void; protected authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined>; protected stringifyQuery(query: Record<string, unknown>): string; private getUserAgent; protected defaultIdempotencyKey(): string; protected makeStatusError(status: number, error: Object, message: string | undefined, headers: Headers): Errors.APIError; buildURL(path: string, query: Record<string, unknown> | null | undefined, defaultBaseURL?: string | undefined): string; /** * Used as a callback for mutating the given `FinalRequestOptions` object. */ protected prepareOptions(options: FinalRequestOptions): Promise<void>; /** * Used as a callback for mutating the given `RequestInit` object. * * This is useful for cases where you want to add certain headers based off of * the request properties, e.g. `method` or `url`. */ protected prepareRequest(request: RequestInit, { url, options }: { url: string; options: FinalRequestOptions; }): Promise<void>; get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>; post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>; patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>; put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>; delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>; private methodRequest; request<Rsp>(options: PromiseOrValue<FinalRequestOptions>, remainingRetries?: number | null): APIPromise<Rsp>; private makeRequest; getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(path: string, Page: new (...args: any[]) => PageClass, opts?: RequestOptions): Pagination.PagePromise<PageClass, Item>; requestAPIList<Item = unknown, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass, options: FinalRequestOptions): Pagination.PagePromise<PageClass, Item>; fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise<Response>; private shouldRetry; private retryRequest; private calculateDefaultRetryTimeoutMillis; buildRequest(inputOptions: FinalRequestOptions, { retryCount }?: { retryCount?: number; }): Promise<{ req: FinalizedRequestInit; url: string; timeout: number; }>; private buildHeaders; private buildBody; static Replit: typeof Replit; static DEFAULT_TIMEOUT: number; static ReplitError: typeof Errors.ReplitError; static APIError: typeof Errors.APIError; static APIConnectionError: typeof Errors.APIConnectionError; static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError; static APIUserAbortError: typeof Errors.APIUserAbortError; static NotFoundError: typeof Errors.NotFoundError; static ConflictError: typeof Errors.ConflictError; static RateLimitError: typeof Errors.RateLimitError; static BadRequestError: typeof Errors.BadRequestError; static AuthenticationError: typeof Errors.AuthenticationError; static InternalServerError: typeof Errors.InternalServerError; static PermissionDeniedError: typeof Errors.PermissionDeniedError; static UnprocessableEntityError: typeof Errors.UnprocessableEntityError; static toFile: typeof Uploads.toFile; } export declare namespace Replit { export type RequestOptions = Opts.RequestOptions; export import OffsetPagination = Pagination.OffsetPagination; export { type OffsetPaginationParams as OffsetPaginationParams, type OffsetPaginationResponse as OffsetPaginationResponse, }; export { type Connector as Connector, type Integration as Integration, type AssignConnectionResponse as AssignConnectionResponse, type CheckConnectionResponse as CheckConnectionResponse, type ConnectorRpcResponse as ConnectorRpcResponse, type CreateConnectionResponse as CreateConnectionResponse, type CreateConnnectorConfigResponse as CreateConnnectorConfigResponse, type CreateTokenResponse as CreateTokenResponse, type DeleteAssignmentResponse as DeleteAssignmentResponse, type DeleteConnectionResponse as DeleteConnectionResponse, type DeleteConnectorConfigResponse as DeleteConnectorConfigResponse, type GetConectorConfigResponse as GetConectorConfigResponse, type GetConnectionResponse as GetConnectionResponse, type GetCurrentUserResponse as GetCurrentUserResponse, type ListAssignmentsResponse as ListAssignmentsResponse, type ListConnectionsResponse as ListConnectionsResponse, type ListConnectorConfigsResponse as ListConnectorConfigsResponse, type ListConnectorsResponse as ListConnectorsResponse, type ListConnnectorConfigsResponse as ListConnnectorConfigsResponse, type ListCustomersResponse as ListCustomersResponse, type ListEventsResponse as ListEventsResponse, type PostConnectResponse as PostConnectResponse, type PreConfigureConnectorResponse as PreConfigureConnectorResponse, type PreConnectResponse as PreConnectResponse, type UpsertConnnectorConfigResponse as UpsertConnnectorConfigResponse, type UpsertCustomerResponse as UpsertCustomerResponse, type UpsertOrganizationResponse as UpsertOrganizationResponse, type ListConnectionsResponsesOffsetPagination as ListConnectionsResponsesOffsetPagination, type ListConnectorConfigsResponsesOffsetPagination as ListConnectorConfigsResponsesOffsetPagination, type ListConnectorsResponsesOffsetPagination as ListConnectorsResponsesOffsetPagination, type ListConnnectorConfigsResponsesOffsetPagination as ListConnnectorConfigsResponsesOffsetPagination, type ListCustomersResponsesOffsetPagination as ListCustomersResponsesOffsetPagination, type ListEventsResponsesOffsetPagination as ListEventsResponsesOffsetPagination, type AssignConnectionParams as AssignConnectionParams, type ConnectorRpcParams as ConnectorRpcParams, type CreateConnectionParams as CreateConnectionParams, type CreateConnnectorConfigParams as CreateConnnectorConfigParams, type CreateTokenParams as CreateTokenParams, type DeleteAssignmentParams as DeleteAssignmentParams, type GetConectorConfigParams as GetConectorConfigParams, type GetConnectionParams as GetConnectionParams, type ListConnectionsParams as ListConnectionsParams, type ListConnectorConfigsParams as ListConnectorConfigsParams, type ListConnectorsParams as ListConnectorsParams, type ListConnnectorConfigsParams as ListConnnectorConfigsParams, type ListCustomersParams as ListCustomersParams, type ListEventsParams as ListEventsParams, type PostConnectParams as PostConnectParams, type PreConfigureConnectorParams as PreConfigureConnectorParams, type PreConnectParams as PreConnectParams, type UpsertConnnectorConfigParams as UpsertConnnectorConfigParams, type UpsertCustomerParams as UpsertCustomerParams, type UpsertOrganizationParams as UpsertOrganizationParams, }; } //# sourceMappingURL=client.d.ts.map