Merge branch 'master' of ssh://taler.net/wallet-webex
This commit is contained in:
commit
541256ca99
@ -4,8 +4,8 @@
|
|||||||
"name": "GNU Taler Wallet (git)",
|
"name": "GNU Taler Wallet (git)",
|
||||||
"description": "Privacy preserving and transparent payments",
|
"description": "Privacy preserving and transparent payments",
|
||||||
"author": "GNU Taler Developers",
|
"author": "GNU Taler Developers",
|
||||||
"version": "0.6.46",
|
"version": "0.6.47",
|
||||||
"version_name": "0.3.0",
|
"version_name": "0.4.0-pre1",
|
||||||
|
|
||||||
"minimum_chrome_version": "51",
|
"minimum_chrome_version": "51",
|
||||||
"minimum_opera_version": "36",
|
"minimum_opera_version": "36",
|
||||||
|
2
node_modules/.bin/tsc
generated
vendored
2
node_modules/.bin/tsc
generated
vendored
@ -1 +1 @@
|
|||||||
../typedoc/node_modules/typescript/bin/tsc
|
../typescript/bin/tsc
|
2
node_modules/.bin/tsserver
generated
vendored
2
node_modules/.bin/tsserver
generated
vendored
@ -1 +1 @@
|
|||||||
../typedoc/node_modules/typescript/bin/tsserver
|
../typescript/bin/tsserver
|
2
node_modules/.bin/uglifyjs
generated
vendored
2
node_modules/.bin/uglifyjs
generated
vendored
@ -1 +1 @@
|
|||||||
../handlebars/node_modules/uglify-js/bin/uglifyjs
|
../uglify-js/bin/uglifyjs
|
221
node_modules/axios/CHANGELOG.md
generated
vendored
Normal file
221
node_modules/axios/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
### 0.16.2 (Jun 3, 2017)
|
||||||
|
|
||||||
|
- Fixing issue with including `buffer` in bundle ([#887](https://github.com/mzabriskie/axios/pull/887))
|
||||||
|
- Including underlying request in errors ([#830](https://github.com/mzabriskie/axios/pull/830))
|
||||||
|
- Convert `method` to lowercase ([#930](https://github.com/mzabriskie/axios/pull/930))
|
||||||
|
|
||||||
|
### 0.16.1 (Apr 8, 2017)
|
||||||
|
|
||||||
|
- Improving HTTP adapter to return last request in case of redirects ([#828](https://github.com/mzabriskie/axios/pull/828))
|
||||||
|
- Updating `follow-redirects` dependency ([#829](https://github.com/mzabriskie/axios/pull/829))
|
||||||
|
- Adding support for passing `Buffer` in node ([#773](https://github.com/mzabriskie/axios/pull/773))
|
||||||
|
|
||||||
|
### 0.16.0 (Mar 31, 2017)
|
||||||
|
|
||||||
|
- **BREAKING** Removing `Promise` from axios typings in favor of built-in type declarations ([#480](https://github.com/mzabriskie/axios/issues/480))
|
||||||
|
- Adding `options` shortcut method ([#461](https://github.com/mzabriskie/axios/pull/461))
|
||||||
|
- Fixing issue with using `responseType: 'json'` in browsers incompatible with XHR Level 2 ([#654](https://github.com/mzabriskie/axios/pull/654))
|
||||||
|
- Improving React Native detection ([#731](https://github.com/mzabriskie/axios/pull/731))
|
||||||
|
- Fixing `combineURLs` to support empty `relativeURL` ([#581](https://github.com/mzabriskie/axios/pull/581))
|
||||||
|
- Removing `PROTECTION_PREFIX` support ([#561](https://github.com/mzabriskie/axios/pull/561))
|
||||||
|
|
||||||
|
### 0.15.3 (Nov 27, 2016)
|
||||||
|
|
||||||
|
- Fixing issue with custom instances and global defaults ([#443](https://github.com/mzabriskie/axios/issues/443))
|
||||||
|
- Renaming `axios.d.ts` to `index.d.ts` ([#519](https://github.com/mzabriskie/axios/issues/519))
|
||||||
|
- Adding `get`, `head`, and `delete` to `defaults.headers` ([#509](https://github.com/mzabriskie/axios/issues/509))
|
||||||
|
- Fixing issue with `btoa` and IE ([#507](https://github.com/mzabriskie/axios/issues/507))
|
||||||
|
- Adding support for proxy authentication ([#483](https://github.com/mzabriskie/axios/pull/483))
|
||||||
|
- Improving HTTP adapter to use `http` protocol by default ([#493](https://github.com/mzabriskie/axios/pull/493))
|
||||||
|
- Fixing proxy issues ([#491](https://github.com/mzabriskie/axios/pull/491))
|
||||||
|
|
||||||
|
### 0.15.2 (Oct 17, 2016)
|
||||||
|
|
||||||
|
- Fixing issue with calling `cancel` after response has been received ([#482](https://github.com/mzabriskie/axios/issues/482))
|
||||||
|
|
||||||
|
### 0.15.1 (Oct 14, 2016)
|
||||||
|
|
||||||
|
- Fixing issue with UMD ([#485](https://github.com/mzabriskie/axios/issues/485))
|
||||||
|
|
||||||
|
### 0.15.0 (Oct 10, 2016)
|
||||||
|
|
||||||
|
- Adding cancellation support ([#452](https://github.com/mzabriskie/axios/pull/452))
|
||||||
|
- Moving default adapter to global defaults ([#437](https://github.com/mzabriskie/axios/pull/437))
|
||||||
|
- Fixing issue with `file` URI scheme ([#440](https://github.com/mzabriskie/axios/pull/440))
|
||||||
|
- Fixing issue with `params` objects that have no prototype ([#445](https://github.com/mzabriskie/axios/pull/445))
|
||||||
|
|
||||||
|
### 0.14.0 (Aug 27, 2016)
|
||||||
|
|
||||||
|
- **BREAKING** Updating TypeScript definitions ([#419](https://github.com/mzabriskie/axios/pull/419))
|
||||||
|
- **BREAKING** Replacing `agent` option with `httpAgent` and `httpsAgent` ([#387](https://github.com/mzabriskie/axios/pull/387))
|
||||||
|
- **BREAKING** Splitting `progress` event handlers into `onUploadProgress` and `onDownloadProgress` ([#423](https://github.com/mzabriskie/axios/pull/423))
|
||||||
|
- Adding support for `http_proxy` and `https_proxy` environment variables ([#366](https://github.com/mzabriskie/axios/pull/366))
|
||||||
|
- Fixing issue with `auth` config option and `Authorization` header ([#397](https://github.com/mzabriskie/axios/pull/397))
|
||||||
|
- Don't set XSRF header if `xsrfCookieName` is `null` ([#406](https://github.com/mzabriskie/axios/pull/406))
|
||||||
|
|
||||||
|
### 0.13.1 (Jul 16, 2016)
|
||||||
|
|
||||||
|
- Fixing issue with response data not being transformed on error ([#378](https://github.com/mzabriskie/axios/issues/378))
|
||||||
|
|
||||||
|
### 0.13.0 (Jul 13, 2016)
|
||||||
|
|
||||||
|
- **BREAKING** Improved error handling ([#345](https://github.com/mzabriskie/axios/pull/345))
|
||||||
|
- **BREAKING** Response transformer now invoked in dispatcher not adapter ([10eb238](https://github.com/mzabriskie/axios/commit/10eb23865101f9347570552c04e9d6211376e25e))
|
||||||
|
- **BREAKING** Request adapters now return a `Promise` ([157efd5](https://github.com/mzabriskie/axios/commit/157efd5615890301824e3121cc6c9d2f9b21f94a))
|
||||||
|
- Fixing issue with `withCredentials` not being overwritten ([#343](https://github.com/mzabriskie/axios/issues/343))
|
||||||
|
- Fixing regression with request transformer being called before request interceptor ([#352](https://github.com/mzabriskie/axios/issues/352))
|
||||||
|
- Fixing custom instance defaults ([#341](https://github.com/mzabriskie/axios/issues/341))
|
||||||
|
- Fixing instances created from `axios.create` to have same API as default axios ([#217](https://github.com/mzabriskie/axios/issues/217))
|
||||||
|
|
||||||
|
### 0.12.0 (May 31, 2016)
|
||||||
|
|
||||||
|
- Adding support for `URLSearchParams` ([#317](https://github.com/mzabriskie/axios/pull/317))
|
||||||
|
- Adding `maxRedirects` option ([#307](https://github.com/mzabriskie/axios/pull/307))
|
||||||
|
|
||||||
|
### 0.11.1 (May 17, 2016)
|
||||||
|
|
||||||
|
- Fixing IE CORS support ([#313](https://github.com/mzabriskie/axios/pull/313))
|
||||||
|
- Fixing detection of `FormData` ([#325](https://github.com/mzabriskie/axios/pull/325))
|
||||||
|
- Adding `Axios` class to exports ([#321](https://github.com/mzabriskie/axios/pull/321))
|
||||||
|
|
||||||
|
### 0.11.0 (Apr 26, 2016)
|
||||||
|
|
||||||
|
- Adding support for Stream with HTTP adapter ([#296](https://github.com/mzabriskie/axios/pull/296))
|
||||||
|
- Adding support for custom HTTP status code error ranges ([#308](https://github.com/mzabriskie/axios/pull/308))
|
||||||
|
- Fixing issue with ArrayBuffer ([#299](https://github.com/mzabriskie/axios/pull/299))
|
||||||
|
|
||||||
|
### 0.10.0 (Apr 20, 2016)
|
||||||
|
|
||||||
|
- Fixing issue with some requests sending `undefined` instead of `null` ([#250](https://github.com/mzabriskie/axios/pull/250))
|
||||||
|
- Fixing basic auth for HTTP adapter ([#252](https://github.com/mzabriskie/axios/pull/252))
|
||||||
|
- Fixing request timeout for XHR adapter ([#227](https://github.com/mzabriskie/axios/pull/227))
|
||||||
|
- Fixing IE8 support by using `onreadystatechange` instead of `onload` ([#249](https://github.com/mzabriskie/axios/pull/249))
|
||||||
|
- Fixing IE9 cross domain requests ([#251](https://github.com/mzabriskie/axios/pull/251))
|
||||||
|
- Adding `maxContentLength` option ([#275](https://github.com/mzabriskie/axios/pull/275))
|
||||||
|
- Fixing XHR support for WebWorker environment ([#279](https://github.com/mzabriskie/axios/pull/279))
|
||||||
|
- Adding request instance to response ([#200](https://github.com/mzabriskie/axios/pull/200))
|
||||||
|
|
||||||
|
### 0.9.1 (Jan 24, 2016)
|
||||||
|
|
||||||
|
- Improving handling of request timeout in node ([#124](https://github.com/mzabriskie/axios/issues/124))
|
||||||
|
- Fixing network errors not rejecting ([#205](https://github.com/mzabriskie/axios/pull/205))
|
||||||
|
- Fixing issue with IE rejecting on HTTP 204 ([#201](https://github.com/mzabriskie/axios/issues/201))
|
||||||
|
- Fixing host/port when following redirects ([#198](https://github.com/mzabriskie/axios/pull/198))
|
||||||
|
|
||||||
|
### 0.9.0 (Jan 18, 2016)
|
||||||
|
|
||||||
|
- Adding support for custom adapters
|
||||||
|
- Fixing Content-Type header being removed when data is false ([#195](https://github.com/mzabriskie/axios/pull/195))
|
||||||
|
- Improving XDomainRequest implementation ([#185](https://github.com/mzabriskie/axios/pull/185))
|
||||||
|
- Improving config merging and order of precedence ([#183](https://github.com/mzabriskie/axios/pull/183))
|
||||||
|
- Fixing XDomainRequest support for only <= IE9 ([#182](https://github.com/mzabriskie/axios/pull/182))
|
||||||
|
|
||||||
|
### 0.8.1 (Dec 14, 2015)
|
||||||
|
|
||||||
|
- Adding support for passing XSRF token for cross domain requests when using `withCredentials` ([#168](https://github.com/mzabriskie/axios/pull/168))
|
||||||
|
- Fixing error with format of basic auth header ([#178](https://github.com/mzabriskie/axios/pull/173))
|
||||||
|
- Fixing error with JSON payloads throwing `InvalidStateError` in some cases ([#174](https://github.com/mzabriskie/axios/pull/174))
|
||||||
|
|
||||||
|
### 0.8.0 (Dec 11, 2015)
|
||||||
|
|
||||||
|
- Adding support for creating instances of axios ([#123](https://github.com/mzabriskie/axios/pull/123))
|
||||||
|
- Fixing http adapter to use `Buffer` instead of `String` in case of `responseType === 'arraybuffer'` ([#128](https://github.com/mzabriskie/axios/pull/128))
|
||||||
|
- Adding support for using custom parameter serializer with `paramsSerializer` option ([#121](https://github.com/mzabriskie/axios/pull/121))
|
||||||
|
- Fixing issue in IE8 caused by `forEach` on `arguments` ([#127](https://github.com/mzabriskie/axios/pull/127))
|
||||||
|
- Adding support for following redirects in node ([#146](https://github.com/mzabriskie/axios/pull/146))
|
||||||
|
- Adding support for transparent decompression if `content-encoding` is set ([#149](https://github.com/mzabriskie/axios/pull/149))
|
||||||
|
- Adding support for transparent XDomainRequest to handle cross domain requests in IE9 ([#140](https://github.com/mzabriskie/axios/pull/140))
|
||||||
|
- Adding support for HTTP basic auth via Authorization header ([#167](https://github.com/mzabriskie/axios/pull/167))
|
||||||
|
- Adding support for baseURL option ([#160](https://github.com/mzabriskie/axios/pull/160))
|
||||||
|
|
||||||
|
### 0.7.0 (Sep 29, 2015)
|
||||||
|
|
||||||
|
- Fixing issue with minified bundle in IE8 ([#87](https://github.com/mzabriskie/axios/pull/87))
|
||||||
|
- Adding support for passing agent in node ([#102](https://github.com/mzabriskie/axios/pull/102))
|
||||||
|
- Adding support for returning result from `axios.spread` for chaining ([#106](https://github.com/mzabriskie/axios/pull/106))
|
||||||
|
- Fixing typescript definition ([#105](https://github.com/mzabriskie/axios/pull/105))
|
||||||
|
- Fixing default timeout config for node ([#112](https://github.com/mzabriskie/axios/pull/112))
|
||||||
|
- Adding support for use in web workers, and react-native ([#70](https://github.com/mzabriskie/axios/issue/70)), ([#98](https://github.com/mzabriskie/axios/pull/98))
|
||||||
|
- Adding support for fetch like API `axios(url[, config])` ([#116](https://github.com/mzabriskie/axios/issues/116))
|
||||||
|
|
||||||
|
### 0.6.0 (Sep 21, 2015)
|
||||||
|
|
||||||
|
- Removing deprecated success/error aliases
|
||||||
|
- Fixing issue with array params not being properly encoded ([#49](https://github.com/mzabriskie/axios/pull/49))
|
||||||
|
- Fixing issue with User-Agent getting overridden ([#69](https://github.com/mzabriskie/axios/issues/69))
|
||||||
|
- Adding support for timeout config ([#56](https://github.com/mzabriskie/axios/issues/56))
|
||||||
|
- Removing es6-promise dependency
|
||||||
|
- Fixing issue preventing `length` to be used as a parameter ([#91](https://github.com/mzabriskie/axios/pull/91))
|
||||||
|
- Fixing issue with IE8 ([#85](https://github.com/mzabriskie/axios/pull/85))
|
||||||
|
- Converting build to UMD
|
||||||
|
|
||||||
|
### 0.5.4 (Apr 08, 2015)
|
||||||
|
|
||||||
|
- Fixing issue with FormData not being sent ([#53](https://github.com/mzabriskie/axios/issues/53))
|
||||||
|
|
||||||
|
### 0.5.3 (Apr 07, 2015)
|
||||||
|
|
||||||
|
- Using JSON.parse unconditionally when transforming response string ([#55](https://github.com/mzabriskie/axios/issues/55))
|
||||||
|
|
||||||
|
### 0.5.2 (Mar 13, 2015)
|
||||||
|
|
||||||
|
- Adding support for `statusText` in response ([#46](https://github.com/mzabriskie/axios/issues/46))
|
||||||
|
|
||||||
|
### 0.5.1 (Mar 10, 2015)
|
||||||
|
|
||||||
|
- Fixing issue using strict mode ([#45](https://github.com/mzabriskie/axios/issues/45))
|
||||||
|
- Fixing issue with standalone build ([#47](https://github.com/mzabriskie/axios/issues/47))
|
||||||
|
|
||||||
|
### 0.5.0 (Jan 23, 2015)
|
||||||
|
|
||||||
|
- Adding support for intercepetors ([#14](https://github.com/mzabriskie/axios/issues/14))
|
||||||
|
- Updating es6-promise dependency
|
||||||
|
|
||||||
|
### 0.4.2 (Dec 10, 2014)
|
||||||
|
|
||||||
|
- Fixing issue with `Content-Type` when using `FormData` ([#22](https://github.com/mzabriskie/axios/issues/22))
|
||||||
|
- Adding support for TypeScript ([#25](https://github.com/mzabriskie/axios/issues/25))
|
||||||
|
- Fixing issue with standalone build ([#29](https://github.com/mzabriskie/axios/issues/29))
|
||||||
|
- Fixing issue with verbs needing to be capitalized in some browsers ([#30](https://github.com/mzabriskie/axios/issues/30))
|
||||||
|
|
||||||
|
### 0.4.1 (Oct 15, 2014)
|
||||||
|
|
||||||
|
- Adding error handling to request for node.js ([#18](https://github.com/mzabriskie/axios/issues/18))
|
||||||
|
|
||||||
|
### 0.4.0 (Oct 03, 2014)
|
||||||
|
|
||||||
|
- Adding support for `ArrayBuffer` and `ArrayBufferView` ([#10](https://github.com/mzabriskie/axios/issues/10))
|
||||||
|
- Adding support for utf-8 for node.js ([#13](https://github.com/mzabriskie/axios/issues/13))
|
||||||
|
- Adding support for SSL for node.js ([#12](https://github.com/mzabriskie/axios/issues/12))
|
||||||
|
- Fixing incorrect `Content-Type` header ([#9](https://github.com/mzabriskie/axios/issues/9))
|
||||||
|
- Adding standalone build without bundled es6-promise ([#11](https://github.com/mzabriskie/axios/issues/11))
|
||||||
|
- Deprecating `success`/`error` in favor of `then`/`catch`
|
||||||
|
|
||||||
|
### 0.3.1 (Sep 16, 2014)
|
||||||
|
|
||||||
|
- Fixing missing post body when using node.js ([#3](https://github.com/mzabriskie/axios/issues/3))
|
||||||
|
|
||||||
|
### 0.3.0 (Sep 16, 2014)
|
||||||
|
|
||||||
|
- Fixing `success` and `error` to properly receive response data as individual arguments ([#8](https://github.com/mzabriskie/axios/issues/8))
|
||||||
|
- Updating `then` and `catch` to receive response data as a single object ([#6](https://github.com/mzabriskie/axios/issues/6))
|
||||||
|
- Fixing issue with `all` not working ([#7](https://github.com/mzabriskie/axios/issues/7))
|
||||||
|
|
||||||
|
### 0.2.2 (Sep 14, 2014)
|
||||||
|
|
||||||
|
- Fixing bundling with browserify ([#4](https://github.com/mzabriskie/axios/issues/4))
|
||||||
|
|
||||||
|
### 0.2.1 (Sep 12, 2014)
|
||||||
|
|
||||||
|
- Fixing build problem causing ridiculous file sizes
|
||||||
|
|
||||||
|
### 0.2.0 (Sep 12, 2014)
|
||||||
|
|
||||||
|
- Adding support for `all` and `spread`
|
||||||
|
- Adding support for node.js ([#1](https://github.com/mzabriskie/axios/issues/1))
|
||||||
|
|
||||||
|
### 0.1.0 (Aug 29, 2014)
|
||||||
|
|
||||||
|
- Initial release
|
19
node_modules/axios/LICENSE
generated
vendored
Normal file
19
node_modules/axios/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2014 Matt Zabriskie
|
||||||
|
|
||||||
|
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.
|
610
node_modules/axios/README.md
generated
vendored
Normal file
610
node_modules/axios/README.md
generated
vendored
Normal file
@ -0,0 +1,610 @@
|
|||||||
|
# axios
|
||||||
|
|
||||||
|
[![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
|
||||||
|
[![build status](https://img.shields.io/travis/mzabriskie/axios.svg?style=flat-square)](https://travis-ci.org/mzabriskie/axios)
|
||||||
|
[![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
|
||||||
|
[![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios)
|
||||||
|
[![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
|
||||||
|
|
||||||
|
Promise based HTTP client for the browser and node.js
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
|
||||||
|
- Make [http](http://nodejs.org/api/http.html) requests from node.js
|
||||||
|
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
|
||||||
|
- Intercept request and response
|
||||||
|
- Transform request and response data
|
||||||
|
- Cancel requests
|
||||||
|
- Automatic transforms for JSON data
|
||||||
|
- Client side support for protecting against [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
||||||
|
|
||||||
|
## Browser Support
|
||||||
|
|
||||||
|
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
|
||||||
|
--- | --- | --- | --- | --- | --- |
|
||||||
|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 8+ ✔ |
|
||||||
|
|
||||||
|
[![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios)
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
Using npm:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm install axios
|
||||||
|
```
|
||||||
|
|
||||||
|
Using bower:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ bower install axios
|
||||||
|
```
|
||||||
|
|
||||||
|
Using cdn:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Performing a `GET` request
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Make a request for a user with a given ID
|
||||||
|
axios.get('/user?ID=12345')
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Optionally the request above could also be done as
|
||||||
|
axios.get('/user', {
|
||||||
|
params: {
|
||||||
|
ID: 12345
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Performing a `POST` request
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.post('/user', {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone'
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Performing multiple concurrent requests
|
||||||
|
|
||||||
|
```js
|
||||||
|
function getUserAccount() {
|
||||||
|
return axios.get('/user/12345');
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUserPermissions() {
|
||||||
|
return axios.get('/user/12345/permissions');
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.all([getUserAccount(), getUserPermissions()])
|
||||||
|
.then(axios.spread(function (acct, perms) {
|
||||||
|
// Both requests are now complete
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
## axios API
|
||||||
|
|
||||||
|
Requests can be made by passing the relevant config to `axios`.
|
||||||
|
|
||||||
|
##### axios(config)
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Send a POST request
|
||||||
|
axios({
|
||||||
|
method: 'post',
|
||||||
|
url: '/user/12345',
|
||||||
|
data: {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
// GET request for remote image
|
||||||
|
axios({
|
||||||
|
method:'get',
|
||||||
|
url:'http://bit.ly/2mTM3nY',
|
||||||
|
responseType:'stream'
|
||||||
|
})
|
||||||
|
.then(function(response) {
|
||||||
|
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
##### axios(url[, config])
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Send a GET request (default method)
|
||||||
|
axios('/user/12345');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Request method aliases
|
||||||
|
|
||||||
|
For convenience aliases have been provided for all supported request methods.
|
||||||
|
|
||||||
|
##### axios.request(config)
|
||||||
|
##### axios.get(url[, config])
|
||||||
|
##### axios.delete(url[, config])
|
||||||
|
##### axios.head(url[, config])
|
||||||
|
##### axios.options(url[, config])
|
||||||
|
##### axios.post(url[, data[, config]])
|
||||||
|
##### axios.put(url[, data[, config]])
|
||||||
|
##### axios.patch(url[, data[, config]])
|
||||||
|
|
||||||
|
###### NOTE
|
||||||
|
When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
|
||||||
|
|
||||||
|
### Concurrency
|
||||||
|
|
||||||
|
Helper functions for dealing with concurrent requests.
|
||||||
|
|
||||||
|
##### axios.all(iterable)
|
||||||
|
##### axios.spread(callback)
|
||||||
|
|
||||||
|
### Creating an instance
|
||||||
|
|
||||||
|
You can create a new instance of axios with a custom config.
|
||||||
|
|
||||||
|
##### axios.create([config])
|
||||||
|
|
||||||
|
```js
|
||||||
|
var instance = axios.create({
|
||||||
|
baseURL: 'https://some-domain.com/api/',
|
||||||
|
timeout: 1000,
|
||||||
|
headers: {'X-Custom-Header': 'foobar'}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Instance methods
|
||||||
|
|
||||||
|
The available instance methods are listed below. The specified config will be merged with the instance config.
|
||||||
|
|
||||||
|
##### axios#request(config)
|
||||||
|
##### axios#get(url[, config])
|
||||||
|
##### axios#delete(url[, config])
|
||||||
|
##### axios#head(url[, config])
|
||||||
|
##### axios#options(url[, config])
|
||||||
|
##### axios#post(url[, data[, config]])
|
||||||
|
##### axios#put(url[, data[, config]])
|
||||||
|
##### axios#patch(url[, data[, config]])
|
||||||
|
|
||||||
|
## Request Config
|
||||||
|
|
||||||
|
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// `url` is the server URL that will be used for the request
|
||||||
|
url: '/user',
|
||||||
|
|
||||||
|
// `method` is the request method to be used when making the request
|
||||||
|
method: 'get', // default
|
||||||
|
|
||||||
|
// `baseURL` will be prepended to `url` unless `url` is absolute.
|
||||||
|
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
|
||||||
|
// to methods of that instance.
|
||||||
|
baseURL: 'https://some-domain.com/api/',
|
||||||
|
|
||||||
|
// `transformRequest` allows changes to the request data before it is sent to the server
|
||||||
|
// This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
|
||||||
|
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
|
||||||
|
// FormData or Stream
|
||||||
|
transformRequest: [function (data) {
|
||||||
|
// Do whatever you want to transform the data
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}],
|
||||||
|
|
||||||
|
// `transformResponse` allows changes to the response data to be made before
|
||||||
|
// it is passed to then/catch
|
||||||
|
transformResponse: [function (data) {
|
||||||
|
// Do whatever you want to transform the data
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}],
|
||||||
|
|
||||||
|
// `headers` are custom headers to be sent
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||||
|
|
||||||
|
// `params` are the URL parameters to be sent with the request
|
||||||
|
// Must be a plain object or a URLSearchParams object
|
||||||
|
params: {
|
||||||
|
ID: 12345
|
||||||
|
},
|
||||||
|
|
||||||
|
// `paramsSerializer` is an optional function in charge of serializing `params`
|
||||||
|
// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
|
||||||
|
paramsSerializer: function(params) {
|
||||||
|
return Qs.stringify(params, {arrayFormat: 'brackets'})
|
||||||
|
},
|
||||||
|
|
||||||
|
// `data` is the data to be sent as the request body
|
||||||
|
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
|
||||||
|
// When no `transformRequest` is set, must be of one of the following types:
|
||||||
|
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
|
||||||
|
// - Browser only: FormData, File, Blob
|
||||||
|
// - Node only: Stream, Buffer
|
||||||
|
data: {
|
||||||
|
firstName: 'Fred'
|
||||||
|
},
|
||||||
|
|
||||||
|
// `timeout` specifies the number of milliseconds before the request times out.
|
||||||
|
// If the request takes longer than `timeout`, the request will be aborted.
|
||||||
|
timeout: 1000,
|
||||||
|
|
||||||
|
// `withCredentials` indicates whether or not cross-site Access-Control requests
|
||||||
|
// should be made using credentials
|
||||||
|
withCredentials: false, // default
|
||||||
|
|
||||||
|
// `adapter` allows custom handling of requests which makes testing easier.
|
||||||
|
// Return a promise and supply a valid response (see lib/adapters/README.md).
|
||||||
|
adapter: function (config) {
|
||||||
|
/* ... */
|
||||||
|
},
|
||||||
|
|
||||||
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
||||||
|
// This will set an `Authorization` header, overwriting any existing
|
||||||
|
// `Authorization` custom headers you have set using `headers`.
|
||||||
|
auth: {
|
||||||
|
username: 'janedoe',
|
||||||
|
password: 's00pers3cret'
|
||||||
|
},
|
||||||
|
|
||||||
|
// `responseType` indicates the type of data that the server will respond with
|
||||||
|
// options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
|
||||||
|
responseType: 'json', // default
|
||||||
|
|
||||||
|
// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
|
||||||
|
xsrfCookieName: 'XSRF-TOKEN', // default
|
||||||
|
|
||||||
|
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
|
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN', // default
|
||||||
|
|
||||||
|
// `onUploadProgress` allows handling of progress events for uploads
|
||||||
|
onUploadProgress: function (progressEvent) {
|
||||||
|
// Do whatever you want with the native progress event
|
||||||
|
},
|
||||||
|
|
||||||
|
// `onDownloadProgress` allows handling of progress events for downloads
|
||||||
|
onDownloadProgress: function (progressEvent) {
|
||||||
|
// Do whatever you want with the native progress event
|
||||||
|
},
|
||||||
|
|
||||||
|
// `maxContentLength` defines the max size of the http response content allowed
|
||||||
|
maxContentLength: 2000,
|
||||||
|
|
||||||
|
// `validateStatus` defines whether to resolve or reject the promise for a given
|
||||||
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
||||||
|
// or `undefined`), the promise will be resolved; otherwise, the promise will be
|
||||||
|
// rejected.
|
||||||
|
validateStatus: function (status) {
|
||||||
|
return status >= 200 && status < 300; // default
|
||||||
|
},
|
||||||
|
|
||||||
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
||||||
|
// If set to 0, no redirects will be followed.
|
||||||
|
maxRedirects: 5, // default
|
||||||
|
|
||||||
|
// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
|
||||||
|
// and https requests, respectively, in node.js. This allows options to be added like
|
||||||
|
// `keepAlive` that are not enabled by default.
|
||||||
|
httpAgent: new http.Agent({ keepAlive: true }),
|
||||||
|
httpsAgent: new https.Agent({ keepAlive: true }),
|
||||||
|
|
||||||
|
// 'proxy' defines the hostname and port of the proxy server
|
||||||
|
// `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
|
||||||
|
// supplies credentials.
|
||||||
|
// This will set an `Proxy-Authorization` header, overwriting any existing
|
||||||
|
// `Proxy-Authorization` custom headers you have set using `headers`.
|
||||||
|
proxy: {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 9000,
|
||||||
|
auth: {
|
||||||
|
username: 'mikeymike',
|
||||||
|
password: 'rapunz3l'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// `cancelToken` specifies a cancel token that can be used to cancel the request
|
||||||
|
// (see Cancellation section below for details)
|
||||||
|
cancelToken: new CancelToken(function (cancel) {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Response Schema
|
||||||
|
|
||||||
|
The response for a request contains the following information.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// `data` is the response that was provided by the server
|
||||||
|
data: {},
|
||||||
|
|
||||||
|
// `status` is the HTTP status code from the server response
|
||||||
|
status: 200,
|
||||||
|
|
||||||
|
// `statusText` is the HTTP status message from the server response
|
||||||
|
statusText: 'OK',
|
||||||
|
|
||||||
|
// `headers` the headers that the server responded with
|
||||||
|
// All header names are lower cased
|
||||||
|
headers: {},
|
||||||
|
|
||||||
|
// `config` is the config that was provided to `axios` for the request
|
||||||
|
config: {},
|
||||||
|
|
||||||
|
// `request` is the request that generated this response
|
||||||
|
// It is the last ClientRequest instance in node.js (in redirects)
|
||||||
|
// and an XMLHttpRequest instance the browser
|
||||||
|
request: {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When using `then`, you will receive the response as follows:
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.get('/user/12345')
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(response.data);
|
||||||
|
console.log(response.status);
|
||||||
|
console.log(response.statusText);
|
||||||
|
console.log(response.headers);
|
||||||
|
console.log(response.config);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as second parameter of `then`, the response will be available through the `error` object as explained in the [Handling Errors](#handling-errors) section.
|
||||||
|
|
||||||
|
## Config Defaults
|
||||||
|
|
||||||
|
You can specify config defaults that will be applied to every request.
|
||||||
|
|
||||||
|
### Global axios defaults
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.defaults.baseURL = 'https://api.example.com';
|
||||||
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
||||||
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom instance defaults
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Set config defaults when creating the instance
|
||||||
|
var instance = axios.create({
|
||||||
|
baseURL: 'https://api.example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Alter defaults after instance has been created
|
||||||
|
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config order of precedence
|
||||||
|
|
||||||
|
Config will be merged with an order of precedence. The order is library defaults found in `lib/defaults.js`, then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Create an instance using the config defaults provided by the library
|
||||||
|
// At this point the timeout config value is `0` as is the default for the library
|
||||||
|
var instance = axios.create();
|
||||||
|
|
||||||
|
// Override timeout default for the library
|
||||||
|
// Now all requests will wait 2.5 seconds before timing out
|
||||||
|
instance.defaults.timeout = 2500;
|
||||||
|
|
||||||
|
// Override timeout for this request as it's known to take a long time
|
||||||
|
instance.get('/longRequest', {
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Interceptors
|
||||||
|
|
||||||
|
You can intercept requests or responses before they are handled by `then` or `catch`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Add a request interceptor
|
||||||
|
axios.interceptors.request.use(function (config) {
|
||||||
|
// Do something before request is sent
|
||||||
|
return config;
|
||||||
|
}, function (error) {
|
||||||
|
// Do something with request error
|
||||||
|
return Promise.reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add a response interceptor
|
||||||
|
axios.interceptors.response.use(function (response) {
|
||||||
|
// Do something with response data
|
||||||
|
return response;
|
||||||
|
}, function (error) {
|
||||||
|
// Do something with response error
|
||||||
|
return Promise.reject(error);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
If you may need to remove an interceptor later you can.
|
||||||
|
|
||||||
|
```js
|
||||||
|
var myInterceptor = axios.interceptors.request.use(function () {/*...*/});
|
||||||
|
axios.interceptors.request.eject(myInterceptor);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can add interceptors to a custom instance of axios.
|
||||||
|
|
||||||
|
```js
|
||||||
|
var instance = axios.create();
|
||||||
|
instance.interceptors.request.use(function () {/*...*/});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Handling Errors
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.get('/user/12345')
|
||||||
|
.catch(function (error) {
|
||||||
|
if (error.response) {
|
||||||
|
// The request was made and the server responded with a status code
|
||||||
|
// that falls out of the range of 2xx
|
||||||
|
console.log(error.response.data);
|
||||||
|
console.log(error.response.status);
|
||||||
|
console.log(error.response.headers);
|
||||||
|
} else if (error.request) {
|
||||||
|
// The request was made but no response was received
|
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
|
// http.ClientRequest in node.js
|
||||||
|
console.log(error.request);
|
||||||
|
} else {
|
||||||
|
// Something happened in setting up the request that triggered an Error
|
||||||
|
console.log('Error', error.message);
|
||||||
|
}
|
||||||
|
console.log(error.config);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can define a custom HTTP status code error range using the `validateStatus` config option.
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.get('/user/12345', {
|
||||||
|
validateStatus: function (status) {
|
||||||
|
return status < 500; // Reject only if the status code is greater than or equal to 500
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cancellation
|
||||||
|
|
||||||
|
You can cancel a request using a *cancel token*.
|
||||||
|
|
||||||
|
> The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
|
||||||
|
|
||||||
|
You can create a cancel token using the `CancelToken.source` factory as shown below:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var CancelToken = axios.CancelToken;
|
||||||
|
var source = CancelToken.source();
|
||||||
|
|
||||||
|
axios.get('/user/12345', {
|
||||||
|
cancelToken: source.token
|
||||||
|
}).catch(function(thrown) {
|
||||||
|
if (axios.isCancel(thrown)) {
|
||||||
|
console.log('Request canceled', thrown.message);
|
||||||
|
} else {
|
||||||
|
// handle error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// cancel the request (the message parameter is optional)
|
||||||
|
source.cancel('Operation canceled by the user.');
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var CancelToken = axios.CancelToken;
|
||||||
|
var cancel;
|
||||||
|
|
||||||
|
axios.get('/user/12345', {
|
||||||
|
cancelToken: new CancelToken(function executor(c) {
|
||||||
|
// An executor function receives a cancel function as a parameter
|
||||||
|
cancel = c;
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// cancel the request
|
||||||
|
cancel();
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note: you can cancel several requests with the same cancel token.
|
||||||
|
|
||||||
|
## Using application/x-www-form-urlencoded format
|
||||||
|
|
||||||
|
By default, axios serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options.
|
||||||
|
|
||||||
|
### Browser
|
||||||
|
|
||||||
|
In a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as follows:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var params = new URLSearchParams();
|
||||||
|
params.append('param1', 'value1');
|
||||||
|
params.append('param2', 'value2');
|
||||||
|
axios.post('/foo', params);
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note that `URLSearchParams` is not supported by all browsers, but there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).
|
||||||
|
|
||||||
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var qs = require('qs');
|
||||||
|
axios.post('/foo', qs.stringify({ 'bar': 123 }));
|
||||||
|
```
|
||||||
|
|
||||||
|
### Node.js
|
||||||
|
|
||||||
|
In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var querystring = require('querystring');
|
||||||
|
axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the `qs` library.
|
||||||
|
|
||||||
|
## Semver
|
||||||
|
|
||||||
|
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
|
||||||
|
|
||||||
|
## Promises
|
||||||
|
|
||||||
|
axios depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises).
|
||||||
|
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
|
||||||
|
|
||||||
|
## TypeScript
|
||||||
|
axios includes [TypeScript](http://typescriptlang.org) definitions.
|
||||||
|
```typescript
|
||||||
|
import axios from 'axios';
|
||||||
|
axios.get('/user?ID=12345');
|
||||||
|
```
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
* [Changelog](https://github.com/mzabriskie/axios/blob/master/CHANGELOG.md)
|
||||||
|
* [Upgrade Guide](https://github.com/mzabriskie/axios/blob/master/UPGRADE_GUIDE.md)
|
||||||
|
* [Ecosystem](https://github.com/mzabriskie/axios/blob/master/ECOSYSTEM.md)
|
||||||
|
* [Contributing Guide](https://github.com/mzabriskie/axios/blob/master/CONTRIBUTING.md)
|
||||||
|
* [Code of Conduct](https://github.com/mzabriskie/axios/blob/master/CODE_OF_CONDUCT.md)
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [Angular](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of Angular.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
162
node_modules/axios/UPGRADE_GUIDE.md
generated
vendored
Normal file
162
node_modules/axios/UPGRADE_GUIDE.md
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
# Upgrade Guide
|
||||||
|
|
||||||
|
### 0.15.x -> 0.16.0
|
||||||
|
|
||||||
|
#### `Promise` Type Declarations
|
||||||
|
|
||||||
|
The `Promise` type declarations have been removed from the axios typings in favor of the built-in type declarations. If you use axios in a TypeScript project that targets `ES5`, please make sure to include the `es2015.promise` lib. Please see [this post](https://blog.mariusschulz.com/2016/11/25/typescript-2-0-built-in-type-declarations) for details.
|
||||||
|
|
||||||
|
### 0.13.x -> 0.14.0
|
||||||
|
|
||||||
|
#### TypeScript Definitions
|
||||||
|
|
||||||
|
The axios TypeScript definitions have been updated to match the axios API and use the ES2015 module syntax.
|
||||||
|
|
||||||
|
Please use the following `import` statement to import axios in TypeScript:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
axios.get('/foo')
|
||||||
|
.then(response => console.log(response))
|
||||||
|
.catch(error => console.log(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `agent` Config Option
|
||||||
|
|
||||||
|
The `agent` config option has been replaced with two new options: `httpAgent` and `httpsAgent`. Please use them instead.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// Define a custom agent for HTTP
|
||||||
|
httpAgent: new http.Agent({ keepAlive: true }),
|
||||||
|
// Define a custom agent for HTTPS
|
||||||
|
httpsAgent: new https.Agent({ keepAlive: true })
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `progress` Config Option
|
||||||
|
|
||||||
|
The `progress` config option has been replaced with the `onUploadProgress` and `onDownloadProgress` options.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// Define a handler for upload progress events
|
||||||
|
onUploadProgress: function (progressEvent) {
|
||||||
|
// ...
|
||||||
|
},
|
||||||
|
|
||||||
|
// Define a handler for download progress events
|
||||||
|
onDownloadProgress: function (progressEvent) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 0.12.x -> 0.13.0
|
||||||
|
|
||||||
|
The `0.13.0` release contains several changes to custom adapters and error handling.
|
||||||
|
|
||||||
|
#### Error Handling
|
||||||
|
|
||||||
|
Previous to this release an error could either be a server response with bad status code or an actual `Error`. With this release Promise will always reject with an `Error`. In the case that a response was received, the `Error` will also include the response.
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.get('/user/12345')
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error.message);
|
||||||
|
console.log(error.code); // Not always specified
|
||||||
|
console.log(error.config); // The config that was used to make the request
|
||||||
|
console.log(error.response); // Only available if response was received from the server
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Request Adapters
|
||||||
|
|
||||||
|
This release changes a few things about how request adapters work. Please take note if you are using your own custom adapter.
|
||||||
|
|
||||||
|
1. Response transformer is now called outside of adapter.
|
||||||
|
2. Request adapter returns a `Promise`.
|
||||||
|
|
||||||
|
This means that you no longer need to invoke `transformData` on response data. You will also no longer receive `resolve` and `reject` as arguments in your adapter.
|
||||||
|
|
||||||
|
Previous code:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function myAdapter(resolve, reject, config) {
|
||||||
|
var response = {
|
||||||
|
data: transformData(
|
||||||
|
responseData,
|
||||||
|
responseHeaders,
|
||||||
|
config.transformResponse
|
||||||
|
),
|
||||||
|
status: request.status,
|
||||||
|
statusText: request.statusText,
|
||||||
|
headers: responseHeaders
|
||||||
|
};
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
New code:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function myAdapter(config) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var response = {
|
||||||
|
data: responseData,
|
||||||
|
status: request.status,
|
||||||
|
statusText: request.statusText,
|
||||||
|
headers: responseHeaders
|
||||||
|
};
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the related commits for more details:
|
||||||
|
- [Response transformers](https://github.com/mzabriskie/axios/commit/10eb23865101f9347570552c04e9d6211376e25e)
|
||||||
|
- [Request adapter Promise](https://github.com/mzabriskie/axios/commit/157efd5615890301824e3121cc6c9d2f9b21f94a)
|
||||||
|
|
||||||
|
### 0.5.x -> 0.6.0
|
||||||
|
|
||||||
|
The `0.6.0` release contains mostly bug fixes, but there are a couple things to be aware of when upgrading.
|
||||||
|
|
||||||
|
#### ES6 Promise Polyfill
|
||||||
|
|
||||||
|
Up until the `0.6.0` release ES6 `Promise` was being polyfilled using [es6-promise](https://github.com/jakearchibald/es6-promise). With this release, the polyfill has been removed, and you will need to supply it yourself if your environment needs it.
|
||||||
|
|
||||||
|
```js
|
||||||
|
require('es6-promise').polyfill();
|
||||||
|
var axios = require('axios');
|
||||||
|
```
|
||||||
|
|
||||||
|
This will polyfill the global environment, and only needs to be done once.
|
||||||
|
|
||||||
|
#### `axios.success`/`axios.error`
|
||||||
|
|
||||||
|
The `success`, and `error` aliases were deprectated in [0.4.0](https://github.com/mzabriskie/axios/blob/master/CHANGELOG.md#040-oct-03-2014). As of this release they have been removed entirely. Instead please use `axios.then`, and `axios.catch` respectively.
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.get('some/url')
|
||||||
|
.then(function (res) {
|
||||||
|
/* ... */
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
/* ... */
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### UMD
|
||||||
|
|
||||||
|
Previous versions of axios shipped with an AMD, CommonJS, and Global build. This has all been rolled into a single UMD build.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// AMD
|
||||||
|
require(['bower_components/axios/dist/axios'], function (axios) {
|
||||||
|
/* ... */
|
||||||
|
});
|
||||||
|
|
||||||
|
// CommonJS
|
||||||
|
var axios = require('axios/dist/axios');
|
||||||
|
```
|
1585
node_modules/axios/dist/axios.js
generated
vendored
Normal file
1585
node_modules/axios/dist/axios.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/axios/dist/axios.map
generated
vendored
Normal file
1
node_modules/axios/dist/axios.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
9
node_modules/axios/dist/axios.min.js
generated
vendored
Normal file
9
node_modules/axios/dist/axios.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/axios/dist/axios.min.map
generated
vendored
Normal file
1
node_modules/axios/dist/axios.min.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
125
node_modules/axios/index.d.ts
generated
vendored
Normal file
125
node_modules/axios/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
export interface AxiosTransformer {
|
||||||
|
(data: any): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosAdapter {
|
||||||
|
(config: AxiosRequestConfig): AxiosPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosBasicCredentials {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosProxyConfig {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosRequestConfig {
|
||||||
|
url?: string;
|
||||||
|
method?: string;
|
||||||
|
baseURL?: string;
|
||||||
|
transformRequest?: AxiosTransformer | AxiosTransformer[];
|
||||||
|
transformResponse?: AxiosTransformer | AxiosTransformer[];
|
||||||
|
headers?: any;
|
||||||
|
params?: any;
|
||||||
|
paramsSerializer?: (params: any) => string;
|
||||||
|
data?: any;
|
||||||
|
timeout?: number;
|
||||||
|
withCredentials?: boolean;
|
||||||
|
adapter?: AxiosAdapter;
|
||||||
|
auth?: AxiosBasicCredentials;
|
||||||
|
responseType?: string;
|
||||||
|
xsrfCookieName?: string;
|
||||||
|
xsrfHeaderName?: string;
|
||||||
|
onUploadProgress?: (progressEvent: any) => void;
|
||||||
|
onDownloadProgress?: (progressEvent: any) => void;
|
||||||
|
maxContentLength?: number;
|
||||||
|
validateStatus?: (status: number) => boolean;
|
||||||
|
maxRedirects?: number;
|
||||||
|
httpAgent?: any;
|
||||||
|
httpsAgent?: any;
|
||||||
|
proxy?: AxiosProxyConfig;
|
||||||
|
cancelToken?: CancelToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosResponse {
|
||||||
|
data: any;
|
||||||
|
status: number;
|
||||||
|
statusText: string;
|
||||||
|
headers: any;
|
||||||
|
config: AxiosRequestConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosError extends Error {
|
||||||
|
config: AxiosRequestConfig;
|
||||||
|
code?: string;
|
||||||
|
response?: AxiosResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosPromise extends Promise<AxiosResponse> {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelStatic {
|
||||||
|
new (message?: string): Cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Cancel {
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Canceler {
|
||||||
|
(message?: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelTokenStatic {
|
||||||
|
new (executor: (cancel: Canceler) => void): CancelToken;
|
||||||
|
source(): CancelTokenSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelToken {
|
||||||
|
promise: Promise<Cancel>;
|
||||||
|
reason?: Cancel;
|
||||||
|
throwIfRequested(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelTokenSource {
|
||||||
|
token: CancelToken;
|
||||||
|
cancel: Canceler;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosInterceptorManager<V> {
|
||||||
|
use(onFulfilled: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
|
||||||
|
eject(id: number): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosInstance {
|
||||||
|
defaults: AxiosRequestConfig;
|
||||||
|
interceptors: {
|
||||||
|
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
||||||
|
response: AxiosInterceptorManager<AxiosResponse>;
|
||||||
|
};
|
||||||
|
request(config: AxiosRequestConfig): AxiosPromise;
|
||||||
|
get(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
head(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AxiosStatic extends AxiosInstance {
|
||||||
|
(config: AxiosRequestConfig): AxiosPromise;
|
||||||
|
(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
||||||
|
create(config?: AxiosRequestConfig): AxiosInstance;
|
||||||
|
Cancel: CancelStatic;
|
||||||
|
CancelToken: CancelTokenStatic;
|
||||||
|
isCancel(value: any): boolean;
|
||||||
|
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
|
||||||
|
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare const Axios: AxiosStatic;
|
||||||
|
|
||||||
|
export default Axios;
|
1
node_modules/axios/index.js
generated
vendored
Normal file
1
node_modules/axios/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./lib/axios');
|
37
node_modules/axios/lib/adapters/README.md
generated
vendored
Normal file
37
node_modules/axios/lib/adapters/README.md
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# axios // adapters
|
||||||
|
|
||||||
|
The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
var settle = require('./../core/settle');
|
||||||
|
|
||||||
|
module.exports = function myAdapter(config) {
|
||||||
|
// At this point:
|
||||||
|
// - config has been merged with defaults
|
||||||
|
// - request transformers have already run
|
||||||
|
// - request interceptors have already run
|
||||||
|
|
||||||
|
// Make the request using config provided
|
||||||
|
// Upon response settle the Promise
|
||||||
|
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
||||||
|
var response = {
|
||||||
|
data: responseData,
|
||||||
|
status: request.status,
|
||||||
|
statusText: request.statusText,
|
||||||
|
headers: responseHeaders,
|
||||||
|
config: config,
|
||||||
|
request: request
|
||||||
|
};
|
||||||
|
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
|
||||||
|
// From here:
|
||||||
|
// - response transformers will run
|
||||||
|
// - response interceptors will run
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
231
node_modules/axios/lib/adapters/http.js
generated
vendored
Normal file
231
node_modules/axios/lib/adapters/http.js
generated
vendored
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
var settle = require('./../core/settle');
|
||||||
|
var buildURL = require('./../helpers/buildURL');
|
||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var httpFollow = require('follow-redirects').http;
|
||||||
|
var httpsFollow = require('follow-redirects').https;
|
||||||
|
var url = require('url');
|
||||||
|
var zlib = require('zlib');
|
||||||
|
var pkg = require('./../../package.json');
|
||||||
|
var createError = require('../core/createError');
|
||||||
|
var enhanceError = require('../core/enhanceError');
|
||||||
|
|
||||||
|
/*eslint consistent-return:0*/
|
||||||
|
module.exports = function httpAdapter(config) {
|
||||||
|
return new Promise(function dispatchHttpRequest(resolve, reject) {
|
||||||
|
var data = config.data;
|
||||||
|
var headers = config.headers;
|
||||||
|
var timer;
|
||||||
|
var aborted = false;
|
||||||
|
|
||||||
|
// Set User-Agent (required by some servers)
|
||||||
|
// Only set header if it hasn't been set in config
|
||||||
|
// See https://github.com/mzabriskie/axios/issues/69
|
||||||
|
if (!headers['User-Agent'] && !headers['user-agent']) {
|
||||||
|
headers['User-Agent'] = 'axios/' + pkg.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data && !utils.isStream(data)) {
|
||||||
|
if (Buffer.isBuffer(data)) {
|
||||||
|
// Nothing to do...
|
||||||
|
} else if (utils.isArrayBuffer(data)) {
|
||||||
|
data = new Buffer(new Uint8Array(data));
|
||||||
|
} else if (utils.isString(data)) {
|
||||||
|
data = new Buffer(data, 'utf-8');
|
||||||
|
} else {
|
||||||
|
return reject(createError(
|
||||||
|
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
||||||
|
config
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Content-Length header if data exists
|
||||||
|
headers['Content-Length'] = data.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
var auth = undefined;
|
||||||
|
if (config.auth) {
|
||||||
|
var username = config.auth.username || '';
|
||||||
|
var password = config.auth.password || '';
|
||||||
|
auth = username + ':' + password;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse url
|
||||||
|
var parsed = url.parse(config.url);
|
||||||
|
var protocol = parsed.protocol || 'http:';
|
||||||
|
|
||||||
|
if (!auth && parsed.auth) {
|
||||||
|
var urlAuth = parsed.auth.split(':');
|
||||||
|
var urlUsername = urlAuth[0] || '';
|
||||||
|
var urlPassword = urlAuth[1] || '';
|
||||||
|
auth = urlUsername + ':' + urlPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auth) {
|
||||||
|
delete headers.Authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isHttps = protocol === 'https:';
|
||||||
|
var agent = isHttps ? config.httpsAgent : config.httpAgent;
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
hostname: parsed.hostname,
|
||||||
|
port: parsed.port,
|
||||||
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
|
method: config.method,
|
||||||
|
headers: headers,
|
||||||
|
agent: agent,
|
||||||
|
auth: auth
|
||||||
|
};
|
||||||
|
|
||||||
|
var proxy = config.proxy;
|
||||||
|
if (!proxy) {
|
||||||
|
var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
||||||
|
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
|
||||||
|
if (proxyUrl) {
|
||||||
|
var parsedProxyUrl = url.parse(proxyUrl);
|
||||||
|
proxy = {
|
||||||
|
host: parsedProxyUrl.hostname,
|
||||||
|
port: parsedProxyUrl.port
|
||||||
|
};
|
||||||
|
|
||||||
|
if (parsedProxyUrl.auth) {
|
||||||
|
var proxyUrlAuth = parsedProxyUrl.auth.split(':');
|
||||||
|
proxy.auth = {
|
||||||
|
username: proxyUrlAuth[0],
|
||||||
|
password: proxyUrlAuth[1]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proxy) {
|
||||||
|
options.hostname = proxy.host;
|
||||||
|
options.host = proxy.host;
|
||||||
|
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
||||||
|
options.port = proxy.port;
|
||||||
|
options.path = protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path;
|
||||||
|
|
||||||
|
// Basic proxy authorization
|
||||||
|
if (proxy.auth) {
|
||||||
|
var base64 = new Buffer(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
||||||
|
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var transport;
|
||||||
|
if (config.maxRedirects === 0) {
|
||||||
|
transport = isHttps ? https : http;
|
||||||
|
} else {
|
||||||
|
if (config.maxRedirects) {
|
||||||
|
options.maxRedirects = config.maxRedirects;
|
||||||
|
}
|
||||||
|
transport = isHttps ? httpsFollow : httpFollow;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the request
|
||||||
|
var req = transport.request(options, function handleResponse(res) {
|
||||||
|
if (aborted) return;
|
||||||
|
|
||||||
|
// Response has been received so kill timer that handles request timeout
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
|
||||||
|
// uncompress the response body transparently if required
|
||||||
|
var stream = res;
|
||||||
|
switch (res.headers['content-encoding']) {
|
||||||
|
/*eslint default-case:0*/
|
||||||
|
case 'gzip':
|
||||||
|
case 'compress':
|
||||||
|
case 'deflate':
|
||||||
|
// add the unzipper to the body stream processing pipeline
|
||||||
|
stream = stream.pipe(zlib.createUnzip());
|
||||||
|
|
||||||
|
// remove the content-encoding in order to not confuse downstream operations
|
||||||
|
delete res.headers['content-encoding'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the last request in case of redirects
|
||||||
|
var lastRequest = res.req || req;
|
||||||
|
|
||||||
|
var response = {
|
||||||
|
status: res.statusCode,
|
||||||
|
statusText: res.statusMessage,
|
||||||
|
headers: res.headers,
|
||||||
|
config: config,
|
||||||
|
request: lastRequest
|
||||||
|
};
|
||||||
|
|
||||||
|
if (config.responseType === 'stream') {
|
||||||
|
response.data = stream;
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
} else {
|
||||||
|
var responseBuffer = [];
|
||||||
|
stream.on('data', function handleStreamData(chunk) {
|
||||||
|
responseBuffer.push(chunk);
|
||||||
|
|
||||||
|
// make sure the content length is not over the maxContentLength if specified
|
||||||
|
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
|
||||||
|
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||||
|
config, null, lastRequest));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('error', function handleStreamError(err) {
|
||||||
|
if (aborted) return;
|
||||||
|
reject(enhanceError(err, config, null, lastRequest));
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('end', function handleStreamEnd() {
|
||||||
|
var responseData = Buffer.concat(responseBuffer);
|
||||||
|
if (config.responseType !== 'arraybuffer') {
|
||||||
|
responseData = responseData.toString('utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
response.data = responseData;
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle errors
|
||||||
|
req.on('error', function handleRequestError(err) {
|
||||||
|
if (aborted) return;
|
||||||
|
reject(enhanceError(err, config, null, req));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle request timeout
|
||||||
|
if (config.timeout && !timer) {
|
||||||
|
timer = setTimeout(function handleRequestTimeout() {
|
||||||
|
req.abort();
|
||||||
|
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
||||||
|
aborted = true;
|
||||||
|
}, config.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.cancelToken) {
|
||||||
|
// Handle cancellation
|
||||||
|
config.cancelToken.promise.then(function onCanceled(cancel) {
|
||||||
|
if (aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
req.abort();
|
||||||
|
reject(cancel);
|
||||||
|
aborted = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
if (utils.isStream(data)) {
|
||||||
|
data.pipe(req);
|
||||||
|
} else {
|
||||||
|
req.end(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
180
node_modules/axios/lib/adapters/xhr.js
generated
vendored
Normal file
180
node_modules/axios/lib/adapters/xhr.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
var settle = require('./../core/settle');
|
||||||
|
var buildURL = require('./../helpers/buildURL');
|
||||||
|
var parseHeaders = require('./../helpers/parseHeaders');
|
||||||
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||||
|
var createError = require('../core/createError');
|
||||||
|
var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || require('./../helpers/btoa');
|
||||||
|
|
||||||
|
module.exports = function xhrAdapter(config) {
|
||||||
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||||
|
var requestData = config.data;
|
||||||
|
var requestHeaders = config.headers;
|
||||||
|
|
||||||
|
if (utils.isFormData(requestData)) {
|
||||||
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
var loadEvent = 'onreadystatechange';
|
||||||
|
var xDomain = false;
|
||||||
|
|
||||||
|
// For IE 8/9 CORS support
|
||||||
|
// Only supports POST and GET calls and doesn't returns the response headers.
|
||||||
|
// DON'T do this for testing b/c XMLHttpRequest is mocked, not XDomainRequest.
|
||||||
|
if (process.env.NODE_ENV !== 'test' &&
|
||||||
|
typeof window !== 'undefined' &&
|
||||||
|
window.XDomainRequest && !('withCredentials' in request) &&
|
||||||
|
!isURLSameOrigin(config.url)) {
|
||||||
|
request = new window.XDomainRequest();
|
||||||
|
loadEvent = 'onload';
|
||||||
|
xDomain = true;
|
||||||
|
request.onprogress = function handleProgress() {};
|
||||||
|
request.ontimeout = function handleTimeout() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
if (config.auth) {
|
||||||
|
var username = config.auth.username || '';
|
||||||
|
var password = config.auth.password || '';
|
||||||
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||||
|
}
|
||||||
|
|
||||||
|
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
|
||||||
|
|
||||||
|
// Set the request timeout in MS
|
||||||
|
request.timeout = config.timeout;
|
||||||
|
|
||||||
|
// Listen for ready state
|
||||||
|
request[loadEvent] = function handleLoad() {
|
||||||
|
if (!request || (request.readyState !== 4 && !xDomain)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The request errored out and we didn't get a response, this will be
|
||||||
|
// handled by onerror instead
|
||||||
|
// With one exception: request that using file: protocol, most browsers
|
||||||
|
// will return status as 0 even though it's a successful request
|
||||||
|
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare the response
|
||||||
|
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
||||||
|
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
|
||||||
|
var response = {
|
||||||
|
data: responseData,
|
||||||
|
// IE sends 1223 instead of 204 (https://github.com/mzabriskie/axios/issues/201)
|
||||||
|
status: request.status === 1223 ? 204 : request.status,
|
||||||
|
statusText: request.status === 1223 ? 'No Content' : request.statusText,
|
||||||
|
headers: responseHeaders,
|
||||||
|
config: config,
|
||||||
|
request: request
|
||||||
|
};
|
||||||
|
|
||||||
|
settle(resolve, reject, response);
|
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle low level network errors
|
||||||
|
request.onerror = function handleError() {
|
||||||
|
// Real errors are hidden from us by the browser
|
||||||
|
// onerror should only fire if it's a network error
|
||||||
|
reject(createError('Network Error', config, null, request));
|
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle timeout
|
||||||
|
request.ontimeout = function handleTimeout() {
|
||||||
|
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED',
|
||||||
|
request));
|
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add xsrf header
|
||||||
|
// This is only done if running in a standard browser environment.
|
||||||
|
// Specifically not if we're in a web worker, or react-native.
|
||||||
|
if (utils.isStandardBrowserEnv()) {
|
||||||
|
var cookies = require('./../helpers/cookies');
|
||||||
|
|
||||||
|
// Add xsrf header
|
||||||
|
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
|
||||||
|
cookies.read(config.xsrfCookieName) :
|
||||||
|
undefined;
|
||||||
|
|
||||||
|
if (xsrfValue) {
|
||||||
|
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add headers to the request
|
||||||
|
if ('setRequestHeader' in request) {
|
||||||
|
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
||||||
|
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
||||||
|
// Remove Content-Type if data is undefined
|
||||||
|
delete requestHeaders[key];
|
||||||
|
} else {
|
||||||
|
// Otherwise add header to the request
|
||||||
|
request.setRequestHeader(key, val);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add withCredentials to request if needed
|
||||||
|
if (config.withCredentials) {
|
||||||
|
request.withCredentials = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add responseType to request if needed
|
||||||
|
if (config.responseType) {
|
||||||
|
try {
|
||||||
|
request.responseType = config.responseType;
|
||||||
|
} catch (e) {
|
||||||
|
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
||||||
|
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
||||||
|
if (config.responseType !== 'json') {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle progress if needed
|
||||||
|
if (typeof config.onDownloadProgress === 'function') {
|
||||||
|
request.addEventListener('progress', config.onDownloadProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not all browsers support upload events
|
||||||
|
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
||||||
|
request.upload.addEventListener('progress', config.onUploadProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.cancelToken) {
|
||||||
|
// Handle cancellation
|
||||||
|
config.cancelToken.promise.then(function onCanceled(cancel) {
|
||||||
|
if (!request) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.abort();
|
||||||
|
reject(cancel);
|
||||||
|
// Clean up request
|
||||||
|
request = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestData === undefined) {
|
||||||
|
requestData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
request.send(requestData);
|
||||||
|
});
|
||||||
|
};
|
52
node_modules/axios/lib/axios.js
generated
vendored
Normal file
52
node_modules/axios/lib/axios.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./utils');
|
||||||
|
var bind = require('./helpers/bind');
|
||||||
|
var Axios = require('./core/Axios');
|
||||||
|
var defaults = require('./defaults');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of Axios
|
||||||
|
*
|
||||||
|
* @param {Object} defaultConfig The default config for the instance
|
||||||
|
* @return {Axios} A new instance of Axios
|
||||||
|
*/
|
||||||
|
function createInstance(defaultConfig) {
|
||||||
|
var context = new Axios(defaultConfig);
|
||||||
|
var instance = bind(Axios.prototype.request, context);
|
||||||
|
|
||||||
|
// Copy axios.prototype to instance
|
||||||
|
utils.extend(instance, Axios.prototype, context);
|
||||||
|
|
||||||
|
// Copy context to instance
|
||||||
|
utils.extend(instance, context);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the default instance to be exported
|
||||||
|
var axios = createInstance(defaults);
|
||||||
|
|
||||||
|
// Expose Axios class to allow class inheritance
|
||||||
|
axios.Axios = Axios;
|
||||||
|
|
||||||
|
// Factory for creating new instances
|
||||||
|
axios.create = function create(instanceConfig) {
|
||||||
|
return createInstance(utils.merge(defaults, instanceConfig));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Expose Cancel & CancelToken
|
||||||
|
axios.Cancel = require('./cancel/Cancel');
|
||||||
|
axios.CancelToken = require('./cancel/CancelToken');
|
||||||
|
axios.isCancel = require('./cancel/isCancel');
|
||||||
|
|
||||||
|
// Expose all/spread
|
||||||
|
axios.all = function all(promises) {
|
||||||
|
return Promise.all(promises);
|
||||||
|
};
|
||||||
|
axios.spread = require('./helpers/spread');
|
||||||
|
|
||||||
|
module.exports = axios;
|
||||||
|
|
||||||
|
// Allow use of default import syntax in TypeScript
|
||||||
|
module.exports.default = axios;
|
19
node_modules/axios/lib/cancel/Cancel.js
generated
vendored
Normal file
19
node_modules/axios/lib/cancel/Cancel.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A `Cancel` is an object that is thrown when an operation is canceled.
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @param {string=} message The message.
|
||||||
|
*/
|
||||||
|
function Cancel(message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cancel.prototype.toString = function toString() {
|
||||||
|
return 'Cancel' + (this.message ? ': ' + this.message : '');
|
||||||
|
};
|
||||||
|
|
||||||
|
Cancel.prototype.__CANCEL__ = true;
|
||||||
|
|
||||||
|
module.exports = Cancel;
|
57
node_modules/axios/lib/cancel/CancelToken.js
generated
vendored
Normal file
57
node_modules/axios/lib/cancel/CancelToken.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Cancel = require('./Cancel');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @param {Function} executor The executor function.
|
||||||
|
*/
|
||||||
|
function CancelToken(executor) {
|
||||||
|
if (typeof executor !== 'function') {
|
||||||
|
throw new TypeError('executor must be a function.');
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolvePromise;
|
||||||
|
this.promise = new Promise(function promiseExecutor(resolve) {
|
||||||
|
resolvePromise = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
var token = this;
|
||||||
|
executor(function cancel(message) {
|
||||||
|
if (token.reason) {
|
||||||
|
// Cancellation has already been requested
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
token.reason = new Cancel(message);
|
||||||
|
resolvePromise(token.reason);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws a `Cancel` if cancellation has been requested.
|
||||||
|
*/
|
||||||
|
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
||||||
|
if (this.reason) {
|
||||||
|
throw this.reason;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
||||||
|
* cancels the `CancelToken`.
|
||||||
|
*/
|
||||||
|
CancelToken.source = function source() {
|
||||||
|
var cancel;
|
||||||
|
var token = new CancelToken(function executor(c) {
|
||||||
|
cancel = c;
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
token: token,
|
||||||
|
cancel: cancel
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = CancelToken;
|
5
node_modules/axios/lib/cancel/isCancel.js
generated
vendored
Normal file
5
node_modules/axios/lib/cancel/isCancel.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function isCancel(value) {
|
||||||
|
return !!(value && value.__CANCEL__);
|
||||||
|
};
|
86
node_modules/axios/lib/core/Axios.js
generated
vendored
Normal file
86
node_modules/axios/lib/core/Axios.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var defaults = require('./../defaults');
|
||||||
|
var utils = require('./../utils');
|
||||||
|
var InterceptorManager = require('./InterceptorManager');
|
||||||
|
var dispatchRequest = require('./dispatchRequest');
|
||||||
|
var isAbsoluteURL = require('./../helpers/isAbsoluteURL');
|
||||||
|
var combineURLs = require('./../helpers/combineURLs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of Axios
|
||||||
|
*
|
||||||
|
* @param {Object} instanceConfig The default config for the instance
|
||||||
|
*/
|
||||||
|
function Axios(instanceConfig) {
|
||||||
|
this.defaults = instanceConfig;
|
||||||
|
this.interceptors = {
|
||||||
|
request: new InterceptorManager(),
|
||||||
|
response: new InterceptorManager()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch a request
|
||||||
|
*
|
||||||
|
* @param {Object} config The config specific for this request (merged with this.defaults)
|
||||||
|
*/
|
||||||
|
Axios.prototype.request = function request(config) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
// Allow for axios('example/url'[, config]) a la fetch API
|
||||||
|
if (typeof config === 'string') {
|
||||||
|
config = utils.merge({
|
||||||
|
url: arguments[0]
|
||||||
|
}, arguments[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
config = utils.merge(defaults, this.defaults, { method: 'get' }, config);
|
||||||
|
config.method = config.method.toLowerCase();
|
||||||
|
|
||||||
|
// Support baseURL config
|
||||||
|
if (config.baseURL && !isAbsoluteURL(config.url)) {
|
||||||
|
config.url = combineURLs(config.baseURL, config.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook up interceptors middleware
|
||||||
|
var chain = [dispatchRequest, undefined];
|
||||||
|
var promise = Promise.resolve(config);
|
||||||
|
|
||||||
|
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
||||||
|
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
||||||
|
chain.push(interceptor.fulfilled, interceptor.rejected);
|
||||||
|
});
|
||||||
|
|
||||||
|
while (chain.length) {
|
||||||
|
promise = promise.then(chain.shift(), chain.shift());
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Provide aliases for supported request methods
|
||||||
|
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
||||||
|
/*eslint func-names:0*/
|
||||||
|
Axios.prototype[method] = function(url, config) {
|
||||||
|
return this.request(utils.merge(config || {}, {
|
||||||
|
method: method,
|
||||||
|
url: url
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||||
|
/*eslint func-names:0*/
|
||||||
|
Axios.prototype[method] = function(url, data, config) {
|
||||||
|
return this.request(utils.merge(config || {}, {
|
||||||
|
method: method,
|
||||||
|
url: url,
|
||||||
|
data: data
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Axios;
|
52
node_modules/axios/lib/core/InterceptorManager.js
generated
vendored
Normal file
52
node_modules/axios/lib/core/InterceptorManager.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
function InterceptorManager() {
|
||||||
|
this.handlers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new interceptor to the stack
|
||||||
|
*
|
||||||
|
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
||||||
|
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
||||||
|
*
|
||||||
|
* @return {Number} An ID used to remove interceptor later
|
||||||
|
*/
|
||||||
|
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
||||||
|
this.handlers.push({
|
||||||
|
fulfilled: fulfilled,
|
||||||
|
rejected: rejected
|
||||||
|
});
|
||||||
|
return this.handlers.length - 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an interceptor from the stack
|
||||||
|
*
|
||||||
|
* @param {Number} id The ID that was returned by `use`
|
||||||
|
*/
|
||||||
|
InterceptorManager.prototype.eject = function eject(id) {
|
||||||
|
if (this.handlers[id]) {
|
||||||
|
this.handlers[id] = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate over all the registered interceptors
|
||||||
|
*
|
||||||
|
* This method is particularly useful for skipping over any
|
||||||
|
* interceptors that may have become `null` calling `eject`.
|
||||||
|
*
|
||||||
|
* @param {Function} fn The function to call for each interceptor
|
||||||
|
*/
|
||||||
|
InterceptorManager.prototype.forEach = function forEach(fn) {
|
||||||
|
utils.forEach(this.handlers, function forEachHandler(h) {
|
||||||
|
if (h !== null) {
|
||||||
|
fn(h);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = InterceptorManager;
|
7
node_modules/axios/lib/core/README.md
generated
vendored
Normal file
7
node_modules/axios/lib/core/README.md
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# axios // core
|
||||||
|
|
||||||
|
The modules found in `core/` should be modules that are specific to the domain logic of axios. These modules would most likely not make sense to be consumed outside of the axios module, as their logic is too specific. Some examples of core modules are:
|
||||||
|
|
||||||
|
- Dispatching requests
|
||||||
|
- Managing interceptors
|
||||||
|
- Handling config
|
18
node_modules/axios/lib/core/createError.js
generated
vendored
Normal file
18
node_modules/axios/lib/core/createError.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var enhanceError = require('./enhanceError');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an Error with the specified message, config, error code, request and response.
|
||||||
|
*
|
||||||
|
* @param {string} message The error message.
|
||||||
|
* @param {Object} config The config.
|
||||||
|
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
||||||
|
* @param {Object} [request] The request.
|
||||||
|
* @param {Object} [response] The response.
|
||||||
|
* @returns {Error} The created error.
|
||||||
|
*/
|
||||||
|
module.exports = function createError(message, config, code, request, response) {
|
||||||
|
var error = new Error(message);
|
||||||
|
return enhanceError(error, config, code, request, response);
|
||||||
|
};
|
79
node_modules/axios/lib/core/dispatchRequest.js
generated
vendored
Normal file
79
node_modules/axios/lib/core/dispatchRequest.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
var transformData = require('./transformData');
|
||||||
|
var isCancel = require('../cancel/isCancel');
|
||||||
|
var defaults = require('../defaults');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws a `Cancel` if cancellation has been requested.
|
||||||
|
*/
|
||||||
|
function throwIfCancellationRequested(config) {
|
||||||
|
if (config.cancelToken) {
|
||||||
|
config.cancelToken.throwIfRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch a request to the server using the configured adapter.
|
||||||
|
*
|
||||||
|
* @param {object} config The config that is to be used for the request
|
||||||
|
* @returns {Promise} The Promise to be fulfilled
|
||||||
|
*/
|
||||||
|
module.exports = function dispatchRequest(config) {
|
||||||
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
|
// Ensure headers exist
|
||||||
|
config.headers = config.headers || {};
|
||||||
|
|
||||||
|
// Transform request data
|
||||||
|
config.data = transformData(
|
||||||
|
config.data,
|
||||||
|
config.headers,
|
||||||
|
config.transformRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
// Flatten headers
|
||||||
|
config.headers = utils.merge(
|
||||||
|
config.headers.common || {},
|
||||||
|
config.headers[config.method] || {},
|
||||||
|
config.headers || {}
|
||||||
|
);
|
||||||
|
|
||||||
|
utils.forEach(
|
||||||
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
||||||
|
function cleanHeaderConfig(method) {
|
||||||
|
delete config.headers[method];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var adapter = config.adapter || defaults.adapter;
|
||||||
|
|
||||||
|
return adapter(config).then(function onAdapterResolution(response) {
|
||||||
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
|
// Transform response data
|
||||||
|
response.data = transformData(
|
||||||
|
response.data,
|
||||||
|
response.headers,
|
||||||
|
config.transformResponse
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}, function onAdapterRejection(reason) {
|
||||||
|
if (!isCancel(reason)) {
|
||||||
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
|
// Transform response data
|
||||||
|
if (reason && reason.response) {
|
||||||
|
reason.response.data = transformData(
|
||||||
|
reason.response.data,
|
||||||
|
reason.response.headers,
|
||||||
|
config.transformResponse
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(reason);
|
||||||
|
});
|
||||||
|
};
|
21
node_modules/axios/lib/core/enhanceError.js
generated
vendored
Normal file
21
node_modules/axios/lib/core/enhanceError.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an Error with the specified config, error code, and response.
|
||||||
|
*
|
||||||
|
* @param {Error} error The error to update.
|
||||||
|
* @param {Object} config The config.
|
||||||
|
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
||||||
|
* @param {Object} [request] The request.
|
||||||
|
* @param {Object} [response] The response.
|
||||||
|
* @returns {Error} The error.
|
||||||
|
*/
|
||||||
|
module.exports = function enhanceError(error, config, code, request, response) {
|
||||||
|
error.config = config;
|
||||||
|
if (code) {
|
||||||
|
error.code = code;
|
||||||
|
}
|
||||||
|
error.request = request;
|
||||||
|
error.response = response;
|
||||||
|
return error;
|
||||||
|
};
|
26
node_modules/axios/lib/core/settle.js
generated
vendored
Normal file
26
node_modules/axios/lib/core/settle.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var createError = require('./createError');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve or reject a Promise based on response status.
|
||||||
|
*
|
||||||
|
* @param {Function} resolve A function that resolves the promise.
|
||||||
|
* @param {Function} reject A function that rejects the promise.
|
||||||
|
* @param {object} response The response.
|
||||||
|
*/
|
||||||
|
module.exports = function settle(resolve, reject, response) {
|
||||||
|
var validateStatus = response.config.validateStatus;
|
||||||
|
// Note: status is not exposed by XDomainRequest
|
||||||
|
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
||||||
|
resolve(response);
|
||||||
|
} else {
|
||||||
|
reject(createError(
|
||||||
|
'Request failed with status code ' + response.status,
|
||||||
|
response.config,
|
||||||
|
null,
|
||||||
|
response.request,
|
||||||
|
response
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
20
node_modules/axios/lib/core/transformData.js
generated
vendored
Normal file
20
node_modules/axios/lib/core/transformData.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform the data for a request or a response
|
||||||
|
*
|
||||||
|
* @param {Object|String} data The data to be transformed
|
||||||
|
* @param {Array} headers The headers for the request or response
|
||||||
|
* @param {Array|Function} fns A single function or Array of functions
|
||||||
|
* @returns {*} The resulting transformed data
|
||||||
|
*/
|
||||||
|
module.exports = function transformData(data, headers, fns) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
utils.forEach(fns, function transform(fn) {
|
||||||
|
data = fn(data, headers);
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
92
node_modules/axios/lib/defaults.js
generated
vendored
Normal file
92
node_modules/axios/lib/defaults.js
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./utils');
|
||||||
|
var normalizeHeaderName = require('./helpers/normalizeHeaderName');
|
||||||
|
|
||||||
|
var DEFAULT_CONTENT_TYPE = {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
};
|
||||||
|
|
||||||
|
function setContentTypeIfUnset(headers, value) {
|
||||||
|
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
||||||
|
headers['Content-Type'] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultAdapter() {
|
||||||
|
var adapter;
|
||||||
|
if (typeof XMLHttpRequest !== 'undefined') {
|
||||||
|
// For browsers use XHR adapter
|
||||||
|
adapter = require('./adapters/xhr');
|
||||||
|
} else if (typeof process !== 'undefined') {
|
||||||
|
// For node use HTTP adapter
|
||||||
|
adapter = require('./adapters/http');
|
||||||
|
}
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaults = {
|
||||||
|
adapter: getDefaultAdapter(),
|
||||||
|
|
||||||
|
transformRequest: [function transformRequest(data, headers) {
|
||||||
|
normalizeHeaderName(headers, 'Content-Type');
|
||||||
|
if (utils.isFormData(data) ||
|
||||||
|
utils.isArrayBuffer(data) ||
|
||||||
|
utils.isBuffer(data) ||
|
||||||
|
utils.isStream(data) ||
|
||||||
|
utils.isFile(data) ||
|
||||||
|
utils.isBlob(data)
|
||||||
|
) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if (utils.isArrayBufferView(data)) {
|
||||||
|
return data.buffer;
|
||||||
|
}
|
||||||
|
if (utils.isURLSearchParams(data)) {
|
||||||
|
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
||||||
|
return data.toString();
|
||||||
|
}
|
||||||
|
if (utils.isObject(data)) {
|
||||||
|
setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
|
||||||
|
return JSON.stringify(data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}],
|
||||||
|
|
||||||
|
transformResponse: [function transformResponse(data) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
} catch (e) { /* Ignore */ }
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}],
|
||||||
|
|
||||||
|
timeout: 0,
|
||||||
|
|
||||||
|
xsrfCookieName: 'XSRF-TOKEN',
|
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN',
|
||||||
|
|
||||||
|
maxContentLength: -1,
|
||||||
|
|
||||||
|
validateStatus: function validateStatus(status) {
|
||||||
|
return status >= 200 && status < 300;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
defaults.headers = {
|
||||||
|
common: {
|
||||||
|
'Accept': 'application/json, text/plain, */*'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
||||||
|
defaults.headers[method] = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||||
|
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = defaults;
|
7
node_modules/axios/lib/helpers/README.md
generated
vendored
Normal file
7
node_modules/axios/lib/helpers/README.md
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# axios // helpers
|
||||||
|
|
||||||
|
The modules found in `helpers/` should be generic modules that are _not_ specific to the domain logic of axios. These modules could theoretically be published to npm on their own and consumed by other modules or apps. Some examples of generic modules are things like:
|
||||||
|
|
||||||
|
- Browser polyfills
|
||||||
|
- Managing cookies
|
||||||
|
- Parsing HTTP headers
|
11
node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
11
node_modules/axios/lib/helpers/bind.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function bind(fn, thisArg) {
|
||||||
|
return function wrap() {
|
||||||
|
var args = new Array(arguments.length);
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
args[i] = arguments[i];
|
||||||
|
}
|
||||||
|
return fn.apply(thisArg, args);
|
||||||
|
};
|
||||||
|
};
|
36
node_modules/axios/lib/helpers/btoa.js
generated
vendored
Normal file
36
node_modules/axios/lib/helpers/btoa.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
|
||||||
|
|
||||||
|
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||||
|
|
||||||
|
function E() {
|
||||||
|
this.message = 'String contains an invalid character';
|
||||||
|
}
|
||||||
|
E.prototype = new Error;
|
||||||
|
E.prototype.code = 5;
|
||||||
|
E.prototype.name = 'InvalidCharacterError';
|
||||||
|
|
||||||
|
function btoa(input) {
|
||||||
|
var str = String(input);
|
||||||
|
var output = '';
|
||||||
|
for (
|
||||||
|
// initialize result and counter
|
||||||
|
var block, charCode, idx = 0, map = chars;
|
||||||
|
// if the next str index does not exist:
|
||||||
|
// change the mapping table to "="
|
||||||
|
// check if d has no fractional digits
|
||||||
|
str.charAt(idx | 0) || (map = '=', idx % 1);
|
||||||
|
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
||||||
|
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
||||||
|
) {
|
||||||
|
charCode = str.charCodeAt(idx += 3 / 4);
|
||||||
|
if (charCode > 0xFF) {
|
||||||
|
throw new E();
|
||||||
|
}
|
||||||
|
block = block << 8 | charCode;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = btoa;
|
68
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
68
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
function encode(val) {
|
||||||
|
return encodeURIComponent(val).
|
||||||
|
replace(/%40/gi, '@').
|
||||||
|
replace(/%3A/gi, ':').
|
||||||
|
replace(/%24/g, '$').
|
||||||
|
replace(/%2C/gi, ',').
|
||||||
|
replace(/%20/g, '+').
|
||||||
|
replace(/%5B/gi, '[').
|
||||||
|
replace(/%5D/gi, ']');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a URL by appending params to the end
|
||||||
|
*
|
||||||
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||||
|
* @param {object} [params] The params to be appended
|
||||||
|
* @returns {string} The formatted url
|
||||||
|
*/
|
||||||
|
module.exports = function buildURL(url, params, paramsSerializer) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
if (!params) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serializedParams;
|
||||||
|
if (paramsSerializer) {
|
||||||
|
serializedParams = paramsSerializer(params);
|
||||||
|
} else if (utils.isURLSearchParams(params)) {
|
||||||
|
serializedParams = params.toString();
|
||||||
|
} else {
|
||||||
|
var parts = [];
|
||||||
|
|
||||||
|
utils.forEach(params, function serialize(val, key) {
|
||||||
|
if (val === null || typeof val === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.isArray(val)) {
|
||||||
|
key = key + '[]';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!utils.isArray(val)) {
|
||||||
|
val = [val];
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.forEach(val, function parseValue(v) {
|
||||||
|
if (utils.isDate(v)) {
|
||||||
|
v = v.toISOString();
|
||||||
|
} else if (utils.isObject(v)) {
|
||||||
|
v = JSON.stringify(v);
|
||||||
|
}
|
||||||
|
parts.push(encode(key) + '=' + encode(v));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
serializedParams = parts.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serializedParams) {
|
||||||
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
};
|
14
node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
14
node_modules/axios/lib/helpers/combineURLs.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new URL by combining the specified URLs
|
||||||
|
*
|
||||||
|
* @param {string} baseURL The base URL
|
||||||
|
* @param {string} relativeURL The relative URL
|
||||||
|
* @returns {string} The combined URL
|
||||||
|
*/
|
||||||
|
module.exports = function combineURLs(baseURL, relativeURL) {
|
||||||
|
return relativeURL
|
||||||
|
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
||||||
|
: baseURL;
|
||||||
|
};
|
53
node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
53
node_modules/axios/lib/helpers/cookies.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
module.exports = (
|
||||||
|
utils.isStandardBrowserEnv() ?
|
||||||
|
|
||||||
|
// Standard browser envs support document.cookie
|
||||||
|
(function standardBrowserEnv() {
|
||||||
|
return {
|
||||||
|
write: function write(name, value, expires, path, domain, secure) {
|
||||||
|
var cookie = [];
|
||||||
|
cookie.push(name + '=' + encodeURIComponent(value));
|
||||||
|
|
||||||
|
if (utils.isNumber(expires)) {
|
||||||
|
cookie.push('expires=' + new Date(expires).toGMTString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.isString(path)) {
|
||||||
|
cookie.push('path=' + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.isString(domain)) {
|
||||||
|
cookie.push('domain=' + domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secure === true) {
|
||||||
|
cookie.push('secure');
|
||||||
|
}
|
||||||
|
|
||||||
|
document.cookie = cookie.join('; ');
|
||||||
|
},
|
||||||
|
|
||||||
|
read: function read(name) {
|
||||||
|
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
||||||
|
return (match ? decodeURIComponent(match[3]) : null);
|
||||||
|
},
|
||||||
|
|
||||||
|
remove: function remove(name) {
|
||||||
|
this.write(name, '', Date.now() - 86400000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser env (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return {
|
||||||
|
write: function write() {},
|
||||||
|
read: function read() { return null; },
|
||||||
|
remove: function remove() {}
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
24
node_modules/axios/lib/helpers/deprecatedMethod.js
generated
vendored
Normal file
24
node_modules/axios/lib/helpers/deprecatedMethod.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/*eslint no-console:0*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supply a warning to the developer that a method they are using
|
||||||
|
* has been deprecated.
|
||||||
|
*
|
||||||
|
* @param {string} method The name of the deprecated method
|
||||||
|
* @param {string} [instead] The alternate method to use if applicable
|
||||||
|
* @param {string} [docs] The documentation URL to get further details
|
||||||
|
*/
|
||||||
|
module.exports = function deprecatedMethod(method, instead, docs) {
|
||||||
|
try {
|
||||||
|
console.warn(
|
||||||
|
'DEPRECATED method `' + method + '`.' +
|
||||||
|
(instead ? ' Use `' + instead + '` instead.' : '') +
|
||||||
|
' This method will be removed in a future release.');
|
||||||
|
|
||||||
|
if (docs) {
|
||||||
|
console.warn('For more information about usage see ' + docs);
|
||||||
|
}
|
||||||
|
} catch (e) { /* Ignore */ }
|
||||||
|
};
|
14
node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
14
node_modules/axios/lib/helpers/isAbsoluteURL.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the specified URL is absolute
|
||||||
|
*
|
||||||
|
* @param {string} url The URL to test
|
||||||
|
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||||
|
*/
|
||||||
|
module.exports = function isAbsoluteURL(url) {
|
||||||
|
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||||
|
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||||
|
// by any combination of letters, digits, plus, period, or hyphen.
|
||||||
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
||||||
|
};
|
68
node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
68
node_modules/axios/lib/helpers/isURLSameOrigin.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
module.exports = (
|
||||||
|
utils.isStandardBrowserEnv() ?
|
||||||
|
|
||||||
|
// Standard browser envs have full support of the APIs needed to test
|
||||||
|
// whether the request URL is of the same origin as current location.
|
||||||
|
(function standardBrowserEnv() {
|
||||||
|
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
||||||
|
var urlParsingNode = document.createElement('a');
|
||||||
|
var originURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a URL to discover it's components
|
||||||
|
*
|
||||||
|
* @param {String} url The URL to be parsed
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
function resolveURL(url) {
|
||||||
|
var href = url;
|
||||||
|
|
||||||
|
if (msie) {
|
||||||
|
// IE needs attribute set twice to normalize properties
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
href = urlParsingNode.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
urlParsingNode.setAttribute('href', href);
|
||||||
|
|
||||||
|
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
||||||
|
return {
|
||||||
|
href: urlParsingNode.href,
|
||||||
|
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
||||||
|
host: urlParsingNode.host,
|
||||||
|
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
||||||
|
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
||||||
|
hostname: urlParsingNode.hostname,
|
||||||
|
port: urlParsingNode.port,
|
||||||
|
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
||||||
|
urlParsingNode.pathname :
|
||||||
|
'/' + urlParsingNode.pathname
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
originURL = resolveURL(window.location.href);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a URL shares the same origin as the current location
|
||||||
|
*
|
||||||
|
* @param {String} requestURL The URL to test
|
||||||
|
* @returns {boolean} True if URL shares the same origin, otherwise false
|
||||||
|
*/
|
||||||
|
return function isURLSameOrigin(requestURL) {
|
||||||
|
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
||||||
|
return (parsed.protocol === originURL.protocol &&
|
||||||
|
parsed.host === originURL.host);
|
||||||
|
};
|
||||||
|
})() :
|
||||||
|
|
||||||
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() {
|
||||||
|
return function isURLSameOrigin() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
})()
|
||||||
|
);
|
12
node_modules/axios/lib/helpers/normalizeHeaderName.js
generated
vendored
Normal file
12
node_modules/axios/lib/helpers/normalizeHeaderName.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('../utils');
|
||||||
|
|
||||||
|
module.exports = function normalizeHeaderName(headers, normalizedName) {
|
||||||
|
utils.forEach(headers, function processHeader(value, name) {
|
||||||
|
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
||||||
|
headers[normalizedName] = value;
|
||||||
|
delete headers[name];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
37
node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
37
node_modules/axios/lib/helpers/parseHeaders.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('./../utils');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse headers into an object
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
||||||
|
* Content-Type: application/json
|
||||||
|
* Connection: keep-alive
|
||||||
|
* Transfer-Encoding: chunked
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param {String} headers Headers needing to be parsed
|
||||||
|
* @returns {Object} Headers parsed into an object
|
||||||
|
*/
|
||||||
|
module.exports = function parseHeaders(headers) {
|
||||||
|
var parsed = {};
|
||||||
|
var key;
|
||||||
|
var val;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
if (!headers) { return parsed; }
|
||||||
|
|
||||||
|
utils.forEach(headers.split('\n'), function parser(line) {
|
||||||
|
i = line.indexOf(':');
|
||||||
|
key = utils.trim(line.substr(0, i)).toLowerCase();
|
||||||
|
val = utils.trim(line.substr(i + 1));
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
};
|
27
node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
27
node_modules/axios/lib/helpers/spread.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
||||||
|
*
|
||||||
|
* Common use case would be to use `Function.prototype.apply`.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* function f(x, y, z) {}
|
||||||
|
* var args = [1, 2, 3];
|
||||||
|
* f.apply(null, args);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* With `spread` this example can be re-written.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* spread(function(x, y, z) {})([1, 2, 3]);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param {Function} callback
|
||||||
|
* @returns {Function}
|
||||||
|
*/
|
||||||
|
module.exports = function spread(callback) {
|
||||||
|
return function wrap(arr) {
|
||||||
|
return callback.apply(null, arr);
|
||||||
|
};
|
||||||
|
};
|
303
node_modules/axios/lib/utils.js
generated
vendored
Normal file
303
node_modules/axios/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var bind = require('./helpers/bind');
|
||||||
|
var isBuffer = require('is-buffer');
|
||||||
|
|
||||||
|
/*global toString:true*/
|
||||||
|
|
||||||
|
// utils is a library of generic helper functions non-specific to axios
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is an Array
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is an Array, otherwise false
|
||||||
|
*/
|
||||||
|
function isArray(val) {
|
||||||
|
return toString.call(val) === '[object Array]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is an ArrayBuffer
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
||||||
|
*/
|
||||||
|
function isArrayBuffer(val) {
|
||||||
|
return toString.call(val) === '[object ArrayBuffer]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a FormData
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is an FormData, otherwise false
|
||||||
|
*/
|
||||||
|
function isFormData(val) {
|
||||||
|
return (typeof FormData !== 'undefined') && (val instanceof FormData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a view on an ArrayBuffer
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
||||||
|
*/
|
||||||
|
function isArrayBufferView(val) {
|
||||||
|
var result;
|
||||||
|
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
||||||
|
result = ArrayBuffer.isView(val);
|
||||||
|
} else {
|
||||||
|
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a String
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a String, otherwise false
|
||||||
|
*/
|
||||||
|
function isString(val) {
|
||||||
|
return typeof val === 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a Number
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a Number, otherwise false
|
||||||
|
*/
|
||||||
|
function isNumber(val) {
|
||||||
|
return typeof val === 'number';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is undefined
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if the value is undefined, otherwise false
|
||||||
|
*/
|
||||||
|
function isUndefined(val) {
|
||||||
|
return typeof val === 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is an Object
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is an Object, otherwise false
|
||||||
|
*/
|
||||||
|
function isObject(val) {
|
||||||
|
return val !== null && typeof val === 'object';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a Date
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a Date, otherwise false
|
||||||
|
*/
|
||||||
|
function isDate(val) {
|
||||||
|
return toString.call(val) === '[object Date]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a File
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a File, otherwise false
|
||||||
|
*/
|
||||||
|
function isFile(val) {
|
||||||
|
return toString.call(val) === '[object File]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a Blob
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a Blob, otherwise false
|
||||||
|
*/
|
||||||
|
function isBlob(val) {
|
||||||
|
return toString.call(val) === '[object Blob]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a Function
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a Function, otherwise false
|
||||||
|
*/
|
||||||
|
function isFunction(val) {
|
||||||
|
return toString.call(val) === '[object Function]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a Stream
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a Stream, otherwise false
|
||||||
|
*/
|
||||||
|
function isStream(val) {
|
||||||
|
return isObject(val) && isFunction(val.pipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a URLSearchParams object
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
||||||
|
*/
|
||||||
|
function isURLSearchParams(val) {
|
||||||
|
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trim excess whitespace off the beginning and end of a string
|
||||||
|
*
|
||||||
|
* @param {String} str The String to trim
|
||||||
|
* @returns {String} The String freed of excess whitespace
|
||||||
|
*/
|
||||||
|
function trim(str) {
|
||||||
|
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if we're running in a standard browser environment
|
||||||
|
*
|
||||||
|
* This allows axios to run in a web worker, and react-native.
|
||||||
|
* Both environments support XMLHttpRequest, but not fully standard globals.
|
||||||
|
*
|
||||||
|
* web workers:
|
||||||
|
* typeof window -> undefined
|
||||||
|
* typeof document -> undefined
|
||||||
|
*
|
||||||
|
* react-native:
|
||||||
|
* navigator.product -> 'ReactNative'
|
||||||
|
*/
|
||||||
|
function isStandardBrowserEnv() {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
typeof window !== 'undefined' &&
|
||||||
|
typeof document !== 'undefined'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate over an Array or an Object invoking a function for each item.
|
||||||
|
*
|
||||||
|
* If `obj` is an Array callback will be called passing
|
||||||
|
* the value, index, and complete array for each item.
|
||||||
|
*
|
||||||
|
* If 'obj' is an Object callback will be called passing
|
||||||
|
* the value, key, and complete object for each property.
|
||||||
|
*
|
||||||
|
* @param {Object|Array} obj The object to iterate
|
||||||
|
* @param {Function} fn The callback to invoke for each item
|
||||||
|
*/
|
||||||
|
function forEach(obj, fn) {
|
||||||
|
// Don't bother if no value provided
|
||||||
|
if (obj === null || typeof obj === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force an array if not already something iterable
|
||||||
|
if (typeof obj !== 'object' && !isArray(obj)) {
|
||||||
|
/*eslint no-param-reassign:0*/
|
||||||
|
obj = [obj];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isArray(obj)) {
|
||||||
|
// Iterate over array values
|
||||||
|
for (var i = 0, l = obj.length; i < l; i++) {
|
||||||
|
fn.call(null, obj[i], i, obj);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Iterate over object keys
|
||||||
|
for (var key in obj) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
fn.call(null, obj[key], key, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts varargs expecting each argument to be an object, then
|
||||||
|
* immutably merges the properties of each object and returns result.
|
||||||
|
*
|
||||||
|
* When multiple objects contain the same key the later object in
|
||||||
|
* the arguments list will take precedence.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* var result = merge({foo: 123}, {foo: 456});
|
||||||
|
* console.log(result.foo); // outputs 456
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param {Object} obj1 Object to merge
|
||||||
|
* @returns {Object} Result of all merge properties
|
||||||
|
*/
|
||||||
|
function merge(/* obj1, obj2, obj3, ... */) {
|
||||||
|
var result = {};
|
||||||
|
function assignValue(val, key) {
|
||||||
|
if (typeof result[key] === 'object' && typeof val === 'object') {
|
||||||
|
result[key] = merge(result[key], val);
|
||||||
|
} else {
|
||||||
|
result[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
forEach(arguments[i], assignValue);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends object a by mutably adding to it the properties of object b.
|
||||||
|
*
|
||||||
|
* @param {Object} a The object to be extended
|
||||||
|
* @param {Object} b The object to copy properties from
|
||||||
|
* @param {Object} thisArg The object to bind function to
|
||||||
|
* @return {Object} The resulting value of object a
|
||||||
|
*/
|
||||||
|
function extend(a, b, thisArg) {
|
||||||
|
forEach(b, function assignValue(val, key) {
|
||||||
|
if (thisArg && typeof val === 'function') {
|
||||||
|
a[key] = bind(val, thisArg);
|
||||||
|
} else {
|
||||||
|
a[key] = val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isArray: isArray,
|
||||||
|
isArrayBuffer: isArrayBuffer,
|
||||||
|
isBuffer: isBuffer,
|
||||||
|
isFormData: isFormData,
|
||||||
|
isArrayBufferView: isArrayBufferView,
|
||||||
|
isString: isString,
|
||||||
|
isNumber: isNumber,
|
||||||
|
isObject: isObject,
|
||||||
|
isUndefined: isUndefined,
|
||||||
|
isDate: isDate,
|
||||||
|
isFile: isFile,
|
||||||
|
isBlob: isBlob,
|
||||||
|
isFunction: isFunction,
|
||||||
|
isStream: isStream,
|
||||||
|
isURLSearchParams: isURLSearchParams,
|
||||||
|
isStandardBrowserEnv: isStandardBrowserEnv,
|
||||||
|
forEach: forEach,
|
||||||
|
merge: merge,
|
||||||
|
extend: extend,
|
||||||
|
trim: trim
|
||||||
|
};
|
78
node_modules/axios/package.json
generated
vendored
Normal file
78
node_modules/axios/package.json
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
"name": "axios",
|
||||||
|
"version": "0.16.2",
|
||||||
|
"description": "Promise based HTTP client for the browser and node.js",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "grunt test",
|
||||||
|
"start": "node ./sandbox/server.js",
|
||||||
|
"build": "NODE_ENV=production grunt build",
|
||||||
|
"preversion": "npm test",
|
||||||
|
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
|
||||||
|
"postversion": "git push && git push --tags",
|
||||||
|
"examples": "node ./examples/server.js",
|
||||||
|
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mzabriskie/axios.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"xhr",
|
||||||
|
"http",
|
||||||
|
"ajax",
|
||||||
|
"promise",
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
"author": "Matt Zabriskie",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/mzabriskie/axios/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/mzabriskie/axios",
|
||||||
|
"devDependencies": {
|
||||||
|
"coveralls": "^2.11.9",
|
||||||
|
"es6-promise": "^4.0.5",
|
||||||
|
"grunt": "^1.0.1",
|
||||||
|
"grunt-banner": "^0.6.0",
|
||||||
|
"grunt-cli": "^1.2.0",
|
||||||
|
"grunt-contrib-clean": "^1.0.0",
|
||||||
|
"grunt-contrib-nodeunit": "^1.0.0",
|
||||||
|
"grunt-contrib-watch": "^1.0.0",
|
||||||
|
"grunt-eslint": "^19.0.0",
|
||||||
|
"grunt-karma": "^2.0.0",
|
||||||
|
"grunt-ts": "^6.0.0-beta.3",
|
||||||
|
"grunt-webpack": "^1.0.18",
|
||||||
|
"istanbul-instrumenter-loader": "^1.0.0",
|
||||||
|
"jasmine-core": "^2.4.1",
|
||||||
|
"karma": "^1.3.0",
|
||||||
|
"karma-chrome-launcher": "^2.0.0",
|
||||||
|
"karma-coverage": "^1.0.0",
|
||||||
|
"karma-firefox-launcher": "^1.0.0",
|
||||||
|
"karma-jasmine": "^1.0.2",
|
||||||
|
"karma-jasmine-ajax": "^0.1.13",
|
||||||
|
"karma-opera-launcher": "^1.0.0",
|
||||||
|
"karma-phantomjs-launcher": "^1.0.0",
|
||||||
|
"karma-safari-launcher": "^1.0.0",
|
||||||
|
"karma-sauce-launcher": "^1.1.0",
|
||||||
|
"karma-sinon": "^1.0.5",
|
||||||
|
"karma-sourcemap-loader": "^0.3.7",
|
||||||
|
"karma-webpack": "^1.7.0",
|
||||||
|
"load-grunt-tasks": "^3.5.2",
|
||||||
|
"minimist": "^1.2.0",
|
||||||
|
"phantomjs-prebuilt": "^2.1.7",
|
||||||
|
"sinon": "^1.17.4",
|
||||||
|
"webpack": "^1.13.1",
|
||||||
|
"webpack-dev-server": "^1.14.1",
|
||||||
|
"url-search-params": "^0.6.1",
|
||||||
|
"typescript": "^2.0.3"
|
||||||
|
},
|
||||||
|
"browser": {
|
||||||
|
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
||||||
|
},
|
||||||
|
"typings": "./index.d.ts",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.2.3",
|
||||||
|
"is-buffer": "^1.1.5"
|
||||||
|
}
|
||||||
|
}
|
19
node_modules/follow-redirects/LICENSE
generated
vendored
Normal file
19
node_modules/follow-redirects/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright 2017 Olivier Lalonde <olalonde@gmail.com>, James Talmage <james@talmage.io>, Ruben Verborgh
|
||||||
|
|
||||||
|
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.
|
135
node_modules/follow-redirects/README.md
generated
vendored
Normal file
135
node_modules/follow-redirects/README.md
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
## Follow Redirects
|
||||||
|
|
||||||
|
Drop-in replacement for Nodes `http` and `https` that automatically follows redirects.
|
||||||
|
|
||||||
|
[![npm version](https://badge.fury.io/js/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
|
||||||
|
[![Build Status](https://travis-ci.org/olalonde/follow-redirects.svg?branch=master)](https://travis-ci.org/olalonde/follow-redirects)
|
||||||
|
[![Coverage Status](https://coveralls.io/repos/olalonde/follow-redirects/badge.svg?branch=master)](https://coveralls.io/r/olalonde/follow-redirects?branch=master)
|
||||||
|
[![Code Climate](https://codeclimate.com/github/olalonde/follow-redirects/badges/gpa.svg)](https://codeclimate.com/github/olalonde/follow-redirects)
|
||||||
|
[![Dependency Status](https://david-dm.org/olalonde/follow-redirects.svg)](https://david-dm.org/olalonde/follow-redirects)
|
||||||
|
[![devDependency Status](https://david-dm.org/olalonde/follow-redirects/dev-status.svg)](https://david-dm.org/olalonde/follow-redirects#info=devDependencies)
|
||||||
|
|
||||||
|
[![NPM](https://nodei.co/npm/follow-redirects.png?downloads=true)](https://nodei.co/npm/follow-redirects/)
|
||||||
|
|
||||||
|
`follow-redirects` provides [request](https://nodejs.org/api/http.html#http_http_request_options_callback) and [get](https://nodejs.org/api/http.html#http_http_get_options_callback)
|
||||||
|
methods that behave identically to those found on the native [http](https://nodejs.org/api/http.html#http_http_request_options_callback) and [https](https://nodejs.org/api/https.html#https_https_request_options_callback)
|
||||||
|
modules, with the exception that they will seamlessly follow redirects.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var http = require('follow-redirects').http;
|
||||||
|
var https = require('follow-redirects').https;
|
||||||
|
|
||||||
|
http.get('http://bit.ly/900913', function (response) {
|
||||||
|
response.on('data', function (chunk) {
|
||||||
|
console.log(chunk);
|
||||||
|
});
|
||||||
|
}).on('error', function (err) {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can inspect the final redirected URL through the `responseUrl` property on the `response`.
|
||||||
|
If no redirection happened, `responseUrl` is the original request URL.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
https.request({
|
||||||
|
host: 'bitly.com',
|
||||||
|
path: '/UHfDGO',
|
||||||
|
}, function (response) {
|
||||||
|
console.log(response.responseUrl);
|
||||||
|
// 'http://duckduckgo.com/robots.txt'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
### Global options
|
||||||
|
Global options are set directly on the `follow-redirects` module:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var followRedirects = require('follow-redirects');
|
||||||
|
followRedirects.maxRedirects = 10;
|
||||||
|
```
|
||||||
|
|
||||||
|
The following global options are supported:
|
||||||
|
|
||||||
|
- `maxRedirects` (default: `21`) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
|
||||||
|
|
||||||
|
|
||||||
|
### Per-request options
|
||||||
|
Per-request options are set by passing an `options` object:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var url = require('url');
|
||||||
|
var followRedirects = require('follow-redirects');
|
||||||
|
|
||||||
|
var options = url.parse('http://bit.ly/900913');
|
||||||
|
options.maxRedirects = 10;
|
||||||
|
http.request(options);
|
||||||
|
```
|
||||||
|
|
||||||
|
In addition to the [standard HTTP](https://nodejs.org/api/http.html#http_http_request_options_callback) and [HTTPS options](https://nodejs.org/api/https.html#https_https_request_options_callback),
|
||||||
|
the following per-request options are supported:
|
||||||
|
- `followRedirects` (default: `true`) – whether redirects should be followed.
|
||||||
|
|
||||||
|
- `maxRedirects` (default: `21`) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
|
||||||
|
|
||||||
|
- `agents` (default: `undefined`) – sets the `agent` option per protocol, since HTTP and HTTPS use different agents. Example value: `{ http: new http.Agent(), https: new https.Agent() }`
|
||||||
|
|
||||||
|
|
||||||
|
## Browserify Usage
|
||||||
|
|
||||||
|
Due to the way `XMLHttpRequest` works, the `browserify` versions of `http` and `https` already follow redirects.
|
||||||
|
If you are *only* targeting the browser, then this library has little value for you. If you want to write cross
|
||||||
|
platform code for node and the browser, `follow-redirects` provides a great solution for making the native node
|
||||||
|
modules behave the same as they do in browserified builds in the browser. To avoid bundling unnecessary code
|
||||||
|
you should tell browserify to swap out `follow-redirects` with the standard modules when bundling.
|
||||||
|
To make this easier, you need to change how you require the modules:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var http = require('follow-redirects/http');
|
||||||
|
var https = require('follow-redirects/https');
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then replace `follow-redirects` in your browserify configuration like so:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
"browser": {
|
||||||
|
"follow-redirects/http" : "http",
|
||||||
|
"follow-redirects/https" : "https"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `browserify-http` module has not kept pace with node development, and no long behaves identically to the native
|
||||||
|
module when running in the browser. If you are experiencing problems, you may want to check out
|
||||||
|
[browserify-http-2](https://www.npmjs.com/package/http-browserify-2). It is more actively maintained and
|
||||||
|
attempts to address a few of the shortcomings of `browserify-http`. In that case, your browserify config should
|
||||||
|
look something like this:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
"browser": {
|
||||||
|
"follow-redirects/http" : "browserify-http-2/http",
|
||||||
|
"follow-redirects/https" : "browserify-http-2/https"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Pull Requests are always welcome. Please [file an issue](https://github.com/olalonde/follow-redirects/issues)
|
||||||
|
detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied
|
||||||
|
by tests. You can run the test suite locally with a simple `npm test` command.
|
||||||
|
|
||||||
|
## Debug Logging
|
||||||
|
|
||||||
|
`follow-redirects` uses the excellent [debug](https://www.npmjs.com/package/debug) for logging. To turn on logging
|
||||||
|
set the environment variable `DEBUG=follow-redirects` for debug output from just this module. When running the test
|
||||||
|
suite it is sometimes advantageous to set `DEBUG=*` to see output from the express server as well.
|
||||||
|
|
||||||
|
## Authors
|
||||||
|
|
||||||
|
- Olivier Lalonde (olalonde@gmail.com)
|
||||||
|
- James Talmage (james@talmage.io)
|
||||||
|
- [Ruben Verborgh](https://ruben.verborgh.org/)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT: [http://olalonde.mit-license.org](http://olalonde.mit-license.org)
|
1
node_modules/follow-redirects/http.js
generated
vendored
Normal file
1
node_modules/follow-redirects/http.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./').http;
|
1
node_modules/follow-redirects/https.js
generated
vendored
Normal file
1
node_modules/follow-redirects/https.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./').https;
|
238
node_modules/follow-redirects/index.js
generated
vendored
Normal file
238
node_modules/follow-redirects/index.js
generated
vendored
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
'use strict';
|
||||||
|
var url = require('url');
|
||||||
|
var assert = require('assert');
|
||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var Writable = require('stream').Writable;
|
||||||
|
var debug = require('debug')('follow-redirects');
|
||||||
|
|
||||||
|
var nativeProtocols = {'http:': http, 'https:': https};
|
||||||
|
var schemes = {};
|
||||||
|
var exports = module.exports = {
|
||||||
|
maxRedirects: 21
|
||||||
|
};
|
||||||
|
// RFC7231§4.2.1: Of the request methods defined by this specification,
|
||||||
|
// the GET, HEAD, OPTIONS, and TRACE methods are defined to be safe.
|
||||||
|
var safeMethods = {GET: true, HEAD: true, OPTIONS: true, TRACE: true};
|
||||||
|
|
||||||
|
// Create handlers that pass events from native requests
|
||||||
|
var eventHandlers = Object.create(null);
|
||||||
|
['abort', 'aborted', 'error', 'socket'].forEach(function (event) {
|
||||||
|
eventHandlers[event] = function (arg) {
|
||||||
|
this._redirectable.emit(event, arg);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// An HTTP(S) request that can be redirected
|
||||||
|
function RedirectableRequest(options, responseCallback) {
|
||||||
|
// Initialize the request
|
||||||
|
Writable.call(this);
|
||||||
|
this._options = options;
|
||||||
|
this._redirectCount = 0;
|
||||||
|
this._bufferedWrites = [];
|
||||||
|
|
||||||
|
// Attach a callback if passed
|
||||||
|
if (responseCallback) {
|
||||||
|
this.on('response', responseCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// React to responses of native requests
|
||||||
|
var self = this;
|
||||||
|
this._onNativeResponse = function (response) {
|
||||||
|
self._processResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Complete the URL object when necessary
|
||||||
|
if (!options.pathname && options.path) {
|
||||||
|
var searchPos = options.path.indexOf('?');
|
||||||
|
if (searchPos < 0) {
|
||||||
|
options.pathname = options.path;
|
||||||
|
} else {
|
||||||
|
options.pathname = options.path.substring(0, searchPos);
|
||||||
|
options.search = options.path.substring(searchPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the first request
|
||||||
|
this._performRequest();
|
||||||
|
}
|
||||||
|
RedirectableRequest.prototype = Object.create(Writable.prototype);
|
||||||
|
|
||||||
|
// Executes the next native request (initial or redirect)
|
||||||
|
RedirectableRequest.prototype._performRequest = function () {
|
||||||
|
// If specified, use the agent corresponding to the protocol
|
||||||
|
// (HTTP and HTTPS use different types of agents)
|
||||||
|
var protocol = this._options.protocol;
|
||||||
|
if (this._options.agents) {
|
||||||
|
this._options.agent = this._options.agents[schemes[protocol]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the native request
|
||||||
|
var nativeProtocol = nativeProtocols[protocol];
|
||||||
|
var request = this._currentRequest =
|
||||||
|
nativeProtocol.request(this._options, this._onNativeResponse);
|
||||||
|
this._currentUrl = url.format(this._options);
|
||||||
|
|
||||||
|
// Set up event handlers
|
||||||
|
request._redirectable = this;
|
||||||
|
for (var event in eventHandlers) {
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (event) {
|
||||||
|
request.on(event, eventHandlers[event]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// End a redirected request
|
||||||
|
// (The first request must be ended explicitly with RedirectableRequest#end)
|
||||||
|
if (this._isRedirect) {
|
||||||
|
// If the request doesn't have en entity, end directly.
|
||||||
|
var bufferedWrites = this._bufferedWrites;
|
||||||
|
if (bufferedWrites.length === 0) {
|
||||||
|
request.end();
|
||||||
|
// Otherwise, write the request entity and end afterwards.
|
||||||
|
} else {
|
||||||
|
var i = 0;
|
||||||
|
(function writeNext() {
|
||||||
|
if (i < bufferedWrites.length) {
|
||||||
|
var bufferedWrite = bufferedWrites[i++];
|
||||||
|
request.write(bufferedWrite.data, bufferedWrite.encoding, writeNext);
|
||||||
|
} else {
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Processes a response from the current native request
|
||||||
|
RedirectableRequest.prototype._processResponse = function (response) {
|
||||||
|
// RFC7231§6.4: The 3xx (Redirection) class of status code indicates
|
||||||
|
// that further action needs to be taken by the user agent in order to
|
||||||
|
// fulfill the request. If a Location header field is provided,
|
||||||
|
// the user agent MAY automatically redirect its request to the URI
|
||||||
|
// referenced by the Location field value,
|
||||||
|
// even if the specific status code is not understood.
|
||||||
|
var location = response.headers.location;
|
||||||
|
if (location && this._options.followRedirects !== false &&
|
||||||
|
response.statusCode >= 300 && response.statusCode < 400) {
|
||||||
|
// RFC7231§6.4: A client SHOULD detect and intervene
|
||||||
|
// in cyclical redirections (i.e., "infinite" redirection loops).
|
||||||
|
if (++this._redirectCount > this._options.maxRedirects) {
|
||||||
|
return this.emit('error', new Error('Max redirects exceeded.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC7231§6.4: Automatic redirection needs to done with
|
||||||
|
// care for methods not known to be safe […],
|
||||||
|
// since the user might not wish to redirect an unsafe request.
|
||||||
|
// RFC7231§6.4.7: The 307 (Temporary Redirect) status code indicates
|
||||||
|
// that the target resource resides temporarily under a different URI
|
||||||
|
// and the user agent MUST NOT change the request method
|
||||||
|
// if it performs an automatic redirection to that URI.
|
||||||
|
var header;
|
||||||
|
var headers = this._options.headers;
|
||||||
|
if (response.statusCode !== 307 && !(this._options.method in safeMethods)) {
|
||||||
|
this._options.method = 'GET';
|
||||||
|
// Drop a possible entity and headers related to it
|
||||||
|
this._bufferedWrites = [];
|
||||||
|
for (header in headers) {
|
||||||
|
if (/^content-/i.test(header)) {
|
||||||
|
delete headers[header];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop the Host header, as the redirect might lead to a different host
|
||||||
|
if (!this._isRedirect) {
|
||||||
|
for (header in headers) {
|
||||||
|
if (/^host$/i.test(header)) {
|
||||||
|
delete headers[header];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the redirected request
|
||||||
|
var redirectUrl = url.resolve(this._currentUrl, location);
|
||||||
|
debug('redirecting to', redirectUrl);
|
||||||
|
Object.assign(this._options, url.parse(redirectUrl));
|
||||||
|
this._isRedirect = true;
|
||||||
|
this._performRequest();
|
||||||
|
} else {
|
||||||
|
// The response is not a redirect; return it as-is
|
||||||
|
response.responseUrl = this._currentUrl;
|
||||||
|
this.emit('response', response);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
delete this._options;
|
||||||
|
delete this._bufferedWrites;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Aborts the current native request
|
||||||
|
RedirectableRequest.prototype.abort = function () {
|
||||||
|
this._currentRequest.abort();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flushes the headers of the current native request
|
||||||
|
RedirectableRequest.prototype.flushHeaders = function () {
|
||||||
|
this._currentRequest.flushHeaders();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sets the noDelay option of the current native request
|
||||||
|
RedirectableRequest.prototype.setNoDelay = function (noDelay) {
|
||||||
|
this._currentRequest.setNoDelay(noDelay);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sets the socketKeepAlive option of the current native request
|
||||||
|
RedirectableRequest.prototype.setSocketKeepAlive = function (enable, initialDelay) {
|
||||||
|
this._currentRequest.setSocketKeepAlive(enable, initialDelay);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sets the timeout option of the current native request
|
||||||
|
RedirectableRequest.prototype.setTimeout = function (timeout, callback) {
|
||||||
|
this._currentRequest.setTimeout(timeout, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Writes buffered data to the current native request
|
||||||
|
RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
||||||
|
this._currentRequest.write(data, encoding, callback);
|
||||||
|
this._bufferedWrites.push({data: data, encoding: encoding});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ends the current native request
|
||||||
|
RedirectableRequest.prototype.end = function (data, encoding, callback) {
|
||||||
|
this._currentRequest.end(data, encoding, callback);
|
||||||
|
if (data) {
|
||||||
|
this._bufferedWrites.push({data: data, encoding: encoding});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Export a redirecting wrapper for each native protocol
|
||||||
|
Object.keys(nativeProtocols).forEach(function (protocol) {
|
||||||
|
var scheme = schemes[protocol] = protocol.substr(0, protocol.length - 1);
|
||||||
|
var nativeProtocol = nativeProtocols[protocol];
|
||||||
|
var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
|
||||||
|
|
||||||
|
// Executes an HTTP request, following redirects
|
||||||
|
wrappedProtocol.request = function (options, callback) {
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
options = url.parse(options);
|
||||||
|
options.maxRedirects = exports.maxRedirects;
|
||||||
|
} else {
|
||||||
|
options = Object.assign({
|
||||||
|
maxRedirects: exports.maxRedirects,
|
||||||
|
protocol: protocol
|
||||||
|
}, options);
|
||||||
|
}
|
||||||
|
assert.equal(options.protocol, protocol, 'protocol mismatch');
|
||||||
|
debug('options', options);
|
||||||
|
|
||||||
|
return new RedirectableRequest(options, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Executes a GET request, following redirects
|
||||||
|
wrappedProtocol.get = function (options, callback) {
|
||||||
|
var request = wrappedProtocol.request(options, callback);
|
||||||
|
request.end();
|
||||||
|
return request;
|
||||||
|
};
|
||||||
|
});
|
68
node_modules/follow-redirects/package.json
generated
vendored
Normal file
68
node_modules/follow-redirects/package.json
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"name": "follow-redirects",
|
||||||
|
"version": "1.2.4",
|
||||||
|
"description": "HTTP and HTTPS modules that follow redirects.",
|
||||||
|
"main": "index.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && BLUEBIRD_DEBUG=1 nyc mocha"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:olalonde/follow-redirects.git"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/olalonde/follow-redirects",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/olalonde/follow-redirects/issues"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"http",
|
||||||
|
"https",
|
||||||
|
"url",
|
||||||
|
"redirect",
|
||||||
|
"client",
|
||||||
|
"location",
|
||||||
|
"utility"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "Olivier Lalonde",
|
||||||
|
"email": "olalonde@gmail.com",
|
||||||
|
"url": "http://www.syskall.com"
|
||||||
|
},
|
||||||
|
"contributors": [
|
||||||
|
"James Talmage <james@talmage.io>",
|
||||||
|
"Ruben Verborgh <ruben@verborgh.org> (https://ruben.verborgh.org/)"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"create.js",
|
||||||
|
"http.js",
|
||||||
|
"https.js"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "^2.4.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"bluebird": "^3.4.0",
|
||||||
|
"concat-stream": "^1.5.2",
|
||||||
|
"coveralls": "^2.11.15",
|
||||||
|
"express": "^4.13.0",
|
||||||
|
"mocha": "^3.2.0",
|
||||||
|
"nyc": "^10.0.0",
|
||||||
|
"xo": "^0.17.1"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"nyc": {
|
||||||
|
"reporter": [
|
||||||
|
"lcov",
|
||||||
|
"text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"xo": {
|
||||||
|
"envs": [
|
||||||
|
"mocha"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
0
node_modules/handlebars/node_modules/uglify-js/bin/uglifyjs
generated
vendored
Executable file → Normal file
0
node_modules/handlebars/node_modules/uglify-js/bin/uglifyjs
generated
vendored
Executable file → Normal file
97
node_modules/nyc/node_modules/md5-hex/package.json
generated
vendored
97
node_modules/nyc/node_modules/md5-hex/package.json
generated
vendored
@ -1,82 +1,25 @@
|
|||||||
{
|
{
|
||||||
"_args": [
|
"name": "md5-hex",
|
||||||
[
|
"version": "1.3.0",
|
||||||
{
|
"description": "Create a MD5 hash with hex encoding",
|
||||||
"raw": "md5-hex@^1.2.0",
|
"license": "MIT",
|
||||||
"scope": null,
|
"repository": "sindresorhus/md5-hex",
|
||||||
"escapedName": "md5-hex",
|
|
||||||
"name": "md5-hex",
|
|
||||||
"rawSpec": "^1.2.0",
|
|
||||||
"spec": ">=1.2.0 <2.0.0",
|
|
||||||
"type": "range"
|
|
||||||
},
|
|
||||||
"/Users/benjamincoe/bcoe/nyc"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "md5-hex@>=1.2.0 <2.0.0",
|
|
||||||
"_id": "md5-hex@1.3.0",
|
|
||||||
"_inCache": true,
|
|
||||||
"_location": "/md5-hex",
|
|
||||||
"_nodeVersion": "4.4.2",
|
|
||||||
"_npmOperationalInternal": {
|
|
||||||
"host": "packages-12-west.internal.npmjs.com",
|
|
||||||
"tmp": "tmp/md5-hex-1.3.0.tgz_1460471196734_0.9732175024691969"
|
|
||||||
},
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "sindresorhus",
|
|
||||||
"email": "sindresorhus@gmail.com"
|
|
||||||
},
|
|
||||||
"_npmVersion": "2.15.0",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"raw": "md5-hex@^1.2.0",
|
|
||||||
"scope": null,
|
|
||||||
"escapedName": "md5-hex",
|
|
||||||
"name": "md5-hex",
|
|
||||||
"rawSpec": "^1.2.0",
|
|
||||||
"spec": ">=1.2.0 <2.0.0",
|
|
||||||
"type": "range"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/",
|
|
||||||
"/caching-transform"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/md5-hex/-/md5-hex-1.3.0.tgz",
|
|
||||||
"_shasum": "d2c4afe983c4370662179b8cad145219135046c4",
|
|
||||||
"_shrinkwrap": null,
|
|
||||||
"_spec": "md5-hex@^1.2.0",
|
|
||||||
"_where": "/Users/benjamincoe/bcoe/nyc",
|
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Sindre Sorhus",
|
"name": "Sindre Sorhus",
|
||||||
"email": "sindresorhus@gmail.com",
|
"email": "sindresorhus@gmail.com",
|
||||||
"url": "sindresorhus.com"
|
"url": "sindresorhus.com"
|
||||||
},
|
},
|
||||||
"browser": "browser.js",
|
"browser": "browser.js",
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/sindresorhus/md5-hex/issues"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"md5-o-matic": "^0.1.1"
|
|
||||||
},
|
|
||||||
"description": "Create a MD5 hash with hex encoding",
|
|
||||||
"devDependencies": {
|
|
||||||
"ava": "*",
|
|
||||||
"xo": "*"
|
|
||||||
},
|
|
||||||
"directories": {},
|
|
||||||
"dist": {
|
|
||||||
"shasum": "d2c4afe983c4370662179b8cad145219135046c4",
|
|
||||||
"tarball": "https://registry.npmjs.org/md5-hex/-/md5-hex-1.3.0.tgz"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
"browser.js"
|
"browser.js"
|
||||||
],
|
],
|
||||||
"gitHead": "273d9c659a29e4cd53512f526282afd5ac1c1413",
|
|
||||||
"homepage": "https://github.com/sindresorhus/md5-hex#readme",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hash",
|
"hash",
|
||||||
"crypto",
|
"crypto",
|
||||||
@ -86,23 +29,11 @@
|
|||||||
"browser",
|
"browser",
|
||||||
"browserify"
|
"browserify"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"dependencies": {
|
||||||
"maintainers": [
|
"md5-o-matic": "^0.1.1"
|
||||||
{
|
|
||||||
"name": "sindresorhus",
|
|
||||||
"email": "sindresorhus@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "md5-hex",
|
|
||||||
"optionalDependencies": {},
|
|
||||||
"readme": "# md5-hex [![Build Status](https://travis-ci.org/sindresorhus/md5-hex.svg?branch=master)](https://travis-ci.org/sindresorhus/md5-hex)\n\n> Create a MD5 hash with hex encoding\n\n*Please don't use MD5 hashes for anything sensitive!*\n\nCheckout [`hasha`](https://github.com/sindresorhus/hasha) if you need something more flexible.\n\n\n## Install\n\n```\n$ npm install --save md5-hex\n```\n\n\n## Usage\n\n```js\nconst fs = require('fs');\nconst md5Hex = require('md5-hex');\nconst buffer = fs.readFileSync('unicorn.png');\n\nmd5Hex(buffer);\n//=> '1abcb33beeb811dca15f0ac3e47b88d9'\n```\n\n\n## API\n\n### md5Hex(input)\n\n#### input\n\nType: `buffer` `string` `array[string|buffer]`\n\nPrefer buffers as they're faster to hash, but strings can be useful for small things.\n\nPass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.\n\n\n## License\n\nMIT © [Sindre Sorhus](https://sindresorhus.com)\n",
|
|
||||||
"readmeFilename": "readme.md",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/sindresorhus/md5-hex.git"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"devDependencies": {
|
||||||
"test": "xo && ava"
|
"ava": "*",
|
||||||
},
|
"xo": "*"
|
||||||
"version": "1.3.0"
|
}
|
||||||
}
|
}
|
||||||
|
89
node_modules/nyc/node_modules/resolve-from/package.json
generated
vendored
89
node_modules/nyc/node_modules/resolve-from/package.json
generated
vendored
@ -1,73 +1,23 @@
|
|||||||
{
|
{
|
||||||
"_args": [
|
"name": "resolve-from",
|
||||||
[
|
"version": "2.0.0",
|
||||||
{
|
"description": "Resolve the path of a module like require.resolve() but from a given path",
|
||||||
"raw": "resolve-from@^2.0.0",
|
"license": "MIT",
|
||||||
"scope": null,
|
"repository": "sindresorhus/resolve-from",
|
||||||
"escapedName": "resolve-from",
|
|
||||||
"name": "resolve-from",
|
|
||||||
"rawSpec": "^2.0.0",
|
|
||||||
"spec": ">=2.0.0 <3.0.0",
|
|
||||||
"type": "range"
|
|
||||||
},
|
|
||||||
"/Users/benjamincoe/bcoe/nyc"
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"_from": "resolve-from@>=2.0.0 <3.0.0",
|
|
||||||
"_id": "resolve-from@2.0.0",
|
|
||||||
"_inCache": true,
|
|
||||||
"_location": "/resolve-from",
|
|
||||||
"_nodeVersion": "4.2.1",
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "sindresorhus",
|
|
||||||
"email": "sindresorhus@gmail.com"
|
|
||||||
},
|
|
||||||
"_npmVersion": "2.14.7",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"raw": "resolve-from@^2.0.0",
|
|
||||||
"scope": null,
|
|
||||||
"escapedName": "resolve-from",
|
|
||||||
"name": "resolve-from",
|
|
||||||
"rawSpec": "^2.0.0",
|
|
||||||
"spec": ">=2.0.0 <3.0.0",
|
|
||||||
"type": "range"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
|
|
||||||
"_shasum": "9480ab20e94ffa1d9e80a804c7ea147611966b57",
|
|
||||||
"_shrinkwrap": null,
|
|
||||||
"_spec": "resolve-from@^2.0.0",
|
|
||||||
"_where": "/Users/benjamincoe/bcoe/nyc",
|
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Sindre Sorhus",
|
"name": "Sindre Sorhus",
|
||||||
"email": "sindresorhus@gmail.com",
|
"email": "sindresorhus@gmail.com",
|
||||||
"url": "sindresorhus.com"
|
"url": "sindresorhus.com"
|
||||||
},
|
},
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/sindresorhus/resolve-from/issues"
|
|
||||||
},
|
|
||||||
"dependencies": {},
|
|
||||||
"description": "Resolve the path of a module like require.resolve() but from a given path",
|
|
||||||
"devDependencies": {
|
|
||||||
"ava": "*",
|
|
||||||
"xo": "*"
|
|
||||||
},
|
|
||||||
"directories": {},
|
|
||||||
"dist": {
|
|
||||||
"shasum": "9480ab20e94ffa1d9e80a804c7ea147611966b57",
|
|
||||||
"tarball": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
"gitHead": "583e0f8df06e1bc4d1c96d8d4f2484c745f522c3",
|
|
||||||
"homepage": "https://github.com/sindresorhus/resolve-from#readme",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"require",
|
"require",
|
||||||
"resolve",
|
"resolve",
|
||||||
@ -77,23 +27,8 @@
|
|||||||
"like",
|
"like",
|
||||||
"path"
|
"path"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"devDependencies": {
|
||||||
"maintainers": [
|
"ava": "*",
|
||||||
{
|
"xo": "*"
|
||||||
"name": "sindresorhus",
|
}
|
||||||
"email": "sindresorhus@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "resolve-from",
|
|
||||||
"optionalDependencies": {},
|
|
||||||
"readme": "# resolve-from [![Build Status](https://travis-ci.org/sindresorhus/resolve-from.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-from)\n\n> Resolve the path of a module like [`require.resolve()`](http://nodejs.org/api/globals.html#globals_require_resolve) but from a given path\n\nUnlike `require.resolve()` it returns `null` instead of throwing when the module can't be found.\n\n\n## Install\n\n```\n$ npm install --save resolve-from\n```\n\n\n## Usage\n\n```js\nconst resolveFrom = require('resolve-from');\n\n// there's a file at `./foo/bar.js`\n\nresolveFrom('foo', './bar');\n//=> '/Users/sindresorhus/dev/test/foo/bar.js'\n```\n\n\n## API\n\n### resolveFrom(fromDir, moduleId)\n\n#### fromDir\n\nType: `string`\n\nDirectory to resolve from.\n\n#### moduleId\n\nType: `string`\n\nWhat you would use in `require()`.\n\n\n## Tip\n\nCreate a partial using a bound function if you want to require from the same `fromDir` multiple times:\n\n```js\nconst resolveFromFoo = resolveFrom.bind(null, 'foo');\n\nresolveFromFoo('./bar');\nresolveFromFoo('./baz');\n```\n\n\n## License\n\nMIT © [Sindre Sorhus](http://sindresorhus.com)\n",
|
|
||||||
"readmeFilename": "readme.md",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/sindresorhus/resolve-from.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "xo && ava"
|
|
||||||
},
|
|
||||||
"version": "2.0.0"
|
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/react": "^16.0.2",
|
"@types/react": "^16.0.2",
|
||||||
"@types/react-dom": "^15.5.2"
|
"@types/react-dom": "^15.5.2",
|
||||||
|
"axios": "^0.16.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ namespace RpcFunctions {
|
|||||||
const newAmount = new native.Amount(cd.coin.currentAmount);
|
const newAmount = new native.Amount(cd.coin.currentAmount);
|
||||||
newAmount.sub(coinSpend);
|
newAmount.sub(coinSpend);
|
||||||
cd.coin.currentAmount = newAmount.toJson();
|
cd.coin.currentAmount = newAmount.toJson();
|
||||||
cd.coin.status = CoinStatus.TransactionPending;
|
cd.coin.status = CoinStatus.PurchasePending;
|
||||||
|
|
||||||
const d = new native.DepositRequestPS({
|
const d = new native.DepositRequestPS({
|
||||||
amount_with_fee: coinSpend.toNbo(),
|
amount_with_fee: coinSpend.toNbo(),
|
||||||
|
@ -208,6 +208,44 @@ export async function recordException(msg: string, e: any): Promise<void> {
|
|||||||
return record("error", e.toString(), stack, frame.file, frame.line, frame.column);
|
return record("error", e.toString(), stack, frame.file, frame.line, frame.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for reports. Also used when something is so broken that we can't even
|
||||||
|
* access the database.
|
||||||
|
*/
|
||||||
|
const reportCache: { [reportId: string]: any } = {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a UUID that does not use cryptographically secure randomness.
|
||||||
|
* Formatted as RFC4122 version 4 UUID.
|
||||||
|
*/
|
||||||
|
function getInsecureUuid() {
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||||
|
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a report and return a unique identifier to retrieve it later.
|
||||||
|
*/
|
||||||
|
export async function storeReport(report: any): Promise<string> {
|
||||||
|
const uid = getInsecureUuid();
|
||||||
|
reportCache[uid] = report;
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a report by its unique identifier.
|
||||||
|
*/
|
||||||
|
export async function getReport(reportUid: string): Promise<any> {
|
||||||
|
return reportCache[reportUid];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record a log entry in the database.
|
* Record a log entry in the database.
|
||||||
*/
|
*/
|
||||||
@ -218,6 +256,8 @@ export async function record(level: Level,
|
|||||||
line?: number,
|
line?: number,
|
||||||
col?: number): Promise<void> {
|
col?: number): Promise<void> {
|
||||||
if (typeof indexedDB === "undefined") {
|
if (typeof indexedDB === "undefined") {
|
||||||
|
console.log("can't access DB for logging in this context");
|
||||||
|
console.log("log was", { level, msg, detail, source, line, col });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +297,7 @@ export async function record(level: Level,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const loggingDbVersion = 1;
|
const loggingDbVersion = 2;
|
||||||
|
|
||||||
const logsStore: Store<LogEntry> = new Store<LogEntry>("logs");
|
const logsStore: Store<LogEntry> = new Store<LogEntry>("logs");
|
||||||
|
|
||||||
@ -283,7 +323,8 @@ export function openLoggingDb(): Promise<IDBDatabase> {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resDb.createObjectStore("logs", {keyPath: "id", autoIncrement: true});
|
resDb.createObjectStore("logs", { keyPath: "id", autoIncrement: true });
|
||||||
|
resDb.createObjectStore("reports", { keyPath: "uid", autoIncrement: false });
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
27
src/query.ts
27
src/query.ts
@ -547,9 +547,18 @@ export class QueryRoot {
|
|||||||
|
|
||||||
private finished: boolean = false;
|
private finished: boolean = false;
|
||||||
|
|
||||||
|
private keys: { [keyName: string]: IDBValidKey } = {};
|
||||||
|
|
||||||
constructor(public db: IDBDatabase) {
|
constructor(public db: IDBDatabase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a named key that was created during the query.
|
||||||
|
*/
|
||||||
|
key(keyName: string): IDBValidKey|undefined {
|
||||||
|
return this.keys[keyName];
|
||||||
|
}
|
||||||
|
|
||||||
private checkFinished() {
|
private checkFinished() {
|
||||||
if (this.finished) {
|
if (this.finished) {
|
||||||
throw Error("Can't add work to query after it was started");
|
throw Error("Can't add work to query after it was started");
|
||||||
@ -627,10 +636,15 @@ export class QueryRoot {
|
|||||||
* Overrides if an existing object with the same key exists
|
* Overrides if an existing object with the same key exists
|
||||||
* in the store.
|
* in the store.
|
||||||
*/
|
*/
|
||||||
put<T>(store: Store<T>, val: T): QueryRoot {
|
put<T>(store: Store<T>, val: T, keyName?: string): QueryRoot {
|
||||||
this.checkFinished();
|
this.checkFinished();
|
||||||
const doPut = (tx: IDBTransaction) => {
|
const doPut = (tx: IDBTransaction) => {
|
||||||
tx.objectStore(store.name).put(val);
|
const req = tx.objectStore(store.name).put(val);
|
||||||
|
if (keyName) {
|
||||||
|
req.onsuccess = () => {
|
||||||
|
this.keys[keyName] = req.result;
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
this.scheduleFinish();
|
this.scheduleFinish();
|
||||||
this.addWork(doPut, store.name, true);
|
this.addWork(doPut, store.name, true);
|
||||||
@ -658,13 +672,13 @@ export class QueryRoot {
|
|||||||
/**
|
/**
|
||||||
* Get, modify and store an element inside a transaction.
|
* Get, modify and store an element inside a transaction.
|
||||||
*/
|
*/
|
||||||
mutate<T>(store: Store<T>, key: any, f: (v: T) => T): QueryRoot {
|
mutate<T>(store: Store<T>, key: any, f: (v: T|undefined) => T|undefined): QueryRoot {
|
||||||
this.checkFinished();
|
this.checkFinished();
|
||||||
const doPut = (tx: IDBTransaction) => {
|
const doPut = (tx: IDBTransaction) => {
|
||||||
const reqGet = tx.objectStore(store.name).get(key);
|
const reqGet = tx.objectStore(store.name).get(key);
|
||||||
reqGet.onsuccess = () => {
|
reqGet.onsuccess = () => {
|
||||||
const r = reqGet.result;
|
const r = reqGet.result;
|
||||||
let m: T;
|
let m: T|undefined;
|
||||||
try {
|
try {
|
||||||
m = f(r);
|
m = f(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -674,8 +688,9 @@ export class QueryRoot {
|
|||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
if (m !== undefined && m !== null) {
|
||||||
tx.objectStore(store.name).put(m);
|
tx.objectStore(store.name).put(m);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
this.scheduleFinish();
|
this.scheduleFinish();
|
||||||
|
41
src/types.ts
41
src/types.ts
@ -759,6 +759,11 @@ export interface RefreshSessionRecord {
|
|||||||
* Is this session finished?
|
* Is this session finished?
|
||||||
*/
|
*/
|
||||||
finished: boolean;
|
finished: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record ID when retrieved from the DB.
|
||||||
|
*/
|
||||||
|
id?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -798,9 +803,9 @@ export enum CoinStatus {
|
|||||||
*/
|
*/
|
||||||
Fresh,
|
Fresh,
|
||||||
/**
|
/**
|
||||||
* Currently planned to be sent to a merchant for a transaction.
|
* Currently planned to be sent to a merchant for a purchase.
|
||||||
*/
|
*/
|
||||||
TransactionPending,
|
PurchasePending,
|
||||||
/**
|
/**
|
||||||
* Used for a completed transaction and now dirty.
|
* Used for a completed transaction and now dirty.
|
||||||
*/
|
*/
|
||||||
@ -1307,7 +1312,7 @@ export namespace Amounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value = value + x.value + Math.floor((fraction + x.fraction) / fractionalBase);
|
value = value + x.value + Math.floor((fraction + x.fraction) / fractionalBase);
|
||||||
fraction = (fraction + x.fraction) % fractionalBase;
|
fraction = Math.floor((fraction + x.fraction) % fractionalBase);
|
||||||
if (value > Number.MAX_SAFE_INTEGER) {
|
if (value > Number.MAX_SAFE_INTEGER) {
|
||||||
return { amount: getMaxAmount(currency), saturated: true };
|
return { amount: getMaxAmount(currency), saturated: true };
|
||||||
}
|
}
|
||||||
@ -1435,7 +1440,7 @@ export namespace Amounts {
|
|||||||
export function fromFloat(floatVal: number, currency: string) {
|
export function fromFloat(floatVal: number, currency: string) {
|
||||||
return {
|
return {
|
||||||
currency,
|
currency,
|
||||||
fraction: (floatVal - Math.floor(floatVal)) * fractionalBase,
|
fraction: Math.floor((floatVal - Math.floor(floatVal)) * fractionalBase),
|
||||||
value: Math.floor(floatVal),
|
value: Math.floor(floatVal),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1662,3 +1667,31 @@ export class ReturnCoinsRequest {
|
|||||||
*/
|
*/
|
||||||
static checked: (obj: any) => ReturnCoinsRequest;
|
static checked: (obj: any) => ReturnCoinsRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface RefundPermission {
|
||||||
|
refund_amount: AmountJson;
|
||||||
|
refund_fee: AmountJson;
|
||||||
|
h_contract_terms: string;
|
||||||
|
coin_pub: string;
|
||||||
|
rtransaction_id: number;
|
||||||
|
merchant_pub: string;
|
||||||
|
merchant_sig: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface PurchaseRecord {
|
||||||
|
contractTermsHash: string;
|
||||||
|
contractTerms: ContractTerms;
|
||||||
|
payReq: PayReq;
|
||||||
|
merchantSig: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purchase isn't active anymore, it's either successfully paid or
|
||||||
|
* refunded/aborted.
|
||||||
|
*/
|
||||||
|
finished: boolean;
|
||||||
|
|
||||||
|
refundsPending: { [refundSig: string]: RefundPermission };
|
||||||
|
refundsDone: { [refundSig: string]: RefundPermission };
|
||||||
|
}
|
||||||
|
198
src/wallet.ts
198
src/wallet.ts
@ -82,6 +82,8 @@ import {
|
|||||||
WalletBalanceEntry,
|
WalletBalanceEntry,
|
||||||
WireFee,
|
WireFee,
|
||||||
WireInfo,
|
WireInfo,
|
||||||
|
RefundPermission,
|
||||||
|
PurchaseRecord,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import URI = require("urijs");
|
import URI = require("urijs");
|
||||||
|
|
||||||
@ -241,19 +243,6 @@ class WireDetailJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface TransactionRecord {
|
|
||||||
contractTermsHash: string;
|
|
||||||
contractTerms: ContractTerms;
|
|
||||||
payReq: PayReq;
|
|
||||||
merchantSig: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The transaction isn't active anymore, it's either successfully paid
|
|
||||||
* or refunded/aborted.
|
|
||||||
*/
|
|
||||||
finished: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Badge that shows activity for the wallet.
|
* Badge that shows activity for the wallet.
|
||||||
@ -424,6 +413,8 @@ export function selectPayCoins(cds: CoinWithDenom[], paymentAmount: AmountJson,
|
|||||||
denom.feeDeposit).amount) >= 0;
|
denom.feeDeposit).amount) >= 0;
|
||||||
isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
|
isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
|
||||||
|
|
||||||
|
console.log("coin selection", { coversAmount, isBelowFee, accFee, accAmount, paymentAmount });
|
||||||
|
|
||||||
if ((coversAmount && isBelowFee) || coversAmountWithFee) {
|
if ((coversAmount && isBelowFee) || coversAmountWithFee) {
|
||||||
return cdsResult;
|
return cdsResult;
|
||||||
}
|
}
|
||||||
@ -516,13 +507,13 @@ export namespace Stores {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransactionsStore extends Store<TransactionRecord> {
|
class PurchasesStore extends Store<PurchaseRecord> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("transactions", {keyPath: "contractTermsHash"});
|
super("purchases", {keyPath: "contractTermsHash"});
|
||||||
}
|
}
|
||||||
|
|
||||||
fulfillmentUrlIndex = new Index<string, TransactionRecord>(this, "fulfillment_url", "contractTerms.fulfillment_url");
|
fulfillmentUrlIndex = new Index<string, PurchaseRecord>(this, "fulfillment_url", "contractTerms.fulfillment_url");
|
||||||
orderIdIndex = new Index<string, TransactionRecord>(this, "order_id", "contractTerms.order_id");
|
orderIdIndex = new Index<string, PurchaseRecord>(this, "order_id", "contractTerms.order_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
class DenominationsStore extends Store<DenominationRecord> {
|
class DenominationsStore extends Store<DenominationRecord> {
|
||||||
@ -566,9 +557,9 @@ export namespace Stores {
|
|||||||
export const nonces = new NonceStore();
|
export const nonces = new NonceStore();
|
||||||
export const precoins = new Store<PreCoinRecord>("precoins", {keyPath: "coinPub"});
|
export const precoins = new Store<PreCoinRecord>("precoins", {keyPath: "coinPub"});
|
||||||
export const proposals = new ProposalsStore();
|
export const proposals = new ProposalsStore();
|
||||||
export const refresh = new Store<RefreshSessionRecord>("refresh", {keyPath: "meltCoinPub"});
|
export const refresh = new Store<RefreshSessionRecord>("refresh", {keyPath: "id", autoIncrement: true});
|
||||||
export const reserves = new Store<ReserveRecord>("reserves", {keyPath: "reserve_pub"});
|
export const reserves = new Store<ReserveRecord>("reserves", {keyPath: "reserve_pub"});
|
||||||
export const transactions = new TransactionsStore();
|
export const purchases = new PurchasesStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tslint:enable:completed-docs */
|
/* tslint:enable:completed-docs */
|
||||||
@ -770,6 +761,8 @@ export class Wallet {
|
|||||||
cds.push({coin, denom});
|
cds.push({coin, denom});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("coin return: selecting from possible coins", { cds, amount } );
|
||||||
|
|
||||||
return selectPayCoins(cds, amount, amount);
|
return selectPayCoins(cds, amount, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -909,12 +902,14 @@ export class Wallet {
|
|||||||
merchant_pub: proposal.contractTerms.merchant_pub,
|
merchant_pub: proposal.contractTerms.merchant_pub,
|
||||||
order_id: proposal.contractTerms.order_id,
|
order_id: proposal.contractTerms.order_id,
|
||||||
};
|
};
|
||||||
const t: TransactionRecord = {
|
const t: PurchaseRecord = {
|
||||||
contractTerms: proposal.contractTerms,
|
contractTerms: proposal.contractTerms,
|
||||||
contractTermsHash: proposal.contractTermsHash,
|
contractTermsHash: proposal.contractTermsHash,
|
||||||
finished: false,
|
finished: false,
|
||||||
merchantSig: proposal.merchantSig,
|
merchantSig: proposal.merchantSig,
|
||||||
payReq,
|
payReq,
|
||||||
|
refundsDone: {},
|
||||||
|
refundsPending: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const historyEntry: HistoryRecord = {
|
const historyEntry: HistoryRecord = {
|
||||||
@ -931,7 +926,7 @@ export class Wallet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await this.q()
|
await this.q()
|
||||||
.put(Stores.transactions, t)
|
.put(Stores.purchases, t)
|
||||||
.put(Stores.history, historyEntry)
|
.put(Stores.history, historyEntry)
|
||||||
.putAll(Stores.coins, payCoinInfo.map((pci) => pci.updatedCoin))
|
.putAll(Stores.coins, payCoinInfo.map((pci) => pci.updatedCoin))
|
||||||
.finish();
|
.finish();
|
||||||
@ -972,9 +967,9 @@ export class Wallet {
|
|||||||
throw Error(`proposal with id ${proposalId} not found`);
|
throw Error(`proposal with id ${proposalId} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transaction = await this.q().get(Stores.transactions, proposal.contractTermsHash);
|
const purchase = await this.q().get(Stores.purchases, proposal.contractTermsHash);
|
||||||
|
|
||||||
if (transaction) {
|
if (purchase) {
|
||||||
// Already payed ...
|
// Already payed ...
|
||||||
return "paid";
|
return "paid";
|
||||||
}
|
}
|
||||||
@ -1017,8 +1012,8 @@ export class Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First check if we already payed for it.
|
// First check if we already payed for it.
|
||||||
const transaction = await this.q().get(Stores.transactions, proposal.contractTermsHash);
|
const purchase = await this.q().get(Stores.purchases, proposal.contractTermsHash);
|
||||||
if (transaction) {
|
if (purchase) {
|
||||||
return "paid";
|
return "paid";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1049,7 +1044,7 @@ export class Wallet {
|
|||||||
async queryPayment(url: string): Promise<QueryPaymentResult> {
|
async queryPayment(url: string): Promise<QueryPaymentResult> {
|
||||||
console.log("query for payment", url);
|
console.log("query for payment", url);
|
||||||
|
|
||||||
const t = await this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, url);
|
const t = await this.q().getIndexed(Stores.purchases.fulfillmentUrlIndex, url);
|
||||||
|
|
||||||
if (!t) {
|
if (!t) {
|
||||||
console.log("query for payment failed");
|
console.log("query for payment failed");
|
||||||
@ -1845,7 +1840,7 @@ export class Wallet {
|
|||||||
if (c.suspended) {
|
if (c.suspended) {
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
if (!(c.status === CoinStatus.Dirty || c.status === CoinStatus.Fresh)) {
|
if (!(c.status === CoinStatus.Fresh)) {
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
console.log("collecting balance");
|
console.log("collecting balance");
|
||||||
@ -1890,7 +1885,7 @@ export class Wallet {
|
|||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectPayments(t: TransactionRecord, balance: WalletBalance) {
|
function collectPayments(t: PurchaseRecord, balance: WalletBalance) {
|
||||||
if (t.finished) {
|
if (t.finished) {
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
@ -1934,7 +1929,7 @@ export class Wallet {
|
|||||||
.reduce(collectPendingWithdraw, balance);
|
.reduce(collectPendingWithdraw, balance);
|
||||||
tx.iter(Stores.reserves)
|
tx.iter(Stores.reserves)
|
||||||
.reduce(collectPaybacks, balance);
|
.reduce(collectPaybacks, balance);
|
||||||
tx.iter(Stores.transactions)
|
tx.iter(Stores.purchases)
|
||||||
.reduce(collectPayments, balance);
|
.reduce(collectPayments, balance);
|
||||||
await tx.finish();
|
await tx.finish();
|
||||||
return balance;
|
return balance;
|
||||||
@ -2008,25 +2003,30 @@ export class Wallet {
|
|||||||
|
|
||||||
// Store refresh session and subtract refreshed amount from
|
// Store refresh session and subtract refreshed amount from
|
||||||
// coin in the same transaction.
|
// coin in the same transaction.
|
||||||
await this.q()
|
const query = this.q();
|
||||||
.put(Stores.refresh, refreshSession)
|
query.put(Stores.refresh, refreshSession, "refreshKey")
|
||||||
.mutate(Stores.coins, coin.coinPub, mutateCoin)
|
.mutate(Stores.coins, coin.coinPub, mutateCoin);
|
||||||
.finish();
|
await query.finish();
|
||||||
|
|
||||||
|
const key = query.key("refreshKey");
|
||||||
|
if (!key || typeof key !== "number") {
|
||||||
|
throw Error("insert failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshSession.id = key;
|
||||||
|
|
||||||
return refreshSession;
|
return refreshSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async refresh(oldCoinPub: string): Promise<void> {
|
async refresh(oldCoinPub: string): Promise<void> {
|
||||||
let refreshSession: RefreshSessionRecord|undefined;
|
|
||||||
const oldSession = await this.q().get(Stores.refresh, oldCoinPub);
|
const oldRefreshSessions = await this.q().iter(Stores.refresh).toArray();
|
||||||
if (oldSession) {
|
for (const session of oldRefreshSessions) {
|
||||||
console.log("got old session for", oldCoinPub);
|
console.log("got old session for", oldCoinPub, session);
|
||||||
console.log(oldSession);
|
this.continueRefreshSession(session);
|
||||||
refreshSession = oldSession;
|
|
||||||
} else {
|
|
||||||
refreshSession = await this.createRefreshSession(oldCoinPub);
|
|
||||||
}
|
}
|
||||||
|
let refreshSession = await this.createRefreshSession(oldCoinPub);
|
||||||
if (!refreshSession) {
|
if (!refreshSession) {
|
||||||
// refreshing not necessary
|
// refreshing not necessary
|
||||||
console.log("not refreshing", oldCoinPub);
|
console.log("not refreshing", oldCoinPub);
|
||||||
@ -2040,9 +2040,8 @@ export class Wallet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof refreshSession.norevealIndex !== "number") {
|
if (typeof refreshSession.norevealIndex !== "number") {
|
||||||
const coinPub = refreshSession.meltCoinPub;
|
|
||||||
await this.refreshMelt(refreshSession);
|
await this.refreshMelt(refreshSession);
|
||||||
const r = await this.q().get<RefreshSessionRecord>(Stores.refresh, coinPub);
|
const r = await this.q().get<RefreshSessionRecord>(Stores.refresh, refreshSession.id);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
throw Error("refresh session does not exist anymore");
|
throw Error("refresh session does not exist anymore");
|
||||||
}
|
}
|
||||||
@ -2282,7 +2281,7 @@ export class Wallet {
|
|||||||
|
|
||||||
async paymentSucceeded(contractTermsHash: string, merchantSig: string): Promise<any> {
|
async paymentSucceeded(contractTermsHash: string, merchantSig: string): Promise<any> {
|
||||||
const doPaymentSucceeded = async() => {
|
const doPaymentSucceeded = async() => {
|
||||||
const t = await this.q().get<TransactionRecord>(Stores.transactions,
|
const t = await this.q().get<PurchaseRecord>(Stores.purchases,
|
||||||
contractTermsHash);
|
contractTermsHash);
|
||||||
if (!t) {
|
if (!t) {
|
||||||
console.error("contract not found");
|
console.error("contract not found");
|
||||||
@ -2309,7 +2308,7 @@ export class Wallet {
|
|||||||
|
|
||||||
await this.q()
|
await this.q()
|
||||||
.putAll(Stores.coins, modifiedCoins)
|
.putAll(Stores.coins, modifiedCoins)
|
||||||
.put(Stores.transactions, t)
|
.put(Stores.purchases, t)
|
||||||
.finish();
|
.finish();
|
||||||
for (const c of t.payReq.coins) {
|
for (const c of t.payReq.coins) {
|
||||||
this.refresh(c.coin_pub);
|
this.refresh(c.coin_pub);
|
||||||
@ -2422,7 +2421,7 @@ export class Wallet {
|
|||||||
const senderWiresSet = new Set();
|
const senderWiresSet = new Set();
|
||||||
await this.q().iter(Stores.reserves).map((x) => {
|
await this.q().iter(Stores.reserves).map((x) => {
|
||||||
if (x.senderWire) {
|
if (x.senderWire) {
|
||||||
senderWiresSet.add(JSON.stringify(x.senderWire));
|
senderWiresSet.add(canonicalJson(x.senderWire));
|
||||||
}
|
}
|
||||||
}).run();
|
}).run();
|
||||||
const senderWires = Array.from(senderWiresSet).map((x) => JSON.parse(x));
|
const senderWires = Array.from(senderWiresSet).map((x) => JSON.parse(x));
|
||||||
@ -2450,6 +2449,7 @@ export class Wallet {
|
|||||||
console.error(`Exchange ${req.exchange} not known to the wallet`);
|
console.error(`Exchange ${req.exchange} not known to the wallet`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("selecting coins for return:", req);
|
||||||
const cds = await this.getCoinsForReturn(req.exchange, req.amount);
|
const cds = await this.getCoinsForReturn(req.exchange, req.amount);
|
||||||
console.log(cds);
|
console.log(cds);
|
||||||
|
|
||||||
@ -2560,4 +2560,110 @@ export class Wallet {
|
|||||||
await this.q().put(Stores.coinsReturns, currentCrr);
|
await this.q().put(Stores.coinsReturns, currentCrr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async acceptRefund(refundPermissions: RefundPermission[]): Promise<void> {
|
||||||
|
if (!refundPermissions.length) {
|
||||||
|
console.warn("got empty refund list");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hc = refundPermissions[0].h_contract_terms;
|
||||||
|
if (!hc) {
|
||||||
|
throw Error("h_contract_terms missing in refund permission");
|
||||||
|
}
|
||||||
|
const m = refundPermissions[0].merchant_pub;
|
||||||
|
if (!hc) {
|
||||||
|
throw Error("merchant_pub missing in refund permission");
|
||||||
|
}
|
||||||
|
for (const perm of refundPermissions) {
|
||||||
|
if (perm.h_contract_terms !== hc) {
|
||||||
|
throw Error("h_contract_terms different in refund permission");
|
||||||
|
}
|
||||||
|
if (perm.merchant_pub !== m) {
|
||||||
|
throw Error("merchant_pub different in refund permission");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add refund to purchase if not already added.
|
||||||
|
*/
|
||||||
|
function f(t: PurchaseRecord|undefined): PurchaseRecord|undefined {
|
||||||
|
if (!t) {
|
||||||
|
console.error("purchase not found, not adding refunds");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const perm of refundPermissions) {
|
||||||
|
if (!t.refundsPending[perm.merchant_sig] && !t.refundsDone[perm.merchant_sig]) {
|
||||||
|
t.refundsPending[perm.merchant_sig] = perm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the refund permissions to the purchase within a DB transaction
|
||||||
|
await this.q().mutate(Stores.purchases, hc, f).finish();
|
||||||
|
this.notifier.notify();
|
||||||
|
|
||||||
|
// Start submitting it but don't wait for it here.
|
||||||
|
this.submitRefunds(hc);
|
||||||
|
}
|
||||||
|
|
||||||
|
async submitRefunds(contractTermsHash: string): Promise<void> {
|
||||||
|
const purchase = await this.q().get(Stores.purchases, contractTermsHash);
|
||||||
|
if (!purchase) {
|
||||||
|
console.error("not submitting refunds, contract terms not found:", contractTermsHash);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pendingKeys = Object.keys(purchase.refundsPending);
|
||||||
|
if (pendingKeys.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const pk of pendingKeys) {
|
||||||
|
const perm = purchase.refundsPending[pk];
|
||||||
|
console.log("sending refund permission", perm);
|
||||||
|
const reqUrl = (new URI("refund")).absoluteTo(purchase.payReq.exchange);
|
||||||
|
const resp = await this.http.postJson(reqUrl.href(), perm);
|
||||||
|
if (resp.status !== 200) {
|
||||||
|
console.error("refund failed", resp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transactionally mark successful refunds as done
|
||||||
|
const transformPurchase = (t: PurchaseRecord|undefined): PurchaseRecord|undefined => {
|
||||||
|
if (!t) {
|
||||||
|
console.warn("purchase not found, not updating refund");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (t.refundsPending[pk]) {
|
||||||
|
t.refundsDone[pk] = t.refundsPending[pk];
|
||||||
|
delete t.refundsPending[pk];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
const transformCoin = (c: CoinRecord|undefined): CoinRecord|undefined => {
|
||||||
|
if (!c) {
|
||||||
|
console.warn("coin not found, can't apply refund");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
c.status = CoinStatus.Dirty;
|
||||||
|
c.currentAmount = Amounts.add(c.currentAmount, perm.refund_amount).amount;
|
||||||
|
c.currentAmount = Amounts.sub(c.currentAmount, perm.refund_fee).amount;
|
||||||
|
|
||||||
|
return c;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
await this.q()
|
||||||
|
.mutate(Stores.purchases, contractTermsHash, transformPurchase)
|
||||||
|
.mutate(Stores.coins, perm.coin_pub, transformCoin)
|
||||||
|
.finish();
|
||||||
|
this.refresh(perm.coin_pub);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notifier.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPurchase(contractTermsHash: string): Promise<PurchaseRecord|undefined> {
|
||||||
|
return this.q().get(Stores.purchases, contractTermsHash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,22 @@ export interface MessageMap {
|
|||||||
request: { };
|
request: { };
|
||||||
response: void;
|
response: void;
|
||||||
};
|
};
|
||||||
|
"log-and-display-error": {
|
||||||
|
request: any;
|
||||||
|
response: void;
|
||||||
|
};
|
||||||
|
"get-report": {
|
||||||
|
request: { reportUid: string };
|
||||||
|
response: void;
|
||||||
|
};
|
||||||
|
"accept-refund": {
|
||||||
|
request: any;
|
||||||
|
response: void;
|
||||||
|
};
|
||||||
|
"get-purchase": {
|
||||||
|
request: any;
|
||||||
|
response: void;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,8 @@ import wxApi = require("./wxApi");
|
|||||||
|
|
||||||
import { QueryPaymentResult } from "../types";
|
import { QueryPaymentResult } from "../types";
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
declare var cloneInto: any;
|
declare var cloneInto: any;
|
||||||
|
|
||||||
let logVerbose: boolean = false;
|
let logVerbose: boolean = false;
|
||||||
@ -98,85 +100,39 @@ function setStyles(installed: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handlePaymentResponse(maybeFoundResponse: QueryPaymentResult) {
|
async function handlePaymentResponse(maybeFoundResponse: QueryPaymentResult) {
|
||||||
if (!maybeFoundResponse.found) {
|
if (!maybeFoundResponse.found) {
|
||||||
console.log("pay-failed", {hint: "payment not found in the wallet"});
|
console.log("pay-failed", {hint: "payment not found in the wallet"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const walletResp = maybeFoundResponse;
|
const walletResp = maybeFoundResponse;
|
||||||
/**
|
|
||||||
* Handle a failed payment.
|
|
||||||
*
|
|
||||||
* Try to notify the wallet first, before we show a potentially
|
|
||||||
* synchronous error message (such as an alert) or leave the page.
|
|
||||||
*/
|
|
||||||
async function handleFailedPayment(r: XMLHttpRequest) {
|
|
||||||
let timeoutHandle: number|null = null;
|
|
||||||
function err() {
|
|
||||||
// FIXME: proper error reporting!
|
|
||||||
console.log("pay-failed", {status: r.status, response: r.responseText});
|
|
||||||
}
|
|
||||||
function onTimeout() {
|
|
||||||
timeoutHandle = null;
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
timeoutHandle = window.setTimeout(onTimeout, 200);
|
|
||||||
|
|
||||||
await wxApi.paymentFailed(walletResp.contractTermsHash);
|
|
||||||
if (timeoutHandle !== null) {
|
|
||||||
clearTimeout(timeoutHandle);
|
|
||||||
timeoutHandle = null;
|
|
||||||
}
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
|
|
||||||
logVerbose && console.log("handling taler-notify-payment: ", walletResp);
|
logVerbose && console.log("handling taler-notify-payment: ", walletResp);
|
||||||
// Payment timeout in ms.
|
let resp;
|
||||||
let timeout_ms = 1000;
|
try {
|
||||||
// Current request.
|
const config = {
|
||||||
let r: XMLHttpRequest|null;
|
timeout: 5000, /* 5 seconds */
|
||||||
let timeoutHandle: number|null = null;
|
headers: { "Content-Type": "application/json;charset=UTF-8" },
|
||||||
function sendPay() {
|
validateStatus: (s: number) => s == 200,
|
||||||
r = new XMLHttpRequest();
|
|
||||||
r.open("post", walletResp.contractTerms.pay_url);
|
|
||||||
r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
||||||
r.send(JSON.stringify(walletResp.payReq));
|
|
||||||
r.onload = async () => {
|
|
||||||
if (!r) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (r.status) {
|
|
||||||
case 200:
|
|
||||||
const merchantResp = JSON.parse(r.responseText);
|
|
||||||
logVerbose && console.log("got success from pay_url");
|
|
||||||
await wxApi.paymentSucceeded(walletResp.contractTermsHash, merchantResp.sig);
|
|
||||||
const nextUrl = walletResp.contractTerms.fulfillment_url;
|
|
||||||
logVerbose && console.log("taler-payment-succeeded done, going to", nextUrl);
|
|
||||||
window.location.href = nextUrl;
|
|
||||||
window.location.reload(true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
handleFailedPayment(r);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
r = null;
|
|
||||||
if (timeoutHandle !== null) {
|
|
||||||
clearTimeout(timeoutHandle!);
|
|
||||||
timeoutHandle = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function retry() {
|
|
||||||
if (r) {
|
|
||||||
r.abort();
|
|
||||||
r = null;
|
|
||||||
}
|
|
||||||
timeout_ms = Math.min(timeout_ms * 2, 10 * 1000);
|
|
||||||
logVerbose && console.log("sendPay timed out, retrying in ", timeout_ms, "ms");
|
|
||||||
sendPay();
|
|
||||||
}
|
}
|
||||||
timeoutHandle = window.setTimeout(retry, timeout_ms);
|
resp = await axios.post(walletResp.contractTerms.pay_url, walletResp.payReq, config);
|
||||||
|
} catch (e) {
|
||||||
|
// Gives the user the option to retry / abort and refresh
|
||||||
|
wxApi.logAndDisplayError({
|
||||||
|
name: "pay-post-failed",
|
||||||
|
contractTerms: walletResp.contractTerms,
|
||||||
|
message: e.message,
|
||||||
|
response: e.response,
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
sendPay();
|
const merchantResp = resp.data;
|
||||||
|
logVerbose && console.log("got success from pay_url");
|
||||||
|
await wxApi.paymentSucceeded(walletResp.contractTermsHash, merchantResp.sig);
|
||||||
|
const nextUrl = walletResp.contractTerms.fulfillment_url;
|
||||||
|
logVerbose && console.log("taler-payment-succeeded done, going to", nextUrl);
|
||||||
|
window.location.href = nextUrl;
|
||||||
|
window.location.reload(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -233,53 +189,24 @@ function init() {
|
|||||||
|
|
||||||
type HandlerFn = (detail: any, sendResponse: (msg: any) => void) => void;
|
type HandlerFn = (detail: any, sendResponse: (msg: any) => void) => void;
|
||||||
|
|
||||||
function downloadContract(url: string, nonce: string): Promise<any> {
|
async function downloadContract(url: string, nonce: string): Promise<any> {
|
||||||
const parsed_url = new URI(url);
|
const parsed_url = new URI(url);
|
||||||
url = parsed_url.setQuery({nonce}).href();
|
url = parsed_url.setQuery({nonce}).href();
|
||||||
// FIXME: include and check nonce!
|
console.log("downloading contract from '" + url + "'");
|
||||||
return new Promise((resolve, reject) => {
|
let resp;
|
||||||
const contract_request = new XMLHttpRequest();
|
try {
|
||||||
console.log("downloading contract from '" + url + "'");
|
resp = await axios.get(url, { validateStatus: (s) => s == 200 });
|
||||||
contract_request.open("GET", url, true);
|
} catch (e) {
|
||||||
contract_request.onload = (e) => {
|
wxApi.logAndDisplayError({
|
||||||
if (contract_request.readyState === 4) {
|
name: "contract-download-failed",
|
||||||
if (contract_request.status === 200) {
|
message: e.message,
|
||||||
console.log("response text:",
|
response: e.response,
|
||||||
contract_request.responseText);
|
sameTab: true,
|
||||||
const contract_wrapper = JSON.parse(contract_request.responseText);
|
});
|
||||||
if (!contract_wrapper) {
|
throw e;
|
||||||
console.error("response text was invalid json");
|
}
|
||||||
const detail = {
|
console.log("got response", resp);
|
||||||
body: contract_request.responseText,
|
return resp.data;
|
||||||
hint: "invalid json",
|
|
||||||
status: contract_request.status,
|
|
||||||
};
|
|
||||||
reject(detail);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(contract_wrapper);
|
|
||||||
} else {
|
|
||||||
const detail = {
|
|
||||||
body: contract_request.responseText,
|
|
||||||
hint: "contract download failed",
|
|
||||||
status: contract_request.status,
|
|
||||||
};
|
|
||||||
reject(detail);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
contract_request.onerror = (e) => {
|
|
||||||
const detail = {
|
|
||||||
body: contract_request.responseText,
|
|
||||||
hint: "contract download failed",
|
|
||||||
status: contract_request.status,
|
|
||||||
};
|
|
||||||
reject(detail);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
contract_request.send();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processProposal(proposal: any) {
|
async function processProposal(proposal: any) {
|
||||||
@ -328,8 +255,38 @@ async function processProposal(proposal: any) {
|
|||||||
document.location.replace(target);
|
document.location.replace(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a payment request (coming either from an HTTP 402 or
|
||||||
|
* the JS wallet API).
|
||||||
|
*/
|
||||||
function talerPay(msg: any): Promise<any> {
|
function talerPay(msg: any): Promise<any> {
|
||||||
|
// Use a promise directly instead of of an async
|
||||||
|
// function since some paths never resolve the promise.
|
||||||
return new Promise(async(resolve, reject) => {
|
return new Promise(async(resolve, reject) => {
|
||||||
|
if (msg.refund_url) {
|
||||||
|
console.log("processing refund");
|
||||||
|
let resp;
|
||||||
|
try {
|
||||||
|
const config = {
|
||||||
|
validateStatus: (s: number) => s == 200,
|
||||||
|
}
|
||||||
|
resp = await axios.get(msg.refund_url, config);
|
||||||
|
} catch (e) {
|
||||||
|
wxApi.logAndDisplayError({
|
||||||
|
name: "refund-download-failed",
|
||||||
|
message: e.message,
|
||||||
|
response: e.response,
|
||||||
|
sameTab: true,
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
await wxApi.acceptRefund(resp.data);
|
||||||
|
const hc = resp.data.refund_permissions[0].h_contract_terms;
|
||||||
|
document.location.href = chrome.extension.getURL(`/src/webex/pages/refund.html?contractTermsHash=${hc}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// current URL without fragment
|
// current URL without fragment
|
||||||
const url = new URI(document.location.href).fragment("").href();
|
const url = new URI(document.location.href).fragment("").href();
|
||||||
const res = await wxApi.queryPayment(url);
|
const res = await wxApi.queryPayment(url);
|
||||||
|
@ -41,7 +41,7 @@ import {
|
|||||||
getReserveCreationInfo,
|
getReserveCreationInfo,
|
||||||
} from "../wxApi";
|
} from "../wxApi";
|
||||||
|
|
||||||
import {renderAmount} from "../renderHtml";
|
import {Collapsible, renderAmount} from "../renderHtml";
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
@ -80,40 +80,6 @@ class EventTrigger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface CollapsibleState {
|
|
||||||
collapsed: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CollapsibleProps {
|
|
||||||
initiallyCollapsed: boolean;
|
|
||||||
title: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Collapsible extends React.Component<CollapsibleProps, CollapsibleState> {
|
|
||||||
constructor(props: CollapsibleProps) {
|
|
||||||
super(props);
|
|
||||||
this.state = { collapsed: props.initiallyCollapsed };
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
const doOpen = (e: any) => {
|
|
||||||
this.setState({collapsed: false});
|
|
||||||
e.preventDefault();
|
|
||||||
};
|
|
||||||
const doClose = (e: any) => {
|
|
||||||
this.setState({collapsed: true});
|
|
||||||
e.preventDefault();
|
|
||||||
};
|
|
||||||
if (this.state.collapsed) {
|
|
||||||
return <h2><a className="opener opener-collapsed" href="#" onClick={doOpen}>{this.props.title}</a></h2>;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h2><a className="opener opener-open" href="#" onClick={doClose}>{this.props.title}</a></h2>
|
|
||||||
{this.props.children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderAuditorDetails(rci: ReserveCreationInfo|null) {
|
function renderAuditorDetails(rci: ReserveCreationInfo|null) {
|
||||||
console.log("rci", rci);
|
console.log("rci", rci);
|
||||||
@ -405,7 +371,7 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> {
|
|||||||
if (this.statusString()) {
|
if (this.statusString()) {
|
||||||
return (
|
return (
|
||||||
<p>
|
<p>
|
||||||
<strong style={{color: "red"}}>{i18n.str`A problem occured, see below. ${this.statusString()}`}</strong>
|
<strong style={{color: "red"}}>{this.statusString()}</strong>
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -549,12 +515,9 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> {
|
|||||||
console.dir(r);
|
console.dir(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("get exchange info rejected", e);
|
console.log("get exchange info rejected", e);
|
||||||
if (e.hasOwnProperty("httpStatus")) {
|
this.statusString(`Error: ${e.message}`);
|
||||||
this.statusString(`Error: request failed with status ${e.httpStatus}`);
|
// Re-try every 5 seconds as long as there is a problem
|
||||||
} else if (e.hasOwnProperty("errorResponse")) {
|
setTimeout(() => this.statusString() ? this.forceReserveUpdate() : undefined, 5000);
|
||||||
const resp = e.errorResponse;
|
|
||||||
this.statusString(`Error: ${resp.error} (${resp.hint})`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,40 +22,103 @@
|
|||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
import URI = require("urijs");
|
import URI = require("urijs");
|
||||||
|
|
||||||
|
import * as wxApi from "../wxApi";
|
||||||
|
|
||||||
|
import { Collapsible } from "../renderHtml";
|
||||||
|
|
||||||
interface ErrorProps {
|
interface ErrorProps {
|
||||||
message: string;
|
report: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ErrorView extends React.Component<ErrorProps, { }> {
|
class ErrorView extends React.Component<ErrorProps, { }> {
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
return (
|
const report = this.props.report;
|
||||||
<div>
|
if (!report) {
|
||||||
An error occurred: {this.props.message}
|
return (
|
||||||
</div>
|
<div id="main">
|
||||||
);
|
<h1>Error Report Not Found</h1>
|
||||||
|
<p>This page is supposed to display an error reported by the GNU Taler wallet,
|
||||||
|
but the corresponding error report can't be found.</p>
|
||||||
|
<p>Maybe the error occured before the browser was restarted or the wallet was reloaded.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
switch (report.name) {
|
||||||
|
case "pay-post-failed": {
|
||||||
|
const summary = report.contractTerms.summary || report.contractTerms.order_id;
|
||||||
|
return (
|
||||||
|
<div id="main">
|
||||||
|
<h1>Failed to send payment</h1>
|
||||||
|
<p>Failed to send payment for <strong>{summary}</strong> to merchant <strong>{report.contractTerms.merchant.name}</strong>.</p>
|
||||||
|
<p>You can <a href={report.contractTerms.fulfillment_url}>retry</a> the payment. If this problem persists,
|
||||||
|
please contact the mechant with the error details below.</p>
|
||||||
|
<Collapsible initiallyCollapsed={true} title="Error Details">
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(report, null, " ")}
|
||||||
|
</pre>
|
||||||
|
</Collapsible>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<div id="main">
|
||||||
|
<h1>Unknown Error</h1>
|
||||||
|
The GNU Taler wallet reported an unknown error. Here are the details:
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(report, null, " ")}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return (
|
||||||
|
<div id="main">
|
||||||
|
<h1>Error</h1>
|
||||||
|
The GNU Taler wallet reported an error. Here are the details:
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(report, null, " ")}
|
||||||
|
</pre>
|
||||||
|
A detailed error report could not be generated:
|
||||||
|
<pre>
|
||||||
|
{e.toString()}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
const url = new URI(document.location.href);
|
||||||
const url = new URI(document.location.href);
|
const query: any = URI.parseQuery(url.query());
|
||||||
const query: any = URI.parseQuery(url.query());
|
|
||||||
|
|
||||||
const message: string = query.message || "unknown error";
|
const container = document.getElementById("container");
|
||||||
|
if (!container) {
|
||||||
ReactDOM.render(<ErrorView message={message} />, document.getElementById(
|
console.error("fatal: can't mount component, countainer missing");
|
||||||
"container")!);
|
return;
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
// TODO: provide more context information, maybe factor it out into a
|
|
||||||
// TODO:generic error reporting function or component.
|
|
||||||
document.body.innerText = `Fatal error: "${e.message}".`;
|
|
||||||
console.error(`got error "${e.message}"`, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// report that we'll render, either looked up from the
|
||||||
|
// logging module or synthesized here for fixed/fatal errors
|
||||||
|
let report;
|
||||||
|
|
||||||
|
const reportUid: string = query.reportUid;
|
||||||
|
if (!reportUid) {
|
||||||
|
report = {
|
||||||
|
name: "missing-error",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
report = await wxApi.getReport(reportUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactDOM.render(<ErrorView report={report} />, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => main());
|
document.addEventListener("DOMContentLoaded", () => main());
|
||||||
|
18
src/webex/pages/refund.html
Normal file
18
src/webex/pages/refund.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Taler Wallet: Refund Status</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="../style/wallet.css">
|
||||||
|
|
||||||
|
<link rel="icon" href="/img/icon.png">
|
||||||
|
|
||||||
|
<script src="/dist/page-common-bundle.js"></script>
|
||||||
|
<script src="/dist/refund-bundle.js"></script>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
138
src/webex/pages/refund.tsx
Normal file
138
src/webex/pages/refund.tsx
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
This file is part of TALER
|
||||||
|
(C) 2015-2016 GNUnet e.V.
|
||||||
|
|
||||||
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page that shows refund status for purchases.
|
||||||
|
*
|
||||||
|
* @author Florian Dold
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import * as ReactDOM from "react-dom";
|
||||||
|
import URI = require("urijs");
|
||||||
|
|
||||||
|
import * as wxApi from "../wxApi";
|
||||||
|
import * as types from "../../types";
|
||||||
|
|
||||||
|
import { AmountDisplay } from "../renderHtml";
|
||||||
|
|
||||||
|
interface RefundStatusViewProps {
|
||||||
|
contractTermsHash: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RefundStatusViewState {
|
||||||
|
purchase?: types.PurchaseRecord;
|
||||||
|
gotResult: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const RefundDetail = ({purchase}: {purchase: types.PurchaseRecord}) => {
|
||||||
|
const pendingKeys = Object.keys(purchase.refundsPending);
|
||||||
|
const doneKeys = Object.keys(purchase.refundsDone);
|
||||||
|
if (pendingKeys.length == 0 && doneKeys.length == 0) {
|
||||||
|
return <p>No refunds</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currency = { ...purchase.refundsDone, ...purchase.refundsPending }[([...pendingKeys, ...doneKeys][0])].refund_amount.currency;
|
||||||
|
if (!currency) {
|
||||||
|
throw Error("invariant");
|
||||||
|
}
|
||||||
|
|
||||||
|
let amountPending = types.Amounts.getZero(currency);
|
||||||
|
let feesPending = types.Amounts.getZero(currency)
|
||||||
|
for (let k of pendingKeys) {
|
||||||
|
amountPending = types.Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount;
|
||||||
|
feesPending = types.Amounts.add(feesPending, purchase.refundsPending[k].refund_fee).amount;
|
||||||
|
}
|
||||||
|
let amountDone = types.Amounts.getZero(currency);
|
||||||
|
let feesDone = types.Amounts.getZero(currency);
|
||||||
|
for (let k of doneKeys) {
|
||||||
|
amountDone = types.Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount;
|
||||||
|
feesDone = types.Amounts.add(feesDone, purchase.refundsDone[k].refund_fee).amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>Refund fully received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={feesDone} />)</p>
|
||||||
|
<p>Refund incoming: <AmountDisplay amount={amountPending} /> (refund fees: <AmountDisplay amount={feesPending} />)</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
class RefundStatusView extends React.Component<RefundStatusViewProps, RefundStatusViewState> {
|
||||||
|
|
||||||
|
constructor(props: RefundStatusViewProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { gotResult: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.update();
|
||||||
|
const port = chrome.runtime.connect();
|
||||||
|
port.onMessage.addListener((msg: any) => {
|
||||||
|
if (msg.notify) {
|
||||||
|
console.log("got notified");
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render(): JSX.Element {
|
||||||
|
const purchase = this.state.purchase;
|
||||||
|
if (!purchase) {
|
||||||
|
if (this.state.gotResult) {
|
||||||
|
return <span>No purchase with contract terms hash {this.props.contractTermsHash} found</span>;
|
||||||
|
} else {
|
||||||
|
return <span>...</span>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const merchantName = purchase.contractTerms.merchant.name || "(unknown)";
|
||||||
|
const summary = purchase.contractTerms.summary || purchase.contractTerms.order_id;
|
||||||
|
return (
|
||||||
|
<div id="main">
|
||||||
|
<h1>Refund Status</h1>
|
||||||
|
<p>Status of purchase <strong>{summary}</strong> from merchant <strong>{merchantName}</strong> (order id {purchase.contractTerms.order_id}).</p>
|
||||||
|
<p>Total amount: <AmountDisplay amount={purchase.contractTerms.amount} /></p>
|
||||||
|
{purchase.finished ? <RefundDetail purchase={purchase} /> : <p>Purchase not completed.</p>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async update() {
|
||||||
|
const purchase = await wxApi.getPurchase(this.props.contractTermsHash);
|
||||||
|
console.log("got purchase", purchase);
|
||||||
|
this.setState({ purchase, gotResult: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const url = new URI(document.location.href);
|
||||||
|
const query: any = URI.parseQuery(url.query());
|
||||||
|
|
||||||
|
const container = document.getElementById("container");
|
||||||
|
if (!container) {
|
||||||
|
console.error("fatal: can't mount component, countainer missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contractTermsHash = query.contractTermsHash || "(none)";
|
||||||
|
ReactDOM.render(<RefundStatusView contractTermsHash={contractTermsHash} />, container);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => main());
|
@ -73,6 +73,8 @@ export function renderAmount(amount: AmountJson) {
|
|||||||
return <span>{x} {amount.currency}</span>;
|
return <span>{x} {amount.currency}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const AmountDisplay = ({amount}: {amount: AmountJson}) => renderAmount(amount);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abbreviate a string to a given length, and show the full
|
* Abbreviate a string to a given length, and show the full
|
||||||
@ -89,3 +91,40 @@ export function abbrev(s: string, n: number = 5) {
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
interface CollapsibleState {
|
||||||
|
collapsed: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CollapsibleProps {
|
||||||
|
initiallyCollapsed: boolean;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Collapsible extends React.Component<CollapsibleProps, CollapsibleState> {
|
||||||
|
constructor(props: CollapsibleProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { collapsed: props.initiallyCollapsed };
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const doOpen = (e: any) => {
|
||||||
|
this.setState({collapsed: false});
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
const doClose = (e: any) => {
|
||||||
|
this.setState({collapsed: true});
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
if (this.state.collapsed) {
|
||||||
|
return <h2><a className="opener opener-collapsed" href="#" onClick={doOpen}>{this.props.title}</a></h2>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2><a className="opener opener-open" href="#" onClick={doClose}>{this.props.title}</a></h2>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ import {
|
|||||||
DenominationRecord,
|
DenominationRecord,
|
||||||
ExchangeRecord,
|
ExchangeRecord,
|
||||||
PreCoinRecord,
|
PreCoinRecord,
|
||||||
|
PurchaseRecord,
|
||||||
QueryPaymentResult,
|
QueryPaymentResult,
|
||||||
ReserveCreationInfo,
|
ReserveCreationInfo,
|
||||||
ReserveRecord,
|
ReserveRecord,
|
||||||
@ -321,3 +322,26 @@ export function getSenderWireInfos(): Promise<SenderWireInfos> {
|
|||||||
export function returnCoins(args: { amount: AmountJson, exchange: string, senderWire: object }): Promise<void> {
|
export function returnCoins(args: { amount: AmountJson, exchange: string, senderWire: object }): Promise<void> {
|
||||||
return callBackend("return-coins", args);
|
return callBackend("return-coins", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record an error report and display it in a tabl.
|
||||||
|
*
|
||||||
|
* If sameTab is set, the error report will be opened in the current tab,
|
||||||
|
* otherwise in a new tab.
|
||||||
|
*/
|
||||||
|
export function logAndDisplayError(args: any): Promise<void> {
|
||||||
|
return callBackend("log-and-display-error", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReport(reportUid: string): Promise<void> {
|
||||||
|
return callBackend("get-report", { reportUid });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function acceptRefund(refundData: any): Promise<number> {
|
||||||
|
return callBackend("accept-refund", refundData);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord> {
|
||||||
|
return callBackend("get-purchase", { contractTermsHash });
|
||||||
|
}
|
||||||
|
@ -303,6 +303,26 @@ function handleMessage(sender: MessageSender,
|
|||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
case "log-and-display-error":
|
||||||
|
logging.storeReport(detail).then((reportUid) => {
|
||||||
|
const url = chrome.extension.getURL(`/src/webex/pages/error.html?reportUid=${reportUid}`);
|
||||||
|
if (detail.sameTab && sender && sender.tab && sender.tab.id) {
|
||||||
|
chrome.tabs.update(detail.tabId, { url });
|
||||||
|
} else {
|
||||||
|
chrome.tabs.create({ url });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
case "get-report":
|
||||||
|
return logging.getReport(detail.reportUid);
|
||||||
|
case "accept-refund":
|
||||||
|
return needsWallet().acceptRefund(detail.refund_permissions);
|
||||||
|
case "get-purchase":
|
||||||
|
const contractTermsHash = detail.contractTermsHash;
|
||||||
|
if (!contractTermsHash) {
|
||||||
|
throw Error("contractTermsHash missing");
|
||||||
|
}
|
||||||
|
return needsWallet().getPurchase(contractTermsHash);
|
||||||
default:
|
default:
|
||||||
// Exhaustiveness check.
|
// Exhaustiveness check.
|
||||||
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html
|
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html
|
||||||
@ -332,7 +352,7 @@ async function dispatch(req: any, sender: any, sendResponse: any): Promise<void>
|
|||||||
try {
|
try {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
error: "exception",
|
error: "exception",
|
||||||
hint: e.message,
|
message: e.message,
|
||||||
stack,
|
stack,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -371,6 +391,9 @@ class ChromeNotifier implements Notifier {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping from tab ID to payment information (if any).
|
* Mapping from tab ID to payment information (if any).
|
||||||
|
*
|
||||||
|
* Used to pass information from an intercepted HTTP header to the content
|
||||||
|
* script on the page.
|
||||||
*/
|
*/
|
||||||
const paymentRequestCookies: { [n: number]: any } = {};
|
const paymentRequestCookies: { [n: number]: any } = {};
|
||||||
|
|
||||||
@ -392,6 +415,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
|
|||||||
const fields = {
|
const fields = {
|
||||||
contract_url: headers["x-taler-contract-url"],
|
contract_url: headers["x-taler-contract-url"],
|
||||||
offer_url: headers["x-taler-offer-url"],
|
offer_url: headers["x-taler-offer-url"],
|
||||||
|
refund_url: headers["x-taler-refund-url"],
|
||||||
};
|
};
|
||||||
|
|
||||||
const talerHeaderFound = Object.keys(fields).filter((x: any) => (fields as any)[x]).length !== 0;
|
const talerHeaderFound = Object.keys(fields).filter((x: any) => (fields as any)[x]).length !== 0;
|
||||||
@ -406,6 +430,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
|
|||||||
const payDetail = {
|
const payDetail = {
|
||||||
contract_url: fields.contract_url,
|
contract_url: fields.contract_url,
|
||||||
offer_url: fields.offer_url,
|
offer_url: fields.offer_url,
|
||||||
|
refund_url: fields.refund_url,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("got pay detail", payDetail);
|
console.log("got pay detail", payDetail);
|
||||||
|
@ -76,6 +76,7 @@ module.exports = function (env) {
|
|||||||
"popup": "./src/webex/pages/popup.tsx",
|
"popup": "./src/webex/pages/popup.tsx",
|
||||||
"reset-required": "./src/webex/pages/reset-required.tsx",
|
"reset-required": "./src/webex/pages/reset-required.tsx",
|
||||||
"return-coins": "./src/webex/pages/return-coins.tsx",
|
"return-coins": "./src/webex/pages/return-coins.tsx",
|
||||||
|
"refund": "./src/webex/pages/refund.tsx",
|
||||||
"show-db": "./src/webex/pages/show-db.ts",
|
"show-db": "./src/webex/pages/show-db.ts",
|
||||||
"tree": "./src/webex/pages/tree.tsx",
|
"tree": "./src/webex/pages/tree.tsx",
|
||||||
},
|
},
|
||||||
|
15
yarn.lock
15
yarn.lock
@ -490,6 +490,13 @@ aws4@^1.2.1:
|
|||||||
version "1.6.0"
|
version "1.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
|
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
|
||||||
|
|
||||||
|
axios@^0.16.2:
|
||||||
|
version "0.16.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
|
||||||
|
dependencies:
|
||||||
|
follow-redirects "^1.2.3"
|
||||||
|
is-buffer "^1.1.5"
|
||||||
|
|
||||||
babel-code-frame@^6.22.0:
|
babel-code-frame@^6.22.0:
|
||||||
version "6.22.0"
|
version "6.22.0"
|
||||||
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
|
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
|
||||||
@ -1523,7 +1530,7 @@ debug-log@^1.0.1:
|
|||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
|
resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
|
||||||
|
|
||||||
debug@^2.1.1, debug@^2.2.0, debug@^2.3.3, debug@^2.6.3:
|
debug@^2.1.1, debug@^2.2.0, debug@^2.3.3, debug@^2.4.5, debug@^2.6.3:
|
||||||
version "2.6.8"
|
version "2.6.8"
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
|
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -2091,6 +2098,12 @@ fn-name@^2.0.0:
|
|||||||
version "2.0.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7"
|
resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7"
|
||||||
|
|
||||||
|
follow-redirects@^1.2.3:
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.4.tgz#355e8f4d16876b43f577b0d5ce2668b9723214ea"
|
||||||
|
dependencies:
|
||||||
|
debug "^2.4.5"
|
||||||
|
|
||||||
for-in@^1.0.1, for-in@^1.0.2:
|
for-in@^1.0.1, for-in@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
|
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
|
||||||
|
Loading…
Reference in New Issue
Block a user