<p align="center">
  <img src="https://intl-image.yzcdn.cn/images/icons/allvalue-logo/colorful.png" alt="AllValue" height="48" />
</p>

<h1 align="center">allvalue-open</h1>

<p align="center">
  <a href="./README.md">简体中文</a> | <strong>English</strong>
</p>

---

## Installation

```bash
npm install -g allvalue-open
```

## Quick Start

```bash
# Set Access Token
allvalue-open config set-token

# List all commands
allvalue-open admin --list

# View command parameters
allvalue-open admin collections

# Execute a query
allvalue-open admin collections --variables '{"first":10}'
```

## Commands

### `allvalue-open admin --list` / `-l`
List all available Query and Mutation commands in compact mode.

### `allvalue-open admin --help` / `-h`
Show usage information.

### `allvalue-open admin schema`
Show the local schema cache file path. Fetches automatically if not cached.

### `allvalue-open admin <command>`
Show detailed parameter description, returnable fields, and a copyable example.

```bash
allvalue-open admin collections
allvalue-open admin products
allvalue-open admin orders
```

### `allvalue-open admin <command> --variables '<json>'`
Execute a named query with variables JSON.

```bash
allvalue-open admin collections --variables '{"first":10}'
allvalue-open admin products --variables '{"first":5,"query":"title:T-shirt"}'

# Read from file
allvalue-open admin collections --variable-file ./vars.json
```

### `allvalue-open admin query`
Raw mode — execute a GraphQL statement directly without validation.

```bash
allvalue-open admin query --query 'query { shop { name } }'

# From file
allvalue-open admin query --query-file ./my-query.graphql --variable-file ./vars.json
```

### Mutation Guard
Mutations are disabled by default. Use `--allow-mutations` to opt in.

```bash
allvalue-open admin productCreate --variables '{...}' --allow-mutations
```

### `allvalue-open config set-token`
Save your Access Token to `~/.allvalue-open.json`.

```bash
allvalue-open config set-token
allvalue-open config set-token --profile admin --token <your-token>
```

### `allvalue-open config show`
Show current saved token configuration.

## Token Priority

| Priority | Source |
|---|---|
| 1 | `--token <token>` flag |
| 2 | `ALLVALUE_TOKEN` environment variable |
| 3 | `~/.allvalue-open.json` config file |
| 4 | Interactive prompt (auto-saved) |

## Schema Cache

Schema is fetched automatically on first use and cached at `~/.allvalue-open/admin-schema.json`.

To force refresh:
```bash
rm ~/.allvalue-open/admin-schema.json
allvalue-open admin --list
```

## Requirements

- Node.js >= 22
