Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
export type Endpoints = Record<string, EndpointConfig>;
 
export type RequestMethod = "GET" | "POST" | "PATCH" | "DELETE" | "PUT" | "HEAD" | "OPTIONS";
 
export type RequestMode = "same-origin" | "cors";
 
export type ResponseConverter = (response: any) => Promise<any>;
 
export type EndpointConfig =
  | string
  | {
      path: string;
      gateway?: string;
      method?: RequestMethod;
      scope?: Record<string, EndpointConfig>;
      params?: Record<string, string>;
      convert?: ResponseConverter;
      forceMock?: boolean;
      mock?: (url: string, params: Record<string, any>, request: Request) => Promise<Record<string, any>>;
      body?: Record<string, any>;
      headers?: Headers;
    };
 
export type APIProxyOptions<T extends {}> = {
  gateway: string | URL;
  endpoints: T;
  commonHeaders?: Record<string, string>;
  mockDelay?: number;
  mockDisabled?: boolean;
  sharedParams?: Record<string, any>;
  alwaysExpectJSON?: boolean;
  onRequestFinished?: (res: Response) => void;
};
 
export type ResponseMeta = {
  /**
   * Response headers
   */
  headers: Map<string, string>;
  /**
   * HTTP status
   */
  status: number;
  /**
   * Original requested URL
   */
  url: string;
  /**
   * Indicates if the request returned with 2xx status
   */
  ok: boolean;
};
 
export type WrappedResponse<T = unknown, ExtraMeta = {}> = T & {
  /**
   * Simplified error message
   */
  error?: string;
  /**
   * Holds an original server response. It might not match with T
   * signature, e.g. error data
   */
  response: Record<string, any>;
  /**
   * Additional data about the request and response
   */
  $meta: ResponseMeta & ExtraMeta;
};
 
export type ApiResponse = ApiError | Record<string, any>;
 
export type ApiError = ResponseError | ResponseServerError;
 
export type ResponseError = {
  status: number;
  error: string;
  response: string | Record<string, any>;
};
 
export type ResponseServerError = {
  error: string;
  details: string | Record<string, any>;
};