import {z} from 'zod' export type ModelDependency = {name: string, source?: string | undefined, format?: (string | null) | undefined, required?: boolean | undefined}; export type PublishExtractorRequest = {public_name?: (string | null) | undefined, display_name?: (string | null) | undefined, description?: (string | null) | undefined, icon_base64?: (string | null) | undefined, readme_markdown?: (string | null) | undefined, tags?: Array | undefined, category?: (string | null) | undefined, model_dependencies?: Array | undefined}; export type CreateApiV1ExtractorsExtractorIdPublishArgs = {extractor_id: string, body: PublishExtractorRequest}; export type CreateApiV1ExtractorsExtractorIdPublishOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publishExtractorResponse = z.object({public_id: z.string(), extractor_id: z.string(), public_name: z.string(), public_url: z.string()}); 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 }; /** * Publish an extractor to the marketplace * * POST /v1/extractors/{extractor_id}/publish */ export const createApiV1ExtractorsExtractorIdPublish = async (args: CreateApiV1ExtractorsExtractorIdPublishArgs, options?: CreateApiV1ExtractorsExtractorIdPublishOptions) => { const {baseUrl = "https://api.mixpeek.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(/\/+$/, '')}/v1/extractors/${encodeURIComponent(String(args.extractor_id))}/publish${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(publishExtractorResponse, await res.json()) };