import * as v from "valibot" import type { CustomBlockErrorInfo } from "../errors.js" import { notionUserSchema } from "../users/user.js" // The schema accepts any string code. The type lists known codes for // autocomplete, with an open string fallback for newer senders. export const customBlockGetUserErrorCodeSchema = v.string() export type CustomBlockGetUserErrorCode = "get_user_failed" | (string & {}) export type CustomBlockGetUserErrorInfo = CustomBlockErrorInfo export const customBlockGetUserErrorInfoSchema = v.object({ code: customBlockGetUserErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Sandbox -> host: fetch a user by ID. */ export const getUserMessageSchema = v.object({ type: v.literal("getUser"), requestId: v.string(), userId: v.string(), }) export type GetUserMessage = v.InferOutput export const getUserResultMessageSchema = v.variant("status", [ v.object({ type: v.literal("getUserResult"), requestId: v.string(), status: v.literal("success"), user: notionUserSchema, }), v.object({ type: v.literal("getUserResult"), requestId: v.string(), status: v.literal("error"), error: customBlockGetUserErrorInfoSchema, }), ]) export type GetUserResultMessage = v.InferOutput< typeof getUserResultMessageSchema >