ec.fdk 0.2.12 → 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},d=(n,t)=>v(n,F(t));var r=(n,t,e)=>new Promise((s,o)=>{var a=u=>{try{l(e.next(u))}catch(f){o(f)}},i=u=>{try{l(e.throw(u))}catch(f){o(f)}},l=u=>u.done?s(u.value):Promise.resolve(u.value).then(a,i);l((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return r(this,arguments,function*(n,t={},e={}){const{token:o,rawRes:a}=t;o&&(e.headers=d(c({},e.headers||{}),{Authorization:`Bearer ${o}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return a?i:yield i.json()})}const m={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function y(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 O={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function j(n){return r(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;h({env:t,dmShortID:e,email:s,password:o});const a=y(`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 r(this,null,function*(){let{env:t,email:e,password:s}=n;h({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 r(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const o=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function S(n){return r(this,null,function*(){let{env:t,token:e}=n;h({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 h({dmShortID:n}),n}function K({env:n}){return h({env:n}),n}function q(n){return r(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),i=y(`api/${e}/${s}?${a}`,t),{count:l,total:u,_embedded:f}=yield g(i,n),p=f?f[`${e}:${s}`]:[];return{count:l,total:u,items:p}})}function C({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const a=$({_id:s}),i=y(`api/${t}/${e}?${a}`,n);return g(i,{dmShortID:t,token:o})}function R(a){return r(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 i=y(`api/${t}/${e}`,n);return console.log("url",i),yield g(i,{env:n,dmShortID:t,token:o},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function x(i){return r(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=y(`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 r(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){h({env:n,dmShortID:t,model:e,entryID:s});const i=y(`api/${t}/${e}?_id=${s}`,n);yield g(i,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function J(a){return r(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=$({assetID:s}),l=y(`a/${t}/${e}?${i}`,n);return(yield g(l,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function N(n){return r(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 i=$(a),l=y(`a/${e}/${s}?${i}`,t),{count:u,total:f,_embedded:p}=yield g(l,{dmShortID:e,token:o}),b=p?p["ec:dm-asset"]:[];return{count:u,total:f,items:b}})}function U(l){return r(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:a,options:i}){h({env:n,dmShortID:t,assetGroup:e,file:o});const u=$(i||{}),f=y(`a/${t}/${e}${u?`?${u}`:""}`,n),p=new FormData;return p.append("file",o,a),(yield g(f,{token:s},{method:"POST",body:p}))._embedded["ec:dm-asset"]})}const E=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:w,getPublicAuthKey:A}=E;function ot(n){const{action:t}=n;if(h({action:t}),!E[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(E).join(", ")}`);return E[t](n)}class k{constructor(t){this.config=t}set(t){return new k(c(c({},this.config),t))}entries(){return r(this,arguments,function*(t={}){const e=yield this.getBestToken();return Q(d(c({},this.config),{options:t,token:e}))})}entryList(t){return r(this,null,function*(){return this.entries(t)})}getEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return V(d(c({},this.config),{entryID:t,token:e}))})}assets(t){return r(this,null,function*(){const e=yield this.getBestToken();return X(d(c({},this.config),{options:t,token:e}))})}assetList(t){return r(this,null,function*(){return this.assets(t)})}createAsset(){return r(this,arguments,function*({file:t,name:e,options:s}={}){const o=yield this.getBestToken();return Y(d(c({},this.config),{file:t,name:e,options:s,token:o}))})}getAsset(t){return r(this,null,function*(){const e=yield this.getBestToken();return W(d(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return Z(d(c({},this.config),{token:e,value:t}))})}editEntry(t,e){return r(this,null,function*(){const s=yield this.getBestToken();return D(d(c({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return r(this,null,function*(){const e=yield this.getBestToken();return I(d(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(w(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(d(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),nt(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}}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 k({env:n});exports.Sdk=k;exports.act=ot;exports.apiURL=y;exports.assetList=N;exports.createAsset=U;exports.createEntry=R;exports.deleteEntry=z;exports.editEntry=x;exports.entryList=q;exports.expect=h;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=$;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,41 +1,49 @@
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)
9
9
  for (var e of T(t))
10
10
  K.call(t, e) && P(n, e, t[e]);
11
11
  return n;
12
- }, l = (n, t) => _(n, L(t));
13
- var r = (n, t, e) => new Promise((s, o) => {
12
+ }, d = (n, t) => _(n, L(t));
13
+ var i = (n, t, e) => new Promise((s, o) => {
14
14
  var a = (u) => {
15
15
  try {
16
- g(e.next(u));
17
- } catch (y) {
18
- o(y);
16
+ h(e.next(u));
17
+ } catch (l) {
18
+ o(l);
19
19
  }
20
- }, i = (u) => {
20
+ }, r = (u) => {
21
21
  try {
22
- g(e.throw(u));
23
- } catch (y) {
24
- o(y);
22
+ h(e.throw(u));
23
+ } catch (l) {
24
+ o(l);
25
25
  }
26
- }, g = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(a, i);
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
- function d(s) {
30
- return r(this, arguments, function* (n, t = {}, e = {}) {
29
+ function y(s) {
30
+ return i(this, arguments, function* (n, t = {}, e = {}) {
31
+ var h;
31
32
  const { token: o, rawRes: a } = t;
32
- o && (e.headers = l(c({}, e.headers || {}), {
33
+ o && (e.headers = d(c({}, e.headers || {}), {
33
34
  Authorization: `Bearer ${o}`
34
35
  }));
35
- const i = yield fetch(n, e);
36
- if (!i.ok)
37
- throw new Error(i.statusText);
38
- return a ? i : yield i.json();
36
+ const r = yield fetch(n, e);
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
+ }
46
+ return a ? r : yield r.json();
39
47
  });
40
48
  }
41
49
  const m = {
@@ -50,25 +58,25 @@ function f(n, t = "stage") {
50
58
  );
51
59
  return e + n;
52
60
  }
53
- function $(n, t = !0) {
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
- return r(this, null, function* () {
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
- return yield d(
79
+ return yield y(
72
80
  a,
73
81
  {},
74
82
  {
@@ -81,12 +89,12 @@ function S(n) {
81
89
  );
82
90
  });
83
91
  }
84
- function q(n) {
85
- return r(this, null, function* () {
92
+ function x(n) {
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`;
89
- return yield d(
95
+ g({ env: t, email: e, password: s });
96
+ const o = `${j[t]}auth/login?clientID=rest`;
97
+ return yield y(
90
98
  o,
91
99
  {},
92
100
  {
@@ -100,14 +108,14 @@ function q(n) {
100
108
  });
101
109
  }
102
110
  function C(n) {
103
- return r(this, null, function* () {
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
109
117
  );
110
- return yield d(
118
+ return yield y(
111
119
  o,
112
120
  { dmShortID: t, rawRes: !0 },
113
121
  {
@@ -116,12 +124,12 @@ function C(n) {
116
124
  );
117
125
  });
118
126
  }
119
- function x(n) {
120
- return r(this, null, function* () {
127
+ function q(n) {
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`;
124
- return yield d(
130
+ g({ env: t, token: e });
131
+ const s = `${j[t]}auth/logout?clientID=rest`;
132
+ return yield y(
125
133
  s,
126
134
  {
127
135
  rawRes: !0,
@@ -134,30 +142,30 @@ 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
- return r(this, null, function* () {
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 = $(o), i = f(`api/${e}/${s}?${a}`, t), { count: g, total: u, _embedded: y } = yield d(i, n), p = y ? y[`${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 });
152
- const a = $({ _id: s }), i = f(`api/${t}/${e}?${a}`, n);
153
- return d(i, { dmShortID: t, token: o });
159
+ g({ env: n, dmShortID: t, model: e, entryID: s });
160
+ const a = k({ _id: s }), r = f(`api/${t}/${e}?${a}`, n);
161
+ return y(r, { dmShortID: t, token: o });
154
162
  }
155
163
  function U(a) {
156
- return r(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);
158
- const i = f(`api/${t}/${e}`, n);
159
- return console.log("url", i), yield d(
160
- i,
164
+ return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
165
+ g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
166
+ const r = f(`api/${t}/${e}`, n);
167
+ return console.log("url", r), yield y(
168
+ r,
161
169
  { env: n, dmShortID: t, token: o },
162
170
  {
163
171
  method: "POST",
@@ -169,8 +177,8 @@ function U(a) {
169
177
  );
170
178
  });
171
179
  }
172
- function F(i) {
173
- return r(this, arguments, function* ({
180
+ function v(r) {
181
+ return i(this, arguments, function* ({
174
182
  env: n,
175
183
  dmShortID: t,
176
184
  model: e,
@@ -178,10 +186,10 @@ function F(i) {
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);
183
- return yield d(
184
- g,
189
+ g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
190
+ const h = f(`api/${t}/${e}?_id=${s}`, n);
191
+ return yield y(
192
+ h,
185
193
  { token: a },
186
194
  {
187
195
  method: "PUT",
@@ -193,12 +201,12 @@ function F(i) {
193
201
  );
194
202
  });
195
203
  }
196
- function G(a) {
197
- return r(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
198
- h({ env: n, dmShortID: t, model: e, entryID: s });
199
- const i = f(`api/${t}/${e}?_id=${s}`, n);
200
- yield d(
201
- i,
204
+ function F(a) {
205
+ return i(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
206
+ g({ env: n, dmShortID: t, model: e, entryID: s });
207
+ const r = f(`api/${t}/${e}?_id=${s}`, n);
208
+ yield y(
209
+ r,
202
210
  { token: o, rawRes: !0 },
203
211
  {
204
212
  method: "DELETE",
@@ -209,58 +217,60 @@ function G(a) {
209
217
  );
210
218
  });
211
219
  }
212
- function M(a) {
213
- return r(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 i = $({ assetID: s }), g = f(`a/${t}/${e}?${i}`, n);
216
- return (yield d(g, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
220
+ function G(a) {
221
+ return i(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
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) {
220
- return r(this, null, function* () {
227
+ function M(n) {
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 i = $(a), g = f(`a/${e}/${s}?${i}`, t), { count: u, total: y, _embedded: p } = yield d(g, { dmShortID: e, token: o }), b = p ? p["ec:dm-asset"] : [];
224
- return { count: u, total: y, items: b };
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) {
228
- return r(this, arguments, function* ({
235
+ function H(h) {
236
+ return i(this, arguments, function* ({
229
237
  env: n,
230
238
  dmShortID: t,
231
239
  assetGroup: e,
232
240
  token: s,
233
241
  file: o,
234
242
  name: a,
235
- options: i
243
+ options: r
236
244
  }) {
237
- h({ env: n, dmShortID: t, assetGroup: e, file: o });
238
- const u = $(i || {}), y = f(`a/${t}/${e}${u ? `?${u}` : ""}`, n), p = new FormData();
239
- return p.append("file", o, a), (yield d(
240
- y,
245
+ g({ env: n, dmShortID: t, assetGroup: e, file: o });
246
+ const u = f(`a/${t}/${e}`, n), l = new FormData();
247
+ return l.append("file", o, a), r && Object.keys(r).forEach(($) => {
248
+ l.append($, r[$]);
249
+ }), (yield y(
250
+ u,
241
251
  { token: s },
242
252
  {
243
253
  method: "POST",
244
- body: p
254
+ body: l
245
255
  }
246
256
  ))._embedded["ec:dm-asset"];
247
257
  });
248
258
  }
249
259
  const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
250
260
  __proto__: null,
251
- assetList: v,
261
+ assetList: M,
252
262
  createAsset: H,
253
263
  createEntry: U,
254
- deleteEntry: G,
255
- editEntry: F,
264
+ deleteEntry: F,
265
+ editEntry: v,
256
266
  entryList: J,
257
- getAsset: M,
267
+ getAsset: G,
258
268
  getEcAuthKey: z,
259
269
  getEntry: N,
260
270
  getPublicAuthKey: R,
261
- loginEc: q,
271
+ loginEc: x,
262
272
  loginPublic: S,
263
- logoutEc: x,
273
+ logoutEc: q,
264
274
  logoutPublic: C
265
275
  }, Symbol.toStringTag, { value: "Module" })), {
266
276
  entryList: Q,
@@ -275,12 +285,12 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
275
285
  loginEc: et,
276
286
  logoutEc: nt,
277
287
  logoutPublic: st,
278
- getEcAuthKey: k,
279
- getPublicAuthKey: w
288
+ getEcAuthKey: w,
289
+ getPublicAuthKey: A
280
290
  } = E;
281
291
  function rt(n) {
282
292
  const { action: t } = n;
283
- if (h({ action: t }), !E[t])
293
+ if (g({ action: t }), !E[t])
284
294
  throw new Error(
285
295
  `"${t}" does not exist! try one of ${Object.keys(E).join(
286
296
  ", "
@@ -288,12 +298,12 @@ function rt(n) {
288
298
  );
289
299
  return E[t](n);
290
300
  }
291
- class A {
301
+ class b {
292
302
  constructor(t) {
293
303
  this.config = t;
294
304
  }
295
305
  set(t) {
296
- return new A(c(c({}, this.config), t));
306
+ return new b(c(c({}, this.config), t));
297
307
  }
298
308
  /**
299
309
  * Loads entry list. Expects `dmShortID` / `model` to be set.
@@ -309,13 +319,13 @@ class A {
309
319
  * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
310
320
  */
311
321
  entries() {
312
- return r(this, arguments, function* (t = {}) {
322
+ return i(this, arguments, function* (t = {}) {
313
323
  const e = yield this.getBestToken();
314
- return Q(l(c({}, this.config), { options: t, token: e }));
324
+ return Q(d(c({}, this.config), { options: t, token: e }));
315
325
  });
316
326
  }
317
327
  entryList(t) {
318
- return r(this, null, function* () {
328
+ return i(this, null, function* () {
319
329
  return this.entries(t);
320
330
  });
321
331
  }
@@ -329,9 +339,9 @@ class A {
329
339
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
330
340
  */
331
341
  getEntry(t) {
332
- return r(this, null, function* () {
342
+ return i(this, null, function* () {
333
343
  const e = yield this.getBestToken();
334
- return V(l(c({}, this.config), { entryID: t, token: e }));
344
+ return V(d(c({}, this.config), { entryID: t, token: e }));
335
345
  });
336
346
  }
337
347
  /**
@@ -348,13 +358,13 @@ class A {
348
358
  * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
349
359
  */
350
360
  assets(t) {
351
- return r(this, null, function* () {
361
+ return i(this, null, function* () {
352
362
  const e = yield this.getBestToken();
353
- return X(l(c({}, this.config), { options: t, token: e }));
363
+ return X(d(c({}, this.config), { options: t, token: e }));
354
364
  });
355
365
  }
356
366
  assetList(t) {
357
- return r(this, null, function* () {
367
+ return i(this, null, function* () {
358
368
  return this.assets(t);
359
369
  });
360
370
  }
@@ -380,9 +390,9 @@ class A {
380
390
  * .createAsset({ file, name: "venndiagram.png" });
381
391
  */
382
392
  createAsset() {
383
- return r(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
393
+ return i(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
384
394
  const o = yield this.getBestToken();
385
- return Y(l(c({}, this.config), { file: t, name: e, options: s, token: o }));
395
+ return Y(d(c({}, this.config), { file: t, name: e, options: s, token: o }));
386
396
  });
387
397
  }
388
398
  /**
@@ -395,9 +405,9 @@ class A {
395
405
  * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
396
406
  */
397
407
  getAsset(t) {
398
- return r(this, null, function* () {
408
+ return i(this, null, function* () {
399
409
  const e = yield this.getBestToken();
400
- return W(l(c({}, this.config), { assetID: t, token: e }));
410
+ return W(d(c({}, this.config), { assetID: t, token: e }));
401
411
  });
402
412
  }
403
413
  /**
@@ -410,9 +420,9 @@ class A {
410
420
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
411
421
  */
412
422
  createEntry(t) {
413
- return r(this, null, function* () {
423
+ return i(this, null, function* () {
414
424
  const e = yield this.getBestToken();
415
- return Z(l(c({}, this.config), { token: e, value: t }));
425
+ return Z(d(c({}, this.config), { token: e, value: t }));
416
426
  });
417
427
  }
418
428
  /**
@@ -426,9 +436,9 @@ class A {
426
436
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
427
437
  */
428
438
  editEntry(t, e) {
429
- return r(this, null, function* () {
439
+ return i(this, null, function* () {
430
440
  const s = yield this.getBestToken();
431
- return D(l(c({}, this.config), { entryID: t, token: s, value: e }));
441
+ return D(d(c({}, this.config), { entryID: t, token: s, value: e }));
432
442
  });
433
443
  }
434
444
  /**
@@ -441,9 +451,9 @@ class A {
441
451
  * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
442
452
  */
443
453
  deleteEntry(t) {
444
- return r(this, null, function* () {
454
+ return i(this, null, function* () {
445
455
  const e = yield this.getBestToken();
446
- return I(l(c({}, this.config), { token: e, entryID: t }));
456
+ return I(d(c({}, this.config), { token: e, entryID: t }));
447
457
  });
448
458
  }
449
459
  // TODO: rename authAdapter -> storageAdapter
@@ -474,31 +484,31 @@ class A {
474
484
  }
475
485
  loginEc(t) {
476
486
  return et(c(c({}, this.config), t)).then(
477
- this.setAuth(k(this.config))
487
+ this.setAuth(w(this.config))
478
488
  );
479
489
  }
480
490
  loginPublic(t) {
481
491
  return tt(c(c({}, this.config), t)).then(
482
- this.setAuth(w(this.config))
492
+ this.setAuth(A(this.config))
483
493
  );
484
494
  }
485
495
  logoutPublic() {
486
496
  const t = this.getPublicToken();
487
- return console.log("token", t), st(l(c({}, this.config), { token: t })).then(
488
- this.unsetAuth(w(this.config))
497
+ return console.log("token", t), st(d(c({}, this.config), { token: t })).then(
498
+ this.unsetAuth(A(this.config))
489
499
  );
490
500
  }
491
501
  logoutEc() {
492
502
  const t = this.getEcToken();
493
- return console.log("token", t), nt(l(c({}, this.config), { token: t })).then(
494
- this.unsetAuth(k(this.config))
503
+ return console.log("token", t), nt(d(c({}, this.config), { token: t })).then(
504
+ this.unsetAuth(w(this.config))
495
505
  );
496
506
  }
497
507
  getPublicToken() {
498
- return this.config.token || this.getAuth(w(this.config));
508
+ return this.config.token || this.getAuth(A(this.config));
499
509
  }
500
510
  getEcToken() {
501
- return this.config.token || this.getAuth(k(this.config));
511
+ return this.config.token || this.getAuth(w(this.config));
502
512
  }
503
513
  hasPublicToken() {
504
514
  return !!this.getPublicToken();
@@ -565,27 +575,27 @@ class A {
565
575
  return this.assetGroup(t);
566
576
  }
567
577
  }
568
- const it = (n) => new A({ env: n });
578
+ const it = (n) => new b({ env: n });
569
579
  export {
570
- A as Sdk,
580
+ b as Sdk,
571
581
  rt as act,
572
582
  f as apiURL,
573
- v as assetList,
583
+ M as assetList,
574
584
  H as createAsset,
575
585
  U as createEntry,
576
- G as deleteEntry,
577
- F as editEntry,
586
+ F as deleteEntry,
587
+ v as editEntry,
578
588
  J as entryList,
579
- h as expect,
580
- d as fetcher,
581
- M as getAsset,
589
+ g as expect,
590
+ y as fetcher,
591
+ G as getAsset,
582
592
  z as getEcAuthKey,
583
593
  N as getEntry,
584
594
  R as getPublicAuthKey,
585
- q as loginEc,
595
+ x as loginEc,
586
596
  S as loginPublic,
587
- x as logoutEc,
597
+ q as logoutEc,
588
598
  C as logoutPublic,
589
- $ as query,
599
+ k as query,
590
600
  it as sdk
591
601
  };
@@ -1 +1 @@
1
- {"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;GAUC;AAED;;;;;;;;iBAwBC"}
1
+ {"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;GAUC;AAED;;;;;;;;iBA6BC"}
@@ -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.12",
3
+ "version": "0.2.14",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {