@cripty2001/utils 0.0.49 → 0.0.51
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/Appserver/client.d.ts +2 -0
- package/dist/Appserver/client.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/react-whispr.d.ts +0 -1
- package/dist/react-whispr.js +2 -7
- package/package.json +1 -1
|
@@ -14,5 +14,7 @@ export declare class ClientValidationError extends ClientError {
|
|
|
14
14
|
export declare class Client {
|
|
15
15
|
private url;
|
|
16
16
|
constructor(url: string);
|
|
17
|
+
private authToken;
|
|
18
|
+
setAuthToken(token: string | null): void;
|
|
17
19
|
exec<I extends AppserverData, O extends AppserverData>(action: string, input: I): Promise<O>;
|
|
18
20
|
}
|
package/dist/Appserver/client.js
CHANGED
|
@@ -31,17 +31,26 @@ class Client {
|
|
|
31
31
|
constructor(url) {
|
|
32
32
|
this.url = url;
|
|
33
33
|
}
|
|
34
|
+
authToken = null;
|
|
35
|
+
setAuthToken(token) {
|
|
36
|
+
this.authToken = token;
|
|
37
|
+
}
|
|
34
38
|
async exec(action, input) {
|
|
35
39
|
const res = await fetch(`${this.url}/exec/${action}`, {
|
|
36
40
|
method: "POST",
|
|
37
41
|
headers: {
|
|
38
42
|
"Content-Type": "application/vnd.msgpack",
|
|
43
|
+
...(this.authToken !== null ? { "Authorization": `Bearer ${this.authToken}` } : {}),
|
|
39
44
|
},
|
|
40
45
|
body: new Blob([new Uint8Array((0, msgpack_1.encode)(input))], { type: 'application/msgpack' }),
|
|
41
46
|
});
|
|
42
47
|
const decoded = (0, msgpack_1.decode)(await res.arrayBuffer());
|
|
43
48
|
let responseData;
|
|
44
49
|
switch (res.status) {
|
|
50
|
+
case 401:
|
|
51
|
+
case 403:
|
|
52
|
+
this.authToken = null;
|
|
53
|
+
throw new ClientError("Permission denied");
|
|
45
54
|
case 200:
|
|
46
55
|
responseData = decoded;
|
|
47
56
|
return responseData;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Whispr } from "@cripty2001/whispr";
|
|
1
2
|
export type JSONEncodable = number | string | boolean | JSONEncodable[] | null | {
|
|
2
3
|
[key: string]: JSONEncodable;
|
|
3
4
|
};
|
|
@@ -82,3 +83,4 @@ export declare function randBetween(min: number, max: number): number;
|
|
|
82
83
|
* @returns The environment variable value, or the default value if provided
|
|
83
84
|
*/
|
|
84
85
|
export declare function getEnv(key: string, defaultValue?: string): string;
|
|
86
|
+
export declare const CURRENT_TS_MS: Whispr<number>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENT_TS_MS = void 0;
|
|
3
4
|
exports.getRandom = getRandom;
|
|
4
5
|
exports.getRandomId = getRandomId;
|
|
5
6
|
exports.getRandomOtp = getRandomOtp;
|
|
@@ -14,6 +15,7 @@ exports.stableLog = stableLog;
|
|
|
14
15
|
exports.parseQuery = parseQuery;
|
|
15
16
|
exports.randBetween = randBetween;
|
|
16
17
|
exports.getEnv = getEnv;
|
|
18
|
+
const whispr_1 = require("@cripty2001/whispr");
|
|
17
19
|
const lodash_1 = require("lodash");
|
|
18
20
|
/**
|
|
19
21
|
* Generate a random string from the given alphabeth.
|
|
@@ -199,3 +201,8 @@ function getEnv(key, defaultValue) {
|
|
|
199
201
|
throw new Error(`Environment variable ${key} is not defined and no default value was provided.`);
|
|
200
202
|
return value;
|
|
201
203
|
}
|
|
204
|
+
const [currentTsMs, setCurrentTsMs] = whispr_1.Whispr.create(Date.now());
|
|
205
|
+
setInterval(() => {
|
|
206
|
+
setCurrentTsMs(Date.now());
|
|
207
|
+
}, 200);
|
|
208
|
+
exports.CURRENT_TS_MS = currentTsMs;
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
|
|
|
33
33
|
export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void): void;
|
|
34
34
|
/**
|
|
35
35
|
* Return a reactive current timestamp (ms), updated at the given interval.
|
|
36
|
-
* @param refresh The refresh interval
|
|
37
36
|
* @returns The current timestamp
|
|
38
37
|
*/
|
|
39
38
|
export declare function useCurrentTimestamp(refresh?: number): number;
|
package/dist/react-whispr.js
CHANGED
|
@@ -11,6 +11,7 @@ const whispr_1 = require("@cripty2001/whispr");
|
|
|
11
11
|
const react_1 = require("react");
|
|
12
12
|
const lodash_1 = require("lodash");
|
|
13
13
|
const Dispatcher_1 = require("./Dispatcher");
|
|
14
|
+
const _1 = require(".");
|
|
14
15
|
/**
|
|
15
16
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
16
17
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -69,16 +70,10 @@ function useOnWhispr(w, cb) {
|
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* Return a reactive current timestamp (ms), updated at the given interval.
|
|
72
|
-
* @param refresh The refresh interval
|
|
73
73
|
* @returns The current timestamp
|
|
74
74
|
*/
|
|
75
75
|
function useCurrentTimestamp(refresh = 1000) {
|
|
76
|
-
|
|
77
|
-
(0, react_1.useEffect)(() => {
|
|
78
|
-
const id = setInterval(() => setCurrTs(Date.now()), refresh);
|
|
79
|
-
return () => clearInterval(id);
|
|
80
|
-
}, [setCurrTs]);
|
|
81
|
-
return currTs;
|
|
76
|
+
return useWhisprValue(_1.CURRENT_TS_MS);
|
|
82
77
|
}
|
|
83
78
|
/**
|
|
84
79
|
* Debounce a reactive value, deep checking for equality, and stopping updates until the value changes.
|
package/package.json
CHANGED