Migrating from services to dedicated API files

This commit is contained in:
2025-05-03 21:28:41 +02:00
parent e789025cd1
commit 043eab423f
22 changed files with 265 additions and 228 deletions

View File

@@ -1,59 +0,0 @@
declare global {
interface Window {
API_BASE_URL: string;
}
}
export const API_BASE_URL = window.API_BASE_URL;
/**
* User role in the system
*/
export enum UserRole {
Admin = 'admin',
Editor = 'editor',
Viewer = 'viewer'
}
/**
* User model from the API
*/
export interface User {
id: number;
email: string;
displayName?: string;
role: UserRole;
createdAt: string;
lastWorkspaceId: number;
}
/**
* Error response from the API
*/
export interface ErrorResponse {
message: string;
}
/**
* Login request parameters
*/
export interface LoginRequest {
email: string;
password: string;
}
/**
* Login response from the API
*/
export interface LoginResponse {
user: User;
sessionId: string;
expiresAt: string;
}
/**
* API call options extending the standard RequestInit
*/
export interface ApiCallOptions extends RequestInit {
headers?: HeadersInit;
}

105
app/src/types/authApi.ts Normal file
View File

@@ -0,0 +1,105 @@
declare global {
interface Window {
API_BASE_URL: string;
}
}
export const API_BASE_URL = window.API_BASE_URL;
/**
* User role in the system
*/
export enum UserRole {
Admin = 'admin',
Editor = 'editor',
Viewer = 'viewer',
}
/**
* Type guard to check if a value is a valid UserRole
*/
export function isUserRole(value: unknown): value is UserRole {
return typeof value === 'string' && value in UserRole;
}
/**
* User model from the API
*/
export interface User {
id: number;
email: string;
displayName?: string;
role: UserRole;
createdAt: string;
lastWorkspaceId: number;
}
/**
* Type guard to check if a value is a valid User
*/
export function isUser(value: unknown): value is User {
return (
typeof value === 'object' &&
value !== null &&
'id' in value &&
typeof (value as User).id === 'number' &&
'email' in value &&
typeof (value as User).email === 'string' &&
('displayName' in value
? typeof (value as User).displayName === 'string'
: true) &&
'role' in value &&
isUserRole((value as User).role) &&
'createdAt' in value &&
typeof (value as User).createdAt === 'string' &&
'lastWorkspaceId' in value &&
typeof (value as User).lastWorkspaceId === 'number'
);
}
/**
* Error response from the API
*/
export interface ErrorResponse {
message: string;
}
/**
* Login request parameters
*/
export interface LoginRequest {
email: string;
password: string;
}
/**
* Login response from the API
*/
export interface LoginResponse {
user: User;
sessionId: string;
expiresAt: string;
}
/**
* Type guard to check if a value is a valid LoginResponse
*/
export function isLoginResponse(value: unknown): value is LoginResponse {
return (
typeof value === 'object' &&
value !== null &&
'user' in value &&
isUser((value as LoginResponse).user) &&
'sessionId' in value &&
typeof (value as LoginResponse).sessionId === 'string' &&
'expiresAt' in value &&
typeof (value as LoginResponse).expiresAt === 'string'
);
}
/**
* API call options extending the standard RequestInit
*/
export interface ApiCallOptions extends RequestInit {
headers?: HeadersInit;
}

View File

@@ -9,10 +9,6 @@ export enum InlineContainerType {
Delete = 'delete',
}
export const INLINE_CONTAINER_TYPES = new Set<InlineContainerType>(
Object.values(InlineContainerType)
);
export const MARKDOWN_REGEX = {
WIKILINK: /(!?)\[\[(.*?)\]\]/g,
} as const;