The Stytch Management Node.js library makes it easy to use Stytch's Programmatic Workspace Actions API in Node.js applications.
This library requires Node.js 20 or later.
Warning
This SDK is currently in alpha with potential breaking changes. Use with caution in production environments.
npm install stytch-managementYou need your Stytch Management API credentials from the workspace management section of your Stytch Dashboard.
Note: These credentials allow you to perform read and write actions on your workspace, potentially modifying or deleting important Stytch resources like projects, environments, or secrets.
This library supports project- and environment-level actions on the following resources:
- Projects
- Environments
- Country Code Allowlists
- Email Templates
- Default Email Templates
- Environment Metrics
- Event Log Streaming
- JWT Templates
- Password Strength Configuration
- Public Tokens
- RBAC Policies (B2B & Consumer)
- Redirect URLs
- SDK Configuration (B2B & Consumer)
- Secrets
- Trusted Token Profiles
- PEM Files
import { ManagementClient, ClientConfig } from "stytch-management";
// Set your Stytch Management API credentials.
const config: ClientConfig = {
workspace_key_id: process.env.STYTCH_WORKSPACE_KEY_ID!,
workspace_key_secret: process.env.STYTCH_WORKSPACE_KEY_SECRET!,
};
const client = new ManagementClient(config);import { projects } from "stytch-management";
const response = await client.projects.create({
name: "My new project",
vertical: "B2B" as projects.Vertical,
});
const newProject = response.project;
console.log(`Created project: ${newProject.projectSlug}`);import { environments } from "stytch-management";
const response = await client.environments.getAll({
projectSlug: newProject.projectSlug,
});
const liveEnv = response.environments.find(
(env) => env.type === ("LIVE" as environments.EnvironmentType)
);
console.log(`Live environment: ${liveEnv?.environmentSlug}`);const response = await client.environments.create({
projectSlug: newProject.projectSlug,
name: "My custom environment",
type: "TEST" as environments.EnvironmentType,
});
const customEnv = response.environment;
console.log(`Created environment: ${customEnv.environmentSlug}`);const response = await client.secrets.create({
projectSlug: newProject.projectSlug,
environmentSlug: liveEnv.environmentSlug,
});
const secret = response.secret;
console.log(`Created secret: ${secret.secretID}`);const response = await client.sdk.getConsumerConfig({
projectSlug: newProject.projectSlug,
environmentSlug: liveEnv.environmentSlug,
});
console.log("Consumer SDK config:", response.config);All request and response types are fully typed. Import them from the specific resource namespaces:
import { projects, environments, secrets } from "stytch-management";
// Use typed requests
const createRequest: projects.CreateRequest = {
name: "My project",
vertical: "B2B",
};
// Responses are also typed
const response: projects.CreateResponse = await client.projects.create(
createRequest
);import { ManagementStytchError } from "stytch-management";
try {
await client.projects.get({ projectSlug: "invalid-slug" });
} catch (error) {
if (error instanceof ManagementStytchError) {
console.error(`Stytch error: ${error.error_type}`);
console.error(`Message: ${error.error_message}`);
console.error(`Request ID: ${error.request_id}`);
}
throw error;
}This library includes comprehensive integration tests that verify functionality against the Stytch API. These tests create and clean up disposable projects and resources.
To run the tests, you need valid Stytch Management API credentials:
export STYTCH_WORKSPACE_KEY_ID="your-workspace-key-id"
export STYTCH_WORKSPACE_KEY_SECRET="your-workspace-key-secret"Important: Tests will be skipped if these environment variables are not set. The tests create real resources in your workspace but clean them up automatically.
# Install dependencies
npm install
# Run all tests
npm test
# Run tests with verbose output
npm test -- --verbose# Run a specific test file
npm test -- lib/projects.test.ts
# Run tests matching a pattern
npm test -- --testNamePattern="Secrets"The test suite includes integration tests for:
- Email Templates - Create, get, update, delete, and default management
- Environments - Environment lifecycle with user locking and IDP configurations
- Secrets - Secret creation, retrieval, and deletion
- Public Tokens - Public token management
- JWT Templates - Session and M2M JWT template configuration
- Redirect URLs - URL validation and type management
- Password Strength Config - LUDS and ZXCVBN policy configuration
- Country Code Allowlist - SMS and WhatsApp country code management
Each test suite:
- ✓ Creates disposable projects/environments
- ✓ Tests all CRUD operations
- ✓ Validates error handling
- ✓ Cleans up all resources automatically
- ✓ Runs independently without side effects
Tests use Jest and provide detailed output:
PASS lib/secrets.test.ts
Secrets Integration Tests
Create
✓ should create secret (234ms)
Get
✓ should get existing secret (156ms)
✓ should fail when secret does not exist (89ms)
GetAll
✓ should get all secrets (445ms)
Delete
✓ should delete existing secret (178ms)
Tests are designed to run in CI environments. Set the environment variables in your CI configuration:
# Example GitHub Actions
env:
STYTCH_WORKSPACE_KEY_ID: ${{ secrets.STYTCH_WORKSPACE_KEY_ID }}
STYTCH_WORKSPACE_KEY_SECRET: ${{ secrets.STYTCH_WORKSPACE_KEY_SECRET }}See DEVELOPMENT.md for information on building and testing the SDK.
See the Stytch API Reference for complete documentation on the Management API endpoints.
If you've found a bug, open an issue!
If you have questions or want help troubleshooting, join us in Slack or email support@stytch.com.
If you've found a security vulnerability, please follow our responsible disclosure instructions.
Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
MIT