Commit Graph

1010 Commits

Author SHA1 Message Date
Knee Cola
b44d5afca6 fix: store rent amount as whole currency units instead of cents
Changed rent amount handling to use whole currency units throughout the application
instead of storing in cents. This simplifies data entry and aligns with Zod validation
requiring integer values.

Changes:
- Set rent input step to "1" (whole numbers only)
- Remove cents-to-currency conversion (/ 100) when formatting for email

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 10:03:12 +01:00
Knee Cola
2c4e0ee5c0 improve: clarify automatic notification toggle labels
Made toggle labels more explicit by adding "to tenant automatically" to clearly
indicate the recipient and automatic nature of the notifications.

Changes:
- "forward utility bills" → "forward utility bills to tenant automatically"
- "send rent notification" → "send rent notification to tenant automatically"
- Fixed capitalization in Croatian: "obavjest O" → "obavjest o"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 09:56:39 +01:00
Knee Cola
554dd8617f feat: require updateScope selection and improve form UX
Location Edit Form:
- Add validation requiring user to select update scope when editing locations
- Add "no-scope-selected" as placeholder option that must be replaced with valid choice
- Display validation error if user attempts to submit without selecting scope
- Clarify update scope options with improved wording (e.g., "ALL months (past and future)")

Bill Form UX:
- Add emoji icons (👤 tenant, 🔑 landlord) to "who bears cost" options for visual clarity

Translation updates:
- Add "update-scope-required" validation message (EN/HR)
- Improve clarity of update scope option labels
- Standardize Croatian terminology ("zadani" instead of "trenutni" for current month)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 09:47:26 +01:00
Knee Cola
7e7eb5a2d8 fix: only trigger bill forwarding for tenant-paid bills
Modified bill forwarding logic to only consider bills marked as "billed to tenant"
when determining if all bills are ready for forwarding. Bills billed to landlord
should not affect the forwarding trigger.

Changes:
- Filter out landlord bills before checking if all bills are paid/attached
- Improved status check to explicitly look for "pending" or "sent" status
- Added edge case handling when no tenant bills exist

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 09:44:55 +01:00
Knee Cola
580951b9c6 refactor: improve type safety in MongoDB operations
Add TypeScript generic type parameters to MongoDB collection calls and
remove ObjectId conversion workaround.

Changes:
- Added <BillingLocation> type parameter to collection().updateOne() calls
- Simplified _id usage by removing new ObjectId() conversion
- Cleaner code with better type inference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 20:01:29 +01:00
Knee Cola
bb66ebe3b1 fix: use zero-width spaces to prevent email auto-linking
Replace &#46; encoding with zero-width space (&#8203;) approach to prevent
email clients from auto-linking "rezije.app" in header and body text.

Changed "rezije.app" to "rezije&#8203;.&#8203;app" which displays normally
but breaks the auto-link detection pattern.

Applied to:
- Header h1 tags in all templates
- Body text mentions in email-validation template

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 19:17:15 +01:00
Knee Cola
a7d13ba6dc fix: encode period in email template header to prevent auto-linking
Replace the period in "rezije.app" header text with HTML entity &#46; to
prevent email clients from automatically converting it into a clickable link.

This change only affects the display text in the h1 header, not the actual
URLs which remain unchanged for proper functionality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 19:09:22 +01:00
Knee Cola
c7e81a27ee fix: update remaining imports in web-app actions to use shared-code
Fix imports in app/lib/actions/ that were still using relative paths
('../db-types') instead of the shared-code package.

Updated files:
- billActions.ts
- emailActions.ts
- locationActions.ts
- monthActions.ts
- navigationActions.ts
- printActions.ts
- userSettingsActions.ts

All imports now correctly reference @evidencija-rezija/shared-code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:42:43 +01:00
Knee Cola
767dda6355 feat: refactor email-worker to use HTML email templates
Replace inline HTML in email notifications with professional HTML templates
for better email client compatibility and consistent branding.

Changes:
- Created emailTemplates.ts utility for loading and rendering templates
  - Template caching for performance
  - Variable substitution with ${variable} syntax
  - Warning logging for unreplaced variables

- Updated sendVerificationRequests to use email-validation template
  - Variables: location.tenantName, ownerName, location.name, shareId

- Updated sendRentDueNotifications to use rent-due template
  - Fetches user settings for owner name and currency
  - Calculates rent due date from yearMonth and rentDueDay
  - Formats rent amount (converts cents to display format)
  - Variables: location.tenantName, location.name, rentDueDate,
    rentAmount, currency, ownerName, shareId

- Updated sendUtilityBillsNotifications to use util-bills-due template
  - Calculates total amount from all bills
  - Fetches user settings for owner name and currency
  - Variables: location.tenantName, location.name, totalAmount,
    currency, ownerName, shareId

- Fixed ObjectId type mismatches in MongoDB operations

All emails now feature:
- Responsive 3-column layout
- rezije.app branding with logo
- Professional typography and spacing
- Unsubscribe links
- Email client compatible table-based layouts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:37:34 +01:00
Knee Cola
3c34627e7e chore: add shared-code to VS Code workspace
Add the shared-code workspace to VS Code workspace configuration for
better development experience and navigation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:30:08 +01:00
Knee Cola
4bac7f4677 refactor: migrate web-app to use shared-code package
Update web-app to use @evidencija-rezija/shared-code for common types
and utilities instead of maintaining duplicate copies.

Changes:
- Add shared-code dependency to package.json
- Update all imports across 35+ files to use @evidencija-rezija/shared-code
- Remove duplicate db-types.ts and shareChecksum.ts files

This ensures type consistency between web-app and email-worker and
reduces maintenance burden.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:30:00 +01:00
Knee Cola
625e468951 refactor: migrate email-worker to use shared-code package
Update email-worker to use @evidencija-rezija/shared-code for common types
and utilities instead of maintaining duplicate copies.

Changes:
- Add shared-code dependency to package.json
- Update imports in emailSenders.ts to use shared-code
- Remove duplicate db-types.ts and shareChecksum.ts files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:29:34 +01:00
Knee Cola
50c8d230f7 feat: create shared-code workspace for common code
Create a new shared-code workspace containing common code shared between
web-app and email-worker. This reduces code duplication and ensures
consistency across workspaces.

Structure:
- Root package.json defines workspaces (web-app, email-worker, shared-code)
- shared-code contains db-types.ts and shareChecksum.ts
- Configured as internal npm package (@evidencija-rezija/shared-code)
- No build step required (TypeScript source consumed directly)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 18:27:53 +01:00
Knee Cola
5a7fb35bd8 (refactor) moved email templates to emaikl-worker workspace 2025-12-30 18:03:28 +01:00
Knee Cola
35e20c8195 refactor: rename email templates with language suffix
Rename email templates to follow a consistent naming pattern with language
suffix for future i18n support:
- email-validation-email.html -> email-template--email-validation--en.html
- rent-due-email.html -> email-template--rent-due--en.html
- utility-bills-due-email.html -> email-template--util-bills-due--en.html

This naming convention allows for easy addition of Croatian (hr) and other
language versions of the same templates.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:58:35 +01:00
Knee Cola
3db0348b8d (config) email-worker: .env populated with working credentials 2025-12-30 17:51:41 +01:00
Knee Cola
5f99ba26c4 feat: update recipient email address in test message 2025-12-30 17:45:33 +01:00
Knee Cola
742521ef4a feat: add professional HTML email notification templates
Add three email templates for tenant notifications with consistent branding
and professional design:

1. email-validation-email.html - Email verification request
2. rent-due-email.html - Rent payment due reminder
3. utility-bills-due-email.html - Utility bills ready notification

All templates feature:
- Responsive 3-column layout with center content area
- rezije.app branding with logo and color scheme (#0070F3 blue, #3c3c3d header)
- Email client compatible table-based layouts with inline CSS
- Template variables for dynamic content (tenant name, location, amounts, etc.)
- Unsubscribe links and footer information
- Professional typography and spacing

Templates use ${variable} syntax for server-side replacement.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:32 +01:00
Knee Cola
1ed82898c6 feat: improve verification email subject and content
Update email verification subject line to be more personal and inviting by
including the landlord's name. Also add the property location name to the
email body to provide better context for the recipient.

- Subject changed from "Please verify your e-mail address" to
  "{ownerName} has invited you to rezije.app"
- Added location name to email body for clarity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:23 +01:00
Knee Cola
7b4e1b2710 feat: configure Mailgun EU API endpoint
Add explicit EU API endpoint configuration for Mailgun client to ensure emails
are sent through the correct regional API server. This is required for accounts
created in the EU region.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:16 +01:00
Knee Cola
1c98b3b2e6 feat: add nodemon configuration for email-worker development
Configure nodemon to automatically load environment variables from .env file
using dotenv/config preload. This ensures all environment variables are available
during development without manual loading.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:11 +01:00
Knee Cola
63b575e07a feat: add reset button for failed email verification status
Add a reset button to the email verification failed status display, allowing users
to retry email verification after a failure. The button appears alongside the error
message and icon for easy access.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:06 +01:00
Knee Cola
3e769d30f9 fix: add missing translations for verification-failed email status
Add English and Croatian translation keys for the verification-failed email status
that were missing from the previous UI implementation commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 17:44:01 +01:00
Knee Cola
2e08289e47 feat: add UI support for VerificationFailed email status
Display verification failed status in location cards and edit forms to provide
clear visual feedback when email verification fails. Uses red X icon and error
styling consistent with other failure states.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 13:08:06 +01:00
Knee Cola
aa6ae91db8 feat: add billFwdStatus auto-trigger for when-payed strategy
Enables automatic email notification trigger when all bills are marked as paid
under "when-payed" forwarding strategy. Complements the existing "when-attached"
strategy to support both notification workflows.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 13:03:01 +01:00
Knee Cola
e26a478577 feat: auto-set billFwdStatus to pending when all bills have attachments
Enables automatic email notification trigger when the last bill receives an
attachment under "when-attached" forwarding strategy. This eliminates manual
intervention for marking locations ready for tenant notification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:58:16 +01:00
Knee Cola
2b6999d728 fix: update environment configuration for email worker 2025-12-30 12:46:11 +01:00
Knee Cola
6a1a5e0dca fix: update Mailgun API key and share link secret in environment configuration 2025-12-30 12:45:40 +01:00
Knee Cola
a901980a6f feat: implement email notification worker with Mailgun integration
- Add MongoDB connection module for database access
- Implement Mailgun email service for sending notifications
- Add shareChecksum utility for generating secure share links
- Implement three email sender functions:
  - Email verification requests (highest priority)
  - Rent due notifications (CET timezone)
  - Utility bills due notifications
- Create main email worker with budget-based email sending
- Add environment variables for configuration
- Install dependencies: mongodb, mailgun.js, form-data
- Update package.json description to reflect email worker purpose
- Add .env.example with all required configuration

The worker processes emails in priority order and respects a configurable
budget to prevent overwhelming the mail server. All database operations are
atomic and updates are performed immediately after each email send.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:27:32 +01:00
Knee Cola
33ab06e22e commit changes 2025-12-30 12:20:06 +01:00
Knee Cola
4a6896c910 docs: improve email-worker specification and add VerificationFailed status
- Fix spelling and grammar errors throughout email-worker.md
- Add DB structure and connection sections
- Add error handling for email send failures
- Add email subjects, sender information, and delivery details
- Add logging requirements section
- Add race condition handling guidelines
- Add email provider specification (Mailgun)
- Add EmailStatus.VerificationFailed enum value for failed verification emails

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 12:16:30 +01:00
Knee Cola
f8291f9f7b docs: add initial email-worker implementation specification
Add comprehensive specification document for email-worker service detailing:
  - Email verification request workflow
  - Rent due notification workflow
  - Utility bills due notification workflow
  - Email budget/throttling strategy (default: 10 emails per run)
  - Priority system (verification requests first)
  - Complete email templates with dynamic content
  - MongoDB integration requirements
2025-12-30 11:29:05 +01:00
Knee Cola
e9012ed231 (refactor) renames autoBillFwd > billFwdEnabled 2025-12-30 11:09:21 +01:00
Knee Cola
4906cc1990 (refactor) rename: rentDueNotification > rentDueNotificationEnabled 2025-12-30 10:45:48 +01:00
Knee Cola
3e4d8fb95c refactor: rename email-server-worker to email-worker
Rename directory from email-server-worker to email-worker for clarity and brevity. Update all references in CLAUDE.md documentation.
2025-12-30 10:33:59 +01:00
Knee Cola
9d6ad17452 chore: add development configuration files
Add .env with default development settings and .vscode debug configurations for easier local development.

- .env: Development environment variables (PORT, DEBUG, PULL_INTERVAL)
- .vscode/launch.json: Debug configurations for server and Jest tests
- .vscode/settings.json: Jest integration settings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 09:05:31 +01:00
Knee Cola
25c2f09eef feat: add email-server-worker with clean template architecture
Add new email-server-worker project implementing a self-scheduling background worker pattern with HTTP monitoring. Removed all business-specific code from copied source, creating a clean, reusable template.

Key features:
- Self-scheduling worker loop with configurable interval
- Graceful shutdown support (Docker-compatible)
- Prometheus metrics collection
- Health check endpoints (/healthcheck, /metrics, /ping)
- Example worker template for easy customization
- Comprehensive architecture documentation in CLAUDE.md

The worker is now ready for email server implementation with no external dependencies on Evolution/MSSQL/ElasticSearch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 09:03:58 +01:00
Knee Cola
7a526c5a85 Merge branch 'feature/email-confirm-unsubscribe' into develop 2025-12-29 23:31:25 +01:00
Knee Cola
f42366c00b feat: add git diff command to permissions in settings 2025-12-29 23:31:09 +01:00
Knee Cola
4dc2df4a12 security: add server-side validation for email status transitions
Implement strict validation to prevent unauthorized email status changes:
- Force status to Unverified when email address changes
- Only allow client to reset status to Unverified (via reset button)
- Block client from upgrading status (Unverified→Verified, etc.)
- All status upgrades must happen server-side via verification links

This prevents attackers from:
- Submitting new emails with fake "verified" status
- Bypassing email verification by modifying client requests
- Escalating email status without proper verification flow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 23:21:49 +01:00
Knee Cola
fe98a63594 feat: add persistence for tenant email status field
- Add tenantEmailStatus hidden field to LocationEditForm
- Update locationActions to persist email status across all scopes
- Add reset button for unsubscribed email status
- Improve email status display with new/modified indicators
- Update translations for email status messages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 23:05:57 +01:00
Knee Cola
b20d68405c refactor: improve email status display and messaging
LocationCard:
- Include email status in card info section display condition
- Remove emoji suffixes (icons already convey status visually)

LocationEditForm:
- Enable autoBillFwd and rentDueNotification toggles
- Only show email status when displayed email matches saved email
- Show unverified status when email is changed or for new emails
- Remove emoji suffixes from status messages
- Add left margin to status display

Messages (EN/HR):
- More descriptive email status messages in both languages
- LocationCard: "tenant email not verified" vs "Email not verified"
- LocationEditForm: Clearer explanations like "this e-mail address
  will need to be verified by the tenant"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 21:58:02 +01:00
Knee Cola
fea0f48cec fix: include tenantEmail and tenantEmailStatus in fetchAllLocations projection
Added tenantEmail and tenantEmailStatus fields to the MongoDB projection
in fetchAllLocations() so LocationCard can display email status indicators.

Previously these fields were always undefined in LocationCard because they
weren't included in the aggregation pipeline's $project stage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 21:11:07 +01:00
Knee Cola
db9c57472d feat: add email status check to verify page
Security Enhancement:
- Server-side validation of email status before allowing verification
- Only allow verifying emails in VerificationPending state
- Show "Action not possible" message for invalid states
- Extract and validate share-id on server side
- Return 404 for invalid share-ids or missing tenant emails

Implementation:
- Convert page.tsx to async server component
- Fetch location and check tenantEmailStatus
- Pass isPending prop to client component
- Add bilingual "not-allowed" translations (same as unsubscribe page)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 20:54:14 +01:00
Knee Cola
ff6f8890c5 refactor: simplify unsubscribe "not-allowed" message
Make error message more generic and less specific:
- Change title from "Action Not Allowed" to "Action not possible"
- Simplify message to cover broader error cases
- Fix typo: "performe" → "performed"
- Apply same changes to Croatian version

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 20:44:58 +01:00
Knee Cola
5d1602df7f feat: add email verification check to unsubscribe page
Security Enhancement:
- Server-side validation of email status before allowing unsubscribe
- Only allow unsubscribing from verified emails
- Show "Action Not Allowed" message for unverified/unsubscribed emails
- Extract and validate share-id on server side
- Return 404 for invalid share-ids or missing tenant emails

Implementation:
- Convert page.tsx to async server component
- Fetch location and check tenantEmailStatus
- Pass isVerified prop to client component
- Add bilingual "not-allowed" translations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 20:33:16 +01:00
Knee Cola
bc7b28e6e9 refactor: improve email verification/unsubscribe UI and messaging
UI Improvements:
- Add spacing (mb-3) to card titles
- Increase heading font size (text-lg) for better hierarchy

Content Updates:
- Rebrand from "Evidencija Režija" to "rezije.app"
- Clarify success message: "subscribed to receive notifications"
- Improve opt-out description wording
- Fix Croatian grammar and phrasing
- Update unsubscribe page title for clarity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 20:26:35 +01:00
Knee Cola
6eee14d0c3 feat: add email sending test script
Add sent-mail-tester.mjs for testing email functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 19:49:28 +01:00
Knee Cola
db92d157c5 feat: create email-server-worker workspace
Initialize workspace for email server worker service
- Polls MongoDB for email status changes
- Sends verification and notification emails
- Updates email statuses
- Runs as standalone background worker

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 19:47:13 +01:00
Knee Cola
1666394435 feat: add mailgun-webhook to VSCode workspace
Add new mailgun-webhook folder to workspace configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 19:06:22 +01:00