1
1
import { Inject , Injectable , Logger as NestjsLogger } from '@nestjs/common' ;
2
+ import { Client , Logger as NotionLogger , LogLevel } from '@notionhq/client' ;
2
3
import {
3
- Client as NotionClient ,
4
- Logger as NotionLogger ,
5
- LogLevel ,
6
- } from '@notionhq/client' ;
4
+ SearchParameters ,
5
+ SearchResponse ,
6
+ } from '@notionhq/client/build/src/api-endpoints' ;
7
+ import { RequestParameters } from '@notionhq/client/build/src/Client ' ;
7
8
8
9
import { NotionModuleOptions } from '../interfaces' ;
9
10
import { NOTION_MODULE_OPTIONS } from '../notion.constants' ;
@@ -12,7 +13,7 @@ import { NOTION_MODULE_OPTIONS } from '../notion.constants';
12
13
export class NotionService {
13
14
private readonly logger = new NestjsLogger ( NotionService . name ) ;
14
15
15
- protected _notion : NotionClient ;
16
+ protected _notion : Client ;
16
17
17
18
constructor (
18
19
@Inject ( NOTION_MODULE_OPTIONS )
@@ -21,7 +22,7 @@ export class NotionService {
21
22
const { nestjsLogger, ...notionOptions } = notionModuleOptions ;
22
23
23
24
const logger = nestjsLogger ?? this . logger ;
24
- this . _notion = new NotionClient ( {
25
+ this . _notion = new Client ( {
25
26
logger : this . createLoggerBridge ( logger ) ,
26
27
...notionOptions ,
27
28
} ) ;
@@ -43,26 +44,40 @@ export class NotionService {
43
44
return this . notion . pages ;
44
45
}
45
46
46
- public get request ( ) {
47
- return this . notion . request ;
47
+ public request < Response > (
48
+ requestParameters : RequestParameters ,
49
+ ) : Promise < Response > {
50
+ return this . notion . request ( requestParameters ) ;
48
51
}
49
52
50
- public get search ( ) {
51
- return this . notion . search ;
53
+ public search ( args : SearchParameters ) : Promise < SearchResponse > {
54
+ return this . notion . search ( args ) ;
52
55
}
53
56
54
57
public get users ( ) {
55
58
return this . notion . users ;
56
59
}
57
60
58
- protected createLoggerBridge ( nestjsLogger : NestjsLogger ) : NotionLogger {
61
+ protected createLoggerBridge ( logger : NestjsLogger ) : NotionLogger {
59
62
return (
60
63
level : LogLevel ,
61
64
message : string ,
62
65
extraInfo : Record < string , unknown > ,
63
66
) => {
64
- nestjsLogger [ level ] ( message ) ;
65
- nestjsLogger . verbose ( extraInfo ) ;
67
+ switch ( level ) {
68
+ case LogLevel . DEBUG :
69
+ case LogLevel . WARN :
70
+ case LogLevel . ERROR :
71
+ logger [ level ] ( message ) ;
72
+ break ;
73
+ case LogLevel . INFO :
74
+ logger . log ( message ) ;
75
+ break ;
76
+
77
+ default :
78
+ throw new Error ( `notion log level not found` ) ;
79
+ }
80
+ if ( typeof extraInfo !== 'undefined' ) logger . verbose ( extraInfo ) ;
66
81
} ;
67
82
}
68
83
}
0 commit comments