import {z} from 'zod' export type Cursor = {cursor?: string | undefined}; export type DateTimeRFC3339 = string; export type ResetCursor = {limit?: number | undefined, start_time?: DateTimeRFC3339 | undefined, end_time?: DateTimeRFC3339 | undefined}; export type CreateApiApiV1AuditeventsArgs = {body: Cursor | ResetCursor}; export type CreateApiApiV1AuditeventsOptions = {baseUrl?: string | undefined, jwtsa?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const dateTimeRFC3339 = z.string(); export const user = z.object({uuid: uUID.optional(), name: z.string().optional(), email: z.string().optional()}); export const auditEventActions = z.enum(["activate", "update", "delete", "convert", "enblduo", "updatduo", "disblduo", "rdmchild", "detchild", "dlgsess", "create", "deolddev", "dealldev", "reauth", "begin", "complete", "propose", "updatfw", "join", "leave", "role", "purge", "view", "export", "replace", "grant", "revoke", "share", "delshare", "uisas", "enblmfa", "updatmfa", "disblmfa", "musercom", "muserdec", "sendpkg", "resendts", "prsndall", "trename", "tverify", "trevoke", "ssotknv", "enblsso", "disblsso", "chngpsso", "chngasso", "chngdsso", "delgsso", "addgsso", "cancel", "hide", "unhide", "upguest", "verify", "reactive", "suspend", "beginr", "provsn", "sendts", "unknown", "completr", "cancelr", "trvlaway", "trvlback", "changeks", "changemp", "changesk", "changenm", "changela", "tdvcsso", "sdvcsso", "patch", "updatea", "vrfydmn", "uvrfydmn", "dvrfydmn"]); export const auditEventObjectTypes = z.enum(["account", "user", "device", "group", "gm", "vault", "item", "items", "itemhist", "vaultkey", "template", "uva", "gva", "invite", "ec", "miguser", "sso", "sub", "card", "pm", "slackapp", "file", "famchild", "sa", "satoken", "dlgdsess", "ssotkn", "report"]); export const session = z.object({uuid: uUID.optional(), login_time: dateTimeRFC3339.optional(), device_uuid: uUID.optional(), ip: z.string().optional()}); export const location = z.object({country: z.string().optional(), region: z.string().optional(), city: z.string().optional(), longitude: z.number().optional(), latitude: z.number().optional()}); export const auditEvent = z.object({uuid: uUID.optional(), timestamp: dateTimeRFC3339.optional(), actor_uuid: uUID.optional(), actor_details: user.optional(), action: auditEventActions.optional(), object_type: auditEventObjectTypes.optional(), object_uuid: uUID.optional(), object_details: user.optional(), aux_id: z.number().int().optional(), aux_uuid: uUID.optional(), aux_details: user.optional(), aux_info: z.string().optional(), session: session.optional(), location: location.optional()}); export const auditEventItems = z.object({items: z.array(auditEvent).optional(), cursor: z.string().optional(), has_more: z.boolean().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 }; /** * Retrieves audit events for actions performed by team members within a 1Password account * * POST /api/v1/auditevents */ export const createApiApiV1Auditevents = async (args: CreateApiApiV1AuditeventsArgs, options?: CreateApiApiV1AuditeventsOptions) => { const {baseUrl = "https://events.1password.com", fetch: fetchFn = fetch, jwtsa} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (jwtsa !== undefined) headers.set('authorization', `Bearer ${jwtsa}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/auditevents${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(auditEventItems, await res.json()) };