import {z} from 'zod' export type AuditLogFilterRequest = {start: string, end: string, eventTypes?: (Array<'USER_LOGGED_IN' | 'USER_LOGGED_OUT' | 'EXISTING_USER_FIRST_LOG_IN' | 'NEW_USER_FIRST_LOG_IN' | 'USER_UPLOADED_ARTIFACT' | 'USER_DOWNLOADED_ARTIFACT' | 'USER_EXPORTED_ARTIFACT' | 'USER_CREATED' | 'USER_UPDATED' | 'USER_SUBSCRIBED' | 'USER_UNSUBSCRIBED' | 'USER_DEFAULT_SUBSCRIBER_ADDED' | 'USER_DEFAULT_SUBSCRIBER_REMOVED' | 'ORG_CREATED' | 'ORG_UPDATED' | 'ORG_FIRST_LOGIN' | 'ORG_OFFBOARD_IN_PROGRESS' | 'ORG_OFFBOARD_SUCCESS' | 'ORG_OFFBOARD_FAILED' | 'ORG_SUBDOMAIN_SET' | 'ORG_ASSESSMENT_DEFAULTS_CREATED' | 'ORG_ASSESSMENT_DEFAULTS_UPDATED' | 'ASSESSMENT_CREATED' | 'ASSESSMENT_UPDATED' | 'ASSESSMENT_COMPLETED' | 'ASSESSMENT_CANCELLED' | 'ASSESSMENT_EXPIRED' | 'ASSESSMENT_AUDIT_COMPLETED' | 'ASSESSMENT_STATUS_CHANGED' | 'RELATIONSHIP_CREATED' | 'RELATIONSHIP_ARCHIVED' | 'RELATIONSHIP_ONBOARDED' | 'RELATIONSHIP_UPDATED' | 'RISK_ACCEPTED' | 'RISK_ACCEPTANCE_REVOKED' | 'PRIMARY_CONTACT_CHANGED'>) | undefined}; export type CreateApiApiV1AuditLogEventsArgs = {body: AuditLogFilterRequest}; export type CreateApiApiV1AuditLogEventsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const auditEventType = z.object({name: z.string().optional()}); export const auditEvent = z.object({auditEventType: auditEventType.optional(), dateTime: z.string().optional()}); export const createApiApiV1AuditLogEventsResponse = z.array(auditEvent); 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 filtered audit log events based on specific types and categories for your organization, limited to 500 records * * POST /api/v1/audit-log/events */ export const createApiApiV1AuditLogEvents = async (args: CreateApiApiV1AuditLogEventsArgs, options?: CreateApiApiV1AuditLogEventsOptions) => { const {baseUrl = "https://app.visotrust.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/audit-log/events${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AuditLogEventsResponse, await res.json()) };