@cripty2001/utils 0.0.63 → 0.0.65
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Whispr } from "@cripty2001/whispr";
|
|
1
2
|
import { AppserverData } from "./common";
|
|
2
3
|
export type { AppserverData };
|
|
3
4
|
export declare class ClientError extends Error {
|
|
@@ -14,8 +15,10 @@ export declare class ClientValidationError extends ClientError {
|
|
|
14
15
|
}
|
|
15
16
|
export declare class Client {
|
|
16
17
|
private url;
|
|
17
|
-
constructor(url: string);
|
|
18
18
|
private authToken;
|
|
19
|
+
loggedIn: Whispr<boolean>;
|
|
20
|
+
private constructor();
|
|
21
|
+
static create(url: string): Client;
|
|
19
22
|
setAuthToken(token: string | null): void;
|
|
20
23
|
exec<I extends AppserverData, O extends AppserverData>(action: string, input: I): Promise<O>;
|
|
21
24
|
}
|
package/dist/Appserver/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Client = exports.ClientValidationError = exports.ClientServerError = exports.ClientError = void 0;
|
|
4
|
+
const whispr_1 = require("@cripty2001/whispr");
|
|
4
5
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
5
6
|
class ClientError extends Error {
|
|
6
7
|
constructor(message) {
|
|
@@ -28,12 +29,18 @@ class ClientValidationError extends ClientError {
|
|
|
28
29
|
exports.ClientValidationError = ClientValidationError;
|
|
29
30
|
class Client {
|
|
30
31
|
url;
|
|
32
|
+
authToken;
|
|
33
|
+
loggedIn;
|
|
31
34
|
constructor(url) {
|
|
32
35
|
this.url = url;
|
|
36
|
+
[this.authToken, this.setAuthToken] = whispr_1.Whispr.create(null);
|
|
37
|
+
this.loggedIn = whispr_1.Whispr.from({ authToken: this.authToken }, ({ authToken }) => authToken !== null);
|
|
38
|
+
}
|
|
39
|
+
static create(url) {
|
|
40
|
+
return new Client(url);
|
|
33
41
|
}
|
|
34
|
-
authToken = null;
|
|
35
42
|
setAuthToken(token) {
|
|
36
|
-
this.
|
|
43
|
+
this.setAuthToken(token ?? null);
|
|
37
44
|
}
|
|
38
45
|
async exec(action, input) {
|
|
39
46
|
const res = await fetch(`${this.url}/exec/${action}`, {
|
|
@@ -49,7 +56,7 @@ class Client {
|
|
|
49
56
|
switch (res.status) {
|
|
50
57
|
case 401:
|
|
51
58
|
case 403:
|
|
52
|
-
this.
|
|
59
|
+
this.setAuthToken(null);
|
|
53
60
|
throw new ClientError("Permission denied");
|
|
54
61
|
case 200:
|
|
55
62
|
responseData = decoded;
|
package/package.json
CHANGED