Skip to content

Commit e739d1e

Browse files
committed
fix: use log function instead of info for the logger bridge
1 parent a8b2fbb commit e739d1e

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

lib/services/notion.service.ts

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Inject, Injectable, Logger as NestjsLogger } from '@nestjs/common';
2+
import { Client, Logger as NotionLogger, LogLevel } from '@notionhq/client';
23
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';
78

89
import { NotionModuleOptions } from '../interfaces';
910
import { NOTION_MODULE_OPTIONS } from '../notion.constants';
@@ -12,7 +13,7 @@ import { NOTION_MODULE_OPTIONS } from '../notion.constants';
1213
export class NotionService {
1314
private readonly logger = new NestjsLogger(NotionService.name);
1415

15-
protected _notion: NotionClient;
16+
protected _notion: Client;
1617

1718
constructor(
1819
@Inject(NOTION_MODULE_OPTIONS)
@@ -21,7 +22,7 @@ export class NotionService {
2122
const { nestjsLogger, ...notionOptions } = notionModuleOptions;
2223

2324
const logger = nestjsLogger ?? this.logger;
24-
this._notion = new NotionClient({
25+
this._notion = new Client({
2526
logger: this.createLoggerBridge(logger),
2627
...notionOptions,
2728
});
@@ -43,26 +44,40 @@ export class NotionService {
4344
return this.notion.pages;
4445
}
4546

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);
4851
}
4952

50-
public get search() {
51-
return this.notion.search;
53+
public search(args: SearchParameters): Promise<SearchResponse> {
54+
return this.notion.search(args);
5255
}
5356

5457
public get users() {
5558
return this.notion.users;
5659
}
5760

58-
protected createLoggerBridge(nestjsLogger: NestjsLogger): NotionLogger {
61+
protected createLoggerBridge(logger: NestjsLogger): NotionLogger {
5962
return (
6063
level: LogLevel,
6164
message: string,
6265
extraInfo: Record<string, unknown>,
6366
) => {
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);
6681
};
6782
}
6883
}

0 commit comments

Comments
 (0)