UNPKG

@mondaydotcomorg/api

Version:

monday.com API client

80 lines (79 loc) 3.97 kB
import { ClientError } from 'graphql-request'; import { QueryVariables } from './constants/index'; import { Sdk } from './generated/sdk'; import { GraphQLClientResponse, RequestConfig } from 'graphql-request/build/esm/types'; export { ClientError }; export interface ApiClientConfig { token: string; apiVersion?: string; requestConfig?: RequestConfig; } export interface RequestOptions { versionOverride?: string; } /** * The `ApiClient` class provides a structured way to interact with the Monday.com API, * handling GraphQL requests with configurable API versioning. * * This class is designed to be initialized with an authentication token and an optional * API version, setting up the necessary headers for all subsequent API requests. */ export declare class ApiClient { private readonly token; private readonly defaultApiVersion; private readonly requestConfig?; readonly operations: Sdk; /** * Constructs a new `ApiClient` instance, storing configuration for dynamic client creation. * * @param {ApiClientConfig} config - Configuration for the API client. * Requires `token`, and optionally includes `apiVersion` and `requestConfig`. */ constructor(config: ApiClientConfig); /** * Creates a GraphQL client with the specified options * * @param {RequestOptions} [options] - Optional request configuration * @returns {GraphQLClient} - Configured GraphQL client */ private createClient; /** * Performs a GraphQL query or mutation to the Monday.com API using a dynamically created * GraphQL client. This method is asynchronous and returns a promise that resolves * with the query result. * * @param {string} query - The GraphQL query or mutation string. * @param {QueryVariables} [variables] - An optional object containing variables for the query. * `QueryVariables` is a type alias for `Record<string, any>`, allowing specification * of key-value pairs where the value can be any type. This parameter is used to provide * dynamic values in the query or mutation. * @param {RequestOptions} [options] - Optional request configuration including version override. * @returns {Promise<T>} A promise that resolves with the result of the query or mutation. * @template T The expected type of the query or mutation result. */ request: <T>(query: string, variables?: QueryVariables, options?: RequestOptions) => Promise<T>; /** * Performs a raw GraphQL query or mutation to the Monday.com API using a dynamically created * GraphQL client. This method is asynchronous and returns a promise that resolves * with the query result. * * The result will be in the raw format: data, errors, extensions. * * @param {string} query - The GraphQL query or mutation string. * @param {QueryVariables} [variables] - An optional object containing variables for the query. * `QueryVariables` is a type alias for `Record<string, any>`, allowing specification * of key-value pairs where the value can be any type. This parameter is used to provide * dynamic values in the query or mutation. * @param {RequestOptions} [options] - Optional request configuration including version override. * @returns {Promise<T>} A promise that resolves with the result of the query or mutation. * @template T The expected type of the query or mutation result. */ rawRequest: <T>(query: string, variables?: QueryVariables, options?: RequestOptions) => Promise<GraphQLClientResponse<T>>; /** * Validates the API version format (yyyy-mm), restricting mm to 01, 04, 07, or 10. * * @param {string} version - The API version string to validate. * @returns {boolean} - Returns true if the version matches yyyy-mm format with allowed months. */ private isValidApiVersion; }