UNPKG

15.5 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("node-fetch")):"function"==typeof define&&define.amd?define(["exports","node-fetch"],t):t((e=e||self).Bitbucket={},e.fetch)}(this,function(e,t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var r=function e(t,r,n,o){if("function"!=typeof n)throw new Error("method for before hook must be a function");o||(o={});if(Array.isArray(r))return r.reverse().reduce(function(r,n){return e.bind(null,t,n,r,o)},n)();return Promise.resolve().then(function(){return t.registry[r]?t.registry[r].reduce(function(e,t){return t.hook.bind(null,e,o)},n)():n(o)})};var n=function(e,t,r,n){var o=n;e.registry[r]||(e.registry[r]=[]);"before"===t&&(n=function(e,t){return Promise.resolve().then(o.bind(null,t)).then(e.bind(null,t))});"after"===t&&(n=function(e,t){var r;return Promise.resolve().then(e.bind(null,t)).then(function(e){return o(r=e,t)}).then(function(){return r})});"error"===t&&(n=function(e,t){return Promise.resolve().then(e.bind(null,t)).catch(function(e){return o(e,t)})});e.registry[r].push({hook:n,orig:o})};var o=function(e,t,r){if(!e.registry[t])return;var n=e.registry[t].map(function(e){return e.orig}).indexOf(r);if(-1===n)return;e.registry[t].splice(n,1)};var i=Function.bind,u=i.bind(i);function a(e,t,r){var i=u(o,null).apply(null,r?[t,r]:[t]);e.api={remove:i},e.remove=i,["before","error","after","wrap"].forEach(function(o){var i=r?[t,o,r]:[t,o];e[o]=e.api[o]=u(n,null).apply(null,i)})}function c(){var e={registry:{}},t=r.bind(null,e);return a(t,e),t}var s=!1;function f(){return s||(console.warn('[before-after-hook]: "Hook()" repurposing warning, use "Hook.Collection()". Read more: https://git.io/upgrade-before-after-hook-to-1.4'),s=!0),c()}f.Singular=function(){var e={registry:{}},t=r.bind(null,e,"h");return a(t,e,"h"),t}.bind(),f.Collection=c.bind();var l=f,p=f,d=f.Singular,h=f.Collection;l.Hook=p,l.Singular=d,l.Collection=h;var y={method:"GET",baseUrl:"".concat("https","://").concat("api.bitbucket.org").concat("/2.0"),headers:{accept:"application/json","user-agent":"bitbucket.js/".concat("2.0.0")}};function b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e,t){return(v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e,t,r){return(g=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&v(o,r.prototype),o}).apply(null,arguments)}function m(e){var t="function"==typeof Map?new Map:void 0;return(m=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return g(e,arguments,b(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,e)})(e)}function O(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function w(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function j(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var E=function(e){return function(e){return!!e&&"object"==typeof e}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===k}(e)}(e)};var k="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function A(e,t){return!1!==t.clone&&t.isMergeableObject(e)?P((r=e,Array.isArray(r)?[]:{}),e,t):e;var r}function S(e,t,r){return e.concat(t).map(function(e){return A(e,r)})}function q(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return e.propertyIsEnumerable(t)}):[]}(e))}function x(e,t,r){var n={};return r.isMergeableObject(e)&&q(e).forEach(function(t){n[t]=A(e[t],r)}),q(t).forEach(function(o){r.isMergeableObject(t[o])&&e[o]?n[o]=function(e,t){if(!t.customMerge)return P;var r=t.customMerge(e);return"function"==typeof r?r:P}(o,r)(e[o],t[o],r):n[o]=A(t[o],r)}),n}function P(e,t,r){(r=r||{}).arrayMerge=r.arrayMerge||S,r.isMergeableObject=r.isMergeableObject||E;var n=Array.isArray(t);return n===Array.isArray(e)?n?r.arrayMerge(e,t,r):x(e,t,r):A(t,r)}P.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,r){return P(e,r,t)},{})};var U=P;function T(e){return!0==(null!=(t=e)&&"object"==typeof t&&!1===Array.isArray(t))&&"[object Object]"===Object.prototype.toString.call(e);var t}function I(e){var t,r;return!1!==T(e)&&("function"==typeof(t=e.constructor)&&(!1!==T(r=t.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))}function C(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.keys(e).reduce(function(t,r){return t[r.toLowerCase()]=e[r],t},{})}function D(e,t,r){if("string"==typeof t){var n=j(t.split(" "),2),o=n[0],i=n[1];r=Object.assign(i?{method:o,url:i}:{url:o},r)}else r=t;return r.headers=C(r.headers),U.all([e,r].filter(Boolean),{isMergeableObject:I})}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var R,N=(function(e,t){e.exports=function(){function e(){}return e.prototype.encodeReserved=function(e){return e.split(/(%[0-9A-Fa-f]{2})/g).map(function(e){return/%[0-9A-Fa-f]/.test(e)||(e=encodeURI(e).replace(/%5B/g,"[").replace(/%5D/g,"]")),e}).join("")},e.prototype.encodeUnreserved=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})},e.prototype.encodeValue=function(e,t,r){return t="+"===e||"#"===e?this.encodeReserved(t):this.encodeUnreserved(t),r?this.encodeUnreserved(r)+"="+t:t},e.prototype.isDefined=function(e){return null!=e},e.prototype.isKeyOperator=function(e){return";"===e||"&"===e||"?"===e},e.prototype.getValues=function(e,t,r,n){var o=e[r],i=[];if(this.isDefined(o)&&""!==o)if("string"==typeof o||"number"==typeof o||"boolean"==typeof o)o=o.toString(),n&&"*"!==n&&(o=o.substring(0,parseInt(n,10))),i.push(this.encodeValue(t,o,this.isKeyOperator(t)?r:null));else if("*"===n)Array.isArray(o)?o.filter(this.isDefined).forEach(function(e){i.push(this.encodeValue(t,e,this.isKeyOperator(t)?r:null))},this):Object.keys(o).forEach(function(e){this.isDefined(o[e])&&i.push(this.encodeValue(t,o[e],e))},this);else{var u=[];Array.isArray(o)?o.filter(this.isDefined).forEach(function(e){u.push(this.encodeValue(t,e))},this):Object.keys(o).forEach(function(e){this.isDefined(o[e])&&(u.push(this.encodeUnreserved(e)),u.push(this.encodeValue(t,o[e].toString())))},this),this.isKeyOperator(t)?i.push(this.encodeUnreserved(r)+"="+u.join(",")):0!==u.length&&i.push(u.join(","))}else";"===t?this.isDefined(o)&&i.push(this.encodeUnreserved(r)):""!==o||"&"!==t&&"?"!==t?""===o&&i.push(""):i.push(this.encodeUnreserved(r)+"=");return i},e.prototype.parse=function(e){var t=this,r=["+","#",".","/",";","?","&"];return{expand:function(n){return e.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(e,o,i){if(o){var u=null,a=[];if(-1!==r.indexOf(o.charAt(0))&&(u=o.charAt(0),o=o.substr(1)),o.split(/,/g).forEach(function(e){var r=/([^:\*]*)(?::(\d+)|(\*))?/.exec(e);a.push.apply(a,t.getValues(n,u,r[1],r[2]||r[3]))}),u&&"+"!==u){var c=",";return"?"===u?c="&":"#"!==u&&(c=u),(0!==a.length?u:"")+a.join(c)}return a.join(",")}return t.encodeReserved(i)})}}},new e}()}(R={exports:{}},R.exports),R.exports);function B(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=/\?/.test(e)?"&":"?",n=Object.keys(t);return 0===n.length?e:"".concat(e).concat(r).concat(n.map(function(e){return"q"===e?"q=".concat(t.q.split(" ").map(encodeURIComponent).join("+")):"".concat(e,"=").concat(encodeURIComponent(t[e]))}).join("&"))}var M=/\{[^}]+\}/g;function _(e){return e.replace(/^\W+|\W+$/g,"").split(/,/)}var G={formData:"multipart/form-data",urlEncoded:"application/x-www-form-urlencoded",json:"application/json; charset=utf-8"};function H(e){var t=e.accepts,r=void 0===t?[]:t,n=e.method,o=e.baseUrl,i=e.url,u=e.headers,a=e.request,c=O(e,["accepts","method","baseUrl","url","headers","request"]),s=n.toUpperCase(),f=function(e){var t=e.match(M);return t?t.map(_).reduce(function(e,t){return e.concat(t)},[]):[]}(i),l=N.parse(i).expand(c);/^http/.test(l)||(l="".concat(o).concat(l));var p,d=Object.keys(c).reduce(function(e,t){return f.includes(t)||(e[t]=c[t]),e},{}),h=d._body,y=O(d,["_body"]),b=!1;if(["GET","DELETE"].includes(s))l=B(l,y);else if(void 0!==h){if((b=/form-?data/i.test((p=h).constructor.name))&&r.includes(G.formData))for(var v=0,g=Object.keys(y);v<g.length;v++){var m=g[v];p.append(m,y[m])}}else Object.keys(y).length&&(p=y);return b||(r.includes(G.urlEncoded)?(p=B("",p).substring(1),u["content-type"]=G.urlEncoded):(p=JSON.stringify(p),u["content-type"]=G.json)),{method:s,url:l,body:p,headers:u,request:a}}var V=function e(t,r){var n=D(t,r),o=function(e,t,r){return H(D(e,t,r))}.bind(null,n);return o.DEFAULTS=n,o.defaults=e.bind(null,n),o.merge=D.bind(null,n),o.parse=H,o}(null,y),K=function(e){function t(e,r){var n,o,i,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),o=this,n=!(i=b(t).call(this,e))||"object"!=typeof i&&"function"!=typeof i?w(o):i,Error.captureStackTrace&&Error.captureStackTrace(w(n),n.constructor),n.name="HTTPError",n.error=u.error,n.headers=u.headers,n.request=u.request,n.status=r,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&v(e,t)}(t,m(Error)),t}();function L(e){var t=e.headers.get("content-type");return/application\/json/.test(t)?e.json():!t||/^text\/|charset=utf-8$/.test(t)?e.text():e.arrayBuffer()}function F(e){var r,n,o=e.method,i=e.url,u=e.headers,a=e.body,c=e.request,s=Object.assign({method:o,body:a,headers:u},c),f={};return(c.fetch||t)(i,s).then(function(t){r=t.status,n=t.url;var o=!0,i=!1,u=void 0;try{for(var a,c=t.headers[Symbol.iterator]();!(o=(a=c.next()).done);o=!0){var s=j(a.value,2),l=s[0],p=s[1];f[l]=p}}catch(e){i=!0,u=e}finally{try{o||null==c.return||c.return()}finally{if(i)throw u}}return t.status>=400||[304].includes(t.status)?L(t).then(function(n){throw new K(t.statusText,r,{error:n,headers:f,request:e})}):L(t)}).then(function(e){return{data:e,headers:f,status:r,url:n}}).catch(function(t){if(t instanceof K)throw t;throw new K(t.message,500,{headers:f,request:e})})}var J=function e(t,r){var n=t.defaults(r);function o(e,t){var r=n.merge(e,t);return r.request&&r.request.hook?r.request.hook(function(e){return F(n.parse(e))},r):F(n.parse(r))}return o.defaults=e.bind(null,n),o.endpoint=n,o}(V,{});function $(e,t){e.headers=C(e.headers);var r,n=U({headers:{},request:{}},(r=e,["baseUrl","headers","request"].reduce(function(e,t){return void 0!==r[t]&&(e[t]=r[t]),e},{})),{isMergeableObject:I});return n.request.hook=t,n}function W(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new d,n={request:J.defaults($(t,r)),requestHook:r};return e.forEach(function(e){e(n,t)}),n}.bind(null,e);return t.plugins=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=e.slice(0);return t.forEach(function(e){r.includes(e)||r.push(e)}),W(r)}.bind(null,e),t}var z=W(),Q=function(e){return new Buffer(e).toString("base64")};function X(e,t,r){var n=r[t];if(!n)throw new K("not found: ".concat(t," page"),404);return e.request({method:"GET",url:n})}var Y=[function(e,t){var r=t.notice;(void 0===r||r)&&(console.log(" %s  %s ","BITBUCKET CLOUD API CHANGING NOTICE:","https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr"),console.log(" %s  %s ","BITBUCKET CLOUD API MIGRATION GUIDE:","https://developer.atlassian.com/cloud/bitbucket/bbc-gdpr-api-migration-guide"),console.log(" %s  %s ","BITBUCKET CLOUD API REPO URL CHANGE:","https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-workspaces"))},function(e,t){if(t.auth){!function(e){if(!("token"in e||e.username&&e.password))throw new Error('Invalid "auth" option: '.concat(JSON.stringify(e)))}(t.auth);var r={client:e,auth:t.auth};e.requestHook.before(function(e,t){if("token"in e.auth)t.headers.authorization="Bearer ".concat(e.auth.token);else if(e.auth.username){var r=Q("".concat(e.auth.username,":").concat(e.auth.password));t.headers.authorization="Basic ".concat(r)}}.bind(null,r))}},function(e){e.hasNextPage=function(e){var t=e.next;return Boolean(t)},e.getNextPage=X.bind(null,e,"next"),e.hasPreviousPage=function(e){var t=e.previous;return Boolean(t)},e.getPreviousPage=X.bind(null,e,"previous")},function(e){e.registerEndpoints=function(e,t){for(var r=function(){var r=o[n];e[r]||(e[r]={});for(var i=function(){var n=a[u],o=t[r][n];if(o.alias){var i=j(o.alias.split("."),2),c=i[0],s=i[1];o=t[c][s]}var f=["accepts","method","url","headers"].reduce(function(e,t){return t in o&&(e[t]=o[t]),e},{});f.request={validate:o.params};var l=e.request.defaults(f);if(o.deprecated)return e[r][n]=function(){return console.log(" %s  %s ","DEPRECATION WARNING:","".concat(f.method," ").concat(f.url)),e[r][n]=l,l.apply(void 0,arguments)},"continue";e[r][n]=l},u=0,a=Object.keys(t[r]);u<a.length;u++)i()},n=0,o=Object.keys(t);n<o.length;n++)r()}.bind(null,e)},function(e){e.requestHook.before(function(e,t){var r=t.request.validate;if(r)for(var n=0,o=Object.keys(r);n<o.length;n++){var i=o[n],u=r[i],a=u.type,c=t[i],s=void 0!==c;if(u.required||s){if(u.required&&!s)throw new K("parameter required: '".concat(i,"'"),400);if("integer"===a){var f=c;if(c=parseInt(c,10),isNaN(c))throw new K("invalid value for parameter '".concat(i,"': ").concat(JSON.stringify(f)," is NaN"),400)}if("boolean"===a&&"boolean"!=typeof c)throw new K("invalid value for parameter '".concat(i,"': ").concat(JSON.stringify(c)),400);if(u.enum&&!u.enum.includes(c))throw new K("invalid value for parameter '".concat(i,"': ").concat(JSON.stringify(c)),400)}}}.bind(null,e))}],Z=z.plugins(Y);e.Bitbucket=Z,Object.defineProperty(e,"__esModule",{value:!0})});
2//# sourceMappingURL=minimal.umd.js.map