@auxilium/datalynk-client 0.6.10 → 0.6.13
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/api.d.ts +14 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +175 -153
- package/dist/index.mjs +175 -153
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,48 +1,55 @@
|
|
|
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 nt = (
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
4
|
+
var rt = Object.defineProperty;
|
|
5
|
+
var nt = (r, t, e) => t in r ? rt(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e;
|
|
6
|
+
var c = (r, t, e) => (nt(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
7
|
+
function ot(r, t = false) {
|
|
8
|
+
if (r == null)
|
|
9
9
|
throw new Error("Cannot clean a NULL value");
|
|
10
|
-
return Array.isArray(
|
|
11
|
-
(t &&
|
|
12
|
-
}),
|
|
10
|
+
return Array.isArray(r) ? r = r.filter((e) => e != null) : Object.entries(r).forEach(([e, n]) => {
|
|
11
|
+
(t && n === void 0 || !t && n == null) && delete r[e];
|
|
12
|
+
}), r;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function St(r) {
|
|
15
15
|
const t = new FormData();
|
|
16
|
-
return Object.entries(
|
|
16
|
+
return Object.entries(r).forEach(([e, n]) => t.append(e, n)), t;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
function T(r) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(r);
|
|
21
|
+
} catch {
|
|
22
|
+
return r;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class E extends Promise {
|
|
19
26
|
constructor(e) {
|
|
20
|
-
super((
|
|
21
|
-
(s) =>
|
|
27
|
+
super((n, o) => e(
|
|
28
|
+
(s) => n(s),
|
|
22
29
|
(s) => o(s),
|
|
23
30
|
(s) => this.progress = s
|
|
24
31
|
));
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
c(this, "listeners", []);
|
|
33
|
+
c(this, "_progress", 0);
|
|
27
34
|
}
|
|
28
35
|
get progress() {
|
|
29
36
|
return this._progress;
|
|
30
37
|
}
|
|
31
38
|
set progress(e) {
|
|
32
|
-
e != this._progress && (this._progress = e, this.listeners.forEach((
|
|
39
|
+
e != this._progress && (this._progress = e, this.listeners.forEach((n) => n(e)));
|
|
33
40
|
}
|
|
34
41
|
static from(e) {
|
|
35
|
-
return e instanceof
|
|
42
|
+
return e instanceof E ? e : new E((n, o) => e.then((...s) => n(...s)).catch((...s) => o(...s)));
|
|
36
43
|
}
|
|
37
44
|
from(e) {
|
|
38
|
-
const
|
|
39
|
-
return this.onProgress((o) =>
|
|
45
|
+
const n = E.from(e);
|
|
46
|
+
return this.onProgress((o) => n.progress = o), n;
|
|
40
47
|
}
|
|
41
48
|
onProgress(e) {
|
|
42
49
|
return this.listeners.push(e), this;
|
|
43
50
|
}
|
|
44
|
-
then(e,
|
|
45
|
-
const o = super.then(e,
|
|
51
|
+
then(e, n) {
|
|
52
|
+
const o = super.then(e, n);
|
|
46
53
|
return this.from(o);
|
|
47
54
|
}
|
|
48
55
|
catch(e) {
|
|
@@ -54,51 +61,51 @@ class m extends Promise {
|
|
|
54
61
|
}
|
|
55
62
|
class v {
|
|
56
63
|
constructor() {
|
|
57
|
-
|
|
64
|
+
c(this, "listeners", {});
|
|
58
65
|
}
|
|
59
66
|
static emit(t, ...e) {
|
|
60
|
-
(this.listeners["*"] || []).forEach((
|
|
67
|
+
(this.listeners["*"] || []).forEach((n) => n(t, ...e)), (this.listeners[t.toString()] || []).forEach((n) => n(...e));
|
|
61
68
|
}
|
|
62
69
|
static off(t, e) {
|
|
63
|
-
const
|
|
64
|
-
this.listeners[
|
|
70
|
+
const n = t.toString();
|
|
71
|
+
this.listeners[n] = (this.listeners[n] || []).filter((o) => o === e);
|
|
65
72
|
}
|
|
66
73
|
static on(t, e) {
|
|
67
74
|
var o;
|
|
68
|
-
const
|
|
69
|
-
return this.listeners[
|
|
75
|
+
const n = t.toString();
|
|
76
|
+
return this.listeners[n] || (this.listeners[n] = []), (o = this.listeners[n]) == null || o.push(e), () => this.off(t, e);
|
|
70
77
|
}
|
|
71
78
|
static once(t, e) {
|
|
72
|
-
return new Promise((
|
|
79
|
+
return new Promise((n) => {
|
|
73
80
|
const o = this.on(t, (...s) => {
|
|
74
|
-
|
|
81
|
+
n(s.length == 1 ? s[0] : s), e && e(...s), o();
|
|
75
82
|
});
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
emit(t, ...e) {
|
|
79
|
-
(this.listeners["*"] || []).forEach((
|
|
86
|
+
(this.listeners["*"] || []).forEach((n) => n(t, ...e)), (this.listeners[t] || []).forEach((n) => n(...e));
|
|
80
87
|
}
|
|
81
88
|
off(t, e) {
|
|
82
|
-
this.listeners[t] = (this.listeners[t] || []).filter((
|
|
89
|
+
this.listeners[t] = (this.listeners[t] || []).filter((n) => n === e);
|
|
83
90
|
}
|
|
84
91
|
on(t, e) {
|
|
85
|
-
var
|
|
86
|
-
return this.listeners[t] || (this.listeners[t] = []), (
|
|
92
|
+
var n;
|
|
93
|
+
return this.listeners[t] || (this.listeners[t] = []), (n = this.listeners[t]) == null || n.push(e), () => this.off(t, e);
|
|
87
94
|
}
|
|
88
95
|
once(t, e) {
|
|
89
|
-
return new Promise((
|
|
96
|
+
return new Promise((n) => {
|
|
90
97
|
const o = this.on(t, (...s) => {
|
|
91
|
-
|
|
98
|
+
n(s.length == 1 ? s[0] : s), e && e(...s), o();
|
|
92
99
|
});
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
|
-
|
|
103
|
+
c(v, "listeners", {});
|
|
97
104
|
class p extends Error {
|
|
98
|
-
constructor(e,
|
|
105
|
+
constructor(e, n) {
|
|
99
106
|
super(e);
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
c(this, "_code");
|
|
108
|
+
n != null && (this._code = n);
|
|
102
109
|
}
|
|
103
110
|
get code() {
|
|
104
111
|
return this._code || this.constructor.code;
|
|
@@ -107,11 +114,11 @@ class p extends Error {
|
|
|
107
114
|
this._code = e;
|
|
108
115
|
}
|
|
109
116
|
static from(e) {
|
|
110
|
-
const
|
|
117
|
+
const n = Number(e.statusCode) ?? Number(e.code), o = new this(e.message || e.toString());
|
|
111
118
|
return Object.assign(o, {
|
|
112
119
|
stack: e.stack,
|
|
113
120
|
...e,
|
|
114
|
-
code:
|
|
121
|
+
code: n ?? void 0
|
|
115
122
|
});
|
|
116
123
|
}
|
|
117
124
|
static instanceof(e) {
|
|
@@ -121,8 +128,8 @@ class p extends Error {
|
|
|
121
128
|
return this.message || super.toString();
|
|
122
129
|
}
|
|
123
130
|
}
|
|
124
|
-
|
|
125
|
-
class
|
|
131
|
+
c(p, "code", 500);
|
|
132
|
+
class Y extends p {
|
|
126
133
|
constructor(t = "Bad Request") {
|
|
127
134
|
super(t);
|
|
128
135
|
}
|
|
@@ -130,7 +137,7 @@ class F extends p {
|
|
|
130
137
|
return t.constructor.code == this.code;
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
|
-
|
|
140
|
+
c(Y, "code", 400);
|
|
134
141
|
class H extends p {
|
|
135
142
|
constructor(t = "Unauthorized") {
|
|
136
143
|
super(t);
|
|
@@ -139,8 +146,8 @@ class H extends p {
|
|
|
139
146
|
return t.constructor.code == this.code;
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
|
-
|
|
143
|
-
class
|
|
149
|
+
c(H, "code", 401);
|
|
150
|
+
class W extends p {
|
|
144
151
|
constructor(t = "Payment Required") {
|
|
145
152
|
super(t);
|
|
146
153
|
}
|
|
@@ -148,8 +155,8 @@ class Y extends p {
|
|
|
148
155
|
return t.constructor.code == this.code;
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
|
-
|
|
152
|
-
class
|
|
158
|
+
c(W, "code", 402);
|
|
159
|
+
class z extends p {
|
|
153
160
|
constructor(t = "Forbidden") {
|
|
154
161
|
super(t);
|
|
155
162
|
}
|
|
@@ -157,8 +164,8 @@ class W extends p {
|
|
|
157
164
|
return t.constructor.code == this.code;
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
|
-
|
|
161
|
-
class
|
|
167
|
+
c(z, "code", 403);
|
|
168
|
+
class K extends p {
|
|
162
169
|
constructor(t = "Not Found") {
|
|
163
170
|
super(t);
|
|
164
171
|
}
|
|
@@ -166,8 +173,8 @@ class J extends p {
|
|
|
166
173
|
return t.constructor.code == this.code;
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
|
-
|
|
170
|
-
class
|
|
176
|
+
c(K, "code", 404);
|
|
177
|
+
class J extends p {
|
|
171
178
|
constructor(t = "Method Not Allowed") {
|
|
172
179
|
super(t);
|
|
173
180
|
}
|
|
@@ -175,8 +182,8 @@ class z extends p {
|
|
|
175
182
|
return t.constructor.code == this.code;
|
|
176
183
|
}
|
|
177
184
|
}
|
|
178
|
-
|
|
179
|
-
class
|
|
185
|
+
c(J, "code", 405);
|
|
186
|
+
class Z extends p {
|
|
180
187
|
constructor(t = "Not Acceptable") {
|
|
181
188
|
super(t);
|
|
182
189
|
}
|
|
@@ -184,7 +191,7 @@ class K extends p {
|
|
|
184
191
|
return t.constructor.code == this.code;
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
|
-
|
|
194
|
+
c(Z, "code", 406);
|
|
188
195
|
class V extends p {
|
|
189
196
|
constructor(t = "Internal Server Error") {
|
|
190
197
|
super(t);
|
|
@@ -193,8 +200,8 @@ class V extends p {
|
|
|
193
200
|
return t.constructor.code == this.code;
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
|
-
|
|
197
|
-
class
|
|
203
|
+
c(V, "code", 500);
|
|
204
|
+
class X extends p {
|
|
198
205
|
constructor(t = "Not Implemented") {
|
|
199
206
|
super(t);
|
|
200
207
|
}
|
|
@@ -202,8 +209,8 @@ class Z extends p {
|
|
|
202
209
|
return t.constructor.code == this.code;
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
|
-
|
|
206
|
-
class
|
|
212
|
+
c(X, "code", 501);
|
|
213
|
+
class Q extends p {
|
|
207
214
|
constructor(t = "Bad Gateway") {
|
|
208
215
|
super(t);
|
|
209
216
|
}
|
|
@@ -211,8 +218,8 @@ class X extends p {
|
|
|
211
218
|
return t.constructor.code == this.code;
|
|
212
219
|
}
|
|
213
220
|
}
|
|
214
|
-
|
|
215
|
-
class
|
|
221
|
+
c(Q, "code", 502);
|
|
222
|
+
class _ extends p {
|
|
216
223
|
constructor(t = "Service Unavailable") {
|
|
217
224
|
super(t);
|
|
218
225
|
}
|
|
@@ -220,8 +227,8 @@ class Q extends p {
|
|
|
220
227
|
return t.constructor.code == this.code;
|
|
221
228
|
}
|
|
222
229
|
}
|
|
223
|
-
|
|
224
|
-
class
|
|
230
|
+
c(_, "code", 503);
|
|
231
|
+
class tt extends p {
|
|
225
232
|
constructor(t = "Gateway Timeout") {
|
|
226
233
|
super(t);
|
|
227
234
|
}
|
|
@@ -229,44 +236,44 @@ class _ extends p {
|
|
|
229
236
|
return t.constructor.code == this.code;
|
|
230
237
|
}
|
|
231
238
|
}
|
|
232
|
-
|
|
233
|
-
function
|
|
234
|
-
if (
|
|
239
|
+
c(tt, "code", 504);
|
|
240
|
+
function kt(r, t) {
|
|
241
|
+
if (r >= 200 && r < 300)
|
|
235
242
|
return null;
|
|
236
|
-
switch (
|
|
243
|
+
switch (r) {
|
|
237
244
|
case 400:
|
|
238
|
-
return new
|
|
245
|
+
return new Y(t);
|
|
239
246
|
case 401:
|
|
240
247
|
return new H(t);
|
|
241
248
|
case 402:
|
|
242
|
-
return new Y(t);
|
|
243
|
-
case 403:
|
|
244
249
|
return new W(t);
|
|
250
|
+
case 403:
|
|
251
|
+
return new z(t);
|
|
245
252
|
case 404:
|
|
246
|
-
return new
|
|
253
|
+
return new K(t);
|
|
247
254
|
case 405:
|
|
248
|
-
return new
|
|
255
|
+
return new J(t);
|
|
249
256
|
case 406:
|
|
250
|
-
return new
|
|
257
|
+
return new Z(t);
|
|
251
258
|
case 500:
|
|
252
259
|
return new V(t);
|
|
253
260
|
case 501:
|
|
254
|
-
return new Z(t);
|
|
255
|
-
case 502:
|
|
256
261
|
return new X(t);
|
|
257
|
-
case
|
|
262
|
+
case 502:
|
|
258
263
|
return new Q(t);
|
|
259
|
-
case
|
|
264
|
+
case 503:
|
|
260
265
|
return new _(t);
|
|
266
|
+
case 504:
|
|
267
|
+
return new tt(t);
|
|
261
268
|
default:
|
|
262
|
-
return new p(t,
|
|
269
|
+
return new p(t, r);
|
|
263
270
|
}
|
|
264
271
|
}
|
|
265
272
|
const w = class w2 {
|
|
266
273
|
constructor(t = {}) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
274
|
+
c(this, "interceptors", {});
|
|
275
|
+
c(this, "headers", {});
|
|
276
|
+
c(this, "url");
|
|
270
277
|
this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => w2.addInterceptor(e));
|
|
271
278
|
}
|
|
272
279
|
static addInterceptor(t) {
|
|
@@ -286,50 +293,56 @@ const w = class w2 {
|
|
|
286
293
|
if (!this.url && !t.url)
|
|
287
294
|
throw new Error("URL needs to be set");
|
|
288
295
|
let e = ((o = t.url) != null && o.startsWith("http") ? t.url : (this.url || "") + (t.url || "")).replace(/([^:]\/)\/+/g, "$1");
|
|
289
|
-
if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (s,
|
|
290
|
-
const s = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((
|
|
291
|
-
e += (e.includes("?") ? "&" : "?") + s.map((
|
|
296
|
+
if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (s, i) => `#${t.fragment}${i}`) : e += "#" + t.fragment), t.query) {
|
|
297
|
+
const s = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((i) => ({ key: i, value: t.query[i] }));
|
|
298
|
+
e += (e.includes("?") ? "&" : "?") + s.map((i) => `${i.key}=${i.value}`).join("&");
|
|
292
299
|
}
|
|
293
|
-
const
|
|
300
|
+
const n = ot({
|
|
294
301
|
"Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
|
|
295
302
|
...w2.headers,
|
|
296
303
|
...this.headers,
|
|
297
304
|
...t.headers
|
|
298
305
|
});
|
|
299
|
-
return typeof t.body == "object" && t.body != null &&
|
|
306
|
+
return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((s, i, y) => {
|
|
300
307
|
fetch(e, {
|
|
301
|
-
headers:
|
|
308
|
+
headers: n,
|
|
302
309
|
method: t.method || (t.body ? "POST" : "GET"),
|
|
303
310
|
body: t.body
|
|
304
311
|
}).then(async (u) => {
|
|
305
|
-
var
|
|
312
|
+
var k, U;
|
|
306
313
|
for (let a of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
|
|
307
314
|
await new Promise((O) => a(u, () => O()));
|
|
308
|
-
const R = u.headers.get("Content-Length"),
|
|
309
|
-
let
|
|
310
|
-
const
|
|
315
|
+
const R = u.headers.get("Content-Length"), L = R ? parseInt(R, 10) : 0;
|
|
316
|
+
let M = 0;
|
|
317
|
+
const N = (k = u.body) == null ? void 0 : k.getReader(), et = new ReadableStream({
|
|
311
318
|
start(a) {
|
|
312
319
|
function O() {
|
|
313
|
-
|
|
314
|
-
if (
|
|
320
|
+
N == null || N.read().then((B) => {
|
|
321
|
+
if (B.done)
|
|
315
322
|
return a.close();
|
|
316
|
-
|
|
317
|
-
}).catch((
|
|
323
|
+
M += B.value.byteLength, y(M / L), a.enqueue(B.value), O();
|
|
324
|
+
}).catch((B) => a.error(B));
|
|
318
325
|
}
|
|
319
326
|
O();
|
|
320
327
|
}
|
|
321
328
|
});
|
|
322
|
-
if (u.data = new Response(
|
|
323
|
-
const a = (
|
|
329
|
+
if (u.data = new Response(et), t.decode == null || t.decode) {
|
|
330
|
+
const a = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
|
|
324
331
|
a != null && a.includes("form") ? u.data = await u.data.formData() : a != null && a.includes("json") ? u.data = await u.data.json() : a != null && a.includes("text") ? u.data = await u.data.text() : a != null && a.includes("application") && (u.data = await u.data.blob());
|
|
325
332
|
}
|
|
326
|
-
u.ok ? s(u) :
|
|
333
|
+
u.ok ? s(u) : i(u);
|
|
327
334
|
});
|
|
328
335
|
});
|
|
329
336
|
}
|
|
330
337
|
};
|
|
331
|
-
|
|
332
|
-
|
|
338
|
+
c(w, "interceptors", {}), c(w, "headers", {});
|
|
339
|
+
function Ut(r) {
|
|
340
|
+
const t = r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
341
|
+
return T(decodeURIComponent(atob(t).split("").map(function(e) {
|
|
342
|
+
return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2);
|
|
343
|
+
}).join("")));
|
|
344
|
+
}
|
|
345
|
+
const S = {
|
|
333
346
|
CLEAR: "\x1B[0m",
|
|
334
347
|
BRIGHT: "\x1B[1m",
|
|
335
348
|
DIM: "\x1B[2m",
|
|
@@ -337,7 +350,7 @@ const A = {
|
|
|
337
350
|
BLINK: "\x1B[5m",
|
|
338
351
|
REVERSE: "\x1B[7m",
|
|
339
352
|
HIDDEN: "\x1B[8m"
|
|
340
|
-
},
|
|
353
|
+
}, C = {
|
|
341
354
|
BLACK: "\x1B[30m",
|
|
342
355
|
RED: "\x1B[31m",
|
|
343
356
|
GREEN: "\x1B[32m",
|
|
@@ -359,11 +372,11 @@ const g = class g2 extends v {
|
|
|
359
372
|
constructor(t) {
|
|
360
373
|
super(), this.namespace = t;
|
|
361
374
|
}
|
|
362
|
-
pad(t, e,
|
|
363
|
-
const s = t.toString(),
|
|
364
|
-
if (
|
|
375
|
+
pad(t, e, n, o = false) {
|
|
376
|
+
const s = t.toString(), i = e - s.length;
|
|
377
|
+
if (i <= 0)
|
|
365
378
|
return s;
|
|
366
|
-
const y = Array(~~(
|
|
379
|
+
const y = Array(~~(i / n.length)).fill(n).join("");
|
|
367
380
|
return o ? s + y : y + s;
|
|
368
381
|
}
|
|
369
382
|
format(...t) {
|
|
@@ -374,40 +387,40 @@ const g = class g2 extends v {
|
|
|
374
387
|
if (g2.LOG_LEVEL < 4)
|
|
375
388
|
return;
|
|
376
389
|
const e = this.format(...t);
|
|
377
|
-
g2.emit(4, e), console.debug(
|
|
390
|
+
g2.emit(4, e), console.debug(C.LIGHT_GREY + e + S.CLEAR);
|
|
378
391
|
}
|
|
379
392
|
log(...t) {
|
|
380
393
|
if (g2.LOG_LEVEL < 3)
|
|
381
394
|
return;
|
|
382
395
|
const e = this.format(...t);
|
|
383
|
-
g2.emit(3, e), console.log(
|
|
396
|
+
g2.emit(3, e), console.log(S.CLEAR + e);
|
|
384
397
|
}
|
|
385
398
|
info(...t) {
|
|
386
399
|
if (g2.LOG_LEVEL < 2)
|
|
387
400
|
return;
|
|
388
401
|
const e = this.format(...t);
|
|
389
|
-
g2.emit(2, e), console.info(
|
|
402
|
+
g2.emit(2, e), console.info(C.BLUE + e + S.CLEAR);
|
|
390
403
|
}
|
|
391
404
|
warn(...t) {
|
|
392
405
|
if (g2.LOG_LEVEL < 1)
|
|
393
406
|
return;
|
|
394
407
|
const e = this.format(...t);
|
|
395
|
-
g2.emit(1, e), console.warn(
|
|
408
|
+
g2.emit(1, e), console.warn(C.YELLOW + e + S.CLEAR);
|
|
396
409
|
}
|
|
397
410
|
error(...t) {
|
|
398
411
|
if (g2.LOG_LEVEL < 0)
|
|
399
412
|
return;
|
|
400
413
|
const e = this.format(...t);
|
|
401
|
-
g2.emit(0, e), console.error(
|
|
414
|
+
g2.emit(0, e), console.error(C.RED + e + S.CLEAR);
|
|
402
415
|
}
|
|
403
416
|
};
|
|
404
|
-
|
|
405
|
-
function
|
|
406
|
-
return new Promise((t) => setTimeout(t,
|
|
417
|
+
c(g, "LOG_LEVEL", 4);
|
|
418
|
+
function mt(r) {
|
|
419
|
+
return new Promise((t) => setTimeout(t, r));
|
|
407
420
|
}
|
|
408
|
-
async function
|
|
409
|
-
for (;
|
|
410
|
-
await
|
|
421
|
+
async function _t(r, t = 100) {
|
|
422
|
+
for (; await r(); )
|
|
423
|
+
await mt(t);
|
|
411
424
|
}
|
|
412
425
|
var extendStatics = function(d, b) {
|
|
413
426
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
@@ -427,27 +440,27 @@ function __extends(d, b) {
|
|
|
427
440
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
428
441
|
}
|
|
429
442
|
function __values(o) {
|
|
430
|
-
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
431
|
-
if (
|
|
443
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
444
|
+
if (m) return m.call(o);
|
|
432
445
|
if (o && typeof o.length === "number") return {
|
|
433
446
|
next: function() {
|
|
434
|
-
if (o &&
|
|
435
|
-
return { value: o && o[
|
|
447
|
+
if (o && i >= o.length) o = void 0;
|
|
448
|
+
return { value: o && o[i++], done: !o };
|
|
436
449
|
}
|
|
437
450
|
};
|
|
438
451
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
439
452
|
}
|
|
440
453
|
function __read(o, n) {
|
|
441
|
-
var
|
|
442
|
-
if (!
|
|
443
|
-
var
|
|
454
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
455
|
+
if (!m) return o;
|
|
456
|
+
var i = m.call(o), r, ar = [], e;
|
|
444
457
|
try {
|
|
445
|
-
while ((n === void 0 || n-- > 0) && !(r =
|
|
458
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
446
459
|
} catch (error) {
|
|
447
460
|
e = { error };
|
|
448
461
|
} finally {
|
|
449
462
|
try {
|
|
450
|
-
if (r && !r.done && (
|
|
463
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
451
464
|
} finally {
|
|
452
465
|
if (e) throw e.error;
|
|
453
466
|
}
|
|
@@ -455,10 +468,10 @@ function __read(o, n) {
|
|
|
455
468
|
return ar;
|
|
456
469
|
}
|
|
457
470
|
function __spreadArray(to, from, pack) {
|
|
458
|
-
if (pack || arguments.length === 2) for (var
|
|
459
|
-
if (ar || !(
|
|
460
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0,
|
|
461
|
-
ar[
|
|
471
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
472
|
+
if (ar || !(i in from)) {
|
|
473
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
474
|
+
ar[i] = from[i];
|
|
462
475
|
}
|
|
463
476
|
}
|
|
464
477
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
@@ -483,8 +496,8 @@ function createErrorClass(createImpl) {
|
|
|
483
496
|
var UnsubscriptionError = createErrorClass(function(_super) {
|
|
484
497
|
return function UnsubscriptionErrorImpl(errors) {
|
|
485
498
|
_super(this);
|
|
486
|
-
this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err,
|
|
487
|
-
return
|
|
499
|
+
this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) {
|
|
500
|
+
return i + 1 + ") " + err.toString();
|
|
488
501
|
}).join("\n ") : "";
|
|
489
502
|
this.name = "UnsubscriptionError";
|
|
490
503
|
this.errors = errors;
|
|
@@ -1441,6 +1454,10 @@ class Auth {
|
|
|
1441
1454
|
set user(user) {
|
|
1442
1455
|
this.user$.next(user);
|
|
1443
1456
|
}
|
|
1457
|
+
get spoke() {
|
|
1458
|
+
var _a;
|
|
1459
|
+
return ((_a = this.api.jwtPayload) == null ? void 0 : _a.realm) || null;
|
|
1460
|
+
}
|
|
1444
1461
|
/**
|
|
1445
1462
|
* Get current user associated with API token
|
|
1446
1463
|
*
|
|
@@ -1532,7 +1549,7 @@ class Auth {
|
|
|
1532
1549
|
login(spoke, login, password, twoFactor) {
|
|
1533
1550
|
return fetch(`${this.api.url}login`, {
|
|
1534
1551
|
method: "POST",
|
|
1535
|
-
body:
|
|
1552
|
+
body: St(ot({
|
|
1536
1553
|
realm: spoke.trim(),
|
|
1537
1554
|
login: login.trim(),
|
|
1538
1555
|
password: password.trim(),
|
|
@@ -1541,7 +1558,7 @@ class Auth {
|
|
|
1541
1558
|
}))
|
|
1542
1559
|
}).then(async (resp) => {
|
|
1543
1560
|
const data = await resp.json().catch(() => ({}));
|
|
1544
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1561
|
+
if (!resp.ok || data["error"]) throw Object.assign(kt(resp.status, data.error) || {}, data);
|
|
1545
1562
|
this.api.token = data["token"];
|
|
1546
1563
|
return data;
|
|
1547
1564
|
});
|
|
@@ -1554,7 +1571,7 @@ class Auth {
|
|
|
1554
1571
|
loginGuest() {
|
|
1555
1572
|
return fetch(`${this.api.url}guest`).then(async (resp) => {
|
|
1556
1573
|
const data = await resp.json().catch(() => ({}));
|
|
1557
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1574
|
+
if (!resp.ok || data["error"]) throw Object.assign(kt(resp.status, data.error) || {}, data);
|
|
1558
1575
|
this.api.token = data["token"];
|
|
1559
1576
|
return data;
|
|
1560
1577
|
});
|
|
@@ -1646,11 +1663,11 @@ class Files {
|
|
|
1646
1663
|
data.append("", file, file.name);
|
|
1647
1664
|
return fetch(this.url, {
|
|
1648
1665
|
method: "POST",
|
|
1649
|
-
headers:
|
|
1666
|
+
headers: ot({ "Authorization": this.api.token ? `Bearer ${this.api.token}` : "" }),
|
|
1650
1667
|
body: data
|
|
1651
1668
|
}).then(async (resp) => {
|
|
1652
1669
|
const data2 = await resp.json().catch(() => ({}));
|
|
1653
|
-
if (!resp.ok || data2["error"]) throw Object.assign(
|
|
1670
|
+
if (!resp.ok || data2["error"]) throw Object.assign(kt(resp.status, data2.error) || {}, data2);
|
|
1654
1671
|
return resp;
|
|
1655
1672
|
});
|
|
1656
1673
|
})).then(async (files2) => {
|
|
@@ -1751,22 +1768,22 @@ const Serializer = {
|
|
|
1751
1768
|
let meta = obj["meta"];
|
|
1752
1769
|
let col;
|
|
1753
1770
|
let fn = [];
|
|
1754
|
-
for (let
|
|
1755
|
-
col = meta[
|
|
1771
|
+
for (let i in meta) {
|
|
1772
|
+
col = meta[i];
|
|
1756
1773
|
fn.push("this['" + col.name + "'] = ");
|
|
1757
1774
|
if (col.cast == null) {
|
|
1758
|
-
fn.push("a[" +
|
|
1775
|
+
fn.push("a[" + i + "];\n");
|
|
1759
1776
|
} else if (col.cast === "num") {
|
|
1760
|
-
fn.push("a[" +
|
|
1777
|
+
fn.push("a[" + i + "] && parseFloat(a[" + i + "]);\n");
|
|
1761
1778
|
} else {
|
|
1762
1779
|
if (col["native"] === "date") {
|
|
1763
|
-
fn.push("a[" +
|
|
1764
|
-
fn.push("a[" +
|
|
1780
|
+
fn.push("a[" + i + "] && dateParse(a[" + i + "]);\n");
|
|
1781
|
+
fn.push("a[" + i + "] && (this['" + col.name + "'].hint = 'date');\n");
|
|
1765
1782
|
} else if (col["native"] === "time") {
|
|
1766
|
-
fn.push("a[" +
|
|
1767
|
-
fn.push("a[" +
|
|
1783
|
+
fn.push("a[" + i + "] && timeParse(a[" + i + "]);\n");
|
|
1784
|
+
fn.push("a[" + i + "] && (this['" + col.name + "'].hint = 'time');\n");
|
|
1768
1785
|
} else {
|
|
1769
|
-
fn.push("a[" +
|
|
1786
|
+
fn.push("a[" + i + "] && datetimeParse(a[" + i + "]);\n");
|
|
1770
1787
|
}
|
|
1771
1788
|
}
|
|
1772
1789
|
}
|
|
@@ -1794,8 +1811,8 @@ const Serializer = {
|
|
|
1794
1811
|
let ctor = Function("datetimeParse", "dateParse", "timeParse", "a", fn.join(""));
|
|
1795
1812
|
let res = [];
|
|
1796
1813
|
let rows = obj["rows"];
|
|
1797
|
-
for (let
|
|
1798
|
-
res[
|
|
1814
|
+
for (let i in rows) {
|
|
1815
|
+
res[i] = new ctor(dateTimeParse, dateParse, timeParse, rows[i]);
|
|
1799
1816
|
}
|
|
1800
1817
|
res["meta"] = meta;
|
|
1801
1818
|
res["rowConstructor"] = ctor;
|
|
@@ -2045,7 +2062,7 @@ class Slice {
|
|
|
2045
2062
|
new Slice(this.slice, this.api).select().exec().rows().then((rows) => this.cache = rows);
|
|
2046
2063
|
if (!this.unsubscribe) this.unsubscribe = this.api.socket.sliceEvents(this.slice, (event) => {
|
|
2047
2064
|
const ids = [...event.data.insert, ...event.data.update];
|
|
2048
|
-
new Slice(this.slice, this.api).select(ids).exec().rows().then((rows) => this.cache = [...this.cache.filter((
|
|
2065
|
+
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]);
|
|
2049
2066
|
this.cache = this.cache.filter((v2) => v2.id && !event.data.remove.includes(v2.id));
|
|
2050
2067
|
});
|
|
2051
2068
|
return this.cache$;
|
|
@@ -2192,7 +2209,7 @@ class Socket {
|
|
|
2192
2209
|
* @return {Unsubscribe} Run returned function to unsubscribe callback
|
|
2193
2210
|
*/
|
|
2194
2211
|
sliceEvents(slice, callback) {
|
|
2195
|
-
|
|
2212
|
+
_t(() => {
|
|
2196
2213
|
var _a;
|
|
2197
2214
|
return ((_a = this.socket) == null ? void 0 : _a.readyState) != 1;
|
|
2198
2215
|
}).then(() => this.send({ onSliceEvents: slice }));
|
|
@@ -2298,19 +2315,24 @@ class Api {
|
|
|
2298
2315
|
set token(token) {
|
|
2299
2316
|
this.token$.next(token);
|
|
2300
2317
|
}
|
|
2318
|
+
/** Get session info from JWT payload */
|
|
2319
|
+
get jwtPayload() {
|
|
2320
|
+
if (!this.token) return null;
|
|
2321
|
+
return Ut(this.token);
|
|
2322
|
+
}
|
|
2301
2323
|
_request(req, options = {}) {
|
|
2302
2324
|
return fetch(this.url, {
|
|
2303
2325
|
method: "POST",
|
|
2304
|
-
headers:
|
|
2326
|
+
headers: ot({
|
|
2305
2327
|
Authorization: this.token ? `Bearer ${this.token}` : void 0,
|
|
2306
2328
|
"Content-Type": "application/json"
|
|
2307
2329
|
}),
|
|
2308
2330
|
body: JSON.stringify(Api.translateTokens(req))
|
|
2309
2331
|
}).then(async (resp) => {
|
|
2310
|
-
if (!resp.ok) throw
|
|
2332
|
+
if (!resp.ok) throw kt(resp.status);
|
|
2311
2333
|
let data = await resp.json();
|
|
2312
2334
|
if (!options.raw) data = Api.translateTokens(data);
|
|
2313
|
-
if (data["error"]) throw Object.assign(
|
|
2335
|
+
if (data["error"]) throw Object.assign(kt(resp.status, data["error"]) || {}, data);
|
|
2314
2336
|
return data;
|
|
2315
2337
|
});
|
|
2316
2338
|
}
|
|
@@ -2374,7 +2396,7 @@ class Api {
|
|
|
2374
2396
|
data = originalBundle.map((row) => row.data);
|
|
2375
2397
|
this._request(data, options).then((resp) => {
|
|
2376
2398
|
if (!(resp instanceof Array)) resp = [resp];
|
|
2377
|
-
resp.filter((ignore,
|
|
2399
|
+
resp.filter((ignore, i) => i < originalBundle.length).forEach((row, i) => row.error ? originalBundle[i].rej(row.error) : originalBundle[i].res(row));
|
|
2378
2400
|
}).catch((err) => originalBundle.forEach((req) => req.rej(err)));
|
|
2379
2401
|
}, this.options.bundleTime);
|
|
2380
2402
|
}
|