import {z} from 'zod' export type GetApiApiKnowledgeListArgs = {parentId?: string | undefined, aptletUuid?: string | undefined, aptletInstanceId?: string | undefined, streamId?: string | undefined, search?: string | undefined, archived?: boolean | undefined, ownerId?: string | undefined, updatedById?: string | undefined, createdFrom?: string | undefined, createdTo?: string | undefined, updatedFrom?: string | undefined, updatedTo?: string | undefined, unlinked?: boolean | undefined, limit?: number | undefined, skip?: number | undefined}; export type GetApiApiKnowledgeListOptions = {baseUrl?: string | undefined, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const knowledgeDocSummary = z.object({_id: z.string().optional(), name: z.string().optional(), emoji: z.string().nullable().optional(), iconUrl: z.string().nullable().optional(), accessType: z.enum(["public", "publicReadonly", "private"]).optional(), parentId: z.string().nullable().optional(), rank: z.number().int().nullable().optional(), archived: z.boolean().optional()}); export const getApiApiKnowledgeListResponse = z.object({docs: z.array(knowledgeDocSummary).optional(), total: z.number().int().optional(), limit: z.number().int().optional(), skip: z.number().int().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 }; /** * List knowledge documents * * GET /api/knowledge/list * * Also accepts auth: DelegateToken, PartnerBearer */ export const getApiApiKnowledgeList = async (args: GetApiApiKnowledgeListArgs, options?: GetApiApiKnowledgeListOptions) => { const {baseUrl = "https://core-api.getaptly.com", fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.parentId != null) query.append("parentId", String(args.parentId)) if (args.aptletUuid != null) query.append("aptletUuid", String(args.aptletUuid)) if (args.aptletInstanceId != null) query.append("aptletInstanceId", String(args.aptletInstanceId)) if (args.streamId != null) query.append("streamId", String(args.streamId)) if (args.search != null) query.append("search", String(args.search)) if (args.archived != null) query.append("archived", String(args.archived)) if (args.ownerId != null) query.append("ownerId", String(args.ownerId)) if (args.updatedById != null) query.append("updatedById", String(args.updatedById)) if (args.createdFrom != null) query.append("createdFrom", String(args.createdFrom)) if (args.createdTo != null) query.append("createdTo", String(args.createdTo)) if (args.updatedFrom != null) query.append("updatedFrom", String(args.updatedFrom)) if (args.updatedTo != null) query.append("updatedTo", String(args.updatedTo)) if (args.unlinked != null) query.append("unlinked", String(args.unlinked)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (ApiKeyHeader !== undefined) headers.set("x-token", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/knowledge/list${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(getApiApiKnowledgeListResponse, await res.json()) };