index.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import * as tough from 'tough-cookie';
  2. interface GenericRequest {
  3. url: string;
  4. }
  5. interface URLLike {
  6. href: string;
  7. }
  8. declare type GenericRequestInfo = string | URLLike | GenericRequest;
  9. interface GenericRequestInit {
  10. method?: string;
  11. redirect?: string;
  12. body?: any;
  13. referrerPolicy?: string;
  14. }
  15. interface GenericResponse {
  16. url: string;
  17. status: number;
  18. headers: {
  19. get: (name: string) => string | null;
  20. has: (name: string) => boolean;
  21. };
  22. }
  23. declare type FetchCookieInit<T extends GenericRequestInit> = T & {
  24. maxRedirect?: number;
  25. redirectCount?: number;
  26. };
  27. declare type GenericFetch<T1 extends GenericRequestInfo, T2 extends GenericRequestInit, T3> = (input: T1, init?: T2) => Promise<T3>;
  28. interface FetchCookieImpl<T1 extends GenericRequestInfo, T2 extends GenericRequestInit, T3> {
  29. (input: T1, init?: FetchCookieInit<T2>): Promise<T3>;
  30. toughCookie: typeof tough;
  31. }
  32. export interface CookieJar {
  33. getCookieString: (currentUrl: string) => Promise<string>;
  34. setCookie: (cookieString: string, currentUrl: string, opts: {
  35. ignoreError: boolean;
  36. }) => Promise<any>;
  37. }
  38. declare function fetchCookie<T1 extends GenericRequestInfo, T2 extends GenericRequestInit, T3 extends GenericResponse>(fetch: GenericFetch<T1, T2, T3>, jar?: CookieJar, ignoreError?: boolean): FetchCookieImpl<T1, T2, T3>;
  39. declare namespace fetchCookie {
  40. var toughCookie: typeof tough;
  41. }
  42. export default fetchCookie;