Skip to content

Client

A fetch wrapper + a progress-tracked file upload, both injecting the active profile header and parsing the server's structured error envelope.

Variables

API_BASE

const API_BASE: string;

Defined in: src/shared/api/client.ts:14

Single source of truth for the API base. Overridable at build time via VITE_API_BASE (defaults to /api, which the dev server proxies), for deployments that serve the API from a different path or host.


UPLOAD_ABORTED_CODE

const UPLOAD_ABORTED_CODE: "UploadAborted" = "UploadAborted";

Defined in: src/shared/api/client.ts:107

The ApiError code reported when an upload is cancelled by the caller.

Distinguishes a deliberate cancel from a genuine failure, so the tray drops the row instead of showing it as an error.

Functions

apiFetch()

function apiFetch<T>(url, opts?): Promise<T>;

Defined in: src/shared/api/client.ts:58

A fetch replacement that prefixes the API base for relative URLs, injects the X-Profile-ID header, throws ApiError on non-2xx, and parses the response by content-type.

Type Parameters

Type Parameter Default type Description
T unknown

Parameters

Parameter Type Description
url string Relative API path (or absolute URL).
opts? RequestInit Fetch options.

Returns

Promise\<T>

The parsed response.


isUploadAborted()

function isUploadAborted(error): boolean;

Defined in: src/shared/api/client.ts:115

Whether an error is an upload the caller cancelled, rather than a failure.

Parameters

Parameter Type Description
error unknown The caught error.

Returns

boolean

true when the upload was aborted deliberately.


uploadFile()

function uploadFile<T>(
  file,
  url,
  headers,
  onProgress,
  onUploadComplete,
  signal?,
): Promise<T>;

Defined in: src/shared/api/client.ts:196

Uploads a file via a streaming XMLHttpRequest with progress, mirroring apiFetch (profile header, ApiError, JSON response).

Type Parameters

Type Parameter Default type Description
T unknown The expected JSON response type.

Parameters

Parameter Type Description
file File The file to upload.
url string The API endpoint.
headers Record\<string, string> Additional request headers.
onProgress (percent) => void Upload progress callback.
onUploadComplete () => void Called when the upload hits 100%.
signal? AbortSignal Cancels the upload when aborted, rejecting with an ApiError carrying UPLOAD_ABORTED_CODE.

Returns

Promise\<T>

The parsed JSON response.


uploadFormData()

function uploadFormData<T>(
  url,
  formData,
  onProgress,
  onUploadComplete,
  signal?,
): Promise<T>;

Defined in: src/shared/api/client.ts:245

Uploads multipart/form-data via a progress-tracked XMLHttpRequest, mirroring uploadFile (profile header, ApiError, JSON response). The file rides in the form body, so large structured metadata is a form field rather than a size-limited header. The browser sets the multipart Content-Type (with boundary), so it is deliberately not set here.

Type Parameters

Type Parameter Default type Description
T unknown The expected JSON response type.

Parameters

Parameter Type Description
url string The API endpoint.
formData FormData The multipart payload (file part + fields).
onProgress (percent) => void Upload progress callback.
onUploadComplete () => void Called when the upload hits 100%.
signal? AbortSignal Cancels the upload when aborted, rejecting with an ApiError carrying UPLOAD_ABORTED_CODE.

Returns

Promise\<T>

The parsed JSON response.