@lastshotlabs/slingshot-image
npm install @lastshotlabs/slingshot-image
Functions
Section titled “Functions”createImagePlugin
Section titled “createImagePlugin”Create the slingshot-image plugin.
Registers a GET /_snapshot/image handler on the Hono app that resizes,
converts, and caches image responses. Backed by sharp when installed;
falls back to serving originals with a warning when sharp is absent.
SSRF protection: The url query parameter is validated against
config.allowedOrigins before any network fetch is attempted. Relative URLs
(starting with /) are always allowed and resolved against localhost.
Absolute URLs are only allowed when their hostname is in allowedOrigins.
Factory pattern (Rule 3): Each call to createImagePlugin() creates a
fresh, isolated cache instance. No shared mutable state between plugin
instances or app instances.
function createImagePlugin(rawConfig?: ImagePluginConfig): SlingshotPluginSource: packages/slingshot-image/src/plugin.ts
createMemoryImageCache
Section titled “createMemoryImageCache”Creates an in-memory LRU image cache adapter.
Uses a Map (insertion-order) as the backing store. When maxEntries is
reached, the oldest-inserted key is evicted on the next set() call.
This is the default cache used by createImagePlugin() when no custom
adapter is provided.
function createMemoryImageCache(opts?: MemoryImageCacheOptions): ImageCacheAdapterSource: packages/slingshot-image/src/cache.ts
Classes
Section titled “Classes”ImageTransformError
Section titled “ImageTransformError”Error thrown when image transform parameters violate configured limits.
Source: packages/slingshot-image/src/types.ts
Interfaces
Section titled “Interfaces”ImageCacheAdapter
Section titled “ImageCacheAdapter”Cache adapter interface for image responses.
Implement this to plug in custom storage (Redis, file system, etc.). The default implementation uses an in-memory LRU map.
Source: packages/slingshot-image/src/types.ts
ImageCacheEntry
Section titled “ImageCacheEntry”A cached image entry stored by the cache adapter.
Source: packages/slingshot-image/src/types.ts
ImagePluginConfig
Section titled “ImagePluginConfig”Configuration for createImagePlugin().
Source: packages/slingshot-image/src/types.ts
ImageTransformOptions
Section titled “ImageTransformOptions”Options controlling how an image is transformed.
Source: packages/slingshot-image/src/types.ts
ImageTransformResult
Section titled “ImageTransformResult”The result of a successful image transformation.
Source: packages/slingshot-image/src/types.ts
ImageFormat
Section titled “ImageFormat”Supported output image formats for the image optimization handler.
Source: packages/slingshot-image/src/types.ts