@nostr-dev-kit/blossom
Version: 
Blossom protocol support for NDK (Nostr Development Kit)
149 lines • 5.29 kB
TypeScript
import type NDK from "@nostr-dev-kit/ndk";
import { NDKBlossomList, type NDKImetaTag, type NDKUser } from "@nostr-dev-kit/ndk";
import type { BlossomOptimizationOptions, BlossomRetryOptions, BlossomServerConfig, BlossomUploadOptions, SHA256Calculator } from "./types";
import { NDKBlossomAuthError, NDKBlossomError, NDKBlossomNotFoundError, NDKBlossomOptimizationError, NDKBlossomServerError, NDKBlossomUploadError } from "./utils/errors";
/**
 * NDKBlossom class for interacting with the Blossom protocol
 */
export declare class NDKBlossom {
    ndk: NDK;
    private serverConfigs;
    private retryOptions;
    private debugMode;
    private logger;
    private sha256Calculator;
    /**
     * Callback for upload failures
     */
    onUploadFailed?: (error: string, serverUrl?: string, file?: File) => void;
    /**
     * Callback for upload progress
     */
    onUploadProgress?: (progress: {
        loaded: number;
        total: number;
    }, file: File, serverUrl: string) => "continue" | "cancel";
    /**
     * Callback for mirror progress
     */
    onMirrorProgress?: (current: number, total: number, sourceUrl: string) => void;
    /**
     * Callback for server errors
     */
    onServerError?: (error: NDKBlossomServerError) => void;
    /**
     * Constructor for NDKBlossom
     * @param ndk NDK instance
     */
    constructor(ndk: NDK);
    /**
     * Enable or disable debug mode
     */
    set debug(value: boolean);
    /**
     * Get debug mode status
     */
    get debug(): boolean;
    /**
     * Set custom logger
     */
    set loggerFunction(logFn: (level: string, message: string, data?: any) => void);
    /**
     * Set a custom SHA256 calculator implementation
     * @param calculator Custom SHA256 calculator
     */
    setSHA256Calculator(calculator: SHA256Calculator): void;
    /**
     * Get the current SHA256 calculator implementation
     * @returns Current SHA256 calculator
     */
    getSHA256Calculator(): SHA256Calculator;
    private _serverList;
    set serverList(serverList: NDKBlossomList);
    getServerList(user?: NDKUser): Promise<NDKBlossomList | undefined>;
    /**
     * Uploads a file to a Blossom server
     * @param file The file to upload
     * @param options Upload options
     * @returns Image metadata
     */
    upload(file: File, options?: BlossomUploadOptions): Promise<NDKImetaTag>;
    /**
     * Fixes a Blossom URL by finding an alternative server with the same blob
     * @param user The user whose servers to check
     * @param url The URL to fix
     * @returns A fixed URL pointing to a valid Blossom server
     */
    fixUrl(user: NDKUser, url: string): Promise<string>;
    /**
     * Gets a blob from a URL
     * @param url The URL of the blob
     * @returns The blob response
     */
    getBlob(url: string): Promise<Response>;
    /**
     * Gets a blob by its hash from one of the user's servers
     * @param user The user whose servers to check
     * @param hash The hash of the blob
     * @returns The blob response
     */
    getBlobByHash(user: NDKUser, hash: string): Promise<Response>;
    /**
     * Lists blobs for a user
     * @param user The user whose blobs to list
     * @returns Array of blob descriptors
     */
    listBlobs(user: NDKUser): Promise<NDKImetaTag[]>;
    /**
     * Deletes a blob
     * @param hash The hash of the blob to delete
     * @returns True if successful
     */
    deleteBlob(hash: string): Promise<boolean>;
    /**
     * Checks if a server has a blob
     * @param serverUrl The URL of the server
     * @param hash The hash of the blob
     * @returns True if the server has the blob
     */
    checkServerForBlob(serverUrl: string, hash: string): Promise<boolean>;
    /**
     * Sets retry options for network operations
     * @param options Retry options
     */
    setRetryOptions(options: Partial<BlossomRetryOptions>): void;
    /**
     * Sets server-specific configuration
     * @param serverUrl The URL of the server
     * @param config Server configuration
     */
    setServerConfig(serverUrl: string, config: BlossomServerConfig): void;
    /**
     * Gets an optimized version of a blob
     * @param url The URL of the blob
     * @param options Optimization options
     * @returns The optimized blob response
     */
    getOptimizedBlob(url: string, options?: BlossomOptimizationOptions): Promise<Response>;
    /**
     * Gets an optimized URL for a blob
     * @param url The URL of the blob
     * @param options Optimization options
     * @returns The optimized URL
     */
    getOptimizedUrl(url: string, options?: BlossomOptimizationOptions): Promise<string>;
    /**
     * Generates a srcset for responsive images
     * @param url The base URL of the image
     * @param sizes Array of size configurations
     * @returns A srcset string
     */
    generateSrcset(url: string, sizes: {
        width: number;
        format?: string;
    }[]): string;
}
export { NDKBlossomError, NDKBlossomUploadError, NDKBlossomServerError, NDKBlossomAuthError, NDKBlossomNotFoundError, NDKBlossomOptimizationError, };
export type { BlossomRetryOptions, BlossomServerConfig, BlossomUploadOptions, BlossomOptimizationOptions, NDKImetaTag };
export default NDKBlossom;
//# sourceMappingURL=blossom.d.ts.map