ec.fdk 0.1.2 → 0.1.3
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 +258 -243
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty,G=Object.defineProperties;var M=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var m=(n,t,e)=>t in n?v(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))F.call(t,e)&&m(n,e,t[e]);if(P)for(var e of P(t))H.call(t,e)&&m(n,e,t[e]);return n},d=(n,t)=>G(n,M(t));var a=(n,t,e)=>new Promise((o,s)=>{var r=g=>{try{h(e.next(g))}catch(y){s(y)}},i=g=>{try{h(e.throw(g))}catch(y){s(y)}},h=g=>g.done?o(g.value):Promise.resolve(g.value).then(r,i);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(o){return a(this,arguments,function*(n,t={},e={}){const{token:s,rawRes:r}=t;s&&(e.headers=d(c({},e.headers||{}),{Authorization:`Bearer ${s}`}));const i=yield fetch(n,e);if(!i.ok)throw new Error(i.statusText);return r?i:yield i.json()})}const j={production:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"};function f(n,t="stage"){const e=j[t];if(!e)throw new Error(`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`);return e+n}function E(n,t=!0){return Object.entries(n).sort((e,o)=>e[0].localeCompare(o[0])).map(([e,o])=>`${e}=${o}`).join("&")}function u(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const L={stage:"https://accounts.cachena.entrecode.de/",production:"https://accounts.cachena.entrecode.de/"};function S(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:o,password:s}=n;u({env:t,dmShortID:e,email:o,password:s});const r=f(`api/${e}/_auth/login?clientID=rest`,t);return yield l(r,{},{method:"POST",body:JSON.stringify({email:o,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return a(this,null,function*(){let{env:t,email:e,password:o}=n;u({env:t,email:e,password:o});const s=`${L[t]}auth/login?clientID=rest`;return yield l(s,{},{method:"POST",body:JSON.stringify({email:e,password:o}),headers:{"Content-Type":"application/json"}})})}function q(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:o}=n;u({dmShortID:t,env:e,token:o});const s=f(`api/${t}/_auth/logout?clientID=rest&token=${o}`,e);return yield l(s,{dmShortID:t,rawRes:!0},{method:"POST"})})}function x(n){return a(this,null,function*(){let{env:t,token:e}=n;u({env:t,token:e});const o=`${L[t]}auth/logout?clientID=rest`;return yield l(o,{rawRes:!0,token:e},{method:"POST"})})}function B({dmShortID:n}){return u({dmShortID:n}),n}function C({env:n}){return u({env:n}),n}function R(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:o,options:s={}}=n;u({env:t,dmShortID:e,model:o}),s=c({size:50,page:1,_list:!0},s);const r=E(s),i=f(`api/${e}/${o}?${r}`,t),{count:h,total:g,_embedded:y}=yield l(i,n),b=y?y[`${e}:${o}`]:[];return{count:h,total:g,items:b}})}function z({env:n,dmShortID:t,model:e,entryID:o,token:s}){u({env:n,dmShortID:t,model:e,entryID:o});const r=E({_id:o}),i=f(`api/${t}/${e}?${r}`,n);return l(i,{dmShortID:t,token:s})}function J(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:o,token:s}){u({env:n,dmShortID:t,model:e,value:o}),console.log("create entry",t,e,o);const i=f(`api/${t}/${e}`,n);return console.log("url",i),yield l(i,{env:n,dmShortID:t,token:s},{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})})}function N(i){return a(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:o,value:s,token:r}){u({env:n,dmShortID:t,model:e,entryID:o,value:s});const h=f(`api/${t}/${e}?_id=${o}`,n);return yield l(h,{token:r},{method:"PUT",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function D(r){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:o,token:s}){u({env:n,dmShortID:t,assetGroup:e,assetID:o});const i=E({assetID:o}),h=f(`a/${t}/${e}?${i}`,n);return(yield l(h,{dmShortID:t,token:s}))._embedded["ec:dm-asset"]})}function I(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:o,token:s,options:r={}}=n;u({env:t,dmShortID:e,assetGroup:o}),r=c({size:50,page:1,_list:!0},r);const i=E(r),h=f(`a/${e}/${o}?${i}`,t),{count:g,total:y,_embedded:b}=yield l(h,{dmShortID:e,token:s}),U=b?b["ec:dm-asset"]:[];return{count:g,total:y,items:U}})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:I,createEntry:J,editEntry:N,entryList:R,getAsset:D,getEcAuthKey:C,getEntry:z,getPublicAuthKey:B,loginEc:K,loginPublic:S,logoutEc:x,logoutPublic:q},Symbol.toStringTag,{value:"Module"})),{entryList:Q,getEntry:V,getAsset:W,assetList:X,createEntry:O,editEntry:_,loginPublic:Y,loginEc:Z,logoutEc:tt,logoutPublic:et,getEcAuthKey:w,getPublicAuthKey:A}=k;function nt(n){const{action:t}=n;if(u({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class p{constructor(t){this.config=t}set(t){return new p(c(c({},this.config),t))}handle(t){return a(this,null,function*(){const e=Object.keys(this.config),o=yield this.getBestToken(),[s,r]=Object.entries(t).find(([i,h])=>e.includes(i))||[];if(!r)throw new Error(`you need to first set ${Object.keys(t).join(" | ")}`);return r(d(c({},this.config),{token:o}))})}entries(t){return a(this,null,function*(){const e=yield this.getBestToken();return Q(d(c({},this.config),{options:t,token:e}))})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return X(d(c({},this.config),{options:t,token:e}))})}get(){return this.handle({assetID:W,entryID:V})}del(){}createEntry(t){return O(d(c({},this.config),{value:t}))}editEntry(t){return _(d(c({},this.config),{value:t}))}create(t){return this.set({value:t}).handle({model:O})}edit(t){return this.set({value:t}).handle({entryID:_})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:o}=this.config.authAdapter;return o(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:o}=this.config.authAdapter;return o(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return Z(c(c({},this.config),t)).then(this.setAuth(w(this.config)))}loginPublic(t){return Y(c(c({},this.config),t)).then(this.setAuth(A(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),et(d(c({},this.config),{token:t})).then(this.unsetAuth(A(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),tt(d(c({},this.config),{token:t})).then(this.unsetAuth(w(this.config)))}getPublicToken(){return this.config.token||this.getAuth(A(this.config))}getEcToken(){return this.config.token||this.getAuth(w(this.config))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){return this.getEcToken()||this.getPublicToken()}}const $=(...n)=>{const[t]=n;n.forEach(e=>{p.prototype[e]=function(o){return this.set({[t]:o})}})},T=(n,t)=>{p.prototype[n]=p.prototype[t]};$("dmShortID","dm","dmshortid");$("model");$("token");$("entryID","entry");$("assetGroup");$("assetID","asset");T("assetgroup","assetGroup");T("entryList","entries");T("assetList","assets");const ot=n=>new p({env:n});exports.act=nt;exports.apiURL=f;exports.assetList=I;exports.createEntry=J;exports.editEntry=N;exports.entryList=R;exports.expect=u;exports.fetcher=l;exports.getAsset=D;exports.getEcAuthKey=C;exports.getEntry=z;exports.getPublicAuthKey=B;exports.loginEc=K;exports.loginPublic=S;exports.logoutEc=x;exports.logoutPublic=q;exports.query=E;exports.sdk=ot;
|
package/dist/index.mjs
CHANGED
|
@@ -1,80 +1,79 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
1
|
+
var K = Object.defineProperty, q = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var P = Object.getOwnPropertySymbols;
|
|
4
|
+
var B = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var m = (n, t, e) => t in n ? K(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, c = (n, t) => {
|
|
6
|
+
for (var e in t || (t = {}))
|
|
7
|
+
B.call(t, e) && m(n, e, t[e]);
|
|
8
|
+
if (P)
|
|
9
|
+
for (var e of P(t))
|
|
10
|
+
C.call(t, e) && m(n, e, t[e]);
|
|
11
|
+
return n;
|
|
12
|
+
}, d = (n, t) => q(n, x(t));
|
|
13
|
+
var a = (n, t, e) => new Promise((s, o) => {
|
|
14
|
+
var r = (h) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
|
|
16
|
+
u(e.next(h));
|
|
17
|
+
} catch (f) {
|
|
18
|
+
o(f);
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, i = (h) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
|
|
22
|
+
u(e.throw(h));
|
|
23
|
+
} catch (f) {
|
|
24
|
+
o(f);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
26
|
+
}, u = (h) => h.done ? s(h.value) : Promise.resolve(h.value).then(r, i);
|
|
27
|
+
u((e = e.apply(n, t)).next());
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Authorization: `Bearer ${s}`
|
|
29
|
+
function l(s) {
|
|
30
|
+
return a(this, arguments, function* (n, t = {}, e = {}) {
|
|
31
|
+
const { token: o, rawRes: r } = t;
|
|
32
|
+
o && (e.headers = d(c({}, e.headers || {}), {
|
|
33
|
+
Authorization: `Bearer ${o}`
|
|
35
34
|
}));
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
throw new Error(
|
|
39
|
-
return
|
|
35
|
+
const i = yield fetch(n, e);
|
|
36
|
+
if (!i.ok)
|
|
37
|
+
throw new Error(i.statusText);
|
|
38
|
+
return r ? i : yield i.json();
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
|
-
const
|
|
41
|
+
const j = {
|
|
43
42
|
production: "https://datamanager.entrecode.de/",
|
|
44
43
|
stage: "https://datamanager.cachena.entrecode.de/"
|
|
45
44
|
};
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
45
|
+
function y(n, t = "stage") {
|
|
46
|
+
const e = j[t];
|
|
47
|
+
if (!e)
|
|
49
48
|
throw new Error(
|
|
50
|
-
`env "${t}" not found. Try one of ${Object.keys(
|
|
49
|
+
`env "${t}" not found. Try one of ${Object.keys(j).join(", ")}`
|
|
51
50
|
);
|
|
52
|
-
return
|
|
51
|
+
return e + n;
|
|
53
52
|
}
|
|
54
|
-
function
|
|
55
|
-
return Object.entries(
|
|
53
|
+
function b(n, t = !0) {
|
|
54
|
+
return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
|
|
56
55
|
}
|
|
57
|
-
function
|
|
58
|
-
Object.entries(
|
|
59
|
-
if (
|
|
56
|
+
function g(n) {
|
|
57
|
+
Object.entries(n).forEach(([t, e]) => {
|
|
58
|
+
if (e === void 0)
|
|
60
59
|
throw new Error(`expected ${t} to be set!`);
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
|
-
const
|
|
62
|
+
const L = {
|
|
64
63
|
stage: "https://accounts.cachena.entrecode.de/",
|
|
65
64
|
production: "https://accounts.cachena.entrecode.de/"
|
|
66
65
|
};
|
|
67
|
-
function
|
|
68
|
-
return
|
|
69
|
-
let { env: t, dmShortID:
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
return yield
|
|
73
|
-
|
|
66
|
+
function z(n) {
|
|
67
|
+
return a(this, null, function* () {
|
|
68
|
+
let { env: t, dmShortID: e, email: s, password: o } = n;
|
|
69
|
+
g({ env: t, dmShortID: e, email: s, password: o });
|
|
70
|
+
const r = y(`api/${e}/_auth/login?clientID=rest`, t);
|
|
71
|
+
return yield l(
|
|
72
|
+
r,
|
|
74
73
|
{},
|
|
75
74
|
{
|
|
76
75
|
method: "POST",
|
|
77
|
-
body: JSON.stringify({ email:
|
|
76
|
+
body: JSON.stringify({ email: s, password: o }),
|
|
78
77
|
headers: {
|
|
79
78
|
"Content-Type": "application/json"
|
|
80
79
|
}
|
|
@@ -82,17 +81,17 @@ function D(e) {
|
|
|
82
81
|
);
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
|
-
function
|
|
86
|
-
return
|
|
87
|
-
let { env: t, email:
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
return yield
|
|
91
|
-
|
|
84
|
+
function J(n) {
|
|
85
|
+
return a(this, null, function* () {
|
|
86
|
+
let { env: t, email: e, password: s } = n;
|
|
87
|
+
g({ env: t, email: e, password: s });
|
|
88
|
+
const o = `${L[t]}auth/login?clientID=rest`;
|
|
89
|
+
return yield l(
|
|
90
|
+
o,
|
|
92
91
|
{},
|
|
93
92
|
{
|
|
94
93
|
method: "POST",
|
|
95
|
-
body: JSON.stringify({ email:
|
|
94
|
+
body: JSON.stringify({ email: e, password: s }),
|
|
96
95
|
headers: {
|
|
97
96
|
"Content-Type": "application/json"
|
|
98
97
|
}
|
|
@@ -100,15 +99,15 @@ function I(e) {
|
|
|
100
99
|
);
|
|
101
100
|
});
|
|
102
101
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
105
|
-
let { dmShortID: t, env:
|
|
106
|
-
|
|
107
|
-
const o =
|
|
108
|
-
`api/${t}/_auth/logout?clientID=rest&token=${
|
|
109
|
-
|
|
102
|
+
function N(n) {
|
|
103
|
+
return a(this, null, function* () {
|
|
104
|
+
let { dmShortID: t, env: e, token: s } = n;
|
|
105
|
+
g({ dmShortID: t, env: e, token: s });
|
|
106
|
+
const o = y(
|
|
107
|
+
`api/${t}/_auth/logout?clientID=rest&token=${s}`,
|
|
108
|
+
e
|
|
110
109
|
);
|
|
111
|
-
return yield
|
|
110
|
+
return yield l(
|
|
112
111
|
o,
|
|
113
112
|
{ dmShortID: t, rawRes: !0 },
|
|
114
113
|
{
|
|
@@ -117,16 +116,16 @@ function q(e) {
|
|
|
117
116
|
);
|
|
118
117
|
});
|
|
119
118
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
122
|
-
let { env: t, token:
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
return yield
|
|
126
|
-
|
|
119
|
+
function R(n) {
|
|
120
|
+
return a(this, null, function* () {
|
|
121
|
+
let { env: t, token: e } = n;
|
|
122
|
+
g({ env: t, token: e });
|
|
123
|
+
const s = `${L[t]}auth/logout?clientID=rest`;
|
|
124
|
+
return yield l(
|
|
125
|
+
s,
|
|
127
126
|
{
|
|
128
127
|
rawRes: !0,
|
|
129
|
-
token:
|
|
128
|
+
token: e
|
|
130
129
|
},
|
|
131
130
|
{
|
|
132
131
|
method: "POST"
|
|
@@ -134,29 +133,35 @@ function v(e) {
|
|
|
134
133
|
);
|
|
135
134
|
});
|
|
136
135
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
function D({ dmShortID: n }) {
|
|
137
|
+
return g({ dmShortID: n }), n;
|
|
138
|
+
}
|
|
139
|
+
function I({ env: n }) {
|
|
140
|
+
return g({ env: n }), n;
|
|
141
|
+
}
|
|
142
|
+
function G(n) {
|
|
143
|
+
return a(this, null, function* () {
|
|
144
|
+
let { env: t, dmShortID: e, model: s, options: o = {} } = n;
|
|
145
|
+
g({ env: t, dmShortID: e, model: s }), o = c({ size: 50, page: 1, _list: !0 }, o);
|
|
146
|
+
const r = b(o), i = y(`api/${e}/${s}?${r}`, t), { count: u, total: h, _embedded: f } = yield l(i, n), E = f ? f[`${e}:${s}`] : [];
|
|
147
|
+
return { count: u, total: h, items: E };
|
|
143
148
|
});
|
|
144
149
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
return
|
|
150
|
+
function U({ env: n, dmShortID: t, model: e, entryID: s, token: o }) {
|
|
151
|
+
g({ env: n, dmShortID: t, model: e, entryID: s });
|
|
152
|
+
const r = b({ _id: s }), i = y(`api/${t}/${e}?${r}`, n);
|
|
153
|
+
return l(i, { dmShortID: t, token: o });
|
|
149
154
|
}
|
|
150
|
-
function
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
return console.log("url",
|
|
155
|
-
|
|
156
|
-
{ env:
|
|
155
|
+
function v(r) {
|
|
156
|
+
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: o }) {
|
|
157
|
+
g({ env: n, dmShortID: t, model: e, value: s }), console.log("create entry", t, e, s);
|
|
158
|
+
const i = y(`api/${t}/${e}`, n);
|
|
159
|
+
return console.log("url", i), yield l(
|
|
160
|
+
i,
|
|
161
|
+
{ env: n, dmShortID: t, token: o },
|
|
157
162
|
{
|
|
158
163
|
method: "POST",
|
|
159
|
-
body: JSON.stringify(
|
|
164
|
+
body: JSON.stringify(s),
|
|
160
165
|
headers: {
|
|
161
166
|
"Content-Type": "application/json"
|
|
162
167
|
}
|
|
@@ -164,88 +169,112 @@ function B(c) {
|
|
|
164
169
|
);
|
|
165
170
|
});
|
|
166
171
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
169
|
-
env:
|
|
172
|
+
function M(i) {
|
|
173
|
+
return a(this, arguments, function* ({
|
|
174
|
+
env: n,
|
|
170
175
|
dmShortID: t,
|
|
171
|
-
model:
|
|
172
|
-
entryID:
|
|
173
|
-
value:
|
|
174
|
-
token:
|
|
176
|
+
model: e,
|
|
177
|
+
entryID: s,
|
|
178
|
+
value: o,
|
|
179
|
+
token: r
|
|
175
180
|
}) {
|
|
176
|
-
|
|
181
|
+
g({ env: n, dmShortID: t, model: e, entryID: s, value: o });
|
|
182
|
+
const u = y(`api/${t}/${e}?_id=${s}`, n);
|
|
183
|
+
return yield l(
|
|
184
|
+
u,
|
|
185
|
+
{ token: r },
|
|
186
|
+
{
|
|
187
|
+
method: "PUT",
|
|
188
|
+
body: JSON.stringify(o),
|
|
189
|
+
headers: {
|
|
190
|
+
"Content-Type": "application/json"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
);
|
|
177
194
|
});
|
|
178
195
|
}
|
|
179
|
-
function F(
|
|
180
|
-
return
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
return (yield
|
|
196
|
+
function F(r) {
|
|
197
|
+
return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: o }) {
|
|
198
|
+
g({ env: n, dmShortID: t, assetGroup: e, assetID: s });
|
|
199
|
+
const i = b({ assetID: s }), u = y(`a/${t}/${e}?${i}`, n);
|
|
200
|
+
return (yield l(u, { dmShortID: t, token: o }))._embedded["ec:dm-asset"];
|
|
184
201
|
});
|
|
185
202
|
}
|
|
186
|
-
function H(
|
|
187
|
-
return
|
|
188
|
-
let { env: t, dmShortID:
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
return { count:
|
|
203
|
+
function H(n) {
|
|
204
|
+
return a(this, null, function* () {
|
|
205
|
+
let { env: t, dmShortID: e, assetGroup: s, token: o, options: r = {} } = n;
|
|
206
|
+
g({ env: t, dmShortID: e, assetGroup: s }), r = c({ size: 50, page: 1, _list: !0 }, r);
|
|
207
|
+
const i = b(r), u = y(`a/${e}/${s}?${i}`, t), { count: h, total: f, _embedded: E } = yield l(u, { dmShortID: e, token: o }), S = E ? E["ec:dm-asset"] : [];
|
|
208
|
+
return { count: h, total: f, items: S };
|
|
192
209
|
});
|
|
193
210
|
}
|
|
194
|
-
const
|
|
211
|
+
const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
195
212
|
__proto__: null,
|
|
196
213
|
assetList: H,
|
|
197
|
-
createEntry:
|
|
198
|
-
editEntry:
|
|
214
|
+
createEntry: v,
|
|
215
|
+
editEntry: M,
|
|
199
216
|
entryList: G,
|
|
200
217
|
getAsset: F,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
218
|
+
getEcAuthKey: I,
|
|
219
|
+
getEntry: U,
|
|
220
|
+
getPublicAuthKey: D,
|
|
221
|
+
loginEc: J,
|
|
222
|
+
loginPublic: z,
|
|
223
|
+
logoutEc: R,
|
|
224
|
+
logoutPublic: N
|
|
206
225
|
}, Symbol.toStringTag, { value: "Module" })), {
|
|
207
226
|
entryList: Q,
|
|
208
227
|
getEntry: V,
|
|
209
228
|
getAsset: W,
|
|
210
229
|
assetList: X,
|
|
211
|
-
createEntry:
|
|
212
|
-
editEntry:
|
|
230
|
+
createEntry: O,
|
|
231
|
+
editEntry: _,
|
|
213
232
|
loginPublic: Y,
|
|
214
233
|
loginEc: Z,
|
|
215
234
|
logoutEc: tt,
|
|
216
|
-
logoutPublic: et
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
235
|
+
logoutPublic: et,
|
|
236
|
+
getEcAuthKey: w,
|
|
237
|
+
getPublicAuthKey: A
|
|
238
|
+
} = k;
|
|
239
|
+
function st(n) {
|
|
240
|
+
const { action: t } = n;
|
|
241
|
+
if (g({ action: t }), !k[t])
|
|
221
242
|
throw new Error(
|
|
222
|
-
`"${t}" does not exist! try one of ${Object.keys(
|
|
243
|
+
`"${t}" does not exist! try one of ${Object.keys(k).join(
|
|
223
244
|
", "
|
|
224
245
|
)}`
|
|
225
246
|
);
|
|
226
|
-
return
|
|
247
|
+
return k[t](n);
|
|
227
248
|
}
|
|
228
249
|
class p {
|
|
229
250
|
constructor(t) {
|
|
230
251
|
this.config = t;
|
|
231
252
|
}
|
|
232
253
|
set(t) {
|
|
233
|
-
return new p(
|
|
254
|
+
return new p(c(c({}, this.config), t));
|
|
234
255
|
}
|
|
235
256
|
handle(t) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
257
|
+
return a(this, null, function* () {
|
|
258
|
+
const e = Object.keys(this.config), s = yield this.getBestToken(), [o, r] = Object.entries(t).find(([i, u]) => e.includes(i)) || [];
|
|
259
|
+
if (!r)
|
|
260
|
+
throw new Error(
|
|
261
|
+
`you need to first set ${Object.keys(t).join(" | ")}`
|
|
262
|
+
);
|
|
263
|
+
return r(d(c({}, this.config), { token: s }));
|
|
264
|
+
});
|
|
242
265
|
}
|
|
243
266
|
///
|
|
244
267
|
entries(t) {
|
|
245
|
-
return
|
|
268
|
+
return a(this, null, function* () {
|
|
269
|
+
const e = yield this.getBestToken();
|
|
270
|
+
return Q(d(c({}, this.config), { options: t, token: e }));
|
|
271
|
+
});
|
|
246
272
|
}
|
|
247
273
|
assets(t) {
|
|
248
|
-
return
|
|
274
|
+
return a(this, null, function* () {
|
|
275
|
+
const e = yield this.getBestToken();
|
|
276
|
+
return X(d(c({}, this.config), { options: t, token: e }));
|
|
277
|
+
});
|
|
249
278
|
}
|
|
250
279
|
get() {
|
|
251
280
|
return this.handle({
|
|
@@ -256,46 +285,99 @@ class p {
|
|
|
256
285
|
del() {
|
|
257
286
|
}
|
|
258
287
|
createEntry(t) {
|
|
259
|
-
return
|
|
288
|
+
return O(d(c({}, this.config), { value: t }));
|
|
260
289
|
}
|
|
261
290
|
editEntry(t) {
|
|
262
|
-
return
|
|
291
|
+
return _(d(c({}, this.config), { value: t }));
|
|
263
292
|
}
|
|
264
293
|
create(t) {
|
|
265
294
|
return this.set({ value: t }).handle({
|
|
266
295
|
//assetID: createAsset,
|
|
267
|
-
model:
|
|
296
|
+
model: O
|
|
268
297
|
});
|
|
269
298
|
}
|
|
270
299
|
edit(t) {
|
|
271
300
|
return this.set({ value: t }).handle({
|
|
272
301
|
//assetID: createAsset,
|
|
273
|
-
entryID:
|
|
302
|
+
entryID: _
|
|
274
303
|
});
|
|
275
304
|
}
|
|
276
|
-
//
|
|
277
|
-
|
|
278
|
-
return
|
|
305
|
+
// TODO: rename authAdapter -> storageAdapter
|
|
306
|
+
authAdapter(t) {
|
|
307
|
+
return this.set({ authAdapter: t });
|
|
279
308
|
}
|
|
280
|
-
|
|
281
|
-
return
|
|
309
|
+
setAuth(t) {
|
|
310
|
+
return (e) => {
|
|
311
|
+
if (!this.config.authAdapter)
|
|
312
|
+
throw new Error("cannot setAuth: no authAdapter defined!");
|
|
313
|
+
const { set: s } = this.config.authAdapter;
|
|
314
|
+
return s(t, e.token), e;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
unsetAuth(t) {
|
|
318
|
+
return (e) => {
|
|
319
|
+
if (console.log("unset auth", e), !this.config.authAdapter)
|
|
320
|
+
throw new Error("cannot unsetAuth: no authAdapter defined!");
|
|
321
|
+
const { remove: s } = this.config.authAdapter;
|
|
322
|
+
return s(t), e;
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
getAuth(t) {
|
|
326
|
+
if (!this.config.authAdapter)
|
|
327
|
+
throw new Error("cannot getAuth: no authAdapter defined!");
|
|
328
|
+
const { get: e } = this.config.authAdapter;
|
|
329
|
+
return e(t);
|
|
282
330
|
}
|
|
283
331
|
loginEc(t) {
|
|
284
|
-
return Z(
|
|
332
|
+
return Z(c(c({}, this.config), t)).then(
|
|
333
|
+
this.setAuth(w(this.config))
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
loginPublic(t) {
|
|
337
|
+
return Y(c(c({}, this.config), t)).then(
|
|
338
|
+
this.setAuth(A(this.config))
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
logoutPublic() {
|
|
342
|
+
const t = this.getPublicToken();
|
|
343
|
+
return console.log("token", t), et(d(c({}, this.config), { token: t })).then(
|
|
344
|
+
this.unsetAuth(A(this.config))
|
|
345
|
+
);
|
|
285
346
|
}
|
|
286
347
|
logoutEc() {
|
|
287
|
-
|
|
348
|
+
const t = this.getEcToken();
|
|
349
|
+
return console.log("token", t), tt(d(c({}, this.config), { token: t })).then(
|
|
350
|
+
this.unsetAuth(w(this.config))
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
getPublicToken() {
|
|
354
|
+
return this.config.token || this.getAuth(A(this.config));
|
|
355
|
+
}
|
|
356
|
+
getEcToken() {
|
|
357
|
+
return this.config.token || this.getAuth(w(this.config));
|
|
358
|
+
}
|
|
359
|
+
hasPublicToken() {
|
|
360
|
+
return !!this.getPublicToken();
|
|
361
|
+
}
|
|
362
|
+
hasEcToken() {
|
|
363
|
+
return !!this.getEcToken();
|
|
364
|
+
}
|
|
365
|
+
hasAnyToken() {
|
|
366
|
+
return !!this.getEcToken() || !!this.getPublicToken();
|
|
367
|
+
}
|
|
368
|
+
getBestToken() {
|
|
369
|
+
return this.getEcToken() || this.getPublicToken();
|
|
288
370
|
}
|
|
289
371
|
}
|
|
290
|
-
const $ = (...
|
|
291
|
-
const [t] =
|
|
292
|
-
|
|
293
|
-
p.prototype[
|
|
294
|
-
return this.set({ [t]:
|
|
372
|
+
const $ = (...n) => {
|
|
373
|
+
const [t] = n;
|
|
374
|
+
n.forEach((e) => {
|
|
375
|
+
p.prototype[e] = function(s) {
|
|
376
|
+
return this.set({ [t]: s });
|
|
295
377
|
};
|
|
296
378
|
});
|
|
297
|
-
},
|
|
298
|
-
p.prototype[
|
|
379
|
+
}, T = (n, t) => {
|
|
380
|
+
p.prototype[n] = p.prototype[t];
|
|
299
381
|
};
|
|
300
382
|
$("dmShortID", "dm", "dmshortid");
|
|
301
383
|
$("model");
|
|
@@ -303,94 +385,27 @@ $("token");
|
|
|
303
385
|
$("entryID", "entry");
|
|
304
386
|
$("assetGroup");
|
|
305
387
|
$("assetID", "asset");
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
"fdk.auth",
|
|
311
|
-
{},
|
|
312
|
-
{
|
|
313
|
-
encode: JSON.stringify,
|
|
314
|
-
decode: JSON.parse
|
|
315
|
-
}
|
|
316
|
-
);
|
|
317
|
-
function P(e) {
|
|
318
|
-
var n;
|
|
319
|
-
let { dmShortID: t } = e;
|
|
320
|
-
if (t)
|
|
321
|
-
return (n = E.get()) == null ? void 0 : n[t];
|
|
322
|
-
}
|
|
323
|
-
function O(e) {
|
|
324
|
-
var n;
|
|
325
|
-
let { env: t } = e;
|
|
326
|
-
if (t)
|
|
327
|
-
return (n = E.get()) == null ? void 0 : n[t];
|
|
328
|
-
}
|
|
329
|
-
function ct(e) {
|
|
330
|
-
return O(e) || P(e);
|
|
331
|
-
}
|
|
332
|
-
function it(e) {
|
|
333
|
-
var t, n;
|
|
334
|
-
return !!((t = O(e)) != null && t.token) || !!((n = P(e)) != null && n.token);
|
|
335
|
-
}
|
|
336
|
-
function at(e) {
|
|
337
|
-
var t;
|
|
338
|
-
return !!((t = O(e)) != null && t.token);
|
|
339
|
-
}
|
|
340
|
-
function ut(e) {
|
|
341
|
-
var t;
|
|
342
|
-
return !!((t = P(e)) != null && t.token);
|
|
343
|
-
}
|
|
344
|
-
function lt(e) {
|
|
345
|
-
return i(this, null, function* () {
|
|
346
|
-
const t = yield D(e);
|
|
347
|
-
return E.setKey(e.dmShortID, { token: t.token }), t;
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
function dt(e) {
|
|
351
|
-
return i(this, null, function* () {
|
|
352
|
-
const t = yield I(e);
|
|
353
|
-
return E.setKey(e.env, { token: t.token }), t;
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
function yt(e) {
|
|
357
|
-
return i(this, null, function* () {
|
|
358
|
-
const t = yield q(e);
|
|
359
|
-
return E.setKey(e.dmShortID, {}), t;
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
function gt(e) {
|
|
363
|
-
return i(this, null, function* () {
|
|
364
|
-
const t = yield v(e);
|
|
365
|
-
return E.setKey(e.env, { token: t.token }), t;
|
|
366
|
-
});
|
|
367
|
-
}
|
|
388
|
+
T("assetgroup", "assetGroup");
|
|
389
|
+
T("entryList", "entries");
|
|
390
|
+
T("assetList", "assets");
|
|
391
|
+
const ot = (n) => new p({ env: n });
|
|
368
392
|
export {
|
|
369
393
|
st as act,
|
|
370
|
-
|
|
394
|
+
y as apiURL,
|
|
371
395
|
H as assetList,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
U as editEntry,
|
|
396
|
+
v as createEntry,
|
|
397
|
+
M as editEntry,
|
|
375
398
|
G as entryList,
|
|
376
|
-
|
|
377
|
-
|
|
399
|
+
g as expect,
|
|
400
|
+
l as fetcher,
|
|
378
401
|
F as getAsset,
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
D as loginPublic,
|
|
389
|
-
lt as loginPublicStored,
|
|
390
|
-
v as logoutEc,
|
|
391
|
-
gt as logoutEcStored,
|
|
392
|
-
q as logoutPublic,
|
|
393
|
-
yt as logoutPublicStored,
|
|
394
|
-
k as query,
|
|
395
|
-
rt as sdk
|
|
402
|
+
I as getEcAuthKey,
|
|
403
|
+
U as getEntry,
|
|
404
|
+
D as getPublicAuthKey,
|
|
405
|
+
J as loginEc,
|
|
406
|
+
z as loginPublic,
|
|
407
|
+
R as logoutEc,
|
|
408
|
+
N as logoutPublic,
|
|
409
|
+
b as query,
|
|
410
|
+
ot as sdk
|
|
396
411
|
};
|