Runtime Reference
Usage
Install luvabase with your package manager of choice for example:
npm install luvabaseThen import the methods you need from luvabase/runtime:
import { getMember, getMembers, getSession, sendMemberEmail } from "luvabase/runtime"Local Development
The runtime APIs only work from inside a deployed Luvabase app. During local development, call your own wrapper instead of importing luvabase/runtime throughout your app, then return mock data locally and delegate to the runtime APIs in production.
For example, create a luvabase.ts file:
import {
getMembers as getRuntimeMembers,
getSession,
type Member,
type RuntimeEnv,
} from "luvabase/runtime"
function isDevelopment(): boolean {
return import.meta.env.MODE !== "production"
}
export async function getMembers(env: RuntimeEnv): Promise<Member[]> {
if (isDevelopment()) {
return [
{
id: "dev-user",
type: "user" as const,
role: "owner",
name: "Development User",
imageUrl: null,
},
]
}
return getRuntimeMembers(env)
}
export async function getCurrentUser(request: Request): Promise<Member | null> {
if (isDevelopment()) {
return {
id: "dev-user",
type: "user" as const,
role: "owner",
name: "Development User",
imageUrl: null,
}
}
const session = getSession(request)
return session.member
}Then import from your wrapper:
import { getCurrentUser } from "./luvabase"
export default {
async fetch(request: Request, env: RuntimeEnv) {
const user = await getCurrentUser(request)
return Response.json({ user })
},
}Runtime Methods Reference
getSession(request)
Returns the current pod session.
function getSession(request: Request): SessionThe returned member is null when the request is not authenticated. This reads the trusted request headers injected by Luvabase and does not call the Runtime API.
getMembers(env)
Returns all members of the current pod.
function getMembers(env: RuntimeEnv): Promise<Member[]>The env value must be the Worker env object passed to your app. Luvabase binds a pod credential there for Runtime API calls.
getMember(env, memberId)
Returns one member of the current pod.
function getMember(env: RuntimeEnv, memberId: string): Promise<Member>sendMemberEmail(env, params)
Send an email to a member of the current pod.
function sendMemberEmail(
env: RuntimeEnv,
params: {
memberId: string
subject: string
content: string
},
): Promise<void>Types
Member
type Member = {
id: string
type: "user" | "agent"
role: string
name: string
imageUrl: string | null
}Session
type Session = {
isAuthenticated: boolean
member: Member | null
}RuntimeEnv
type RuntimeEnv = {
LUVABASE_RUNTIME_VERSION?: string
LUVABASE_POD_ID?: string
LUVABASE_POD_URL?: string
LUVABASE_POD_ADMIN_URL?: string
LUVABASE_POD_INSTALLED_AT?: string
LUVABASE_POD_UPDATED_AT?: string
LUVABASE_POD_SECRET?: string
}