SDKs on npm
The eight JavaScript packages of Hosting by Infaris, each with its install line and a minimal example.
All SDKs are on npm under @infaris/*, version 0.1.0. Attach the service to your site first; Hosting then sets the
variables the examples use.
| Package | For |
|---|---|
@infaris/auth-js | Sign-in with an email code, React hooks and token checks on the server |
@infaris/data | The Data API: REST on your database with Row Level Security |
@infaris/realtime-js | Database changes, broadcast and presence over WebSockets |
@infaris/storage-js | Files in buckets, signed URLs and uploads |
@infaris/kv | KV (Valkey) over HTTP, with rate limiting and caching |
@infaris/vector | Vector search with pgvector |
@infaris/flags | Feature flags and Edge Config |
@infaris/insights | Speed Insights and Web Analytics without cookies |
Secret keys (ifr_sk_...) belong on the server only.
@infaris/auth-js
npm install @infaris/auth-jsimport { createClient } from '@infaris/auth-js';
const auth = createClient(process.env.NEXT_PUBLIC_INFARIS_AUTH_URL!, process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!);
await auth.signInWithOtp({ email });
const { data, error } = await auth.verifyOtp({ email, token: code });More in Auth.
@infaris/data
npm install @infaris/dataimport { createClient } from '@infaris/data';
const db = createClient(process.env.NEXT_PUBLIC_INFARIS_DATA_URL!, process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!, {
accessToken: () => auth.getAccessToken(), // auth from @infaris/auth-js
});
const { data, error } = await db.from('todos').select('id, title').eq('done', false);A table is only reachable after hosting db expose. More in Data API.
@infaris/realtime-js
npm install @infaris/realtime-jsimport { createRealtimeClient } from '@infaris/realtime-js';
const rt = createRealtimeClient({
url: process.env.NEXT_PUBLIC_INFARIS_REALTIME_URL!,
apiKey: process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!,
accessToken: () => auth.getAccessToken(),
});
rt.channel('todos')
.on('postgres_changes', { event: '*', schema: 'public', table: 'todos' }, (p) => console.log(p.new))
.subscribe();Turn the table on for Realtime first. More in Realtime.
@infaris/storage-js
npm install @infaris/storage-jsimport { createStorageClientFromEnv } from '@infaris/storage-js';
const storage = createStorageClientFromEnv(); // server, reads INFARIS_STORAGE_*
await storage.bucket.upload('invoices/0042.pdf', pdf, { contentType: 'application/pdf' });
const { data } = await storage.bucket.createSignedUrl('invoices/0042.pdf', 300);More in Storage.
@infaris/kv
npm install @infaris/kvimport { Kv } from '@infaris/kv';
const kv = Kv.fromEnv(); // KV_REST_API_URL and KV_REST_API_TOKEN
await kv.set('greeting', 'hello', { ex: 60 });
const greeting = await kv.get<string>('greeting');Attach: infaris-guard hosting kv link <kvId> --site <site>. More in KV and vector.
@infaris/vector
npm install @infaris/vector pgimport pg from 'pg';
import { createVectorStore, mistral } from '@infaris/vector';
const docs = createVectorStore({
db: new pg.Pool({ connectionString: process.env.DATABASE_URL }),
table: 'docs',
dimensions: 1024,
embed: mistral(), // MISTRAL_API_KEY
});
await docs.upsert([{ id: 'faq-1', content: 'You can cancel every month.' }]);
const hits = await docs.search('How do I cancel?', { limit: 5 });Server only. Create the table with infaris-guard hosting db vector create <databaseId> docs --dimensions 1024.
@infaris/flags
npm install @infaris/flagsimport { createFlagsClient } from '@infaris/flags';
const flags = createFlagsClient(); // server, reads INFARIS_FLAGS_URL and INFARIS_FLAGS_SECRET_KEY
if (await flags.getFlag('new-checkout', { userId: user.id })) {
// new checkout
}Turn on: infaris-guard hosting config enable --site <site>. More in Feature flags.
@infaris/insights
npm install @infaris/insightsimport { Insights } from '@infaris/insights/next';
<Insights apiKey="ins_..." />Also for React (@infaris/insights/react) and Vue (@infaris/insights/vue). On Hosting the script is added for
you; the package is for sites elsewhere. More in Speed Insights.