Skip to content

@storyshelf/storage-gcs

View as Markdown

@storyshelf/storage-gcs stores StoryShelf blobs in a Google Cloud Storage (GCS) bucket — captured screenshots, diff overlays, and uploaded Storybook archives.

Terminal window
npm i @storyshelf/storage-gcs

JSR JSR Score

import { createGcsStorage } from "@storyshelf/storage-gcs";
import { createShelfApp } from "@storyshelf/app";
const storage = createGcsStorage({
bucket: "my-shelf",
prefix: "storyshelf", // optional
projectId: "my-gcp-project", // optional, defaults to ADC
});
const app = createShelfApp({ database, storage });

For local emulators or custom endpoints:

const storage = createGcsStorage({
bucket: "my-shelf",
apiEndpoint: "http://localhost:9090",
projectId: "test-project",
});

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

import { Storage } from "@google-cloud/storage";
const client = new Storage({ projectId: "my-project" });
const storage = createGcsStorage({ bucket: "my-shelf", client });
interface GcsStorageOptions {
bucket: string; // required GCS bucket name
prefix?: string; // optional key prefix, defaults to ""
client?: Storage; // optional pre-configured @google-cloud/storage client
projectId?: string; // optional GCP project id
keyFilename?: string; // optional path to service-account JSON
credentials?: object; // optional service-account credentials object
apiEndpoint?: string; // optional custom endpoint (emulator)
}

Options at a glance:

OptionRequiredNotes
bucketyesGCS bucket name
prefixnoKey prefix for every object
clientnoPre-built Storage client (tests, custom endpoint)
projectIdnoGCP project ID (defaults to ADC)
keyFilenamenoPath to service-account JSON
credentialsnoInline service-account object
apiEndpointnoCustom endpoint (emulator, e.g. http://localhost:9090)

Auth otherwise uses Application Default Credentials.

createGcsStorage(options: GcsStorageOptions): StorageAdapter

Section titled “createGcsStorage(options: GcsStorageOptions): StorageAdapter”

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

gcsKey(prefix: string, path: string): string

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

Helper that joins a storage prefix with a relative path into an object key.

Use GCS for GCP deploys — Cloud Run, GKE, or Cloud Functions — especially paired with db-postgres. It is a drop-in replacement for local storage, S3, and Azure Blob.