@@ -847,13 +847,40 @@ export interface AsyncRequestOptions extends RequestOptions {
847847 body : { async_handle : string ; } & Required < RequestOptions [ "body" ] > ;
848848}
849849
850+ const SENSITIVE_KEYS = [ "token" , "password" , "secret" , "apiKey" , "authorization" , "auth" , "key" , "access_token" ] ;
851+
852+ function sanitize ( value : any , seen = new WeakSet ( ) ) : any {
853+ if ( value === null || value === undefined ) return value ;
854+
855+ if ( typeof value === "object" ) {
856+ if ( seen . has ( value ) ) return "[CIRCULAR]" ;
857+ seen . add ( value ) ;
858+
859+ if ( Array . isArray ( value ) ) {
860+ return value . map ( ( v ) => sanitize ( v , seen ) ) ;
861+ }
862+
863+ const sanitizedObj : Record < string , any > = { } ;
864+ for ( const [ k , v ] of Object . entries ( value ) ) {
865+ const isSensitiveKey = SENSITIVE_KEYS . some ( ( sensitiveKey ) =>
866+ k . toLowerCase ( ) . includes ( sensitiveKey . toLowerCase ( ) )
867+ ) ;
868+ sanitizedObj [ k ] = isSensitiveKey ? "[REDACTED]" : sanitize ( v , seen ) ;
869+ }
870+ return sanitizedObj ;
871+ }
872+
873+ return value ; // numbers, booleans, functions, etc.
874+ }
875+
850876export function DEBUG ( ...args : any [ ] ) {
851877 if (
852878 typeof process !== "undefined" &&
853879 typeof process . env !== "undefined" &&
854- process . env . DEBUG === "true"
880+ process . env . PD_SDK_DEBUG === "true"
855881 ) {
856- console . log ( "[DEBUG]" , ...args ) ;
882+ const safeArgs = args . map ( ( arg ) => sanitize ( arg ) ) ;
883+ console . log ( "[PD_SDK_DEBUG]" , ...safeArgs ) ;
857884 }
858885}
859886
@@ -971,9 +998,6 @@ export abstract class BaseClient {
971998 ) {
972999 requestOptions . body = processedBody ;
9731000 }
974- DEBUG ( "makeRequest" )
975- DEBUG ( "url: " , url . toString ( ) )
976- DEBUG ( "requestOptions: " , requestOptions )
9771001
9781002 const response : Response = await fetch ( url . toString ( ) , requestOptions ) ;
9791003
@@ -992,27 +1016,25 @@ export abstract class BaseClient {
9921016
9931017 return (await response.text()) as unknown as T;*/
9941018 const rawBody = await response . text ( ) ;
995- DEBUG ( "Response status:" , response . status ) ;
996- DEBUG ( "Response body:" , rawBody ) ;
9971019
9981020 if ( ! response . ok ) {
9991021 throw new Error ( `HTTP error! status: ${ response . status } , body: ${ rawBody } ` ) ;
10001022 }
10011023
1024+ DEBUG ( response . status , url . toString ( ) , requestOptions , rawBody )
10021025 const contentType = response . headers . get ( "Content-Type" ) ;
10031026 if ( contentType && contentType . includes ( "application/json" ) ) {
10041027 try {
10051028 const json = JSON . parse ( rawBody ) ;
1006- DEBUG ( "Parsed JSON:" , json ) ;
10071029 return json as T ;
10081030 } catch ( err ) {
1009- DEBUG ( "Failed to parse JSON, returning raw body as fallback." ) ;
10101031 }
10111032 }
10121033
10131034 return rawBody as unknown as T ;
10141035 }
10151036
1037+
10161038 protected abstract authHeaders ( ) : string | Promise < string > ;
10171039
10181040 /**
0 commit comments