Fas 2 steg 4: Quick Reconciliation (motor, API, app + 12-språks i18n)

This commit is contained in:
Sven (AAMOS AI)
2026-08-07 01:02:08 +07:00
parent 4385fe5125
commit 218bc44d08
24 changed files with 1069 additions and 17 deletions
+30
View File
@@ -2,6 +2,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
import { and, eq } from "drizzle-orm";
import type { Database } from "@app/database";
import { schema } from "@app/database";
import type { AnalyticsEvent } from "@app/analytics";
import type { DecayProfile } from "@app/inventory-engine";
import type { EventType } from "@app/shared-types";
import type { NewDomainEvent } from "@app/events";
@@ -117,6 +118,35 @@ export async function emitEvent<T extends EventType>(
});
}
/** Track product analytics server-side if user opted in. */
export async function trackProductAnalytics(
db: Database,
userId: string,
event: AnalyticsEvent,
): Promise<void> {
const optedIn = await db
.select({ status: schema.userConsents.status })
.from(schema.userConsents)
.where(and(eq(schema.userConsents.userId, userId), eq(schema.userConsents.kind, "product_analytics")))
.limit(1);
if (optedIn[0] && optedIn[0].status !== "granted") return;
await db.insert(schema.productAnalyticsEvents).values({
occurredAt: event.occurredAt ? new Date(event.occurredAt) : new Date(),
receivedAt: new Date(),
eventName: event.name,
anonymousId: event.anonymousId ?? null,
sessionId: event.sessionId ?? null,
userId,
householdId: event.householdId ?? null,
appVersion: event.appVersion ?? null,
platform: event.platform ?? null,
locale: event.locale ?? null,
experimentVariant: event.experimentVariant ?? null,
properties: event.properties ?? {},
});
}
/** Audit-logg (spec §56). */
export async function audit(
db: Database,