Overview
The SDK exports all TypeScript types for full type safety in your application.Import
Web SDK:Copy
Ask AI
import type {
ClientOptions,
TraceOptions,
AddEventOptions,
ChainName,
ClientMetadata,
TraceEvent,
TxHashHint,
StackFrame,
StackTrace
} from '@miradorlabs/web-sdk';
Copy
Ask AI
import type {
ClientOptions,
TraceOptions,
AddEventOptions,
ChainName,
StackFrame,
StackTrace
} from '@miradorlabs/nodejs-sdk';
ClientOptions
Configuration options for the client.Copy
Ask AI
interface ClientOptions {
/**
* Gateway URL for the Mirador Ingest API
* @default 'ingest-gateway-dev.mirador.org:443'
*/
apiUrl?: string;
/**
* Keep-alive ping interval in milliseconds
* @default 10000
*/
keepAliveIntervalMs?: number;
}
Usage
Copy
Ask AI
const options: ClientOptions = {
apiUrl: 'https://custom-gateway.example.com:443'
};
const client = new Client('api-key', options);
TraceOptions
Configuration options for individual traces. Web SDK:Copy
Ask AI
interface TraceOptions {
/**
* Name identifying the trace
*/
name?: string;
/**
* Include browser metadata on first flush
* @default true
*/
includeUserMeta?: boolean;
/**
* Maximum retry attempts on network failure
* @default 3
*/
maxRetries?: number;
/**
* Base delay in ms for exponential backoff
* @default 1000
*/
retryBackoff?: number;
/**
* Automatically close trace on page unload
* @default false
*/
autoClose?: boolean;
}
Copy
Ask AI
interface TraceOptions {
/**
* Name identifying the trace
*/
name?: string;
/**
* Capture stack trace at trace creation point
* @default true
*/
captureStackTrace?: boolean;
/**
* Maximum retry attempts on network failure
* @default 3
*/
maxRetries?: number;
/**
* Base delay in ms for exponential backoff
* @default 1000
*/
retryBackoff?: number;
}
Usage
Web SDK:Copy
Ask AI
const options: TraceOptions = {
name: 'MyTrace',
includeUserMeta: true,
maxRetries: 5,
retryBackoff: 2000
};
const trace = client.trace(options);
Copy
Ask AI
const options: TraceOptions = {
name: 'MyTrace',
captureStackTrace: false
};
const trace = client.trace(options);
ChainName
Supported blockchain networks for transaction hints.Copy
Ask AI
type ChainName =
| 'ethereum'
| 'polygon'
| 'arbitrum'
| 'base'
| 'optimism'
| 'bsc';
Usage
Copy
Ask AI
const chain: ChainName = 'ethereum';
trace.addTxHint(txHash, chain);
// Type-safe: only valid chains allowed
trace.addTxHint(hash, 'polygon'); // ✓
trace.addTxHint(hash, 'invalid'); // ✗ Type error
TraceEvent
Structure of events added to traces.Copy
Ask AI
interface TraceEvent {
/**
* Event name
*/
eventName: string;
/**
* Optional event details (stringified if object)
*/
details?: string;
/**
* Timestamp of the event
*/
timestamp: Date;
}
Usage
Copy
Ask AI
// Events are created internally by addEvent()
trace.addEvent('my_event', { key: 'value' });
// The SDK creates a TraceEvent like:
// {
// eventName: 'my_event',
// details: '{"key":"value"}',
// timestamp: new Date()
// }
TxHashHint
Structure of blockchain transaction hints.Copy
Ask AI
interface TxHashHint {
/**
* Transaction hash
*/
txHash: string;
/**
* Blockchain network
*/
chain: ChainName;
/**
* Optional description
*/
details?: string;
/**
* Timestamp of the hint
*/
timestamp: Date;
}
Usage
Copy
Ask AI
// TxHashHints are created internally by addTxHint()
trace.addTxHint('0x123...', 'ethereum', 'Swap transaction');
// The SDK creates a TxHashHint like:
// {
// txHash: '0x123...',
// chain: 'ethereum',
// details: 'Swap transaction'
// }
AddEventOptions
Options for theaddEvent() method.
Copy
Ask AI
interface AddEventOptions {
/**
* Capture stack trace at event location
* @default false
*/
captureStackTrace?: boolean;
}
Usage
Copy
Ask AI
// Capture stack trace for debugging
trace.addEvent('error_occurred', { code: 500 }, { captureStackTrace: true });
StackFrame
Represents a single frame in a stack trace.Copy
Ask AI
interface StackFrame {
/**
* Function name (or '<anonymous>')
*/
functionName: string;
/**
* File name or URL
*/
fileName: string;
/**
* Line number
*/
lineNumber: number;
/**
* Column number
*/
columnNumber: number;
}
StackTrace
Captured stack trace information.Copy
Ask AI
interface StackTrace {
/**
* Parsed stack frames
*/
frames: StackFrame[];
/**
* Original Error.stack string
*/
raw: string;
}
Usage
Copy
Ask AI
import { captureStackTrace, formatStackTrace } from '@miradorlabs/web-sdk';
// Capture current stack trace
const stack = captureStackTrace();
// Format for storage
const json = formatStackTrace(stack);
// Format for display
const readable = formatStackTraceReadable(stack);
ClientMetadata (Web SDK Only)
Browser environment metadata collected automatically.Copy
Ask AI
interface ClientMetadata {
// Browser
browser?: string;
browserVersion?: string;
userAgent?: string;
// Operating System
os?: string;
osVersion?: string;
deviceType?: string;
// Display
screenWidth?: string;
screenHeight?: string;
viewportWidth?: string;
viewportHeight?: string;
colorDepth?: string;
pixelRatio?: string;
// Hardware
cpuCores?: string;
deviceMemory?: string;
touchSupport?: string;
// Network
connectionType?: string;
online?: string;
// Locale
language?: string;
languages?: string;
timezone?: string;
timezoneOffset?: string;
// Page Context
url?: string;
origin?: string;
pathname?: string;
referrer?: string;
documentVisibility?: string;
// Privacy
cookiesEnabled?: string;
doNotTrack?: string;
}
Usage
Copy
Ask AI
import { getClientMetadata } from '@miradorlabs/web-sdk';
const metadata: ClientMetadata = getClientMetadata();
console.log(metadata.browser); // 'Chrome'
console.log(metadata.deviceType); // 'desktop'
Utility Functions (Web SDK Only)
The Web SDK also exports utility functions for metadata detection:Copy
Ask AI
import {
getClientMetadata,
detectBrowser,
detectOS,
detectDeviceType,
captureStackTrace,
formatStackTrace,
formatStackTraceReadable
} from '@miradorlabs/web-sdk';
// Get full metadata object
const metadata = getClientMetadata();
// Individual detection
const browser = detectBrowser();
// { name: 'Chrome', version: '120.0.0' }
const os = detectOS();
// { name: 'macOS', version: '14.0' }
const device = detectDeviceType();
// 'desktop' | 'mobile' | 'tablet'