Skip to content
← Public packages

@kody/notion

Search, read, query, and safely write Notion pages and databases through the saved notion OAuth integration.

src/smoke-test.ts

23 lines · 719 B · TypeScript
import { notionRequest } from './request.ts'

type BotUserResponse = {
  object?: string
  type?: string
  bot?: { owner?: { type?: string } }
  [key: string]: unknown
}

/** Verify Notion OAuth access without returning workspace or user PII. */
export default async function smokeTest() {
  const result = await notionRequest<BotUserResponse>('/users/me')

  if (result.object !== 'user') {
    throw new Error('Unexpected response from Notion /users/me; the notion integration may be misconfigured.')
  }

  return {
    ok: true,
    tokenType: typeof result.type === 'string' ? result.type : 'unknown',
    hasBotOwner: typeof result.bot === 'object' && result.bot !== null && result.bot.owner !== undefined,
  }
}