import {z} from 'zod' export type GetApiAnalyzeV1AgreementsArgs = {type?: string | undefined, tags?: string | undefined, after_date?: string | undefined, sort_by?: string | undefined, cursor?: string | undefined, tags_delimiter?: string | undefined, page_size?: string | undefined}; export type GetApiAnalyzeV1AgreementsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAnalyzeV1AgreementsResponse = z.object({page_size: z.number().int(), count: z.number().int(), next_cursor: z.string().nullable(), agreements: z.array(z.object({id: z.string().optional(), parent_agreement_id: z.string().nullable().optional(), finalize_agreement_id: z.string().nullable().optional(), name: z.string().optional(), original_name: z.string().optional(), updated_date: z.string().optional(), upload_date: z.string().optional(), uploaded_by: z.string().optional(), type: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), tags: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).nullable().optional(), child_agreements: z.array(z.object({id: z.string().optional()})).nullable().optional(), terms: z.array(z.object({id: z.string().optional(), name: z.string().optional(), value: z.string().nullable().optional(), kind: z.string().optional(), status: z.string().optional()})).nullable().optional()})).nullable()}); 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 Agreements * * GET /analyze/v1/agreements */ export const getApiAnalyzeV1Agreements = async (args: GetApiAnalyzeV1AgreementsArgs, options?: GetApiAnalyzeV1AgreementsOptions) => { const {baseUrl = "https://api.linksquares.com/api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.after_date != null) query.append("after_date", String(args.after_date)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.tags_delimiter != null) query.append("tags_delimiter", String(args.tags_delimiter)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/analyze/v1/agreements${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(getApiAnalyzeV1AgreementsResponse, await res.json()) };