@lumera/sdk-js
    Preparing search index...

    Class SNApiClient

    Typed REST client for interacting with sn-api endpoints.

    This client provides a thin, type-safe wrapper around the HttpClient for Cascade storage operations. It maps directly to the sn-api REST endpoints defined in the OpenAPI specification.

    const httpClient = new HttpClient({ baseUrl: 'https://sn-api.example.com' });
    const client = new SNApiClient(httpClient);

    // Start a cascade action
    const response = await client.startCascade({ file: fileBlob });
    console.log('Task ID:', response.taskId);

    // Check task status
    const status = await client.getTaskStatus(response.taskId);
    console.log('Status:', status.status);
    Index

    Constructors

    Methods

    • Download the file associated with a task

      Downloads the file data as a ReadableStream for efficient streaming of large files without loading them entirely into memory. Maps to: GET /api/downloads/cascade/{task_id}/file

      Parameters

      • taskId: string

        The task ID to download

      Returns Promise<ReadableStream<any>>

      Promise resolving to a ReadableStream of the file data

      If the request fails

      const stream = await client.downloadFile('task-456');
      // Stream can be piped to a file or processed in chunks
      const reader = stream.getReader();
      while (true) {
      const { done, value } = await reader.read();
      if (done) break;
      // Process chunk...
      }
    • Get information about a specific task

      Retrieves detailed information about a Cascade task, including its status and progress. Maps to: GET /api/actions/cascade/tasks/{task_id}

      Parameters

      • taskId: string

        The task ID to query

      Returns Promise<{ progress?: number; status?: string; taskId?: string }>

      Promise resolving to task information

      If the request fails

      const task = await client.getTask('task-456');
      console.log('Task status:', task.status);
      console.log('Progress:', task.progress);
    • Get the status of a specific task

      Retrieves just the status information for a Cascade task, which is lighter weight than getting the full task details. Maps to: GET /api/actions/cascade/tasks/{task_id}/status

      Parameters

      • taskId: string

        The task ID to query

      Returns Promise<
          {
              progress?: number;
              status?: "pending"
              | "processing"
              | "completed"
              | "failed";
          },
      >

      Promise resolving to task status

      If the request fails

      const status = await client.getTaskStatus('task-456');
      if (status.status === 'completed') {
      console.log('Task completed!');
      }
    • Request a download for a specific Cascade action

      Initiates a download task for a previously stored Cascade action. Maps to: POST /api/actions/cascade/{action_id}/downloads

      Parameters

      • actionId: string

        The action ID to download

      • body: RequestDownloadBody

        Request body (currently unused in spec)

      Returns Promise<{ taskId?: string }>

      Promise resolving to the response with download task ID

      If the request fails

      const response = await client.requestDownload('action-123', {});
      console.log('Download task:', response.taskId);
    • Start a new Cascade storage action

      Initiates a new Cascade storage action by uploading a file with required authentication. Maps to: POST /api/v1/actions/cascade

      Parameters

      • body: StartCascadeRequest

        Request body containing the action ID, signature, and file to upload

      Returns Promise<{ task_id?: string }>

      Promise resolving to the response with task ID

      If the request fails

      const response = await client.startCascade({
      actionId: 'action-123',
      signature: 'base64_signature',
      file: myFile
      });
      console.log('Started task:', response.task_id);
    • Watch download task status via Server-Sent Events (SSE)

      Creates an EventSource connection to monitor task status updates in real-time. The SSE stream will emit events until the task completes or fails. Maps to: GET /api/v1/downloads/cascade/{task_id}/status

      Parameters

      • taskId: string

        The task ID to watch

      Returns EventSource

      EventSource instance for receiving status updates

      const eventSource = client.watchDownloadTask('task-456');

      eventSource.addEventListener('sdk:completed', (event) => {
      console.log('Task completed:', event.data);
      eventSource.close();
      });

      eventSource.addEventListener('error', (event) => {
      console.error('Task error:', event);
      eventSource.close();
      });