1 | import { AxiosHeaderValue, AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios';
|
2 | import type { AxiosInstance as OriginalAxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
3 | export type DefaultOptions = AxiosRequestConfig & {
|
4 | logHandler: (level: string, data?: Error | string) => void;
|
5 | responseLogger?: (response: AxiosResponse<any> | Error) => unknown;
|
6 | requestLogger?: (request: AxiosRequestConfig | Error) => unknown;
|
7 | retryOnError?: boolean;
|
8 | };
|
9 | export type AxiosInstance = OriginalAxiosInstance & {
|
10 | httpClientParams: CreateHttpClientParams;
|
11 | cloneWithNewParams: (params: Partial<CreateHttpClientParams>) => AxiosInstance;
|
12 | defaults: DefaultOptions;
|
13 | };
|
14 | export type CreateHttpClientParams = {
|
15 |
|
16 | accessToken: string | (() => Promise<string>);
|
17 | /** Space ID */
|
18 | space?: string;
|
19 | /**
|
20 | * Requests will be made over http instead of the default https
|
21 | * @default false
|
22 | */
|
23 | insecure?: boolean;
|
24 | /**
|
25 | * API host
|
26 | */
|
27 | host?: string;
|
28 | /** HTTP agent for node */
|
29 | httpAgent?: AxiosRequestConfig['httpAgent'];
|
30 | /** HTTPS agent for node */
|
31 | httpsAgent?: AxiosRequestConfig['httpsAgent'];
|
32 | /** Axios adapter to handle requests */
|
33 | adapter?: AxiosRequestConfig['adapter'];
|
34 | /** Axios proxy config */
|
35 | proxy?: AxiosRequestConfig['proxy'];
|
36 | /** Gets called on every request triggered by the SDK, takes the axios request config as an argument */
|
37 | requestLogger?: DefaultOptions['requestLogger'];
|
38 | /** Gets called on every response, takes axios response object as an argument */
|
39 | responseLogger?: DefaultOptions['responseLogger'];
|
40 | /** Request interceptor */
|
41 | onBeforeRequest?: (value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
|
42 |
|
43 | onError?: (error: any) => any;
|
44 |
|
45 | logHandler?: DefaultOptions['logHandler'];
|
46 |
|
47 | headers?: AxiosRequestHeaders | Record<string, AxiosHeaderValue>;
|
48 | defaultHostname?: string;
|
49 | |
50 |
|
51 |
|
52 |
|
53 | retryOnError?: boolean;
|
54 | |
55 |
|
56 |
|
57 |
|
58 | retryLimit?: number;
|
59 | |
60 |
|
61 |
|
62 |
|
63 | timeout?: number;
|
64 | basePath?: string;
|
65 | baseURL?: string;
|
66 | |
67 |
|
68 |
|
69 |
|
70 | maxContentLength?: number;
|
71 | |
72 |
|
73 |
|
74 |
|
75 | maxBodyLength?: number;
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | throttle?: 'auto' | string | number;
|
83 | |
84 |
|
85 |
|
86 |
|
87 | attempt?: number;
|
88 | };
|
89 | export type ContentfulErrorData = {
|
90 | status?: number;
|
91 | statusText?: string;
|
92 | requestId?: string;
|
93 | message: string;
|
94 | details: Record<string, any>;
|
95 | request?: Record<string, any>;
|
96 | sys?: {
|
97 | id?: string;
|
98 | };
|
99 | };
|