Usage
import { ApiClient } from "@tahanabavi/typefetch";
import { encryptionMiddleware } from "@tahanabavi/typefetch-encryption";
const client = new ApiClient({ baseUrl: "https://api.example.com" }, contracts);
client.use(encryptionMiddleware, {
keyProvider: () => ({ type: "symmetric", key: process.env.FIELD_KEY! }),
});
client.init();Which fields are encrypted is declared on the endpoint, not at the call site:
updateUser: {
method: "PATCH",
path: "/users/:id",
request: z.object({ path: z.object({ id: z.string() }), body: Profile }),
response: Profile,
encryption: {
method: "AES",
request: { body: { ssn: true, phone: true } },
response: { ssn: true },
},
}