@reactor-cloud/client
v0.3.0
Published
Reactor JS SDK - the official TypeScript client for Reactor
Downloads
273
Maintainers
Readme
@reactor-cloud/client
The official Reactor JS/TS SDK. A unified client for all Reactor capabilities.
Installation
npm install @reactor-cloud/client
# or
pnpm add @reactor-cloud/client
# or
yarn add @reactor-cloud/clientQuick Start
import { createClient } from '@reactor-cloud/client';
import type { Database } from './database.types';
const reactor = createClient<Database>('https://your-project.reactor.cloud', {
key: 'rk_pub_...',
});
// Authentication
const { data: { user } } = await reactor.auth.signIn({
email: '[email protected]',
password: 'password',
});
// Data queries (PostgREST-style)
const { data: posts } = await reactor.from('posts')
.select('*, author:users(*)')
.eq('published', true)
.order('created_at', { ascending: false })
.limit(10);
// Storage
const { data } = await reactor.storage
.from('avatars')
.upload('me.jpg', file, { contentType: 'image/jpeg' });
// Functions
const { data: result } = await reactor.functions.invoke('process-order', {
body: { orderId: '123' },
});
// Jobs
await reactor.jobs.trigger('send-email', {
payload: { to: '[email protected]', subject: 'Hello!' },
});API Reference
createClient<Schema>(url, options)
Creates a new Reactor client instance.
Parameters:
url- The Reactor API URLoptions.key- Project key (anon key) for authenticationoptions.org- Default organization contextoptions.fetch- Custom fetch implementationoptions.headers- Global headers for all requestsoptions.auth- Auth-specific optionsoptions.storage- Custom storage adapter for session persistence
Returns: ReactorClient<Schema>
Client Properties
auth- Authentication clientfrom(table)- Data query builderrpc(fn, args)- RPC function callsstorage- Storage clientfunctions- Functions clientjobs- Jobs clientsites- Sites admin clientrealtime- Realtime client
TypeScript Support
Generate types from your database schema:
reactor types generate --output ./database.types.tsThen use them with the client:
import { createClient } from '@reactor-cloud/client';
import type { Database } from './database.types';
const reactor = createClient<Database>(url, options);
// Full type safety for queries
const { data } = await reactor.from('users').select('id, email');
// data is typed as { id: string; email: string }[]Documentation
License
MIT
