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 ships a set of validation utilities that plug into the Riven startup sequence and into individual BullMQ job processors. These utilities cover three areas: startup validation (deciding whether a plugin should load at all), error classification (telling BullMQ whether a failed job should be retried), and Zod schema helpers for encoding, decoding, and refining structured data.
Startup validation flow
Every plugin exports avalidator function. Riven calls it after parsing the plugin’s settings and before the plugin is considered ready to receive events:
validator receives a DataSourceMap (all DataSources already instantiated) and the PluginSettings instance. It must return Promise<boolean> (or the synchronous boolean — the schema accepts Promisable<boolean>):
BaseDataSource.validate() is the standard pattern because the DataSource already has the settings object and the HTTP client ready to go.
FatalValidationError
FatalValidationError extends Error and its name is "FatalValidationError". Throw it from either your plugin’s validator function or from BaseDataSource.validate() when the failure is permanent — when retrying will never succeed because the configuration is fundamentally wrong.
UnrecoverableError
UnrecoverableError is re-exported from BullMQ via the SDK and used inside job processors (hooks and DataSource workers) to signal that this specific job should not be retried, even if retries are configured. The job moves directly to the failed state.
BaseDataSource uses it internally when it cannot decode a request body:
Zod codecs
json(schema)
Encodes/decodes between a raw JSON string and a fully-typed parsed object. The codec validates the decoded value against the provided Zod schema.
json() is built on z.codec() from Zod, so it integrates naturally with other Zod schema compositions. If the input string is not valid JSON, a z.ZodError is thrown with code: "invalid_format" and format: "json".
urlSearchParamsCodec
A pre-built codec that encodes/decodes between a query-string (string) and a URLSearchParams instance.
BaseDataSource uses this codec internally to serialise request params for BullMQ job payloads (which must be JSON-serialisable) and to restore them before performing the actual HTTP fetch.
Zod refinement helpers
atLeastOnePropertyRequired(obj, fields?)
Returns true if at least one property of obj (optionally filtered to fields) is non-null and non-empty. “Empty” means null, undefined, "", 0, or [].
fields array restricts which keys are checked. If fields is omitted, all keys in the object are evaluated.
recordIsNotEmpty(obj)
Returns true if the plain object has at least one key. Useful as a Zod .refine() predicate to reject empty result maps.
BaseDataSource.validate() best practices
validate() is the abstract method every BaseDataSource subclass must implement. It is called at startup and can be re-triggered via a GraphQL query. Follow these patterns:
Use the cheapest endpoint
Prefer a
/health, /ping, or /status endpoint over a data endpoint. If no health endpoint exists, a lightweight read (e.g. fetching your own user profile) works well.Return false for transient errors
Wrap the call in
try/catch. Return false for network timeouts or 5xx responses — Riven will retry. This lets the plugin eventually come online after a brief API outage.Throw FatalValidationError for auth failures
When the response clearly indicates bad credentials (401, 403, or a specific error body) throw
FatalValidationError so the operator gets an immediate, actionable error message.Cache auth tokens
If validation involves obtaining an auth token (like TVDB’s
/login), cache the token as a private field. The validate() method can then double as the token-refresh path used by all subsequent requests.Complete example: TVDB validate()
willSendRequest calls read this.#token.value without hitting /login again.