// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../core/resource'; import * as ConnectorsAPI from './connectors'; import { APIPromise } from '../core/api-promise'; import { buildHeaders } from '../internal/headers'; import { RequestOptions } from '../internal/request-options'; import { path } from '../internal/utils/path'; export class Connectors extends APIResource { /** * Get connector data. */ retrieve( connectorName: string, params: ConnectorRetrieveParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.get(path`/connectors/${connectorName}`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Get all connectors of the user. */ list( params: ConnectorListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.get('/connectors', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Connect to a connector, or reconnect it when its status is * `reauthorization_required`. Fails when the connector is already connected. */ connect( connectorName: string, params: ConnectorConnectParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post(path`/connectors/${connectorName}/connect`, { body, ...options, headers: buildHeaders([ { 'Content-Type': 'application/x-www-form-urlencoded', ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Disconnect from a connector. */ disconnect( connectorName: string, params: ConnectorDisconnectParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.post(path`/connectors/${connectorName}/disconnect`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * A user's connection state for a connector. */ export type ConnectorStatus = 'not_connected' | 'connected' | 'reauthorization_required'; /** * Response model for getting connector data. * * Attributes: user_identifier (str): The user identifier of the connector. * auth_string (str): The auth string of the connector. */ export interface ConnectorRetrieveResponse { auth_string: string; user_identifier: string; } /** * Response model for getting connectors. * * Attributes: connectors (list[ConnectorDataResponse]): List of connectors. */ export interface ConnectorListResponse { connectors: Array; } export namespace ConnectorListResponse { /** * Response model for getting connector item. * * Attributes: id (str): The ID of the connector. name (str): The name of the * connector. display_name (str): The display name of the connector. description * (str | None): The description of the connector. icon (str | None): The icon of * the connector. is_connected (bool): Whether the connector is connected and * usable. Deprecated, use `status`. status (ConnectorStatus): The connection * state, including whether the user must reconnect. user_identifier (str | None): * The user identifier of the connector. */ export interface Connector { id: string; display_name: string; /** * @deprecated Deprecated: use `status`. */ is_connected: boolean; name: string; description?: string | null; icon?: string | null; /** * A user's connection state for a connector. */ status?: ConnectorsAPI.ConnectorStatus; user_identifier?: string | null; } } /** * Response model for connecting to a connector. * * Attributes: redirect_url (str): The redirect URL for the connector. */ export interface ConnectorConnectResponse { redirect_url: string; } export type ConnectorDisconnectResponse = unknown; export interface ConnectorRetrieveParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConnectorListParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConnectorConnectParams { /** * Body param */ callback_url: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConnectorDisconnectParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export declare namespace Connectors { export { type ConnectorStatus as ConnectorStatus, type ConnectorRetrieveResponse as ConnectorRetrieveResponse, type ConnectorListResponse as ConnectorListResponse, type ConnectorConnectResponse as ConnectorConnectResponse, type ConnectorDisconnectResponse as ConnectorDisconnectResponse, type ConnectorRetrieveParams as ConnectorRetrieveParams, type ConnectorListParams as ConnectorListParams, type ConnectorConnectParams as ConnectorConnectParams, type ConnectorDisconnectParams as ConnectorDisconnectParams, }; }