import {z} from 'zod' export type CreateApiMcpV1ActionsUdBackordersListArgs = {body: {status?: (Array<'pending' | 'cancelled' | 'in-progress' | 'registration-pending' | 'completed-success' | 'completed-not-available' | 'completed-payment-failed' | 'completed-user-contact-invalid' | 'failed'>) | undefined, query?: string | undefined, offset?: number | undefined, limit?: number | undefined}}; export type CreateApiMcpV1ActionsUdBackordersListOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiMcpV1ActionsUdBackordersListResponse = z.object({backorders: z.array(z.object({backorderId: z.number().optional(), domain: z.string().optional(), status: z.string().optional(), price: z.number().optional(), serviceFee: z.number().optional(), availableAfter: z.number().optional(), createdAt: z.number().optional(), updatedAt: z.number().optional()})).optional(), pagination: z.object({total: z.number().optional(), count: z.number().optional(), offset: z.number().optional(), limit: z.number().optional(), hasMore: z.boolean().optional(), nextOffset: z.number().nullable().optional()}).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 user's backorders * * POST /mcp/v1/actions/ud_backorders_list */ export const createApiMcpV1ActionsUdBackordersList = async (args: CreateApiMcpV1ActionsUdBackordersListArgs, options?: CreateApiMcpV1ActionsUdBackordersListOptions) => { 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_backorders_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(createApiMcpV1ActionsUdBackordersListResponse, await res.json()) };