@microsoft/rayfin-storage
SDK reference for Rayfin Storage — storageService and createStorageClient, path-based upload, download, list, and delete signatures, options, result shapes, and error codes.
@microsoft/rayfin-storage is the typed client for Rayfin Storage folders declared with @blob(). Storage is generally available from Rayfin 2.0. For setup, folder declarations, and deployment, see Storage; for task-oriented examples, see Upload and download files.
Installation
Install the exact same version as every other @microsoft/rayfin-* package, in the package that creates your Rayfin client. The 2.0 @microsoft/rayfin-client does not bring Storage in, so add it yourself:
npm install @microsoft/rayfin-storage@2.0.0The package depends on @microsoft/rayfin-core and @microsoft/rayfin-lib at the same version. It has one entry point, @microsoft/rayfin-storage; imports of files under dist/ are not exported. Changed in 2.0
Exports
export { storageService } from './storageService.js';
export { StorageFolderClient } from './StorageFolderClient.js';
export { StorageApi, createStorageClient } from './StorageClient.js';
export type {
StorageError,
StorageCustomFields,
StorageObjectRef,
StorageUploadResult,
StorageDownloadResult,
StorageDeleteResult,
StorageListResult,
UploadOptions,
DownloadOptions,
DeleteOptions,
ListOptions,
} from './StorageFolderClient.js';
export type { StorageSchema, StorageClient } from './StorageClient.js';
export { STORAGE_ERROR_CODES, isStorageError, type StorageErrorCode } from './storageErrorCodes.js';storageService
function storageService<TSchema extends StorageSchema>(): ClientServiceFactory<StorageClient<TSchema>>;Registers typed folders on a client built with RayfinClient.create. The factory runs createStorageClient on the client's shared, authenticated transport, so Storage calls use the same session as data and function calls.
import { RayfinClient } from '@microsoft/rayfin-client';
import { browserSession } from '@microsoft/rayfin-auth';
import { storageService } from '@microsoft/rayfin-storage';
import type { AppStorageSchema } from '../../rayfin/storage/client-schema';
export const rayfinClient = RayfinClient.create({
baseUrl: import.meta.env.VITE_RAYFIN_API_URL,
publishableKey: import.meta.env.VITE_RAYFIN_PUBLISHABLE_KEY,
auth: browserSession({ storage: true }),
services: {
storage: storageService<AppStorageSchema>(),
},
});rayfinClient.storage is a StorageClient<AppStorageSchema>.
StorageSchema and StorageClient
type StorageSchema = Record<string, object>;
type StorageClient<TSchema extends StorageSchema> = {
[K in keyof TSchema]: StorageFolderClient<
StorageObjectRef & Partial<StorageCustomFields<TSchema[K]>>
>;
} & StorageApi<TSchema>;
type StorageCustomFields<TObject> = Omit<TObject, keyof StorageObjectRef | keyof StorageObject>;Each schema key is a folder name — the @blob class name, or its @blob({ name }) value. Each value is either the decorated class or an object type that lists the folder's custom metadata fields (object when there are none). The client adds the StorageObjectRef envelope itself; do not intersect schema values with StorageObjectRef. Custom fields are optional on returned objects.
The client normalizes a key to a folder name (lowercase letters, digits, and single hyphens) before it sends a request, so client.storage.Attachment addresses the attachment folder.
createStorageClient and StorageApi
function createStorageClient<TSchema extends StorageSchema = StorageSchema>(
apiClient: ApiClient,
): StorageClient<TSchema>;
class StorageApi<TSchema extends StorageSchema = StorageSchema> extends ServicePlugin {
getFolderClient<K extends keyof TSchema & string>(
folderName: K,
): StorageFolderClient<StorageObjectRef & Partial<StorageCustomFields<TSchema[K]>>>;
getInstantiatedFolderNames(): (keyof TSchema)[];
}createStorageClient stays public for code that owns an ApiClient from @microsoft/rayfin-lib directly. Application clients use storageService(). Composing Storage through ExtendableRayfinClient from @microsoft/rayfin-client/experimental no longer works. Removed in 2.0
StorageFolderClient
class StorageFolderClient<TObject extends StorageObjectRef = StorageObjectRef> {
upload(
path: string,
data: Blob | ArrayBuffer | Uint8Array | ReadableStream | string,
options?: UploadOptions<TObject>,
): Promise<StorageUploadResult<TObject>>;
download(path: string, options?: DownloadOptions): Promise<StorageDownloadResult>;
list(options?: ListOptions): Promise<StorageListResult<TObject>>;
list(directoryPath: string, options?: ListOptions): Promise<StorageListResult<TObject>>;
delete(path: string, options?: DeleteOptions): Promise<StorageDeleteResult>;
}path is the complete object path relative to the folder, including the file name, such as avatars/photo.png. list() takes an optional directory path; omit it, or pass an empty string, to list from the folder root.
| Path rule | Example that fails |
|---|---|
Segments are separated by / | avatars\photo.png |
No leading or trailing / | /avatars/photo.png, avatars/ |
No empty, ., or .. segments | avatars//photo.png, ../photo.png |
A path that breaks a rule throws a StorageError with code InvalidName and status 400 before any request is sent. Other characters and casing are preserved.
Options
| Type | Properties |
|---|---|
UploadOptions<TObject> | signal?, contentType?, contentDisposition?, cacheControl?, expiresInSeconds?, fields?: Partial<StorageCustomFields<TObject>> |
DownloadOptions | signal?, expiresInSeconds? |
ListOptions | limit?, continuation?, signal? |
DeleteOptions | signal? |
prefix is removed from all four option types; put directory segments in the path instead. Removed in 2.0
contentTypeoverrides the type inferred fromBlobdata. Other data defaults toapplication/octet-stream.contentDispositionandcacheControlare stored as object metadata and set on the file in OneLake.expiresInSecondsrequests the lifetime of the temporary upload or download URL. The service clamps upload URLs to 60–3600 seconds. It does not affect how long the object is kept.fieldssends custom metadata declared on the@blobclass. Do not send intrinsicStorageObjectfields.signalaborts the operation with codeAborted.
StorageObjectRef
interface StorageObjectRef {
id: string;
folder: string;
path: string;
name: string;
size: number;
sizeBig?: bigint;
contentType?: string;
contentDisposition?: string;
cacheControl?: string;
createdAt?: string;
updatedAt?: string;
lastAccessedAt?: string | null;
etag?: string;
}path is the complete relative object path, including the file name, and name is its last segment. Changed in 2.0 size is capped at Number.MAX_SAFE_INTEGER; sizeBig carries the exact size of larger objects. list() flattens each item's custom fields onto the returned object, so a team_id field is read as item.team_id.
Results
interface StorageUploadResult<TObject = StorageObjectRef> {
object: TObject;
correlationId: string;
}
interface StorageDownloadResult {
stream: ReadableStream<Uint8Array>;
contentType?: string;
contentDisposition?: string;
contentLength?: number;
etag?: string;
correlationId: string;
}
interface StorageListResult<TObject = StorageObjectRef> {
items: TObject[];
continuation?: string;
correlationId: string;
}
interface StorageDeleteResult {
success: boolean;
deleted: number;
correlationId: string;
}upload()transfers the bytes directly to OneLake through a temporary signed URL, commits the upload, and waits for the operation to succeed. The service does not return the committed object yet, soobjectis built from the request:idis an empty string, andsizeis0for aReadableStream.download()returns the OneLake response as a stream.contentTypeandcontentDispositionare the headers OneLake returns; the SDK does not override or synthesize them.delete()resolves after the service's delete operation succeeds.- Each operation uses one
correlationIdfor every request it makes and returns it.
Errors
interface StorageError extends Error {
code: StorageErrorCode;
status: number;
correlationId: string;
response?: Response;
retryable: boolean;
}
function isStorageError(error: unknown): error is StorageError;retryable is true for statuses of 500 and above and for rate limiting. It is a recommendation only: the SDK never retries automatically, and calling the operation again starts it over rather than resuming it.
Stable codes are exported as STORAGE_ERROR_CODES:
| Code | When it occurs |
|---|---|
InvalidName | The object or directory path breaks the path rules (thrown by the SDK before a request), or the service rejects the file name. |
InvalidFolder | The service rejects the folder name. |
InvalidSasExpiry | The service rejects the requested expiresInSeconds. |
InvalidContinuation | The continuation token is not valid. |
TooLarge | The object exceeds the folder's maxSize or the service limit. |
UnsupportedContentType | The content type is not in the folder's allowedContentTypes. |
Conflict | An object exists at the path and the folder uses onConflict: 'error', or another upload or delete of the same object is in progress. |
NotFound | The folder, object, or operation does not exist. |
PermissionDenied | The folder's @role() policy does not allow the operation. |
Unauthenticated | The request has no valid session. |
UploadSessionExpired | The temporary upload URL expired before the transfer finished. |
CommitFailed | The stored file did not match the upload when it was committed. |
RateLimited | The service is throttling requests. retryable is true. |
NoStorageEntitiesConfigured | No Storage folders are configured for the app. |
MissingOrMalformedOperationId | The service could not use the operation or upload ID. |
Aborted | The signal you passed was aborted. |
Unexpected | Any other failure. |
The set also contains InvalidPath, and InvalidPrefix, which is kept for compatibility with earlier clients.
Removed APIs
| Removed | Replacement |
|---|---|
prefix on upload, download, list, and delete options | Pass the complete object path; call list(directoryPath, options). Removed in 2.0 |
ExtendableRayfinClient composition with createStorageClient | storageService() in RayfinClient.create({ services }). Removed in 2.0 |
declaredSize, onProgress, userMetadata, and per-call onConflict upload options | The service enforces size limits; no progress callback; custom fields; @blob({ onConflict }). Removed in 1.36 |
Download range and contentType / contentDisposition overrides | Download returns the headers OneLake supplies. Removed in 1.36 |
Caller-supplied correlationId | The SDK creates one per operation. Removed in 1.36 |
storedPath and userMetadata on StorageObjectRef | path, and custom fields flattened onto each item. Removed in 1.36 |
StorageConflictMode and UploadProgressEvent exports | None. Removed in 1.36 |
To upgrade 1.36 code, follow Migrate from 1.36 Storage.
@microsoft/rayfin-functions
SDK reference for functionsService, FunctionClient, FunctionsSchema, InvokeOptions, FunctionsError, and typed client.functions invocations.
@microsoft/rayfin-telemetry
Package reference for @microsoft/rayfin-telemetry — the browser initializer initTelemetry, its options, defaults, and lifecycle, and the pinned OpenTelemetry peer dependencies.