import {z} from 'zod' export type McpBootstrapDto = {authApiKey?: string | undefined, authHeaderName?: string | undefined, description?: string | undefined, imageUrl?: string | undefined, mcpDomain?: string | undefined, metadata?: {[key: string]: unknown} | undefined, name?: string | undefined, originUrl: string, plans?: (Array<{currency?: string | undefined, features?: {[key: string]: unknown} | undefined, key: string, name: string, options: Array<{amountMinor: number, currency: string, kind: 'charge', label?: string | undefined, meter?: string | undefined, oneTime?: boolean | undefined, per: 'unit' | 'seat' | 'flat'} | {anchor?: string | undefined, count?: number | undefined, interval: 'week' | 'month' | 'year', kind: 'billingCycle'} | {charge: {amountMinor: number, currency: string, label?: string | undefined, meter?: string | undefined, per: 'unit' | 'seat' | 'flat'}, from: number, kind: 'tier', label?: string | undefined, mode: 'graduated' | 'volume', to: number | null} | {cap: number, kind: 'limit', label?: string | undefined, meter: string, onExceed: 'block' | 'draw_credits', scope: 'billing_period' | 'lifetime' | 'rolling_window', windowDays?: number | undefined} | {feature: string, kind: 'entitlement', label?: string | undefined, scope?: string | undefined, value: boolean | number | string} | {days: number, kind: 'trial', label?: string | undefined, onEnd: 'convert' | 'cancel'} | {appliesTo?: ('recurring' | 'setup' | 'usage' | 'all') | undefined, currency?: string | undefined, cycles?: number | undefined, duration: 'once' | 'repeating' | 'forever', kind: 'discount', label?: string | undefined, mode: 'percentage' | 'fixed', value: number} | {kind: 'autoAssigned', label?: string | undefined} | {kind: 'hidden', label?: string | undefined}>}>) | undefined, productType?: string | undefined, tools?: (Array<{description?: string | undefined, name: string, noPlan?: boolean | undefined, planKeys?: Array | undefined}>) | undefined}; export type CreateApiV1SdkProductsMcpBootstrapArgs = {body: McpBootstrapDto}; export type CreateApiV1SdkProductsMcpBootstrapOptions = {baseUrl?: string | undefined, SecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const productConfigDto = z.object({deliveryMethod: z.string().optional(), fulfillmentType: z.string().optional(), validityPeriod: z.number().optional()}); export const sdkPlanResponse = z.object({createdAt: z.string(), currency: z.string(), currencySymbol: z.string().optional(), description: z.string().optional(), features: z.record(z.string(), z.unknown()).optional(), isActive: z.boolean(), name: z.string().optional(), options: z.array(z.record(z.string(), z.unknown())), price: z.number().optional(), reference: z.string(), requiresPayment: z.boolean(), status: z.string(), type: z.enum(["recurring", "one-time", "usage-based", "hybrid"]), updatedAt: z.string()}); export const sdkProductResponse = z.object({balance: z.number(), config: productConfigDto.optional(), createdAt: z.string(), description: z.string().optional(), imageUrl: z.string().optional(), isManagedMcp: z.boolean(), isMcpPay: z.boolean(), mcp: z.record(z.string(), z.unknown()).optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string(), plans: z.array(sdkPlanResponse).optional(), productType: z.string().optional(), reference: z.string(), status: z.string(), totalTransactions: z.number(), updatedAt: z.string()}); export const mcpBootstrapResult = z.object({autoMappedTools: z.array(z.object({description: z.string().optional(), name: z.string().optional()})).optional(), mcpServer: z.record(z.string(), z.unknown()), planMap: z.record(z.string(), z.unknown()), product: sdkProductResponse, toolsAutoMapped: z.boolean().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 }; /** * Bootstrap MCP product integration * * POST /v1/sdk/products/mcp/bootstrap */ export const createApiV1SdkProductsMcpBootstrap = async (args: CreateApiV1SdkProductsMcpBootstrapArgs, options?: CreateApiV1SdkProductsMcpBootstrapOptions) => { const {baseUrl = "https://api.solvapay.com", fetch: fetchFn = fetch, SecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SecretKey !== undefined) headers.set('authorization', `Bearer ${SecretKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/sdk/products/mcp/bootstrap${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(mcpBootstrapResult, await res.json()) };