import { resolveIntegrationName } from './accounts.ts' import { notionRequest } from './request.ts' import { inputRecord, optionalString } from './validation.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(params: Record = {}) { const input = inputRecord(params) const account = optionalString(input, 'account') const integration = optionalString(input, 'integration') const resolvedIntegration = resolveIntegrationName({ account, integration }) const result = await notionRequest('/users/me', { account, integration, }) if (result.object !== 'user') { throw new Error( 'Unexpected response from Notion /users/me; the "' + resolvedIntegration + '" 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, } }