Turso.AuditLogs (turso v0.1.1)

View Source

Audit log retrieval for Turso Cloud Platform.

This module provides functions for accessing audit logs that track all activities and changes within your Turso organization. Audit logs are useful for compliance, security monitoring, and troubleshooting.

Summary

Functions

Lists audit logs for the organization.

Retrieves a specific audit log entry by ID.

Streams all audit logs for the organization.

Types

api_result(success_type)

@type api_result(success_type) :: Turso.api_result(success_type)

audit_log()

@type audit_log() :: %{required(String.t()) => any()}

Functions

list(client, opts \\ [])

@spec list(
  Turso.t(),
  keyword()
) :: api_result(map())

Lists audit logs for the organization.

Returns a paginated list of audit log entries showing all activities within the organization.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

  • :page_size (pos_integer/0) - Number of logs to return per page (max 1000). The default value is 100.

  • :page_token (String.t/0) - Token for pagination to get the next page of results.

  • :order (String.t/0) - Sort order: 'asc' for ascending, 'desc' for descending (default).

  • :start_time (String.t/0) - Start time for log filtering (ISO 8601 format).

  • :end_time (String.t/0) - End time for log filtering (ISO 8601 format).

  • :action (String.t/0) - Filter by specific action type (e.g., 'database.create').

  • :actor_id (String.t/0) - Filter by actor (user) ID who performed the action.

Examples

# Basic audit log listing
{:ok, response} = Turso.AuditLogs.list(client)

# With pagination and filtering
{:ok, response} = Turso.AuditLogs.list(client,
  page_size: 50,
  action: "database.create",
  start_time: "2024-01-01T00:00:00Z"
)

Returns

  • {:ok, map()} - Audit logs response with logs and pagination info
  • {:error, map()} - Error details

Response Format

The response typically contains:

  • audit_logs - Array of audit log entries
  • page_token - Token for next page (if more results available)
  • has_more - Boolean indicating if more results are available

Audit Log Entry

Each audit log entry contains:

  • id - Unique log entry ID
  • timestamp - When the action occurred (ISO 8601)
  • action - The action that was performed
  • actor_id - ID of the user who performed the action
  • actor_email - Email of the user who performed the action
  • resource_type - Type of resource affected (e.g., "database", "group")
  • resource_id - ID of the affected resource
  • details - Additional details about the action
  • ip_address - IP address of the actor
  • user_agent - User agent string of the request

retrieve(client, log_id, opts \\ [])

@spec retrieve(Turso.t(), String.t(), keyword()) :: api_result(audit_log())

Retrieves a specific audit log entry by ID.

Examples

{:ok, log_entry} = Turso.AuditLogs.retrieve(client, "log-123", organization: "my-org")

Parameters

  • client - The Turso client
  • log_id - The audit log entry ID
  • opts - Options including organization override

Returns

  • {:ok, audit_log()} - The audit log entry
  • {:error, map()} - Error details

stream(client, opts \\ [])

@spec stream(
  Turso.t(),
  keyword()
) :: Enumerable.t()

Streams all audit logs for the organization.

This is a convenience function that automatically handles pagination to retrieve all audit logs. It returns a stream that yields individual audit log entries.

Examples

# Stream all audit logs
client
|> Turso.AuditLogs.stream()
|> Enum.take(100)

# Stream with filtering
client
|> Turso.AuditLogs.stream(action: "database.create")
|> Stream.filter(&filter_function/1)
|> Enum.to_list()

Parameters

  • client - The Turso client
  • opts - Same options as list/2, except page_token which is managed automatically

Returns

A Stream that yields individual audit log entries.

Note

This function makes multiple API calls as needed to fetch all pages. Use with care for large audit log datasets to avoid rate limiting.