import type { Selectable } from 'kysely'
import * as Id from '../../internal/Id.js'
import type * as Db from '../Db.js'
import type * as db_Schema from '../Schema.js'
/** Columns of the `admin_audit_logs` table. */
export type Table = db_Schema.AdminAuditLog
/** One stored administrator access event. */
export type Record = Selectable
/** Records an authenticated access to a protected admin API route. */
export function insert(db: Db.Db, input: insert.Input): Promise {
return db.kysely
.insertInto('admin_audit_logs')
.values({
actor: input.actor,
createdAt: new Date().toISOString(),
id: Id.generate('aud'),
method: input.method,
path: input.path,
query: input.query ?? null,
requestId: input.requestId,
status: input.status,
})
.returningAll()
.executeTakeFirstOrThrow()
}
export declare namespace insert {
/** Fields captured for one administrator access. */
type Input = {
/** Verified administrator email. */
actor: string
/** HTTP method used for the access. */
method: string
/** Admin API path accessed, without query parameters. */
path: string
/** Query string used for the lookup. */
query?: string | undefined
/** Request id correlating the access with request logs. */
requestId: string
/** HTTP response status returned to the administrator. */
status: number
}
}