@cripty2001/utils 0.0.40 → 0.0.41
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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Whispr } from "@cripty2001/whispr";
|
|
2
|
+
type LoggerItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
date: Date;
|
|
5
|
+
message: string;
|
|
6
|
+
severity: "success" | "info" | "warning" | "error";
|
|
7
|
+
context: string | undefined;
|
|
8
|
+
dismiss: () => void;
|
|
9
|
+
trace: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
declare class Logger {
|
|
12
|
+
private static instance;
|
|
13
|
+
lines: Whispr<LoggerItem[]>;
|
|
14
|
+
private setLines;
|
|
15
|
+
private constructor();
|
|
16
|
+
private reconstructError;
|
|
17
|
+
static getInstance(): Logger;
|
|
18
|
+
log(message: string, severity?: LoggerItem['severity'], context?: string): void;
|
|
19
|
+
logError(error: Error | DOMException | any): void;
|
|
20
|
+
}
|
|
21
|
+
declare const _default: Logger;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const whispr_1 = require("@cripty2001/whispr");
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class Logger {
|
|
6
|
+
static instance;
|
|
7
|
+
lines;
|
|
8
|
+
setLines;
|
|
9
|
+
constructor() {
|
|
10
|
+
[this.lines, this.setLines] = whispr_1.Whispr.create([]);
|
|
11
|
+
window.addEventListener("unhandledrejection", (e) => this.log(e.reason, "error"));
|
|
12
|
+
window.addEventListener("error", (e) => this.logError(this.reconstructError(e)));
|
|
13
|
+
}
|
|
14
|
+
reconstructError(e) {
|
|
15
|
+
if (e.error && e.error instanceof Error) {
|
|
16
|
+
return e.error;
|
|
17
|
+
}
|
|
18
|
+
if (e.message && typeof e.message === 'string') {
|
|
19
|
+
return new Error(e.message);
|
|
20
|
+
}
|
|
21
|
+
return new Error("Unknown error");
|
|
22
|
+
}
|
|
23
|
+
static getInstance() {
|
|
24
|
+
if (!Logger.instance) {
|
|
25
|
+
Logger.instance = new Logger();
|
|
26
|
+
}
|
|
27
|
+
return Logger.instance;
|
|
28
|
+
}
|
|
29
|
+
log(message, severity = "info", context) {
|
|
30
|
+
const item = {
|
|
31
|
+
id: (0, __1.getRandomId)(),
|
|
32
|
+
date: new Date(),
|
|
33
|
+
message,
|
|
34
|
+
severity,
|
|
35
|
+
context,
|
|
36
|
+
dismiss: () => {
|
|
37
|
+
this.setLines(this.lines.value.filter(i => i.id !== item.id));
|
|
38
|
+
},
|
|
39
|
+
trace: (new Error()).stack
|
|
40
|
+
};
|
|
41
|
+
this.setLines([...this.lines.value, item]);
|
|
42
|
+
}
|
|
43
|
+
logError(error) {
|
|
44
|
+
if (error instanceof DOMException ||
|
|
45
|
+
error instanceof Error ||
|
|
46
|
+
false) {
|
|
47
|
+
return this.log(error.message, "error", error.stack);
|
|
48
|
+
}
|
|
49
|
+
console.trace('UNKNOWN ERROR', error);
|
|
50
|
+
return this.log("Unknown error - See Console", "error");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = Logger.getInstance();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function LoggerReactDisplay(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 react_whispr_1 = require("../react-whispr");
|
|
9
|
+
const Logger_1 = __importDefault(require("./Logger"));
|
|
10
|
+
const lucide_react_1 = require("lucide-react");
|
|
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", { className: "fixed bottom-0 right-0 w-full z-50 p-4 rounded ", children: (0, jsx_runtime_1.jsx)("div", { className: "flex flex-col gap-2 items-center w-full justify-center", children: messages
|
|
29
|
+
.slice(0, 3)
|
|
30
|
+
.map((message) => ((0, jsx_runtime_1.jsxs)("div", { className: `p-2 rounded shadow-md text-white ng-black w-full max-w-prose cursor-pointer`, onClick: message.dismiss, style: {
|
|
31
|
+
backgroundColor: getColor(message.severity)
|
|
32
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between items-center", 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", { className: "ml-2", children: [" - ", message.context, " "] })] }), (0, jsx_runtime_1.jsx)("button", { onClick: message.dismiss, className: "ml-4 text-white font-bold", children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { size: 16 }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-1", children: [" ", message.message, " "] })] }, message.id))) }) }));
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cripty2001/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
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": {
|
|
@@ -34,11 +34,12 @@
|
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
+
"lucide-react": "^0.552.0",
|
|
38
|
+
"@msgpack/msgpack": "^3.1.2",
|
|
37
39
|
"@sinclair/typebox": "^0.34.41",
|
|
38
40
|
"dotenv": "^17.2.3",
|
|
39
41
|
"express": "^5.1.0",
|
|
40
|
-
"react": "^19"
|
|
41
|
-
"@msgpack/msgpack": "^3.1.2"
|
|
42
|
+
"react": "^19"
|
|
42
43
|
},
|
|
43
44
|
"peerDependenciesMeta": {
|
|
44
45
|
"react": {
|