1
- import type { Agent } from "http"
1
+ import type { Agent } from "node: http"
2
2
import {
3
- Logger ,
3
+ type Logger ,
4
4
LogLevel ,
5
5
logLevelSeverity ,
6
6
makeConsoleLogger ,
@@ -13,76 +13,82 @@ import {
13
13
} from "./errors"
14
14
import { pick } from "./utils"
15
15
import {
16
- GetBlockParameters ,
17
- GetBlockResponse ,
16
+ type GetBlockParameters ,
17
+ type GetBlockResponse ,
18
18
getBlock ,
19
- UpdateBlockParameters ,
20
- UpdateBlockResponse ,
19
+ type UpdateBlockParameters ,
20
+ type UpdateBlockResponse ,
21
21
updateBlock ,
22
- DeleteBlockParameters ,
23
- DeleteBlockResponse ,
22
+ type DeleteBlockParameters ,
23
+ type DeleteBlockResponse ,
24
24
deleteBlock ,
25
- AppendBlockChildrenParameters ,
26
- AppendBlockChildrenResponse ,
25
+ type AppendBlockChildrenParameters ,
26
+ type AppendBlockChildrenResponse ,
27
27
appendBlockChildren ,
28
- ListBlockChildrenParameters ,
29
- ListBlockChildrenResponse ,
28
+ type ListBlockChildrenParameters ,
29
+ type ListBlockChildrenResponse ,
30
30
listBlockChildren ,
31
- ListDatabasesParameters ,
32
- ListDatabasesResponse ,
31
+ type ListDatabasesParameters ,
32
+ type ListDatabasesResponse ,
33
33
listDatabases ,
34
- GetDatabaseParameters ,
35
- GetDatabaseResponse ,
34
+ type GetDatabaseParameters ,
35
+ type GetDatabaseResponse ,
36
36
getDatabase ,
37
- QueryDatabaseParameters ,
38
- QueryDatabaseResponse ,
37
+ type QueryDatabaseParameters ,
38
+ type QueryDatabaseResponse ,
39
39
queryDatabase ,
40
- CreateDatabaseParameters ,
41
- CreateDatabaseResponse ,
40
+ type CreateDatabaseParameters ,
41
+ type CreateDatabaseResponse ,
42
42
createDatabase ,
43
- UpdateDatabaseParameters ,
44
- UpdateDatabaseResponse ,
43
+ type UpdateDatabaseParameters ,
44
+ type UpdateDatabaseResponse ,
45
45
updateDatabase ,
46
- CreatePageParameters ,
47
- CreatePageResponse ,
46
+ type CreatePageParameters ,
47
+ type CreatePageResponse ,
48
48
createPage ,
49
- GetPageParameters ,
50
- GetPageResponse ,
49
+ type GetPageParameters ,
50
+ type GetPageResponse ,
51
51
getPage ,
52
- UpdatePageParameters ,
53
- UpdatePageResponse ,
52
+ type UpdatePageParameters ,
53
+ type UpdatePageResponse ,
54
54
updatePage ,
55
- GetUserParameters ,
56
- GetUserResponse ,
55
+ type GetUserParameters ,
56
+ type GetUserResponse ,
57
57
getUser ,
58
- ListUsersParameters ,
59
- ListUsersResponse ,
58
+ type ListUsersParameters ,
59
+ type ListUsersResponse ,
60
60
listUsers ,
61
- SearchParameters ,
62
- SearchResponse ,
61
+ type SearchParameters ,
62
+ type SearchResponse ,
63
63
search ,
64
- GetSelfParameters ,
65
- GetSelfResponse ,
64
+ type GetSelfParameters ,
65
+ type GetSelfResponse ,
66
66
getSelf ,
67
- GetPagePropertyParameters ,
68
- GetPagePropertyResponse ,
67
+ type GetPagePropertyParameters ,
68
+ type GetPagePropertyResponse ,
69
69
getPageProperty ,
70
- CreateCommentParameters ,
71
- CreateCommentResponse ,
70
+ type CreateCommentParameters ,
71
+ type CreateCommentResponse ,
72
72
createComment ,
73
- ListCommentsParameters ,
74
- ListCommentsResponse ,
73
+ type ListCommentsParameters ,
74
+ type ListCommentsResponse ,
75
75
listComments ,
76
- OauthTokenResponse ,
77
- OauthTokenParameters ,
76
+ type OauthTokenResponse ,
77
+ type OauthTokenParameters ,
78
78
oauthToken ,
79
+ type OauthIntrospectResponse ,
80
+ type OauthIntrospectParameters ,
81
+ oauthIntrospect ,
82
+ type OauthRevokeResponse ,
83
+ type OauthRevokeParameters ,
84
+ oauthRevoke ,
79
85
} from "./api-endpoints"
80
86
import nodeFetch from "node-fetch"
81
87
import {
82
88
version as PACKAGE_VERSION ,
83
89
name as PACKAGE_NAME ,
84
90
} from "../package.json"
85
- import { SupportedFetch } from "./fetch-types"
91
+ import type { SupportedFetch } from "./fetch-types"
86
92
87
93
export interface ClientOptions {
88
94
auth ?: string
@@ -131,7 +137,7 @@ export default class Client {
131
137
this . #auth = options ?. auth
132
138
this . #logLevel = options ?. logLevel ?? LogLevel . WARN
133
139
this . #logger = options ?. logger ?? makeConsoleLogger ( PACKAGE_NAME )
134
- this . #prefixUrl = ( options ?. baseUrl ?? "https://api.notion.com" ) + " /v1/"
140
+ this . #prefixUrl = ` ${ options ?. baseUrl ?? "https://api.notion.com" } /v1/`
135
141
this . #timeoutMs = options ?. timeoutMs ?? 60_000
136
142
this . #notionVersion = options ?. notionVersion ?? Client . defaultNotionVersion
137
143
this . #fetch = options ?. fetch ?? nodeFetch
@@ -219,22 +225,22 @@ export default class Client {
219
225
}
220
226
221
227
const responseJson : ResponseBody = JSON . parse ( responseText )
222
- this . log ( LogLevel . INFO , ` request success` , { method, path } )
228
+ this . log ( LogLevel . INFO , " request success" , { method, path } )
223
229
return responseJson
224
230
} catch ( error : unknown ) {
225
231
if ( ! isNotionClientError ( error ) ) {
226
232
throw error
227
233
}
228
234
229
235
// Log the error if it's one of our known error types
230
- this . log ( LogLevel . WARN , ` request fail` , {
236
+ this . log ( LogLevel . WARN , " request fail" , {
231
237
code : error . code ,
232
238
message : error . message ,
233
239
} )
234
240
235
241
if ( isHTTPResponseError ( error ) ) {
236
242
// The response body may contain sensitive information so it is logged separately at the DEBUG level
237
- this . log ( LogLevel . DEBUG , ` failed response body` , {
243
+ this . log ( LogLevel . DEBUG , " failed response body" , {
238
244
body : error . body ,
239
245
} )
240
246
}
@@ -574,6 +580,46 @@ export default class Client {
574
580
} ,
575
581
} )
576
582
} ,
583
+ /**
584
+ * Introspect token
585
+ */
586
+ introspect : (
587
+ args : OauthIntrospectParameters & {
588
+ client_id : string
589
+ client_secret : string
590
+ }
591
+ ) : Promise < OauthIntrospectResponse > => {
592
+ return this . request < OauthIntrospectResponse > ( {
593
+ path : oauthIntrospect . path ( ) ,
594
+ method : oauthIntrospect . method ,
595
+ query : pick ( args , oauthIntrospect . queryParams ) ,
596
+ body : pick ( args , oauthIntrospect . bodyParams ) ,
597
+ auth : {
598
+ client_id : args . client_id ,
599
+ client_secret : args . client_secret ,
600
+ } ,
601
+ } )
602
+ } ,
603
+ /**
604
+ * Revoke token
605
+ */
606
+ revoke : (
607
+ args : OauthRevokeParameters & {
608
+ client_id : string
609
+ client_secret : string
610
+ }
611
+ ) : Promise < OauthRevokeResponse > => {
612
+ return this . request < OauthRevokeResponse > ( {
613
+ path : oauthRevoke . path ( ) ,
614
+ method : oauthRevoke . method ,
615
+ query : pick ( args , oauthRevoke . queryParams ) ,
616
+ body : pick ( args , oauthRevoke . bodyParams ) ,
617
+ auth : {
618
+ client_id : args . client_id ,
619
+ client_secret : args . client_secret ,
620
+ } ,
621
+ } )
622
+ } ,
577
623
}
578
624
579
625
/**
0 commit comments