notion-client module provides a shared Notion SDK client instance and environment-based database ID accessors. All workers use these functions to ensure consistent credential management.
getNotionClient
Returns a cached Notion SDK client instance authenticated withNOTION_TOKEN.
Behavior
- Reads
NOTION_TOKENfromprocess.env - Caches the client instance for reuse across worker invocations
- Throws if
NOTION_TOKENis not set
Example
getDocsDatabaseId
Returns the Docs database ID fromDOCS_DATABASE_ID environment variable.
Throws
ErrorifDOCS_DATABASE_IDis not set in environment
Example
getHomeDocsDatabaseId
Returns the Home Docs database ID fromHOME_DOCS_DATABASE_ID environment variable.
Throws
ErrorifHOME_DOCS_DATABASE_IDis not set in environment
Example
getTasksDatabaseId
Returns the Tasks database ID fromTASKS_DATABASE_ID environment variable.
Throws
ErrorifTASKS_DATABASE_IDis not set in environment
Example
Environment Variables
All functions require these environment variables to be set:| Variable | Purpose | Required By |
|---|---|---|
NOTION_TOKEN | Notion integration token | All workers |
DOCS_DATABASE_ID | Docs database ID | write-agent-digest, check-upstream-status |
HOME_DOCS_DATABASE_ID | Home Docs database ID | write-agent-digest, check-upstream-status |
TASKS_DATABASE_ID | Tasks database ID | create-handoff-marker |
Implementation Notes
Client caching
Client caching
The Notion client is instantiated once and cached in module scope. Subsequent calls to
getNotionClient() return the same instance, avoiding unnecessary authentication overhead.Fail-fast validation
Fail-fast validation
All accessor functions throw immediately if the required environment variable is missing. This follows the “fail fast” design principle from the architecture—better to crash early with a clear error than to proceed with invalid state.
Deployment credentials
Deployment credentials
In production (via
ntn workers deploy), set these secrets using:Related
Credentials Setup
Configure environment variables and secrets
Architecture
Understand the shared module layer