@auxilium/datalynk-client 1.0.3 → 1.0.6
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 +12 -11
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +4 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +51 -21
- package/dist/index.mjs +51 -21
- package/dist/login-prompt.d.ts +1 -1
- package/dist/login-prompt.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -65,17 +65,7 @@ export declare class Api {
|
|
|
65
65
|
private localStorageKey;
|
|
66
66
|
/** Pending requests cache */
|
|
67
67
|
private pending;
|
|
68
|
-
/**
|
|
69
|
-
readonly auth: Auth;
|
|
70
|
-
/** File helpers */
|
|
71
|
-
readonly files: Files;
|
|
72
|
-
/** PDF helpers */
|
|
73
|
-
readonly pdf: Pdf;
|
|
74
|
-
/** Socket object */
|
|
75
|
-
readonly socket: Socket;
|
|
76
|
-
/** Superuser helpers */
|
|
77
|
-
readonly superuser: Superuser;
|
|
78
|
-
/** API URL endpoint */
|
|
68
|
+
/** API URL */
|
|
79
69
|
readonly url: string;
|
|
80
70
|
/** API Session token */
|
|
81
71
|
token$: BehaviorSubject<string | null>;
|
|
@@ -83,6 +73,17 @@ export declare class Api {
|
|
|
83
73
|
set token(token: string | null);
|
|
84
74
|
/** Get session info from JWT payload */
|
|
85
75
|
get jwtPayload(): JwtPayload | null;
|
|
76
|
+
/** Helpers */
|
|
77
|
+
/** Authentication */
|
|
78
|
+
readonly auth: Auth;
|
|
79
|
+
/** File */
|
|
80
|
+
readonly files: Files;
|
|
81
|
+
/** PDF */
|
|
82
|
+
readonly pdf: Pdf;
|
|
83
|
+
/** Socket */
|
|
84
|
+
readonly socket: Socket;
|
|
85
|
+
/** Superuser */
|
|
86
|
+
readonly superuser: Superuser;
|
|
86
87
|
/**
|
|
87
88
|
* Connect to Datalynk & send requests
|
|
88
89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AAM,CAAC;IACzB,gBAAgB;IAChB,QAAQ,CAAC,SAAS,YAAuB;IAEzC;;;;;;;;;;OAUG;gBACS,GAAG,EAAE,MAAM,EAAkB,OAAO,GAAE,UAAe;IA0BjE,OAAO,CAAC,QAAQ;IAoBhB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAsB9B;;;;OAIG;IACI,KAAK,CAAC,GAAG,QAAQ,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IAe9C;;;;OAIG;IACI,QAAQ,CAAC,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAiB7C;;;;;;OAMG;IACI,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAU7E;;;;;;;;;;;OAWG;IACI,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAqC/E;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAG5C"}
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { Api } from './api';
|
|
3
|
-
import { LoginPromptOptions } from './login-prompt';
|
|
3
|
+
import { LoginPrompt, LoginPromptOptions } from './login-prompt';
|
|
4
4
|
/** User Account */
|
|
5
5
|
export type User = {
|
|
6
6
|
/** User ID */
|
|
@@ -96,7 +96,7 @@ export declare class Auth {
|
|
|
96
96
|
login(spoke: string, login: string, password: string, opts?: {
|
|
97
97
|
twoFactor?: string;
|
|
98
98
|
expire?: null | string;
|
|
99
|
-
}): Promise<
|
|
99
|
+
}): Promise<User>;
|
|
100
100
|
/**
|
|
101
101
|
* Login as guest user
|
|
102
102
|
*
|
|
@@ -108,9 +108,9 @@ export declare class Auth {
|
|
|
108
108
|
*
|
|
109
109
|
* @param {string} spoke Desired spoke
|
|
110
110
|
* @param {LoginPromptOptions} options Aesthetic options
|
|
111
|
-
* @return {
|
|
111
|
+
* @return {LoginPrompt} Login prompt
|
|
112
112
|
*/
|
|
113
|
-
loginPrompt(spoke: string, options?: LoginPromptOptions):
|
|
113
|
+
loginPrompt(spoke: string, options?: LoginPromptOptions): LoginPrompt;
|
|
114
114
|
/**
|
|
115
115
|
* Logout current user
|
|
116
116
|
*
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAyB,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAE/D,mBAAmB;AACnB,MAAM,MAAM,IAAI,GAAG;IAClB,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IACX,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,KAAK,EAAE,OAAO,CAAC;IACf,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE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,CAAC,EAAE,kBAAkB,GAAG,WAAW;IAIrE;;;;OAIG;IACH,MAAM;gBAC6B,MAAM;aAAO,MAAM;;IAOtD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAWvD;;;;;;OAMG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO;CAI3D"}
|
package/dist/index.cjs
CHANGED
|
@@ -19,11 +19,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19
19
|
}
|
|
20
20
|
return obj;
|
|
21
21
|
}
|
|
22
|
-
function formData(target) {
|
|
23
|
-
const data = new FormData();
|
|
24
|
-
Object.entries(target).forEach(([key, value2]) => data.append(key, value2));
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
22
|
function JSONAttemptParse(json) {
|
|
28
23
|
try {
|
|
29
24
|
return JSON.parse(json);
|
|
@@ -1313,6 +1308,38 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1313
1308
|
};
|
|
1314
1309
|
return BehaviorSubject2;
|
|
1315
1310
|
}(Subject);
|
|
1311
|
+
var EmptyError = createErrorClass(function(_super) {
|
|
1312
|
+
return function EmptyErrorImpl() {
|
|
1313
|
+
_super(this);
|
|
1314
|
+
this.name = "EmptyError";
|
|
1315
|
+
this.message = "no elements in sequence";
|
|
1316
|
+
};
|
|
1317
|
+
});
|
|
1318
|
+
function firstValueFrom(source, config2) {
|
|
1319
|
+
return new Promise(function(resolve, reject) {
|
|
1320
|
+
var subscriber = new SafeSubscriber({
|
|
1321
|
+
next: function(value) {
|
|
1322
|
+
resolve(value);
|
|
1323
|
+
subscriber.unsubscribe();
|
|
1324
|
+
},
|
|
1325
|
+
error: reject,
|
|
1326
|
+
complete: function() {
|
|
1327
|
+
{
|
|
1328
|
+
reject(new EmptyError());
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
source.subscribe(subscriber);
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
function filter(predicate, thisArg) {
|
|
1336
|
+
return operate(function(source, subscriber) {
|
|
1337
|
+
var index = 0;
|
|
1338
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1339
|
+
return predicate.call(thisArg, value, index++) && subscriber.next(value);
|
|
1340
|
+
}));
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1316
1343
|
function distinctUntilChanged(comparator, keySelector) {
|
|
1317
1344
|
if (keySelector === void 0) {
|
|
1318
1345
|
keySelector = identity;
|
|
@@ -1444,6 +1471,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1444
1471
|
border: 1px solid #ddd;
|
|
1445
1472
|
border-radius: 5px;
|
|
1446
1473
|
background-color: white;
|
|
1474
|
+
color: black;
|
|
1447
1475
|
}
|
|
1448
1476
|
|
|
1449
1477
|
#datalynk-login input:disabled {
|
|
@@ -1582,6 +1610,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1582
1610
|
/** Current user as an observable */
|
|
1583
1611
|
__publicField(this, "user$", new BehaviorSubject(void 0));
|
|
1584
1612
|
this.api = api;
|
|
1613
|
+
this.api.token$.subscribe(() => this.current());
|
|
1585
1614
|
}
|
|
1586
1615
|
/** Current user */
|
|
1587
1616
|
get user() {
|
|
@@ -1629,7 +1658,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1629
1658
|
location.reload();
|
|
1630
1659
|
});
|
|
1631
1660
|
} else {
|
|
1632
|
-
await this.loginPrompt(spoke, options);
|
|
1661
|
+
await this.loginPrompt(spoke, options).done;
|
|
1633
1662
|
location.reload();
|
|
1634
1663
|
}
|
|
1635
1664
|
}
|
|
@@ -1688,7 +1717,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1688
1717
|
date.setFullYear(date.getFullYear() + 1);
|
|
1689
1718
|
return fetch(`${this.api.url}login`, {
|
|
1690
1719
|
method: "POST",
|
|
1691
|
-
|
|
1720
|
+
headers: { "Content-Type": "application/json" },
|
|
1721
|
+
body: JSON.stringify(clean({
|
|
1692
1722
|
realm: spoke.trim(),
|
|
1693
1723
|
login: login.trim(),
|
|
1694
1724
|
password: password.trim(),
|
|
@@ -1700,7 +1730,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1700
1730
|
const data = await resp.json().catch(() => ({}));
|
|
1701
1731
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1702
1732
|
this.api.token = data["token"];
|
|
1703
|
-
return data;
|
|
1733
|
+
return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
|
|
1704
1734
|
});
|
|
1705
1735
|
}
|
|
1706
1736
|
/**
|
|
@@ -1721,10 +1751,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1721
1751
|
*
|
|
1722
1752
|
* @param {string} spoke Desired spoke
|
|
1723
1753
|
* @param {LoginPromptOptions} options Aesthetic options
|
|
1724
|
-
* @return {
|
|
1754
|
+
* @return {LoginPrompt} Login prompt
|
|
1725
1755
|
*/
|
|
1726
1756
|
loginPrompt(spoke, options) {
|
|
1727
|
-
return new LoginPrompt(this.api, spoke, options)
|
|
1757
|
+
return new LoginPrompt(this.api, spoke, options);
|
|
1728
1758
|
}
|
|
1729
1759
|
/**
|
|
1730
1760
|
* Logout current user
|
|
@@ -2373,7 +2403,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2373
2403
|
* @param {number} timeout Retry to connect every x seconds
|
|
2374
2404
|
*/
|
|
2375
2405
|
connect(timeout = 30) {
|
|
2376
|
-
if (
|
|
2406
|
+
if (this.options.url === false) return console.warn("Datalynk socket disabled");
|
|
2377
2407
|
if (this.open) this.close();
|
|
2378
2408
|
this.retry = setTimeout(() => {
|
|
2379
2409
|
if (this.open) return;
|
|
@@ -2482,20 +2512,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2482
2512
|
__publicField(this, "localStorageKey", "datalynk-token");
|
|
2483
2513
|
/** Pending requests cache */
|
|
2484
2514
|
__publicField(this, "pending", {});
|
|
2485
|
-
/**
|
|
2515
|
+
/** API URL */
|
|
2516
|
+
__publicField(this, "url");
|
|
2517
|
+
/** API Session token */
|
|
2518
|
+
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2519
|
+
/** Helpers */
|
|
2520
|
+
/** Authentication */
|
|
2486
2521
|
__publicField(this, "auth", new Auth(this));
|
|
2487
|
-
/** File
|
|
2522
|
+
/** File */
|
|
2488
2523
|
__publicField(this, "files", new Files(this));
|
|
2489
|
-
/** PDF
|
|
2524
|
+
/** PDF */
|
|
2490
2525
|
__publicField(this, "pdf", new Pdf(this));
|
|
2491
|
-
/** Socket
|
|
2526
|
+
/** Socket */
|
|
2492
2527
|
__publicField(this, "socket");
|
|
2493
|
-
/** Superuser
|
|
2528
|
+
/** Superuser */
|
|
2494
2529
|
__publicField(this, "superuser", new Superuser(this));
|
|
2495
|
-
/** API URL endpoint */
|
|
2496
|
-
__publicField(this, "url");
|
|
2497
|
-
/** API Session token */
|
|
2498
|
-
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2499
2530
|
this.options = options;
|
|
2500
2531
|
this.url = `${new URL(url).origin}/api/`;
|
|
2501
2532
|
this.options = {
|
|
@@ -2514,7 +2545,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2514
2545
|
});
|
|
2515
2546
|
}
|
|
2516
2547
|
Slice.api = this;
|
|
2517
|
-
this.token$.subscribe(() => this.auth.current());
|
|
2518
2548
|
this.socket = new Socket(this, { url: options.socket });
|
|
2519
2549
|
}
|
|
2520
2550
|
get token() {
|
package/dist/index.mjs
CHANGED
|
@@ -15,11 +15,6 @@ function clean(obj, undefinedOnly = false) {
|
|
|
15
15
|
}
|
|
16
16
|
return obj;
|
|
17
17
|
}
|
|
18
|
-
function formData(target) {
|
|
19
|
-
const data = new FormData();
|
|
20
|
-
Object.entries(target).forEach(([key, value2]) => data.append(key, value2));
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
18
|
function JSONAttemptParse(json) {
|
|
24
19
|
try {
|
|
25
20
|
return JSON.parse(json);
|
|
@@ -1309,6 +1304,38 @@ var BehaviorSubject = function(_super) {
|
|
|
1309
1304
|
};
|
|
1310
1305
|
return BehaviorSubject2;
|
|
1311
1306
|
}(Subject);
|
|
1307
|
+
var EmptyError = createErrorClass(function(_super) {
|
|
1308
|
+
return function EmptyErrorImpl() {
|
|
1309
|
+
_super(this);
|
|
1310
|
+
this.name = "EmptyError";
|
|
1311
|
+
this.message = "no elements in sequence";
|
|
1312
|
+
};
|
|
1313
|
+
});
|
|
1314
|
+
function firstValueFrom(source, config2) {
|
|
1315
|
+
return new Promise(function(resolve, reject) {
|
|
1316
|
+
var subscriber = new SafeSubscriber({
|
|
1317
|
+
next: function(value) {
|
|
1318
|
+
resolve(value);
|
|
1319
|
+
subscriber.unsubscribe();
|
|
1320
|
+
},
|
|
1321
|
+
error: reject,
|
|
1322
|
+
complete: function() {
|
|
1323
|
+
{
|
|
1324
|
+
reject(new EmptyError());
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
source.subscribe(subscriber);
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
function filter(predicate, thisArg) {
|
|
1332
|
+
return operate(function(source, subscriber) {
|
|
1333
|
+
var index = 0;
|
|
1334
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1335
|
+
return predicate.call(thisArg, value, index++) && subscriber.next(value);
|
|
1336
|
+
}));
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1312
1339
|
function distinctUntilChanged(comparator, keySelector) {
|
|
1313
1340
|
if (keySelector === void 0) {
|
|
1314
1341
|
keySelector = identity;
|
|
@@ -1440,6 +1467,7 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
|
|
|
1440
1467
|
border: 1px solid #ddd;
|
|
1441
1468
|
border-radius: 5px;
|
|
1442
1469
|
background-color: white;
|
|
1470
|
+
color: black;
|
|
1443
1471
|
}
|
|
1444
1472
|
|
|
1445
1473
|
#datalynk-login input:disabled {
|
|
@@ -1578,6 +1606,7 @@ class Auth {
|
|
|
1578
1606
|
/** Current user as an observable */
|
|
1579
1607
|
__publicField(this, "user$", new BehaviorSubject(void 0));
|
|
1580
1608
|
this.api = api;
|
|
1609
|
+
this.api.token$.subscribe(() => this.current());
|
|
1581
1610
|
}
|
|
1582
1611
|
/** Current user */
|
|
1583
1612
|
get user() {
|
|
@@ -1625,7 +1654,7 @@ class Auth {
|
|
|
1625
1654
|
location.reload();
|
|
1626
1655
|
});
|
|
1627
1656
|
} else {
|
|
1628
|
-
await this.loginPrompt(spoke, options);
|
|
1657
|
+
await this.loginPrompt(spoke, options).done;
|
|
1629
1658
|
location.reload();
|
|
1630
1659
|
}
|
|
1631
1660
|
}
|
|
@@ -1684,7 +1713,8 @@ class Auth {
|
|
|
1684
1713
|
date.setFullYear(date.getFullYear() + 1);
|
|
1685
1714
|
return fetch(`${this.api.url}login`, {
|
|
1686
1715
|
method: "POST",
|
|
1687
|
-
|
|
1716
|
+
headers: { "Content-Type": "application/json" },
|
|
1717
|
+
body: JSON.stringify(clean({
|
|
1688
1718
|
realm: spoke.trim(),
|
|
1689
1719
|
login: login.trim(),
|
|
1690
1720
|
password: password.trim(),
|
|
@@ -1696,7 +1726,7 @@ class Auth {
|
|
|
1696
1726
|
const data = await resp.json().catch(() => ({}));
|
|
1697
1727
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1698
1728
|
this.api.token = data["token"];
|
|
1699
|
-
return data;
|
|
1729
|
+
return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
|
|
1700
1730
|
});
|
|
1701
1731
|
}
|
|
1702
1732
|
/**
|
|
@@ -1717,10 +1747,10 @@ class Auth {
|
|
|
1717
1747
|
*
|
|
1718
1748
|
* @param {string} spoke Desired spoke
|
|
1719
1749
|
* @param {LoginPromptOptions} options Aesthetic options
|
|
1720
|
-
* @return {
|
|
1750
|
+
* @return {LoginPrompt} Login prompt
|
|
1721
1751
|
*/
|
|
1722
1752
|
loginPrompt(spoke, options) {
|
|
1723
|
-
return new LoginPrompt(this.api, spoke, options)
|
|
1753
|
+
return new LoginPrompt(this.api, spoke, options);
|
|
1724
1754
|
}
|
|
1725
1755
|
/**
|
|
1726
1756
|
* Logout current user
|
|
@@ -2369,7 +2399,7 @@ class Socket {
|
|
|
2369
2399
|
* @param {number} timeout Retry to connect every x seconds
|
|
2370
2400
|
*/
|
|
2371
2401
|
connect(timeout = 30) {
|
|
2372
|
-
if (
|
|
2402
|
+
if (this.options.url === false) return console.warn("Datalynk socket disabled");
|
|
2373
2403
|
if (this.open) this.close();
|
|
2374
2404
|
this.retry = setTimeout(() => {
|
|
2375
2405
|
if (this.open) return;
|
|
@@ -2478,20 +2508,21 @@ class Api {
|
|
|
2478
2508
|
__publicField(this, "localStorageKey", "datalynk-token");
|
|
2479
2509
|
/** Pending requests cache */
|
|
2480
2510
|
__publicField(this, "pending", {});
|
|
2481
|
-
/**
|
|
2511
|
+
/** API URL */
|
|
2512
|
+
__publicField(this, "url");
|
|
2513
|
+
/** API Session token */
|
|
2514
|
+
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2515
|
+
/** Helpers */
|
|
2516
|
+
/** Authentication */
|
|
2482
2517
|
__publicField(this, "auth", new Auth(this));
|
|
2483
|
-
/** File
|
|
2518
|
+
/** File */
|
|
2484
2519
|
__publicField(this, "files", new Files(this));
|
|
2485
|
-
/** PDF
|
|
2520
|
+
/** PDF */
|
|
2486
2521
|
__publicField(this, "pdf", new Pdf(this));
|
|
2487
|
-
/** Socket
|
|
2522
|
+
/** Socket */
|
|
2488
2523
|
__publicField(this, "socket");
|
|
2489
|
-
/** Superuser
|
|
2524
|
+
/** Superuser */
|
|
2490
2525
|
__publicField(this, "superuser", new Superuser(this));
|
|
2491
|
-
/** API URL endpoint */
|
|
2492
|
-
__publicField(this, "url");
|
|
2493
|
-
/** API Session token */
|
|
2494
|
-
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2495
2526
|
this.options = options;
|
|
2496
2527
|
this.url = `${new URL(url).origin}/api/`;
|
|
2497
2528
|
this.options = {
|
|
@@ -2510,7 +2541,6 @@ class Api {
|
|
|
2510
2541
|
});
|
|
2511
2542
|
}
|
|
2512
2543
|
Slice.api = this;
|
|
2513
|
-
this.token$.subscribe(() => this.auth.current());
|
|
2514
2544
|
this.socket = new Socket(this, { url: options.socket });
|
|
2515
2545
|
}
|
|
2516
2546
|
get token() {
|
package/dist/login-prompt.d.ts
CHANGED
|
@@ -38,6 +38,6 @@ export declare class LoginPrompt {
|
|
|
38
38
|
/** Check if login prompt is still open */
|
|
39
39
|
isOpen(): boolean;
|
|
40
40
|
/** Login form submit event */
|
|
41
|
-
login(event: any): Promise<
|
|
41
|
+
login(event: any): Promise<void | import('./auth').User>;
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=login-prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-prompt.d.ts","sourceRoot":"","sources":["../src/login-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,uCAAuC;AACvC,MAAM,MAAM,kBAAkB,GAAG;IAChC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,OAAO,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,EAAE,MAAM,EAAS,OAAO,GAAE,kBAAuB;IAgB7G;;OAEG;IACH,KAAK;IAKL,0CAA0C;IAC1C,MAAM;IAIN,8BAA8B;IAC9B,KAAK,CAAC,KAAK,EAAE,GAAG;CA4BhB"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@auxilium/datalynk-client",
|
|
3
3
|
"description": "Datalynk client library",
|
|
4
4
|
"repository": "https://gitlab.auxiliumgroup.com/auxilium/datalynk/datalynk-client",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.6",
|
|
6
6
|
"author": "Zak Timson <zaktimson@gmail.com>",
|
|
7
7
|
"private": false,
|
|
8
8
|
"main": "./dist/index.cjs",
|