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 +3 -3
- package/dist/index.mjs +244 -239
- package/dist/lib/entries.d.mts +1 -1
- package/dist/lib/entries.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${
|
|
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
|
|
2
|
-
var
|
|
1
|
+
var K = Object.defineProperty, x = Object.defineProperties;
|
|
2
|
+
var J = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var L = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
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
|
-
|
|
7
|
+
N.call(t, e) && j(n, e, t[e]);
|
|
8
8
|
if (L)
|
|
9
9
|
for (var e of L(t))
|
|
10
|
-
|
|
10
|
+
z.call(t, e) && j(n, e, t[e]);
|
|
11
11
|
return n;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var c = (
|
|
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
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
r(
|
|
16
|
+
h(e.next(o));
|
|
17
|
+
} catch (l) {
|
|
18
|
+
r(l);
|
|
19
19
|
}
|
|
20
|
-
}, i = (
|
|
20
|
+
}, i = (o) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
r(
|
|
22
|
+
h(e.throw(o));
|
|
23
|
+
} catch (l) {
|
|
24
|
+
r(l);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
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
|
|
31
|
-
var
|
|
30
|
+
return a(this, arguments, function* (n, t = {}, e = {}) {
|
|
31
|
+
var h;
|
|
32
32
|
const { token: r, rawRes: c } = t;
|
|
33
|
-
r && (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 ((
|
|
39
|
-
const
|
|
40
|
-
${
|
|
41
|
-
${
|
|
42
|
-
throw new Error(
|
|
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
|
|
49
|
+
const S = {
|
|
50
50
|
live: "https://datamanager.entrecode.de/",
|
|
51
51
|
stage: "https://datamanager.cachena.entrecode.de/"
|
|
52
52
|
};
|
|
53
|
-
function
|
|
54
|
-
const e =
|
|
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(
|
|
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
|
|
70
|
+
const B = {
|
|
71
71
|
stage: "https://accounts.cachena.entrecode.de/",
|
|
72
72
|
live: "https://accounts.entrecode.de/"
|
|
73
73
|
};
|
|
74
|
-
function
|
|
75
|
-
return
|
|
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 =
|
|
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
|
|
93
|
-
return
|
|
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 = `${
|
|
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
|
|
111
|
-
return
|
|
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 =
|
|
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
|
|
128
|
-
return
|
|
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 = `${
|
|
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
|
|
144
|
+
function U({ dmShortID: n }) {
|
|
145
145
|
return d({ dmShortID: n }), n;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function v({ env: n }) {
|
|
148
148
|
return d({ env: n }), n;
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
|
|
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 =
|
|
179
|
+
const s = y(`api/${e}`, t);
|
|
155
180
|
return g(s, n);
|
|
156
181
|
});
|
|
157
182
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
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 =
|
|
162
|
-
const c = w(r), i =
|
|
163
|
-
let $ =
|
|
164
|
-
return $ = Array.isArray($) ? $ : [$], { count:
|
|
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
|
|
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 =
|
|
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
|
|
173
|
-
return
|
|
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 =
|
|
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
|
|
190
|
-
return
|
|
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
|
|
200
|
-
return yield g(
|
|
201
|
-
|
|
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
|
|
214
|
-
return
|
|
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 =
|
|
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
|
|
230
|
-
return
|
|
231
|
-
var
|
|
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 =
|
|
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:
|
|
239
|
-
let
|
|
240
|
-
|
|
241
|
-
"
|
|
242
|
-
|
|
243
|
-
|
|
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
|
|
271
|
+
delete o[A].title;
|
|
267
272
|
}
|
|
268
|
-
return
|
|
273
|
+
return o;
|
|
269
274
|
});
|
|
270
275
|
}
|
|
271
|
-
function
|
|
272
|
-
return
|
|
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 }),
|
|
275
|
-
return (yield g(
|
|
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
|
|
279
|
-
return
|
|
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 =
|
|
282
|
-
const i = w(c),
|
|
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:
|
|
289
|
+
return m = Array.isArray(m) ? m : [m], { count: o, total: l, items: m };
|
|
285
290
|
});
|
|
286
291
|
}
|
|
287
|
-
function
|
|
288
|
-
return
|
|
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
|
|
299
|
-
return
|
|
300
|
-
|
|
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
|
-
|
|
307
|
+
o,
|
|
303
308
|
{ token: s },
|
|
304
309
|
{
|
|
305
310
|
method: "POST",
|
|
306
|
-
body:
|
|
311
|
+
body: l
|
|
307
312
|
}
|
|
308
313
|
))._embedded["ec:dm-asset"];
|
|
309
314
|
});
|
|
310
315
|
}
|
|
311
|
-
function
|
|
312
|
-
return
|
|
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 =
|
|
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
|
|
331
|
-
return
|
|
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 =
|
|
339
|
+
const r = y(`?dataManagerID=${e}`, t);
|
|
335
340
|
return g(r, { token: s });
|
|
336
341
|
});
|
|
337
342
|
}
|
|
338
|
-
function
|
|
339
|
-
return
|
|
343
|
+
function it(n) {
|
|
344
|
+
return a(this, null, function* () {
|
|
340
345
|
let { env: t, options: e = {} } = n;
|
|
341
|
-
d({ env: t }), e =
|
|
342
|
-
const s = w(e), r =
|
|
343
|
-
let
|
|
344
|
-
return
|
|
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
|
|
348
|
-
return
|
|
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 =
|
|
351
|
-
const r = w(s), c =
|
|
352
|
-
let
|
|
353
|
-
return
|
|
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
|
|
361
|
+
const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
357
362
|
__proto__: null,
|
|
358
|
-
assetList:
|
|
359
|
-
createAsset:
|
|
360
|
-
createEntry:
|
|
361
|
-
deleteAsset:
|
|
362
|
-
deleteEntry:
|
|
363
|
-
dmList:
|
|
364
|
-
editEntry:
|
|
365
|
-
entryList:
|
|
366
|
-
getAsset:
|
|
367
|
-
getDatamanager:
|
|
368
|
-
getEcAuthKey:
|
|
369
|
-
getEntry:
|
|
370
|
-
getPublicAuthKey:
|
|
371
|
-
getSchema:
|
|
372
|
-
loginEc:
|
|
373
|
-
loginPublic:
|
|
374
|
-
logoutEc:
|
|
375
|
-
logoutPublic:
|
|
376
|
-
modelList:
|
|
377
|
-
publicApi:
|
|
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:
|
|
380
|
-
getEntry:
|
|
381
|
-
getAsset:
|
|
382
|
-
assetList:
|
|
383
|
-
createAsset:
|
|
384
|
-
deleteAsset:
|
|
385
|
-
createEntry:
|
|
386
|
-
editEntry:
|
|
387
|
-
deleteEntry:
|
|
388
|
-
getSchema:
|
|
389
|
-
loginPublic:
|
|
390
|
-
loginEc:
|
|
391
|
-
logoutEc:
|
|
392
|
-
logoutPublic:
|
|
393
|
-
getEcAuthKey:
|
|
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:
|
|
396
|
-
modelList:
|
|
397
|
-
publicApi:
|
|
398
|
-
getDatamanager:
|
|
399
|
-
} =
|
|
400
|
-
function
|
|
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 }), !
|
|
407
|
+
if (d({ action: t }), !E[t])
|
|
403
408
|
throw new Error(
|
|
404
|
-
`"${t}" does not exist! try one of ${Object.keys(
|
|
409
|
+
`"${t}" does not exist! try one of ${Object.keys(E).join(
|
|
405
410
|
", "
|
|
406
411
|
)}`
|
|
407
412
|
);
|
|
408
|
-
return
|
|
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(
|
|
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
|
|
436
|
+
return a(this, arguments, function* (t = {}) {
|
|
432
437
|
const e = yield this.getBestToken();
|
|
433
|
-
return
|
|
438
|
+
return at(f(u({}, this.config), { options: t, token: e }));
|
|
434
439
|
});
|
|
435
440
|
}
|
|
436
441
|
entryList(t) {
|
|
437
|
-
return
|
|
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
|
|
456
|
+
return a(this, null, function* () {
|
|
452
457
|
const e = yield this.getBestToken();
|
|
453
|
-
return
|
|
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
|
|
466
|
-
return
|
|
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
|
|
488
|
+
return a(this, null, function* () {
|
|
484
489
|
const e = yield this.getBestToken();
|
|
485
|
-
return
|
|
490
|
+
return lt(f(u({}, this.config), { options: t, token: e }));
|
|
486
491
|
});
|
|
487
492
|
}
|
|
488
493
|
assetList(t) {
|
|
489
|
-
return
|
|
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
|
|
520
|
+
return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
|
|
516
521
|
const r = yield this.getBestToken();
|
|
517
|
-
return
|
|
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
|
|
535
|
+
return a(this, null, function* () {
|
|
531
536
|
const e = yield this.getBestToken();
|
|
532
|
-
return
|
|
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
|
|
550
|
+
return a(this, null, function* () {
|
|
546
551
|
const e = yield this.getBestToken();
|
|
547
|
-
return
|
|
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
|
|
565
|
+
return a(this, null, function* () {
|
|
561
566
|
const e = yield this.getBestToken();
|
|
562
|
-
return
|
|
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
|
|
581
|
+
return a(this, null, function* () {
|
|
577
582
|
const s = yield this.getBestToken();
|
|
578
|
-
return
|
|
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
|
|
596
|
+
return a(this, null, function* () {
|
|
592
597
|
const e = yield this.getBestToken();
|
|
593
|
-
return
|
|
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
|
|
624
|
-
this.setAuth(
|
|
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
|
|
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),
|
|
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),
|
|
641
|
-
this.unsetAuth(
|
|
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(
|
|
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
|
|
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
|
|
739
|
+
return a(this, null, function* () {
|
|
735
740
|
const e = yield this.getBestToken();
|
|
736
|
-
return
|
|
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
|
|
753
|
+
return a(this, arguments, function* (t = {}) {
|
|
749
754
|
const e = yield this.getBestToken();
|
|
750
|
-
return
|
|
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
|
|
767
|
+
return a(this, arguments, function* (t = {}) {
|
|
763
768
|
const e = yield this.getBestToken();
|
|
764
|
-
return
|
|
769
|
+
return kt(f(u({}, this.config), { options: t, token: e }));
|
|
765
770
|
});
|
|
766
771
|
}
|
|
767
772
|
}
|
|
768
|
-
const
|
|
773
|
+
const Ot = (n) => new T({ env: n });
|
|
769
774
|
export {
|
|
770
775
|
T as Sdk,
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
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
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
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
|
-
|
|
801
|
+
Ot as sdk
|
|
797
802
|
};
|
package/dist/lib/entries.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"
|
|
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"}
|