ec.fdk 0.2.30 → 0.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +16 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var tt=Object.defineProperty,et=Object.defineProperties;var nt=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var st=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?tt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))st.call(t,e)&&S(n,e,t[e]);if(L)for(var e of L(t))rt.call(t,e)&&S(n,e,t[e]);return n},f=(n,t)=>et(n,nt(t));var c=(n,t,e)=>new Promise((s,r)=>{var a=o=>{try{h(e.next(o))}catch(l){r(l)}},i=o=>{try{h(e.throw(o))}catch(l){r(l)}},h=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,i);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return c(this,arguments,function*(n,t={},e={}){var h;const{token:r,rawRes:a}=t;r&&(e.headers=f(u({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((h=i.headers.get("content-type"))!=null&&h.includes("application/json")){const o=yield i.json(),l=`${o.title}
|
|
2
2
|
${o.detail}
|
|
3
|
-
${o.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return a?i:yield i.json()})}const j={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(n,t="stage"){const e=j[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`);return e+n}function w(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function d(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const B={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function q(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function D(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${B[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${B[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function J({dmShortID:n}){return d({dmShortID:n}),n}function N({env:n}){return d({env:n}),n}let it=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function R(n){let t={};for(let e in n)it.includes(e)||(t[e]=n[e]);return t}function ot(n){return JSON.parse(JSON.stringify(n))}function z(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=y(`api/${e}`,t);return g(s,n)})}function C(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=u({size:50,page:1,_list:!0},r);const a=w(r),i=y(`api/${e}/${s}?${a}`,t),{count:h,total:o,_embedded:l}=yield g(i,n);let $=l?l[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:h,total:o,items:$}})}function F({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return g(i,{dmShortID:t,token:r})}function M(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function U(i){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const h=y(`api/${t}/${e}?_id=${s}`,n);return r=ot(r),r=R(r),yield g(h,{token:a},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function v(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function V(s){return c(this,arguments,function*({env:n,dmShortID:t,model:e}){var l,$,m,P,_;d({env:n,dmShortID:t,model:e});const r=y(`api/schema/${t}/${e}`,n),a=yield g(r),i=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof i.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=i,o=R(h);for(let A in o){let p=o[A];if(p.required=i.required.includes(A),($=o[A])!=null&&$.oneOf&&((m=o[A])==null||delete m.oneOf),(P=p.title)!=null&&P.includes("<")&&((_=p.title)!=null&&_.includes(">"))){const O=p.title.split("<")[1].slice(0,-1),Z=p.title.split("<")[0];p.type=Z,p.resource.includes(":")?p.resource=O.split(":")[1]:p.resource=O}else["asset","entry","assets","entries"].includes(p.title)?(p.type=p.title,p.resource=null):p.type=p.title;delete o[A].title}return o})}function G(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),h=y(`a/${t}/${e}?${i}`,n);return(yield g(h,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function H(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=u({size:50,page:1,_list:!0},a);const i=w(a),h=y(`a/${e}/${s}?${i}`,t),{count:o,total:l,_embedded:$}=yield g(h,{dmShortID:e,token:r});let m=$?$["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:o,total:l,items:m}})}function I(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:i}){d({env:n,dmShortID:t,assetGroup:e,file:r});const o=y(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),i&&Object.keys(i).forEach(m=>{l.append(m,i[m])}),(yield g(o,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function Q(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function W(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function X(n){return c(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=u({size:25,page:1,_list:!0},e);const s=w(e),r=y(`?${s}`,t),{count:a,total:i,_embedded:h}=yield g(r,n);let o=h?h["ec:datamanager"]:[];return o=Array.isArray(o)?o:[o],{count:a,total:i,items:o}})}function Y(n){return c(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=u({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),a=y(`model?${r}`,t),{count:i,total:h,_embedded:o}=yield g(a,n);let l=o?o["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:i,total:h,items:l}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:I,createEntry:M,deleteAsset:Q,deleteEntry:v,dmList:X,editEntry:U,entryList:C,getAsset:G,getDatamanager:W,getEcAuthKey:N,getEntry:F,getPublicAuthKey:J,getSchema:V,loginEc:D,loginPublic:q,logoutEc:x,logoutPublic:K,modelList:Y,publicApi:z},Symbol.toStringTag,{value:"Module"})),{entryList:ct,getEntry:at,getAsset:ut,assetList:lt,createAsset:ht,deleteAsset:dt,createEntry:gt,editEntry:yt,deleteEntry:ft,getSchema:pt,loginPublic:$t,loginEc:mt,logoutEc:wt,logoutPublic:At,getEcAuthKey:b,getPublicAuthKey:T,dmList:kt,modelList:Et,publicApi:bt,getDatamanager:Tt}=k;function Pt(n){const{action:t}=n;if(d({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class E{constructor(t){this.config=t}set(t){return new E(u(u({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return ct(f(u({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}getEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return at(f(u({},this.config),{entryID:t,token:e}))})}getSchema(){return c(this,null,function*(){return pt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return lt(f(u({},this.config),{options:t,token:e}))})}assetList(t){return c(this,null,function*(){return this.assets(t)})}createAsset(){return c(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return ht(f(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return dt(f(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ut(f(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(f(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return yt(f(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return ft(f(u({},this.config),{token:e,entryID:t}))})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return mt(u(u({},this.config),t)).then(this.setAuth(b(this.config)))}loginPublic(t){return $t(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),At(f(u({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),wt(f(u({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}getPublicToken(){return this.config.token||this.getAuth(T(this.config))}getEcToken(){return this.config.token||this.getAuth(b(this.config))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch(t){return}}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dmID(t){return this.set({dmID:t})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}publicApi(){return bt(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Tt(f(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return kt(f(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Et(f(u({},this.config),{options:t,token:e}))})}}const _t=n=>new E({env:n});exports.Sdk=E;exports.act=Pt;exports.apiURL=y;exports.assetList=H;exports.createAsset=I;exports.createEntry=M;exports.deleteAsset=Q;exports.deleteEntry=v;exports.dmList=X;exports.editEntry=U;exports.entryList=C;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=W;exports.getEcAuthKey=N;exports.getEntry=F;exports.getPublicAuthKey=J;exports.getSchema=V;exports.loginEc=D;exports.loginPublic=q;exports.logoutEc=x;exports.logoutPublic=K;exports.modelList=Y;exports.publicApi=z;exports.query=w;exports.sdk=_t;
|
|
3
|
+
${o.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return a?i:yield i.json()})}const j={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(n,t="stage"){const e=j[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`);return e+n}function w(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function d(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const B={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function q(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function D(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${B[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${B[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function J({dmShortID:n}){return d({dmShortID:n}),n}function N({env:n}){return d({env:n}),n}let it=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function R(n){let t={};for(let e in n)it.includes(e)||(t[e]=n[e]);return t}function ot(n){return JSON.parse(JSON.stringify(n))}function z(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=y(`api/${e}`,t);return g(s,n)})}function C(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=u({size:50,page:1,_list:!0},r);const a=w(r),i=y(`api/${e}/${s}?${a}`,t),{count:h,total:o,_embedded:l}=yield g(i,n);let $=l?l[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:h,total:o,items:$}})}function F({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return g(i,{dmShortID:t,token:r})}function M(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function U(i){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const h=y(`api/${t}/${e}?_id=${s}`,n);return r=ot(r),r=R(r),yield g(h,{token:a},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function v(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function V(s){return c(this,arguments,function*({env:n,dmShortID:t,model:e}){var l,$,m,_,O;d({env:n,dmShortID:t,model:e});const r=y(`api/schema/${t}/${e}`,n),a=yield g(r),i=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof i.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=i,o=R(h);for(let A in o){let p=o[A];if(p.required=i.required.includes(A),($=o[A])!=null&&$.oneOf&&((m=o[A])==null||delete m.oneOf),(_=p.title)!=null&&_.includes("<")&&((O=p.title)!=null&&O.includes(">"))){const b=p.title.split("<")[1].slice(0,-1),Z=p.title.split("<")[0];p.type=Z,b.includes(":")?p.resource=b.split(":")[1]:p.resource=b}else["asset","entry","assets","entries"].includes(p.title)?(p.type=p.title,p.resource=null):p.type=p.title;delete o[A].title}return o})}function G(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),h=y(`a/${t}/${e}?${i}`,n);return(yield g(h,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function H(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=u({size:50,page:1,_list:!0},a);const i=w(a),h=y(`a/${e}/${s}?${i}`,t),{count:o,total:l,_embedded:$}=yield g(h,{dmShortID:e,token:r});let m=$?$["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:o,total:l,items:m}})}function I(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:i}){d({env:n,dmShortID:t,assetGroup:e,file:r});const o=y(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),i&&Object.keys(i).forEach(m=>{l.append(m,i[m])}),(yield g(o,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function Q(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function W(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function X(n){return c(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=u({size:25,page:1,_list:!0},e);const s=w(e),r=y(`?${s}`,t),{count:a,total:i,_embedded:h}=yield g(r,n);let o=h?h["ec:datamanager"]:[];return o=Array.isArray(o)?o:[o],{count:a,total:i,items:o}})}function Y(n){return c(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=u({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),a=y(`model?${r}`,t),{count:i,total:h,_embedded:o}=yield g(a,n);let l=o?o["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:i,total:h,items:l}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:I,createEntry:M,deleteAsset:Q,deleteEntry:v,dmList:X,editEntry:U,entryList:C,getAsset:G,getDatamanager:W,getEcAuthKey:N,getEntry:F,getPublicAuthKey:J,getSchema:V,loginEc:D,loginPublic:q,logoutEc:x,logoutPublic:K,modelList:Y,publicApi:z},Symbol.toStringTag,{value:"Module"})),{entryList:ct,getEntry:at,getAsset:ut,assetList:lt,createAsset:ht,deleteAsset:dt,createEntry:gt,editEntry:yt,deleteEntry:ft,getSchema:pt,loginPublic:$t,loginEc:mt,logoutEc:wt,logoutPublic:At,getEcAuthKey:T,getPublicAuthKey:P,dmList:kt,modelList:Et,publicApi:bt,getDatamanager:Tt}=k;function Pt(n){const{action:t}=n;if(d({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class E{constructor(t){this.config=t}set(t){return new E(u(u({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return ct(f(u({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}getEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return at(f(u({},this.config),{entryID:t,token:e}))})}getSchema(){return c(this,null,function*(){return pt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return lt(f(u({},this.config),{options:t,token:e}))})}assetList(t){return c(this,null,function*(){return this.assets(t)})}createAsset(){return c(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return ht(f(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return dt(f(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ut(f(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(f(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return yt(f(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return ft(f(u({},this.config),{token:e,entryID:t}))})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return mt(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return $t(u(u({},this.config),t)).then(this.setAuth(P(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),At(f(u({},this.config),{token:t})).then(this.unsetAuth(P(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),wt(f(u({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}getPublicToken(){return this.config.token||this.getAuth(P(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)}publicApi(){return bt(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Tt(f(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return kt(f(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Et(f(u({},this.config),{options:t,token:e}))})}}const _t=n=>new E({env:n});exports.Sdk=E;exports.act=Pt;exports.apiURL=y;exports.assetList=H;exports.createAsset=I;exports.createEntry=M;exports.deleteAsset=Q;exports.deleteEntry=v;exports.dmList=X;exports.editEntry=U;exports.entryList=C;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=W;exports.getEcAuthKey=N;exports.getEntry=F;exports.getPublicAuthKey=J;exports.getSchema=V;exports.loginEc=D;exports.loginPublic=q;exports.logoutEc=x;exports.logoutPublic=K;exports.modelList=Y;exports.publicApi=z;exports.query=w;exports.sdk=_t;
|
package/dist/index.mjs
CHANGED
|
@@ -253,7 +253,7 @@ function Y(c) {
|
|
|
253
253
|
}
|
|
254
254
|
function Z(s) {
|
|
255
255
|
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
|
|
256
|
-
var l, $, m,
|
|
256
|
+
var l, $, m, _, O;
|
|
257
257
|
d({ env: n, dmShortID: t, model: e });
|
|
258
258
|
const r = y(`api/schema/${t}/${e}`, n), c = yield g(r), i = (l = c == null ? void 0 : c.allOf) == null ? void 0 : l[1];
|
|
259
259
|
if (typeof i.properties != "object")
|
|
@@ -263,9 +263,9 @@ function Z(s) {
|
|
|
263
263
|
const { properties: h } = i, o = q(h);
|
|
264
264
|
for (let A in o) {
|
|
265
265
|
let p = o[A];
|
|
266
|
-
if (p.required = i.required.includes(A), ($ = o[A]) != null && $.oneOf && ((m = o[A]) == null || delete m.oneOf), (
|
|
267
|
-
const
|
|
268
|
-
p.type = D,
|
|
266
|
+
if (p.required = i.required.includes(A), ($ = o[A]) != null && $.oneOf && ((m = o[A]) == null || delete m.oneOf), (_ = p.title) != null && _.includes("<") && ((O = p.title) != null && O.includes(">"))) {
|
|
267
|
+
const k = p.title.split("<")[1].slice(0, -1), D = p.title.split("<")[0];
|
|
268
|
+
p.type = D, k.includes(":") ? p.resource = k.split(":")[1] : p.resource = k;
|
|
269
269
|
} else
|
|
270
270
|
["asset", "entry", "assets", "entries"].includes(p.title) ? (p.type = p.title, p.resource = null) : p.type = p.title;
|
|
271
271
|
delete o[A].title;
|
|
@@ -395,8 +395,8 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
395
395
|
loginEc: mt,
|
|
396
396
|
logoutEc: wt,
|
|
397
397
|
logoutPublic: At,
|
|
398
|
-
getEcAuthKey:
|
|
399
|
-
getPublicAuthKey:
|
|
398
|
+
getEcAuthKey: b,
|
|
399
|
+
getPublicAuthKey: T,
|
|
400
400
|
dmList: Et,
|
|
401
401
|
modelList: kt,
|
|
402
402
|
publicApi: bt,
|
|
@@ -412,12 +412,12 @@ function _t(n) {
|
|
|
412
412
|
);
|
|
413
413
|
return E[t](n);
|
|
414
414
|
}
|
|
415
|
-
class
|
|
415
|
+
class P {
|
|
416
416
|
constructor(t) {
|
|
417
417
|
this.config = t;
|
|
418
418
|
}
|
|
419
419
|
set(t) {
|
|
420
|
-
return new
|
|
420
|
+
return new P(u(u({}, this.config), t));
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
423
423
|
* Loads entry list. Expects `dmShortID` / `model` to be set.
|
|
@@ -626,31 +626,31 @@ class T {
|
|
|
626
626
|
}
|
|
627
627
|
loginEc(t) {
|
|
628
628
|
return mt(u(u({}, this.config), t)).then(
|
|
629
|
-
this.setAuth(
|
|
629
|
+
this.setAuth(b(this.config))
|
|
630
630
|
);
|
|
631
631
|
}
|
|
632
632
|
loginPublic(t) {
|
|
633
633
|
return $t(u(u({}, this.config), t)).then(
|
|
634
|
-
this.setAuth(
|
|
634
|
+
this.setAuth(T(this.config))
|
|
635
635
|
);
|
|
636
636
|
}
|
|
637
637
|
logoutPublic() {
|
|
638
638
|
const t = this.getPublicToken();
|
|
639
639
|
return console.log("token", t), At(f(u({}, this.config), { token: t })).then(
|
|
640
|
-
this.unsetAuth(
|
|
640
|
+
this.unsetAuth(T(this.config))
|
|
641
641
|
);
|
|
642
642
|
}
|
|
643
643
|
logoutEc() {
|
|
644
644
|
const t = this.getEcToken();
|
|
645
645
|
return console.log("token", t), wt(f(u({}, this.config), { token: t })).then(
|
|
646
|
-
this.unsetAuth(
|
|
646
|
+
this.unsetAuth(b(this.config))
|
|
647
647
|
);
|
|
648
648
|
}
|
|
649
649
|
getPublicToken() {
|
|
650
|
-
return this.config.token || this.getAuth(
|
|
650
|
+
return this.config.token || this.getAuth(T(this.config));
|
|
651
651
|
}
|
|
652
652
|
getEcToken() {
|
|
653
|
-
return this.config.token || this.getAuth(
|
|
653
|
+
return this.config.token || this.getAuth(b(this.config));
|
|
654
654
|
}
|
|
655
655
|
hasPublicToken() {
|
|
656
656
|
return !!this.getPublicToken();
|
|
@@ -770,9 +770,9 @@ class T {
|
|
|
770
770
|
});
|
|
771
771
|
}
|
|
772
772
|
}
|
|
773
|
-
const Ot = (n) => new
|
|
773
|
+
const Ot = (n) => new P({ env: n });
|
|
774
774
|
export {
|
|
775
|
-
|
|
775
|
+
P as Sdk,
|
|
776
776
|
_t as act,
|
|
777
777
|
y as apiURL,
|
|
778
778
|
et as assetList,
|