import {z} from 'zod' export type UpdateApiApiV1ProjectsProjectIdSourcesSourceIdArgs = {projectId: number, sourceId: number, body: {executive_js?: boolean | undefined, data_refresh_frequency?: ('never' | 'daily' | 'weekly' | 'monthly' | 'advanced') | undefined, create_new_pages?: boolean | undefined, remove_unexist_pages?: boolean | undefined, refresh_existing_pages?: ('never' | 'always' | 'if_updated') | undefined, refresh_schedule?: ({days?: Array | undefined, hours?: Array | undefined}) | undefined, advanced_refresh_schedule?: ({version?: number | undefined, times_by_day?: Record | undefined}) | undefined, allow_extra_timeout?: boolean | undefined, image_extraction_type?: ('none' | 'sync_from_sitemap' | 'extract_opengraph_images') | undefined, update_existing_images?: boolean | undefined, sync_all_images?: boolean | undefined}}; export type UpdateApiApiV1ProjectsProjectIdSourcesSourceIdOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({id: z.number().int().optional(), page_url: z.string().optional(), page_url_hash: z.string().optional(), project_id: z.number().int().optional(), s3_path: z.string().nullable().optional(), crawl_status: z.enum(["ok", "queued", "failed", "n/a", "limited"]).optional(), index_status: z.enum(["ok", "queued", "failed", "n/a", "limited"]).optional(), is_file: z.boolean().optional(), is_refreshable: z.boolean().optional(), is_file_kept: z.boolean().optional(), filename: z.string().nullable().optional(), filesize: z.number().int().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional()}); export const projectSource = z.object({id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), type: z.enum(["sitemap", "web-images", "upload"]).optional(), sub_type: z.enum(["readme", "gitbook", "document360", "knowledgeowl", "wordpress", "wix", "webflow", "framer", "squarespace", "weebly", "ghost", "shopify", "magento", "bigcommerce", "woocommerce", "hubspot", "url-list", "rss", "podcast", "web-search", "extra_timeout", "low_performance", "archive", "images-sitemap", "images-opengraph", "zendesk_articles", "zendesk_tickets", "freshdesk_tickets"]).nullable().optional(), settings: z.object({executive_js: z.boolean().optional(), data_refresh_frequency: z.enum(["never", "daily", "weekly", "monthly", "advanced"]).optional(), create_new_pages: z.boolean().optional(), remove_unexist_pages: z.boolean().optional(), refresh_existing_pages: z.enum(["never", "always", "if_updated"]).optional(), sitemap_path: z.string().optional(), image_extraction_type: z.enum(["none", "sync_from_sitemap", "extract_opengraph_images"]).optional(), update_existing_images: z.boolean().optional(), sync_all_images: z.boolean().optional()}).optional(), pages: z.array(page).nullable().optional()}); export const updateApiApiV1ProjectsProjectIdSourcesSourceIdResponse = z.object({status: z.enum(["error", "success"]).optional(), data: projectSource.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 }; /** * Update source settings. * * PUT /api/v1/projects/{projectId}/sources/{sourceId} */ export const updateApiApiV1ProjectsProjectIdSourcesSourceId = async (args: UpdateApiApiV1ProjectsProjectIdSourcesSourceIdArgs, options?: UpdateApiApiV1ProjectsProjectIdSourcesSourceIdOptions) => { const {baseUrl = "https://app.customgpt.ai", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectId))}/sources/${encodeURIComponent(String(args.sourceId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV1ProjectsProjectIdSourcesSourceIdResponse, await res.json()) };