import 'server-only'; import type { SmartCdnUrlParams } from '@transloadit/utils/node'; import type { ReactNode } from 'react'; import type { StoragePreviewFormats } from '../index.ts'; import type { TransloaditImageLayoutProps } from './index.tsx'; import type { StorageImageCatalog, StorageImageLayoutProps } from './layout.ts'; /** Values available to application authorization before a Storage redirect is issued. */ export interface TransloaditImageAuthorizationContext { path: string; /** Pinned Storage identity; absent for customer HTTP/S3 Template inputs. */ asset_id?: string; version_id?: string; request: Request; workspace: string; template: string; } /** * Return true to authorize a signed rendition. Usually the object is private; legacy capabilities * beyond public rendition limits still need authorization after publication. Thrown errors propagate. */ export type AuthorizeTransloaditImage = (context: TransloaditImageAuthorizationContext) => boolean | Promise; /** Request-authorized, byte-pass-through-free Storage delivery through a local route. */ export interface TransloaditImageRedirectDelivery { authorize: AuthorizeTransloaditImage; /** Server-declared public directories: use unsigned, direct CDN delivery. */ public?: readonly string[]; /** Next.js `basePath` prepended only to browser-facing route URLs. */ basePath?: string; /** Opt-in browser caching; capped at the rotation interval. Delays reauthorization. */ cacheMaxAgeMs?: number; /** Internal App Router path that exports `imageRoute`, for example `/api/private-images`. */ route: string; } /** A maximum grant age, in milliseconds or an explicit duration such as "1h" or "365d". */ export type StorageImageLifetime = number | `${number}${'ms' | 's' | 'm' | 'h' | 'd'}`; interface StorageImageOptions { /** Trusted key override; otherwise resolved from the server environment on first use. */ authKey?: string; /** Trusted secret override; otherwise resolved from the server environment on first use. */ authSecret?: string; /** Explicit workspace; otherwise resolved from TRANSLOADIT_WORKSPACE on first use. */ workspace?: string; /** Catalog transport overrides, or direct signing inside a request-authorized page. */ delivery?: 'direct' | { baseUrl?: string; urlParams?: SmartCdnUrlParams; }; /** Catalog keys become typed src references; values provide intrinsic geometry. */ images?: Catalog; /** Defaults to public and catalog directories, plus exact root-level catalog paths. */ allowedPathPrefixes?: readonly string[]; /** Explicitly allow every object in the workspace, including root-level paths. */ allowWorkspaceRoot?: boolean; /** Server-declared public directories. These render unsigned URLs without keys or expiry. */ public?: readonly string[]; /** Opt into a redirect handler; private objects require this check for every uncached request. */ authorize?: AuthorizeTransloaditImage; /** Defaults to /api/storage-images when authorize is provided. */ route?: string; basePath?: string; /** Opt-in private browser caching, capped at rotation and remaining grant age. */ cacheMaxAge?: StorageImageLifetime; /** @deprecated Use cacheMaxAge with a duration such as '1m'. */ cacheMaxAgeMs?: number; /** Maximum private CDN grant age, at most 48h; defaults to 1h. Public URLs never expire. */ lifetime?: StorageImageLifetime; /** Stable signature bucket, at most half the private lifetime. Defaults to min(lifetime / 2, one hour). */ rotationInterval?: StorageImageLifetime; /** @deprecated Use rotationInterval with a duration such as '30m'. */ rotationIntervalMs?: number; /** Trusted development endpoint override; never derive this from request data. */ baseUrl?: string; /** Trusted compatible signed Template override for Storage previews. */ template?: string; /** Trusted unsigned public Template override; independent of the private Template. */ publicTemplate?: string; /** Trusted transport parameters appended to every signed URL, such as `cdn=required`. */ urlParams?: SmartCdnUrlParams; } /** One flat policy with either a catalog, explicit prefixes (including deny-all []), or root access. */ export type ImageConfiguration = StorageImageOptions & ({ images: Catalog extends undefined ? never : Catalog; } | { allowedPathPrefixes: readonly string[]; } | { allowWorkspaceRoot: true; }); /** Request-authorized private delivery with the same flat configuration as direct delivery. */ export type AuthorizedImagesConfiguration = ImageConfiguration & { authorize: AuthorizeTransloaditImage; }; /** Props for a Transloadit Storage preview, optionally typed from a rendering catalog. */ export type TransloaditImageProps = TransloaditImageLayoutProps & StorageImageLayoutProps & { /** Opaque JPEG background as #rrggbb or #rrggbbff. Defaults to white. */ fallbackBackground?: string; /** Encoding quality for the signed JPEG fallback. Defaults to 75. */ fallbackQuality?: number; formats?: StoragePreviewFormats; /** Opt-in receipt blur; request-authorized private redirects do not expose placeholder pixels. */ placeholder?: 'blur' | 'empty'; /** Static shell used only while direct request-time signing is suspended. */ suspenseFallback?: ReactNode; /** Advanced candidate override. Defaults to a conservative ladder capped at `width`. */ widths?: readonly number[]; }; /** Redirect images render synchronously and have no signing suspension to replace. */ export type TransloaditRedirectImageProps = TransloaditImageProps & { suspenseFallback?: never; }; /** One configured Next.js Server Component for Transloadit Storage objects. */ export type TransloaditImageComponent = (props: TransloaditImageProps) => ReactNode; /** A Next.js route handler that authorizes and redirects one private image request. */ export type TransloaditImageRoute = (request: Request) => Promise; /** Direct-delivery integration. Image bytes and requests bypass the Next.js server. */ export interface TransloaditImageIntegration { Image: TransloaditImageComponent; } /** Redirect-delivery integration with a route handler for private Storage images. */ export interface TransloaditRedirectImageIntegration { Image: (props: TransloaditRedirectImageProps) => ReactNode; imageRoute: TransloaditImageRoute; } /** Reads rendering credentials once on first render/request, not while importing the factory. */ export declare function createImages(configuration: AuthorizedImagesConfiguration): TransloaditRedirectImageIntegration; export declare function createImages(configuration: ImageConfiguration): TransloaditImageIntegration; export {}; //# sourceMappingURL=server.d.ts.map