Compare commits

...

14 Commits

Author SHA1 Message Date
d7902deeb4 pipeline
Some checks failed
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build is passing
2026-02-25 20:09:52 +01:00
7fefb9a153 pino shoudn't be a dev dependency; hopefully fixed pipeline
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is passing
2026-02-25 19:08:32 +01:00
565cb0a044 sanitize tag-names for kubernetes
Some checks failed
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build is failing
2026-02-25 18:39:00 +01:00
6463100fbd feat: restore CI pipelines and add k3s deployment
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
Re-enable build/test/format pipelines, rename deploy_server to
deploy_latest, add upload_tag (tag-triggered k3s deploy) and
upload_commit (promote-triggered k3s deploy). Update CLAUDE.md.
2026-02-25 17:58:03 +01:00
b088e380a4 typo
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing
2026-02-24 18:11:56 +01:00
54936f1b96 added tsconfig.json in Dockerfile
Some checks failed
continuous-integration/drone/push Build is failing
2026-02-24 18:08:59 +01:00
e732305d99 feat: add deploy pipeline and switch Dockerfile to COPY-based build
Some checks failed
continuous-integration/drone/push Build is failing
Add deploy_server Drone pipeline that builds and pushes the Docker image
to Gitea Container Registry, then deploys to VPS via SSH. Switch
Dockerfile from git clone to COPY-based build for CI compatibility and
better layer caching. Change exposed port to 3001.
2026-02-24 17:52:48 +01:00
93a0928928 hopefully final pipeline fix for now
All checks were successful
continuous-integration/drone/push Build is passing
2026-02-24 12:57:35 +01:00
68a49712bc another pipeline fix
Some checks failed
continuous-integration/drone/push Build encountered an error
2026-02-24 12:52:09 +01:00
602e4e1413 added types in pipeline
Some checks failed
continuous-integration/drone/push Build encountered an error
2026-02-24 12:47:14 +01:00
bf8bb3cfb8 feat: add Drone CI pipelines, Jest unit tests, and Prettier check
Some checks failed
continuous-integration/drone/push Build encountered an error
Add Drone CI with server build/test and format check pipelines.
Add unit tests for password utils and recurrenceExpander.
Add check_format script, fix Jest config to ignore dist/,
remove dead CaldavService.test.ts, apply Prettier formatting.
2026-02-24 12:43:31 +01:00
16848bfdf0 refactor: clone repo from Gitea in Dockerfile instead of COPY
Replace local COPY with git clone --depth 1 so the image can be built
without a local source context. Adds BRANCH build arg (default: main).
2026-02-18 20:12:05 +01:00
a3e7f0288e feat: add Docker support and compile shared package to dist
- Add multi-stage Dockerfile for server containerization
- Add .dockerignore to exclude unnecessary files from build context
- Switch shared package from source to compiled CommonJS output (dist/)
- Server dev/build scripts now build shared package first
- Fix deep imports to use @calchat/shared barrel export
- Update CLAUDE.md with Docker and shared package documentation
2026-02-18 19:37:27 +01:00
0c157da817 update README 2026-02-10 01:10:44 +01:00
22 changed files with 714 additions and 77 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
node_modules
*/node_modules
*/*/node_modules
**/dist
apps/client
.git
.env
*.md

171
.drone.yml Normal file
View File

@@ -0,0 +1,171 @@
kind: pipeline
type: docker
name: server_build_and_test
trigger:
branch:
- main
event:
- push
steps:
- name: build_server
image: node
commands:
- npm ci -w @calchat/shared
- npm ci -w @calchat/server
- npm run build -w @calchat/server
- name: jest_server
image: node
commands:
- npm run test -w @calchat/server
---
kind: pipeline
type: docker
name: check_for_formatting
trigger:
branch:
- main
event:
- push
steps:
- name: format_check
image: node
commands:
- npm ci
- npm run check_format
---
kind: pipeline
type: docker
name: deploy_latest
trigger:
branch:
- main
event:
- push
steps:
- name: upload_latest
image: plugins/docker
settings:
registry: gitea.gilmour109.de
repo: gitea.gilmour109.de/gilmour109/calchat-server
dockerfile: apps/server/docker/Dockerfile
tags:
- latest
username:
from_secret: gitea_username
password:
from_secret: gitea_password
- name: deploy_to_vps
image: appleboy/drone-ssh
settings:
host:
- 10.0.0.1
username: root
password:
from_secret: vps_ssh_password
envs:
- gitea_username
- gitea_password
port: 22
command_timeout: 2m
script:
- docker login -u $GITEA_USERNAME -p $GITEA_PASSWORD gitea.gilmour109.de
- docker pull gitea.gilmour109.de/gilmour109/calchat-server:latest
- docker compose -f /root/calchat-mongo/docker-compose.yml up -d
depends_on:
- server_build_and_test
- check_for_formatting
---
kind: pipeline
type: docker
name: upload_tag
trigger:
event:
- tag
steps:
- name: upload_tag
image: plugins/docker
settings:
registry: gitea.gilmour109.de
repo: gitea.gilmour109.de/gilmour109/calchat-server
dockerfile: apps/server/docker/Dockerfile
tags:
- ${DRONE_TAG}
username:
from_secret: gitea_username
password:
from_secret: gitea_password
- name: deploy_to_k3s
image: appleboy/drone-ssh
settings:
host:
- 192.168.178.201
username: debian
password:
from_secret: k3s_ssh_password
envs:
- drone_tag
port: 22
command_timeout: 2m
script:
- export TAG=$DRONE_TAG
- export NAME=$(echo $DRONE_TAG | tr -d '.')
- envsubst < /home/debian/manifest.yml | sudo kubectl apply -f -
---
kind: pipeline
type: docker
name: upload_commit
trigger:
event:
- promote
steps:
- name: upload_commit
image: plugins/docker
settings:
registry: gitea.gilmour109.de
repo: gitea.gilmour109.de/gilmour109/calchat-server
dockerfile: apps/server/docker/Dockerfile
tags:
- ${DRONE_COMMIT_SHA:0:8}
username:
from_secret: gitea_username
password:
from_secret: gitea_password
- name: deploy_to_k3s
image: appleboy/drone-ssh
settings:
host:
- 192.168.178.201
username: debian
password:
from_secret: k3s_ssh_password
envs:
- drone_commit_sha
port: 22
command_timeout: 2m
script:
- export TAG=$(echo $DRONE_COMMIT_SHA | cut -c1-8)
- export NAME=$TAG
- envsubst < /home/debian/manifest.yml | sudo kubectl apply -f -

View File

@@ -14,6 +14,7 @@ This is a fullstack TypeScript monorepo with npm workspaces.
```bash ```bash
npm install # Install all dependencies for all workspaces npm install # Install all dependencies for all workspaces
npm run format # Format all TypeScript files with Prettier npm run format # Format all TypeScript files with Prettier
npm run check_format # Check formatting without modifying files (used in CI)
``` ```
### Client (apps/client) - Expo React Native app ### Client (apps/client) - Expo React Native app
@@ -26,11 +27,17 @@ npm run lint -w @calchat/client # Run ESLint
npm run build:apk -w @calchat/client # Build APK locally with EAS npm run build:apk -w @calchat/client # Build APK locally with EAS
``` ```
### Shared (packages/shared)
```bash
npm run build -w @calchat/shared # Compile shared types to dist/
```
### Server (apps/server) - Express.js backend ### Server (apps/server) - Express.js backend
```bash ```bash
npm run dev -w @calchat/server # Start dev server with hot reload (tsx watch) npm run dev -w @calchat/server # Build shared + start dev server with hot reload (tsx watch)
npm run build -w @calchat/server # Compile TypeScript npm run build -w @calchat/server # Build shared + compile TypeScript
npm run start -w @calchat/server # Run compiled server (port 3000) npm run start -w @calchat/server # Run compiled server (port 3000)
npm run test -w @calchat/server # Run Jest unit tests
``` ```
## Technology Stack ## Technology Stack
@@ -53,6 +60,9 @@ npm run start -w @calchat/server # Run compiled server (port 3000)
| | react-native-logs | Client-side logging | | | react-native-logs | Client-side logging |
| | tsdav | CalDAV client library | | | tsdav | CalDAV client library |
| | ical.js | iCalendar parsing/generation | | | ical.js | iCalendar parsing/generation |
| Testing | Jest / ts-jest | Server unit tests |
| Deployment | Docker | Server containerization (multi-stage build) |
| | Drone CI | CI/CD pipelines (build, test, format check, deploy) |
| Planned | iCalendar | Event export/import | | Planned | iCalendar | Event export/import |
## Architecture ## Architecture
@@ -318,6 +328,8 @@ src/
### Shared Package (packages/shared) ### Shared Package (packages/shared)
The shared package is compiled to `dist/` (CommonJS). All imports must use `@calchat/shared` (NOT `@calchat/shared/src/...`). Server `dev` and `build` scripts automatically build shared first.
``` ```
src/ src/
├── index.ts ├── index.ts
@@ -530,6 +542,14 @@ docker compose up -d # Start Radicale CalDAV server
``` ```
- Radicale: `localhost:5232` - Radicale: `localhost:5232`
### Server Docker Image
```bash
# Build (requires local build context):
docker build -f apps/server/docker/Dockerfile -t calchat-server .
docker run -p 3001:3001 --env-file apps/server/.env calchat-server
```
Multi-stage COPY-based build: copies `package.json` files first for layer caching, then source code. Compiles shared + server, then copies only `dist/` and production dependencies to the runtime stage. Exposes port 3001. In CI, the `plugins/docker` Drone plugin builds and pushes the image automatically.
### Environment Variables ### Environment Variables
Server requires `.env` file in `apps/server/`: Server requires `.env` file in `apps/server/`:
``` ```
@@ -676,6 +696,29 @@ This uses the `preview` profile from `eas.json` which builds an APK with:
- Package name: `com.gilmour109.calchat` - Package name: `com.gilmour109.calchat`
- EAS Project ID: `b722dde6-7d89-48ff-9095-e007e7c7da87` - EAS Project ID: `b722dde6-7d89-48ff-9095-e007e7c7da87`
## CI/CD (Drone)
The project uses Drone CI (`.drone.yml`) with five pipelines:
**On push to main:**
1. **`server_build_and_test`**: Builds the server (`npm ci` + `npm run build`) and runs Jest tests (`npm run test`)
2. **`check_for_formatting`**: Checks Prettier formatting across all workspaces (`npm run check_format`)
3. **`deploy_latest`**: Builds Docker image, pushes to Gitea Container Registry (`gitea.gilmour109.de/gilmour109/calchat-server:latest`), then SSHs into VPS (`10.0.0.1`) to pull and restart via `docker compose`. Depends on both pipelines above passing first.
**On tag:**
4. **`upload_tag`**: Builds Docker image tagged with the git tag (`${DRONE_TAG}`), pushes to registry, then deploys to k3s cluster (`192.168.178.201`) via SSH using `envsubst` with a Kubernetes manifest template.
**On promote:**
5. **`upload_commit`**: Builds Docker image tagged with short commit SHA (first 8 chars), pushes to registry, then deploys to k3s cluster (`192.168.178.201`) via SSH using `envsubst` with a Kubernetes manifest template.
## Testing
Server uses Jest with ts-jest for unit testing. Config in `apps/server/jest.config.js` ignores `/node_modules/` and `/dist/`.
**Existing tests:**
- `src/utils/password.test.ts` - Tests for bcrypt hash() and compare()
- `src/utils/recurrenceExpander.test.ts` - Tests for expandRecurringEvents() (non-recurring, weekly/daily/UNTIL recurrence, EXDATE filtering, RRULE: prefix stripping, invalid RRULE fallback, multi-day events, sorting)
## Documentation ## Documentation
Detailed architecture diagrams are in `docs/`: Detailed architecture diagrams are in `docs/`:

145
README.md
View File

@@ -1,50 +1,141 @@
# Welcome to your Expo app 👋 # CalChat
This is an [Expo](https://expo.dev) project created with [`create-expo-app`](https://www.npmjs.com/package/create-expo-app). Kalender-App mit KI-Chatbot. Termine lassen sich per Chat in natuerlicher Sprache erstellen, bearbeiten und loeschen.
## Get started ## Tech Stack
1. Install dependencies | Bereich | Technologie |
|---------|-------------|
| Frontend | React Native, Expo, Expo-Router, NativeWind, Zustand |
| Backend | Express.js, MongoDB, Mongoose, OpenAI GPT |
| Shared | TypeScript Monorepo mit npm Workspaces |
| Optional | CalDAV-Sync (z.B. Radicale) |
## Voraussetzungen
- Node.js (>= 20)
- npm
- Docker & Docker Compose (fuer MongoDB)
- OpenAI API Key (fuer KI-Chat)
- Android SDK + Java (nur fuer APK-Build)
## Projekt aufsetzen
### 1. Repository klonen
```bash
git clone <repo-url>
cd calchat
```
### 2. Dependencies installieren
```bash ```bash
npm install npm install
``` ```
2. Start the app Installiert alle Dependencies fuer Client, Server und Shared.
### 3. MongoDB starten
```bash ```bash
npx expo start cd apps/server/docker/mongo
docker compose up -d
``` ```
In the output, you'll find options to open the app in a - MongoDB: `localhost:27017` (root/mongoose)
- Mongo Express UI: `localhost:8083` (admin/admin)
- [development build](https://docs.expo.dev/develop/development-builds/introduction/) ### 4. Server konfigurieren
- [Android emulator](https://docs.expo.dev/workflow/android-studio-emulator/)
- [iOS simulator](https://docs.expo.dev/workflow/ios-simulator/)
- [Expo Go](https://expo.dev/go), a limited sandbox for trying out app development with Expo
You can start developing by editing the files inside the **app** directory. This project uses [file-based routing](https://docs.expo.dev/router/introduction).
## Get a fresh project
When you're ready, run:
```bash ```bash
npm run reset-project cp apps/server/.env.example apps/server/.env
``` ```
This command will move the starter code to the **app-example** directory and create a blank **app** directory where you can start developing. `apps/server/.env` bearbeiten:
## Learn more ```env
MONGODB_URI=mongodb://root:mongoose@localhost:27017/calchat?authSource=admin
OPENAI_API_KEY=sk-proj-... # Eigenen Key eintragen
USE_TEST_RESPONSES=false # true = statische Testantworten ohne GPT
LOG_LEVEL=debug
NODE_ENV=development
PORT=3000
```
To learn more about developing your project with Expo, look at the following resources: ### 5. Client konfigurieren
- [Expo documentation](https://docs.expo.dev/): Learn fundamentals, or go into advanced topics with our [guides](https://docs.expo.dev/guides). ```bash
- [Learn Expo tutorial](https://docs.expo.dev/tutorial/introduction/): Follow a step-by-step tutorial where you'll create a project that runs on Android, iOS, and the web. cp apps/client/.env.example apps/client/.env
```
## Join the community `apps/client/.env` bearbeiten:
Join our community of developers creating universal apps. ```env
# Fuer Emulator/Web:
EXPO_PUBLIC_API_URL=http://localhost:3000/api
- [Expo on GitHub](https://github.com/expo/expo): View our open source platform and contribute. # Fuer physisches Geraet im gleichen Netzwerk:
- [Discord community](https://chat.expo.dev): Chat with Expo users and ask questions. EXPO_PUBLIC_API_URL=http://<DEINE-LOKALE-IP>:3000/api
```
### 6. Server starten
```bash
npm run dev -w @calchat/server
```
Startet den Server auf Port 3000 (mit `tsx watch` - startet bei Dateiänderungen automatisch neu (oder sollte es zumindest)).
### 7. Client starten
```bash
npm run start -w @calchat/client
```
Dann im Expo-Menue die gewuenschte Plattform waehlen:
- `a` - Android Emulator
- `i` - iOS Simulator
- `w` - Web Browser
Oder direkt:
```bash
npm run android -w @calchat/client
npm run ios -w @calchat/client
npm run web -w @calchat/client
```
## CalDAV (optional)
Fuer CalDAV-Synchronisation kann ein Radicale-Server gestartet werden:
```bash
cd apps/server/docker/radicale
docker compose up -d
```
Radicale ist dann unter `localhost:5232` erreichbar. Die CalDAV-Verbindung wird in der App unter Einstellungen konfiguriert.
## Weitere Befehle
```bash
npm run format # Prettier auf alle TS/TSX-Dateien
npm run lint -w @calchat/client # ESLint (Client)
npm run build -w @calchat/server # TypeScript kompilieren (Server)
npm run build:apk -w @calchat/client # APK lokal bauen (EAS)
```
## Projektstruktur
```
calchat/
├── apps/
│ ├── client/ # Expo React Native App
│ └── server/ # Express.js Backend
│ └── docker/
│ ├── mongo/ # MongoDB + Mongo Express
│ └── radicale/ # CalDAV Server
└── packages/
└── shared/ # Geteilte Types und Utilities
```

View File

@@ -623,7 +623,7 @@ const CalendarToolbar = ({ loadEvents }: CalendarToolbarProps) => {
elevation: 4, elevation: 4,
}; };
const className = "flex flex-row items-center gap-2 px-3 py-1 rounded-lg" const className = "flex flex-row items-center gap-2 px-3 py-1 rounded-lg";
return ( return (
<View <View

View File

@@ -45,7 +45,9 @@ const CaldavTextInput = ({
const { theme } = useThemeStore(); const { theme } = useThemeStore();
return ( return (
<View className="flex flex-row items-center py-1"> <View className="flex flex-row items-center py-1">
<Text className="ml-4 w-24" style={{ color: theme.textPrimary }}>{title}:</Text> <Text className="ml-4 w-24" style={{ color: theme.textPrimary }}>
{title}:
</Text>
<CustomTextInput <CustomTextInput
className="flex-1 mr-4 px-3 py-2" className="flex-1 mr-4 px-3 py-2"
text={value} text={value}
@@ -111,7 +113,13 @@ const CaldavSettings = () => {
); );
const saveConfig = async () => { const saveConfig = async () => {
showFeedback(setSaveFeedback, saveTimer, "Speichere Konfiguration...", false, true); showFeedback(
setSaveFeedback,
saveTimer,
"Speichere Konfiguration...",
false,
true,
);
try { try {
const saved = await CaldavConfigService.saveConfig( const saved = await CaldavConfigService.saveConfig(
serverUrl, serverUrl,
@@ -119,9 +127,19 @@ const CaldavSettings = () => {
password, password,
); );
setConfig(saved); setConfig(saved);
showFeedback(setSaveFeedback, saveTimer, "Konfiguration wurde gespeichert", false); showFeedback(
setSaveFeedback,
saveTimer,
"Konfiguration wurde gespeichert",
false,
);
} catch { } catch {
showFeedback(setSaveFeedback, saveTimer, "Fehler beim Speichern der Konfiguration", true); showFeedback(
setSaveFeedback,
saveTimer,
"Fehler beim Speichern der Konfiguration",
true,
);
} }
}; };
@@ -129,9 +147,19 @@ const CaldavSettings = () => {
showFeedback(setSyncFeedback, syncTimer, "Synchronisiere...", false, true); showFeedback(setSyncFeedback, syncTimer, "Synchronisiere...", false, true);
try { try {
await CaldavConfigService.sync(); await CaldavConfigService.sync();
showFeedback(setSyncFeedback, syncTimer, "Synchronisierung erfolgreich", false); showFeedback(
setSyncFeedback,
syncTimer,
"Synchronisierung erfolgreich",
false,
);
} catch { } catch {
showFeedback(setSyncFeedback, syncTimer, "Fehler beim Synchronisieren", true); showFeedback(
setSyncFeedback,
syncTimer,
"Fehler beim Synchronisieren",
true,
);
} }
}; };

View File

@@ -0,0 +1,31 @@
FROM node:alpine AS build
WORKDIR /app
COPY package.json package-lock.json tsconfig.json ./
COPY packages/shared/package.json ./packages/shared/
COPY apps/server/package.json ./apps/server/
RUN npm ci -w @calchat/server -w @calchat/shared --include-workspace-root
COPY packages/shared/ packages/shared/
COPY apps/server/ apps/server/
RUN npm run build -w @calchat/shared && npm run build -w @calchat/server
FROM node:alpine
WORKDIR /app
COPY --from=build /app/package.json /app/package-lock.json ./
COPY --from=build /app/packages/shared/package.json packages/shared/
COPY --from=build /app/apps/server/package.json apps/server/
RUN npm ci --omit=dev -w @calchat/server -w @calchat/shared
COPY --from=build /app/packages/shared/dist/ packages/shared/dist/
COPY --from=build /app/apps/server/dist/ apps/server/dist/
EXPOSE 3001
CMD ["node", "apps/server/dist/app.js"]

View File

@@ -1,4 +1,5 @@
module.exports = { module.exports = {
preset: "ts-jest", preset: "ts-jest",
testEnvironment: "node", testEnvironment: "node",
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
}; };

View File

@@ -3,8 +3,8 @@
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "tsx watch src/app.ts", "dev": "npm run build --workspace=@calchat/shared && tsx watch src/app.ts",
"build": "tsc", "build": "npm run build --workspace=@calchat/shared && tsc",
"start": "node dist/app.js", "start": "node dist/app.js",
"test": "jest" "test": "jest"
}, },
@@ -18,6 +18,7 @@
"openai": "^6.15.0", "openai": "^6.15.0",
"pino": "^10.1.1", "pino": "^10.1.1",
"pino-http": "^11.0.0", "pino-http": "^11.0.0",
"pino-pretty": "^13.1.3",
"rrule": "^2.8.1", "rrule": "^2.8.1",
"tsdav": "^2.1.6" "tsdav": "^2.1.6"
}, },
@@ -28,7 +29,6 @@
"@types/jest": "^30.0.0", "@types/jest": "^30.0.0",
"@types/node": "^24.10.1", "@types/node": "^24.10.1",
"jest": "^30.2.0", "jest": "^30.2.0",
"pino-pretty": "^13.1.3",
"ts-jest": "^29.4.6", "ts-jest": "^29.4.6",
"tsx": "^4.21.0", "tsx": "^4.21.0",
"typescript": "^5.9.3" "typescript": "^5.9.3"

View File

@@ -21,5 +21,4 @@ export class AuthController {
res.status(400).json({ error: (error as Error).message }); res.status(400).json({ error: (error as Error).message });
} }
} }
} }

View File

@@ -15,7 +15,10 @@ export class CaldavController {
const response = await this.caldavService.saveConfig(config); const response = await this.caldavService.saveConfig(config);
res.json(response); res.json(response);
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error saving config"); log.error(
{ err: error, userId: req.user?.userId },
"Error saving config",
);
res.status(500).json({ error: "Failed to save config" }); res.status(500).json({ error: "Failed to save config" });
} }
} }
@@ -30,7 +33,10 @@ export class CaldavController {
// Don't expose the password to the client // Don't expose the password to the client
res.json(config); res.json(config);
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error loading config"); log.error(
{ err: error, userId: req.user?.userId },
"Error loading config",
);
res.status(500).json({ error: "Failed to load config" }); res.status(500).json({ error: "Failed to load config" });
} }
} }
@@ -40,7 +46,10 @@ export class CaldavController {
await this.caldavService.deleteConfig(req.user!.userId); await this.caldavService.deleteConfig(req.user!.userId);
res.status(204).send(); res.status(204).send();
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error deleting config"); log.error(
{ err: error, userId: req.user?.userId },
"Error deleting config",
);
res.status(500).json({ error: "Failed to delete config" }); res.status(500).json({ error: "Failed to delete config" });
} }
} }
@@ -50,7 +59,10 @@ export class CaldavController {
const events = await this.caldavService.pullEvents(req.user!.userId); const events = await this.caldavService.pullEvents(req.user!.userId);
res.json(events); res.json(events);
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error pulling events"); log.error(
{ err: error, userId: req.user?.userId },
"Error pulling events",
);
res.status(500).json({ error: "Failed to pull events" }); res.status(500).json({ error: "Failed to pull events" });
} }
} }
@@ -60,7 +72,10 @@ export class CaldavController {
await this.caldavService.pushAll(req.user!.userId); await this.caldavService.pushAll(req.user!.userId);
res.status(204).send(); res.status(204).send();
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error pushing events"); log.error(
{ err: error, userId: req.user?.userId },
"Error pushing events",
);
res.status(500).json({ error: "Failed to push events" }); res.status(500).json({ error: "Failed to push events" });
} }
} }
@@ -78,7 +93,10 @@ export class CaldavController {
await this.caldavService.pushEvent(req.user!.userId, event); await this.caldavService.pushEvent(req.user!.userId, event);
res.status(204).send(); res.status(204).send();
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error pushing event"); log.error(
{ err: error, userId: req.user?.userId },
"Error pushing event",
);
res.status(500).json({ error: "Failed to push event" }); res.status(500).json({ error: "Failed to push event" });
} }
} }

View File

@@ -40,7 +40,10 @@ export class EventController {
await this.pushToCaldav(userId, event); await this.pushToCaldav(userId, event);
res.status(201).json(event); res.status(201).json(event);
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error creating event"); log.error(
{ err: error, userId: req.user?.userId },
"Error creating event",
);
res.status(500).json({ error: "Failed to create event" }); res.status(500).json({ error: "Failed to create event" });
} }
} }
@@ -67,7 +70,10 @@ export class EventController {
const events = await this.eventService.getAll(req.user!.userId); const events = await this.eventService.getAll(req.user!.userId);
res.json(events); res.json(events);
} catch (error) { } catch (error) {
log.error({ err: error, userId: req.user?.userId }, "Error getting events"); log.error(
{ err: error, userId: req.user?.userId },
"Error getting events",
);
res.status(500).json({ error: "Failed to get events" }); res.status(500).json({ error: "Failed to get events" });
} }
} }

View File

@@ -44,5 +44,4 @@ export class AuthService {
return { user, accessToken: "" }; return { user, accessToken: "" };
} }
} }

View File

@@ -1,11 +0,0 @@
// import { createLogger } from "../logging";
// import { CaldavService } from "./CaldavService";
//
// const logger = createLogger("CaldavService-Test");
//
// const cdService = new CaldavService();
//
// test("print events", async () => {
// const client = await cdService.login();
// await cdService.pullEvents(client);
// });

View File

@@ -6,9 +6,10 @@ import { CaldavRepository } from "./interfaces/CaldavRepository";
import { import {
CalendarEvent, CalendarEvent,
CreateEventDTO, CreateEventDTO,
} from "@calchat/shared/src/models/CalendarEvent"; CaldavConfig,
formatDateKey,
} from "@calchat/shared";
import { EventService } from "./EventService"; import { EventService } from "./EventService";
import { CaldavConfig, formatDateKey } from "@calchat/shared";
const logger = createLogger("CaldavService"); const logger = createLogger("CaldavService");

View File

@@ -1,4 +1,4 @@
import { CaldavConfig } from "@calchat/shared/src/models/CaldavConfig"; import { CaldavConfig } from "@calchat/shared";
export interface CaldavRepository { export interface CaldavRepository {
findByUserId(userId: string): Promise<CaldavConfig | null>; findByUserId(userId: string): Promise<CaldavConfig | null>;

View File

@@ -0,0 +1,37 @@
import { hash, compare } from "./password";
describe("password", () => {
describe("hash()", () => {
it("returns a valid bcrypt hash", async () => {
const result = await hash("testpassword");
expect(result).toMatch(/^\$2b\$/);
});
it("produces different hashes for the same password (salt)", async () => {
const hash1 = await hash("samepassword");
const hash2 = await hash("samepassword");
expect(hash1).not.toBe(hash2);
});
});
describe("compare()", () => {
it("returns true for the correct password", async () => {
const hashed = await hash("correct");
const result = await compare("correct", hashed);
expect(result).toBe(true);
});
it("returns false for a wrong password", async () => {
const hashed = await hash("correct");
const result = await compare("wrong", hashed);
expect(result).toBe(false);
});
it("handles special characters and unicode", async () => {
const password = "p@$$w0rd!#%& äöü 🔑";
const hashed = await hash(password);
expect(await compare(password, hashed)).toBe(true);
expect(await compare("other", hashed)).toBe(false);
});
});
});

View File

@@ -0,0 +1,210 @@
import { CalendarEvent } from "@calchat/shared";
import { expandRecurringEvents } from "./recurrenceExpander";
// Helper: create a CalendarEvent with sensible defaults
function makeEvent(
overrides: Partial<CalendarEvent> & { startTime: Date; endTime: Date },
): CalendarEvent {
return {
id: "evt-1",
userId: "user-1",
title: "Test Event",
...overrides,
};
}
// Helper: create a date from "YYYY-MM-DD HH:mm" (local time)
function d(dateStr: string): Date {
const [datePart, timePart] = dateStr.split(" ");
const [y, m, day] = datePart.split("-").map(Number);
if (timePart) {
const [h, min] = timePart.split(":").map(Number);
return new Date(y, m - 1, day, h, min);
}
return new Date(y, m - 1, day);
}
describe("expandRecurringEvents", () => {
// Range: 2025-06-01 to 2025-06-30
const rangeStart = d("2025-06-01 00:00");
const rangeEnd = d("2025-06-30 23:59");
describe("non-recurring events", () => {
it("returns event within the range", () => {
const event = makeEvent({
startTime: d("2025-06-10 09:00"),
endTime: d("2025-06-10 10:00"),
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(1);
expect(result[0].occurrenceStart).toEqual(d("2025-06-10 09:00"));
expect(result[0].occurrenceEnd).toEqual(d("2025-06-10 10:00"));
});
it("excludes event outside the range", () => {
const event = makeEvent({
startTime: d("2025-07-05 09:00"),
endTime: d("2025-07-05 10:00"),
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(0);
});
it("includes event that starts before range and ends within", () => {
const event = makeEvent({
startTime: d("2025-05-31 22:00"),
endTime: d("2025-06-01 02:00"),
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(1);
});
it("includes event that spans the entire range", () => {
const event = makeEvent({
startTime: d("2025-05-01 00:00"),
endTime: d("2025-07-31 23:59"),
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(1);
});
it("returns empty array for empty input", () => {
const result = expandRecurringEvents([], rangeStart, rangeEnd);
expect(result).toEqual([]);
});
});
describe("recurring events", () => {
it("expands weekly event to all occurrences in range", () => {
// Weekly on Mondays, starting 2025-06-02 (a Monday)
const event = makeEvent({
startTime: d("2025-06-02 10:00"),
endTime: d("2025-06-02 11:00"),
recurrenceRule: "FREQ=WEEKLY;BYDAY=MO",
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
// Mondays in June 2025: 2, 9, 16, 23, 30
expect(result).toHaveLength(5);
expect(result[0].occurrenceStart).toEqual(d("2025-06-02 10:00"));
expect(result[1].occurrenceStart).toEqual(d("2025-06-09 10:00"));
expect(result[2].occurrenceStart).toEqual(d("2025-06-16 10:00"));
expect(result[3].occurrenceStart).toEqual(d("2025-06-23 10:00"));
expect(result[4].occurrenceStart).toEqual(d("2025-06-30 10:00"));
});
it("daily event with UNTIL stops at the right date", () => {
const event = makeEvent({
startTime: d("2025-06-01 08:00"),
endTime: d("2025-06-01 09:00"),
recurrenceRule: "FREQ=DAILY;UNTIL=20250605T235959",
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
// June 1, 2, 3, 4, 5
expect(result).toHaveLength(5);
expect(result[4].occurrenceStart).toEqual(d("2025-06-05 08:00"));
});
it("skips occurrences on exception dates (EXDATE)", () => {
const event = makeEvent({
startTime: d("2025-06-02 10:00"),
endTime: d("2025-06-02 11:00"),
recurrenceRule: "FREQ=WEEKLY;BYDAY=MO",
exceptionDates: ["2025-06-09", "2025-06-23"],
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
// 5 Mondays minus 2 exceptions = 3
expect(result).toHaveLength(3);
const dates = result.map((r) => r.occurrenceStart.getDate());
expect(dates).toEqual([2, 16, 30]);
});
it("handles RRULE: prefix (strips it)", () => {
const event = makeEvent({
startTime: d("2025-06-01 08:00"),
endTime: d("2025-06-01 09:00"),
recurrenceRule: "RRULE:FREQ=DAILY;COUNT=3",
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(3);
});
it("falls back to single occurrence on invalid RRULE", () => {
const consoleSpy = jest.spyOn(console, "error").mockImplementation();
const event = makeEvent({
startTime: d("2025-06-10 09:00"),
endTime: d("2025-06-10 10:00"),
recurrenceRule: "COMPLETELY_INVALID_RULE",
});
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
expect(result).toHaveLength(1);
expect(result[0].occurrenceStart).toEqual(d("2025-06-10 09:00"));
expect(consoleSpy).toHaveBeenCalled();
consoleSpy.mockRestore();
});
});
describe("multi-day events", () => {
it("finds event starting before range that ends within range", () => {
// 3-day recurring event starting May 15, weekly
const event = makeEvent({
startTime: d("2025-05-15 08:00"),
endTime: d("2025-05-18 08:00"),
recurrenceRule: "FREQ=WEEKLY",
});
// The occurrence starting May 29 ends June 1 → overlaps with range
const result = expandRecurringEvents([event], rangeStart, rangeEnd);
const starts = result.map((r) => r.occurrenceStart.getDate());
// May 29 (ends June 1), June 5, 12, 19, 26
expect(starts).toContain(29); // May 29
});
});
describe("sorting", () => {
it("returns events sorted by occurrenceStart", () => {
const laterEvent = makeEvent({
id: "evt-later",
startTime: d("2025-06-20 14:00"),
endTime: d("2025-06-20 15:00"),
});
const earlierEvent = makeEvent({
id: "evt-earlier",
startTime: d("2025-06-05 09:00"),
endTime: d("2025-06-05 10:00"),
});
// Pass in reverse order
const result = expandRecurringEvents(
[laterEvent, earlierEvent],
rangeStart,
rangeEnd,
);
expect(result).toHaveLength(2);
expect(result[0].id).toBe("evt-earlier");
expect(result[1].id).toBe("evt-later");
});
});
});

View File

@@ -7,7 +7,8 @@
"packages/*" "packages/*"
], ],
"scripts": { "scripts": {
"format": "prettier --write \"apps/*/src/**/*.{ts,tsx}\" \"packages/*/src/**/*.ts\"" "format": "prettier --write \"apps/*/src/**/*.{ts,tsx}\" \"packages/*/src/**/*.ts\"",
"check_format": "prettier --check \"apps/*/src/**/*.{ts,tsx}\" \"packages/*/src/**/*.ts\""
}, },
"devDependencies": { "devDependencies": {
"eslint": "^9.25.0", "eslint": "^9.25.0",

1
packages/shared/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
dist/

View File

@@ -2,11 +2,14 @@
"name": "@calchat/shared", "name": "@calchat/shared",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"main": "./src/index.ts", "main": "./dist/index.js",
"types": "./src/index.ts", "types": "./dist/index.d.ts",
"exports": { "exports": {
".": "./src/index.ts", ".": "./dist/index.js",
"./*": "./src/*" "./*": "./dist/*"
},
"scripts": {
"build": "tsc"
}, },
"dependencies": { "dependencies": {
"rrule": "^2.8.1" "rrule": "^2.8.1"

View File

@@ -1,10 +1,10 @@
{ {
"extends": "../../tsconfig.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"composite": true,
"declaration": true, "declaration": true,
"declarationMap": true, "outDir": "dist",
"module": "ESNext", "rootDir": "src",
"module": "CommonJS",
"target": "ES2020", "target": "ES2020",
"moduleResolution": "Node", "moduleResolution": "Node",
"esModuleInterop": true, "esModuleInterop": true,