@cube-dev/platform-client
v0.2.0
Published
Cube Platform Client
Downloads
1,086
Keywords
Readme
@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
- API reference & guides: https://docs.cube.dev/api-reference/introduction
- Changelog: https://docs.cube.dev/api-reference/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-clientUsage
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
