@auxilium/datalynk-client 0.7.0 → 0.8.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/index.cjs +294 -167
- package/dist/index.mjs +292 -165
- package/dist/socket.d.ts +2 -5
- package/dist/socket.d.ts.map +1 -1
- package/package.json +2 -4
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var c = (r, t, e) => (
|
|
7
|
-
function
|
|
8
|
-
if (r == null)
|
|
9
|
-
throw new Error("Cannot clean a NULL value");
|
|
4
|
+
var it = Object.defineProperty;
|
|
5
|
+
var ct = (r, t, e) => t in r ? it(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e;
|
|
6
|
+
var c = (r, t, e) => ct(r, typeof t != "symbol" ? t + "" : t, e);
|
|
7
|
+
function ut(r, t = false) {
|
|
8
|
+
if (r == null) throw new Error("Cannot clean a NULL value");
|
|
10
9
|
return Array.isArray(r) ? r = r.filter((e) => e != null) : Object.entries(r).forEach(([e, n]) => {
|
|
11
10
|
(t && n === void 0 || !t && n == null) && delete r[e];
|
|
12
11
|
}), r;
|
|
13
12
|
}
|
|
14
|
-
function
|
|
13
|
+
function $t(r) {
|
|
15
14
|
const t = new FormData();
|
|
16
15
|
return Object.entries(r).forEach(([e, n]) => t.append(e, n)), t;
|
|
17
16
|
}
|
|
18
|
-
function
|
|
17
|
+
function M(r) {
|
|
19
18
|
try {
|
|
20
19
|
return JSON.parse(r);
|
|
21
20
|
} catch {
|
|
@@ -24,10 +23,10 @@ function T(r) {
|
|
|
24
23
|
}
|
|
25
24
|
class E extends Promise {
|
|
26
25
|
constructor(e) {
|
|
27
|
-
super((n,
|
|
28
|
-
(
|
|
29
|
-
(
|
|
30
|
-
(
|
|
26
|
+
super((n, s) => e(
|
|
27
|
+
(o) => n(o),
|
|
28
|
+
(o) => s(o),
|
|
29
|
+
(o) => this.progress = o
|
|
31
30
|
));
|
|
32
31
|
c(this, "listeners", []);
|
|
33
32
|
c(this, "_progress", 0);
|
|
@@ -39,18 +38,18 @@ class E extends Promise {
|
|
|
39
38
|
e != this._progress && (this._progress = e, this.listeners.forEach((n) => n(e)));
|
|
40
39
|
}
|
|
41
40
|
static from(e) {
|
|
42
|
-
return e instanceof E ? e : new E((n,
|
|
41
|
+
return e instanceof E ? e : new E((n, s) => e.then((...o) => n(...o)).catch((...o) => s(...o)));
|
|
43
42
|
}
|
|
44
43
|
from(e) {
|
|
45
44
|
const n = E.from(e);
|
|
46
|
-
return this.onProgress((
|
|
45
|
+
return this.onProgress((s) => n.progress = s), n;
|
|
47
46
|
}
|
|
48
47
|
onProgress(e) {
|
|
49
48
|
return this.listeners.push(e), this;
|
|
50
49
|
}
|
|
51
50
|
then(e, n) {
|
|
52
|
-
const
|
|
53
|
-
return this.from(
|
|
51
|
+
const s = super.then(e, n);
|
|
52
|
+
return this.from(s);
|
|
54
53
|
}
|
|
55
54
|
catch(e) {
|
|
56
55
|
return this.from(super.catch(e));
|
|
@@ -59,7 +58,7 @@ class E extends Promise {
|
|
|
59
58
|
return this.from(super.finally(e));
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
class
|
|
61
|
+
class _ {
|
|
63
62
|
constructor() {
|
|
64
63
|
c(this, "listeners", {});
|
|
65
64
|
}
|
|
@@ -68,17 +67,17 @@ class v {
|
|
|
68
67
|
}
|
|
69
68
|
static off(t, e) {
|
|
70
69
|
const n = t.toString();
|
|
71
|
-
this.listeners[n] = (this.listeners[n] || []).filter((
|
|
70
|
+
this.listeners[n] = (this.listeners[n] || []).filter((s) => s === e);
|
|
72
71
|
}
|
|
73
72
|
static on(t, e) {
|
|
74
|
-
var
|
|
73
|
+
var s;
|
|
75
74
|
const n = t.toString();
|
|
76
|
-
return this.listeners[n] || (this.listeners[n] = []), (
|
|
75
|
+
return this.listeners[n] || (this.listeners[n] = []), (s = this.listeners[n]) == null || s.push(e), () => this.off(t, e);
|
|
77
76
|
}
|
|
78
77
|
static once(t, e) {
|
|
79
78
|
return new Promise((n) => {
|
|
80
|
-
const
|
|
81
|
-
n(
|
|
79
|
+
const s = this.on(t, (...o) => {
|
|
80
|
+
n(o.length == 1 ? o[0] : o), e && e(...o), s();
|
|
82
81
|
});
|
|
83
82
|
});
|
|
84
83
|
}
|
|
@@ -94,13 +93,13 @@ class v {
|
|
|
94
93
|
}
|
|
95
94
|
once(t, e) {
|
|
96
95
|
return new Promise((n) => {
|
|
97
|
-
const
|
|
98
|
-
n(
|
|
96
|
+
const s = this.on(t, (...o) => {
|
|
97
|
+
n(o.length == 1 ? o[0] : o), e && e(...o), s();
|
|
99
98
|
});
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
|
-
c(
|
|
102
|
+
c(_, "listeners", {});
|
|
104
103
|
class p extends Error {
|
|
105
104
|
constructor(e, n) {
|
|
106
105
|
super(e);
|
|
@@ -114,8 +113,8 @@ class p extends Error {
|
|
|
114
113
|
this._code = e;
|
|
115
114
|
}
|
|
116
115
|
static from(e) {
|
|
117
|
-
const n = Number(e.statusCode) ?? Number(e.code),
|
|
118
|
-
return Object.assign(
|
|
116
|
+
const n = Number(e.statusCode) ?? Number(e.code), s = new this(e.message || e.toString());
|
|
117
|
+
return Object.assign(s, {
|
|
119
118
|
stack: e.stack,
|
|
120
119
|
...e,
|
|
121
120
|
code: n ?? void 0
|
|
@@ -129,7 +128,7 @@ class p extends Error {
|
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
c(p, "code", 500);
|
|
132
|
-
class
|
|
131
|
+
class W extends p {
|
|
133
132
|
constructor(t = "Bad Request") {
|
|
134
133
|
super(t);
|
|
135
134
|
}
|
|
@@ -137,8 +136,8 @@ class Y extends p {
|
|
|
137
136
|
return t.constructor.code == this.code;
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
|
-
c(
|
|
141
|
-
class
|
|
139
|
+
c(W, "code", 400);
|
|
140
|
+
class J extends p {
|
|
142
141
|
constructor(t = "Unauthorized") {
|
|
143
142
|
super(t);
|
|
144
143
|
}
|
|
@@ -146,8 +145,8 @@ class H extends p {
|
|
|
146
145
|
return t.constructor.code == this.code;
|
|
147
146
|
}
|
|
148
147
|
}
|
|
149
|
-
c(
|
|
150
|
-
class
|
|
148
|
+
c(J, "code", 401);
|
|
149
|
+
class z extends p {
|
|
151
150
|
constructor(t = "Payment Required") {
|
|
152
151
|
super(t);
|
|
153
152
|
}
|
|
@@ -155,8 +154,8 @@ class W extends p {
|
|
|
155
154
|
return t.constructor.code == this.code;
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
|
-
c(
|
|
159
|
-
class
|
|
157
|
+
c(z, "code", 402);
|
|
158
|
+
class K extends p {
|
|
160
159
|
constructor(t = "Forbidden") {
|
|
161
160
|
super(t);
|
|
162
161
|
}
|
|
@@ -164,8 +163,8 @@ class z extends p {
|
|
|
164
163
|
return t.constructor.code == this.code;
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
|
-
c(
|
|
168
|
-
class
|
|
166
|
+
c(K, "code", 403);
|
|
167
|
+
class Z extends p {
|
|
169
168
|
constructor(t = "Not Found") {
|
|
170
169
|
super(t);
|
|
171
170
|
}
|
|
@@ -173,8 +172,8 @@ class K extends p {
|
|
|
173
172
|
return t.constructor.code == this.code;
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
|
-
c(
|
|
177
|
-
class
|
|
175
|
+
c(Z, "code", 404);
|
|
176
|
+
class V extends p {
|
|
178
177
|
constructor(t = "Method Not Allowed") {
|
|
179
178
|
super(t);
|
|
180
179
|
}
|
|
@@ -182,8 +181,8 @@ class J extends p {
|
|
|
182
181
|
return t.constructor.code == this.code;
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
|
-
c(
|
|
186
|
-
class
|
|
184
|
+
c(V, "code", 405);
|
|
185
|
+
class X extends p {
|
|
187
186
|
constructor(t = "Not Acceptable") {
|
|
188
187
|
super(t);
|
|
189
188
|
}
|
|
@@ -191,8 +190,8 @@ class Z extends p {
|
|
|
191
190
|
return t.constructor.code == this.code;
|
|
192
191
|
}
|
|
193
192
|
}
|
|
194
|
-
c(
|
|
195
|
-
class
|
|
193
|
+
c(X, "code", 406);
|
|
194
|
+
class Q extends p {
|
|
196
195
|
constructor(t = "Internal Server Error") {
|
|
197
196
|
super(t);
|
|
198
197
|
}
|
|
@@ -200,8 +199,8 @@ class V extends p {
|
|
|
200
199
|
return t.constructor.code == this.code;
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
|
-
c(
|
|
204
|
-
class
|
|
202
|
+
c(Q, "code", 500);
|
|
203
|
+
class tt extends p {
|
|
205
204
|
constructor(t = "Not Implemented") {
|
|
206
205
|
super(t);
|
|
207
206
|
}
|
|
@@ -209,8 +208,8 @@ class X extends p {
|
|
|
209
208
|
return t.constructor.code == this.code;
|
|
210
209
|
}
|
|
211
210
|
}
|
|
212
|
-
c(
|
|
213
|
-
class
|
|
211
|
+
c(tt, "code", 501);
|
|
212
|
+
class et extends p {
|
|
214
213
|
constructor(t = "Bad Gateway") {
|
|
215
214
|
super(t);
|
|
216
215
|
}
|
|
@@ -218,8 +217,8 @@ class Q extends p {
|
|
|
218
217
|
return t.constructor.code == this.code;
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
|
-
c(
|
|
222
|
-
class
|
|
220
|
+
c(et, "code", 502);
|
|
221
|
+
class rt extends p {
|
|
223
222
|
constructor(t = "Service Unavailable") {
|
|
224
223
|
super(t);
|
|
225
224
|
}
|
|
@@ -227,8 +226,8 @@ class _ extends p {
|
|
|
227
226
|
return t.constructor.code == this.code;
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
|
-
c(
|
|
231
|
-
class
|
|
229
|
+
c(rt, "code", 503);
|
|
230
|
+
class nt extends p {
|
|
232
231
|
constructor(t = "Gateway Timeout") {
|
|
233
232
|
super(t);
|
|
234
233
|
}
|
|
@@ -236,35 +235,34 @@ class tt extends p {
|
|
|
236
235
|
return t.constructor.code == this.code;
|
|
237
236
|
}
|
|
238
237
|
}
|
|
239
|
-
c(
|
|
240
|
-
function
|
|
241
|
-
if (r >= 200 && r < 300)
|
|
242
|
-
return null;
|
|
238
|
+
c(nt, "code", 504);
|
|
239
|
+
function Yt(r, t) {
|
|
240
|
+
if (r >= 200 && r < 300) return null;
|
|
243
241
|
switch (r) {
|
|
244
242
|
case 400:
|
|
245
|
-
return new
|
|
243
|
+
return new W(t);
|
|
246
244
|
case 401:
|
|
247
|
-
return new
|
|
245
|
+
return new J(t);
|
|
248
246
|
case 402:
|
|
249
|
-
return new W(t);
|
|
250
|
-
case 403:
|
|
251
247
|
return new z(t);
|
|
252
|
-
case
|
|
248
|
+
case 403:
|
|
253
249
|
return new K(t);
|
|
250
|
+
case 404:
|
|
251
|
+
return new Z(t);
|
|
254
252
|
case 405:
|
|
255
|
-
return new
|
|
253
|
+
return new V(t);
|
|
256
254
|
case 406:
|
|
257
|
-
return new
|
|
255
|
+
return new X(t);
|
|
258
256
|
case 500:
|
|
259
|
-
return new
|
|
257
|
+
return new Q(t);
|
|
260
258
|
case 501:
|
|
261
|
-
return new
|
|
259
|
+
return new tt(t);
|
|
262
260
|
case 502:
|
|
263
|
-
return new
|
|
261
|
+
return new et(t);
|
|
264
262
|
case 503:
|
|
265
|
-
return new
|
|
263
|
+
return new rt(t);
|
|
266
264
|
case 504:
|
|
267
|
-
return new
|
|
265
|
+
return new nt(t);
|
|
268
266
|
default:
|
|
269
267
|
return new p(t, r);
|
|
270
268
|
}
|
|
@@ -289,60 +287,58 @@ const w = class w2 {
|
|
|
289
287
|
};
|
|
290
288
|
}
|
|
291
289
|
request(t = {}) {
|
|
292
|
-
var
|
|
293
|
-
if (!this.url && !t.url)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
e += (e.includes("?") ? "&" : "?") + s.map((i) => `${i.key}=${i.value}`).join("&");
|
|
290
|
+
var s;
|
|
291
|
+
if (!this.url && !t.url) throw new Error("URL needs to be set");
|
|
292
|
+
let e = ((s = t.url) != null && s.startsWith("http") ? t.url : (this.url || "") + (t.url || "")).replace(/([^:]\/)\/+/g, "$1");
|
|
293
|
+
if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (o, i) => `#${t.fragment}${i}`) : e += "#" + t.fragment), t.query) {
|
|
294
|
+
const o = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((i) => ({ key: i, value: t.query[i] }));
|
|
295
|
+
e += (e.includes("?") ? "&" : "?") + o.map((i) => `${i.key}=${i.value}`).join("&");
|
|
299
296
|
}
|
|
300
|
-
const n =
|
|
297
|
+
const n = ut({
|
|
301
298
|
"Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
|
|
302
299
|
...w2.headers,
|
|
303
300
|
...this.headers,
|
|
304
301
|
...t.headers
|
|
305
302
|
});
|
|
306
|
-
return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((
|
|
303
|
+
return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((o, i, a) => {
|
|
307
304
|
fetch(e, {
|
|
308
305
|
headers: n,
|
|
309
306
|
method: t.method || (t.body ? "POST" : "GET"),
|
|
310
307
|
body: t.body
|
|
311
308
|
}).then(async (u) => {
|
|
312
|
-
var
|
|
313
|
-
for (let
|
|
314
|
-
await new Promise((
|
|
315
|
-
const
|
|
316
|
-
let
|
|
317
|
-
const
|
|
318
|
-
start(
|
|
319
|
-
function
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}).catch((B) => a.error(B));
|
|
309
|
+
var G, U;
|
|
310
|
+
for (let l of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
|
|
311
|
+
await new Promise((R) => l(u, () => R()));
|
|
312
|
+
const v = u.headers.get("Content-Length"), N = v ? parseInt(v, 10) : 0;
|
|
313
|
+
let P = 0;
|
|
314
|
+
const I = (G = u.body) == null ? void 0 : G.getReader(), ot = new ReadableStream({
|
|
315
|
+
start(l) {
|
|
316
|
+
function R() {
|
|
317
|
+
I == null || I.read().then((O) => {
|
|
318
|
+
if (O.done) return l.close();
|
|
319
|
+
P += O.value.byteLength, a(P / N), l.enqueue(O.value), R();
|
|
320
|
+
}).catch((O) => l.error(O));
|
|
325
321
|
}
|
|
326
|
-
|
|
322
|
+
R();
|
|
327
323
|
}
|
|
328
324
|
});
|
|
329
|
-
if (u.data = new Response(
|
|
330
|
-
const
|
|
331
|
-
|
|
325
|
+
if (u.data = new Response(ot), t.decode == null || t.decode) {
|
|
326
|
+
const l = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
|
|
327
|
+
l != null && l.includes("form") ? u.data = await u.data.formData() : l != null && l.includes("json") ? u.data = await u.data.json() : l != null && l.includes("text") ? u.data = await u.data.text() : l != null && l.includes("application") && (u.data = await u.data.blob());
|
|
332
328
|
}
|
|
333
|
-
u.ok ?
|
|
329
|
+
u.ok ? o(u) : i(u);
|
|
334
330
|
});
|
|
335
331
|
});
|
|
336
332
|
}
|
|
337
333
|
};
|
|
338
334
|
c(w, "interceptors", {}), c(w, "headers", {});
|
|
339
|
-
function
|
|
335
|
+
function Ht(r) {
|
|
340
336
|
const t = r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
341
|
-
return
|
|
337
|
+
return M(decodeURIComponent(atob(t).split("").map(function(e) {
|
|
342
338
|
return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2);
|
|
343
339
|
}).join("")));
|
|
344
340
|
}
|
|
345
|
-
const
|
|
341
|
+
const x = {
|
|
346
342
|
CLEAR: "\x1B[0m",
|
|
347
343
|
BRIGHT: "\x1B[1m",
|
|
348
344
|
DIM: "\x1B[2m",
|
|
@@ -350,7 +346,7 @@ const S = {
|
|
|
350
346
|
BLINK: "\x1B[5m",
|
|
351
347
|
REVERSE: "\x1B[7m",
|
|
352
348
|
HIDDEN: "\x1B[8m"
|
|
353
|
-
},
|
|
349
|
+
}, j = {
|
|
354
350
|
BLACK: "\x1B[30m",
|
|
355
351
|
RED: "\x1B[31m",
|
|
356
352
|
GREEN: "\x1B[32m",
|
|
@@ -368,60 +364,186 @@ const S = {
|
|
|
368
364
|
LIGHT_CYAN: "\x1B[96m",
|
|
369
365
|
WHITE: "\x1B[97m"
|
|
370
366
|
};
|
|
371
|
-
const g = class g2 extends
|
|
367
|
+
const g = class g2 extends _ {
|
|
372
368
|
constructor(t) {
|
|
373
369
|
super(), this.namespace = t;
|
|
374
370
|
}
|
|
375
|
-
pad(t, e, n,
|
|
376
|
-
const
|
|
377
|
-
if (i <= 0)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return o ? s + y : y + s;
|
|
371
|
+
pad(t, e, n, s = false) {
|
|
372
|
+
const o = t.toString(), i = e - o.length;
|
|
373
|
+
if (i <= 0) return o;
|
|
374
|
+
const a = Array(~~(i / n.length)).fill(n).join("");
|
|
375
|
+
return s ? o + a : a + o;
|
|
381
376
|
}
|
|
382
377
|
format(...t) {
|
|
383
378
|
const e = /* @__PURE__ */ new Date();
|
|
384
379
|
return `${`${e.getFullYear()}-${e.getMonth() + 1}-${e.getDate()} ${this.pad(e.getHours().toString(), 2, "0")}:${this.pad(e.getMinutes().toString(), 2, "0")}:${this.pad(e.getSeconds().toString(), 2, "0")}.${this.pad(e.getMilliseconds().toString(), 3, "0", true)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${t.join(" ")}`;
|
|
385
380
|
}
|
|
386
381
|
debug(...t) {
|
|
387
|
-
if (g2.LOG_LEVEL < 4)
|
|
388
|
-
return;
|
|
382
|
+
if (g2.LOG_LEVEL < 4) return;
|
|
389
383
|
const e = this.format(...t);
|
|
390
|
-
g2.emit(4, e), console.debug(
|
|
384
|
+
g2.emit(4, e), console.debug(j.LIGHT_GREY + e + x.CLEAR);
|
|
391
385
|
}
|
|
392
386
|
log(...t) {
|
|
393
|
-
if (g2.LOG_LEVEL < 3)
|
|
394
|
-
return;
|
|
387
|
+
if (g2.LOG_LEVEL < 3) return;
|
|
395
388
|
const e = this.format(...t);
|
|
396
|
-
g2.emit(3, e), console.log(
|
|
389
|
+
g2.emit(3, e), console.log(x.CLEAR + e);
|
|
397
390
|
}
|
|
398
391
|
info(...t) {
|
|
399
|
-
if (g2.LOG_LEVEL < 2)
|
|
400
|
-
return;
|
|
392
|
+
if (g2.LOG_LEVEL < 2) return;
|
|
401
393
|
const e = this.format(...t);
|
|
402
|
-
g2.emit(2, e), console.info(
|
|
394
|
+
g2.emit(2, e), console.info(j.BLUE + e + x.CLEAR);
|
|
403
395
|
}
|
|
404
396
|
warn(...t) {
|
|
405
|
-
if (g2.LOG_LEVEL < 1)
|
|
406
|
-
return;
|
|
397
|
+
if (g2.LOG_LEVEL < 1) return;
|
|
407
398
|
const e = this.format(...t);
|
|
408
|
-
g2.emit(1, e), console.warn(
|
|
399
|
+
g2.emit(1, e), console.warn(j.YELLOW + e + x.CLEAR);
|
|
409
400
|
}
|
|
410
401
|
error(...t) {
|
|
411
|
-
if (g2.LOG_LEVEL < 0)
|
|
412
|
-
return;
|
|
402
|
+
if (g2.LOG_LEVEL < 0) return;
|
|
413
403
|
const e = this.format(...t);
|
|
414
|
-
g2.emit(0, e), console.error(
|
|
404
|
+
g2.emit(0, e), console.error(j.RED + e + x.CLEAR);
|
|
415
405
|
}
|
|
416
406
|
};
|
|
417
407
|
c(g, "LOG_LEVEL", 4);
|
|
418
|
-
function
|
|
408
|
+
function Ot(r) {
|
|
419
409
|
return new Promise((t) => setTimeout(t, r));
|
|
420
410
|
}
|
|
421
|
-
async function
|
|
422
|
-
for (; await r(); )
|
|
423
|
-
await mt(t);
|
|
411
|
+
async function ie(r, t = 100) {
|
|
412
|
+
for (; await r(); ) await Ot(t);
|
|
424
413
|
}
|
|
414
|
+
var $ = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, xt = {}, S = {};
|
|
415
|
+
Object.defineProperty(S, "__esModule", { value: true });
|
|
416
|
+
S.persist = S.Persist = void 0;
|
|
417
|
+
class st {
|
|
418
|
+
/**
|
|
419
|
+
* @param {string} key Primary key value will be stored under
|
|
420
|
+
* @param {PersistOptions<T>} options Configure using {@link PersistOptions}
|
|
421
|
+
*/
|
|
422
|
+
constructor(t, e = {}) {
|
|
423
|
+
c(this, "key");
|
|
424
|
+
c(this, "options");
|
|
425
|
+
c(this, "storage");
|
|
426
|
+
c(this, "watches", {});
|
|
427
|
+
c(this, "_value");
|
|
428
|
+
this.key = t, this.options = e, this.storage = e.storage || localStorage, this.load();
|
|
429
|
+
}
|
|
430
|
+
/** Current value or default if undefined */
|
|
431
|
+
get value() {
|
|
432
|
+
var t;
|
|
433
|
+
return this._value !== void 0 ? this._value : (t = this.options) == null ? void 0 : t.default;
|
|
434
|
+
}
|
|
435
|
+
/** Set value with proxy object wrapper to sync future changes */
|
|
436
|
+
set value(t) {
|
|
437
|
+
t == null || typeof t != "object" ? this._value = t : this._value = new Proxy(t, {
|
|
438
|
+
get: (e, n) => typeof e[n] == "function" ? (...o) => {
|
|
439
|
+
const i = e[n](...o);
|
|
440
|
+
return this.save(), i;
|
|
441
|
+
} : e[n],
|
|
442
|
+
set: (e, n, s) => (e[n] = s, this.save(), true)
|
|
443
|
+
}), this.save();
|
|
444
|
+
}
|
|
445
|
+
/** Notify listeners of change */
|
|
446
|
+
notify(t) {
|
|
447
|
+
Object.values(this.watches).forEach((e) => e(t));
|
|
448
|
+
}
|
|
449
|
+
/** Delete value from storage */
|
|
450
|
+
clear() {
|
|
451
|
+
this.storage.removeItem(this.key);
|
|
452
|
+
}
|
|
453
|
+
/** Save current value to storage */
|
|
454
|
+
save() {
|
|
455
|
+
this._value === void 0 ? this.clear() : this.storage.setItem(this.key, JSON.stringify(this._value)), this.notify(this.value);
|
|
456
|
+
}
|
|
457
|
+
/** Load value from storage */
|
|
458
|
+
load() {
|
|
459
|
+
if (this.storage[this.key] != null) {
|
|
460
|
+
let t = JSON.parse(this.storage.getItem(this.key));
|
|
461
|
+
t != null && typeof t == "object" && this.options.type && (t.__proto__ = this.options.type.prototype), this.value = t;
|
|
462
|
+
} else
|
|
463
|
+
this.value = this.options.default || void 0;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Callback function which is run when there are changes
|
|
467
|
+
*
|
|
468
|
+
* @param {(value: T) => any} fn Callback will run on each change; it's passed the next value & it's return is ignored
|
|
469
|
+
* @returns {() => void} Function which will unsubscribe the watch/callback when called
|
|
470
|
+
*/
|
|
471
|
+
watch(t) {
|
|
472
|
+
const e = Object.keys(this.watches).length;
|
|
473
|
+
return this.watches[e] = t, () => {
|
|
474
|
+
delete this.watches[e];
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Return value as JSON string
|
|
479
|
+
*
|
|
480
|
+
* @returns {string} Stringified object as JSON
|
|
481
|
+
*/
|
|
482
|
+
toString() {
|
|
483
|
+
return JSON.stringify(this.value);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Return current value
|
|
487
|
+
*
|
|
488
|
+
* @returns {T} Current value
|
|
489
|
+
*/
|
|
490
|
+
valueOf() {
|
|
491
|
+
return this.value;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
S.Persist = st;
|
|
495
|
+
function Bt(r) {
|
|
496
|
+
return (t, e) => {
|
|
497
|
+
const n = (r == null ? void 0 : r.key) || `${t.constructor.name}.${e.toString()}`, s = new st(n, r);
|
|
498
|
+
Object.defineProperty(t, e, {
|
|
499
|
+
get: function() {
|
|
500
|
+
return s.value;
|
|
501
|
+
},
|
|
502
|
+
set: function(o) {
|
|
503
|
+
s.value = o;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
S.persist = Bt;
|
|
509
|
+
var L = {};
|
|
510
|
+
Object.defineProperty(L, "__esModule", { value: true });
|
|
511
|
+
L.MemoryStorage = void 0;
|
|
512
|
+
class At {
|
|
513
|
+
get length() {
|
|
514
|
+
return Object.keys(this).length;
|
|
515
|
+
}
|
|
516
|
+
clear() {
|
|
517
|
+
Object.keys(this).forEach((t) => this.removeItem(t));
|
|
518
|
+
}
|
|
519
|
+
getItem(t) {
|
|
520
|
+
return this[t];
|
|
521
|
+
}
|
|
522
|
+
key(t) {
|
|
523
|
+
return Object.keys(this)[t];
|
|
524
|
+
}
|
|
525
|
+
removeItem(t) {
|
|
526
|
+
delete this[t];
|
|
527
|
+
}
|
|
528
|
+
setItem(t, e) {
|
|
529
|
+
this[t] = e;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
L.MemoryStorage = At;
|
|
533
|
+
(function(r) {
|
|
534
|
+
var t = $ && $.__createBinding || (Object.create ? function(n, s, o, i) {
|
|
535
|
+
i === void 0 && (i = o);
|
|
536
|
+
var a = Object.getOwnPropertyDescriptor(s, o);
|
|
537
|
+
(!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: true, get: function() {
|
|
538
|
+
return s[o];
|
|
539
|
+
} }), Object.defineProperty(n, i, a);
|
|
540
|
+
} : function(n, s, o, i) {
|
|
541
|
+
i === void 0 && (i = o), n[i] = s[o];
|
|
542
|
+
}), e = $ && $.__exportStar || function(n, s) {
|
|
543
|
+
for (var o in n) o !== "default" && !Object.prototype.hasOwnProperty.call(s, o) && t(s, n, o);
|
|
544
|
+
};
|
|
545
|
+
Object.defineProperty(r, "__esModule", { value: true }), e(S, r), e(L, r);
|
|
546
|
+
})(xt);
|
|
425
547
|
var extendStatics = function(d, b) {
|
|
426
548
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
427
549
|
d2.__proto__ = b2;
|
|
@@ -656,8 +778,7 @@ var timeoutProvider = {
|
|
|
656
778
|
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
657
779
|
},
|
|
658
780
|
clearTimeout: function(handle) {
|
|
659
|
-
|
|
660
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
781
|
+
return clearTimeout(handle);
|
|
661
782
|
},
|
|
662
783
|
delegate: void 0
|
|
663
784
|
};
|
|
@@ -830,8 +951,8 @@ var EMPTY_OBSERVER = {
|
|
|
830
951
|
var observable = function() {
|
|
831
952
|
return typeof Symbol === "function" && Symbol.observable || "@@observable";
|
|
832
953
|
}();
|
|
833
|
-
function identity(
|
|
834
|
-
return
|
|
954
|
+
function identity(x2) {
|
|
955
|
+
return x2;
|
|
835
956
|
}
|
|
836
957
|
function pipeFromArray(fns) {
|
|
837
958
|
if (fns.length === 0) {
|
|
@@ -912,8 +1033,8 @@ var Observable = function() {
|
|
|
912
1033
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
913
1034
|
return new promiseCtor(function(resolve, reject) {
|
|
914
1035
|
var value;
|
|
915
|
-
_this.subscribe(function(
|
|
916
|
-
return value =
|
|
1036
|
+
_this.subscribe(function(x2) {
|
|
1037
|
+
return value = x2;
|
|
917
1038
|
}, function(err) {
|
|
918
1039
|
return reject(err);
|
|
919
1040
|
}, function() {
|
|
@@ -1549,7 +1670,7 @@ class Auth {
|
|
|
1549
1670
|
login(spoke, login, password, twoFactor) {
|
|
1550
1671
|
return fetch(`${this.api.url}login`, {
|
|
1551
1672
|
method: "POST",
|
|
1552
|
-
body:
|
|
1673
|
+
body: $t(ut({
|
|
1553
1674
|
realm: spoke.trim(),
|
|
1554
1675
|
login: login.trim(),
|
|
1555
1676
|
password: password.trim(),
|
|
@@ -1558,7 +1679,7 @@ class Auth {
|
|
|
1558
1679
|
}))
|
|
1559
1680
|
}).then(async (resp) => {
|
|
1560
1681
|
const data = await resp.json().catch(() => ({}));
|
|
1561
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1682
|
+
if (!resp.ok || data["error"]) throw Object.assign(Yt(resp.status, data.error) || {}, data);
|
|
1562
1683
|
this.api.token = data["token"];
|
|
1563
1684
|
return data;
|
|
1564
1685
|
});
|
|
@@ -1571,7 +1692,7 @@ class Auth {
|
|
|
1571
1692
|
loginGuest() {
|
|
1572
1693
|
return fetch(`${this.api.url}guest`).then(async (resp) => {
|
|
1573
1694
|
const data = await resp.json().catch(() => ({}));
|
|
1574
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1695
|
+
if (!resp.ok || data["error"]) throw Object.assign(Yt(resp.status, data.error) || {}, data);
|
|
1575
1696
|
this.api.token = data["token"];
|
|
1576
1697
|
return data;
|
|
1577
1698
|
});
|
|
@@ -1663,11 +1784,11 @@ class Files {
|
|
|
1663
1784
|
data.append("", file, file.name);
|
|
1664
1785
|
return fetch(this.url, {
|
|
1665
1786
|
method: "POST",
|
|
1666
|
-
headers:
|
|
1787
|
+
headers: ut({ "Authorization": this.api.token ? `Bearer ${this.api.token}` : "" }),
|
|
1667
1788
|
body: data
|
|
1668
1789
|
}).then(async (resp) => {
|
|
1669
1790
|
const data2 = await resp.json().catch(() => ({}));
|
|
1670
|
-
if (!resp.ok || data2["error"]) throw Object.assign(
|
|
1791
|
+
if (!resp.ok || data2["error"]) throw Object.assign(Yt(resp.status, data2.error) || {}, data2);
|
|
1671
1792
|
return resp;
|
|
1672
1793
|
});
|
|
1673
1794
|
})).then(async (files2) => {
|
|
@@ -2063,7 +2184,7 @@ class Slice {
|
|
|
2063
2184
|
if (!this.unsubscribe) this.unsubscribe = this.api.socket.sliceEvents(this.slice, (event) => {
|
|
2064
2185
|
const ids = [...event.data.new, ...event.data.changed];
|
|
2065
2186
|
new Slice(this.slice, this.api).select(ids).exec().rows().then((rows) => this.cache = [...this.cache.filter((c2) => c2.id != null && !ids.includes(c2.id)), ...rows]);
|
|
2066
|
-
this.cache = this.cache.filter((
|
|
2187
|
+
this.cache = this.cache.filter((v) => v.id && !event.data.lost.includes(v.id));
|
|
2067
2188
|
});
|
|
2068
2189
|
return this.cache$;
|
|
2069
2190
|
} else if (this.unsubscribe) {
|
|
@@ -2128,22 +2249,20 @@ class Socket {
|
|
|
2128
2249
|
__publicField(this, "listeners", []);
|
|
2129
2250
|
__publicField(this, "reconnect", false);
|
|
2130
2251
|
__publicField(this, "socket");
|
|
2252
|
+
__publicField(this, "_connected", false);
|
|
2131
2253
|
this.api = api;
|
|
2132
2254
|
this.options = options;
|
|
2255
|
+
const url = new URL(this.api.url.replace("http", "ws"));
|
|
2256
|
+
url.port = "9390";
|
|
2133
2257
|
this.options = {
|
|
2134
|
-
url:
|
|
2258
|
+
url: url.origin,
|
|
2135
2259
|
...this.options
|
|
2136
2260
|
};
|
|
2137
2261
|
if (this.options.url !== false)
|
|
2138
2262
|
api.token$.pipe(distinctUntilChanged()).subscribe(() => this.connect());
|
|
2139
2263
|
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
* @return {boolean} true if connected, false if offline
|
|
2143
|
-
*/
|
|
2144
|
-
get open() {
|
|
2145
|
-
var _a;
|
|
2146
|
-
return ((_a = this.socket) == null ? void 0 : _a.readyState) == 1;
|
|
2264
|
+
get connected() {
|
|
2265
|
+
return this._connected;
|
|
2147
2266
|
}
|
|
2148
2267
|
/**
|
|
2149
2268
|
* Add listener for all socket events
|
|
@@ -2159,6 +2278,7 @@ class Socket {
|
|
|
2159
2278
|
* Close socket connection
|
|
2160
2279
|
*/
|
|
2161
2280
|
close() {
|
|
2281
|
+
this._connected = false;
|
|
2162
2282
|
this.reconnect = false;
|
|
2163
2283
|
this.socket.close();
|
|
2164
2284
|
}
|
|
@@ -2168,28 +2288,34 @@ class Socket {
|
|
|
2168
2288
|
* @param {number} timeout Retry interval, defaults to 30s
|
|
2169
2289
|
*/
|
|
2170
2290
|
connect(timeout = 3e4) {
|
|
2171
|
-
if (this.options.url
|
|
2172
|
-
if (this.
|
|
2291
|
+
if (!this.options.url) throw new Error("Socket is disabled");
|
|
2292
|
+
if (this.connected) {
|
|
2173
2293
|
this.reconnect = false;
|
|
2174
2294
|
this.socket.close();
|
|
2175
2295
|
}
|
|
2176
2296
|
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}` : ""));
|
|
2177
|
-
|
|
2178
|
-
if (this.
|
|
2179
|
-
this.socket.close();
|
|
2180
|
-
this.connect();
|
|
2297
|
+
let t = setTimeout(() => {
|
|
2298
|
+
if (this.reconnect && !this.connected) this.connect();
|
|
2181
2299
|
}, timeout);
|
|
2182
|
-
this.socket.onopen = () => {
|
|
2183
|
-
clearTimeout(t);
|
|
2184
|
-
this.reconnect = true;
|
|
2185
|
-
console.debug("Datalynk Socket: Connected");
|
|
2186
|
-
};
|
|
2187
2300
|
this.socket.onmessage = (message) => {
|
|
2188
2301
|
const payload = JSON.parse(message.data);
|
|
2189
|
-
|
|
2302
|
+
if (payload.connected != void 0) {
|
|
2303
|
+
if (payload.connected) {
|
|
2304
|
+
clearTimeout(t);
|
|
2305
|
+
t = null;
|
|
2306
|
+
this._connected = true;
|
|
2307
|
+
this.reconnect = true;
|
|
2308
|
+
console.debug("Datalynk Socket: Connected");
|
|
2309
|
+
} else {
|
|
2310
|
+
throw new Error(`Socket failed to connect: ${payload.error}`);
|
|
2311
|
+
}
|
|
2312
|
+
} else {
|
|
2313
|
+
this.listeners.forEach((l) => l(payload));
|
|
2314
|
+
}
|
|
2190
2315
|
};
|
|
2191
2316
|
this.socket.onclose = () => {
|
|
2192
|
-
|
|
2317
|
+
this._connected = false;
|
|
2318
|
+
if (this.reconnect && !t) this.connect();
|
|
2193
2319
|
console.debug("Datalynk Socket: Disconnected");
|
|
2194
2320
|
};
|
|
2195
2321
|
}
|
|
@@ -2209,14 +2335,15 @@ class Socket {
|
|
|
2209
2335
|
* @return {Unsubscribe} Run returned function to unsubscribe callback
|
|
2210
2336
|
*/
|
|
2211
2337
|
sliceEvents(slice, callback) {
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
})
|
|
2338
|
+
let cancelled = false;
|
|
2339
|
+
ie(() => !this.connected).then(() => {
|
|
2340
|
+
if (!cancelled) this.send({ onSliceEvents: slice });
|
|
2341
|
+
});
|
|
2216
2342
|
const unsubscribe = this.addListener((event) => {
|
|
2217
2343
|
if (event.type == "sliceEvents" && event.data.slice == slice) callback(event);
|
|
2218
2344
|
});
|
|
2219
2345
|
return () => {
|
|
2346
|
+
cancelled = true;
|
|
2220
2347
|
this.send({ offSliceEvents: slice });
|
|
2221
2348
|
unsubscribe();
|
|
2222
2349
|
};
|
|
@@ -2290,7 +2417,7 @@ class Api {
|
|
|
2290
2417
|
/** API Session token */
|
|
2291
2418
|
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2292
2419
|
this.options = options;
|
|
2293
|
-
this.url = `${url}
|
|
2420
|
+
this.url = `${new URL(url).origin}/api/`;
|
|
2294
2421
|
this.options = {
|
|
2295
2422
|
bundleTime: 100,
|
|
2296
2423
|
origin: typeof location !== "undefined" ? location.host : "Unknown",
|
|
@@ -2318,21 +2445,21 @@ class Api {
|
|
|
2318
2445
|
/** Get session info from JWT payload */
|
|
2319
2446
|
get jwtPayload() {
|
|
2320
2447
|
if (!this.token) return null;
|
|
2321
|
-
return
|
|
2448
|
+
return Ht(this.token);
|
|
2322
2449
|
}
|
|
2323
2450
|
_request(req, options = {}) {
|
|
2324
2451
|
return fetch(this.url, {
|
|
2325
2452
|
method: "POST",
|
|
2326
|
-
headers:
|
|
2453
|
+
headers: ut({
|
|
2327
2454
|
Authorization: this.token ? `Bearer ${this.token}` : void 0,
|
|
2328
2455
|
"Content-Type": "application/json"
|
|
2329
2456
|
}),
|
|
2330
2457
|
body: JSON.stringify(Api.translateTokens(req))
|
|
2331
2458
|
}).then(async (resp) => {
|
|
2332
|
-
if (!resp.ok) throw
|
|
2459
|
+
if (!resp.ok) throw Yt(resp.status);
|
|
2333
2460
|
let data = await resp.json();
|
|
2334
2461
|
if (!options.raw) data = Api.translateTokens(data);
|
|
2335
|
-
if (data["error"]) throw Object.assign(
|
|
2462
|
+
if (data["error"]) throw Object.assign(Yt(resp.status, data["error"]) || {}, data);
|
|
2336
2463
|
return data;
|
|
2337
2464
|
});
|
|
2338
2465
|
}
|