import {z} from 'zod' export type GetApiIntegrationsSharepointSitesArgs = {chat_id?: (number | null) | undefined, library_id?: (number | null) | undefined, assistant_id?: (number | null) | undefined, project_id?: (number | null) | undefined, cookie_name?: (string | null) | undefined}; export type GetApiIntegrationsSharepointSitesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const sharepointSiteModel = z.object({id: z.string(), web_url: z.string(), name: z.string().nullable(), display_name: z.string().nullable(), description: z.string().nullable(), imported_count: z.number().int().optional()}); export const getApiIntegrationsSharepointSitesResponse = z.array(sharepointSiteModel); 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 SharePoint sites * * GET /integrations/sharepoint/sites */ export const getApiIntegrationsSharepointSites = async (args: GetApiIntegrationsSharepointSitesArgs, options?: GetApiIntegrationsSharepointSitesOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.chat_id != null) query.append("chat_id", String(args.chat_id)) if (args.library_id != null) query.append("library_id", String(args.library_id)) if (args.assistant_id != null) query.append("assistant_id", String(args.assistant_id)) if (args.project_id != null) query.append("project_id", String(args.project_id)) if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/integrations/sharepoint/sites${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(getApiIntegrationsSharepointSitesResponse, await res.json()) };