ec.fdk 0.2.23 → 0.2.25

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,3 +1,3 @@
1
- "use strict";var F=Object.defineProperty,G=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var m=(n,t,e)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t)=>{for(var e in t||(t={}))Q.call(t,e)&&m(n,e,t[e]);if(T)for(var e of T(t))V.call(t,e)&&m(n,e,t[e]);return n},y=(n,t)=>G(n,H(t));var i=(n,t,e)=>new Promise((s,o)=>{var u=c=>{try{h(e.next(c))}catch(d){o(d)}},r=c=>{try{h(e.throw(c))}catch(d){o(d)}},h=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,r);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return i(this,arguments,function*(n,t={},e={}){var h;const{token:o,rawRes:u}=t;o&&(e.headers=y(a({},e.headers||{}),{Authorization:`Bearer ${o}`}));const r=yield fetch(n,e);if(!r.ok){if((h=r.headers.get("content-type"))!=null&&h.includes("application/json")){const c=yield r.json(),d=`${c.title}
2
- ${c.detail}
3
- ${c.verbose}`;throw new Error(d)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return u?r:yield r.json()})}const P={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(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 E(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 j={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function L(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;l({env:t,dmShortID:e,email:s,password:o});const u=f(`api/${e}/_auth/login?clientID=rest`,t);return yield g(u,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function O(n){return i(this,null,function*(){let{env:t,email:e,password:s}=n;l({env:t,email:e,password:s});const o=`${j[t]}auth/login?clientID=rest`;return yield g(o,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function _(n){return i(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;l({dmShortID:t,env:e,token:s});const o=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function B(n){return i(this,null,function*(){let{env:t,token:e}=n;l({env:t,token:e});const s=`${j[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function S({dmShortID:n}){return l({dmShortID:n}),n}function K({env:n}){return l({env:n}),n}function q(n){return i(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;l({env:t,dmShortID:e,model:s}),o=a({size:50,page:1,_list:!0},o);const u=E(o),r=f(`api/${e}/${s}?${u}`,t),{count:h,total:c,_embedded:d}=yield g(r,n);let $=d?d[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:h,total:c,items:$}})}function R({env:n,dmShortID:t,model:e,entryID:s,token:o}){l({env:n,dmShortID:t,model:e,entryID:s});const u=E({_id:s}),r=f(`api/${t}/${e}?${u}`,n);return g(r,{dmShortID:t,token:o})}function x(u){return i(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){l({env:n,dmShortID:t,model:e,value:s}),console.log("create entry",t,e,s);const r=f(`api/${t}/${e}`,n);return console.log("url",r),yield g(r,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function C(r){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:o,token:u}){l({env:n,dmShortID:t,model:e,entryID:s,value:o});const h=f(`api/${t}/${e}?_id=${s}`,n);return yield g(h,{token:u},{method:"PUT",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function z(u){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){l({env:n,dmShortID:t,model:e,entryID:s});const r=f(`api/${t}/${e}?_id=${s}`,n);yield g(r,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function J(u){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){l({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=E({assetID:s}),h=f(`a/${t}/${e}?${r}`,n);return(yield g(h,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function N(n){return i(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:o,options:u={}}=n;l({env:t,dmShortID:e,assetGroup:s}),u=a({size:50,page:1,_list:!0},u);const r=E(u),h=f(`a/${e}/${s}?${r}`,t),{count:c,total:d,_embedded:$}=yield g(h,{dmShortID:e,token:o});let p=$?$["ec:dm-asset"]:[];return p=Array.isArray(p)?p:[p],{count:c,total:d,items:p}})}function U(h){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:u,options:r}){l({env:n,dmShortID:t,assetGroup:e,file:o});const c=f(`a/${t}/${e}`,n),d=new FormData;return d.append("file",o,u),r&&Object.keys(r).forEach(p=>{d.append(p,r[p])}),(yield g(c,{token:s},{method:"POST",body:d}))._embedded["ec:dm-asset"]})}function v(u){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){l({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=f(`a/${t}/${e}/${s}`,n);yield g(r,{token:o,rawRes:!0},{method:"DELETE"})})}function M(n){return i(this,null,function*(){let{env:t,options:e={}}=n;l({env:t}),e=a({size:25,page:1,_list:!0},e);const s=E(e),o=f(`?${s}`,t),{count:u,total:r,_embedded:h}=yield g(o,n);let c=h?h["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:u,total:r,items:c}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:U,createEntry:x,deleteAsset:v,deleteEntry:z,dmList:M,editEntry:C,entryList:q,getAsset:J,getEcAuthKey:K,getEntry:R,getPublicAuthKey:S,loginEc:O,loginPublic:L,logoutEc:B,logoutPublic:_},Symbol.toStringTag,{value:"Module"})),{entryList:W,getEntry:X,getAsset:Y,assetList:Z,createAsset:D,deleteAsset:I,createEntry:tt,editEntry:et,deleteEntry:nt,loginPublic:st,loginEc:ot,logoutEc:rt,logoutPublic:it,getEcAuthKey:w,getPublicAuthKey:b,dmList:ct}=k;function at(n){const{action:t}=n;if(l({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class A{constructor(t){this.config=t}set(t){return new A(a(a({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return W(y(a({},this.config),{options:t,token:e}))})}entryList(t){return i(this,null,function*(){return this.entries(t)})}getEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return X(y(a({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return Z(y(a({},this.config),{options:t,token:e}))})}assetList(t){return i(this,null,function*(){return this.assets(t)})}createAsset(){return i(this,arguments,function*({file:t,name:e,options:s}={}){const o=yield this.getBestToken();return D(y(a({},this.config),{file:t,name:e,options:s,token:o}))})}deleteAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(y(a({},this.config),{token:e,assetID:t}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return Y(y(a({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return tt(y(a({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return et(y(a({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return nt(y(a({},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 ot(a(a({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return st(a(a({},this.config),t)).then(this.setAuth(b(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),it(y(a({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),rt(y(a({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(b(this.config))}getEcToken(){return this.config.token||this.getAuth(w(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)}dmList(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return ct(y(a({},this.config),{options:t,token:e}))})}}const ut=n=>new A({env:n});exports.Sdk=A;exports.act=at;exports.apiURL=f;exports.assetList=N;exports.createAsset=U;exports.createEntry=x;exports.deleteAsset=v;exports.deleteEntry=z;exports.dmList=M;exports.editEntry=C;exports.entryList=q;exports.expect=l;exports.fetcher=g;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=R;exports.getPublicAuthKey=S;exports.loginEc=O;exports.loginPublic=L;exports.logoutEc=B;exports.logoutPublic=_;exports.query=E;exports.sdk=ut;
1
+ "use strict";var G=Object.defineProperty,H=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var T=(n,t,e)=>t in n?G(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))V.call(t,e)&&T(n,e,t[e]);if(b)for(var e of b(t))W.call(t,e)&&T(n,e,t[e]);return n},y=(n,t)=>H(n,Q(t));var o=(n,t,e)=>new Promise((s,r)=>{var u=a=>{try{l(e.next(a))}catch(g){r(g)}},i=a=>{try{l(e.throw(a))}catch(g){r(g)}},l=a=>a.done?s(a.value):Promise.resolve(a.value).then(u,i);l((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(s){return o(this,arguments,function*(n,t={},e={}){var l;const{token:r,rawRes:u}=t;r&&(e.headers=y(c({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((l=i.headers.get("content-type"))!=null&&l.includes("application/json")){const a=yield i.json(),g=`${a.title}
2
+ ${a.detail}
3
+ ${a.verbose}`;throw new Error(g)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return u?i:yield i.json()})}const P={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(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 A(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 L={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function j(n){return o(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const u=f(`api/${e}/_auth/login?clientID=rest`,t);return yield d(u,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function O(n){return o(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${L[t]}auth/login?clientID=rest`;return yield d(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function _(n){return o(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield d(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function B(n){return o(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${L[t]}auth/logout?clientID=rest`;return yield d(s,{rawRes:!0,token:e},{method:"POST"})})}function S({dmShortID:n}){return h({dmShortID:n}),n}function D({env:n}){return h({env:n}),n}function q(n){return o(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=f(`api/${e}`,t);return d(s,n)})}function K(n){return o(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=c({size:50,page:1,_list:!0},r);const u=A(r),i=f(`api/${e}/${s}?${u}`,t),{count:l,total:a,_embedded:g}=yield d(i,n);let p=g?g[`${e}:${s}`]:[];return p=Array.isArray(p)?p:[p],{count:l,total:a,items:p}})}function R({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=A({_id:s}),i=f(`api/${t}/${e}?${u}`,n);return d(i,{dmShortID:t,token:r})}function v(u){return o(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=f(`api/${t}/${e}`,n);return yield d(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function x(i){return o(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:u}){h({env:n,dmShortID:t,model:e,entryID:s,value:r});const l=f(`api/${t}/${e}?_id=${s}`,n);return yield d(l,{token:u},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function z(u){return o(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const i=f(`api/${t}/${e}?_id=${s}`,n);yield d(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function C(u){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=A({assetID:s}),l=f(`a/${t}/${e}?${i}`,n);return(yield d(l,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function J(n){return o(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:u={}}=n;h({env:t,dmShortID:e,assetGroup:s}),u=c({size:50,page:1,_list:!0},u);const i=A(u),l=f(`a/${e}/${s}?${i}`,t),{count:a,total:g,_embedded:p}=yield d(l,{dmShortID:e,token:r});let $=p?p["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:a,total:g,items:$}})}function M(l){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:u,options:i}){h({env:n,dmShortID:t,assetGroup:e,file:r});const a=f(`a/${t}/${e}`,n),g=new FormData;return g.append("file",r,u),i&&Object.keys(i).forEach($=>{g.append($,i[$])}),(yield d(a,{token:s},{method:"POST",body:g}))._embedded["ec:dm-asset"]})}function N(u){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=f(`a/${t}/${e}/${s}`,n);yield d(i,{token:r,rawRes:!0},{method:"DELETE"})})}function U(n){return o(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=f(`?dataManagerID=${e}`,t);return d(r,{token:s})})}function F(n){return o(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=c({size:25,page:1,_list:!0},e);const s=A(e),r=f(`?${s}`,t),{count:u,total:i,_embedded:l}=yield d(r,n);let a=l?l["ec:datamanager"]:[];return a=Array.isArray(a)?a:[a],{count:u,total:i,items:a}})}function I(n){return o(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=c({size:25,dataManagerID:e,page:1,_list:!0},s);const r=A(s),u=f(`model?${r}`,t),{count:i,total:l,_embedded:a}=yield d(u,n);let g=a?a["ec:model"]:[];return g=Array.isArray(g)?g:[g],{count:i,total:l,items:g}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:J,createAsset:M,createEntry:v,deleteAsset:N,deleteEntry:z,dmList:F,editEntry:x,entryList:K,getAsset:C,getDatamanager:U,getEcAuthKey:D,getEntry:R,getPublicAuthKey:S,loginEc:O,loginPublic:j,logoutEc:B,logoutPublic:_,modelList:I,publicApi:q},Symbol.toStringTag,{value:"Module"})),{entryList:X,getEntry:Y,getAsset:Z,assetList:tt,createAsset:et,deleteAsset:nt,createEntry:st,editEntry:rt,deleteEntry:ot,loginPublic:it,loginEc:at,logoutEc:ct,logoutPublic:ut,getEcAuthKey:w,getPublicAuthKey:m,dmList:ht,modelList:lt,publicApi:gt,getDatamanager:dt}=k;function yt(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class E{constructor(t){this.config=t}set(t){return new E(c(c({},this.config),t))}entries(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return X(y(c({},this.config),{options:t,token:e}))})}entryList(t){return o(this,null,function*(){return this.entries(t)})}getEntry(t){return o(this,null,function*(){const e=yield this.getBestToken();return Y(y(c({},this.config),{entryID:t,token:e}))})}assets(t){return o(this,null,function*(){const e=yield this.getBestToken();return tt(y(c({},this.config),{options:t,token:e}))})}assetList(t){return o(this,null,function*(){return this.assets(t)})}createAsset(){return o(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return et(y(c({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return o(this,null,function*(){const e=yield this.getBestToken();return nt(y(c({},this.config),{token:e,assetID:t}))})}getAsset(t){return o(this,null,function*(){const e=yield this.getBestToken();return Z(y(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return o(this,null,function*(){const e=yield this.getBestToken();return st(y(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return o(this,null,function*(){const s=yield this.getBestToken();return rt(y(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return o(this,null,function*(){const e=yield this.getBestToken();return ot(y(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 at(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return it(c(c({},this.config),t)).then(this.setAuth(m(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),ut(y(c({},this.config),{token:t})).then(this.unsetAuth(m(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),ct(y(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(m(this.config))}getEcToken(){return this.config.token||this.getAuth(w(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})}dmID(t){return this.set({dmID:t})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}publicApi(){return gt(this.config)}getDatamanager(t){return o(this,null,function*(){const e=yield this.getBestToken();return dt(y(c({},this.config),{dmID:t,token:e}))})}dmList(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return ht(y(c({},this.config),{options:t,token:e}))})}modelList(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return lt(y(c({},this.config),{options:t,token:e}))})}}const ft=n=>new E({env:n});exports.Sdk=E;exports.act=yt;exports.apiURL=f;exports.assetList=J;exports.createAsset=M;exports.createEntry=v;exports.deleteAsset=N;exports.deleteEntry=z;exports.dmList=F;exports.editEntry=x;exports.entryList=K;exports.expect=h;exports.fetcher=d;exports.getAsset=C;exports.getDatamanager=U;exports.getEcAuthKey=D;exports.getEntry=R;exports.getPublicAuthKey=S;exports.loginEc=O;exports.loginPublic=j;exports.logoutEc=B;exports.logoutPublic=_;exports.modelList=I;exports.publicApi=q;exports.query=A;exports.sdk=ft;
package/dist/index.mjs CHANGED
@@ -1,49 +1,49 @@
1
- var L = Object.defineProperty, O = Object.defineProperties;
2
- var _ = Object.getOwnPropertyDescriptors;
3
- var T = Object.getOwnPropertySymbols;
4
- var B = Object.prototype.hasOwnProperty, K = Object.prototype.propertyIsEnumerable;
5
- var m = (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 O = Object.getOwnPropertyDescriptors;
3
+ var b = Object.getOwnPropertySymbols;
4
+ var B = Object.prototype.hasOwnProperty, D = 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
- B.call(t, e) && m(n, e, t[e]);
8
- if (T)
9
- for (var e of T(t))
10
- K.call(t, e) && m(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
+ D.call(t, e) && T(n, e, t[e]);
11
11
  return n;
12
- }, d = (n, t) => O(n, _(t));
13
- var i = (n, t, e) => new Promise((s, o) => {
14
- var u = (c) => {
12
+ }, y = (n, t) => _(n, O(t));
13
+ var r = (n, t, e) => new Promise((s, o) => {
14
+ var u = (a) => {
15
15
  try {
16
- h(e.next(c));
16
+ h(e.next(a));
17
17
  } catch (l) {
18
18
  o(l);
19
19
  }
20
- }, r = (c) => {
20
+ }, i = (a) => {
21
21
  try {
22
- h(e.throw(c));
22
+ h(e.throw(a));
23
23
  } catch (l) {
24
24
  o(l);
25
25
  }
26
- }, h = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(u, r);
26
+ }, h = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(u, i);
27
27
  h((e = e.apply(n, t)).next());
28
28
  });
29
- function y(s) {
30
- return i(this, arguments, function* (n, t = {}, e = {}) {
29
+ function d(s) {
30
+ return r(this, arguments, function* (n, t = {}, e = {}) {
31
31
  var h;
32
32
  const { token: o, rawRes: u } = t;
33
- o && (e.headers = d(a({}, e.headers || {}), {
33
+ o && (e.headers = y(c({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${o}`
35
35
  }));
36
- const r = yield fetch(n, e);
37
- if (!r.ok) {
38
- if ((h = r.headers.get("content-type")) != null && h.includes("application/json")) {
39
- const c = yield r.json(), l = `${c.title}
40
- ${c.detail}
41
- ${c.verbose}`;
36
+ const i = yield fetch(n, e);
37
+ if (!i.ok) {
38
+ if ((h = i.headers.get("content-type")) != null && h.includes("application/json")) {
39
+ const a = yield i.json(), l = `${a.title}
40
+ ${a.detail}
41
+ ${a.verbose}`;
42
42
  throw new Error(l);
43
43
  }
44
- throw new Error(`unexpected fetch error: ${r.statusText}`);
44
+ throw new Error(`unexpected fetch error: ${i.statusText}`);
45
45
  }
46
- return u ? r : yield r.json();
46
+ return u ? i : yield i.json();
47
47
  });
48
48
  }
49
49
  const P = {
@@ -58,7 +58,7 @@ function f(n, t = "stage") {
58
58
  );
59
59
  return e + n;
60
60
  }
61
- function E(n, t = !0) {
61
+ function A(n, t = !0) {
62
62
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
63
63
  }
64
64
  function g(n) {
@@ -67,16 +67,16 @@ function g(n) {
67
67
  throw new Error(`expected ${t} to be set!`);
68
68
  });
69
69
  }
70
- const j = {
70
+ const L = {
71
71
  stage: "https://accounts.cachena.entrecode.de/",
72
72
  live: "https://accounts.entrecode.de/"
73
73
  };
74
74
  function S(n) {
75
- return i(this, null, function* () {
75
+ return r(this, null, function* () {
76
76
  let { env: t, dmShortID: e, email: s, password: o } = n;
77
77
  g({ env: t, dmShortID: e, email: s, password: o });
78
78
  const u = f(`api/${e}/_auth/login?clientID=rest`, t);
79
- return yield y(
79
+ return yield d(
80
80
  u,
81
81
  {},
82
82
  {
@@ -89,12 +89,12 @@ function S(n) {
89
89
  );
90
90
  });
91
91
  }
92
- function q(n) {
93
- return i(this, null, function* () {
92
+ function K(n) {
93
+ return r(this, null, function* () {
94
94
  let { env: t, email: e, password: s } = n;
95
95
  g({ env: t, email: e, password: s });
96
- const o = `${j[t]}auth/login?clientID=rest`;
97
- return yield y(
96
+ const o = `${L[t]}auth/login?clientID=rest`;
97
+ return yield d(
98
98
  o,
99
99
  {},
100
100
  {
@@ -107,15 +107,15 @@ function q(n) {
107
107
  );
108
108
  });
109
109
  }
110
- function x(n) {
111
- return i(this, null, function* () {
110
+ function q(n) {
111
+ return r(this, null, function* () {
112
112
  let { dmShortID: t, env: e, token: s } = n;
113
113
  g({ dmShortID: t, env: e, token: s });
114
114
  const o = f(
115
115
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
116
116
  e
117
117
  );
118
- return yield y(
118
+ return yield d(
119
119
  o,
120
120
  { dmShortID: t, rawRes: !0 },
121
121
  {
@@ -124,12 +124,12 @@ function x(n) {
124
124
  );
125
125
  });
126
126
  }
127
- function C(n) {
128
- return i(this, null, function* () {
127
+ function x(n) {
128
+ return r(this, null, function* () {
129
129
  let { env: t, token: e } = n;
130
130
  g({ env: t, token: e });
131
- const s = `${j[t]}auth/logout?clientID=rest`;
132
- return yield y(
131
+ const s = `${L[t]}auth/logout?clientID=rest`;
132
+ return yield d(
133
133
  s,
134
134
  {
135
135
  rawRes: !0,
@@ -141,32 +141,40 @@ function C(n) {
141
141
  );
142
142
  });
143
143
  }
144
- function R({ dmShortID: n }) {
144
+ function z({ dmShortID: n }) {
145
145
  return g({ dmShortID: n }), n;
146
146
  }
147
- function z({ env: n }) {
147
+ function C({ env: n }) {
148
148
  return g({ env: n }), n;
149
149
  }
150
- function J(n) {
151
- return i(this, null, function* () {
150
+ function R(n) {
151
+ return r(this, null, function* () {
152
+ let { env: t, dmShortID: e } = n;
153
+ g({ env: t, dmShortID: e });
154
+ const s = f(`api/${e}`, t);
155
+ return d(s, n);
156
+ });
157
+ }
158
+ function v(n) {
159
+ return r(this, null, function* () {
152
160
  let { env: t, dmShortID: e, model: s, options: o = {} } = n;
153
- g({ env: t, dmShortID: e, model: s }), o = a({ size: 50, page: 1, _list: !0 }, o);
154
- const u = E(o), r = f(`api/${e}/${s}?${u}`, t), { count: h, total: c, _embedded: l } = yield y(r, n);
155
- let $ = l ? l[`${e}:${s}`] : [];
156
- return $ = Array.isArray($) ? $ : [$], { count: h, total: c, items: $ };
161
+ g({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
162
+ const u = A(o), i = f(`api/${e}/${s}?${u}`, t), { count: h, total: a, _embedded: l } = yield d(i, n);
163
+ let p = l ? l[`${e}:${s}`] : [];
164
+ return p = Array.isArray(p) ? p : [p], { count: h, total: a, items: p };
157
165
  });
158
166
  }
159
- function N({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
167
+ function J({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
160
168
  g({ env: n, dmShortID: t, model: e, entryID: s });
161
- const u = E({ _id: s }), r = f(`api/${t}/${e}?${u}`, n);
162
- return y(r, { dmShortID: t, token: o });
169
+ const u = A({ _id: s }), i = f(`api/${t}/${e}?${u}`, n);
170
+ return d(i, { dmShortID: t, token: o });
163
171
  }
164
- function U(u) {
165
- return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
166
- g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
167
- const r = f(`api/${t}/${e}`, n);
168
- return console.log("url", r), yield y(
169
- r,
172
+ function N(u) {
173
+ return r(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
174
+ g({ env: n, dmShortID: t, model: e, value: s });
175
+ const i = f(`api/${t}/${e}`, n);
176
+ return yield d(
177
+ i,
170
178
  { env: n, dmShortID: t, token: o },
171
179
  {
172
180
  method: "POST",
@@ -178,8 +186,8 @@ function U(u) {
178
186
  );
179
187
  });
180
188
  }
181
- function v(r) {
182
- return i(this, arguments, function* ({
189
+ function M(i) {
190
+ return r(this, arguments, function* ({
183
191
  env: n,
184
192
  dmShortID: t,
185
193
  model: e,
@@ -189,7 +197,7 @@ function v(r) {
189
197
  }) {
190
198
  g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
191
199
  const h = f(`api/${t}/${e}?_id=${s}`, n);
192
- return yield y(
200
+ return yield d(
193
201
  h,
194
202
  { token: u },
195
203
  {
@@ -202,12 +210,12 @@ function v(r) {
202
210
  );
203
211
  });
204
212
  }
205
- function F(u) {
206
- return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
213
+ function U(u) {
214
+ return r(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
207
215
  g({ env: n, dmShortID: t, model: e, entryID: s });
208
- const r = f(`api/${t}/${e}?_id=${s}`, n);
209
- yield y(
210
- r,
216
+ const i = f(`api/${t}/${e}?_id=${s}`, n);
217
+ yield d(
218
+ i,
211
219
  { token: o, rawRes: !0 },
212
220
  {
213
221
  method: "DELETE",
@@ -218,38 +226,38 @@ function F(u) {
218
226
  );
219
227
  });
220
228
  }
221
- function M(u) {
222
- return i(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
229
+ function F(u) {
230
+ return r(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
223
231
  g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
224
- const r = E({ assetID: s }), h = f(`a/${t}/${e}?${r}`, n);
225
- return (yield y(h, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
232
+ const i = A({ assetID: s }), h = f(`a/${t}/${e}?${i}`, n);
233
+ return (yield d(h, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
226
234
  });
227
235
  }
228
- function G(n) {
229
- return i(this, null, function* () {
236
+ function I(n) {
237
+ return r(this, null, function* () {
230
238
  let { env: t, dmShortID: e, assetGroup: s, token: o, options: u = {} } = n;
231
- g({ env: t, dmShortID: e, assetGroup: s }), u = a({ size: 50, page: 1, _list: !0 }, u);
232
- const r = E(u), h = f(`a/${e}/${s}?${r}`, t), { count: c, total: l, _embedded: $ } = yield y(h, { dmShortID: e, token: o });
233
- let p = $ ? $["ec:dm-asset"] : [];
234
- return p = Array.isArray(p) ? p : [p], { count: c, total: l, items: p };
239
+ g({ env: t, dmShortID: e, assetGroup: s }), u = c({ size: 50, page: 1, _list: !0 }, u);
240
+ const i = A(u), h = f(`a/${e}/${s}?${i}`, t), { count: a, total: l, _embedded: p } = yield d(h, { dmShortID: e, token: o });
241
+ let $ = p ? p["ec:dm-asset"] : [];
242
+ return $ = Array.isArray($) ? $ : [$], { count: a, total: l, items: $ };
235
243
  });
236
244
  }
237
- function H(h) {
238
- return i(this, arguments, function* ({
245
+ function G(h) {
246
+ return r(this, arguments, function* ({
239
247
  env: n,
240
248
  dmShortID: t,
241
249
  assetGroup: e,
242
250
  token: s,
243
251
  file: o,
244
252
  name: u,
245
- options: r
253
+ options: i
246
254
  }) {
247
255
  g({ env: n, dmShortID: t, assetGroup: e, file: o });
248
- const c = f(`a/${t}/${e}`, n), l = new FormData();
249
- return l.append("file", o, u), r && Object.keys(r).forEach((p) => {
250
- l.append(p, r[p]);
251
- }), (yield y(
252
- c,
256
+ const a = f(`a/${t}/${e}`, n), l = new FormData();
257
+ return l.append("file", o, u), i && Object.keys(i).forEach(($) => {
258
+ l.append($, i[$]);
259
+ }), (yield d(
260
+ a,
253
261
  { token: s },
254
262
  {
255
263
  method: "POST",
@@ -258,8 +266,8 @@ function H(h) {
258
266
  ))._embedded["ec:dm-asset"];
259
267
  });
260
268
  }
261
- function Q(u) {
262
- return i(this, arguments, function* ({
269
+ function H(u) {
270
+ return r(this, arguments, function* ({
263
271
  env: n,
264
272
  dmShortID: t,
265
273
  assetGroup: e,
@@ -267,9 +275,9 @@ function Q(u) {
267
275
  token: o
268
276
  }) {
269
277
  g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
270
- const r = f(`a/${t}/${e}/${s}`, n);
271
- yield y(
272
- r,
278
+ const i = f(`a/${t}/${e}/${s}`, n);
279
+ yield d(
280
+ i,
273
281
  { token: o, rawRes: !0 },
274
282
  {
275
283
  method: "DELETE"
@@ -277,67 +285,90 @@ function Q(u) {
277
285
  );
278
286
  });
279
287
  }
288
+ function Q(n) {
289
+ return r(this, null, function* () {
290
+ let { env: t, dmID: e, token: s } = n;
291
+ g({ env: t, dmID: e });
292
+ const o = f(`?dataManagerID=${e}`, t);
293
+ return d(o, { token: s });
294
+ });
295
+ }
280
296
  function V(n) {
281
- return i(this, null, function* () {
297
+ return r(this, null, function* () {
282
298
  let { env: t, options: e = {} } = n;
283
- g({ env: t }), e = a({ size: 25, page: 1, _list: !0 }, e);
284
- const s = E(e), o = f(`?${s}`, t), { count: u, total: r, _embedded: h } = yield y(o, n);
285
- let c = h ? h["ec:datamanager"] : [];
286
- return c = Array.isArray(c) ? c : [c], { count: u, total: r, items: c };
299
+ g({ env: t }), e = c({ size: 25, page: 1, _list: !0 }, e);
300
+ const s = A(e), o = f(`?${s}`, t), { count: u, total: i, _embedded: h } = yield d(o, n);
301
+ let a = h ? h["ec:datamanager"] : [];
302
+ return a = Array.isArray(a) ? a : [a], { count: u, total: i, items: a };
287
303
  });
288
304
  }
289
- const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
305
+ function W(n) {
306
+ return r(this, null, function* () {
307
+ let { env: t, dmID: e, options: s = {} } = n;
308
+ g({ env: t, dmID: e }), s = c({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
309
+ const o = A(s), u = f(`model?${o}`, t), { count: i, total: h, _embedded: a } = yield d(u, n);
310
+ let l = a ? a["ec:model"] : [];
311
+ return l = Array.isArray(l) ? l : [l], { count: i, total: h, items: l };
312
+ });
313
+ }
314
+ const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
290
315
  __proto__: null,
291
- assetList: G,
292
- createAsset: H,
293
- createEntry: U,
294
- deleteAsset: Q,
295
- deleteEntry: F,
316
+ assetList: I,
317
+ createAsset: G,
318
+ createEntry: N,
319
+ deleteAsset: H,
320
+ deleteEntry: U,
296
321
  dmList: V,
297
- editEntry: v,
298
- entryList: J,
299
- getAsset: M,
300
- getEcAuthKey: z,
301
- getEntry: N,
302
- getPublicAuthKey: R,
303
- loginEc: q,
322
+ editEntry: M,
323
+ entryList: v,
324
+ getAsset: F,
325
+ getDatamanager: Q,
326
+ getEcAuthKey: C,
327
+ getEntry: J,
328
+ getPublicAuthKey: z,
329
+ loginEc: K,
304
330
  loginPublic: S,
305
- logoutEc: C,
306
- logoutPublic: x
331
+ logoutEc: x,
332
+ logoutPublic: q,
333
+ modelList: W,
334
+ publicApi: R
307
335
  }, Symbol.toStringTag, { value: "Module" })), {
308
- entryList: W,
309
- getEntry: X,
310
- getAsset: Y,
311
- assetList: Z,
312
- createAsset: D,
313
- deleteAsset: I,
314
- createEntry: tt,
315
- editEntry: et,
316
- deleteEntry: nt,
317
- loginPublic: st,
318
- loginEc: ot,
319
- logoutEc: rt,
320
- logoutPublic: it,
321
- getEcAuthKey: w,
322
- getPublicAuthKey: k,
323
- dmList: ct
324
- } = A;
325
- function ut(n) {
336
+ entryList: X,
337
+ getEntry: Y,
338
+ getAsset: Z,
339
+ assetList: tt,
340
+ createAsset: et,
341
+ deleteAsset: nt,
342
+ createEntry: st,
343
+ editEntry: ot,
344
+ deleteEntry: rt,
345
+ loginPublic: it,
346
+ loginEc: at,
347
+ logoutEc: ct,
348
+ logoutPublic: ut,
349
+ getEcAuthKey: E,
350
+ getPublicAuthKey: w,
351
+ dmList: ht,
352
+ modelList: lt,
353
+ publicApi: gt,
354
+ getDatamanager: dt
355
+ } = k;
356
+ function ft(n) {
326
357
  const { action: t } = n;
327
- if (g({ action: t }), !A[t])
358
+ if (g({ action: t }), !k[t])
328
359
  throw new Error(
329
- `"${t}" does not exist! try one of ${Object.keys(A).join(
360
+ `"${t}" does not exist! try one of ${Object.keys(k).join(
330
361
  ", "
331
362
  )}`
332
363
  );
333
- return A[t](n);
364
+ return k[t](n);
334
365
  }
335
- class b {
366
+ class m {
336
367
  constructor(t) {
337
368
  this.config = t;
338
369
  }
339
370
  set(t) {
340
- return new b(a(a({}, this.config), t));
371
+ return new m(c(c({}, this.config), t));
341
372
  }
342
373
  /**
343
374
  * Loads entry list. Expects `dmShortID` / `model` to be set.
@@ -353,13 +384,13 @@ class b {
353
384
  * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
354
385
  */
355
386
  entries() {
356
- return i(this, arguments, function* (t = {}) {
387
+ return r(this, arguments, function* (t = {}) {
357
388
  const e = yield this.getBestToken();
358
- return W(d(a({}, this.config), { options: t, token: e }));
389
+ return X(y(c({}, this.config), { options: t, token: e }));
359
390
  });
360
391
  }
361
392
  entryList(t) {
362
- return i(this, null, function* () {
393
+ return r(this, null, function* () {
363
394
  return this.entries(t);
364
395
  });
365
396
  }
@@ -373,9 +404,9 @@ class b {
373
404
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
374
405
  */
375
406
  getEntry(t) {
376
- return i(this, null, function* () {
407
+ return r(this, null, function* () {
377
408
  const e = yield this.getBestToken();
378
- return X(d(a({}, this.config), { entryID: t, token: e }));
409
+ return Y(y(c({}, this.config), { entryID: t, token: e }));
379
410
  });
380
411
  }
381
412
  /**
@@ -392,13 +423,13 @@ class b {
392
423
  * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
393
424
  */
394
425
  assets(t) {
395
- return i(this, null, function* () {
426
+ return r(this, null, function* () {
396
427
  const e = yield this.getBestToken();
397
- return Z(d(a({}, this.config), { options: t, token: e }));
428
+ return tt(y(c({}, this.config), { options: t, token: e }));
398
429
  });
399
430
  }
400
431
  assetList(t) {
401
- return i(this, null, function* () {
432
+ return r(this, null, function* () {
402
433
  return this.assets(t);
403
434
  });
404
435
  }
@@ -424,9 +455,9 @@ class b {
424
455
  * .createAsset({ file, name: "venndiagram.png" });
425
456
  */
426
457
  createAsset() {
427
- return i(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
458
+ return r(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
428
459
  const o = yield this.getBestToken();
429
- return D(d(a({}, this.config), { file: t, name: e, options: s, token: o }));
460
+ return et(y(c({}, this.config), { file: t, name: e, options: s, token: o }));
430
461
  });
431
462
  }
432
463
  /**
@@ -439,9 +470,9 @@ class b {
439
470
  * await ecadmin.assetgroup("test").deleteAsset('xxxx');
440
471
  */
441
472
  deleteAsset(t) {
442
- return i(this, null, function* () {
473
+ return r(this, null, function* () {
443
474
  const e = yield this.getBestToken();
444
- return I(d(a({}, this.config), { token: e, assetID: t }));
475
+ return nt(y(c({}, this.config), { token: e, assetID: t }));
445
476
  });
446
477
  }
447
478
  /**
@@ -454,9 +485,9 @@ class b {
454
485
  * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
455
486
  */
456
487
  getAsset(t) {
457
- return i(this, null, function* () {
488
+ return r(this, null, function* () {
458
489
  const e = yield this.getBestToken();
459
- return Y(d(a({}, this.config), { assetID: t, token: e }));
490
+ return Z(y(c({}, this.config), { assetID: t, token: e }));
460
491
  });
461
492
  }
462
493
  /**
@@ -469,9 +500,9 @@ class b {
469
500
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
470
501
  */
471
502
  createEntry(t) {
472
- return i(this, null, function* () {
503
+ return r(this, null, function* () {
473
504
  const e = yield this.getBestToken();
474
- return tt(d(a({}, this.config), { token: e, value: t }));
505
+ return st(y(c({}, this.config), { token: e, value: t }));
475
506
  });
476
507
  }
477
508
  /**
@@ -485,9 +516,9 @@ class b {
485
516
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
486
517
  */
487
518
  editEntry(t, e) {
488
- return i(this, null, function* () {
519
+ return r(this, null, function* () {
489
520
  const s = yield this.getBestToken();
490
- return et(d(a({}, this.config), { entryID: t, token: s, value: e }));
521
+ return ot(y(c({}, this.config), { entryID: t, token: s, value: e }));
491
522
  });
492
523
  }
493
524
  /**
@@ -500,9 +531,9 @@ class b {
500
531
  * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
501
532
  */
502
533
  deleteEntry(t) {
503
- return i(this, null, function* () {
534
+ return r(this, null, function* () {
504
535
  const e = yield this.getBestToken();
505
- return nt(d(a({}, this.config), { token: e, entryID: t }));
536
+ return rt(y(c({}, this.config), { token: e, entryID: t }));
506
537
  });
507
538
  }
508
539
  // TODO: rename authAdapter -> storageAdapter
@@ -532,32 +563,32 @@ class b {
532
563
  return e(t);
533
564
  }
534
565
  loginEc(t) {
535
- return ot(a(a({}, this.config), t)).then(
536
- this.setAuth(w(this.config))
566
+ return at(c(c({}, this.config), t)).then(
567
+ this.setAuth(E(this.config))
537
568
  );
538
569
  }
539
570
  loginPublic(t) {
540
- return st(a(a({}, this.config), t)).then(
541
- this.setAuth(k(this.config))
571
+ return it(c(c({}, this.config), t)).then(
572
+ this.setAuth(w(this.config))
542
573
  );
543
574
  }
544
575
  logoutPublic() {
545
576
  const t = this.getPublicToken();
546
- return console.log("token", t), it(d(a({}, this.config), { token: t })).then(
547
- this.unsetAuth(k(this.config))
577
+ return console.log("token", t), ut(y(c({}, this.config), { token: t })).then(
578
+ this.unsetAuth(w(this.config))
548
579
  );
549
580
  }
550
581
  logoutEc() {
551
582
  const t = this.getEcToken();
552
- return console.log("token", t), rt(d(a({}, this.config), { token: t })).then(
553
- this.unsetAuth(w(this.config))
583
+ return console.log("token", t), ct(y(c({}, this.config), { token: t })).then(
584
+ this.unsetAuth(E(this.config))
554
585
  );
555
586
  }
556
587
  getPublicToken() {
557
- return this.config.token || this.getAuth(k(this.config));
588
+ return this.config.token || this.getAuth(w(this.config));
558
589
  }
559
590
  getEcToken() {
560
- return this.config.token || this.getAuth(w(this.config));
591
+ return this.config.token || this.getAuth(E(this.config));
561
592
  }
562
593
  hasPublicToken() {
563
594
  return !!this.getPublicToken();
@@ -599,6 +630,14 @@ class b {
599
630
  dmShortID(t) {
600
631
  return this.set({ dmShortID: t });
601
632
  }
633
+ /**
634
+ * Sets the (long) ID of the datamanager to use
635
+ * @param {string} dmID
636
+ * @returns Sdk
637
+ */
638
+ dmID(t) {
639
+ return this.set({ dmID: t });
640
+ }
602
641
  /**
603
642
  * Sets the short ID of the datamanager to use. Alias for `dmShortID`
604
643
  * @param {string} dmShortID
@@ -623,48 +662,78 @@ class b {
623
662
  assetgroup(t) {
624
663
  return this.assetGroup(t);
625
664
  }
665
+ /**
666
+ * Returns the public api root endpoint. Expects dmShortID to be set.
667
+ * @returns any
668
+ */
669
+ publicApi() {
670
+ return gt(this.config);
671
+ }
672
+ /**
673
+ * Loads a DatamanagerResource by its long id. Requires token.
674
+ * @returns any
675
+ */
676
+ getDatamanager(t) {
677
+ return r(this, null, function* () {
678
+ const e = yield this.getBestToken();
679
+ return dt(y(c({}, this.config), { dmID: t, token: e }));
680
+ });
681
+ }
626
682
  /**
627
683
  * Loads datamanager list. Make sure to provide an ec.admin `token` intercept one.
628
684
  *
629
685
  * @param {object=} options options for entry list request.
630
686
  * @returns {Promise<DatamanagerList>}
631
687
  * @example
632
- * // public model
633
- * const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
634
- * @example
635
- * // non-public model
636
- * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
688
+ * const dms = await sdk("stage").dmList()
637
689
  */
638
690
  dmList() {
639
- return i(this, arguments, function* (t = {}) {
691
+ return r(this, arguments, function* (t = {}) {
692
+ const e = yield this.getBestToken();
693
+ return ht(y(c({}, this.config), { options: t, token: e }));
694
+ });
695
+ }
696
+ /**
697
+ * Loads model list. Expects dmID to be set. Make sure to provide an ec.admin `token` intercept one.
698
+ *
699
+ * @param {object=} options options for entry list request.
700
+ * @returns {Promise<ModelList>}
701
+ * @example
702
+ * const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
703
+ */
704
+ modelList() {
705
+ return r(this, arguments, function* (t = {}) {
640
706
  const e = yield this.getBestToken();
641
- return ct(d(a({}, this.config), { options: t, token: e }));
707
+ return lt(y(c({}, this.config), { options: t, token: e }));
642
708
  });
643
709
  }
644
710
  }
645
- const ht = (n) => new b({ env: n });
711
+ const pt = (n) => new m({ env: n });
646
712
  export {
647
- b as Sdk,
648
- ut as act,
713
+ m as Sdk,
714
+ ft as act,
649
715
  f as apiURL,
650
- G as assetList,
651
- H as createAsset,
652
- U as createEntry,
653
- Q as deleteAsset,
654
- F as deleteEntry,
716
+ I as assetList,
717
+ G as createAsset,
718
+ N as createEntry,
719
+ H as deleteAsset,
720
+ U as deleteEntry,
655
721
  V as dmList,
656
- v as editEntry,
657
- J as entryList,
722
+ M as editEntry,
723
+ v as entryList,
658
724
  g as expect,
659
- y as fetcher,
660
- M as getAsset,
661
- z as getEcAuthKey,
662
- N as getEntry,
663
- R as getPublicAuthKey,
664
- q as loginEc,
725
+ d as fetcher,
726
+ F as getAsset,
727
+ Q as getDatamanager,
728
+ C as getEcAuthKey,
729
+ J as getEntry,
730
+ z as getPublicAuthKey,
731
+ K as loginEc,
665
732
  S as loginPublic,
666
- C as logoutEc,
667
- x as logoutPublic,
668
- E as query,
669
- ht as sdk
733
+ x as logoutEc,
734
+ q as logoutPublic,
735
+ W as modelList,
736
+ R as publicApi,
737
+ A as query,
738
+ pt as sdk
670
739
  };
@@ -1,6 +1,12 @@
1
+ export function getDatamanager(config: any): Promise<any>;
1
2
  export function dmList(config: any): Promise<{
2
3
  count: any;
3
4
  total: any;
4
5
  items: any;
5
6
  }>;
7
+ export function modelList(config: any): Promise<{
8
+ count: any;
9
+ total: any;
10
+ items: any;
11
+ }>;
6
12
  //# sourceMappingURL=admin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA;;;;GAWC"}
1
+ {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA,0DAKC;AAED;;;;GAWC;AAED;;;;GAWC"}
@@ -156,6 +156,12 @@ export class Sdk {
156
156
  * @returns Sdk
157
157
  */
158
158
  dmShortID(dmShortID: string): Sdk;
159
+ /**
160
+ * Sets the (long) ID of the datamanager to use
161
+ * @param {string} dmID
162
+ * @returns Sdk
163
+ */
164
+ dmID(dmID: string): Sdk;
159
165
  /**
160
166
  * Sets the short ID of the datamanager to use. Alias for `dmShortID`
161
167
  * @param {string} dmShortID
@@ -174,19 +180,34 @@ export class Sdk {
174
180
  * @returns Sdk
175
181
  */
176
182
  assetgroup(assetGroup: string): Sdk;
183
+ /**
184
+ * Returns the public api root endpoint. Expects dmShortID to be set.
185
+ * @returns any
186
+ */
187
+ publicApi(): Promise<any>;
188
+ /**
189
+ * Loads a DatamanagerResource by its long id. Requires token.
190
+ * @returns any
191
+ */
192
+ getDatamanager(dmID: any): Promise<any>;
177
193
  /**
178
194
  * Loads datamanager list. Make sure to provide an ec.admin `token` intercept one.
179
195
  *
180
196
  * @param {object=} options options for entry list request.
181
197
  * @returns {Promise<DatamanagerList>}
182
198
  * @example
183
- * // public model
184
- * const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
185
- * @example
186
- * // non-public model
187
- * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
199
+ * const dms = await sdk("stage").dmList()
188
200
  */
189
201
  dmList(options?: object | undefined): Promise<DatamanagerList>;
202
+ /**
203
+ * Loads model list. Expects dmID to be set. Make sure to provide an ec.admin `token` intercept one.
204
+ *
205
+ * @param {object=} options options for entry list request.
206
+ * @returns {Promise<ModelList>}
207
+ * @example
208
+ * const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
209
+ */
210
+ modelList(options?: object | undefined): Promise<ModelList>;
190
211
  }
191
212
  export function sdk(env: any): Sdk;
192
213
  export type AssetFile = {
@@ -281,4 +302,42 @@ export type AssetList = {
281
302
  total: number;
282
303
  items: AssetResource[];
283
304
  };
305
+ /**
306
+ * // config: {} ?
307
+ */
308
+ export type ModelFieldConfig = {
309
+ default: any;
310
+ description: string;
311
+ localizable: boolean;
312
+ mutable: boolean;
313
+ readOnly: boolean;
314
+ required: boolean;
315
+ unique: boolean;
316
+ title: string;
317
+ type: string;
318
+ validation: string | null;
319
+ };
320
+ export type ModelResource = {
321
+ config: any;
322
+ created: string;
323
+ description: string;
324
+ fields: ModelFieldConfig[];
325
+ hasEntries: boolean;
326
+ hexColor: string;
327
+ hooks: any[];
328
+ lastSyncs: any[];
329
+ locales: string[];
330
+ modelID: string;
331
+ modified: string;
332
+ policies: any[];
333
+ sync: any;
334
+ title: string;
335
+ titleField: string;
336
+ _links: any;
337
+ };
338
+ export type ModelList = {
339
+ count: number;
340
+ total: number;
341
+ items: ModelResource[];
342
+ };
284
343
  //# sourceMappingURL=api.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AA0BA,sCAWC;;AAED;;GAEG;AACH;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sCAjBW;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,MAAM,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAClD,QAAQ,aAAa,CAAC,CAmBlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAOzB;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IAED;;;;;;;;OAQG;IACH,mBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;OASG;IACH,mBANW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,IAAI,CAOhB;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;IAED;;;;;;;;;;;OAWG;IACH,iBATW,MAAM,eACJ,QAAQ,eAAe,CAAC,CAWpC;CACF;AAEM,mCAAqC;;SAI9B,MAAM;UACN,MAAM;;;;aAMN,MAAM;aACN,IAAI;WACJ,MAAM,GAAG,CAAC;UACV,MAAM,MAAM,GAAG,GAAG,CAAC;WACnB,MAAM;UACN,MAAM;UACN,SAAS;;;;;;QAKT,MAAM;;;;cACN,IAAI;;;;cACJ,MAAM;;;;eACN,GAAG;;;;YACH,GAAG;;;;iBACH,MAAM;;;;sBACN,MAAM;;;;eACN,IAAI;;;;aACJ,IAAI;;;;cACJ,IAAI;;;;UACJ,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;aAKf,MAAM;mBACN,MAAM;mBACN,MAAM;iBACN,MAAM;YACN,GAAG;cACH,MAAM;aACN,MAAM,EAAE;YACR,MAAM,EAAE;uBACR,MAAM,EAAE;aACR,MAAM;WACN,MAAM;;;;YACN,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,mBAAmB,EAAE;;;WAKrB,MAAM;WACN,MAAM;WACN,aAAa,EAAE"}
1
+ {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AA6BA,sCAWC;;AAED;;GAEG;AACH;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sCAjBW;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,MAAM,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAClD,QAAQ,aAAa,CAAC,CAmBlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAOzB;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IAED;;;;;;;;OAQG;IACH,mBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;OASG;IACH,mBANW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,IAAI,CAOhB;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,WAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,cAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IAED;;;OAGG;IACH,0BAEC;IAED;;;OAGG;IACH,wCAGC;IAED;;;;;;;OAOG;IACH,iBALW,MAAM,eACJ,QAAQ,eAAe,CAAC,CAOpC;IACD;;;;;;;OAOG;IACH,oBALW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAO9B;CACF;AAEM,mCAAqC;;SAI9B,MAAM;UACN,MAAM;;;;aAMN,MAAM;aACN,IAAI;WACJ,MAAM,GAAG,CAAC;UACV,MAAM,MAAM,GAAG,GAAG,CAAC;WACnB,MAAM;UACN,MAAM;UACN,SAAS;;;;;;QAKT,MAAM;;;;cACN,IAAI;;;;cACJ,MAAM;;;;eACN,GAAG;;;;YACH,GAAG;;;;iBACH,MAAM;;;;sBACN,MAAM;;;;eACN,IAAI;;;;aACJ,IAAI;;;;cACJ,IAAI;;;;UACJ,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;aAKf,MAAM;mBACN,MAAM;mBACN,MAAM;iBACN,MAAM;YACN,GAAG;cACH,MAAM;aACN,MAAM,EAAE;YACR,MAAM,EAAE;uBACR,MAAM,EAAE;aACR,MAAM;WACN,MAAM;;;;YACN,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,mBAAmB,EAAE;;;WAKrB,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;;;;aAMf,GAAG;iBACH,MAAM;iBACN,OAAO;aACP,OAAO;cACP,OAAO;cACP,OAAO;YACP,OAAO;WACP,MAAM;UACN,MAAM;gBACN,MAAM,GAAG,IAAI;;;YAKb,GAAG;aACH,MAAM;iBACN,MAAM;YACN,gBAAgB,EAAE;gBAClB,OAAO;cACP,MAAM;WACN,GAAG,EAAE;eACL,GAAG,EAAE;aACL,MAAM,EAAE;aACR,MAAM;cACN,MAAM;cACN,GAAG,EAAE;UACL,GAAG;WACH,MAAM;gBACN,MAAM;YACN,GAAG;;;WAMH,MAAM;WACN,MAAM;WACN,aAAa,EAAE"}
@@ -1,3 +1,4 @@
1
+ export function publicApi(config: any): Promise<any>;
1
2
  export function entryList(config: any): Promise<{
2
3
  count: any;
3
4
  total: any;
@@ -1 +1 @@
1
- {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAEA;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAiBC;AAED;;;;;;;iBAuBC;AAED;;;;;;kBAcC"}
1
+ {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAEA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;iBAuBC;AAED;;;;;;kBAcC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {