File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ export interface RequestParameters {
127127 query ?: QueryParams
128128 body ?: Record < string , unknown >
129129 formDataParams ?: Record < string , string | FileParam >
130+ headers ?: Record < string , string >
130131 /**
131132 * To authenticate using public API token, `auth` should be passed as a
132133 * string. If you are trying to complete OAuth, then `auth` should be an object
@@ -212,6 +213,10 @@ export default class Client {
212213 }
213214
214215 const headers : Record < string , string > = {
216+ // Request-level custom additional headers can be provided, but
217+ // don't allow them to override all other headers, e.g. the
218+ // standard user agent.
219+ ...args . headers ,
215220 ...authorizationHeader ,
216221 "Notion-Version" : this . #notionVersion,
217222 "user-agent" : this . #userAgent,
Original file line number Diff line number Diff line change @@ -114,5 +114,27 @@ describe("Notion SDK Client", () => {
114114 assert ( "size" in formData [ "file" ] )
115115 expect ( formData [ "file" ] . size ) . toEqual ( 4 )
116116 } )
117+
118+ it ( "accepts custom request-level headers" , async ( ) => {
119+ await notion . request ( {
120+ path : "comments" ,
121+ method : "get" ,
122+ headers : {
123+ "X-Custom-Header" : "custom-value" ,
124+ } ,
125+ } )
126+
127+ expect ( mockFetch ) . toHaveBeenCalledWith (
128+ "https://api.notion.com/v1/comments" ,
129+ expect . objectContaining ( {
130+ method : "GET" ,
131+ headers : expect . objectContaining ( {
132+ "Notion-Version" : expect . any ( String ) ,
133+ "user-agent" : expect . stringContaining ( "notionhq-client" ) ,
134+ "X-Custom-Header" : "custom-value" ,
135+ } ) ,
136+ } )
137+ )
138+ } )
117139 } )
118140} )
You can’t perform that action at this time.
0 commit comments