App SDK
App SDK
@inhaus/sdk: the signed-in user and files, from inside your app.
@inhaus/sdk is the small library your app imports to use Inhaus features. You do not install it: Inhaus supplies it when it builds your app, in a browser version and a server version, and picks the right one for each file.
import { getUser, files } from '@inhaus/sdk';What is in it
| Export | Browser | Server | Reference |
|---|---|---|---|
getUser() | ✓ | ✓ | getUser |
files.put(), files.get(), files.url(), files.delete() | ✓ | files |
Server functions that talk to Inhaus take the env object your fetch handler receives as their first argument.
TypeScript
Add this declaration to your project so TypeScript knows the shapes:
declare module '@inhaus/sdk' {
export interface InhausUser {
id: string;
email: string;
name: string;
role: 'owner' | 'editor' | 'viewer';
workspace: string;
}
/** Browser: who is signed in. Server: pass the incoming request. */
export function getUser(): Promise<InhausUser | null>;
export function getUser(request: Request): InhausUser | null;
export const files: {
put(env: unknown, key: string, body: string | ArrayBuffer | Uint8Array | Blob, contentType?: string): Promise<void>;
get(env: unknown, key: string): Promise<Response | null>;
url(env: unknown, key: string): Promise<string>;
delete(env: unknown, key: string): Promise<void>;
};
}