Bin
2025-12-17 2b99d77d73ba568beff0a549534017caaad8a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { ApiResponse, WrappedResponse } from "../api-proxy/types";
import type { APIProxy } from "../api-proxy";
 
export interface ApiCallOptions {
  params?: Record<string, unknown>;
  suppressError?: boolean;
  errorFilter?: (response: ApiResponse) => boolean;
  headers?: Record<string, string>;
  signal?: AbortSignal;
  body?: FormData | URLSearchParams | Record<string, unknown>;
}
 
export interface FormattedError {
  title: string;
  message: string;
  stacktrace?: string;
  version?: string;
  validation: [string, string[]][];
  isShutdown: boolean;
}
 
export interface ApiContextType {
  api: APIProxy<Record<string, unknown>>;
  callApi: <T>(method: string, options?: ApiCallOptions) => Promise<WrappedResponse<T> | null>;
  handleError: (response: Response | ApiResponse, options?: ErrorHandlerOptions) => Promise<boolean>;
  resetError: () => void;
  error: ApiResponse | null;
  showGlobalError: boolean;
  errorFormatter: (result: ApiResponse) => FormattedError;
  isValidMethod: (name: string) => boolean;
}
 
export interface ErrorHandlerOptions {
  showGlobalError?: boolean;
  customHandler?: (error: FormattedError, response: ApiResponse) => void;
}
 
export interface ApiProviderConfig {
  gateway: string;
  endpoints: Record<string, unknown>;
  commonHeaders?: Record<string, string>;
  onRequestFinished?: (res: Response) => void;
  alwaysExpectJSON?: boolean;
  sharedParams?: Record<string, unknown>;
  mockDelay?: number;
  mockDisabled?: boolean;
}