import {z} from 'zod' export type GetApiApiRegistryServiceNameDiscoverArgs = {name: string, create?: boolean | undefined}; export type GetApiApiRegistryServiceNameDiscoverOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const schema = z.object({defaultValue: z.object({}).optional(), format: z.string().optional(), type: z.string().optional()}); export const requestParam = z.object({name: z.string().optional(), required: z.boolean().optional(), schema: schema.optional(), type: z.string().optional()}); export const serviceMethod = z.object({deprecated: z.boolean().optional(), description: z.string().optional(), exampleInput: z.record(z.string(), z.object({})).optional(), id: z.number().int().optional(), inputType: z.string().optional(), methodName: z.string().optional(), methodType: z.string().optional(), operationName: z.string().optional(), outputType: z.string().optional(), requestContentType: z.string().optional(), requestParams: z.array(requestParam).optional(), responseContentType: z.string().optional()}); export const getApiApiRegistryServiceNameDiscoverResponse = z.array(serviceMethod); 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 /api/registry/service/{name}/discover */ export const getApiApiRegistryServiceNameDiscover = async (args: GetApiApiRegistryServiceNameDiscoverArgs, options?: GetApiApiRegistryServiceNameDiscoverOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.create != null) query.append("create", String(args.create)) if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/registry/service/${encodeURIComponent(String(args.name))}/discover${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiRegistryServiceNameDiscoverResponse, await res.json()) };