@ztimson/momentum 0.17.0 → 0.19.0

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/momentum.mjs CHANGED
@@ -1,8 +1,8 @@
1
- var dt = Object.defineProperty;
2
- var pt = (i, e, t) => e in i ? dt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var a = (i, e, t) => (pt(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- var ft = Object.defineProperty, mt = (i, e, t) => e in i ? ft(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (mt(i, typeof e != "symbol" ? e + "" : e, t), t);
5
- function Et(i, e = !1) {
1
+ var ut = Object.defineProperty;
2
+ var at = (i, e, t) => e in i ? ut(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var a = (i, e, t) => (at(i, typeof e != "symbol" ? e + "" : e, t), t);
4
+ var ct = Object.defineProperty, ht = (i, e, t) => e in i ? ct(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (ht(i, typeof e != "symbol" ? e + "" : e, t), t);
5
+ function lt(i, e = !1) {
6
6
  if (i == null)
7
7
  throw new Error("Cannot clean a NULL value");
8
8
  return Array.isArray(i) ? i = i.filter((t) => t != null) : Object.entries(i).forEach(([t, r]) => {
@@ -11,13 +11,13 @@ function Et(i, e = !1) {
11
11
  }
12
12
  function X(i, e) {
13
13
  const t = typeof i, r = typeof e;
14
- return t != "object" || i == null || r != "object" || e == null ? t == "function" && r == "function" ? i.toString() == e.toString() : i === e : Object.keys(i).length != Object.keys(e).length ? !1 : Object.keys(i).every((s) => X(i[s], e[s]));
14
+ return t != "object" || i == null || r != "object" || e == null ? t == "function" && r == "function" ? i.toString() == e.toString() : i === e : Object.keys(i).length != Object.keys(e).length ? !1 : Object.keys(i).every((n) => X(i[n], e[n]));
15
15
  }
16
- function yt(i, e) {
16
+ function Z(i, e) {
17
17
  const t = document.createElement("a");
18
18
  t.href = i, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
19
19
  }
20
- class d {
20
+ class p {
21
21
  constructor() {
22
22
  h(this, "listeners", {});
23
23
  }
@@ -26,17 +26,17 @@ class d {
26
26
  }
27
27
  static off(e, t) {
28
28
  const r = e.toString();
29
- this.listeners[r] = (this.listeners[r] || []).filter((s) => s === t);
29
+ this.listeners[r] = (this.listeners[r] || []).filter((n) => n === t);
30
30
  }
31
31
  static on(e, t) {
32
32
  var r;
33
- const s = e.toString();
34
- return this.listeners[s] || (this.listeners[s] = []), (r = this.listeners[s]) == null || r.push(t), () => this.off(e, t);
33
+ const n = e.toString();
34
+ return this.listeners[n] || (this.listeners[n] = []), (r = this.listeners[n]) == null || r.push(t), () => this.off(e, t);
35
35
  }
36
36
  static once(e, t) {
37
37
  return new Promise((r) => {
38
- const s = this.on(e, (...n) => {
39
- r(n.length == 1 ? n[0] : n), t && t(...n), s();
38
+ const n = this.on(e, (...s) => {
39
+ r(s.length == 1 ? s[0] : s), t && t(...s), n();
40
40
  });
41
41
  });
42
42
  }
@@ -52,61 +52,14 @@ class d {
52
52
  }
53
53
  once(e, t) {
54
54
  return new Promise((r) => {
55
- const s = this.on(e, (...n) => {
56
- r(n.length == 1 ? n[0] : n), t && t(...n), s();
55
+ const n = this.on(e, (...s) => {
56
+ r(s.length == 1 ? s[0] : s), t && t(...s), n();
57
57
  });
58
58
  });
59
59
  }
60
60
  }
61
- h(d, "listeners", {});
62
- const B = class b {
63
- constructor(e = {}) {
64
- h(this, "interceptors", {}), h(this, "headers", {}), this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => b.addInterceptor(t));
65
- }
66
- static addInterceptor(e) {
67
- const t = Object.keys(b.interceptors).length.toString();
68
- return b.interceptors[t] = e, () => {
69
- b.interceptors[t] = null;
70
- };
71
- }
72
- addInterceptor(e) {
73
- const t = Object.keys(this.interceptors).length.toString();
74
- return this.interceptors[t] = e, () => {
75
- this.interceptors[t] = null;
76
- };
77
- }
78
- async request(e = {}) {
79
- var t, r;
80
- if (!this.opts.url && !e.url)
81
- throw new Error("URL needs to be set");
82
- const s = ((t = e.url) != null && t.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1"), n = Et({
83
- "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
84
- ...b.headers,
85
- ...this.headers,
86
- ...e.headers
87
- });
88
- return fetch(s, {
89
- headers: n,
90
- method: e.method || (e.body ? "POST" : "GET"),
91
- body: (r = n["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
92
- }).then(async (o) => {
93
- var u, c;
94
- for (let f of [...Object.values(b.interceptors), ...Object.values(this.interceptors)])
95
- await new Promise((w) => f(o, () => w()));
96
- if (!o.ok)
97
- throw new Error(o.statusText);
98
- return !e.skipConverting && (u = o.headers.get("Content-Type")) != null && u.startsWith("application/json") ? await o.json() : !e.skipConverting && (c = o.headers.get("Content-Type")) != null && c.startsWith("text/plain") ? await o.text() : o;
99
- });
100
- }
101
- };
102
- h(B, "interceptors", {}), h(B, "headers", {});
103
- let Z = B;
104
- Z.addInterceptor((i, e) => {
105
- if (i.status == 200)
106
- return e();
107
- throw i.status == 400 ? new tt(i.statusText) : i.status == 401 ? new et(i.statusText) : i.status == 403 ? new rt(i.statusText) : i.status == 404 ? new it(i.statusText) : i.status == 500 ? new st(i.statusText) : new v(i.statusText, i.status);
108
- });
109
- class v extends Error {
61
+ h(p, "listeners", {});
62
+ class L extends Error {
110
63
  constructor(e, t) {
111
64
  super(e), h(this, "_code"), t != null && (this._code = t);
112
65
  }
@@ -131,8 +84,8 @@ class v extends Error {
131
84
  return this.message || super.toString();
132
85
  }
133
86
  }
134
- h(v, "code", 500);
135
- class tt extends v {
87
+ h(L, "code", 500);
88
+ class dt extends L {
136
89
  constructor(e = "Bad Request") {
137
90
  super(e);
138
91
  }
@@ -140,8 +93,8 @@ class tt extends v {
140
93
  return e.constructor.code == this.code;
141
94
  }
142
95
  }
143
- h(tt, "code", 400);
144
- class et extends v {
96
+ h(dt, "code", 400);
97
+ class pt extends L {
145
98
  constructor(e = "Unauthorized") {
146
99
  super(e);
147
100
  }
@@ -149,8 +102,8 @@ class et extends v {
149
102
  return e.constructor.code == this.code;
150
103
  }
151
104
  }
152
- h(et, "code", 401);
153
- class rt extends v {
105
+ h(pt, "code", 401);
106
+ class ft extends L {
154
107
  constructor(e = "Forbidden") {
155
108
  super(e);
156
109
  }
@@ -158,8 +111,8 @@ class rt extends v {
158
111
  return e.constructor.code == this.code;
159
112
  }
160
113
  }
161
- h(rt, "code", 403);
162
- class it extends v {
114
+ h(ft, "code", 403);
115
+ class mt extends L {
163
116
  constructor(e = "Not Found") {
164
117
  super(e);
165
118
  }
@@ -167,8 +120,8 @@ class it extends v {
167
120
  return e.constructor.code == this.code;
168
121
  }
169
122
  }
170
- h(it, "code", 404);
171
- class st extends v {
123
+ h(mt, "code", 404);
124
+ class Et extends L {
172
125
  constructor(e = "Internal Server Error") {
173
126
  super(e);
174
127
  }
@@ -176,7 +129,7 @@ class st extends v {
176
129
  return e.constructor.code == this.code;
177
130
  }
178
131
  }
179
- h(st, "code", 500);
132
+ h(Et, "code", 500);
180
133
  const O = {
181
134
  CLEAR: "\x1B[0m",
182
135
  BRIGHT: "\x1B[1m",
@@ -185,7 +138,7 @@ const O = {
185
138
  BLINK: "\x1B[5m",
186
139
  REVERSE: "\x1B[7m",
187
140
  HIDDEN: "\x1B[8m"
188
- }, $ = {
141
+ }, R = {
189
142
  BLACK: "\x1B[30m",
190
143
  RED: "\x1B[31m",
191
144
  GREEN: "\x1B[32m",
@@ -203,17 +156,17 @@ const O = {
203
156
  LIGHT_CYAN: "\x1B[96m",
204
157
  WHITE: "\x1B[97m"
205
158
  };
206
- var L = /* @__PURE__ */ ((i) => (i[i.ERROR = 0] = "ERROR", i[i.WARN = 1] = "WARN", i[i.INFO = 2] = "INFO", i[i.LOG = 3] = "LOG", i[i.DEBUG = 4] = "DEBUG", i))(L || {});
207
- const gt = class m extends d {
159
+ var S = /* @__PURE__ */ ((i) => (i[i.ERROR = 0] = "ERROR", i[i.WARN = 1] = "WARN", i[i.INFO = 2] = "INFO", i[i.LOG = 3] = "LOG", i[i.DEBUG = 4] = "DEBUG", i))(S || {});
160
+ const yt = class m extends p {
208
161
  constructor(e) {
209
162
  super(), this.namespace = e;
210
163
  }
211
- pad(e, t, r, s = !1) {
212
- const n = e.toString(), o = t - n.length;
164
+ pad(e, t, r, n = !1) {
165
+ const s = e.toString(), o = t - s.length;
213
166
  if (o <= 0)
214
- return n;
167
+ return s;
215
168
  const u = Array(~~(o / r.length)).fill(r).join("");
216
- return s ? n + u : u + n;
169
+ return n ? s + u : u + s;
217
170
  }
218
171
  format(...e) {
219
172
  const t = /* @__PURE__ */ new Date();
@@ -223,7 +176,7 @@ const gt = class m extends d {
223
176
  if (m.LOG_LEVEL < 4)
224
177
  return;
225
178
  const t = this.format(...e);
226
- m.emit(4, t), console.debug($.LIGHT_GREY + t + O.CLEAR);
179
+ m.emit(4, t), console.debug(R.LIGHT_GREY + t + O.CLEAR);
227
180
  }
228
181
  log(...e) {
229
182
  if (m.LOG_LEVEL < 3)
@@ -235,28 +188,28 @@ const gt = class m extends d {
235
188
  if (m.LOG_LEVEL < 2)
236
189
  return;
237
190
  const t = this.format(...e);
238
- m.emit(2, t), console.info($.BLUE + t + O.CLEAR);
191
+ m.emit(2, t), console.info(R.BLUE + t + O.CLEAR);
239
192
  }
240
193
  warn(...e) {
241
194
  if (m.LOG_LEVEL < 1)
242
195
  return;
243
196
  const t = this.format(...e);
244
- m.emit(1, t), console.warn($.YELLOW + t + O.CLEAR);
197
+ m.emit(1, t), console.warn(R.YELLOW + t + O.CLEAR);
245
198
  }
246
199
  error(...e) {
247
200
  if (m.LOG_LEVEL < 0)
248
201
  return;
249
202
  const t = this.format(...e);
250
- m.emit(0, t), console.error($.RED + t + O.CLEAR);
203
+ m.emit(0, t), console.error(R.RED + t + O.CLEAR);
251
204
  }
252
205
  };
253
- h(gt, "LOG_LEVEL", 4);
206
+ h(yt, "LOG_LEVEL", 4);
254
207
  class bt extends Promise {
255
208
  constructor(e) {
256
209
  super((t, r) => e(
257
- (s) => t(s),
258
- (s) => r(s),
259
- (s) => this.progress = s
210
+ (n) => t(n),
211
+ (n) => r(n),
212
+ (n) => this.progress = n
260
213
  )), h(this, "listeners", []), h(this, "_progress", 0);
261
214
  }
262
215
  get progress() {
@@ -269,11 +222,57 @@ class bt extends Promise {
269
222
  return this.listeners.push(e), this;
270
223
  }
271
224
  }
272
- class p extends Z {
225
+ const B = class v {
226
+ constructor(e = {}) {
227
+ h(this, "interceptors", {}), h(this, "headers", {}), this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => v.addInterceptor(t));
228
+ }
229
+ static addInterceptor(e) {
230
+ const t = Object.keys(v.interceptors).length.toString();
231
+ return v.interceptors[t] = e, () => {
232
+ v.interceptors[t] = null;
233
+ };
234
+ }
235
+ addInterceptor(e) {
236
+ const t = Object.keys(this.interceptors).length.toString();
237
+ return this.interceptors[t] = e, () => {
238
+ this.interceptors[t] = null;
239
+ };
240
+ }
241
+ async request(e = {}) {
242
+ var t, r;
243
+ if (!this.opts.url && !e.url)
244
+ throw new Error("URL needs to be set");
245
+ const n = ((t = e.url) != null && t.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1"), s = lt({
246
+ "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
247
+ ...v.headers,
248
+ ...this.headers,
249
+ ...e.headers
250
+ });
251
+ return fetch(n, {
252
+ headers: s,
253
+ method: e.method || (e.body ? "POST" : "GET"),
254
+ body: (r = s["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
255
+ }).then(async (o) => {
256
+ for (let l of [...Object.values(v.interceptors), ...Object.values(this.interceptors)])
257
+ await new Promise((y) => l(o, () => y()));
258
+ const u = await (async () => {
259
+ var l, y;
260
+ return !e.skipConverting && (l = o.headers.get("Content-Type")) != null && l.startsWith("application/json") ? await o.json() : !e.skipConverting && (y = o.headers.get("Content-Type")) != null && y.startsWith("text/plain") ? await o.text() : o;
261
+ })();
262
+ if (o.ok)
263
+ return u;
264
+ const c = o.statusText || (typeof u == "string" ? u : null);
265
+ throw c ? new Error(c) : u;
266
+ });
267
+ }
268
+ };
269
+ h(B, "interceptors", {}), h(B, "headers", {});
270
+ let gt = B;
271
+ class f extends gt {
273
272
  constructor(t = location.origin, r = {}) {
274
273
  r.url = t;
275
274
  super(r);
276
- a(this, "emitter", new d());
275
+ a(this, "emitter", new p());
277
276
  a(this, "_token", null);
278
277
  a(this, "emit", this.emitter.emit.bind(this.emitter));
279
278
  a(this, "off", this.emitter.off.bind(this.emitter));
@@ -288,8 +287,8 @@ class p extends Z {
288
287
  t != this._token && (this._token = t, this.headers.Authorization = `Bearer ${t}`, this.emit("TOKEN", t));
289
288
  }
290
289
  request(t) {
291
- const r = super.request(t).then((s) => (this.emit("RESPONSE", s, t), s)).catch((s) => {
292
- throw this.emit("REJECTED", s, t), s;
290
+ const r = super.request(t).then((n) => (this.emit("RESPONSE", n, t), n)).catch((n) => {
291
+ throw this.emit("REJECTED", n, t), n;
293
292
  });
294
293
  return this.emit("REQUEST", r, t), r;
295
294
  }
@@ -298,11 +297,11 @@ var j = function(i, e) {
298
297
  return j = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
299
298
  t.__proto__ = r;
300
299
  } || function(t, r) {
301
- for (var s in r)
302
- Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
300
+ for (var n in r)
301
+ Object.prototype.hasOwnProperty.call(r, n) && (t[n] = r[n]);
303
302
  }, j(i, e);
304
303
  };
305
- function x(i, e) {
304
+ function $(i, e) {
306
305
  if (typeof e != "function" && e !== null)
307
306
  throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
308
307
  j(i, e);
@@ -327,42 +326,42 @@ function G(i, e) {
327
326
  var t = typeof Symbol == "function" && i[Symbol.iterator];
328
327
  if (!t)
329
328
  return i;
330
- var r = t.call(i), s, n = [], o;
329
+ var r = t.call(i), n, s = [], o;
331
330
  try {
332
- for (; (e === void 0 || e-- > 0) && !(s = r.next()).done; )
333
- n.push(s.value);
331
+ for (; (e === void 0 || e-- > 0) && !(n = r.next()).done; )
332
+ s.push(n.value);
334
333
  } catch (u) {
335
334
  o = { error: u };
336
335
  } finally {
337
336
  try {
338
- s && !s.done && (t = r.return) && t.call(r);
337
+ n && !n.done && (t = r.return) && t.call(r);
339
338
  } finally {
340
339
  if (o)
341
340
  throw o.error;
342
341
  }
343
342
  }
344
- return n;
343
+ return s;
345
344
  }
346
345
  function N(i, e, t) {
347
346
  if (t || arguments.length === 2)
348
- for (var r = 0, s = e.length, n; r < s; r++)
349
- (n || !(r in e)) && (n || (n = Array.prototype.slice.call(e, 0, r)), n[r] = e[r]);
350
- return i.concat(n || Array.prototype.slice.call(e));
347
+ for (var r = 0, n = e.length, s; r < n; r++)
348
+ (s || !(r in e)) && (s || (s = Array.prototype.slice.call(e, 0, r)), s[r] = e[r]);
349
+ return i.concat(s || Array.prototype.slice.call(e));
351
350
  }
352
- function y(i) {
351
+ function b(i) {
353
352
  return typeof i == "function";
354
353
  }
355
- function nt(i) {
354
+ function tt(i) {
356
355
  var e = function(r) {
357
356
  Error.call(r), r.stack = new Error().stack;
358
357
  }, t = i(e);
359
358
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
360
359
  }
361
- var U = nt(function(i) {
360
+ var U = tt(function(i) {
362
361
  return function(t) {
363
362
  i(this), this.message = t ? t.length + ` errors occurred during unsubscription:
364
- ` + t.map(function(r, s) {
365
- return s + 1 + ") " + r.toString();
363
+ ` + t.map(function(r, n) {
364
+ return n + 1 + ") " + r.toString();
366
365
  }).join(`
367
366
  `) : "", this.name = "UnsubscriptionError", this.errors = t;
368
367
  };
@@ -378,7 +377,7 @@ var P = function() {
378
377
  this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
379
378
  }
380
379
  return i.prototype.unsubscribe = function() {
381
- var e, t, r, s, n;
380
+ var e, t, r, n, s;
382
381
  if (!this.closed) {
383
382
  this.closed = !0;
384
383
  var o = this._parentage;
@@ -386,11 +385,11 @@ var P = function() {
386
385
  if (this._parentage = null, Array.isArray(o))
387
386
  try {
388
387
  for (var u = k(o), c = u.next(); !c.done; c = u.next()) {
389
- var f = c.value;
390
- f.remove(this);
388
+ var l = c.value;
389
+ l.remove(this);
391
390
  }
392
- } catch (l) {
393
- e = { error: l };
391
+ } catch (d) {
392
+ e = { error: d };
394
393
  } finally {
395
394
  try {
396
395
  c && !c.done && (t = u.return) && t.call(u);
@@ -401,12 +400,12 @@ var P = function() {
401
400
  }
402
401
  else
403
402
  o.remove(this);
404
- var w = this.initialTeardown;
405
- if (y(w))
403
+ var y = this.initialTeardown;
404
+ if (b(y))
406
405
  try {
407
- w();
408
- } catch (l) {
409
- n = l instanceof U ? l.errors : [l];
406
+ y();
407
+ } catch (d) {
408
+ s = d instanceof U ? d.errors : [d];
410
409
  }
411
410
  var T = this._finalizers;
412
411
  if (T) {
@@ -416,23 +415,23 @@ var P = function() {
416
415
  var _ = E.value;
417
416
  try {
418
417
  V(_);
419
- } catch (l) {
420
- n = n ?? [], l instanceof U ? n = N(N([], G(n)), G(l.errors)) : n.push(l);
418
+ } catch (d) {
419
+ s = s ?? [], d instanceof U ? s = N(N([], G(s)), G(d.errors)) : s.push(d);
421
420
  }
422
421
  }
423
- } catch (l) {
424
- r = { error: l };
422
+ } catch (d) {
423
+ r = { error: d };
425
424
  } finally {
426
425
  try {
427
- E && !E.done && (s = g.return) && s.call(g);
426
+ E && !E.done && (n = g.return) && n.call(g);
428
427
  } finally {
429
428
  if (r)
430
429
  throw r.error;
431
430
  }
432
431
  }
433
432
  }
434
- if (n)
435
- throw new U(n);
433
+ if (s)
434
+ throw new U(s);
436
435
  }
437
436
  }, i.prototype.add = function(e) {
438
437
  var t;
@@ -463,49 +462,49 @@ var P = function() {
463
462
  var e = new i();
464
463
  return e.closed = !0, e;
465
464
  }(), i;
466
- }(), ot = P.EMPTY;
467
- function ut(i) {
468
- return i instanceof P || i && "closed" in i && y(i.remove) && y(i.add) && y(i.unsubscribe);
465
+ }(), et = P.EMPTY;
466
+ function rt(i) {
467
+ return i instanceof P || i && "closed" in i && b(i.remove) && b(i.add) && b(i.unsubscribe);
469
468
  }
470
469
  function V(i) {
471
- y(i) ? i() : i.unsubscribe();
470
+ b(i) ? i() : i.unsubscribe();
472
471
  }
473
- var at = {
472
+ var it = {
474
473
  onUnhandledError: null,
475
474
  onStoppedNotification: null,
476
475
  Promise: void 0,
477
476
  useDeprecatedSynchronousErrorHandling: !1,
478
477
  useDeprecatedNextContext: !1
479
- }, ct = {
478
+ }, nt = {
480
479
  setTimeout: function(i, e) {
481
480
  for (var t = [], r = 2; r < arguments.length; r++)
482
481
  t[r - 2] = arguments[r];
483
482
  return setTimeout.apply(void 0, N([i, e], G(t)));
484
483
  },
485
484
  clearTimeout: function(i) {
486
- var e = ct.delegate;
485
+ var e = nt.delegate;
487
486
  return ((e == null ? void 0 : e.clearTimeout) || clearTimeout)(i);
488
487
  },
489
488
  delegate: void 0
490
489
  };
491
490
  function vt(i) {
492
- ct.setTimeout(function() {
491
+ nt.setTimeout(function() {
493
492
  throw i;
494
493
  });
495
494
  }
496
495
  function K() {
497
496
  }
498
- function R(i) {
497
+ function x(i) {
499
498
  i();
500
499
  }
501
- var ht = function(i) {
502
- x(e, i);
500
+ var st = function(i) {
501
+ $(e, i);
503
502
  function e(t) {
504
503
  var r = i.call(this) || this;
505
- return r.isStopped = !1, t ? (r.destination = t, ut(t) && t.add(r)) : r.destination = Tt, r;
504
+ return r.isStopped = !1, t ? (r.destination = t, rt(t) && t.add(r)) : r.destination = Tt, r;
506
505
  }
507
- return e.create = function(t, r, s) {
508
- return new W(t, r, s);
506
+ return e.create = function(t, r, n) {
507
+ return new W(t, r, n);
509
508
  }, e.prototype.next = function(t) {
510
509
  this.isStopped || this._next(t);
511
510
  }, e.prototype.error = function(t) {
@@ -565,29 +564,29 @@ var St = function() {
565
564
  }
566
565
  }, i;
567
566
  }(), W = function(i) {
568
- x(e, i);
569
- function e(t, r, s) {
570
- var n = i.call(this) || this, o;
571
- if (y(t) || !t)
567
+ $(e, i);
568
+ function e(t, r, n) {
569
+ var s = i.call(this) || this, o;
570
+ if (b(t) || !t)
572
571
  o = {
573
572
  next: t ?? void 0,
574
573
  error: r ?? void 0,
575
- complete: s ?? void 0
574
+ complete: n ?? void 0
576
575
  };
577
576
  else {
578
577
  var u;
579
- n && at.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
580
- return n.unsubscribe();
578
+ s && it.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
579
+ return s.unsubscribe();
581
580
  }, o = {
582
581
  next: t.next && C(t.next, u),
583
582
  error: t.error && C(t.error, u),
584
583
  complete: t.complete && C(t.complete, u)
585
584
  }) : o = t;
586
585
  }
587
- return n.destination = new St(o), n;
586
+ return s.destination = new St(o), s;
588
587
  }
589
588
  return e;
590
- }(ht);
589
+ }(st);
591
590
  function A(i) {
592
591
  vt(i);
593
592
  }
@@ -602,13 +601,13 @@ var Tt = {
602
601
  }, Ot = function() {
603
602
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
604
603
  }();
605
- function xt(i) {
604
+ function $t(i) {
606
605
  return i;
607
606
  }
608
607
  function _t(i) {
609
- return i.length === 0 ? xt : i.length === 1 ? i[0] : function(t) {
610
- return i.reduce(function(r, s) {
611
- return s(r);
608
+ return i.length === 0 ? $t : i.length === 1 ? i[0] : function(t) {
609
+ return i.reduce(function(r, n) {
610
+ return n(r);
612
611
  }, t);
613
612
  };
614
613
  }
@@ -620,11 +619,11 @@ var z = function() {
620
619
  var t = new i();
621
620
  return t.source = this, t.operator = e, t;
622
621
  }, i.prototype.subscribe = function(e, t, r) {
623
- var s = this, n = At(e) ? e : new W(e, t, r);
624
- return R(function() {
625
- var o = s, u = o.operator, c = o.source;
626
- n.add(u ? u.call(n, c) : c ? s._subscribe(n) : s._trySubscribe(n));
627
- }), n;
622
+ var n = this, s = At(e) ? e : new W(e, t, r);
623
+ return x(function() {
624
+ var o = n, u = o.operator, c = o.source;
625
+ s.add(u ? u.call(s, c) : c ? n._subscribe(s) : n._trySubscribe(s));
626
+ }), s;
628
627
  }, i.prototype._trySubscribe = function(e) {
629
628
  try {
630
629
  return this._subscribe(e);
@@ -633,17 +632,17 @@ var z = function() {
633
632
  }
634
633
  }, i.prototype.forEach = function(e, t) {
635
634
  var r = this;
636
- return t = J(t), new t(function(s, n) {
635
+ return t = J(t), new t(function(n, s) {
637
636
  var o = new W({
638
637
  next: function(u) {
639
638
  try {
640
639
  e(u);
641
640
  } catch (c) {
642
- n(c), o.unsubscribe();
641
+ s(c), o.unsubscribe();
643
642
  }
644
643
  },
645
- error: n,
646
- complete: s
644
+ error: s,
645
+ complete: n
647
646
  });
648
647
  r.subscribe(o);
649
648
  });
@@ -658,14 +657,14 @@ var z = function() {
658
657
  return _t(e)(this);
659
658
  }, i.prototype.toPromise = function(e) {
660
659
  var t = this;
661
- return e = J(e), new e(function(r, s) {
662
- var n;
660
+ return e = J(e), new e(function(r, n) {
661
+ var s;
663
662
  t.subscribe(function(o) {
664
- return n = o;
663
+ return s = o;
665
664
  }, function(o) {
666
- return s(o);
665
+ return n(o);
667
666
  }, function() {
668
- return r(n);
667
+ return r(s);
669
668
  });
670
669
  });
671
670
  }, i.create = function(e) {
@@ -674,20 +673,20 @@ var z = function() {
674
673
  }();
675
674
  function J(i) {
676
675
  var e;
677
- return (e = i ?? at.Promise) !== null && e !== void 0 ? e : Promise;
676
+ return (e = i ?? it.Promise) !== null && e !== void 0 ? e : Promise;
678
677
  }
679
- function $t(i) {
680
- return i && y(i.next) && y(i.error) && y(i.complete);
678
+ function Rt(i) {
679
+ return i && b(i.next) && b(i.error) && b(i.complete);
681
680
  }
682
681
  function At(i) {
683
- return i && i instanceof ht || $t(i) && ut(i);
682
+ return i && i instanceof st || Rt(i) && rt(i);
684
683
  }
685
- var Rt = nt(function(i) {
684
+ var xt = tt(function(i) {
686
685
  return function() {
687
686
  i(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
688
687
  };
689
- }), lt = function(i) {
690
- x(e, i);
688
+ }), ot = function(i) {
689
+ $(e, i);
691
690
  function e() {
692
691
  var t = i.call(this) || this;
693
692
  return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
@@ -697,11 +696,11 @@ var Rt = nt(function(i) {
697
696
  return r.operator = t, r;
698
697
  }, e.prototype._throwIfClosed = function() {
699
698
  if (this.closed)
700
- throw new Rt();
699
+ throw new xt();
701
700
  }, e.prototype.next = function(t) {
702
701
  var r = this;
703
- R(function() {
704
- var s, n;
702
+ x(function() {
703
+ var n, s;
705
704
  if (r._throwIfClosed(), !r.isStopped) {
706
705
  r.currentObservers || (r.currentObservers = Array.from(r.observers));
707
706
  try {
@@ -709,30 +708,30 @@ var Rt = nt(function(i) {
709
708
  var c = u.value;
710
709
  c.next(t);
711
710
  }
712
- } catch (f) {
713
- s = { error: f };
711
+ } catch (l) {
712
+ n = { error: l };
714
713
  } finally {
715
714
  try {
716
- u && !u.done && (n = o.return) && n.call(o);
715
+ u && !u.done && (s = o.return) && s.call(o);
717
716
  } finally {
718
- if (s)
719
- throw s.error;
717
+ if (n)
718
+ throw n.error;
720
719
  }
721
720
  }
722
721
  }
723
722
  });
724
723
  }, e.prototype.error = function(t) {
725
724
  var r = this;
726
- R(function() {
725
+ x(function() {
727
726
  if (r._throwIfClosed(), !r.isStopped) {
728
727
  r.hasError = r.isStopped = !0, r.thrownError = t;
729
- for (var s = r.observers; s.length; )
730
- s.shift().error(t);
728
+ for (var n = r.observers; n.length; )
729
+ n.shift().error(t);
731
730
  }
732
731
  });
733
732
  }, e.prototype.complete = function() {
734
733
  var t = this;
735
- R(function() {
734
+ x(function() {
736
735
  if (t._throwIfClosed(), !t.isStopped) {
737
736
  t.isStopped = !0;
738
737
  for (var r = t.observers; r.length; )
@@ -753,13 +752,13 @@ var Rt = nt(function(i) {
753
752
  }, e.prototype._subscribe = function(t) {
754
753
  return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
755
754
  }, e.prototype._innerSubscribe = function(t) {
756
- var r = this, s = this, n = s.hasError, o = s.isStopped, u = s.observers;
757
- return n || o ? ot : (this.currentObservers = null, u.push(t), new P(function() {
755
+ var r = this, n = this, s = n.hasError, o = n.isStopped, u = n.observers;
756
+ return s || o ? et : (this.currentObservers = null, u.push(t), new P(function() {
758
757
  r.currentObservers = null, H(u, t);
759
758
  }));
760
759
  }, e.prototype._checkFinalizedStatuses = function(t) {
761
- var r = this, s = r.hasError, n = r.thrownError, o = r.isStopped;
762
- s ? t.error(n) : o && t.complete();
760
+ var r = this, n = r.hasError, s = r.thrownError, o = r.isStopped;
761
+ n ? t.error(s) : o && t.complete();
763
762
  }, e.prototype.asObservable = function() {
764
763
  var t = new z();
765
764
  return t.source = this, t;
@@ -767,26 +766,26 @@ var Rt = nt(function(i) {
767
766
  return new Q(t, r);
768
767
  }, e;
769
768
  }(z), Q = function(i) {
770
- x(e, i);
769
+ $(e, i);
771
770
  function e(t, r) {
772
- var s = i.call(this) || this;
773
- return s.destination = t, s.source = r, s;
771
+ var n = i.call(this) || this;
772
+ return n.destination = t, n.source = r, n;
774
773
  }
775
774
  return e.prototype.next = function(t) {
776
- var r, s;
777
- (s = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || s === void 0 || s.call(r, t);
775
+ var r, n;
776
+ (n = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || n === void 0 || n.call(r, t);
778
777
  }, e.prototype.error = function(t) {
779
- var r, s;
780
- (s = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || s === void 0 || s.call(r, t);
778
+ var r, n;
779
+ (n = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || n === void 0 || n.call(r, t);
781
780
  }, e.prototype.complete = function() {
782
781
  var t, r;
783
782
  (r = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || r === void 0 || r.call(t);
784
783
  }, e.prototype._subscribe = function(t) {
785
- var r, s;
786
- return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && s !== void 0 ? s : ot;
784
+ var r, n;
785
+ return (n = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && n !== void 0 ? n : et;
787
786
  }, e;
788
- }(lt), I = function(i) {
789
- x(e, i);
787
+ }(ot), q = function(i) {
788
+ $(e, i);
790
789
  function e(t) {
791
790
  var r = i.call(this) || this;
792
791
  return r._value = t, r;
@@ -801,20 +800,20 @@ var Rt = nt(function(i) {
801
800
  var r = i.prototype._subscribe.call(this, t);
802
801
  return !r.closed && t.next(this._value), r;
803
802
  }, e.prototype.getValue = function() {
804
- var t = this, r = t.hasError, s = t.thrownError, n = t._value;
803
+ var t = this, r = t.hasError, n = t.thrownError, s = t._value;
805
804
  if (r)
806
- throw s;
807
- return this._throwIfClosed(), n;
805
+ throw n;
806
+ return this._throwIfClosed(), s;
808
807
  }, e.prototype.next = function(t) {
809
808
  i.prototype.next.call(this, this._value = t);
810
809
  }, e;
811
- }(lt), Dt = /* @__PURE__ */ ((i) => (i[i.DISABLED = 0] = "DISABLED", i[i.CRON = 1] = "CRON", i[i.EVENT = 2] = "EVENT", i[i.GET = 3] = "GET", i[i.POST = 4] = "POST", i[i.PATCH = 5] = "PATCH", i[i.PUT = 6] = "PUT", i[i.DELETE = 7] = "DELETE", i))(Dt || {});
812
- class Pt extends d {
810
+ }(ot), Dt = /* @__PURE__ */ ((i) => (i[i.DISABLED = 0] = "DISABLED", i[i.CRON = 1] = "CRON", i[i.EVENT = 2] = "EVENT", i[i.GET = 3] = "GET", i[i.POST = 4] = "POST", i[i.PATCH = 5] = "PATCH", i[i.PUT = 6] = "PUT", i[i.DELETE = 7] = "DELETE", i))(Dt || {});
811
+ class Pt extends p {
813
812
  constructor(t) {
814
813
  super();
815
814
  a(this, "api");
816
- a(this, "$cache", new I([]));
817
- this.api = typeof t == "string" ? new p(t) : t;
815
+ a(this, "$cache", new q([]));
816
+ this.api = typeof t == "string" ? new f(t) : t;
818
817
  }
819
818
  get cache() {
820
819
  return this.$cache.value;
@@ -831,37 +830,37 @@ class Pt extends d {
831
830
  return this.api.request({ url: "/api/actions" }).then((t) => (this.cache = t, this.emit("LIST", t), t));
832
831
  }
833
832
  read(t, r = !1) {
834
- const s = this.cache.find((n) => n._id == t);
835
- return !r && s ? Promise.resolve(s) : this.api.request({ url: `/api/actions/${t}` }).then((n) => (n && (this.cache = this.cache.filter((o) => o._id != t).concat([n])), this.emit("READ", n), n));
833
+ const n = this.cache.find((s) => s._id == t);
834
+ return !r && n ? Promise.resolve(n) : this.api.request({ url: `/api/actions/${t}` }).then((s) => (s && (this.cache = this.cache.filter((o) => o._id != t).concat([s])), this.emit("READ", s), s));
836
835
  }
837
836
  run(t, r = {}) {
838
837
  return this.api.request({ url: ("/api/actions/run/" + t).replaceAll("//", "/"), ...r });
839
838
  }
840
839
  runById(t, r = {}) {
841
- const s = typeof t == "string" ? t : t._id;
842
- return this.api.request({ url: "/api/actions/run-by-id/" + s, ...r });
840
+ const n = typeof t == "string" ? t : t._id;
841
+ return this.api.request({ url: "/api/actions/run-by-id/" + n, ...r });
843
842
  }
844
843
  update(t) {
845
844
  return this.api.request({
846
845
  url: `/api/actions${t._id ? `/${t._id}` : ""}`,
847
846
  method: "POST",
848
847
  body: t
849
- }).then((r) => (r && (this.cache = this.cache.filter((s) => s._id != r._id).concat([r])), this.emit("UPDATE", r), r));
848
+ }).then((r) => (r && (this.cache = this.cache.filter((n) => n._id != r._id).concat([r])), this.emit("UPDATE", r), r));
850
849
  }
851
850
  }
852
- class It extends d {
851
+ class qt extends p {
853
852
  constructor(t, r) {
854
- var s;
853
+ var n;
855
854
  super();
856
855
  a(this, "api");
857
856
  a(this, "storageKey");
858
- a(this, "$user", new I(void 0));
859
- if (this.opts = r, this.api = typeof t == "string" ? new p(t) : t, (s = this.opts) != null && s.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (n) => {
857
+ a(this, "$user", new q(void 0));
858
+ if (this.opts = r, this.api = typeof t == "string" ? new f(t) : t, (n = this.opts) != null && n.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (s) => {
860
859
  var o;
861
- (o = this.opts) != null && o.persist && (n ? localStorage.setItem(this.storageKey, n) : localStorage.removeItem(this.storageKey)), n ? this.whoAmI(n, !0) : this.user = null;
860
+ (o = this.opts) != null && o.persist && (s ? localStorage.setItem(this.storageKey, s) : localStorage.removeItem(this.storageKey)), s ? this.whoAmI(s, !0) : this.user = null;
862
861
  }), r != null && r.persist) {
863
- const n = localStorage.getItem(this.storageKey);
864
- n ? this.api.token = n : this.user = null;
862
+ const s = localStorage.getItem(this.storageKey);
863
+ s ? this.api.token = s : this.user = null;
865
864
  } else
866
865
  this.user = null;
867
866
  }
@@ -885,19 +884,19 @@ class It extends d {
885
884
  username: t,
886
885
  password: r
887
886
  }
888
- }).then(async (s) => (this.api.token = s.token, await this.once("USER")));
887
+ }).then(async (n) => (this.api.token = n.token, await this.once("USER")));
889
888
  }
890
889
  loginRedirect(t = location.origin) {
891
- return new Promise((r, s) => {
890
+ return new Promise((r, n) => {
892
891
  var o;
893
- const n = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
894
- if (!n)
895
- return s("Unable to open login");
896
- n.addEventListener("message", (u) => {
892
+ const s = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
893
+ if (!s)
894
+ return n("Unable to open login");
895
+ s.addEventListener("message", (u) => {
897
896
  var c;
898
897
  if (!((c = u == null ? void 0 : u.data) != null && c.token))
899
- return s("Unknown response from login");
900
- this.api.token = u.data.token, r(u.data.token), n.close();
898
+ return n("Unknown response from login");
899
+ this.api.token = u.data.token, r(u.data.token), s.close();
901
900
  });
902
901
  });
903
902
  }
@@ -920,18 +919,18 @@ class It extends d {
920
919
  }
921
920
  async whoAmI(t, r = !1) {
922
921
  t || (t = this.api.token);
923
- const s = await this.api.request({
922
+ const n = await this.api.request({
924
923
  url: "/api/auth/whoami",
925
924
  headers: t ? { Authorization: `Bearer ${t}` } : void 0
926
925
  });
927
- return r && (this.api.token = t, this.user = (s == null ? void 0 : s.user) || null, s && this.emit("LOGIN", s.user)), s;
926
+ return r && (this.api.token = t, this.user = (n == null ? void 0 : n.user) || null, n && this.emit("LOGIN", n.user)), n;
928
927
  }
929
928
  }
930
- class qt extends d {
929
+ class It extends p {
931
930
  constructor(t) {
932
931
  super();
933
932
  a(this, "api");
934
- this.api = typeof t == "string" ? new p(t) : t;
933
+ this.api = typeof t == "string" ? new f(t) : t;
935
934
  }
936
935
  delete(t, r) {
937
936
  return this.api.request({
@@ -940,42 +939,42 @@ class qt extends d {
940
939
  }).then(() => this.emit("DELETE", t, r));
941
940
  }
942
941
  get(t, r) {
943
- return this.api.request({ url: `/api/data/${t}${r ? `/${r}` : ""}` }).then((s) => (this.emit("GET", t, s), s));
942
+ return this.api.request({ url: `/api/data/${t}${r ? `/${r}` : ""}` }).then((n) => (this.emit("GET", t, n), n));
944
943
  }
945
- raw(t, r, s, n) {
944
+ raw(t, r, n, s) {
946
945
  return this.api.request({
947
946
  url: `/api/data/${t}`,
948
947
  body: {
949
948
  operand: r,
950
- query: s,
951
- options: n
949
+ query: n,
950
+ options: s
952
951
  }
953
952
  }).then((o) => (this.emit("RAW", t, o), o));
954
953
  }
955
- set(t, r, s = !1) {
954
+ set(t, r, n = !1) {
956
955
  return this.api.request({
957
956
  url: `/api/data/${t}/${r._id || ""}`,
958
- method: s ? "PATCH" : "POST",
957
+ method: n ? "PATCH" : "POST",
959
958
  body: r
960
- }).then((n) => (this.emit("SET", t, r), n));
959
+ }).then((s) => (this.emit("SET", t, r), s));
961
960
  }
962
961
  }
963
- class Ut extends d {
962
+ class Ut extends p {
964
963
  constructor(t) {
965
964
  super();
966
965
  a(this, "api");
967
- this.api = typeof t == "string" ? new p(t) : t;
966
+ this.api = typeof t == "string" ? new f(t) : t;
968
967
  }
969
968
  send(t) {
970
969
  let r = "/api/email";
971
- return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((s) => (this.emit("SENT", t), s));
970
+ return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((n) => (this.emit("SENT", t), n));
972
971
  }
973
972
  }
974
- class Ct extends d {
973
+ class Ct extends p {
975
974
  constructor(t) {
976
975
  super();
977
976
  a(this, "api");
978
- this.api = typeof t == "string" ? new p(t) : t;
977
+ this.api = typeof t == "string" ? new f(t) : t;
979
978
  }
980
979
  create(t) {
981
980
  return this.api.request({
@@ -1007,7 +1006,7 @@ class Ct extends d {
1007
1006
  class Bt {
1008
1007
  constructor(e, t) {
1009
1008
  a(this, "api");
1010
- this.api = typeof e == "string" ? new p(e) : e, t != null && t != "NONE" && (window.addEventListener("error", (r) => this.error(r.error.stack)), window.addEventListener("unhandledrejection", async (r) => this.error(r.reason.stack)));
1009
+ this.api = typeof e == "string" ? new f(e) : e, t != null && t != "NONE" && (window.addEventListener("error", (r) => this.error(r.error.stack)), window.addEventListener("unhandledrejection", async (r) => this.error(r.reason.stack)));
1011
1010
  }
1012
1011
  buildLog(e, t) {
1013
1012
  return {
@@ -1029,41 +1028,65 @@ class Bt {
1029
1028
  return this.api.request({ url: "/api/logs/server", method: "DELETE" });
1030
1029
  }
1031
1030
  clientLogs(e, t) {
1032
- const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1031
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((n) => !!n).join("&");
1033
1032
  return this.api.request({ url: `/api/logs/client${r ? `?${r}` : ""}` });
1034
1033
  }
1035
1034
  serverLogs(e, t) {
1036
- const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1035
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((n) => !!n).join("&");
1037
1036
  return this.api.request({ url: `/api/logs/server${r ? `?${r}` : ""}` });
1038
1037
  }
1039
1038
  debug(...e) {
1040
- return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.DEBUG, e) }).catch(() => {
1039
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(S.DEBUG, e) }).catch(() => {
1041
1040
  });
1042
1041
  }
1043
1042
  log(...e) {
1044
- return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.LOG, e) }).catch(() => {
1043
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(S.LOG, e) }).catch(() => {
1045
1044
  });
1046
1045
  }
1047
1046
  info(...e) {
1048
- return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.INFO, e) }).catch(() => {
1047
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(S.INFO, e) }).catch(() => {
1049
1048
  });
1050
1049
  }
1051
1050
  warn(...e) {
1052
- return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.WARN, e) }).catch(() => {
1051
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(S.WARN, e) }).catch(() => {
1053
1052
  });
1054
1053
  }
1055
1054
  error(...e) {
1056
- return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.ERROR, e) }).catch(() => {
1055
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(S.ERROR, e) }).catch(() => {
1057
1056
  });
1058
1057
  }
1059
1058
  }
1059
+ class jt extends p {
1060
+ constructor(t) {
1061
+ super();
1062
+ a(this, "api");
1063
+ this.api = typeof t == "string" ? new f(t) : t;
1064
+ }
1065
+ async handleResponse(t, r) {
1066
+ const n = await t.blob();
1067
+ if (r) {
1068
+ const s = URL.createObjectURL(n);
1069
+ Z(s, r.endsWith(".pdf") ? r : r + ".pdf"), URL.revokeObjectURL(s);
1070
+ }
1071
+ return this.emit("CREATE", n), n;
1072
+ }
1073
+ fromHtml(t, r = {}) {
1074
+ return this.api.request({ url: "/api/pdf", body: { html: t } }).then((n) => this.handleResponse(n, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1075
+ }
1076
+ fromUrl(t, r = {}) {
1077
+ return this.api.request({ url: `/api/pdf?url=${t}` }).then((n) => this.handleResponse(n, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1078
+ }
1079
+ fromTemplate(t, r, n = {}) {
1080
+ return this.api.request({ url: `/api/pdf/${t}`, body: { data: r } }).then((s) => this.handleResponse(s, n.download ? n.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1081
+ }
1082
+ }
1060
1083
  const D = class D {
1061
1084
  constructor(e) {
1062
1085
  a(this, "api");
1063
1086
  a(this, "url");
1064
1087
  a(this, "connection");
1065
1088
  a(this, "open", !1);
1066
- this.api = typeof e == "string" ? new p(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1089
+ this.api = typeof e == "string" ? new f(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1067
1090
  }
1068
1091
  close() {
1069
1092
  console.debug("Disconnected from Momentum"), this.open = !1, this.connection.close();
@@ -1090,12 +1113,12 @@ const D = class D {
1090
1113
  }
1091
1114
  };
1092
1115
  a(D, "timeout", 1e4);
1093
- let M = D;
1094
- class jt extends d {
1116
+ let F = D;
1117
+ class kt extends p {
1095
1118
  constructor(t) {
1096
1119
  super();
1097
1120
  a(this, "api");
1098
- this.api = typeof t == "string" ? new p(t) : t;
1121
+ this.api = typeof t == "string" ? new f(t) : t;
1099
1122
  }
1100
1123
  delete(t) {
1101
1124
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
@@ -1105,33 +1128,33 @@ class jt extends d {
1105
1128
  }
1106
1129
  list(t) {
1107
1130
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
1108
- return this.api.request({ url: r + "?list" }).then((s) => (this.emit("LIST", t, s), s));
1131
+ return this.api.request({ url: r + "?list" }).then((n) => (this.emit("LIST", t, n), n));
1109
1132
  }
1110
1133
  open(t, r = "_blank") {
1111
- const s = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/"), n = `${this.api.url}${s}${this.api.token ? `?token=${this.api.token}` : ""}`;
1112
- return r ? (this.emit("OPEN", t), window.open(n, r)) : n;
1134
+ const n = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/"), s = `${this.api.url}${n}${this.api.token ? `?token=${this.api.token}` : ""}`;
1135
+ return r ? (this.emit("OPEN", t), window.open(s, r)) : s;
1113
1136
  }
1114
1137
  mkdir(t) {
1115
1138
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/");
1116
1139
  return this.api.request({ url: r + "?directory", method: "POST" });
1117
1140
  }
1118
1141
  download(t, r = {}) {
1119
- return new bt((s, n, o) => {
1142
+ return new bt((n, s, o) => {
1120
1143
  const u = ("/api/storage/" + t).replaceAll("//", "/");
1121
1144
  this.api.request({ ...r, url: u, skipConverting: !0 }).then((c) => {
1122
- var l;
1145
+ var d;
1123
1146
  if (!c.ok)
1124
- return n(c.statusText);
1125
- const f = c.headers.get("Content-Length"), w = f ? parseInt(f, 10) : 0;
1147
+ return s(c.statusText);
1148
+ const l = c.headers.get("Content-Length"), y = l ? parseInt(l, 10) : 0;
1126
1149
  let T = [], g = 0;
1127
- const E = (l = c.body) == null ? void 0 : l.getReader(), _ = (F) => {
1128
- if (F.done) {
1150
+ const E = (d = c.body) == null ? void 0 : d.getReader(), _ = (M) => {
1151
+ if (M.done) {
1129
1152
  o(1);
1130
- const S = new Blob(T), q = r.downloadAs || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(S);
1131
- yt(Y, q.includes(".") ? q : q + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, S), s(S);
1153
+ const w = new Blob(T), I = r.downloadAs || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(w);
1154
+ Z(Y, I.includes(".") ? I : I + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, w), n(w);
1132
1155
  } else {
1133
- const S = F.value;
1134
- T.push(S), g += S.length, o(g / w), E.read().then(_);
1156
+ const w = M.value;
1157
+ T.push(w), g += w.length, o(g / y), E.read().then(_);
1135
1158
  }
1136
1159
  };
1137
1160
  E == null || E.read().then(_);
@@ -1146,17 +1169,17 @@ class jt extends d {
1146
1169
  }, document.body.appendChild(c), c.click();
1147
1170
  })), !t || Array.isArray(t) && !t.length)
1148
1171
  return [];
1149
- const n = new FormData(), o = ("/api/storage/" + (typeof r == "string" ? r : r == null ? void 0 : r.path)).replaceAll("//", "/");
1150
- return (Array.isArray(t) ? t : [t]).forEach((u) => n.append("file", u)), this.api.request({ url: o, body: n }).then((u) => (this.emit("UPLOAD", u), u));
1172
+ const s = new FormData(), o = ("/api/storage/" + (typeof r == "string" ? r : r == null ? void 0 : r.path)).replaceAll("//", "/");
1173
+ return (Array.isArray(t) ? t : [t]).forEach((u) => s.append("file", u)), this.api.request({ url: o, body: s }).then((u) => (this.emit("UPLOAD", u), u));
1151
1174
  }
1152
1175
  }
1153
- class kt extends d {
1176
+ class Gt extends p {
1154
1177
  constructor(t) {
1155
1178
  super();
1156
1179
  a(this, "api");
1157
1180
  a(this, "listed", !1);
1158
- a(this, "$cache", new I([]));
1159
- this.api = typeof t == "string" ? new p(t) : t;
1181
+ a(this, "$cache", new q([]));
1182
+ this.api = typeof t == "string" ? new f(t) : t;
1160
1183
  }
1161
1184
  get cache() {
1162
1185
  return this.$cache.value;
@@ -1177,26 +1200,26 @@ class kt extends d {
1177
1200
  }
1178
1201
  read(t, r = !1) {
1179
1202
  if (!r) {
1180
- const s = this.cache.find((n) => n.username == t);
1181
- if (s)
1182
- return Promise.resolve(s);
1203
+ const n = this.cache.find((s) => s.username == t);
1204
+ if (n)
1205
+ return Promise.resolve(n);
1183
1206
  }
1184
- return this.api.request({ url: `/api/users/${t}` }).then((s) => (s && (this.cache = { ...this.cache, [s.username]: s }), this.emit("READ", s), s));
1207
+ return this.api.request({ url: `/api/users/${t}` }).then((n) => (n && (this.cache = { ...this.cache, [n.username]: n }), this.emit("READ", n), n));
1185
1208
  }
1186
1209
  update(t) {
1187
1210
  return this.api.request({
1188
1211
  url: `/api/users/${t.username}`,
1189
1212
  method: "PATCH",
1190
1213
  body: t
1191
- }).then((r) => (r && (this.cache = this.cache.filter((s) => s.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1214
+ }).then((r) => (r && (this.cache = this.cache.filter((n) => n.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1192
1215
  }
1193
1216
  }
1194
- class Gt extends d {
1217
+ class Nt extends p {
1195
1218
  constructor(t) {
1196
1219
  super();
1197
1220
  a(this, "api");
1198
- a(this, "$cache", new I({}));
1199
- this.api = typeof t == "string" ? new p(t) : t;
1221
+ a(this, "$cache", new q({}));
1222
+ this.api = typeof t == "string" ? new f(t) : t;
1200
1223
  }
1201
1224
  get cache() {
1202
1225
  return this.$cache.value;
@@ -1205,7 +1228,7 @@ class Gt extends d {
1205
1228
  this.$cache.next(t);
1206
1229
  }
1207
1230
  list(t = !1) {
1208
- return this.api.request({ url: "/api/settings" + (t ? "?detailed" : "") }).then((r) => (this.cache = t ? Object.values(r).reduce((s, n) => ({ ...s, [n.key]: n.value }), {}) : r, this.emit("LIST", r), r));
1231
+ return this.api.request({ url: "/api/settings" + (t ? "?detailed" : "") }).then((r) => (this.cache = t ? Object.values(r).reduce((n, s) => ({ ...n, [s.key]: s.value }), {}) : r, this.emit("LIST", r), r));
1209
1232
  }
1210
1233
  delete(t) {
1211
1234
  return this.api.request({ url: `/api/settings/${t}`, method: "DELETE" }).then(() => {
@@ -1213,17 +1236,17 @@ class Gt extends d {
1213
1236
  });
1214
1237
  }
1215
1238
  read(t, r = !1) {
1216
- return !r && this.cache[t] ? Promise.resolve(this.cache[t]) : this.api.request({ url: `/api/settings/${t}` }).then((s) => (s && (this.cache = { ...this.cache, [s.key]: s }), this.emit("READ", s), s));
1239
+ return !r && this.cache[t] ? Promise.resolve(this.cache[t]) : this.api.request({ url: `/api/settings/${t}` }).then((n) => (n && (this.cache = { ...this.cache, [n.key]: n }), this.emit("READ", n), n));
1217
1240
  }
1218
1241
  update(t) {
1219
1242
  return this.api.request({ url: `/api/settings/${t.key}`, body: t }).then((r) => (r && (this.cache = { ...this.cache, [r.key]: r.value }), this.emit("UPDATE", r), r));
1220
1243
  }
1221
1244
  }
1222
- class Nt extends d {
1245
+ class Ht extends p {
1223
1246
  constructor(t) {
1224
1247
  super();
1225
1248
  a(this, "api");
1226
- this.api = typeof t == "string" ? new p(t) : t;
1249
+ this.api = typeof t == "string" ? new f(t) : t;
1227
1250
  }
1228
1251
  delete(t) {
1229
1252
  return this.api.request({ url: `/api/static/${t}`, method: "DELETE" }).then(() => {
@@ -1232,14 +1255,14 @@ class Nt extends d {
1232
1255
  }
1233
1256
  list(t) {
1234
1257
  const r = ("/api/static/" + t).replaceAll("//", "/");
1235
- return this.api.request({ url: r }).then((s) => (this.emit("LIST", t, s), s));
1258
+ return this.api.request({ url: r }).then((n) => (this.emit("LIST", t, n), n));
1236
1259
  }
1237
1260
  upload(t, r = "/") {
1238
- const s = new FormData();
1239
- return (Array.isArray(t) ? t : [t]).forEach((n) => s.append("file", n)), this.api.request({ url: "/api/static" + r, body: s }).then((n) => (this.emit("UPLOAD", n), n));
1261
+ const n = new FormData();
1262
+ return (Array.isArray(t) ? t : [t]).forEach((s) => n.append("file", s)), this.api.request({ url: "/api/static" + r, body: n }).then((s) => (this.emit("UPLOAD", s), s));
1240
1263
  }
1241
1264
  }
1242
- class Wt extends d {
1265
+ class Ft extends p {
1243
1266
  constructor(t, r) {
1244
1267
  super();
1245
1268
  a(this, "api");
@@ -1249,41 +1272,43 @@ class Wt extends d {
1249
1272
  a(this, "email");
1250
1273
  a(this, "groups");
1251
1274
  a(this, "logger");
1275
+ a(this, "pdf");
1252
1276
  a(this, "settings");
1253
1277
  a(this, "socket");
1254
1278
  a(this, "static");
1255
1279
  a(this, "storage");
1256
1280
  a(this, "users");
1257
- this.api = new p(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1281
+ this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new qt(this.api, {
1258
1282
  persist: (r == null ? void 0 : r.persist) ?? !0,
1259
1283
  loginUi: r == null ? void 0 : r.loginUi
1260
- }), this.data = new qt(this.api), this.email = new Ut(this.api), this.groups = new Ct(this.api), this.logger = new Bt(this.api, r == null ? void 0 : r.logLevel), this.settings = new Gt(this.api), this.static = new Nt(this.api), this.storage = new jt(this.api), this.users = new kt(this.api), r != null && r.socket && (this.socket = new M(this.api)), this.api.on("*", (s, ...n) => this.emit(`API::${s}`, ...n)), this.actions.on("*", (s, ...n) => this.emit(`ACTIONS::${s}`, ...n)), this.auth.on("*", (s, ...n) => this.emit(`AUTH::${s}`, ...n)), this.data.on("*", (s, ...n) => this.emit(`DATA::${s}`, ...n)), this.email.on("*", (s, ...n) => this.emit(`EMAIL::${s}`, ...n)), this.groups.on("*", (s, ...n) => this.emit(`GROUPS::${s}`, ...n)), this.settings.on("*", (s, ...n) => this.emit(`SETTINGS::${s}`, ...n)), this.static.on("*", (s, ...n) => this.emit(`STATIC::${s}`, ...n)), this.storage.on("*", (s, ...n) => this.emit(`STORAGE::${s}`, ...n)), this.users.on("*", (s, ...n) => this.emit(`USERS::${s}`, ...n)), this.users.on("*", (s, ...n) => {
1284
+ }), this.data = new It(this.api), this.email = new Ut(this.api), this.groups = new Ct(this.api), this.logger = new Bt(this.api, r == null ? void 0 : r.logLevel), this.pdf = new jt(this.api), this.settings = new Nt(this.api), this.static = new Ht(this.api), this.storage = new kt(this.api), this.users = new Gt(this.api), r != null && r.socket && (this.socket = new F(this.api)), this.api.on("*", (n, ...s) => this.emit(`API::${n}`, ...s)), this.actions.on("*", (n, ...s) => this.emit(`ACTIONS::${n}`, ...s)), this.auth.on("*", (n, ...s) => this.emit(`AUTH::${n}`, ...s)), this.data.on("*", (n, ...s) => this.emit(`DATA::${n}`, ...s)), this.email.on("*", (n, ...s) => this.emit(`EMAIL::${n}`, ...s)), this.groups.on("*", (n, ...s) => this.emit(`GROUPS::${n}`, ...s)), this.pdf.on("*", (n, ...s) => this.emit(`PDF::${n}`, ...s)), this.settings.on("*", (n, ...s) => this.emit(`SETTINGS::${n}`, ...s)), this.static.on("*", (n, ...s) => this.emit(`STATIC::${n}`, ...s)), this.storage.on("*", (n, ...s) => this.emit(`STORAGE::${n}`, ...s)), this.users.on("*", (n, ...s) => this.emit(`USERS::${n}`, ...s)), this.users.on("*", (n, ...s) => {
1261
1285
  var o;
1262
- if (Array.isArray(n[0])) {
1263
- const u = n[0].find((c) => {
1264
- var f;
1265
- return c._id == ((f = this.auth.user) == null ? void 0 : f._id);
1286
+ if (Array.isArray(s[0])) {
1287
+ const u = s[0].find((c) => {
1288
+ var l;
1289
+ return c._id == ((l = this.auth.user) == null ? void 0 : l._id);
1266
1290
  });
1267
1291
  u && (this.auth.user = u);
1268
1292
  } else
1269
- n[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = n[0]);
1293
+ s[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = s[0]);
1270
1294
  });
1271
1295
  }
1272
1296
  }
1273
1297
  export {
1274
1298
  Dt as ActionType,
1275
1299
  Pt as Actions,
1276
- p as Api,
1277
- It as Auth,
1278
- qt as Data,
1300
+ f as Api,
1301
+ qt as Auth,
1302
+ It as Data,
1279
1303
  Ut as Email,
1280
1304
  Ct as Groups,
1281
1305
  Bt as Logger,
1282
- Wt as Momentum,
1283
- Gt as Settings,
1284
- M as Socket,
1285
- Nt as Static,
1286
- jt as Storage,
1287
- kt as Users
1306
+ Ft as Momentum,
1307
+ jt as Pdf,
1308
+ Nt as Settings,
1309
+ F as Socket,
1310
+ Ht as Static,
1311
+ kt as Storage,
1312
+ Gt as Users
1288
1313
  };
1289
1314
  //# sourceMappingURL=momentum.mjs.map