btpet
v1.0.0
Published
CLI tool for Banho e Tosa Pet - Pet Shop Management System
Downloads
3
Maintainers
Readme
@banhoetosapet/cli
CLI tool for Banho e Tosa Pet - Pet Shop Management System
Installation
pnpm add -g @banhoetosapet/cliOr run directly with npx:
npx @banhoetosapet/cliDevelopment
When developing locally:
# From the CLI directory
cd packages/cli
pnpm cli [command]Quick Start
# Initialize a profile for development
btpet init --profile dev --dev
# Initialize a profile for production (default)
btpet init --profile prod
# Login
btpet auth login -e [email protected] -p yourpassword
# Switch between profiles
btpet auth use dev
btpet auth use prodDebug Mode
Enable debug mode to see detailed information about API requests and responses:
# Basic debug mode - shows API logs and timing
btpet --debug auth me
# Verbose mode - shows everything including SQL queries
btpet --verbose auth me
# Environment variables (alternative)
BTPET_DEBUG=true btpet auth me
BTPET_VERBOSE=true btpet auth meDebug information includes:
- Application logs from the backend
- SQL queries and their execution time
- Request/response timing
- Error details and stack traces
Commands
Authentication
# Login
btpet auth login -e [email protected] -p password
# Login with JSON data
btpet auth login --data '{"email":"[email protected]","password":"password"}'
# Login with specific organization (non-interactive)
btpet auth login -e [email protected] -p password --org-id org_123
btpet auth login --data '{"email":"[email protected]","password":"password","orgId":"org_123"}'
# Login with organization reference code
btpet auth login -e [email protected] -p password --ref PET-0147
btpet auth login --data '{"email":"[email protected]","password":"password","ref":"PET-0147"}'
# Login without saving to profile
btpet auth login -e [email protected] -p password --no-save
# Get token for scripts (never saves to profile)
btpet auth token -e [email protected] -p password
btpet auth token --data '{"email":"[email protected]","password":"password"}'
# Get token with organization
btpet auth token -e [email protected] -p password --org-id org_123
btpet auth token --data '{"email":"[email protected]","password":"password","orgId":"org_123"}'
# Get token with JSON output
btpet auth token -e [email protected] -p password --json
btpet auth token --data '{"email":"[email protected]","password":"password"}' --json
# List available organizations (table format)
btpet auth orgs list
btpet auth orgs list --json
# Show current organization details
btpet auth org
btpet auth org --json
# Logout
btpet auth logout
btpet auth logout --force # Skip confirmation
# Show current user info
btpet auth me
btpet auth me --json # JSON output
btpet auth me --all # Show info for all profiles
btpet auth me --all --json # All profiles in JSON
# Profile management
btpet auth profiles # List all profiles in table format
btpet auth profiles --json # JSON output
btpet auth use <profile> # Switch active profile
btpet auth current # Show current profile
btpet auth remove-profile <name> --force
# Switch organization (requires re-authentication)
btpet auth switch-org
btpet auth switch-org --id org_456 # Non-interactiveConfiguration
# Initialize new profile
btpet init --profile <name>
btpet init --profile <name> --dev # For localhost:3000
btpet init --profile <name> --url <custom-url>
# Show current configuration
btpet config show
btpet config show --json
# List all profiles
btpet config list
btpet config list --jsonMulti-Tenant Support
The CLI fully supports multi-tenant authentication with master tokens:
- Users without organizations: Receive a master token without organization context
- Users with one organization: Automatically selected, receive organization-scoped token
- Users with multiple organizations: Receive master token, then select organization
Login Flow
# Single organization - automatic selection
btpet auth login -e [email protected] -p password
# ✓ Login successful
# Organization: Pet Shop ABC (OWNER)
# Multiple organizations - interactive selection
btpet auth login -e [email protected] -p password
# ⚠ Multiple organizations found. Please select one:
# > Pet Shop ABC (OWNER)
# Pet Shop XYZ (ADMIN)
# Direct organization selection (skip interactive)
btpet auth login -e [email protected] -p password --org-id org_123Organization Management
# List user's organizations
btpet auth orgs list
# Show current organization details
btpet auth org
# Shows organization name, reference code, ID, role, etc.
# Switch between organizations (uses cached master token)
btpet auth switch-org
# > Select organization: [shows all available orgs]
# Switch directly to specific organization by ID
btpet auth switch-org --id org_456
# Switch using organization reference code (e.g., PET-0147)
btpet auth switch-org --ref PET-0147Organization Reference Codes
Organizations now have human-readable reference codes for easier identification:
- Format:
ABC-1234(3 letters + 4 digits with check digit) - Examples:
STA-0005,PSD-0007,PET-0147 - Use reference codes with
--refin commands that accept organization identifiers
# Login directly to organization using reference code
btpet auth login -e [email protected] -p password --ref STA-0005
# Get token for specific organization using reference
btpet auth token -e [email protected] -p password --ref PET-0147
# Switch organization using reference
btpet auth switch-org --ref PSD-0007Token Types
The system uses two types of tokens:
- Master Token: Valid for 24h (or 30d with --remember-me), used to generate organization tokens
- Organization Token: Valid for 8h, contains organization context and permissions
# Get master token (for users with multiple orgs)
btpet auth token -e [email protected] -p password
# Returns: eyJ... (master token)
# Get organization-specific token
btpet auth token -e [email protected] -p password --org-id org_123
# Returns: eyJ... (organization token)Special Cases
# Users without organizations
btpet auth switch-org
# ✗ You don't have access to any organizations.
# This user account is not associated with any organizations.
# Users with single organization
btpet auth switch-org
# Current organization: Pet Shop Demo (ADMIN)
# You only have access to one organization.Profiles
The CLI supports multiple profiles for different environments and users:
# Initialize profiles
btpet init --profile dev --dev # Uses http://localhost:3000
btpet init --profile prod # Uses https://api.banhoetosa.pet
btpet init --profile custom --url https://api.custom.com
# Login to different profiles
btpet --profile dev auth login -e [email protected] -p password
btpet --profile prod auth login -e [email protected] -p password
# Use a specific profile for commands
btpet --profile production customers list
# Switch default profile
btpet auth use dev
btpet auth use prod
# List all profiles (shows in table format)
btpet auth profiles
# Remove a profile
btpet auth remove-profile old-profile --forceEnvironment Variables
BTPET_PROFILE: Set the active profileBTPET_API_URL: Override the API URLBTPET_TOKEN: Override the auth token
Examples
JSON Output Support
Most commands support the --json flag for machine-readable output:
# Authentication commands
btpet auth me --json
btpet auth profiles --json
btpet auth orgs list --json
btpet auth org --json
# Configuration commands
btpet config show --json
btpet config list --json
# Combined with other options
btpet auth me --all --json
btpet config show --profile prod --jsonClean JSON Output (Development)
When developing with pnpm, use the -s flag to suppress pnpm headers:
# Regular output (includes pnpm headers)
pnpm cli auth org --json
# Clean JSON output only
pnpm -s cli auth org --json
# Or use tsx directly
./node_modules/.bin/tsx src/index.ts auth org --jsonUsing --data for JSON Input
Many commands support the --data option to pass parameters as JSON instead of individual flags:
# Login with JSON data
btpet auth login --data '{"email":"[email protected]","password":"pass123"}'
# Complex login with multiple options
btpet auth login --data '{
"email": "[email protected]",
"password": "pass123",
"orgId": "org_123",
"rememberMe": true,
"profile": "production"
}'
# Get token with organization reference
btpet auth token --data '{"email":"[email protected]","password":"pass123","ref":"PET-0147"}'The --data option is particularly useful for:
- Scripts and automation
- Avoiding shell escaping issues
- Passing data from other programs
- Complex configurations
Non-Interactive Mode
The CLI is designed to be "non-interactive first" for easy scripting and automation:
Authentication for Scripts
# Get token for automation
TOKEN=$(btpet auth token -e $EMAIL -p $PASSWORD --org-id $ORG_ID)
# Use token directly
curl -H "Authorization: Bearer $TOKEN" https://api.example.com/data
# Or set environment variable
export BTPET_TOKEN=$TOKEN
btpet customers listSkip Confirmations
# Force actions without prompts
btpet auth logout --forceDirect Organization Selection
# Login directly to specific org
btpet auth login -e [email protected] -p pass123 --org-id org_789
# Get token without saving state
btpet auth login -e [email protected] -p pass123 --org-id org_789 --no-saveJSON Output
# Get organizations in JSON
btpet auth orgs list --json
# Get token with metadata
btpet auth token -e [email protected] -p pass123 --org-id org_789 --json
# Output: {"token": "...", "organization": {"id": "...", "name": "...", "role": "..."}}Example Script
#!/bin/bash
set -e
# Configuration
EMAIL="[email protected]"
PASSWORD="secure123"
ORG_ID="org_petshop"
# Get auth token
TOKEN=$(btpet auth token -e $EMAIL -p $PASSWORD --org-id $ORG_ID)
export BTPET_TOKEN=$TOKEN
# Use token in other scripts
curl -H "Authorization: Bearer $TOKEN" https://api.banhoetosa.pet/healthLicense
MIT
