UNPKG

@altostra/core

Version:

Core library for shared types and logic

52 lines (51 loc) 2.29 kB
import type { NaturalNumber } from "../../common/CustomTypes/Numerics"; import { UserFacingError } from "../../common/Errors"; import type { Logger, OperationLoggingSeverity } from "../../common/Logging"; import type { ValidationRejection } from '@altostra/type-validations'; import type { AxiosInstance, AxiosRequestConfig } from 'axios'; import type { Maybe } from "../../common/Maybe"; import type { AnonymousTokenGetter } from "./ServiceClientBase"; export declare type ErrorFactory = (data: unknown, rejections: ValidationRejection[]) => unknown; export declare type ClientType = 'cli' | 'other'; export declare function createServiceErrorFactory(serviceName: string, clientType?: ClientType): ErrorFactory; export declare const bossResponseError: ErrorFactory; export declare const integrationServiceResponseError: ErrorFactory; export declare const importServiceErrorFactory: ErrorFactory; export interface ServiceEndpoints { backoffice: string; compiler: string; integrations: string; } export interface ServiceClientConfig { runWithLimit: NaturalNumber; } export interface ServiceClientOptions { endpoints?: ServiceEndpoints; getToken: Maybe<AnonymousTokenGetter>; serviceName?: string; axios?: AxiosInstance; logger?: Logger<OperationLoggingSeverity>; config?: ServiceClientConfig; /** * An array of strings that would be sent the the server to signal that a certain * feature is supported for the current call. * * This allow using "breaking" features by exposing them only for calls that contain * certain features */ supportedFeatures?: string[]; errorMapping?: ErrorMapping; } export interface Pagination { page?: NaturalNumber | 0; 'page-size'?: NaturalNumber; } export declare function paginate(pagination?: Pagination, requestOptions?: AxiosRequestConfig): AxiosRequestConfig; export declare function isValidPage(page: number): page is (NaturalNumber | 0); export declare const RUN_WITH_LIMIT: NaturalNumber; export declare const SUPPORTED_FEATURES_HEADER = "x-altostra-support"; export interface IdentityToken { token: string; team?: string; } export declare type ErrorMapping = Record<string, string | ((err: UserFacingError) => Error | Promise<Error | string> | string)>;