JavaScript SDK - Installation#

@rafikidb/sdk is a typed client for the RafikiDB API: data, auth, realtime, storage, environment variables, secrets, webhooks, edge functions and payments.

  • Zero runtime dependencies (native fetch)
  • ESM + CJS + TypeScript types
  • Optional React hook (@rafikidb/sdk/react)
  • Browser and Node.js (18+)

Install#

npm install @rafikidb/sdk
Bash

The React useAuth hook is a subpath of the same package - do not install it separately:

import { useAuth } from '@rafikidb/sdk/react';
TypeScript

Initialize#

import { createClient } from '@rafikidb/sdk';

const db = createClient({
  projectId: '5c73dab0-...',
  apiKey: 'raf_live_...',
  baseUrl: 'https://api.rafikidb.com/api/v1', // optional
  persistSession: true,     // optional: survive refreshes
});
TypeScript
OptionTypeDescription
projectIdstringRequired. Used by auth/realtime URLs
apiKeystringRequired. Sent as X-AFRIBASE-API-Key
baseUrlstringDefault http://localhost:8080/api/v1
persistSessionbooleanSave/restore the user session in localStorage
fetchtypeof fetchCustom fetch implementation

Responses#

Every method returns the API envelope unchanged:

const res = await db.from('profiles').select().limit(10);
// { success: true, message: 'Request was successful', data: [...] }
TypeScript

Failures throw RafikiDBError:

import { RafikiDBError } from '@rafikidb/sdk';

try {
  await db.from('profiles').insert({});
} catch (err) {
  if (err instanceof RafikiDBError) {
    err.message; err.status; err.code; err.errors;
    JSON.stringify(err); // fully serializable
  }
}
TypeScript

Next: Data.