@auxilium/datalynk-client 0.4.8 → 0.5.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/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +45 -5
- package/dist/auth.d.ts.map +1 -1
- package/dist/files.d.ts +50 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/index.cjs +163 -10
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +164 -11
- package/dist/slice.d.ts +1 -1
- package/dist/slice.d.ts.map +1 -1
- package/dist/socket.d.ts +1 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/superuser.d.ts +23 -0
- package/dist/superuser.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { Auth } from './auth';
|
|
3
|
+
import { Files } from './files';
|
|
3
4
|
import { Slice, SliceMeta } from './slice';
|
|
4
5
|
import { Socket } from './socket';
|
|
6
|
+
import { Superuser } from './superuser';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Function definition for API callbacks
|
|
@@ -53,8 +55,12 @@ export declare class Api {
|
|
|
53
55
|
private pending;
|
|
54
56
|
/** Authentication helpers */
|
|
55
57
|
readonly auth: Auth;
|
|
58
|
+
/** File helpers */
|
|
59
|
+
readonly files: Files;
|
|
56
60
|
/** Socket object */
|
|
57
61
|
readonly socket: Socket;
|
|
62
|
+
/** Superuser helpers */
|
|
63
|
+
readonly superuser: Superuser;
|
|
58
64
|
/** API endpoint */
|
|
59
65
|
readonly url: string;
|
|
60
66
|
/** API Session token */
|
|
@@ -81,7 +87,7 @@ export declare class Api {
|
|
|
81
87
|
* @param {number} slice ID of the slice to use
|
|
82
88
|
* @returns {Slice<T extends SliceMeta>} Slice object to create query
|
|
83
89
|
*/
|
|
84
|
-
slice<T extends SliceMeta>(slice: number): Slice<T>;
|
|
90
|
+
slice<T extends SliceMeta>(slice: number | string): Slice<T>;
|
|
85
91
|
/**
|
|
86
92
|
* Send a request and automatically log the output
|
|
87
93
|
* @param {object | string} data request
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AACzC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sCAAsC;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,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIxD;;;;;OAKG;IACI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;CAU5E"}
|
package/dist/auth.d.ts
CHANGED
|
@@ -22,11 +22,6 @@ export type User = {
|
|
|
22
22
|
*/
|
|
23
23
|
export declare class Auth {
|
|
24
24
|
private readonly api;
|
|
25
|
-
/**
|
|
26
|
-
* Check whether user has a token
|
|
27
|
-
* @return {boolean}
|
|
28
|
-
*/
|
|
29
|
-
get isAuthenticated(): boolean;
|
|
30
25
|
user$: BehaviorSubject<User | null>;
|
|
31
26
|
get user(): User | null;
|
|
32
27
|
set user(user: User | null);
|
|
@@ -44,6 +39,31 @@ export declare class Auth {
|
|
|
44
39
|
* @return {Promise<void>} Login complete
|
|
45
40
|
*/
|
|
46
41
|
handleLogin(spoke: string, options?: LoginPromptOptions): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Check whether user has a token
|
|
44
|
+
* @return {boolean} True if session token authenticated
|
|
45
|
+
*/
|
|
46
|
+
isAuthenticated(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Check if the current user is a guest
|
|
49
|
+
* @return {boolean} True if guest
|
|
50
|
+
*/
|
|
51
|
+
isGuest(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Check if user is a system administrator
|
|
54
|
+
* @return {Promise<boolean>} True if system administrator
|
|
55
|
+
*/
|
|
56
|
+
isSysAdmin(): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Check if user is a table administrator
|
|
59
|
+
* @return {Promise<boolean>} True if table administrator
|
|
60
|
+
*/
|
|
61
|
+
isTableAdmin(): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Check if user is a user administrator
|
|
64
|
+
* @return {Promise<boolean>} True if user administrator
|
|
65
|
+
*/
|
|
66
|
+
isUserAdmin(): Promise<boolean>;
|
|
47
67
|
/**
|
|
48
68
|
* Create Login UI
|
|
49
69
|
* @param {string} spoke Desired spoke
|
|
@@ -60,6 +80,11 @@ export declare class Auth {
|
|
|
60
80
|
* @returns {Promise<any>} Session information returned from login request
|
|
61
81
|
*/
|
|
62
82
|
login(spoke: string, login: string, password: string, twoFactor?: string): Promise<any>;
|
|
83
|
+
/**
|
|
84
|
+
* Login as guest user
|
|
85
|
+
* @return {Promise<any>}
|
|
86
|
+
*/
|
|
87
|
+
loginGuest(): Promise<any>;
|
|
63
88
|
/**
|
|
64
89
|
* Logout current user
|
|
65
90
|
* @return {Promise<{closed: string, new: string}>}
|
|
@@ -68,5 +93,20 @@ export declare class Auth {
|
|
|
68
93
|
closed: string;
|
|
69
94
|
new: string;
|
|
70
95
|
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Reset user account password
|
|
98
|
+
* @param {string} login User login
|
|
99
|
+
* @param {string} newPassword New password
|
|
100
|
+
* @param {string} code Reset code sent with `resetRequest`
|
|
101
|
+
* @return {Promise<any>} New session
|
|
102
|
+
*/
|
|
103
|
+
reset(login: string, newPassword: string, code?: string): Promise<any>;
|
|
104
|
+
/**
|
|
105
|
+
* Request reset code for user
|
|
106
|
+
* @param {string} login User to reset
|
|
107
|
+
* @param {"email" | "sms" | "voice"} mode Method of sending reset code
|
|
108
|
+
* @return {Promise<any>} Unknown
|
|
109
|
+
*/
|
|
110
|
+
resetRequest(login: string, mode: 'email' | 'sms' | 'voice'): Promise<any>;
|
|
71
111
|
}
|
|
72
112
|
//# sourceMappingURL=auth.d.ts.map
|
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,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAc,kBAAkB,EAAC,MA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export interface UploadedFile {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
size: number;
|
|
7
|
+
extension: string;
|
|
8
|
+
mime: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handle uploading & fetching files from Datalynk
|
|
13
|
+
*/
|
|
14
|
+
export declare class Files {
|
|
15
|
+
private readonly api;
|
|
16
|
+
readonly url: string;
|
|
17
|
+
constructor(api: Api);
|
|
18
|
+
/**
|
|
19
|
+
* Associate an existing file with an existing row
|
|
20
|
+
* @param {number | number[]} fileIds Existing files to associate
|
|
21
|
+
* @param {number} slice Target slice
|
|
22
|
+
* @param {number} rowId Target slice record
|
|
23
|
+
* @param {string} field Record filed file should be added to
|
|
24
|
+
* @param {true} chain Submit request automatically if falsy, returns as a chained command otherwise
|
|
25
|
+
* @return {any} Unknown
|
|
26
|
+
*/
|
|
27
|
+
associate(fileIds: number | number[], slice: number, rowId: number, field: string, chain: true): {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
associate(fileIds: number | number[], slice: number, rowId: number, field: string): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Get an authenticated URL to fetch files from
|
|
33
|
+
* @param {number} id File ID
|
|
34
|
+
* @param {boolean} ignoreToken Ignore authentication
|
|
35
|
+
* @return {string} URL file can be viewed at
|
|
36
|
+
*/
|
|
37
|
+
get(id: number, ignoreToken?: boolean): string;
|
|
38
|
+
/**
|
|
39
|
+
* Upload file(s) to the API & optionally associate them with a row
|
|
40
|
+
* @param {FileList | File | File[]} files Files to be uploaded
|
|
41
|
+
* @param {{slice: number, row: any, field: string, pk?: string}} associate Row to associate with
|
|
42
|
+
*/
|
|
43
|
+
upload(files: FileList | File | File[], associate?: {
|
|
44
|
+
slice: number;
|
|
45
|
+
row: number | any;
|
|
46
|
+
field: string;
|
|
47
|
+
pk?: string;
|
|
48
|
+
}): Promise<UploadedFile[]>;
|
|
49
|
+
}
|
|
50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C,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CAyB5I"}
|
package/dist/index.cjs
CHANGED
|
@@ -1427,13 +1427,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1427
1427
|
__publicField(this, "user$", new BehaviorSubject(null));
|
|
1428
1428
|
this.api = api;
|
|
1429
1429
|
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Check whether user has a token
|
|
1432
|
-
* @return {boolean}
|
|
1433
|
-
*/
|
|
1434
|
-
get isAuthenticated() {
|
|
1435
|
-
return !!this.user;
|
|
1436
|
-
}
|
|
1437
1430
|
get user() {
|
|
1438
1431
|
return this.user$.getValue();
|
|
1439
1432
|
}
|
|
@@ -1471,6 +1464,42 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1471
1464
|
location.reload();
|
|
1472
1465
|
}
|
|
1473
1466
|
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Check whether user has a token
|
|
1469
|
+
* @return {boolean} True if session token authenticated
|
|
1470
|
+
*/
|
|
1471
|
+
isAuthenticated() {
|
|
1472
|
+
return !!this.user && !this.user.guest;
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Check if the current user is a guest
|
|
1476
|
+
* @return {boolean} True if guest
|
|
1477
|
+
*/
|
|
1478
|
+
isGuest() {
|
|
1479
|
+
var _a;
|
|
1480
|
+
return !!((_a = this.user) == null ? void 0 : _a.guest);
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Check if user is a system administrator
|
|
1484
|
+
* @return {Promise<boolean>} True if system administrator
|
|
1485
|
+
*/
|
|
1486
|
+
async isSysAdmin() {
|
|
1487
|
+
return !!(await this.api.slice("sysadmin").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Check if user is a table administrator
|
|
1491
|
+
* @return {Promise<boolean>} True if table administrator
|
|
1492
|
+
*/
|
|
1493
|
+
async isTableAdmin() {
|
|
1494
|
+
return !!(await this.api.slice("tableadmins").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Check if user is a user administrator
|
|
1498
|
+
* @return {Promise<boolean>} True if user administrator
|
|
1499
|
+
*/
|
|
1500
|
+
async isUserAdmin() {
|
|
1501
|
+
return !!(await this.api.slice("useradmins").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1502
|
+
}
|
|
1474
1503
|
/**
|
|
1475
1504
|
* Create Login UI
|
|
1476
1505
|
* @param {string} spoke Desired spoke
|
|
@@ -1489,7 +1518,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1489
1518
|
* @returns {Promise<any>} Session information returned from login request
|
|
1490
1519
|
*/
|
|
1491
1520
|
login(spoke, login, password, twoFactor) {
|
|
1492
|
-
return fetch(`${this.api.url}login`, {
|
|
1521
|
+
return fetch(`${this.api.url}/login`, {
|
|
1493
1522
|
method: "POST",
|
|
1494
1523
|
body: xt(rt({
|
|
1495
1524
|
realm: spoke.trim(),
|
|
@@ -1500,7 +1529,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1500
1529
|
}))
|
|
1501
1530
|
}).then(async (resp) => {
|
|
1502
1531
|
const data = await resp.json().catch(() => ({}));
|
|
1503
|
-
if (!resp.ok) throw Dt(resp.status, data.error);
|
|
1532
|
+
if (!resp.ok || data["error"]) throw Object.assign(Dt(resp.status, data.error) || {}, data);
|
|
1533
|
+
this.api.token = data["token"];
|
|
1534
|
+
return data;
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Login as guest user
|
|
1539
|
+
* @return {Promise<any>}
|
|
1540
|
+
*/
|
|
1541
|
+
loginGuest() {
|
|
1542
|
+
return fetch(`${this.api.url}/guest`).then(async (resp) => {
|
|
1543
|
+
const data = await resp.json().catch(() => ({}));
|
|
1544
|
+
if (!resp.ok || data["error"]) throw Object.assign(Dt(resp.status, data.error) || {}, data);
|
|
1504
1545
|
this.api.token = data["token"];
|
|
1505
1546
|
return data;
|
|
1506
1547
|
});
|
|
@@ -1515,6 +1556,84 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1515
1556
|
return resp;
|
|
1516
1557
|
});
|
|
1517
1558
|
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Reset user account password
|
|
1561
|
+
* @param {string} login User login
|
|
1562
|
+
* @param {string} newPassword New password
|
|
1563
|
+
* @param {string} code Reset code sent with `resetRequest`
|
|
1564
|
+
* @return {Promise<any>} New session
|
|
1565
|
+
*/
|
|
1566
|
+
reset(login, newPassword, code) {
|
|
1567
|
+
return this.api.request({ "$/auth/mobile/rescue": {
|
|
1568
|
+
user: login,
|
|
1569
|
+
password: newPassword,
|
|
1570
|
+
pin: code
|
|
1571
|
+
} }).then((resp) => {
|
|
1572
|
+
if (resp.token) this.api.token = resp.token;
|
|
1573
|
+
return resp;
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Request reset code for user
|
|
1578
|
+
* @param {string} login User to reset
|
|
1579
|
+
* @param {"email" | "sms" | "voice"} mode Method of sending reset code
|
|
1580
|
+
* @return {Promise<any>} Unknown
|
|
1581
|
+
*/
|
|
1582
|
+
resetRequest(login, mode) {
|
|
1583
|
+
if (mode == "email") return this.api.request({ "$/auth/rescue_email": { user: { $or: { login, email: login } } } });
|
|
1584
|
+
return this.api.request({ "$/auth/mobile/generate": { user: login, method: mode } });
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
class Files {
|
|
1588
|
+
constructor(api) {
|
|
1589
|
+
__publicField(this, "url");
|
|
1590
|
+
this.api = api;
|
|
1591
|
+
this.url = `${this.api.url}/file`;
|
|
1592
|
+
}
|
|
1593
|
+
associate(fileIds, slice, rowId, field, chain) {
|
|
1594
|
+
const req = { [`${chain ? "!" : "$"}/tools/file/update`]: { row: rowId, field, slice, ids: fileIds } };
|
|
1595
|
+
if (!chain) return this.api.request(req);
|
|
1596
|
+
return req;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Get an authenticated URL to fetch files from
|
|
1600
|
+
* @param {number} id File ID
|
|
1601
|
+
* @param {boolean} ignoreToken Ignore authentication
|
|
1602
|
+
* @return {string} URL file can be viewed at
|
|
1603
|
+
*/
|
|
1604
|
+
get(id, ignoreToken) {
|
|
1605
|
+
return `${this.url}?id=${id}${ignoreToken ? "" : `&token=${this.api.token}`}`;
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Upload file(s) to the API & optionally associate them with a row
|
|
1609
|
+
* @param {FileList | File | File[]} files Files to be uploaded
|
|
1610
|
+
* @param {{slice: number, row: any, field: string, pk?: string}} associate Row to associate with
|
|
1611
|
+
*/
|
|
1612
|
+
upload(files, associate) {
|
|
1613
|
+
let f = [];
|
|
1614
|
+
if (files instanceof FileList) f = Array.from(files);
|
|
1615
|
+
else f = Array.isArray(files) ? files : [files];
|
|
1616
|
+
return Promise.all(f.map((file) => {
|
|
1617
|
+
const data = new FormData();
|
|
1618
|
+
data.append("", file, file.name);
|
|
1619
|
+
return fetch(this.url, {
|
|
1620
|
+
method: "POST",
|
|
1621
|
+
headers: rt({ "Authorization": this.api.token ? `Bearer ${this.api.token}` : "" }),
|
|
1622
|
+
body: data
|
|
1623
|
+
}).then(async (resp) => {
|
|
1624
|
+
const data2 = await resp.json().catch(() => ({}));
|
|
1625
|
+
if (!resp.ok || data2["error"]) throw Object.assign(Dt(resp.status, data2.error) || {}, data2);
|
|
1626
|
+
return resp;
|
|
1627
|
+
});
|
|
1628
|
+
})).then(async (files2) => {
|
|
1629
|
+
if (associate) {
|
|
1630
|
+
let id = typeof associate.row == "number" ? associate.row : associate.row[associate.pk || "id"];
|
|
1631
|
+
if (!id) id = await this.api.slice(associate.slice).insert(associate.row).exec().key();
|
|
1632
|
+
await this.associate(files2.map((f2) => f2.id), associate == null ? void 0 : associate.slice, associate == null ? void 0 : associate.row, associate == null ? void 0 : associate.field);
|
|
1633
|
+
}
|
|
1634
|
+
return files2;
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1518
1637
|
}
|
|
1519
1638
|
const Serializer = {
|
|
1520
1639
|
/**
|
|
@@ -2007,6 +2126,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2007
2126
|
};
|
|
2008
2127
|
}
|
|
2009
2128
|
}
|
|
2129
|
+
class Superuser {
|
|
2130
|
+
constructor(api) {
|
|
2131
|
+
this.api = api;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Switch to another user by ID
|
|
2135
|
+
* @param {number} userId User ID
|
|
2136
|
+
* @return {Promise<any>} New session
|
|
2137
|
+
*/
|
|
2138
|
+
assume(userId) {
|
|
2139
|
+
return this.api.request({ "$/report/users/become": { id: userId } }).then((resp) => {
|
|
2140
|
+
if (resp.token) this.api.token = resp.token;
|
|
2141
|
+
return resp;
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Turn on the superuser flag, required to make any of the requests in the module
|
|
2146
|
+
* @param {string} username Superuser account
|
|
2147
|
+
* @param {string} password Superuser password
|
|
2148
|
+
* @return {Promise<any>} Unknown
|
|
2149
|
+
*/
|
|
2150
|
+
on(username, password) {
|
|
2151
|
+
return this.api.request({ "$/superuser/validate": {
|
|
2152
|
+
name: username,
|
|
2153
|
+
password
|
|
2154
|
+
} });
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2010
2157
|
class Api {
|
|
2011
2158
|
/**
|
|
2012
2159
|
* Object to handle communications between the app and Datalynk
|
|
@@ -2025,15 +2172,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2025
2172
|
// Cache for ongoing requests
|
|
2026
2173
|
/** Authentication helpers */
|
|
2027
2174
|
__publicField(this, "auth", new Auth(this));
|
|
2175
|
+
/** File helpers */
|
|
2176
|
+
__publicField(this, "files", new Files(this));
|
|
2028
2177
|
/** Socket object */
|
|
2029
2178
|
__publicField(this, "socket");
|
|
2179
|
+
/** Superuser helpers */
|
|
2180
|
+
__publicField(this, "superuser", new Superuser(this));
|
|
2030
2181
|
/** API endpoint */
|
|
2031
2182
|
__publicField(this, "url");
|
|
2032
2183
|
// API URL endpoint for requests
|
|
2033
2184
|
/** API Session token */
|
|
2034
2185
|
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2035
2186
|
this.options = options;
|
|
2036
|
-
this.url = `${url}${url.endsWith("/") ? "" : "/"}api
|
|
2187
|
+
this.url = `${url}${url.endsWith("/") ? "" : "/"}api`;
|
|
2037
2188
|
this.options = {
|
|
2038
2189
|
bundleTime: 100,
|
|
2039
2190
|
origin: typeof location !== "undefined" ? location.host : "Unknown",
|
|
@@ -2154,10 +2305,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2154
2305
|
}
|
|
2155
2306
|
exports2.Api = Api;
|
|
2156
2307
|
exports2.Auth = Auth;
|
|
2308
|
+
exports2.Files = Files;
|
|
2157
2309
|
exports2.LoginPrompt = LoginPrompt;
|
|
2158
2310
|
exports2.Serializer = Serializer;
|
|
2159
2311
|
exports2.Slice = Slice;
|
|
2160
2312
|
exports2.SlicePromise = SlicePromise;
|
|
2161
2313
|
exports2.Socket = Socket;
|
|
2314
|
+
exports2.Superuser = Superuser;
|
|
2162
2315
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
2163
2316
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './api';
|
|
2
2
|
export * from './auth';
|
|
3
|
+
export * from './files';
|
|
3
4
|
export * from './login-prompt';
|
|
4
5
|
export * from './serializer';
|
|
5
6
|
export * from './slice';
|
|
6
7
|
export * from './socket';
|
|
8
|
+
export * from './superuser';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1423,13 +1423,6 @@ class Auth {
|
|
|
1423
1423
|
__publicField(this, "user$", new BehaviorSubject(null));
|
|
1424
1424
|
this.api = api;
|
|
1425
1425
|
}
|
|
1426
|
-
/**
|
|
1427
|
-
* Check whether user has a token
|
|
1428
|
-
* @return {boolean}
|
|
1429
|
-
*/
|
|
1430
|
-
get isAuthenticated() {
|
|
1431
|
-
return !!this.user;
|
|
1432
|
-
}
|
|
1433
1426
|
get user() {
|
|
1434
1427
|
return this.user$.getValue();
|
|
1435
1428
|
}
|
|
@@ -1467,6 +1460,42 @@ class Auth {
|
|
|
1467
1460
|
location.reload();
|
|
1468
1461
|
}
|
|
1469
1462
|
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Check whether user has a token
|
|
1465
|
+
* @return {boolean} True if session token authenticated
|
|
1466
|
+
*/
|
|
1467
|
+
isAuthenticated() {
|
|
1468
|
+
return !!this.user && !this.user.guest;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Check if the current user is a guest
|
|
1472
|
+
* @return {boolean} True if guest
|
|
1473
|
+
*/
|
|
1474
|
+
isGuest() {
|
|
1475
|
+
var _a;
|
|
1476
|
+
return !!((_a = this.user) == null ? void 0 : _a.guest);
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Check if user is a system administrator
|
|
1480
|
+
* @return {Promise<boolean>} True if system administrator
|
|
1481
|
+
*/
|
|
1482
|
+
async isSysAdmin() {
|
|
1483
|
+
return !!(await this.api.slice("sysadmin").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Check if user is a table administrator
|
|
1487
|
+
* @return {Promise<boolean>} True if table administrator
|
|
1488
|
+
*/
|
|
1489
|
+
async isTableAdmin() {
|
|
1490
|
+
return !!(await this.api.slice("tableadmins").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Check if user is a user administrator
|
|
1494
|
+
* @return {Promise<boolean>} True if user administrator
|
|
1495
|
+
*/
|
|
1496
|
+
async isUserAdmin() {
|
|
1497
|
+
return !!(await this.api.slice("useradmins").select().where("auth_ref", "==", "$viewer").exec().keys()).length;
|
|
1498
|
+
}
|
|
1470
1499
|
/**
|
|
1471
1500
|
* Create Login UI
|
|
1472
1501
|
* @param {string} spoke Desired spoke
|
|
@@ -1485,7 +1514,7 @@ class Auth {
|
|
|
1485
1514
|
* @returns {Promise<any>} Session information returned from login request
|
|
1486
1515
|
*/
|
|
1487
1516
|
login(spoke, login, password, twoFactor) {
|
|
1488
|
-
return fetch(`${this.api.url}login`, {
|
|
1517
|
+
return fetch(`${this.api.url}/login`, {
|
|
1489
1518
|
method: "POST",
|
|
1490
1519
|
body: xt(rt({
|
|
1491
1520
|
realm: spoke.trim(),
|
|
@@ -1496,7 +1525,19 @@ class Auth {
|
|
|
1496
1525
|
}))
|
|
1497
1526
|
}).then(async (resp) => {
|
|
1498
1527
|
const data = await resp.json().catch(() => ({}));
|
|
1499
|
-
if (!resp.ok) throw Dt(resp.status, data.error);
|
|
1528
|
+
if (!resp.ok || data["error"]) throw Object.assign(Dt(resp.status, data.error) || {}, data);
|
|
1529
|
+
this.api.token = data["token"];
|
|
1530
|
+
return data;
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Login as guest user
|
|
1535
|
+
* @return {Promise<any>}
|
|
1536
|
+
*/
|
|
1537
|
+
loginGuest() {
|
|
1538
|
+
return fetch(`${this.api.url}/guest`).then(async (resp) => {
|
|
1539
|
+
const data = await resp.json().catch(() => ({}));
|
|
1540
|
+
if (!resp.ok || data["error"]) throw Object.assign(Dt(resp.status, data.error) || {}, data);
|
|
1500
1541
|
this.api.token = data["token"];
|
|
1501
1542
|
return data;
|
|
1502
1543
|
});
|
|
@@ -1511,6 +1552,84 @@ class Auth {
|
|
|
1511
1552
|
return resp;
|
|
1512
1553
|
});
|
|
1513
1554
|
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Reset user account password
|
|
1557
|
+
* @param {string} login User login
|
|
1558
|
+
* @param {string} newPassword New password
|
|
1559
|
+
* @param {string} code Reset code sent with `resetRequest`
|
|
1560
|
+
* @return {Promise<any>} New session
|
|
1561
|
+
*/
|
|
1562
|
+
reset(login, newPassword, code) {
|
|
1563
|
+
return this.api.request({ "$/auth/mobile/rescue": {
|
|
1564
|
+
user: login,
|
|
1565
|
+
password: newPassword,
|
|
1566
|
+
pin: code
|
|
1567
|
+
} }).then((resp) => {
|
|
1568
|
+
if (resp.token) this.api.token = resp.token;
|
|
1569
|
+
return resp;
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Request reset code for user
|
|
1574
|
+
* @param {string} login User to reset
|
|
1575
|
+
* @param {"email" | "sms" | "voice"} mode Method of sending reset code
|
|
1576
|
+
* @return {Promise<any>} Unknown
|
|
1577
|
+
*/
|
|
1578
|
+
resetRequest(login, mode) {
|
|
1579
|
+
if (mode == "email") return this.api.request({ "$/auth/rescue_email": { user: { $or: { login, email: login } } } });
|
|
1580
|
+
return this.api.request({ "$/auth/mobile/generate": { user: login, method: mode } });
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
class Files {
|
|
1584
|
+
constructor(api) {
|
|
1585
|
+
__publicField(this, "url");
|
|
1586
|
+
this.api = api;
|
|
1587
|
+
this.url = `${this.api.url}/file`;
|
|
1588
|
+
}
|
|
1589
|
+
associate(fileIds, slice, rowId, field, chain) {
|
|
1590
|
+
const req = { [`${chain ? "!" : "$"}/tools/file/update`]: { row: rowId, field, slice, ids: fileIds } };
|
|
1591
|
+
if (!chain) return this.api.request(req);
|
|
1592
|
+
return req;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Get an authenticated URL to fetch files from
|
|
1596
|
+
* @param {number} id File ID
|
|
1597
|
+
* @param {boolean} ignoreToken Ignore authentication
|
|
1598
|
+
* @return {string} URL file can be viewed at
|
|
1599
|
+
*/
|
|
1600
|
+
get(id, ignoreToken) {
|
|
1601
|
+
return `${this.url}?id=${id}${ignoreToken ? "" : `&token=${this.api.token}`}`;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Upload file(s) to the API & optionally associate them with a row
|
|
1605
|
+
* @param {FileList | File | File[]} files Files to be uploaded
|
|
1606
|
+
* @param {{slice: number, row: any, field: string, pk?: string}} associate Row to associate with
|
|
1607
|
+
*/
|
|
1608
|
+
upload(files, associate) {
|
|
1609
|
+
let f = [];
|
|
1610
|
+
if (files instanceof FileList) f = Array.from(files);
|
|
1611
|
+
else f = Array.isArray(files) ? files : [files];
|
|
1612
|
+
return Promise.all(f.map((file) => {
|
|
1613
|
+
const data = new FormData();
|
|
1614
|
+
data.append("", file, file.name);
|
|
1615
|
+
return fetch(this.url, {
|
|
1616
|
+
method: "POST",
|
|
1617
|
+
headers: rt({ "Authorization": this.api.token ? `Bearer ${this.api.token}` : "" }),
|
|
1618
|
+
body: data
|
|
1619
|
+
}).then(async (resp) => {
|
|
1620
|
+
const data2 = await resp.json().catch(() => ({}));
|
|
1621
|
+
if (!resp.ok || data2["error"]) throw Object.assign(Dt(resp.status, data2.error) || {}, data2);
|
|
1622
|
+
return resp;
|
|
1623
|
+
});
|
|
1624
|
+
})).then(async (files2) => {
|
|
1625
|
+
if (associate) {
|
|
1626
|
+
let id = typeof associate.row == "number" ? associate.row : associate.row[associate.pk || "id"];
|
|
1627
|
+
if (!id) id = await this.api.slice(associate.slice).insert(associate.row).exec().key();
|
|
1628
|
+
await this.associate(files2.map((f2) => f2.id), associate == null ? void 0 : associate.slice, associate == null ? void 0 : associate.row, associate == null ? void 0 : associate.field);
|
|
1629
|
+
}
|
|
1630
|
+
return files2;
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1514
1633
|
}
|
|
1515
1634
|
const Serializer = {
|
|
1516
1635
|
/**
|
|
@@ -2003,6 +2122,34 @@ class Socket {
|
|
|
2003
2122
|
};
|
|
2004
2123
|
}
|
|
2005
2124
|
}
|
|
2125
|
+
class Superuser {
|
|
2126
|
+
constructor(api) {
|
|
2127
|
+
this.api = api;
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Switch to another user by ID
|
|
2131
|
+
* @param {number} userId User ID
|
|
2132
|
+
* @return {Promise<any>} New session
|
|
2133
|
+
*/
|
|
2134
|
+
assume(userId) {
|
|
2135
|
+
return this.api.request({ "$/report/users/become": { id: userId } }).then((resp) => {
|
|
2136
|
+
if (resp.token) this.api.token = resp.token;
|
|
2137
|
+
return resp;
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Turn on the superuser flag, required to make any of the requests in the module
|
|
2142
|
+
* @param {string} username Superuser account
|
|
2143
|
+
* @param {string} password Superuser password
|
|
2144
|
+
* @return {Promise<any>} Unknown
|
|
2145
|
+
*/
|
|
2146
|
+
on(username, password) {
|
|
2147
|
+
return this.api.request({ "$/superuser/validate": {
|
|
2148
|
+
name: username,
|
|
2149
|
+
password
|
|
2150
|
+
} });
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2006
2153
|
class Api {
|
|
2007
2154
|
/**
|
|
2008
2155
|
* Object to handle communications between the app and Datalynk
|
|
@@ -2021,15 +2168,19 @@ class Api {
|
|
|
2021
2168
|
// Cache for ongoing requests
|
|
2022
2169
|
/** Authentication helpers */
|
|
2023
2170
|
__publicField(this, "auth", new Auth(this));
|
|
2171
|
+
/** File helpers */
|
|
2172
|
+
__publicField(this, "files", new Files(this));
|
|
2024
2173
|
/** Socket object */
|
|
2025
2174
|
__publicField(this, "socket");
|
|
2175
|
+
/** Superuser helpers */
|
|
2176
|
+
__publicField(this, "superuser", new Superuser(this));
|
|
2026
2177
|
/** API endpoint */
|
|
2027
2178
|
__publicField(this, "url");
|
|
2028
2179
|
// API URL endpoint for requests
|
|
2029
2180
|
/** API Session token */
|
|
2030
2181
|
__publicField(this, "token$", new BehaviorSubject(null));
|
|
2031
2182
|
this.options = options;
|
|
2032
|
-
this.url = `${url}${url.endsWith("/") ? "" : "/"}api
|
|
2183
|
+
this.url = `${url}${url.endsWith("/") ? "" : "/"}api`;
|
|
2033
2184
|
this.options = {
|
|
2034
2185
|
bundleTime: 100,
|
|
2035
2186
|
origin: typeof location !== "undefined" ? location.host : "Unknown",
|
|
@@ -2151,9 +2302,11 @@ class Api {
|
|
|
2151
2302
|
export {
|
|
2152
2303
|
Api,
|
|
2153
2304
|
Auth,
|
|
2305
|
+
Files,
|
|
2154
2306
|
LoginPrompt,
|
|
2155
2307
|
Serializer,
|
|
2156
2308
|
Slice,
|
|
2157
2309
|
SlicePromise,
|
|
2158
|
-
Socket
|
|
2310
|
+
Socket,
|
|
2311
|
+
Superuser
|
|
2159
2312
|
};
|
package/dist/slice.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare class Slice<T extends SliceMeta> {
|
|
|
96
96
|
* @param {number} slice Slice ID to interact with
|
|
97
97
|
* @param {Api} api Api to send the requests through
|
|
98
98
|
*/
|
|
99
|
-
constructor(slice: number, api: Api);
|
|
99
|
+
constructor(slice: number | string, api: Api);
|
|
100
100
|
/**
|
|
101
101
|
* Whitelist and alias fields. Alias for the fields functions
|
|
102
102
|
* @param {object} aliasKeyVals List of properties to whitelist and what to rename them to
|
package/dist/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAmB,WAAW,EAAC,MAAM,UAAU,CAAC;AAEvD,MAAM,WAAW,SAAS;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,SAAS;aAOhB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;aAAkB,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAL/F;;;;OAIG;gBACyB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAkB,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAE/F;;OAEG;IACH,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC;IAKxB;;OAEG;IACG,MAAM;IAKZ;;OAEG;IACG,OAAO;IAKb;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;I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ASxC;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAO;IAoBd;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE;IAQpB;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC;CAgC5D"}
|
package/dist/socket.d.ts
CHANGED
|
@@ -51,6 +51,6 @@ export declare class Socket {
|
|
|
51
51
|
* @param {SocketListener<SocketEventSlice>} callback Function to run on changes
|
|
52
52
|
* @return {Unsubscribe} Run returned function to unsubscribe callback
|
|
53
53
|
*/
|
|
54
|
-
sliceEvents(slice: number | number[], callback: SocketListener<SocketEventSlice>): Unsubscribe;
|
|
54
|
+
sliceEvents(slice: number | number[] | string | string[], callback: SocketListener<SocketEventSlice>): Unsubscribe;
|
|
55
55
|
}
|
|
56
56
|
//# sourceMappingURL=socket.d.ts.map
|
package/dist/socket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../src/socket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAA;CACP,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAA;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MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC;AACrE,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,qBAAa,MAAM;IAON,OAAO,CAAC,QAAQ,CAAC,GAAG;aAAuB,OAAO,EAAE,aAAa;IAN7E,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAa;IAE3B,IAAI,IAAI,YAA0C;gBAErB,GAAG,EAAE,GAAG,EAAkB,OAAO,GAAE,aAAkB;IAUlF;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,cAAc,GAAG,WAAW;IAK5C;;OAEG;IACH,KAAK;IAKL;;;OAGG;IACH,OAAO,CAAC,OAAO,SAAQ;IA8BvB;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,GAAG;IAIjB;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,cAAc,CAAC,gBAAgB,CAAC,GAAG,WAAW;CAelH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Superuser helpers
|
|
5
|
+
*/
|
|
6
|
+
export declare class Superuser {
|
|
7
|
+
private readonly api;
|
|
8
|
+
constructor(api: Api);
|
|
9
|
+
/**
|
|
10
|
+
* Switch to another user by ID
|
|
11
|
+
* @param {number} userId User ID
|
|
12
|
+
* @return {Promise<any>} New session
|
|
13
|
+
*/
|
|
14
|
+
assume(userId: number): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Turn on the superuser flag, required to make any of the requests in the module
|
|
17
|
+
* @param {string} username Superuser account
|
|
18
|
+
* @param {string} password Superuser password
|
|
19
|
+
* @return {Promise<any>} Unknown
|
|
20
|
+
*/
|
|
21
|
+
on(username: string, password: string): Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=superuser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"superuser.d.ts","sourceRoot":"","sources":["../src/superuser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,qBAAa,SAAS;IAET,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG;IAErC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM;IAOrB;;;;;OAKG;IACH,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAMrC"}
|
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/ztimson/datalynk-client",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.5.0",
|
|
6
6
|
"author": "Zak Timson",
|
|
7
7
|
"private": false,
|
|
8
8
|
"main": "./dist/index.cjs",
|