From 45ecb2834e4226db40a583bfe3015a4dfe7b3730 Mon Sep 17 00:00:00 2001 From: "Charles \"Demurgos\" Samborski" Date: Thu, 28 Apr 2016 22:07:14 +0200 Subject: [PATCH 1/4] Update type of CoreOptions.jar to fix issue #3 --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 956ffd1..239312c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -68,7 +68,7 @@ declare namespace request { interface CoreOptions { baseUrl?: string; callback?: (error: any, response: IncomingMessage, body: any) => void; - jar?: CookieJar; + jar?: boolean | CookieJar; formData?: any; // Object form?: any; // Object or string auth?: AuthOptions; From 81394e074f2a353d0e906d6d3cf9f693ccf82e82 Mon Sep 17 00:00:00 2001 From: "Charles \"Demurgos\" Samborski" Date: Thu, 28 Apr 2016 22:15:52 +0200 Subject: [PATCH 2/4] Lint definitions --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 239312c..9d5ab7e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,8 @@ import {Stream} from 'stream'; import {Agent, ClientRequest, IncomingMessage} from 'http'; -import {Url} from 'url'; +// import {Url} from 'url'; import * as FormData from 'form-data'; -import * as toughCookie from "tough-cookie"; +import * as toughCookie from 'tough-cookie'; declare var request: request.RequestAPI; From c07ff63ce77ef70e8194ceacef172c64218730f9 Mon Sep 17 00:00:00 2001 From: "Charles \"Demurgos\" Samborski" Date: Thu, 28 Apr 2016 23:52:08 +0200 Subject: [PATCH 3/4] Fix CookieJar implementation (request's CookieJar is a synchronous wrapper for tough-cookie's CookieJar) --- index.d.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9d5ab7e..3a917e2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,5 @@ import {Stream} from 'stream'; import {Agent, ClientRequest, IncomingMessage} from 'http'; -// import {Url} from 'url'; import * as FormData from 'form-data'; import * as toughCookie from 'tough-cookie'; @@ -227,8 +226,39 @@ declare namespace request { bucket?: string; } - export type CookieJar = toughCookie.CookieJar; + /** + * Cookies + */ + // Request wraps the `tough-cookies`'s CookieJar in a synchronous RequestJar + // https://github.com/request/request/blob/master/lib/cookies.js export type Cookie = toughCookie.Cookie; + export type CookieStore = toughCookie.Store; + export type SetCookieOptions = toughCookie.SetCookieOptions; + + export class CookieJar { + /** + * @param store defaults to toughCookie.MemoryCookieStore + */ + constructor (store?: CookieStore); + + // RequestJar.prototype.setCookie = function(cookieOrStr, uri, options) { + // var self = this + // return self._jar.setCookieSync(cookieOrStr, uri, options || {}) + // } + setCookie(cookieOrString: Cookie | string, uri: string, options?: SetCookieOptions): Cookie; + + // RequestJar.prototype.getCookieString = function(uri) { + // var self = this + // return self._jar.getCookieStringSync(uri) + // } + getCookieString(uri: string): string; + + // RequestJar.prototype.getCookies = function(uri) { + // var self = this + // return self._jar.getCookiesSync(uri) + // } + getCookies(uri: string): Cookie[]; + } } export = request; From 40b15161789b5bf21612339f3ab93fcf62100b2b Mon Sep 17 00:00:00 2001 From: "Charles \"Demurgos\" Samborski" Date: Thu, 28 Apr 2016 23:58:29 +0200 Subject: [PATCH 4/4] Use interface instead of class for CookieJar --- index.d.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3a917e2..d399e82 100644 --- a/index.d.ts +++ b/index.d.ts @@ -235,12 +235,7 @@ declare namespace request { export type CookieStore = toughCookie.Store; export type SetCookieOptions = toughCookie.SetCookieOptions; - export class CookieJar { - /** - * @param store defaults to toughCookie.MemoryCookieStore - */ - constructor (store?: CookieStore); - + export interface CookieJar { // RequestJar.prototype.setCookie = function(cookieOrStr, uri, options) { // var self = this // return self._jar.setCookieSync(cookieOrStr, uri, options || {})