@@ -34,12 +34,13 @@ export function decodePayload(
3434  // eslint-disable-next-line @typescript-eslint/no-explicit-any 
3535) : Payload  |  Record < any ,  any >  |  string  { 
3636  const  encoding  =  atob ( String ( payload ?. metadata ?. encoding  ??  '' ) ) ; 
37+ 
3738  // Help users out with an english encoding 
3839  ( payload . metadata . encodingDecoded  as  unknown  as  string )  =  encoding ; 
3940
40-   if  ( encoding . startsWith ( 'json/' ) )  { 
41+   if  ( encoding ? .startsWith ( 'json/' ) )  { 
4142    try  { 
42-       return  parseWithBigInt ( atob ( String ( payload . data ) ) ) ; 
43+       return  parseWithBigInt ( atob ( String ( payload ? .data   ??   '' ) ) ) ; 
4344    }  catch  ( _e )  { 
4445      // Couldn't correctly decode this just let the user deal with the data as is 
4546    } 
@@ -119,7 +120,7 @@ export const decodeAllPotentialPayloadsWithCodec = async (
119120          JSONPayload  =  payloads . map ( decodePayload ) ; 
120121        } 
121122        anyAttributes [ key ]  =  JSONPayload ; 
122-       }  else  if  ( key  ===  'encodedAttributes' )  { 
123+       }  else  if  ( key  ===  'encodedAttributes'   &&   anyAttributes [ key ] )  { 
123124        // Can expand if more fields have single payload 
124125        // eslint-disable-next-line @typescript-eslint/no-explicit-any 
125126        let  JSONPayload : string  |  Payload  |  Record < any ,  any > ; 
@@ -175,7 +176,7 @@ export const decodeAllPotentialPayloadsWithWebsockets = async (
175176          JSONPayload  =  payloads . map ( decodePayload ) ; 
176177        } 
177178        anyAttributes [ key ]  =  JSONPayload ; 
178-       }  else  if  ( key  ===  'encodedAttributes' )  { 
179+       }  else  if  ( key  ===  'encodedAttributes'   &&   anyAttributes [ key ] )  { 
179180        // Can expand if more fields have single payload 
180181        // eslint-disable-next-line @typescript-eslint/no-explicit-any 
181182        let  JSONPayload : string  |  Payload  |  Record < any ,  any > ; 
0 commit comments