ec.fdk 0.4.0 → 0.4.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/README.md CHANGED
@@ -72,7 +72,7 @@ Now what follows is the autogenerated doc from source:
72
72
  * [.editEntry(entryID, value)](#module_api.Sdk+editEntry) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
73
73
  * [.deleteEntry(entryID)](#module_api.Sdk+deleteEntry) ⇒ <code>void</code>
74
74
  * [.resourceList([options])](#module_api.Sdk+resourceList) ⇒ [<code>Promise.&lt;ResourceList&gt;</code>](#ResourceList)
75
- * [.raw([options])](#module_api.Sdk+raw) ⇒ <code>Promise.&lt;any&gt;</code>
75
+ * [.raw([options], [fetchOptions])](#module_api.Sdk+raw) ⇒ <code>Promise.&lt;any&gt;</code>
76
76
  * [.model(model)](#module_api.Sdk+model) ⇒
77
77
  * [.token(token)](#module_api.Sdk+token) ⇒
78
78
  * [.dmShortID(dmShortID)](#module_api.Sdk+dmShortID) ⇒
@@ -313,7 +313,7 @@ const res = await sdk("stage").resource("template").resourceList()
313
313
  ```
314
314
  <a name="module_api.Sdk+raw"></a>
315
315
 
316
- #### sdk.raw([options]) ⇒ <code>Promise.&lt;any&gt;</code>
316
+ #### sdk.raw([options], [fetchOptions]) ⇒ <code>Promise.&lt;any&gt;</code>
317
317
  <p>Fetches raw route. Expects <code>route</code> to be set. <code>subdomain</code> defaults to &quot;datamanager&quot;.
318
318
  Fetches <code>https://&lt;subdomain&gt;.entrecode.de/&lt;route&gt;?&lt;options&gt;</code>
319
319
  Use this when no other fdk method can give you your request.</p>
@@ -323,6 +323,7 @@ Use this when no other fdk method can give you your request.</p>
323
323
  | Param | Type | Description |
324
324
  | --- | --- | --- |
325
325
  | [options] | <code>object</code> | <p>options for list request.</p> |
326
+ | [fetchOptions] | <code>object</code> | <p>(optional) options passed to fetch.</p> |
326
327
 
327
328
  **Example**
328
329
  ```js
@@ -492,3 +493,18 @@ const dms = await sdk("stage").dmList()
492
493
  ```js
493
494
  const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
494
495
  ```
496
+ <a name="module_api.sdkOptions"></a>
497
+
498
+ ### api.sdkOptions(options) ⇒ <code>Promise.&lt;any&gt;</code>
499
+ <p>Takes <a href="https://entrecode.github.io/ec.sdk/#filteroptions">ec.sdk filterOptions</a>, outputs an <a href="https://doc.entrecode.de/api-basics/#filtering">entrecode filter</a></p>
500
+
501
+ **Kind**: static method of [<code>api</code>](#module_api)
502
+
503
+ | Param | Type | Description |
504
+ | --- | --- | --- |
505
+ | options | <code>SdkFilterOptions</code> | <p>sdk filterOptions</p> |
506
+
507
+ **Example**
508
+ ```js
509
+ const res = await sdk("stage").route("stats").raw()
510
+ ```
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var st=Object.defineProperty,rt=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var it=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?st(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))it.call(t,e)&&S(n,e,t[e]);if(O)for(var e of O(t))ct.call(t,e)&&S(n,e,t[e]);return n},y=(n,t)=>rt(n,ot(t));var c=(n,t,e)=>new Promise((s,r)=>{var a=i=>{try{h(e.next(i))}catch(l){r(l)}},o=i=>{try{h(e.throw(i))}catch(l){r(l)}},h=i=>i.done?s(i.value):Promise.resolve(i.value).then(a,o);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=y(u({},e.headers||{}),{Authorization:`Bearer ${r}`}));const o=yield fetch(n,e);if(!o.ok){if((h=o.headers.get("content-type"))!=null&&h.includes("application/json")){const i=yield o.json(),l=`${i.title}
2
- ${i.detail}
3
- ${i.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${o.statusText}`)}return a?o:yield o.json()})}const j={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 p(n,t="stage",e="datamanager"){const s=j[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(j).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 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 q={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function D(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=p(`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 x(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${q[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=p(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function z(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${q[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function C({dmShortID:n}){return d({dmShortID:n}),n}function J({env:n}){return d({env:n}),n}let at=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function N(n){let t={};for(let e in n)at.includes(e)||(t[e]=n[e]);return t}function ut(n){return JSON.parse(JSON.stringify(n))}function R(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=p(`api/${e}`,t);return g(s,n)})}function v(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),o=p(`api/${e}/${s}?${a}`,t),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function U({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),o=p(`api/${t}/${e}?${a}`,n);return g(o,{dmShortID:t,token:r})}function F(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 o=p(`api/${t}/${e}`,n);return yield g(o,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function M(h){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a,safePut:o=!1}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const i={"Content-Type":"application/json"};if(o){if(!("_modified"in r))throw new Error("expected _modified to be set!");i["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const l=p(`api/${t}/${e}?_id=${s}`,n);return r=ut(r),r=N(r),yield g(l,{token:a},{method:"PUT",headers:i,body:JSON.stringify(r)})})}function I(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 o=p(`api/${t}/${e}?_id=${s}`,n);yield g(o,{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,f,m,P,L;d({env:n,dmShortID:t,model:e});const r=p(`api/schema/${t}/${e}`,n),a=yield g(r),o=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=o,i=N(h);for(let k in i){let $=i[k];if($.required=o.required.includes(k),(f=i[k])!=null&&f.oneOf&&((m=i[k])==null||delete m.oneOf),(P=$.title)!=null&&P.includes("<")&&((L=$.title)!=null&&L.includes(">"))){const b=$.title.split("<")[1].slice(0,-1),nt=$.title.split("<")[0];$.type=nt,b.includes(":")?$.resource=b.split(":")[1]:$.resource=b}else["asset","entry","assets","entries"].includes($.title)?($.type=$.title,$.resource=null):$.type=$.title;delete i[k].title}return i})}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 o=w({assetID:s}),h=p(`a/${t}/${e}?${o}`,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 o=w(a),h=p(`a/${e}/${s}?${o}`,t),{count:i,total:l,_embedded:f}=yield g(h,{dmShortID:e,token:r});let m=f?f["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:i,total:l,items:m}})}function Q(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:o}){d({env:n,dmShortID:t,assetGroup:e,file:r});const i=p(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),o&&Object.keys(o).forEach(m=>{l.append(m,o[m])}),(yield g(i,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function W(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 o=p(`a/${t}/${e}/${s}`,n);yield g(o,{token:r,rawRes:!0},{method:"DELETE"})})}function X(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=p(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function Y(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=p(`?${s}`,t),{count:a,total:o,_embedded:h}=yield g(r,n);let i=h?h["ec:datamanager"]:[];return i=Array.isArray(i)?i:[i],{count:a,total:o,items:i}})}function Z(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=p(`model?${r}`,t),{count:o,total:h,_embedded:i}=yield g(a,n);let l=i?i["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:o,total:h,items:l}})}function tt(n){return c(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;d({env:t,subdomain:r,resource:e}),s=u({size:25,page:1,_list:!0},s);const a=w(s),o=p(`${e}?${a}`,t,r),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[Object.keys(l)[0]]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function et(n){return c(this,null,function*(){let{env:t,route:e,options:s={},subdomain:r="datamanager"}=n;d({env:t,subdomain:r,route:e}),s=u({},s);const a=w(s),o=p(`${e}?${a}`,t,r);return g(o,n)})}const A=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:Q,createEntry:F,deleteAsset:W,deleteEntry:I,dmList:Y,editEntry:M,entryList:v,getAsset:G,getDatamanager:X,getEcAuthKey:J,getEntry:U,getPublicAuthKey:C,getSchema:V,loginEc:x,loginPublic:D,logoutEc:z,logoutPublic:K,modelList:Z,publicApi:R,raw:et,resourceList:tt},Symbol.toStringTag,{value:"Module"})),{entryList:lt,getEntry:dt,getAsset:ht,assetList:gt,createAsset:ft,deleteAsset:yt,createEntry:pt,editEntry:B,deleteEntry:$t,getSchema:mt,loginPublic:wt,loginEc:kt,logoutEc:At,logoutPublic:Et,getEcAuthKey:T,getPublicAuthKey:_,dmList:bt,modelList:Tt,publicApi:_t,getDatamanager:Pt,resourceList:Lt,raw:Ot}=A;function St(n){const{action:t}=n;if(d({action:t}),!A[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(A).join(", ")}`);return A[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 lt(y(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 dt(y(u({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return B(y(u({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return c(this,null,function*(){return mt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(y(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 ft(y(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return yt(y(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ht(y(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return pt(y(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return B(y(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return $t(y(u({},this.config),{token:e,entryID:t}))})}resourceList(t){return c(this,null,function*(){const e=yield this.getBestToken();return Lt(y(u({},this.config),{options:t,token:e}))})}raw(t){return c(this,null,function*(){const e=yield this.getBestToken();return Ot(y(u({},this.config),{options:t,token:e}))})}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 kt(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return wt(u(u({},this.config),t)).then(this.setAuth(_(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Et(y(u({},this.config),{token:t})).then(this.unsetAuth(_(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),At(y(u({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}getPublicToken(){return this.config.token||this.getAuth(_(this.config))}getEcToken(){return this.config.token||this.getAuth(T(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 _t(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Pt(y(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(y(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Tt(y(u({},this.config),{options:t,token:e}))})}}const jt=n=>new E({env:n});exports.Sdk=E;exports.act=St;exports.apiURL=p;exports.assetList=H;exports.createAsset=Q;exports.createEntry=F;exports.deleteAsset=W;exports.deleteEntry=I;exports.dmList=Y;exports.editEntry=M;exports.entryList=v;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=X;exports.getEcAuthKey=J;exports.getEntry=U;exports.getPublicAuthKey=C;exports.getSchema=V;exports.loginEc=x;exports.loginPublic=D;exports.logoutEc=z;exports.logoutPublic=K;exports.modelList=Z;exports.publicApi=R;exports.query=w;exports.raw=et;exports.resourceList=tt;exports.sdk=jt;
1
+ "use strict";var rt=Object.defineProperty,it=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var ct=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?rt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,o=(n,t)=>{for(var e in t||(t={}))ct.call(t,e)&&S(n,e,t[e]);if(j)for(var e of j(t))at.call(t,e)&&S(n,e,t[e]);return n},y=(n,t)=>it(n,ot(t));var c=(n,t,e)=>new Promise((s,r)=>{var l=a=>{try{d(e.next(a))}catch(u){r(u)}},i=a=>{try{d(e.throw(a))}catch(u){r(u)}},d=a=>a.done?s(a.value):Promise.resolve(a.value).then(l,i);d((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 d;const{token:r,rawRes:l}=t;r&&(e.headers=y(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 a=yield i.json(),u=`${a.title}
2
+ ${a.detail}
3
+ ${a.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 p(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 w(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 D={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function x(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const l=p(`api/${e}/_auth/login?clientID=rest`,t);return yield g(l,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function K(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${D[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function N(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=p(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function z(n){return c(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${D[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function C({dmShortID:n}){return h({dmShortID:n}),n}function F({env:n}){return h({env:n}),n}let ut=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function J(n){let t={};for(let e in n)ut.includes(e)||(t[e]=n[e]);return t}function lt(n){return JSON.parse(JSON.stringify(n))}function R(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=p(`api/${e}`,t);return g(s,n)})}function v(n){return c(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=w(r),i=p(`api/${e}/${s}?${l}`,t),{count:d,total:a,_embedded:u}=yield g(i,n);let f=u?u[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:d,total:a,items:f}})}function U({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const l=w({_id:s}),i=p(`api/${t}/${e}?${l}`,n);return g(i,{dmShortID:t,token:r})}function M(l){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=p(`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 I(d){return c(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 a={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");a["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const u=p(`api/${t}/${e}?_id=${s}`,n);return r=lt(r),r=J(r),yield g(u,{token:l},{method:"PUT",headers:a,body:JSON.stringify(r)})})}function V(l){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const i=p(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function G(r){return c(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var f,$,P,O,L;h({env:n,dmShortID:t,model:e});const l=p(`api/schema/${t}/${e}`,n),i=yield g(l),d=(f=i==null?void 0:i.allOf)==null?void 0:f[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${l} returned unexpected format: ${JSON.stringify(i)}`);const{properties:a}=d,u=J(a);for(let A in u){let m=u[A];if(m.required=d.required.includes(A),($=u[A])!=null&&$.oneOf&&((P=u[A])==null||delete P.oneOf),(O=m.title)!=null&&O.includes("<")&&((L=m.title)!=null&&L.includes(">"))){const E=m.title.split("<")[1].slice(0,-1),st=m.title.split("<")[0];m.type=st,E.includes(":")?m.resource=E.split(":")[1]:m.resource=E}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete u[A].title}if(s){const A=a._modelTitle.title,m=a._modelTitleField.title;return{properties:u,meta:{modelTitleField:m,modelTitle:A}}}return u})}function H(l){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),d=p(`a/${t}/${e}?${i}`,n);return(yield g(d,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function Q(n){return c(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=w(l),d=p(`a/${e}/${s}?${i}`,t),{count:a,total:u,_embedded:f}=yield g(d,{dmShortID:e,token:r});let $=f?f["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:a,total:u,items:$}})}function W(d){return c(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 a=p(`a/${t}/${e}`,n),u=new FormData;return u.append("file",r,l),i&&Object.keys(i).forEach($=>{u.append($,i[$])}),(yield g(a,{token:s},{method:"POST",body:u}))._embedded["ec:dm-asset"]})}function X(l){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=p(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function Y(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=p(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function Z(n){return c(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=o({size:25,page:1,_list:!0},e);const s=w(e),r=p(`?${s}`,t),{count:l,total:i,_embedded:d}=yield g(r,n);let a=d?d["ec:datamanager"]:[];return a=Array.isArray(a)?a:[a],{count:l,total:i,items:a}})}function tt(n){return c(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=w(s),l=p(`model?${r}`,t),{count:i,total:d,_embedded:a}=yield g(l,n);let u=a?a["ec:model"]:[];return u=Array.isArray(u)?u:[u],{count:i,total:d,items:u}})}function et(n){return c(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=w(s),i=p(`${e}?${l}`,t,r),{count:d,total:a,_embedded:u}=yield g(i,n);let f=u?u[Object.keys(u)[0]]:[];return f=Array.isArray(f)?f:[f],{count:d,total:a,items:f}})}function nt(e){return c(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=w(l),a=p(`${r}?${d}`,s,i);return g(a,n,t)})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:Q,createAsset:W,createEntry:M,deleteAsset:X,deleteEntry:V,dmList:Z,editEntry:I,entryList:v,getAsset:H,getDatamanager:Y,getEcAuthKey:F,getEntry:U,getPublicAuthKey:C,getSchema:G,loginEc:K,loginPublic:x,logoutEc:z,logoutPublic:N,modelList:tt,publicApi:R,raw:nt,resourceList:et},Symbol.toStringTag,{value:"Module"})),{entryList:dt,getEntry:ht,getAsset:gt,assetList:ft,createAsset:yt,deleteAsset:pt,createEntry:mt,editEntry:q,deleteEntry:$t,getSchema:wt,loginPublic:At,loginEc:kt,logoutEc:bt,logoutPublic:Et,getEcAuthKey:T,getPublicAuthKey:_,dmList:Tt,modelList:_t,publicApi:Pt,getDatamanager:Ot,resourceList:Lt,raw:jt}=k;function St(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 b{constructor(t){this.config=t}set(t){return new b(o(o({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return dt(y(o({},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 ht(y(o({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return q(y(o({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return c(this,null,function*(){return wt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return ft(y(o({},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 yt(y(o({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return pt(y(o({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(y(o({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return mt(y(o({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return q(y(o({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return $t(y(o({},this.config),{token:e,entryID:t}))})}resourceList(t){return c(this,null,function*(){const e=yield this.getBestToken();return Lt(y(o({},this.config),{options:t,token:e}))})}raw(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return jt(y(o({},this.config),{options:t,token:s}),e)})}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 kt(o(o({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return At(o(o({},this.config),t)).then(this.setAuth(_(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Et(y(o({},this.config),{token:t})).then(this.unsetAuth(_(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),bt(y(o({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}getPublicToken(){return this.config.token||this.getAuth(_(this.config))}getEcToken(){return this.config.token||this.getAuth(T(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 Pt(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Ot(y(o({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Tt(y(o({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return _t(y(o({},this.config),{options:t,token:e}))})}}const Bt=n=>new b({env:n});function qt(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),{})}exports.Sdk=b;exports.act=St;exports.apiURL=p;exports.assetList=Q;exports.createAsset=W;exports.createEntry=M;exports.deleteAsset=X;exports.deleteEntry=V;exports.dmList=Z;exports.editEntry=I;exports.entryList=v;exports.expect=h;exports.fetcher=g;exports.getAsset=H;exports.getDatamanager=Y;exports.getEcAuthKey=F;exports.getEntry=U;exports.getPublicAuthKey=C;exports.getSchema=G;exports.loginEc=K;exports.loginPublic=x;exports.logoutEc=z;exports.logoutPublic=N;exports.modelList=tt;exports.publicApi=R;exports.query=w;exports.raw=nt;exports.resourceList=et;exports.sdk=Bt;exports.sdkOptions=qt;
package/dist/index.mjs CHANGED
@@ -1,52 +1,52 @@
1
- var K = Object.defineProperty, z = Object.defineProperties;
1
+ var N = Object.defineProperty, z = Object.defineProperties;
2
2
  var C = Object.getOwnPropertyDescriptors;
3
- var O = Object.getOwnPropertySymbols;
4
- var J = Object.prototype.hasOwnProperty, N = 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) => {
3
+ var j = Object.getOwnPropertySymbols;
4
+ var F = Object.prototype.hasOwnProperty, J = Object.prototype.propertyIsEnumerable;
5
+ var S = (n, t, e) => t in n ? N(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, o = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
- J.call(t, e) && j(n, e, t[e]);
8
- if (O)
9
- for (var e of O(t))
10
- N.call(t, e) && j(n, e, t[e]);
7
+ F.call(t, e) && S(n, e, t[e]);
8
+ if (j)
9
+ for (var e of j(t))
10
+ J.call(t, e) && S(n, e, t[e]);
11
11
  return n;
12
12
  }, y = (n, t) => z(n, C(t));
13
13
  var a = (n, t, e) => new Promise((s, r) => {
14
- var c = (i) => {
14
+ var l = (c) => {
15
15
  try {
16
- h(e.next(i));
17
- } catch (l) {
18
- r(l);
16
+ d(e.next(c));
17
+ } catch (u) {
18
+ r(u);
19
19
  }
20
- }, o = (i) => {
20
+ }, i = (c) => {
21
21
  try {
22
- h(e.throw(i));
23
- } catch (l) {
24
- r(l);
22
+ d(e.throw(c));
23
+ } catch (u) {
24
+ r(u);
25
25
  }
26
- }, h = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(c, o);
27
- h((e = e.apply(n, t)).next());
26
+ }, d = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(l, i);
27
+ d((e = e.apply(n, t)).next());
28
28
  });
29
29
  function g(s) {
30
30
  return a(this, arguments, function* (n, t = {}, e = {}) {
31
- var h;
32
- const { token: r, rawRes: c } = t;
33
- r && (e.headers = y(u({}, e.headers || {}), {
31
+ var d;
32
+ const { token: r, rawRes: l } = t;
33
+ r && (e.headers = y(o({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${r}`
35
35
  }));
36
- const o = yield fetch(n, e);
37
- if (!o.ok) {
38
- if ((h = o.headers.get("content-type")) != null && h.includes("application/json")) {
39
- const i = yield o.json(), l = `${i.title}
40
- ${i.detail}
41
- ${i.verbose}`;
42
- throw new Error(l);
36
+ const i = yield fetch(n, e);
37
+ if (!i.ok) {
38
+ if ((d = i.headers.get("content-type")) != null && d.includes("application/json")) {
39
+ const c = yield i.json(), u = `${c.title}
40
+ ${c.detail}
41
+ ${c.verbose}`;
42
+ throw new Error(u);
43
43
  }
44
- throw new Error(`unexpected fetch error: ${o.statusText}`);
44
+ throw new Error(`unexpected fetch error: ${i.statusText}`);
45
45
  }
46
- return c ? o : yield o.json();
46
+ return l ? i : yield i.json();
47
47
  });
48
48
  }
49
- const S = {
49
+ const B = {
50
50
  datamanager: {
51
51
  live: "https://datamanager.entrecode.de/",
52
52
  stage: "https://datamanager.cachena.entrecode.de/"
@@ -61,10 +61,12 @@ const S = {
61
61
  }
62
62
  };
63
63
  function p(n, t = "stage", e = "datamanager") {
64
- const s = S[e];
64
+ const s = B[e];
65
65
  if (!s)
66
66
  throw new Error(
67
- `subdomain "${e}" not found. Try one of ${Object.keys(S).join(", ")}`
67
+ `subdomain "${e}" not found. Try one of ${Object.keys(B).join(
68
+ ", "
69
+ )}`
68
70
  );
69
71
  const r = s[t];
70
72
  if (!r)
@@ -76,23 +78,23 @@ function p(n, t = "stage", e = "datamanager") {
76
78
  function w(n, t = !0) {
77
79
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
78
80
  }
79
- function d(n) {
81
+ function h(n) {
80
82
  Object.entries(n).forEach(([t, e]) => {
81
83
  if (e === void 0)
82
84
  throw new Error(`expected ${t} to be set!`);
83
85
  });
84
86
  }
85
- const q = {
87
+ const D = {
86
88
  stage: "https://accounts.cachena.entrecode.de/",
87
89
  live: "https://accounts.entrecode.de/"
88
90
  };
89
91
  function R(n) {
90
92
  return a(this, null, function* () {
91
93
  let { env: t, dmShortID: e, email: s, password: r } = n;
92
- d({ env: t, dmShortID: e, email: s, password: r });
93
- const c = p(`api/${e}/_auth/login?clientID=rest`, t);
94
+ h({ env: t, dmShortID: e, email: s, password: r });
95
+ const l = p(`api/${e}/_auth/login?clientID=rest`, t);
94
96
  return yield g(
95
- c,
97
+ l,
96
98
  {},
97
99
  {
98
100
  method: "POST",
@@ -107,8 +109,8 @@ function R(n) {
107
109
  function v(n) {
108
110
  return a(this, null, function* () {
109
111
  let { env: t, email: e, password: s } = n;
110
- d({ env: t, email: e, password: s });
111
- const r = `${q[t]}auth/login?clientID=rest`;
112
+ h({ env: t, email: e, password: s });
113
+ const r = `${D[t]}auth/login?clientID=rest`;
112
114
  return yield g(
113
115
  r,
114
116
  {},
@@ -125,7 +127,7 @@ function v(n) {
125
127
  function U(n) {
126
128
  return a(this, null, function* () {
127
129
  let { dmShortID: t, env: e, token: s } = n;
128
- d({ dmShortID: t, env: e, token: s });
130
+ h({ dmShortID: t, env: e, token: s });
129
131
  const r = p(
130
132
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
131
133
  e
@@ -139,11 +141,11 @@ function U(n) {
139
141
  );
140
142
  });
141
143
  }
142
- function F(n) {
144
+ function M(n) {
143
145
  return a(this, null, function* () {
144
146
  let { env: t, token: e } = n;
145
- d({ env: t, token: e });
146
- const s = `${q[t]}auth/logout?clientID=rest`;
147
+ h({ env: t, token: e });
148
+ const s = `${D[t]}auth/logout?clientID=rest`;
147
149
  return yield g(
148
150
  s,
149
151
  {
@@ -156,13 +158,13 @@ function F(n) {
156
158
  );
157
159
  });
158
160
  }
159
- function M({ dmShortID: n }) {
160
- return d({ dmShortID: n }), n;
161
+ function I({ dmShortID: n }) {
162
+ return h({ dmShortID: n }), n;
161
163
  }
162
- function I({ env: n }) {
163
- return d({ env: n }), n;
164
+ function V({ env: n }) {
165
+ return h({ env: n }), n;
164
166
  }
165
- let V = [
167
+ let G = [
166
168
  "created",
167
169
  "creator",
168
170
  "id",
@@ -178,43 +180,43 @@ let V = [
178
180
  "_modelTitleField",
179
181
  "_modified"
180
182
  ];
181
- function D(n) {
183
+ function x(n) {
182
184
  let t = {};
183
185
  for (let e in n)
184
- V.includes(e) || (t[e] = n[e]);
186
+ G.includes(e) || (t[e] = n[e]);
185
187
  return t;
186
188
  }
187
- function G(n) {
189
+ function H(n) {
188
190
  return JSON.parse(JSON.stringify(n));
189
191
  }
190
- function H(n) {
192
+ function Q(n) {
191
193
  return a(this, null, function* () {
192
194
  let { env: t, dmShortID: e } = n;
193
- d({ env: t, dmShortID: e });
195
+ h({ env: t, dmShortID: e });
194
196
  const s = p(`api/${e}`, t);
195
197
  return g(s, n);
196
198
  });
197
199
  }
198
- function Q(n) {
200
+ function W(n) {
199
201
  return a(this, null, function* () {
200
202
  let { env: t, dmShortID: e, model: s, options: r = {} } = n;
201
- d({ env: t, dmShortID: e, model: s }), r = u({ size: 50, page: 1, _list: !0 }, r);
202
- const c = w(r), o = p(`api/${e}/${s}?${c}`, t), { count: h, total: i, _embedded: l } = yield g(o, n);
203
- let f = l ? l[`${e}:${s}`] : [];
204
- return f = Array.isArray(f) ? f : [f], { count: h, total: i, items: f };
203
+ h({ env: t, dmShortID: e, model: s }), r = o({ size: 50, page: 1, _list: !0 }, r);
204
+ const l = w(r), i = p(`api/${e}/${s}?${l}`, t), { count: d, total: c, _embedded: u } = yield g(i, n);
205
+ let f = u ? u[`${e}:${s}`] : [];
206
+ return f = Array.isArray(f) ? f : [f], { count: d, total: c, items: f };
205
207
  });
206
208
  }
207
- function W({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
208
- d({ env: n, dmShortID: t, model: e, entryID: s });
209
- const c = w({ _id: s }), o = p(`api/${t}/${e}?${c}`, n);
210
- return g(o, { dmShortID: t, token: r });
209
+ function X({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
210
+ h({ env: n, dmShortID: t, model: e, entryID: s });
211
+ const l = w({ _id: s }), i = p(`api/${t}/${e}?${l}`, n);
212
+ return g(i, { dmShortID: t, token: r });
211
213
  }
212
- function X(c) {
214
+ function Y(l) {
213
215
  return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
214
- d({ env: n, dmShortID: t, model: e, value: s });
215
- const o = p(`api/${t}/${e}`, n);
216
+ h({ env: n, dmShortID: t, model: e, value: s });
217
+ const i = p(`api/${t}/${e}`, n);
216
218
  return yield g(
217
- o,
219
+ i,
218
220
  { env: n, dmShortID: t, token: r },
219
221
  {
220
222
  method: "POST",
@@ -226,43 +228,43 @@ function X(c) {
226
228
  );
227
229
  });
228
230
  }
229
- function Y(h) {
231
+ function Z(d) {
230
232
  return a(this, arguments, function* ({
231
233
  env: n,
232
234
  dmShortID: t,
233
235
  model: e,
234
236
  entryID: s,
235
237
  value: r,
236
- token: c,
237
- safePut: o = !1
238
+ token: l,
239
+ safePut: i = !1
238
240
  }) {
239
- d({ env: n, dmShortID: t, model: e, entryID: s, value: r });
240
- const i = {
241
+ h({ env: n, dmShortID: t, model: e, entryID: s, value: r });
242
+ const c = {
241
243
  "Content-Type": "application/json"
242
244
  };
243
- if (o) {
245
+ if (i) {
244
246
  if (!("_modified" in r))
245
247
  throw new Error("expected _modified to be set!");
246
- i["If-Unmodified-Since"] = new Date(r._modified).toUTCString();
248
+ c["If-Unmodified-Since"] = new Date(r._modified).toUTCString();
247
249
  }
248
- const l = p(`api/${t}/${e}?_id=${s}`, n);
249
- return r = G(r), r = D(r), yield g(
250
- l,
251
- { token: c },
250
+ const u = p(`api/${t}/${e}?_id=${s}`, n);
251
+ return r = H(r), r = x(r), yield g(
252
+ u,
253
+ { token: l },
252
254
  {
253
255
  method: "PUT",
254
- headers: i,
256
+ headers: c,
255
257
  body: JSON.stringify(r)
256
258
  }
257
259
  );
258
260
  });
259
261
  }
260
- function Z(c) {
262
+ function tt(l) {
261
263
  return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
262
- d({ env: n, dmShortID: t, model: e, entryID: s });
263
- const o = p(`api/${t}/${e}?_id=${s}`, n);
264
+ h({ env: n, dmShortID: t, model: e, entryID: s });
265
+ const i = p(`api/${t}/${e}?_id=${s}`, n);
264
266
  yield g(
265
- o,
267
+ i,
266
268
  { token: r, rawRes: !0 },
267
269
  {
268
270
  method: "DELETE",
@@ -273,69 +275,73 @@ function Z(c) {
273
275
  );
274
276
  });
275
277
  }
276
- function tt(s) {
277
- return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
278
- var l, f, m, P, L;
279
- d({ env: n, dmShortID: t, model: e });
280
- const r = p(`api/schema/${t}/${e}`, n), c = yield g(r), o = (l = c == null ? void 0 : c.allOf) == null ? void 0 : l[1];
281
- if (typeof o.properties != "object")
278
+ function et(r) {
279
+ return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, withMetadata: s }) {
280
+ var f, $, P, L, O;
281
+ h({ env: n, dmShortID: t, model: e });
282
+ const l = p(`api/schema/${t}/${e}`, n), i = yield g(l), d = (f = i == null ? void 0 : i.allOf) == null ? void 0 : f[1];
283
+ if (typeof d.properties != "object")
282
284
  throw new Error(
283
- `getSchema: ${r} returned unexpected format: ${JSON.stringify(c)}`
285
+ `getSchema: ${l} returned unexpected format: ${JSON.stringify(i)}`
284
286
  );
285
- const { properties: h } = o, i = D(h);
286
- for (let k in i) {
287
- let $ = i[k];
288
- if ($.required = o.required.includes(k), (f = i[k]) != null && f.oneOf && ((m = i[k]) == null || delete m.oneOf), (P = $.title) != null && P.includes("<") && ((L = $.title) != null && L.includes(">"))) {
289
- const E = $.title.split("<")[1].slice(0, -1), x = $.title.split("<")[0];
290
- $.type = x, E.includes(":") ? $.resource = E.split(":")[1] : $.resource = E;
287
+ const { properties: c } = d, u = x(c);
288
+ for (let A in u) {
289
+ let m = u[A];
290
+ if (m.required = d.required.includes(A), ($ = u[A]) != null && $.oneOf && ((P = u[A]) == null || delete P.oneOf), (L = m.title) != null && L.includes("<") && ((O = m.title) != null && O.includes(">"))) {
291
+ const k = m.title.split("<")[1].slice(0, -1), K = m.title.split("<")[0];
292
+ m.type = K, k.includes(":") ? m.resource = k.split(":")[1] : m.resource = k;
291
293
  } else
292
- ["asset", "entry", "assets", "entries"].includes($.title) ? ($.type = $.title, $.resource = null) : $.type = $.title;
293
- delete i[k].title;
294
+ ["asset", "entry", "assets", "entries"].includes(m.title) ? (m.type = m.title, m.resource = null) : m.type = m.title;
295
+ delete u[A].title;
296
+ }
297
+ if (s) {
298
+ const A = c._modelTitle.title, m = c._modelTitleField.title;
299
+ return { properties: u, meta: { modelTitleField: m, modelTitle: A } };
294
300
  }
295
- return i;
301
+ return u;
296
302
  });
297
303
  }
298
- function et(c) {
304
+ function nt(l) {
299
305
  return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
300
- d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
301
- const o = w({ assetID: s }), h = p(`a/${t}/${e}?${o}`, n);
302
- return (yield g(h, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
306
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
307
+ const i = w({ assetID: s }), d = p(`a/${t}/${e}?${i}`, n);
308
+ return (yield g(d, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
303
309
  });
304
310
  }
305
- function nt(n) {
311
+ function st(n) {
306
312
  return a(this, null, function* () {
307
- let { env: t, dmShortID: e, assetGroup: s, token: r, options: c = {} } = n;
308
- d({ env: t, dmShortID: e, assetGroup: s }), c = u({ size: 50, page: 1, _list: !0 }, c);
309
- const o = w(c), h = p(`a/${e}/${s}?${o}`, t), { count: i, total: l, _embedded: f } = yield g(h, { dmShortID: e, token: r });
310
- let m = f ? f["ec:dm-asset"] : [];
311
- return m = Array.isArray(m) ? m : [m], { count: i, total: l, items: m };
313
+ let { env: t, dmShortID: e, assetGroup: s, token: r, options: l = {} } = n;
314
+ h({ env: t, dmShortID: e, assetGroup: s }), l = o({ size: 50, page: 1, _list: !0 }, l);
315
+ const i = w(l), d = p(`a/${e}/${s}?${i}`, t), { count: c, total: u, _embedded: f } = yield g(d, { dmShortID: e, token: r });
316
+ let $ = f ? f["ec:dm-asset"] : [];
317
+ return $ = Array.isArray($) ? $ : [$], { count: c, total: u, items: $ };
312
318
  });
313
319
  }
314
- function st(h) {
320
+ function rt(d) {
315
321
  return a(this, arguments, function* ({
316
322
  env: n,
317
323
  dmShortID: t,
318
324
  assetGroup: e,
319
325
  token: s,
320
326
  file: r,
321
- name: c,
322
- options: o
327
+ name: l,
328
+ options: i
323
329
  }) {
324
- d({ env: n, dmShortID: t, assetGroup: e, file: r });
325
- const i = p(`a/${t}/${e}`, n), l = new FormData();
326
- return l.append("file", r, c), o && Object.keys(o).forEach((m) => {
327
- l.append(m, o[m]);
330
+ h({ env: n, dmShortID: t, assetGroup: e, file: r });
331
+ const c = p(`a/${t}/${e}`, n), u = new FormData();
332
+ return u.append("file", r, l), i && Object.keys(i).forEach(($) => {
333
+ u.append($, i[$]);
328
334
  }), (yield g(
329
- i,
335
+ c,
330
336
  { token: s },
331
337
  {
332
338
  method: "POST",
333
- body: l
339
+ body: u
334
340
  }
335
341
  ))._embedded["ec:dm-asset"];
336
342
  });
337
343
  }
338
- function rt(c) {
344
+ function it(l) {
339
345
  return a(this, arguments, function* ({
340
346
  env: n,
341
347
  dmShortID: t,
@@ -343,10 +349,10 @@ function rt(c) {
343
349
  assetID: s,
344
350
  token: r
345
351
  }) {
346
- d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
347
- const o = p(`a/${t}/${e}/${s}`, n);
352
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
353
+ const i = p(`a/${t}/${e}/${s}`, n);
348
354
  yield g(
349
- o,
355
+ i,
350
356
  { token: r, rawRes: !0 },
351
357
  {
352
358
  method: "DELETE"
@@ -357,110 +363,110 @@ function rt(c) {
357
363
  function ot(n) {
358
364
  return a(this, null, function* () {
359
365
  let { env: t, dmID: e, token: s } = n;
360
- d({ env: t, dmID: e });
366
+ h({ env: t, dmID: e });
361
367
  const r = p(`?dataManagerID=${e}`, t);
362
368
  return g(r, { token: s });
363
369
  });
364
370
  }
365
- function it(n) {
371
+ function at(n) {
366
372
  return a(this, null, function* () {
367
373
  let { env: t, options: e = {} } = n;
368
- d({ env: t }), e = u({ size: 25, page: 1, _list: !0 }, e);
369
- const s = w(e), r = p(`?${s}`, t), { count: c, total: o, _embedded: h } = yield g(r, n);
370
- let i = h ? h["ec:datamanager"] : [];
371
- return i = Array.isArray(i) ? i : [i], { count: c, total: o, items: i };
374
+ h({ env: t }), e = o({ size: 25, page: 1, _list: !0 }, e);
375
+ const s = w(e), r = p(`?${s}`, t), { count: l, total: i, _embedded: d } = yield g(r, n);
376
+ let c = d ? d["ec:datamanager"] : [];
377
+ return c = Array.isArray(c) ? c : [c], { count: l, total: i, items: c };
372
378
  });
373
379
  }
374
- function at(n) {
380
+ function ct(n) {
375
381
  return a(this, null, function* () {
376
382
  let { env: t, dmID: e, options: s = {} } = n;
377
- d({ env: t, dmID: e }), s = u({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
378
- const r = w(s), c = p(`model?${r}`, t), { count: o, total: h, _embedded: i } = yield g(c, n);
379
- let l = i ? i["ec:model"] : [];
380
- return l = Array.isArray(l) ? l : [l], { count: o, total: h, items: l };
383
+ h({ env: t, dmID: e }), s = o({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
384
+ const r = w(s), l = p(`model?${r}`, t), { count: i, total: d, _embedded: c } = yield g(l, n);
385
+ let u = c ? c["ec:model"] : [];
386
+ return u = Array.isArray(u) ? u : [u], { count: i, total: d, items: u };
381
387
  });
382
388
  }
383
- function ct(n) {
389
+ function ut(n) {
384
390
  return a(this, null, function* () {
385
391
  let { env: t, resource: e, options: s = {}, subdomain: r = "datamanager" } = n;
386
- d({ env: t, subdomain: r, resource: e }), s = u({ size: 25, page: 1, _list: !0 }, s);
387
- const c = w(s), o = p(`${e}?${c}`, t, r), { count: h, total: i, _embedded: l } = yield g(o, n);
388
- let f = l ? l[Object.keys(l)[0]] : [];
389
- return f = Array.isArray(f) ? f : [f], { count: h, total: i, items: f };
392
+ h({ env: t, subdomain: r, resource: e }), s = o({ size: 25, page: 1, _list: !0 }, s);
393
+ const l = w(s), i = p(`${e}?${l}`, t, r), { count: d, total: c, _embedded: u } = yield g(i, n);
394
+ let f = u ? u[Object.keys(u)[0]] : [];
395
+ return f = Array.isArray(f) ? f : [f], { count: d, total: c, items: f };
390
396
  });
391
397
  }
392
- function ut(n) {
393
- return a(this, null, function* () {
394
- let { env: t, route: e, options: s = {}, subdomain: r = "datamanager" } = n;
395
- d({ env: t, subdomain: r, route: e }), s = u({}, s);
396
- const c = w(s), o = p(`${e}?${c}`, t, r);
397
- return g(o, n);
398
+ function lt(e) {
399
+ return a(this, arguments, function* (n, t = {}) {
400
+ let { env: s, route: r, options: l = {}, subdomain: i = "datamanager" } = n;
401
+ h({ env: s, subdomain: i, route: r }), l = o({}, l);
402
+ const d = w(l), c = p(`${r}?${d}`, s, i);
403
+ return g(c, n, t);
398
404
  });
399
405
  }
400
- const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
406
+ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
401
407
  __proto__: null,
402
- assetList: nt,
403
- createAsset: st,
404
- createEntry: X,
405
- deleteAsset: rt,
406
- deleteEntry: Z,
407
- dmList: it,
408
- editEntry: Y,
409
- entryList: Q,
410
- getAsset: et,
408
+ assetList: st,
409
+ createAsset: rt,
410
+ createEntry: Y,
411
+ deleteAsset: it,
412
+ deleteEntry: tt,
413
+ dmList: at,
414
+ editEntry: Z,
415
+ entryList: W,
416
+ getAsset: nt,
411
417
  getDatamanager: ot,
412
- getEcAuthKey: I,
413
- getEntry: W,
414
- getPublicAuthKey: M,
415
- getSchema: tt,
418
+ getEcAuthKey: V,
419
+ getEntry: X,
420
+ getPublicAuthKey: I,
421
+ getSchema: et,
416
422
  loginEc: v,
417
423
  loginPublic: R,
418
- logoutEc: F,
424
+ logoutEc: M,
419
425
  logoutPublic: U,
420
- modelList: at,
421
- publicApi: H,
422
- raw: ut,
423
- resourceList: ct
426
+ modelList: ct,
427
+ publicApi: Q,
428
+ raw: lt,
429
+ resourceList: ut
424
430
  }, Symbol.toStringTag, { value: "Module" })), {
425
- entryList: lt,
426
- getEntry: dt,
427
- getAsset: ht,
428
- assetList: gt,
429
- createAsset: ft,
430
- deleteAsset: yt,
431
- createEntry: pt,
432
- editEntry: B,
431
+ entryList: dt,
432
+ getEntry: ht,
433
+ getAsset: gt,
434
+ assetList: ft,
435
+ createAsset: yt,
436
+ deleteAsset: pt,
437
+ createEntry: mt,
438
+ editEntry: q,
433
439
  deleteEntry: $t,
434
- getSchema: mt,
435
- loginPublic: wt,
436
- loginEc: kt,
437
- logoutEc: At,
438
- logoutPublic: Et,
440
+ getSchema: wt,
441
+ loginPublic: At,
442
+ loginEc: Et,
443
+ logoutEc: kt,
444
+ logoutPublic: bt,
439
445
  getEcAuthKey: b,
440
446
  getPublicAuthKey: T,
441
- dmList: bt,
442
- modelList: Tt,
443
- publicApi: _t,
444
- getDatamanager: Pt,
445
- resourceList: Lt,
446
- raw: Ot
447
- } = A;
448
- function St(n) {
447
+ dmList: Tt,
448
+ modelList: _t,
449
+ publicApi: Pt,
450
+ getDatamanager: Lt,
451
+ resourceList: Ot,
452
+ raw: jt
453
+ } = E;
454
+ function Bt(n) {
449
455
  const { action: t } = n;
450
- if (d({ action: t }), !A[t])
456
+ if (h({ action: t }), !E[t])
451
457
  throw new Error(
452
- `"${t}" does not exist! try one of ${Object.keys(A).join(
458
+ `"${t}" does not exist! try one of ${Object.keys(E).join(
453
459
  ", "
454
460
  )}`
455
461
  );
456
- return A[t](n);
462
+ return E[t](n);
457
463
  }
458
464
  class _ {
459
465
  constructor(t) {
460
466
  this.config = t;
461
467
  }
462
468
  set(t) {
463
- return new _(u(u({}, this.config), t));
469
+ return new _(o(o({}, this.config), t));
464
470
  }
465
471
  /**
466
472
  * Loads entry list. Expects `dmShortID` / `model` to be set.
@@ -478,7 +484,7 @@ class _ {
478
484
  entries() {
479
485
  return a(this, arguments, function* (t = {}) {
480
486
  const e = yield this.getBestToken();
481
- return lt(y(u({}, this.config), { options: t, token: e }));
487
+ return dt(y(o({}, this.config), { options: t, token: e }));
482
488
  });
483
489
  }
484
490
  entryList(t) {
@@ -498,7 +504,7 @@ class _ {
498
504
  getEntry(t) {
499
505
  return a(this, null, function* () {
500
506
  const e = yield this.getBestToken();
501
- return dt(y(u({}, this.config), { entryID: t, token: e }));
507
+ return ht(y(o({}, this.config), { entryID: t, token: e }));
502
508
  });
503
509
  }
504
510
  /**
@@ -518,7 +524,7 @@ class _ {
518
524
  editEntrySafe(t, e) {
519
525
  return a(this, null, function* () {
520
526
  const s = yield this.getBestToken();
521
- return B(y(u({}, this.config), { entryID: t, token: s, value: e, safePut: !0 }));
527
+ return q(y(o({}, this.config), { entryID: t, token: s, value: e, safePut: !0 }));
522
528
  });
523
529
  }
524
530
  /**
@@ -531,7 +537,7 @@ class _ {
531
537
  */
532
538
  getSchema() {
533
539
  return a(this, null, function* () {
534
- return mt(this.config);
540
+ return wt(this.config);
535
541
  });
536
542
  }
537
543
  /**
@@ -550,7 +556,7 @@ class _ {
550
556
  assets(t) {
551
557
  return a(this, null, function* () {
552
558
  const e = yield this.getBestToken();
553
- return gt(y(u({}, this.config), { options: t, token: e }));
559
+ return ft(y(o({}, this.config), { options: t, token: e }));
554
560
  });
555
561
  }
556
562
  assetList(t) {
@@ -582,7 +588,7 @@ class _ {
582
588
  createAsset() {
583
589
  return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
584
590
  const r = yield this.getBestToken();
585
- return ft(y(u({}, this.config), { file: t, name: e, options: s, token: r }));
591
+ return yt(y(o({}, this.config), { file: t, name: e, options: s, token: r }));
586
592
  });
587
593
  }
588
594
  /**
@@ -597,7 +603,7 @@ class _ {
597
603
  deleteAsset(t) {
598
604
  return a(this, null, function* () {
599
605
  const e = yield this.getBestToken();
600
- return yt(y(u({}, this.config), { token: e, assetID: t }));
606
+ return pt(y(o({}, this.config), { token: e, assetID: t }));
601
607
  });
602
608
  }
603
609
  /**
@@ -612,7 +618,7 @@ class _ {
612
618
  getAsset(t) {
613
619
  return a(this, null, function* () {
614
620
  const e = yield this.getBestToken();
615
- return ht(y(u({}, this.config), { assetID: t, token: e }));
621
+ return gt(y(o({}, this.config), { assetID: t, token: e }));
616
622
  });
617
623
  }
618
624
  /**
@@ -627,7 +633,7 @@ class _ {
627
633
  createEntry(t) {
628
634
  return a(this, null, function* () {
629
635
  const e = yield this.getBestToken();
630
- return pt(y(u({}, this.config), { token: e, value: t }));
636
+ return mt(y(o({}, this.config), { token: e, value: t }));
631
637
  });
632
638
  }
633
639
  /**
@@ -643,7 +649,7 @@ class _ {
643
649
  editEntry(t, e) {
644
650
  return a(this, null, function* () {
645
651
  const s = yield this.getBestToken();
646
- return B(y(u({}, this.config), { entryID: t, token: s, value: e }));
652
+ return q(y(o({}, this.config), { entryID: t, token: s, value: e }));
647
653
  });
648
654
  }
649
655
  /**
@@ -658,7 +664,7 @@ class _ {
658
664
  deleteEntry(t) {
659
665
  return a(this, null, function* () {
660
666
  const e = yield this.getBestToken();
661
- return $t(y(u({}, this.config), { token: e, entryID: t }));
667
+ return $t(y(o({}, this.config), { token: e, entryID: t }));
662
668
  });
663
669
  }
664
670
  /**
@@ -673,7 +679,7 @@ class _ {
673
679
  resourceList(t) {
674
680
  return a(this, null, function* () {
675
681
  const e = yield this.getBestToken();
676
- return Lt(y(u({}, this.config), { options: t, token: e }));
682
+ return Ot(y(o({}, this.config), { options: t, token: e }));
677
683
  });
678
684
  }
679
685
  /**
@@ -682,14 +688,15 @@ class _ {
682
688
  * Use this when no other fdk method can give you your request.
683
689
  *
684
690
  * @param {object=} options options for list request.
691
+ * @param {object=} fetchOptions (optional) options passed to fetch.
685
692
  * @returns {Promise<any>}
686
693
  * @example
687
694
  * const res = await sdk("stage").route("stats").raw()
688
695
  */
689
- raw(t) {
696
+ raw(t, e) {
690
697
  return a(this, null, function* () {
691
- const e = yield this.getBestToken();
692
- return Ot(y(u({}, this.config), { options: t, token: e }));
698
+ const s = yield this.getBestToken();
699
+ return jt(y(o({}, this.config), { options: t, token: s }), e);
693
700
  });
694
701
  }
695
702
  // TODO: rename authAdapter -> storageAdapter
@@ -719,24 +726,24 @@ class _ {
719
726
  return e(t);
720
727
  }
721
728
  loginEc(t) {
722
- return kt(u(u({}, this.config), t)).then(
729
+ return Et(o(o({}, this.config), t)).then(
723
730
  this.setAuth(b(this.config))
724
731
  );
725
732
  }
726
733
  loginPublic(t) {
727
- return wt(u(u({}, this.config), t)).then(
734
+ return At(o(o({}, this.config), t)).then(
728
735
  this.setAuth(T(this.config))
729
736
  );
730
737
  }
731
738
  logoutPublic() {
732
739
  const t = this.getPublicToken();
733
- return console.log("token", t), Et(y(u({}, this.config), { token: t })).then(
740
+ return console.log("token", t), bt(y(o({}, this.config), { token: t })).then(
734
741
  this.unsetAuth(T(this.config))
735
742
  );
736
743
  }
737
744
  logoutEc() {
738
745
  const t = this.getEcToken();
739
- return console.log("token", t), At(y(u({}, this.config), { token: t })).then(
746
+ return console.log("token", t), kt(y(o({}, this.config), { token: t })).then(
740
747
  this.unsetAuth(b(this.config))
741
748
  );
742
749
  }
@@ -847,7 +854,7 @@ class _ {
847
854
  * @returns any
848
855
  */
849
856
  publicApi() {
850
- return _t(this.config);
857
+ return Pt(this.config);
851
858
  }
852
859
  /**
853
860
  * Loads a DatamanagerResource by its long id. Requires token.
@@ -856,7 +863,7 @@ class _ {
856
863
  getDatamanager(t) {
857
864
  return a(this, null, function* () {
858
865
  const e = yield this.getBestToken();
859
- return Pt(y(u({}, this.config), { dmID: t, token: e }));
866
+ return Lt(y(o({}, this.config), { dmID: t, token: e }));
860
867
  });
861
868
  }
862
869
  /**
@@ -870,7 +877,7 @@ class _ {
870
877
  dmList() {
871
878
  return a(this, arguments, function* (t = {}) {
872
879
  const e = yield this.getBestToken();
873
- return bt(y(u({}, this.config), { options: t, token: e }));
880
+ return Tt(y(o({}, this.config), { options: t, token: e }));
874
881
  });
875
882
  }
876
883
  /**
@@ -884,39 +891,43 @@ class _ {
884
891
  modelList() {
885
892
  return a(this, arguments, function* (t = {}) {
886
893
  const e = yield this.getBestToken();
887
- return Tt(y(u({}, this.config), { options: t, token: e }));
894
+ return _t(y(o({}, this.config), { options: t, token: e }));
888
895
  });
889
896
  }
890
897
  }
891
- const Bt = (n) => new _({ env: n });
898
+ const qt = (n) => new _({ env: n });
899
+ function Dt(n) {
900
+ 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), {});
901
+ }
892
902
  export {
893
903
  _ as Sdk,
894
- St as act,
904
+ Bt as act,
895
905
  p as apiURL,
896
- nt as assetList,
897
- st as createAsset,
898
- X as createEntry,
899
- rt as deleteAsset,
900
- Z as deleteEntry,
901
- it as dmList,
902
- Y as editEntry,
903
- Q as entryList,
904
- d as expect,
906
+ st as assetList,
907
+ rt as createAsset,
908
+ Y as createEntry,
909
+ it as deleteAsset,
910
+ tt as deleteEntry,
911
+ at as dmList,
912
+ Z as editEntry,
913
+ W as entryList,
914
+ h as expect,
905
915
  g as fetcher,
906
- et as getAsset,
916
+ nt as getAsset,
907
917
  ot as getDatamanager,
908
- I as getEcAuthKey,
909
- W as getEntry,
910
- M as getPublicAuthKey,
911
- tt as getSchema,
918
+ V as getEcAuthKey,
919
+ X as getEntry,
920
+ I as getPublicAuthKey,
921
+ et as getSchema,
912
922
  v as loginEc,
913
923
  R as loginPublic,
914
- F as logoutEc,
924
+ M as logoutEc,
915
925
  U as logoutPublic,
916
- at as modelList,
917
- H as publicApi,
926
+ ct as modelList,
927
+ Q as publicApi,
918
928
  w as query,
919
- ut as raw,
920
- ct as resourceList,
921
- Bt as sdk
929
+ lt as raw,
930
+ ut as resourceList,
931
+ qt as sdk,
932
+ Dt as sdkOptions
922
933
  };
@@ -14,5 +14,5 @@ export function resourceList(config: any): Promise<{
14
14
  total: any;
15
15
  items: any;
16
16
  }>;
17
- export function raw(config: any): Promise<any>;
17
+ export function raw(config: any, fetchOptions?: {}): Promise<any>;
18
18
  //# sourceMappingURL=admin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA,0DAMC;AAED;;;;GAYC;AAED;;;;GAWC;AAED;;;;GAWC;AAED,+CAQC"}
1
+ {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA,0DAMC;AAED;;;;GAYC;AAED;;;;GAWC;AAED;;;;GAWC;AAED,kEAQC"}
@@ -1,4 +1,13 @@
1
1
  export function act(config: any): any;
2
+ /**
3
+ * Takes [ec.sdk filterOptions](https://entrecode.github.io/ec.sdk/#filteroptions), outputs an [entrecode filter](https://doc.entrecode.de/api-basics/#filtering)
4
+ *
5
+ * @param {SdkFilterOptions} options sdk filterOptions
6
+ * @returns {Record<string, string>}
7
+ * @example
8
+ * const res = await sdk("stage").route("stats").raw()
9
+ */
10
+ export function sdkOptions(options: SdkFilterOptions): Record<string, string>;
2
11
  export * from "./util.mjs";
3
12
  /**
4
13
  * SDK
@@ -164,11 +173,12 @@ export class Sdk {
164
173
  * Use this when no other fdk method can give you your request.
165
174
  *
166
175
  * @param {object=} options options for list request.
176
+ * @param {object=} fetchOptions (optional) options passed to fetch.
167
177
  * @returns {Promise<any>}
168
178
  * @example
169
179
  * const res = await sdk("stage").route("stats").raw()
170
180
  */
171
- raw(options?: object | undefined): Promise<any>;
181
+ raw(options?: object | undefined, fetchOptions?: object | undefined): Promise<any>;
172
182
  authAdapter(authAdapter: any): Sdk;
173
183
  setAuth(key: any): (auth: any) => any;
174
184
  unsetAuth(key: any): (auth: any) => any;
@@ -285,6 +295,8 @@ export type AssetResource = {
285
295
  tags: Array<string | any>;
286
296
  title: string;
287
297
  type: string;
298
+ mimetype: string;
299
+ duplicates: number;
288
300
  file: AssetFile;
289
301
  };
290
302
  export type EntryResource = {
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src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AE;YACR,MAAM,EAAE;uBACR,MAAM,EAAE;aACR,MAAM;WACN,MAAM;;;;YACN,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,mBAAmB,EAAE;;;WAKrB,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;WAKf,MAAM;WACN,MAAM;WACN,GAAG,EAAE;;;;;;aAML,GAAG;iBACH,MAAM;iBACN,OAAO;aACP,OAAO;cACP,OAAO;cACP,OAAO;YACP,OAAO;WACP,MAAM;UACN,MAAM;gBACN,MAAM,GAAG,IAAI;;;YAKb,GAAG;aACH,MAAM;iBACN,MAAM;YACN,gBAAgB,EAAE;gBAClB,OAAO;cACP,MAAM;WACN,GAAG,EAAE;eACL,GAAG,EAAE;aACL,MAAM,EAAE;aACR,MAAM;cACN,MAAM;cACN,GAAG,EAAE;UACL,GAAG;WACH,MAAM;gBACN,MAAM;YACN,GAAG;;;WAMH,MAAM;WACN,MAAM;WACN,aAAa,EAAE"}
1
+ {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAgCA,sCAWC;AAgbD;;;;;;;GAOG;AACH,uDAJa,OAAO,MAAM,EAAE,MAAM,CAAC,CAqBlC;;AAvcD;;GAEG;AACH;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;;;;;OAaG;IACH,uBATW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAUlC;IACD;;;;;;;OAOG;IACH,aAJa,QAAQ,WAAW,CAAC,CAMhC;IACD;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sCA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AAM;cACN,GAAG,EAAE;UACL,GAAG;WACH,MAAM;gBACN,MAAM;YACN,GAAG;;;WAMH,MAAM;WACN,MAAM;WACN,aAAa,EAAE"}
@@ -34,9 +34,10 @@ export function deleteEntry({ env, dmShortID, model, entryID, token }: {
34
34
  entryID: any;
35
35
  token: any;
36
36
  }): Promise<void>;
37
- export function getSchema({ env, dmShortID, model }: {
37
+ export function getSchema({ env, dmShortID, model, withMetadata }: {
38
38
  env: any;
39
39
  dmShortID: any;
40
40
  model: any;
41
+ withMetadata: any;
41
42
  }): Promise<{}>;
42
43
  //# sourceMappingURL=entries.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAiCA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;;iBAkCC;AAED;;;;;;kBAcC;AAED;;;;gBAsCC"}
1
+ {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAiCA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;;iBAkCC;AAED;;;;;;kBAcC;AAED;;;;;gBA4CC"}
@@ -2,4 +2,19 @@ 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 type SdkFilter = {
6
+ sort: string | string[];
7
+ search: string;
8
+ notNull: boolean;
9
+ null: boolean;
10
+ any: any[][];
11
+ from: string;
12
+ to: string;
13
+ };
14
+ export type SdkFilterOptions = {
15
+ sort: SdkFilter;
16
+ _count: number;
17
+ page: number;
18
+ key?: Record<string, SdkFilter> | string | boolean;
19
+ };
5
20
  //# sourceMappingURL=util.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAsBC;AAiBD,0EAcC;AAED,wDAKC;AAED,uCAMC"}
1
+ {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAsBC;AAiBD,0EAgBC;AAED,wDAKC;AAED,uCAMC;;UAIa,MAAM,GAAG,MAAM,EAAE;YACjB,MAAM;aACN,OAAO;UACP,OAAO;SACP,OAAO;UACP,MAAM;QACN,MAAM;;;UAKN,SAAS;YACT,MAAM;UACN,MAAM;UACN,OAAO,MAAM,EAAE,SAAS,CAAC,GAAG,MAAM,GAAG,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {