Use the SDK

Read and write your database, files and realtime channels, and send email and push, from JavaScript or TypeScript.

Last updated

The SDK has one client per kind of credential. Pick the one that matches where your code runs.

ClientKeyRuns inGives you
createProductClientBrowser key daster_pk_…Browser, mobile, serverauth, database, storage, realtime, with your row-level security
createServiceClientServer key daster_sk_…Server onlydatabase, storage, realtime as the project owner
createCommunicationsClientApp email key daster_sk_…Server onlysendMessage, push

Each client takes projectId, the project's ID (a UUID), and its key. See Install and sign in for where the keys come from.

Query the database from your server

TypeScript
import { createServiceClient } from '@dasterhq/daster';

const db = createServiceClient({
  projectId: process.env.DASTER_PROJECT_ID!,
  serverKey: process.env.DASTER_SERVER_KEY!,
});

const { rows } = await db.database.select('todos', { eq: { done: false }, limit: 20 });
await db.database.insert('todos', { title: 'Write the docs', done: false });
await db.database.update('todos', { done: true }, { eq: { id: 42 } });

The server key bypasses row-level security, so filter every query yourself. Apps hosted on DASTER already receive DASTER_SERVER_KEY in their environment (Connect once); set DASTER_PROJECT_ID yourself.

The database methods follow the data API's rules:

  • select filters by equality only (eq). It returns at most 100 rows (50 by default); offset goes up to 10,000, and paginate walks through pages for you.
  • update and delete refuse to run without an eq filter.
  • insert and update take 1 to 30 columns.
  • rpc(name, args) calls a database function, if the API role may run it.

Sign a user in from the browser

TypeScript
import { createProductClient } from '@dasterhq/daster';

const app = createProductClient({
  projectId: '<project id>',
  publishableKey: 'daster_pk_…',
});

await app.auth.signIn({ email, password });
const { rows } = await app.database.select('todos', { limit: 20 });

With a signed-in user, requests carry the user's session and your row-level security policies decide what they see. app.auth also has signUp, verifyEmail, requestPasswordReset, resetPassword, refresh, signOut, revokeAllSessions and user. By default the session is kept in memory; pass sessionStore with get and set to keep it elsewhere. See Authentication.

Files and realtime

TypeScript
const uploaded = await app.storage.upload(bucketId, {
  path: 'avatars/ada.png',
  contentType: 'image/png',
  bytes,
});
const link = await app.storage.createSignedUrl(uploaded.id, { expiresIn: 300 });

for await (const batch of app.realtime.stream('orders')) {
  for (const event of batch.items) console.log(event.type, event);
}

bytes is a Uint8Array (or pass base64 instead). A signed URL lasts at most 300 seconds; link.url is the download address. storage also has list, download and remove. Each realtime batch carries a cursor; pass it back as { cursor } to resume after a reconnect. realtime.events(channel, { cursor }) reads one batch instead of a stream, and realtime.broadcast(channel, payload, { idempotencyKey }) sends an event to a channel. See Storage and Realtime.

Send an email

TypeScript
import { createCommunicationsClient } from '@dasterhq/daster';

const messages = createCommunicationsClient({
  projectId: process.env.DASTER_PROJECT_ID!,
  credential: process.env.DASTER_EMAIL_KEY!,
});

const receipt = await messages.sendMessage(
  {
    channel: 'email',
    to: 'ada@example.com',
    subject: 'Your receipt',
    text: 'Order 1042 confirmed.',
  },
  { idempotencyKey: 'receipt-1042' },
);

idempotencyKey is required. Sending again with the same key returns the first message instead of sending twice. An email takes text, html, or a templateId with variables. The answer is a receipt with the message id, its status and a masked recipient. See App email.

Send a push notification

Push needs a credential with Push access. Apps hosted on DASTER receive one as DASTER_PUSH_KEY when Push is wired to them; the project's server key does not reach Push.

TypeScript
const push = createCommunicationsClient({
  projectId: process.env.DASTER_PROJECT_ID!,
  credential: process.env.DASTER_PUSH_KEY!,
});

await push.push.send(
  pushAppId,
  { topic: 'news', title: 'New article', body: 'Read it now.', url: 'https://example.com/news' },
  { idempotencyKey: 'news-2026-11-21' },
);

Choose exactly one audience: targets (device IDs), broadcast: true or topic. Register devices with push.push.registerDevice(pushAppId, { target, topics }). See Push notifications.

Note: The communications client also has sendOtp, verifyOtp and an sms channel. SMS is not available in production yet, so those calls are refused for now.

Errors and retries

ErrorWhen
DasterApiErrorDASTER answered with an error. It has status, code and requestId
DasterTransportErrorThe request did not complete: kind is network, timeout, aborted and so on
DasterConfigErrorAn option is wrong, for example a server key passed to createProductClient

Reads and calls with an idempotencyKey are retried up to 3 attempts in all. Other changes, such as insert, are never retried. When a DasterTransportError has ambiguous: true, the change may have happened; repeat it only with the same idempotencyKey. One call times out after 15 seconds by default; set timeoutMs (up to 120,000) on the client or on a call, or pass an AbortSignal as signal.