Guard

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.

PackageFor
@infaris/auth-jsSign-in with an email code, React hooks and token checks on the server
@infaris/dataThe Data API: REST on your database with Row Level Security
@infaris/realtime-jsDatabase changes, broadcast and presence over WebSockets
@infaris/storage-jsFiles in buckets, signed URLs and uploads
@infaris/kvKV (Valkey) over HTTP, with rate limiting and caching
@infaris/vectorVector search with pgvector
@infaris/flagsFeature flags and Edge Config
@infaris/insightsSpeed Insights and Web Analytics without cookies

Secret keys (ifr_sk_...) belong on the server only.

@infaris/auth-js

npm install @infaris/auth-js
import { 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/data
import { 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-js
import { 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-js
import { 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/kv
import { 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 pg
import 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/flags
import { 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/insights
import { 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.