This page covers how to add custom logic, methods, and dependencies to your TypeScript SDK.
To get started adding custom code:
By default, the TypeScript generator only auto-generates exports entries in package.json for your API definition. If you want consumers to import your custom file via a dedicated subpath (e.g. import { myHelper } from "@acme/sdk/helper"), you must register it manually using packageJson.exports in generators.yml:
The export key (e.g., "./helper") determines the import path your users will use and doesn’t need to match the source file path. These entries are merged into the generated exports, so they persist across regenerations. Since Node.js enforces the exports map, custom files aren’t importable via a subpath until you add them here.
Fern also allows you to add custom methods to the SDK itself (e.g.
client.my_method() ) by inheriting the Fern generated client and then
extending it.
See an example from Flatfile using this process in their TypeScript SDK
First, import the Fern generated client from ../client and alias it to FernClient.
Next, extend FernClient and add whatever methods you want.
See an example from Flatfile doing this in their FlatfileClient
Update your index.ts file to export the extended client instead of the generated client.
See an example index.ts from Flatfile
.fernignoreAdd both the wrapper directory and index.ts to .fernignore.
See an example .fernignore from Flatfile
This feature is available only for the Enterprise plan. To get started, reach out to support@buildwithfern.com.
To add packages that your custom code requires, use the extraDependencies and extraDevDependencies options in your generators.yml.