@zenku/sdk
v0.3.2
Published
SDK for building apps with Zenku — auth, RBAC, file storage, and migrations
Readme
@zenku/sdk
SDK for building RBAC apps with PocketBase.
Install
npm install @zenku/sdk
# or
pnpm add @zenku/sdkInstall the peer dependencies you need based on which subpaths you use:
# Required for all subpaths
pnpm add pocketbase
# For API apps (./hono, ./hono/env, ./rbac/superuser)
pnpm add hono zod
# For web apps (./react/auth, ./react/token-callback)
pnpm add reactSubpath Exports
Server / API
@zenku/sdk/hono
Hono app factory with CORS, health checks, error handling, and standalone PocketBase JWT auth middleware.
import { createBaseApp, createAuthMiddleware } from "@zenku/sdk/hono";
import type { AuthUser } from "@zenku/sdk/hono";
const { app } = createBaseApp({ serviceName: "my-api" });
app.use(
"*",
createAuthMiddleware({
pbUrl: "https://pb.example.com",
excludePaths: ["/health"],
}),
);
app.get("/me", (c) => {
const user = c.get("user") as AuthUser;
return c.json({ id: user.id, email: user.email });
});@zenku/sdk/hono/env
Base environment schema and loader for API apps.
import { baseEnvSchema, createEnvLoader } from "@zenku/sdk/hono/env";
const envSchema = baseEnvSchema.extend({
PORT: z.coerce.number().default(3600),
});@zenku/sdk/rbac
RBAC client for managing accounts, roles, members, and invitations.
import { createPocketBaseExtensions } from "@zenku/sdk/rbac";@zenku/sdk/rbac/superuser
Server-only PocketBase superuser client with auto-reauth.
import { createSuperuserClient } from "@zenku/sdk/rbac/superuser";Client / React
@zenku/sdk/react/auth
Auth context factory for React apps. Creates an AuthProvider component and useAuth hook bound to a PocketBase instance.
import { createAuth } from "@zenku/sdk/react/auth";
import PocketBase from "pocketbase";
const pb = new PocketBase("https://pb.example.com");
pb.autoCancellation(false);
// Pass a type parameter for typed user access (recommended).
// UsersResponse can be generated with the zenku-types CLI.
import type { UsersResponse } from "./pocketbase-types";
export const { AuthProvider, useAuth } = createAuth<UsersResponse>(pb);
// Wrap your app with AuthProvider, then use the hook in any component:
// const { isAuthenticated, isLoading, user, logout } = useAuth();
// user?.email — fully typed, no cast needed@zenku/sdk/react/token-callback
Token callback page for CLI-based login flows. Reads a JWT from the URL fragment, validates it against PocketBase, and saves auth state.
import { TokenCallback } from "@zenku/sdk/react/token-callback";
export default function AuthCallbackPage() {
return <TokenCallback pbUrl="https://pb.example.com" />;
}Build-time
@zenku/sdk/migrations
PocketBase migration helpers — field builders, index helpers, condition builders, and API rule presets.
import {
accountField,
autodateFields,
accountIndexes,
rules,
} from "@zenku/sdk/migrations";CLI
zenku-types
Generate TypeScript types from PocketBase collections.
npx zenku-types --local --migrations-dir ./pb_migrations
npx zenku-types --url https://pb.example.com --email [email protected] --password secretLicense
Proprietary — see LICENSE.
