ec.fdk 0.2.16 → 0.2.18
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 +1 -1
- package/dist/index.mjs +5 -3
- package/dist/lib/assets.d.mts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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
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
|
|
3
|
+
${u.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${r.statusText}`)}return a?r:yield r.json()})}const m={live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=m[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(m).join(", ")}`);return e+n}function E(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const j={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function O(n){return i(this,null,function*(){let{env:t,dmShortID:e,email:s,password:o}=n;h({env:t,dmShortID:e,email:s,password:o});const a=f(`api/${e}/_auth/login?clientID=rest`,t);return yield d(a,{},{method:"POST",body:JSON.stringify({email:s,password:o}),headers:{"Content-Type":"application/json"}})})}function _(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=E(o),r=f(`api/${e}/${s}?${a}`,t),{count:g,total:u,_embedded:l}=yield d(r,n);let p=l?l[`${e}:${s}`]:[];return p=Array.isArray(p)?p:[p],{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=E({_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=E({assetID:s}),g=f(`a/${t}/${e}?${r}`,n);return(yield d(g,{dmShortID:t,token:o}))._embedded["ec:dm-asset"]})}function N(n){return i(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:o,options:a={}}=n;h({env:t,dmShortID:e,assetGroup:s}),a=c({size:50,page:1,_list:!0},a);const r=E(a),g=f(`a/${e}/${s}?${r}`,t),{count:u,total:l,_embedded:p}=yield d(g,{dmShortID:e,token:o});let $=p?p["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:u,total:l,items:$}})}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($=>{l.append($,r[$])}),(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:A,getPublicAuthKey:b}=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(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=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=E;exports.sdk=rt;
|
package/dist/index.mjs
CHANGED
|
@@ -151,7 +151,8 @@ function J(n) {
|
|
|
151
151
|
return i(this, null, function* () {
|
|
152
152
|
let { env: t, dmShortID: e, model: s, options: o = {} } = n;
|
|
153
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)
|
|
154
|
+
const a = k(o), r = f(`api/${e}/${s}?${a}`, t), { count: h, total: u, _embedded: l } = yield y(r, n);
|
|
155
|
+
let p = l ? l[`${e}:${s}`] : [];
|
|
155
156
|
return p = Array.isArray(p) ? p : [p], { count: h, total: u, items: p };
|
|
156
157
|
});
|
|
157
158
|
}
|
|
@@ -228,8 +229,9 @@ function M(n) {
|
|
|
228
229
|
return i(this, null, function* () {
|
|
229
230
|
let { env: t, dmShortID: e, assetGroup: s, token: o, options: a = {} } = n;
|
|
230
231
|
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 })
|
|
232
|
-
|
|
232
|
+
const r = k(a), h = f(`a/${e}/${s}?${r}`, t), { count: u, total: l, _embedded: p } = yield y(h, { dmShortID: e, token: o });
|
|
233
|
+
let $ = p ? p["ec:dm-asset"] : [];
|
|
234
|
+
return $ = Array.isArray($) ? $ : [$], { count: u, total: l, items: $ };
|
|
233
235
|
});
|
|
234
236
|
}
|
|
235
237
|
function H(h) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;
|
|
1
|
+
{"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/lib/assets.mjs"],"names":[],"mappings":"AAEA;;;;;;iBAMC;AAED;;;;GAWC;AAED;;;;;;;;iBA6BC"}
|