import {z} from 'zod' export type CreateApiMcpV1ActionsUdPortfolioListArgs = {body: {page?: number | undefined, pageSize?: number | undefined, searchTerm?: string | undefined, status?: ('all' | 'for-sale' | 'unlisted') | undefined, registryType?: ('dns' | 'web3') | undefined, expiringWithinDays?: number | undefined, expired?: boolean | undefined, minLength?: number | undefined, maxLength?: number | undefined, autoRenewal?: ('true' | 'false') | undefined, tagFilters?: Array | undefined, orderBy?: ('name' | 'length' | 'purchasedAt' | 'expiresAt' | 'listingPrice' | 'offers' | 'leads' | 'watchlistCount') | undefined, orderDirection?: ('asc' | 'desc') | undefined}}; export type CreateApiMcpV1ActionsUdPortfolioListOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const portfolioDomain = z.object({name: z.string().optional(), extension: z.string().optional(), label: z.string().optional(), sld: z.string().nullable().optional(), punycode: z.boolean().optional(), purchasedAt: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), transferStatus: z.string().optional(), isExternallyOwned: z.boolean().optional(), tags: z.array(z.string()).optional(), reverse: z.boolean().optional(), offersCount: z.number().optional(), leadsCount: z.number().optional(), watchlistCount: z.number().optional(), listing: z.object({id: z.number().optional(), price: z.number().optional(), status: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), views: z.number().optional()}).nullable().optional(), autoRenewal: z.object({status: z.string().optional(), expiresAt: z.string().nullable().optional()}).nullable().optional()}); export const listDomainsResponse = z.object({domains: z.array(portfolioDomain).optional(), pagination: z.object({page: z.number().optional(), pageSize: z.number().optional(), totalPages: z.number().optional(), total: z.number().optional(), hasMore: z.boolean().optional(), nextPage: z.number().nullable().optional()}).optional(), truncated: z.boolean().optional(), truncationMessage: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List portfolio domains * * POST /mcp/v1/actions/ud_portfolio_list */ export const createApiMcpV1ActionsUdPortfolioList = async (args: CreateApiMcpV1ActionsUdPortfolioListArgs, options?: CreateApiMcpV1ActionsUdPortfolioListOptions) => { const {baseUrl = "https://api.unstoppabledomains.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/mcp/v1/actions/ud_portfolio_list${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listDomainsResponse, await res.json()) };