Fix API build: shared package emits dist, fix type errors

- packages/shared: tsconfig adds outDir/declaration, package.json adds build script
- apps/api/tsconfig.json: paths now point to shared/dist (.d.ts) instead of source,
  resolves TS6059 rootDir conflict
- apps/api/src/routes/{health,notifications,users}.ts: explicit Router type annotation
  to fix TS2742 portable type inference
- apps/api/src/events/handler.ts: cast via 'as unknown as' to satisfy TS2352
- apps/api/Dockerfile: build shared package before api
This commit is contained in:
2026-04-30 11:07:21 +01:00
parent 22e8cc893f
commit 00a914279b
8 changed files with 20 additions and 13 deletions

View File

@@ -16,6 +16,9 @@ RUN pnpm install --frozen-lockfile
COPY packages/shared ./packages/shared COPY packages/shared ./packages/shared
COPY apps/api ./apps/api COPY apps/api ./apps/api
# Compila primero el paquete shared (api lo consume vía dist/)
RUN pnpm --filter @naturcalabacera/shared build
# Compila TypeScript del api # Compila TypeScript del api
RUN pnpm --filter @naturcalabacera/api build RUN pnpm --filter @naturcalabacera/api build

View File

@@ -75,8 +75,8 @@ function buildChangesBlock(prev: Reservation, curr: Reservation): string {
const changes: Array<{ label: string; from: string; to: string }> = []; const changes: Array<{ label: string; from: string; to: string }> = [];
for (const [field, label] of Object.entries(FIELD_LABELS)) { for (const [field, label] of Object.entries(FIELD_LABELS)) {
const prevVal = (prev as Record<string, unknown>)[field]; const prevVal = (prev as unknown as Record<string, unknown>)[field];
const currVal = (curr as Record<string, unknown>)[field]; const currVal = (curr as unknown as Record<string, unknown>)[field];
const prevStr = formatFieldValue(field, prevVal); const prevStr = formatFieldValue(field, prevVal);
const currStr = formatFieldValue(field, currVal); const currStr = formatFieldValue(field, currVal);
if (prevStr !== currStr) { if (prevStr !== currStr) {

View File

@@ -1,6 +1,6 @@
import { Router } from 'express'; import { Router, type Router as ExpressRouter } from 'express';
const router = Router(); const router: ExpressRouter = Router();
router.get('/', (_req, res) => { router.get('/', (_req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() }); res.json({ status: 'ok', timestamp: new Date().toISOString() });

View File

@@ -1,10 +1,10 @@
import { Router } from 'express'; import { Router, type Router as ExpressRouter } from 'express';
import { scheduleNotificationsForReservation } from '../jobs/runner.js'; import { scheduleNotificationsForReservation } from '../jobs/runner.js';
import { handleNotificationEvent } from '../events/handler.js'; import { handleNotificationEvent } from '../events/handler.js';
import { supabaseAdmin } from '../lib/supabase.js'; import { supabaseAdmin } from '../lib/supabase.js';
import type { Reservation } from '@naturcalabacera/shared'; import type { Reservation } from '@naturcalabacera/shared';
const router = Router(); const router: ExpressRouter = Router();
/** /**
* POST /api/notifications/reservation-event * POST /api/notifications/reservation-event

View File

@@ -1,8 +1,8 @@
import { Router, type Request, type Response, type NextFunction } from 'express'; import { Router, type Request, type Response, type NextFunction, type Router as ExpressRouter } from 'express';
import { supabaseAdmin } from '../lib/supabase.js'; import { supabaseAdmin } from '../lib/supabase.js';
import type { UserRole } from '@naturcalabacera/shared'; import type { UserRole } from '@naturcalabacera/shared';
const router = Router(); const router: ExpressRouter = Router();
const VALID_ROLES: UserRole[] = ['admin', 'internal_staff', 'external_availability_viewer']; const VALID_ROLES: UserRole[] = ['admin', 'internal_staff', 'external_availability_viewer'];

View File

@@ -10,8 +10,8 @@
"esModuleInterop": true, "esModuleInterop": true,
"declaration": true, "declaration": true,
"paths": { "paths": {
"@naturcalabacera/shared": ["../../packages/shared/src/index.ts"], "@naturcalabacera/shared": ["../../packages/shared/dist/index.d.ts"],
"@naturcalabacera/shared/*": ["../../packages/shared/src/*"] "@naturcalabacera/shared/*": ["../../packages/shared/dist/*"]
} }
}, },
"include": ["src"], "include": ["src"],

View File

@@ -6,6 +6,7 @@
"main": "./src/index.ts", "main": "./src/index.ts",
"types": "./src/index.ts", "types": "./src/index.ts",
"scripts": { "scripts": {
"build": "tsc",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest" "test:watch": "vitest"
}, },

View File

@@ -1,12 +1,15 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2022", "target": "ES2022",
"module": "ESNext", "module": "NodeNext",
"moduleResolution": "bundler", "moduleResolution": "NodeNext",
"strict": true, "strict": true,
"skipLibCheck": true, "skipLibCheck": true,
"declaration": true, "declaration": true,
"declarationMap": true,
"rootDir": "./src",
"outDir": "./dist" "outDir": "./dist"
}, },
"include": ["src"] "include": ["src"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
} }