TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/rivenmedia/riven-ts/llms.txt
Use this file to discover all available pages before exploring further.
@repo/util-plugin-sdk package bundles a set of focused utilities that solve common plugin authoring problems: timing async calls, managing type-safe dates, parsing environment-variable settings, mapping media items to Stremio-compatible API parameters, and validating data structures with Zod codecs. Each utility is designed to be imported individually so plugins only pull in what they need.
Helpers (lib/helpers/)
benchmark
Wraps any async function and measures its wall-clock execution time using the Web Performance API (performance.now()). Returns an object containing the original result and the elapsed time in milliseconds. Particularly useful for logging the latency of DataSource HTTP calls.
The async (or sync) function to execute and time. Called with no arguments. Must return a value —
benchmark preserves the full return type via Awaited<ReturnType<T>>.The resolved return value of
fn, typed correctly.Elapsed time in milliseconds with sub-millisecond precision, computed as
performance.now() end − start.dates
A re-export of the entire Luxon library with Settings.throwOnInvalid = true pre-configured. Importing from this module guarantees that any invalid DateTime operation throws a TypeError at the point of failure rather than silently producing an Invalid DateTime sentinel — eliminating an entire class of silent data corruption bugs.
getStremioScrapeConfig
Maps any MediaItem entity to the three-field config object expected by Stremio-compatible scraper APIs. Handles all four media item types (Movie, Show, Season, Episode) and derives the correct identifier string (:season:episode) for series content.
Any
MediaItem subclass instance (Movie, Show, Season, or Episode). Must have a non-null imdbId — throws an Error if imdbId is missing. Throws if an unsupported media item type is provided.The
:season:episode suffix for series content. null for movies.Movie→nullShow→":1:1"(first episode)Season→":<seasonNumber>:1"Episode→":<seasonNumber>:<episodeNumber>"
"movie" for Movie, "series" for all show-like types.The IMDB identifier of the media item. Taken directly from
item.imdbId.Utilities (lib/utilities/)
DataSourceMap
A typed extension of the built-in Map<DataSourceConstructor, BaseDataSource> that overrides .get() to throw when a constructor is not registered, rather than returning undefined. This makes misconfigured plugins fail fast during startup rather than producing subtle null-dereference bugs at runtime.
PluginSettings
Manages typed, prefix-namespaced plugin settings sourced from environment variables. Riven instantiates a single PluginSettings during startup, calls .set() once per plugin to register its schema, then calls .lock() to freeze all settings before any resolver runs.
Environment variable format:
Methods
Registers and parses the settings block for a given prefix. Must be called before
.lock(). Throws if settings are already locked or if no environment variables are found for the given prefix.Retrieves the previously parsed settings object for a schema. Throws if the schema was never registered via
.set().Returns: z.infer<T> — the fully parsed and validated settings object.Freezes all registered settings using a deep-freeze. Called by Riven after all plugins are registered. Any subsequent
.set() call throws. Logs a warning for any RIVEN_PLUGIN_SETTING__* variables that were not consumed by any schema.StatusCodes
A direct re-export of the StatusCodes enum from the http-status-codes package. Use it in event handler responses wherever a numeric HTTP status code is required.
Validation Codecs (lib/validation/)
These Zod utilities are exported from @repo/util-plugin-sdk/validation alongside a re-export of z from Zod itself.
json(schema)
A Zod codec that bidirectionally transforms between a raw string and a parsed JSON value. The decoded value is validated against the provided schema.
Any Zod schema. The decoded JSON value is piped through this schema before being returned.
urlSearchParamsCodec
A Zod codec that bidirectionally transforms between a query string and a URLSearchParams instance.
atLeastOnePropertyRequired(obj, fields?)
A plain function (not a Zod refinement directly) that returns true if at least one of the specified fields in obj is non-null, non-empty-string, non-zero, and non-empty-array. Pass it to z.refine() or z.superRefine().
The object to inspect.
If provided, only the listed keys are checked. If omitted, all keys are checked.
recordIsNotEmpty
A plain function that returns true if an object has at least one own key. Use it with z.refine() to ensure a record-type field is not an empty object {}.
Both
atLeastOnePropertyRequired and recordIsNotEmpty are plain boolean-returning functions, not Zod .superRefine() callbacks. Pass them directly to .refine() as the predicate argument.