import { Bucket } from '@google-cloud/storage'; import { App } from 'firebase-admin/app'; import { Adapter, FilesError } from '../index.js'; interface FirebaseStorageAdapterOptions { /** * Storage bucket name. Falls back to `FIREBASE_STORAGE_BUCKET`, then * `.firebasestorage.app` if `projectId` is known. The Firebase * console shows the bucket as `.appspot.com` on older projects * and `.firebasestorage.app` on newer ones — pass the literal * name from the console rather than relying on the default. */ bucket?: string; /** * GCP project ID. Falls back to `FIREBASE_PROJECT_ID`, then * `GOOGLE_CLOUD_PROJECT`, then `GCLOUD_PROJECT`. Optional — Application * Default Credentials carry a project ID and the SDK will discover it * automatically. */ projectId?: string; /** * Inline service-account credentials. Useful when you only have * `clientEmail` + `privateKey` available as separate env vars (e.g. * Vercel/Netlify) and don't want to materialize a JSON file. When neither * this nor `serviceAccountPath` is set, the SDK falls back to ADC. * Falls back to `FIREBASE_CLIENT_EMAIL` + `FIREBASE_PRIVATE_KEY`. */ credentials?: { clientEmail: string; privateKey: string; }; /** * Path to a service-account JSON file. When set, takes precedence over * inline `credentials`. Falls back to `GOOGLE_APPLICATION_CREDENTIALS`. */ serviceAccountPath?: string; /** * Existing Firebase {@link App} or `@google-cloud/storage` {@link Bucket}. * Highest precedence — when passed, all other credential options are * ignored. Useful when the consumer already initializes Firebase elsewhere * (e.g. for Firestore/Auth) and wants to share the app. */ app?: App | Bucket; /** * Origin used to build URLs from `url()`. When set, `url(key)` returns * `${publicBaseUrl}/${key}` and skips signing — appropriate for a public * bucket or a CDN in front of Firebase Storage. When unset, `url()` falls * back to a V4 signed read URL (default expiry: 1 hour). Firebase's * `?alt=media&token=...` download-token URL form is out of scope for v1; * reach for `adapter.raw` if you need it. */ publicBaseUrl?: string; /** * Default expiry, in seconds, for the V4 signed URLs returned by `url()` * when `publicBaseUrl` is not set. Defaults to 3600 (1 hour). Per-call * `url(key, { expiresIn })` overrides. GCS V4 caps at 7 days. */ defaultUrlExpiresIn?: number; /** * Internal Firebase app name. Allows multiple adapter instances pointing * at different projects to coexist without the `initializeApp()` "default * app already exists" error. Defaults to a stable name derived from the * project ID and bucket; only set this if you have a reason. */ appName?: string; } type FirebaseStorageAdapter = Adapter & { readonly bucket: string; }; declare const mapFirebaseStorageError: (err: unknown) => FilesError; declare const firebaseStorage: (opts?: FirebaseStorageAdapterOptions) => FirebaseStorageAdapter; export { type FirebaseStorageAdapter, type FirebaseStorageAdapterOptions, firebaseStorage, mapFirebaseStorageError };