@auxilium/datalynk-client 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +388 -465
- package/dist/index.mjs +386 -463
- package/dist/socket.d.ts +4 -6
- package/dist/socket.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,344 +1,400 @@
|
|
|
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
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
var __defProp2 = Object.defineProperty;
|
|
5
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
function clean(obj, undefinedOnly = false) {
|
|
8
|
+
if (obj == null) throw new Error("Cannot clean a NULL value");
|
|
9
|
+
if (Array.isArray(obj)) {
|
|
10
|
+
obj = obj.filter((o) => o != null);
|
|
11
|
+
} else {
|
|
12
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
13
|
+
if (undefinedOnly && value === void 0 || !undefinedOnly && value == null) delete obj[key];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return obj;
|
|
12
17
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
18
|
+
function formData(target) {
|
|
19
|
+
const data = new FormData();
|
|
20
|
+
Object.entries(target).forEach(([key, value]) => data.append(key, value));
|
|
21
|
+
return data;
|
|
16
22
|
}
|
|
17
|
-
function
|
|
23
|
+
function JSONAttemptParse(json) {
|
|
18
24
|
try {
|
|
19
|
-
return JSON.parse(
|
|
25
|
+
return JSON.parse(json);
|
|
20
26
|
} catch {
|
|
21
|
-
return
|
|
27
|
+
return json;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
(
|
|
30
|
+
function JSONSanitize(obj, space) {
|
|
31
|
+
let cache = [];
|
|
32
|
+
return JSON.stringify(obj, (key, value) => {
|
|
33
|
+
if (typeof value === "object" && value !== null) {
|
|
34
|
+
if (cache.includes(value)) return;
|
|
35
|
+
cache.push(value);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}, space);
|
|
39
|
+
}
|
|
40
|
+
class PromiseProgress extends Promise {
|
|
41
|
+
constructor(executor) {
|
|
42
|
+
super((resolve, reject) => executor(
|
|
43
|
+
(value) => resolve(value),
|
|
44
|
+
(reason) => reject(reason),
|
|
45
|
+
(progress) => this.progress = progress
|
|
30
46
|
));
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
__publicField2(this, "listeners", []);
|
|
48
|
+
__publicField2(this, "_progress", 0);
|
|
33
49
|
}
|
|
34
50
|
get progress() {
|
|
35
51
|
return this._progress;
|
|
36
52
|
}
|
|
37
|
-
set progress(
|
|
38
|
-
|
|
53
|
+
set progress(p) {
|
|
54
|
+
if (p == this._progress) return;
|
|
55
|
+
this._progress = p;
|
|
56
|
+
this.listeners.forEach((l) => l(p));
|
|
39
57
|
}
|
|
40
|
-
static from(
|
|
41
|
-
|
|
58
|
+
static from(promise) {
|
|
59
|
+
if (promise instanceof PromiseProgress) return promise;
|
|
60
|
+
return new PromiseProgress((res, rej) => promise.then((...args) => res(...args)).catch((...args) => rej(...args)));
|
|
42
61
|
}
|
|
43
|
-
from(
|
|
44
|
-
const
|
|
45
|
-
|
|
62
|
+
from(promise) {
|
|
63
|
+
const newPromise = PromiseProgress.from(promise);
|
|
64
|
+
this.onProgress((p) => newPromise.progress = p);
|
|
65
|
+
return newPromise;
|
|
46
66
|
}
|
|
47
|
-
onProgress(
|
|
48
|
-
|
|
67
|
+
onProgress(callback) {
|
|
68
|
+
this.listeners.push(callback);
|
|
69
|
+
return this;
|
|
49
70
|
}
|
|
50
|
-
then(
|
|
51
|
-
const
|
|
52
|
-
return this.from(
|
|
71
|
+
then(res, rej) {
|
|
72
|
+
const resp = super.then(res, rej);
|
|
73
|
+
return this.from(resp);
|
|
53
74
|
}
|
|
54
|
-
catch(
|
|
55
|
-
return this.from(super.catch(
|
|
75
|
+
catch(rej) {
|
|
76
|
+
return this.from(super.catch(rej));
|
|
56
77
|
}
|
|
57
|
-
finally(
|
|
58
|
-
return this.from(super.finally(
|
|
78
|
+
finally(res) {
|
|
79
|
+
return this.from(super.finally(res));
|
|
59
80
|
}
|
|
60
81
|
}
|
|
61
|
-
class
|
|
82
|
+
class TypedEmitter {
|
|
62
83
|
constructor() {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
static emit(t, ...e) {
|
|
66
|
-
(this.listeners["*"] || []).forEach((n) => n(t, ...e)), (this.listeners[t.toString()] || []).forEach((n) => n(...e));
|
|
84
|
+
__publicField2(this, "listeners", {});
|
|
67
85
|
}
|
|
68
|
-
static
|
|
69
|
-
|
|
70
|
-
this.listeners[
|
|
86
|
+
static emit(event, ...args) {
|
|
87
|
+
(this.listeners["*"] || []).forEach((l) => l(event, ...args));
|
|
88
|
+
(this.listeners[event.toString()] || []).forEach((l) => l(...args));
|
|
71
89
|
}
|
|
72
|
-
static
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return this.listeners[n] || (this.listeners[n] = []), (s = this.listeners[n]) == null || s.push(e), () => this.off(t, e);
|
|
90
|
+
static off(event, listener) {
|
|
91
|
+
const e = event.toString();
|
|
92
|
+
this.listeners[e] = (this.listeners[e] || []).filter((l) => l === listener);
|
|
76
93
|
}
|
|
77
|
-
static
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
static on(event, listener) {
|
|
95
|
+
var _a;
|
|
96
|
+
const e = event.toString();
|
|
97
|
+
if (!this.listeners[e]) this.listeners[e] = [];
|
|
98
|
+
(_a = this.listeners[e]) == null ? void 0 : _a.push(listener);
|
|
99
|
+
return () => this.off(event, listener);
|
|
100
|
+
}
|
|
101
|
+
static once(event, listener) {
|
|
102
|
+
return new Promise((res) => {
|
|
103
|
+
const unsubscribe = this.on(event, (...args) => {
|
|
104
|
+
res(args.length == 1 ? args[0] : args);
|
|
105
|
+
if (listener) listener(...args);
|
|
106
|
+
unsubscribe();
|
|
81
107
|
});
|
|
82
108
|
});
|
|
83
109
|
}
|
|
84
|
-
emit(
|
|
85
|
-
(this.listeners["*"] || []).forEach((
|
|
86
|
-
|
|
87
|
-
off(t, e) {
|
|
88
|
-
this.listeners[t] = (this.listeners[t] || []).filter((n) => n === e);
|
|
110
|
+
emit(event, ...args) {
|
|
111
|
+
(this.listeners["*"] || []).forEach((l) => l(event, ...args));
|
|
112
|
+
(this.listeners[event] || []).forEach((l) => l(...args));
|
|
89
113
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.listeners[t] || (this.listeners[t] = []), (n = this.listeners[t]) == null || n.push(e), () => this.off(t, e);
|
|
114
|
+
off(event, listener) {
|
|
115
|
+
this.listeners[event] = (this.listeners[event] || []).filter((l) => l === listener);
|
|
93
116
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
117
|
+
on(event, listener) {
|
|
118
|
+
var _a;
|
|
119
|
+
if (!this.listeners[event]) this.listeners[event] = [];
|
|
120
|
+
(_a = this.listeners[event]) == null ? void 0 : _a.push(listener);
|
|
121
|
+
return () => this.off(event, listener);
|
|
122
|
+
}
|
|
123
|
+
once(event, listener) {
|
|
124
|
+
return new Promise((res) => {
|
|
125
|
+
const unsubscribe = this.on(event, (...args) => {
|
|
126
|
+
res(args.length == 1 ? args[0] : args);
|
|
127
|
+
if (listener) listener(...args);
|
|
128
|
+
unsubscribe();
|
|
98
129
|
});
|
|
99
130
|
});
|
|
100
131
|
}
|
|
101
132
|
}
|
|
102
|
-
|
|
103
|
-
class
|
|
104
|
-
constructor(
|
|
105
|
-
super(
|
|
106
|
-
|
|
107
|
-
|
|
133
|
+
__publicField2(TypedEmitter, "listeners", {});
|
|
134
|
+
class CustomError extends Error {
|
|
135
|
+
constructor(message, code) {
|
|
136
|
+
super(message);
|
|
137
|
+
__publicField2(this, "_code");
|
|
138
|
+
if (code != null) this._code = code;
|
|
108
139
|
}
|
|
109
140
|
get code() {
|
|
110
141
|
return this._code || this.constructor.code;
|
|
111
142
|
}
|
|
112
|
-
set code(
|
|
113
|
-
this._code =
|
|
143
|
+
set code(c) {
|
|
144
|
+
this._code = c;
|
|
114
145
|
}
|
|
115
|
-
static from(
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
146
|
+
static from(err) {
|
|
147
|
+
const code = Number(err.statusCode) ?? Number(err.code);
|
|
148
|
+
const newErr = new this(err.message || err.toString());
|
|
149
|
+
return Object.assign(newErr, {
|
|
150
|
+
stack: err.stack,
|
|
151
|
+
...err,
|
|
152
|
+
code: code ?? void 0
|
|
121
153
|
});
|
|
122
154
|
}
|
|
123
|
-
static instanceof(
|
|
124
|
-
return
|
|
155
|
+
static instanceof(err) {
|
|
156
|
+
return err.constructor.code != void 0;
|
|
125
157
|
}
|
|
126
158
|
toString() {
|
|
127
159
|
return this.message || super.toString();
|
|
128
160
|
}
|
|
129
161
|
}
|
|
130
|
-
|
|
131
|
-
class
|
|
132
|
-
constructor(
|
|
133
|
-
super(
|
|
162
|
+
__publicField2(CustomError, "code", 500);
|
|
163
|
+
class BadRequestError extends CustomError {
|
|
164
|
+
constructor(message = "Bad Request") {
|
|
165
|
+
super(message);
|
|
134
166
|
}
|
|
135
|
-
static instanceof(
|
|
136
|
-
return
|
|
167
|
+
static instanceof(err) {
|
|
168
|
+
return err.constructor.code == this.code;
|
|
137
169
|
}
|
|
138
170
|
}
|
|
139
|
-
|
|
140
|
-
class
|
|
141
|
-
constructor(
|
|
142
|
-
super(
|
|
171
|
+
__publicField2(BadRequestError, "code", 400);
|
|
172
|
+
class UnauthorizedError extends CustomError {
|
|
173
|
+
constructor(message = "Unauthorized") {
|
|
174
|
+
super(message);
|
|
143
175
|
}
|
|
144
|
-
static instanceof(
|
|
145
|
-
return
|
|
176
|
+
static instanceof(err) {
|
|
177
|
+
return err.constructor.code == this.code;
|
|
146
178
|
}
|
|
147
179
|
}
|
|
148
|
-
|
|
149
|
-
class
|
|
150
|
-
constructor(
|
|
151
|
-
super(
|
|
180
|
+
__publicField2(UnauthorizedError, "code", 401);
|
|
181
|
+
class PaymentRequiredError extends CustomError {
|
|
182
|
+
constructor(message = "Payment Required") {
|
|
183
|
+
super(message);
|
|
152
184
|
}
|
|
153
|
-
static instanceof(
|
|
154
|
-
return
|
|
185
|
+
static instanceof(err) {
|
|
186
|
+
return err.constructor.code == this.code;
|
|
155
187
|
}
|
|
156
188
|
}
|
|
157
|
-
|
|
158
|
-
class
|
|
159
|
-
constructor(
|
|
160
|
-
super(
|
|
189
|
+
__publicField2(PaymentRequiredError, "code", 402);
|
|
190
|
+
class ForbiddenError extends CustomError {
|
|
191
|
+
constructor(message = "Forbidden") {
|
|
192
|
+
super(message);
|
|
161
193
|
}
|
|
162
|
-
static instanceof(
|
|
163
|
-
return
|
|
194
|
+
static instanceof(err) {
|
|
195
|
+
return err.constructor.code == this.code;
|
|
164
196
|
}
|
|
165
197
|
}
|
|
166
|
-
|
|
167
|
-
class
|
|
168
|
-
constructor(
|
|
169
|
-
super(
|
|
198
|
+
__publicField2(ForbiddenError, "code", 403);
|
|
199
|
+
class NotFoundError extends CustomError {
|
|
200
|
+
constructor(message = "Not Found") {
|
|
201
|
+
super(message);
|
|
170
202
|
}
|
|
171
|
-
static instanceof(
|
|
172
|
-
return
|
|
203
|
+
static instanceof(err) {
|
|
204
|
+
return err.constructor.code == this.code;
|
|
173
205
|
}
|
|
174
206
|
}
|
|
175
|
-
|
|
176
|
-
class
|
|
177
|
-
constructor(
|
|
178
|
-
super(
|
|
207
|
+
__publicField2(NotFoundError, "code", 404);
|
|
208
|
+
class MethodNotAllowedError extends CustomError {
|
|
209
|
+
constructor(message = "Method Not Allowed") {
|
|
210
|
+
super(message);
|
|
179
211
|
}
|
|
180
|
-
static instanceof(
|
|
181
|
-
return
|
|
212
|
+
static instanceof(err) {
|
|
213
|
+
return err.constructor.code == this.code;
|
|
182
214
|
}
|
|
183
215
|
}
|
|
184
|
-
|
|
185
|
-
class
|
|
186
|
-
constructor(
|
|
187
|
-
super(
|
|
216
|
+
__publicField2(MethodNotAllowedError, "code", 405);
|
|
217
|
+
class NotAcceptableError extends CustomError {
|
|
218
|
+
constructor(message = "Not Acceptable") {
|
|
219
|
+
super(message);
|
|
188
220
|
}
|
|
189
|
-
static instanceof(
|
|
190
|
-
return
|
|
221
|
+
static instanceof(err) {
|
|
222
|
+
return err.constructor.code == this.code;
|
|
191
223
|
}
|
|
192
224
|
}
|
|
193
|
-
|
|
194
|
-
class
|
|
195
|
-
constructor(
|
|
196
|
-
super(
|
|
225
|
+
__publicField2(NotAcceptableError, "code", 406);
|
|
226
|
+
class InternalServerError extends CustomError {
|
|
227
|
+
constructor(message = "Internal Server Error") {
|
|
228
|
+
super(message);
|
|
197
229
|
}
|
|
198
|
-
static instanceof(
|
|
199
|
-
return
|
|
230
|
+
static instanceof(err) {
|
|
231
|
+
return err.constructor.code == this.code;
|
|
200
232
|
}
|
|
201
233
|
}
|
|
202
|
-
|
|
203
|
-
class
|
|
204
|
-
constructor(
|
|
205
|
-
super(
|
|
234
|
+
__publicField2(InternalServerError, "code", 500);
|
|
235
|
+
class NotImplementedError extends CustomError {
|
|
236
|
+
constructor(message = "Not Implemented") {
|
|
237
|
+
super(message);
|
|
206
238
|
}
|
|
207
|
-
static instanceof(
|
|
208
|
-
return
|
|
239
|
+
static instanceof(err) {
|
|
240
|
+
return err.constructor.code == this.code;
|
|
209
241
|
}
|
|
210
242
|
}
|
|
211
|
-
|
|
212
|
-
class
|
|
213
|
-
constructor(
|
|
214
|
-
super(
|
|
243
|
+
__publicField2(NotImplementedError, "code", 501);
|
|
244
|
+
class BadGatewayError extends CustomError {
|
|
245
|
+
constructor(message = "Bad Gateway") {
|
|
246
|
+
super(message);
|
|
215
247
|
}
|
|
216
|
-
static instanceof(
|
|
217
|
-
return
|
|
248
|
+
static instanceof(err) {
|
|
249
|
+
return err.constructor.code == this.code;
|
|
218
250
|
}
|
|
219
251
|
}
|
|
220
|
-
|
|
221
|
-
class
|
|
222
|
-
constructor(
|
|
223
|
-
super(
|
|
252
|
+
__publicField2(BadGatewayError, "code", 502);
|
|
253
|
+
class ServiceUnavailableError extends CustomError {
|
|
254
|
+
constructor(message = "Service Unavailable") {
|
|
255
|
+
super(message);
|
|
224
256
|
}
|
|
225
|
-
static instanceof(
|
|
226
|
-
return
|
|
257
|
+
static instanceof(err) {
|
|
258
|
+
return err.constructor.code == this.code;
|
|
227
259
|
}
|
|
228
260
|
}
|
|
229
|
-
|
|
230
|
-
class
|
|
231
|
-
constructor(
|
|
232
|
-
super(
|
|
261
|
+
__publicField2(ServiceUnavailableError, "code", 503);
|
|
262
|
+
class GatewayTimeoutError extends CustomError {
|
|
263
|
+
constructor(message = "Gateway Timeout") {
|
|
264
|
+
super(message);
|
|
233
265
|
}
|
|
234
|
-
static instanceof(
|
|
235
|
-
return
|
|
266
|
+
static instanceof(err) {
|
|
267
|
+
return err.constructor.code == this.code;
|
|
236
268
|
}
|
|
237
269
|
}
|
|
238
|
-
|
|
239
|
-
function
|
|
240
|
-
|
|
241
|
-
switch (r) {
|
|
270
|
+
__publicField2(GatewayTimeoutError, "code", 504);
|
|
271
|
+
function errorFromCode(code, message) {
|
|
272
|
+
switch (code) {
|
|
242
273
|
case 400:
|
|
243
|
-
return new
|
|
274
|
+
return new BadRequestError(message);
|
|
244
275
|
case 401:
|
|
245
|
-
return new
|
|
276
|
+
return new UnauthorizedError(message);
|
|
246
277
|
case 402:
|
|
247
|
-
return new
|
|
278
|
+
return new PaymentRequiredError(message);
|
|
248
279
|
case 403:
|
|
249
|
-
return new
|
|
280
|
+
return new ForbiddenError(message);
|
|
250
281
|
case 404:
|
|
251
|
-
return new
|
|
282
|
+
return new NotFoundError(message);
|
|
252
283
|
case 405:
|
|
253
|
-
return new
|
|
284
|
+
return new MethodNotAllowedError(message);
|
|
254
285
|
case 406:
|
|
255
|
-
return new
|
|
286
|
+
return new NotAcceptableError(message);
|
|
256
287
|
case 500:
|
|
257
|
-
return new
|
|
288
|
+
return new InternalServerError(message);
|
|
258
289
|
case 501:
|
|
259
|
-
return new
|
|
290
|
+
return new NotImplementedError(message);
|
|
260
291
|
case 502:
|
|
261
|
-
return new
|
|
292
|
+
return new BadGatewayError(message);
|
|
262
293
|
case 503:
|
|
263
|
-
return new
|
|
294
|
+
return new ServiceUnavailableError(message);
|
|
264
295
|
case 504:
|
|
265
|
-
return new
|
|
296
|
+
return new GatewayTimeoutError(message);
|
|
266
297
|
default:
|
|
267
|
-
return new
|
|
298
|
+
return new CustomError(message, code);
|
|
268
299
|
}
|
|
269
300
|
}
|
|
270
|
-
const
|
|
271
|
-
constructor(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.url =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
301
|
+
const _Http = class _Http2 {
|
|
302
|
+
constructor(defaults = {}) {
|
|
303
|
+
__publicField2(this, "interceptors", {});
|
|
304
|
+
__publicField2(this, "headers", {});
|
|
305
|
+
__publicField2(this, "url");
|
|
306
|
+
this.url = defaults.url ?? null;
|
|
307
|
+
this.headers = defaults.headers || {};
|
|
308
|
+
if (defaults.interceptors) {
|
|
309
|
+
defaults.interceptors.forEach((i) => _Http2.addInterceptor(i));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
static addInterceptor(fn) {
|
|
313
|
+
const key = Object.keys(_Http2.interceptors).length.toString();
|
|
314
|
+
_Http2.interceptors[key] = fn;
|
|
315
|
+
return () => {
|
|
316
|
+
_Http2.interceptors[key] = null;
|
|
281
317
|
};
|
|
282
318
|
}
|
|
283
|
-
addInterceptor(
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
319
|
+
addInterceptor(fn) {
|
|
320
|
+
const key = Object.keys(this.interceptors).length.toString();
|
|
321
|
+
this.interceptors[key] = fn;
|
|
322
|
+
return () => {
|
|
323
|
+
this.interceptors[key] = null;
|
|
287
324
|
};
|
|
288
325
|
}
|
|
289
|
-
request(
|
|
290
|
-
var
|
|
291
|
-
if (!this.url && !
|
|
292
|
-
let
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
326
|
+
request(opts = {}) {
|
|
327
|
+
var _a;
|
|
328
|
+
if (!this.url && !opts.url) throw new Error("URL needs to be set");
|
|
329
|
+
let url = (((_a = opts.url) == null ? void 0 : _a.startsWith("http")) ? opts.url : (this.url || "") + (opts.url || "")).replace(/([^:]\/)\/+/g, "$1");
|
|
330
|
+
if (opts.fragment) url.includes("#") ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : url += "#" + opts.fragment;
|
|
331
|
+
if (opts.query) {
|
|
332
|
+
const q = Array.isArray(opts.query) ? opts.query : Object.keys(opts.query).map((k) => ({ key: k, value: opts.query[k] }));
|
|
333
|
+
url += (url.includes("?") ? "&" : "?") + q.map((q2) => `${q2.key}=${q2.value}`).join("&");
|
|
296
334
|
}
|
|
297
|
-
const
|
|
298
|
-
"Content-Type":
|
|
299
|
-
...
|
|
335
|
+
const headers = clean({
|
|
336
|
+
"Content-Type": !opts.body ? void 0 : opts.body instanceof FormData ? "multipart/form-data" : "application/json",
|
|
337
|
+
..._Http2.headers,
|
|
300
338
|
...this.headers,
|
|
301
|
-
...
|
|
339
|
+
...opts.headers
|
|
302
340
|
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
341
|
+
if (typeof opts.body == "object" && opts.body != null && headers["Content-Type"] == "application/json")
|
|
342
|
+
opts.body = JSON.stringify(opts.body);
|
|
343
|
+
return new PromiseProgress((res, rej, prog) => {
|
|
344
|
+
try {
|
|
345
|
+
fetch(url, {
|
|
346
|
+
headers,
|
|
347
|
+
method: opts.method || (opts.body ? "POST" : "GET"),
|
|
348
|
+
body: opts.body
|
|
349
|
+
}).then(async (resp) => {
|
|
350
|
+
var _a2, _b;
|
|
351
|
+
for (let fn of [...Object.values(_Http2.interceptors), ...Object.values(this.interceptors)]) {
|
|
352
|
+
await new Promise((res2) => fn(resp, () => res2()));
|
|
353
|
+
}
|
|
354
|
+
const contentLength = resp.headers.get("Content-Length");
|
|
355
|
+
const total = contentLength ? parseInt(contentLength, 10) : 0;
|
|
356
|
+
let loaded = 0;
|
|
357
|
+
const reader = (_a2 = resp.body) == null ? void 0 : _a2.getReader();
|
|
358
|
+
const stream = new ReadableStream({
|
|
359
|
+
start(controller) {
|
|
360
|
+
function push() {
|
|
361
|
+
reader == null ? void 0 : reader.read().then((event) => {
|
|
362
|
+
if (event.done) return controller.close();
|
|
363
|
+
loaded += event.value.byteLength;
|
|
364
|
+
prog(loaded / total);
|
|
365
|
+
controller.enqueue(event.value);
|
|
366
|
+
push();
|
|
367
|
+
}).catch((error) => controller.error(error));
|
|
368
|
+
}
|
|
369
|
+
push();
|
|
321
370
|
}
|
|
322
|
-
|
|
371
|
+
});
|
|
372
|
+
resp.data = new Response(stream);
|
|
373
|
+
if (opts.decode == null || opts.decode) {
|
|
374
|
+
const content = (_b = resp.headers.get("Content-Type")) == null ? void 0 : _b.toLowerCase();
|
|
375
|
+
if (content == null ? void 0 : content.includes("form")) resp.data = await resp.data.formData();
|
|
376
|
+
else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.data.json();
|
|
377
|
+
else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.data.text();
|
|
378
|
+
else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.data.blob();
|
|
323
379
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
});
|
|
380
|
+
if (resp.ok) res(resp);
|
|
381
|
+
else rej(resp);
|
|
382
|
+
}).catch((err) => rej(err));
|
|
383
|
+
} catch (err) {
|
|
384
|
+
rej(err);
|
|
385
|
+
}
|
|
331
386
|
});
|
|
332
387
|
}
|
|
333
388
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
389
|
+
__publicField2(_Http, "interceptors", {});
|
|
390
|
+
__publicField2(_Http, "headers", {});
|
|
391
|
+
function jwtDecode(token) {
|
|
392
|
+
const base64 = token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
393
|
+
return JSONAttemptParse(decodeURIComponent(atob(base64).split("").map(function(c) {
|
|
394
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
339
395
|
}).join("")));
|
|
340
396
|
}
|
|
341
|
-
const
|
|
397
|
+
const CliEffects = {
|
|
342
398
|
CLEAR: "\x1B[0m",
|
|
343
399
|
BRIGHT: "\x1B[1m",
|
|
344
400
|
DIM: "\x1B[2m",
|
|
@@ -346,7 +402,8 @@ const x = {
|
|
|
346
402
|
BLINK: "\x1B[5m",
|
|
347
403
|
REVERSE: "\x1B[7m",
|
|
348
404
|
HIDDEN: "\x1B[8m"
|
|
349
|
-
}
|
|
405
|
+
};
|
|
406
|
+
const CliForeground = {
|
|
350
407
|
BLACK: "\x1B[30m",
|
|
351
408
|
RED: "\x1B[31m",
|
|
352
409
|
GREEN: "\x1B[32m",
|
|
@@ -364,191 +421,59 @@ const x = {
|
|
|
364
421
|
LIGHT_CYAN: "\x1B[96m",
|
|
365
422
|
WHITE: "\x1B[97m"
|
|
366
423
|
};
|
|
367
|
-
const
|
|
368
|
-
constructor(
|
|
369
|
-
super()
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
return
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
error(...
|
|
402
|
-
if (
|
|
403
|
-
const
|
|
404
|
-
|
|
424
|
+
const _Logger = class _Logger2 extends TypedEmitter {
|
|
425
|
+
constructor(namespace) {
|
|
426
|
+
super();
|
|
427
|
+
this.namespace = namespace;
|
|
428
|
+
}
|
|
429
|
+
format(...text) {
|
|
430
|
+
const now = /* @__PURE__ */ new Date();
|
|
431
|
+
const timestamp = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now.getMilliseconds().toString().padEnd(3, "0")}`;
|
|
432
|
+
return `${timestamp}${this.namespace ? ` [${this.namespace}]` : ""} ${text.map((t) => typeof t == "string" ? t : JSONSanitize(t, 2)).join(" ")}`;
|
|
433
|
+
}
|
|
434
|
+
debug(...args) {
|
|
435
|
+
if (_Logger2.LOG_LEVEL < 4) return;
|
|
436
|
+
const str = this.format(...args);
|
|
437
|
+
_Logger2.emit(4, str);
|
|
438
|
+
console.debug(CliForeground.LIGHT_GREY + str + CliEffects.CLEAR);
|
|
439
|
+
}
|
|
440
|
+
log(...args) {
|
|
441
|
+
if (_Logger2.LOG_LEVEL < 3) return;
|
|
442
|
+
const str = this.format(...args);
|
|
443
|
+
_Logger2.emit(3, str);
|
|
444
|
+
console.log(CliEffects.CLEAR + str);
|
|
445
|
+
}
|
|
446
|
+
info(...args) {
|
|
447
|
+
if (_Logger2.LOG_LEVEL < 2) return;
|
|
448
|
+
const str = this.format(...args);
|
|
449
|
+
_Logger2.emit(2, str);
|
|
450
|
+
console.info(CliForeground.BLUE + str + CliEffects.CLEAR);
|
|
451
|
+
}
|
|
452
|
+
warn(...args) {
|
|
453
|
+
if (_Logger2.LOG_LEVEL < 1) return;
|
|
454
|
+
const str = this.format(...args);
|
|
455
|
+
_Logger2.emit(1, str);
|
|
456
|
+
console.warn(CliForeground.YELLOW + str + CliEffects.CLEAR);
|
|
457
|
+
}
|
|
458
|
+
error(...args) {
|
|
459
|
+
if (_Logger2.LOG_LEVEL < 0) return;
|
|
460
|
+
const str = this.format(...args);
|
|
461
|
+
_Logger2.emit(0, str);
|
|
462
|
+
console.error(CliForeground.RED + str + CliEffects.CLEAR);
|
|
405
463
|
}
|
|
406
464
|
};
|
|
407
|
-
|
|
408
|
-
function
|
|
409
|
-
return new Promise((
|
|
410
|
-
}
|
|
411
|
-
async function ie(r, t = 100) {
|
|
412
|
-
for (; await r(); ) await Ot(t);
|
|
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
|
-
}
|
|
465
|
+
__publicField2(_Logger, "LOG_LEVEL", 4);
|
|
466
|
+
function sleep(ms) {
|
|
467
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
493
468
|
}
|
|
494
|
-
|
|
495
|
-
|
|
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
|
-
};
|
|
469
|
+
async function sleepWhile(fn, checkInterval = 100) {
|
|
470
|
+
while (await fn()) await sleep(checkInterval);
|
|
507
471
|
}
|
|
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);
|
|
547
472
|
var extendStatics = function(d, b) {
|
|
548
473
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
549
474
|
d2.__proto__ = b2;
|
|
550
475
|
} || function(d2, b2) {
|
|
551
|
-
for (var
|
|
476
|
+
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
|
|
552
477
|
};
|
|
553
478
|
return extendStatics(d, b);
|
|
554
479
|
};
|
|
@@ -951,8 +876,8 @@ var EMPTY_OBSERVER = {
|
|
|
951
876
|
var observable = function() {
|
|
952
877
|
return typeof Symbol === "function" && Symbol.observable || "@@observable";
|
|
953
878
|
}();
|
|
954
|
-
function identity(
|
|
955
|
-
return
|
|
879
|
+
function identity(x) {
|
|
880
|
+
return x;
|
|
956
881
|
}
|
|
957
882
|
function pipeFromArray(fns) {
|
|
958
883
|
if (fns.length === 0) {
|
|
@@ -1033,8 +958,8 @@ var Observable = function() {
|
|
|
1033
958
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
1034
959
|
return new promiseCtor(function(resolve, reject) {
|
|
1035
960
|
var value;
|
|
1036
|
-
_this.subscribe(function(
|
|
1037
|
-
return value =
|
|
961
|
+
_this.subscribe(function(x) {
|
|
962
|
+
return value = x;
|
|
1038
963
|
}, function(err) {
|
|
1039
964
|
return reject(err);
|
|
1040
965
|
}, function() {
|
|
@@ -1670,7 +1595,7 @@ class Auth {
|
|
|
1670
1595
|
login(spoke, login, password, twoFactor) {
|
|
1671
1596
|
return fetch(`${this.api.url}login`, {
|
|
1672
1597
|
method: "POST",
|
|
1673
|
-
body:
|
|
1598
|
+
body: formData(clean({
|
|
1674
1599
|
realm: spoke.trim(),
|
|
1675
1600
|
login: login.trim(),
|
|
1676
1601
|
password: password.trim(),
|
|
@@ -1679,7 +1604,7 @@ class Auth {
|
|
|
1679
1604
|
}))
|
|
1680
1605
|
}).then(async (resp) => {
|
|
1681
1606
|
const data = await resp.json().catch(() => ({}));
|
|
1682
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1607
|
+
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1683
1608
|
this.api.token = data["token"];
|
|
1684
1609
|
return data;
|
|
1685
1610
|
});
|
|
@@ -1692,7 +1617,7 @@ class Auth {
|
|
|
1692
1617
|
loginGuest() {
|
|
1693
1618
|
return fetch(`${this.api.url}guest`).then(async (resp) => {
|
|
1694
1619
|
const data = await resp.json().catch(() => ({}));
|
|
1695
|
-
if (!resp.ok || data["error"]) throw Object.assign(
|
|
1620
|
+
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1696
1621
|
this.api.token = data["token"];
|
|
1697
1622
|
return data;
|
|
1698
1623
|
});
|
|
@@ -1784,11 +1709,11 @@ class Files {
|
|
|
1784
1709
|
data.append("", file, file.name);
|
|
1785
1710
|
return fetch(this.url, {
|
|
1786
1711
|
method: "POST",
|
|
1787
|
-
headers:
|
|
1712
|
+
headers: clean({ "Authorization": this.api.token ? `Bearer ${this.api.token}` : "" }),
|
|
1788
1713
|
body: data
|
|
1789
1714
|
}).then(async (resp) => {
|
|
1790
1715
|
const data2 = await resp.json().catch(() => ({}));
|
|
1791
|
-
if (!resp.ok || data2["error"]) throw Object.assign(
|
|
1716
|
+
if (!resp.ok || data2["error"]) throw Object.assign(errorFromCode(resp.status, data2.error) || {}, data2);
|
|
1792
1717
|
return resp;
|
|
1793
1718
|
});
|
|
1794
1719
|
})).then(async (files2) => {
|
|
@@ -2183,7 +2108,7 @@ class Slice {
|
|
|
2183
2108
|
new Slice(this.slice, this.api).select().exec().rows().then((rows) => this.cache = rows);
|
|
2184
2109
|
if (!this.unsubscribe) this.unsubscribe = this.api.socket.sliceEvents(this.slice, (event) => {
|
|
2185
2110
|
const ids = [...event.data.new, ...event.data.changed];
|
|
2186
|
-
new Slice(this.slice, this.api).select(ids).exec().rows().then((rows) => this.cache = [...this.cache.filter((
|
|
2111
|
+
new Slice(this.slice, this.api).select(ids).exec().rows().then((rows) => this.cache = [...this.cache.filter((c) => c.id != null && !ids.includes(c.id)), ...rows]);
|
|
2187
2112
|
this.cache = this.cache.filter((v) => v.id && !event.data.lost.includes(v.id));
|
|
2188
2113
|
});
|
|
2189
2114
|
return this.cache$;
|
|
@@ -2247,9 +2172,9 @@ class Slice {
|
|
|
2247
2172
|
class Socket {
|
|
2248
2173
|
constructor(api, options = {}) {
|
|
2249
2174
|
__publicField(this, "listeners", []);
|
|
2250
|
-
__publicField(this, "
|
|
2175
|
+
__publicField(this, "retry");
|
|
2251
2176
|
__publicField(this, "socket");
|
|
2252
|
-
__publicField(this, "
|
|
2177
|
+
__publicField(this, "open", false);
|
|
2253
2178
|
this.api = api;
|
|
2254
2179
|
this.options = options;
|
|
2255
2180
|
const url = new URL(this.api.url.replace("http", "ws"));
|
|
@@ -2261,9 +2186,6 @@ class Socket {
|
|
|
2261
2186
|
if (this.options.url !== false)
|
|
2262
2187
|
api.token$.pipe(distinctUntilChanged()).subscribe(() => this.connect());
|
|
2263
2188
|
}
|
|
2264
|
-
get connected() {
|
|
2265
|
-
return this._connected;
|
|
2266
|
-
}
|
|
2267
2189
|
/**
|
|
2268
2190
|
* Add listener for all socket events
|
|
2269
2191
|
*
|
|
@@ -2278,46 +2200,46 @@ class Socket {
|
|
|
2278
2200
|
* Close socket connection
|
|
2279
2201
|
*/
|
|
2280
2202
|
close() {
|
|
2281
|
-
|
|
2282
|
-
this.
|
|
2283
|
-
this.
|
|
2203
|
+
var _a;
|
|
2204
|
+
if (this.open) console.debug("Datalynk socket: disconnected");
|
|
2205
|
+
this.open = false;
|
|
2206
|
+
(_a = this.socket) == null ? void 0 : _a.close();
|
|
2207
|
+
this.socket = void 0;
|
|
2208
|
+
if (this.retry) clearTimeout(this.retry);
|
|
2209
|
+
this.retry = null;
|
|
2284
2210
|
}
|
|
2285
2211
|
/**
|
|
2286
2212
|
* Connect socket client to socket server
|
|
2287
|
-
*
|
|
2288
|
-
* @param {number} timeout Retry interval, defaults to 30s
|
|
2213
|
+
* @param {number} timeout Retry to connect every x seconds
|
|
2289
2214
|
*/
|
|
2290
|
-
connect(timeout =
|
|
2291
|
-
if (!this.options.url) throw new Error("
|
|
2292
|
-
if (this.
|
|
2293
|
-
|
|
2294
|
-
this.
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2215
|
+
connect(timeout = 30) {
|
|
2216
|
+
if (!this.options.url) throw new Error("Datalynk socket disabled");
|
|
2217
|
+
if (this.open) this.close();
|
|
2218
|
+
this.retry = setTimeout(() => {
|
|
2219
|
+
if (this.open) return;
|
|
2220
|
+
this.close();
|
|
2221
|
+
this.connect();
|
|
2222
|
+
}, timeout * 1e3);
|
|
2223
|
+
if (navigator.onLine) {
|
|
2224
|
+
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}` : ""));
|
|
2225
|
+
this.socket.onopen = () => clearTimeout(this.retry);
|
|
2226
|
+
this.socket.onclose = () => {
|
|
2227
|
+
if (this.open) this.connect(timeout);
|
|
2228
|
+
};
|
|
2229
|
+
this.socket.onmessage = (message) => {
|
|
2230
|
+
const payload = JSON.parse(message.data);
|
|
2231
|
+
if (payload.connected != void 0) {
|
|
2232
|
+
if (payload.connected) {
|
|
2233
|
+
this.open = true;
|
|
2234
|
+
console.debug("Datalynk socket: connected");
|
|
2235
|
+
} else {
|
|
2236
|
+
throw new Error(`Datalynk socket failed: ${payload.error}`);
|
|
2237
|
+
}
|
|
2309
2238
|
} else {
|
|
2310
|
-
|
|
2239
|
+
this.listeners.forEach((l) => l(payload));
|
|
2311
2240
|
}
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
}
|
|
2315
|
-
};
|
|
2316
|
-
this.socket.onclose = () => {
|
|
2317
|
-
this._connected = false;
|
|
2318
|
-
if (this.reconnect && !t) this.connect();
|
|
2319
|
-
console.debug("Datalynk Socket: Disconnected");
|
|
2320
|
-
};
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2321
2243
|
}
|
|
2322
2244
|
/**
|
|
2323
2245
|
* Send data to socket server
|
|
@@ -2325,7 +2247,9 @@ class Socket {
|
|
|
2325
2247
|
* @param payload Data that will be serialized
|
|
2326
2248
|
*/
|
|
2327
2249
|
send(payload) {
|
|
2328
|
-
|
|
2250
|
+
var _a;
|
|
2251
|
+
if (!this.open) throw new Error("Datalynk socket not connected");
|
|
2252
|
+
(_a = this.socket) == null ? void 0 : _a.send(JSON.stringify(payload));
|
|
2329
2253
|
}
|
|
2330
2254
|
/**
|
|
2331
2255
|
* Run callback whenever the server notifies us of slice changes
|
|
@@ -2336,7 +2260,7 @@ class Socket {
|
|
|
2336
2260
|
*/
|
|
2337
2261
|
sliceEvents(slice, callback) {
|
|
2338
2262
|
let cancelled = false;
|
|
2339
|
-
|
|
2263
|
+
sleepWhile(() => !this.open).then(() => {
|
|
2340
2264
|
if (!cancelled) this.send({ onSliceEvents: slice });
|
|
2341
2265
|
});
|
|
2342
2266
|
const unsubscribe = this.addListener((event) => {
|
|
@@ -2445,21 +2369,20 @@ class Api {
|
|
|
2445
2369
|
/** Get session info from JWT payload */
|
|
2446
2370
|
get jwtPayload() {
|
|
2447
2371
|
if (!this.token) return null;
|
|
2448
|
-
return
|
|
2372
|
+
return jwtDecode(this.token);
|
|
2449
2373
|
}
|
|
2450
2374
|
_request(req, options = {}) {
|
|
2451
2375
|
return fetch(this.url, {
|
|
2452
2376
|
method: "POST",
|
|
2453
|
-
headers:
|
|
2377
|
+
headers: clean({
|
|
2454
2378
|
Authorization: this.token ? `Bearer ${this.token}` : void 0,
|
|
2455
2379
|
"Content-Type": "application/json"
|
|
2456
2380
|
}),
|
|
2457
2381
|
body: JSON.stringify(Api.translateTokens(req))
|
|
2458
2382
|
}).then(async (resp) => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2383
|
+
let data = JSONAttemptParse(await resp.text());
|
|
2384
|
+
if (!resp.ok || (data == null ? void 0 : data.error)) throw Object.assign(errorFromCode(resp.status, data.error), data);
|
|
2461
2385
|
if (!options.raw) data = Api.translateTokens(data);
|
|
2462
|
-
if (data["error"]) throw Object.assign(Yt(resp.status, data["error"]) || {}, data);
|
|
2463
2386
|
return data;
|
|
2464
2387
|
});
|
|
2465
2388
|
}
|