@auxilium/datalynk-client 0.4.1 → 0.4.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 ADDED
@@ -0,0 +1,93 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { Auth } from './auth';
3
+ import { Slice, SliceMeta } from './slice';
4
+ import { Socket } from './socket';
5
+
6
+ /**
7
+ * Function definition for API callbacks
8
+ */
9
+ export type ApiCallback = (code: number, data: any) => void;
10
+ /**
11
+ * Api connection options
12
+ */
13
+ export type ApiOptions = {
14
+ /** Bundle requests that happen within X ms to save network overhead */
15
+ bundleTime?: number;
16
+ /** Name of client for logging */
17
+ origin?: string;
18
+ /** Save session token to localStorage to persist logins */
19
+ saveSession?: boolean;
20
+ /** Disable sockets or override socket URL */
21
+ socket?: false | string;
22
+ };
23
+ /**
24
+ * Options when making requests
25
+ */
26
+ export interface ApiRequestOptions {
27
+ /** Skip optimizations like bundling & caching */
28
+ force?: boolean;
29
+ /** Skip the token translating step */
30
+ raw?: boolean;
31
+ /** Skip wrapping IDs in an array */
32
+ rawUpload?: boolean;
33
+ }
34
+ /** Request error shape */
35
+ export interface ApiRequestError {
36
+ message: string;
37
+ request: any;
38
+ debug?: any;
39
+ trace?: any;
40
+ }
41
+ /**
42
+ * Object to handle communications between the app and Datalynk
43
+ */
44
+ export declare class Api {
45
+ readonly options: ApiOptions;
46
+ /** Current requests bundle */
47
+ private bundle;
48
+ /** Bundle lifecycle tracking */
49
+ private bundleOngoing;
50
+ /** LocalStorage key for persisting logins */
51
+ private localStorageKey;
52
+ /** Pending requests */
53
+ private pending;
54
+ /** Authentication helpers */
55
+ readonly auth: Auth;
56
+ /** Socket object */
57
+ readonly socket: Socket;
58
+ /** API endpoint */
59
+ readonly url: string;
60
+ /** API Session token */
61
+ token$: BehaviorSubject<string | null>;
62
+ get token(): string | null;
63
+ set token(token: string | null);
64
+ /**
65
+ * Object to handle communications between the app and Datalynk
66
+ * @param {string} url API URL
67
+ * @param {ApiOptions} options
68
+ */
69
+ constructor(url: string, options?: ApiOptions);
70
+ private _request;
71
+ private static translateTokens;
72
+ /**
73
+ * Send a request to Datalynk
74
+ * @param {object} data request
75
+ * @param {ApiRequestOptions} options Options
76
+ * @returns {Promise<any>} Promise of response
77
+ */
78
+ request<T = any>(data: any, options?: ApiRequestOptions): Promise<T>;
79
+ /**
80
+ * Use the slice object to create the request
81
+ * @param {number} slice ID of the slice to use
82
+ * @returns {Slice<T extends SliceMeta>} Slice object to create query
83
+ */
84
+ slice<T extends SliceMeta>(slice: number): Slice<T>;
85
+ /**
86
+ * Send a request and automatically log the output
87
+ * @param {object | string} data request
88
+ * @param {ApiRequestOptions} options Options
89
+ * @returns {Promise<any>} Promise of response
90
+ */
91
+ test<T = any>(data: any, options?: ApiRequestOptions): Promise<T>;
92
+ }
93
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +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;AAE5B,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AACzC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC;;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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AAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM;IAI/C;;;;;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 ADDED
@@ -0,0 +1,55 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { Api } from './api';
3
+
4
+ /** User */
5
+ export type User = {
6
+ id: Number;
7
+ token: string;
8
+ guest: boolean;
9
+ sysadmin: boolean;
10
+ first_name: string;
11
+ last_name: string;
12
+ email: string;
13
+ login: string;
14
+ "2FA"?: string;
15
+ "2FA_code"?: string;
16
+ mobile_phone?: string;
17
+ spoke: string;
18
+ };
19
+ /**
20
+ * Authentication requests
21
+ */
22
+ export declare class Auth {
23
+ private readonly api;
24
+ /**
25
+ * Check whether user has a token
26
+ * @return {boolean}
27
+ */
28
+ get isAuthenticated(): boolean;
29
+ user$: BehaviorSubject<User | null>;
30
+ get user(): User | null;
31
+ set user(user: User | null);
32
+ constructor(api: Api);
33
+ /**
34
+ * Get current user associated with API token
35
+ * @return {Promise<User | null>}
36
+ */
37
+ current(): Promise<null | User>;
38
+ /**
39
+ * Perform login and save the session token
40
+ * @param {string} login Login username or email
41
+ * @param {string} password Password for account
42
+ * @param {string} spoke Override login spoke
43
+ * @returns {Promise<any>} Session information returned from login request
44
+ */
45
+ login(spoke: string, login: string, password: string): Promise<any>;
46
+ /**
47
+ * Logout current user
48
+ * @return {Promise<{closed: string, new: string}>}
49
+ */
50
+ logout(): Promise<{
51
+ closed: string;
52
+ new: string;
53
+ }>;
54
+ }
55
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +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;AAG1B,WAAW;AACX,MAAM,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACd,CAAA;AAED;;GAEG;AACH,qBAAa,IAAI;IAYJ,OAAO,CAAC,QAAQ,CAAC,GAAG;IAVhC;;;OAGG;IACH,IAAI,eAAe,YAA0B;IAE7C,KAAK,+BAA0C;IAC/C,IAAI,IAAI,IACO,IAAI,GAAG,IAAI,CADkB;IAC5C,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAA4B;gBAEzB,GAAG,EAAE,GAAG;IAErC;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAW/B;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAWnE;;;OAGG;IACH,MAAM;gBAC6B,MAAM;aAAO,MAAM;;CAMtD"}