Configure Documenso across multiple environments (dev, staging, production).
Use when setting up environment-specific configurations, managing API keys,
or implementing environment promotion workflows.
Trigger with phrases like "documenso environments", "documenso staging",
"documenso dev setup", "multi-environment documenso".
Configure Documenso across development, staging, and production with environment isolation, secret management, and promotion workflows. Documenso cloud offers a staging environment at stg-app.documenso.com; self-hosted users run separate instances.
Prerequisites
Documenso accounts or instances for each environment
Secret management solution (Vault, AWS Secrets Manager, or .env files)
// src/documenso/factory.ts
import { Documenso } from "@documenso/sdk-typescript";
interface EnvConfig {
apiKey: string;
baseUrl: string;
webhookSecret: string;
}
function getConfig(): EnvConfig {
const apiKey = process.env.DOCUMENSO_API_KEY;
if (!apiKey) throw new Error("DOCUMENSO_API_KEY required");
return {
apiKey,
baseUrl: process.env.DOCUMENSO_BASE_URL ?? "https://app.documenso.com/api/v2",
webhookSecret: process.env.DOCUMENSO_WEBHOOK_SECRET ?? "",
};
}
let client: Documenso | null = null;
export function getClient(): Documenso {
if (!client) {
const config = getConfig();
client = new Documenso({
apiKey: config.apiKey,
serverURL: config.baseUrl,
});
}
return client;
}
export function getWebhookSecret(): string {
return getConfig().webhookSecret;
}
// Reset for testing
export function resetClient(): void {
client = null;
}
Step 3: Environment Guards
// src/guards.ts
function requireProduction() {
if (process.env.NODE_ENV !== "production") {
throw new Error("This operation requires production environment");
}
}
function blockProduction(operation: string) {
if (process.env.NODE_ENV === "production") {
throw new Error(`${operation} is blocked in production`);
}
}
// Usage
async function deleteAllDrafts(client: Documenso) {
blockProduction("deleteAllDrafts"); // Safety guard
// ... only runs in dev/staging
}
async function sendBulkContracts(client: Documenso) {
requireProduction(); // Only send real contracts in prod
// ...
}