Skip to content
TypeWire

@tahanabavi/typefetch-encryption

documents v0.0.0

Field-level request/response encryption middleware for TypeFetch contracts (AES, DES, RSA, Base64, custom).

Usage

ts
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:

ts
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 },
},
}