doggo.js
Version:
Typed client for Doggo.Ninja's public API
3 lines (2 loc) • 17.3 kB
JavaScript
"use strict";function t(t,e,r,n,o,a,i){try{var s=t[a](i),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function e(e){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=e.apply(r,n);function s(e){t(i,o,a,s,u,"next",e)}function u(e){t(i,o,a,s,u,"throw",e)}s(void 0)}))}}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0}),require("isomorphic-unfetch");var n,o=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),a=new R(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=x(i,r);if(s){if(s===p)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,a),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p={};function f(){}function h(){}function l(){}var v={};s(v,o,(function(){return this}));var d=Object.getPrototypeOf,m=d&&d(d(L([])));m&&m!==e&&r.call(m,o)&&(v=m);var y=l.prototype=f.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,s){var u=c(t[o],t,a);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,i,s)}),(function(t){n("throw",t,i,s)})):e.resolve(f).then((function(t){p.value=t,i(p)}),(function(t){return n("throw",t,i,s)}))}s(u.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function R(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function L(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:E}}function E(){return{value:void 0,done:!0}}return h.prototype=l,s(y,"constructor",l),s(l,"constructor",h),h.displayName=s(l,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,s(t,i,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},w(g.prototype),s(g.prototype,a,(function(){return this})),t.AsyncIterator=g,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new g(u(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(y),s(y,i,"Generator"),s(y,o,(function(){return this})),s(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),b(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;b(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(n={exports:{}}),n.exports);exports.PatClient=function(){function t(t){this.baseUrl=null!=t?t:"https://pat.doggo.ninja"}var n=t.prototype;return n.files=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/files",{parent:e});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.upload=function(){var t=e(o.mark((function t(e,r,n){var a;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=new URL(this.baseUrl+"/v1/upload"),r&&a.searchParams.set("parent",r),a.searchParams.set("mimeType",e.type),e.name&&a.searchParams.set("originalName",e.name),t.next=6,this.makeUploadRequest("post",a.toString(),e,n);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.replace=function(){var t=e(o.mark((function t(e,r,n){var a;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return(a=new URL(this.baseUrl+"/v1/file/"+encodeURIComponent(e))).searchParams.set("mimeType",r.type),r.name&&a.searchParams.set("originalName",r.name),t.next=5,this.makeUploadRequest("put",a.toString(),r,n);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.getDownloadToken=function(){var t=e(o.mark((function t(e,r){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/files/token",{},{shortName:e,password:r});case 2:return t.abrupt("return",t.sent.downloadToken);case 5:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.updateFileSharing=function(){var t=e(o.mark((function t(e,n,a){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/files/sharing",{},r({shortName:e,private:n},a));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.moveFile=function(){var t=e(o.mark((function t(e,n,a){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/files/move",{},r({shortName:e},n,{forceMove:"parent"in n,copy:a}));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.getFile=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/file/"+encodeURIComponent(e));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.deleteFile=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("delete","/v1/file/"+encodeURIComponent(e));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.deleteFolder=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("delete","/v1/folder/"+encodeURIComponent(e));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.folders=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/folders",{parent:e});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.createFolder=function(){var t=e(o.mark((function t(e,r){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/folders/create",{},{name:e,parent:r});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.moveFolder=function(){var t=e(o.mark((function t(e,n){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/folders/move",{},r({id:e},n,{forceMove:"parent"in n}));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getFolder=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/folder/"+encodeURIComponent(e));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.checkAuth=function(){var t=e(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.makeRequest("get","/v1/auth/check");case 3:return t.abrupt("return",!0);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",!1);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),n.login=function(){var t=e(o.mark((function t(e,r){var n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/auth/login",{},{name:e,password:r});case 2:return t.abrupt("return",{sessionToken:(n=t.sent).sessionToken,expiration:new Date(n.expiration)});case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.resetPassword=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/auth/reset",{},{nameOrEmail:e});case 2:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.completeResetPassword=function(){var t=e(o.mark((function t(e,r,n){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/auth/reset/complete",{},{resetToken:e,newPassword:r,regenerateAccessToken:n});case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.invalidateSession=function(){var t=e(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/auth/invalidate");case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.regenerateAccessToken=function(){var t=e(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/auth/regenerate");case 2:return t.abrupt("return",t.sent.newToken);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.me=function(){var t=e(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/me");case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.setDomain=function(){var t=e(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/domain",{},{domain:e});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.adminUsage=function(){var t=e(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("get","/v1/admin/usage");case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.makeUser=function(){var t=e(o.mark((function t(e,r){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.makeRequest("post","/v1/admin/mkuser",{},{name:e,email:r});case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.makeUploadRequest=function(){var t=e(o.mark((function t(e,r,n,a){var i=this;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.next=2;break;case 2:return t.abrupt("return",new Promise((function(t,o){var s=new XMLHttpRequest;s.upload.addEventListener("progress",(function(t){a&&a(t.loaded,t.total)})),s.addEventListener("readystatechange",(function(){if(4===s.readyState){var e=s.responseText;try{var r=JSON.parse(e);s.status>=200&&s.status<300?t(r):o(new Error(r.message||s.statusText||"No error info"))}catch(t){o(new Error("Unable to parse json"))}}})),s.addEventListener("error",(function(){o(new Error("An unexpected error occurred"))})),s.open(e,r),s.setRequestHeader("Authorization","Bearer "+i.token),s.setRequestHeader("Content-Type","application/octet-stream"),s.send(n)})));case 3:case"end":return t.stop()}}),t)})));return function(e,r,n,o){return t.apply(this,arguments)}}(),n.makeRequest=function(){var t=e(o.mark((function t(e,r,n,a){var i,s,u,c,p,f,h,l,v,d;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(void 0===n&&(n={}),i={Accept:"application/json"},this.token&&(i.Authorization="Bearer "+this.token),a&&(i["Content-Type"]="application/json"),s=new URL(this.baseUrl.concat(r)),u=0,c=Object.entries(n);u<c.length;u++)f=(p=c[u])[0],(h=p[1])&&s.searchParams.set(f,h);return t.next=8,fetch(s.toString(),{method:e,headers:i,body:JSON.stringify(a)});case 8:if((l=t.sent).ok){t.next=21;break}return t.prev=10,t.next=13,l.json();case 13:d=t.sent.message,t.next=19;break;case 16:t.prev=16,t.t0=t.catch(10),d=l.statusText;case 19:throw d=null!=(v=d)?v:"No error info",new Error(d);case 21:return t.next=23,l.json();case 23:return t.abrupt("return",t.sent);case 25:case"end":return t.stop()}}),t,this,[[10,16]])})));return function(e,r,n,o){return t.apply(this,arguments)}}(),t}();
//# sourceMappingURL=doggo.js.cjs.production.min.js.map