//native
/**
* List Activities
* List audit log events for one application: admin (Admin console changes), login, drive (file access and sharing), token (third-party app grants), groups, saml, … newest first. Narrow with `user_key` (an email, or `all`), `event_name` (e.g. login_failure, change_user_access), an RFC 3339 time range and `filters` (e.g. `doc_id==abc,visibility==people_with_link`). Returns `items` and `nextPageToken`. Requires admin.reports.audit.readonly on the connection and a Workspace admin with the Reports privilege.
*/
export async function main(
auth: RT.Gworkspace,
application_name:
| "access_transparency"
| "admin"
| "calendar"
| "chat"
| "drive"
| "gcp"
| "gmail"
| "gplus"
| "groups"
| "groups_enterprise"
| "jamboard"
| "login"
| "meet"
| "mobile"
| "rules"
| "saml"
| "token"
| "user_accounts"
| "context_aware_access"
| "chrome"
| "data_studio"
| "keep"
| "vault"
| "gemini_in_workspace_apps"
| "classroom"
| "assignments"
| "cloud_search"
| "tasks"
| "data_migration"
| "meet_hardware"
| "directory_sync"
| "ldap"
| "profile"
| "access_evaluation"
| "admin_data_action"
| "contacts"
| "takeout"
| "graduation"
| "voice"
| "chrome_sync"
| "workspace_studio"
| "gemini_notebook",
user_key: string = "all",
event_name: string | undefined,
start_time: string | undefined,
end_time: string | undefined,
filters: string | undefined,
actor_ip_address: string | undefined,
org_unit_id: string | undefined,
max_results: number = 100,
page_token: string | undefined
) {
const url = new URL(
`https://admin.googleapis.com/admin/reports/v1/activity/users/${encodeURIComponent(user_key || "all")}/applications/${application_name}`
)
for (const [k, v] of Object.entries({
eventName: event_name,
startTime: start_time,
endTime: end_time,
filters,
actorIpAddress: actor_ip_address,
orgUnitID: org_unit_id,
pageToken: page_token,
})) {
if (v != null && v !== "") url.searchParams.append(k, v)
}
url.searchParams.append("maxResults", String(max_results))
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago