@cripty2001/utils 0.0.40 → 0.0.42

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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const whispr_1 = require("@cripty2001/whispr");
4
- const _1 = require(".");
4
+ const __1 = require("..");
5
5
  class Logger {
6
6
  static instance;
7
7
  lines;
@@ -28,7 +28,7 @@ class Logger {
28
28
  }
29
29
  log(message, severity = "info", context) {
30
30
  const item = {
31
- id: (0, _1.getRandomId)(),
31
+ id: (0, __1.getRandomId)(),
32
32
  date: new Date(),
33
33
  message,
34
34
  severity,
@@ -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.40",
3
+ "version": "0.0.42",
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": {
@@ -59,8 +60,12 @@
59
60
  "types": "./dist/react-whispr.d.ts"
60
61
  },
61
62
  "./logger": {
62
- "import": "./dist/Logger.js",
63
- "types": "./dist/Logger.d.ts"
63
+ "import": "./dist/Logger/Logger.js",
64
+ "types": "./dist/Logger/Logger.d.ts"
65
+ },
66
+ "./logger/react": {
67
+ "import": "./dist/Logger/react-display.js",
68
+ "types": "./dist/Logger/react-display.d.ts"
64
69
  },
65
70
  "./appserver/server": {
66
71
  "import": "./dist/Appserver/server.js",
@@ -1,20 +0,0 @@
1
- import { JSONEncodable } from '.';
2
- import { Static, TSchema } from '@sinclair/typebox';
3
- export type AppserverHandler<I extends JSONEncodable, U extends JSONEncodable, O extends JSONEncodable> = (input: I, user: U | null) => Promise<O> | O;
4
- export type AppserverUsergetter<U extends JSONEncodable> = (token: string) => Promise<U | null>;
5
- declare class AppserverError extends Error {
6
- code: string;
7
- status: number;
8
- constructor(code: string, message: string, payload?: JSONEncodable, status?: number);
9
- }
10
- export declare class AppserverHandledError extends AppserverError {
11
- constructor(code: string, message: string, payload?: JSONEncodable);
12
- }
13
- export declare class Appserver<U extends JSONEncodable> {
14
- private app;
15
- private parseUser;
16
- constructor(port: number, parseUser: AppserverUsergetter<U>);
17
- private parseInput;
18
- register<ISchema extends TSchema, O extends JSONEncodable, I extends Static<ISchema> & JSONEncodable = Static<ISchema> & JSONEncodable>(action: string, inputSchema: ISchema, handler: AppserverHandler<I, U, O>): void;
19
- }
20
- export {};
package/dist/Appserver.js DELETED
@@ -1,77 +0,0 @@
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.Appserver = exports.AppserverHandledError = void 0;
7
- const express_1 = __importDefault(require("express"));
8
- const value_1 = require("@sinclair/typebox/value");
9
- class AppserverError extends Error {
10
- code;
11
- status;
12
- constructor(code, message, payload = {}, status = 500) {
13
- super(message);
14
- this.code = code;
15
- this.status = status;
16
- }
17
- }
18
- class AppserverHandledError extends AppserverError {
19
- constructor(code, message, payload = {}) {
20
- super(code, message, payload);
21
- }
22
- }
23
- exports.AppserverHandledError = AppserverHandledError;
24
- class Appserver {
25
- app;
26
- parseUser;
27
- constructor(port, parseUser) {
28
- this.parseUser = parseUser;
29
- this.app = (0, express_1.default)();
30
- this.app.listen(port);
31
- }
32
- async parseInput(req) {
33
- if (req.headers['content-type'] !== 'application/json')
34
- throw new AppserverError('REQUEST_INVALID_TYPE_HEADER', 'Content-Type must be application/json', 400);
35
- const data = (() => {
36
- try {
37
- return JSON.parse(req.body);
38
- }
39
- catch {
40
- throw new AppserverError('REQUEST_INVALID_BODY', 'Request body is not valid JSON', 400);
41
- }
42
- })();
43
- const authHeader = req.headers['authorization'];
44
- const token = authHeader?.startsWith('Bearer ') ? authHeader.slice(7) : null;
45
- return {
46
- data,
47
- user: token ? await this.parseUser(token) : null
48
- };
49
- }
50
- register(action, inputSchema, handler) {
51
- this.app.post(`/exec/${action}`, async (req, res) => {
52
- try {
53
- const { data: unsafeData, user } = await this.parseInput(req);
54
- if (!value_1.Value.Check(inputSchema, unsafeData))
55
- return res
56
- .status(422)
57
- .json({
58
- errors: [...value_1.Value.Errors(inputSchema, unsafeData)]
59
- });
60
- const data = unsafeData;
61
- const output = await handler(data, user);
62
- return res
63
- .json(output);
64
- }
65
- catch (e) {
66
- if (e instanceof AppserverError)
67
- return res
68
- .status(e.status)
69
- .json({ error: e.message, code: e.code });
70
- return res
71
- .status(500)
72
- .json({ error: 'Internal server error', code: 'INTERNAL_SERVERERROR' });
73
- }
74
- });
75
- }
76
- }
77
- exports.Appserver = Appserver;
File without changes