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 {
127
127
query ?: QueryParams
128
128
body ?: Record < string , unknown >
129
129
formDataParams ?: Record < string , string | FileParam >
130
+ headers ?: Record < string , string >
130
131
/**
131
132
* To authenticate using public API token, `auth` should be passed as a
132
133
* string. If you are trying to complete OAuth, then `auth` should be an object
@@ -212,6 +213,10 @@ export default class Client {
212
213
}
213
214
214
215
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 ,
215
220
...authorizationHeader ,
216
221
"Notion-Version" : this . #notionVersion,
217
222
"user-agent" : this . #userAgent,
Original file line number Diff line number Diff line change @@ -114,5 +114,27 @@ describe("Notion SDK Client", () => {
114
114
assert ( "size" in formData [ "file" ] )
115
115
expect ( formData [ "file" ] . size ) . toEqual ( 4 )
116
116
} )
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
+ } )
117
139
} )
118
140
} )
You can’t perform that action at this time.
0 commit comments