Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Commands Reference

Audit Log


Audit logs in DID Spaces provide a comprehensive record of various activities, offering transparency and traceability for operations within your space. This section guides you through querying and managing these logs, including listing existing logs and recording the status of object synchronization processes.

For a general overview of all available commands, refer to the Commands Reference section.

List Logs#

The auditLogList command allows you to retrieve a paginated list of audit logs based on various filters and sorting options. This is useful for monitoring activities, debugging, and compliance.

Parameters

Name

Type

Description

Default Value

endpoint

string

The DID Space service endpoint URL.


size

string or number

The number of audit logs to return per page. Converted to an integer.

10

page

string or number

The page number to retrieve. Converted to an integer.

0

sort

string

The field to sort the results by (e.g., 'createdAt', 'actionType').

''

order

string or number

The sort order: 0 for ascending, 1 for descending. Converted to an integer.

0

status

AuditLogStatus or AuditLogStatus[]

Optional. Filter logs by their status. Can be a single status or an array of statuses. Valid AuditLogStatus values include: INITIAL, SUCCESS, FAILED, PENDING, CANCELED.


actionType

AuditLogAction or AuditLogAction[]

Optional. Filter logs by the type of action. Can be a single action type or an array of action types. Valid AuditLogAction values include: APP_OBJECTS_SYNC, APP_BACKUP, APP_RESTORE.


Returns

Name

Type

Description

statusCode

number

The HTTP status code of the response.

statusMessage

string

The HTTP status message.

data

any

An object containing the list of audit logs and pagination information. The exact structure depends on the DID Space service's response, but typically includes total, page, pageSize, and an array of items (logs).

Example

import { DIDSpaceClient } from '@did-space/client';
import { AuditLogAction, AuditLogStatus } from '@did-space/constants';

async function getAuditLogs(wallet, endpoint) {
const client = new DIDSpaceClient({
wallet,
endpoint,
});

try {
const response = await client.auditLog.listLogs({
endpoint: `${endpoint}/.well-known/service/api/did-space`,
size: 5,
page: 0,
sort: 'createdAt',
order: 1, // Descending
status: AuditLogStatus.SUCCESS,
actionType: AuditLogAction.APP_OBJECTS_SYNC,
});

console.log('Successfully retrieved audit logs:');
console.log('Status Code:', response.statusCode);
console.log('Status Message:', response.statusMessage);
console.log('Data:', JSON.stringify(response.data, null, 2));

if (response.data && response.data.items) {
response.data.items.forEach((log) => {
console.log(`- Log ID: ${log.id}, Action: ${log.actionType}, Status: ${log.status}`);
});
}
} catch (error) {
console.error('Error retrieving audit logs:', error);
}
}

// Replace with your actual wallet and DID Space endpoint
// const wallet = { /* your wallet object */ };
// const endpoint = 'https://your-space-did.space';
// getAuditLogs(wallet, endpoint);

This example demonstrates how to retrieve the first page of up to 5 audit logs, sorted by creation time in descending order, specifically for successful APP_OBJECTS_SYNC actions. The endpoint parameter for listLogs should point to the Blocklet Service API endpoint, usually in the format https://your-space-did.space/.well-known/service/api/did-space.

Post Sync#

The PostObjectsSyncCommand allows you to record the initiation of an object synchronization process in the audit logs. This command is typically used at the start of a sync operation to log its details.

Parameters

Name

Type

Description

source

string

The source path or identifier of the objects being synchronized. Must not be empty.

target

string

The target path or identifier where the objects are being synchronized to. Must not be empty.

metadata

Record<string, any>

Optional. Additional metadata related to the synchronization process, stored as key-value pairs.

Returns

Name

Type

Description

statusCode

number

The HTTP status code of the response.

statusMessage

string

The HTTP status message.

data

AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>

The created audit log entry for the object synchronization. This model includes details like id, actionType (set to APP_OBJECTS_SYNC), status (initial status, e.g., PENDING), data (containing the input source, target, metadata, and initialized counts/size/duration).

Example

import { DIDSpaceClient } from '@did-space/client';

async function postSyncLog(wallet, endpoint) {
const client = new DIDSpaceClient({
wallet,
endpoint,
});

try {
const response = await client.auditLog.postSync({
source: '/my-local-folder',
target: '/did-space-backup/data',
metadata: {
syncType: 'full',
initiatedBy: 'user-xyz',
},
});

console.log('Successfully posted sync log:');
console.log('Status Code:', response.statusCode);
console.log('Status Message:', response.statusMessage);
console.log('Created Log ID:', response.data.id);
console.log('Log Data:', JSON.stringify(response.data, null, 2));
} catch (error) {
console.error('Error posting sync log:', error);
}
}

// Replace with your actual wallet and DID Space endpoint
// const wallet = { /* your wallet object */ };
// const endpoint = 'https://your-space-did.space';
// postSyncLog(wallet, endpoint);

This example demonstrates how to create an audit log entry for a new object synchronization process, specifying the source and target paths along with some custom metadata. The initial status of the log will typically be PENDING or INITIAL.

Put Sync#

The PutObjectsSyncCommand allows you to update the status and details of an ongoing or completed object synchronization process in the audit logs. This is crucial for tracking the progress and outcome of synchronization tasks.

Parameters

Name

Type

Description

id

string

The unique identifier of the audit log entry to update. Must not be empty.

status

AuditLogStatus

The new status of the synchronization. Valid values include: INITIAL, SUCCESS, FAILED, PENDING, CANCELED.

reason

string

Optional. A descriptive reason for the status update, especially useful for FAILED or CANCELED statuses.

totalCount

number

The total number of objects processed during synchronization.

errorCount

number

The number of objects that failed to synchronize.

successCount

number

Optional. The number of objects successfully synchronized.

size

number

The total size (in bytes) of objects processed.

duration

number

The duration (in milliseconds) of the synchronization process.

Returns

Name

Type

Description

statusCode

number

The HTTP status code of the response.

statusMessage

string

The HTTP status message.

data

AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>

The updated audit log entry for the object synchronization, reflecting the new status and metrics.

Example

import { DIDSpaceClient } from '@did-space/client';
import { AuditLogStatus } from '@did-space/constants';

async function putSyncLog(wallet, endpoint, logId) {
const client = new DIDSpaceClient({
wallet,
endpoint,
});

try {
const response = await client.auditLog.putSync({
id: logId, // ID obtained from a previous postSyncLog call
status: AuditLogStatus.SUCCESS,
totalCount: 100,
successCount: 98,
errorCount: 2,
size: 1024 * 1024 * 50, // 50 MB
duration: 15000, // 15 seconds
reason: 'Synchronization completed successfully with minor errors.',
});

console.log('Successfully updated sync log:');
console.log('Status Code:', response.statusCode);
console.log('Status Message:', response.statusMessage);
console.log('Updated Log ID:', response.data.id);
console.log('New Status:', response.data.status);
console.log('Log Data:', JSON.stringify(response.data, null, 2));
} catch (error) {
console.error('Error updating sync log:', error);
}
}

// Replace with your actual wallet, DID Space endpoint, and a valid log ID
// const wallet = { /* your wallet object */ };
// const endpoint = 'https://your-space-did.space';
// const existingLogId = 'some-audit-log-id'; // This ID would come from the postSyncLog response
// putSyncLog(wallet, endpoint, existingLogId);

This example demonstrates how to update an existing audit log entry with detailed metrics and a new status (e.g., SUCCESS). You would typically call this command after a synchronization process has finished to record its final outcome.


This section provided an in-depth look into managing audit logs within DID Spaces, from listing existing entries to tracking object synchronization progress. These commands are essential for maintaining visibility and accountability over activities in your DID Space. You can now proceed to explore other advanced commands, such as Space Head for checking space availability.