@auxilium/datalynk-client 0.2.0 → 0.2.1

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,89 @@
1
+ import { Auth } from './auth';
2
+ import { Slice } from './slice';
3
+
4
+ /**
5
+ * Function definition for API callbacks
6
+ */
7
+ export type ApiCallback = (code: number, data: any) => void;
8
+ /**
9
+ * Api connection options
10
+ */
11
+ export interface ApiOptions {
12
+ /** Bundle requests that happen within X ms to save network overhead */
13
+ bundleTime?: number;
14
+ /** Name of client for logging */
15
+ origin?: string;
16
+ /** Save session token to localStorage to persist logins */
17
+ saveSession?: boolean;
18
+ }
19
+ /**
20
+ * Options when making requests
21
+ */
22
+ export interface RequestOptions {
23
+ /** Skip optimizations like bundling & caching */
24
+ force?: boolean;
25
+ /** Skip the token translating step */
26
+ raw?: boolean;
27
+ /** Skip wrapping IDs in an array */
28
+ rawUpload?: boolean;
29
+ /** Override target spoke */
30
+ spoke?: string;
31
+ }
32
+ /**
33
+ * Object to handle communications between the app and Datalynk
34
+ */
35
+ export declare class Api {
36
+ readonly url: string;
37
+ spoke: string;
38
+ readonly options: ApiOptions;
39
+ /** Current requests bundle */
40
+ private bundle;
41
+ /** Bundle lifecycle tracking */
42
+ private bundleOngoing;
43
+ /** API dispatch endpoint */
44
+ private endpoint;
45
+ /** Client created callbacks to HTTP status codes */
46
+ private eventCallbacks;
47
+ /** Pending requests */
48
+ private pending;
49
+ readonly auth: Auth;
50
+ /** Session token - Syncs to localStorage */
51
+ private _token;
52
+ get token(): string | null;
53
+ set token(token: string | null);
54
+ /**
55
+ * Object to handle communications between the app and Datalynk
56
+ * @param {string} url API URL
57
+ * @param {ApiOptions} options
58
+ */
59
+ constructor(url: string, spoke: string, options?: ApiOptions);
60
+ private _request;
61
+ private static translateTokens;
62
+ /**
63
+ * Add an error code listener
64
+ * @param {number} code the error code to listen to
65
+ * @param {ApiCallback} fn the callback function
66
+ */
67
+ addListener(code: number, fn: ApiCallback): void;
68
+ /**
69
+ * Send a request to Datalynk
70
+ * @param {object} data request
71
+ * @param {RequestOptions} options Options
72
+ * @returns {Promise<any>} Promise of response
73
+ */
74
+ request<T = any>(data: any, options?: RequestOptions): Promise<T>;
75
+ /**
76
+ * Use the slice object to create the request
77
+ * @param {number} slice ID of the slice to use
78
+ * @returns {Slice<T>} Slice object to create query
79
+ */
80
+ slice<T>(slice: number): Slice<T>;
81
+ /**
82
+ * Send a request and automatically log the output
83
+ * @param {object | string} data request
84
+ * @param {RequestOptions} options Options
85
+ * @returns {Promise<any>} Promise of response
86
+ */
87
+ test<T = any>(data: any, options?: RequestOptions): Promise<T>;
88
+ }
89
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sCAAsC;IACtC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,GAAG;aAkCc,GAAG,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;aAAkB,OAAO,EAAE,UAAU;IAjClG,8BAA8B;IAC9B,OAAO,CAAC,MAAM,CAAwD;IACtE,gCAAgC;IAChC,OAAO,CAAC,aAAa,CAAkB;IACvC,4BAA4B;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,oDAAoD;IACpD,OAAO,CAAC,cAAc,CAAwC;IAC9D,uBAAuB;IACvB,OAAO,CAAC,OAAO,CAA8B;IAG7C,QAAQ,CAAC,IAAI,OAAkB;IAE/B,4CAA4C;IAC5C,OAAO,CAAC,MAAM,CAAuB;IACrC,IAAI,KAAK,IAIQ,MAAM,GAAG,IAAI,CAD7B;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAM7B;IAED;;;;OAIG;gBACyB,GAAG,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAkB,OAAO,GAAE,UAAe;IAUvG,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,MAAM,CAAC,eAAe;IAsB9B;;;;OAIG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW;IAKhD;;;;;OAKG;IACI,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAmC5E;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM;IAI7B;;;;;OAKG;IACI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;CAU1E"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { Api } from './api';
2
+
3
+ /** User */
4
+ export type User = {
5
+ id: Number;
6
+ token: string;
7
+ guest: boolean;
8
+ sysadmin: boolean;
9
+ first_name: string;
10
+ last_name: string;
11
+ email: string;
12
+ login: string;
13
+ "2FA"?: string;
14
+ "2FA_code"?: string;
15
+ mobile_phone?: string;
16
+ spoke: string;
17
+ };
18
+ /**
19
+ * Authentication requests
20
+ */
21
+ export declare class Auth {
22
+ private readonly api;
23
+ /**
24
+ * Check whether user has a token
25
+ * @return {boolean}
26
+ */
27
+ get isAuthenticated(): boolean;
28
+ constructor(api: Api);
29
+ /**
30
+ * Get current user associated with API token
31
+ * @return {Promise<User | null>}
32
+ */
33
+ current(): Promise<null | User>;
34
+ /**
35
+ * Perform login and save the session token
36
+ * @param {string} login Login username or email
37
+ * @param {string} password Password for account
38
+ * @param {string} spoke Override login spoke
39
+ * @returns {Promise<any>} Session information returned from login request
40
+ */
41
+ login(login: string, password: string, spoke?: string): Promise<any>;
42
+ /**
43
+ * Logout current user
44
+ * @return {Promise<{closed: string, new: string}>}
45
+ */
46
+ logout(): Promise<{
47
+ closed: string;
48
+ new: string;
49
+ }>;
50
+ }
51
+ //# 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,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,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;IAQJ,OAAO,CAAC,QAAQ,CAAC,GAAG;IANhC;;;OAGG;IACH,IAAI,eAAe,YAA+B;gBAErB,GAAG,EAAE,GAAG;IAErC;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAK/B;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAOpE;;;OAGG;IACH,MAAM;gBAC4B,MAAM;aAAO,MAAM;;CAMrD"}