ec.fdk 0.1.3 → 0.1.4

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 +1 @@
1
- "use strict";var v=Object.defineProperty,G=Object.defineProperties;var M=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var m=(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={}))F.call(t,e)&&m(n,e,t[e]);if(P)for(var e of P(t))H.call(t,e)&&m(n,e,t[e]);return n},d=(n,t)=>G(n,M(t));var a=(n,t,e)=>new Promise((o,s)=>{var r=g=>{try{h(e.next(g))}catch(y){s(y)}},i=g=>{try{h(e.throw(g))}catch(y){s(y)}},h=g=>g.done?o(g.value):Promise.resolve(g.value).then(r,i);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(o){return a(this,arguments,function*(n,t={},e={}){const{token:s,rawRes:r}=t;s&&(e.headers=d(c({},e.headers||{}),{Authorization:`Bearer ${s}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return r?i:yield i.json()})}const j={production:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(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 E(n,t=!0){return Object.entries(n).sort((e,o)=>e[0].localeCompare(o[0])).map(([e,o])=>`${e}=${o}`).join("&")}function u(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const L={stage:"https://accounts.cachena.entrecode.de/",production:"https://accounts.cachena.entrecode.de/"};function S(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:o,password:s}=n;u({env:t,dmShortID:e,email:o,password:s});const r=f(`api/${e}/_auth/login?clientID=rest`,t);return yield l(r,{},{method:"POST",body:JSON.stringify({email:o,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return a(this,null,function*(){let{env:t,email:e,password:o}=n;u({env:t,email:e,password:o});const s=`${L[t]}auth/login?clientID=rest`;return yield l(s,{},{method:"POST",body:JSON.stringify({email:e,password:o}),headers:{"Content-Type":"application/json"}})})}function q(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:o}=n;u({dmShortID:t,env:e,token:o});const s=f(`api/${t}/_auth/logout?clientID=rest&token=${o}`,e);return yield l(s,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return a(this,null,function*(){let{env:t,token:e}=n;u({env:t,token:e});const o=`${L[t]}auth/logout?clientID=rest`;return yield l(o,{rawRes:!0,token:e},{method:"POST"})})}function B({dmShortID:n}){return u({dmShortID:n}),n}function C({env:n}){return u({env:n}),n}function R(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:o,options:s={}}=n;u({env:t,dmShortID:e,model:o}),s=c({size:50,page:1,_list:!0},s);const r=E(s),i=f(`api/${e}/${o}?${r}`,t),{count:h,total:g,_embedded:y}=yield l(i,n),b=y?y[`${e}:${o}`]:[];return{count:h,total:g,items:b}})}function z({env:n,dmShortID:t,model:e,entryID:o,token:s}){u({env:n,dmShortID:t,model:e,entryID:o});const r=E({_id:o}),i=f(`api/${t}/${e}?${r}`,n);return l(i,{dmShortID:t,token:s})}function J(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:o,token:s}){u({env:n,dmShortID:t,model:e,value:o}),console.log("create entry",t,e,o);const i=f(`api/${t}/${e}`,n);return console.log("url",i),yield l(i,{env:n,dmShortID:t,token:s},{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function N(i){return a(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:o,value:s,token:r}){u({env:n,dmShortID:t,model:e,entryID:o,value:s});const h=f(`api/${t}/${e}?_id=${o}`,n);return yield l(h,{token:r},{method:"PUT",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function D(r){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:o,token:s}){u({env:n,dmShortID:t,assetGroup:e,assetID:o});const i=E({assetID:o}),h=f(`a/${t}/${e}?${i}`,n);return(yield l(h,{dmShortID:t,token:s}))._embedded["ec:dm-asset"]})}function I(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:o,token:s,options:r={}}=n;u({env:t,dmShortID:e,assetGroup:o}),r=c({size:50,page:1,_list:!0},r);const i=E(r),h=f(`a/${e}/${o}?${i}`,t),{count:g,total:y,_embedded:b}=yield l(h,{dmShortID:e,token:s}),U=b?b["ec:dm-asset"]:[];return{count:g,total:y,items:U}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:I,createEntry:J,editEntry:N,entryList:R,getAsset:D,getEcAuthKey:C,getEntry:z,getPublicAuthKey:B,loginEc:K,loginPublic:S,logoutEc:x,logoutPublic:q},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createEntry:O,editEntry:_,loginPublic:Y,loginEc:Z,logoutEc:tt,logoutPublic:et,getEcAuthKey:w,getPublicAuthKey:A}=k;function nt(n){const{action:t}=n;if(u({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class p{constructor(t){this.config=t}set(t){return new p(c(c({},this.config),t))}handle(t){return a(this,null,function*(){const e=Object.keys(this.config),o=yield this.getBestToken(),[s,r]=Object.entries(t).find(([i,h])=>e.includes(i))||[];if(!r)throw new Error(`you need to first set ${Object.keys(t).join(" | ")}`);return r(d(c({},this.config),{token:o}))})}entries(t){return a(this,null,function*(){const e=yield this.getBestToken();return Q(d(c({},this.config),{options:t,token:e}))})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return X(d(c({},this.config),{options:t,token:e}))})}get(){return this.handle({assetID:W,entryID:V})}del(){}createEntry(t){return O(d(c({},this.config),{value:t}))}editEntry(t){return _(d(c({},this.config),{value:t}))}create(t){return this.set({value:t}).handle({model:O})}edit(t){return this.set({value:t}).handle({entryID:_})}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:o}=this.config.authAdapter;return o(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:o}=this.config.authAdapter;return o(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 Z(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return Y(c(c({},this.config),t)).then(this.setAuth(A(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),et(d(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),tt(d(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(A(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(){return this.getEcToken()||this.getPublicToken()}}const $=(...n)=>{const[t]=n;n.forEach(e=>{p.prototype[e]=function(o){return this.set({[t]:o})}})},T=(n,t)=>{p.prototype[n]=p.prototype[t]};$("dmShortID","dm","dmshortid");$("model");$("token");$("entryID","entry");$("assetGroup");$("assetID","asset");T("assetgroup","assetGroup");T("entryList","entries");T("assetList","assets");const ot=n=>new p({env:n});exports.act=nt;exports.apiURL=f;exports.assetList=I;exports.createEntry=J;exports.editEntry=N;exports.entryList=R;exports.expect=u;exports.fetcher=l;exports.getAsset=D;exports.getEcAuthKey=C;exports.getEntry=z;exports.getPublicAuthKey=B;exports.loginEc=K;exports.loginPublic=S;exports.logoutEc=x;exports.logoutPublic=q;exports.query=E;exports.sdk=ot;
1
+ "use strict";var v=Object.defineProperty,G=Object.defineProperties;var M=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var m=(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={}))F.call(t,e)&&m(n,e,t[e]);if(P)for(var e of P(t))H.call(t,e)&&m(n,e,t[e]);return n},d=(n,t)=>G(n,M(t));var a=(n,t,e)=>new Promise((o,s)=>{var r=g=>{try{h(e.next(g))}catch(y){s(y)}},i=g=>{try{h(e.throw(g))}catch(y){s(y)}},h=g=>g.done?o(g.value):Promise.resolve(g.value).then(r,i);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(o){return a(this,arguments,function*(n,t={},e={}){const{token:s,rawRes:r}=t;s&&(e.headers=d(c({},e.headers||{}),{Authorization:`Bearer ${s}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return r?i:yield i.json()})}const j={production:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(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 E(n,t=!0){return Object.entries(n).sort((e,o)=>e[0].localeCompare(o[0])).map(([e,o])=>`${e}=${o}`).join("&")}function u(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const L={stage:"https://accounts.cachena.entrecode.de/",production:"https://accounts.cachena.entrecode.de/"};function S(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:o,password:s}=n;u({env:t,dmShortID:e,email:o,password:s});const r=f(`api/${e}/_auth/login?clientID=rest`,t);return yield l(r,{},{method:"POST",body:JSON.stringify({email:o,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return a(this,null,function*(){let{env:t,email:e,password:o}=n;u({env:t,email:e,password:o});const s=`${L[t]}auth/login?clientID=rest`;return yield l(s,{},{method:"POST",body:JSON.stringify({email:e,password:o}),headers:{"Content-Type":"application/json"}})})}function q(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:o}=n;u({dmShortID:t,env:e,token:o});const s=f(`api/${t}/_auth/logout?clientID=rest&token=${o}`,e);return yield l(s,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return a(this,null,function*(){let{env:t,token:e}=n;u({env:t,token:e});const o=`${L[t]}auth/logout?clientID=rest`;return yield l(o,{rawRes:!0,token:e},{method:"POST"})})}function B({dmShortID:n}){return u({dmShortID:n}),n}function C({env:n}){return u({env:n}),n}function R(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:o,options:s={}}=n;u({env:t,dmShortID:e,model:o}),s=c({size:50,page:1,_list:!0},s);const r=E(s),i=f(`api/${e}/${o}?${r}`,t),{count:h,total:g,_embedded:y}=yield l(i,n),b=y?y[`${e}:${o}`]:[];return{count:h,total:g,items:b}})}function z({env:n,dmShortID:t,model:e,entryID:o,token:s}){u({env:n,dmShortID:t,model:e,entryID:o});const r=E({_id:o}),i=f(`api/${t}/${e}?${r}`,n);return l(i,{dmShortID:t,token:s})}function J(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:o,token:s}){u({env:n,dmShortID:t,model:e,value:o}),console.log("create entry",t,e,o);const i=f(`api/${t}/${e}`,n);return console.log("url",i),yield l(i,{env:n,dmShortID:t,token:s},{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function N(i){return a(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:o,value:s,token:r}){u({env:n,dmShortID:t,model:e,entryID:o,value:s});const h=f(`api/${t}/${e}?_id=${o}`,n);return yield l(h,{token:r},{method:"PUT",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function D(r){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:o,token:s}){u({env:n,dmShortID:t,assetGroup:e,assetID:o});const i=E({assetID:o}),h=f(`a/${t}/${e}?${i}`,n);return(yield l(h,{dmShortID:t,token:s}))._embedded["ec:dm-asset"]})}function I(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:o,token:s,options:r={}}=n;u({env:t,dmShortID:e,assetGroup:o}),r=c({size:50,page:1,_list:!0},r);const i=E(r),h=f(`a/${e}/${o}?${i}`,t),{count:g,total:y,_embedded:b}=yield l(h,{dmShortID:e,token:s}),U=b?b["ec:dm-asset"]:[];return{count:g,total:y,items:U}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:I,createEntry:J,editEntry:N,entryList:R,getAsset:D,getEcAuthKey:C,getEntry:z,getPublicAuthKey:B,loginEc:K,loginPublic:S,logoutEc:x,logoutPublic:q},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createEntry:O,editEntry:_,loginPublic:Y,loginEc:Z,logoutEc:tt,logoutPublic:et,getEcAuthKey:w,getPublicAuthKey:A}=k;function nt(n){const{action:t}=n;if(u({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class p{constructor(t){this.config=t}set(t){return new p(c(c({},this.config),t))}handle(t){return a(this,null,function*(){const e=Object.keys(this.config),o=yield this.getBestToken(),[s,r]=Object.entries(t).find(([i,h])=>e.includes(i))||[];if(!r)throw new Error(`you need to first set ${Object.keys(t).join(" | ")}`);return r(d(c({},this.config),{token:o}))})}entries(t){return a(this,null,function*(){const e=yield this.getBestToken();return Q(d(c({},this.config),{options:t,token:e}))})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return X(d(c({},this.config),{options:t,token:e}))})}get(){return this.handle({assetID:W,entryID:V})}del(){}createEntry(t){return O(d(c({},this.config),{value:t}))}editEntry(t){return _(d(c({},this.config),{value:t}))}create(t){return this.set({value:t}).handle({model:O})}edit(t){return this.set({value:t}).handle({entryID:_})}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:o}=this.config.authAdapter;return o(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:o}=this.config.authAdapter;return o(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 Z(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return Y(c(c({},this.config),t)).then(this.setAuth(A(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),et(d(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),tt(d(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(A(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}}}const $=(...n)=>{const[t]=n;n.forEach(e=>{p.prototype[e]=function(o){return this.set({[t]:o})}})},T=(n,t)=>{p.prototype[n]=p.prototype[t]};$("dmShortID","dm","dmshortid");$("model");$("token");$("entryID","entry");$("assetGroup");$("assetID","asset");T("assetgroup","assetGroup");T("entryList","entries");T("assetList","assets");const ot=n=>new p({env:n});exports.act=nt;exports.apiURL=f;exports.assetList=I;exports.createEntry=J;exports.editEntry=N;exports.entryList=R;exports.expect=u;exports.fetcher=l;exports.getAsset=D;exports.getEcAuthKey=C;exports.getEntry=z;exports.getPublicAuthKey=B;exports.loginEc=K;exports.loginPublic=S;exports.logoutEc=x;exports.logoutPublic=q;exports.query=E;exports.sdk=ot;
package/dist/index.mjs CHANGED
@@ -366,7 +366,11 @@ class p {
366
366
  return !!this.getEcToken() || !!this.getPublicToken();
367
367
  }
368
368
  getBestToken() {
369
- return this.getEcToken() || this.getPublicToken();
369
+ try {
370
+ return this.getEcToken() || this.getPublicToken();
371
+ } catch (t) {
372
+ return;
373
+ }
370
374
  }
371
375
  }
372
376
  const $ = (...n) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {