@cube-dev/platform-client

中文文档
0.26.0发布于 2026/11/07MITTypeScriptES Module近 30 天下载 3854

Cube Platform Client

原始使用文档
文档目录6 节
  1. Documentation & changelog
  2. Installation
  3. Usage
  4. React Query bindings
  5. Types
  6. License

@cube-dev/platform-client

A typed client for the Cube Cloud Platform control-plane REST API. It wraps the public OpenAPI spec with end-to-end types for every endpoint, request, and response, plus optional React Query bindings.

Documentation & changelog

A copy of the per-release changelog also ships in this package as CHANGELOG.md.

Installation

npm install @cube-dev/platform-client
# or
yarn add @cube-dev/platform-client

Usage

import { createCubePlatformClient } from '@cube-dev/platform-client';

const client = createCubePlatformClient({
  baseUrl: 'https://<your-tenant>.cubecloud.dev',
  // Called on every request — return the auth headers for the Platform API.
  getHeaders: () => ({ Authorization: process.env.CUBE_API_TOKEN! }),
});

// `fetchClient` is a fully-typed openapi-fetch client: paths, params,
// request bodies and responses are all checked against the OpenAPI spec.
const { data, error } = await client.fetchClient.GET('/api/v1/deployments/', {
  params: { query: { first: 50 } },
});

for (const deployment of data?.items ?? []) {
  console.log(deployment.id, deployment.name, deployment.deploymentUrl);
}

React Query bindings

The ./react-query entry point exposes a provider and typed hooks built on @tanstack/react-query (a peer dependency, along with react):

import { createCubePlatformClient } from '@cube-dev/platform-client';
import {
  CubePlatformApiProvider,
  useCubePlatformApiQuery,
} from '@cube-dev/platform-client/react-query';

const client = createCubePlatformClient({ baseUrl, getHeaders });

function App() {
  return (
    <CubePlatformApiProvider client={client}>
      <Deployments />
    </CubePlatformApiProvider>
  );
}

function Deployments() {
  const { data } = useCubePlatformApiQuery('get', '/api/v1/deployments/');
  return <ul>{data?.items.map((deployment) => <li key={deployment.id}>{deployment.name}</li>)}</ul>;
}

Types

The full set of schema types is exported as PlatformApiSchemas, and the raw OpenAPI paths / operations types are available for advanced use:

import type { PlatformApiSchemas, paths } from '@cube-dev/platform-client';

type Deployment = PlatformApiSchemas['Deployment'];

License

MIT

版本与发布记录

@cube-dev/platform-client 共发布 33 个版本,首次发布于 2026/06/06;过去 12 个月发布了 33 个版本。

版本发布日期距今
0.26.0latest2026/11/073 天前
0.25.02026/11/028 天前
0.24.12026/10/2912 天前
0.24.02026/10/2417 天前
0.23.12026/10/2318 天前
0.23.02026/10/2219 天前

关于 @cube-dev/platform-client 的常见问题

@cube-dev/platform-client 是什么?

Cube Platform Client

如何安装 @cube-dev/platform-client?

在项目目录运行 npm install @cube-dev/platform-client,或使用 pnpm add / yarn add / bun add。

@cube-dev/platform-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cube-dev/platform-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cube-dev/platform-client 可以商用吗?

@cube-dev/platform-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cube-dev/platform-client 的下载量有多少?

根据 npm 官方下载统计,@cube-dev/platform-client 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,854 次,日均约 128 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cube-dev/platform-client 还在维护吗?

最新版本 0.26.0 发布于 2026/11/07(3 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/06/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。