import { mkdir, writeFile } from 'node:fs/promises'; import { dirname, resolve } from 'node:path'; import prettier from 'prettier'; const root = resolve(import.meta.dirname, '..'); const files = new Map([ [ 'packages/api-client/src/public-api.ts', `export * from './models';\nexport * from './api-client.service';\n`, ], [ 'packages/api-client/src/models.ts', `// Generated from the backend OpenAPI contract. Do not edit manually.\nexport type Permission =\n | 'items.read'\n | 'items.create'\n | 'items.update'\n | 'items.delete'\n | 'users.read'\n | 'users.manage'\n | 'roles.read'\n | 'roles.manage'\n | 'audit.read'\n | 'sessions.readOwn'\n | 'sessions.revokeOwn'\n | 'sessions.manage';\n\nexport interface ApiErrorBody {\n status: number;\n code: string;\n message: string;\n requestId: string;\n validation?: { field: string; messages: string[] }[];\n}\n\nexport interface PageDto {\n items: T[];\n total: number;\n page: number;\n pageSize: number;\n}\n\nexport interface UserDto {\n id: string;\n name: string;\n email: string | null;\n active: boolean;\n lastLoginAt: string | null;\n roles: RoleDto[];\n settings: { tablePageSize: number; sidebarExpanded: boolean };\n}\n\nexport interface RoleDto {\n id: string;\n name: string;\n protected: boolean;\n permissions: { id: Permission; description: string }[];\n users?: UserDto[];\n}\n\nexport interface ItemDto {\n id: string;\n name: string;\n description: string | null;\n status: 'draft' | 'active' | 'archived';\n version: number;\n createdAt: string;\n updatedAt: string;\n deletedAt: string | null;\n}\n\nexport interface SaveItemDto {\n name: string;\n description?: string;\n status: ItemDto['status'];\n version?: number;\n}\n\nexport interface SessionDto {\n id: string;\n createdAt: string;\n lastActivityAt: string;\n userAgent: string | null;\n approximateIp: string | null;\n current: boolean;\n revokedAt: string | null;\n}\n\nexport interface AuditLogDto {\n id: string;\n createdAt: string;\n actorUserId: string | null;\n action: string;\n targetType: string;\n targetId: string;\n metadata: Record | null;\n requestId: string;\n}\n`, ], [ 'packages/api-client/src/api-client.service.ts', `// Generated from the backend OpenAPI contract. Do not edit manually.\nimport { Injectable, inject } from '@angular/core';\nimport { HttpClient, HttpParams } from '@angular/common/http';\nimport type { Observable } from 'rxjs';\nimport type { AuditLogDto, ItemDto, PageDto, RoleDto, SaveItemDto, SessionDto, UserDto } from './models';\n\n@Injectable({ providedIn: 'root' })\nexport class ApiClientService {\n private readonly http = inject(HttpClient);\n private readonly base = '/api';\n\n me(): Observable { return this.http.get(\`\${this.base}/me\`, { withCredentials: true }); }\n updateSettings(body: { tablePageSize?: number; sidebarExpanded?: boolean }): Observable { return this.http.patch(\`\${this.base}/me/settings\`, body, { withCredentials: true }); }\n 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 }); }\n\n items(query: { search?: string; page?: number; pageSize?: number; sort?: string; direction?: string } = {}): Observable> {\n return this.http.get>(\`\${this.base}/items\`, { params: this.params(query), withCredentials: true });\n }\n item(id: string): Observable { return this.http.get(\`\${this.base}/items/\${id}\`, { withCredentials: true }); }\n createItem(body: SaveItemDto): Observable { return this.http.post(\`\${this.base}/items\`, body, { withCredentials: true }); }\n updateItem(id: string, body: Required): Observable { return this.http.put(\`\${this.base}/items/\${id}\`, body, { withCredentials: true }); }\n deleteItem(id: string, version: number): Observable { return this.http.delete(\`\${this.base}/items/\${id}\`, { params: { version }, withCredentials: true }); }\n\n users(query: { search?: string; page?: number; pageSize?: number } = {}): Observable> { return this.http.get>(\`\${this.base}/users\`, { params: this.params(query), withCredentials: true }); }\n setUserActive(id: string, active: boolean): Observable { return this.http.patch(\`\${this.base}/users/\${id}/active\`, { active }, { withCredentials: true }); }\n setUserRoles(id: string, roleIds: string[]): Observable { return this.http.patch(\`\${this.base}/users/\${id}/roles\`, { roleIds }, { withCredentials: true }); }\n\n roles(): Observable { return this.http.get(\`\${this.base}/roles\`, { withCredentials: true }); }\n createRole(body: { name: string; permissions: string[] }): Observable { return this.http.post(\`\${this.base}/roles\`, body, { withCredentials: true }); }\n updateRole(id: string, body: { name: string; permissions: string[] }): Observable { return this.http.put(\`\${this.base}/roles/\${id}\`, body, { withCredentials: true }); }\n deleteRole(id: string): Observable { return this.http.delete(\`\${this.base}/roles/\${id}\`, { withCredentials: true }); }\n\n sessions(): Observable { return this.http.get(\`\${this.base}/sessions/own\`, { withCredentials: true }); }\n revokeSession(id: string): Observable { return this.http.delete(\`\${this.base}/sessions/own/\${id}\`, { withCredentials: true }); }\n revokeOtherSessions(): Observable { return this.http.delete(\`\${this.base}/sessions/own\`, { withCredentials: true }); }\n revokeUserSessions(userId: string): Observable { return this.http.delete(\`\${this.base}/sessions/users/\${userId}\`, { withCredentials: true }); }\n\n audit(page = 1, pageSize = 20): Observable> { return this.http.get>(\`\${this.base}/audit-log\`, { params: { page, pageSize }, withCredentials: true }); }\n\n private params(value: Record): HttpParams {\n let params = new HttpParams();\n Object.entries(value).forEach(([key, entry]) => {\n if (entry !== undefined && entry !== '') params = params.set(key, String(entry));\n });\n return params;\n }\n}\n`, ], ]); for (const [file, content] of files) { const target = resolve(root, file); await mkdir(dirname(target), { recursive: true }); const formatted = await prettier.format(content, { parser: file.endsWith('.ts') ? 'typescript' : 'json', singleQuote: true, semi: true, printWidth: 100, trailingComma: 'all', }); await writeFile(target, formatted, 'utf8'); }