UNPKG

doggo.js

Version:

Typed client for Doggo.Ninja's public API

3 lines (2 loc) 11.5 kB
"use strict";function t(t,n,e,r,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void e(t)}u.done?n(s):Promise.resolve(s).then(r,o)}function n(n){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=n.apply(e,r);function u(n){t(a,o,i,u,s,"next",n)}function s(n){t(a,o,i,u,s,"throw",n)}u(void 0)}))}}function e(){return(e=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)({}).hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(null,arguments)}function r(){var t,n,e="function"==typeof Symbol?Symbol:{},i=e.iterator||"@@iterator",a=e.toStringTag||"@@toStringTag";function u(e,r,i,a){var u=Object.create((r&&r.prototype instanceof c?r:c).prototype);return o(u,"_invoke",function(e,r,o){var i,a,u,c=0,f=o||[],h=!1,p={p:0,n:0,v:t,a:l,f:l.bind(t,4),d:function(n,e){return i=n,a=0,u=t,p.n=e,s}};function l(e,r){for(a=e,u=r,n=0;!h&&c&&!o&&n<f.length;n++){var o,i=f[n],l=p.p,v=i[2];e>3?(o=v===r)&&(u=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=l&&((o=e<2&&l<i[1])?(a=0,p.v=r,p.n=i[1]):l<v&&(o=e<3||i[0]>r||r>v)&&(i[4]=e,i[5]=r,p.n=v,a=0))}if(o||e>1)return s;throw h=!0,r}return function(o,f,v){if(c>1)throw TypeError("Generator is already running");for(h&&1===f&&l(f,v),a=f,u=v;(n=a<2?t:u)||!h;){i||(a?a<3?(a>1&&(p.n=-1),l(a,u)):p.n=u:p.v=u);try{if(c=2,i){if(a||(o="next"),n=i[o]){if(!(n=n.call(i,u)))throw TypeError("iterator result is not an object");if(!n.done)return n;u=n.value,a<2&&(a=0)}else 1===a&&(n=i.return)&&n.call(i),a<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((n=(h=p.n<0)?u:e.call(r,p))!==s)break}catch(n){i=t,a=1,u=n}finally{c=1}}return{value:n,done:h}}}(e,i,a),!0),u}var s={};function c(){}function f(){}function h(){}n=Object.getPrototypeOf;var p=[][i]?n(n([][i]())):(o(n={},i,(function(){return this})),n),l=h.prototype=c.prototype=Object.create(p);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,o(t,a,"GeneratorFunction")),t.prototype=Object.create(l),t}return f.prototype=h,o(l,"constructor",h),o(h,"constructor",f),f.displayName="GeneratorFunction",o(h,a,"GeneratorFunction"),o(l),o(l,a,"Generator"),o(l,i,(function(){return this})),o(l,"toString",(function(){return"[object Generator]"})),(r=function(){return{w:u,m:v}})()}function o(t,n,e,r){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}(o=function(t,n,e,r){function a(n,e){o(t,n,(function(t){return this._invoke(n,e,t)}))}n?i?i(t,n,{value:e,enumerable:!r,configurable:!r,writable:!r}):t[n]=e:(a("next",0),a("throw",1),a("return",2))})(t,n,e,r)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.PatClient=function(){function t(t){this.baseUrl=null!=t?t:"https://pat.doggo.ninja"}var o=t.prototype;return o.files=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/files",{parentId:n});case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.recentFiles=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/files",{count:n.toString()});case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.upload=function(){var t=n(r().m((function t(n,e,o){var i;return r().w((function(t){for(;;)switch(t.n){case 0:return i=new URL(this.baseUrl+"/v1/upload"),e&&i.searchParams.set("parentId",e),i.searchParams.set("mimeType",n.type),n.name&&i.searchParams.set("originalName",n.name),t.n=1,this.makeUploadRequest("post",i.toString(),n,o);case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e,r){return t.apply(this,arguments)}}(),o.replace=function(){var t=n(r().m((function t(n,e,o){var i;return r().w((function(t){for(;;)switch(t.n){case 0:return(i=new URL(this.baseUrl+"/v1/file/"+encodeURIComponent(n))).searchParams.set("mimeType",e.type),e.name&&i.searchParams.set("originalName",e.name),t.n=1,this.makeUploadRequest("put",i.toString(),e,o);case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e,r){return t.apply(this,arguments)}}(),o.getDownloadToken=function(){var t=n(r().m((function t(n,e){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/files/token",{},{shortName:n,password:e});case 1:return t.a(2,t.v.downloadToken)}}),t,this)})));return function(n,e){return t.apply(this,arguments)}}(),o.updateFileSharing=function(){var t=n(r().m((function t(n,o,i){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/files/sharing",{},e({shortName:n,private:o},i));case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e,r){return t.apply(this,arguments)}}(),o.moveFile=function(){var t=n(r().m((function t(n,o,i){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/files/move",{},e({shortName:n},o,{forceMove:"parentId"in o,copy:i}));case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e,r){return t.apply(this,arguments)}}(),o.getFile=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/file/"+encodeURIComponent(n));case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.deleteFile=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("delete","/v1/file/"+encodeURIComponent(n));case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.deleteFolder=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("delete","/v1/folder/"+encodeURIComponent(n));case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.folders=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/folders",{parentId:n});case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.createFolder=function(){var t=n(r().m((function t(n,e){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/folders/create",{},{name:n,parentId:e});case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e){return t.apply(this,arguments)}}(),o.moveFolder=function(){var t=n(r().m((function t(n,o){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/folders/move",{},e({id:n},o,{forceMove:"parentId"in o}));case 1:return t.a(2,t.v)}}),t,this)})));return function(n,e){return t.apply(this,arguments)}}(),o.getFolder=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/folder/"+encodeURIComponent(n));case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.checkAuth=function(){var t=n(r().m((function t(){return r().w((function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.makeRequest("get","/v1/auth/check");case 1:return t.a(2,!0);case 2:return t.p=2,t.a(2,!1)}}),t,this,[[0,2]])})));return function(){return t.apply(this,arguments)}}(),o.login=function(){var t=n(r().m((function t(n,e){var o;return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/auth/login",{},{name:n,password:e});case 1:return t.a(2,{sessionToken:(o=t.v).sessionToken,expiration:new Date(o.expiration)})}}),t,this)})));return function(n,e){return t.apply(this,arguments)}}(),o.resetPassword=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/auth/reset",{},{nameOrEmail:n});case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.completeResetPassword=function(){var t=n(r().m((function t(n,e,o){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/auth/reset/complete",{},{resetToken:n,newPassword:e,regenerateAccessToken:o});case 1:return t.a(2)}}),t,this)})));return function(n,e,r){return t.apply(this,arguments)}}(),o.invalidateSession=function(){var t=n(r().m((function t(){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/auth/invalidate");case 1:return t.a(2)}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.regenerateAccessToken=function(){var t=n(r().m((function t(){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/auth/regenerate");case 1:return t.a(2,t.v.newToken)}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.me=function(){var t=n(r().m((function t(){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/me");case 1:return t.a(2,t.v)}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.setDomain=function(){var t=n(r().m((function t(n){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/domain",{},{domain:n});case 1:return t.a(2,t.v)}}),t,this)})));return function(n){return t.apply(this,arguments)}}(),o.adminUsage=function(){var t=n(r().m((function t(){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("get","/v1/admin/usage");case 1:return t.a(2,t.v)}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.makeUser=function(){var t=n(r().m((function t(n,e){return r().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,this.makeRequest("post","/v1/admin/mkuser",{},{name:n,email:e});case 1:return t.a(2)}}),t,this)})));return function(n,e){return t.apply(this,arguments)}}(),o.makeUploadRequest=function(){var t=n(r().m((function t(n,e,o,i){var a=this;return r().w((function(t){for(;;)switch(t.n){case 0:t.n=1;break;case 1:return t.a(2,new Promise((function(t,r){var u=new XMLHttpRequest;u.upload.addEventListener("progress",(function(t){i&&i(t.loaded,t.total)})),u.addEventListener("readystatechange",(function(){if(4===u.readyState){var n=u.responseText;try{var e=JSON.parse(n);u.status>=200&&u.status<300?t(e):r(new Error(e.message||u.statusText||"No error info"))}catch(t){r(new Error("Unable to parse json"))}}})),u.addEventListener("error",(function(){r(new Error("An unexpected error occurred"))})),u.open(n,e),u.setRequestHeader("Authorization","Bearer "+a.token),u.setRequestHeader("Content-Type","application/octet-stream"),u.send(o)})))}}),t)})));return function(n,e,r,o){return t.apply(this,arguments)}}(),o.makeRequest=function(){var t=n(r().m((function t(n,e,o,i){var a,u,s,c,f,h,p,l,v;return r().w((function(t){for(;;)switch(t.p=t.n){case 0:for(void 0===o&&(o={}),a={Accept:"application/json"},this.token&&(a.Authorization="Bearer "+this.token),i&&(a["Content-Type"]="application/json"),u=new URL(this.baseUrl.concat(e)),s=0,c=Object.entries(o);s<c.length;s++)h=(f=c[s])[0],(p=f[1])&&u.searchParams.set(h,p);return t.n=1,fetch(u.toString(),{method:n,headers:a,body:JSON.stringify(i)});case 1:if((l=t.v).ok){t.n=6;break}return t.p=2,t.n=3,l.json();case 3:v=t.v.message,t.n=5;break;case 4:t.p=4,v=l.statusText;case 5:throw v=null!=v?v:"No error info",new Error(v);case 6:return t.n=7,l.json();case 7:return t.a(2,t.v)}}),t,this,[[2,4]])})));return function(n,e,r,o){return t.apply(this,arguments)}}(),t}(); //# sourceMappingURL=doggo.js.cjs.production.min.js.map