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 +18 -2
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +244 -233
- package/dist/lib/admin.d.mts +1 -1
- package/dist/lib/admin.d.mts.map +1 -1
- package/dist/lib/api.d.mts +13 -1
- package/dist/lib/api.d.mts.map +1 -1
- package/dist/lib/entries.d.mts +2 -1
- package/dist/lib/entries.d.mts.map +1 -1
- package/dist/lib/util.d.mts +15 -0
- package/dist/lib/util.d.mts.map +1 -1
- package/package.json +1 -1
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.<EntryResource></code>](#EntryResource)
|
|
73
73
|
* [.deleteEntry(entryID)](#module_api.Sdk+deleteEntry) ⇒ <code>void</code>
|
|
74
74
|
* [.resourceList([options])](#module_api.Sdk+resourceList) ⇒ [<code>Promise.<ResourceList></code>](#ResourceList)
|
|
75
|
-
* [.raw([options])](#module_api.Sdk+raw) ⇒ <code>Promise.<any></code>
|
|
75
|
+
* [.raw([options], [fetchOptions])](#module_api.Sdk+raw) ⇒ <code>Promise.<any></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.<any></code>
|
|
316
|
+
#### sdk.raw([options], [fetchOptions]) ⇒ <code>Promise.<any></code>
|
|
317
317
|
<p>Fetches raw route. Expects <code>route</code> to be set. <code>subdomain</code> defaults to "datamanager".
|
|
318
318
|
Fetches <code>https://<subdomain>.entrecode.de/<route>?<options></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.<any></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
|
|
2
|
-
${
|
|
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
|
|
1
|
+
var N = Object.defineProperty, z = Object.defineProperties;
|
|
2
2
|
var C = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
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
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
|
|
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
|
|
14
|
+
var l = (c) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
r(
|
|
16
|
+
d(e.next(c));
|
|
17
|
+
} catch (u) {
|
|
18
|
+
r(u);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, i = (c) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
r(
|
|
22
|
+
d(e.throw(c));
|
|
23
|
+
} catch (u) {
|
|
24
|
+
r(u);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
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
|
|
32
|
-
const { token: r, rawRes:
|
|
33
|
-
r && (e.headers = y(
|
|
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
|
|
37
|
-
if (!
|
|
38
|
-
if ((
|
|
39
|
-
const
|
|
40
|
-
${
|
|
41
|
-
${
|
|
42
|
-
throw new Error(
|
|
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: ${
|
|
44
|
+
throw new Error(`unexpected fetch error: ${i.statusText}`);
|
|
45
45
|
}
|
|
46
|
-
return
|
|
46
|
+
return l ? i : yield i.json();
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
const
|
|
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 =
|
|
64
|
+
const s = B[e];
|
|
65
65
|
if (!s)
|
|
66
66
|
throw new Error(
|
|
67
|
-
`subdomain "${e}" not found. Try one of ${Object.keys(
|
|
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
|
|
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
|
|
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
|
-
|
|
93
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
111
|
-
const r = `${
|
|
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
|
-
|
|
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
|
|
144
|
+
function M(n) {
|
|
143
145
|
return a(this, null, function* () {
|
|
144
146
|
let { env: t, token: e } = n;
|
|
145
|
-
|
|
146
|
-
const s = `${
|
|
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
|
|
160
|
-
return
|
|
161
|
+
function I({ dmShortID: n }) {
|
|
162
|
+
return h({ dmShortID: n }), n;
|
|
161
163
|
}
|
|
162
|
-
function
|
|
163
|
-
return
|
|
164
|
+
function V({ env: n }) {
|
|
165
|
+
return h({ env: n }), n;
|
|
164
166
|
}
|
|
165
|
-
let
|
|
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
|
|
183
|
+
function x(n) {
|
|
182
184
|
let t = {};
|
|
183
185
|
for (let e in n)
|
|
184
|
-
|
|
186
|
+
G.includes(e) || (t[e] = n[e]);
|
|
185
187
|
return t;
|
|
186
188
|
}
|
|
187
|
-
function
|
|
189
|
+
function H(n) {
|
|
188
190
|
return JSON.parse(JSON.stringify(n));
|
|
189
191
|
}
|
|
190
|
-
function
|
|
192
|
+
function Q(n) {
|
|
191
193
|
return a(this, null, function* () {
|
|
192
194
|
let { env: t, dmShortID: e } = n;
|
|
193
|
-
|
|
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
|
|
200
|
+
function W(n) {
|
|
199
201
|
return a(this, null, function* () {
|
|
200
202
|
let { env: t, dmShortID: e, model: s, options: r = {} } = n;
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
let f =
|
|
204
|
-
return f = Array.isArray(f) ? f : [f], { count:
|
|
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
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
return g(
|
|
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
|
|
214
|
+
function Y(l) {
|
|
213
215
|
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
+
h({ env: n, dmShortID: t, model: e, value: s });
|
|
217
|
+
const i = p(`api/${t}/${e}`, n);
|
|
216
218
|
return yield g(
|
|
217
|
-
|
|
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
|
|
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:
|
|
237
|
-
safePut:
|
|
238
|
+
token: l,
|
|
239
|
+
safePut: i = !1
|
|
238
240
|
}) {
|
|
239
|
-
|
|
240
|
-
const
|
|
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 (
|
|
245
|
+
if (i) {
|
|
244
246
|
if (!("_modified" in r))
|
|
245
247
|
throw new Error("expected _modified to be set!");
|
|
246
|
-
|
|
248
|
+
c["If-Unmodified-Since"] = new Date(r._modified).toUTCString();
|
|
247
249
|
}
|
|
248
|
-
const
|
|
249
|
-
return r =
|
|
250
|
-
|
|
251
|
-
{ token:
|
|
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:
|
|
256
|
+
headers: c,
|
|
255
257
|
body: JSON.stringify(r)
|
|
256
258
|
}
|
|
257
259
|
);
|
|
258
260
|
});
|
|
259
261
|
}
|
|
260
|
-
function
|
|
262
|
+
function tt(l) {
|
|
261
263
|
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
|
|
262
|
-
|
|
263
|
-
const
|
|
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
|
-
|
|
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
|
|
277
|
-
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
if (typeof
|
|
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: ${
|
|
285
|
+
`getSchema: ${l} returned unexpected format: ${JSON.stringify(i)}`
|
|
284
286
|
);
|
|
285
|
-
const { properties:
|
|
286
|
-
for (let
|
|
287
|
-
let
|
|
288
|
-
if (
|
|
289
|
-
const
|
|
290
|
-
|
|
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(
|
|
293
|
-
delete
|
|
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
|
|
301
|
+
return u;
|
|
296
302
|
});
|
|
297
303
|
}
|
|
298
|
-
function
|
|
304
|
+
function nt(l) {
|
|
299
305
|
return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
return (yield g(
|
|
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
|
|
311
|
+
function st(n) {
|
|
306
312
|
return a(this, null, function* () {
|
|
307
|
-
let { env: t, dmShortID: e, assetGroup: s, token: r, options:
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
let
|
|
311
|
-
return
|
|
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
|
|
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:
|
|
322
|
-
options:
|
|
327
|
+
name: l,
|
|
328
|
+
options: i
|
|
323
329
|
}) {
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
return
|
|
327
|
-
|
|
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
|
-
|
|
335
|
+
c,
|
|
330
336
|
{ token: s },
|
|
331
337
|
{
|
|
332
338
|
method: "POST",
|
|
333
|
-
body:
|
|
339
|
+
body: u
|
|
334
340
|
}
|
|
335
341
|
))._embedded["ec:dm-asset"];
|
|
336
342
|
});
|
|
337
343
|
}
|
|
338
|
-
function
|
|
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
|
-
|
|
347
|
-
const
|
|
352
|
+
h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
|
|
353
|
+
const i = p(`a/${t}/${e}/${s}`, n);
|
|
348
354
|
yield g(
|
|
349
|
-
|
|
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
|
-
|
|
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
|
|
371
|
+
function at(n) {
|
|
366
372
|
return a(this, null, function* () {
|
|
367
373
|
let { env: t, options: e = {} } = n;
|
|
368
|
-
|
|
369
|
-
const s = w(e), r = p(`?${s}`, t), { count:
|
|
370
|
-
let
|
|
371
|
-
return
|
|
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
|
|
380
|
+
function ct(n) {
|
|
375
381
|
return a(this, null, function* () {
|
|
376
382
|
let { env: t, dmID: e, options: s = {} } = n;
|
|
377
|
-
|
|
378
|
-
const r = w(s),
|
|
379
|
-
let
|
|
380
|
-
return
|
|
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
|
|
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
|
-
|
|
387
|
-
const
|
|
388
|
-
let f =
|
|
389
|
-
return f = Array.isArray(f) ? f : [f], { count:
|
|
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
|
|
393
|
-
return a(this,
|
|
394
|
-
let { env:
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
return g(
|
|
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
|
|
406
|
+
const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
401
407
|
__proto__: null,
|
|
402
|
-
assetList:
|
|
403
|
-
createAsset:
|
|
404
|
-
createEntry:
|
|
405
|
-
deleteAsset:
|
|
406
|
-
deleteEntry:
|
|
407
|
-
dmList:
|
|
408
|
-
editEntry:
|
|
409
|
-
entryList:
|
|
410
|
-
getAsset:
|
|
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:
|
|
413
|
-
getEntry:
|
|
414
|
-
getPublicAuthKey:
|
|
415
|
-
getSchema:
|
|
418
|
+
getEcAuthKey: V,
|
|
419
|
+
getEntry: X,
|
|
420
|
+
getPublicAuthKey: I,
|
|
421
|
+
getSchema: et,
|
|
416
422
|
loginEc: v,
|
|
417
423
|
loginPublic: R,
|
|
418
|
-
logoutEc:
|
|
424
|
+
logoutEc: M,
|
|
419
425
|
logoutPublic: U,
|
|
420
|
-
modelList:
|
|
421
|
-
publicApi:
|
|
422
|
-
raw:
|
|
423
|
-
resourceList:
|
|
426
|
+
modelList: ct,
|
|
427
|
+
publicApi: Q,
|
|
428
|
+
raw: lt,
|
|
429
|
+
resourceList: ut
|
|
424
430
|
}, Symbol.toStringTag, { value: "Module" })), {
|
|
425
|
-
entryList:
|
|
426
|
-
getEntry:
|
|
427
|
-
getAsset:
|
|
428
|
-
assetList:
|
|
429
|
-
createAsset:
|
|
430
|
-
deleteAsset:
|
|
431
|
-
createEntry:
|
|
432
|
-
editEntry:
|
|
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:
|
|
435
|
-
loginPublic:
|
|
436
|
-
loginEc:
|
|
437
|
-
logoutEc:
|
|
438
|
-
logoutPublic:
|
|
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:
|
|
442
|
-
modelList:
|
|
443
|
-
publicApi:
|
|
444
|
-
getDatamanager:
|
|
445
|
-
resourceList:
|
|
446
|
-
raw:
|
|
447
|
-
} =
|
|
448
|
-
function
|
|
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 (
|
|
456
|
+
if (h({ action: t }), !E[t])
|
|
451
457
|
throw new Error(
|
|
452
|
-
`"${t}" does not exist! try one of ${Object.keys(
|
|
458
|
+
`"${t}" does not exist! try one of ${Object.keys(E).join(
|
|
453
459
|
", "
|
|
454
460
|
)}`
|
|
455
461
|
);
|
|
456
|
-
return
|
|
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 _(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
692
|
-
return
|
|
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
|
|
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
|
|
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),
|
|
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),
|
|
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
|
|
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
|
|
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
|
|
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
|
|
894
|
+
return _t(y(o({}, this.config), { options: t, token: e }));
|
|
888
895
|
});
|
|
889
896
|
}
|
|
890
897
|
}
|
|
891
|
-
const
|
|
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
|
-
|
|
904
|
+
Bt as act,
|
|
895
905
|
p as apiURL,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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
|
-
|
|
916
|
+
nt as getAsset,
|
|
907
917
|
ot as getDatamanager,
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
-
|
|
924
|
+
M as logoutEc,
|
|
915
925
|
U as logoutPublic,
|
|
916
|
-
|
|
917
|
-
|
|
926
|
+
ct as modelList,
|
|
927
|
+
Q as publicApi,
|
|
918
928
|
w as query,
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
929
|
+
lt as raw,
|
|
930
|
+
ut as resourceList,
|
|
931
|
+
qt as sdk,
|
|
932
|
+
Dt as sdkOptions
|
|
922
933
|
};
|
package/dist/lib/admin.d.mts
CHANGED
package/dist/lib/admin.d.mts.map
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/lib/api.d.mts
CHANGED
|
@@ -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 = {
|
package/dist/lib/api.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAgCA,sCAWC;;
|
|
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,sCAjBW;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,MAAM,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAClD,QAAQ,aAAa,CAAC,CAmBlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAOzB;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IAED;;;;;;;;OAQG;IACH,mBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;OASG;IACH,mBANW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,IAAI,CAOhB;IAED;;;;;;;;OAQG;IACH,uBALW,MAAM,eACJ,QAAQ,YAAY,CAAC,CAOjC;IAED;;;;;;;;;;OAUG;IACH,cANW,MAAM,6BACN,MAAM,eACJ,QAAQ,GAAG,CAAC,CAOxB;IAID,mCAGC;IAED,sCASC;IACD,wCAUC;IACD,uBAMC;IAED,mCAIC;IACD,uCAKC;IAED,6BAMC;IAED,yBAMC;IAED,sBAEC;IACD,kBAEC;IACD,0BAEC;IACD,sBAEC;IACD,uBAEC;IACD,oBAMC;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,WAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,cAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,mBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IAED;;;OAGG;IACH,0BAEC;IAED;;;OAGG;IACH,wCAGC;IAED;;;;;;;OAOG;IACH,iBALW,MAAM,eACJ,QAAQ,eAAe,CAAC,CAOpC;IACD;;;;;;;OAOG;IACH,oBALW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAO9B;CACF;AAEM,mCAAqC;;SA+B9B,MAAM;UACN,MAAM;;;;aAMN,MAAM;aACN,IAAI;WACJ,MAAM,GAAG,CAAC;UACV,MAAM,MAAM,GAAG,GAAG,CAAC;WACnB,MAAM;UACN,MAAM;cACN,MAAM;gBACN,MAAM;UACN,SAAS;;;;;;QAKT,MAAM;;;;cACN,IAAI;;;;cACJ,MAAM;;;;eACN,GAAG;;;;YACH,GAAG;;;;iBACH,MAAM;;;;sBACN,MAAM;;;;eACN,IAAI;;;;aACJ,IAAI;;;;cACJ,IAAI;;;;UACJ,GAAG;;;;;;aAOH,GAAG;;;;iBACH,MAAM;;;;cACN,OAAO;;;;cACP,OAAO;;;;UACP,MAAM;;;;cACN,MAAM;;;QAIC,MAAM,GAAE,gBAAgB;;;WAK/B,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;aAKf,MAAM;mBACN,MAAM;mBACN,MAAM;iBACN,MAAM;YACN,GAAG;cACH,MAAM;aACN,MAAM,EAAE;YACR,MAAM,EAAE;uBACR,MAAM,EAAE;aACR,MAAM;WACN,MAAM;;;;YACN,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,mBAAmB,EAAE;;;WAKrB,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;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"}
|
package/dist/lib/entries.d.mts
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/lib/util.d.mts
CHANGED
|
@@ -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
|
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;AAiBD,
|
|
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"}
|