Restructures frontend to a feature-based folder layout
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Skipped
Continuous Integration / backend-test (pull_request) Skipped
Continuous Integration / vulnerability-scan (pull_request) Skipped
Continuous Integration / frontend-prepare (pull_request) Successful in 1m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m12s
Continuous Integration / frontend-test (pull_request) Successful in 4m42s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m51s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Skipped
Continuous Integration / backend-test (pull_request) Skipped
Continuous Integration / vulnerability-scan (pull_request) Skipped
Continuous Integration / frontend-prepare (pull_request) Successful in 1m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m12s
Continuous Integration / frontend-test (pull_request) Successful in 4m42s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m51s
Continuous Integration / deploy-test (pull_request) Skipped
Groups auth, setup, invitation, profile, users, cms, availability and system code (services/hooks, components, schemas, mocks, pages) under src/features/<name> instead of splitting by technical layer (api/, components/, lib/schemas/, mocks/, pages/). Renames the old connection-oriented `api` layer to `services` per feature, and splits the monolithic api/types.ts into per-feature types.ts files (with ProblemDetails/ApiResult merged into lib/api-client.ts as shared infra). Layout-agnostic code (ui primitives, app shell, i18n, test utils, lib) stays at the top level. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
import type { ProblemDetails } from '@/api/types';
|
||||
import { getAppConfig } from '@/lib/config';
|
||||
|
||||
// RFC 9457 ProblemDetails for standardized error handling.
|
||||
export interface ProblemDetails {
|
||||
type?: string;
|
||||
title?: string;
|
||||
status?: number;
|
||||
detail?: string;
|
||||
instance?: string;
|
||||
// Extension members (e.g. traceId, errors).
|
||||
[extension: string]: unknown;
|
||||
}
|
||||
|
||||
// Convenience wrapper for API results (optional usage).
|
||||
export type ApiResult<T> = { ok: true; data: T } | { ok: false; error: ProblemDetails };
|
||||
|
||||
/**
|
||||
* Typed error thrown for any non-2xx API response. Wraps an RFC 9457
|
||||
* ProblemDetails body so callers can present context-aware messages
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
passwordSchema,
|
||||
setupFormSchema,
|
||||
loginFormSchema,
|
||||
invitationCompleteFormSchema,
|
||||
} from '@/lib/schemas/auth';
|
||||
|
||||
describe('passwordSchema', () => {
|
||||
it('accepts a valid password', () => {
|
||||
expect(passwordSchema.safeParse('Password1!').success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects a password that is too short', () => {
|
||||
expect(passwordSchema.safeParse('Pass1!').success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a password without an uppercase letter', () => {
|
||||
expect(passwordSchema.safeParse('password1!').success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a password without a digit', () => {
|
||||
expect(passwordSchema.safeParse('Password!').success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a password without a special character', () => {
|
||||
expect(passwordSchema.safeParse('Password1').success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setupFormSchema', () => {
|
||||
const valid = {
|
||||
name: 'Admin',
|
||||
email: 'admin@example.com',
|
||||
password: 'Password1!',
|
||||
confirmPassword: 'Password1!',
|
||||
language: 'nl' as const,
|
||||
};
|
||||
|
||||
it('accepts valid setup data', () => {
|
||||
expect(setupFormSchema.safeParse(valid).success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects when passwords do not match', () => {
|
||||
const result = setupFormSchema.safeParse({ ...valid, confirmPassword: 'Different1!' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty name', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, name: '' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects name exceeding 255 characters', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, name: 'a'.repeat(256) }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid email format', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, email: 'not-an-email' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty email', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, email: '' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid language', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, language: 'fr' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts "en" as language', () => {
|
||||
expect(setupFormSchema.safeParse({ ...valid, language: 'en' }).success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loginFormSchema', () => {
|
||||
it('accepts valid login credentials', () => {
|
||||
expect(loginFormSchema.safeParse({ email: 'user@example.com', password: 'anypass' }).success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects empty email', () => {
|
||||
expect(loginFormSchema.safeParse({ email: '', password: 'pass' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid email format', () => {
|
||||
expect(loginFormSchema.safeParse({ email: 'not-email', password: 'pass' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty password', () => {
|
||||
expect(loginFormSchema.safeParse({ email: 'user@example.com', password: '' }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invitationCompleteFormSchema', () => {
|
||||
const valid = {
|
||||
name: 'New User',
|
||||
password: 'Password1!',
|
||||
confirmPassword: 'Password1!',
|
||||
};
|
||||
|
||||
it('accepts valid invitation completion data', () => {
|
||||
expect(invitationCompleteFormSchema.safeParse(valid).success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects when passwords do not match', () => {
|
||||
expect(
|
||||
invitationCompleteFormSchema.safeParse({ ...valid, confirmPassword: 'Different1!' }).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty name', () => {
|
||||
expect(invitationCompleteFormSchema.safeParse({ ...valid, name: '' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects weak password', () => {
|
||||
expect(
|
||||
invitationCompleteFormSchema.safeParse({
|
||||
...valid,
|
||||
password: 'weak',
|
||||
confirmPassword: 'weak',
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,61 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// Shared password validation schema matching backend rules:
|
||||
// - Minimum 8 characters
|
||||
// - At least 1 uppercase letter
|
||||
// - At least 1 digit
|
||||
// - At least 1 special character
|
||||
export const passwordSchema = z.string()
|
||||
.min(8, 'Wachtwoord moet minstens 8 tekens bevatten')
|
||||
.regex(/[A-Z]/, 'Wachtwoord moet minstens één hoofdletter bevatten')
|
||||
.regex(/[0-9]/, 'Wachtwoord moet minstens één cijfer bevatten')
|
||||
.regex(
|
||||
/[!@#$%^&*()\-_=+[\]{}|;:,.<>?]/,
|
||||
'Wachtwoord moet minstens één speciaal teken bevatten'
|
||||
);
|
||||
|
||||
export const confirmPasswordSchema = z.string()
|
||||
.min(1, 'Bevestig wachtwoord is vereist');
|
||||
|
||||
// Setup form schema
|
||||
export const setupFormSchema = z.object({
|
||||
name: z.string()
|
||||
.min(1, 'Naam is vereist')
|
||||
.max(255, 'Naam mag maximaal 255 tekens zijn'),
|
||||
email: z.string()
|
||||
.min(1, 'E-mailadres is vereist')
|
||||
.email('Voer een geldig e-mailadres in'),
|
||||
password: passwordSchema,
|
||||
confirmPassword: confirmPasswordSchema,
|
||||
language: z.enum(['en', 'nl'])
|
||||
}).refine((data) => data.password === data.confirmPassword, {
|
||||
message: 'Wachtwoorden komen niet overeen',
|
||||
path: ['confirmPassword']
|
||||
});
|
||||
|
||||
export type SetupFormData = z.infer<typeof setupFormSchema>;
|
||||
|
||||
// Invitation completion form schema
|
||||
export const invitationCompleteFormSchema = z.object({
|
||||
name: z.string()
|
||||
.min(1, 'Naam is vereist')
|
||||
.max(255, 'Naam mag maximaal 255 tekens zijn'),
|
||||
password: passwordSchema,
|
||||
confirmPassword: confirmPasswordSchema
|
||||
}).refine((data) => data.password === data.confirmPassword, {
|
||||
message: 'Wachtwoorden komen niet overeen',
|
||||
path: ['confirmPassword']
|
||||
});
|
||||
|
||||
export type InvitationCompleteFormData = z.infer<typeof invitationCompleteFormSchema>;
|
||||
|
||||
// Login form schema (password only)
|
||||
export const loginFormSchema = z.object({
|
||||
email: z.string()
|
||||
.min(1, 'E-mailadres is vereist')
|
||||
.email('Voer een geldig e-mailadres in'),
|
||||
password: z.string()
|
||||
.min(1, 'Wachtwoord is vereist')
|
||||
});
|
||||
|
||||
export type LoginFormData = z.infer<typeof loginFormSchema>;
|
||||
@@ -1,69 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { addCmsInstanceSchema, setStatusSchema } from './cms';
|
||||
|
||||
describe('addCmsInstanceSchema', () => {
|
||||
it('accepts valid data', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({
|
||||
name: 'My CMS',
|
||||
url: 'http://192.168.1.5:8080',
|
||||
apiKey: 'secret-key',
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts https URLs', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({
|
||||
name: 'My CMS',
|
||||
url: 'https://cms.example.com',
|
||||
apiKey: 'secret-key',
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects missing name', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({ name: '', url: 'http://example.com', apiKey: 'k' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects URL without protocol', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({ name: 'CMS', url: 'cms.example.com', apiKey: 'k' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects bare IP without protocol', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({ name: 'CMS', url: '192.168.1.5:8080', apiKey: 'k' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects missing apiKey', () => {
|
||||
const result = addCmsInstanceSchema.safeParse({ name: 'CMS', url: 'http://example.com', apiKey: '' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setStatusSchema', () => {
|
||||
it('accepts Available without disableMessage', () => {
|
||||
const result = setStatusSchema.safeParse({ status: 'Available' });
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts Inactive without disableMessage', () => {
|
||||
const result = setStatusSchema.safeParse({ status: 'Inactive' });
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts NotAvailable with a disableMessage', () => {
|
||||
const result = setStatusSchema.safeParse({ status: 'NotAvailable', disableMessage: 'System down' });
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects NotAvailable without disableMessage', () => {
|
||||
const result = setStatusSchema.safeParse({ status: 'NotAvailable' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects NotAvailable with blank disableMessage', () => {
|
||||
const result = setStatusSchema.safeParse({ status: 'NotAvailable', disableMessage: ' ' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const addCmsInstanceSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(255, 'Name must be 255 characters or fewer'),
|
||||
url: z.string().url('Must be a valid URL (include http:// or https://)'),
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
});
|
||||
|
||||
export type AddCmsInstanceFormData = z.infer<typeof addCmsInstanceSchema>;
|
||||
|
||||
export const setStatusSchema = z
|
||||
.object({
|
||||
status: z.enum(['Available', 'NotAvailable', 'Inactive']),
|
||||
disableMessage: z.string().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) =>
|
||||
data.status !== 'NotAvailable' || (data.disableMessage?.trim().length ?? 0) > 0,
|
||||
{
|
||||
message: 'Disable message is required when status is Not Available',
|
||||
path: ['disableMessage'],
|
||||
},
|
||||
);
|
||||
|
||||
export type SetStatusFormData = z.infer<typeof setStatusSchema>;
|
||||
@@ -1,24 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { inviteUserSchema } from './users';
|
||||
|
||||
describe('inviteUserSchema', () => {
|
||||
it('accepts valid email and role', () => {
|
||||
const result = inviteUserSchema.safeParse({ email: 'user@example.com', role: 'Administrator' });
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects invalid email', () => {
|
||||
const result = inviteUserSchema.safeParse({ email: 'not-an-email', role: 'User' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects missing role', () => {
|
||||
const result = inviteUserSchema.safeParse({ email: 'user@example.com' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid role value', () => {
|
||||
const result = inviteUserSchema.safeParse({ email: 'user@example.com', role: 'Owner' });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const inviteUserSchema = z.object({
|
||||
email: z.string().email(),
|
||||
role: z.enum(['Administrator', 'User']),
|
||||
});
|
||||
|
||||
export type InviteUserFormData = z.infer<typeof inviteUserSchema>;
|
||||
Reference in New Issue
Block a user