ec.fdk 0.2.28 → 0.2.30

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 Z=Object.defineProperty,tt=Object.defineProperties;var et=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var O=(n,t,e)=>t in n?Z(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,l=(n,t)=>{for(var e in t||(t={}))nt.call(t,e)&&O(n,e,t[e]);if(L)for(var e of L(t))st.call(t,e)&&O(n,e,t[e]);return n},f=(n,t)=>tt(n,et(t));var o=(n,t,e)=>new Promise((s,r)=>{var a=c=>{try{u(e.next(c))}catch(h){r(h)}},i=c=>{try{u(e.throw(c))}catch(h){r(h)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(a,i);u((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return o(this,arguments,function*(n,t={},e={}){var u;const{token:r,rawRes:a}=t;r&&(e.headers=f(l({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((u=i.headers.get("content-type"))!=null&&u.includes("application/json")){const c=yield i.json(),h=`${c.title}
2
- ${c.detail}
3
- ${c.verbose}`;throw new Error(h)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return a?i:yield i.json()})}const j={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(n,t="stage"){const e=j[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`);return e+n}function k(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function d(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const S={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function B(n){return o(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function q(n){return o(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${S[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function D(n){return o(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function K(n){return o(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${S[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function x({dmShortID:n}){return d({dmShortID:n}),n}function R({env:n}){return d({env:n}),n}function v(n){return o(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=y(`api/${e}`,t);return g(s,n)})}function z(n){return o(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=l({size:50,page:1,_list:!0},r);const a=k(r),i=y(`api/${e}/${s}?${a}`,t),{count:u,total:c,_embedded:h}=yield g(i,n);let $=h?h[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:u,total:c,items:$}})}function C({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=k({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return g(i,{dmShortID:t,token:r})}function J(a){return o(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function N(i){return o(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const u=y(`api/${t}/${e}?_id=${s}`,n);return yield g(u,{token:a},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function M(a){return o(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function U(s){return o(this,arguments,function*({env:n,dmShortID:t,model:e}){var h,$,m,P,_;d({env:n,dmShortID:t,model:e});const r=y(`api/schema/${t}/${e}`,n),a=yield g(r),i=(h=a==null?void 0:a.allOf)==null?void 0:h[1];if(typeof i.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:u}=i;let c=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];for(let A in u){let p=u[A];if(p.required=i.required.includes(A),c.includes(A)){delete u[A];continue}if(($=u[A])!=null&&$.oneOf&&((m=u[A])==null||delete m.oneOf),(P=p.title)!=null&&P.includes("<")&&((_=p.title)!=null&&_.includes(">"))){const X=p.title.split("<")[1].slice(0,-1),Y=p.title.split("<")[0];p.type=Y,p.resource=X}else["asset","entry","assets","entries"].includes(p.title)?(p.type=p.title,p.resource=null):p.type=p.title;delete u[A].title}return u})}function F(a){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=k({assetID:s}),u=y(`a/${t}/${e}?${i}`,n);return(yield g(u,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function G(n){return o(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=l({size:50,page:1,_list:!0},a);const i=k(a),u=y(`a/${e}/${s}?${i}`,t),{count:c,total:h,_embedded:$}=yield g(u,{dmShortID:e,token:r});let m=$?$["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:c,total:h,items:m}})}function H(u){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:i}){d({env:n,dmShortID:t,assetGroup:e,file:r});const c=y(`a/${t}/${e}`,n),h=new FormData;return h.append("file",r,a),i&&Object.keys(i).forEach(m=>{h.append(m,i[m])}),(yield g(c,{token:s},{method:"POST",body:h}))._embedded["ec:dm-asset"]})}function I(a){return o(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function Q(n){return o(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function V(n){return o(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=l({size:25,page:1,_list:!0},e);const s=k(e),r=y(`?${s}`,t),{count:a,total:i,_embedded:u}=yield g(r,n);let c=u?u["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:a,total:i,items:c}})}function W(n){return o(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=l({size:25,dataManagerID:e,page:1,_list:!0},s);const r=k(s),a=y(`model?${r}`,t),{count:i,total:u,_embedded:c}=yield g(a,n);let h=c?c["ec:model"]:[];return h=Array.isArray(h)?h:[h],{count:i,total:u,items:h}})}const w=Object.freeze(Object.defineProperty({__proto__:null,assetList:G,createAsset:H,createEntry:J,deleteAsset:I,deleteEntry:M,dmList:V,editEntry:N,entryList:z,getAsset:F,getDatamanager:Q,getEcAuthKey:R,getEntry:C,getPublicAuthKey:x,getSchema:U,loginEc:q,loginPublic:B,logoutEc:K,logoutPublic:D,modelList:W,publicApi:v},Symbol.toStringTag,{value:"Module"})),{entryList:rt,getEntry:it,getAsset:ot,assetList:ct,createAsset:at,deleteAsset:ut,createEntry:lt,editEntry:ht,deleteEntry:dt,getSchema:gt,loginPublic:yt,loginEc:ft,logoutEc:pt,logoutPublic:$t,getEcAuthKey:b,getPublicAuthKey:T,dmList:mt,modelList:At,publicApi:kt,getDatamanager:wt}=w;function Et(n){const{action:t}=n;if(d({action:t}),!w[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(w).join(", ")}`);return w[t](n)}class E{constructor(t){this.config=t}set(t){return new E(l(l({},this.config),t))}entries(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return rt(f(l({},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 it(f(l({},this.config),{entryID:t,token:e}))})}getSchema(){return o(this,null,function*(){return gt(this.config)})}assets(t){return o(this,null,function*(){const e=yield this.getBestToken();return ct(f(l({},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 at(f(l({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return o(this,null,function*(){const e=yield this.getBestToken();return ut(f(l({},this.config),{token:e,assetID:t}))})}getAsset(t){return o(this,null,function*(){const e=yield this.getBestToken();return ot(f(l({},this.config),{assetID:t,token:e}))})}createEntry(t){return o(this,null,function*(){const e=yield this.getBestToken();return lt(f(l({},this.config),{token:e,value:t}))})}editEntry(t,e){return o(this,null,function*(){const s=yield this.getBestToken();return ht(f(l({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return o(this,null,function*(){const e=yield this.getBestToken();return dt(f(l({},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 ft(l(l({},this.config),t)).then(this.setAuth(b(this.config)))}loginPublic(t){return yt(l(l({},this.config),t)).then(this.setAuth(T(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),$t(f(l({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),pt(f(l({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}getPublicToken(){return this.config.token||this.getAuth(T(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})}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 kt(this.config)}getDatamanager(t){return o(this,null,function*(){const e=yield this.getBestToken();return wt(f(l({},this.config),{dmID:t,token:e}))})}dmList(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return mt(f(l({},this.config),{options:t,token:e}))})}modelList(){return o(this,arguments,function*(t={}){const e=yield this.getBestToken();return At(f(l({},this.config),{options:t,token:e}))})}}const bt=n=>new E({env:n});exports.Sdk=E;exports.act=Et;exports.apiURL=y;exports.assetList=G;exports.createAsset=H;exports.createEntry=J;exports.deleteAsset=I;exports.deleteEntry=M;exports.dmList=V;exports.editEntry=N;exports.entryList=z;exports.expect=d;exports.fetcher=g;exports.getAsset=F;exports.getDatamanager=Q;exports.getEcAuthKey=R;exports.getEntry=C;exports.getPublicAuthKey=x;exports.getSchema=U;exports.loginEc=q;exports.loginPublic=B;exports.logoutEc=K;exports.logoutPublic=D;exports.modelList=W;exports.publicApi=v;exports.query=k;exports.sdk=bt;
1
+ "use strict";var tt=Object.defineProperty,et=Object.defineProperties;var nt=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var st=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?tt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))st.call(t,e)&&S(n,e,t[e]);if(L)for(var e of L(t))rt.call(t,e)&&S(n,e,t[e]);return n},f=(n,t)=>et(n,nt(t));var c=(n,t,e)=>new Promise((s,r)=>{var a=o=>{try{h(e.next(o))}catch(l){r(l)}},i=o=>{try{h(e.throw(o))}catch(l){r(l)}},h=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,i);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return c(this,arguments,function*(n,t={},e={}){var h;const{token:r,rawRes:a}=t;r&&(e.headers=f(u({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((h=i.headers.get("content-type"))!=null&&h.includes("application/json")){const o=yield i.json(),l=`${o.title}
2
+ ${o.detail}
3
+ ${o.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return a?i:yield i.json()})}const j={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(n,t="stage"){const e=j[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`);return e+n}function w(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function d(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const B={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function q(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function D(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${B[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${B[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function J({dmShortID:n}){return d({dmShortID:n}),n}function N({env:n}){return d({env:n}),n}let it=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function R(n){let t={};for(let e in n)it.includes(e)||(t[e]=n[e]);return t}function ot(n){return JSON.parse(JSON.stringify(n))}function z(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=y(`api/${e}`,t);return g(s,n)})}function C(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=u({size:50,page:1,_list:!0},r);const a=w(r),i=y(`api/${e}/${s}?${a}`,t),{count:h,total:o,_embedded:l}=yield g(i,n);let $=l?l[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:h,total:o,items:$}})}function F({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return g(i,{dmShortID:t,token:r})}function M(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function U(i){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const h=y(`api/${t}/${e}?_id=${s}`,n);return r=ot(r),r=R(r),yield g(h,{token:a},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function v(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function V(s){return c(this,arguments,function*({env:n,dmShortID:t,model:e}){var l,$,m,P,_;d({env:n,dmShortID:t,model:e});const r=y(`api/schema/${t}/${e}`,n),a=yield g(r),i=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof i.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=i,o=R(h);for(let A in o){let p=o[A];if(p.required=i.required.includes(A),($=o[A])!=null&&$.oneOf&&((m=o[A])==null||delete m.oneOf),(P=p.title)!=null&&P.includes("<")&&((_=p.title)!=null&&_.includes(">"))){const O=p.title.split("<")[1].slice(0,-1),Z=p.title.split("<")[0];p.type=Z,p.resource.includes(":")?p.resource=O.split(":")[1]:p.resource=O}else["asset","entry","assets","entries"].includes(p.title)?(p.type=p.title,p.resource=null):p.type=p.title;delete o[A].title}return o})}function G(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),h=y(`a/${t}/${e}?${i}`,n);return(yield g(h,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function H(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=u({size:50,page:1,_list:!0},a);const i=w(a),h=y(`a/${e}/${s}?${i}`,t),{count:o,total:l,_embedded:$}=yield g(h,{dmShortID:e,token:r});let m=$?$["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:o,total:l,items:m}})}function I(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:i}){d({env:n,dmShortID:t,assetGroup:e,file:r});const o=y(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),i&&Object.keys(i).forEach(m=>{l.append(m,i[m])}),(yield g(o,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function Q(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function W(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function X(n){return c(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=u({size:25,page:1,_list:!0},e);const s=w(e),r=y(`?${s}`,t),{count:a,total:i,_embedded:h}=yield g(r,n);let o=h?h["ec:datamanager"]:[];return o=Array.isArray(o)?o:[o],{count:a,total:i,items:o}})}function Y(n){return c(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=u({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),a=y(`model?${r}`,t),{count:i,total:h,_embedded:o}=yield g(a,n);let l=o?o["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:i,total:h,items:l}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:I,createEntry:M,deleteAsset:Q,deleteEntry:v,dmList:X,editEntry:U,entryList:C,getAsset:G,getDatamanager:W,getEcAuthKey:N,getEntry:F,getPublicAuthKey:J,getSchema:V,loginEc:D,loginPublic:q,logoutEc:x,logoutPublic:K,modelList:Y,publicApi:z},Symbol.toStringTag,{value:"Module"})),{entryList:ct,getEntry:at,getAsset:ut,assetList:lt,createAsset:ht,deleteAsset:dt,createEntry:gt,editEntry:yt,deleteEntry:ft,getSchema:pt,loginPublic:$t,loginEc:mt,logoutEc:wt,logoutPublic:At,getEcAuthKey:b,getPublicAuthKey:T,dmList:kt,modelList:Et,publicApi:bt,getDatamanager:Tt}=k;function Pt(n){const{action:t}=n;if(d({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(u(u({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return ct(f(u({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}getEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return at(f(u({},this.config),{entryID:t,token:e}))})}getSchema(){return c(this,null,function*(){return pt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return lt(f(u({},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,options:s}={}){const r=yield this.getBestToken();return ht(f(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return dt(f(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ut(f(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(f(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return yt(f(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return ft(f(u({},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 mt(u(u({},this.config),t)).then(this.setAuth(b(this.config)))}loginPublic(t){return $t(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),At(f(u({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),wt(f(u({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}getPublicToken(){return this.config.token||this.getAuth(T(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})}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 bt(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Tt(f(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return kt(f(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Et(f(u({},this.config),{options:t,token:e}))})}}const _t=n=>new E({env:n});exports.Sdk=E;exports.act=Pt;exports.apiURL=y;exports.assetList=H;exports.createAsset=I;exports.createEntry=M;exports.deleteAsset=Q;exports.deleteEntry=v;exports.dmList=X;exports.editEntry=U;exports.entryList=C;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=W;exports.getEcAuthKey=N;exports.getEntry=F;exports.getPublicAuthKey=J;exports.getSchema=V;exports.loginEc=D;exports.loginPublic=q;exports.logoutEc=x;exports.logoutPublic=K;exports.modelList=Y;exports.publicApi=z;exports.query=w;exports.sdk=_t;
package/dist/index.mjs CHANGED
@@ -1,60 +1,60 @@
1
- var D = Object.defineProperty, K = Object.defineProperties;
2
- var x = Object.getOwnPropertyDescriptors;
1
+ var K = Object.defineProperty, x = Object.defineProperties;
2
+ var J = Object.getOwnPropertyDescriptors;
3
3
  var L = Object.getOwnPropertySymbols;
4
- var z = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable;
5
- var O = (n, t, e) => t in n ? D(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, l = (n, t) => {
4
+ var N = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
5
+ var j = (n, t, e) => t in n ? K(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, u = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
- z.call(t, e) && O(n, e, t[e]);
7
+ N.call(t, e) && j(n, e, t[e]);
8
8
  if (L)
9
9
  for (var e of L(t))
10
- C.call(t, e) && O(n, e, t[e]);
10
+ z.call(t, e) && j(n, e, t[e]);
11
11
  return n;
12
- }, y = (n, t) => K(n, x(t));
13
- var o = (n, t, e) => new Promise((s, r) => {
14
- var c = (a) => {
12
+ }, f = (n, t) => x(n, J(t));
13
+ var a = (n, t, e) => new Promise((s, r) => {
14
+ var c = (o) => {
15
15
  try {
16
- u(e.next(a));
17
- } catch (h) {
18
- r(h);
16
+ h(e.next(o));
17
+ } catch (l) {
18
+ r(l);
19
19
  }
20
- }, i = (a) => {
20
+ }, i = (o) => {
21
21
  try {
22
- u(e.throw(a));
23
- } catch (h) {
24
- r(h);
22
+ h(e.throw(o));
23
+ } catch (l) {
24
+ r(l);
25
25
  }
26
- }, u = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(c, i);
27
- u((e = e.apply(n, t)).next());
26
+ }, h = (o) => o.done ? s(o.value) : Promise.resolve(o.value).then(c, i);
27
+ h((e = e.apply(n, t)).next());
28
28
  });
29
29
  function g(s) {
30
- return o(this, arguments, function* (n, t = {}, e = {}) {
31
- var u;
30
+ return a(this, arguments, function* (n, t = {}, e = {}) {
31
+ var h;
32
32
  const { token: r, rawRes: c } = t;
33
- r && (e.headers = y(l({}, e.headers || {}), {
33
+ r && (e.headers = f(u({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${r}`
35
35
  }));
36
36
  const i = yield fetch(n, e);
37
37
  if (!i.ok) {
38
- if ((u = i.headers.get("content-type")) != null && u.includes("application/json")) {
39
- const a = yield i.json(), h = `${a.title}
40
- ${a.detail}
41
- ${a.verbose}`;
42
- throw new Error(h);
38
+ if ((h = i.headers.get("content-type")) != null && h.includes("application/json")) {
39
+ const o = yield i.json(), l = `${o.title}
40
+ ${o.detail}
41
+ ${o.verbose}`;
42
+ throw new Error(l);
43
43
  }
44
44
  throw new Error(`unexpected fetch error: ${i.statusText}`);
45
45
  }
46
46
  return c ? i : yield i.json();
47
47
  });
48
48
  }
49
- const j = {
49
+ const S = {
50
50
  live: "https://datamanager.entrecode.de/",
51
51
  stage: "https://datamanager.cachena.entrecode.de/"
52
52
  };
53
- function f(n, t = "stage") {
54
- const e = j[t];
53
+ function y(n, t = "stage") {
54
+ const e = S[t];
55
55
  if (!e)
56
56
  throw new Error(
57
- `env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`
57
+ `env "${t}" not found. Try one of ${Object.keys(S).join(", ")}`
58
58
  );
59
59
  return e + n;
60
60
  }
@@ -67,15 +67,15 @@ function d(n) {
67
67
  throw new Error(`expected ${t} to be set!`);
68
68
  });
69
69
  }
70
- const S = {
70
+ const B = {
71
71
  stage: "https://accounts.cachena.entrecode.de/",
72
72
  live: "https://accounts.entrecode.de/"
73
73
  };
74
- function R(n) {
75
- return o(this, null, function* () {
74
+ function C(n) {
75
+ return a(this, null, function* () {
76
76
  let { env: t, dmShortID: e, email: s, password: r } = n;
77
77
  d({ env: t, dmShortID: e, email: s, password: r });
78
- const c = f(`api/${e}/_auth/login?clientID=rest`, t);
78
+ const c = y(`api/${e}/_auth/login?clientID=rest`, t);
79
79
  return yield g(
80
80
  c,
81
81
  {},
@@ -89,11 +89,11 @@ function R(n) {
89
89
  );
90
90
  });
91
91
  }
92
- function v(n) {
93
- return o(this, null, function* () {
92
+ function R(n) {
93
+ return a(this, null, function* () {
94
94
  let { env: t, email: e, password: s } = n;
95
95
  d({ env: t, email: e, password: s });
96
- const r = `${S[t]}auth/login?clientID=rest`;
96
+ const r = `${B[t]}auth/login?clientID=rest`;
97
97
  return yield g(
98
98
  r,
99
99
  {},
@@ -107,11 +107,11 @@ function v(n) {
107
107
  );
108
108
  });
109
109
  }
110
- function J(n) {
111
- return o(this, null, function* () {
110
+ function F(n) {
111
+ return a(this, null, function* () {
112
112
  let { dmShortID: t, env: e, token: s } = n;
113
113
  d({ dmShortID: t, env: e, token: s });
114
- const r = f(
114
+ const r = y(
115
115
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
116
116
  e
117
117
  );
@@ -124,11 +124,11 @@ function J(n) {
124
124
  );
125
125
  });
126
126
  }
127
- function N(n) {
128
- return o(this, null, function* () {
127
+ function M(n) {
128
+ return a(this, null, function* () {
129
129
  let { env: t, token: e } = n;
130
130
  d({ env: t, token: e });
131
- const s = `${S[t]}auth/logout?clientID=rest`;
131
+ const s = `${B[t]}auth/logout?clientID=rest`;
132
132
  return yield g(
133
133
  s,
134
134
  {
@@ -141,38 +141,63 @@ function N(n) {
141
141
  );
142
142
  });
143
143
  }
144
- function M({ dmShortID: n }) {
144
+ function U({ dmShortID: n }) {
145
145
  return d({ dmShortID: n }), n;
146
146
  }
147
- function F({ env: n }) {
147
+ function v({ env: n }) {
148
148
  return d({ env: n }), n;
149
149
  }
150
- function U(n) {
151
- return o(this, null, function* () {
150
+ let V = [
151
+ "created",
152
+ "creator",
153
+ "id",
154
+ "modified",
155
+ "private",
156
+ "_created",
157
+ "_creator",
158
+ "_embedded",
159
+ "_entryTitle",
160
+ "_id",
161
+ "_links",
162
+ "_modelTitle",
163
+ "_modelTitleField",
164
+ "_modified"
165
+ ];
166
+ function q(n) {
167
+ let t = {};
168
+ for (let e in n)
169
+ V.includes(e) || (t[e] = n[e]);
170
+ return t;
171
+ }
172
+ function G(n) {
173
+ return JSON.parse(JSON.stringify(n));
174
+ }
175
+ function H(n) {
176
+ return a(this, null, function* () {
152
177
  let { env: t, dmShortID: e } = n;
153
178
  d({ env: t, dmShortID: e });
154
- const s = f(`api/${e}`, t);
179
+ const s = y(`api/${e}`, t);
155
180
  return g(s, n);
156
181
  });
157
182
  }
158
- function G(n) {
159
- return o(this, null, function* () {
183
+ function I(n) {
184
+ return a(this, null, function* () {
160
185
  let { env: t, dmShortID: e, model: s, options: r = {} } = n;
161
- d({ env: t, dmShortID: e, model: s }), r = l({ size: 50, page: 1, _list: !0 }, r);
162
- const c = w(r), i = f(`api/${e}/${s}?${c}`, t), { count: u, total: a, _embedded: h } = yield g(i, n);
163
- let $ = h ? h[`${e}:${s}`] : [];
164
- return $ = Array.isArray($) ? $ : [$], { count: u, total: a, items: $ };
186
+ d({ env: t, dmShortID: e, model: s }), r = u({ size: 50, page: 1, _list: !0 }, r);
187
+ const c = w(r), i = y(`api/${e}/${s}?${c}`, t), { count: h, total: o, _embedded: l } = yield g(i, n);
188
+ let $ = l ? l[`${e}:${s}`] : [];
189
+ return $ = Array.isArray($) ? $ : [$], { count: h, total: o, items: $ };
165
190
  });
166
191
  }
167
- function H({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
192
+ function Q({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
168
193
  d({ env: n, dmShortID: t, model: e, entryID: s });
169
- const c = w({ _id: s }), i = f(`api/${t}/${e}?${c}`, n);
194
+ const c = w({ _id: s }), i = y(`api/${t}/${e}?${c}`, n);
170
195
  return g(i, { dmShortID: t, token: r });
171
196
  }
172
- function I(c) {
173
- return o(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
197
+ function W(c) {
198
+ return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
174
199
  d({ env: n, dmShortID: t, model: e, value: s });
175
- const i = f(`api/${t}/${e}`, n);
200
+ const i = y(`api/${t}/${e}`, n);
176
201
  return yield g(
177
202
  i,
178
203
  { env: n, dmShortID: t, token: r },
@@ -186,8 +211,8 @@ function I(c) {
186
211
  );
187
212
  });
188
213
  }
189
- function Q(i) {
190
- return o(this, arguments, function* ({
214
+ function X(i) {
215
+ return a(this, arguments, function* ({
191
216
  env: n,
192
217
  dmShortID: t,
193
218
  model: e,
@@ -196,9 +221,9 @@ function Q(i) {
196
221
  token: c
197
222
  }) {
198
223
  d({ env: n, dmShortID: t, model: e, entryID: s, value: r });
199
- const u = f(`api/${t}/${e}?_id=${s}`, n);
200
- return yield g(
201
- u,
224
+ const h = y(`api/${t}/${e}?_id=${s}`, n);
225
+ return r = G(r), r = q(r), yield g(
226
+ h,
202
227
  { token: c },
203
228
  {
204
229
  method: "PUT",
@@ -210,10 +235,10 @@ function Q(i) {
210
235
  );
211
236
  });
212
237
  }
213
- function V(c) {
214
- return o(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
238
+ function Y(c) {
239
+ return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
215
240
  d({ env: n, dmShortID: t, model: e, entryID: s });
216
- const i = f(`api/${t}/${e}?_id=${s}`, n);
241
+ const i = y(`api/${t}/${e}?_id=${s}`, n);
217
242
  yield g(
218
243
  i,
219
244
  { token: r, rawRes: !0 },
@@ -226,66 +251,46 @@ function V(c) {
226
251
  );
227
252
  });
228
253
  }
229
- function W(s) {
230
- return o(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
231
- var h, $, m, P, _;
254
+ function Z(s) {
255
+ return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
256
+ var l, $, m, P, _;
232
257
  d({ env: n, dmShortID: t, model: e });
233
- const r = f(`api/schema/${t}/${e}`, n), c = yield g(r), i = (h = c == null ? void 0 : c.allOf) == null ? void 0 : h[1];
258
+ const r = y(`api/schema/${t}/${e}`, n), c = yield g(r), i = (l = c == null ? void 0 : c.allOf) == null ? void 0 : l[1];
234
259
  if (typeof i.properties != "object")
235
260
  throw new Error(
236
261
  `getSchema: ${r} returned unexpected format: ${JSON.stringify(c)}`
237
262
  );
238
- const { properties: u } = i;
239
- let a = [
240
- "created",
241
- "creator",
242
- "id",
243
- "modified",
244
- "private",
245
- "_created",
246
- "_creator",
247
- "_embedded",
248
- "_entryTitle",
249
- "_id",
250
- "_links",
251
- "_modelTitle",
252
- "_modelTitleField",
253
- "_modified"
254
- ];
255
- for (let A in u) {
256
- let p = u[A];
257
- if (p.required = i.required.includes(A), a.includes(A)) {
258
- delete u[A];
259
- continue;
260
- }
261
- if (($ = u[A]) != null && $.oneOf && ((m = u[A]) == null || delete m.oneOf), (P = p.title) != null && P.includes("<") && ((_ = p.title) != null && _.includes(">"))) {
262
- const B = p.title.split("<")[1].slice(0, -1), q = p.title.split("<")[0];
263
- p.type = q, p.resource = B;
263
+ const { properties: h } = i, o = q(h);
264
+ for (let A in o) {
265
+ let p = o[A];
266
+ if (p.required = i.required.includes(A), ($ = o[A]) != null && $.oneOf && ((m = o[A]) == null || delete m.oneOf), (P = p.title) != null && P.includes("<") && ((_ = p.title) != null && _.includes(">"))) {
267
+ const O = p.title.split("<")[1].slice(0, -1), D = p.title.split("<")[0];
268
+ p.type = D, p.resource.includes(":") ? p.resource = O.split(":")[1] : p.resource = O;
264
269
  } else
265
270
  ["asset", "entry", "assets", "entries"].includes(p.title) ? (p.type = p.title, p.resource = null) : p.type = p.title;
266
- delete u[A].title;
271
+ delete o[A].title;
267
272
  }
268
- return u;
273
+ return o;
269
274
  });
270
275
  }
271
- function X(c) {
272
- return o(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
276
+ function tt(c) {
277
+ return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
273
278
  d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
274
- const i = w({ assetID: s }), u = f(`a/${t}/${e}?${i}`, n);
275
- return (yield g(u, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
279
+ const i = w({ assetID: s }), h = y(`a/${t}/${e}?${i}`, n);
280
+ return (yield g(h, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
276
281
  });
277
282
  }
278
- function Y(n) {
279
- return o(this, null, function* () {
283
+ function et(n) {
284
+ return a(this, null, function* () {
280
285
  let { env: t, dmShortID: e, assetGroup: s, token: r, options: c = {} } = n;
281
- d({ env: t, dmShortID: e, assetGroup: s }), c = l({ size: 50, page: 1, _list: !0 }, c);
282
- const i = w(c), u = f(`a/${e}/${s}?${i}`, t), { count: a, total: h, _embedded: $ } = yield g(u, { dmShortID: e, token: r });
286
+ d({ env: t, dmShortID: e, assetGroup: s }), c = u({ size: 50, page: 1, _list: !0 }, c);
287
+ const i = w(c), h = y(`a/${e}/${s}?${i}`, t), { count: o, total: l, _embedded: $ } = yield g(h, { dmShortID: e, token: r });
283
288
  let m = $ ? $["ec:dm-asset"] : [];
284
- return m = Array.isArray(m) ? m : [m], { count: a, total: h, items: m };
289
+ return m = Array.isArray(m) ? m : [m], { count: o, total: l, items: m };
285
290
  });
286
291
  }
287
- function Z(u) {
288
- return o(this, arguments, function* ({
292
+ function nt(h) {
293
+ return a(this, arguments, function* ({
289
294
  env: n,
290
295
  dmShortID: t,
291
296
  assetGroup: e,
@@ -295,21 +300,21 @@ function Z(u) {
295
300
  options: i
296
301
  }) {
297
302
  d({ env: n, dmShortID: t, assetGroup: e, file: r });
298
- const a = f(`a/${t}/${e}`, n), h = new FormData();
299
- return h.append("file", r, c), i && Object.keys(i).forEach((m) => {
300
- h.append(m, i[m]);
303
+ const o = y(`a/${t}/${e}`, n), l = new FormData();
304
+ return l.append("file", r, c), i && Object.keys(i).forEach((m) => {
305
+ l.append(m, i[m]);
301
306
  }), (yield g(
302
- a,
307
+ o,
303
308
  { token: s },
304
309
  {
305
310
  method: "POST",
306
- body: h
311
+ body: l
307
312
  }
308
313
  ))._embedded["ec:dm-asset"];
309
314
  });
310
315
  }
311
- function tt(c) {
312
- return o(this, arguments, function* ({
316
+ function st(c) {
317
+ return a(this, arguments, function* ({
313
318
  env: n,
314
319
  dmShortID: t,
315
320
  assetGroup: e,
@@ -317,7 +322,7 @@ function tt(c) {
317
322
  token: r
318
323
  }) {
319
324
  d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
320
- const i = f(`a/${t}/${e}/${s}`, n);
325
+ const i = y(`a/${t}/${e}/${s}`, n);
321
326
  yield g(
322
327
  i,
323
328
  { token: r, rawRes: !0 },
@@ -327,92 +332,92 @@ function tt(c) {
327
332
  );
328
333
  });
329
334
  }
330
- function et(n) {
331
- return o(this, null, function* () {
335
+ function rt(n) {
336
+ return a(this, null, function* () {
332
337
  let { env: t, dmID: e, token: s } = n;
333
338
  d({ env: t, dmID: e });
334
- const r = f(`?dataManagerID=${e}`, t);
339
+ const r = y(`?dataManagerID=${e}`, t);
335
340
  return g(r, { token: s });
336
341
  });
337
342
  }
338
- function nt(n) {
339
- return o(this, null, function* () {
343
+ function it(n) {
344
+ return a(this, null, function* () {
340
345
  let { env: t, options: e = {} } = n;
341
- d({ env: t }), e = l({ size: 25, page: 1, _list: !0 }, e);
342
- const s = w(e), r = f(`?${s}`, t), { count: c, total: i, _embedded: u } = yield g(r, n);
343
- let a = u ? u["ec:datamanager"] : [];
344
- return a = Array.isArray(a) ? a : [a], { count: c, total: i, items: a };
346
+ d({ env: t }), e = u({ size: 25, page: 1, _list: !0 }, e);
347
+ const s = w(e), r = y(`?${s}`, t), { count: c, total: i, _embedded: h } = yield g(r, n);
348
+ let o = h ? h["ec:datamanager"] : [];
349
+ return o = Array.isArray(o) ? o : [o], { count: c, total: i, items: o };
345
350
  });
346
351
  }
347
- function st(n) {
348
- return o(this, null, function* () {
352
+ function ot(n) {
353
+ return a(this, null, function* () {
349
354
  let { env: t, dmID: e, options: s = {} } = n;
350
- d({ env: t, dmID: e }), s = l({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
351
- const r = w(s), c = f(`model?${r}`, t), { count: i, total: u, _embedded: a } = yield g(c, n);
352
- let h = a ? a["ec:model"] : [];
353
- return h = Array.isArray(h) ? h : [h], { count: i, total: u, items: h };
355
+ d({ env: t, dmID: e }), s = u({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
356
+ const r = w(s), c = y(`model?${r}`, t), { count: i, total: h, _embedded: o } = yield g(c, n);
357
+ let l = o ? o["ec:model"] : [];
358
+ return l = Array.isArray(l) ? l : [l], { count: i, total: h, items: l };
354
359
  });
355
360
  }
356
- const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
361
+ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
357
362
  __proto__: null,
358
- assetList: Y,
359
- createAsset: Z,
360
- createEntry: I,
361
- deleteAsset: tt,
362
- deleteEntry: V,
363
- dmList: nt,
364
- editEntry: Q,
365
- entryList: G,
366
- getAsset: X,
367
- getDatamanager: et,
368
- getEcAuthKey: F,
369
- getEntry: H,
370
- getPublicAuthKey: M,
371
- getSchema: W,
372
- loginEc: v,
373
- loginPublic: R,
374
- logoutEc: N,
375
- logoutPublic: J,
376
- modelList: st,
377
- publicApi: U
363
+ assetList: et,
364
+ createAsset: nt,
365
+ createEntry: W,
366
+ deleteAsset: st,
367
+ deleteEntry: Y,
368
+ dmList: it,
369
+ editEntry: X,
370
+ entryList: I,
371
+ getAsset: tt,
372
+ getDatamanager: rt,
373
+ getEcAuthKey: v,
374
+ getEntry: Q,
375
+ getPublicAuthKey: U,
376
+ getSchema: Z,
377
+ loginEc: R,
378
+ loginPublic: C,
379
+ logoutEc: M,
380
+ logoutPublic: F,
381
+ modelList: ot,
382
+ publicApi: H
378
383
  }, Symbol.toStringTag, { value: "Module" })), {
379
- entryList: rt,
380
- getEntry: it,
381
- getAsset: ot,
382
- assetList: at,
383
- createAsset: ct,
384
- deleteAsset: ut,
385
- createEntry: lt,
386
- editEntry: ht,
387
- deleteEntry: dt,
388
- getSchema: gt,
389
- loginPublic: yt,
390
- loginEc: ft,
391
- logoutEc: pt,
392
- logoutPublic: $t,
393
- getEcAuthKey: E,
384
+ entryList: at,
385
+ getEntry: ct,
386
+ getAsset: ut,
387
+ assetList: lt,
388
+ createAsset: ht,
389
+ deleteAsset: dt,
390
+ createEntry: gt,
391
+ editEntry: ft,
392
+ deleteEntry: yt,
393
+ getSchema: pt,
394
+ loginPublic: $t,
395
+ loginEc: mt,
396
+ logoutEc: wt,
397
+ logoutPublic: At,
398
+ getEcAuthKey: k,
394
399
  getPublicAuthKey: b,
395
- dmList: mt,
396
- modelList: At,
397
- publicApi: wt,
398
- getDatamanager: kt
399
- } = k;
400
- function bt(n) {
400
+ dmList: Et,
401
+ modelList: kt,
402
+ publicApi: bt,
403
+ getDatamanager: Tt
404
+ } = E;
405
+ function _t(n) {
401
406
  const { action: t } = n;
402
- if (d({ action: t }), !k[t])
407
+ if (d({ action: t }), !E[t])
403
408
  throw new Error(
404
- `"${t}" does not exist! try one of ${Object.keys(k).join(
409
+ `"${t}" does not exist! try one of ${Object.keys(E).join(
405
410
  ", "
406
411
  )}`
407
412
  );
408
- return k[t](n);
413
+ return E[t](n);
409
414
  }
410
415
  class T {
411
416
  constructor(t) {
412
417
  this.config = t;
413
418
  }
414
419
  set(t) {
415
- return new T(l(l({}, this.config), t));
420
+ return new T(u(u({}, this.config), t));
416
421
  }
417
422
  /**
418
423
  * Loads entry list. Expects `dmShortID` / `model` to be set.
@@ -428,13 +433,13 @@ class T {
428
433
  * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
429
434
  */
430
435
  entries() {
431
- return o(this, arguments, function* (t = {}) {
436
+ return a(this, arguments, function* (t = {}) {
432
437
  const e = yield this.getBestToken();
433
- return rt(y(l({}, this.config), { options: t, token: e }));
438
+ return at(f(u({}, this.config), { options: t, token: e }));
434
439
  });
435
440
  }
436
441
  entryList(t) {
437
- return o(this, null, function* () {
442
+ return a(this, null, function* () {
438
443
  return this.entries(t);
439
444
  });
440
445
  }
@@ -448,9 +453,9 @@ class T {
448
453
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
449
454
  */
450
455
  getEntry(t) {
451
- return o(this, null, function* () {
456
+ return a(this, null, function* () {
452
457
  const e = yield this.getBestToken();
453
- return it(y(l({}, this.config), { entryID: t, token: e }));
458
+ return ct(f(u({}, this.config), { entryID: t, token: e }));
454
459
  });
455
460
  }
456
461
  /**
@@ -462,8 +467,8 @@ class T {
462
467
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getSchema()
463
468
  */
464
469
  getSchema() {
465
- return o(this, null, function* () {
466
- return gt(this.config);
470
+ return a(this, null, function* () {
471
+ return pt(this.config);
467
472
  });
468
473
  }
469
474
  /**
@@ -480,13 +485,13 @@ class T {
480
485
  * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
481
486
  */
482
487
  assets(t) {
483
- return o(this, null, function* () {
488
+ return a(this, null, function* () {
484
489
  const e = yield this.getBestToken();
485
- return at(y(l({}, this.config), { options: t, token: e }));
490
+ return lt(f(u({}, this.config), { options: t, token: e }));
486
491
  });
487
492
  }
488
493
  assetList(t) {
489
- return o(this, null, function* () {
494
+ return a(this, null, function* () {
490
495
  return this.assets(t);
491
496
  });
492
497
  }
@@ -512,9 +517,9 @@ class T {
512
517
  * .createAsset({ file, name: "venndiagram.png" });
513
518
  */
514
519
  createAsset() {
515
- return o(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
520
+ return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
516
521
  const r = yield this.getBestToken();
517
- return ct(y(l({}, this.config), { file: t, name: e, options: s, token: r }));
522
+ return ht(f(u({}, this.config), { file: t, name: e, options: s, token: r }));
518
523
  });
519
524
  }
520
525
  /**
@@ -527,9 +532,9 @@ class T {
527
532
  * await ecadmin.assetgroup("test").deleteAsset('xxxx');
528
533
  */
529
534
  deleteAsset(t) {
530
- return o(this, null, function* () {
535
+ return a(this, null, function* () {
531
536
  const e = yield this.getBestToken();
532
- return ut(y(l({}, this.config), { token: e, assetID: t }));
537
+ return dt(f(u({}, this.config), { token: e, assetID: t }));
533
538
  });
534
539
  }
535
540
  /**
@@ -542,9 +547,9 @@ class T {
542
547
  * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
543
548
  */
544
549
  getAsset(t) {
545
- return o(this, null, function* () {
550
+ return a(this, null, function* () {
546
551
  const e = yield this.getBestToken();
547
- return ot(y(l({}, this.config), { assetID: t, token: e }));
552
+ return ut(f(u({}, this.config), { assetID: t, token: e }));
548
553
  });
549
554
  }
550
555
  /**
@@ -557,9 +562,9 @@ class T {
557
562
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
558
563
  */
559
564
  createEntry(t) {
560
- return o(this, null, function* () {
565
+ return a(this, null, function* () {
561
566
  const e = yield this.getBestToken();
562
- return lt(y(l({}, this.config), { token: e, value: t }));
567
+ return gt(f(u({}, this.config), { token: e, value: t }));
563
568
  });
564
569
  }
565
570
  /**
@@ -573,9 +578,9 @@ class T {
573
578
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
574
579
  */
575
580
  editEntry(t, e) {
576
- return o(this, null, function* () {
581
+ return a(this, null, function* () {
577
582
  const s = yield this.getBestToken();
578
- return ht(y(l({}, this.config), { entryID: t, token: s, value: e }));
583
+ return ft(f(u({}, this.config), { entryID: t, token: s, value: e }));
579
584
  });
580
585
  }
581
586
  /**
@@ -588,9 +593,9 @@ class T {
588
593
  * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
589
594
  */
590
595
  deleteEntry(t) {
591
- return o(this, null, function* () {
596
+ return a(this, null, function* () {
592
597
  const e = yield this.getBestToken();
593
- return dt(y(l({}, this.config), { token: e, entryID: t }));
598
+ return yt(f(u({}, this.config), { token: e, entryID: t }));
594
599
  });
595
600
  }
596
601
  // TODO: rename authAdapter -> storageAdapter
@@ -620,32 +625,32 @@ class T {
620
625
  return e(t);
621
626
  }
622
627
  loginEc(t) {
623
- return ft(l(l({}, this.config), t)).then(
624
- this.setAuth(E(this.config))
628
+ return mt(u(u({}, this.config), t)).then(
629
+ this.setAuth(k(this.config))
625
630
  );
626
631
  }
627
632
  loginPublic(t) {
628
- return yt(l(l({}, this.config), t)).then(
633
+ return $t(u(u({}, this.config), t)).then(
629
634
  this.setAuth(b(this.config))
630
635
  );
631
636
  }
632
637
  logoutPublic() {
633
638
  const t = this.getPublicToken();
634
- return console.log("token", t), $t(y(l({}, this.config), { token: t })).then(
639
+ return console.log("token", t), At(f(u({}, this.config), { token: t })).then(
635
640
  this.unsetAuth(b(this.config))
636
641
  );
637
642
  }
638
643
  logoutEc() {
639
644
  const t = this.getEcToken();
640
- return console.log("token", t), pt(y(l({}, this.config), { token: t })).then(
641
- this.unsetAuth(E(this.config))
645
+ return console.log("token", t), wt(f(u({}, this.config), { token: t })).then(
646
+ this.unsetAuth(k(this.config))
642
647
  );
643
648
  }
644
649
  getPublicToken() {
645
650
  return this.config.token || this.getAuth(b(this.config));
646
651
  }
647
652
  getEcToken() {
648
- return this.config.token || this.getAuth(E(this.config));
653
+ return this.config.token || this.getAuth(k(this.config));
649
654
  }
650
655
  hasPublicToken() {
651
656
  return !!this.getPublicToken();
@@ -724,16 +729,16 @@ class T {
724
729
  * @returns any
725
730
  */
726
731
  publicApi() {
727
- return wt(this.config);
732
+ return bt(this.config);
728
733
  }
729
734
  /**
730
735
  * Loads a DatamanagerResource by its long id. Requires token.
731
736
  * @returns any
732
737
  */
733
738
  getDatamanager(t) {
734
- return o(this, null, function* () {
739
+ return a(this, null, function* () {
735
740
  const e = yield this.getBestToken();
736
- return kt(y(l({}, this.config), { dmID: t, token: e }));
741
+ return Tt(f(u({}, this.config), { dmID: t, token: e }));
737
742
  });
738
743
  }
739
744
  /**
@@ -745,9 +750,9 @@ class T {
745
750
  * const dms = await sdk("stage").dmList()
746
751
  */
747
752
  dmList() {
748
- return o(this, arguments, function* (t = {}) {
753
+ return a(this, arguments, function* (t = {}) {
749
754
  const e = yield this.getBestToken();
750
- return mt(y(l({}, this.config), { options: t, token: e }));
755
+ return Et(f(u({}, this.config), { options: t, token: e }));
751
756
  });
752
757
  }
753
758
  /**
@@ -759,39 +764,39 @@ class T {
759
764
  * const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
760
765
  */
761
766
  modelList() {
762
- return o(this, arguments, function* (t = {}) {
767
+ return a(this, arguments, function* (t = {}) {
763
768
  const e = yield this.getBestToken();
764
- return At(y(l({}, this.config), { options: t, token: e }));
769
+ return kt(f(u({}, this.config), { options: t, token: e }));
765
770
  });
766
771
  }
767
772
  }
768
- const Tt = (n) => new T({ env: n });
773
+ const Ot = (n) => new T({ env: n });
769
774
  export {
770
775
  T as Sdk,
771
- bt as act,
772
- f as apiURL,
773
- Y as assetList,
774
- Z as createAsset,
775
- I as createEntry,
776
- tt as deleteAsset,
777
- V as deleteEntry,
778
- nt as dmList,
779
- Q as editEntry,
780
- G as entryList,
776
+ _t as act,
777
+ y as apiURL,
778
+ et as assetList,
779
+ nt as createAsset,
780
+ W as createEntry,
781
+ st as deleteAsset,
782
+ Y as deleteEntry,
783
+ it as dmList,
784
+ X as editEntry,
785
+ I as entryList,
781
786
  d as expect,
782
787
  g as fetcher,
783
- X as getAsset,
784
- et as getDatamanager,
785
- F as getEcAuthKey,
786
- H as getEntry,
787
- M as getPublicAuthKey,
788
- W as getSchema,
789
- v as loginEc,
790
- R as loginPublic,
791
- N as logoutEc,
792
- J as logoutPublic,
793
- st as modelList,
794
- U as publicApi,
788
+ tt as getAsset,
789
+ rt as getDatamanager,
790
+ v as getEcAuthKey,
791
+ Q as getEntry,
792
+ U as getPublicAuthKey,
793
+ Z as getSchema,
794
+ R as loginEc,
795
+ C as loginPublic,
796
+ M as logoutEc,
797
+ F as logoutPublic,
798
+ ot as modelList,
799
+ H as publicApi,
795
800
  w as query,
796
- Tt as sdk
801
+ Ot as sdk
797
802
  };
@@ -37,5 +37,5 @@ export function getSchema({ env, dmShortID, model }: {
37
37
  env: any;
38
38
  dmShortID: any;
39
39
  model: any;
40
- }): Promise<any>;
40
+ }): Promise<{}>;
41
41
  //# sourceMappingURL=entries.d.mts.map
@@ -1 +1 @@
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;AAED;;;;iBAsDC"}
1
+ {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAiCA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;iBA0BC;AAED;;;;;;kBAcC;AAED;;;;gBAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {