The Auth0 Deploy CLI is a TypeScript-based tool for managing Auth0 tenant configurations through bidirectional sync (export/import) operations. It supports both YAML and directory formats with dynamic keyword replacement for multi-environment workflows.
Key Capabilities:
- Export Auth0 tenant configurations to local files (YAML or directory structure)
- Import configurations from local files to Auth0 tenants
- Keyword replacement for multi-environment deployments
- Resource-specific handlers for 30+ Auth0 resource types
# Install dependencies
npm install
# Build TypeScript to JavaScript
npm run build
# Build in watch mode during development
npm run dev
# Run unit tests
npm test
# Run E2E tests (requires Auth0 tenant)
npm run test:e2e:node-module
npm run test:e2e:cli
# Run linter
npm run lintCommon operations for working with the CLI:
# Export tenant configuration to local/
npm run build && node lib/index.js export -c config-dev.json -f directory -o ./local/
# Import configuration
npm run build && node lib/index.js import -c config-dev.json -i ./local/tenant.json
# Export as YAML
npm run build && node lib/index.js export -c config-dev.json -f yaml -o ./local-export/
# Import from YAML
npm run build && node lib/index.js import -c config-dev.json -i ./local-export/tenant.yaml- Source TypeScript files live in
src/ - Compiled JavaScript output goes to
lib/(published to npm) - Always run
npm run buildbefore testing CLI changes - Use
npm run devfor watch mode during active development
src/ # TypeScript source
├── index.ts # CLI entry point
├── commands/ # import.ts, export.ts
├── tools/ # Core logic (deploy.ts, calculateChanges.ts)
│ └── auth0/ # Auth0 API integration
│ ├── handlers/ # 30+ resource-specific handlers
│ └── schema/ # JSON validation schemas
└── context/ # Format parsers (yaml/, directory/)
test/ # Test suite mirrors src/
├── tools/auth0/handlers/ # Handler unit tests
├── context/ # Context parser tests
└── e2e/ # End-to-end tests
- Use strict TypeScript configuration (
tsconfig.json) - Define types in
src/types.tsfor shared interfaces - Follow existing patterns for handler implementations
- Use proper async/await patterns, avoid callbacks
Every resource handler in src/tools/auth0/handlers/ must implement:
class ResourceHandler {
validate(); // Schema validation using AJV
processChanges(); // CRUD operations with API calls
calcChanges(); // Determine create/update/delete ops
dump(); // Format for export
getType(); // Fetch from Auth0 API
}- All environment variables prefixed with
AUTH0_ - Config priority: CLI args → env vars → config files → defaults
- Support both direct values and JSON serialization for complex types
- Use
ValidationErrorclass fromsrc/tools/validationError.ts - Provide clear, actionable error messages
- Preserve context when bubbling errors up
- Validate early before making API calls
# Unit tests only (fast)
npm test
# E2E tests as node module
npm run test:e2e:node-module
# E2E tests as CLI (requires real tenant credentials)
npm run test:e2e:cli- Unit tests mirror
src/directory structure intest/ - Use
.test.jsor.test.tsextensions - Handler tests use sinon stubs for Auth0 clients
- Context tests use temporary directories with fixtures
- E2E tests require real Auth0 tenant (configured via env vars)
Pattern for testing resource handlers:
const mockClient = {
resource: {
getAll: sinon.stub(),
create: sinon.stub(),
update: sinon.stub(),
delete: sinon.stub(),
},
};
const mockConfig = (key) => {
const config = {
AUTH0_ALLOW_DELETE: true,
AUTH0_EXCLUDED: [],
};
return config[key];
};- Add tests for any new handlers or features
- Test both success and error paths
- Check resource identifier mapping logic
- Test keyword replacement in context parsers
# Run specific test file
npm test -- test/tools/auth0/handlers/clients.test.js
# Run tests matching pattern
npm test -- --grep "should validate clients"- Create handler in
src/tools/auth0/handlers/<resource>.ts - Implement all required methods (validate, processChanges, dump, etc.)
- Add resource type to
src/tools/constants.ts - Create JSON schema in
src/tools/auth0/schema/ - Write unit tests in
test/tools/auth0/handlers/<resource>.test.js - Add E2E test coverage if applicable
- Update documentation in
docs/resource-specific-documentation.md
- DirectoryContext (
src/context/directory/): Loads nested JSON files - YAMLContext (
src/context/yaml/): Parses single YAML file - Both support keyword patterns:
@@KEY@@(JSON-stringified) and##KEY##(literal) - Test with fixtures in
test/context/{directory,yaml}/
- Mock config functions return expected values for each key
- Test resource exclusion with
AUTH0_EXCLUDEDandAUTH0_EXCLUDED_*patterns - Test property exclusion with
EXCLUDED_PROPSandINCLUDED_PROPS - Verify keyword replacement mappings work correctly
# Always run before commit
npm run build
npm test
npm run lint- All tests pass locally
- New code has corresponding tests
- TypeScript compiles without errors
- Updated relevant documentation in
docs/ - Added entry to
CHANGELOG.mdif user-facing change - Tested with both YAML and directory formats if applicable
- Checked backward compatibility
Follow conventional commits style:
feat: add support for new resource typefix: resolve table formatting issuedocs: update handler implementation guidetest: add coverage for keyword replacementrefactor: simplify change calculation logic
- Never commit Auth0 credentials or API keys
- Config files with credentials should be gitignored
- Use environment variables for sensitive data
- Example configs use
.json.examplesuffix
- All resources validated against JSON schemas before processing
- Delete operations require explicit
AUTH0_ALLOW_DELETE=true - Resource identifiers properly sanitized before API calls
- Use dedicated development tenants for E2E tests
- Never run E2E tests against production tenants
- Credentials stored in environment variables only
- Clean up test resources after test runs
export AUTH0_DEBUG=true
npm run build && node lib/index.js import -c config.json- Build errors: Check
tsconfig.jsonand ensure all imports resolve - Handler not found: Verify resource added to
src/tools/constants.ts - Schema validation fails: Check JSON schema in
src/tools/auth0/schema/ - Keyword replacement not working: Verify mappings in config and context parser
# Check compiled output
cat lib/index.js
# Test CLI directly
node lib/index.js export -c config.json --output_folder ./test-output
# Run with verbose errors
NODE_ENV=development npm test
# Check Auth0 API pagination
AUTH0_DEBUG=true npm run test:e2e:node-module- CLI Entry (
src/index.ts) → Command routing - Commands (
src/commands/import.ts) → Load config and context - Deploy (
src/tools/deploy.ts) → Orchestrate deployment - Handlers (
src/tools/auth0/handlers/*) → Resource-specific logic - Auth0 Client (
src/tools/auth0/client.ts) → Management API calls
- Compare local assets (from YAML/directory) with remote state (from API)
- Use resource identifiers (name, id, etc.) to match resources
- Determine CREATE (new), UPDATE (changed), DELETE (removed) operations
- Respect exclusion patterns and allow-delete config
- Full documentation: See
docs/directory - Examples: Check
examples/yaml/andexamples/directory/ - Contributing: Read
CONTRIBUTING.md - Migration guide: See
docs/v8_MIGRATION_GUIDE.md - Issue templates:
.github/ISSUE_TEMPLATE/
AUTH0_DOMAIN # Tenant domain
AUTH0_CLIENT_ID # Client ID
AUTH0_CLIENT_SECRET # Client secret
AUTH0_ALLOW_DELETE=true # Enable deletions
AUTH0_KEYWORD_REPLACE_MAPPINGS # JSON mapping for replacements
AUTH0_EXCLUDED # Array of resources to exclude
AUTH0_DEBUG=true # Verbose loggingsrc/tools/deploy.ts- Main deployment orchestratorsrc/tools/calculateChanges.ts- Change detection logicsrc/tools/constants.ts- Supported resource typessrc/configFactory.ts- Configuration managementsrc/types.ts- TypeScript type definitionstest/utils.js- Test helper functions