This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbus-promise.min.js
1 lines (1 loc) · 17.2 KB
/
bus-promise.min.js
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.bus={})}(this,function(e){"use strict";function t(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function r(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&t(e.slice(0,0))}function n(e){return"[object Array]"===$.call(e)}function o(e){return null!==e&&"object"===(void 0===e?"undefined":V(e))}function i(e){return"[object Function]"===$.call(e)}function a(e,t){if(null!==e&&void 0!==e)if("object"===(void 0===e?"undefined":V(e))||n(e)||(e=[e]),n(e))for(var r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(null,e[i],i,e)}function s(){for(var e={},t=0,r=arguments.length;t<r;t++)a(arguments[t],function(t,r){"object"===V(e[r])&&"object"===(void 0===t?"undefined":V(t))?e[r]=s(e[r],t):e[r]=t});return e}function u(e){return encodeURIComponent(e).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function c(){this.message="String contains an invalid character"}function p(e,t){!K.isUndefined(e)&&K.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}function f(){this.handlers=[]}function d(e){e.cancelToken&&e.cancelToken.throwIfRequested()}function l(e){this.defaults=e,this.interceptors={request:new ce,response:new ce}}function h(e){this.message=e}function m(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise(function(e){t=e});var r=this;e(function(e){r.reason||(r.reason=new ye(e),t(r.reason))})}function y(e){var t=new me(e),r=M(me.prototype.request,t);return K.extend(r,me.prototype,t),K.extend(r,t),r}function v(e){throw new Error(e)}function g(e){return Ce?e.data:e}function w(e){return e||v("O token é obrigatório para autenticação."),e}function b(e){return 200===e.status||v("Erro ao se conectar com o serviço da SPTrans."),e}function x(e){return e.data||v("Token inválido."),e}function S(e){return Ce?e.auth[0]:e.headers["set-cookie"][0]}function C(e){var t=Se.sptrans+Se.auth.route;return Ce&&(t=Se.server+"/auth"),xe({method:"post",url:t,params:{token:e}}).then(g).then(b).then(x).then(S)}function P(e,t){if("*"===t)return e.map(function(e){return{direction:e.direction_id,shapeId:e.shape_id,mainTerminal:e.trip_headsign,displaySign:e.route_id.split("-")[0],type:e.route_id.split("-")[1]}});var r=function(e){return xe({method:"get",url:Se.server+"/trips/"+e})},n=function(e){return e.map(function(e){return e.data[0]?e.data[0].shape_id:null})};return function(e){var t=e.map(r);return Promise.all(t).then(n)}(e.map(function(e){return e.lt+"-"+e.tl+"-"+(e.sl-1)})).then(function(t){return e.map(function(e,r){return{lineId:e.cl,shapeId:t[r],circular:e.lc,displaySign:e.lt,direction:e.sl,type:e.tl,mainTerminal:e.tp,secondaryTerminal:e.ts}})})}function E(e){return e.map(function(e){return{shapeId:e.shape_id,lat:e.shape_pt_lat,lng:e.shape_pt_lon,sequence:e.shape_pt_sequence,traveled:e.shape_dist_traveled}})}function T(e,t){return"*"===t?e.map(function(e){return{stopId:e.stop_id,name:e.stop_name,address:e.stop_desc,lat:e.stop_lat,lng:e.stop_lon}}):e.map(function(e){return{stopId:e.cp,name:e.np,address:e.ed,lat:e.py,lng:e.px}})}function q(e){return e.map(function(e){return{corridorId:e.cc,name:e.nc}})}function I(e){return e.vs.length?{hour:e.hr,vehicles:Pe(e.vs)}:{hour:e.hr,vehicles:null}}function R(e){return e.p?{hour:e.hr,stop:{stopId:e.p.cp,name:e.p.np,lat:e.p.py,lng:e.p.px,lines:Te(e.p.l)}}:{hour:e.hr,stop:null}}function j(e){return e.ps?{hour:e.hr,stops:Ie(e.ps)}:{hour:e.hr,stops:null}}function A(e){return e.p?{hour:e.hr,stop:{stopId:e.p.cp,name:e.p.np,lat:e.p.py,lng:e.p.px,lines:je(e.p.l)}}:{hour:e.hr,stop:null}}function B(e){return e.map(function(e){return{lineId:e.cl,circular:e.lc,displaySign:e.lt,direction:e.sl,type:e.tl,mainTerminal:e.tp,secondaryTerminal:e.ts}})}function _(e){var t=e.e;return{informationDate:e.hr,companiesByOperationArea:t.map(function(e){return{operationCode:e.a,companies:e.e.map(function(e){return{operationAreaCode:e.a,referenceCode:e.c,name:e.n}})}})}}function L(e){throw new Error(e)}function O(e){return e||L('The "find" method should receive an object with options.'),e}function U(e){return e.auth||L('The "find" method should receive the "auth" parameter.'),e}function k(e){return e.type in Se||L('The "'+e.type+'" type does not exist.'),e}function D(e){return Se[e.type].required}function F(e){var t=D(e);if(!t)return e;var r=t.filter(function(t){return!(t in e)});return 0===r.length||L('Required parameter(s): "'+r+'".'),e}function N(e){var t=D(e);if(!t)return e;var r=t.reduce(function(t,r){var n=Se[e.type].proxyParams[r],o=e[r];return o instanceof Array?o.map(function(e){return J({},n,e)}):Object.assign({},t,J({},n,o))},{});return Object.assign(e,{params:r})}function H(e){return 200===e.status||L("Error "+e.status+" when connecting to the SPTrans service."),e}function X(e,t){var r=e.data,n=t.type,o=t.terms,i={lines:P,shapes:E,stops:T,stopsByCorridor:T,stopsByLine:T,corridors:q,vehiclesPosition:I,arrivalForecast:R,lineForecast:j,stopForecast:A,linesDirection:B,companies:_};return"lines"===n&&"*"===o?i[n](r,o):"stops"===n&&"*"===o?i[n](r,o):i[n](r)}function z(e){var t=Se.sptrans+Se[e.type].route,r={Cookie:e.auth};Ae&&(r=null,t=Se.server+"/find",Object.assign(e.params,{auth:e.auth,type:e.type,route:Se[e.type].route})),"shapes"===e.type&&(r=null,t=Se.server+"/shapes/"+e.shapeId),"lines"===e.type&&"*"===e.terms&&(r=null,t=Se.server+"/trips"),"stops"===e.type&&"*"===e.terms&&(r=null,t=Se.server+"/stops");var n={method:"get",url:t,headers:r,params:e.params};return console.log("config data",n),xe(n).then(H).then(function(t){return X(t,e)})}var M=function(e,t){return function(){for(var r=new Array(arguments.length),n=0;n<r.length;n++)r[n]=arguments[n];return e.apply(t,r)}},V="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},J=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},$=Object.prototype.toString,K={isArray:n,isArrayBuffer:function(e){return"[object ArrayBuffer]"===$.call(e)},isBuffer:function(e){return null!=e&&(t(e)||r(e)||!!e._isBuffer)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:o,isUndefined:function(e){return void 0===e},isDate:function(e){return"[object Date]"===$.call(e)},isFile:function(e){return"[object File]"===$.call(e)},isBlob:function(e){return"[object Blob]"===$.call(e)},isFunction:i,isStream:function(e){return o(e)&&i(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product)&&"undefined"!=typeof window&&"undefined"!=typeof document},forEach:a,merge:s,extend:function(e,t,r){return a(t,function(t,n){e[n]=r&&"function"==typeof t?M(t,r):t}),e},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")}},G=function(e,t){K.forEach(e,function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])})},Q=function(e,t,r,n,o){return e.config=t,r&&(e.code=r),e.request=n,e.response=o,e},W=function(e,t,r,n,o){var i=new Error(e);return Q(i,t,r,n,o)},Y=function(e,t,r){var n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(W("Request failed with status code "+r.status,r.config,null,r.request,r)):e(r)},Z=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(K.isURLSearchParams(t))n=t.toString();else{var o=[];K.forEach(t,function(e,t){null!==e&&void 0!==e&&(K.isArray(e)&&(t+="[]"),K.isArray(e)||(e=[e]),K.forEach(e,function(e){K.isDate(e)?e=e.toISOString():K.isObject(e)&&(e=JSON.stringify(e)),o.push(u(t)+"="+u(e))}))}),n=o.join("&")}return n&&(e+=(-1===e.indexOf("?")?"?":"&")+n),e},ee=function(e){var t,r,n,o={};return e?(K.forEach(e.split("\n"),function(e){n=e.indexOf(":"),t=K.trim(e.substr(0,n)).toLowerCase(),r=K.trim(e.substr(n+1)),t&&(o[t]=o[t]?o[t]+", "+r:r)}),o):o},te=K.isStandardBrowserEnv()?function(){function e(e){var t=e;return r&&(n.setAttribute("href",t),t=n.href),n.setAttribute("href",t),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}var t,r=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");return t=e(window.location.href),function(r){var n=K.isString(r)?e(r):r;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0},re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";c.prototype=new Error,c.prototype.code=5,c.prototype.name="InvalidCharacterError";var ne=K.isStandardBrowserEnv()?{write:function(e,t,r,n,o,i){var a=[];a.push(e+"="+encodeURIComponent(t)),K.isNumber(r)&&a.push("expires="+new Date(r).toGMTString()),K.isString(n)&&a.push("path="+n),K.isString(o)&&a.push("domain="+o),!0===i&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}},oe="undefined"!=typeof window&&window.btoa&&window.btoa.bind(window)||function(e){for(var t,r,n=String(e),o="",i=0,a=re;n.charAt(0|i)||(a="=",i%1);o+=a.charAt(63&t>>8-i%1*8)){if((r=n.charCodeAt(i+=.75))>255)throw new c;t=t<<8|r}return o},ie=function(e){return new Promise(function(t,r){var n=e.data,o=e.headers;K.isFormData(n)&&delete o["Content-Type"];var i=new XMLHttpRequest,a="onreadystatechange",s=!1;if("undefined"==typeof window||!window.XDomainRequest||"withCredentials"in i||te(e.url)||(i=new window.XDomainRequest,a="onload",s=!0,i.onprogress=function(){},i.ontimeout=function(){}),e.auth){var u=e.auth.username||"",c=e.auth.password||"";o.Authorization="Basic "+oe(u+":"+c)}if(i.open(e.method.toUpperCase(),Z(e.url,e.params,e.paramsSerializer),!0),i.timeout=e.timeout,i[a]=function(){if(i&&(4===i.readyState||s)&&(0!==i.status||i.responseURL&&0===i.responseURL.indexOf("file:"))){var n="getAllResponseHeaders"in i?ee(i.getAllResponseHeaders()):null,o={data:e.responseType&&"text"!==e.responseType?i.response:i.responseText,status:1223===i.status?204:i.status,statusText:1223===i.status?"No Content":i.statusText,headers:n,config:e,request:i};Y(t,r,o),i=null}},i.onerror=function(){r(W("Network Error",e,null,i)),i=null},i.ontimeout=function(){r(W("timeout of "+e.timeout+"ms exceeded",e,"ECONNABORTED",i)),i=null},K.isStandardBrowserEnv()){var p=ne,f=(e.withCredentials||te(e.url))&&e.xsrfCookieName?p.read(e.xsrfCookieName):void 0;f&&(o[e.xsrfHeaderName]=f)}if("setRequestHeader"in i&&K.forEach(o,function(e,t){void 0===n&&"content-type"===t.toLowerCase()?delete o[t]:i.setRequestHeader(t,e)}),e.withCredentials&&(i.withCredentials=!0),e.responseType)try{i.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&i.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&i.upload&&i.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then(function(e){i&&(i.abort(),r(e),i=null)}),void 0===n&&(n=null),i.send(n)})},ae={"Content-Type":"application/x-www-form-urlencoded"},se={adapter:function(){var e;return"undefined"!=typeof XMLHttpRequest?e=ie:"undefined"!=typeof process&&(e=ie),e}(),transformRequest:[function(e,t){return G(t,"Content-Type"),K.isFormData(e)||K.isArrayBuffer(e)||K.isBuffer(e)||K.isStream(e)||K.isFile(e)||K.isBlob(e)?e:K.isArrayBufferView(e)?e.buffer:K.isURLSearchParams(e)?(p(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):K.isObject(e)?(p(t,"application/json;charset=utf-8"),JSON.stringify(e)):e}],transformResponse:[function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,validateStatus:function(e){return e>=200&&e<300}};se.headers={common:{Accept:"application/json, text/plain, */*"}},K.forEach(["delete","get","head"],function(e){se.headers[e]={}}),K.forEach(["post","put","patch"],function(e){se.headers[e]=K.merge(ae)});var ue=se;f.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},f.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},f.prototype.forEach=function(e){K.forEach(this.handlers,function(t){null!==t&&e(t)})};var ce=f,pe=function(e,t,r){return K.forEach(r,function(r){e=r(e,t)}),e},fe=function(e){return!(!e||!e.__CANCEL__)},de=function(e){return d(e),e.headers=e.headers||{},e.data=pe(e.data,e.headers,e.transformRequest),e.headers=K.merge(e.headers.common||{},e.headers[e.method]||{},e.headers||{}),K.forEach(["delete","get","head","post","put","patch","common"],function(t){delete e.headers[t]}),(e.adapter||ue.adapter)(e).then(function(t){return d(e),t.data=pe(t.data,t.headers,e.transformResponse),t},function(t){return fe(t)||(d(e),t&&t.response&&(t.response.data=pe(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)})},le=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)},he=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e};l.prototype.request=function(e){"string"==typeof e&&(e=K.merge({url:arguments[0]},arguments[1])),(e=K.merge(ue,this.defaults,{method:"get"},e)).method=e.method.toLowerCase(),e.baseURL&&!le(e.url)&&(e.url=he(e.baseURL,e.url));var t=[de,void 0],r=Promise.resolve(e);for(this.interceptors.request.forEach(function(e){t.unshift(e.fulfilled,e.rejected)}),this.interceptors.response.forEach(function(e){t.push(e.fulfilled,e.rejected)});t.length;)r=r.then(t.shift(),t.shift());return r},K.forEach(["delete","get","head","options"],function(e){l.prototype[e]=function(t,r){return this.request(K.merge(r||{},{method:e,url:t}))}}),K.forEach(["post","put","patch"],function(e){l.prototype[e]=function(t,r,n){return this.request(K.merge(n||{},{method:e,url:t,data:r}))}});var me=l;h.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},h.prototype.__CANCEL__=!0;var ye=h;m.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},m.source=function(){var e;return{token:new m(function(t){e=t}),cancel:e}};var ve=m,ge=y(ue);ge.Axios=me,ge.create=function(e){return y(K.merge(ue,e))},ge.Cancel=ye,ge.CancelToken=ve,ge.isCancel=fe,ge.all=function(e){return Promise.all(e)},ge.spread=function(e){return function(t){return e.apply(null,t)}};var we=ge,be=ge;we.default=be;var xe=we,Se={sptrans:"http://api.olhovivo.sptrans.com.br/v2.1",server:"https://busserver.herokuapp.com",auth:{route:"/login/autenticar",required:["token"]},lines:{route:"/linha/buscar",required:["terms"],proxyParams:{terms:"termosBusca"}},shapes:{route:"/shapes",required:["shapeId"],proxyParams:{shapeId:"codigoTrajeto"}},stops:{route:"/parada/buscar",required:["terms"],proxyParams:{terms:"termosBusca"}},stopsByLine:{route:"/parada/buscarParadasPorLinha",required:["lineId"],proxyParams:{lineId:"codigoLinha"}},corridors:{route:"/corredor"},stopsByCorridor:{route:"/parada/buscarParadasPorCorredor",required:["corridorId"],proxyParams:{corridorId:"codigoCorredor"}},vehiclesPosition:{route:"/posicao/linha",required:["lineId"],proxyParams:{lineId:"codigoLinha"}},arrivalForecast:{route:"/previsao",required:["stopId","lineId"],proxyParams:{stopId:"codigoParada",lineId:"codigoLinha"}},lineForecast:{route:"/previsao/linha",required:["lineId"],proxyParams:{lineId:"codigoLinha"}},stopForecast:{route:"/previsao/parada",required:["stopId"],proxyParams:{stopId:"codigoParada"}},linesDirection:{route:"/linha/buscarLinhaSentido",required:["terms","direction"],proxyParams:{terms:"termosBusca",direction:"sentido"}},companies:{route:"/empresa"}},Ce="undefined"!=typeof window,Pe=function(e){return e.map(function(e){return{prefix:e.p,accessible:e.a,hour:e.ta,lat:e.py,lng:e.px}})},Ee=function(e){return e.map(function(e){return{prefix:e.p,accessible:e.a,hour:e.t,lat:e.py,lng:e.px}})},Te=function(e){return e.map(function(e){return{lineId:e.cl,displaySign:e.c,direction:e.sl,mainTerminal:e.lt0,secondaryTerminal:e.lt1,quantity:e.qv,vehicles:Ee(e.vs)}})},qe=function(e){return e.map(function(e){return{prefix:e.p,accessible:e.a,hour:e.t,lat:e.py,lng:e.px}})},Ie=function(e){return e.map(function(e){return{stopId:e.cp,name:e.np,lat:e.py,lng:e.px,vehicles:qe(e.vs)}})},Re=function(e){return e.map(function(e){return{prefix:e.p,accessible:e.a,hour:e.ta,lat:e.py,lng:e.px}})},je=function(e){return e.map(function(e){return{lineId:e.cl,displaySign:e.c,direction:e.sl,mainTerminal:e.lt0,secondaryTerminal:e.lt1,quantity:e.qv,vehicles:Re(e.vs)}})},Ae="undefined"!=typeof window;e.auth=function(e){return Promise.resolve(e).then(w).then(C)},e.find=function(e){return Promise.resolve(e).then(O).then(U).then(k).then(F).then(N).then(z)},Object.defineProperty(e,"__esModule",{value:!0})});