index.d.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. export type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE";
  2. export type Version = "HTTP/1.0" | "HTTP/1.1" | "HTTP/2.0" | "HTTP/3.0";
  3. export type StatusCode = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
  4. export type FormDataValue = {
  5. kind: "text";
  6. value: string;
  7. } | {
  8. kind: "file";
  9. filename: string;
  10. contentType: string;
  11. data: Uint8Array;
  12. };
  13. export type FormData = Map<string, FormDataValue[]>;
  14. export declare enum MediaType {
  15. TEXT_PLAIN = "text/plain",
  16. TEXT_HTML = "text/html",
  17. TEXT_CSS = "text/css",
  18. TEXT_CSV = "text/csv",
  19. APPLICATION_JSON = "application/json",
  20. APPLICATION_LD_JSON = "application/ld+json",
  21. APPLICATION_XML = "application/xml",
  22. TEXT_XML = "text/xml",
  23. APPLICATION_FORM = "application/x-www-form-urlencoded",
  24. APPLICATION_OCTET = "application/octet-stream",
  25. MULTIPART_FORM = "multipart/form-data"
  26. }
  27. export type ContentType = {
  28. kind: "text";
  29. content: string;
  30. mediaType: MediaType.TEXT_PLAIN | MediaType.TEXT_HTML | MediaType.TEXT_CSS | MediaType.TEXT_CSV;
  31. } | {
  32. kind: "json";
  33. content: unknown;
  34. mediaType: MediaType.APPLICATION_JSON | MediaType.APPLICATION_LD_JSON;
  35. } | {
  36. kind: "xml";
  37. content: string;
  38. mediaType: MediaType.APPLICATION_XML | MediaType.TEXT_XML;
  39. } | {
  40. kind: "form";
  41. content: FormData;
  42. mediaType: MediaType.APPLICATION_FORM;
  43. } | {
  44. kind: "binary";
  45. content: Uint8Array;
  46. mediaType: MediaType.APPLICATION_OCTET | string;
  47. filename?: string;
  48. } | {
  49. kind: "multipart";
  50. content: FormData;
  51. mediaType: MediaType.MULTIPART_FORM;
  52. } | {
  53. kind: "urlencoded";
  54. content: string;
  55. mediaType: MediaType.APPLICATION_FORM;
  56. } | {
  57. kind: "stream";
  58. content: ReadableStream;
  59. mediaType: string;
  60. };
  61. export interface ResponseBody {
  62. body: Uint8Array;
  63. mediaType: MediaType | string;
  64. }
  65. export type AuthType = {
  66. kind: "none";
  67. } | {
  68. kind: "basic";
  69. username: string;
  70. password: string;
  71. } | {
  72. kind: "bearer";
  73. token: string;
  74. } | {
  75. kind: "digest";
  76. username: string;
  77. password: string;
  78. realm?: string;
  79. nonce?: string;
  80. opaque?: string;
  81. algorithm?: "MD5" | "SHA-256" | "SHA-512";
  82. qop?: "auth" | "auth-int";
  83. nc?: string;
  84. cnonce?: string;
  85. } | {
  86. kind: "oauth2";
  87. grantType: {
  88. kind: "authorization_code";
  89. authEndpoint: string;
  90. tokenEndpoint: string;
  91. clientId: string;
  92. clientSecret?: string;
  93. } | {
  94. kind: "client_credentials";
  95. tokenEndpoint: string;
  96. clientId: string;
  97. clientSecret?: string;
  98. } | {
  99. kind: "password";
  100. tokenEndpoint: string;
  101. username: string;
  102. password: string;
  103. } | {
  104. kind: "implicit";
  105. authEndpoint: string;
  106. clientId: string;
  107. };
  108. accessToken?: string;
  109. refreshToken?: string;
  110. };
  111. export type CertificateType = {
  112. kind: "pem";
  113. cert: Uint8Array;
  114. key: Uint8Array;
  115. } | {
  116. kind: "pfx";
  117. data: Uint8Array;
  118. password: string;
  119. };
  120. export interface Request {
  121. id: number;
  122. url: string;
  123. method: Method;
  124. version: Version;
  125. headers?: Record<string, string>;
  126. params?: Record<string, string>;
  127. content?: ContentType;
  128. auth?: AuthType;
  129. security?: {
  130. certificates?: {
  131. client?: CertificateType;
  132. ca?: Array<Uint8Array>;
  133. };
  134. validateCertificates?: boolean;
  135. verifyHost?: boolean;
  136. verifyPeer?: boolean;
  137. };
  138. proxy?: {
  139. url: string;
  140. auth?: {
  141. username: string;
  142. password: string;
  143. };
  144. };
  145. }
  146. export interface Response {
  147. id: number;
  148. status: StatusCode;
  149. statusText: string;
  150. version: Version;
  151. headers: Record<string, string>;
  152. cookies?: Array<{
  153. name: string;
  154. value: string;
  155. domain?: string;
  156. path?: string;
  157. expires?: Date;
  158. secure?: boolean;
  159. httpOnly?: boolean;
  160. sameSite?: 'Strict' | 'Lax' | 'None';
  161. }>;
  162. body: ResponseBody;
  163. meta: {
  164. timing: {
  165. start: number;
  166. end: number;
  167. };
  168. size: {
  169. headers: number;
  170. body: number;
  171. total: number;
  172. };
  173. };
  174. }
  175. export type UnsupportedFeatureError = {
  176. kind: "unsupported_feature";
  177. feature: string;
  178. message: string;
  179. relay: string;
  180. };
  181. export type RelayError = UnsupportedFeatureError | {
  182. kind: "network";
  183. message: string;
  184. cause?: unknown;
  185. } | {
  186. kind: "timeout";
  187. message: string;
  188. phase?: "connect" | "tls" | "response";
  189. } | {
  190. kind: "certificate";
  191. message: string;
  192. cause?: unknown;
  193. } | {
  194. kind: "parse";
  195. message: string;
  196. cause?: unknown;
  197. } | {
  198. kind: "abort";
  199. message: string;
  200. };
  201. export type RequestResult = {
  202. kind: 'success';
  203. response: Response;
  204. } | {
  205. kind: 'error';
  206. error: RelayError;
  207. };
  208. export declare function execute(request: Request): Promise<RequestResult>;
  209. export declare function cancel(requestId: number): Promise<void>;
  210. //# sourceMappingURL=index.d.ts.map