-
Notifications
You must be signed in to change notification settings - Fork 0
v2.2.4 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
v2.2.4 #13
Changes from all commits
5ac4ad1
c880541
39c171f
6d02bf5
e72c485
834d908
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| @modl-gg:registry=https://npm.pkg.github.com | ||
| //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} | ||
| @modl-gg:registry=https://nexus.modl.gg/repository/npm-releases/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { requestJsonRaw } from '@/lib/api'; | ||
| import { isRecord, normalizeEpochMillisValue, toEpochMillisString } from '@/lib/api-contracts/common'; | ||
|
|
||
| export type SystemAlertSeverity = 'BASIC' | 'WARNING' | 'CRITICAL'; | ||
| export type SystemAlertAudience = 'ALL_PANEL_USERS' | 'SUPER_ADMINS_ONLY'; | ||
|
|
||
| export interface SystemAlert { | ||
| id: string; | ||
| message: string; | ||
| severity: SystemAlertSeverity; | ||
| audience: SystemAlertAudience; | ||
| expiresAt?: string; | ||
| createdAt?: string; | ||
| updatedAt?: string; | ||
| createdBy?: string; | ||
| updatedBy?: string; | ||
| } | ||
|
|
||
| interface RawSystemAlert { | ||
| id?: unknown; | ||
| _id?: unknown; | ||
| message?: unknown; | ||
| severity?: unknown; | ||
| audience?: unknown; | ||
| expiresAt?: unknown; | ||
| createdAt?: unknown; | ||
| updatedAt?: unknown; | ||
| createdBy?: unknown; | ||
| updatedBy?: unknown; | ||
| } | ||
|
|
||
| export interface AlertPayload { | ||
| message: string; | ||
| severity: SystemAlertSeverity; | ||
| audience: SystemAlertAudience; | ||
| expiresAt: string; | ||
| } | ||
|
|
||
| function toSeverity(value: unknown): SystemAlertSeverity { | ||
| const normalized = typeof value === 'string' ? value.trim().toUpperCase() : ''; | ||
| return normalized === 'WARNING' || normalized === 'CRITICAL' ? normalized : 'BASIC'; | ||
| } | ||
|
|
||
| function toAudience(value: unknown): SystemAlertAudience { | ||
| const normalized = typeof value === 'string' ? value.trim().toUpperCase() : ''; | ||
| return normalized === 'SUPER_ADMINS_ONLY' ? normalized : 'ALL_PANEL_USERS'; | ||
| } | ||
|
|
||
| function mapAlert(raw: RawSystemAlert): SystemAlert { | ||
| const id = typeof raw.id === 'string' ? raw.id : (typeof raw._id === 'string' ? raw._id : ''); | ||
|
|
||
| return { | ||
| id, | ||
| message: typeof raw.message === 'string' ? raw.message : '', | ||
| severity: toSeverity(raw.severity), | ||
| audience: toAudience(raw.audience), | ||
| expiresAt: normalizeEpochMillisValue(raw.expiresAt), | ||
| createdAt: normalizeEpochMillisValue(raw.createdAt), | ||
| updatedAt: normalizeEpochMillisValue(raw.updatedAt), | ||
| createdBy: typeof raw.createdBy === 'string' ? raw.createdBy : undefined, | ||
| updatedBy: typeof raw.updatedBy === 'string' ? raw.updatedBy : undefined, | ||
| }; | ||
| } | ||
|
|
||
| function toRequestBody(payload: AlertPayload): Record<string, unknown> { | ||
| return { | ||
| message: payload.message, | ||
| severity: payload.severity, | ||
| audience: payload.audience, | ||
| expiresAt: toEpochMillisString(payload.expiresAt) ?? '0', | ||
| }; | ||
| } | ||
|
|
||
| export const alertsService = { | ||
| async getAlerts(): Promise<SystemAlert[]> { | ||
| const raw = await requestJsonRaw<unknown>('/v1/admin/alerts'); | ||
| const items = isRecord(raw) && Array.isArray(raw.items) ? (raw.items as RawSystemAlert[]) : []; | ||
| return items.map(mapAlert); | ||
| }, | ||
|
|
||
| async createAlert(payload: AlertPayload): Promise<SystemAlert> { | ||
| const raw = await requestJsonRaw<RawSystemAlert>('/v1/admin/alerts', { | ||
| method: 'POST', | ||
| body: toRequestBody(payload), | ||
| }); | ||
| return mapAlert(raw); | ||
| }, | ||
|
|
||
| async updateAlert(id: string, payload: AlertPayload): Promise<SystemAlert> { | ||
| const raw = await requestJsonRaw<RawSystemAlert>(`/v1/admin/alerts/${id}`, { | ||
| method: 'PUT', | ||
| body: toRequestBody(payload), | ||
| }); | ||
| return mapAlert(raw); | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ interface SessionPayload { | |||||
| interface LoginPayload { | ||||||
| email?: unknown; | ||||||
| lastActivityAt?: unknown; | ||||||
| isAuthenticated?: boolean; | ||||||
| } | ||||||
|
|
||||||
| function mapSessionPayload(payload: SessionPayload): AdminSession { | ||||||
|
|
@@ -63,7 +64,7 @@ export const authService = { | |||||
| email: typeof data.email === 'string' ? data.email : email, | ||||||
| lastActivityAt: normalizeDateValue(data.lastActivityAt), | ||||||
| loggedInIps: [], | ||||||
| isAuthenticated: true, | ||||||
| isAuthenticated: data.isAuthenticated ?? true, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: client/src/lib/services/auth-service.ts
Line: 67
Comment:
**Validate login state**
This returns `data.isAuthenticated` directly whenever the field is present. If the API returns a string value such as `"false"`, the runtime value becomes a truthy string and callers like `ProtectedRoute` can treat the login as authenticated until the session refetch corrects it. Keep the mapper consistent with `mapSessionPayload` by only accepting a real boolean `true` as authenticated.
```suggestion
isAuthenticated: data.isAuthenticated === true,
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| }; | ||||||
| }, | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads
itemsfrom the top-level response, but the other admin services unwrap the API envelope before mapping payloads. If/v1/admin/alertsreturns the same shape as the rest of these endpoints, such as{ success: true, data: { items: [...] } }, this returns an empty array and the Alerts page shows no alerts even when alerts exist.Rule Used: This is a React frontend project on React 19 with ... (source)
Prompt To Fix With AI