import {z} from 'zod' export type AuditLogsQueryRequest = {workspaceId?: (string | null) | undefined, organizationId?: (string | null) | undefined, startDate?: (number | null) | undefined, endDate?: (number | null) | undefined, actions?: (Array | null) | undefined, actorIds?: (Array | null) | undefined, targetId?: (string | null) | undefined, cursor?: (string | null) | undefined, limit?: number | undefined}; export type CreateApiV2AuditLogsEventsSearchArgs = {body: AuditLogsQueryRequest}; export type CreateApiV2AuditLogsEventsSearchOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const actorType = z.enum(["user", "system", "service"]); export const actor = z.object({type: actorType, id: z.string(), name: z.string().nullable().optional(), email: z.string().nullable().optional()}); export const targetType = z.enum(["workspace", "video", "user", "organization", "asset"]); export const target = z.object({type: targetType, id: z.string(), name: z.string().nullable().optional()}); export const context = z.object({workspaceId: z.string().nullable().optional(), organizationId: z.string().nullable().optional(), ipAddress: z.string().nullable().optional()}); export const metadata = z.object({createdAt: z.string(), processedAt: z.string().nullable().optional()}); export const auditLogEvent = z.object({id: z.string(), action: z.string(), status: z.string(), actor: actor, target: target, context: context, details: z.object({}), metadata: metadata}); export const auditLogsPageResponse = z.object({events: z.array(auditLogEvent), nextCursor: z.string().nullable().optional(), hasMore: z.boolean()}); 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 }; /** * Search audit log events (Advanced) * * POST /v2/auditLogs/events/search */ export const createApiV2AuditLogsEventsSearch = async (args: CreateApiV2AuditLogsEventsSearchArgs, options?: CreateApiV2AuditLogsEventsSearchOptions) => { const {baseUrl = "https://api.synthesia.io", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/auditLogs/events/search${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(auditLogsPageResponse, await res.json()) };