ec.fdk 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -0
- package/dist/lib/util.d.mts +18 -18
- package/dist/lib/util.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var ft=Object.defineProperty,pt=Object.defineProperties;var yt=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,$t=Object.prototype.propertyIsEnumerable;var C=(n,t,e)=>t in n?ft(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,o=(n,t)=>{for(var e in t||(t={}))mt.call(t,e)&&C(n,e,t[e]);if(z)for(var e of z(t))$t.call(t,e)&&C(n,e,t[e]);return n},f=(n,t)=>pt(n,yt(t));var a=(n,t,e)=>new Promise((s,r)=>{var l=c=>{try{d(e.next(c))}catch(u){r(u)}},i=c=>{try{d(e.throw(c))}catch(u){r(u)}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(l,i);d((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(s){return a(this,arguments,function*(n,t={},e={}){var d;const{token:r,rawRes:l}=t;r&&(e.headers=f(o({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((d=i.headers.get("content-type"))!=null&&d.includes("application/json")){const c=yield i.json(),u=`${c.title}
|
|
2
2
|
${c.detail}
|
|
3
|
-
${c.verbose}`;throw new Error(u)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return l?i:yield i.json()})}const b={datamanager:{live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"},accounts:{live:"https://accounts.entrecode.de/",stage:"https://accounts.cachena.entrecode.de/"},appserver:{live:"https://appserver.entrecode.de/",stage:"https://appserver.cachena.entrecode.de/"}};function y(n,t="stage",e="datamanager"){const s=b[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(b).join(", ")}`);const r=s[t];if(!r)throw new Error(`env "${t}" not found. Try one of ${Object.keys(s[t]).join(", ")}`);return r+n}function E(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const N={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function F(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const l=y(`api/${e}/_auth/login?clientID=rest`,t);return yield p(l,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function I(n){return a(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${N[t]}auth/login?clientID=rest`;return yield p(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function J(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield p(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function R(n){return a(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${N[t]}auth/logout?clientID=rest`;return yield p(s,{rawRes:!0,token:e},{method:"POST"})})}function U({dmShortID:n}){return h({dmShortID:n}),n}function M({env:n}){return h({env:n}),n}let Et=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function V(n){let t={};for(let e in n)Et.includes(e)||(t[e]=n[e]);return t}function wt(n){return JSON.parse(JSON.stringify(n))}function G(n){return a(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=y(`api/${e}`,t);return p(s,n)})}function P(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=o({size:50,page:1,_list:!0},r);const l=E(r),i=y(`api/${e}/${s}?${l}`,t),{count:d,total:c,_embedded:u}=yield p(i,n);let g=u?u[`${e}:${s}`]:[];return g=Array.isArray(g)?g:[g],{count:d,total:c,items:g}})}function H({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const l=E({_id:s}),i=y(`api/${t}/${e}?${l}`,n);return p(i,{dmShortID:t,token:r})}function Q(l){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield p(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function S(d){return a(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:l,safePut:i=!1}){h({env:n,dmShortID:t,model:e,entryID:s,value:r});const c={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");c["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const u=y(`api/${t}/${e}?_id=${s}`,n);return r=wt(r),r=V(r),yield p(u,{token:l},{method:"PUT",headers:c,body:JSON.stringify(r)})})}function L({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const l=y(`api/${t}/${e}?_id=${s}`,n);return p(l,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function W(n,t){return a(this,null,function*(){let{env:e,dmShortID:s,model:r,options:l={}}=n;h({env:e,dmShortID:s,model:r}),n.options=o({size:50,page:1,_list:!0},l);let i=0,d,c=[];for(;d===void 0||i<d;){const u=yield P(n);for(let g of u.items)c.push(yield t(g));i+=u.items.length,d=u.total,n.options.page++}return c})}function X(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var g,$,q,v,x;h({env:n,dmShortID:t,model:e});const l=y(`api/schema/${t}/${e}`,n),i=yield p(l),d=(g=i==null?void 0:i.allOf)==null?void 0:g[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${l} returned unexpected format: ${JSON.stringify(i)}`);const{properties:c}=d,u=V(c);for(let w in u){let m=u[w];if(m.required=d.required.includes(w),($=u[w])!=null&&$.oneOf&&((q=u[w])==null||delete q.oneOf),(v=m.title)!=null&&v.includes("<")&&((x=m.title)!=null&&x.includes(">"))){const _=m.title.split("<")[1].slice(0,-1),gt=m.title.split("<")[0];m.type=gt,_.includes(":")?m.resource=_.split(":")[1]:m.resource=_}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete u[w].title}if(s){const w=c._modelTitle.title,m=c._modelTitleField.title;return{properties:u,meta:{modelTitleField:m,modelTitle:w}}}return u})}function B(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:o(o(o(o(o(o(o({},e.sort&&{sort:Array.isArray(e)?e.join(","):e}),e.search&&{[t+"~"]:e.search}),e.notNull&&{[t+"!"]:""}),e.null&&{[t]:""}),e.any&&{[t]:e.any.join(",")}),e.from&&{[t+"From"]:e.from}),e.to&&{[t+"To"]:e.to})).reduce((t,e)=>o(o({},t),e),{})}const Y=B;function A(n){return n._links.collection.href.split("/").slice(-2)[0]}function D(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(b.datamanager).find(s=>b.datamanager[s]===t)}const Z=n=>{const t=A(n),e=D(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},tt=n=>L(Z(n)),et=(n,t)=>S(f(o({},Z(n)),{value:t}));function nt(n,t){const e=A(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function st(l){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=E({assetID:s}),d=y(`a/${t}/${e}?${i}`,n);return(yield p(d,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function rt(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:l={}}=n;h({env:t,dmShortID:e,assetGroup:s}),l=o({size:50,page:1,_list:!0},l);const i=E(l),d=y(`a/${e}/${s}?${i}`,t),{count:c,total:u,_embedded:g}=yield p(d,{dmShortID:e,token:r});let $=g?g["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:c,total:u,items:$}})}function it(d){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:l,options:i}){h({env:n,dmShortID:t,assetGroup:e,file:r});const c=y(`a/${t}/${e}`,n),u=new FormData;return u.append("file",r,l),i&&Object.keys(i).forEach($=>{u.append($,i[$])}),(yield p(c,{token:s},{method:"POST",body:u}))._embedded["ec:dm-asset"]})}function ot(l){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield p(i,{token:r,rawRes:!0},{method:"DELETE"})})}function ct(n){return a(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return p(r,{token:s})})}function at(n){return a(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=o({size:25,page:1,_list:!0},e);const s=E(e),r=y(`?${s}`,t),{count:l,total:i,_embedded:d}=yield p(r,n);let c=d?d["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:l,total:i,items:c}})}function ut(n){return a(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=o({size:25,dataManagerID:e,page:1,_list:!0},s);const r=E(s),l=y(`model?${r}`,t),{count:i,total:d,_embedded:c}=yield p(l,n);let u=c?c["ec:model"]:[];return u=Array.isArray(u)?u:[u],{count:i,total:d,items:u}})}function lt(n){return a(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;h({env:t,subdomain:r,resource:e}),s=o({size:25,page:1,_list:!0},s);const l=E(s),i=y(`${e}?${l}`,t,r),{count:d,total:c,_embedded:u}=yield p(i,n);let g=u?u[Object.keys(u)[0]]:[];return g=Array.isArray(g)?g:[g],{count:d,total:c,items:g}})}function dt(e){return a(this,arguments,function*(n,t={}){let{env:s,route:r,options:l={},subdomain:i="datamanager"}=n;h({env:s,subdomain:i,route:r}),l=o({},l);const d=E(l),c=y(`${r}?${d}`,s,i);return p(c,n,t)})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:rt,createAsset:it,createEntry:Q,deleteAsset:ot,deleteEntry:L,deleteEntryObject:tt,dmList:at,editEntry:S,editEntryObject:et,entryList:P,filterOptions:Y,getAsset:st,getDatamanager:ct,getEcAuthKey:M,getEntry:H,getEntryAsset:nt,getEntryEnv:D,getEntryShortID:A,getPublicAuthKey:U,getSchema:X,loginEc:I,loginPublic:F,logoutEc:R,logoutPublic:J,mapEntries:W,modelList:ut,publicApi:G,raw:dt,resourceList:lt,sdkOptions:B},Symbol.toStringTag,{value:"Module"})),{entryList:bt,mapEntries:kt,getEntry:At,getAsset:Tt,assetList:_t,createAsset:Ot,deleteAsset:jt,createEntry:Pt,editEntry:K,deleteEntry:St,getSchema:Lt,loginPublic:Bt,loginEc:Dt,logoutEc:qt,logoutPublic:vt,getEcAuthKey:O,getPublicAuthKey:j,dmList:xt,modelList:zt,publicApi:Ct,getDatamanager:Kt,resourceList:Nt,raw:Ft}=k;function It(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class T{constructor(t){this.config=t}set(t){return new T(o(o({},this.config),t))}entries(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(f(o({},this.config),{options:t,token:e}))})}entryList(t){return a(this,null,function*(){return this.entries(t)})}mapEntries(s){return a(this,arguments,function*(t,e={}){const r=yield this.getBestToken();return kt(f(o({},this.config),{options:e,token:r}),t)})}getEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return At(f(o({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return a(this,null,function*(){return Lt(this.config)})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return _t(f(o({},this.config),{options:t,token:e}))})}assetList(t){return a(this,null,function*(){return this.assets(t)})}createAsset(){return a(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return Ot(f(o({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return jt(f(o({},this.config),{token:e,assetID:t}))})}getAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return Tt(f(o({},this.config),{assetID:t,token:e}))})}createEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return Pt(f(o({},this.config),{token:e,value:t}))})}editEntry(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return St(f(o({},this.config),{token:e,entryID:t}))})}resourceList(t){return a(this,null,function*(){const e=yield this.getBestToken();return Nt(f(o({},this.config),{options:t,token:e}))})}raw(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return Ft(f(o({},this.config),{options:t,token:s}),e)})}storageAdapter(t){return this.set({storageAdapter:t})}setAuth(t){return e=>{if(!this.config.storageAdapter)throw new Error("cannot setAuth: no storageAdapter defined!");const{set:s}=this.config.storageAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(!this.config.storageAdapter)throw new Error("cannot unsetAuth: no storageAdapter defined!");const{remove:s}=this.config.storageAdapter;return s(t),e}}getAuth(t){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:e}=this.config.storageAdapter;return e(t)}loginEc(t){return Dt(o(o({},this.config),t)).then(this.setAuth(O(this.config)))}loginPublic(t){return Bt(o(o({},this.config),t)).then(this.setAuth(j(this.config)))}logoutPublic(){const t=this.getPublicToken();return vt(f(o({},this.config),{token:t})).then(this.unsetAuth(j(this.config)))}logoutEc(){const t=this.getEcToken();return qt(f(o({},this.config),{token:t})).then(this.unsetAuth(O(this.config)))}getPublicToken(){return this.config.token||this.getAuth(j(this.config))}getEcToken(){return this.config.token||this.getAuth(O(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)}subdomain(t){return this.set({subdomain:t})}resource(t){return this.set({resource:t})}route(t){return this.set({route:t})}publicApi(){return Ct(this.config)}getDatamanager(t){return a(this,null,function*(){const e=yield this.getBestToken();return Kt(f(o({},this.config),{dmID:t,token:e}))})}dmList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return xt(f(o({},this.config),{options:t,token:e}))})}modelList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return zt(f(o({},this.config),{options:t,token:e}))})}}const ht=n=>new T({env:n}),Jt=ht;exports.Sdk=T;exports.act=It;exports.apiURL=y;exports.apis=b;exports.assetList=rt;exports.createAsset=it;exports.createEntry=Q;exports.deleteAsset=ot;exports.deleteEntry=L;exports.deleteEntryObject=tt;exports.dmList=at;exports.editEntry=S;exports.editEntryObject=et;exports.entryList=P;exports.expect=h;exports.fdk=Jt;exports.fetcher=p;exports.filterOptions=Y;exports.getAsset=st;exports.getDatamanager=ct;exports.getEcAuthKey=M;exports.getEntry=H;exports.getEntryAsset=nt;exports.getEntryEnv=D;exports.getEntryShortID=A;exports.getPublicAuthKey=U;exports.getSchema=X;exports.loginEc=I;exports.loginPublic=F;exports.logoutEc=R;exports.logoutPublic=J;exports.mapEntries=W;exports.modelList=ut;exports.publicApi=G;exports.query=E;exports.raw=dt;exports.resourceList=lt;exports.sdk=ht;exports.sdkOptions=B;
|
|
3
|
+
${c.verbose}`;throw new Error(u)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return l?i:yield i.json()})}const b={datamanager:{live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"},accounts:{live:"https://accounts.entrecode.de/",stage:"https://accounts.cachena.entrecode.de/"},appserver:{live:"https://appserver.entrecode.de/",stage:"https://appserver.cachena.entrecode.de/"},"dm-history":{live:"https://dm-history.entrecode.de/",stage:"https://dm-history.cachena.entrecode.de/"}};function y(n,t="stage",e="datamanager"){const s=b[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(b).join(", ")}`);const r=s[t];if(!r)throw new Error(`env "${t}" not found. Try one of ${Object.keys(s[t]).join(", ")}`);return r+n}function E(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const N={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function F(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const l=y(`api/${e}/_auth/login?clientID=rest`,t);return yield p(l,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function I(n){return a(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${N[t]}auth/login?clientID=rest`;return yield p(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function J(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield p(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function R(n){return a(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${N[t]}auth/logout?clientID=rest`;return yield p(s,{rawRes:!0,token:e},{method:"POST"})})}function U({dmShortID:n}){return h({dmShortID:n}),n}function M({env:n}){return h({env:n}),n}let Et=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function V(n){let t={};for(let e in n)Et.includes(e)||(t[e]=n[e]);return t}function wt(n){return JSON.parse(JSON.stringify(n))}function G(n){return a(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=y(`api/${e}`,t);return p(s,n)})}function P(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=o({size:50,page:1,_list:!0},r);const l=E(r),i=y(`api/${e}/${s}?${l}`,t),{count:d,total:c,_embedded:u}=yield p(i,n);let g=u?u[`${e}:${s}`]:[];return g=Array.isArray(g)?g:[g],{count:d,total:c,items:g}})}function H({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const l=E({_id:s}),i=y(`api/${t}/${e}?${l}`,n);return p(i,{dmShortID:t,token:r})}function Q(l){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield p(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function S(d){return a(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:l,safePut:i=!1}){h({env:n,dmShortID:t,model:e,entryID:s,value:r});const c={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");c["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const u=y(`api/${t}/${e}?_id=${s}`,n);return r=wt(r),r=V(r),yield p(u,{token:l},{method:"PUT",headers:c,body:JSON.stringify(r)})})}function L({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const l=y(`api/${t}/${e}?_id=${s}`,n);return p(l,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function W(n,t){return a(this,null,function*(){let{env:e,dmShortID:s,model:r,options:l={}}=n;h({env:e,dmShortID:s,model:r}),n.options=o({size:50,page:1,_list:!0},l);let i=0,d,c=[];for(;d===void 0||i<d;){const u=yield P(n);for(let g of u.items)c.push(yield t(g));i+=u.items.length,d=u.total,n.options.page++}return c})}function X(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var g,$,v,q,x;h({env:n,dmShortID:t,model:e});const l=y(`api/schema/${t}/${e}`,n),i=yield p(l),d=(g=i==null?void 0:i.allOf)==null?void 0:g[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${l} returned unexpected format: ${JSON.stringify(i)}`);const{properties:c}=d,u=V(c);for(let w in u){let m=u[w];if(m.required=d.required.includes(w),($=u[w])!=null&&$.oneOf&&((v=u[w])==null||delete v.oneOf),(q=m.title)!=null&&q.includes("<")&&((x=m.title)!=null&&x.includes(">"))){const _=m.title.split("<")[1].slice(0,-1),gt=m.title.split("<")[0];m.type=gt,_.includes(":")?m.resource=_.split(":")[1]:m.resource=_}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete u[w].title}if(s){const w=c._modelTitle.title,m=c._modelTitleField.title;return{properties:u,meta:{modelTitleField:m,modelTitle:w}}}return u})}function B(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:o(o(o(o(o(o(o({},e.sort&&{sort:Array.isArray(e)?e.join(","):e}),e.search&&{[t+"~"]:e.search}),e.notNull&&{[t+"!"]:""}),e.null&&{[t]:""}),e.any&&{[t]:e.any.join(",")}),e.from&&{[t+"From"]:e.from}),e.to&&{[t+"To"]:e.to})).reduce((t,e)=>o(o({},t),e),{})}const Y=B;function A(n){return n._links.collection.href.split("/").slice(-2)[0]}function D(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(b.datamanager).find(s=>b.datamanager[s]===t)}const Z=n=>{const t=A(n),e=D(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},tt=n=>L(Z(n)),et=(n,t)=>S(f(o({},Z(n)),{value:t}));function nt(n,t){const e=A(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function st(l){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=E({assetID:s}),d=y(`a/${t}/${e}?${i}`,n);return(yield p(d,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function rt(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:l={}}=n;h({env:t,dmShortID:e,assetGroup:s}),l=o({size:50,page:1,_list:!0},l);const i=E(l),d=y(`a/${e}/${s}?${i}`,t),{count:c,total:u,_embedded:g}=yield p(d,{dmShortID:e,token:r});let $=g?g["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:c,total:u,items:$}})}function it(d){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:l,options:i}){h({env:n,dmShortID:t,assetGroup:e,file:r});const c=y(`a/${t}/${e}`,n),u=new FormData;return u.append("file",r,l),i&&Object.keys(i).forEach($=>{u.append($,i[$])}),(yield p(c,{token:s},{method:"POST",body:u}))._embedded["ec:dm-asset"]})}function ot(l){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield p(i,{token:r,rawRes:!0},{method:"DELETE"})})}function ct(n){return a(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return p(r,{token:s})})}function at(n){return a(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=o({size:25,page:1,_list:!0},e);const s=E(e),r=y(`?${s}`,t),{count:l,total:i,_embedded:d}=yield p(r,n);let c=d?d["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:l,total:i,items:c}})}function ut(n){return a(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=o({size:25,dataManagerID:e,page:1,_list:!0},s);const r=E(s),l=y(`model?${r}`,t),{count:i,total:d,_embedded:c}=yield p(l,n);let u=c?c["ec:model"]:[];return u=Array.isArray(u)?u:[u],{count:i,total:d,items:u}})}function lt(n){return a(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;h({env:t,subdomain:r,resource:e}),s=o({size:25,page:1,_list:!0},s);const l=E(s),i=y(`${e}?${l}`,t,r),{count:d,total:c,_embedded:u}=yield p(i,n);let g=u?u[Object.keys(u)[0]]:[];return g=Array.isArray(g)?g:[g],{count:d,total:c,items:g}})}function dt(e){return a(this,arguments,function*(n,t={}){let{env:s,route:r,options:l={},subdomain:i="datamanager"}=n;h({env:s,subdomain:i,route:r}),l=o({},l);const d=E(l),c=y(`${r}?${d}`,s,i);return p(c,n,t)})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:rt,createAsset:it,createEntry:Q,deleteAsset:ot,deleteEntry:L,deleteEntryObject:tt,dmList:at,editEntry:S,editEntryObject:et,entryList:P,filterOptions:Y,getAsset:st,getDatamanager:ct,getEcAuthKey:M,getEntry:H,getEntryAsset:nt,getEntryEnv:D,getEntryShortID:A,getPublicAuthKey:U,getSchema:X,loginEc:I,loginPublic:F,logoutEc:R,logoutPublic:J,mapEntries:W,modelList:ut,publicApi:G,raw:dt,resourceList:lt,sdkOptions:B},Symbol.toStringTag,{value:"Module"})),{entryList:bt,mapEntries:kt,getEntry:At,getAsset:Tt,assetList:_t,createAsset:Ot,deleteAsset:jt,createEntry:Pt,editEntry:K,deleteEntry:St,getSchema:Lt,loginPublic:Bt,loginEc:Dt,logoutEc:vt,logoutPublic:qt,getEcAuthKey:O,getPublicAuthKey:j,dmList:xt,modelList:zt,publicApi:Ct,getDatamanager:Kt,resourceList:Nt,raw:Ft}=k;function It(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class T{constructor(t){this.config=t}set(t){return new T(o(o({},this.config),t))}entries(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(f(o({},this.config),{options:t,token:e}))})}entryList(t){return a(this,null,function*(){return this.entries(t)})}mapEntries(s){return a(this,arguments,function*(t,e={}){const r=yield this.getBestToken();return kt(f(o({},this.config),{options:e,token:r}),t)})}getEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return At(f(o({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return a(this,null,function*(){return Lt(this.config)})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return _t(f(o({},this.config),{options:t,token:e}))})}assetList(t){return a(this,null,function*(){return this.assets(t)})}createAsset(){return a(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return Ot(f(o({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return jt(f(o({},this.config),{token:e,assetID:t}))})}getAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return Tt(f(o({},this.config),{assetID:t,token:e}))})}createEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return Pt(f(o({},this.config),{token:e,value:t}))})}editEntry(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return St(f(o({},this.config),{token:e,entryID:t}))})}resourceList(t){return a(this,null,function*(){const e=yield this.getBestToken();return Nt(f(o({},this.config),{options:t,token:e}))})}raw(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return Ft(f(o({},this.config),{options:t,token:s}),e)})}storageAdapter(t){return this.set({storageAdapter:t})}setAuth(t){return e=>{if(!this.config.storageAdapter)throw new Error("cannot setAuth: no storageAdapter defined!");const{set:s}=this.config.storageAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(!this.config.storageAdapter)throw new Error("cannot unsetAuth: no storageAdapter defined!");const{remove:s}=this.config.storageAdapter;return s(t),e}}getAuth(t){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:e}=this.config.storageAdapter;return e(t)}loginEc(t){return Dt(o(o({},this.config),t)).then(this.setAuth(O(this.config)))}loginPublic(t){return Bt(o(o({},this.config),t)).then(this.setAuth(j(this.config)))}logoutPublic(){const t=this.getPublicToken();return qt(f(o({},this.config),{token:t})).then(this.unsetAuth(j(this.config)))}logoutEc(){const t=this.getEcToken();return vt(f(o({},this.config),{token:t})).then(this.unsetAuth(O(this.config)))}getPublicToken(){return this.config.token||this.getAuth(j(this.config))}getEcToken(){return this.config.token||this.getAuth(O(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)}subdomain(t){return this.set({subdomain:t})}resource(t){return this.set({resource:t})}route(t){return this.set({route:t})}publicApi(){return Ct(this.config)}getDatamanager(t){return a(this,null,function*(){const e=yield this.getBestToken();return Kt(f(o({},this.config),{dmID:t,token:e}))})}dmList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return xt(f(o({},this.config),{options:t,token:e}))})}modelList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return zt(f(o({},this.config),{options:t,token:e}))})}}const ht=n=>new T({env:n}),Jt=ht;exports.Sdk=T;exports.act=It;exports.apiURL=y;exports.apis=b;exports.assetList=rt;exports.createAsset=it;exports.createEntry=Q;exports.deleteAsset=ot;exports.deleteEntry=L;exports.deleteEntryObject=tt;exports.dmList=at;exports.editEntry=S;exports.editEntryObject=et;exports.entryList=P;exports.expect=h;exports.fdk=Jt;exports.fetcher=p;exports.filterOptions=Y;exports.getAsset=st;exports.getDatamanager=ct;exports.getEcAuthKey=M;exports.getEntry=H;exports.getEntryAsset=nt;exports.getEntryEnv=D;exports.getEntryShortID=A;exports.getPublicAuthKey=U;exports.getSchema=X;exports.loginEc=I;exports.loginPublic=F;exports.logoutEc=R;exports.logoutPublic=J;exports.mapEntries=W;exports.modelList=ut;exports.publicApi=G;exports.query=E;exports.raw=dt;exports.resourceList=lt;exports.sdk=ht;exports.sdkOptions=B;
|
package/dist/index.mjs
CHANGED
|
@@ -58,6 +58,10 @@ const b = {
|
|
|
58
58
|
appserver: {
|
|
59
59
|
live: "https://appserver.entrecode.de/",
|
|
60
60
|
stage: "https://appserver.cachena.entrecode.de/"
|
|
61
|
+
},
|
|
62
|
+
"dm-history": {
|
|
63
|
+
live: "https://dm-history.entrecode.de/",
|
|
64
|
+
stage: "https://dm-history.cachena.entrecode.de/"
|
|
61
65
|
}
|
|
62
66
|
};
|
|
63
67
|
function y(n, t = "stage", e = "datamanager") {
|
package/dist/lib/util.d.mts
CHANGED
|
@@ -2,22 +2,22 @@ export function fetcher(url: any, config?: {}, options?: {}): Promise<any>;
|
|
|
2
2
|
export function apiURL(route: any, env?: string, subdomain?: string): any;
|
|
3
3
|
export function query(params: any, sort?: boolean): any;
|
|
4
4
|
export function expect(obj: any): void;
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
5
|
+
export const apis: {
|
|
6
|
+
datamanager: {
|
|
7
|
+
live: string;
|
|
8
|
+
stage: string;
|
|
9
|
+
};
|
|
10
|
+
accounts: {
|
|
11
|
+
live: string;
|
|
12
|
+
stage: string;
|
|
13
|
+
};
|
|
14
|
+
appserver: {
|
|
15
|
+
live: string;
|
|
16
|
+
stage: string;
|
|
17
|
+
};
|
|
18
|
+
"dm-history": {
|
|
19
|
+
live: string;
|
|
20
|
+
stage: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
23
|
//# sourceMappingURL=util.d.mts.map
|
package/dist/lib/util.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAsBC;
|
|
1
|
+
{"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAsBC;AAqBD,0EAgBC;AAED,wDAKC;AAED,uCAMC;AAlDD;;;;;;;;;;;;;;;;;EAiBE"}
|