ec.fdk 0.3.1 → 0.4.1

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.mjs CHANGED
@@ -1,52 +1,52 @@
1
- var K = Object.defineProperty, v = Object.defineProperties;
2
- var x = Object.getOwnPropertyDescriptors;
3
- var O = Object.getOwnPropertySymbols;
4
- var z = Object.prototype.hasOwnProperty, J = Object.prototype.propertyIsEnumerable;
5
- var j = (n, t, e) => t in n ? K(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, u = (n, t) => {
1
+ var z = Object.defineProperty, C = Object.defineProperties;
2
+ var J = Object.getOwnPropertyDescriptors;
3
+ var j = Object.getOwnPropertySymbols;
4
+ var N = Object.prototype.hasOwnProperty, F = Object.prototype.propertyIsEnumerable;
5
+ var S = (n, t, e) => t in n ? z(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, l = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
- z.call(t, e) && j(n, e, t[e]);
8
- if (O)
9
- for (var e of O(t))
10
- J.call(t, e) && j(n, e, t[e]);
7
+ N.call(t, e) && S(n, e, t[e]);
8
+ if (j)
9
+ for (var e of j(t))
10
+ F.call(t, e) && S(n, e, t[e]);
11
11
  return n;
12
- }, f = (n, t) => v(n, x(t));
13
- var a = (n, t, e) => new Promise((s, r) => {
14
- var c = (i) => {
12
+ }, y = (n, t) => C(n, J(t));
13
+ var o = (n, t, e) => new Promise((s, r) => {
14
+ var u = (a) => {
15
15
  try {
16
- h(e.next(i));
17
- } catch (l) {
18
- r(l);
16
+ d(e.next(a));
17
+ } catch (c) {
18
+ r(c);
19
19
  }
20
- }, o = (i) => {
20
+ }, i = (a) => {
21
21
  try {
22
- h(e.throw(i));
23
- } catch (l) {
24
- r(l);
22
+ d(e.throw(a));
23
+ } catch (c) {
24
+ r(c);
25
25
  }
26
- }, h = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(c, o);
27
- h((e = e.apply(n, t)).next());
26
+ }, d = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(u, i);
27
+ d((e = e.apply(n, t)).next());
28
28
  });
29
29
  function g(s) {
30
- return a(this, arguments, function* (n, t = {}, e = {}) {
31
- var h;
32
- const { token: r, rawRes: c } = t;
33
- r && (e.headers = f(u({}, e.headers || {}), {
30
+ return o(this, arguments, function* (n, t = {}, e = {}) {
31
+ var d;
32
+ const { token: r, rawRes: u } = t;
33
+ r && (e.headers = y(l({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${r}`
35
35
  }));
36
- const o = yield fetch(n, e);
37
- if (!o.ok) {
38
- if ((h = o.headers.get("content-type")) != null && h.includes("application/json")) {
39
- const i = yield o.json(), l = `${i.title}
40
- ${i.detail}
41
- ${i.verbose}`;
42
- throw new Error(l);
36
+ const i = yield fetch(n, e);
37
+ if (!i.ok) {
38
+ if ((d = i.headers.get("content-type")) != null && d.includes("application/json")) {
39
+ const a = yield i.json(), c = `${a.title}
40
+ ${a.detail}
41
+ ${a.verbose}`;
42
+ throw new Error(c);
43
43
  }
44
- throw new Error(`unexpected fetch error: ${o.statusText}`);
44
+ throw new Error(`unexpected fetch error: ${i.statusText}`);
45
45
  }
46
- return c ? o : yield o.json();
46
+ return u ? i : yield i.json();
47
47
  });
48
48
  }
49
- const S = {
49
+ const B = {
50
50
  datamanager: {
51
51
  live: "https://datamanager.entrecode.de/",
52
52
  stage: "https://datamanager.cachena.entrecode.de/"
@@ -61,10 +61,10 @@ const S = {
61
61
  }
62
62
  };
63
63
  function p(n, t = "stage", e = "datamanager") {
64
- const s = S[e];
64
+ const s = B[e];
65
65
  if (!s)
66
66
  throw new Error(
67
- `subdomain "${e}" not found. Try one of ${Object.keys(S).join(", ")}`
67
+ `subdomain "${e}" not found. Try one of ${Object.keys(B).join(", ")}`
68
68
  );
69
69
  const r = s[t];
70
70
  if (!r)
@@ -76,23 +76,23 @@ function p(n, t = "stage", e = "datamanager") {
76
76
  function w(n, t = !0) {
77
77
  return Object.entries(n).sort((e, s) => e[0].localeCompare(s[0])).map(([e, s]) => `${e}=${s}`).join("&");
78
78
  }
79
- function d(n) {
79
+ function h(n) {
80
80
  Object.entries(n).forEach(([t, e]) => {
81
81
  if (e === void 0)
82
82
  throw new Error(`expected ${t} to be set!`);
83
83
  });
84
84
  }
85
- const B = {
85
+ const D = {
86
86
  stage: "https://accounts.cachena.entrecode.de/",
87
87
  live: "https://accounts.entrecode.de/"
88
88
  };
89
- function N(n) {
90
- return a(this, null, function* () {
89
+ function R(n) {
90
+ return o(this, null, function* () {
91
91
  let { env: t, dmShortID: e, email: s, password: r } = n;
92
- d({ env: t, dmShortID: e, email: s, password: r });
93
- const c = p(`api/${e}/_auth/login?clientID=rest`, t);
92
+ h({ env: t, dmShortID: e, email: s, password: r });
93
+ const u = p(`api/${e}/_auth/login?clientID=rest`, t);
94
94
  return yield g(
95
- c,
95
+ u,
96
96
  {},
97
97
  {
98
98
  method: "POST",
@@ -104,11 +104,11 @@ function N(n) {
104
104
  );
105
105
  });
106
106
  }
107
- function C(n) {
108
- return a(this, null, function* () {
107
+ function v(n) {
108
+ return o(this, null, function* () {
109
109
  let { env: t, email: e, password: s } = n;
110
- d({ env: t, email: e, password: s });
111
- const r = `${B[t]}auth/login?clientID=rest`;
110
+ h({ env: t, email: e, password: s });
111
+ const r = `${D[t]}auth/login?clientID=rest`;
112
112
  return yield g(
113
113
  r,
114
114
  {},
@@ -122,10 +122,10 @@ function C(n) {
122
122
  );
123
123
  });
124
124
  }
125
- function R(n) {
126
- return a(this, null, function* () {
125
+ function U(n) {
126
+ return o(this, null, function* () {
127
127
  let { dmShortID: t, env: e, token: s } = n;
128
- d({ dmShortID: t, env: e, token: s });
128
+ h({ dmShortID: t, env: e, token: s });
129
129
  const r = p(
130
130
  `api/${t}/_auth/logout?clientID=rest&token=${s}`,
131
131
  e
@@ -139,11 +139,11 @@ function R(n) {
139
139
  );
140
140
  });
141
141
  }
142
- function F(n) {
143
- return a(this, null, function* () {
142
+ function M(n) {
143
+ return o(this, null, function* () {
144
144
  let { env: t, token: e } = n;
145
- d({ env: t, token: e });
146
- const s = `${B[t]}auth/logout?clientID=rest`;
145
+ h({ env: t, token: e });
146
+ const s = `${D[t]}auth/logout?clientID=rest`;
147
147
  return yield g(
148
148
  s,
149
149
  {
@@ -156,13 +156,13 @@ function F(n) {
156
156
  );
157
157
  });
158
158
  }
159
- function M({ dmShortID: n }) {
160
- return d({ dmShortID: n }), n;
159
+ function I({ dmShortID: n }) {
160
+ return h({ dmShortID: n }), n;
161
161
  }
162
- function U({ env: n }) {
163
- return d({ env: n }), n;
162
+ function V({ env: n }) {
163
+ return h({ env: n }), n;
164
164
  }
165
- let V = [
165
+ let G = [
166
166
  "created",
167
167
  "creator",
168
168
  "id",
@@ -178,43 +178,43 @@ let V = [
178
178
  "_modelTitleField",
179
179
  "_modified"
180
180
  ];
181
- function q(n) {
181
+ function x(n) {
182
182
  let t = {};
183
183
  for (let e in n)
184
- V.includes(e) || (t[e] = n[e]);
184
+ G.includes(e) || (t[e] = n[e]);
185
185
  return t;
186
186
  }
187
- function G(n) {
187
+ function H(n) {
188
188
  return JSON.parse(JSON.stringify(n));
189
189
  }
190
- function H(n) {
191
- return a(this, null, function* () {
190
+ function Q(n) {
191
+ return o(this, null, function* () {
192
192
  let { env: t, dmShortID: e } = n;
193
- d({ env: t, dmShortID: e });
193
+ h({ env: t, dmShortID: e });
194
194
  const s = p(`api/${e}`, t);
195
195
  return g(s, n);
196
196
  });
197
197
  }
198
- function I(n) {
199
- return a(this, null, function* () {
198
+ function W(n) {
199
+ return o(this, null, function* () {
200
200
  let { env: t, dmShortID: e, model: s, options: r = {} } = n;
201
- d({ env: t, dmShortID: e, model: s }), r = u({ size: 50, page: 1, _list: !0 }, r);
202
- const c = w(r), o = p(`api/${e}/${s}?${c}`, t), { count: h, total: i, _embedded: l } = yield g(o, n);
203
- let y = l ? l[`${e}:${s}`] : [];
204
- return y = Array.isArray(y) ? y : [y], { count: h, total: i, items: y };
201
+ h({ env: t, dmShortID: e, model: s }), r = l({ size: 50, page: 1, _list: !0 }, r);
202
+ const u = w(r), i = p(`api/${e}/${s}?${u}`, t), { count: d, total: a, _embedded: c } = yield g(i, n);
203
+ let f = c ? c[`${e}:${s}`] : [];
204
+ return f = Array.isArray(f) ? f : [f], { count: d, total: a, items: f };
205
205
  });
206
206
  }
207
- function Q({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
208
- d({ env: n, dmShortID: t, model: e, entryID: s });
209
- const c = w({ _id: s }), o = p(`api/${t}/${e}?${c}`, n);
210
- return g(o, { dmShortID: t, token: r });
207
+ function X({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
208
+ h({ env: n, dmShortID: t, model: e, entryID: s });
209
+ const u = w({ _id: s }), i = p(`api/${t}/${e}?${u}`, n);
210
+ return g(i, { dmShortID: t, token: r });
211
211
  }
212
- function W(c) {
213
- return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
214
- d({ env: n, dmShortID: t, model: e, value: s });
215
- const o = p(`api/${t}/${e}`, n);
212
+ function Y(u) {
213
+ return o(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
214
+ h({ env: n, dmShortID: t, model: e, value: s });
215
+ const i = p(`api/${t}/${e}`, n);
216
216
  return yield g(
217
- o,
217
+ i,
218
218
  { env: n, dmShortID: t, token: r },
219
219
  {
220
220
  method: "POST",
@@ -226,36 +226,43 @@ function W(c) {
226
226
  );
227
227
  });
228
228
  }
229
- function X(o) {
230
- return a(this, arguments, function* ({
229
+ function Z(d) {
230
+ return o(this, arguments, function* ({
231
231
  env: n,
232
232
  dmShortID: t,
233
233
  model: e,
234
234
  entryID: s,
235
235
  value: r,
236
- token: c
236
+ token: u,
237
+ safePut: i = !1
237
238
  }) {
238
- d({ env: n, dmShortID: t, model: e, entryID: s, value: r });
239
- const h = p(`api/${t}/${e}?_id=${s}`, n);
240
- return r = G(r), r = q(r), yield g(
241
- h,
242
- { token: c },
239
+ h({ env: n, dmShortID: t, model: e, entryID: s, value: r });
240
+ const a = {
241
+ "Content-Type": "application/json"
242
+ };
243
+ if (i) {
244
+ if (!("_modified" in r))
245
+ throw new Error("expected _modified to be set!");
246
+ a["If-Unmodified-Since"] = new Date(r._modified).toUTCString();
247
+ }
248
+ const c = p(`api/${t}/${e}?_id=${s}`, n);
249
+ return r = H(r), r = x(r), yield g(
250
+ c,
251
+ { token: u },
243
252
  {
244
253
  method: "PUT",
245
- body: JSON.stringify(r),
246
- headers: {
247
- "Content-Type": "application/json"
248
- }
254
+ headers: a,
255
+ body: JSON.stringify(r)
249
256
  }
250
257
  );
251
258
  });
252
259
  }
253
- function Y(c) {
254
- return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
255
- d({ env: n, dmShortID: t, model: e, entryID: s });
256
- const o = p(`api/${t}/${e}?_id=${s}`, n);
260
+ function tt(u) {
261
+ return o(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
262
+ h({ env: n, dmShortID: t, model: e, entryID: s });
263
+ const i = p(`api/${t}/${e}?_id=${s}`, n);
257
264
  yield g(
258
- o,
265
+ i,
259
266
  { token: r, rawRes: !0 },
260
267
  {
261
268
  method: "DELETE",
@@ -266,80 +273,84 @@ function Y(c) {
266
273
  );
267
274
  });
268
275
  }
269
- function Z(s) {
270
- return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
271
- var l, y, m, P, L;
272
- d({ env: n, dmShortID: t, model: e });
273
- const r = p(`api/schema/${t}/${e}`, n), c = yield g(r), o = (l = c == null ? void 0 : c.allOf) == null ? void 0 : l[1];
274
- if (typeof o.properties != "object")
276
+ function et(r) {
277
+ return o(this, arguments, function* ({ env: n, dmShortID: t, model: e, withMetadata: s }) {
278
+ var f, $, P, L, O;
279
+ h({ env: n, dmShortID: t, model: e });
280
+ const u = p(`api/schema/${t}/${e}`, n), i = yield g(u), d = (f = i == null ? void 0 : i.allOf) == null ? void 0 : f[1];
281
+ if (typeof d.properties != "object")
275
282
  throw new Error(
276
- `getSchema: ${r} returned unexpected format: ${JSON.stringify(c)}`
283
+ `getSchema: ${u} returned unexpected format: ${JSON.stringify(i)}`
277
284
  );
278
- const { properties: h } = o, i = q(h);
279
- for (let k in i) {
280
- let $ = i[k];
281
- if ($.required = o.required.includes(k), (y = i[k]) != null && y.oneOf && ((m = i[k]) == null || delete m.oneOf), (P = $.title) != null && P.includes("<") && ((L = $.title) != null && L.includes(">"))) {
282
- const E = $.title.split("<")[1].slice(0, -1), D = $.title.split("<")[0];
283
- $.type = D, E.includes(":") ? $.resource = E.split(":")[1] : $.resource = E;
285
+ const { properties: a } = d, c = x(a);
286
+ for (let k in c) {
287
+ let m = c[k];
288
+ if (m.required = d.required.includes(k), ($ = c[k]) != null && $.oneOf && ((P = c[k]) == null || delete P.oneOf), (L = m.title) != null && L.includes("<") && ((O = m.title) != null && O.includes(">"))) {
289
+ const E = m.title.split("<")[1].slice(0, -1), K = m.title.split("<")[0];
290
+ m.type = K, E.includes(":") ? m.resource = E.split(":")[1] : m.resource = E;
284
291
  } else
285
- ["asset", "entry", "assets", "entries"].includes($.title) ? ($.type = $.title, $.resource = null) : $.type = $.title;
286
- delete i[k].title;
292
+ ["asset", "entry", "assets", "entries"].includes(m.title) ? (m.type = m.title, m.resource = null) : m.type = m.title;
293
+ delete c[k].title;
287
294
  }
288
- return i;
295
+ if (s) {
296
+ const k = a._modelTitle.title, m = a._modelTitleField.title;
297
+ return { properties: c, meta: { modelTitleField: m, modelTitle: k } };
298
+ }
299
+ return c;
289
300
  });
290
301
  }
291
- function tt(c) {
292
- return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
293
- d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
294
- const o = w({ assetID: s }), h = p(`a/${t}/${e}?${o}`, n);
295
- return (yield g(h, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
302
+ function nt(u) {
303
+ return o(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
304
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
305
+ const i = w({ assetID: s }), d = p(`a/${t}/${e}?${i}`, n);
306
+ return (yield g(d, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
296
307
  });
297
308
  }
298
- function et(n) {
299
- return a(this, null, function* () {
300
- let { env: t, dmShortID: e, assetGroup: s, token: r, options: c = {} } = n;
301
- d({ env: t, dmShortID: e, assetGroup: s }), c = u({ size: 50, page: 1, _list: !0 }, c);
302
- const o = w(c), h = p(`a/${e}/${s}?${o}`, t), { count: i, total: l, _embedded: y } = yield g(h, { dmShortID: e, token: r });
303
- let m = y ? y["ec:dm-asset"] : [];
304
- return m = Array.isArray(m) ? m : [m], { count: i, total: l, items: m };
309
+ function st(n) {
310
+ return o(this, null, function* () {
311
+ let { env: t, dmShortID: e, assetGroup: s, token: r, options: u = {} } = n;
312
+ h({ env: t, dmShortID: e, assetGroup: s }), u = l({ size: 50, page: 1, _list: !0 }, u);
313
+ const i = w(u), d = p(`a/${e}/${s}?${i}`, t), { count: a, total: c, _embedded: f } = yield g(d, { dmShortID: e, token: r });
314
+ let $ = f ? f["ec:dm-asset"] : [];
315
+ return $ = Array.isArray($) ? $ : [$], { count: a, total: c, items: $ };
305
316
  });
306
317
  }
307
- function nt(h) {
308
- return a(this, arguments, function* ({
318
+ function rt(d) {
319
+ return o(this, arguments, function* ({
309
320
  env: n,
310
321
  dmShortID: t,
311
322
  assetGroup: e,
312
323
  token: s,
313
324
  file: r,
314
- name: c,
315
- options: o
325
+ name: u,
326
+ options: i
316
327
  }) {
317
- d({ env: n, dmShortID: t, assetGroup: e, file: r });
318
- const i = p(`a/${t}/${e}`, n), l = new FormData();
319
- return l.append("file", r, c), o && Object.keys(o).forEach((m) => {
320
- l.append(m, o[m]);
328
+ h({ env: n, dmShortID: t, assetGroup: e, file: r });
329
+ const a = p(`a/${t}/${e}`, n), c = new FormData();
330
+ return c.append("file", r, u), i && Object.keys(i).forEach(($) => {
331
+ c.append($, i[$]);
321
332
  }), (yield g(
322
- i,
333
+ a,
323
334
  { token: s },
324
335
  {
325
336
  method: "POST",
326
- body: l
337
+ body: c
327
338
  }
328
339
  ))._embedded["ec:dm-asset"];
329
340
  });
330
341
  }
331
- function st(c) {
332
- return a(this, arguments, function* ({
342
+ function it(u) {
343
+ return o(this, arguments, function* ({
333
344
  env: n,
334
345
  dmShortID: t,
335
346
  assetGroup: e,
336
347
  assetID: s,
337
348
  token: r
338
349
  }) {
339
- d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
340
- const o = p(`a/${t}/${e}/${s}`, n);
350
+ h({ env: n, dmShortID: t, assetGroup: e, assetID: s });
351
+ const i = p(`a/${t}/${e}/${s}`, n);
341
352
  yield g(
342
- o,
353
+ i,
343
354
  { token: r, rawRes: !0 },
344
355
  {
345
356
  method: "DELETE"
@@ -347,100 +358,100 @@ function st(c) {
347
358
  );
348
359
  });
349
360
  }
350
- function rt(n) {
351
- return a(this, null, function* () {
361
+ function ot(n) {
362
+ return o(this, null, function* () {
352
363
  let { env: t, dmID: e, token: s } = n;
353
- d({ env: t, dmID: e });
364
+ h({ env: t, dmID: e });
354
365
  const r = p(`?dataManagerID=${e}`, t);
355
366
  return g(r, { token: s });
356
367
  });
357
368
  }
358
- function ot(n) {
359
- return a(this, null, function* () {
369
+ function at(n) {
370
+ return o(this, null, function* () {
360
371
  let { env: t, options: e = {} } = n;
361
- d({ env: t }), e = u({ size: 25, page: 1, _list: !0 }, e);
362
- const s = w(e), r = p(`?${s}`, t), { count: c, total: o, _embedded: h } = yield g(r, n);
363
- let i = h ? h["ec:datamanager"] : [];
364
- return i = Array.isArray(i) ? i : [i], { count: c, total: o, items: i };
372
+ h({ env: t }), e = l({ size: 25, page: 1, _list: !0 }, e);
373
+ const s = w(e), r = p(`?${s}`, t), { count: u, total: i, _embedded: d } = yield g(r, n);
374
+ let a = d ? d["ec:datamanager"] : [];
375
+ return a = Array.isArray(a) ? a : [a], { count: u, total: i, items: a };
365
376
  });
366
377
  }
367
- function it(n) {
368
- return a(this, null, function* () {
378
+ function ct(n) {
379
+ return o(this, null, function* () {
369
380
  let { env: t, dmID: e, options: s = {} } = n;
370
- d({ env: t, dmID: e }), s = u({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
371
- const r = w(s), c = p(`model?${r}`, t), { count: o, total: h, _embedded: i } = yield g(c, n);
372
- let l = i ? i["ec:model"] : [];
373
- return l = Array.isArray(l) ? l : [l], { count: o, total: h, items: l };
381
+ h({ env: t, dmID: e }), s = l({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
382
+ const r = w(s), u = p(`model?${r}`, t), { count: i, total: d, _embedded: a } = yield g(u, n);
383
+ let c = a ? a["ec:model"] : [];
384
+ return c = Array.isArray(c) ? c : [c], { count: i, total: d, items: c };
374
385
  });
375
386
  }
376
- function at(n) {
377
- return a(this, null, function* () {
387
+ function ut(n) {
388
+ return o(this, null, function* () {
378
389
  let { env: t, resource: e, options: s = {}, subdomain: r = "datamanager" } = n;
379
- d({ env: t, subdomain: r, resource: e }), s = u({ size: 25, page: 1, _list: !0 }, s);
380
- const c = w(s), o = p(`${e}?${c}`, t, r), { count: h, total: i, _embedded: l } = yield g(o, n);
381
- let y = l ? l[Object.keys(l)[0]] : [];
382
- return y = Array.isArray(y) ? y : [y], { count: h, total: i, items: y };
390
+ h({ env: t, subdomain: r, resource: e }), s = l({ size: 25, page: 1, _list: !0 }, s);
391
+ const u = w(s), i = p(`${e}?${u}`, t, r), { count: d, total: a, _embedded: c } = yield g(i, n);
392
+ let f = c ? c[Object.keys(c)[0]] : [];
393
+ return f = Array.isArray(f) ? f : [f], { count: d, total: a, items: f };
383
394
  });
384
395
  }
385
- function ct(e) {
386
- return a(this, arguments, function* (n, t = {}) {
387
- let { env: s, route: r, options: c = {}, subdomain: o = "datamanager" } = n;
388
- d({ env: s, subdomain: o, route: r }), c = u({}, c);
389
- const h = w(c), i = p(`${r}?${h}`, s, o);
390
- return g(i, n, t);
396
+ function lt(e) {
397
+ return o(this, arguments, function* (n, t = {}) {
398
+ let { env: s, route: r, options: u = {}, subdomain: i = "datamanager" } = n;
399
+ h({ env: s, subdomain: i, route: r }), u = l({}, u);
400
+ const d = w(u), a = p(`${r}?${d}`, s, i);
401
+ return g(a, n, t);
391
402
  });
392
403
  }
393
404
  const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
394
405
  __proto__: null,
395
- assetList: et,
396
- createAsset: nt,
397
- createEntry: W,
398
- deleteAsset: st,
399
- deleteEntry: Y,
400
- dmList: ot,
401
- editEntry: X,
402
- entryList: I,
403
- getAsset: tt,
404
- getDatamanager: rt,
405
- getEcAuthKey: U,
406
- getEntry: Q,
407
- getPublicAuthKey: M,
408
- getSchema: Z,
409
- loginEc: C,
410
- loginPublic: N,
411
- logoutEc: F,
412
- logoutPublic: R,
413
- modelList: it,
414
- publicApi: H,
415
- raw: ct,
416
- resourceList: at
406
+ assetList: st,
407
+ createAsset: rt,
408
+ createEntry: Y,
409
+ deleteAsset: it,
410
+ deleteEntry: tt,
411
+ dmList: at,
412
+ editEntry: Z,
413
+ entryList: W,
414
+ getAsset: nt,
415
+ getDatamanager: ot,
416
+ getEcAuthKey: V,
417
+ getEntry: X,
418
+ getPublicAuthKey: I,
419
+ getSchema: et,
420
+ loginEc: v,
421
+ loginPublic: R,
422
+ logoutEc: M,
423
+ logoutPublic: U,
424
+ modelList: ct,
425
+ publicApi: Q,
426
+ raw: lt,
427
+ resourceList: ut
417
428
  }, Symbol.toStringTag, { value: "Module" })), {
418
- entryList: ut,
419
- getEntry: lt,
420
- getAsset: ht,
421
- assetList: dt,
422
- createAsset: gt,
423
- deleteAsset: yt,
424
- createEntry: ft,
425
- editEntry: pt,
429
+ entryList: dt,
430
+ getEntry: ht,
431
+ getAsset: gt,
432
+ assetList: ft,
433
+ createAsset: yt,
434
+ deleteAsset: pt,
435
+ createEntry: mt,
436
+ editEntry: q,
426
437
  deleteEntry: $t,
427
- getSchema: mt,
428
- loginPublic: wt,
429
- loginEc: kt,
430
- logoutEc: At,
431
- logoutPublic: Et,
438
+ getSchema: wt,
439
+ loginPublic: kt,
440
+ loginEc: At,
441
+ logoutEc: Et,
442
+ logoutPublic: bt,
432
443
  getEcAuthKey: b,
433
444
  getPublicAuthKey: T,
434
- dmList: bt,
435
- modelList: Tt,
436
- publicApi: _t,
437
- getDatamanager: Pt,
438
- resourceList: Lt,
439
- raw: Ot
445
+ dmList: Tt,
446
+ modelList: _t,
447
+ publicApi: Pt,
448
+ getDatamanager: Lt,
449
+ resourceList: Ot,
450
+ raw: jt
440
451
  } = A;
441
- function St(n) {
452
+ function Bt(n) {
442
453
  const { action: t } = n;
443
- if (d({ action: t }), !A[t])
454
+ if (h({ action: t }), !A[t])
444
455
  throw new Error(
445
456
  `"${t}" does not exist! try one of ${Object.keys(A).join(
446
457
  ", "
@@ -453,7 +464,7 @@ class _ {
453
464
  this.config = t;
454
465
  }
455
466
  set(t) {
456
- return new _(u(u({}, this.config), t));
467
+ return new _(l(l({}, this.config), t));
457
468
  }
458
469
  /**
459
470
  * Loads entry list. Expects `dmShortID` / `model` to be set.
@@ -469,13 +480,13 @@ class _ {
469
480
  * const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
470
481
  */
471
482
  entries() {
472
- return a(this, arguments, function* (t = {}) {
483
+ return o(this, arguments, function* (t = {}) {
473
484
  const e = yield this.getBestToken();
474
- return ut(f(u({}, this.config), { options: t, token: e }));
485
+ return dt(y(l({}, this.config), { options: t, token: e }));
475
486
  });
476
487
  }
477
488
  entryList(t) {
478
- return a(this, null, function* () {
489
+ return o(this, null, function* () {
479
490
  return this.entries(t);
480
491
  });
481
492
  }
@@ -484,14 +495,34 @@ class _ {
484
495
  * If the model is not public, you also need to provide a `token`.
485
496
  *
486
497
  * @param {string} entryID
487
- * @returns {Promise<EntryResource & Record<string, any>>}
498
+ * @returns {Promise<EntryResource>}
488
499
  * @example
489
500
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
490
501
  */
491
502
  getEntry(t) {
492
- return a(this, null, function* () {
503
+ return o(this, null, function* () {
493
504
  const e = yield this.getBestToken();
494
- return lt(f(u({}, this.config), { entryID: t, token: e }));
505
+ return ht(y(l({}, this.config), { entryID: t, token: e }));
506
+ });
507
+ }
508
+ /**
509
+ * Edits an entry with safe put. Expects `dmShortID` / `model` to be set.
510
+ * Expects a `_modified` field in the value. Will only update if the entry has not been changed since.
511
+ * If model PUT is not public, you also need to provide a `token`.
512
+ *
513
+ * @param {string} entryID id of entry to edit
514
+ * @param {object} value values to set. undefined fields are ignored
515
+ * @returns {Promise<EntryResource>}
516
+ * @example
517
+ * const entry = await sdk("stage")
518
+ * .dm("83cc6374")
519
+ * .model("muffin")
520
+ * .editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
521
+ */
522
+ editEntrySafe(t, e) {
523
+ return o(this, null, function* () {
524
+ const s = yield this.getBestToken();
525
+ return q(y(l({}, this.config), { entryID: t, token: s, value: e, safePut: !0 }));
495
526
  });
496
527
  }
497
528
  /**
@@ -503,8 +534,8 @@ class _ {
503
534
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getSchema()
504
535
  */
505
536
  getSchema() {
506
- return a(this, null, function* () {
507
- return mt(this.config);
537
+ return o(this, null, function* () {
538
+ return wt(this.config);
508
539
  });
509
540
  }
510
541
  /**
@@ -521,13 +552,13 @@ class _ {
521
552
  * const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
522
553
  */
523
554
  assets(t) {
524
- return a(this, null, function* () {
555
+ return o(this, null, function* () {
525
556
  const e = yield this.getBestToken();
526
- return dt(f(u({}, this.config), { options: t, token: e }));
557
+ return ft(y(l({}, this.config), { options: t, token: e }));
527
558
  });
528
559
  }
529
560
  assetList(t) {
530
- return a(this, null, function* () {
561
+ return o(this, null, function* () {
531
562
  return this.assets(t);
532
563
  });
533
564
  }
@@ -553,9 +584,9 @@ class _ {
553
584
  * .createAsset({ file, name: "venndiagram.png" });
554
585
  */
555
586
  createAsset() {
556
- return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
587
+ return o(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
557
588
  const r = yield this.getBestToken();
558
- return gt(f(u({}, this.config), { file: t, name: e, options: s, token: r }));
589
+ return yt(y(l({}, this.config), { file: t, name: e, options: s, token: r }));
559
590
  });
560
591
  }
561
592
  /**
@@ -568,9 +599,9 @@ class _ {
568
599
  * await ecadmin.assetgroup("test").deleteAsset('xxxx');
569
600
  */
570
601
  deleteAsset(t) {
571
- return a(this, null, function* () {
602
+ return o(this, null, function* () {
572
603
  const e = yield this.getBestToken();
573
- return yt(f(u({}, this.config), { token: e, assetID: t }));
604
+ return pt(y(l({}, this.config), { token: e, assetID: t }));
574
605
  });
575
606
  }
576
607
  /**
@@ -583,9 +614,9 @@ class _ {
583
614
  * const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
584
615
  */
585
616
  getAsset(t) {
586
- return a(this, null, function* () {
617
+ return o(this, null, function* () {
587
618
  const e = yield this.getBestToken();
588
- return ht(f(u({}, this.config), { assetID: t, token: e }));
619
+ return gt(y(l({}, this.config), { assetID: t, token: e }));
589
620
  });
590
621
  }
591
622
  /**
@@ -598,9 +629,9 @@ class _ {
598
629
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
599
630
  */
600
631
  createEntry(t) {
601
- return a(this, null, function* () {
632
+ return o(this, null, function* () {
602
633
  const e = yield this.getBestToken();
603
- return ft(f(u({}, this.config), { token: e, value: t }));
634
+ return mt(y(l({}, this.config), { token: e, value: t }));
604
635
  });
605
636
  }
606
637
  /**
@@ -614,9 +645,9 @@ class _ {
614
645
  * const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
615
646
  */
616
647
  editEntry(t, e) {
617
- return a(this, null, function* () {
648
+ return o(this, null, function* () {
618
649
  const s = yield this.getBestToken();
619
- return pt(f(u({}, this.config), { entryID: t, token: s, value: e }));
650
+ return q(y(l({}, this.config), { entryID: t, token: s, value: e }));
620
651
  });
621
652
  }
622
653
  /**
@@ -629,9 +660,9 @@ class _ {
629
660
  * await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
630
661
  */
631
662
  deleteEntry(t) {
632
- return a(this, null, function* () {
663
+ return o(this, null, function* () {
633
664
  const e = yield this.getBestToken();
634
- return $t(f(u({}, this.config), { token: e, entryID: t }));
665
+ return $t(y(l({}, this.config), { token: e, entryID: t }));
635
666
  });
636
667
  }
637
668
  /**
@@ -644,9 +675,9 @@ class _ {
644
675
  * const res = await sdk("stage").resource("template").resourceList()
645
676
  */
646
677
  resourceList(t) {
647
- return a(this, null, function* () {
678
+ return o(this, null, function* () {
648
679
  const e = yield this.getBestToken();
649
- return Lt(f(u({}, this.config), { options: t, token: e }));
680
+ return Ot(y(l({}, this.config), { options: t, token: e }));
650
681
  });
651
682
  }
652
683
  /**
@@ -661,9 +692,9 @@ class _ {
661
692
  * const res = await sdk("stage").route("stats").raw()
662
693
  */
663
694
  raw(t, e) {
664
- return a(this, null, function* () {
695
+ return o(this, null, function* () {
665
696
  const s = yield this.getBestToken();
666
- return Ot(f(u({}, this.config), { options: t, token: s }), e);
697
+ return jt(y(l({}, this.config), { options: t, token: s }), e);
667
698
  });
668
699
  }
669
700
  // TODO: rename authAdapter -> storageAdapter
@@ -693,24 +724,24 @@ class _ {
693
724
  return e(t);
694
725
  }
695
726
  loginEc(t) {
696
- return kt(u(u({}, this.config), t)).then(
727
+ return At(l(l({}, this.config), t)).then(
697
728
  this.setAuth(b(this.config))
698
729
  );
699
730
  }
700
731
  loginPublic(t) {
701
- return wt(u(u({}, this.config), t)).then(
732
+ return kt(l(l({}, this.config), t)).then(
702
733
  this.setAuth(T(this.config))
703
734
  );
704
735
  }
705
736
  logoutPublic() {
706
737
  const t = this.getPublicToken();
707
- return console.log("token", t), Et(f(u({}, this.config), { token: t })).then(
738
+ return console.log("token", t), bt(y(l({}, this.config), { token: t })).then(
708
739
  this.unsetAuth(T(this.config))
709
740
  );
710
741
  }
711
742
  logoutEc() {
712
743
  const t = this.getEcToken();
713
- return console.log("token", t), At(f(u({}, this.config), { token: t })).then(
744
+ return console.log("token", t), Et(y(l({}, this.config), { token: t })).then(
714
745
  this.unsetAuth(b(this.config))
715
746
  );
716
747
  }
@@ -821,16 +852,16 @@ class _ {
821
852
  * @returns any
822
853
  */
823
854
  publicApi() {
824
- return _t(this.config);
855
+ return Pt(this.config);
825
856
  }
826
857
  /**
827
858
  * Loads a DatamanagerResource by its long id. Requires token.
828
859
  * @returns any
829
860
  */
830
861
  getDatamanager(t) {
831
- return a(this, null, function* () {
862
+ return o(this, null, function* () {
832
863
  const e = yield this.getBestToken();
833
- return Pt(f(u({}, this.config), { dmID: t, token: e }));
864
+ return Lt(y(l({}, this.config), { dmID: t, token: e }));
834
865
  });
835
866
  }
836
867
  /**
@@ -842,9 +873,9 @@ class _ {
842
873
  * const dms = await sdk("stage").dmList()
843
874
  */
844
875
  dmList() {
845
- return a(this, arguments, function* (t = {}) {
876
+ return o(this, arguments, function* (t = {}) {
846
877
  const e = yield this.getBestToken();
847
- return bt(f(u({}, this.config), { options: t, token: e }));
878
+ return Tt(y(l({}, this.config), { options: t, token: e }));
848
879
  });
849
880
  }
850
881
  /**
@@ -856,41 +887,41 @@ class _ {
856
887
  * const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
857
888
  */
858
889
  modelList() {
859
- return a(this, arguments, function* (t = {}) {
890
+ return o(this, arguments, function* (t = {}) {
860
891
  const e = yield this.getBestToken();
861
- return Tt(f(u({}, this.config), { options: t, token: e }));
892
+ return _t(y(l({}, this.config), { options: t, token: e }));
862
893
  });
863
894
  }
864
895
  }
865
- const Bt = (n) => new _({ env: n });
896
+ const qt = (n) => new _({ env: n });
866
897
  export {
867
898
  _ as Sdk,
868
- St as act,
899
+ Bt as act,
869
900
  p as apiURL,
870
- et as assetList,
871
- nt as createAsset,
872
- W as createEntry,
873
- st as deleteAsset,
874
- Y as deleteEntry,
875
- ot as dmList,
876
- X as editEntry,
877
- I as entryList,
878
- d as expect,
901
+ st as assetList,
902
+ rt as createAsset,
903
+ Y as createEntry,
904
+ it as deleteAsset,
905
+ tt as deleteEntry,
906
+ at as dmList,
907
+ Z as editEntry,
908
+ W as entryList,
909
+ h as expect,
879
910
  g as fetcher,
880
- tt as getAsset,
881
- rt as getDatamanager,
882
- U as getEcAuthKey,
883
- Q as getEntry,
884
- M as getPublicAuthKey,
885
- Z as getSchema,
886
- C as loginEc,
887
- N as loginPublic,
888
- F as logoutEc,
889
- R as logoutPublic,
890
- it as modelList,
891
- H as publicApi,
911
+ nt as getAsset,
912
+ ot as getDatamanager,
913
+ V as getEcAuthKey,
914
+ X as getEntry,
915
+ I as getPublicAuthKey,
916
+ et as getSchema,
917
+ v as loginEc,
918
+ R as loginPublic,
919
+ M as logoutEc,
920
+ U as logoutPublic,
921
+ ct as modelList,
922
+ Q as publicApi,
892
923
  w as query,
893
- ct as raw,
894
- at as resourceList,
895
- Bt as sdk
924
+ lt as raw,
925
+ ut as resourceList,
926
+ qt as sdk
896
927
  };