File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,7 +102,21 @@ export function coerceBugReportsFeatureFromFeaturesPayload(payload: unknown): Bu
102102 return parsed . success ? parsed . data : DEFAULT_BUG_REPORTS_FEATURE ;
103103}
104104
105- export const FeaturesResponseSchema = z . object ( {
105+ function coerceFeaturesResponsePayload ( raw : unknown ) : unknown {
106+ if ( ! isRecord ( raw ) || ! isRecord ( raw . features ) ) return raw ;
107+
108+ // Robustness: a malformed bugReports payload should not invalidate unrelated features.
109+ // Coerce it to a safe default while preserving the rest of the payload.
110+ return {
111+ ...raw ,
112+ features : {
113+ ...raw . features ,
114+ bugReports : coerceBugReportsFeatureFromFeaturesPayload ( raw ) ,
115+ } ,
116+ } ;
117+ }
118+
119+ export const FeaturesResponseSchema = z . preprocess ( coerceFeaturesResponsePayload , z . object ( {
106120 features : z . object ( {
107121 bugReports : BugReportsFeatureSchema . optional ( ) . default ( DEFAULT_BUG_REPORTS_FEATURE ) ,
108122 automations : AutomationsFeatureSchema . optional ( ) . default ( DEFAULT_AUTOMATIONS_FEATURE ) ,
@@ -186,6 +200,6 @@ export const FeaturesResponseSchema = z.object({
186200 ) ,
187201 } ) ,
188202 } ) ,
189- } ) ;
203+ } ) ) ;
190204
191205export type FeaturesResponse = z . infer < typeof FeaturesResponseSchema > ;
You can’t perform that action at this time.
0 commit comments