Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
# OpenSpec Change: enterprise-react-auth-whitelabel
- **Change ID**: enterprise-react-auth-whitelabel
- **Package**: `@suaveplan/react-auth-whitelabel`
- **Category**: react
- **Target path**: `react/auth/react-auth-whitelabel`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/react-auth-whitelabel.md`
---
## Summary
Deliver `@suaveplan/react-auth-whitelabel` on genesis from scratch at enterprise quality. White-label authentication React components with tenant branding: `LoginForm`, `RegisterForm`, `PasswordResetForm`, `AuthProvider`, `BrandingProvider`, and six hooks. Genesis adds an interception hook for SSO flows (replacing direct `window.location.href` assignment), improves `BrandingContext` README documentation, and reaches 100% test coverage with real `@suaveplan/react-translate`.
---
## Current-state audit (genesis)
Package does not exist on genesis — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | `AuthWhitelabelError` |
| `@suaveplan/react-translate` (`workspace:^`) | i18n |
| `zod` (`catalog:forms`) | Form schemas + branding schemas |
External: `@hookform/resolvers catalog:forms`, `react-hook-form catalog:forms`, `clsx catalog:ui`, `tailwind-merge catalog:ui`, `tslib catalog:build`. React 18 peer.
---
## Preserved public API surface
```ts
// Components
LoginForm, RegisterForm, PasswordResetForm
// Context
AuthProvider (+ AuthProviderProps), BrandingProvider
// Hooks
useAuth, useBranding, useIsAuthenticated, useLogo, useTenantBranding, useUser
// Types
AuthConfig, AuthContextValue, AuthUser, BrandingContextValue, BrandingProviderProps,
RegisterData, TenantBranding, LoginFormProps, LoginFormValues,
PasswordResetConfirmValues, PasswordResetFormProps, PasswordResetMode,
PasswordResetRequestValues, RegisterFormProps, RegisterFormValues,
AuthProviderConfig
```
---
## New additions for genesis
1. **SSO navigation hook** — `AuthProvider` accepts optional `onNavigate(url: string): void`; `loginWithProvider` calls this instead of `window.location.href` directly. Enables full testability.
2. **`AuthWhitelabelError`** — codes: `AUTH_WL_CONTEXT_MISSING`, `AUTH_WL_INVALID_BRANDING`.
3. **`TenantBranding` Zod schema** — documents the full shape (colors, fonts, logoUrl) with validation.
4. **Stories** — all three forms with default branding, custom branding, loading, error states.
5. **E2E** — `e2e/login-form.spec.ts`, `register-form.spec.ts`, `password-reset-form.spec.ts`.
---
## File layout
```text
react/auth/react-auth-whitelabel/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
components/
login-form/ register-form/ password-reset-form/
context/
auth-context/ branding-context/
hooks/ (6 hooks)
types/
branding.types.ts
e2e/
login-form.spec.ts
register-form.spec.ts
password-reset-form.spec.ts
```

View File

@@ -0,0 +1,79 @@
# Tasks: enterprise-react-auth-whitelabel
**Change ID**: enterprise-react-auth-whitelabel
**Package**: `@suaveplan/react-auth-whitelabel`
**Target path**: `react/auth/react-auth-whitelabel`
**Prerequisite packages on Verdaccio**: `@suaveplan/error`, `@suaveplan/react-translate`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold
- [ ] Create directory tree per proposal layout.
- [ ] Write `package.json` at `0.1.0` with `"sideEffects": false`, exports map.
- [ ] Dependencies: `@suaveplan/error workspace:^`, `@suaveplan/react-translate workspace:^`, `@hookform/resolvers catalog:forms`, `react-hook-form catalog:forms`, `clsx catalog:ui`, `tailwind-merge catalog:ui`, `zod catalog:forms`, `tslib catalog:build`.
- [ ] Write `tsconfig.json`, `vitest.config.ts`, scripts.
---
## 2. Error codes and types
- [ ] Define `AuthWhitelabelError` extending `SuaveplanError`; codes: `AUTH_WL_CONTEXT_MISSING`, `AUTH_WL_INVALID_BRANDING`.
- [ ] Define `TenantBranding`: `{ logoUrl?: string; primaryColor?: string; secondaryColor?: string; fontFamily?: string; companyName?: string }`.
- [ ] Write `TenantBrandingSchema` Zod schema.
- [ ] Define `AuthConfig`, `AuthUser`, `AuthContextValue`, `BrandingContextValue`, `BrandingProviderProps`, `AuthProviderConfig` + `AuthProviderProps`.
---
## 3. BrandingContext + BrandingProvider
- [ ] Provides `TenantBranding` via context; validates on mount via `TenantBrandingSchema`; throws `AuthWhitelabelError(AUTH_WL_INVALID_BRANDING)` on invalid.
- [ ] Hooks: `useBranding(): BrandingContextValue`, `useLogo(): string | undefined`, `useTenantBranding(): TenantBranding`.
- [ ] Write test + md.
---
## 4. AuthContext + AuthProvider
- [ ] Manages `user: AuthUser | null`, `isAuthenticated`.
- [ ] `login(credentials)`, `logout()`, `loginWithProvider(providerUrl)` — uses `onNavigate(url)` callback (not direct `window.location.href`).
- [ ] `useAuth()`, `useUser()`, `useIsAuthenticated()` hooks throw `AuthWhitelabelError(AUTH_WL_CONTEXT_MISSING)` outside provider.
- [ ] Write `auth-context.test.tsx` (≤500 lines): login, logout, loginWithProvider calls `onNavigate`, context missing. `{ timeout: 5000 }`.
- [ ] Write `auth-context.md`.
---
## 5. Form components
For each (`LoginForm`, `RegisterForm`, `PasswordResetForm`):
- [ ] `react-hook-form` + `@hookform/resolvers/zod`; `useTranslation` for all labels/errors/buttons.
- [ ] Respects `BrandingProvider` — applies `primaryColor`, `fontFamily` via CSS variables.
- [ ] Write `<form>.test.tsx` (≤500 lines): valid submit, invalid submit errors, branding applied. `{ timeout: 5000 }`.
- [ ] Write `<form>.stories.tsx`: default, custom-branding, loading, error, playground.
- [ ] Write `<form>.md`.
`PasswordResetForm`: supports `mode: 'request' | 'confirm'` switching between `PasswordResetRequestValues` and `PasswordResetConfirmValues`.
---
## 6. E2E (3 files)
- [ ] `e2e/login-form.spec.ts` — fill email + password, submit → `onLogin` called.
- [ ] `e2e/register-form.spec.ts` — fill all fields, submit → `onRegister` called.
- [ ] `e2e/password-reset-form.spec.ts` — request mode: fill email, submit; confirm mode: fill passwords, submit.
---
## 7. Verify and publish
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/react-auth-whitelabel` — green.
- [ ] `bunx turbo test:coverage --filter=@suaveplan/react-auth-whitelabel` — 100%.
- [ ] `bun scripts/publish.ts --package @suaveplan/react-auth-whitelabel`.
- [ ] Archive change folder.