import {z} from 'zod' export type CreateApiMcpV1ActionsUdCartGetArgs = {body: {discountCode?: string | undefined}}; export type CreateApiMcpV1ActionsUdCartGetOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cartItem = z.object({productId: z.number().optional(), productCode: z.string().optional(), productType: z.string().optional(), domain: z.string().nullable().optional(), originalPrice: z.number().optional(), originalPriceFormatted: z.string().optional(), discountAmount: z.number().optional(), discountAmountFormatted: z.string().optional(), promoCreditsApplied: z.number().optional(), accountBalanceApplied: z.number().optional(), salesTax: z.number().optional(), fees: z.array(z.object({})).optional()}); export const cartResponse = z.object({items: z.array(cartItem).optional(), itemCount: z.number().optional(), pricing: z.object({totalOrderValue: z.number().optional(), totalOrderValueFormatted: z.string().optional(), preTaxAmountDue: z.number().optional(), preTaxAmountDueFormatted: z.string().optional(), salesTax: z.number().optional(), salesTaxFormatted: z.string().optional(), taxRate: z.number().optional(), promoCreditsUsed: z.number().optional(), promoCreditsUsedFormatted: z.string().optional(), storeCreditsUsed: z.number().optional(), storeCreditsUsedFormatted: z.string().optional(), accountBalanceUsed: z.number().optional(), accountBalanceUsedFormatted: z.string().optional(), totalAmountDue: z.number().optional(), totalAmountDueFormatted: z.string().optional()}).optional(), discounts: z.array(z.object({amount: z.number().optional(), amountFormatted: z.string().optional(), type: z.string().optional(), title: z.string().optional(), code: z.string().nullable().optional(), productIds: z.array(z.number()).optional()})).optional(), totalDiscounts: z.number().optional(), totalDiscountsFormatted: 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 }; /** * Get shopping cart with pricing * * POST /mcp/v1/actions/ud_cart_get */ export const createApiMcpV1ActionsUdCartGet = async (args: CreateApiMcpV1ActionsUdCartGetArgs, options?: CreateApiMcpV1ActionsUdCartGetOptions) => { 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_cart_get${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(cartResponse, await res.json()) };