ec.fdk 0.2.23 → 0.2.24
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 +2 -2
- package/dist/index.mjs +8 -8
- package/dist/lib/entries.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var F=Object.defineProperty,G=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var m=(n,t,e)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t)=>{for(var e in t||(t={}))Q.call(t,e)&&m(n,e,t[e]);if(T)for(var e of T(t))V.call(t,e)&&m(n,e,t[e]);return n},y=(n,t)=>G(n,H(t));var i=(n,t,e)=>new Promise((s,o)=>{var u=c=>{try{h(e.next(c))}catch(d){o(d)}},r=c=>{try{h(e.throw(c))}catch(d){o(d)}},h=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,r);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";var F=Object.defineProperty,G=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var m=(n,t,e)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t)=>{for(var e in t||(t={}))Q.call(t,e)&&m(n,e,t[e]);if(T)for(var e of T(t))V.call(t,e)&&m(n,e,t[e]);return n},y=(n,t)=>G(n,H(t));var i=(n,t,e)=>new Promise((s,o)=>{var u=c=>{try{h(e.next(c))}catch(d){o(d)}},r=c=>{try{h(e.throw(c))}catch(d){o(d)}},h=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,r);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(s){return i(this,arguments,function*(n,t={},e={}){var h;const{token:o,rawRes:u}=t;o&&(e.headers=y(a({},e.headers||{}),{Authorization:`Bearer ${o}`}));const r=yield fetch(n,e);if(!r.ok){if((h=r.headers.get("content-type"))!=null&&h.includes("application/json")){const c=yield r.json(),d=`${c.title}
|
|
2
2
|
${c.detail}
|
|
3
|
-
${c.verbose}`;throw new Error(d)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return u?r:yield r.json()})}const P={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=P[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(P).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
|
|
3
|
+
${c.verbose}`;throw new Error(d)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return u?r:yield r.json()})}const P={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=P[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(P).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 g(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 L(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;g({env:t,dmShortID:e,email:s,password:o});const u=f(`api/${e}/_auth/login?clientID=rest`,t);return yield l(u,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function O(n){return i(this,null,function*(){let{env:t,email:e,password:s}=n;g({env:t,email:e,password:s});const o=`${j[t]}auth/login?clientID=rest`;return yield l(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;g({dmShortID:t,env:e,token:s});const o=f(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield l(o,{dmShortID:t,rawRes:!0},{method:"POST"})})}function B(n){return i(this,null,function*(){let{env:t,token:e}=n;g({env:t,token:e});const s=`${j[t]}auth/logout?clientID=rest`;return yield l(s,{rawRes:!0,token:e},{method:"POST"})})}function S({dmShortID:n}){return g({dmShortID:n}),n}function K({env:n}){return g({env:n}),n}function q(n){return i(this,null,function*(){let{env:t,dmShortID:e,model:s,options:o={}}=n;g({env:t,dmShortID:e,model:s}),o=a({size:50,page:1,_list:!0},o);const u=E(o),r=f(`api/${e}/${s}?${u}`,t),{count:h,total:c,_embedded:d}=yield l(r,n);let $=d?d[`${e}:${s}`]:[];return $=Array.isArray($)?$:[$],{count:h,total:c,items:$}})}function R({env:n,dmShortID:t,model:e,entryID:s,token:o}){g({env:n,dmShortID:t,model:e,entryID:s});const u=E({_id:s}),r=f(`api/${t}/${e}?${u}`,n);return l(r,{dmShortID:t,token:o})}function x(u){return i(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:o}){g({env:n,dmShortID:t,model:e,value:s});const r=f(`api/${t}/${e}`,n);return yield l(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:u}){g({env:n,dmShortID:t,model:e,entryID:s,value:o});const h=f(`api/${t}/${e}?_id=${s}`,n);return yield l(h,{token:u},{method:"PUT",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function z(u){return i(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:o}){g({env:n,dmShortID:t,model:e,entryID:s});const r=f(`api/${t}/${e}?_id=${s}`,n);yield l(r,{token:o,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function J(u){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){g({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=E({assetID:s}),h=f(`a/${t}/${e}?${r}`,n);return(yield l(h,{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:u={}}=n;g({env:t,dmShortID:e,assetGroup:s}),u=a({size:50,page:1,_list:!0},u);const r=E(u),h=f(`a/${e}/${s}?${r}`,t),{count:c,total:d,_embedded:$}=yield l(h,{dmShortID:e,token:o});let p=$?$["ec:dm-asset"]:[];return p=Array.isArray(p)?p:[p],{count:c,total:d,items:p}})}function v(h){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:o,name:u,options:r}){g({env:n,dmShortID:t,assetGroup:e,file:o});const c=f(`a/${t}/${e}`,n),d=new FormData;return d.append("file",o,u),r&&Object.keys(r).forEach(p=>{d.append(p,r[p])}),(yield l(c,{token:s},{method:"POST",body:d}))._embedded["ec:dm-asset"]})}function U(u){return i(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:o}){g({env:n,dmShortID:t,assetGroup:e,assetID:s});const r=f(`a/${t}/${e}/${s}`,n);yield l(r,{token:o,rawRes:!0},{method:"DELETE"})})}function M(n){return i(this,null,function*(){let{env:t,options:e={}}=n;g({env:t}),e=a({size:25,page:1,_list:!0},e);const s=E(e),o=f(`?${s}`,t),{count:u,total:r,_embedded:h}=yield l(o,n);let c=h?h["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:u,total:r,items:c}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:N,createAsset:v,createEntry:x,deleteAsset:U,deleteEntry:z,dmList:M,editEntry:C,entryList:q,getAsset:J,getEcAuthKey:K,getEntry:R,getPublicAuthKey:S,loginEc:O,loginPublic:L,logoutEc:B,logoutPublic:_},Symbol.toStringTag,{value:"Module"})),{entryList:W,getEntry:X,getAsset:Y,assetList:Z,createAsset:D,deleteAsset:I,createEntry:tt,editEntry:et,deleteEntry:nt,loginPublic:st,loginEc:ot,logoutEc:rt,logoutPublic:it,getEcAuthKey:w,getPublicAuthKey:b,dmList:ct}=k;function at(n){const{action:t}=n;if(g({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(a(a({},this.config),t))}entries(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return W(y(a({},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 X(y(a({},this.config),{entryID:t,token:e}))})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return Z(y(a({},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 D(y(a({},this.config),{file:t,name:e,options:s,token:o}))})}deleteAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return I(y(a({},this.config),{token:e,assetID:t}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return Y(y(a({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return tt(y(a({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return et(y(a({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return nt(y(a({},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 ot(a(a({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return st(a(a({},this.config),t)).then(this.setAuth(b(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),it(y(a({},this.config),{token:t})).then(this.unsetAuth(b(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),rt(y(a({},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)}dmList(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return ct(y(a({},this.config),{options:t,token:e}))})}}const ut=n=>new A({env:n});exports.Sdk=A;exports.act=at;exports.apiURL=f;exports.assetList=N;exports.createAsset=v;exports.createEntry=x;exports.deleteAsset=U;exports.deleteEntry=z;exports.dmList=M;exports.editEntry=C;exports.entryList=q;exports.expect=g;exports.fetcher=l;exports.getAsset=J;exports.getEcAuthKey=K;exports.getEntry=R;exports.getPublicAuthKey=S;exports.loginEc=O;exports.loginPublic=L;exports.logoutEc=B;exports.logoutPublic=_;exports.query=E;exports.sdk=ut;
|
package/dist/index.mjs
CHANGED
|
@@ -161,11 +161,11 @@ function N({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
|
|
|
161
161
|
const u = E({ _id: s }), r = f(`api/${t}/${e}?${u}`, n);
|
|
162
162
|
return y(r, { dmShortID: t, token: o });
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function v(u) {
|
|
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 })
|
|
166
|
+
g({ env: n, dmShortID: t, model: e, value: s });
|
|
167
167
|
const r = f(`api/${t}/${e}`, n);
|
|
168
|
-
return
|
|
168
|
+
return yield y(
|
|
169
169
|
r,
|
|
170
170
|
{ env: n, dmShortID: t, token: o },
|
|
171
171
|
{
|
|
@@ -178,7 +178,7 @@ function U(u) {
|
|
|
178
178
|
);
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function U(r) {
|
|
182
182
|
return i(this, arguments, function* ({
|
|
183
183
|
env: n,
|
|
184
184
|
dmShortID: t,
|
|
@@ -290,11 +290,11 @@ const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
290
290
|
__proto__: null,
|
|
291
291
|
assetList: G,
|
|
292
292
|
createAsset: H,
|
|
293
|
-
createEntry:
|
|
293
|
+
createEntry: v,
|
|
294
294
|
deleteAsset: Q,
|
|
295
295
|
deleteEntry: F,
|
|
296
296
|
dmList: V,
|
|
297
|
-
editEntry:
|
|
297
|
+
editEntry: U,
|
|
298
298
|
entryList: J,
|
|
299
299
|
getAsset: M,
|
|
300
300
|
getEcAuthKey: z,
|
|
@@ -649,11 +649,11 @@ export {
|
|
|
649
649
|
f as apiURL,
|
|
650
650
|
G as assetList,
|
|
651
651
|
H as createAsset,
|
|
652
|
-
|
|
652
|
+
v as createEntry,
|
|
653
653
|
Q as deleteAsset,
|
|
654
654
|
F as deleteEntry,
|
|
655
655
|
V as dmList,
|
|
656
|
-
|
|
656
|
+
U as editEntry,
|
|
657
657
|
J as entryList,
|
|
658
658
|
g as expect,
|
|
659
659
|
y as fetcher,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAEA;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;
|
|
1
|
+
{"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAEA;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;iBAuBC;AAED;;;;;;kBAcC"}
|