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