import {z} from 'zod' export type GetApiTrustExchangeContentLibraryDocumentListArgs = {page_size?: number | undefined, page_token?: string | undefined, filter_name?: string | undefined, filter_document_types?: Array | undefined, filter_added_to_any_trust_center?: boolean | undefined, archived?: boolean | undefined}; export type GetApiTrustExchangeContentLibraryDocumentListOptions = {baseUrl?: string | undefined, APIKeyInHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const contentLibraryDocumentVersion = z.object({created_at: z.string().optional(), filename: z.string().optional(), version: z.number().int().optional(), virus_safe: z.boolean().optional()}); export const contentLibraryDocument = z.object({archived: z.boolean().optional(), created_at: z.string().optional(), created_by_email: z.string().optional(), created_by_name: z.string().optional(), description: z.string().optional(), document_type: z.string().optional(), expires_at: z.string().optional(), internal_notes: z.string().optional(), name: z.string().optional(), published_trust_center_uuids: z.array(z.string()).optional(), unpublished_trust_center_uuids: z.array(z.string()).optional(), updated_at: z.string().optional(), updated_by_email: z.string().optional(), updated_by_name: z.string().optional(), usage_count: z.number().int().optional(), uuid: z.string().optional(), versions: z.array(contentLibraryDocumentVersion).optional()}); export const contentLibraryDocumentListResponse = z.object({documents: z.array(contentLibraryDocument).optional(), next_page_token: z.string().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 content library documents * * GET /trust_exchange/content_library/document/list */ export const getApiTrustExchangeContentLibraryDocumentList = async (args: GetApiTrustExchangeContentLibraryDocumentListArgs, options?: GetApiTrustExchangeContentLibraryDocumentListOptions) => { const {baseUrl = "https://cyber-risk.upguard.com/api/public", fetch: fetchFn = fetch, APIKeyInHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (args.filter_name != null) query.append("filter_name", String(args.filter_name)) for (const item of args.filter_document_types ?? []) query.append("filter_document_types", String(item)) if (args.filter_added_to_any_trust_center != null) query.append("filter_added_to_any_trust_center", String(args.filter_added_to_any_trust_center)) if (args.archived != null) query.append("archived", String(args.archived)) if (APIKeyInHeader !== undefined) headers.set("Authorization", APIKeyInHeader) const url = `${baseUrl.replace(/\/+$/, '')}/trust_exchange/content_library/document/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(contentLibraryDocumentListResponse, await res.json()) };