hap.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else {
  7. var a = factory();
  8. for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
  9. }
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // identity function for calling harmony imports with the correct context
  47. /******/ __webpack_require__.i = function(value) { return value; };
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function(exports, name, getter) {
  51. /******/ if(!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/ });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = function(module) {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ function getDefault() { return module['default']; } :
  64. /******/ function getModuleExports() { return module; };
  65. /******/ __webpack_require__.d(getter, 'a', getter);
  66. /******/ return getter;
  67. /******/ };
  68. /******/
  69. /******/ // Object.prototype.hasOwnProperty.call
  70. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  71. /******/
  72. /******/ // __webpack_public_path__
  73. /******/ __webpack_require__.p = "";
  74. /******/
  75. /******/ // Load entry module and return exports
  76. /******/ return __webpack_require__(__webpack_require__.s = 11);
  77. /******/ })
  78. /************************************************************************/
  79. /******/ ([
  80. /* 0 */
  81. /***/ (function(module, exports, __webpack_require__) {
  82. "use strict";
  83. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  84. module.exports = {
  85. type: function type(ob) {
  86. return Object.prototype.toString.call(ob).slice(8, -1).toLowerCase();
  87. },
  88. isObject: function isObject(ob, real) {
  89. if (real) {
  90. return this.type(ob) === "object";
  91. } else {
  92. return ob && (typeof ob === 'undefined' ? 'undefined' : _typeof(ob)) === 'object';
  93. }
  94. },
  95. isFormData: function isFormData(val) {
  96. return typeof FormData !== 'undefined' && val instanceof FormData;
  97. },
  98. trim: function trim(str) {
  99. return str.replace(/(^\s*)|(\s*$)/g, '');
  100. },
  101. encode: function encode(val) {
  102. return encodeURIComponent(val).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+').replace(/%5B/gi, '[').replace(/%5D/gi, ']');
  103. },
  104. formatParams: function formatParams(data) {
  105. var str = "";
  106. var first = true;
  107. var that = this;
  108. if (!this.isObject(data)) {
  109. return data;
  110. }
  111. function _encode(sub, path) {
  112. var encode = that.encode;
  113. var type = that.type(sub);
  114. if (type == "array") {
  115. sub.forEach(function (e, i) {
  116. if (!that.isObject(e)) i = "";
  117. _encode(e, path + ('%5B' + i + '%5D'));
  118. });
  119. } else if (type == "object") {
  120. for (var key in sub) {
  121. if (path) {
  122. _encode(sub[key], path + "%5B" + encode(key) + "%5D");
  123. } else {
  124. _encode(sub[key], encode(key));
  125. }
  126. }
  127. } else {
  128. if (!first) {
  129. str += "&";
  130. }
  131. first = false;
  132. str += path + "=" + encode(sub);
  133. }
  134. }
  135. _encode(data, "");
  136. return str;
  137. },
  138. // Do not overwrite existing attributes
  139. merge: function merge(a, b) {
  140. for (var key in b) {
  141. if (!a.hasOwnProperty(key)) {
  142. a[key] = b[key];
  143. } else if (this.isObject(b[key], 1) && this.isObject(a[key], 1)) {
  144. this.merge(a[key], b[key]);
  145. }
  146. }
  147. return a;
  148. }
  149. };
  150. /***/ }),
  151. /* 1 */
  152. /***/ (function(module, exports, __webpack_require__) {
  153. function KEEP(_,cb){cb();}
  154. "use strict";
  155. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  156. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  157. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  158. /*
  159. * author: wendu
  160. * email: 824783146@qq.com
  161. **/
  162. var util = __webpack_require__(0);
  163. var isBrowser = typeof document !== "undefined";
  164. //EngineWrapper can help generating a http engine quickly through a adapter
  165. function EngineWrapper(adapter) {
  166. var AjaxEngine = function () {
  167. function AjaxEngine() {
  168. _classCallCheck(this, AjaxEngine);
  169. this.requestHeaders = {};
  170. this.readyState = 0;
  171. this.timeout = 0; // 0 stands for no timeout
  172. this.responseURL = "";
  173. this.responseHeaders = {};
  174. }
  175. _createClass(AjaxEngine, [{
  176. key: "_call",
  177. value: function _call(name) {
  178. this[name] && this[name].apply(this, [].splice.call(arguments, 1));
  179. }
  180. }, {
  181. key: "_changeReadyState",
  182. value: function _changeReadyState(state) {
  183. this.readyState = state;
  184. this._call("onreadystatechange");
  185. }
  186. }, {
  187. key: "open",
  188. value: function open(method, url) {
  189. this.method = method;
  190. if (!url) {
  191. url = location.href;
  192. } else {
  193. url = util.trim(url);
  194. if (url.indexOf("http") !== 0) {
  195. // Normalize the request url
  196. if (isBrowser) {
  197. var t = document.createElement("a");
  198. t.href = url;
  199. url = t.href;
  200. }
  201. }
  202. }
  203. this.responseURL = url;
  204. this._changeReadyState(1);
  205. }
  206. }, {
  207. key: "send",
  208. value: function send(arg) {
  209. var _this = this;
  210. arg = arg || null;
  211. var self = this;
  212. if (adapter) {
  213. var request = {
  214. method: self.method,
  215. url: self.responseURL,
  216. headers: self.requestHeaders || {},
  217. body: arg
  218. };
  219. util.merge(request, self._options || {});
  220. if (request.method === "GET") {
  221. request.body = null;
  222. }
  223. self._changeReadyState(3);
  224. var timer = void 0;
  225. self.timeout = self.timeout || 0;
  226. if (self.timeout > 0) {
  227. timer = setTimeout(function () {
  228. if (self.readyState === 3) {
  229. _this._call("onloadend");
  230. self._changeReadyState(0);
  231. self._call("ontimeout");
  232. }
  233. }, self.timeout);
  234. }
  235. request.timeout = self.timeout;
  236. adapter(request, function (response) {
  237. function getAndDelete(key) {
  238. var t = response[key];
  239. delete response[key];
  240. return t;
  241. }
  242. // If the request has already timeout, return
  243. if (self.readyState !== 3) return;
  244. clearTimeout(timer);
  245. // Make sure the type of status is integer
  246. self.status = getAndDelete("statusCode") - 0;
  247. var responseText = getAndDelete("responseText");
  248. var statusMessage = getAndDelete("statusMessage");
  249. // Network error, set the status code 0
  250. if (!self.status) {
  251. self.statusText = responseText;
  252. self._call("onerror", { msg: statusMessage });
  253. } else {
  254. // Parsing the response headers to array in a object, because
  255. // there may be multiple values with the same header name
  256. var responseHeaders = getAndDelete("headers");
  257. var headers = {};
  258. for (var field in responseHeaders) {
  259. var value = responseHeaders[field];
  260. var key = field.toLowerCase();
  261. // Is array
  262. if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "object") {
  263. headers[key] = value;
  264. } else {
  265. headers[key] = headers[key] || [];
  266. headers[key].push(value);
  267. }
  268. }
  269. var cookies = headers["set-cookie"];
  270. if (isBrowser && cookies) {
  271. cookies.forEach(function (e) {
  272. // Remove the http-Only property of the cookie
  273. // so that JavaScript can operate it.
  274. document.cookie = e.replace(/;\s*httpOnly/ig, "");
  275. });
  276. }
  277. self.responseHeaders = headers;
  278. // Set the fields of engine from response
  279. self.statusText = statusMessage || "";
  280. self.response = self.responseText = responseText;
  281. self._response = response;
  282. self._changeReadyState(4);
  283. self._call("onload");
  284. }
  285. self._call("onloadend");
  286. });
  287. } else {
  288. console.error("Ajax require adapter");
  289. }
  290. }
  291. }, {
  292. key: "setRequestHeader",
  293. value: function setRequestHeader(key, value) {
  294. this.requestHeaders[util.trim(key)] = value;
  295. }
  296. }, {
  297. key: "getResponseHeader",
  298. value: function getResponseHeader(key) {
  299. return (this.responseHeaders[key.toLowerCase()] || "").toString() || null;
  300. }
  301. }, {
  302. key: "getAllResponseHeaders",
  303. value: function getAllResponseHeaders() {
  304. var str = "";
  305. for (var key in this.responseHeaders) {
  306. str += key + ":" + this.getResponseHeader(key) + "\r\n";
  307. }
  308. return str || null;
  309. }
  310. }, {
  311. key: "abort",
  312. value: function abort(msg) {
  313. this._changeReadyState(0);
  314. this._call("onerror", { msg: msg });
  315. this._call("onloadend");
  316. }
  317. }], [{
  318. key: "setAdapter",
  319. value: function setAdapter(requestAdapter) {
  320. adapter = requestAdapter;
  321. }
  322. }]);
  323. return AjaxEngine;
  324. }();
  325. return AjaxEngine;
  326. }
  327. // learn more about keep-loader: https://github.com/wendux/keep-loader
  328. ;
  329. module.exports = EngineWrapper;
  330. /***/ }),
  331. /* 2 */
  332. /***/ (function(module, exports, __webpack_require__) {
  333. function KEEP(_,cb){cb();}
  334. "use strict";
  335. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  336. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  337. var utils = __webpack_require__(0);
  338. var isBrowser = typeof document !== "undefined";
  339. var Fly = function () {
  340. function Fly(engine) {
  341. _classCallCheck(this, Fly);
  342. this.engine = engine || XMLHttpRequest;
  343. this.default = this; //For typeScript
  344. /**
  345. * Add lock/unlock API for interceptor.
  346. *
  347. * Once an request/response interceptor is locked, the incoming request/response
  348. * will be added to a queue before they enter the interceptor, they will not be
  349. * continued until the interceptor is unlocked.
  350. *
  351. * @param [interceptor] either is interceptors.request or interceptors.response
  352. */
  353. function wrap(interceptor) {
  354. var resolve = void 0;
  355. var reject = void 0;
  356. function _clear() {
  357. interceptor.p = resolve = reject = null;
  358. }
  359. utils.merge(interceptor, {
  360. lock: function lock() {
  361. if (!resolve) {
  362. interceptor.p = new Promise(function (_resolve, _reject) {
  363. resolve = _resolve;
  364. reject = _reject;
  365. });
  366. }
  367. },
  368. unlock: function unlock() {
  369. if (resolve) {
  370. resolve();
  371. _clear();
  372. }
  373. },
  374. clear: function clear() {
  375. if (reject) {
  376. reject("cancel");
  377. _clear();
  378. }
  379. }
  380. });
  381. }
  382. var interceptors = this.interceptors = {
  383. response: {
  384. use: function use(handler, onerror) {
  385. this.handler = handler;
  386. this.onerror = onerror;
  387. }
  388. },
  389. request: {
  390. use: function use(handler) {
  391. this.handler = handler;
  392. }
  393. }
  394. };
  395. var irq = interceptors.request;
  396. var irp = interceptors.response;
  397. wrap(irp);
  398. wrap(irq);
  399. this.config = {
  400. method: "GET",
  401. baseURL: "",
  402. headers: {},
  403. timeout: 0,
  404. params: {}, // Default Url params
  405. parseJson: true, // Convert response data to JSON object automatically.
  406. withCredentials: false
  407. };
  408. }
  409. _createClass(Fly, [{
  410. key: "request",
  411. value: function request(url, data, options) {
  412. var _this = this;
  413. var engine = new this.engine();
  414. var contentType = "Content-Type";
  415. var contentTypeLowerCase = contentType.toLowerCase();
  416. var interceptors = this.interceptors;
  417. var requestInterceptor = interceptors.request;
  418. var responseInterceptor = interceptors.response;
  419. var requestInterceptorHandler = requestInterceptor.handler;
  420. var promise = new Promise(function (resolve, reject) {
  421. if (utils.isObject(url)) {
  422. options = url;
  423. url = options.url;
  424. }
  425. options = options || {};
  426. options.headers = options.headers || {};
  427. function isPromise(p) {
  428. // some polyfill implementation of Promise may be not standard,
  429. // so, we test by duck-typing
  430. return p && p.then && p.catch;
  431. }
  432. /**
  433. * If the request/response interceptor has been locked,
  434. * the new request/response will enter a queue. otherwise, it will be performed directly.
  435. * @param [promise] if the promise exist, means the interceptor is locked.
  436. * @param [callback]
  437. */
  438. function enqueueIfLocked(promise, callback) {
  439. if (promise) {
  440. promise.then(function () {
  441. callback();
  442. });
  443. } else {
  444. callback();
  445. }
  446. }
  447. // make the http request
  448. function makeRequest(options) {
  449. data = options.body;
  450. // Normalize the request url
  451. url = utils.trim(options.url);
  452. var baseUrl = utils.trim(options.baseURL || "");
  453. if (!url && isBrowser && !baseUrl) url = location.href;
  454. if (url.indexOf("http") !== 0) {
  455. var isAbsolute = url[0] === "/";
  456. if (!baseUrl && isBrowser) {
  457. var arr = location.pathname.split("/");
  458. arr.pop();
  459. baseUrl = location.protocol + "//" + location.host + (isAbsolute ? "" : arr.join("/"));
  460. }
  461. if (baseUrl[baseUrl.length - 1] !== "/") {
  462. baseUrl += "/";
  463. }
  464. url = baseUrl + (isAbsolute ? url.substr(1) : url);
  465. if (isBrowser) {
  466. // Normalize the url which contains the ".." or ".", such as
  467. // "http://xx.com/aa/bb/../../xx" to "http://xx.com/xx" .
  468. var t = document.createElement("a");
  469. t.href = url;
  470. url = t.href;
  471. }
  472. }
  473. var responseType = utils.trim(options.responseType || "");
  474. var needQuery = ["GET", "HEAD", "DELETE", "OPTION"].indexOf(options.method) !== -1;
  475. var dataType = utils.type(data);
  476. var params = options.params || {};
  477. // merge url params when the method is "GET" (data is object)
  478. if (needQuery && dataType === "object") {
  479. params = utils.merge(data, params);
  480. }
  481. // encode params to String
  482. params = utils.formatParams(params);
  483. // save url params
  484. var _params = [];
  485. if (params) {
  486. _params.push(params);
  487. }
  488. // Add data to url params when the method is "GET" (data is String)
  489. if (needQuery && data && dataType === "string") {
  490. _params.push(data);
  491. }
  492. // make the final url
  493. if (_params.length > 0) {
  494. url += (url.indexOf("?") === -1 ? "?" : "&") + _params.join("&");
  495. }
  496. engine.open(options.method, url);
  497. // try catch for ie >=9
  498. try {
  499. engine.withCredentials = !!options.withCredentials;
  500. engine.timeout = options.timeout || 0;
  501. if (responseType !== "stream") {
  502. engine.responseType = responseType;
  503. }
  504. } catch (e) {}
  505. var customContentType = options.headers[contentType] || options.headers[contentTypeLowerCase];
  506. // default content type
  507. var _contentType = "application/x-www-form-urlencoded";
  508. // If the request data is json object, transforming it to json string,
  509. // and set request content-type to "json". In browser, the data will
  510. // be sent as RequestBody instead of FormData
  511. if (utils.trim((customContentType || "").toLowerCase()) === _contentType) {
  512. data = utils.formatParams(data);
  513. } else if (!utils.isFormData(data) && ["object", "array"].indexOf(utils.type(data)) !== -1) {
  514. _contentType = 'application/json;charset=utf-8';
  515. data = JSON.stringify(data);
  516. }
  517. //If user doesn't set content-type, set default.
  518. if (!(customContentType || needQuery)) {
  519. options.headers[contentType] = _contentType;
  520. }
  521. for (var k in options.headers) {
  522. if (k === contentType && utils.isFormData(data)) {
  523. // Delete the content-type, Let the browser set it
  524. delete options.headers[k];
  525. } else {
  526. try {
  527. // In browser environment, some header fields are readonly,
  528. // write will cause the exception .
  529. engine.setRequestHeader(k, options.headers[k]);
  530. } catch (e) {}
  531. }
  532. }
  533. function onresult(handler, data, type) {
  534. enqueueIfLocked(responseInterceptor.p, function () {
  535. if (handler) {
  536. //如果失败,添加请求信息
  537. if (type) {
  538. data.request = options;
  539. }
  540. var ret = handler.call(responseInterceptor, data, Promise);
  541. data = ret === undefined ? data : ret;
  542. }
  543. if (!isPromise(data)) {
  544. data = Promise[type === 0 ? "resolve" : "reject"](data);
  545. }
  546. data.then(function (d) {
  547. resolve(d);
  548. }).catch(function (e) {
  549. reject(e);
  550. });
  551. });
  552. }
  553. function onerror(e) {
  554. e.engine = engine;
  555. onresult(responseInterceptor.onerror, e, -1);
  556. }
  557. function Err(msg, status) {
  558. this.message = msg;
  559. this.status = status;
  560. }
  561. engine.onload = function () {
  562. try {
  563. // The xhr of IE9 has not response field
  564. var response = engine.response || engine.responseText;
  565. if (response && options.parseJson && (engine.getResponseHeader(contentType) || "").indexOf("json") !== -1
  566. // Some third engine implementation may transform the response text to json object automatically,
  567. // so we should test the type of response before transforming it
  568. && !utils.isObject(response)) {
  569. response = JSON.parse(response);
  570. }
  571. var headers = engine.responseHeaders;
  572. // In browser
  573. if (!headers) {
  574. headers = {};
  575. var items = (engine.getAllResponseHeaders() || "").split("\r\n");
  576. items.pop();
  577. items.forEach(function (e) {
  578. if (!e) return;
  579. var key = e.split(":")[0];
  580. headers[key] = engine.getResponseHeader(key);
  581. });
  582. }
  583. var status = engine.status;
  584. var statusText = engine.statusText;
  585. var _data = { data: response, headers: headers, status: status, statusText: statusText };
  586. // The _response filed of engine is set in adapter which be called in engine-wrapper.js
  587. utils.merge(_data, engine._response);
  588. if (status >= 200 && status < 300 || status === 304) {
  589. _data.engine = engine;
  590. _data.request = options;
  591. onresult(responseInterceptor.handler, _data, 0);
  592. } else {
  593. var e = new Err(statusText, status);
  594. e.response = _data;
  595. onerror(e);
  596. }
  597. } catch (e) {
  598. onerror(new Err(e.msg, engine.status));
  599. }
  600. };
  601. engine.onerror = function (e) {
  602. onerror(new Err(e.msg || "Network Error", 0));
  603. };
  604. engine.ontimeout = function () {
  605. onerror(new Err("timeout [ " + engine.timeout + "ms ]", 1));
  606. };
  607. engine._options = options;
  608. setTimeout(function () {
  609. engine.send(needQuery ? null : data);
  610. }, 0);
  611. }
  612. enqueueIfLocked(requestInterceptor.p, function () {
  613. utils.merge(options, JSON.parse(JSON.stringify(_this.config)));
  614. var headers = options.headers;
  615. headers[contentType] = headers[contentType] || headers[contentTypeLowerCase] || "";
  616. delete headers[contentTypeLowerCase];
  617. options.body = data || options.body;
  618. url = utils.trim(url || "");
  619. options.method = options.method.toUpperCase();
  620. options.url = url;
  621. var ret = options;
  622. if (requestInterceptorHandler) {
  623. ret = requestInterceptorHandler.call(requestInterceptor, options, Promise) || options;
  624. }
  625. if (!isPromise(ret)) {
  626. ret = Promise.resolve(ret);
  627. }
  628. ret.then(function (d) {
  629. //if options continue
  630. if (d === options) {
  631. makeRequest(d);
  632. } else {
  633. resolve(d);
  634. }
  635. }, function (err) {
  636. reject(err);
  637. });
  638. });
  639. });
  640. promise.engine = engine;
  641. return promise;
  642. }
  643. }, {
  644. key: "all",
  645. value: function all(promises) {
  646. return Promise.all(promises);
  647. }
  648. }, {
  649. key: "spread",
  650. value: function spread(callback) {
  651. return function (arr) {
  652. return callback.apply(null, arr);
  653. };
  654. }
  655. }]);
  656. return Fly;
  657. }();
  658. //For typeScript
  659. Fly.default = Fly;
  660. ["get", "post", "put", "patch", "head", "delete"].forEach(function (e) {
  661. Fly.prototype[e] = function (url, data, option) {
  662. return this.request(url, data, utils.merge({ method: e }, option));
  663. };
  664. });
  665. ["lock", "unlock", "clear"].forEach(function (e) {
  666. Fly.prototype[e] = function () {
  667. this.interceptors.request[e]();
  668. };
  669. });
  670. // Learn more about keep-loader: https://github.com/wendux/keep-loader
  671. ;
  672. module.exports = Fly;
  673. /***/ }),
  674. /* 3 */,
  675. /* 4 */,
  676. /* 5 */
  677. /***/ (function(module, exports, __webpack_require__) {
  678. "use strict";
  679. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  680. //hap adapter
  681. module.exports = function (fetch) {
  682. return function (request, responseCallback) {
  683. request.data = request.body;
  684. request.header = request.headers;
  685. request.complete = function (ret) {
  686. if ((typeof ret === "undefined" ? "undefined" : _typeof(ret)) !== "object") {
  687. ret = {
  688. code: 0,
  689. msg: ret
  690. };
  691. }
  692. responseCallback({
  693. statusCode: ret.code || 0,
  694. responseText: ret.data,
  695. headers: ret.headers,
  696. statusMessage: ret.msg
  697. });
  698. };
  699. fetch.fetch(request);
  700. };
  701. };
  702. /***/ }),
  703. /* 6 */,
  704. /* 7 */,
  705. /* 8 */,
  706. /* 9 */,
  707. /* 10 */,
  708. /* 11 */
  709. /***/ (function(module, exports, __webpack_require__) {
  710. "use strict";
  711. //quick app entry
  712. var Fly = __webpack_require__(2);
  713. var EngineWrapper = __webpack_require__(1);
  714. var adapter = __webpack_require__(5);
  715. module.exports = function (fetch) {
  716. var hapEngine = EngineWrapper(adapter(fetch));
  717. return new Fly(hapEngine);
  718. };
  719. /***/ })
  720. /******/ ]);
  721. });