import {z} from 'zod' export type GetApiApiV1RelationshipIdAssessmentsArgs = {id: number}; export type GetApiApiV1RelationshipIdAssessmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const assessmentRecommendation = z.object({description: z.string().optional(), createdDate: z.string().optional(), recommendationType: z.enum(["EXPIRED", "HIGH_ASSURANCE", "CONTROL_DOMAINS", "COMBINED", "CERT_ONLY", "LOW_COVERAGE", "PRESUMED_ARTIFACT"]).optional()}); export const assessmentStatusHistory = z.object({date: z.string().optional(), status: z.enum(["NOT_ASSESSED", "AWAITING_REMEDIATION", "STARTED", "REVIEW_STARTED", "AUDIT_COMPLETED", "COMPLETED", "CANCELLED", "DELETED", "COLLECTING_INFORMATION", "EXPIRED"]).optional()}); export const visoUser = z.object({firstName: z.string().optional(), lastName: z.string().optional(), email: z.string().optional(), businessUnit: z.string().optional()}); export const assessment = z.object({id: z.number().int().optional(), recommendations: z.array(assessmentRecommendation).optional(), status: z.enum(["NOT_ASSESSED", "AWAITING_REMEDIATION", "STARTED", "REVIEW_STARTED", "AUDIT_COMPLETED", "COMPLETED", "CANCELLED", "DELETED", "COLLECTING_INFORMATION", "EXPIRED"]).optional(), assessmentType: z.string().optional(), statusHistories: z.array(assessmentStatusHistory).optional(), sentToFirstName: z.string().optional(), sentToLastName: z.string().optional(), createdReason: z.enum(["INITIAL_ASSESSMENT", "ARTIFACTS_EXPIRED", "RECERTIFICATION_INITIATED", "BUSINESS_CASE_OR_DATA_TYPES_CHANGED", "THIRD_PARTY_CONTACT_UPDATED", "ARTIFACTS_UPLOADED_ON_RELATIONSHIP", "REMEDIATION", "RISK_ADVISORY_RESPONSE", "INSTANT_ANALYSIS", "PUBLIC_SEARCH"]).optional(), sentToEmail: z.string().optional(), createdDate: z.string().optional(), summary: z.string().optional(), expirationDate: z.string().optional(), completedDate: z.string().optional(), requestedAuditTypes: z.array(z.string()).optional(), aiProcessingOnly: z.boolean().optional(), noVendorResponseAction: z.enum(["CLOSE_COLLECTION_REQUEST", "NOTIFY_ME"]).optional(), collectionTimeline: z.enum(["SEVEN_DAYS", "FOURTEEN_DAYS", "THIRTY_DAYS", "SIXTY_DAYS", "NINETY_DAYS", "ONE_HUNDRED_TWENTY_DAYS"]).optional(), followupTimeline: z.enum(["SEVEN_DAYS", "FOURTEEN_DAYS", "THIRTY_DAYS", "SIXTY_DAYS", "NINETY_DAYS"]).optional(), followupRiskThreshold: z.enum(["NO_CONTEXT", "LOW", "MEDIUM", "HIGH", "EXTREME"]).optional(), followupType: z.enum(["MANUAL", "AUTOMATIC", "CONCIERGE"]).optional(), sentBy: visoUser.optional(), updatedDate: z.string().optional(), phaseDate: z.string().optional(), requestedArtifactCollection: z.boolean().optional()}); export const getApiApiV1RelationshipIdAssessmentsResponse = z.array(assessment); 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 assessment history for a relationship * * GET /api/v1/relationship/{id}/assessments */ export const getApiApiV1RelationshipIdAssessments = async (args: GetApiApiV1RelationshipIdAssessmentsArgs, options?: GetApiApiV1RelationshipIdAssessmentsOptions) => { const {baseUrl = "https://app.visotrust.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/relationship/${encodeURIComponent(String(args.id))}/assessments${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(getApiApiV1RelationshipIdAssessmentsResponse, await res.json()) };