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): AuditServiceCreates a new AuditService
with the given Pangea API token and
configuration.
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.
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.
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.
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.
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.
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.
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 of a search
results(id: string, limit: number, offset: number, options: SearchOptions, queryOptions: ResultOptions): Promise<PangeaResponse<ResultResponse>>Fetch paginated results of a previously executed search.
const response = await audit.results(
"pas_sqilrhruwu54uggihqj3aie24wrctakr",
50,
100
);
Tamperproof verification
root(size: number): Promise<PangeaResponse<RootResult>>Returns current root hash and consistency proof.
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.
const response = await audit.search(
"add_employee:Gumby"
);
Enum DownloadFormat
DownloadFormatCSV
= "csv"
JSON
= "json"