Skip to main content

Types

This page documents the shared type definitions used across Pixstore frontend and backend.

Some types on this page are internal and not exported.

All exported types can be imported from the pixstore/types entrypoint:

import type { ImageRecord, ImageFetcher } from 'pixstore/types'

Exported Types

ImageRecord

Represents a reference to an image stored in Pixstore, including the ID, access token, decryption metadata, and a stateless proof required for secure access.

Used to fetch and decrypt images on the frontend and for all access/authorization calls.

Definition

export interface ImageRecord {
id: string // Unique ID used to locate and identify the image
token: number // Used for cache validation and version control
meta: ImageDecryptionMeta // Metadata required to decrypt the image (key, IV, tag, format)
statelessProof: string // Stateless, time-based proof-of-access hash for endpoint authorization
}

Fields

NameTypeDescription
idstringUnique identifier of the image
tokennumberUsed for cache validation and versioning
metaImageDecryptionMetaDecryption metadata: key, IV, tag, format, etc.
statelessProofstringStateless time-based proof-of-access for secure endpoint requests

📄 Source: src/types/image-record.ts


ImageFetcher

Type definition for Pixstore’s image fetching logic, including all parameters required for secure access. This function receives all access data as an object and returns a Promise<Uint8Array> containing the wire-format image payload.

Definition

export type ImageFetcher = (
imageRecord: ImageRecord, // Includes id, token, decryption meta, and stateless proof
context?: unknown, // Optional context (user, session, etc.)
) => Promise<Uint8Array>

Fields (Function Parameters)

NameTypeDescription
imageRecordImageRecordFull metadata and token/proof information about the image.
contextanyOptional user/session data passed from getImage().

📄 Source: src/types/image-fetcher.ts


Internal Types

ImageDecryptionMeta

Metadata required to decrypt an encrypted image in Pixstore.

This object is used internally and included as part of each ImageRecord.

Definition

export interface ImageDecryptionMeta {
key: string // Base64-encoded AES-GCM encryption key
iv: string // Initialization vector (IV) for AES-GCM, base64-encoded
tag: string // Authentication tag for AES-GCM, base64-encoded
}

Fields

NameTypeDescription
keystringBase64-encoded AES-GCM encryption key
ivstringBase64-encoded initialization vector (IV)
tagstringBase64-encoded authentication tag

📄 Source: src/types/image-record.ts


PixstoreBackendConfig

Configuration object for customizing Pixstore’s backend storage, server, and error handling.

All fields are optional; any missing values are filled using Pixstore’s internal defaultConfig.

Definition

export interface PixstoreBackendConfig {
imageFormats: readonly ImageFormat[]
imageRootDir: string
databasePath: string
statelessKeyWindowLength: number
defaultEndpointEnabled: boolean
defaultEndpointListenHost: string
defaultEndpointListenPort: number
defaultEndpointRoute: string
accessControlAllowOrigin: string
errorHandlingMode: ErrorHandlingMode
}

Fields

PropertyTypeDefault (non-test)Description
imageFormatsImageFormat[]['png', 'jpeg', 'webp']Allowed image formats
imageRootDirstring'pixstore-images'Folder where images are saved
databasePathstring'./.pixstore.sqlite'Path to SQLite metadata DB
statelessKeyWindowLengthnumber20000Time window (ms) for stateless proof generation (-1 for static)
defaultEndpointEnabledbooleantrueWhether to expose the default GET image endpoint
defaultEndpointRoutestring'/pixstore-image'Route path for the default image endpoint
defaultEndpointListenHoststring'0.0.0.0'Host/IP where the image endpoint HTTP server listens
defaultEndpointListenPortnumber3001Port where the image endpoint HTTP server listens
accessControlAllowOriginstring'*'CORS Access-Control-Allow-Origin header for the default route
errorHandlingModeErrorHandlingMode'hybrid'Error handling strategy for Pixstore API calls.

ℹ️ When running in test mode (IS_TEST === true), values like paths and ports are automatically randomized or sandboxed.


📄 Source: src/types/pixstore-config.ts


PixstoreFrontendConfig

Configuration object for customizing Pixstore’s frontend image caching, database, and endpoint connection.

All fields are optional; any missing values are filled using Pixstore’s internal defaultConfig.

Definition

export interface PixstoreFrontendConfig {
imageFormats: readonly ImageFormat[]
frontendDbName: string
frontendDbVersion: number
imageStoreName: string
frontendImageCacheLimit: number
frontendCleanupBatch: number
defaultEndpointConnectHost: string
defaultEndpointConnectPort: number
defaultEndpointRoute: string
errorHandlingMode: ErrorHandlingMode
}

Fields

PropertyTypeDefault (non-test)Description
imageFormatsImageFormat[]['png', 'jpeg', 'webp']Allowed image formats
frontendDbNamestring'pixstore'IndexedDB database name
frontendDbVersionnumber1IndexedDB schema version
imageStoreNamestring'images'Object store name for image records
frontendImageCacheLimitnumber1000Maximum number of images to keep in the local cache
frontendCleanupBatchnumber50Number of items to remove per cleanup cycle when limit is exceeded
defaultEndpointConnectHoststring'unknown'Host to contact for image fetching (used if no custom fetcher is provided)
defaultEndpointConnectPortnumber3001Port to contact for image fetching
defaultEndpointRoutestring'/pixstore-image'Route to contact for image fetching
errorHandlingModeErrorHandlingMode'hybrid'Error handling strategy for Pixstore API calls.

ℹ️ In test mode (IS_TEST === true), database names and limits are automatically sandboxed.


📄 Source: src/types/pixstore-config.ts


ErrorHandlingMode

Enumerates the possible error handling strategies for Pixstore API calls.

Used in Pixstore configuration to control error propagation and reporting across all modules.

Note: This type is internal and not exported. It cannot be imported directly.

Definition

export type ErrorHandlingMode =
| 'hybrid'
| 'throw'
| 'warn'
| 'silent'
| 'custom'

Fields

ValueDescription
hybridLogs and returns null for PixstoreError (expected errors); throws all other errors.(default)
throwThrows all errors (default in test environments).
warnLogs any error and returns null.
silentIgnores any error and returns null.
customCalls a user-provided error handler; all error logic must be handled in your handler.

Note: If you use errorHandlingMode: 'hybrid' (the default), you can optionally use getLastPixstoreError() for advanced error debugging and reporting. If you use errorHandlingMode: 'custom', you must provide a custom error handler using setCustomErrorHandler(); otherwise, Pixstore will throw an error.


📄 Source: src/types/error-handling-mode.ts

📄 Source: src/shared/handle-error.ts