JavaScript client

Get started

Create a client and make your first typed request.

import { GalleryClient } from '@degallery/sdk';

const client = new GalleryClient({
  apiUrl: 'https://api.degallery.mpotulo.com',
  apiKey: process.env.DEGALLERY_API_KEY,
});

const result = await client.galleries.retrieve('gallery_uuid', {
  includeAssets: true,
});

console.log(result.name, result.items?.length ?? 0);

The client exposes typed resource clients through client.galleries and client.assets, plus convenience methods for uploads, gallery mapping, and event tracking.

const gallery = await client.getGallery('gallery_uuid');
const assets = await client.assets.list({ limit: 25 });

Requests use the bearer credential configured in the client. Never construct authorization headers with a secret in browser code.

Resource-oriented API

Use the resource clients when you need explicit request options or want code that mirrors the REST API:

const gallery = await client.galleries.retrieve('gallery_uuid', {
  includeAssets: true,
});

const page = await client.assets.list({
  galleryId: gallery.id,
  limit: 50,
});

for (const asset of page.items ?? []) {
  console.log(asset.id, asset.url);
}

Use convenience methods such as getGallery when you want the smallest amount of code. Both styles use the same configured base URL, bearer credential, and typed response contracts.

Server and browser boundaries

The SDK can be imported in shared TypeScript code, but credential ownership still belongs to the runtime that creates the client:

// Server-only module
export function createDeGalleryClient() {
  return new GalleryClient({
    apiUrl: process.env.DEGALLERY_API_URL,
    apiKey: process.env.DEGALLERY_API_KEY,
  });
}

For browser reads, use a public/read credential or pass a server-fetched gallery to your UI. A publishable key can identify a public application; it must not be treated as a replacement for private authorization.

On this page