harbor-sdk 0.1.0

Add API key auth and billing to your Rust API in one line. Harbor handles validation so your users can authenticate with keys they manage from the Harbor dashboard.
Documentation
# harbor-sdk

> Add API key auth and billing to your Rust API in one line.

Harbor handles validation so your users can authenticate with keys they manage from the [Harbor dashboard](https://harbor-black.vercel.app).

## Install

```toml
[dependencies]
harbor-sdk = "0.1"

# With Axum middleware support:
harbor-sdk = { version = "0.1", features = ["axum"] }
```

## Quick Start

### Validate a key

```rust
use harbor_sdk::validate;

#[tokio::main]
async fn main() {
    match validate("hbr_live_your_key").await {
        Ok(info) => println!("Plan: {}, Project: {}", info.plan, info.project_id),
        Err(e) => println!("Error: {}", e),
    }
}
```

### Axum middleware

```rust
use axum::{Router, routing::get, middleware, Extension};
use harbor_sdk::{KeyInfo, axum_middleware::harbor_auth};

async fn handler(Extension(key): Extension<KeyInfo>) -> String {
    format!("Hello, {}! Plan: {}", key.name, key.plan)
}

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/data", get(handler))
        .layer(middleware::from_fn_with_state(
            "proj_harbor_xyz".to_string(),
            harbor_auth,
        ));

    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}
```

The middleware reads the `x-harbor-key` header and validates it against the Harbor API. On success, a `KeyInfo` extension is inserted into the request so your handlers can access plan info, usage counts, and more.

## KeyInfo fields

| Field | Type | Description |
|-------|------|-------------|
| `key_id` | `String` | Unique key identifier |
| `project_id` | `String` | Your Harbor project ID |
| `plan` | `String` | Subscription plan (e.g. `"free"`, `"pro"`) |
| `calls_this_month` | `u64` | API calls used this billing cycle |
| `name` | `String` | Name associated with the key |
| `country` | `Option<String>` | Country code of the key owner |

## Custom validation URL

For local development with [harbor-mock](https://www.npmjs.com/package/harbor-mock):

```rust
use harbor_sdk::validate_with_url;

let info = validate_with_url("hbr_test_key", "http://localhost:4000/api/validate").await?;
```

## Features

| Feature | Enables |
|---------|---------|
| `axum` | Axum middleware layer (`axum_middleware::harbor_auth`) |
| `full` | All optional integrations |

## Links

- [Harbor dashboard]https://harbor-black.vercel.app
- [Documentation]https://harbor-black.vercel.app/docs
- [GitHub]https://github.com/nicolugo0503-glitch/harbor-rust
- [crates.io]https://crates.io/crates/harbor-sdk

## License

MIT