Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: Stable version matching package.json (for example 1.0.0)
description: Stable version matching package.json
required: true
type: string
commit:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.1.0

- Add account balance, product catalog and supported-country queries.
- Add read-only setup previews and single/batch proxy helpers with live defaults and dedicated-channel reuse.
- Coordinate default-channel creation within a client; reconcile uncertain creation without blind retries.
- Add the standalone `nstdata-proxy` CLI with hidden key input, explicit confirmation and private file export.
- Preserve the six existing customer API methods and their input contracts.

## 1.0.0

- Customer proxy generation and channel list, detail, create, update and delete methods.
Expand Down
8 changes: 3 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Build the archive after checks pass, then install it from a separate application

```sh
npm pack
npm install /path/to/nstdata-proxy-sdk-node/nstdata-ai-proxy-1.0.0.tgz
npm install /path/to/nstdata-proxy-sdk-node/nstdata-ai-proxy-1.1.0.tgz
```

Package checks use empty npm caches to verify the exact tarball and default npm installation through a loopback registry. They run installed-client regressions, compile TypeScript declarations, and execute the documented Node.js command and guide operations against loopback API fixtures. Markdown checks cover all public documents; package checks execute the quick start and guide operations. Pass a previously built tarball path after `npm run check:package --` to validate that exact archive. Checks verify bilingual programs, documentation links and package bytes; they do not prove public npm availability or deployed API compatibility.
Package checks use empty npm caches to verify the exact tarball and default npm installation through a loopback registry. They verify the standalone npx/global CLI and run installed-client/CLI regressions, compile TypeScript declarations, and execute the documented Node.js command and guide operations against loopback API fixtures. Markdown checks cover all public documents; package checks execute the quick start and guide operations. Pass a previously built tarball path after `npm run check:package --` to validate that exact archive. Checks verify bilingual programs, documentation links and package bytes; they do not prove public npm availability or deployed API compatibility.

Keep customer, reseller and Dashboard authentication separate. Route/payload changes need source-backed contracts and public-client regressions. Preserve cancellation, response limits, error redaction and no-retry behavior for uncertain outcomes. Keep runtime and declarations aligned and update both language guides and the changelog.

Expand All @@ -28,8 +28,6 @@ Never commit API keys, proxy credentials or account responses. Report vulnerabil

The `Publish npm` workflow is started manually from `main`, with a stable version matching `package.json` and the full commit SHA. It checks the source, builds one archive, and records its integrity. The `npm-production` environment reviewer approves publication of that same archive. Successful publication must pass public integrity and default-install checks.

For an existing npm package, configure [trusted publishing](https://docs.npmjs.com/trusted-publishers/) for this repository, `release.yml` and `npm-production`, permitting `npm publish`. The environment must require a reviewer, allow only the `main` branch and disable administrator bypass. No npm token is needed. Configure a new binding near the next release so its first-use deadline is met.

A new package must exist before trusted publishing can be configured. For its first release, the scope owner publishes the reviewed archive using their own npm login and two-factor authentication, following [npm's public scoped-package instructions](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages/). Use trusted publishing for subsequent versions. The workflow refuses to bootstrap an unpublished package.
Configure [trusted publishing](https://docs.npmjs.com/trusted-publishers/) for this repository, `release.yml` and `npm-production`, permitting `npm publish`. The environment must require a reviewer, allow only the `main` branch and disable administrator bypass. No npm token is needed. Configure a new binding near the next release so its first-use deadline is met.

If publication fails or the outcome is uncertain, inspect the registry version and integrity before taking further action. Do not retry publication blindly or change a published version's contents.
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@

[中文](README_zh.md)

Generate Nstdata proxy connections and manage customer channels. ESM with TypeScript declarations and no runtime dependencies.

## Features

| Capability | Guide |
|---|---|
| Proxy generation | [HTTP/SOCKS5 connection strings and session options](docs/guide.md#proxy-generation). |
| Channel reads | [Page-based lists and active-channel details](docs/guide.md#channel-reads). |
| Channel management | [Create, update and soft-delete channels](docs/guide.md#channel-management). |
| Reliability | [Deadlines, cancellation and safe errors](docs/guide.md#configuration-and-errors). |
Generate proxy connections with an API key and available account balance. Use the interactive CLI without a Node.js project, or the ESM SDK in an application. Includes TypeScript declarations; no runtime dependencies.

## Installation

Requires Node.js 22.18+ within 22.x, or Node.js 24.x.
Requires Node.js 22.18+ within 22.x, or Node.js 24.x. To use the SDK:

```sh
npm install @nstdata-ai/proxy
```

## Quick start
## Command line

Get an authorized personal or team API key from the [Nstdata dashboard](https://app.nstdata.io/); accounts using teams require a team key. Save it in a local `.env` file:
Run from any directory. Enter your API key at the hidden prompt, review the selected product and country, then press Enter to generate one connection. Choose Advanced to change the product, country or existing channel.

```sh
npx --yes --package=@nstdata-ai/proxy nstdata-proxy
```

For scripts, save your authorized API key from the [Nstdata dashboard](https://app.nstdata.io/) in a local `.env` file. Use the key for the intended personal or team account:

```dotenv
NSTDATA_API_TOKEN=your-api-key
```

Save the following as `quickstart.mjs`. It reads one channel-list page and prints only its length.
Generate one connection and save it to a new private file:

```sh
npx --yes --package=@nstdata-ai/proxy \
nstdata-proxy --env .env --yes --output proxies.json
```

`--yes` before `--package` accepts npx installation; the second `--yes` authorizes channel setup and proxy generation. `proxies.json` contains a `proxies` array with complete credential-bearing URLs. It is created with mode `0600` and never overwrites an existing file. Normal terminal output contains only metadata; the API key is never saved.

## SDK quick start

Use the same `.env` file. Save this program as `quickstart.mjs`:

```js
import { ProxyClient, ProxyAPIError } from '@nstdata-ai/proxy';
Expand All @@ -38,25 +46,33 @@ try {
const client = new ProxyClient({
apiKey: process.env.NSTDATA_API_TOKEN,
});
const channels = await client.listChannels({ page: 1, pageSize: 10 });
console.log({ channelsOnPage: channels.length });
const proxy = await client.getProxy();
// Pass proxy.url to your proxy-capable HTTP client; it contains credentials.
console.log({ country: proxy.country, protocol: proxy.protocol });
} catch (error) {
if (!(error instanceof ProxyAPIError)) throw error;
console.error({ code: error.code, statusCode: error.statusCode });
process.exitCode = 1;
}
```

Run with the `.env` file in the same directory:

```sh
node --env-file=.env quickstart.mjs
```

Expected output: `{ channelsOnPage: number }`; an empty channel list has length `0`. Configuration or request failures print an error code and exit with a nonzero status.
The output shows the selected country and protocol. `proxy.url` is the connection to pass to a proxy-capable client. Generating a connection does not test connectivity; actual proxy traffic is metered.

## Defaults and controls

| Capability | Behavior |
|---|---|
| First use | Finds a compatible `nstdata-sdk-default` channel or creates one using a random password. Other channels are unchanged. |
| Selection | Uses the account catalog: Residential Lite, then Residential; HTTP, one connection, 10-minute session. Uses a fixed channel country, otherwise US if available, then a supported country. |
| Preview | `prepareProxy()` or CLI `--dry-run` shows the setup without creating a channel or generating connections. |
| Explicit control | `getProxy({ country, channelId, ... })`, `getProxies({ count, ... })`, and the existing channel methods. Unsupported explicit choices fail without fallback. |

Channel records and proxy URLs can contain passwords. Inspect only fields your application needs; do not print complete results. For inputs, results and operation effects, see the [usage guide](docs/guide.md).
An API key and balance are sufficient for the normal pay-per-use flow when the account has compatible products and access. Availability and billing remain service-controlled; the SDK does not purchase or renew packages.

This package calls customer APIs. Proxy network transport, connectivity checks and Proxy Manager are separate capabilities.
[Full guide](docs/guide.md) covers CLI options, results, channel management and recovery.

[Contributing](CONTRIBUTING.md) · [Security](SECURITY.md) · [Changes](CHANGELOG.md) · [MIT license](LICENSE)
60 changes: 38 additions & 22 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
# Nstdata Node.js Proxy SDK
# Nstdata Proxy SDK for Node.js

[English](README.md)

通过 Nstdata 普通用户 API 生成代理连接并管理渠道。ESM 包含 TypeScript 声明,无运行时依赖。

## 功能

| 能力 | 指南 |
|---|---|
| 代理出号 | [HTTP/SOCKS5 连接串及会话参数](docs/guide_zh.md#代理出号)。 |
| 渠道读取 | [分页列表和活跃渠道详情](docs/guide_zh.md#渠道读取)。 |
| 渠道管理 | [创建、更新和软删除](docs/guide_zh.md#渠道管理)。 |
| 可靠性 | [期限、取消和安全错误](docs/guide_zh.md#配置与错误)。 |
使用 API Key 和可用余额获取代理连接。可直接运行交互式命令行,无需创建 Node.js 项目;也可通过 ESM SDK 集成到应用。提供 TypeScript 类型,无运行时依赖。

## 安装

需要 Node.js 22 系列的22.18+,或 Node.js 24 系列。
需要 Node.js 22 系列的 22.18+ 或 Node.js 24 系列。应用中使用 SDK:

```sh
npm install @nstdata-ai/proxy
```

## 快速开始
## 命令行使用

从 [Nstdata 控制台](https://app.nstdata.io/) 获取获准使用的个人或团队 API key;团队账号须使用团队 key。将 Key 保存到本地 `.env` 文件:
在任意目录运行。按提示输入 API Key(不回显),核对产品与国家后按 Enter 获取一条连接;选择 Advanced 可更换产品、国家或已有渠道。

```sh
npx --yes --package=@nstdata-ai/proxy nstdata-proxy
```

用于脚本时,从 [Nstdata 控制台](https://app.nstdata.io/) 获取获准使用的个人或团队 API Key,保存到本地 `.env` 文件:

```dotenv
NSTDATA_API_TOKEN=your-api-key
```

将以下程序保存为 `quickstart.mjs`。它读取一页渠道列表,只输出本页数量。
获取一条连接并保存到新的私密文件:

```sh
npx --yes --package=@nstdata-ai/proxy \
nstdata-proxy --env .env --yes --output proxies.json
```

`--package` 前的 `--yes` 确认 npx 安装,后一个 `--yes` 确认渠道准备与出号。`proxies.json` 中的 `proxies` 数组保存含认证信息的完整连接 URL;文件权限设为 `0600`,已存在时不会覆盖。默认终端输出只含元数据,不保存 API Key。

## SDK 快速开始

使用上述 `.env` 文件,将以下程序保存为 `quickstart.mjs`:

```js
import { ProxyClient, ProxyAPIError } from '@nstdata-ai/proxy';
Expand All @@ -38,25 +46,33 @@ try {
const client = new ProxyClient({
apiKey: process.env.NSTDATA_API_TOKEN,
});
const channels = await client.listChannels({ page: 1, pageSize: 10 });
console.log({ channelsOnPage: channels.length });
const proxy = await client.getProxy();
// Pass proxy.url to your proxy-capable HTTP client; it contains credentials.
console.log({ country: proxy.country, protocol: proxy.protocol });
} catch (error) {
if (!(error instanceof ProxyAPIError)) throw error;
console.error({ code: error.code, statusCode: error.statusCode });
process.exitCode = 1;
}
```

使用同一目录中的 `.env` 运行:

```sh
node --env-file=.env quickstart.mjs
```

预期输出 `{ channelsOnPage: 数量 }`;空渠道列表的数量为 `0`。配置或请求失败时输出错误码并以非零状态退出。
输出显示实际选择的国家和协议。将 `proxy.url` 交给支持代理的客户端使用。出号本身不测试连通性;实际代理流量按服务规则计量。

## 默认行为与控制

| 能力 | 行为 |
|---|---|
| 首次使用 | 查找兼容的 `nstdata-sdk-default` 渠道,没有时使用随机密码创建;不修改其他渠道。 |
| 自动选择 | 依据实际产品目录,优先 Residential Lite,其次 Residential;默认 HTTP、1 条、10 分钟会话。先遵守渠道固定国家,否则优先可用的 US,再选择支持的国家。 |
| 只读预览 | `prepareProxy()` 或 CLI `--dry-run` 查看方案,不创建渠道、不出号。 |
| 精确控制 | `getProxy({ country, channelId, ... })`、`getProxies({ count, ... })` 及原有渠道方法。显式指定的选择不支持时直接报错,不自动换产品或国家。 |

渠道记录和代理 URL 可能包含密码。只读取应用所需字段,不打印完整结果。各项功能的参数、返回值和操作影响见[使用指南](docs/guide_zh.md)。
账号具备兼容产品和访问权限时,正常按量流程仅需 API Key 与余额。产品可用性和计费由服务端决定;SDK 不购买或续费套餐。

本包调用普通用户 API。代理网络传输、连通性检测和 Proxy Manager 属于独立能力。
[完整指南](docs/guide_zh.md) 提供命令行选项、返回字段、渠道管理与异常恢复说明。

[贡献说明](CONTRIBUTING.md) · [安全反馈](SECURITY.md) · [变更记录](CHANGELOG.md) · [MIT 许可](LICENSE)
Loading
Loading