UNPKG

@jahands/notion-client

Version:
173 lines 6.34 kB
import { LogLevel } from './logging'; import type { Agent } from 'node:http'; import type { AppendBlockChildrenParameters, AppendBlockChildrenResponse, CreateCommentParameters, CreateCommentResponse, CreateDatabaseParameters, CreateDatabaseResponse, CreatePageParameters, CreatePageResponse, DeleteBlockParameters, DeleteBlockResponse, GetBlockParameters, GetBlockResponse, GetDatabaseParameters, GetDatabaseResponse, GetPageParameters, GetPagePropertyParameters, GetPagePropertyResponse, GetPageResponse, GetSelfParameters, GetSelfResponse, GetUserParameters, GetUserResponse, ListBlockChildrenParameters, ListBlockChildrenResponse, ListCommentsParameters, ListCommentsResponse, ListDatabasesParameters, ListDatabasesResponse, ListUsersParameters, ListUsersResponse, OauthTokenParameters, OauthTokenResponse, QueryDatabaseParameters, QueryDatabaseResponse, SearchParameters, SearchResponse, UpdateBlockParameters, UpdateBlockResponse, UpdateDatabaseParameters, UpdateDatabaseResponse, UpdatePageParameters, UpdatePageResponse } from './api-endpoints'; import type { Logger } from './logging'; export interface ClientOptions { auth?: string; timeoutMs?: number; baseUrl?: string; logLevel?: LogLevel; logger?: Logger; notionVersion?: string; /** Silently ignored in the browser */ agent?: Agent; } export interface RequestParameters { path: string; method: Method; query?: QueryParams; body?: Record<string, unknown>; /** * To authenticate using public API token, `auth` should be passed as a * string. If you are trying to complete OAuth, then `auth` should be an object * containing your integration's client ID and secret. */ auth?: string | { client_id: string; client_secret: string; }; } export default class Client { #private; static readonly defaultNotionVersion = "2022-06-28"; constructor(options?: ClientOptions); /** * Sends a request. * * @param path * @param method * @param query * @param body * @returns */ request<ResponseBody>({ path, method, query, body, auth, }: RequestParameters): Promise<ResponseBody>; readonly blocks: { /** * Retrieve block */ retrieve: (args: WithAuth<GetBlockParameters>) => Promise<GetBlockResponse>; /** * Update block */ update: (args: WithAuth<UpdateBlockParameters>) => Promise<UpdateBlockResponse>; /** * Delete block */ delete: (args: WithAuth<DeleteBlockParameters>) => Promise<DeleteBlockResponse>; children: { /** * Append block children */ append: (args: WithAuth<AppendBlockChildrenParameters>) => Promise<AppendBlockChildrenResponse>; /** * Retrieve block children */ list: (args: WithAuth<ListBlockChildrenParameters>) => Promise<ListBlockChildrenResponse>; }; }; readonly databases: { /** * List databases * * @deprecated Please use `search` */ list: (args: WithAuth<ListDatabasesParameters>) => Promise<ListDatabasesResponse>; /** * Retrieve a database */ retrieve: (args: WithAuth<GetDatabaseParameters>) => Promise<GetDatabaseResponse>; /** * Query a database */ query: (args: WithAuth<QueryDatabaseParameters>) => Promise<QueryDatabaseResponse>; /** * Create a database */ create: (args: WithAuth<CreateDatabaseParameters>) => Promise<CreateDatabaseResponse>; /** * Update a database */ update: (args: WithAuth<UpdateDatabaseParameters>) => Promise<UpdateDatabaseResponse>; }; readonly pages: { /** * Create a page */ create: (args: WithAuth<CreatePageParameters>) => Promise<CreatePageResponse>; /** * Retrieve a page */ retrieve: (args: WithAuth<GetPageParameters>) => Promise<GetPageResponse>; /** * Update page properties */ update: (args: WithAuth<UpdatePageParameters>) => Promise<UpdatePageResponse>; properties: { /** * Retrieve page property */ retrieve: (args: WithAuth<GetPagePropertyParameters>) => Promise<GetPagePropertyResponse>; }; }; readonly users: { /** * Retrieve a user */ retrieve: (args: WithAuth<GetUserParameters>) => Promise<GetUserResponse>; /** * List all users */ list: (args: WithAuth<ListUsersParameters>) => Promise<ListUsersResponse>; /** * Get details about bot */ me: (args: WithAuth<GetSelfParameters>) => Promise<GetSelfResponse>; }; readonly comments: { /** * Create a comment */ create: (args: WithAuth<CreateCommentParameters>) => Promise<CreateCommentResponse>; /** * List comments */ list: (args: WithAuth<ListCommentsParameters>) => Promise<ListCommentsResponse>; }; /** * Search */ search: (args: WithAuth<SearchParameters>) => Promise<SearchResponse>; readonly oauth: { /** * Get token */ token: (args: OauthTokenParameters & { client_id: string; client_secret: string; }) => Promise<OauthTokenResponse>; }; /** * Emits a log message to the console. * * @param level The level for this message * @param args Arguments to send to the console */ private log; /** * Transforms an API key or access token into a headers object suitable for an HTTP request. * * This method uses the instance's value as the default when the input is undefined. If neither are defined, it returns * an empty object * * @param auth API key or access token * @returns headers key-value object */ private authAsHeaders; } type Method = 'get' | 'post' | 'patch' | 'delete'; type QueryParams = Record<string, string | number | string[]> | URLSearchParams; type WithAuth<P> = P & { auth?: string; }; export {}; //# sourceMappingURL=Client.d.ts.map