Skip to main content

Audit | Node.js SDK

The audit API is designed for recording a trail of application-based user activity in a scalable, tamper-proof log.

Audit

constructor(token: PangeaToken, config: PangeaConfig, tenantID: string, configID: string): AuditService

Creates a new AuditService with the given Pangea API token and configuration.

PangeaToken

Pangea API token.

Configuration.

string
string

AuditService
const config = new PangeaConfig({ domain: "pangea_domain" });
const audit = new AuditService("pangea_token", config);

Download search results

downloadResults(request: DownloadRequest): Promise<PangeaResponse<DownloadResult>>

Get all search results as a compressed (gzip) CSV file.

DownloadRequest

Request parameters.

Promise<PangeaResponse<DownloadResult>>
const response = await audit.downloadResults({
  result_id: "pas_[...]",
  format: Audit.DownloadFormat.CSV,
});

Export from the audit log

export(request: ExportRequest): Promise<PangeaResponse<{}>>

Bulk export of data from the Secure Audit Log, with optional filtering.

ExportRequest

Request parameters.

Promise<PangeaResponse<{}>>
const exportRes = await audit.export({ verbose: false });

// Export may take several dozens of minutes, so polling for the result
// should be done in a loop. That is omitted here for brevity's sake.
try {
  await audit.pollResult(exportRes.request_id);
} catch (error) {
  if (error instanceof PangeaErrors.AcceptedRequestException) {
    // Retry later.
  }
}

// Download the result when it's ready.
const downloadRes = await audit.downloadResults({ request_id: exportRes.request_id });
downloadRes.result.dest_url;
// => https://pangea-runtime.s3.amazonaws.com/audit/xxxxx/search_results_[...]

Log an entry

log(event: Event, options: LogOptions): Promise<PangeaResponse<LogResponse>>

Create a log entry in the Secure Audit Log.

Event

A structured event describing an auditable activity. Supported fields are:

  • actor (string): Record who performed the auditable activity.
  • action (string): The auditable action that occurred.
  • status (string): Record whether or not the activity was successful.
  • source (string): Used to record the location from where an activity occurred.
  • target (string): Used to record the specific record that was targeted by the auditable activity.
  • message (string|object): A message describing a detailed account of what happened. This can be recorded as free-form text or as a JSON-formatted string.
  • new (string|object): The value of a record after it was changed.
  • old (string|object): The value of a record before it was changed.
  • tenant_id (string): Used to record the tenant associated with this activity.
LogOptions

Log options. The following log options are supported:

  • verbose (bool): Return a verbose response, including the canonical event hash and received_at time.

Promise<PangeaResponse<LogResponse>>
const auditData = {
  action: "add_employee",
  actor: user,
  target: data.email,
  status: "error",
  message: `Resume denied - sanctioned country from ${clientIp}`,
  source: "web",
};
const options = { verbose: true };

const response = await audit.log(auditData, options);

Log multiple entries

logBulk(events: Event[], options: LogOptions): Promise<PangeaResponse<LogBulkResponse>>

Create multiple log entries in the Secure Audit Log.

Array<Event>
LogOptions

Promise<PangeaResponse<LogBulkResponse>>
const events = [
 { message: "hello world" },
];
const options = { verbose: true };

const response = await audit.logBulk(events, options);

Log multiple entries asynchronously

logBulkAsync(events: Event[], options: LogOptions): Promise<PangeaResponse<LogBulkResponse>>

Asynchronously create multiple log entries in the Secure Audit Log.

Array<Event>
LogOptions

Promise<PangeaResponse<LogBulkResponse>>
const events = [
 { message: "hello world" },
];
const options = { verbose: true };

const response = await audit.logBulkAsync(events, options);

Log streaming endpoint

logStream(data: object): Promise<PangeaResponse<{}>>

This API allows 3rd party vendors (like Auth0) to stream events to this endpoint where the structure of the payload varies across different vendors.

object

Event data. The exact schema of this will vary by vendor.

Promise<PangeaResponse<{}>>
const data = {
  logs: [
    {
      log_id: "some log id",
      data: {
        date: "2024-03-29T17:26:50.193Z",
        type: "some_type",
        description: "Create a log stream",
        client_id: "test client ID",
        ip: "127.0.0.1",
        user_agent: "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0",
        user_id: "test user ID",
      },
    },
  ],
};
const response = await audit.logStream(data);
results(id: string, limit: number, offset: number, options: SearchOptions, queryOptions: ResultOptions): Promise<PangeaResponse<ResultResponse>>

Fetch paginated results of a previously executed search.

string

The id of a successful search

number

(default 20) - The number of results returned

number

(default 0) - The starting position of the first returned result

Search options. The following search options are supported:

  • verifyConsistency (boolean): If true verify published roots and membership proof of each event
  • skipEventVerification (boolean): If true skip event hash verification
ResultOptions

Search options. The following search options are supported:

  • assert_search_restriction (Audit.SearchRestriction): A list of keys to restrict the search results to. Useful for partitioning data available to the query string.
  • return_context (boolean): Return the context data needed to decrypt secure audit events that have been redacted with format preserving encryption.

Promise<PangeaResponse<ResultResponse>>
const response = await audit.results(
  "pas_sqilrhruwu54uggihqj3aie24wrctakr",
  50,
  100
);

Tamperproof verification

root(size: number): Promise<PangeaResponse<RootResult>>

Returns current root hash and consistency proof.

number

The size of the tree (the number of records)

Promise<PangeaResponse<RootResult>>
const response = audit.root(7);

Search the log

search(query: string, queryOptions: SearchParamsOptions, options: SearchOptions): Promise<PangeaResponse<SearchResponse>>

Search for events that match the provided search criteria.

string

Natural search string; list of keywords with optional <option>:<value> qualifiers. The following optional qualifiers are supported:

  • action:
  • actor:
  • message:
  • new:
  • old:
  • status:
  • target:

Search options. The following search options are supported:

  • limit (number): Maximum number of records to return per page.
  • start (string): The start of the time range to perform the search on.
  • end (string): The end of the time range to perform the search on. All records up to the latest if left out.
  • max_results (number): Maximum number of results to return.
  • order (string): Specify the sort order of the response.
  • order_by (string): Name of column to sort the results by.
  • search_restriction (Audit.SearchRestriction): A list of keys to restrict the search results to. Useful for partitioning data available to the query string.
  • verbose (boolean): If true, include the root hash of the tree and the membership proof for each record.
  • return_context (boolean): Return the context data needed to decrypt secure audit events that have been redacted with format preserving encryption.

Search options. The following search options are supported:

  • verifyConsistency (boolean): If true verify published roots and membership proof of each event
  • skipEventVerification (boolean): If true skip event hash verification

Promise<PangeaResponse<SearchResponse>>
const response = await audit.search(
  "add_employee:Gumby"
);

Enum DownloadFormat

DownloadFormat

CSV = "csv"

JSON = "json"

Interface AuditRecord

AuditRecord

EventEnvelope
string

string
string
string
string
string
boolean
string

Interface DownloadRequest

DownloadRequest

DownloadFormat

Format for the records.

string

ID returned by the export API.

string

ID returned by the search API.

boolean

Return the context data needed to decrypt secure audit events that have been redacted with format preserving encryption.

Interface DownloadResult

DownloadResult

string

URL where search results can be downloaded.

Interface Event

Event

Interface EventEnvelope

EventEnvelope

Event
string

string
string

Interface ExportRequest

ExportRequest

string

The end of the time range to perform the search on. If omitted, then all records up to the latest will be searched.

Format for the records.

asc | desc

Specify the sort order of the response.

string

Name of column to sort the results by.

string

The start of the time range to perform the search on.

boolean

Whether or not to include the root hash of the tree and the membership proof for each record.

Interface LogBulkRequest

LogBulkRequest

Array<LogEvent>

boolean

Interface LogBulkResponse

LogBulkResponse

Array<LogResponse>

Interface LogData

LogData

Event

string
string
string
boolean

Interface LogEvent

LogEvent

Event

string
string

Interface LogOptions

LogOptions

Object
Signer
boolean
boolean
boolean

Interface LogRequestCommon

LogRequestCommon

boolean

Interface LogResponse

LogResponse

EventEnvelope
string

Array<string>
string
string
string
string
string

Interface ResultOptions

ResultOptions

SearchRestriction
boolean

Interface ResultResponse

ResultResponse

number

Root

Interface Root

Root

Array<string>
string
number
string

string
string

Interface RootParams

RootParams

number

Interface RootRequest

RootRequest

number

Interface RootResult

RootResult

Array<string>
Root
string
number
string

string
string

Interface SearchOptions

SearchOptions

boolean
boolean

Interface SearchParams

SearchParams

string

string
number
number
string
string
boolean
SearchRestriction
string
boolean

Interface SearchParamsOptions

SearchParamsOptions

string
number
number
string
string
boolean
SearchRestriction
string
boolean

Interface SearchResponse

SearchResponse

number
string
string

Root
Root

Interface SearchRestriction

SearchRestriction

Array<string>
Array<string>
Array<string>
Array<string>
Array<string>