@glboost/sdk
v0.1.1
Published
Typed client for the GLBoost API: uploads, optimized variants, signed CDN URLs, shares.
Readme
@glboost/sdk
Typed client for the GLBoost API: upload glTF/GLB models, wait for the optimized variants, mint signed CDN URLs, and call every other endpoint with the types generated from the API's OpenAPI document. Works in Node 20+ and browsers.
npm install @glboost/sdkimport { createClient, uploadModel, waitForReady, assetUrl } from '@glboost/sdk';
import { readFile } from 'node:fs/promises';
const client = createClient({ apiKey: process.env.GLBOOST_API_KEY! });
const { assetId } = await uploadModel(client, {
name: 'chair.glb',
data: await readFile('chair.glb'),
});
const ready = await waitForReady(client, assetId);
console.log(ready.variants.map((v) => [v.preset, v.bytes, v.score?.grade]));
console.log(assetUrl(assetId, { preset: 'gpu' })); // https://cdn.glboost.com/<id>.glb?p=gpuEvery endpoint is on client.api (an openapi-fetch client):
const { data, error } = await client.api.GET('/api/v1/assets', {
params: { query: { q: 'chair' } },
});Errors from the helpers are GLBoostApiError instances; error.isPlanLimit is true for 402 and 413,
with plan, used, limit, and upgradeUrl filled in.
For tests, @glboost/sdk/testing exports createFakeApi(), an in-memory stand-in for the API and
the CDN upload endpoints: createClient({ fetch: createFakeApi().fetch }).
Docs: https://glboost.com/docs/sdk
