ec.fdk 0.2.13 → 0.2.14

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,3 @@
1
- "use strict";var M=Object.defineProperty,v=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var P=(n,t,e)=>t in n?M(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))G.call(t,e)&&P(n,e,t[e]);if(T)for(var e of T(t))H.call(t,e)&&P(n,e,t[e]);return n},y=(n,t)=>v(n,F(t));var i=(n,t,e)=>new Promise((s,o)=>{var a=h=>{try{l(e.next(h))}catch(d){o(d)}},r=h=>{try{l(e.throw(h))}catch(d){o(d)}},l=h=>h.done?s(h.value):Promise.resolve(h.value).then(a,r);l((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return i(this,arguments,function*(n,t={},e={}){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)throw new 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 u(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const O={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function j(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;u({env:t,dmShortID:e,email:s,password:o});const a=f(`api/${e}/_auth/login?clientID=rest`,t);return yield g(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;u({env:t,email:e,password:s});const o=`${O[t]}auth/login?clientID=rest`;return yield g(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;u({dmShortID:t,env:e,token:s});const o=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function S(n){return i(this,null,function*(){let{env:t,token:e}=n;u({env:t,token:e});const s=`${O[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function B({dmShortID:n}){return u({dmShortID:n}),n}function K({env:n}){return u({env:n}),n}function q(n){return i(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;u({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:h,_embedded:d}=yield g(r,n),p=d?d[`${e}:${s}`]:[];return{count:l,total:h,items:p}})}function C({env:n,dmShortID:t,model:e,entryID:s,token:o}){u({env:n,dmShortID:t,model:e,entryID:s});const a=E({_id:s}),r=f(`api/${t}/${e}?${a}`,n);return g(r,{dmShortID:t,token:o})}function R(a){return i(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){u({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 g(r,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function x(r){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:o,token:a}){u({env:n,dmShortID:t,model:e,entryID:s,value:o});const l=f(`api/${t}/${e}?_id=${s}`,n);return yield g(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}){u({env:n,dmShortID:t,model:e,entryID:s});const r=f(`api/${t}/${e}?_id=${s}`,n);yield g(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}){u({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=E({assetID:s}),l=f(`a/${t}/${e}?${r}`,n);return(yield g(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;u({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:h,total:d,_embedded:p}=yield g(l,{dmShortID:e,token:o}),$=p?p["ec:dm-asset"]:[];return{count:h,total:d,items:$}})}function U(l){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:a,options:r}){u({env:n,dmShortID:t,assetGroup:e,file:o});const h=f(`a/${t}/${e}`,n),d=new FormData;return d.append("file",o,a),r&&Object.keys(r).forEach($=>{d.append($,r[$])}),(yield g(h,{token:s},{method:"POST",body:d}))._embedded["ec:dm-asset"]})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:U,createEntry:R,deleteEntry:z,editEntry:x,entryList:q,getAsset:J,getEcAuthKey:K,getEntry:C,getPublicAuthKey:B,loginEc:_,loginPublic:j,logoutEc:S,logoutPublic:L},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createAsset:Y,createEntry:Z,editEntry:D,deleteEntry:I,loginPublic:tt,loginEc:et,logoutEc:nt,logoutPublic:st,getEcAuthKey:A,getPublicAuthKey:b}=k;function ot(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 w{constructor(t){this.config=t}set(t){return new w(c(c({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return Q(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 V(y(c({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return X(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 Y(y(c({},this.config),{file:t,name:e,options:s,token:o}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return W(y(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return Z(y(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return D(y(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(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 et(c(c({},this.config),t)).then(this.setAuth(A(this.config)))}loginPublic(t){return tt(c(c({},this.config),t)).then(this.setAuth(b(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),st(y(c({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),nt(y(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}getPublicToken(){return this.config.token||this.getAuth(b(this.config))}getEcToken(){return this.config.token||this.getAuth(A(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 rt=n=>new w({env:n});exports.Sdk=w;exports.act=ot;exports.apiURL=f;exports.assetList=N;exports.createAsset=U;exports.createEntry=R;exports.deleteEntry=z;exports.editEntry=x;exports.entryList=q;exports.expect=u;exports.fetcher=g;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=C;exports.getPublicAuthKey=B;exports.loginEc=_;exports.loginPublic=j;exports.logoutEc=S;exports.logoutPublic=L;exports.query=E;exports.sdk=rt;
1
+ "use strict";var v=Object.defineProperty,M=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,H=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={}))G.call(t,e)&&P(n,e,t[e]);if(T)for(var e of T(t))H.call(t,e)&&P(n,e,t[e]);return n},y=(n,t)=>M(n,F(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
+ ${u.detail}
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 $(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 S(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 B({dmShortID:n}){return h({dmShortID:n}),n}function K({env:n}){return h({env:n}),n}function q(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=$(o),r=f(`api/${e}/${s}?${a}`,t),{count:g,total:u,_embedded:l}=yield d(r,n),p=l?l[`${e}:${s}`]:[];return{count:g,total:u,items:p}})}function x({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const a=$({_id:s}),r=f(`api/${t}/${e}?${a}`,n);return d(r,{dmShortID:t,token:o})}function C(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 R(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=$({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=$(a),g=f(`a/${e}/${s}?${r}`,t),{count:u,total:l,_embedded:p}=yield d(g,{dmShortID:e,token:o}),E=p?p["ec:dm-asset"]:[];return{count:u,total:l,items:E}})}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(E=>{l.append(E,r[E])}),(yield d(u,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:U,createEntry:C,deleteEntry:z,editEntry:R,entryList:q,getAsset:J,getEcAuthKey:K,getEntry:x,getPublicAuthKey:B,loginEc:_,loginPublic:O,logoutEc:S,logoutPublic:L},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createAsset:Y,createEntry:Z,editEntry:D,deleteEntry:I,loginPublic:tt,loginEc:et,logoutEc:nt,logoutPublic:st,getEcAuthKey:b,getPublicAuthKey:A}=k;function ot(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 w{constructor(t){this.config=t}set(t){return new w(c(c({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return Q(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 V(y(c({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return X(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 Y(y(c({},this.config),{file:t,name:e,options:s,token:o}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return W(y(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return Z(y(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return D(y(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(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 et(c(c({},this.config),t)).then(this.setAuth(b(this.config)))}loginPublic(t){return tt(c(c({},this.config),t)).then(this.setAuth(A(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),st(y(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),nt(y(c({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}getPublicToken(){return this.config.token||this.getAuth(A(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})}dm(t){return this.dmShortID(t)}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}}const rt=n=>new w({env:n});exports.Sdk=w;exports.act=ot;exports.apiURL=f;exports.assetList=N;exports.createAsset=U;exports.createEntry=C;exports.deleteEntry=z;exports.editEntry=R;exports.entryList=q;exports.expect=h;exports.fetcher=d;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=x;exports.getPublicAuthKey=B;exports.loginEc=_;exports.loginPublic=O;exports.logoutEc=S;exports.logoutPublic=L;exports.query=$;exports.sdk=rt;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- var j = Object.defineProperty, _ = Object.defineProperties;
1
+ var O = Object.defineProperty, _ = Object.defineProperties;
2
2
  var L = Object.getOwnPropertyDescriptors;
3
3
  var T = Object.getOwnPropertySymbols;
4
4
  var B = Object.prototype.hasOwnProperty, K = Object.prototype.propertyIsEnumerable;
5
- var P = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, c = (n, t) => {
5
+ var P = (n, t, e) => t in n ? O(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, c = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
7
  B.call(t, e) && P(n, e, t[e]);
8
8
  if (T)
@@ -13,28 +13,36 @@ var P = (n, t, e) => t in n ? j(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
- g(e.next(u));
16
+ h(e.next(u));
17
17
  } catch (l) {
18
18
  o(l);
19
19
  }
20
20
  }, r = (u) => {
21
21
  try {
22
- g(e.throw(u));
22
+ h(e.throw(u));
23
23
  } catch (l) {
24
24
  o(l);
25
25
  }
26
- }, g = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, r);
27
- g((e = e.apply(n, t)).next());
26
+ }, h = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, r);
27
+ h((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
32
  const { token: o, rawRes: a } = t;
32
33
  o && (e.headers = d(c({}, e.headers || {}), {
33
34
  Authorization: `Bearer ${o}`
34
35
  }));
35
36
  const r = yield fetch(n, e);
36
- if (!r.ok)
37
- throw new Error(r.statusText);
37
+ if (!r.ok) {
38
+ if ((h = r.headers.get("content-type")) != null && h.includes("application/json")) {
39
+ const u = yield r.json(), l = `${u.title}
40
+ ${u.detail}
41
+ ${u.verbose}`;
42
+ throw new Error(l);
43
+ }
44
+ throw new Error(`unexpected fetch error: ${r.statusText}`);
45
+ }
38
46
  return a ? r : yield r.json();
39
47
  });
40
48
  }
@@ -53,20 +61,20 @@ function f(n, t = "stage") {
53
61
  function k(n, t = !0) {
54
62
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
55
63
  }
56
- function h(n) {
64
+ function g(n) {
57
65
  Object.entries(n).forEach(([t, e]) => {
58
66
  if (e === void 0)
59
67
  throw new Error(`expected ${t} to be set!`);
60
68
  });
61
69
  }
62
- const O = {
70
+ const j = {
63
71
  stage: "https://accounts.cachena.entrecode.de/",
64
72
  live: "https://accounts.entrecode.de/"
65
73
  };
66
74
  function S(n) {
67
75
  return i(this, null, function* () {
68
76
  let { env: t, dmShortID: e, email: s, password: o } = n;
69
- h({ env: t, dmShortID: e, email: s, password: o });
77
+ g({ env: t, dmShortID: e, email: s, password: o });
70
78
  const a = f(`api/${e}/_auth/login?clientID=rest`, t);
71
79
  return yield y(
72
80
  a,
@@ -81,11 +89,11 @@ function S(n) {
81
89
  );
82
90
  });
83
91
  }
84
- function C(n) {
92
+ function x(n) {
85
93
  return i(this, null, function* () {
86
94
  let { env: t, email: e, password: s } = n;
87
- h({ env: t, email: e, password: s });
88
- const o = `${O[t]}auth/login?clientID=rest`;
95
+ g({ env: t, email: e, password: s });
96
+ const o = `${j[t]}auth/login?clientID=rest`;
89
97
  return yield y(
90
98
  o,
91
99
  {},
@@ -99,10 +107,10 @@ function C(n) {
99
107
  );
100
108
  });
101
109
  }
102
- function q(n) {
110
+ function C(n) {
103
111
  return i(this, null, function* () {
104
112
  let { dmShortID: t, env: e, token: s } = n;
105
- h({ dmShortID: t, env: e, token: s });
113
+ g({ dmShortID: t, env: e, token: s });
106
114
  const o = f(
107
115
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
108
116
  e
@@ -116,11 +124,11 @@ function q(n) {
116
124
  );
117
125
  });
118
126
  }
119
- function x(n) {
127
+ function q(n) {
120
128
  return i(this, null, function* () {
121
129
  let { env: t, token: e } = n;
122
- h({ env: t, token: e });
123
- const s = `${O[t]}auth/logout?clientID=rest`;
130
+ g({ env: t, token: e });
131
+ const s = `${j[t]}auth/logout?clientID=rest`;
124
132
  return yield y(
125
133
  s,
126
134
  {
@@ -134,27 +142,27 @@ function x(n) {
134
142
  });
135
143
  }
136
144
  function R({ dmShortID: n }) {
137
- return h({ dmShortID: n }), n;
145
+ return g({ dmShortID: n }), n;
138
146
  }
139
147
  function z({ env: n }) {
140
- return h({ env: n }), n;
148
+ return g({ env: n }), n;
141
149
  }
142
150
  function J(n) {
143
151
  return i(this, null, function* () {
144
152
  let { env: t, dmShortID: e, model: s, options: o = {} } = n;
145
- h({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
146
- const a = k(o), r = f(`api/${e}/${s}?${a}`, t), { count: g, total: u, _embedded: l } = yield y(r, n), p = l ? l[`${e}:${s}`] : [];
147
- return { count: g, total: u, items: p };
153
+ g({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
154
+ const a = k(o), r = f(`api/${e}/${s}?${a}`, t), { count: h, total: u, _embedded: l } = yield y(r, n), p = l ? l[`${e}:${s}`] : [];
155
+ return { count: h, total: u, items: p };
148
156
  });
149
157
  }
150
158
  function N({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
151
- h({ env: n, dmShortID: t, model: e, entryID: s });
159
+ g({ env: n, dmShortID: t, model: e, entryID: s });
152
160
  const a = k({ _id: s }), r = f(`api/${t}/${e}?${a}`, n);
153
161
  return y(r, { dmShortID: t, token: o });
154
162
  }
155
163
  function U(a) {
156
164
  return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
157
- h({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
165
+ g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
158
166
  const r = f(`api/${t}/${e}`, n);
159
167
  return console.log("url", r), yield y(
160
168
  r,
@@ -169,7 +177,7 @@ function U(a) {
169
177
  );
170
178
  });
171
179
  }
172
- function F(r) {
180
+ function v(r) {
173
181
  return i(this, arguments, function* ({
174
182
  env: n,
175
183
  dmShortID: t,
@@ -178,10 +186,10 @@ function F(r) {
178
186
  value: o,
179
187
  token: a
180
188
  }) {
181
- h({ env: n, dmShortID: t, model: e, entryID: s, value: o });
182
- const g = f(`api/${t}/${e}?_id=${s}`, n);
189
+ g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
190
+ const h = f(`api/${t}/${e}?_id=${s}`, n);
183
191
  return yield y(
184
- g,
192
+ h,
185
193
  { token: a },
186
194
  {
187
195
  method: "PUT",
@@ -193,9 +201,9 @@ function F(r) {
193
201
  );
194
202
  });
195
203
  }
196
- function G(a) {
204
+ function F(a) {
197
205
  return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
198
- h({ env: n, dmShortID: t, model: e, entryID: s });
206
+ g({ env: n, dmShortID: t, model: e, entryID: s });
199
207
  const r = f(`api/${t}/${e}?_id=${s}`, n);
200
208
  yield y(
201
209
  r,
@@ -209,22 +217,22 @@ function G(a) {
209
217
  );
210
218
  });
211
219
  }
212
- function M(a) {
220
+ function G(a) {
213
221
  return i(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
214
- h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
215
- const r = k({ assetID: s }), g = f(`a/${t}/${e}?${r}`, n);
216
- return (yield y(g, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
222
+ g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
223
+ const r = k({ assetID: s }), h = f(`a/${t}/${e}?${r}`, n);
224
+ return (yield y(h, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
217
225
  });
218
226
  }
219
- function v(n) {
227
+ function M(n) {
220
228
  return i(this, null, function* () {
221
229
  let { env: t, dmShortID: e, assetGroup: s, token: o, options: a = {} } = n;
222
- h({ env: t, dmShortID: e, assetGroup: s }), a = c({ size: 50, page: 1, _list: !0 }, a);
223
- const r = k(a), g = f(`a/${e}/${s}?${r}`, t), { count: u, total: l, _embedded: p } = yield y(g, { dmShortID: e, token: o }), E = p ? p["ec:dm-asset"] : [];
224
- return { count: u, total: l, items: E };
230
+ g({ env: t, dmShortID: e, assetGroup: s }), a = c({ size: 50, page: 1, _list: !0 }, a);
231
+ const r = k(a), h = f(`a/${e}/${s}?${r}`, t), { count: u, total: l, _embedded: p } = yield y(h, { dmShortID: e, token: o }), $ = p ? p["ec:dm-asset"] : [];
232
+ return { count: u, total: l, items: $ };
225
233
  });
226
234
  }
227
- function H(g) {
235
+ function H(h) {
228
236
  return i(this, arguments, function* ({
229
237
  env: n,
230
238
  dmShortID: t,
@@ -234,10 +242,10 @@ function H(g) {
234
242
  name: a,
235
243
  options: r
236
244
  }) {
237
- h({ env: n, dmShortID: t, assetGroup: e, file: o });
245
+ g({ env: n, dmShortID: t, assetGroup: e, file: o });
238
246
  const u = f(`a/${t}/${e}`, n), l = new FormData();
239
- return l.append("file", o, a), r && Object.keys(r).forEach((E) => {
240
- l.append(E, r[E]);
247
+ return l.append("file", o, a), r && Object.keys(r).forEach(($) => {
248
+ l.append($, r[$]);
241
249
  }), (yield y(
242
250
  u,
243
251
  { token: s },
@@ -248,22 +256,22 @@ function H(g) {
248
256
  ))._embedded["ec:dm-asset"];
249
257
  });
250
258
  }
251
- const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
259
+ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
252
260
  __proto__: null,
253
- assetList: v,
261
+ assetList: M,
254
262
  createAsset: H,
255
263
  createEntry: U,
256
- deleteEntry: G,
257
- editEntry: F,
264
+ deleteEntry: F,
265
+ editEntry: v,
258
266
  entryList: J,
259
- getAsset: M,
267
+ getAsset: G,
260
268
  getEcAuthKey: z,
261
269
  getEntry: N,
262
270
  getPublicAuthKey: R,
263
- loginEc: C,
271
+ loginEc: x,
264
272
  loginPublic: S,
265
- logoutEc: x,
266
- logoutPublic: q
273
+ logoutEc: q,
274
+ logoutPublic: C
267
275
  }, Symbol.toStringTag, { value: "Module" })), {
268
276
  entryList: Q,
269
277
  getEntry: V,
@@ -279,16 +287,16 @@ const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
279
287
  logoutPublic: st,
280
288
  getEcAuthKey: w,
281
289
  getPublicAuthKey: A
282
- } = $;
290
+ } = E;
283
291
  function rt(n) {
284
292
  const { action: t } = n;
285
- if (h({ action: t }), !$[t])
293
+ if (g({ action: t }), !E[t])
286
294
  throw new Error(
287
- `"${t}" does not exist! try one of ${Object.keys($).join(
295
+ `"${t}" does not exist! try one of ${Object.keys(E).join(
288
296
  ", "
289
297
  )}`
290
298
  );
291
- return $[t](n);
299
+ return E[t](n);
292
300
  }
293
301
  class b {
294
302
  constructor(t) {
@@ -572,22 +580,22 @@ export {
572
580
  b as Sdk,
573
581
  rt as act,
574
582
  f as apiURL,
575
- v as assetList,
583
+ M as assetList,
576
584
  H as createAsset,
577
585
  U as createEntry,
578
- G as deleteEntry,
579
- F as editEntry,
586
+ F as deleteEntry,
587
+ v as editEntry,
580
588
  J as entryList,
581
- h as expect,
589
+ g as expect,
582
590
  y as fetcher,
583
- M as getAsset,
591
+ G as getAsset,
584
592
  z as getEcAuthKey,
585
593
  N as getEntry,
586
594
  R as getPublicAuthKey,
587
- C as loginEc,
595
+ x as loginEc,
588
596
  S as loginPublic,
589
- x as logoutEc,
590
- q as logoutPublic,
597
+ q as logoutEc,
598
+ C as logoutPublic,
591
599
  k as query,
592
600
  it as sdk
593
601
  };
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAiBC;AAOD,sDAQC;AAED,wDAKC;AAED,uCAMC"}
1
+ {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../src/lib/util.mjs"],"names":[],"mappings":"AAAA,2EAsBC;AAOD,sDAQC;AAED,wDAKC;AAED,uCAMC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {