import { Client } from '@notionhq/client';
import {
CreatePageArgs,
RetrievePageArgs,
UpdatePageArgs,
RetrievePagePropertyArgs,
} from './types.js';
export class NotionClient {
private client: Client;
constructor(apiKey: string, version?: string) {
this.client = new Client({
auth: apiKey,
notionVersion: version || '2022-06-28'
});
}
async createPage(args: CreatePageArgs) {
return await this.client.pages.create(args as any);
}
async retrievePage(args: RetrievePageArgs) {
const { page_id, filter_properties } = args;
return await this.client.pages.retrieve({
page_id,
...(filter_properties && { filter_properties })
});
}
async updatePage(args: UpdatePageArgs) {
return await this.client.pages.update(args as any);
}
async retrievePageProperty(args: RetrievePagePropertyArgs) {
const { page_id, property_id, page_size, start_cursor } = args;
return await this.client.pages.properties.retrieve({
page_id,
property_id,
...(page_size && { page_size }),
...(start_cursor && { start_cursor })
});
}
}