Skip to content

@storyshelf/storage-azure

View as Markdown

@storyshelf/storage-azure stores StoryShelf blobs in an Azure Blob Storage container. It persists the same artifacts as the other storage adapters — captured screenshots, diff overlays, and uploaded Storybook archives.

Terminal window
npm i @storyshelf/storage-azure

JSR JSR Score

import { createAzureStorage } from "@storyshelf/storage-azure";
import { createShelfApp } from "@storyshelf/app";
// Via connection string (recommended for local / Azurite)
const storage = createAzureStorage({
container: "storyshelf",
prefix: "storyshelf", // optional
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
});
// Via account name + key
const storage2 = createAzureStorage({
container: "storyshelf",
accountName: "myaccount",
accountKey: process.env.AZURE_STORAGE_KEY,
accountUrl: "https://myaccount.blob.core.windows.net", // optional, derived from accountName if omitted
});
const app = createShelfApp({ database, storage });

Inject a pre-configured client (tests / custom credential rotation):

import { BlobServiceClient } from "@azure/storage-blob";
const service = BlobServiceClient.fromConnectionString(connStr);
const containerClient = service.getContainerClient("storyshelf");
const storage = createAzureStorage({ container: "storyshelf", client: containerClient });

Azurite (local emulator):

const storage = createAzureStorage({
container: "storyshelf",
connectionString:
"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
});
interface AzureStorageOptions {
container: string; // required container name
prefix?: string; // optional blob prefix, defaults to ""
client?: ContainerClient; // optional pre-configured container client
connectionString?: string; // optional Azure connection string
accountName?: string; // optional storage account name
accountKey?: string; // optional storage account key
accountUrl?: string; // optional blob service URL (e.g. https://myaccount.blob.core.windows.net)
sasToken?: string; // optional SAS token (without leading ? OK)
}

Options at a glance:

OptionRequiredNotes
containeryesBlob container name
prefixnoKey prefix applied to every object
clientnoPre-built ContainerClient; skips client construction
connectionStringno*Storage connection string
accountName / accountKeyno*Explicit credentials pair
accountUrl / sasTokenno*URL + SAS form (emulator, fine-grained SAS)

* At least one auth form is needed unless client is supplied.

createAzureStorage(options: AzureStorageOptions): StorageAdapter

Section titled “createAzureStorage(options: AzureStorageOptions): StorageAdapter”

Creates a StorageAdapter backed by the configured Azure container. The returned adapter implements every method of the StorageAdapter interface (read, write, delete, exists, list(prefix), readStream, writeStream).

azureKey(prefix: string, path: string): string

Section titled “azureKey(prefix: string, path: string): string”

Helper that joins a storage prefix with a relative path into a blob name.

Choose Azure Blob Storage for Azure deploys — Container Apps, AKS, or Functions — especially paired with db-postgres. It is a drop-in replacement for local storage and S3 storage; for Google Cloud see storage-gcs.