UNPKG

@crowdin/crowdin-api-client

Version:
213 lines (212 loc) 6.44 kB
import { HttpClientError } from './http-client-error'; import { RetryConfig, RetryService } from './internal/retry'; /** * @internal */ export interface HttpClient { get<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; delete<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; head<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; post<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; put<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; patch<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; } export type HttpClientType = 'axios' | 'fetch'; /** * Authorization credentials */ export interface Credentials { /** Personal Access Token */ token: string; /** Yor Crowdin Enterprise organization name */ organization?: string; /** API base URL */ baseUrl?: string; } /** * Client Configuration */ export interface ClientConfig { /** The type of HTTP client to be used for making requests */ httpClientType?: HttpClientType; /** Instance of your HTTP client if needed */ httpClient?: HttpClient; /** Custom User-Agent to be passed to the `User-Agent` header */ userAgent?: string; /** Custom User-Agent to be passed to the `X-Crowdin-Integrations-User-Agent` header */ integrationUserAgent?: string; /** Retry strategy configuration */ retryConfig?: RetryConfig; /** Http request timeout in ms */ httpRequestTimeout?: number; } export interface ResponseList<T> { data: ResponseObject<T>[]; pagination: Pagination; } export interface ResponseObject<T> { data: T; } export interface Pagination { offset: number; limit: number; } export type PaginationOptions = Partial<Pagination>; /** * A JSON Patch document as defined by [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902#section-3) */ export interface PatchRequest { /** Patch value */ value?: any; /** Patch operation to perform */ op: PatchOperation; /** A JSON Pointer as defined by [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901) */ path: string; } export type PatchOperation = 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test'; export type ProjectRoles = 'manager' | 'developer' | 'translator' | 'proofreader' | 'language_coordinator' | 'member'; export interface DownloadLink { url: string; expireIn: string; } /** * @internal */ export declare enum BooleanInt { TRUE = 1, FALSE = 0 } export interface Status<T> { identifier: string; status: string; progress: number; attributes: T; createdAt: string; updatedAt: string; startedAt: string; finishedAt: string; eta: string; } export interface Attribute { [key: string]: string; } export type PlainObject = Record<string, any>; /** * @internal */ export declare class CrowdinError extends Error { apiError: any; code: number; constructor(message: string, code: number, apiError: any); } /** * @internal */ export declare class CrowdinValidationError extends CrowdinError { validationCodes: { key: string; codes: string[]; }[]; constructor(message: string, validationCodes: { key: string; codes: string[]; }[], apiError: any); } /** * @internal */ export declare function handleHttpClientError(error: HttpClientError): never; export declare abstract class CrowdinApi { private static readonly CROWDIN_URL_SUFFIX; private static readonly AXIOS_INSTANCE; private static readonly FETCH_INSTANCE; /** @internal */ readonly token: string; /** @internal */ readonly organization?: string; /** @internal */ readonly url: string; /** @internal */ readonly config: ClientConfig | undefined; /** @internal */ readonly retryService: RetryService; protected fetchAllFlag: boolean; protected maxLimit: number | undefined; /** * @param credentials credentials * @param config optional configuration of the client */ constructor(credentials: Credentials, config?: ClientConfig); graphql<T>(req: { query: string; operationName?: string; variables?: any; }, config?: { url?: string; }): Promise<ResponseObject<T>>; protected addQueryParam(url: string, name: string, value?: string | number): string; protected defaultConfig(): { headers: Record<string, string>; }; /** @internal */ get httpClient(): HttpClient; withFetchAll(maxLimit?: number): this; protected getList<T = any>(url: string, limit?: number, offset?: number, config?: { headers: Record<string, string>; }): Promise<ResponseList<T>>; protected fetchAll<T>(url: string, config: { headers: Record<string, string>; }, maxAmount?: number): Promise<ResponseList<T>>; protected encodeUrlParam(param: string | number | boolean): string; protected get<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; protected delete<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; protected head<T>(url: string, config?: { headers: Record<string, string>; }): Promise<T>; protected post<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; protected put<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; protected patch<T>(url: string, data?: unknown, config?: { headers: Record<string, string>; }): Promise<T>; } /** * @internal */ export declare function isOptionalString(parameter: string | unknown, parameterInArgs: boolean): parameter is string | undefined; /** * @internal */ export declare function isOptionalNumber(parameter: number | unknown, parameterInArgs: boolean): parameter is number | undefined; export interface ProjectRole { name: string; permissions: ProjectRolePermissions; } export interface ProjectRolePermissions { allLanguages: boolean; languagesAccess: { [lang: string]: { allContent: boolean; workflowStepIds: number[]; }; }; }