ec.fdk 0.2.21 → 0.2.22

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var v=Object.defineProperty,F=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var P=(n,t,e)=>t in n?v(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))H.call(t,e)&&P(n,e,t[e]);if(T)for(var e of T(t))Q.call(t,e)&&P(n,e,t[e]);return n},y=(n,t)=>F(n,G(t));var i=(n,t,e)=>new Promise((s,o)=>{var a=u=>{try{l(e.next(u))}catch(g){o(g)}},r=u=>{try{l(e.throw(u))}catch(g){o(g)}},l=u=>u.done?s(u.value):Promise.resolve(u.value).then(a,r);l((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(s){return i(this,arguments,function*(n,t={},e={}){var l;const{token:o,rawRes:a}=t;o&&(e.headers=y(c({},e.headers||{}),{Authorization:`Bearer ${o}`}));const r=yield fetch(n,e);if(!r.ok){if((l=r.headers.get("content-type"))!=null&&l.includes("application/json")){const u=yield r.json(),g=`${u.title}
1
+ "use strict";var v=Object.defineProperty,F=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var P=(n,t,e)=>t in n?v(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))H.call(t,e)&&P(n,e,t[e]);if(T)for(var e of T(t))Q.call(t,e)&&P(n,e,t[e]);return n},y=(n,t)=>F(n,G(t));var i=(n,t,e)=>new Promise((s,o)=>{var a=u=>{try{g(e.next(u))}catch(l){o(l)}},r=u=>{try{g(e.throw(u))}catch(l){o(l)}},g=u=>u.done?s(u.value):Promise.resolve(u.value).then(a,r);g((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(s){return i(this,arguments,function*(n,t={},e={}){var g;const{token:o,rawRes:a}=t;o&&(e.headers=y(c({},e.headers||{}),{Authorization:`Bearer ${o}`}));const r=yield fetch(n,e);if(!r.ok){if((g=r.headers.get("content-type"))!=null&&g.includes("application/json")){const u=yield r.json(),l=`${u.title}
2
2
  ${u.detail}
3
- ${u.verbose}`;throw new Error(g)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return a?r:yield r.json()})}const m={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=m[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(m).join(", ")}`);return e+n}function E(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const j={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function O(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;h({env:t,dmShortID:e,email:s,password:o});const a=f(`api/${e}/_auth/login?clientID=rest`,t);return yield d(a,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function _(n){return i(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const o=`${j[t]}auth/login?clientID=rest`;return yield d(o,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function L(n){return i(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const o=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield d(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function B(n){return i(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${j[t]}auth/logout?clientID=rest`;return yield d(s,{rawRes:!0,token:e},{method:"POST"})})}function S({dmShortID:n}){return h({dmShortID:n}),n}function K({env:n}){return h({env:n}),n}function R(n){return i(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;h({env:t,dmShortID:e,model:s}),o=c({size:50,page:1,_list:!0},o);const a=E(o),r=f(`api/${e}/${s}?${a}`,t),{count:l,total:u,_embedded:g}=yield d(r,n);let $=g?g[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:l,total:u,items:$}})}function q({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const a=E({_id:s}),r=f(`api/${t}/${e}?${a}`,n);return d(r,{dmShortID:t,token:o})}function x(a){return i(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){h({env:n,dmShortID:t,model:e,value:s}),console.log("create entry",t,e,s);const r=f(`api/${t}/${e}`,n);return console.log("url",r),yield d(r,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function C(r){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:o,token:a}){h({env:n,dmShortID:t,model:e,entryID:s,value:o});const l=f(`api/${t}/${e}?_id=${s}`,n);return yield d(l,{token:a},{method:"PUT",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function z(a){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const r=f(`api/${t}/${e}?_id=${s}`,n);yield d(r,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function J(a){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=E({assetID:s}),l=f(`a/${t}/${e}?${r}`,n);return(yield d(l,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function N(n){return i(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:o,options:a={}}=n;h({env:t,dmShortID:e,assetGroup:s}),a=c({size:50,page:1,_list:!0},a);const r=E(a),l=f(`a/${e}/${s}?${r}`,t),{count:u,total:g,_embedded:$}=yield d(l,{dmShortID:e,token:o});let p=$?$["ec:dm-asset"]:[];return p=Array.isArray(p)?p:[p],{count:u,total:g,items:p}})}function U(l){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:a,options:r}){h({env:n,dmShortID:t,assetGroup:e,file:o});const u=f(`a/${t}/${e}`,n),g=new FormData;return g.append("file",o,a),r&&Object.keys(r).forEach(p=>{g.append(p,r[p])}),(yield d(u,{token:s},{method:"POST",body:g}))._embedded["ec:dm-asset"]})}function M(a){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=f(`a/${t}/${e}/${s}`,n);return(yield d(r,{token:o,rawRes:!0},{method:"DELETE"}))._embedded["ec:dm-asset"]})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:U,createEntry:x,deleteAsset:M,deleteEntry:z,editEntry:C,entryList:R,getAsset:J,getEcAuthKey:K,getEntry:q,getPublicAuthKey:S,loginEc:_,loginPublic:O,logoutEc:B,logoutPublic:L},Symbol.toStringTag,{value:"Module"})),{entryList:V,getEntry:W,getAsset:X,assetList:Y,createAsset:Z,deleteAsset:D,createEntry:I,editEntry:tt,deleteEntry:et,loginPublic:nt,loginEc:st,logoutEc:ot,logoutPublic:rt,getEcAuthKey:w,getPublicAuthKey:b}=k;function it(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class A{constructor(t){this.config=t}set(t){return new A(c(c({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return V(y(c({},this.config),{options:t,token:e}))})}entryList(t){return i(this,null,function*(){return this.entries(t)})}getEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return W(y(c({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return Y(y(c({},this.config),{options:t,token:e}))})}assetList(t){return i(this,null,function*(){return this.assets(t)})}createAsset(){return i(this,arguments,function*({file:t,name:e,options:s}={}){const o=yield this.getBestToken();return Z(y(c({},this.config),{file:t,name:e,options:s,token:o}))})}deleteAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return D(y(c({},this.config),{token:e,assetID:t}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return X(y(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(y(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return tt(y(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return et(y(c({},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 st(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return nt(c(c({},this.config),t)).then(this.setAuth(b(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),rt(y(c({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),ot(y(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(b(this.config))}getEcToken(){return this.config.token||this.getAuth(w(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})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}}const ct=n=>new A({env:n});exports.Sdk=A;exports.act=it;exports.apiURL=f;exports.assetList=N;exports.createAsset=U;exports.createEntry=x;exports.deleteAsset=M;exports.deleteEntry=z;exports.editEntry=C;exports.entryList=R;exports.expect=h;exports.fetcher=d;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=q;exports.getPublicAuthKey=S;exports.loginEc=_;exports.loginPublic=O;exports.logoutEc=B;exports.logoutPublic=L;exports.query=E;exports.sdk=ct;
3
+ ${u.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return a?r:yield r.json()})}const m={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=m[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(m).join(", ")}`);return e+n}function E(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const j={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function O(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;h({env:t,dmShortID:e,email:s,password:o});const a=f(`api/${e}/_auth/login?clientID=rest`,t);return yield d(a,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function L(n){return i(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const o=`${j[t]}auth/login?clientID=rest`;return yield d(o,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function _(n){return i(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const o=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield d(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function B(n){return i(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${j[t]}auth/logout?clientID=rest`;return yield d(s,{rawRes:!0,token:e},{method:"POST"})})}function S({dmShortID:n}){return h({dmShortID:n}),n}function K({env:n}){return h({env:n}),n}function R(n){return i(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;h({env:t,dmShortID:e,model:s}),o=c({size:50,page:1,_list:!0},o);const a=E(o),r=f(`api/${e}/${s}?${a}`,t),{count:g,total:u,_embedded:l}=yield d(r,n);let $=l?l[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:g,total:u,items:$}})}function q({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const a=E({_id:s}),r=f(`api/${t}/${e}?${a}`,n);return d(r,{dmShortID:t,token:o})}function x(a){return i(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){h({env:n,dmShortID:t,model:e,value:s}),console.log("create entry",t,e,s);const r=f(`api/${t}/${e}`,n);return console.log("url",r),yield d(r,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function C(r){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:o,token:a}){h({env:n,dmShortID:t,model:e,entryID:s,value:o});const g=f(`api/${t}/${e}?_id=${s}`,n);return yield d(g,{token:a},{method:"PUT",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function z(a){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const r=f(`api/${t}/${e}?_id=${s}`,n);yield d(r,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function J(a){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=E({assetID:s}),g=f(`a/${t}/${e}?${r}`,n);return(yield d(g,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function N(n){return i(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:o,options:a={}}=n;h({env:t,dmShortID:e,assetGroup:s}),a=c({size:50,page:1,_list:!0},a);const r=E(a),g=f(`a/${e}/${s}?${r}`,t),{count:u,total:l,_embedded:$}=yield d(g,{dmShortID:e,token:o});let p=$?$["ec:dm-asset"]:[];return p=Array.isArray(p)?p:[p],{count:u,total:l,items:p}})}function U(g){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:a,options:r}){h({env:n,dmShortID:t,assetGroup:e,file:o});const u=f(`a/${t}/${e}`,n),l=new FormData;return l.append("file",o,a),r&&Object.keys(r).forEach(p=>{l.append(p,r[p])}),(yield d(u,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function M(a){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=f(`a/${t}/${e}/${s}`,n);yield d(r,{token:o,rawRes:!0},{method:"DELETE"})})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:U,createEntry:x,deleteAsset:M,deleteEntry:z,editEntry:C,entryList:R,getAsset:J,getEcAuthKey:K,getEntry:q,getPublicAuthKey:S,loginEc:L,loginPublic:O,logoutEc:B,logoutPublic:_},Symbol.toStringTag,{value:"Module"})),{entryList:V,getEntry:W,getAsset:X,assetList:Y,createAsset:Z,deleteAsset:D,createEntry:I,editEntry:tt,deleteEntry:et,loginPublic:nt,loginEc:st,logoutEc:ot,logoutPublic:rt,getEcAuthKey:w,getPublicAuthKey:b}=k;function it(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class A{constructor(t){this.config=t}set(t){return new A(c(c({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return V(y(c({},this.config),{options:t,token:e}))})}entryList(t){return i(this,null,function*(){return this.entries(t)})}getEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return W(y(c({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return Y(y(c({},this.config),{options:t,token:e}))})}assetList(t){return i(this,null,function*(){return this.assets(t)})}createAsset(){return i(this,arguments,function*({file:t,name:e,options:s}={}){const o=yield this.getBestToken();return Z(y(c({},this.config),{file:t,name:e,options:s,token:o}))})}deleteAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return D(y(c({},this.config),{token:e,assetID:t}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return X(y(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(y(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return tt(y(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return et(y(c({},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 st(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return nt(c(c({},this.config),t)).then(this.setAuth(b(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),rt(y(c({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),ot(y(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(b(this.config))}getEcToken(){return this.config.token||this.getAuth(w(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})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}}const ct=n=>new A({env:n});exports.Sdk=A;exports.act=it;exports.apiURL=f;exports.assetList=N;exports.createAsset=U;exports.createEntry=x;exports.deleteAsset=M;exports.deleteEntry=z;exports.editEntry=C;exports.entryList=R;exports.expect=h;exports.fetcher=d;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=q;exports.getPublicAuthKey=S;exports.loginEc=L;exports.loginPublic=O;exports.logoutEc=B;exports.logoutPublic=_;exports.query=E;exports.sdk=ct;
package/dist/index.mjs CHANGED
@@ -13,29 +13,29 @@ var P = (n, t, e) => t in n ? O(n, t, { enumerable: !0, configurable: !0, writab
13
13
  var i = (n, t, e) => new Promise((s, o) => {
14
14
  var a = (u) => {
15
15
  try {
16
- h(e.next(u));
16
+ g(e.next(u));
17
17
  } catch (l) {
18
18
  o(l);
19
19
  }
20
20
  }, r = (u) => {
21
21
  try {
22
- h(e.throw(u));
22
+ g(e.throw(u));
23
23
  } catch (l) {
24
24
  o(l);
25
25
  }
26
- }, h = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, r);
27
- h((e = e.apply(n, t)).next());
26
+ }, g = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, r);
27
+ g((e = e.apply(n, t)).next());
28
28
  });
29
29
  function y(s) {
30
30
  return i(this, arguments, function* (n, t = {}, e = {}) {
31
- var h;
31
+ var g;
32
32
  const { token: o, rawRes: a } = t;
33
33
  o && (e.headers = d(c({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${o}`
35
35
  }));
36
36
  const r = yield fetch(n, e);
37
37
  if (!r.ok) {
38
- if ((h = r.headers.get("content-type")) != null && h.includes("application/json")) {
38
+ if ((g = r.headers.get("content-type")) != null && g.includes("application/json")) {
39
39
  const u = yield r.json(), l = `${u.title}
40
40
  ${u.detail}
41
41
  ${u.verbose}`;
@@ -61,7 +61,7 @@ function f(n, t = "stage") {
61
61
  function A(n, t = !0) {
62
62
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
63
63
  }
64
- function g(n) {
64
+ function h(n) {
65
65
  Object.entries(n).forEach(([t, e]) => {
66
66
  if (e === void 0)
67
67
  throw new Error(`expected ${t} to be set!`);
@@ -74,7 +74,7 @@ const j = {
74
74
  function S(n) {
75
75
  return i(this, null, function* () {
76
76
  let { env: t, dmShortID: e, email: s, password: o } = n;
77
- g({ env: t, dmShortID: e, email: s, password: o });
77
+ h({ env: t, dmShortID: e, email: s, password: o });
78
78
  const a = f(`api/${e}/_auth/login?clientID=rest`, t);
79
79
  return yield y(
80
80
  a,
@@ -92,7 +92,7 @@ function S(n) {
92
92
  function x(n) {
93
93
  return i(this, null, function* () {
94
94
  let { env: t, email: e, password: s } = n;
95
- g({ env: t, email: e, password: s });
95
+ h({ env: t, email: e, password: s });
96
96
  const o = `${j[t]}auth/login?clientID=rest`;
97
97
  return yield y(
98
98
  o,
@@ -110,7 +110,7 @@ function x(n) {
110
110
  function C(n) {
111
111
  return i(this, null, function* () {
112
112
  let { dmShortID: t, env: e, token: s } = n;
113
- g({ dmShortID: t, env: e, token: s });
113
+ h({ dmShortID: t, env: e, token: s });
114
114
  const o = f(
115
115
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
116
116
  e
@@ -127,7 +127,7 @@ function C(n) {
127
127
  function R(n) {
128
128
  return i(this, null, function* () {
129
129
  let { env: t, token: e } = n;
130
- g({ env: t, token: e });
130
+ h({ env: t, token: e });
131
131
  const s = `${j[t]}auth/logout?clientID=rest`;
132
132
  return yield y(
133
133
  s,
@@ -142,28 +142,28 @@ function R(n) {
142
142
  });
143
143
  }
144
144
  function q({ dmShortID: n }) {
145
- return g({ dmShortID: n }), n;
145
+ return h({ dmShortID: n }), n;
146
146
  }
147
147
  function z({ env: n }) {
148
- return g({ env: n }), n;
148
+ return h({ env: n }), n;
149
149
  }
150
150
  function J(n) {
151
151
  return i(this, null, function* () {
152
152
  let { env: t, dmShortID: e, model: s, options: o = {} } = n;
153
- g({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
154
- const a = A(o), r = f(`api/${e}/${s}?${a}`, t), { count: h, total: u, _embedded: l } = yield y(r, n);
153
+ h({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
154
+ const a = A(o), r = f(`api/${e}/${s}?${a}`, t), { count: g, total: u, _embedded: l } = yield y(r, n);
155
155
  let $ = l ? l[`${e}:${s}`] : [];
156
- return $ = Array.isArray($) ? $ : [$], { count: h, total: u, items: $ };
156
+ return $ = Array.isArray($) ? $ : [$], { count: g, total: u, items: $ };
157
157
  });
158
158
  }
159
159
  function N({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
160
- g({ env: n, dmShortID: t, model: e, entryID: s });
160
+ h({ env: n, dmShortID: t, model: e, entryID: s });
161
161
  const a = A({ _id: s }), r = f(`api/${t}/${e}?${a}`, n);
162
162
  return y(r, { dmShortID: t, token: o });
163
163
  }
164
164
  function U(a) {
165
165
  return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
166
- g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
166
+ h({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
167
167
  const r = f(`api/${t}/${e}`, n);
168
168
  return console.log("url", r), yield y(
169
169
  r,
@@ -187,10 +187,10 @@ function F(r) {
187
187
  value: o,
188
188
  token: a
189
189
  }) {
190
- g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
191
- const h = f(`api/${t}/${e}?_id=${s}`, n);
190
+ h({ env: n, dmShortID: t, model: e, entryID: s, value: o });
191
+ const g = f(`api/${t}/${e}?_id=${s}`, n);
192
192
  return yield y(
193
- h,
193
+ g,
194
194
  { token: a },
195
195
  {
196
196
  method: "PUT",
@@ -204,7 +204,7 @@ function F(r) {
204
204
  }
205
205
  function M(a) {
206
206
  return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
207
- g({ env: n, dmShortID: t, model: e, entryID: s });
207
+ h({ env: n, dmShortID: t, model: e, entryID: s });
208
208
  const r = f(`api/${t}/${e}?_id=${s}`, n);
209
209
  yield y(
210
210
  r,
@@ -220,21 +220,21 @@ function M(a) {
220
220
  }
221
221
  function v(a) {
222
222
  return i(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
223
- g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
224
- const r = A({ assetID: s }), h = f(`a/${t}/${e}?${r}`, n);
225
- return (yield y(h, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
223
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
224
+ const r = A({ assetID: s }), g = f(`a/${t}/${e}?${r}`, n);
225
+ return (yield y(g, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
226
226
  });
227
227
  }
228
228
  function G(n) {
229
229
  return i(this, null, function* () {
230
230
  let { env: t, dmShortID: e, assetGroup: s, token: o, options: a = {} } = n;
231
- g({ env: t, dmShortID: e, assetGroup: s }), a = c({ size: 50, page: 1, _list: !0 }, a);
232
- const r = A(a), h = f(`a/${e}/${s}?${r}`, t), { count: u, total: l, _embedded: $ } = yield y(h, { dmShortID: e, token: o });
231
+ h({ env: t, dmShortID: e, assetGroup: s }), a = c({ size: 50, page: 1, _list: !0 }, a);
232
+ const r = A(a), g = f(`a/${e}/${s}?${r}`, t), { count: u, total: l, _embedded: $ } = yield y(g, { dmShortID: e, token: o });
233
233
  let p = $ ? $["ec:dm-asset"] : [];
234
234
  return p = Array.isArray(p) ? p : [p], { count: u, total: l, items: p };
235
235
  });
236
236
  }
237
- function H(h) {
237
+ function H(g) {
238
238
  return i(this, arguments, function* ({
239
239
  env: n,
240
240
  dmShortID: t,
@@ -244,7 +244,7 @@ function H(h) {
244
244
  name: a,
245
245
  options: r
246
246
  }) {
247
- g({ env: n, dmShortID: t, assetGroup: e, file: o });
247
+ h({ env: n, dmShortID: t, assetGroup: e, file: o });
248
248
  const u = f(`a/${t}/${e}`, n), l = new FormData();
249
249
  return l.append("file", o, a), r && Object.keys(r).forEach((p) => {
250
250
  l.append(p, r[p]);
@@ -266,15 +266,15 @@ function Q(a) {
266
266
  assetID: s,
267
267
  token: o
268
268
  }) {
269
- g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
269
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
270
270
  const r = f(`a/${t}/${e}/${s}`, n);
271
- return (yield y(
271
+ yield y(
272
272
  r,
273
273
  { token: o, rawRes: !0 },
274
274
  {
275
275
  method: "DELETE"
276
276
  }
277
- ))._embedded["ec:dm-asset"];
277
+ );
278
278
  });
279
279
  }
280
280
  const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -313,7 +313,7 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
313
313
  } = E;
314
314
  function ct(n) {
315
315
  const { action: t } = n;
316
- if (g({ action: t }), !E[t])
316
+ if (h({ action: t }), !E[t])
317
317
  throw new Error(
318
318
  `"${t}" does not exist! try one of ${Object.keys(E).join(
319
319
  ", "
@@ -625,7 +625,7 @@ export {
625
625
  M as deleteEntry,
626
626
  F as editEntry,
627
627
  J as entryList,
628
- g as expect,
628
+ h as expect,
629
629
  y as fetcher,
630
630
  v as getAsset,
631
631
  z as getEcAuthKey,
@@ -25,5 +25,5 @@ export function deleteAsset({ env, dmShortID, assetGroup, assetID, token, }: {
25
25
  assetGroup: any;
26
26
  assetID: any;
27
27
  token: any;
28
- }): Promise<any>;
28
+ }): Promise<void>;
29
29
  //# sourceMappingURL=assets.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;GAWC;AAED;;;;;;;;iBA6BC;AAED;;;;;;iBAiBC"}
1
+ {"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;GAWC;AAED;;;;;;;;iBA6BC;AAED;;;;;;kBAgBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {