Compare commits

..

97 Commits

Author SHA1 Message Date
Darius
b2d4953fb6 1.8.2 2026-02-06 19:49:56 +01:00
Darius
ec4c9ec492 add grist record to fullinfo 2026-02-06 19:49:46 +01:00
Darius
27dc6f2b12 1.8.1 2026-02-06 17:18:10 +01:00
Darius
845dd30b43 forgot export 2026-02-06 17:18:04 +01:00
Darius
4509de76a2 1.8.0 2026-02-06 17:16:22 +01:00
Darius
4337372b38 add grist 2026-02-06 17:16:17 +01:00
Darius
cd95b63174 1.7.1 2026-02-06 11:14:00 +01:00
Darius
17e6b75ec5 WebSocket improt 2026-02-06 11:13:55 +01:00
Darius
bb8014ccf3 1.7.0 2026-02-06 11:08:32 +01:00
Darius
ad9cf36e98 sse => ws 2026-02-06 11:08:26 +01:00
Darius
60bcd23f5b 1.6.4 2026-02-05 22:51:24 +01:00
Darius
c674d0fa72 1.6.3 2026-02-05 22:50:07 +01:00
Darius
c072f52a1a add seconds to API 2026-02-05 22:50:02 +01:00
Darius
ceadd4e5a2 1.6.2 2026-02-05 22:22:05 +01:00
Darius
b32006cf10 dont actually need that 2026-02-05 22:21:57 +01:00
Darius
0ab6194b43 1.6.1 2026-02-05 22:16:12 +01:00
Darius
46f359bb1e add LastPoll Type 2026-02-05 22:16:06 +01:00
Darius
9b852dc40c 1.6.0 2026-02-05 22:05:43 +01:00
Darius
a6d837f953 make clients of sse service observable 2026-02-05 22:05:35 +01:00
Darius
921882054d 1.5.5 2026-02-05 04:32:04 +01:00
Darius
cdd2fcb59e set => map 2026-02-05 04:31:54 +01:00
Darius
8daeed6b5f 1.5.4 2026-02-05 01:00:05 +01:00
Darius
6d05233a6e fix logger import 2026-02-05 00:59:56 +01:00
Darius
3dd61ab4e8 1.5.3 2026-02-05 00:47:31 +01:00
Darius
b7ea7bc552 dont need volume 2026-02-05 00:47:23 +01:00
Darius
d23c89c3c9 1.5.2 2026-02-05 00:31:13 +01:00
Darius
fd766a822c add homepage information type pt2 2026-02-05 00:31:08 +01:00
Darius
bf580c8a84 1.5.1 2026-02-05 00:27:11 +01:00
Darius
12fc98c925 add homepage information type 2026-02-05 00:26:47 +01:00
Darius
3b7ef0f3ee 1.5.0 2026-02-04 21:52:35 +01:00
Darius
ada7268062 sse typing 2026-02-04 21:52:32 +01:00
Darius
b55e1dd0a6 1.4.1 2026-02-03 22:20:11 +01:00
Darius
49f04ef82f dont make it more complicated than needed 2026-02-03 22:20:01 +01:00
Darius
862401fa9b forgot to build oops 2026-01-28 22:53:57 +01:00
Darius
20e94a7e0e 1.4.0 2026-01-28 22:51:15 +01:00
Darius
7f2b8ce5aa update tidal objects 2026-01-28 22:49:54 +01:00
Darius
14df9ae2cd 1.3.0 2025-11-24 01:37:03 +01:00
Darius
36f2535cf8 add timezone to timespan 2025-11-24 01:36:55 +01:00
Darius
3dfa3007bf 1.2.6 2025-11-23 02:52:00 +01:00
Darius
e80ff5fece Generic Commit; Most likely a fix or small feature 2025-11-23 02:51:54 +01:00
Darius
694d88bb72 1.2.5 2025-11-23 02:49:14 +01:00
Darius
9569477a26 Generic Commit; Most likely a fix or small feature 2025-11-23 02:49:06 +01:00
Darius
6574f8f672 1.2.4 2025-11-23 02:45:59 +01:00
Darius
ea6605f9dc Generic Commit; Most likely a fix or small feature 2025-11-23 02:45:54 +01:00
Darius
953afcbc84 1.2.3 2025-11-21 17:36:06 +01:00
Darius
1d4ade717a Generic Commit; Most likely a fix or small feature 2025-11-21 17:35:58 +01:00
Darius
25ff0b9903 1.2.2 2025-11-21 17:34:20 +01:00
Darius
2f8f3ea017 Generic Commit; Most likely a fix or small feature 2025-11-21 17:34:15 +01:00
Darius
c3f0fd84ac 1.2.1 2025-11-21 17:19:56 +01:00
Darius
64eb6fbf4e Generic Commit; Most likely a fix or small feature 2025-11-21 17:19:50 +01:00
Darius
50c951e0d3 1.2.0 2025-11-21 17:13:31 +01:00
Darius
6086c6dbcc Generic Commit; Most likely a fix or small feature 2025-11-21 17:13:20 +01:00
Darius
30b5c74c06 1.1.5 2025-11-21 17:11:18 +01:00
Darius
a835f220e2 Generic Commit; Most likely a fix or small feature 2025-11-21 17:11:14 +01:00
Darius
a35a3e7ecb 1.1.4 2025-11-21 16:24:14 +01:00
Darius
9b61909eab Generic Commit; Most likely a fix or small feature 2025-11-21 16:24:10 +01:00
Darius
a3689f4cd2 Generic Commit; Most likely a fix or small feature 2025-11-21 16:24:04 +01:00
Darius
bf7f3ee77c 1.1.3 2025-11-21 16:22:20 +01:00
Darius
d0e9f28c8c Generic Commit; Most likely a fix or small feature 2025-11-21 16:22:14 +01:00
Darius
5f9b97ca54 1.1.2 2025-11-21 16:07:03 +01:00
Darius
0103f73c39 Generic Commit; Most likely a fix or small feature 2025-11-21 16:07:01 +01:00
Darius
39d45c80b9 1.1.1 2025-11-21 15:57:56 +01:00
Darius
c415912a0a Generic Commit; Most likely a fix or small feature 2025-11-21 15:57:48 +01:00
Darius
868bf0dc53 1.1.0 2025-11-21 15:49:29 +01:00
Darius
94c10f13e9 add fastify service result type 2025-11-21 15:49:24 +01:00
Darius
9269eaaa88 1.0.14 2025-11-18 21:55:39 +01:00
Darius
07b067279e clean dist 2025-11-18 21:55:34 +01:00
Darius
7659fa0cf4 1.0.13 2025-11-18 21:46:54 +01:00
Darius
314ef5c2ff change to ES2022 2025-11-18 21:46:48 +01:00
Darius
9b02c09677 1.0.12 2025-11-18 19:35:04 +01:00
Darius
45f4ca4d63 Generic Commit; Most likely a fix or small feature 2025-11-18 19:35:01 +01:00
Darius
1aade62ddb 1.0.11 2025-11-18 01:16:00 +01:00
Darius
31a02625e8 Generic Commit; Most likely a fix or small feature 2025-11-18 01:15:56 +01:00
Darius
16c262f2c4 1.0.10 2025-11-18 01:10:22 +01:00
Darius
dfa93723ef Generic Commit; Most likely a fix or small feature 2025-11-18 01:10:18 +01:00
Darius
59900bf294 1.0.9 2025-11-18 01:09:11 +01:00
Darius
1ab38c4c87 Generic Commit; Most likely a fix or small feature 2025-11-18 01:09:00 +01:00
Darius
b47db3cf05 1.0.8 2025-11-18 01:03:27 +01:00
Darius
32c21f82eb Generic Commit; Most likely a fix or small feature 2025-11-18 01:03:24 +01:00
Darius
5afb0e243d 1.0.7 2025-11-17 23:52:40 +01:00
Darius
a80e4ec00d Generic Commit; Most likely a fix or small feature 2025-11-17 23:52:37 +01:00
Darius
7beb867bd5 1.0.6 2025-11-17 23:52:19 +01:00
Darius
d11d6bf5b1 Generic Commit; Most likely a fix or small feature 2025-11-17 23:52:14 +01:00
Darius
cfb45a03a2 1.0.5 2025-11-17 23:49:52 +01:00
Darius
49bb137388 Generic Commit; Most likely a fix or small feature 2025-11-17 23:49:48 +01:00
Darius
10501bc0a9 1.0.4 2025-11-17 23:48:41 +01:00
Darius
f016d7a01c Generic Commit; Most likely a fix or small feature 2025-11-17 23:48:37 +01:00
Darius
fee4ca327a 1.0.3 2025-11-17 23:47:48 +01:00
Darius
60390fcbdf 1.0.2 2025-11-17 23:47:36 +01:00
Darius
04322894b5 Generic Commit; Most likely a fix or small feature 2025-11-17 23:47:27 +01:00
Darius
2e01edcb53 1.0.1 2025-11-17 23:47:18 +01:00
Darius
e8161935b1 Generic Commit; Most likely a fix or small feature 2025-11-17 23:35:09 +01:00
Darius
89355bab8b 1.0.2 2025-11-17 21:39:44 +01:00
Darius
00192c7444 Generic Commit; Most likely a fix or small feature 2025-11-17 21:39:40 +01:00
Darius
bdf8e711b3 1.0.1 2025-11-17 21:39:03 +01:00
Darius
faee9bf9c4 Merge branch 'main' of https://git.dariusbag.dev/DarDarBinks/dpu-types 2025-11-17 21:38:45 +01:00
Darius
079227ee29 Generic Commit; Most likely a fix or small feature 2025-11-17 21:38:41 +01:00
40 changed files with 1078 additions and 50 deletions

3
.gitignore vendored
View File

@@ -1,9 +1,6 @@
# Dependencies
node_modules/
# Build output
dist/
# IDE
.vscode/
.idea/

22
dist/fastify.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
import type { AxiosInstance } from "axios";
export type ServiceResult<T = unknown> = {
result: T;
successful: boolean;
};
export declare class API_Error {
error: string;
constructor(error: string);
}
export declare abstract class BaseClient {
private axiosInstance;
constructor(axiosInstance: AxiosInstance);
getAxios(): AxiosInstance;
}
export declare abstract class BaseService<T> {
private client;
constructor(client: T);
getClient(): T;
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R>;
getErrorResult(error: string): ServiceResult<string>;
}
//# sourceMappingURL=fastify.d.ts.map

1
dist/fastify.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,qBAAa,SAAS;IACF,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CAChC;AAED,8BAAsB,UAAU;IAC/B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC,QAAQ,IAAI,aAAa;CAGzB;AAED,8BAAsB,WAAW,CAAC,CAAC;IAClC,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,CAAC;IAIrB,SAAS,IAAI,CAAC;IAId,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAO7D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;CAOpD"}

38
dist/fastify.js vendored Normal file
View File

@@ -0,0 +1,38 @@
import { logWarning } from "./logger";
export class API_Error {
error;
constructor(error) {
this.error = error;
}
}
export class BaseClient {
axiosInstance;
constructor(axiosInstance) {
this.axiosInstance = axiosInstance;
}
getAxios() {
return this.axiosInstance;
}
}
export class BaseService {
client;
constructor(client) {
this.client = client;
}
getClient() {
return this.client;
}
getSuccessfulResult(result) {
return {
result,
successful: true,
};
}
getErrorResult(error) {
logWarning(error);
return {
result: error,
successful: false,
};
}
}

15
dist/grist.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
export type GristRecord_PersonalGoals = {
went_outside: boolean;
standing: boolean;
standing_goal: number;
steps: boolean;
steps_goal: number;
pushups: boolean;
squats: boolean;
leg_raises: boolean;
reps_goal: number;
stairs: boolean;
stairs_goal: number;
is_workday: boolean;
};
//# sourceMappingURL=grist.d.ts.map

1
dist/grist.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"grist.d.ts","sourceRoot":"","sources":["../src/grist.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG;IACvC,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACpB,CAAC"}

1
dist/grist.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

33
dist/homeassistant.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
import type { TimeBetween } from "./timehelper";
export type HomeAssistantEntity = {
entity_id: string;
state: string;
attributes: {
state_class?: string;
unit_of_measurement?: string;
icon?: string;
friendly_name?: string;
[key: string]: unknown;
};
last_changed: string;
last_reported: string;
last_updated: string;
context: {
id: string;
parent_id: string | null;
user_id: string | null;
};
};
export interface HomeAssistantDeskPositionResult {
raw: HomeAssistantEntity;
as_boolean: boolean;
as_text: () => string;
last_changed: TimeBetween;
}
export type API_HA_DeskPosition = {
position: string;
is_standing: boolean;
last_changed: string;
last_changed_seconds: number;
};
//# sourceMappingURL=homeassistant.d.ts.map

1
dist/homeassistant.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC"}

1
dist/homeassistant.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

10
dist/homepage.d.ts vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { GristRecord_PersonalGoals } from "./grist";
import type { API_HA_DeskPosition } from "./homeassistant";
import type { TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
grist_personal_goals: GristRecord_PersonalGoals | null;
};
//# sourceMappingURL=homepage.d.ts.map

1
dist/homepage.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;IACtC,oBAAoB,EAAE,yBAAyB,GAAG,IAAI,CAAC;CACvD,CAAC"}

1
dist/homepage.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

9
dist/index.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";
//# sourceMappingURL=index.d.ts.map

1
dist/index.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}

8
dist/index.js vendored Normal file
View File

@@ -0,0 +1,8 @@
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";

6
dist/logger.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
export declare function logError(...args: unknown[]): void;
export declare function logWarning(...args: unknown[]): void;
export declare function logSuccess(...args: unknown[]): void;
export declare function logInfo(...args: unknown[]): void;
export declare function printNetworkError(error: unknown): void;
//# sourceMappingURL=logger.d.ts.map

1
dist/logger.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE1C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAEzC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,QAY/C"}

28
dist/logger.js vendored Normal file
View File

@@ -0,0 +1,28 @@
import axios from "axios";
import chalk from "chalk";
export function logError(...args) {
console.error(chalk.red("ERROR:"), ...args);
}
export function logWarning(...args) {
console.warn(chalk.yellow("WARNING:"), ...args);
}
export function logSuccess(...args) {
console.info(chalk.green("SUCCESS:"), ...args);
}
export function logInfo(...args) {
console.info(chalk.cyan("INFO:"), ...args);
}
export function printNetworkError(error) {
if (axios.isAxiosError(error)) {
logError("Axios error details:", {
message: error.message,
status: error.response?.status,
statusText: error.response?.statusText,
data: error.response?.data,
url: error.config?.url,
});
}
else {
logError("Unexpected error:", error);
}
}

26
dist/tidal.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
export type TidalGetCurrent = {
title: string;
artists: string;
artistsArray: string[];
album: string;
playingFrom: string;
status: "playing" | "paused";
url: string;
current: string;
currentInSeconds: number;
duration: string;
durationInSeconds: number;
image: string;
icon: string;
localAlbumArt: string;
favorite: boolean;
trackId: string;
volume: number;
player: {
status: "playing" | "paused";
shuffle: boolean;
repeat: "all" | "single" | "none";
};
artist: string;
};
//# sourceMappingURL=tidal.d.ts.map

1
dist/tidal.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"tidal.d.ts","sourceRoot":"","sources":["../src/tidal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACP,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;KAClC,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;CACf,CAAC"}

1
dist/tidal.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

15
dist/timehelper.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
export declare class TimeSpan {
private start;
private end;
private timeZone;
constructor(timeSpanStr: string, timeZone: string);
private parseTime;
contains(timestamp?: number): boolean;
}
export interface TimeBetween {
seconds: number;
toReadable: (roundToMinutes?: boolean) => string;
}
export declare function calculateSecondsBetween(start: number, end: number): TimeBetween;
export declare function secondsToReadable(secs: number, roundToMinutes?: boolean): string;
//# sourceMappingURL=timehelper.d.ts.map

1
dist/timehelper.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACpB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;IAChD,OAAO,CAAC,QAAQ,CAAC;gBAEL,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOjD,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAqBjD;AAED,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CACjD;AAED,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACT,WAAW,CAOb;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC7B,MAAM,CAmBR"}

53
dist/timehelper.js vendored Normal file
View File

@@ -0,0 +1,53 @@
export class TimeSpan {
start;
end;
timeZone;
constructor(timeSpanStr, timeZone) {
const [startStr, endStr] = timeSpanStr.split("-");
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
this.timeZone = timeZone;
}
parseTime(timeStr) {
const [hours, minutes] = timeStr.split(":").map(Number);
return { hours, minutes };
}
contains(timestamp = Date.now()) {
const date = new Date(timestamp);
const berlinTimeStr = date.toLocaleString("de-DE", {
timeZone: this.timeZone, // "Europe/Berlin"
hour12: false,
hour: "2-digit",
minute: "2-digit",
});
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;
if (startMinutes > endMinutes) {
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
}
else {
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
}
}
}
export function calculateSecondsBetween(start, end) {
const seconds = Math.max(60, (end - start) / 1000);
return {
seconds,
toReadable: (roundToMinutes) => secondsToReadable(seconds, roundToMinutes),
};
}
export function secondsToReadable(secs, roundToMinutes = false) {
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
var days = Math.floor(totalSeconds / (3600 * 24));
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
var minutes = Math.floor((totalSeconds % 3600) / 60);
var seconds = Math.floor(totalSeconds % 60);
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
var hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
var minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
var secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(/,\s*$/, "");
}

17
dist/ws.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
import type { WebSocket } from "ws";
export type WsEvent = {
type: string;
data?: unknown;
};
export type WsClientChangeCallback = (clients: number) => void;
export declare class WsService {
private clients;
private listeners;
onClientChange(callback: WsClientChangeCallback): () => void;
private emitClientChange;
addClient(ws: WebSocket): void;
removeClient(ws: WebSocket): void;
broadcast(message: WsEvent): void;
getClientCount(): number;
}
//# sourceMappingURL=ws.d.ts.map

1
dist/ws.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpC,MAAM,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/D,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAgC;IAEjD,cAAc,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,IAAI;IAO5D,OAAO,CAAC,gBAAgB;IAMxB,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAM9B,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAMjC,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,cAAc,IAAI,MAAM;CAGxB"}

34
dist/ws.js vendored Normal file
View File

@@ -0,0 +1,34 @@
import { logInfo } from "./logger.js";
export class WsService {
clients = new Set();
listeners = [];
onClientChange(callback) {
this.listeners.push(callback);
return () => {
this.listeners = this.listeners.filter((cb) => cb !== callback);
};
}
emitClientChange() {
for (const callback of this.listeners) {
callback(this.clients.size);
}
}
addClient(ws) {
this.clients.add(ws);
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
removeClient(ws) {
this.clients.delete(ws);
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
broadcast(message) {
this.clients.forEach((socket) => {
socket.send(JSON.stringify(message));
});
}
getClientCount() {
return this.clients.size;
}
}

442
package-lock.json generated
View File

@@ -1,19 +1,447 @@
{
"name": "@dpu/types",
"version": "1.0.0",
"name": "@dpu/shared",
"version": "1.8.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@dpu/types",
"version": "1.0.0",
"name": "@dpu/shared",
"version": "1.8.2",
"dependencies": {
"@types/ws": "^8.18.1",
"axios": "^1.7.9",
"chalk": "^5.6.2",
"rimraf": "^6.1.0"
},
"devDependencies": {
"@types/node": "^24.10.1",
"typescript": "^5.3.0"
},
"peerDependencies": {
"typescript": ">=4.5.0"
}
},
"node_modules/@isaacs/balanced-match": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
"integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
"license": "MIT",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@isaacs/brace-expansion": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz",
"integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==",
"license": "MIT",
"dependencies": {
"@isaacs/balanced-match": "^4.0.1"
},
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@types/node": {
"version": "24.10.11",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.11.tgz",
"integrity": "sha512-/Af7O8r1frCVgOz0I62jWUtMohJ0/ZQU/ZoketltOJPZpnb17yoNc9BSoVuV9qlaIXJiPNOpsfq4ByFajSArNQ==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.16.0"
}
},
"node_modules/@types/ws": {
"version": "8.18.1",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/axios": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.13.4.tgz",
"integrity": "sha512-1wVkUaAO6WyaYtCkcYCOx12ZgpGf9Zif+qXa4n+oYzK558YryKqiL6UWwd5DqiH3VRW0GYhTZQ/vlgJrCoNQlg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.4",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/chalk": {
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",
"license": "MIT",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/follow-redirects": {
"version": "1.15.11",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz",
"integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz",
"integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"hasown": "^2.0.2",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/glob": {
"version": "13.0.1",
"resolved": "https://registry.npmjs.org/glob/-/glob-13.0.1.tgz",
"integrity": "sha512-B7U/vJpE3DkJ5WXTgTpTRN63uV42DseiXXKMwG14LQBXmsdeIoHAPbU/MEo6II0k5ED74uc2ZGTC6MwHFQhF6w==",
"license": "BlueOak-1.0.0",
"dependencies": {
"minimatch": "^10.1.2",
"minipass": "^7.1.2",
"path-scurry": "^2.0.0"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"license": "MIT",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/lru-cache": {
"version": "11.2.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.5.tgz",
"integrity": "sha512-vFrFJkWtJvJnD5hg+hJvVE8Lh/TcMzKnTgCWmtBipwI5yLX/iX+5UB2tfuyODF5E7k9xEzMdYgGqaSb1c0c5Yw==",
"license": "BlueOak-1.0.0",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/minimatch": {
"version": "10.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.2.tgz",
"integrity": "sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==",
"license": "BlueOak-1.0.0",
"dependencies": {
"@isaacs/brace-expansion": "^5.0.1"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/minipass": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
"license": "ISC",
"engines": {
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/package-json-from-dist": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
"license": "BlueOak-1.0.0"
},
"node_modules/path-scurry": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.1.tgz",
"integrity": "sha512-oWyT4gICAu+kaA7QWk/jvCHWarMKNs6pXOGWKDTr7cw4IGcUbW+PeTfbaQiLGheFRpjo6O9J0PmyMfQPjH71oA==",
"license": "BlueOak-1.0.0",
"dependencies": {
"lru-cache": "^11.0.0",
"minipass": "^7.1.2"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/rimraf": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.1.2.tgz",
"integrity": "sha512-cFCkPslJv7BAXJsYlK1dZsbP8/ZNLkCAQ0bi1hf5EKX2QHegmDFEFA6QhuYJlk7UDdc+02JjO80YSOrWPpw06g==",
"license": "BlueOak-1.0.0",
"dependencies": {
"glob": "^13.0.0",
"package-json-from-dist": "^1.0.1"
},
"bin": {
"rimraf": "dist/esm/bin.mjs"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/typescript": {
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
@@ -27,6 +455,12 @@
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "7.16.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"license": "MIT"
}
}
}

View File

@@ -1,16 +1,16 @@
{
"name": "@dpu/types",
"version": "1.0.0",
"name": "@dpu/shared",
"version": "1.8.2",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"clean": "rm -rf dist"
"build": "npm run clean && tsc",
"clean": "rimraf dist"
},
"keywords": [
"typescript",
@@ -19,9 +19,16 @@
],
"author": "Darius",
"devDependencies": {
"@types/node": "^24.10.1",
"typescript": "^5.3.0"
},
"peerDependencies": {
"typescript": ">=4.5.0"
},
"dependencies": {
"@types/ws": "^8.18.1",
"axios": "^1.7.9",
"chalk": "^5.6.2",
"rimraf": "^6.1.0"
}
}

50
src/fastify.ts Normal file
View File

@@ -0,0 +1,50 @@
import type { AxiosInstance } from "axios";
import { logWarning } from "./logger";
export type ServiceResult<T = unknown> = {
result: T;
successful: boolean;
};
export class API_Error {
constructor(public error: string) {}
}
export abstract class BaseClient {
private axiosInstance: AxiosInstance;
constructor(axiosInstance: AxiosInstance) {
this.axiosInstance = axiosInstance;
}
getAxios(): AxiosInstance {
return this.axiosInstance;
}
}
export abstract class BaseService<T> {
private client: T;
constructor(client: T) {
this.client = client;
}
getClient(): T {
return this.client;
}
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R> {
return {
result,
successful: true,
};
}
getErrorResult(error: string): ServiceResult<string> {
logWarning(error);
return {
result: error,
successful: false,
};
}
}

14
src/grist.ts Normal file
View File

@@ -0,0 +1,14 @@
export type GristRecord_PersonalGoals = {
went_outside: boolean;
standing: boolean;
standing_goal: number;
steps: boolean;
steps_goal: number;
pushups: boolean;
squats: boolean;
leg_raises: boolean;
reps_goal: number;
stairs: boolean;
stairs_goal: number;
is_workday: boolean;
};

View File

@@ -1,25 +1,35 @@
import type { TimeBetween } from "./timehelper";
export type HomeAssistantEntity = {
entity_id: string;
state: string;
attributes: {
state_class?: string;
unit_of_measurement?: string;
icon?: string;
friendly_name?: string;
[key: string]: unknown;
};
last_changed: string; // datetime string
last_reported: string; // datetime string
last_updated: string; // datetime string
context: {
id: string;
parent_id: string | null;
user_id: string | null;
};
entity_id: string;
state: string;
attributes: {
state_class?: string;
unit_of_measurement?: string;
icon?: string;
friendly_name?: string;
[key: string]: unknown;
};
last_changed: string; // datetime string
last_reported: string; // datetime string
last_updated: string; // datetime string
context: {
id: string;
parent_id: string | null;
user_id: string | null;
};
};
export interface HomeAssistantDeskPositionResult {
raw: HomeAssistantEntity;
asBoolean: boolean;
asText: () => string;
raw: HomeAssistantEntity;
as_boolean: boolean;
as_text: () => string;
last_changed: TimeBetween;
}
export type API_HA_DeskPosition = {
position: string;
is_standing: boolean;
last_changed: string;
last_changed_seconds: number;
};

10
src/homepage.ts Normal file
View File

@@ -0,0 +1,10 @@
import type { GristRecord_PersonalGoals } from "./grist";
import type { API_HA_DeskPosition } from "./homeassistant";
import type { TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
grist_personal_goals: GristRecord_PersonalGoals | null;
};

View File

@@ -1,2 +1,8 @@
export * from "./homeassistant";
export * from "./tidal";
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";

32
src/logger.ts Normal file
View File

@@ -0,0 +1,32 @@
import axios from "axios";
import chalk from "chalk";
export function logError(...args: unknown[]) {
console.error(chalk.red("ERROR:"), ...args);
}
export function logWarning(...args: unknown[]) {
console.warn(chalk.yellow("WARNING:"), ...args);
}
export function logSuccess(...args: unknown[]) {
console.info(chalk.green("SUCCESS:"), ...args);
}
export function logInfo(...args: unknown[]) {
console.info(chalk.cyan("INFO:"), ...args);
}
export function printNetworkError(error: unknown) {
if (axios.isAxiosError(error)) {
logError("Axios error details:", {
message: error.message,
status: error.response?.status,
statusText: error.response?.statusText,
data: error.response?.data,
url: error.config?.url,
});
} else {
logError("Unexpected error:", error);
}
}

View File

@@ -1,14 +1,25 @@
export type TidalSong = {
title: string;
artists: string;
album: string;
playingFrom: string;
status: "playing" | "paused";
url: string;
current: string;
duration: string;
};
export type TidalVolume = {
volume: number;
export type TidalGetCurrent = {
title: string;
artists: string;
artistsArray: string[];
album: string;
playingFrom: string;
status: "playing" | "paused";
url: string;
current: string;
currentInSeconds: number;
duration: string;
durationInSeconds: number;
image: string;
icon: string;
localAlbumArt: string;
favorite: boolean;
trackId: string;
volume: number;
player: {
status: "playing" | "paused";
shuffle: boolean;
repeat: "all" | "single" | "none";
};
artist: string;
};

80
src/timehelper.ts Normal file
View File

@@ -0,0 +1,80 @@
export class TimeSpan {
private start: { hours: number; minutes: number };
private end: { hours: number; minutes: number };
private timeZone;
constructor(timeSpanStr: string, timeZone: string) {
const [startStr, endStr] = timeSpanStr.split("-");
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
this.timeZone = timeZone;
}
private parseTime(timeStr: string) {
const [hours, minutes] = timeStr.split(":").map(Number);
return { hours, minutes };
}
contains(timestamp: number = Date.now()): boolean {
const date = new Date(timestamp);
const berlinTimeStr = date.toLocaleString("de-DE", {
timeZone: this.timeZone, // "Europe/Berlin"
hour12: false,
hour: "2-digit",
minute: "2-digit",
});
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;
if (startMinutes > endMinutes) {
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
} else {
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
}
}
}
export interface TimeBetween {
seconds: number;
toReadable: (roundToMinutes?: boolean) => string;
}
export function calculateSecondsBetween(
start: number,
end: number,
): TimeBetween {
const seconds = Math.max(60, (end - start) / 1000);
return {
seconds,
toReadable: (roundToMinutes?: boolean) =>
secondsToReadable(seconds, roundToMinutes),
};
}
export function secondsToReadable(
secs: number,
roundToMinutes: boolean = false,
): string {
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
var days = Math.floor(totalSeconds / (3600 * 24));
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
var minutes = Math.floor((totalSeconds % 3600) / 60);
var seconds = Math.floor(totalSeconds % 60);
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
var hourDisplay =
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
var minuteDisplay =
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
var secondDisplay =
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
/,\s*$/,
"",
);
}

49
src/ws.ts Normal file
View File

@@ -0,0 +1,49 @@
import type { WebSocket } from "ws";
import { logInfo } from "./logger.js";
export type WsEvent = {
type: string;
data?: unknown;
};
export type WsClientChangeCallback = (clients: number) => void;
export class WsService {
private clients: Set<WebSocket> = new Set();
private listeners: WsClientChangeCallback[] = [];
onClientChange(callback: WsClientChangeCallback): () => void {
this.listeners.push(callback);
return () => {
this.listeners = this.listeners.filter((cb) => cb !== callback);
};
}
private emitClientChange(): void {
for (const callback of this.listeners) {
callback(this.clients.size);
}
}
addClient(ws: WebSocket): void {
this.clients.add(ws);
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
removeClient(ws: WebSocket): void {
this.clients.delete(ws);
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
broadcast(message: WsEvent): void {
this.clients.forEach((socket) => {
socket.send(JSON.stringify(message));
});
}
getClientCount(): number {
return this.clients.size;
}
}

View File

@@ -1,8 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"target": "ES2022",
"module": "ES2022",
"lib": ["ES2022"],
"types": ["node"],
"declaration": true,
"declarationMap": true,
"outDir": "./dist",