
Research
/Security News
Fake imToken Chrome Extension Steals Seed Phrases via Phishing Redirects
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.
typesafe-rpc
Advanced tools
A modern, type-safe RPC (Remote Procedure Call) library for Node.js, TypeScript, and React applications. Built with full TypeScript support, providing end-to-end type safety between client and server.
npm install typesafe-rpc
# or
yarn add typesafe-rpc
# or
pnpm add typesafe-rpc
# or
bun add typesafe-rpc
// api-schema.ts
import type { BaseContext, Handler } from 'typesafe-rpc';
type UserContext = BaseContext & {
user?: { id: string; name: string };
};
type UserParams = { id: string };
type UserResult = { id: string; name: string; email: string };
const getUserHandler: Handler<UserParams, UserContext, UserResult, {}> = async ({
params,
context,
}) => {
// Your business logic here
return {
id: params.id,
name: 'John Doe',
email: 'john@example.com',
};
};
export const apiSchema = {
users: {
getById: getUserHandler,
},
} as const;
// server.ts
import { createRpcHandler } from 'typesafe-rpc/server';
import { apiSchema } from './api-schema';
export async function handleRequest(request: Request): Promise<Response> {
const context = { request };
return createRpcHandler({
context,
operations: apiSchema,
errorHandler: (error) => {
console.error('RPC Error:', error);
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
status: 500,
headers: { 'Content-Type': 'application/json' },
});
},
hooks: {
preCall: (context) => console.log('RPC call started'),
postCall: (context, performance) => console.log(`RPC call completed in ${performance}ms`),
error: (context, performance, error) =>
console.error(`RPC call failed after ${performance}ms:`, error),
},
});
}
// client.ts
import { createRpcClient } from 'typesafe-rpc/client';
import type { apiSchema } from './api-schema';
const client = createRpcClient<typeof apiSchema>('/api/rpc');
// Usage with full type safety
const user = await client.users.getById({ id: '123' });
console.log(user.name); // TypeScript knows this exists!
// React component
import { useState, useEffect } from 'react';
import { client } from './client';
function UserProfile({ userId }: { userId: string }) {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const controller = new AbortController();
client.users.getById({ id: userId }, controller.signal)
.then(setUser)
.catch(console.error)
.finally(() => setLoading(false));
return () => controller.abort();
}, [userId]);
if (loading) return <div>Loading...</div>;
if (!user) return <div>User not found</div>;
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
);
}
BaseContexttype BaseContext = {
request: Request;
};
Handler<Params, Context, Result, ExtraParams>type Handler<Params, Context extends BaseContext, Result, ExtraParams> = (
args: Args<Params, Context, ExtraParams>,
) => Promise<Result>;
RpcSchematype RpcSchema = {
[entity: string]: {
[operation: string]: Handler<any, any, any, any>;
};
};
createRpcHandler<T, Context>Creates an RPC handler for processing requests.
function createRpcHandler<T extends RpcSchema, Context extends BaseContext>({
context,
operations,
errorHandler?,
hooks?,
}: {
context: Context;
operations: T;
errorHandler?: (error: any) => Response;
hooks?: {
preCall?: (context: Context) => void;
postCall?: (context: Context, performance: number) => void;
error?: (context: Context, performance: number, error: any) => void;
};
}): Promise<Response>
createRpcClient<T>(endpoint)Creates a type-safe RPC client.
function createRpcClient<T extends RpcSchema>(endpoint: string): RpcClient<T>;
The returned client provides a proxy that matches your schema structure with full type safety.
import type { Middleware } from 'typesafe-rpc';
// Authentication middleware
const authMiddleware: Middleware<any, BaseContext, {}, { user: { id: string } }> = async ({
context,
}) => {
const token = context.request.headers.get('Authorization');
if (!token) throw new Response('Unauthorized', { status: 401 });
// Verify token and return user info
return { user: { id: 'user-123' } };
};
// Usage in handler
const protectedHandler: Handler<
UserParams,
BaseContext,
UserResult,
{ user: { id: string } }
> = async ({ params, context, extraParams }) => {
// extraParams.user is now available with full type safety
return {
/* ... */
};
};
git clone https://github.com/bacali95/typesafe-rpc.git
cd typesafe-rpc
bun install
# Build the library
bun run build
# Run tests
bun run test
# Lint code
bun run lint
# Format code
bun run prettier:fix
# Check code formatting
bun run prettier:check
We welcome contributions! Please see our Contributing Guide for details.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by Nasreddine Bac Ali
FAQs
A typesafe RPC library for Node.js, TypeScript and React.
The npm package typesafe-rpc receives a total of 10 weekly downloads. As such, typesafe-rpc popularity was classified as not popular.
We found that typesafe-rpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.

Security News
Latio’s 2026 report recognizes Socket as a Supply Chain Innovator and highlights our work in 0-day malware detection, SCA, and auto-patching.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.