@cripty2001/utils 0.0.73 → 0.0.75
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.js +5 -2
- package/dist/react-whispr.d.ts +8 -0
- package/dist/react-whispr.js +25 -1
- package/package.json +1 -1
package/dist/Appserver/client.js
CHANGED
|
@@ -64,11 +64,12 @@ class Client {
|
|
|
64
64
|
return this.unsafeExec(`/exec/${action}`, input);
|
|
65
65
|
}
|
|
66
66
|
async unsafeExec(action, input) {
|
|
67
|
+
const testedToken = this.authToken.value;
|
|
67
68
|
const res = await fetch(`${this.url}${action}`, {
|
|
68
69
|
method: "POST",
|
|
69
70
|
headers: {
|
|
70
71
|
"Content-Type": "application/vnd.msgpack",
|
|
71
|
-
...(
|
|
72
|
+
...(testedToken !== null ? { "Authorization": `Bearer ${testedToken}` } : {}),
|
|
72
73
|
},
|
|
73
74
|
body: new Blob([new Uint8Array((0, msgpack_1.encode)(input))], { type: 'application/msgpack' }),
|
|
74
75
|
});
|
|
@@ -77,7 +78,9 @@ class Client {
|
|
|
77
78
|
switch (res.status) {
|
|
78
79
|
case 401:
|
|
79
80
|
case 403:
|
|
80
|
-
this.
|
|
81
|
+
if (testedToken === this.authToken.value) {
|
|
82
|
+
this.setAuthToken(null);
|
|
83
|
+
}
|
|
81
84
|
throw new ClientError("Permission denied");
|
|
82
85
|
case 200:
|
|
83
86
|
responseData = decoded;
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -42,6 +42,14 @@ export declare function useCurrentTimestamp(refresh?: number): number;
|
|
|
42
42
|
* @returns The debounced value
|
|
43
43
|
*/
|
|
44
44
|
export declare function useDebounced<T>(value: T): T;
|
|
45
|
+
/**
|
|
46
|
+
* Allow for having a locally defined state, that can be kept synced with an external one, if available.
|
|
47
|
+
* @param def The default value
|
|
48
|
+
* @param value The value to sync
|
|
49
|
+
* @param setValue The function to set the value
|
|
50
|
+
* @returns The synced value and the function to set it
|
|
51
|
+
*/
|
|
52
|
+
export declare function useSynced<T extends any>(def: T, value: T | undefined, setValue: ((value: T) => void) | undefined): [T, (value: T) => void];
|
|
45
53
|
/**
|
|
46
54
|
*
|
|
47
55
|
* Wraps an async function into a reactable data.
|
package/dist/react-whispr.js
CHANGED
|
@@ -5,13 +5,14 @@ exports.useWhispr = useWhispr;
|
|
|
5
5
|
exports.useOnWhispr = useOnWhispr;
|
|
6
6
|
exports.useCurrentTimestamp = useCurrentTimestamp;
|
|
7
7
|
exports.useDebounced = useDebounced;
|
|
8
|
+
exports.useSynced = useSynced;
|
|
8
9
|
exports.useAsync = useAsync;
|
|
9
10
|
exports.useRelTime = useRelTime;
|
|
10
11
|
const whispr_1 = require("@cripty2001/whispr");
|
|
11
12
|
const react_1 = require("react");
|
|
12
13
|
const lodash_1 = require("lodash");
|
|
13
|
-
const Dispatcher_1 = require("./Dispatcher");
|
|
14
14
|
const _1 = require(".");
|
|
15
|
+
const Dispatcher_1 = require("./Dispatcher");
|
|
15
16
|
/**
|
|
16
17
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
17
18
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -91,6 +92,29 @@ function useDebounced(value) {
|
|
|
91
92
|
}, [value]);
|
|
92
93
|
return debounced;
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Allow for having a locally defined state, that can be kept synced with an external one, if available.
|
|
97
|
+
* @param def The default value
|
|
98
|
+
* @param value The value to sync
|
|
99
|
+
* @param setValue The function to set the value
|
|
100
|
+
* @returns The synced value and the function to set it
|
|
101
|
+
*/
|
|
102
|
+
function useSynced(def, value, setValue) {
|
|
103
|
+
const [v, setV] = (0, react_1.useState)(def);
|
|
104
|
+
if (value !== undefined) {
|
|
105
|
+
(0, react_1.useEffect)(() => {
|
|
106
|
+
setV(value);
|
|
107
|
+
}, [value, setV]);
|
|
108
|
+
}
|
|
109
|
+
if (setValue !== undefined) {
|
|
110
|
+
(0, react_1.useEffect)(() => {
|
|
111
|
+
if ((0, lodash_1.isEqual)(v, value))
|
|
112
|
+
return;
|
|
113
|
+
setValue(v);
|
|
114
|
+
}, [v, setValue]);
|
|
115
|
+
}
|
|
116
|
+
return [v, setV];
|
|
117
|
+
}
|
|
94
118
|
/**
|
|
95
119
|
*
|
|
96
120
|
* Wraps an async function into a reactable data.
|
package/package.json
CHANGED