diff --git a/docs/api-reference/cli/ID_FORMAT_UPDATE.md b/docs/api-reference/cli/ID_FORMAT_UPDATE.md new file mode 100644 index 00000000..145fdb18 --- /dev/null +++ b/docs/api-reference/cli/ID_FORMAT_UPDATE.md @@ -0,0 +1,78 @@ +# CLI Documentation ID Format Update + +## Issue +PR feedback indicates that `planId` and `agentId` examples in documentation use incorrect format. + +## Current Format (Incorrect) +``` +did:nvm:abc123 +did:nvm:plan1 +did:nvm:agent123 +``` + +## Correct Format (BigInt) +Plan IDs and Agent IDs are returned as large numeric strings (BigInt format): +``` +"123456789012345678" +"987654321098765432" +``` + +## Files to Update +1. cli/docs/getting-started.md +2. cli/docs/plans.md +3. cli/docs/agents.md +4. cli/docs/purchases.md +5. cli/docs/querying.md +6. cli/docs/other-commands.md +7. cli/docs/README.md +8. cli/docs/TESTING_NPM.md + +## Example Replacements + +### Plans Documentation +**Before**: +```bash +nevermined plans get-plan did:nvm:abc123 +``` + +**After**: +```bash +nevermined plans get-plan "123456789012345678" +``` + +### Agents Documentation +**Before**: +```bash +nevermined agents get-agent did:nvm:agent123 +``` + +**After**: +```bash +nevermined agents get-agent "987654321098765432" +``` + +### Variable Assignments +**Before**: +```bash +PLAN_ID="did:nvm:abc123" +``` + +**After**: +```bash +PLAN_ID="123456789012345678" +``` + +## Implementation Strategy +1. Replace all `did:nvm:abc123` and similar patterns with numeric BigInt strings +2. Use distinct numbers for different entities to avoid confusion +3. Keep examples consistent across documentation +4. Maintain quotes around numeric strings in shell examples + +## Standard Example IDs +- Basic plan: `"123456789012345678"` +- Pro plan: `"234567890123456789"` +- Enterprise plan: `"345678901234567890"` +- Trial plan: `"456789012345678901"` +- Agent 1: `"987654321098765432"` +- Agent 2: `"876543210987654321"` +- Agent 3: `"765432109876543210"` diff --git a/docs/api-reference/cli/README.md b/docs/api-reference/cli/README.md new file mode 100644 index 00000000..fc2fcd90 --- /dev/null +++ b/docs/api-reference/cli/README.md @@ -0,0 +1,401 @@ +# Nevermined Payments CLI Documentation + +Complete documentation for the Nevermined Payments CLI (`nevermined`). + +## Overview + +The Nevermined Payments CLI is a command-line interface for interacting with the Nevermined Payments Protocol. It enables developers to: + +- Create and manage payment plans +- Register AI agents with pay-per-use billing +- Purchase and manage subscriptions +- Query agents using X402 access tokens +- Verify and settle permissions +- Manage organizations and members + +## Documentation + +### Getting Started + +**[Getting Started Guide](./getting-started.md)** + +Everything you need to install and configure the CLI: +- Prerequisites and system requirements +- Getting your NVM API key +- Installation methods (npm, npx, from source) +- Configuration setup and profiles +- Environment selection guide +- Common installation issues + +### Core Functionality + +**[Managing Payment Plans](./plans.md)** + +Create and manage payment plans for your services: +- Listing and viewing plans +- Creating credits-based, time-based, and service plans +- Updating plan metadata and pricing +- Checking balances and credits +- Plan files and transfers +- Advanced plan operations + +**[Managing AI Agents](./agents.md)** + +Register and configure AI agents: +- Listing and viewing agents +- Registering new agents with payment plans +- Updating agent metadata and endpoints +- Managing payment plan associations +- Agent files and resources +- Access control configuration + +**[Making Purchases](./purchases.md)** + +Order plans and manage subscriptions: +- Ordering payment plans +- Checking credit balances +- Managing subscriptions +- Refilling credits +- Transaction history and analytics +- Automated purchasing and budgeting + +**[Querying Agents](./querying.md)** + +Access agents using X402 tokens: +- Generating X402 access tokens +- Making HTTP requests with tokens +- Verifying and settling requests +- Complete query workflows +- Batch queries and rate limiting +- Monitoring credit usage + +**[Other Commands](./other-commands.md)** + +Additional CLI features and utilities: +- Configuration management +- Facilitator operations (verify/settle) +- Organization member management +- X402 token commands +- Global flags and options +- Scripting and automation examples + +## Quick Links + +### Installation + +```bash +# Global installation +npm install -g @nevermined-io/cli + +# Using npx +npx @nevermined-io/cli --help +``` + +### First Steps + +```bash +# Authenticate via browser (recommended) +nevermined login + +# Or initialize configuration manually +nevermined config init + +# List available plans +nevermined plans get-plans + +# Get plan details +nevermined plans get-plan + +# Order a plan +nevermined plans order-plan + +# Get access token +nevermined x402token get-x402-access-token +``` + +### Common Commands + +```bash +# Authentication +nevermined login # Authenticate via browser +nevermined logout # Remove API key from config + +# Configuration +nevermined config init # Initialize configuration +nevermined config show # Display current config +nevermined config set # Update configuration + +# Plans +nevermined plans get-plans # List all plans +nevermined plans get-plan # Get plan details +nevermined plans get-plan-balance # Check balance +nevermined plans order-plan # Purchase plan + +# Agents +nevermined agents get-agent # Get agent details +nevermined agents get-agent-plans # List agent's plans +nevermined agents register-agent \ # Register new agent + --agent-metadata metadata.json \ + --agent-api "https://api.example.com" \ + --payment-plans "plan-id-1,plan-id-2" + +# X402 Tokens +nevermined x402token get-x402-access-token # Get access token + +# Organizations +nevermined organizations get-members # List members +nevermined organizations create-member # Add member +nevermined organizations connect-stripe-account \ # Connect Stripe + --user-email "user@example.com" \ + --user-country-code "US" \ + --return-url "https://yourapp.com/callback" +``` + +## Global Flags + +All commands support these global flags: + +- `-f, --format ` - Output format: table, json, quiet (default: table) +- `-p, --profile ` - Configuration profile to use +- `-v, --verbose` - Verbose output with detailed logging +- `-h, --help` - Display help for command + +## Output Formats + +### Table (Default) + +Human-readable table output for interactive use: + +```bash +nevermined plans get-plans +``` + +### JSON + +Machine-readable JSON for scripting: + +```bash +nevermined plans get-plans --format json +``` + +### Quiet + +Minimal output for automation: + +```bash +nevermined plans get-plans --format quiet +``` + +## Configuration Profiles + +Use profiles to manage multiple environments: + +```bash +# Create production profile +nevermined config set profiles.production.nvmApiKey live:eyJxxxxaaaabbbbbbbb +nevermined config set profiles.production.environment live + +# Use production profile +nevermined --profile production plans get-plans + +# Switch active profile +nevermined config set activeProfile production +``` + +## Environment Guide + +| Environment | Use Case | Blockchain | Payments | +|-------------|----------|------------|----------| +| `sandbox` | Development, testing | Test network | Test credits | +| `live` | Production | Mainnet | Real payments | + +## Examples + +### Complete Workflow + +```bash +#!/bin/bash +# Complete workflow: Setup -> Purchase -> Query + +# 1. Initialize configuration +nevermined config init + +# 2. List available plans +nevermined plans get-plans + +# 3. Get plan details +PLAN_ID="123456789012345678" +nevermined plans get-plan $PLAN_ID + +# 4. Purchase plan +nevermined plans order-plan $PLAN_ID + +# 5. Check balance +nevermined plans get-plan-balance $PLAN_ID + +# 6. Get access token +TOKEN=$(nevermined x402token get-x402-access-token $PLAN_ID --format json | jq -r '.token') + +# 7. Query agent +curl -H "payment-signature: $TOKEN" https://agent-api.example.com/query +``` + +### Agent Registration + +```bash +#!/bin/bash +# Register an AI agent with payment plan + +# 1. Create payment plan +PLAN_ID=$(nevermined plans register-credits-plan \ + --plan-metadata plan.json \ + --price-config price.json \ + --credits-config credits.json \ + --format json | jq -r '.planId') + +# 2. Register agent with plan +AGENT_ID=$(nevermined agents register-agent \ + --agent-metadata agent.json \ + --agent-api "https://api.example.com" \ + --payment-plans "$PLAN_ID" \ + --format json | jq -r '.agentId') + +# 3. Verify agent is accessible +nevermined agents get-agent $AGENT_ID +``` + +## Getting Help + +### Command Help + +```bash +# General help +nevermined --help + +# Topic help +nevermined plans --help +nevermined agents --help + +# Command help +nevermined plans get-plan --help +``` + +### Documentation + +- Full Documentation: https://nevermined.ai/docs +- GitHub Repository: https://github.com/nevermined-io/payments +- Issue Tracker: https://github.com/nevermined-io/payments/issues + +### Support + +- Discord Community: https://discord.gg/GZju2qScKq +- Email Support: support@nevermined.io +- Developer Forum: https://forum.nevermined.io + +## Advanced Topics + +### Automation + +The CLI is designed for automation: + +```bash +# Cron job for credit monitoring +0 */6 * * * /path/to/check-credits.sh + +# CI/CD integration +- run: nevermined agents register-agent --agent-metadata agent.json +``` + +### Scripting + +Use JSON output for scripting: + +```bash +# Extract data with jq +BALANCE=$(nevermined plans get-plan-balance $PLAN_ID --format json | jq -r '.balance') + +# Loop over plans +PLANS=$(nevermined plans get-plans --format json | jq -r '.[].id') +for PLAN in $PLANS; do + nevermined plans get-plan $PLAN +done +``` + +### Integration + +Integrate with other tools: + +```bash +# Export to CSV +nevermined plans get-plans --format json | jq -r '.[] | [.id, .name, .price] | @csv' > plans.csv + +# Send to monitoring +BALANCE=$(nevermined plans get-plan-balance $PLAN_ID --format json) +curl -X POST monitoring-api.com/metrics -d "$BALANCE" +``` + +## Troubleshooting + +Common issues and solutions: + +### Command Not Found + +```bash +# Verify installation +npm list -g @nevermined-io/cli + +# Reinstall if needed +npm install -g @nevermined-io/cli +``` + +### API Key Errors + +```bash +# Browser login (recommended) +nevermined login + +# Or initialize configuration manually +nevermined config init + +# Or set environment variable +export NVM_API_KEY=your-api-key +``` + +### Permission Errors + +```bash +# Fix config file permissions +chmod 600 ~/.config/nvm/config.json + +# Use npx instead of global install +npx @nevermined-io/cli +``` + +## Contributing + +Contributions are welcome! See the main repository for: + +- Contributing guidelines +- Development setup +- Testing procedures +- Code of conduct + +## License + +Apache-2.0 License - see LICENSE file for details + +## Version + +Current version: 1.0.2 + +Check your version: + +```bash +nevermined --version +``` + +Update to latest: + +```bash +npm update -g @nevermined-io/cli +``` diff --git a/docs/api-reference/cli/TESTING_NPM.md b/docs/api-reference/cli/TESTING_NPM.md new file mode 100644 index 00000000..f4eb8308 --- /dev/null +++ b/docs/api-reference/cli/TESTING_NPM.md @@ -0,0 +1,474 @@ +# CLI NPM Package Testing Report + +Testing report for `@nevermined-io/cli` package version `1.0.3-rc2`. + +**Date**: 2026-02-02 +**Tester**: Automated Testing +**Package**: `@nevermined-io/cli@1.0.3-rc2` +**Platform**: Linux (Ubuntu) +**Node Version**: v24.10.0 + +## Installation + +### Prerequisites Check + +Before installation, the old package `@nevermined-io/payments-cli` needed to be removed: + +```bash +$ npm uninstall -g @nevermined-io/payments-cli +removed 626 packages in 497ms +``` + +### Package Installation + +```bash +$ npm install -g @nevermined-io/cli@1.0.3-rc2 +added 352 packages, removed 237 packages, and changed 66 packages in 5s + +88 packages are looking for funding + run `npm fund` for details +``` + +**Status**: ✅ Installation successful + +### Package Verification + +```bash +$ npm list -g @nevermined-io/cli +/home/user/.n/lib +└── @nevermined-io/cli@1.0.3-rc2 +``` + +**Status**: ✅ Package correctly installed + +## Command Testing + +### 1. Version Command + +**Command**: `nevermined --version` + +**Output**: +``` +@nevermined-io/cli/1.0.3-rc2 linux-x64 node-v24.10.0 +``` + +**Status**: ✅ Working correctly +**Notes**: Version format matches documentation (`x.y.z-rcN`) + +--- + +### 2. Main Help Command + +**Command**: `nevermined --help` + +**Output**: +``` +CLI for Nevermined Payments SDK + +VERSION + @nevermined-io/cli/1.0.3-rc2 linux-x64 node-v24.10.0 + +USAGE + $ nevermined [COMMAND] + +TOPICS + agents Manage AI agents + config Manage CLI configuration + facilitator Settle (burn) credits from a subscriber's payment plan... + organizations Manage organizations + plans Manage payment plans + plugins List installed plugins. + x402token Create a permission and get an X402 access token... + +COMMANDS + help Display help for nevermined. + plugins List installed plugins. +``` + +**Status**: ✅ Working correctly +**Notes**: All documented topics are present + +--- + +### 3. Configuration Commands + +#### 3.1 Config Help + +**Command**: `nevermined config --help` + +**Output**: +``` +Manage CLI configuration + +USAGE + $ nevermined config COMMAND + +COMMANDS + config init Initialize CLI configuration + config set Set a configuration value + config show Display current configuration +``` + +**Status**: ✅ Working correctly +**Documentation Match**: ✅ Commands match getting-started.md + +#### 3.2 Config Show + +**Command**: `nevermined config show` + +**Output**: +``` +┌─────────────┬─────────────────┐ +│ profile │ default │ +├─────────────┼─────────────────┤ +│ active │ true │ +├─────────────┼─────────────────┤ +│ nvmApiKey │ test-key │ +├─────────────┼─────────────────┤ +│ environment │ sandbox │ +└─────────────┴─────────────────┘ +ℹ Config file: /home/aitor/.config/nvm/config.json +``` + +**Status**: ✅ Working correctly +**Documentation Match**: ✅ Output format matches getting-started.md (lines 171-176) + +--- + +### 4. Plans Commands + +#### 4.1 Plans Help + +**Command**: `nevermined plans --help` + +**Output**: +``` +Manage payment plans + +USAGE + $ nevermined plans COMMAND + +COMMANDS + plans get-agents-associated-to-a-plan + plans get-crypto-price-config + plans get-dynamic-credits-config + plans get-erc20-price-config + plans get-expirable-duration-config + plans get-fiat-price-config + plans get-fixed-credits-config + plans get-free-price-config + plans get-native-token-price-config + plans get-non-expirable-duration-config + plans get-pay-as-you-go-credits-config + [... additional commands ...] +``` + +**Status**: ✅ Working correctly +**Notes**: All plan management commands available + +#### 4.2 Get Plan Command Help + +**Command**: `nevermined plans get-plan --help` + +**Output**: +``` +Gets the information about a Payment Plan by its identifier. + +USAGE + $ nevermined plans get-plan PLAN [-p ] [-f table|json|quiet] [-v] + +ARGUMENTS + PLAN plan identifier + +FLAGS + -f, --format=