@cripty2001/utils 0.0.93 → 0.0.95
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.
|
@@ -4,6 +4,9 @@ export type { AppserverData };
|
|
|
4
4
|
export declare class ClientError extends Error {
|
|
5
5
|
constructor(message: string);
|
|
6
6
|
}
|
|
7
|
+
export declare class ClientAuthError extends ClientError {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
7
10
|
export declare class ClientServerError extends Error {
|
|
8
11
|
code: string;
|
|
9
12
|
payload: AppserverData;
|
|
@@ -22,5 +25,11 @@ export declare class Client {
|
|
|
22
25
|
static create(url: string): Client;
|
|
23
26
|
login(token: string): Promise<boolean>;
|
|
24
27
|
exec<I extends AppserverData, O extends AppserverData>(action: string, input: I): Promise<O>;
|
|
28
|
+
/**
|
|
29
|
+
* Executes an action on the server without invalidating the auth token on auth errors.
|
|
30
|
+
* @param action - The action to execute
|
|
31
|
+
* @param input - The input to the action
|
|
32
|
+
* @returns The result of the action
|
|
33
|
+
*/
|
|
25
34
|
private unsafeExec;
|
|
26
35
|
}
|
package/dist/Appserver/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = exports.ClientValidationError = exports.ClientServerError = exports.ClientError = void 0;
|
|
3
|
+
exports.Client = exports.ClientValidationError = exports.ClientServerError = exports.ClientAuthError = exports.ClientError = void 0;
|
|
4
4
|
const whispr_1 = require("@cripty2001/whispr");
|
|
5
5
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
6
6
|
const Dispatcher_1 = require("../Dispatcher");
|
|
@@ -10,6 +10,12 @@ class ClientError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.ClientError = ClientError;
|
|
13
|
+
class ClientAuthError extends ClientError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("Authentication error");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ClientAuthError = ClientAuthError;
|
|
13
19
|
class ClientServerError extends Error {
|
|
14
20
|
code;
|
|
15
21
|
payload;
|
|
@@ -64,8 +70,20 @@ class Client {
|
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
72
|
async exec(action, input) {
|
|
67
|
-
return this.unsafeExec(`/exec/${action}`, input)
|
|
73
|
+
return await this.unsafeExec(`/exec/${action}`, input)
|
|
74
|
+
.catch(e => {
|
|
75
|
+
if (e instanceof ClientAuthError) {
|
|
76
|
+
this.setAuthToken(null);
|
|
77
|
+
}
|
|
78
|
+
throw e;
|
|
79
|
+
});
|
|
68
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Executes an action on the server without invalidating the auth token on auth errors.
|
|
83
|
+
* @param action - The action to execute
|
|
84
|
+
* @param input - The input to the action
|
|
85
|
+
* @returns The result of the action
|
|
86
|
+
*/
|
|
69
87
|
async unsafeExec(action, input) {
|
|
70
88
|
const testedToken = this.authToken.value;
|
|
71
89
|
const res = await fetch(`${this.url}${action}`, {
|
|
@@ -76,12 +94,8 @@ class Client {
|
|
|
76
94
|
},
|
|
77
95
|
body: new Blob([new Uint8Array((0, msgpack_1.encode)(input))], { type: 'application/msgpack' }),
|
|
78
96
|
});
|
|
79
|
-
if (res.status === 401 || res.status === 403)
|
|
80
|
-
if (testedToken === this.authToken.value) {
|
|
81
|
-
this.setAuthToken(null);
|
|
82
|
-
}
|
|
97
|
+
if (res.status === 401 || res.status === 403)
|
|
83
98
|
throw new ClientError("Permission denied");
|
|
84
|
-
}
|
|
85
99
|
if (res.status === 404)
|
|
86
100
|
throw new ClientError("Not found");
|
|
87
101
|
const decoded = (0, msgpack_1.decode)(await res.arrayBuffer());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function LoggerReactDisplay(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LoggerReactDisplay = LoggerReactDisplay;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const lucide_react_1 = require("lucide-react");
|
|
9
|
+
const Logger_1 = __importDefault(require("../Logger/Logger"));
|
|
10
|
+
const react_whispr_1 = require("../react-whispr");
|
|
11
|
+
function LoggerReactDisplay() {
|
|
12
|
+
const messages = (0, react_whispr_1.useWhisprValue)(Logger_1.default.lines);
|
|
13
|
+
const getColor = (severity) => {
|
|
14
|
+
switch (severity) {
|
|
15
|
+
case 'success':
|
|
16
|
+
return '#4CAF50';
|
|
17
|
+
case 'info':
|
|
18
|
+
return '#2196F3';
|
|
19
|
+
case 'warning':
|
|
20
|
+
return '#FF9800';
|
|
21
|
+
case 'error':
|
|
22
|
+
return '#F44336';
|
|
23
|
+
default:
|
|
24
|
+
return '#333';
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const relTs = (0, react_whispr_1.useRelTime)();
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
29
|
+
position: 'fixed',
|
|
30
|
+
bottom: 0,
|
|
31
|
+
right: 0,
|
|
32
|
+
width: '100%',
|
|
33
|
+
zIndex: 50,
|
|
34
|
+
padding: '1rem',
|
|
35
|
+
borderRadius: '0.5rem',
|
|
36
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexDirection: 'column',
|
|
39
|
+
gap: '0.5rem',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
width: '100%',
|
|
42
|
+
justifyContent: 'center',
|
|
43
|
+
}, children: [...messages]
|
|
44
|
+
.reverse()
|
|
45
|
+
.slice(0, 3)
|
|
46
|
+
.map((message) => ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
47
|
+
padding: '0.5rem',
|
|
48
|
+
borderRadius: '0.375rem',
|
|
49
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.2)',
|
|
50
|
+
color: '#fff',
|
|
51
|
+
width: '100%',
|
|
52
|
+
maxWidth: '65ch',
|
|
53
|
+
cursor: 'pointer',
|
|
54
|
+
backgroundColor: getColor(message.severity)
|
|
55
|
+
}, onClick: message.dismiss, children: [(0, jsx_runtime_1.jsxs)("div", { style: {
|
|
56
|
+
display: 'flex',
|
|
57
|
+
justifyContent: 'space-between',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("strong", { children: ["[", relTs(message.date), "] "] }), message.context && (0, jsx_runtime_1.jsxs)("span", { style: {
|
|
60
|
+
marginLeft: '0.5rem',
|
|
61
|
+
}, children: [" - ", message.context, " "] })] }), (0, jsx_runtime_1.jsx)("button", { onClick: message.dismiss, style: {
|
|
62
|
+
marginLeft: '1rem',
|
|
63
|
+
color: '#fff',
|
|
64
|
+
fontWeight: 'bold',
|
|
65
|
+
background: 'none',
|
|
66
|
+
border: 'none',
|
|
67
|
+
cursor: 'pointer',
|
|
68
|
+
padding: 0,
|
|
69
|
+
}, children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { size: 16 }) })] }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
70
|
+
marginTop: '0.25rem',
|
|
71
|
+
}, children: message.message })] }, message.id))) }) }));
|
|
72
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ModalComponent;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_whispr_1 = require("../react-whispr");
|
|
7
|
+
let modalCount = 0;
|
|
8
|
+
function ModalComponent(props) {
|
|
9
|
+
const zIndex = (0, react_1.useRef)(1000 + modalCount++).current;
|
|
10
|
+
const id = (0, react_1.useRef)(`modal-${zIndex}`).current;
|
|
11
|
+
const [open, setOpen] = (0, react_whispr_1.useSynced)(true, props.open, props.setOpen);
|
|
12
|
+
if (!open)
|
|
13
|
+
return null;
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)("div", { id: id, className: "fixed inset-0 bg-black/50 flex items-center justify-center p-6", style: { zIndex: zIndex }, onClick: () => setOpen(false), children: (0, jsx_runtime_1.jsx)("div", { className: "w-full animate-slide-up", onClick: (e) => e.stopPropagation(), children: props.children }) }));
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cripty2001/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.95",
|
|
4
4
|
"description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
|
|
5
5
|
"homepage": "https://github.com/cripty2001/utils#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dotenv": "^17.2.3",
|
|
41
41
|
"express": "^5.1.0",
|
|
42
42
|
"handlebars": "^4.7.8",
|
|
43
|
-
"lucide-react": "
|
|
43
|
+
"lucide-react": ">=0.552.0",
|
|
44
44
|
"mjml": "^4.17.1",
|
|
45
45
|
"react": "^19"
|
|
46
46
|
},
|