UNPKG

circleci-api

Version:

A Node and Browser client for the CircleCI API, written in TypeScript.

18 lines (15 loc) 27.1 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).circleciApi={})}(this,(function(e){"use strict";var t,r,n="https://circleci.com/api/v1.1";function o(t){var r=t.type;return"/project/"+(void 0===r?e.GitType.GITHUB:r)+"/"+t.owner+"/"+t.repo}(t=e.GitType||(e.GitType={})).GITHUB="github",t.BITBUCKET="bitbucket",(r=e.BuildAction||(e.BuildAction={})).RETRY="retry",r.CANCEL="cancel"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var i=function(){return(i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function s(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function c(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function c(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))}function a(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var u=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)}},f=Object.prototype.toString;function l(e){return"[object Array]"===f.call(e)}function p(e){return void 0===e}function d(e){return null!==e&&"object"==typeof e}function h(e){if("[object Object]"!==f.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function v(e){return"[object Function]"===f.call(e)}function y(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),l(e))for(var r=0,n=e.length;r<n;r++)t.call(null,e[r],r,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var m={isArray:l,isArrayBuffer:function(e){return"[object ArrayBuffer]"===f.call(e)},isBuffer:function(e){return null!==e&&!p(e)&&null!==e.constructor&&!p(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},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:d,isPlainObject:h,isUndefined:p,isDate:function(e){return"[object Date]"===f.call(e)},isFile:function(e){return"[object File]"===f.call(e)},isBlob:function(e){return"[object Blob]"===f.call(e)},isFunction:v,isStream:function(e){return d(e)&&v(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:y,merge:function e(){var t={};function r(r,n){h(t[n])&&h(r)?t[n]=e(t[n],r):h(r)?t[n]=e({},r):l(r)?t[n]=r.slice():t[n]=r}for(var n=0,o=arguments.length;n<o;n++)y(arguments[n],r);return t},extend:function(e,t,r){return y(t,(function(t,n){e[n]=r&&"function"==typeof t?u(t,r):t})),e},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}};function g(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var w=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(m.isURLSearchParams(t))n=t.toString();else{var o=[];m.forEach(t,(function(e,t){null!=e&&(m.isArray(e)?t+="[]":e=[e],m.forEach(e,(function(e){m.isDate(e)?e=e.toISOString():m.isObject(e)&&(e=JSON.stringify(e)),o.push(g(t)+"="+g(e))})))})),n=o.join("&")}if(n){var i=e.indexOf("#");-1!==i&&(e=e.slice(0,i)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e};function b(){this.handlers=[]}b.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},b.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},b.prototype.forEach=function(e){m.forEach(this.handlers,(function(t){null!==t&&e(t)}))};var k=b,O=function(e,t,r){return m.forEach(r,(function(r){e=r(e,t)})),e},E=function(e){return!(!e||!e.__CANCEL__)},T="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function R(){throw new Error("setTimeout has not been defined")}function C(){throw new Error("clearTimeout has not been defined")}var A=R,j=C;function H(e){if(A===setTimeout)return setTimeout(e,0);if((A===R||!A)&&setTimeout)return A=setTimeout,setTimeout(e,0);try{return A(e,0)}catch(t){try{return A.call(null,e,0)}catch(t){return A.call(this,e,0)}}}"function"==typeof T.setTimeout&&(A=setTimeout),"function"==typeof T.clearTimeout&&(j=clearTimeout);var x,B=[],S=!1,q=-1;function N(){S&&x&&(S=!1,x.length?B=x.concat(B):q=-1,B.length&&U())}function U(){if(!S){var e=H(N);S=!0;for(var t=B.length;t;){for(x=B,B=[];++q<t;)x&&x[q].run();q=-1,t=B.length}x=null,S=!1,function(e){if(j===clearTimeout)return clearTimeout(e);if((j===C||!j)&&clearTimeout)return j=clearTimeout,clearTimeout(e);try{j(e)}catch(t){try{return j.call(null,e)}catch(t){return j.call(this,e)}}}(e)}}function P(e,t){this.fun=e,this.array=t}P.prototype.run=function(){this.fun.apply(null,this.array)};function L(){}var I=L,D=L,_=L,F=L,K=L,M=L,G=L;var z=T.performance||{},V=z.now||z.mozNow||z.msNow||z.oNow||z.webkitNow||function(){return(new Date).getTime()};var J=new Date;var X={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];B.push(new P(e,t)),1!==B.length||S||H(U)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:I,addListener:D,once:_,off:F,removeListener:K,removeAllListeners:M,emit:G,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*V.call(z),r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r-=e[0],(n-=e[1])<0&&(r--,n+=1e9)),[r,n]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-J)/1e3}},$=function(e,t){m.forEach(e,(function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])}))},Y=function(e,t,r,n,o){return function(e,t,r,n,o){return e.config=t,r&&(e.code=r),e.request=n,e.response=o,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e}(new Error(e),t,r,n,o)},Q=m.isStandardBrowserEnv()?{write:function(e,t,r,n,o,i){var s=[];s.push(e+"="+encodeURIComponent(t)),m.isNumber(r)&&s.push("expires="+new Date(r).toGMTString()),m.isString(n)&&s.push("path="+n),m.isString(o)&&s.push("domain="+o),!0===i&&s.push("secure"),document.cookie=s.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(){}},W=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],Z=m.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a");function n(e){var n=e;return t&&(r.setAttribute("href",n),n=r.href),r.setAttribute("href",n),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:"/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname}}return e=n(window.location.href),function(t){var r=m.isString(t)?n(t):t;return r.protocol===e.protocol&&r.host===e.host}}():function(){return!0},ee=function(e){return new Promise((function(t,r){var n=e.data,o=e.headers;m.isFormData(n)&&delete o["Content-Type"];var i=new XMLHttpRequest;if(e.auth){var s=e.auth.username||"",c=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(s+":"+c)}var a,u,f=(a=e.baseURL,u=e.url,a&&!/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(u)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(a,u):u);if(i.open(e.method.toUpperCase(),w(f,e.params,e.paramsSerializer),!0),i.timeout=e.timeout,i.onreadystatechange=function(){if(i&&4===i.readyState&&(0!==i.status||i.responseURL&&0===i.responseURL.indexOf("file:"))){var n,o,s,c,a,u="getAllResponseHeaders"in i?(n=i.getAllResponseHeaders(),a={},n?(m.forEach(n.split("\n"),(function(e){if(c=e.indexOf(":"),o=m.trim(e.substr(0,c)).toLowerCase(),s=m.trim(e.substr(c+1)),o){if(a[o]&&W.indexOf(o)>=0)return;a[o]="set-cookie"===o?(a[o]?a[o]:[]).concat([s]):a[o]?a[o]+", "+s:s}})),a):a):null,f={data:e.responseType&&"text"!==e.responseType?i.response:i.responseText,status:i.status,statusText:i.statusText,headers:u,config:e,request:i};!function(e,t,r){var n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(Y("Request failed with status code "+r.status,r.config,null,r.request,r)):e(r)}(t,r,f),i=null}},i.onabort=function(){i&&(r(Y("Request aborted",e,"ECONNABORTED",i)),i=null)},i.onerror=function(){r(Y("Network Error",e,null,i)),i=null},i.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),r(Y(t,e,"ECONNABORTED",i)),i=null},m.isStandardBrowserEnv()){var l=(e.withCredentials||Z(f))&&e.xsrfCookieName?Q.read(e.xsrfCookieName):void 0;l&&(o[e.xsrfHeaderName]=l)}if("setRequestHeader"in i&&m.forEach(o,(function(e,t){void 0===n&&"content-type"===t.toLowerCase()?delete o[t]:i.setRequestHeader(t,e)})),m.isUndefined(e.withCredentials)||(i.withCredentials=!!e.withCredentials),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)})),n||(n=null),i.send(n)}))},te={"Content-Type":"application/x-www-form-urlencoded"};function re(e,t){!m.isUndefined(e)&&m.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var ne,oe={adapter:(("undefined"!=typeof XMLHttpRequest||void 0!==X&&"[object process]"===Object.prototype.toString.call(X))&&(ne=ee),ne),transformRequest:[function(e,t){return $(t,"Accept"),$(t,"Content-Type"),m.isFormData(e)||m.isArrayBuffer(e)||m.isBuffer(e)||m.isStream(e)||m.isFile(e)||m.isBlob(e)?e:m.isArrayBufferView(e)?e.buffer:m.isURLSearchParams(e)?(re(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):m.isObject(e)?(re(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,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};oe.headers={common:{Accept:"application/json, text/plain, */*"}},m.forEach(["delete","get","head"],(function(e){oe.headers[e]={}})),m.forEach(["post","put","patch"],(function(e){oe.headers[e]=m.merge(te)}));var ie=oe;function se(e){e.cancelToken&&e.cancelToken.throwIfRequested()}var ce=function(e){return se(e),e.headers=e.headers||{},e.data=O(e.data,e.headers,e.transformRequest),e.headers=m.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),m.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||ie.adapter)(e).then((function(t){return se(e),t.data=O(t.data,t.headers,e.transformResponse),t}),(function(t){return E(t)||(se(e),t&&t.response&&(t.response.data=O(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))},ae=function(e,t){t=t||{};var r={},n=["url","method","data"],o=["headers","auth","proxy","params"],i=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],s=["validateStatus"];function c(e,t){return m.isPlainObject(e)&&m.isPlainObject(t)?m.merge(e,t):m.isPlainObject(t)?m.merge({},t):m.isArray(t)?t.slice():t}function a(n){m.isUndefined(t[n])?m.isUndefined(e[n])||(r[n]=c(void 0,e[n])):r[n]=c(e[n],t[n])}m.forEach(n,(function(e){m.isUndefined(t[e])||(r[e]=c(void 0,t[e]))})),m.forEach(o,a),m.forEach(i,(function(n){m.isUndefined(t[n])?m.isUndefined(e[n])||(r[n]=c(void 0,e[n])):r[n]=c(void 0,t[n])})),m.forEach(s,(function(n){n in t?r[n]=c(e[n],t[n]):n in e&&(r[n]=c(void 0,e[n]))}));var u=n.concat(o).concat(i).concat(s),f=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===u.indexOf(e)}));return m.forEach(f,a),r};function ue(e){this.defaults=e,this.interceptors={request:new k,response:new k}}ue.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=ae(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=[ce,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},ue.prototype.getUri=function(e){return e=ae(this.defaults,e),w(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},m.forEach(["delete","get","head","options"],(function(e){ue.prototype[e]=function(t,r){return this.request(ae(r||{},{method:e,url:t,data:(r||{}).data}))}})),m.forEach(["post","put","patch"],(function(e){ue.prototype[e]=function(t,r,n){return this.request(ae(n||{},{method:e,url:t,data:r}))}}));var fe=ue;function le(e){this.message=e}le.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},le.prototype.__CANCEL__=!0;var pe=le;function de(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 pe(e),t(r.reason))}))}de.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},de.source=function(){var e;return{token:new de((function(t){e=t})),cancel:e}};var he=de;function ve(e){var t=new fe(e),r=u(fe.prototype.request,t);return m.extend(r,fe.prototype,t),m.extend(r,t),r}var ye=ve(ie);ye.Axios=fe,ye.create=function(e){return ve(ae(ye.defaults,e))},ye.Cancel=pe,ye.CancelToken=he,ye.isCancel=E,ye.all=function(e){return Promise.all(e)},ye.spread=function(e){return function(t){return e.apply(null,t)}},ye.isAxiosError=function(e){return"object"==typeof e&&!0===e.isAxiosError};var me=ye,ge=ye;me.default=ge;var we=me;function be(e){void 0===e&&(e={});var t=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]})).reduce((function(t,r){return function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var i=arguments[t],s=0,c=i.length;s<c;s++,o++)n[o]=i[s];return n}(t,[r+"="+encodeURIComponent(e[r])])}),[]).join("&");return t.length?"?"+t:""}function ke(e){void 0===e&&(e={});var t=e.headers,r=void 0===t?{}:t,n=s(e,["headers"]);return i(i({},n),{headers:i(i({},r),{"User-Agent":"worldturtlemedia/circleci-api 4.1.4"})})}function Oe(e,t,r){return we.get(Re(e,t),r)}function Ee(e,t,r,n){return we.post(Re(e,t),r,n)}function Te(e,t,r){return we.delete(Re(e,t),r)}function Re(e,t){return t+(t.includes("?")?"&":"?")+"circle-token="+e}function Ce(e,t){var r=this;void 0===t&&(t=n);var o={baseURL:t};return{get:function(t,n){return void 0===n&&(n={}),c(r,void 0,void 0,(function(){var r;return a(this,(function(i){switch(i.label){case 0:return r=ke(Ae(o,n)),[4,Oe(e,t,r)];case 1:return[2,i.sent().data]}}))}))},post:function(t,n,i){return void 0===i&&(i={}),c(r,void 0,void 0,(function(){var r;return a(this,(function(s){switch(s.label){case 0:return r=ke(Ae(o,i)),[4,Ee(e,t,n,r)];case 1:return[2,s.sent().data]}}))}))},delete:function(t,n){return void 0===n&&(n={}),c(r,void 0,void 0,(function(){var r;return a(this,(function(i){switch(i.label){case 0:return r=ke(Ae(o,n)),[4,Te(e,t,r)];case 1:return[2,i.sent().data]}}))}))}}}function Ae(e,t){return i(i({},e),t)}function je(e,t,r,n){var i=n.circleHost,c=o(s(n,["circleHost"]))+"/"+t+"/"+r;return Ce(e,i).post(c)}function He(e,t){var r=t.circleHost,n=t.vcs,i=t.options,s=void 0===i?{}:i,c=s.branch,a=void 0===c?"":c,u=s.newBuildOptions,f=void 0===u?{}:u,l=o(n)+(a?"/tree/"+a:"");return Ce(e,r).post(l,f)}function xe(e,t,r){var n=r.circleHost,i=o(s(r,["circleHost"]))+"/"+t+"/artifacts";return Ce(e,n).get(i)}function Be(e,t){var r=t.vcs,n=t.options,i=void 0===n?{}:n,s=t.circleHost,c=i.branch,a=i.filter,u=o(r)+"/latest/artifacts"+be({branch:c,filter:a});return Ce(e,s).get(u)}function Se(e,t){var r=void 0===t?{}:t,n=r.limit,o=r.offset,i=r.circleHost,s="/recent-builds"+be({limit:n,offset:o});return Ce(e,i).get(s)}function qe(e,t){var r=t.vcs,n=t.options,i=void 0===n?{}:n,s=t.circleHost,c=i.limit,a=i.offset,u=i.filter,f=i.branch,l=o(r)+(f?"/tree/"+f:""),p=be({limit:c,offset:a,filter:u});return Ce(e,s).get(""+l+p)}function Ne(e,t,r){var n=r.circleHost,i=o(s(r,["circleHost"]))+"/"+t;return Ce(e,n).get(i)}function Ue(e,t){return Ce(e,(void 0===t?{}:t).circleHost).get("/projects")}function Pe(e,t){var r=t.vcs,n=t.circleHost,i=o(r)+"/follow";return Ce(e,n).post(i)}function Le(e,t){var r=t.circleHost,n=o(s(t,["circleHost"]))+"/build-cache";return Ce(e,r).delete(n)}function Ie(e,t){var r=t.circleHost,n=s(t,["circleHost"]);return Ce(e,r).get(Ke(n))}function De(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).post(Ke(o),t,{headers:{"Content-Type":"application/json",Accepts:"application/json"}})}function _e(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).get(Ke(o,t))}function Fe(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).delete(Ke(o,t))}function Ke(e,t){return o(e)+"/checkout-key"+(t?"/"+t:"")}function Me(e,t){var r=t.circleHost,n=s(t,["circleHost"]);return Ce(e,r).get(Je(n))}function Ge(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).post(Je(o),t,{headers:{"Content-Type":"application/json",Accepts:"application/json"}})}function ze(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).get(Je(o,t))}function Ve(e,t,r){var n=r.circleHost,o=s(r,["circleHost"]);return Ce(e,n).delete(Je(o,t))}function Je(e,t){return void 0===t&&(t=""),o(e)+"/envvar"+(t?"/"+t:"")}function Xe(e,t,r){var n=r.circleHost,i=o(s(r,["circleHost"]))+"/"+t+"/tests";return Ce(e,n).get(i)}function $e(e,t,r,n){var i=(void 0===n?{}:n).circleHost,s=o(t)+"/ssh-key";return Ce(e,i).post(s,r)}function Ye(e,t,r){return Ce(e,(void 0===r?{}:r).circleHost).post("/user/heroku-key",t)}function Qe(e,t){return Ce(e,(void 0===t?{}:t).circleHost).get("/me")}var We=function(){function t(t){var r=t.token,n=t.vcs,o=void 0===n?{}:n,i=o.type,s=void 0===i?e.GitType.GITHUB:i,c=o.owner,a=void 0===c?"":c,u=o.repo,f=void 0===u?"":u,l=t.options,p=void 0===l?{}:l,d=t.circleHost;this.token=r,this.vcs={type:s,owner:a,repo:f},this.options=p,this.circleOptions={circleHost:d}}return t.prototype.defaults=function(){return{token:this.token,vcs:this.vcs,options:this.options}},t.prototype.addToken=function(e){return e+"?circle-token="+this.token},t.prototype.me=function(){return Qe(this.token,this.circleOptions)},t.prototype.projects=function(){return Ue(this.token,this.circleOptions)},t.prototype.followProject=function(e){var t=this.createRequest(e),r=t.token,n=s(t,["token"]);return Pe(r,i(i({},n),this.circleOptions))},t.prototype.recentBuilds=function(e,t){void 0===e&&(e={});var r=this.createRequest(i(i({},t||{}),{options:i(i({},t?t.options:{}),e)})),n=r.token,o=r.options;return Se(n,i(i({},o),this.circleOptions))},t.prototype.builds=function(e,t){var r=this.createRequest(i(i({},t||{}),{options:i(i({},t?t.options:{}),e||{})})),n=r.token,o=s(r,["token"]);return qe(n,i(i({},o),this.circleOptions))},t.prototype.buildsFor=function(e,t,r){void 0===e&&(e="master"),void 0===t&&(t={});var n=this.createRequest(i(i({},r),{options:i(i(i({},r?r.options:{}),t),{branch:e})})),o=n.token,c=s(n,["token"]);return qe(o,i(i({},c),this.circleOptions))},t.prototype.build=function(e,t){var r=this.createRequest(i(i({},t||{}),{options:i({},t?t.options:{})})),n=r.token,o=r.vcs;return Ne(n,e,i(i({},o),this.circleOptions))},t.prototype.artifacts=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return xe(n,e,i(i({},o),this.circleOptions))},t.prototype.latestArtifacts=function(e,t){void 0===t&&(t={});var r=this.createRequest(i(i({},t),{options:i(i({},t.options),e||{})})),n=r.token,o=s(r,["token"]);return Be(n,i(i({},o),this.circleOptions))},t.prototype.retry=function(t,r){return this.performAction(i(i({},this.createRequest(r)),this.circleOptions),t,e.BuildAction.RETRY)},t.prototype.cancel=function(t,r){return this.performAction(i(i({},this.createRequest(r)),this.circleOptions),t,e.BuildAction.CANCEL)},t.prototype.triggerBuild=function(e){var t=this.createRequest(e),r=t.token,n=s(t,["token"]);return He(r,i(i({},n),this.circleOptions))},t.prototype.triggerBuildFor=function(e,t){void 0===e&&(e="master");var r=this.createRequest(i(i({},t),{options:i(i({},t?t.options:{}),{branch:e})})),n=r.token,o=s(r,["token"]);return He(n,i(i({},o),this.circleOptions))},t.prototype.clearCache=function(e){var t=this.createRequest(e),r=t.token,n=t.vcs;return Le(r,i(i({},n),this.circleOptions))},t.prototype.listEnvVars=function(e){var t=this.createRequest(e),r=t.token,n=t.vcs;return Me(r,i(i({},n),this.circleOptions))},t.prototype.addEnvVar=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return Ge(n,e,i(i({},o),this.circleOptions))},t.prototype.getEnvVar=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return ze(n,e,i(i({},o),this.circleOptions))},t.prototype.deleteEnvVar=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return Ve(n,e,i(i({},o),this.circleOptions))},t.prototype.listCheckoutKeys=function(e){var t=this.createRequest(e),r=t.token,n=t.vcs;return Ie(r,i(i({},n),this.circleOptions))},t.prototype.addCheckoutKey=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return De(n,{type:e},i(i({},o),this.circleOptions))},t.prototype.getCheckoutKey=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return _e(n,e,i(i({},o),this.circleOptions))},t.prototype.deleteCheckoutKey=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return Fe(n,e,i(i({},o),this.circleOptions))},t.prototype.getTestMetadata=function(e,t){var r=this.createRequest(t),n=r.token,o=r.vcs;return Xe(n,e,i(i({},o),this.circleOptions))},t.prototype.addSSHKey=function(e,t){var r=this.createRequest(t);return $e(r.token,r.vcs,e,this.circleOptions)},t.prototype.addHerokuKey=function(e,t){return Ye(this.createRequest(t).token,e,this.circleOptions)},t.prototype.createRequest=function(e){void 0===e&&(e={});var t={token:e.token||this.token,options:i(i({},this.options),e.options),vcs:i(i({},this.vcs),e.vcs)};return function(e){var t=e.token,r=e.vcs,n=r.type,o=r.owner,i=r.repo;if(!t)throw new Error("CircleCiApi - No token was provided");var s=[];if(n||s.push("type"),o||s.push("owner"),i||s.push("repo"),s.length)throw new Error("CircleCiApi - Missing options "+s)}(t),t},t.prototype.performAction=function(e,t,r){var n=e.token,o=e.vcs,s=e.circleHost;return je(n,t,r,i(i({},o),{circleHost:s}))},t}();e.API_ALL_PROJECTS="/projects",e.API_BASE=n,e.API_ME="/me",e.API_PROJECT="/project",e.API_RECENT_BUILDS="/recent-builds",e.API_USER="/user",e.CircleCI=We,e.CircleCIFactory=Ce,e.addEnv=Ge,e.addHerokuKey=Ye,e.addSSHKey=$e,e.clearCache=Le,e.createCheckoutKey=De,e.createVcsUrl=o,e.deleteCheckoutKey=Fe,e.deleteEnv=Ve,e.getAllProjects=Ue,e.getBuildArtifacts=xe,e.getBuildSummaries=qe,e.getCheckoutKey=_e,e.getCheckoutKeys=Ie,e.getEnv=ze,e.getFullBuild=Ne,e.getGitType=function(t){var r=t.trim().replace(/ /g,"").toLowerCase();return r===e.GitType.BITBUCKET?r:e.GitType.GITHUB},e.getLatestArtifacts=Be,e.getMe=Qe,e.getRecentBuilds=Se,e.getTestMetadata=Xe,e.listEnv=Me,e.postBuildActions=je,e.postFollowNewProject=Pe,e.postTriggerNewBuild=He,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=circleci-api.umd.min.js.map