import {z} from 'zod' export type CreateApiProductsHelpDeskKnowledgeBaseDisableArgs = {body: {version: number}}; export type CreateApiProductsHelpDeskKnowledgeBaseDisableOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const knowledgeBaseSourceSummary = z.object({external_id: z.string().max(200), source_hash: z.string().max(128)}); export const knowledgeBaseCategorySummary = z.object({name: z.string().max(160), slug: z.string().max(80), description: z.string().max(1000), parent_id: z.string().nullable(), position: z.number().int().gte(0).lte(1000000), source: knowledgeBaseSourceSummary.nullable(), path: z.string().max(512).nullable(), category_id: z.string(), version: z.number().int().gte(0), source_version: z.number().int().gte(1).nullable()}); export const knowledgeBaseArticleSummary = z.object({article_id: z.string(), title: z.string().max(160), slug: z.string().max(80), category_id: z.string().nullable(), position: z.number().int().gte(0).lte(1000000), version: z.number().int().gte(0), current_revision_id: z.string(), published_revision_id: z.string().nullable(), has_unpublished_changes: z.boolean(), source_revision_id: z.string().nullable(), created_at: z.number().int().gte(0), updated_at: z.number().int().gte(0), archived: z.boolean(), source: knowledgeBaseSourceSummary.nullable()}); export const knowledgeBaseWorkspace = z.object({desk_id: z.string(), version: z.number().int().gte(0), public_url: z.string(), settings: z.object({title: z.string().max(160).optional(), description: z.string().max(1000).optional(), theme: z.enum(["default", "privacybee"]).optional(), branding_credit: z.boolean().optional(), accent_color: z.string().optional(), logo_asset_id: z.string().nullable().optional(), seo_title: z.string().max(160).nullable().optional(), seo_description: z.string().max(500).nullable().optional(), redirects: z.array(z.object({from: z.string(), to: z.string(), status: z.literal(301).optional()})).optional(), enabled: z.boolean().optional()}), publication: z.object({state: z.enum(["idle", "publishing", "failed"]).optional(), operation_id: z.string().nullable().optional(), job_id: z.string().nullable().optional(), active_release_id: z.string().nullable().optional(), published_at: z.number().int().nullable().optional(), error: z.string().nullable().optional(), lifecycle_paused: z.boolean().optional()}), categories: z.array(knowledgeBaseCategorySummary), articles: z.array(knowledgeBaseArticleSummary)}); export const responseMeta = z.object({api_version: z.string().optional(), request_id: z.string().optional(), response_ms: z.number().int().optional(), timestamp: z.number().int().optional(), pools: z.object({}).optional(), billing: z.object({past_due: z.boolean().optional()}).optional(), quota: z.object({limit: z.number().int().optional(), used: z.number().int().optional(), remaining: z.number().int().optional(), resets_at: z.number().int().optional()}).optional()}); export const createApiProductsHelpDeskKnowledgeBaseDisableResponse = z.object({data: knowledgeBaseWorkspace, meta: responseMeta.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 }; /** * Disable the public knowledge base * * POST /products/help-desk/knowledge-base/disable */ export const createApiProductsHelpDeskKnowledgeBaseDisable = async (args: CreateApiProductsHelpDeskKnowledgeBaseDisableArgs, options?: CreateApiProductsHelpDeskKnowledgeBaseDisableOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", 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(/\/+$/, '')}/products/help-desk/knowledge-base/disable${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(createApiProductsHelpDeskKnowledgeBaseDisableResponse, await res.json()) };