This commit is contained in:
Bastian Wagner
2026-07-16 09:49:22 +02:00
commit 543e8273a7
157 changed files with 22761 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
{
"name": "@boilerplate/api-client",
"version": "1.0.0",
"private": true,
"type": "module",
"main": "dist/public-api.js",
"types": "dist/public-api.d.ts",
"exports": {
".": {
"types": "./src/public-api.ts",
"default": "./src/public-api.ts"
}
},
"scripts": {
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"peerDependencies": {
"@angular/common": "22.0.6",
"@angular/core": "22.0.6",
"rxjs": "7.8.2"
}
}

View File

@@ -0,0 +1,135 @@
// Generated from the backend OpenAPI contract. Do not edit manually.
import { Injectable, inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import type { Observable } from 'rxjs';
import type {
AuditLogDto,
ItemDto,
PageDto,
RoleDto,
SaveItemDto,
SessionDto,
UserDto,
} from './models';
@Injectable({ providedIn: 'root' })
export class ApiClientService {
private readonly http = inject(HttpClient);
private readonly base = '/api';
me(): Observable<UserDto> {
return this.http.get<UserDto>(`${this.base}/me`, { withCredentials: true });
}
updateSettings(body: { tablePageSize?: number; sidebarExpanded?: boolean }): Observable<UserDto> {
return this.http.patch<UserDto>(`${this.base}/me/settings`, body, { withCredentials: true });
}
dashboard(): Observable<{
userCount: number;
activeSessions: number;
roleCount: number;
itemCount: number;
}> {
return this.http.get<{
userCount: number;
activeSessions: number;
roleCount: number;
itemCount: number;
}>(`${this.base}/dashboard`, { withCredentials: true });
}
items(
query: {
search?: string;
page?: number;
pageSize?: number;
sort?: string;
direction?: string;
} = {},
): Observable<PageDto<ItemDto>> {
return this.http.get<PageDto<ItemDto>>(`${this.base}/items`, {
params: this.params(query),
withCredentials: true,
});
}
item(id: string): Observable<ItemDto> {
return this.http.get<ItemDto>(`${this.base}/items/${id}`, { withCredentials: true });
}
createItem(body: SaveItemDto): Observable<ItemDto> {
return this.http.post<ItemDto>(`${this.base}/items`, body, { withCredentials: true });
}
updateItem(id: string, body: Required<SaveItemDto>): Observable<ItemDto> {
return this.http.put<ItemDto>(`${this.base}/items/${id}`, body, { withCredentials: true });
}
deleteItem(id: string, version: number): Observable<void> {
return this.http.delete<void>(`${this.base}/items/${id}`, {
params: { version },
withCredentials: true,
});
}
users(
query: { search?: string; page?: number; pageSize?: number } = {},
): Observable<PageDto<UserDto>> {
return this.http.get<PageDto<UserDto>>(`${this.base}/users`, {
params: this.params(query),
withCredentials: true,
});
}
setUserActive(id: string, active: boolean): Observable<UserDto> {
return this.http.patch<UserDto>(
`${this.base}/users/${id}/active`,
{ active },
{ withCredentials: true },
);
}
setUserRoles(id: string, roleIds: string[]): Observable<UserDto> {
return this.http.patch<UserDto>(
`${this.base}/users/${id}/roles`,
{ roleIds },
{ withCredentials: true },
);
}
roles(): Observable<RoleDto[]> {
return this.http.get<RoleDto[]>(`${this.base}/roles`, { withCredentials: true });
}
createRole(body: { name: string; permissions: string[] }): Observable<RoleDto> {
return this.http.post<RoleDto>(`${this.base}/roles`, body, { withCredentials: true });
}
updateRole(id: string, body: { name: string; permissions: string[] }): Observable<RoleDto> {
return this.http.put<RoleDto>(`${this.base}/roles/${id}`, body, { withCredentials: true });
}
deleteRole(id: string): Observable<void> {
return this.http.delete<void>(`${this.base}/roles/${id}`, { withCredentials: true });
}
sessions(): Observable<SessionDto[]> {
return this.http.get<SessionDto[]>(`${this.base}/sessions/own`, { withCredentials: true });
}
revokeSession(id: string): Observable<void> {
return this.http.delete<void>(`${this.base}/sessions/own/${id}`, { withCredentials: true });
}
revokeOtherSessions(): Observable<void> {
return this.http.delete<void>(`${this.base}/sessions/own`, { withCredentials: true });
}
revokeUserSessions(userId: string): Observable<void> {
return this.http.delete<void>(`${this.base}/sessions/users/${userId}`, {
withCredentials: true,
});
}
audit(page = 1, pageSize = 20): Observable<PageDto<AuditLogDto>> {
return this.http.get<PageDto<AuditLogDto>>(`${this.base}/audit-log`, {
params: { page, pageSize },
withCredentials: true,
});
}
private params(value: Record<string, string | number | undefined>): HttpParams {
let params = new HttpParams();
Object.entries(value).forEach(([key, entry]) => {
if (entry !== undefined && entry !== '') params = params.set(key, String(entry));
});
return params;
}
}

View File

@@ -0,0 +1,86 @@
// Generated from the backend OpenAPI contract. Do not edit manually.
export type Permission =
| 'items.read'
| 'items.create'
| 'items.update'
| 'items.delete'
| 'users.read'
| 'users.manage'
| 'roles.read'
| 'roles.manage'
| 'audit.read'
| 'sessions.readOwn'
| 'sessions.revokeOwn'
| 'sessions.manage';
export interface ApiErrorBody {
status: number;
code: string;
message: string;
requestId: string;
validation?: { field: string; messages: string[] }[];
}
export interface PageDto<T> {
items: T[];
total: number;
page: number;
pageSize: number;
}
export interface UserDto {
id: string;
name: string;
email: string | null;
active: boolean;
lastLoginAt: string | null;
roles: RoleDto[];
settings: { tablePageSize: number; sidebarExpanded: boolean };
}
export interface RoleDto {
id: string;
name: string;
protected: boolean;
permissions: { id: Permission; description: string }[];
users?: UserDto[];
}
export interface ItemDto {
id: string;
name: string;
description: string | null;
status: 'draft' | 'active' | 'archived';
version: number;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
}
export interface SaveItemDto {
name: string;
description?: string;
status: ItemDto['status'];
version?: number;
}
export interface SessionDto {
id: string;
createdAt: string;
lastActivityAt: string;
userAgent: string | null;
approximateIp: string | null;
current: boolean;
revokedAt: string | null;
}
export interface AuditLogDto {
id: string;
createdAt: string;
actorUserId: string | null;
action: string;
targetType: string;
targetId: string;
metadata: Record<string, string | number | boolean | null> | null;
requestId: string;
}

View File

@@ -0,0 +1,2 @@
export * from './models';
export * from './api-client.service';

View File

@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"module": "ES2022",
"moduleResolution": "Bundler",
"lib": ["ES2023", "DOM"]
},
"include": ["src/**/*.ts"]
}