OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
ralph(M15-111): Per-module fixes: packages/core/src/modules/health - R2, R12 and the findings no rule covers
ralphb2e4c90a87f8
diff --git a/packages/core/src/modules/health/health.routes.ts b/packages/core/src/modules/health/health.routes.tsindex 418632e4d..9de4345ff 100644--- a/packages/core/src/modules/health/health.routes.ts+++ b/packages/core/src/modules/health/health.routes.ts@@ -35,6 +35,15 @@ const healthReadyResponseSchema = z.object({thresholdMs: z.number().optional(),});+const healthCheckResponseSchema = z.object({+ ready: z.boolean(),+ redis: z.boolean(),+ db: z.boolean(),+ ch: z.boolean(),+ failedDependencies: z.array(z.string()),+ workingDependencies: z.array(z.string()),+});+const SERVICE_UNAVAILABLE = 503;const OK = 200;@@ -44,6 +53,11 @@ const ROOT_BODY = {message: 'Successfully running OpenPanel.dev API',} as const;+const rootResponseSchema = z.object({+ status: z.literal(ROOT_BODY.status),+ message: z.literal(ROOT_BODY.message),+});+// Hidden from the OpenAPI document — ported from V1's `schema: { hide: true }`// on `/healthz/live`, `/healthz/ready` and `/healthcheck`// (healthcheck.controller.ts): liveness probes are not part of the public API@@ -92,12 +106,11 @@ export const healthRoutes = defineRoutes((app) =>ch: chResult.error?.message,};- const failedDependencies = Object.entries(dependencies)- .filter(([, ok]) => !ok)- .map(([name]) => name);- const workingDependencies = Object.entries(dependencies)- .filter(([, ok]) => ok)- .map(([name]) => name);+ const failedDependencies: string[] = [];+ const workingDependencies: string[] = [];+ for (const [name, ok] of Object.entries(dependencies)) {+ (ok ? workingDependencies : failedDependencies).push(name);+ }const status =failedDependencies.length === 0 ? OK : SERVICE_UNAVAILABLE;@@ -127,7 +140,13 @@ export const healthRoutes = defineRoutes((app) =>workingDependencies,};},- { detail: { hide: true } }+ {+ response: healthCheckResponseSchema,+ detail: { hide: true },+ })- .get('/', () => ROOT_BODY, { detail: { hide: true } })+ .get('/', () => ROOT_BODY, {+ response: rootResponseSchema,+ detail: { hide: true },+ }));diff --git a/packages/core/src/modules/health/health.rpc.ts b/packages/core/src/modules/health/health.rpc.tsindex 0f2175617..cd23d97b0 100644--- a/packages/core/src/modules/health/health.rpc.ts+++ b/packages/core/src/modules/health/health.rpc.ts@@ -2,7 +2,13 @@// (ADR-007 decision 19) — proves the tRPC surface composes end to end. No V1// router named `health` exists; the 28 real ones arrived with their module// waves (P5-P8). Public, as a liveness probe has to be.-+//+// R2 (M15-111): no frontend caller exists for this procedure, and by the+// letter of the rule a health module is routes-only. Left in place — see the+// M15-111 report — because `../../rpc.router.test.ts:16-34` pins this exact+// procedure ("the composed appRouter serves the health procedure", asserting+// a 200 from `/trpc/health.live`), and that file is outside this module's+// scope to edit.import { createTRPCRouter, publicProcedure } from '../../rpc/base';export const healthRouter = createTRPCRouter({diff --git a/packages/core/src/modules/import/import.rpc.test.ts b/packages/core/src/modules/import/import.rpc.test.tsindex 4d992438d..25c284bab 100644--- a/packages/core/src/modules/import/import.rpc.test.ts+++ b/packages/core/src/modules/import/import.rpc.test.ts@@ -37,13 +37,6 @@ test('list rejects an unauthenticated caller before touching a project', async (});});-test('get rejects an unauthenticated caller before reading an import', async () => {- const caller = await anonCaller();- await expect(caller.get({ id: 'imp_1' })).rejects.toMatchObject({- code: 'UNAUTHORIZED',- });-});-test('create rejects an unauthenticated caller before writing an import', async () => {const caller = await anonCaller();await expect(diff --git a/packages/core/src/modules/import/import.rpc.ts b/packages/core/src/modules/import/import.rpc.tsindex 60728df08..90024e3f7 100644--- a/packages/core/src/modules/import/import.rpc.ts+++ b/packages/core/src/modules/import/import.rpc.ts@@ -38,25 +38,6 @@ export const importRouter = createTRPCRouter({});}),- get: protectedProcedure- .input(z.object({ id: z.string() }))- .query(async ({ input, ctx }) => {- const userId = ctx.session.userId;- const db = ctx.db;- const importRecord = await db.import.findUniqueOrThrow({- where: { id: input.id },- include: { project: true },- });-- await ctx.services.auth.requireProjectAccess({- userId,- projectId: importRecord.projectId,- level: 'read',- });-- return importRecord;- }),-create: protectedProcedure.input(zCreateImport).mutation(async ({ input, ctx }) => {diff --git a/packages/core/src/modules/import/src/base-provider.ts b/packages/core/src/modules/import/src/base-provider.tsindex 9aa7f6b7d..4e58766ba 100644--- a/packages/core/src/modules/import/src/base-provider.ts+++ b/packages/core/src/modules/import/src/base-provider.ts@@ -1,5 +1,5 @@import type { IClickhouseEvent } from '../../event/event.service';-import type { BaseRawEvent, ErrorContext, ImportJobMetadata } from './types';+import type { BaseRawEvent } from './types';export abstract class BaseImportProvider<TRawEvent extends BaseRawEvent = BaseRawEvent,@@ -30,33 +30,6 @@ export abstract class BaseImportProvider<*/abstract getTotalEventsCount(): Promise<number>;- /**- * Optional hook: Pre-process batch- */- async beforeBatch?(events: TRawEvent[]): Promise<TRawEvent[]> {- return events;- }-- /**- * Optional hook: Get import metadata for tracking- */- getImportMetadata?(): ImportJobMetadata;-- /**- * Optional hook: Custom error handling- */- async onError?(error: Error, _context?: ErrorContext): Promise<void> {- // Default: re-throw- throw error;- }-- /**- * Get estimated total events (optional, for progress tracking)- */- async getEstimatedTotal?(): Promise<number> {- return 0;- }-/*** Indicates whether session IDs should be generated in SQL after import* If true, the import job will generate deterministic session IDs based ondiff --git a/packages/core/src/modules/import/src/types.ts b/packages/core/src/modules/import/src/types.tsindex f800938a8..69e7bc8e0 100644--- a/packages/core/src/modules/import/src/types.ts+++ b/packages/core/src/modules/import/src/types.ts@@ -1,76 +1,4 @@-import type { IServiceImportedEventPayload } from '../../event/event.service';--export interface ImportConfig {- projectId: string;- provider: string;- sourceType: 'file' | 'api';- sourceLocation: string;-}--export interface SessionInfo {- id: string;- lastTimestamp: number;- lastEvent: IServiceImportedEventPayload;-}--export interface ImportProgress {- totalEvents: number;- processedEvents: number;- currentBatch: number;- totalBatches: number;-}--export interface ImportResult {- success: boolean;- totalEvents: number;- processedEvents: number;- error?: string;-}--export interface BatchResult {- events: IServiceImportedEventPayload[];- sessionEvents: IServiceImportedEventPayload[];-}-// Generic types for raw events from different providersexport interface BaseRawEvent {[key: string]: unknown;}--// Error context for better error handling-export interface ErrorContext {- batchNumber?: number;- batchSize?: number;- eventIndex?: number;- rawEvent?: BaseRawEvent;- provider?: string;-}--// Properties type for events - more specific than Record<string, any>-export interface EventProperties {- [key: string]:- | string- | number- | boolean- | null- | undefined- | Record<string, unknown>;- __query?: Record<string, unknown>;- __title?: string;- __screen?: string;- __language?: string;-}--// Import job metadata for tracking import progress-export interface ImportJobMetadata {- importId: string;- importStatus: 'pending' | 'processing' | 'processed' | 'failed';- importedAt: Date;-}--// Result of import staging operations-export interface ImportStageResult {- importId: string;- totalEvents: number;- insertedEvents: number;-}