@@ -13,6 +13,42 @@ import {
1313 type StoredTokens ,
1414} from "../storage/keychain" ;
1515
16+ /**
17+ * Recursively normalizes OneUptime API serialized types in response data.
18+ * Converts { _type: "ObjectID", value: "uuid" } → "uuid"
19+ * Converts { _type: "DateTime", value: "iso-string" } → "iso-string"
20+ */
21+ function normalizeResponseData ( data : unknown ) : unknown {
22+ if ( data === null || data === undefined ) {
23+ return data ;
24+ }
25+
26+ if ( Array . isArray ( data ) ) {
27+ return data . map ( normalizeResponseData ) ;
28+ }
29+
30+ if ( typeof data === "object" ) {
31+ const obj : Record < string , unknown > = data as Record < string , unknown > ;
32+
33+ // Check for serialized OneUptime types
34+ if (
35+ typeof obj [ "_type" ] === "string" &&
36+ typeof obj [ "value" ] === "string" &&
37+ ( obj [ "_type" ] === "ObjectID" || obj [ "_type" ] === "DateTime" )
38+ ) {
39+ return obj [ "value" ] ;
40+ }
41+
42+ const normalized : Record < string , unknown > = { } ;
43+ for ( const key in obj ) {
44+ normalized [ key ] = normalizeResponseData ( obj [ key ] ) ;
45+ }
46+ return normalized ;
47+ }
48+
49+ return data ;
50+ }
51+
1652let isRefreshing : boolean = false ;
1753let refreshSubscribers : Array < ( token : string ) => void > = [ ] ;
1854let onAuthFailure : ( ( ) => void ) | null = null ;
@@ -55,9 +91,10 @@ apiClient.interceptors.request.use(
5591 } ,
5692) ;
5793
58- // Response interceptor: handle 401 with token refresh queue
94+ // Response interceptor: normalize OneUptime serialized types then handle 401
5995apiClient . interceptors . response . use (
6096 ( response : AxiosResponse ) => {
97+ response . data = normalizeResponseData ( response . data ) ;
6198 return response ;
6299 } ,
63100 async ( error : AxiosError ) => {
0 commit comments