feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { isRecord, isUuid } from './core-contract.generated.ts'
|
||||
|
||||
export type ManagedRole = 'user' | 'manager' | 'admin' | 'super_admin'
|
||||
export type SubscriptionTier = 'free' | 'pro' | 'pro_plus'
|
||||
export type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'expired'
|
||||
|
|
@ -12,16 +14,15 @@ export class AdminPublicError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
||||
const ROLE_VALUES = new Set<ManagedRole>(['user', 'manager', 'admin', 'super_admin'])
|
||||
const TIER_VALUES = new Set<SubscriptionTier>(['free', 'pro', 'pro_plus'])
|
||||
const STATUS_VALUES = new Set<SubscriptionStatus>(['active', 'canceled', 'past_due', 'expired'])
|
||||
|
||||
function recordValue(value: unknown): Record<string, unknown> {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
if (!isRecord(value)) {
|
||||
throw new AdminPublicError(400, 'invalid_json_body')
|
||||
}
|
||||
return value as Record<string, unknown>
|
||||
return value
|
||||
}
|
||||
|
||||
function assertOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): void {
|
||||
|
|
@ -60,7 +61,7 @@ function optionalString(
|
|||
}
|
||||
|
||||
export function requireUuid(value: string | null | undefined, code: string): string {
|
||||
if (!value || !UUID_PATTERN.test(value)) throw new AdminPublicError(400, code)
|
||||
if (!value || !isUuid(value)) throw new AdminPublicError(400, code)
|
||||
return value.toLowerCase()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue