ec.fdk 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty,F=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var T=(n,t,e)=>t in n?M(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t)=>{for(var e in t||(t={}))v.call(t,e)&&T(n,e,t[e]);if(A)for(var e of A(t))H.call(t,e)&&T(n,e,t[e]);return n},y=(n,t)=>F(n,G(t));var c=(n,t,e)=>new Promise((s,r)=>{var o=h=>{try{u(e.next(h))}catch(f){r(f)}},i=h=>{try{u(e.throw(h))}catch(f){r(f)}},u=h=>h.done?s(h.value):Promise.resolve(h.value).then(o,i);u((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return c(this,arguments,function*(n,t={},e={}){const{token:r,rawRes:o}=t;r&&(e.headers=y(a({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return o?i:yield i.json()})}const P={production:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function d(n,t="stage"){const e=P[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(P).join(", ")}`);return e+n}function p(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function l(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const O={stage:"https://accounts.cachena.entrecode.de/",production:"https://accounts.cachena.entrecode.de/"};function _(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;l({env:t,dmShortID:e,email:s,password:r});const o=d(`api/${e}/_auth/login?clientID=rest`,t);return yield g(o,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function L(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;l({env:t,email:e,password:s});const r=`${O[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function S(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;l({dmShortID:t,env:e,token:s});const r=d(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function K(n){return c(this,null,function*(){let{env:t,token:e}=n;l({env:t,token:e});const s=`${O[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function D({dmShortID:n}){return l({dmShortID:n}),n}function q({env:n}){return l({env:n}),n}function B(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;l({env:t,dmShortID:e,model:s}),r=a({size:50,page:1,_list:!0},r);const o=p(r),i=d(`api/${e}/${s}?${o}`,t),{count:u,total:h,_embedded:f}=yield g(i,n),$=f?f[`${e}:${s}`]:[];return{count:u,total:h,items:$}})}function C({env:n,dmShortID:t,model:e,entryID:s,token:r}){l({env:n,dmShortID:t,model:e,entryID:s});const o=p({_id:s}),i=d(`api/${t}/${e}?${o}`,n);return g(i,{dmShortID:t,token:r})}function R(o){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){l({env:n,dmShortID:t,model:e,value:s}),console.log("create entry",t,e,s);const i=d(`api/${t}/${e}`,n);return console.log("url",i),yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function x(i){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:o}){l({env:n,dmShortID:t,model:e,entryID:s,value:r});const u=d(`api/${t}/${e}?_id=${s}`,n);return yield g(u,{token:o},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function z(o){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){l({env:n,dmShortID:t,model:e,entryID:s});const i=d(`api/${t}/${e}?_id=${s}`,n);return yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function I(o){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){l({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=p({assetID:s}),u=d(`a/${t}/${e}?${i}`,n);return(yield g(u,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function J(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:o={}}=n;l({env:t,dmShortID:e,assetGroup:s}),o=a({size:50,page:1,_list:!0},o);const i=p(o),u=d(`a/${e}/${s}?${i}`,t),{count:h,total:f,_embedded:$}=yield g(u,{dmShortID:e,token:r}),U=$?$["ec:dm-asset"]:[];return{count:h,total:f,items:U}})}function N(i){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:o}){l({env:n,dmShortID:t,assetGroup:e,file:r});const u=d(`a/${t}/${e}`,n),h=new FormData;return h.append("file",r,o),(yield g(u,{token:s},{method:"POST",body:h}))._embedded["ec:dm-asset"]})}const E=Object.freeze(Object.defineProperty({__proto__:null,assetList:J,createAsset:N,createEntry:R,deleteEntry:z,editEntry:x,entryList:B,getAsset:I,getEcAuthKey:q,getEntry:C,getPublicAuthKey:D,loginEc:L,loginPublic:_,logoutEc:K,logoutPublic:S},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createAsset:Y,createEntry:m,editEntry:j,deleteEntry:Z,loginPublic:tt,loginEc:et,logoutEc:nt,logoutPublic:st,getEcAuthKey:b,getPublicAuthKey:k}=E;function rt(n){const{action:t}=n;if(l({action:t}),!E[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(E).join(", ")}`);return E[t](n)}class w{constructor(t){this.config=t}set(t){return new w(a(a({},this.config),t))}handle(t){return c(this,null,function*(){const e=Object.keys(this.config),s=yield this.getBestToken(),[r,o]=Object.entries(t).find(([i,u])=>e.includes(i))||[];if(!o)throw new Error(`you need to first set ${Object.keys(t).join(" | ")}`);return o(y(a({},this.config),{token:s}))})}entries(t){return c(this,null,function*(){const e=yield this.getBestToken();return Q(y(a({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return X(y(a({},this.config),{options:t,token:e}))})}assetList(t){return c(this,null,function*(){return this.assets(t)})}createAsset(){return c(this,arguments,function*({file:t,name:e}={}){const s=yield this.getBestToken();return Y(y(a({},this.config),{file:t,name:e,token:s}))})}get(){return this.handle({assetID:W,entryID:V})}del(){return this.handle({entryID:Z})}createEntry(t){return m(y(a({},this.config),{value:t}))}editEntry(t){return j(y(a({},this.config),{value:t}))}create(t){return this.set({value:t}).handle({model:m})}edit(t){return this.set({value:t}).handle({entryID:j})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return et(a(a({},this.config),t)).then(this.setAuth(b(this.config)))}loginPublic(t){return tt(a(a({},this.config),t)).then(this.setAuth(k(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),st(y(a({},this.config),{token:t})).then(this.unsetAuth(k(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),nt(y(a({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}getPublicToken(){return this.config.token||this.getAuth(k(this.config))}getEcToken(){return this.config.token||this.getAuth(b(this.config))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch(t){return}}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dm(t){return this.dmShortID(t)}entryID(t){return this.set({entryID:t})}entry(t){return this.entryID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}assetID(t){return this.set({assetID:t})}asset(t){return this.assetID(t)}}const ot=n=>new w({env:n});exports.act=rt;exports.apiURL=d;exports.assetList=J;exports.createAsset=N;exports.createEntry=R;exports.deleteEntry=z;exports.editEntry=x;exports.entryList=B;exports.expect=l;exports.fetcher=g;exports.getAsset=I;exports.getEcAuthKey=q;exports.getEntry=C;exports.getPublicAuthKey=D;exports.loginEc=L;exports.loginPublic=_;exports.logoutEc=K;exports.logoutPublic=S;exports.query=p;exports.sdk=ot;
1
+ "use strict";var M=Object.defineProperty,F=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var T=(n,t,e)=>t in n?M(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))H.call(t,e)&&T(n,e,t[e]);if(b)for(var e of b(t))Q.call(t,e)&&T(n,e,t[e]);return n},d=(n,t)=>F(n,G(t));var r=(n,t,e)=>new Promise((s,o)=>{var a=u=>{try{g(e.next(u))}catch(f){o(f)}},i=u=>{try{g(e.throw(u))}catch(f){o(f)}},g=u=>u.done?s(u.value):Promise.resolve(u.value).then(a,i);g((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(s){return r(this,arguments,function*(n,t={},e={}){const{token:o,rawRes:a}=t;o&&(e.headers=d(c({},e.headers||{}),{Authorization:`Bearer ${o}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return a?i:yield i.json()})}const P={production:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(n,t="stage"){const e=P[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(P).join(", ")}`);return e+n}function p(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const m={stage:"https://accounts.cachena.entrecode.de/",production:"https://accounts.cachena.entrecode.de/"};function O(n){return r(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;h({env:t,dmShortID:e,email:s,password:o});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield l(a,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function j(n){return r(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const o=`${m[t]}auth/login?clientID=rest`;return yield l(o,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function _(n){return r(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const o=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield l(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function L(n){return r(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${m[t]}auth/logout?clientID=rest`;return yield l(s,{rawRes:!0,token:e},{method:"POST"})})}function B({dmShortID:n}){return h({dmShortID:n}),n}function S({env:n}){return h({env:n}),n}function K(n){return r(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;h({env:t,dmShortID:e,model:s}),o=c({size:50,page:1,_list:!0},o);const a=p(o),i=y(`api/${e}/${s}?${a}`,t),{count:g,total:u,_embedded:f}=yield l(i,n),E=f?f[`${e}:${s}`]:[];return{count:g,total:u,items:E}})}function q({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const a=p({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return l(i,{dmShortID:t,token:o})}function C(a){return r(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){h({env:n,dmShortID:t,model:e,value:s}),console.log("create entry",t,e,s);const i=y(`api/${t}/${e}`,n);return console.log("url",i),yield l(i,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function R(i){return r(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:o,token:a}){h({env:n,dmShortID:t,model:e,entryID:s,value:o});const g=y(`api/${t}/${e}?_id=${s}`,n);return yield l(g,{token:a},{method:"PUT",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function x(a){return r(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);return yield l(i,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function z(a){return r(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=p({assetID:s}),g=y(`a/${t}/${e}?${i}`,n);return(yield l(g,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function J(n){return r(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:o,options:a={}}=n;h({env:t,dmShortID:e,assetGroup:s}),a=c({size:50,page:1,_list:!0},a);const i=p(a),g=y(`a/${e}/${s}?${i}`,t),{count:u,total:f,_embedded:E}=yield l(g,{dmShortID:e,token:o}),U=E?E["ec:dm-asset"]:[];return{count:u,total:f,items:U}})}function N(i){return r(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:a}){h({env:n,dmShortID:t,assetGroup:e,file:o});const g=y(`a/${t}/${e}`,n),u=new FormData;return u.append("file",o,a),(yield l(g,{token:s},{method:"POST",body:u}))._embedded["ec:dm-asset"]})}const $=Object.freeze(Object.defineProperty({__proto__:null,assetList:J,createAsset:N,createEntry:C,deleteEntry:x,editEntry:R,entryList:K,getAsset:z,getEcAuthKey:S,getEntry:q,getPublicAuthKey:B,loginEc:j,loginPublic:O,logoutEc:L,logoutPublic:_},Symbol.toStringTag,{value:"Module"})),{entryList:V,getEntry:W,getAsset:X,assetList:Y,createAsset:Z,createEntry:v,editEntry:D,deleteEntry:I,loginPublic:tt,loginEc:et,logoutEc:nt,logoutPublic:st,getEcAuthKey:k,getPublicAuthKey:w}=$;function ot(n){const{action:t}=n;if(h({action:t}),!$[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys($).join(", ")}`);return $[t](n)}class A{constructor(t){this.config=t}set(t){return new A(c(c({},this.config),t))}entries(){return r(this,arguments,function*(t={}){const e=yield this.getBestToken();return V(d(c({},this.config),{options:t,token:e}))})}entryList(t){return r(this,null,function*(){return this.entries(t)})}getEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return W(d(c({},this.config),{entryID:t,token:e}))})}assets(t){return r(this,null,function*(){const e=yield this.getBestToken();return Y(d(c({},this.config),{options:t,token:e}))})}assetList(t){return r(this,null,function*(){return this.assets(t)})}createAsset(){return r(this,arguments,function*({file:t,name:e}={}){const s=yield this.getBestToken();return Z(d(c({},this.config),{file:t,name:e,token:s}))})}getAsset(t){return r(this,null,function*(){const e=yield this.getBestToken();return X(d(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return v(d(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return r(this,null,function*(){const s=yield this.getBestToken();return D(d(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return I(d(c({},this.config),{token:e,entryID:t}))})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return et(c(c({},this.config),t)).then(this.setAuth(k(this.config)))}loginPublic(t){return tt(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),st(d(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),nt(d(c({},this.config),{token:t})).then(this.unsetAuth(k(this.config)))}getPublicToken(){return this.config.token||this.getAuth(w(this.config))}getEcToken(){return this.config.token||this.getAuth(k(this.config))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch(t){return}}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}}const rt=n=>new A({env:n});exports.act=ot;exports.apiURL=y;exports.assetList=J;exports.createAsset=N;exports.createEntry=C;exports.deleteEntry=x;exports.editEntry=R;exports.entryList=K;exports.expect=h;exports.fetcher=l;exports.getAsset=z;exports.getEcAuthKey=S;exports.getEntry=q;exports.getPublicAuthKey=B;exports.loginEc=j;exports.loginPublic=O;exports.logoutEc=L;exports.logoutPublic=_;exports.query=p;exports.sdk=rt;
package/dist/index.mjs CHANGED
@@ -1,41 +1,41 @@
1
- var L = Object.defineProperty, K = Object.defineProperties;
2
- var S = Object.getOwnPropertyDescriptors;
3
- var A = Object.getOwnPropertySymbols;
4
- var D = Object.prototype.hasOwnProperty, B = Object.prototype.propertyIsEnumerable;
5
- var T = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, a = (n, t) => {
1
+ var j = Object.defineProperty, _ = Object.defineProperties;
2
+ var L = Object.getOwnPropertyDescriptors;
3
+ var b = Object.getOwnPropertySymbols;
4
+ var B = Object.prototype.hasOwnProperty, K = Object.prototype.propertyIsEnumerable;
5
+ var T = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, c = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
- D.call(t, e) && T(n, e, t[e]);
8
- if (A)
9
- for (var e of A(t))
10
- B.call(t, e) && T(n, e, t[e]);
7
+ B.call(t, e) && T(n, e, t[e]);
8
+ if (b)
9
+ for (var e of b(t))
10
+ K.call(t, e) && T(n, e, t[e]);
11
11
  return n;
12
- }, d = (n, t) => K(n, S(t));
13
- var c = (n, t, e) => new Promise((s, r) => {
14
- var o = (h) => {
12
+ }, l = (n, t) => _(n, L(t));
13
+ var r = (n, t, e) => new Promise((s, o) => {
14
+ var a = (u) => {
15
15
  try {
16
- u(e.next(h));
16
+ h(e.next(u));
17
17
  } catch (f) {
18
- r(f);
18
+ o(f);
19
19
  }
20
- }, i = (h) => {
20
+ }, i = (u) => {
21
21
  try {
22
- u(e.throw(h));
22
+ h(e.throw(u));
23
23
  } catch (f) {
24
- r(f);
24
+ o(f);
25
25
  }
26
- }, u = (h) => h.done ? s(h.value) : Promise.resolve(h.value).then(o, i);
27
- u((e = e.apply(n, t)).next());
26
+ }, h = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, i);
27
+ h((e = e.apply(n, t)).next());
28
28
  });
29
- function g(s) {
30
- return c(this, arguments, function* (n, t = {}, e = {}) {
31
- const { token: r, rawRes: o } = t;
32
- r && (e.headers = d(a({}, e.headers || {}), {
33
- Authorization: `Bearer ${r}`
29
+ function d(s) {
30
+ return r(this, arguments, function* (n, t = {}, e = {}) {
31
+ const { token: o, rawRes: a } = t;
32
+ o && (e.headers = l(c({}, e.headers || {}), {
33
+ Authorization: `Bearer ${o}`
34
34
  }));
35
35
  const i = yield fetch(n, e);
36
36
  if (!i.ok)
37
37
  throw new Error(i.statusText);
38
- return o ? i : yield i.json();
38
+ return a ? i : yield i.json();
39
39
  });
40
40
  }
41
41
  const P = {
@@ -50,30 +50,30 @@ function y(n, t = "stage") {
50
50
  );
51
51
  return e + n;
52
52
  }
53
- function E(n, t = !0) {
53
+ function $(n, t = !0) {
54
54
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
55
55
  }
56
- function l(n) {
56
+ function g(n) {
57
57
  Object.entries(n).forEach(([t, e]) => {
58
58
  if (e === void 0)
59
59
  throw new Error(`expected ${t} to be set!`);
60
60
  });
61
61
  }
62
- const O = {
62
+ const m = {
63
63
  stage: "https://accounts.cachena.entrecode.de/",
64
64
  production: "https://accounts.cachena.entrecode.de/"
65
65
  };
66
- function C(n) {
67
- return c(this, null, function* () {
68
- let { env: t, dmShortID: e, email: s, password: r } = n;
69
- l({ env: t, dmShortID: e, email: s, password: r });
70
- const o = y(`api/${e}/_auth/login?clientID=rest`, t);
71
- return yield g(
72
- o,
66
+ function S(n) {
67
+ return r(this, null, function* () {
68
+ let { env: t, dmShortID: e, email: s, password: o } = n;
69
+ g({ env: t, dmShortID: e, email: s, password: o });
70
+ const a = y(`api/${e}/_auth/login?clientID=rest`, t);
71
+ return yield d(
72
+ a,
73
73
  {},
74
74
  {
75
75
  method: "POST",
76
- body: JSON.stringify({ email: s, password: r }),
76
+ body: JSON.stringify({ email: s, password: o }),
77
77
  headers: {
78
78
  "Content-Type": "application/json"
79
79
  }
@@ -81,13 +81,13 @@ function C(n) {
81
81
  );
82
82
  });
83
83
  }
84
- function q(n) {
85
- return c(this, null, function* () {
84
+ function C(n) {
85
+ return r(this, null, function* () {
86
86
  let { env: t, email: e, password: s } = n;
87
- l({ env: t, email: e, password: s });
88
- const r = `${O[t]}auth/login?clientID=rest`;
89
- return yield g(
90
- r,
87
+ g({ env: t, email: e, password: s });
88
+ const o = `${m[t]}auth/login?clientID=rest`;
89
+ return yield d(
90
+ o,
91
91
  {},
92
92
  {
93
93
  method: "POST",
@@ -99,16 +99,16 @@ function q(n) {
99
99
  );
100
100
  });
101
101
  }
102
- function x(n) {
103
- return c(this, null, function* () {
102
+ function q(n) {
103
+ return r(this, null, function* () {
104
104
  let { dmShortID: t, env: e, token: s } = n;
105
- l({ dmShortID: t, env: e, token: s });
106
- const r = y(
105
+ g({ dmShortID: t, env: e, token: s });
106
+ const o = y(
107
107
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
108
108
  e
109
109
  );
110
- return yield g(
111
- r,
110
+ return yield d(
111
+ o,
112
112
  { dmShortID: t, rawRes: !0 },
113
113
  {
114
114
  method: "POST"
@@ -116,12 +116,12 @@ function x(n) {
116
116
  );
117
117
  });
118
118
  }
119
- function R(n) {
120
- return c(this, null, function* () {
119
+ function x(n) {
120
+ return r(this, null, function* () {
121
121
  let { env: t, token: e } = n;
122
- l({ env: t, token: e });
123
- const s = `${O[t]}auth/logout?clientID=rest`;
124
- return yield g(
122
+ g({ env: t, token: e });
123
+ const s = `${m[t]}auth/logout?clientID=rest`;
124
+ return yield d(
125
125
  s,
126
126
  {
127
127
  rawRes: !0,
@@ -133,32 +133,32 @@ function R(n) {
133
133
  );
134
134
  });
135
135
  }
136
- function z({ dmShortID: n }) {
137
- return l({ dmShortID: n }), n;
136
+ function R({ dmShortID: n }) {
137
+ return g({ dmShortID: n }), n;
138
138
  }
139
- function I({ env: n }) {
140
- return l({ env: n }), n;
139
+ function z({ env: n }) {
140
+ return g({ env: n }), n;
141
141
  }
142
142
  function J(n) {
143
- return c(this, null, function* () {
144
- let { env: t, dmShortID: e, model: s, options: r = {} } = n;
145
- l({ env: t, dmShortID: e, model: s }), r = a({ size: 50, page: 1, _list: !0 }, r);
146
- const o = E(r), i = y(`api/${e}/${s}?${o}`, t), { count: u, total: h, _embedded: f } = yield g(i, n), p = f ? f[`${e}:${s}`] : [];
147
- return { count: u, total: h, items: p };
143
+ return r(this, null, function* () {
144
+ let { env: t, dmShortID: e, model: s, options: o = {} } = n;
145
+ g({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
146
+ const a = $(o), i = y(`api/${e}/${s}?${a}`, t), { count: h, total: u, _embedded: f } = yield d(i, n), p = f ? f[`${e}:${s}`] : [];
147
+ return { count: h, total: u, items: p };
148
148
  });
149
149
  }
150
- function N({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
151
- l({ env: n, dmShortID: t, model: e, entryID: s });
152
- const o = E({ _id: s }), i = y(`api/${t}/${e}?${o}`, n);
153
- return g(i, { dmShortID: t, token: r });
150
+ function N({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
151
+ g({ env: n, dmShortID: t, model: e, entryID: s });
152
+ const a = $({ _id: s }), i = y(`api/${t}/${e}?${a}`, n);
153
+ return d(i, { dmShortID: t, token: o });
154
154
  }
155
- function U(o) {
156
- return c(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
157
- l({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
155
+ function U(a) {
156
+ return r(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
157
+ g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
158
158
  const i = y(`api/${t}/${e}`, n);
159
- return console.log("url", i), yield g(
159
+ return console.log("url", i), yield d(
160
160
  i,
161
- { env: n, dmShortID: t, token: r },
161
+ { env: n, dmShortID: t, token: o },
162
162
  {
163
163
  method: "POST",
164
164
  body: JSON.stringify(s),
@@ -170,22 +170,22 @@ function U(o) {
170
170
  });
171
171
  }
172
172
  function F(i) {
173
- return c(this, arguments, function* ({
173
+ return r(this, arguments, function* ({
174
174
  env: n,
175
175
  dmShortID: t,
176
176
  model: e,
177
177
  entryID: s,
178
- value: r,
179
- token: o
178
+ value: o,
179
+ token: a
180
180
  }) {
181
- l({ env: n, dmShortID: t, model: e, entryID: s, value: r });
182
- const u = y(`api/${t}/${e}?_id=${s}`, n);
183
- return yield g(
184
- u,
185
- { token: o },
181
+ g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
182
+ const h = y(`api/${t}/${e}?_id=${s}`, n);
183
+ return yield d(
184
+ h,
185
+ { token: a },
186
186
  {
187
187
  method: "PUT",
188
- body: JSON.stringify(r),
188
+ body: JSON.stringify(o),
189
189
  headers: {
190
190
  "Content-Type": "application/json"
191
191
  }
@@ -193,13 +193,13 @@ function F(i) {
193
193
  );
194
194
  });
195
195
  }
196
- function G(o) {
197
- return c(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
198
- l({ env: n, dmShortID: t, model: e, entryID: s });
196
+ function G(a) {
197
+ return r(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
198
+ g({ env: n, dmShortID: t, model: e, entryID: s });
199
199
  const i = y(`api/${t}/${e}?_id=${s}`, n);
200
- return yield g(
200
+ return yield d(
201
201
  i,
202
- { token: r, rawRes: !0 },
202
+ { token: o, rawRes: !0 },
203
203
  {
204
204
  method: "DELETE",
205
205
  headers: {
@@ -209,43 +209,43 @@ function G(o) {
209
209
  );
210
210
  });
211
211
  }
212
- function M(o) {
213
- return c(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
214
- l({ env: n, dmShortID: t, assetGroup: e, assetID: s });
215
- const i = E({ assetID: s }), u = y(`a/${t}/${e}?${i}`, n);
216
- return (yield g(u, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
212
+ function M(a) {
213
+ return r(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
214
+ g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
215
+ const i = $({ assetID: s }), h = y(`a/${t}/${e}?${i}`, n);
216
+ return (yield d(h, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
217
217
  });
218
218
  }
219
219
  function H(n) {
220
- return c(this, null, function* () {
221
- let { env: t, dmShortID: e, assetGroup: s, token: r, options: o = {} } = n;
222
- l({ env: t, dmShortID: e, assetGroup: s }), o = a({ size: 50, page: 1, _list: !0 }, o);
223
- const i = E(o), u = y(`a/${e}/${s}?${i}`, t), { count: h, total: f, _embedded: p } = yield g(u, { dmShortID: e, token: r }), _ = p ? p["ec:dm-asset"] : [];
224
- return { count: h, total: f, items: _ };
220
+ return r(this, null, function* () {
221
+ let { env: t, dmShortID: e, assetGroup: s, token: o, options: a = {} } = n;
222
+ g({ env: t, dmShortID: e, assetGroup: s }), a = c({ size: 50, page: 1, _list: !0 }, a);
223
+ const i = $(a), h = y(`a/${e}/${s}?${i}`, t), { count: u, total: f, _embedded: p } = yield d(h, { dmShortID: e, token: o }), O = p ? p["ec:dm-asset"] : [];
224
+ return { count: u, total: f, items: O };
225
225
  });
226
226
  }
227
227
  function Q(i) {
228
- return c(this, arguments, function* ({
228
+ return r(this, arguments, function* ({
229
229
  env: n,
230
230
  dmShortID: t,
231
231
  assetGroup: e,
232
232
  token: s,
233
- file: r,
234
- name: o
233
+ file: o,
234
+ name: a
235
235
  }) {
236
- l({ env: n, dmShortID: t, assetGroup: e, file: r });
237
- const u = y(`a/${t}/${e}`, n), h = new FormData();
238
- return h.append("file", r, o), (yield g(
239
- u,
236
+ g({ env: n, dmShortID: t, assetGroup: e, file: o });
237
+ const h = y(`a/${t}/${e}`, n), u = new FormData();
238
+ return u.append("file", o, a), (yield d(
239
+ h,
240
240
  { token: s },
241
241
  {
242
242
  method: "POST",
243
- body: h
243
+ body: u
244
244
  }
245
245
  ))._embedded["ec:dm-asset"];
246
246
  });
247
247
  }
248
- const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
248
+ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
249
249
  __proto__: null,
250
250
  assetList: H,
251
251
  createAsset: Q,
@@ -254,112 +254,195 @@ const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
254
254
  editEntry: F,
255
255
  entryList: J,
256
256
  getAsset: M,
257
- getEcAuthKey: I,
257
+ getEcAuthKey: z,
258
258
  getEntry: N,
259
- getPublicAuthKey: z,
260
- loginEc: q,
261
- loginPublic: C,
262
- logoutEc: R,
263
- logoutPublic: x
259
+ getPublicAuthKey: R,
260
+ loginEc: C,
261
+ loginPublic: S,
262
+ logoutEc: x,
263
+ logoutPublic: q
264
264
  }, Symbol.toStringTag, { value: "Module" })), {
265
265
  entryList: V,
266
266
  getEntry: W,
267
267
  getAsset: X,
268
268
  assetList: Y,
269
269
  createAsset: Z,
270
- createEntry: m,
271
- editEntry: j,
272
- deleteEntry: v,
270
+ createEntry: D,
271
+ editEntry: v,
272
+ deleteEntry: I,
273
273
  loginPublic: tt,
274
274
  loginEc: et,
275
275
  logoutEc: nt,
276
276
  logoutPublic: st,
277
277
  getEcAuthKey: k,
278
278
  getPublicAuthKey: w
279
- } = $;
280
- function ot(n) {
279
+ } = E;
280
+ function rt(n) {
281
281
  const { action: t } = n;
282
- if (l({ action: t }), !$[t])
282
+ if (g({ action: t }), !E[t])
283
283
  throw new Error(
284
- `"${t}" does not exist! try one of ${Object.keys($).join(
284
+ `"${t}" does not exist! try one of ${Object.keys(E).join(
285
285
  ", "
286
286
  )}`
287
287
  );
288
- return $[t](n);
288
+ return E[t](n);
289
289
  }
290
- class b {
290
+ class A {
291
291
  constructor(t) {
292
292
  this.config = t;
293
293
  }
294
294
  set(t) {
295
- return new b(a(a({}, this.config), t));
296
- }
297
- handle(t) {
298
- return c(this, null, function* () {
299
- const e = Object.keys(this.config), s = yield this.getBestToken(), [r, o] = Object.entries(t).find(([i, u]) => e.includes(i)) || [];
300
- if (!o)
301
- throw new Error(
302
- `you need to first set ${Object.keys(t).join(" | ")}`
303
- );
304
- return o(d(a({}, this.config), { token: s }));
305
- });
295
+ return new A(c(c({}, this.config), t));
306
296
  }
307
- ///
308
- entries(t) {
309
- return c(this, null, function* () {
297
+ /**
298
+ * Loads entry list. Expects `dmShortID` / `model` to be set.
299
+ * If the model is not public, you also need to provide a `token`.
300
+ *
301
+ * @param {object=} options options for entry list request.
302
+ * @returns {{ count: number, total: number, items: object[] }}
303
+ * @example
304
+ * // public model
305
+ * const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
306
+ * @example
307
+ * // non-public model
308
+ * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
309
+ */
310
+ entries() {
311
+ return r(this, arguments, function* (t = {}) {
310
312
  const e = yield this.getBestToken();
311
- return V(d(a({}, this.config), { options: t, token: e }));
313
+ return V(l(c({}, this.config), { options: t, token: e }));
312
314
  });
313
315
  }
314
316
  entryList(t) {
315
- return c(this, null, function* () {
317
+ return r(this, null, function* () {
316
318
  return this.entries(t);
317
319
  });
318
320
  }
321
+ /**
322
+ * Loads a single entry. Expects `dmShortID` / `model` to be set.
323
+ * If the model is not public, you also need to provide a `token`.
324
+ *
325
+ * @param {string} entryID
326
+ * @returns {object}
327
+ * @example
328
+ * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
329
+ */
330
+ getEntry(t) {
331
+ return r(this, null, function* () {
332
+ const e = yield this.getBestToken();
333
+ return W(l(c({}, this.config), { entryID: t, token: e }));
334
+ });
335
+ }
336
+ /**
337
+ * Loads asset list. Expects `dmShortID` / `assetGroup` to be set.
338
+ * If the assetGroup is not public, you also need to provide a `token`.
339
+ *
340
+ * @param {object=} options options for entry list request.
341
+ * @returns {{ count: number, total: number, items: object[] }}
342
+ * @example
343
+ * // public assetGroup
344
+ * const files = await sdk("stage").dm("83cc6374").assetGroup("avatars").assets()
345
+ * @example
346
+ * // non-public assetGroup
347
+ * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
348
+ */
319
349
  assets(t) {
320
- return c(this, null, function* () {
350
+ return r(this, null, function* () {
321
351
  const e = yield this.getBestToken();
322
- return Y(d(a({}, this.config), { options: t, token: e }));
352
+ return Y(l(c({}, this.config), { options: t, token: e }));
323
353
  });
324
354
  }
325
355
  assetList(t) {
326
- return c(this, null, function* () {
356
+ return r(this, null, function* () {
327
357
  return this.assets(t);
328
358
  });
329
359
  }
360
+ /**
361
+ * Uploads an asset. Expects `dmShortID` / `assetGroup` / `file` to be set.
362
+ * If the assetGroup is not public, you also need to provide a `token`.
363
+ *
364
+ * @param {object=} options options for entry list request.
365
+ * @returns {{ count: number, total: number, items: object[] }}
366
+ * @example
367
+ * // browser example
368
+ * document.getElementById("file").addEventListener("input", async (e) => {
369
+ * const [file] = e.target.files;
370
+ * const asset = await ecadmin.assetgroup("test").createAsset({ file })
371
+ * });
372
+ * @example
373
+ * // node example
374
+ * const buf = fs.readFileSync("venndiagram.png");
375
+ * const file = new Blob([buf]);
376
+ * const upload = await sdk("stage")
377
+ * .dm("83cc6374")
378
+ * .assetgroup("test")
379
+ * .createAsset({ file, name: "venndiagram.png" });
380
+ */
330
381
  createAsset() {
331
- return c(this, arguments, function* ({ file: t, name: e } = {}) {
382
+ return r(this, arguments, function* ({ file: t, name: e } = {}) {
332
383
  const s = yield this.getBestToken();
333
- return Z(d(a({}, this.config), { file: t, name: e, token: s }));
384
+ return Z(l(c({}, this.config), { file: t, name: e, token: s }));
334
385
  });
335
386
  }
336
- get() {
337
- return this.handle({
338
- assetID: X,
339
- entryID: W
340
- });
341
- }
342
- del() {
343
- return this.handle({
344
- entryID: v
387
+ /**
388
+ * Loads a single asset. Expects `dmShortID` / `assetGroup` to be set.
389
+ * If the asset group is not public, you also need to provide a `token`.
390
+ *
391
+ * @param {string} assetID
392
+ * @returns {object}
393
+ * @example
394
+ * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
395
+ */
396
+ getAsset(t) {
397
+ return r(this, null, function* () {
398
+ const e = yield this.getBestToken();
399
+ return X(l(c({}, this.config), { assetID: t, token: e }));
345
400
  });
346
401
  }
402
+ /**
403
+ * Creates a new entry. Expects `dmShortID` / `model` to be set.
404
+ * If model POST is not public, you also need to provide a `token`.
405
+ *
406
+ * @param {object} value values to set.
407
+ * @returns {object}
408
+ * @example
409
+ * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
410
+ */
347
411
  createEntry(t) {
348
- return m(d(a({}, this.config), { value: t }));
349
- }
350
- editEntry(t) {
351
- return j(d(a({}, this.config), { value: t }));
412
+ return r(this, null, function* () {
413
+ const e = yield this.getBestToken();
414
+ return D(l(c({}, this.config), { token: e, value: t }));
415
+ });
352
416
  }
353
- create(t) {
354
- return this.set({ value: t }).handle({
355
- //assetID: createAsset,
356
- model: m
417
+ /**
418
+ * Edits an entry. Expects `dmShortID` / `model` to be set.
419
+ * If model PUT is not public, you also need to provide a `token`.
420
+ *
421
+ * @param {string} entryID id of entry to edit
422
+ * @param {object} value values to set. undefined fields are ignored
423
+ * @returns {object}
424
+ * @example
425
+ * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
426
+ */
427
+ editEntry(t, e) {
428
+ return r(this, null, function* () {
429
+ const s = yield this.getBestToken();
430
+ return v(l(c({}, this.config), { entryID: t, token: s, value: e }));
357
431
  });
358
432
  }
359
- edit(t) {
360
- return this.set({ value: t }).handle({
361
- //assetID: createAsset,
362
- entryID: j
433
+ /**
434
+ * Deletes an entry. Expects `dmShortID` / `model` to be set.
435
+ * If model DELETE is not public, you also need to provide a `token`.
436
+ *
437
+ * @param {string} entryID id of entry to delete
438
+ * @returns {object}
439
+ * @example
440
+ * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
441
+ */
442
+ deleteEntry(t) {
443
+ return r(this, null, function* () {
444
+ const e = yield this.getBestToken();
445
+ return I(l(c({}, this.config), { token: e, entryID: t }));
363
446
  });
364
447
  }
365
448
  // TODO: rename authAdapter -> storageAdapter
@@ -389,24 +472,24 @@ class b {
389
472
  return e(t);
390
473
  }
391
474
  loginEc(t) {
392
- return et(a(a({}, this.config), t)).then(
475
+ return et(c(c({}, this.config), t)).then(
393
476
  this.setAuth(k(this.config))
394
477
  );
395
478
  }
396
479
  loginPublic(t) {
397
- return tt(a(a({}, this.config), t)).then(
480
+ return tt(c(c({}, this.config), t)).then(
398
481
  this.setAuth(w(this.config))
399
482
  );
400
483
  }
401
484
  logoutPublic() {
402
485
  const t = this.getPublicToken();
403
- return console.log("token", t), st(d(a({}, this.config), { token: t })).then(
486
+ return console.log("token", t), st(l(c({}, this.config), { token: t })).then(
404
487
  this.unsetAuth(w(this.config))
405
488
  );
406
489
  }
407
490
  logoutEc() {
408
491
  const t = this.getEcToken();
409
- return console.log("token", t), nt(d(a({}, this.config), { token: t })).then(
492
+ return console.log("token", t), nt(l(c({}, this.config), { token: t })).then(
410
493
  this.unsetAuth(k(this.config))
411
494
  );
412
495
  }
@@ -464,22 +547,6 @@ class b {
464
547
  dm(t) {
465
548
  return this.dmShortID(t);
466
549
  }
467
- /**
468
- * Sets the id of the entry to use
469
- * @param {string} entryID
470
- * @returns Sdk
471
- */
472
- entryID(t) {
473
- return this.set({ entryID: t });
474
- }
475
- /**
476
- * Sets the id of the entry to use. Alias for `entryID`
477
- * @param {string} entryID
478
- * @returns Sdk
479
- */
480
- entry(t) {
481
- return this.entryID(t);
482
- }
483
550
  /**
484
551
  * Sets the name of the asset group to use.
485
552
  * @param {string} assetGroup name of the asset group
@@ -496,26 +563,10 @@ class b {
496
563
  assetgroup(t) {
497
564
  return this.assetGroup(t);
498
565
  }
499
- /**
500
- * Sets the id of the asset to use
501
- * @param {string} assetID
502
- * @returns Sdk
503
- */
504
- assetID(t) {
505
- return this.set({ assetID: t });
506
- }
507
- /**
508
- * Sets the id of the asset to use. Alias for `assetID`
509
- * @param {string} assetID
510
- * @returns Sdk
511
- */
512
- asset(t) {
513
- return this.assetID(t);
514
- }
515
566
  }
516
- const it = (n) => new b({ env: n });
567
+ const it = (n) => new A({ env: n });
517
568
  export {
518
- ot as act,
569
+ rt as act,
519
570
  y as apiURL,
520
571
  H as assetList,
521
572
  Q as createAsset,
@@ -523,16 +574,16 @@ export {
523
574
  G as deleteEntry,
524
575
  F as editEntry,
525
576
  J as entryList,
526
- l as expect,
527
- g as fetcher,
577
+ g as expect,
578
+ d as fetcher,
528
579
  M as getAsset,
529
- I as getEcAuthKey,
580
+ z as getEcAuthKey,
530
581
  N as getEntry,
531
- z as getPublicAuthKey,
532
- q as loginEc,
533
- C as loginPublic,
534
- R as logoutEc,
535
- x as logoutPublic,
536
- E as query,
582
+ R as getPublicAuthKey,
583
+ C as loginEc,
584
+ S as loginPublic,
585
+ x as logoutEc,
586
+ q as logoutPublic,
587
+ $ as query,
537
588
  it as sdk
538
589
  };
@@ -5,37 +5,129 @@ declare class Sdk {
5
5
  constructor(config: any);
6
6
  config: any;
7
7
  set(obj: any): Sdk;
8
- handle(handlers: any): Promise<any>;
9
- entries(options: any): Promise<{
10
- count: any;
11
- total: any;
12
- items: any;
13
- }>;
8
+ /**
9
+ * Loads entry list. Expects `dmShortID` / `model` to be set.
10
+ * If the model is not public, you also need to provide a `token`.
11
+ *
12
+ * @param {object=} options options for entry list request.
13
+ * @returns {{ count: number, total: number, items: object[] }}
14
+ * @example
15
+ * // public model
16
+ * const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
17
+ * @example
18
+ * // non-public model
19
+ * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
20
+ */
21
+ entries(options?: object | undefined): {
22
+ count: number;
23
+ total: number;
24
+ items: object[];
25
+ };
14
26
  entryList(options: any): Promise<{
15
- count: any;
16
- total: any;
17
- items: any;
18
- }>;
19
- assets(options: any): Promise<{
20
- count: any;
21
- total: any;
22
- items: any;
27
+ count: number;
28
+ total: number;
29
+ items: object[];
23
30
  }>;
31
+ /**
32
+ * Loads a single entry. Expects `dmShortID` / `model` to be set.
33
+ * If the model is not public, you also need to provide a `token`.
34
+ *
35
+ * @param {string} entryID
36
+ * @returns {object}
37
+ * @example
38
+ * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
39
+ */
40
+ getEntry(entryID: string): object;
41
+ /**
42
+ * Loads asset list. Expects `dmShortID` / `assetGroup` to be set.
43
+ * If the assetGroup is not public, you also need to provide a `token`.
44
+ *
45
+ * @param {object=} options options for entry list request.
46
+ * @returns {{ count: number, total: number, items: object[] }}
47
+ * @example
48
+ * // public assetGroup
49
+ * const files = await sdk("stage").dm("83cc6374").assetGroup("avatars").assets()
50
+ * @example
51
+ * // non-public assetGroup
52
+ * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
53
+ */
54
+ assets(options?: object | undefined): {
55
+ count: number;
56
+ total: number;
57
+ items: object[];
58
+ };
24
59
  assetList(options: any): Promise<{
25
- count: any;
26
- total: any;
27
- items: any;
60
+ count: number;
61
+ total: number;
62
+ items: object[];
28
63
  }>;
29
- createAsset({ file, name }?: {
30
- file: any;
31
- name: any;
32
- }): Promise<any>;
33
- get(): Promise<any>;
34
- del(): Promise<any>;
35
- createEntry(value: any): Promise<any>;
36
- editEntry(value: any): Promise<any>;
37
- create(value: any): Promise<any>;
38
- edit(value: any): Promise<any>;
64
+ /**
65
+ * Uploads an asset. Expects `dmShortID` / `assetGroup` / `file` to be set.
66
+ * If the assetGroup is not public, you also need to provide a `token`.
67
+ *
68
+ * @param {object=} options options for entry list request.
69
+ * @returns {{ count: number, total: number, items: object[] }}
70
+ * @example
71
+ * // browser example
72
+ * document.getElementById("file").addEventListener("input", async (e) => {
73
+ * const [file] = e.target.files;
74
+ * const asset = await ecadmin.assetgroup("test").createAsset({ file })
75
+ * });
76
+ * @example
77
+ * // node example
78
+ * const buf = fs.readFileSync("venndiagram.png");
79
+ * const file = new Blob([buf]);
80
+ * const upload = await sdk("stage")
81
+ * .dm("83cc6374")
82
+ * .assetgroup("test")
83
+ * .createAsset({ file, name: "venndiagram.png" });
84
+ */
85
+ createAsset({ file, name }?: object | undefined): {
86
+ count: number;
87
+ total: number;
88
+ items: object[];
89
+ };
90
+ /**
91
+ * Loads a single asset. Expects `dmShortID` / `assetGroup` to be set.
92
+ * If the asset group is not public, you also need to provide a `token`.
93
+ *
94
+ * @param {string} assetID
95
+ * @returns {object}
96
+ * @example
97
+ * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
98
+ */
99
+ getAsset(assetID: string): object;
100
+ /**
101
+ * Creates a new entry. Expects `dmShortID` / `model` to be set.
102
+ * If model POST is not public, you also need to provide a `token`.
103
+ *
104
+ * @param {object} value values to set.
105
+ * @returns {object}
106
+ * @example
107
+ * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
108
+ */
109
+ createEntry(value: object): object;
110
+ /**
111
+ * Edits an entry. Expects `dmShortID` / `model` to be set.
112
+ * If model PUT is not public, you also need to provide a `token`.
113
+ *
114
+ * @param {string} entryID id of entry to edit
115
+ * @param {object} value values to set. undefined fields are ignored
116
+ * @returns {object}
117
+ * @example
118
+ * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
119
+ */
120
+ editEntry(entryID: string, value: object): object;
121
+ /**
122
+ * Deletes an entry. Expects `dmShortID` / `model` to be set.
123
+ * If model DELETE is not public, you also need to provide a `token`.
124
+ *
125
+ * @param {string} entryID id of entry to delete
126
+ * @returns {object}
127
+ * @example
128
+ * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
129
+ */
130
+ deleteEntry(entryID: string): object;
39
131
  authAdapter(authAdapter: any): Sdk;
40
132
  setAuth(key: any): (auth: any) => any;
41
133
  unsetAuth(key: any): (auth: any) => any;
@@ -74,18 +166,6 @@ declare class Sdk {
74
166
  * @returns Sdk
75
167
  */
76
168
  dm(dmShortID: string): Sdk;
77
- /**
78
- * Sets the id of the entry to use
79
- * @param {string} entryID
80
- * @returns Sdk
81
- */
82
- entryID(entryID: string): Sdk;
83
- /**
84
- * Sets the id of the entry to use. Alias for `entryID`
85
- * @param {string} entryID
86
- * @returns Sdk
87
- */
88
- entry(entryID: string): Sdk;
89
169
  /**
90
170
  * Sets the name of the asset group to use.
91
171
  * @param {string} assetGroup name of the asset group
@@ -98,17 +178,5 @@ declare class Sdk {
98
178
  * @returns Sdk
99
179
  */
100
180
  assetgroup(assetGroup: string): Sdk;
101
- /**
102
- * Sets the id of the asset to use
103
- * @param {string} assetID
104
- * @returns Sdk
105
- */
106
- assetID(assetID: string): Sdk;
107
- /**
108
- * Sets the id of the asset to use. Alias for `assetID`
109
- * @param {string} assetID
110
- * @returns Sdk
111
- */
112
- asset(assetID: string): Sdk;
113
181
  }
114
182
  //# sourceMappingURL=api.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAqBA,sCAWC;;AAyPM,mCAAqC;AAvP5C;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED,oCAWC;IAGD;;;;OAGC;IACD;;;;OAEC;IAED;;;;OAGC;IACD;;;;OAEC;IAED;;;qBAGC;IAED,oBAKC;IAED,oBAIC;IAED,sCAEC;IACD,oCAEC;IAED,iCAKC;IAED,+BAKC;IAID,mCAGC;IAED,sCASC;IACD,wCAUC;IACD,uBAMC;IAED,mCAIC;IACD,uCAKC;IAED,6BAMC;IAED,yBAMC;IAED,sBAEC;IACD,kBAEC;IACD,0BAEC;IACD,sBAEC;IACD,uBAEC;IACD,oBAMC;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,cAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,iBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,eAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,iBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,eAHW,MAAM,OAKhB;CACF"}
1
+ {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAqBA,sCAWC;;AAyRM,mCAAqC;AAvR5C;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAW7D;IACD;eAZsB,MAAM;eAAS,MAAM;eAAS,MAAM,EAAE;OAc3D;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,MAAM,CAOlB;IACD;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,eACJ;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAW7D;IACD;eAZsB,MAAM;eAAS,MAAM;eAAS,MAAM,EAAE;OAc3D;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,6BAjBW,MAAM,eACJ;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAmB7D;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,MAAM,CAOlB;IAED;;;;;;;;OAQG;IACH,mBALW,MAAM,GACJ,MAAM,CAOlB;IACD;;;;;;;;;OASG;IACH,mBANW,MAAM,SACN,MAAM,GACJ,MAAM,CAOlB;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,MAAM,CAOlB;IAID,mCAGC;IAED,sCASC;IACD,wCAUC;IACD,uBAMC;IAED,mCAIC;IACD,uCAKC;IAED,6BAMC;IAED,yBAMC;IAED,sBAEC;IACD,kBAEC;IACD,0BAEC;IACD,sBAEC;IACD,uBAEC;IACD,oBAMC;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,cAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {