import {z} from 'zod' export type GetApiAnalyzeV1AgreementsIdArgs = {id: string}; export type GetApiAnalyzeV1AgreementsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAnalyzeV1AgreementsIdResponse = z.object({id: z.string(), original_name: z.string(), name: z.string(), type: z.object({id: z.string(), name: z.string()}), terms: z.array(z.object({value: z.string().optional(), name: z.string().optional(), status: z.string().optional(), kind: z.string().optional()})), tags: z.array(z.object({name: z.string().optional()})), uploaded_by: z.string(), upload_date: z.string(), updated_date: z.string(), parent_agreement_id: z.string(), finalize_agreement_id: z.string(), child_agreements: z.array(z.object({id: 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 }; /** * Get Agreement * * GET /analyze/v1/agreements/{id} */ export const getApiAnalyzeV1AgreementsId = async (args: GetApiAnalyzeV1AgreementsIdArgs, options?: GetApiAnalyzeV1AgreementsIdOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/analyze/v1/agreements/${encodeURIComponent(String(args.id))}${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(getApiAnalyzeV1AgreementsIdResponse, await res.json()) };