@ghostspeak/sdk
Version:
TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta
120 lines (116 loc) • 3.55 kB
TypeScript
import { Address } from '@solana/addresses';
import { ErrorCode, SDKError } from './types.js';
/**
* Smart Error System with Actionable Solutions
*
* Every error includes context and suggested solutions to help developers
* quickly resolve issues.
*/
/**
* Base GhostSpeak error class
*/
declare class GhostSpeakError extends Error {
readonly code: ErrorCode;
readonly context: Record<string, unknown>;
readonly solution?: string;
readonly instruction?: string;
constructor(code: ErrorCode, message: string, context?: Record<string, unknown>, solution?: string, instruction?: string);
/**
* Format error for display
*/
toString(): string;
/**
* Convert to SDK error type
*/
toSDKError(): SDKError;
}
/**
* Network-related errors
*/
declare class NetworkError extends GhostSpeakError {
constructor(endpoint: string, originalError?: Error);
}
/**
* Insufficient balance error
*/
declare class InsufficientBalanceError extends GhostSpeakError {
constructor(required: bigint, available: bigint, address: Address);
}
/**
* Account not found error
*/
declare class AccountNotFoundError extends GhostSpeakError {
constructor(address: Address, accountType: string);
}
/**
* Invalid input error
*/
declare class InvalidInputError extends GhostSpeakError {
constructor(field: string, value: unknown, requirement: string);
}
/**
* Transaction failed error
*/
declare class TransactionFailedError extends GhostSpeakError {
constructor(signature: string, logs: string[], programError?: string);
private static getSolution;
}
/**
* Simulation failed error
*/
declare class SimulationFailedError extends GhostSpeakError {
constructor(logs: string[], unitsConsumed?: bigint);
}
/**
* Timeout error
*/
declare class TimeoutError extends GhostSpeakError {
constructor(operation: string, timeoutMs: number);
}
/**
* Error factory for creating specific errors
*/
declare class ErrorFactory {
/**
* Create error from program logs
*/
static fromProgramLogs(logs: string[], signature?: string): GhostSpeakError;
/**
* Create error from RPC error
*/
static fromRpcError(error: unknown, endpoint: string): GhostSpeakError;
}
/**
* Global error handler for consistent error handling
*/
declare class ErrorHandler {
private static handlers;
/**
* Register error handler
*/
static on(code: ErrorCode, handler: (error: GhostSpeakError) => void): void;
/**
* Handle error
*/
static handle(error: unknown): SDKError;
}
/**
* Validation error for invalid inputs
*/
declare class ValidationError extends GhostSpeakError {
constructor(message: string, context?: Record<string, unknown>);
}
declare const _default: {
GhostSpeakError: typeof GhostSpeakError;
NetworkError: typeof NetworkError;
InsufficientBalanceError: typeof InsufficientBalanceError;
AccountNotFoundError: typeof AccountNotFoundError;
InvalidInputError: typeof InvalidInputError;
TransactionFailedError: typeof TransactionFailedError;
SimulationFailedError: typeof SimulationFailedError;
TimeoutError: typeof TimeoutError;
ValidationError: typeof ValidationError;
ErrorFactory: typeof ErrorFactory;
ErrorHandler: typeof ErrorHandler;
};
export { AccountNotFoundError, ErrorFactory, ErrorHandler, GhostSpeakError, InsufficientBalanceError, InvalidInputError, NetworkError, SimulationFailedError, TimeoutError, TransactionFailedError, ValidationError, _default as default };