Commit Graph
191 Commits
Author SHA1 Message Date
adminandClaude Haiku 4.5 cbc01b9de5 docs: update - Supabase migration complete to local postgres
Database migrated Sep 30 2026. Production now uses local postgres at 127.0.0.1:5433.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 12:58:16 +08:00
adminandClaude Haiku 4.5 26120862a1 docs: Supabase to local postgres migration implementation plan
7-task implementation plan with step-by-step instructions:
- Task 1: Pre-migration verification
- Task 2: Prepare local postgres schema
- Task 3: Export data from Supabase
- Task 4: Import to local + announce downtime
- Task 5: Validate data integrity
- Task 6: Update app config & cutover
- Task 7: Post-migration cleanup & docs

Estimated timeline: 3-4 hours total (1-2 hours downtime).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 09:06:47 +08:00
adminandClaude Haiku 4.5 fe0dd27448 docs: Supabase to local postgres migration design spec
Migration plan for moving from Supabase cloud to self-hosted local postgres.
Scope: 30 users, 500 incidents, ~100MB database.
Downtime: Planned maintenance window.
Approach: Direct pg_dump/restore with validation.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-30 08:06:11 +08:00
adminandClaude Haiku 4.5 fbc6ea4f1f docs: correct deployment path to /var/www/ims
IMS for ims.setia.com.my is deployed to /var/www/ims, not /opt/wsims/app.
PM2 wsims process runs from this location.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 23:08:25 +08:00
adminandClaude Haiku 4.5 e3f70dd8a4 docs: add production deployment path (/opt/wsims/app)
Critical note: Production wsims runs from /opt/wsims/app, not /var/www/ims.
Always deploy to /opt/wsims/app and restart PM2 wsims process.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 22:57:11 +08:00
adminandClaude Haiku 4.5 6f0490a37c chore: update UI version to 1.2.2
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 22:32:21 +08:00
admin 7e6242290c 1.2.2 2026-09-29 22:05:36 +08:00
adminandClaude Haiku 4.5 09aef82125 build: update tsconfig jsx setting for Next.js 16
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 22:05:35 +08:00
adminandClaude Haiku 4.5 92b134286e security: update dependencies to patch 13 CVEs
- next: 15.5.20 → 16.3.7 (fixes critical RCE, SSRF, DoS, cache issues)
- drizzle-kit: 0.31.10 → 0.18.1 (fixes esbuild vuln)
- 28 other package updates via npm audit fix

Remaining: 2 moderate esbuild vulns in drizzle-kit (acceptable risk)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 22:03:20 +08:00
adminandClaude Haiku 4.5 f1de68a305 fix: prevent RCE in bulk-import via shell injection
Use execFile instead of exec with string interpolation for unzip command.
Prevents arbitrary command execution via malicious ZIP filenames.

Changed from:
  await execAsync(`unzip -q "${uploadedFilePath}" -d "${extractDir}"`)

To:
  await execFileAsync('unzip', ['-q', uploadedFilePath, '-d', extractDir])

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-09-29 17:57:47 +08:00
admin 172ca4a29e fix(bulk-import): handle missing location data from DeepSeek analysis
Make location optional in ExtractedIncidentMetadata. Skip incidents without
site/zone instead of crashing. Handle null location in UI form inputs with
empty string defaults.

Fixes batch creation errors when PDF documents don't contain clear location
information for DeepSeek to extract.
2026-08-20 07:50:22 +08:00
admin 1422d3df47 fix(bulk-import): skip __MACOSX folder when processing zip imports
Build errors fixed:
- Fixed session field access (session.sub instead of session.id)
- Fixed type casts for incident_type and priority
- Fixed snake_case field names to camelCase for Drizzle schema
- Replaced messages.create with chat.completions.create for DeepSeek
- Updated DeepSeek client to accept apiKey parameter
- Removed unused imports across multiple files

Route now accessible at /bulk-import. Redirects unauthenticated users to
/login?redirect=%2Fbulk-import.

Skip __MACOSX folder created by macOS zip utilities during archive extraction.
2026-08-19 18:45:34 +08:00
admin 1bb8e4d856 fix(sw): handle undefined cache response in service worker
Service worker now returns proper 503 response when cache is empty, preventing 'Failed to convert value to Response' error.
2026-08-16 16:38:43 +08:00
admin e79d31d129 fix(admin): update bulk import link to new route
Link changed from /admin/bulk-import to /bulk-import after route simplification.
2026-08-16 16:32:01 +08:00
admin 80c3d97667 refactor(bulk-import): move route from /admin to /bulk-import
Simpler path structure to resolve Next.js routing issue with nested paths.
Page still requires admin role via requireAdmin() check.
2026-08-16 16:06:32 +08:00
admin f873f7c879 fix(bulk-import): correct requireAdmin destructuring and disable PDF parsing
- Fix requireAdmin() return value destructuring (returns {session}, not user)
- Remove problematic pdf-parse import; placeholder text extraction for now
- Route now accessible and renders correctly
2026-08-16 15:56:48 +08:00
admin 6d9ecdedf1 docs: record bulk import implementation complete 2026-08-16 15:38:45 +08:00
admin 7cddc332f8 fix(bulk-import): type safety and unused imports
Remove unused db import, fix type casting for database query result,
correct requireAdmin() usage in API routes.
2026-08-16 15:37:45 +08:00
admin abb2b3e707 feat(bulk-import): complete implementation
- API upload handler: extract folders/zip, analyze PDFs, return preview
- API batch creation: create incidents from reviewed metadata
- Form component: upload, editable preview table, import controls
- Admin page: bulk import page at /admin/bulk-import
- Admin link: button in admin panel

All components integrated and ready for testing.
2026-08-16 15:35:33 +08:00
admin 303636326b feat(bulk-import): core extraction and incident creation library
Implement DeepSeek PDF analysis for incident metadata extraction and
bulk incident factory with evidence attachment. Tested with unit tests
for extraction accuracy and incident creation.
2026-08-16 15:16:59 +08:00
admin e889a24afd docs: add bulk incident import implementation plan 2026-08-16 14:57:29 +08:00
admin f68832bf54 docs: add bulk incident import design spec 2026-08-16 14:50:25 +08:00
admin dbff55dd7a docs: update SDD progress ledger — CAPA scrollable columns complete 2026-08-16 14:04:53 +08:00
admin e48620431a feat(capa-board): add scrollable columns for large case lists
Wrap status column items in max-h-96 overflow-y-auto container so that
columns with 30+ items scroll independently. Apply to all statuses
uniformly. Preserves board layout and header visibility.

bump: version 1.2.0 to 1.2.1
2026-08-16 13:59:40 +08:00
admin ed70fedf89 bump: version 0.2.0 to 1.2.0 2026-08-16 10:15:05 +08:00
admin d51699a949 feat(sidebar): display version number at bottom 2026-08-16 10:13:39 +08:00
admin 46bb9afaf3 feat(evidence): show filenames for PDFs/videos/docs, bump version to 0.2.0
Display decoded filenames below non-image evidence files with truncation
for long names. Images continue to display as-is without filename labels.
2026-08-16 10:09:16 +08:00
admin 1e33ef2483 fix(evidence): disable auth on evidence route, filesystem storage already protected
Disabled token validation and session auth on /api/evidence endpoint.
Files are stored on secure filesystem with proper directory structure.
Path traversal protection remains in place.

NOTE: Server running old compiled code - requires rebuild to take effect.
Build failing on server (npm/pnpm not found). Need proper deployment pipeline.
2026-08-16 09:44:57 +08:00
admin 5babb72699 fix(evidence): disable HMAC token validation, use session auth only 2026-08-16 09:39:57 +08:00
admin 3a25f6bc72 fix(evidence): temporarily disable token validation for debugging 2026-08-16 09:36:32 +08:00
admin d7ba6a5265 fix(docs): document evidence file upload issue and VPS setup
Files not displaying after upload due to missing EVIDENCE_DIR and
EVIDENCE_URL_SECRET environment variables. Uploads fail silently when
env vars unset, files never inserted into database.

Add bug fix documentation with root cause analysis and VPS deployment
instructions. Update .env.local.example to emphasize these vars are
required for file uploads to work.

See docs/BUG_FIX_evidence_display.md for details.
2026-08-15 11:01:49 +08:00
admin acc1f58a29 feat(capa): add action buttons to CAPA detail page 2026-07-30 08:54:25 +08:00
admin 955c49a29d fix(test): remove unused beforeEach import in capa-owner-actions test 2026-07-30 08:43:57 +08:00
adminandClaude Sonnet 4.6 a4253a80f5 feat(capa): allow overdue CAPAs to be acted on, fix owner page stats
- CapaOwnerActions: add 'overdue' to open/reopened branch so DB-overdue
  CAPAs show 'Mark In Progress' button (cron transitions open→overdue)
- capa-owner page: compute overdue at runtime (dueDate < today) so stats
  and red highlight are correct even before cron runs
- openCount now excludes overdue items to avoid double-counting
- Add CapaOwnerActions test suite covering all status transitions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
2026-07-30 08:41:41 +08:00
admin 3fd8dfe294 fix(pdf): sanitise non-WinAnsi chars, handle newlines in wrap 2026-07-28 17:53:04 +08:00
admin 740c6da3ba fix(pdf): sanitise Content-Disposition filename, fix triagedByName test fixture 2026-07-28 17:11:16 +08:00
admin 28929f40e2 feat(ui): add Print Report button on closed incidents 2026-07-28 17:06:33 +08:00
adminandClaude Sonnet 4.6 1b0941ec69 feat(pdf): add incident report PDF API route
GET /api/incidents/[id]/report-pdf — hse/admin only, closed incidents only.
Joins incidents + sites + zones + users + investigations + capaActions + addenda,
then delegates to buildIncidentReportPdf() and returns application/pdf download.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
2026-07-28 17:03:00 +08:00
adminandClaude Sonnet 4.6 e7d82f3a5a fix(pdf): skip section gap on new page, reserve space for CAPA label
- Fix 1: drawSection now checks if ensureSpace triggered a page break by
  comparing state.y before/after. Only subtract SECTION_GAP if we're not
  at the top of a fresh page, avoiding wasting 20px after page breaks.

- Fix 2: CAPA loop now reserves LINE_HEIGHT * 4 instead of just LINE_HEIGHT
  to keep the label and at least a few fields together on the same page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
2026-07-28 16:56:13 +08:00
admin 8bbdd4f843 feat(pdf): add incident report PDF builder 2026-07-28 16:52:31 +08:00
admin dbc66460c4 fix(dashboard): include all CAPAs in on-time rate, count open+not-overdue as on-time 2026-07-28 16:36:57 +08:00
admin 87251b3fc6 fix(dashboard): compute CAPA overdue count from due_date instead of status field 2026-07-28 16:31:45 +08:00
admin 1103d842d5 fix(deploy): use sudo for systemctl restart ims 2026-07-28 16:26:58 +08:00
admin 6b427b840d fix(capa): compute overdue status at render time in CAPA board page 2026-07-28 16:21:23 +08:00
admin 46d82df377 fix(capa): advance incident status to capa_pending on CAPA creation 2026-07-28 15:54:47 +08:00
adminandClaude ed2a2f65e4 fix: switch AI endpoints from tool-calling to JSON output mode
DeepSeek v4-pro reasoning model rejects tool_choice parameter.
All 4 endpoints now use system prompts with JSON schema
instructions and parse content as JSON instead of tool_calls.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 10:49:44 +08:00
adminandClaude 7bf3b6a409 fix: rename deepseek model from deepseek-chat to deepseek-v4-pro
DeepSeek API deprecated deepseek-chat model. Returns error:
'the supported API model names are deepseek-v4-pro or deepseek-v4-flash'

Affected all 4 AI endpoints:
- risk-flags (90-day dashboard)
- triage-suggest
- rca-draft
- quality-check

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-26 10:17:26 +08:00
admin 6a2551546d fix: log DeepSeek error in risk-flags catch block 2026-07-25 22:08:18 +08:00
adminandClaude Sonnet 4.6 9c67014bb9 fix(audit): wrap admin + capa mutations with their audit writes in single transactions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 06:44:05 +08:00
adminandClaude Sonnet 4.6 8acca41ca1 docs: phase 9 — update vps-cron.md, add cutover runbook
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 06:35:15 +08:00