V2 lives entirely under v2/ and is built around three asks the team raised about V1: per-video assets sometimes drifted onto the wrong trend, hashtag scrapes returned junk that wasn't filterable per-client, and there was no multi-user model behind Microsoft SSO. Highlights: - Stable TikTok numeric-id key for every per-video asset; URL form drift is logged loudly to drift_log.jsonl and never silently nulls assets. Stage 5 manifest hard-gates Stage 6 if any selected video is missing any required asset; --drop-failing auto-backfills from the next-best recipe candidates. - Per-brief engagement floor (min_likes / min_plays / min_stl_pct), applied at Apify scrape time and re-validated locally; spend_log.json records raw_returned vs kept_after_floor per scrape. - Users + teams + memberships with owner/admin/editor/viewer roles; SSO upserts a user keyed on Azure oid, auto-creates a personal team, and a super-admin is bootstrapped via BOOTSTRAP_SUPER_ADMIN_EMAIL on first sign-in. Phase A integration test: 16/16 pass. - 10-stage TS pipeline (brief → seed → scrape1 → select → scrape2 → validate → analyse → insights → trends → qa → build) wired through one CLI; each stage idempotent + resumable from disk via .state sentinels. §4.5 rubrics shipped under prompts/ and loaded into Claude calls. - React 18 + Vite + TS + Tailwind operator SPA: brief intake form, team management, super-admin user list, help/FAQ ported from V1. - Separate Docker Compose project (name: social-reporting-v2, port 3457, Postgres 5437) with deploy/setup-v2.sh, deploy-v2.sh, rollback-to-v1.sh scripts that take over V1's /social-reports URL and let us roll back. Verification: 62 unit tests pass (auth/session, ids extractor with full URL fixture, engagement floor, recipes, manifest, linking-fix, MoM compare). Live smoke run on a Dove brief: 1400 raw → 253 kept (82% culled) → 21 fully-bundled videos → 25 editorial trends across 8 brief-driven categories, with drift=0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { sql } from './client.js';
|
|
|
|
export interface UserRow {
|
|
id: string;
|
|
azure_oid: string;
|
|
email: string;
|
|
display_name: string;
|
|
is_super_admin: boolean;
|
|
password_hash: string | null;
|
|
created_at: Date;
|
|
last_login_at: Date | null;
|
|
}
|
|
|
|
export async function getUserById(id: string): Promise<UserRow | null> {
|
|
const [row] = await sql<UserRow[]>`SELECT * FROM users WHERE id = ${id}`;
|
|
return row ?? null;
|
|
}
|
|
|
|
export async function getUserByOid(oid: string): Promise<UserRow | null> {
|
|
const [row] = await sql<UserRow[]>`SELECT * FROM users WHERE azure_oid = ${oid}`;
|
|
return row ?? null;
|
|
}
|
|
|
|
export async function getUserByEmail(email: string): Promise<UserRow | null> {
|
|
const [row] = await sql<UserRow[]>`SELECT * FROM users WHERE email = ${email}`;
|
|
return row ?? null;
|
|
}
|
|
|
|
export interface UpsertSsoUserInput {
|
|
oid: string;
|
|
email: string;
|
|
display_name: string;
|
|
}
|
|
|
|
export async function upsertSsoUser(input: UpsertSsoUserInput): Promise<UserRow> {
|
|
const [row] = await sql<UserRow[]>`
|
|
INSERT INTO users (azure_oid, email, display_name, last_login_at)
|
|
VALUES (${input.oid}, ${input.email}, ${input.display_name}, NOW())
|
|
ON CONFLICT (azure_oid) DO UPDATE SET
|
|
email = EXCLUDED.email,
|
|
display_name = EXCLUDED.display_name,
|
|
last_login_at = NOW()
|
|
RETURNING *
|
|
`;
|
|
if (!row) throw new Error('upsertSsoUser: no row returned');
|
|
return row;
|
|
}
|
|
|
|
export async function setSuperAdmin(userId: string, isSuper: boolean): Promise<UserRow> {
|
|
const [row] = await sql<UserRow[]>`
|
|
UPDATE users SET is_super_admin = ${isSuper} WHERE id = ${userId} RETURNING *
|
|
`;
|
|
if (!row) throw new Error('setSuperAdmin: user not found');
|
|
return row;
|
|
}
|
|
|
|
export async function listAllUsers(): Promise<UserRow[]> {
|
|
return sql<UserRow[]>`SELECT * FROM users ORDER BY created_at DESC`;
|
|
}
|