first commit

This commit is contained in:
2026-04-09 13:05:27 +02:00
commit 3bbd7d6413
3084 changed files with 84284 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
2.1.1 / 2015-02-12
==================
* Preserve header casing
2.1.0 / 2015-01-21
==================
* Add retry, maxRedirects and timeout
2.0.3 / 2015-01-21
==================
* Add a "dist" folder with prebuilt clients for browsers
2.0.1 / 2015-01-14
==================
* Add support for 303 See Other redirects
1.1.0 / 2014-12-18
==================
* Support not following redirects
1.0.5 / 2014-12-18
==================
* Update dependencies
1.0.4 / 2014-09-29
==================
* Update promise to 6.0.0 ([@ForbesLindesay](https://github.com/ForbesLindesay))
1.0.3 / 2014-09-09
==================
* Update qs to 2.2.3 ([@ForbesLindesay](https://github.com/ForbesLindesay))
1.0.2 / 2014-09-09
==================
* Add content-length header ([@ForbesLindesay](https://github.com/ForbesLindesay))
1.0.1 / 2014-08-07
==================
* Update dependencies ([@ForbesLindesay](https://github.com/ForbesLindesay))
1.0.0 / 2014-08-01
==================
* Completely new API ([@ForbesLindesay](https://github.com/ForbesLindesay))
* Gzip support ([@ForbesLindesay](https://github.com/ForbesLindesay))
* Caching support ([@ForbesLindesay](https://github.com/ForbesLindesay))
* Redirects support ([@ForbesLindesay](https://github.com/ForbesLindesay))
* Documentation ([@ForbesLindesay](https://github.com/ForbesLindesay))
0.0.4 / 2014-04-02
==================
* Fix for empty responses ([@ForbesLindesay](https://github.com/ForbesLindesay))
0.0.3 / 2014-04-02
==================
* Fix for empty responses ([@ForbesLindesay](https://github.com/ForbesLindesay))
0.0.2 / 2014-04-01
==================
* Fix dependencies ([@Volox](https://github.com/Volox))
* Update readme ([@Volox](https://github.com/Volox))
0.0.1 / 2014-02-10
==================
* Initial release ([@ForbesLindesay](https://github.com/ForbesLindesay))

View File

@@ -0,0 +1,19 @@
Copyright (c) 2014 Forbes Lindesay
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,135 @@
# then-request
A request library that returns promises and supports both browsers and node.js
[![Build Status](https://img.shields.io/travis/then/then-request/master.svg)](https://travis-ci.org/then/then-request)
[![Dependency Status](https://img.shields.io/david/then/then-request.svg)](https://david-dm.org/then/then-request)
[![NPM version](https://img.shields.io/npm/v/then-request.svg)](https://www.npmjs.org/package/then-request)
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/gg9sZwctSLxyov1sJwW6pfyS/then/then-request'>
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/gg9sZwctSLxyov1sJwW6pfyS/then/then-request.svg' />
</a>
## Installation
npm install then-request
## Usage
`request(method, url, options, callback?)`
The following examples all work on both client and server.
```js
var request = require('then-request');
request('GET', 'http://example.com').done(function (res) {
console.log(res.getBody());
});
request('POST', 'http://example.com/json-api', {json: {some: 'values'}}).getBody('utf8').then(JSON.parse).done(function (res) {
console.log(res);
});
var FormData = request.FormData;
var data = new FormData();
data.append('some', 'values');
request('POST', 'http://example.com/form-api', {form: data}).done(function (res) {
console.log(res.getBody());
});
```
Or with ES6
```js
import request, {FormData} from 'then-request';
request('GET', 'http://example.com').done((res) => {
console.log(res.getBody());
});
request('POST', 'http://example.com/json-api', {json: {some: 'values'}}).getBody('utf8').then(JSON.parse).done((res) => {
console.log(res);
});
var FormData = request.FormData;
var data = new FormData();
data.append('some', 'values');
request('POST', 'http://example.com/form-api', {form: data}).done((res) => {
console.log(res.getBody());
});
```
**Method:**
An HTTP method (e.g. `GET`, `POST`, `PUT`, `DELETE` or `HEAD`). It is not case sensitive.
**URL:**
A url as a string (e.g. `http://example.com`). Relative URLs are allowed in the browser.
**Options:**
- `qs` - an object containing querystring values to be appended to the uri
- `headers` - http headers (default: `{}`)
- `body` - body for PATCH, POST and PUT requests. Must be a `Buffer`, `ReadableStream` or `String` (only strings are accepted client side)
- `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json`. Does not have any affect on how the response is treated.
- `form` - You can pass a `FormData` instance to the `form` option, this will manage all the appropriate headers for you. Does not have any affect on how the response is treated.
- `cache` - only used in node.js (browsers already have their own caches) Can be `'memory'`, `'file'` or your own custom implementaton (see https://github.com/ForbesLindesay/http-basic#implementing-a-cache).
- `followRedirects` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request following redirects automatically.
- `maxRedirects` - sets the maximum number of redirects to follow before erroring on node.js (default: `Infinity`)
- `allowRedirectHeaders` (default: `null`) - an array of headers allowed for redirects (none if `null`).
- `gzip` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request automatically supporting the gzip encoding on responses.
- `agent` - (default: `false`) - An `Agent` to controll keep-alive. When set to `false` use an `Agent` with default values.
- `timeout` (default: `false`) - times out if no response is returned within the given number of milliseconds.
- `socketTimeout` (default: `false`) - calls `req.setTimeout` internally which causes the request to timeout if no new data is seen for the given number of milliseconds. This option is ignored in the browser.
- `retry` (default: `false`) - retry GET requests. Set this to `true` to retry when the request errors or returns a status code greater than or equal to 400 (can also be a function that takes `(err, req, attemptNo) => shouldRetry`)
- `retryDelay` (default: `200`) - the delay between retries (can also be set to a function that takes `(err, res, attemptNo) => delay`)
- `maxRetries` (default: `5`) - the number of times to retry before giving up.
**Returns:**
A [Promise](https://www.promisejs.org/) is returned that eventually resolves to the `Response`. The resulting Promise also has an additional `.getBody(encoding?)` method that is equivallent to calling `.then(function (res) { return res.getBody(encoding?); })`.
### Response
Note that even for status codes that represent an error, the promise will be resolved as the request succeeded. You can call `getBody` if you want to error on invalid status codes. The response has the following properties:
- `statusCode` - a number representing the HTTP status code
- `headers` - http response headers
- `body` - a string if in the browser or a buffer if on the server
- `url` - the URL that was requested (in the case of redirects on the server, this is the final url that was requested)
It also has a method `getBody(encoding?)` which looks like:
```js
function getBody(encoding) {
if (this.statusCode >= 300) {
var err = new Error('Server responded with status code ' + this.statusCode + ':\n' + this.body.toString(encoding));
err.statusCode = this.statusCode;
err.headers = this.headers;
err.body = this.body;
throw err;
}
return encoding ? this.body.toString(encoding) : this.body;
}
```
### FormData
```js
var FormData = require('then-request').FormData;
```
Form data either exposes the node.js module, [form-data](https://www.npmjs.com/package/form-data), or the builtin browser object [FormData](https://developer.mozilla.org/en/docs/Web/API/FormData), as appropriate.
They have broadly the same API, with the exception that form-data handles node.js streams and Buffers, while FormData handles the browser's `File` Objects.
## License
MIT

View File

@@ -0,0 +1,30 @@
/// <reference types="node" />
import { Agent } from 'http';
import { IncomingHttpHeaders } from 'http';
import Response = require('http-response-object');
import { ICache, CachedResponse } from 'http-basic';
import FormData = require('form-data');
interface Options {
allowRedirectHeaders?: string[];
cache?: 'file' | 'memory' | ICache;
agent?: boolean | Agent;
followRedirects?: boolean;
gzip?: boolean;
headers?: IncomingHttpHeaders;
maxRedirects?: number;
maxRetries?: number;
retry?: boolean | ((err: NodeJS.ErrnoException | null, res: Response<NodeJS.ReadableStream | Buffer | string> | void, attemptNumber: number) => boolean);
retryDelay?: number | ((err: NodeJS.ErrnoException | null, res: Response<NodeJS.ReadableStream | Buffer | string> | void, attemptNumber: number) => number);
socketTimeout?: number;
timeout?: number;
isMatch?: (requestHeaders: IncomingHttpHeaders, cachedResponse: CachedResponse, defaultValue: boolean) => boolean;
isExpired?: (cachedResponse: CachedResponse, defaultValue: boolean) => boolean;
canCache?: (res: Response<NodeJS.ReadableStream>, defaultValue: boolean) => boolean;
qs?: {
[key: string]: any;
};
json?: any;
form?: FormData;
body?: string | Buffer | NodeJS.ReadableStream;
}
export { Options };

View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,52 @@
// @flow
// Generated using flowgen2
import {Agent} from 'http';
type IncomingHttpHeaders = Object;
const Response = require('http-response-object');
import type {ICache} from 'http-basic';
import type {CachedResponse} from 'http-basic';
const FormData = require('form-data');
interface Options {
allowRedirectHeaders?: Array<string>;
cache?: 'file' | 'memory' | ICache;
agent?: boolean | Agent;
followRedirects?: boolean;
gzip?: boolean;
headers?: IncomingHttpHeaders;
maxRedirects?: number;
maxRetries?: number;
retry?:
| boolean
| ((
err: ErrnoError | null,
res: Response<stream$Readable | Buffer | string> | void,
attemptNumber: number,
) => boolean);
retryDelay?:
| number
| ((
err: ErrnoError | null,
res: Response<stream$Readable | Buffer | string> | void,
attemptNumber: number,
) => number);
socketTimeout?: number;
timeout?: number;
isMatch?: (
requestHeaders: IncomingHttpHeaders,
cachedResponse: CachedResponse,
defaultValue: boolean,
) => boolean;
isExpired?: (
cachedResponse: CachedResponse,
defaultValue: boolean,
) => boolean;
canCache?: (res: Response<stream$Readable>, defaultValue: boolean) => boolean;
qs?: {[key: string]: any};
json?: any;
form?: FormData;
body?: string | Buffer | stream$Readable;
}
export type {Options};

View File

@@ -0,0 +1,5 @@
import { HttpVerb } from 'http-basic';
import { Options } from './Options';
import { ResponsePromise } from './ResponsePromise';
declare type RequestFn = (method: HttpVerb, url: string, options?: Options) => ResponsePromise;
export { RequestFn };

View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,14 @@
// @flow
// Generated using flowgen2
import type {HttpVerb} from 'http-basic';
import type {Options} from './Options';
import {ResponsePromise} from './ResponsePromise';
type RequestFn = (
method: HttpVerb,
url: string,
options?: Options,
) => ResponsePromise;
export type {RequestFn};

View File

@@ -0,0 +1,9 @@
/// <reference types="node" />
import Promise = require('promise');
import Response = require('http-response-object');
export declare class ResponsePromise extends Promise<Response<Buffer | string>> {
getBody(encoding: string): Promise<string>;
getBody(): Promise<Buffer | string>;
}
declare function toResponsePromise(result: Promise<Response<Buffer | string>>): ResponsePromise;
export default toResponsePromise;

View File

@@ -0,0 +1,27 @@
"use strict";
exports.__esModule = true;
var Promise = require("promise");
function getBody(encoding) {
if (!encoding) {
return this.then(getBodyBinary);
}
if (encoding === 'utf8') {
return this.then(getBodyUTF8);
}
return this.then(getBodyWithEncoding(encoding));
}
function getBodyWithEncoding(encoding) {
return function (res) { return res.getBody(encoding); };
}
function getBodyBinary(res) {
return res.getBody();
}
function getBodyUTF8(res) {
return res.getBody('utf8');
}
function toResponsePromise(result) {
result.getBody = getBody;
return result;
}
exports["default"] = toResponsePromise;
exports.ResponsePromise = undefined;

View File

@@ -0,0 +1,17 @@
// @flow
// Generated using flowgen2
const Promise = require('promise');
const Response = require('http-response-object');
declare class ResponsePromise extends Promise<Response<Buffer | string>> {
getBody(encoding: string): Promise<string>;
getBody(): Promise<Buffer | string>;
}
export {ResponsePromise};
declare function toResponsePromise(
result: Promise<Response<Buffer | string>>,
): ResponsePromise;
export default toResponsePromise;

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
import { HttpVerb } from 'http-basic/lib/HttpVerb';
import { IncomingHttpHeaders } from 'http';
import GenericResponse = require('http-response-object');
import { Options } from './Options';
import { ResponsePromise } from './ResponsePromise';
import { RequestFn } from './RequestFn';
declare type Response = GenericResponse<Buffer | string>;
export { HttpVerb, IncomingHttpHeaders as Headers, Options, ResponsePromise, Response };
declare const fd: any;
export { fd as FormData };
declare const _default: RequestFn;
export default _default;

View File

@@ -0,0 +1,124 @@
'use strict';
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
exports.__esModule = true;
var GenericResponse = require("http-response-object");
var Promise = require("promise");
var ResponsePromise_1 = require("./ResponsePromise");
exports.ResponsePromise = ResponsePromise_1.ResponsePromise;
var handle_qs_1 = require("./handle-qs");
function request(method, url, options) {
return ResponsePromise_1["default"](new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
// check types of arguments
if (typeof method !== 'string') {
throw new TypeError('The method must be a string.');
}
if (typeof url !== 'string') {
throw new TypeError('The URL/path must be a string.');
}
if (options == null) {
options = {};
}
if (typeof options !== 'object') {
throw new TypeError('Options must be an object (or null).');
}
method = method.toUpperCase();
function attempt(n, options) {
request(method, url, {
qs: options.qs,
headers: options.headers,
timeout: options.timeout
}).nodeify(function (err, res) {
var retry = !!(err || res.statusCode >= 400);
if (typeof options.retry === 'function') {
retry = options.retry(err, res, n + 1);
}
if (n >= (options.maxRetries || 5)) {
retry = false;
}
if (retry) {
var delay = options.retryDelay;
if (typeof options.retryDelay === 'function') {
delay = options.retryDelay(err, res, n + 1);
}
delay = delay || 200;
setTimeout(function () {
attempt(n + 1, options);
}, delay);
}
else {
if (err)
reject(err);
else
resolve(res);
}
});
}
if (options.retry && method === 'GET') {
return attempt(0, options);
}
var headers = options.headers || {};
// handle cross domain
var match;
var crossDomain = !!((match = /^([\w-]+:)?\/\/([^\/]+)/.exec(url)) && (match[2] != location.host));
if (!crossDomain) {
headers = __assign({}, headers, { 'X-Requested-With': 'XMLHttpRequest' });
}
// handle query string
if (options.qs) {
url = handle_qs_1["default"](url, options.qs);
}
// handle json body
if (options.json) {
options.body = JSON.stringify(options.json);
headers = __assign({}, headers, { 'Content-Type': 'application/json' });
}
if (options.form) {
options.body = options.form;
}
if (options.timeout) {
xhr.timeout = options.timeout;
var start_1 = Date.now();
xhr.ontimeout = function () {
var duration = Date.now() - start_1;
var err = new Error('Request timed out after ' + duration + 'ms');
err.timeout = true;
err.duration = duration;
reject(err);
};
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var headers = {};
xhr.getAllResponseHeaders().split('\r\n').forEach(function (header) {
var h = header.split(':');
if (h.length > 1) {
headers[h[0].toLowerCase()] = h.slice(1).join(':').trim();
}
});
var res = new GenericResponse(xhr.status, headers, xhr.responseText, url);
resolve(res);
}
};
// method, url, async
xhr.open(method, url, true);
for (var name in headers) {
xhr.setRequestHeader(name, headers[name]);
}
// avoid sending empty string (#319)
xhr.send(options.body ? options.body : null);
}));
}
var fd = FormData;
exports.FormData = fd;
exports["default"] = request;
module.exports = request;
module.exports["default"] = request;
module.exports.FormData = fd;

View File

@@ -0,0 +1,21 @@
// @flow
// Generated using flowgen2
import type {HttpVerb} from 'http-basic/lib/HttpVerb';
type IncomingHttpHeaders = Object;
const GenericResponse = require('http-response-object');
import type {Options} from './Options';
import {ResponsePromise} from './ResponsePromise';
import type {RequestFn} from './RequestFn';
type Response = GenericResponse<Buffer | string>;
export type {HttpVerb};
export type {IncomingHttpHeaders as Headers};
export type {Options};
export {ResponsePromise};
export type {Response};
declare var fd: any;
export {fd as FormData};
declare var _default: RequestFn;
export default _default;

View File

@@ -0,0 +1,3 @@
export default function handleQs(url: string, query: {
[key: string]: any;
}): string;

View File

@@ -0,0 +1,18 @@
"use strict";
exports.__esModule = true;
var qs_1 = require("qs");
function handleQs(url, query) {
var _a = url.split('?'), start = _a[0], part2 = _a[1];
var qs = (part2 || '').split('#')[0];
var end = part2 && part2.split('#').length > 1 ? '#' + part2.split('#')[1] : '';
var baseQs = qs_1.parse(qs);
for (var i in query) {
baseQs[i] = query[i];
}
qs = qs_1.stringify(baseQs);
if (qs !== '') {
qs = '?' + qs;
}
return start + qs + end;
}
exports["default"] = handleQs;

View File

@@ -0,0 +1,5 @@
// @flow
// Generated using flowgen2
declare function handleQs(url: string, query: {[key: string]: any}): string;
export default handleQs;

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
import GenericResponse = require('http-response-object');
import { IncomingHttpHeaders } from 'http';
import { Options } from './Options';
import { ResponsePromise } from './ResponsePromise';
import { RequestFn } from './RequestFn';
import { HttpVerb } from 'http-basic';
import FormData = require('form-data');
declare type Response = GenericResponse<Buffer | string>;
export { HttpVerb, IncomingHttpHeaders as Headers, Options, ResponsePromise, Response };
export { FormData };
declare const _default: RequestFn;
export default _default;

View File

@@ -0,0 +1,176 @@
'use strict';
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
exports.__esModule = true;
var GenericResponse = require("http-response-object");
var Promise = require("promise");
var concat = require("concat-stream");
var ResponsePromise_1 = require("./ResponsePromise");
exports.ResponsePromise = ResponsePromise_1.ResponsePromise;
var handle_qs_1 = require("./handle-qs");
var http_basic_1 = require("http-basic");
var FormData = require("form-data");
exports.FormData = FormData;
var caseless = require('caseless');
var basicRequest = http_basic_1["default"];
var BufferBody = /** @class */ (function () {
function BufferBody(body, extraHeaders) {
this._body = body;
this._headers = extraHeaders;
}
BufferBody.prototype.getHeaders = function () {
return Promise.resolve(__assign({ 'content-length': '' + this._body.length }, this._headers));
};
BufferBody.prototype.pipe = function (stream) {
stream.end(this._body);
};
return BufferBody;
}());
var FormBody = /** @class */ (function () {
function FormBody(body) {
this._body = body;
}
FormBody.prototype.getHeaders = function () {
var _this = this;
var headers = this._body.getHeaders();
return new Promise(function (resolve, reject) {
var gotLength = false;
_this._body.getLength(function (err, length) {
if (gotLength)
return;
gotLength = true;
if (err) {
return reject(typeof err == 'string'
? new Error(err)
: err);
}
headers['content-length'] = '' + length;
resolve(headers);
});
});
};
FormBody.prototype.pipe = function (stream) {
this._body.pipe(stream);
};
return FormBody;
}());
var StreamBody = /** @class */ (function () {
function StreamBody(body) {
this._body = body;
}
StreamBody.prototype.getHeaders = function () {
return Promise.resolve({});
};
StreamBody.prototype.pipe = function (stream) {
this._body.pipe(stream);
};
return StreamBody;
}());
function handleBody(options) {
if (options.form) {
return new FormBody(options.form);
}
var extraHeaders = {};
var body = options.body;
if (options.json) {
extraHeaders['content-type'] = 'application/json';
body = JSON.stringify(options.json);
}
if (typeof body === 'string') {
body = Buffer.from(body);
}
if (!body) {
body = Buffer.alloc(0);
}
if (!Buffer.isBuffer(body)) {
if (typeof body.pipe === 'function') {
return new StreamBody(body);
}
throw new TypeError('body should be a Buffer or a String');
}
return new BufferBody(body, extraHeaders);
}
function request(method, url, options) {
if (options === void 0) { options = {}; }
return ResponsePromise_1["default"](new Promise(function (resolve, reject) {
// check types of arguments
if (typeof method !== 'string') {
throw new TypeError('The method must be a string.');
}
if (typeof url !== 'string') {
throw new TypeError('The URL/path must be a string.');
}
if (options == null) {
options = {};
}
if (typeof options !== 'object') {
throw new TypeError('Options must be an object (or null).');
}
method = method.toUpperCase();
options.headers = options.headers || {};
var headers = caseless(options.headers);
// handle query string
if (options.qs) {
url = handle_qs_1["default"](url, options.qs);
}
var duplex = !(method === 'GET' || method === 'DELETE' || method === 'HEAD');
if (duplex) {
var body_1 = handleBody(options);
body_1.getHeaders().then(function (bodyHeaders) {
Object.keys(bodyHeaders).forEach(function (key) {
if (!headers.has(key)) {
headers.set(key, bodyHeaders[key]);
}
});
ready(body_1);
})["catch"](reject);
}
else if (options.body) {
throw new Error('You cannot pass a body to a ' + method + ' request.');
}
else {
ready();
}
function ready(body) {
var req = basicRequest(method, url, {
allowRedirectHeaders: options.allowRedirectHeaders,
headers: options.headers,
followRedirects: options.followRedirects !== false,
maxRedirects: options.maxRedirects,
gzip: options.gzip !== false,
cache: options.cache,
agent: options.agent,
timeout: options.timeout,
socketTimeout: options.socketTimeout,
retry: options.retry,
retryDelay: options.retryDelay,
maxRetries: options.maxRetries,
isMatch: options.isMatch,
isExpired: options.isExpired,
canCache: options.canCache
}, function (err, res) {
if (err)
return reject(err);
if (!res)
return reject(new Error('No request was received'));
res.body.on('error', reject);
res.body.pipe(concat(function (body) {
resolve(new GenericResponse(res.statusCode, res.headers, Array.isArray(body) ? Buffer.alloc(0) : body, res.url));
}));
});
if (req && body) {
body.pipe(req);
}
}
}));
}
exports["default"] = request;
module.exports = request;
module.exports["default"] = request;
module.exports.FormData = FormData;

View File

@@ -0,0 +1,21 @@
// @flow
// Generated using flowgen2
const GenericResponse = require('http-response-object');
type IncomingHttpHeaders = Object;
import type {Options} from './Options';
import {ResponsePromise} from './ResponsePromise';
import type {RequestFn} from './RequestFn';
import type {HttpVerb} from 'http-basic';
const FormData = require('form-data');
type Response = GenericResponse<Buffer | string>;
export type {HttpVerb};
export type {IncomingHttpHeaders as Headers};
export type {Options};
export {ResponsePromise};
export type {Response};
export {FormData};
declare var _default: RequestFn;
export default _default;

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

View File

@@ -0,0 +1,16 @@
# Installation
> `npm install --save @types/node`
# Summary
This package contains type definitions for Node.js (http://nodejs.org/).
# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v8.
### Additional Details
* Last updated: Wed, 28 Oct 2020 18:55:52 GMT
* Dependencies: none
* Global values: `Buffer`, `NodeJS`, `SlowBuffer`, `__dirname`, `__filename`, `clearImmediate`, `clearInterval`, `clearTimeout`, `console`, `exports`, `global`, `module`, `process`, `require`, `setImmediate`, `setInterval`, `setTimeout`
# Credits
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [DefinitelyTyped](https://github.com/DefinitelyTyped), [Parambir Singh](https://github.com/parambirs), [Wilco Bakker](https://github.com/WilcoBakker), [Chigozirim C.](https://github.com/smac89), [Flarna](https://github.com/Flarna), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [wwwy3y3](https://github.com/wwwy3y3), [Deividas Bakanas](https://github.com/DeividasBakanas), [Kelvin Jin](https://github.com/kjin), [Alvis HT Tang](https://github.com/alvis), [Sebastian Silbermann](https://github.com/eps1lon), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Alberto Schiabel](https://github.com/jkomyno), [Huw](https://github.com/hoo29), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Bruno Scheufler](https://github.com/brunoscheufler), [Hoàng Văn Khải](https://github.com/KSXGitHub), [Lishude](https://github.com/islishude), [Andrew Makarov](https://github.com/r3nya), [Jordi Oliveras Rovira](https://github.com/j-oliveras), and [Thanik Bhongbhibhat](https://github.com/bhongy).

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
// Type definitions for Node.js 8.10
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Parambir Singh <https://github.com/parambirs>
// Wilco Bakker <https://github.com/WilcoBakker>
// Chigozirim C. <https://github.com/smac89>
// Flarna <https://github.com/Flarna>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// wwwy3y3 <https://github.com/wwwy3y3>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Kelvin Jin <https://github.com/kjin>
// Alvis HT Tang <https://github.com/alvis>
// Sebastian Silbermann <https://github.com/eps1lon>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Alberto Schiabel <https://github.com/jkomyno>
// Huw <https://github.com/hoo29>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Lishude <https://github.com/islishude>
// Andrew Makarov <https://github.com/r3nya>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// NOTE: These definitions support NodeJS and TypeScript 3.2.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2
// Reference required types from the default lib:
/// <reference lib="es2017" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// TypeScript 3.2-specific augmentations:
declare module "util" {
namespace inspect {
const custom: unique symbol;
}
namespace promisify {
const custom: unique symbol;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,134 @@
{
"name": "@types/node",
"version": "8.10.66",
"description": "TypeScript definitions for Node.js",
"license": "MIT",
"contributors": [
{
"name": "Microsoft TypeScript",
"url": "https://github.com/Microsoft",
"githubUsername": "Microsoft"
},
{
"name": "DefinitelyTyped",
"url": "https://github.com/DefinitelyTyped",
"githubUsername": "DefinitelyTyped"
},
{
"name": "Parambir Singh",
"url": "https://github.com/parambirs",
"githubUsername": "parambirs"
},
{
"name": "Wilco Bakker",
"url": "https://github.com/WilcoBakker",
"githubUsername": "WilcoBakker"
},
{
"name": "Chigozirim C.",
"url": "https://github.com/smac89",
"githubUsername": "smac89"
},
{
"name": "Flarna",
"url": "https://github.com/Flarna",
"githubUsername": "Flarna"
},
{
"name": "Mariusz Wiktorczyk",
"url": "https://github.com/mwiktorczyk",
"githubUsername": "mwiktorczyk"
},
{
"name": "wwwy3y3",
"url": "https://github.com/wwwy3y3",
"githubUsername": "wwwy3y3"
},
{
"name": "Deividas Bakanas",
"url": "https://github.com/DeividasBakanas",
"githubUsername": "DeividasBakanas"
},
{
"name": "Kelvin Jin",
"url": "https://github.com/kjin",
"githubUsername": "kjin"
},
{
"name": "Alvis HT Tang",
"url": "https://github.com/alvis",
"githubUsername": "alvis"
},
{
"name": "Sebastian Silbermann",
"url": "https://github.com/eps1lon",
"githubUsername": "eps1lon"
},
{
"name": "Hannes Magnusson",
"url": "https://github.com/Hannes-Magnusson-CK",
"githubUsername": "Hannes-Magnusson-CK"
},
{
"name": "Alberto Schiabel",
"url": "https://github.com/jkomyno",
"githubUsername": "jkomyno"
},
{
"name": "Huw",
"url": "https://github.com/hoo29",
"githubUsername": "hoo29"
},
{
"name": "Nicolas Even",
"url": "https://github.com/n-e",
"githubUsername": "n-e"
},
{
"name": "Nikita Galkin",
"url": "https://github.com/galkin",
"githubUsername": "galkin"
},
{
"name": "Bruno Scheufler",
"url": "https://github.com/brunoscheufler",
"githubUsername": "brunoscheufler"
},
{
"name": "Hoàng Văn Khải",
"url": "https://github.com/KSXGitHub",
"githubUsername": "KSXGitHub"
},
{
"name": "Lishude",
"url": "https://github.com/islishude",
"githubUsername": "islishude"
},
{
"name": "Andrew Makarov",
"url": "https://github.com/r3nya",
"githubUsername": "r3nya"
},
{
"name": "Jordi Oliveras Rovira",
"url": "https://github.com/j-oliveras",
"githubUsername": "j-oliveras"
},
{
"name": "Thanik Bhongbhibhat",
"url": "https://github.com/bhongy",
"githubUsername": "bhongy"
}
],
"main": "",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
"directory": "types/node"
},
"scripts": {},
"dependencies": {},
"typesPublisherContentHash": "bbdc3f41bff51f7e23469a2e9fc3ee831a778f6bea4de0a8f85e86b868dd7bd3",
"typeScriptVersion": "3.2"
}

View File

@@ -0,0 +1,58 @@
{
"name": "then-request",
"version": "6.0.2",
"description": "A request library that returns promises, inspired by request",
"keywords": [],
"main": "lib/index.js",
"browser": "lib/browser.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"dependencies": {
"@types/concat-stream": "^1.6.0",
"@types/form-data": "0.0.33",
"@types/node": "^8.0.0",
"@types/qs": "^6.2.31",
"caseless": "~0.12.0",
"concat-stream": "^1.6.0",
"form-data": "^2.2.0",
"http-basic": "^8.1.1",
"http-response-object": "^3.0.1",
"promise": "^8.0.0",
"qs": "^6.4.0"
},
"devDependencies": {
"browserify": "^14.4.0",
"busboy": "^0.2.14",
"exorcist": "^0.4.0",
"flowgen2": "^2.2.2",
"istanbul": "^0.4.5",
"jsdom": "^11.1.0",
"minifyify": "^7.3.5",
"mkdirp": "^0.5.1",
"multiparty": "^4.1.3",
"rimraf": "^2.6.1",
"testit": "^2.1.3",
"typescript": "^2.4.0"
},
"scripts": {
"pretest": "npm run build:types",
"test": "node test/index.js && istanbul cover test/index.js",
"prepublishOnly": "npm run build",
"prebuild": "rimraf dist && mkdirp dist",
"build": "npm run build:types && npm run build:full && npm run build:min",
"build:types": "tsc && flowgen lib/**/*",
"build:full": "browserify -d --standalone request lib/browser.js | exorcist -u request.js.map dist/request.js.map > dist/request.js",
"build:min": "browserify -d --standalone request lib/browser.js -p [minifyify --compressPath . --map request.min.js.map --output dist/request.min.js.map] > dist/request.min.js"
},
"engines": {
"node": ">=6.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/then/then-request.git"
},
"author": "ForbesLindesay",
"license": "MIT"
}