# Pennyzo API Status Checker Node.js scripts for checking the status of all primary endpoints of the Pennyzo General API. This package includes two versions of the script: - `api-status-checker.js` - Basic version with console output - `api-status-checker-extended.js` - Extended version with report generation and additional features ## Overview These scripts test both public and authenticated endpoints of the Pennyzo General API and log the results to the console. The scripts perform the following checks: ### Public Endpoints: - GET `/system/health` - GET `/registration/company/identity-rules` ### Authentication Flow: - POST `/auth/login` (using placeholder credentials) ### Authenticated Endpoints (only if login is successful): - GET `/auth/me` - GET `/users/profile` - GET `/users/stats` - GET `/users/membership-info` ## Requirements - Node.js (version 14 or higher recommended) - npm packages: - axios (for HTTP requests) - chalk (for colorful console output) ## Installation Both required packages are already installed in the project. ## Usage ### Using npm Scripts (Recommended) The following npm scripts are available for checking API status: ```bash # Run basic API check npm run api:check # Run extended API check with report generation npm run api:check:extended # Run extended API check with verbose output npm run api:check:verbose # Run extended API check with real credentials npm run api:check:real ``` ### Direct Node Execution To run the scripts directly with Node: #### Basic Script ```powershell node scripts/api-status-checker.js ``` #### Extended Script ```powershell node scripts/api-status-checker-extended.js [options] ``` Available options: - `--verbose`: Show detailed response data - `--no-report`: Don't save a report file - `--use-real-credentials`: Use credentials from environment variables ### Helper PowerShell Script For additional flexibility, a PowerShell helper script is provided: ```powershell .\scripts\run-api-check.ps1 [-Verbose] [-NoReport] [-UseRealCredentials] [-Extended] ``` Examples: ```powershell # Run basic script .\scripts\run-api-check.ps1 # Run extended script with verbose output .\scripts\run-api-check.ps1 -Extended -Verbose # Run extended script with real credentials .\scripts\run-api-check.ps1 -Extended -UseRealCredentials ``` ## Configuration ### Basic Configuration You can modify the test credentials in the script to use valid credentials for testing authenticated endpoints: ```javascript // Test credentials (replace with actual test credentials if available) const TEST_CREDENTIALS = { email: "your-test-email@example.com", password: "your-test-password", }; ``` ### Environment Variables For the extended script, you can set environment variables for secure credential management: ```powershell $env:PENNYZO_TEST_EMAIL = "your-test-email@example.com" $env:PENNYZO_TEST_PASSWORD = "your-test-password" ``` Then run with the `--use-real-credentials` flag: ```powershell node scripts/api-status-checker-extended.js --use-real-credentials ``` ## Output The script provides detailed output for each API call: - Endpoint being tested - HTTP method - Status (SUCCESS or FAILED) - HTTP status code - Error details (if applicable) For the system health endpoint, additional information is displayed: - API Status - Environment - Version - Message ## Features ### Basic Script - Tests both public and authenticated endpoints - Colorful console output with chalk - Clear status indicators ### Extended Script (Additional Features) - Saves detailed reports to JSON files (in a `reports` folder) - Provides response time measurements - Supports command line arguments - Environment variable support for credentials - Verbose mode for detailed output - Summary statistics ## Example Output ### Basic Script Output ``` === Pennyzo General API Status Checker === --- Testing Public Endpoints --- GET /system/health: SUCCESS (200) API Status: operational Environment: production Version: 1.0.0 Message: Service is healthy GET /registration/company/identity-rules: SUCCESS (200) --- Testing Authentication Flow --- POST /auth/login: FAILED (401) Error: Request failed with status code 401 Details: { "error": { "type": "unauthorized", "code": 401, "message": "Invalid credentials" } } Authentication failed. Cannot test authenticated endpoints. Note: This is expected if using placeholder credentials. To test authenticated endpoints, update the TEST_CREDENTIALS with valid credentials. === API Status Check Complete === ``` ### Extended Script Output ``` === Pennyzo General API Status Checker === Timestamp: 2025-09-25T10:15:30.123Z Base URL: https://api.pennyzo.com/api/v1/general Save Report: Yes Verbose Mode: Yes Using Real Credentials: No --- Testing Public Endpoints --- GET /system/health: SUCCESS (200) [342ms] API Status: operational Environment: production Version: 1.0.0 Message: Service is healthy GET /registration/company/identity-rules: SUCCESS (200) [285ms] --- Testing Authentication Flow --- POST /auth/login: FAILED (401) [520ms] Error: Request failed with status code 401 Authentication failed. Cannot test authenticated endpoints. Note: This is expected if using placeholder credentials. To test authenticated endpoints, use the --use-real-credentials flag and set PENNYZO_TEST_EMAIL and PENNYZO_TEST_PASSWORD environment variables. === API Status Check Summary === Total endpoints checked: 3 Successful: 2 Failed: 1 Success rate: 66.7% Total time: 1.15 seconds Report saved to: c:\Users\naman\OneDrive\Desktop\Pennyzo Web\reports\api-status-2025-09-25T10-15-30.123Z.json === API Status Check Complete === ``` ## Notes - The scripts use placeholder credentials by default, which will likely fail authentication. This is expected behavior. - To properly test authenticated endpoints, use real credentials via environment variables or direct script modification. - The extended script saves reports to a `reports` directory for historical tracking of API status. - All API calls and their results are logged to the console and (optionally) to report files. - Response times are logged to help identify slow endpoints. - A HTML report viewer is included at `reports/report-viewer.html` for visualizing the JSON reports.